Skip to content

Soap XML layer cleanup #18694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/soap/php_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTyp
break;
}
parent = parent->parent;
}
}
if (parent == NULL) {
cur_type->form = XSD_FORM_UNQUALIFIED;
}
Expand Down
47 changes: 8 additions & 39 deletions ext/soap/php_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static bool is_blank(const xmlChar* str)
return true;
}

/* removes all empty text, comments and other insignoficant nodes */
/* removes all empty text, comments and other insignificant nodes */
static void cleanup_xml_node(xmlNodePtr node)
{
xmlNodePtr trav;
Expand Down Expand Up @@ -80,10 +80,6 @@ xmlDocPtr soap_xmlParseFile(const char *filename)
xmlDocPtr ret;
bool old_allow_url_fopen;

/*
xmlInitParser();
*/

old_allow_url_fopen = PG(allow_url_fopen);
PG(allow_url_fopen) = 1;
ctxt = xmlCreateFileParserCtxt(filename);
Expand Down Expand Up @@ -120,10 +116,6 @@ xmlDocPtr soap_xmlParseFile(const char *filename)
ret = NULL;
}

/*
xmlCleanupParser();
*/

if (ret) {
cleanup_xml_node((xmlNodePtr)ret);
}
Expand All @@ -135,10 +127,6 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
xmlParserCtxtPtr ctxt = NULL;
xmlDocPtr ret;


/*
xmlInitParser();
*/
ctxt = xmlCreateMemoryParserCtxt(buf, buf_size);
if (ctxt) {
bool old;
Expand Down Expand Up @@ -171,10 +159,6 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
ret = NULL;
}

/*
xmlCleanupParser();
*/

/*
if (ret) {
cleanup_xml_node((xmlNodePtr)ret);
Expand All @@ -183,6 +167,7 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t buf_size)
return ret;
}

/* FIXME: this is wrong, attributes don't inherit the namespace of the node they're in! */
xmlNsPtr attr_find_ns(xmlAttrPtr node)
{
if (node->ns) {
Expand All @@ -203,7 +188,7 @@ xmlNsPtr node_find_ns(xmlNodePtr node)
}
}

int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns)
int attr_is_equal_ex(xmlAttrPtr node, const char *name, const char *ns)
{
if (name == NULL || ((node->name) && strcmp((char*)node->name, name) == 0)) {
if (ns) {
Expand All @@ -219,7 +204,7 @@ int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns)
return FALSE;
}

int node_is_equal_ex(xmlNodePtr node, char *name, char *ns)
int node_is_equal_ex(xmlNodePtr node, const char *name, const char *ns)
{
if (name == NULL || ((node->name) && strcmp((char*)node->name, name) == 0)) {
if (ns) {
Expand All @@ -236,7 +221,7 @@ int node_is_equal_ex(xmlNodePtr node, char *name, char *ns)
}


xmlAttrPtr get_attribute_ex(xmlAttrPtr node, char *name, char *ns)
xmlAttrPtr get_attribute_ex(xmlAttrPtr node, const char *name, const char *ns)
{
while (node!=NULL) {
if (attr_is_equal_ex(node, name, ns)) {
Expand All @@ -247,7 +232,7 @@ xmlAttrPtr get_attribute_ex(xmlAttrPtr node, char *name, char *ns)
return NULL;
}

xmlNodePtr get_node_ex(xmlNodePtr node, char *name, char *ns)
xmlNodePtr get_node_ex(xmlNodePtr node, const char *name, const char *ns)
{
while (node!=NULL) {
if (node_is_equal_ex(node, name, ns)) {
Expand All @@ -258,23 +243,7 @@ xmlNodePtr get_node_ex(xmlNodePtr node, char *name, char *ns)
return NULL;
}

xmlNodePtr get_node_recurisve_ex(xmlNodePtr node, char *name, char *ns)
{
while (node != NULL) {
if (node_is_equal_ex(node, name, ns)) {
return node;
} else if (node->children != NULL) {
xmlNodePtr tmp = get_node_recurisve_ex(node->children, name, ns);
if (tmp) {
return tmp;
}
}
node = node->next;
}
return NULL;
}

xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns)
xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, const char *name, const char *name_ns, const char *attribute, const char *value, const char *attr_ns)
{
xmlAttrPtr attr;

Expand All @@ -295,7 +264,7 @@ xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns
return NULL;
}

xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns)
xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, const char *name, const char *name_ns, const char *attribute, const char *value, const char *attr_ns)
{
while (node != NULL) {
if (node_is_equal_ex(node, name, name_ns)) {
Expand Down
28 changes: 7 additions & 21 deletions ext/soap/php_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,15 @@ xmlDocPtr soap_xmlParseMemory(const void *buf, size_t size);

xmlNsPtr attr_find_ns(xmlAttrPtr node);
xmlNsPtr node_find_ns(xmlNodePtr node);
int attr_is_equal_ex(xmlAttrPtr node, char *name, char *ns);
int node_is_equal_ex(xmlNodePtr node, char *name, char *ns);
xmlAttrPtr get_attribute_ex(xmlAttrPtr node,char *name, char *ns);
xmlNodePtr get_node_ex(xmlNodePtr node,char *name, char *ns);
xmlNodePtr get_node_recursive_ex(xmlNodePtr node,char *name, char *ns);
xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns);
xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, char *name, char *name_ns, char *attribute, char *value, char *attr_ns);
int attr_is_equal_ex(xmlAttrPtr node, const char *name, const char *ns);
int node_is_equal_ex(xmlNodePtr node, const char *name, const char *ns);
xmlAttrPtr get_attribute_ex(xmlAttrPtr node,const char *name, const char *ns);
xmlNodePtr get_node_ex(xmlNodePtr node, const char *name, const char *ns);
xmlNodePtr get_node_recursive_ex(xmlNodePtr node, const char *name, const char *ns);
xmlNodePtr get_node_with_attribute_ex(xmlNodePtr node, const char *name, const char *name_ns, const char *attribute, const char *value, const char *attr_ns);
xmlNodePtr get_node_with_attribute_recursive_ex(xmlNodePtr node, const char *name, const char *name_ns, const char *attribute, const char *value, const char *attr_ns);
void parse_namespace(const xmlChar *inval, const char **value, char **namespace);

#define FOREACHATTRNODE(n,c,i) FOREACHATTRNODEEX(n,c,NULL,i)
#define FOREACHATTRNODEEX(n,c,ns,i) \
do { \
if (n == NULL) { \
break; \
} \
if (c) { \
i = get_attribute_ex(n,c,ns); \
} else { \
i = n; \
} \
if (i != NULL) { \
n = i;

#define FOREACHNODE(n,c,i) FOREACHNODEEX(n,c,NULL,i)
#define FOREACHNODEEX(n,c,ns,i) \
do { \
Expand Down