Skip to content

Commit b7b492b

Browse files
authored
Deduplicate URI building code in soap schema code (#15799)
1 parent 6ed730e commit b7b492b

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

ext/soap/php_schema.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ static void schema_load_file(sdlCtx *ctx, xmlAttrPtr ns, xmlChar *location, xmlA
143143
}
144144
}
145145

146+
/* Returned uri must be freed by the caller. */
147+
xmlChar *schema_location_construct_uri(const xmlAttr *attribute)
148+
{
149+
xmlChar *uri;
150+
xmlChar *base = xmlNodeGetBase(attribute->doc, attribute->parent);
151+
152+
if (base == NULL) {
153+
uri = xmlBuildURI(attribute->children->content, attribute->doc->URL);
154+
} else {
155+
uri = xmlBuildURI(attribute->children->content, base);
156+
xmlFree(base);
157+
}
158+
159+
return uri;
160+
}
161+
146162
/*
147163
2.6.1 xsi:type
148164
2.6.2 xsi:nil
@@ -196,15 +212,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema)
196212
if (location == NULL) {
197213
soap_error0(E_ERROR, "Parsing Schema: include has no 'schemaLocation' attribute");
198214
} else {
199-
xmlChar *uri;
200-
xmlChar *base = xmlNodeGetBase(trav->doc, trav);
201-
202-
if (base == NULL) {
203-
uri = xmlBuildURI(location->children->content, trav->doc->URL);
204-
} else {
205-
uri = xmlBuildURI(location->children->content, base);
206-
xmlFree(base);
207-
}
215+
xmlChar *uri = schema_location_construct_uri(location);
208216
schema_load_file(ctx, NULL, uri, tns, 0);
209217
xmlFree(uri);
210218
}
@@ -216,15 +224,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema)
216224
if (location == NULL) {
217225
soap_error0(E_ERROR, "Parsing Schema: redefine has no 'schemaLocation' attribute");
218226
} else {
219-
xmlChar *uri;
220-
xmlChar *base = xmlNodeGetBase(trav->doc, trav);
221-
222-
if (base == NULL) {
223-
uri = xmlBuildURI(location->children->content, trav->doc->URL);
224-
} else {
225-
uri = xmlBuildURI(location->children->content, base);
226-
xmlFree(base);
227-
}
227+
xmlChar *uri = schema_location_construct_uri(location);
228228
schema_load_file(ctx, NULL, uri, tns, 0);
229229
xmlFree(uri);
230230
/* TODO: <redefine> support */
@@ -245,14 +245,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema)
245245
}
246246
}
247247
if (location) {
248-
xmlChar *base = xmlNodeGetBase(trav->doc, trav);
249-
250-
if (base == NULL) {
251-
uri = xmlBuildURI(location->children->content, trav->doc->URL);
252-
} else {
253-
uri = xmlBuildURI(location->children->content, base);
254-
xmlFree(base);
255-
}
248+
uri = schema_location_construct_uri(location);
256249
}
257250
schema_load_file(ctx, ns, uri, tns, 1);
258251
if (uri != NULL) {xmlFree(uri);}

ext/soap/php_schema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
int load_schema(sdlCtx *ctx, xmlNodePtr schema);
2323
void schema_pass2(sdlCtx *ctx);
2424

25+
xmlChar *schema_location_construct_uri(const xmlAttr *attribute);
26+
2527
void delete_model(zval *zv);
2628
void delete_model_persistent(zval *zv);
2729
void delete_type(zval *zv);

ext/soap/php_sdl.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include)
361361
/* TODO: namespace ??? */
362362
xmlAttrPtr tmp = get_attribute(trav->properties, "location");
363363
if (tmp) {
364-
xmlChar *uri;
365-
xmlChar *base = xmlNodeGetBase(trav->doc, trav);
366-
367-
if (base == NULL) {
368-
uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
369-
} else {
370-
uri = xmlBuildURI(tmp->children->content, base);
371-
xmlFree(base);
372-
}
364+
xmlChar *uri = schema_location_construct_uri(tmp);
373365
load_wsdl_ex(this_ptr, (char*)uri, ctx, 1);
374366
xmlFree(uri);
375367
}

0 commit comments

Comments
 (0)