Fix ns extraction

This commit is contained in:
Vivek Kumar Dutta 2026-02-26 17:12:30 +05:30 committed by Vivek Dutta
parent 715f2c85ef
commit b47c250634
5 changed files with 65 additions and 64 deletions

View file

@ -668,7 +668,7 @@ extern const char *g_download_file_types[__MAX_DOWNLOAD_FILETYPE];
extern struct cwmp cwmp_ctx;
extern unsigned int flashsize;
extern struct FAULT_CPE FAULT_CPE_ARRAY[];
extern struct cwmp_namespaces ns;
extern struct cwmp_namespaces g_cwmp_ns;
extern struct session_timer_event *global_session_event;
void add_dm_parameter_to_list_without_check(struct list_head *head, const char *param_name, const char *param_val,

View file

@ -58,7 +58,7 @@ static int cwmp_rpc_acs_prepare_du_state_change_complete(struct rpc *rpc);
static int cwmp_rpc_acs_prepare_autonomous_du_state_change_complete(struct rpc *rpc);
#endif
struct cwmp_namespaces ns;
struct cwmp_namespaces g_cwmp_ns;
const struct rpc_cpe_method rpc_cpe_methods[] = {
[RPC_CPE_GET_RPC_METHODS] = { "GetRPCMethods", cwmp_handle_rpc_cpe_get_rpc_methods, AMD_1 },
[RPC_CPE_SET_PARAMETER_VALUES] = { "SetParameterValues", cwmp_handle_rpc_cpe_set_parameter_values, AMD_1 },
@ -110,7 +110,7 @@ int xml_handle_message()
struct config *conf = &(cwmp_ctx.conf);
/* get method */
snprintf(buf, sizeof(buf), "%s:%s", ns.soap_env, "Body");
snprintf(buf, sizeof(buf), "%s:%s", g_cwmp_ns.soap_env, "Body");
if (strlen(buf) == 0) {
cwmp_ctx.session->fault_code = FAULT_CPE_INTERNAL_ERROR;
@ -121,7 +121,7 @@ int xml_handle_message()
b = xml_find_element(root, root, buf, XML_DESCEND);
if (!b) {
CWMP_LOG(INFO, "Invalid received message");
CWMP_LOG(ERROR, "# Not able to locate Body<%s> #", buf);
cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED;
goto fault;
}
@ -143,19 +143,19 @@ int xml_handle_message()
}
/* convert QName to localPart, check that ns is the expected one */
/* convert QName to localPart, check that g_cwmp_ns is the expected one */
if (c && strchr(c, ':')) {
char *tmp = strchr(c, ':');
size_t ns_len = tmp - c;
if (CWMP_STRLEN(ns.cwmp) != ns_len) {
CWMP_LOG(INFO, "Namespace length is not matched in string (%s) and expected (%s)", c, ns.cwmp);
if (CWMP_STRLEN(g_cwmp_ns.cwmp) != ns_len) {
CWMP_LOG(INFO, "Namespace length is not matched in string (%s) and expected (%s)", c, g_cwmp_ns.cwmp);
cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED;
goto fault;
}
if (CWMP_STRNCMP(ns.cwmp, c, ns_len)) {
CWMP_LOG(INFO, "Namespace in string (%s) is not the expected (%s) one", c, ns.cwmp);
if (CWMP_STRNCMP(g_cwmp_ns.cwmp, c, ns_len)) {
CWMP_LOG(INFO, "Namespace in string (%s) is not the expected (%s) one", c, g_cwmp_ns.cwmp);
cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED;
goto fault;
}
@ -1295,7 +1295,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc)
char c[256];
const char *err_msg = NULL;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "SetParameterAttributes") == -1) {
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "SetParameterAttributes") == -1) {
err_msg = "Failed to write in buffer, string operation failure";
goto fault;
}
@ -1833,7 +1833,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc)
char c[256];
char err_msg[256] = {0};
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ChangeDUState") == -1) {
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "ChangeDUState") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
snprintf(err_msg, sizeof(err_msg), "Failed to write in buffer, string operation failed");
goto fault;
@ -1948,7 +1948,7 @@ int cwmp_handle_rpc_cpe_download(struct rpc *rpc)
char *start_time = NULL;
char *complete_time = NULL;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "Download") == -1) {
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "Download") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
snprintf(err_msg, sizeof(err_msg), "Failure in buffer writting, string operation failed");
goto fault;
@ -2097,7 +2097,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc)
long int schedule_download_delay[4] = { 0, 0, 0, 0 };
char err_msg[256] = {0};
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ScheduleDownload") == -1) {
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "ScheduleDownload") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
snprintf(err_msg, sizeof(err_msg), "Failure in buffer writting, string operation failed");
goto fault;
@ -2263,7 +2263,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc)
char *start_time = NULL;
char *complete_time = NULL;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "Upload") == -1) {
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "Upload") == -1) {
error = FAULT_CPE_INTERNAL_ERROR;
snprintf(err_msg, sizeof(err_msg), "Failed to write on buffer, string operation failure");
goto fault;

View file

@ -182,20 +182,24 @@ int cwmp_schedule_rpc()
while (cwmp_ctx.session->rpc_cpe) {
CWMP_LOG(INFO, "Preparing the %s%s message", rpc_cpe_methods[cwmp_ctx.session->rpc_cpe->type].name, (cwmp_ctx.session->rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
if (cwmp_rpc_cpe_handle_message(cwmp_ctx.session->rpc_cpe))
if (cwmp_rpc_cpe_handle_message(cwmp_ctx.session->rpc_cpe)) {
goto retry;
}
XML_FREE_DOC(cwmp_ctx.session->tree_in);
CWMP_LOG(INFO, "Send the %s%s message to the ACS", rpc_cpe_methods[cwmp_ctx.session->rpc_cpe->type].name, (cwmp_ctx.session->rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : "");
if (xml_send_message(cwmp_ctx.session->rpc_cpe))
if (xml_send_message(cwmp_ctx.session->rpc_cpe)) {
goto retry;
}
XML_FREE_DOC(cwmp_ctx.session->tree_out);
FREE(cwmp_ctx.session->rpc_cpe);
if (!cwmp_ctx.session->tree_in)
break;
CWMP_LOG(INFO, "Receive request from the ACS");
CWMP_LOG(INFO, "Receive request from the ACS iteratively");
if (xml_handle_message())
goto retry;
}

View file

@ -1590,65 +1590,62 @@ int xml_recreate_namespace(xmlNode *tree)
{
xmlNode *b = tree;
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
FREE(ns.xsi);
FREE(ns.cwmp);
if (b == NULL)
return -1;
if (tree) {
do {
const char *c;
xmlNs *ns = b->nsDef;
if (ns == NULL)
return -1;
c = xml__get_attribute_name_by_value(b, soap_env_url);
if (c && *(c + 5) == ':') {
FREE(ns.soap_env);
ns.soap_env = strdup((c + 6));
while (ns) {
const char *href = (const char *)ns->href;
if (href) {
const char *prefix = (const char *)ns->prefix;
if (CWMP_STRCMP(href, soap_env_url) == 0) {
FREE(g_cwmp_ns.soap_env);
g_cwmp_ns.soap_env = strdup(prefix);
}
c = xml__get_attribute_name_by_value(b, soap_enc_url);
if (c && *(c + 5) == ':') {
FREE(ns.soap_enc);
ns.soap_enc = strdup((c + 6));
if (CWMP_STRCMP(href, soap_enc_url) == 0) {
FREE(g_cwmp_ns.soap_enc);
g_cwmp_ns.soap_enc = strdup(prefix);
}
c = xml__get_attribute_name_by_value(b, xsd_url);
if (c && *(c + 5) == ':') {
FREE(ns.xsd);
ns.xsd = strdup((c + 6));
if (CWMP_STRCMP(href, xsd_url) == 0) {
FREE(g_cwmp_ns.xsd);
g_cwmp_ns.xsd = strdup(prefix);
}
c = xml__get_attribute_name_by_value(b, xsi_url);
if (c && *(c + 5) == ':') {
FREE(ns.xsi);
ns.xsi = strdup((c + 6));
if (CWMP_STRCMP(href, xsi_url) == 0) {
FREE(g_cwmp_ns.xsi);
g_cwmp_ns.xsi = strdup(prefix);
}
int i;
for (i = 0; cwmp_urls[i] != NULL; i++) {
const char *cwmp_urn = cwmp_urls[i];
c = xml__get_attribute_name_by_value(b, cwmp_urn);
if (c && *(c + 5) == ':') {
FREE(ns.cwmp);
ns.cwmp = strdup((c + 6));
if (CWMP_STRCMP(href, cwmp_urn) == 0) {
FREE(g_cwmp_ns.cwmp);
g_cwmp_ns.cwmp = strdup(prefix);
break;
}
}
} while ((b = xml_walk_next(b, tree, XML_DESCEND)));
return 0;
}
ns = ns->next;
}
return -1;
CWMP_LOG(DEBUG, "HEADER env[%s], enc[%s], xsd[%s], xsi[%s], cwmp[%s]", g_cwmp_ns.soap_env, g_cwmp_ns.soap_enc, g_cwmp_ns.xsd, g_cwmp_ns.xsi, g_cwmp_ns.cwmp);
return 0;
}
void xml_exit(void)
{
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
FREE(ns.xsi);
FREE(ns.cwmp);
FREE(g_cwmp_ns.soap_env);
FREE(g_cwmp_ns.soap_enc);
FREE(g_cwmp_ns.xsd);
FREE(g_cwmp_ns.xsi);
FREE(g_cwmp_ns.cwmp);
}
int xml_send_message(struct rpc *rpc)
@ -1718,14 +1715,14 @@ int xml_send_message(struct rpc *rpc)
goto error;
xmlNode *root = xml_get_root_element((xmlDoc *)cwmp_ctx.session->tree_in);
if (xml_recreate_namespace(root) == -1) {
CWMP_LOG(ERROR, "Failed to get ns parameters");
CWMP_LOG(ERROR, "Failed to get g_cwmp_ns parameters");
goto error;
}
/* get NoMoreRequests or HolRequest*/
cwmp_ctx.session->hold_request = false;
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "NoMoreRequests") == -1)
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "NoMoreRequests") == -1)
goto error;
b = xml_find_element(root, root, c, XML_DESCEND);
if (b) {
@ -1736,7 +1733,7 @@ int xml_send_message(struct rpc *rpc)
FREE(bname);
}
} else {
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "HoldRequests") == -1)
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "HoldRequests") == -1)
goto error;
b = xml_find_element(root, root, c, XML_DESCEND);
@ -1809,7 +1806,7 @@ int xml_set_cwmp_id_rpc_cpe()
xmlNode *b;
/* handle cwmp:ID */
if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ID") == -1)
if (snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.cwmp, "ID") == -1)
return -1;
xmlNode *root_in = xml_get_root_element((xmlDoc *)cwmp_ctx.session->tree_in);

View file

@ -42,11 +42,11 @@ struct list_head force_inform_list;
static void clean_name_space()
{
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
FREE(ns.xsi);
FREE(ns.cwmp);
FREE(g_cwmp_ns.soap_env);
FREE(g_cwmp_ns.soap_enc);
FREE(g_cwmp_ns.xsd);
FREE(g_cwmp_ns.xsi);
FREE(g_cwmp_ns.cwmp);
}
static void unit_test_remove_all_session_events()
@ -168,7 +168,7 @@ static void prepare_session_for_rpc_method_call()
xmlNode *b;
char c[128];
snprintf(c, sizeof(c), "%s:%s", ns.soap_env, "Body");
snprintf(c, sizeof(c), "%s:%s", g_cwmp_ns.soap_env, "Body");
xmlNode *root = xmlDocGetRootElement(cwmp_ctx.session->tree_in);
b = xml_find_element(root, root, c, XML_DESCEND);
cwmp_ctx.session->body_in = b;