From 06278ffdca1d2b8d97f9340993f464a5f9e3bfd7 Mon Sep 17 00:00:00 2001 From: vdutta Date: Tue, 30 Aug 2022 09:25:12 +0530 Subject: [PATCH] Optimize get of namespaces --- src/xml.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/xml.c b/src/xml.c index f3d3ff4..41de419 100644 --- a/src/xml.c +++ b/src/xml.c @@ -922,16 +922,18 @@ int xml_recreate_namespace(mxml_node_t *tree) int i; mxml_node_t *b = tree; + FREE(ns.soap_env); + FREE(ns.soap_enc); + FREE(ns.xsd); + FREE(ns.xsi); + FREE(ns.cwmp); + do { char *c; - FREE(ns.soap_env); - FREE(ns.soap_enc); - FREE(ns.xsd); - FREE(ns.xsi); - FREE(ns.cwmp); c = (char *)xml__get_attribute_name_by_value(b, soap_env_url); if (c && *(c + 5) == ':') { + FREE(ns.soap_env); ns.soap_env = strdup((c + 6)); } else { continue; @@ -939,6 +941,7 @@ int xml_recreate_namespace(mxml_node_t *tree) c = (char *)xml__get_attribute_name_by_value(b, soap_enc_url); if (c && *(c + 5) == ':') { + FREE(ns.soap_enc); ns.soap_enc = strdup((c + 6)); } else { continue; @@ -946,6 +949,7 @@ int xml_recreate_namespace(mxml_node_t *tree) c = (char *)xml__get_attribute_name_by_value(b, xsd_url); if (c && *(c + 5) == ':') { + FREE(ns.xsd); ns.xsd = strdup((c + 6)); } else { continue; @@ -953,6 +957,7 @@ int xml_recreate_namespace(mxml_node_t *tree) c = (char *)xml__get_attribute_name_by_value(b, xsi_url); if (c && *(c + 5) == ':') { + FREE(ns.xsi); ns.xsi = strdup((c + 6)); } else { continue; @@ -962,15 +967,17 @@ int xml_recreate_namespace(mxml_node_t *tree) cwmp_urn = cwmp_urls[i]; c = (char *)xml__get_attribute_name_by_value(b, cwmp_urn); if (c && *(c + 5) == ':') { + FREE(ns.cwmp); ns.cwmp = strdup((c + 6)); break; + } else { + continue; } } - if (!ns.cwmp) - continue; + if (ns.cwmp && ns.soap_env && ns.xsd && ns.soap_enc && ns.xsi) + return 0; - return 0; } while ((b = mxmlWalkNext(b, tree, MXML_DESCEND))); return -1; @@ -1039,7 +1046,12 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK); if (!session->tree_in) goto error; - xml_recreate_namespace(session->tree_in); + + if (xml_recreate_namespace(session->tree_in) == -1) { + CWMP_LOG(ERROR, "Failed to get ns parameters"); + goto error; + } + /* get NoMoreRequests or HolRequest*/ session->hold_request = false;