From b7b492b184d227e1c59ac5293bf130237c7c5d19 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:44:09 +0200 Subject: [PATCH] Deduplicate URI building code in soap schema code (#15799) --- ext/soap/php_schema.c | 45 ++++++++++++++++++------------------------- ext/soap/php_schema.h | 2 ++ ext/soap/php_sdl.c | 10 +--------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c index 8f94ec07b2e..c52a4dbe838 100644 --- a/ext/soap/php_schema.c +++ b/ext/soap/php_schema.c @@ -143,6 +143,22 @@ static void schema_load_file(sdlCtx *ctx, xmlAttrPtr ns, xmlChar *location, xmlA } } +/* Returned uri must be freed by the caller. */ +xmlChar *schema_location_construct_uri(const xmlAttr *attribute) +{ + xmlChar *uri; + xmlChar *base = xmlNodeGetBase(attribute->doc, attribute->parent); + + if (base == NULL) { + uri = xmlBuildURI(attribute->children->content, attribute->doc->URL); + } else { + uri = xmlBuildURI(attribute->children->content, base); + xmlFree(base); + } + + return uri; +} + /* 2.6.1 xsi:type 2.6.2 xsi:nil @@ -196,15 +212,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema) if (location == NULL) { soap_error0(E_ERROR, "Parsing Schema: include has no 'schemaLocation' attribute"); } else { - xmlChar *uri; - xmlChar *base = xmlNodeGetBase(trav->doc, trav); - - if (base == NULL) { - uri = xmlBuildURI(location->children->content, trav->doc->URL); - } else { - uri = xmlBuildURI(location->children->content, base); - xmlFree(base); - } + xmlChar *uri = schema_location_construct_uri(location); schema_load_file(ctx, NULL, uri, tns, 0); xmlFree(uri); } @@ -216,15 +224,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema) if (location == NULL) { soap_error0(E_ERROR, "Parsing Schema: redefine has no 'schemaLocation' attribute"); } else { - xmlChar *uri; - xmlChar *base = xmlNodeGetBase(trav->doc, trav); - - if (base == NULL) { - uri = xmlBuildURI(location->children->content, trav->doc->URL); - } else { - uri = xmlBuildURI(location->children->content, base); - xmlFree(base); - } + xmlChar *uri = schema_location_construct_uri(location); schema_load_file(ctx, NULL, uri, tns, 0); xmlFree(uri); /* TODO: support */ @@ -245,14 +245,7 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema) } } if (location) { - xmlChar *base = xmlNodeGetBase(trav->doc, trav); - - if (base == NULL) { - uri = xmlBuildURI(location->children->content, trav->doc->URL); - } else { - uri = xmlBuildURI(location->children->content, base); - xmlFree(base); - } + uri = schema_location_construct_uri(location); } schema_load_file(ctx, ns, uri, tns, 1); if (uri != NULL) {xmlFree(uri);} diff --git a/ext/soap/php_schema.h b/ext/soap/php_schema.h index e84c77baff7..68035000e1e 100644 --- a/ext/soap/php_schema.h +++ b/ext/soap/php_schema.h @@ -22,6 +22,8 @@ int load_schema(sdlCtx *ctx, xmlNodePtr schema); void schema_pass2(sdlCtx *ctx); +xmlChar *schema_location_construct_uri(const xmlAttr *attribute); + void delete_model(zval *zv); void delete_model_persistent(zval *zv); void delete_type(zval *zv); diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 68565e72dfa..538e361a78f 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -361,15 +361,7 @@ static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include) /* TODO: namespace ??? */ xmlAttrPtr tmp = get_attribute(trav->properties, "location"); if (tmp) { - xmlChar *uri; - xmlChar *base = xmlNodeGetBase(trav->doc, trav); - - if (base == NULL) { - uri = xmlBuildURI(tmp->children->content, trav->doc->URL); - } else { - uri = xmlBuildURI(tmp->children->content, base); - xmlFree(base); - } + xmlChar *uri = schema_location_construct_uri(tmp); load_wsdl_ex(this_ptr, (char*)uri, ctx, 1); xmlFree(uri); }