From 201a6900a9d3d99be2961f751e0fb21f665567c2 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Fri, 27 Sep 2024 14:48:47 +0200 Subject: [PATCH] Fix probable crash using icwmp cli --- src/autonomous_complpolicy.c | 40 +-- src/backupSession.c | 2 +- src/common.c | 121 +++++---- src/common.h | 4 +- src/config.c | 38 +-- src/cwmp.c | 53 ++-- src/cwmp_du_state.c | 16 +- src/cwmp_event.c | 24 +- src/cwmp_http.c | 12 +- src/datamodel_interface.c | 8 +- src/diagnostic.c | 22 +- src/download.c | 66 ++--- src/event.c | 32 +-- src/heartbeat.c | 46 ++-- src/http.c | 74 ++--- src/notifications.c | 45 ++-- src/notifications.h | 2 +- src/reboot.c | 18 +- src/rpc.c | 238 ++++++++--------- src/session.c | 213 ++++++++------- src/ssl_utils.c | 2 +- src/ubus_utils.c | 70 ++--- src/uci_utils.c | 252 +++++++++--------- src/upload.c | 12 +- src/xml.c | 66 ++--- test/cmocka/icwmp_backup_session_unit_test.c | 4 - test/cmocka/icwmp_cli_unit_test.c | 5 +- .../icwmp_datamodel_interface_unit_test.c | 2 - test/cmocka/icwmp_download_unit_test.c | 2 - test/cmocka/icwmp_notifications_unit_test.c | 5 +- test/cmocka/icwmp_soap_msg_unit_test.c | 163 ++++++----- 31 files changed, 828 insertions(+), 829 deletions(-) diff --git a/src/autonomous_complpolicy.c b/src/autonomous_complpolicy.c index 267278e..059ad04 100644 --- a/src/autonomous_complpolicy.c +++ b/src/autonomous_complpolicy.c @@ -37,18 +37,18 @@ static void free_autonomous_transfer_complete_data(auto_transfer_complete *p); static bool validate_du_state_change_data(auto_du_state_change_compl *data) { - if (data->fault_code && CWMP_STRCMP(cwmp_main->conf.auto_cdu_result_type, "Failure") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_cdu_result_type, "Both") != 0) + if (data->fault_code && CWMP_STRCMP(cwmp_ctx.conf.auto_cdu_result_type, "Failure") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_cdu_result_type, "Both") != 0) return false; - if (!data->fault_code && CWMP_STRCMP(cwmp_main->conf.auto_cdu_result_type, "Success") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_cdu_result_type, "Both") != 0) + if (!data->fault_code && CWMP_STRCMP(cwmp_ctx.conf.auto_cdu_result_type, "Success") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_cdu_result_type, "Both") != 0) return false; - if (data->operation && CWMP_STRSTR(cwmp_main->conf.auto_cdu_oprt_type, data->operation) == NULL) + if (data->operation && CWMP_STRSTR(cwmp_ctx.conf.auto_cdu_oprt_type, data->operation) == NULL) return false; char fault_code[5] = {0}; snprintf(fault_code, 4, "%d", data->fault_code); - if (CWMP_STRSTR(cwmp_main->conf.auto_cdu_fault_code, fault_code) == NULL) + if (CWMP_STRSTR(cwmp_ctx.conf.auto_cdu_fault_code, fault_code) == NULL) return false; return true; @@ -56,11 +56,11 @@ static bool validate_du_state_change_data(auto_du_state_change_compl *data) static void send_du_state_change_notif(struct blob_attr *msg) { - if (!cwmp_main->conf.auto_cdu_enable) { + if (!cwmp_ctx.conf.auto_cdu_enable) { CWMP_LOG(INFO, "Autonomous Change DU State is disabled"); return; } - if (strlen(cwmp_main->conf.auto_cdu_oprt_type) == 0) { + if (strlen(cwmp_ctx.conf.auto_cdu_oprt_type) == 0) { CWMP_LOG(INFO, "Autonomous Change DU State OperationTypeFilter is empty"); return; } @@ -155,11 +155,11 @@ static void send_du_state_change_notif(struct blob_attr *msg) free_autonomous_du_state_change_complete_data(data); return; } - if ((cwmp_main->auto_cdu_id < 0) || (cwmp_main->auto_cdu_id >= MAX_INT_ID)) { - cwmp_main->auto_cdu_id = 0; + if ((cwmp_ctx.auto_cdu_id < 0) || (cwmp_ctx.auto_cdu_id >= MAX_INT_ID)) { + cwmp_ctx.auto_cdu_id = 0; } - cwmp_main->auto_cdu_id++; - data->id = cwmp_main->auto_cdu_id; + cwmp_ctx.auto_cdu_id++; + data->id = cwmp_ctx.auto_cdu_id; bkp_session_insert_autonomous_du_state_change(data); bkp_session_save(); @@ -176,16 +176,16 @@ static void send_du_state_change_notif(struct blob_attr *msg) bool validate_transfer_complete_data(auto_transfer_complete *data) { - if (data->is_download && CWMP_STRCMP(cwmp_main->conf.auto_tc_transfer_type, "Download") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_tc_transfer_type, "Both") != 0) + if (data->is_download && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_transfer_type, "Download") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_transfer_type, "Both") != 0) return false; - if (!data->is_download && CWMP_STRCMP(cwmp_main->conf.auto_tc_transfer_type, "Upload") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_tc_transfer_type, "Both") != 0) + if (!data->is_download && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_transfer_type, "Upload") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_transfer_type, "Both") != 0) return false; - if (data->fault_code && CWMP_STRCMP(cwmp_main->conf.auto_tc_result_type, "Failure") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_tc_result_type, "Both") != 0) + if (data->fault_code && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_result_type, "Failure") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_result_type, "Both") != 0) return false; - if (!data->fault_code && CWMP_STRCMP(cwmp_main->conf.auto_tc_result_type, "Success") != 0 && CWMP_STRCMP(cwmp_main->conf.auto_tc_result_type, "Both") != 0) + if (!data->fault_code && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_result_type, "Success") != 0 && CWMP_STRCMP(cwmp_ctx.conf.auto_tc_result_type, "Both") != 0) return false; if (CWMP_STRLEN(data->file_type) == 0) @@ -197,7 +197,7 @@ bool validate_transfer_complete_data(auto_transfer_complete *data) static void send_transfer_complete_notif(struct blob_attr *msg) { - if (!cwmp_main->conf.auto_tc_enable) { + if (!cwmp_ctx.conf.auto_tc_enable) { CWMP_LOG(INFO, "Autonomous TransferComplete is disabled"); return; } @@ -239,7 +239,7 @@ static void send_transfer_complete_notif(struct blob_attr *msg) data->is_download = (tb1[1] && CWMP_STRCMP(blobmsg_get_string(tb1[1]), "Download") == 0) ? true : false; data->file_size = 0; data->target_file_name = strdup(""); - snprintf(file_type, sizeof(file_type), "X %s %s", cwmp_main->deviceid.oui, data->is_download ? "Download" : "Upload"); + snprintf(file_type, sizeof(file_type), "X %s %s", cwmp_ctx.deviceid.oui, data->is_download ? "Download" : "Upload"); data->file_type = strdup(file_type); if (tb1[2]) { @@ -264,11 +264,11 @@ static void send_transfer_complete_notif(struct blob_attr *msg) free_autonomous_transfer_complete_data(data); return; } - if ((cwmp_main->auto_tc_id < 0) || (cwmp_main->auto_tc_id >= MAX_INT_ID)) { - cwmp_main->auto_tc_id = 0; + if ((cwmp_ctx.auto_tc_id < 0) || (cwmp_ctx.auto_tc_id >= MAX_INT_ID)) { + cwmp_ctx.auto_tc_id = 0; } - cwmp_main->auto_tc_id++; - data->id = cwmp_main->auto_tc_id; + cwmp_ctx.auto_tc_id++; + data->id = cwmp_ctx.auto_tc_id; bkp_session_insert_autonomous_transfer_complete(data); bkp_session_save(); diff --git a/src/backupSession.c b/src/backupSession.c index 743ef46..1a07223 100644 --- a/src/backupSession.c +++ b/src/backupSession.c @@ -105,7 +105,7 @@ int bkp_session_check_file() int save_acs_bkp_config() { CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__); - bkp_session_simple_insert("acs", "URL", cwmp_main->conf.acs_url); + bkp_session_simple_insert("acs", "URL", cwmp_ctx.conf.acs_url); bkp_session_save(); CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__); return CWMP_OK; diff --git a/src/common.c b/src/common.c index cee17a9..1942f29 100755 --- a/src/common.c +++ b/src/common.c @@ -30,7 +30,7 @@ char *commandKey = NULL; bool cwmp_stop = false; unsigned int flashsize = 256000000; -struct cwmp *cwmp_main = NULL; +struct cwmp cwmp_ctx = {0}; struct session_timer_event *global_session_event = NULL; static LIST_HEAD(critical_service_list); @@ -121,27 +121,25 @@ int global_env_init(int argc, char **argv, struct env *env) env->periodic = CWMP_START_PERIODIC; break; case 'c': - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); - cwmp_main->conf.amd_version = DEFAULT_AMD_VERSION; + cwmp_ctx.conf.amd_version = DEFAULT_AMD_VERSION; get_uci_path_value(NULL, "cwmp.cpe.amd_version", value, BUF_SIZE_256); if (CWMP_STRLEN(value) != 0) { int a = (int)strtol(value, NULL, 10); - cwmp_main->conf.amd_version = (a >= 1 && a <= 6) ? a : DEFAULT_AMD_VERSION; + cwmp_ctx.conf.amd_version = (a >= 1 && a <= 6) ? a : DEFAULT_AMD_VERSION; } memset(value, 0, sizeof(value)); - cwmp_main->conf.instance_mode = DEFAULT_INSTANCE_MODE; + cwmp_ctx.conf.instance_mode = DEFAULT_INSTANCE_MODE; get_uci_path_value(NULL, "cwmp.cpe.instance_mode", value, BUF_SIZE_256); if (strlen(value) != 0) { if (CWMP_STRCMP(value, "InstanceNumber") == 0) { - cwmp_main->conf.instance_mode = INSTANCE_MODE_NUMBER; + cwmp_ctx.conf.instance_mode = INSTANCE_MODE_NUMBER; } else { - cwmp_main->conf.instance_mode = INSTANCE_MODE_ALIAS; + cwmp_ctx.conf.instance_mode = INSTANCE_MODE_ALIAS; } } execute_cwmp_cli_command(argv[2], argv + 3); - FREE(cwmp_main); icwmp_free_ubus(); exit(0); case 'h': @@ -155,6 +153,26 @@ int global_env_init(int argc, char **argv, struct env *env) /* * List dm_paramter */ +void add_dm_parameter_to_list_without_check(struct list_head *head, const char *param_name, const char *param_val, + const char *param_type, bool writable) +{ + struct cwmp_dm_parameter *dm_parameter = NULL; + + if (!head || !param_name) + return; + + dm_parameter = (struct cwmp_dm_parameter *)calloc(1, sizeof(struct cwmp_dm_parameter)); + if (!dm_parameter) + return; + + list_add_tail(&dm_parameter->list, head); + + dm_parameter->name = strdup(param_name); + dm_parameter->value = param_val ? strdup(param_val) : NULL; + dm_parameter->type = param_type ? strdup(param_type) : NULL; + dm_parameter->writable = writable; +} + void add_dm_parameter_to_list(struct list_head *head, const char *param_name, const char *param_val, const char *param_type, int notification, bool writable) { @@ -175,7 +193,10 @@ void add_dm_parameter_to_list(struct list_head *head, const char *param_name, co } } - dm_parameter = calloc(1, sizeof(struct cwmp_dm_parameter)); + dm_parameter = (struct cwmp_dm_parameter *)calloc(1, sizeof(struct cwmp_dm_parameter)); + if (!dm_parameter) + return; + list_add_tail(&dm_parameter->list, head); dm_parameter->name = strdup(param_name); @@ -250,7 +271,12 @@ void add_dm_alias_to_list(struct list_head *head, char *param, char *val, char * } } - dm_alias = calloc(1, sizeof(struct cwmp_dm_alias)); + dm_alias = (struct cwmp_dm_alias *)calloc(1, sizeof(struct cwmp_dm_alias)); + if (!dm_alias) { + FREE(s_path); + return; + } + list_add_tail(&dm_alias->list, head); dm_alias->org_name = strdup(s_path); @@ -273,39 +299,29 @@ void add_dm_alias_to_list(struct list_head *head, char *param, char *val, char * FREE(s_path); } -static void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter) -{ - list_del(&dm_parameter->list); - FREE(dm_parameter->name); - FREE(dm_parameter->value); - FREE(dm_parameter->type); - FREE(dm_parameter->access_list); - FREE(dm_parameter); -} - -static void delete_dm_alias_from_list(struct cwmp_dm_alias *dm_alias) -{ - list_del(&dm_alias->list); - FREE(dm_alias->org_name); - FREE(dm_alias->trs_name); - FREE(dm_alias); -} - void cwmp_free_all_dm_parameter_list(struct list_head *list) { - struct cwmp_dm_parameter *dm_parameter = NULL, *node; + struct cwmp_dm_parameter *dm_parameter = NULL, *node = NULL; list_for_each_entry_safe(dm_parameter, node, list, list) { - delete_dm_parameter_from_list(dm_parameter); + list_del(&dm_parameter->list); + FREE(dm_parameter->name); + FREE(dm_parameter->value); + FREE(dm_parameter->type); + FREE(dm_parameter->access_list); + FREE(dm_parameter); } } void cwmp_free_all_dm_alias_list(struct list_head *list) { - struct cwmp_dm_alias *dm_alias = NULL, *node; + struct cwmp_dm_alias *dm_alias = NULL, *node = NULL; list_for_each_entry_safe(dm_alias, node, list, list) { - delete_dm_alias_from_list(dm_alias); + list_del(&dm_alias->list); + FREE(dm_alias->org_name); + FREE(dm_alias->trs_name); + FREE(dm_alias); } } @@ -316,7 +332,10 @@ void cwmp_add_list_fault_param(char *param_name, char *fault_msg, int fault_code { struct cwmp_param_fault *param_fault = NULL; - param_fault = calloc(1, sizeof(struct cwmp_param_fault)); + param_fault = (struct cwmp_param_fault *)calloc(1, sizeof(struct cwmp_param_fault)); + if (!param_fault) + return; + list_add_tail(¶m_fault->list, list_set_value_fault); snprintf(param_fault->path_name, sizeof(param_fault->path_name), "%s", param_name ? param_name : ""); @@ -324,18 +343,13 @@ void cwmp_add_list_fault_param(char *param_name, char *fault_msg, int fault_code param_fault->fault_code = fault_code; } -static void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault) -{ - list_del(¶m_fault->list); - free(param_fault); -} - void cwmp_free_all_list_param_fault(struct list_head *list_param_fault) { - struct cwmp_param_fault *param_fault = NULL, *node; + struct cwmp_param_fault *param_fault = NULL, *node = NULL; list_for_each_entry_safe(param_fault, node, list_param_fault, list) { - cwmp_del_list_fault_param(param_fault); + list_del(¶m_fault->list); + free(param_fault); } } @@ -354,7 +368,11 @@ int icwmp_asprintf(char **s, const char *format, ...) va_end(arg); return -1; } - str = (char *)calloc(sizeof(char), size + 1); + + str = (char *)calloc(size + 1, sizeof(char)); + if (!str) + return -1; + vsnprintf(str, size + 1, format, arg); // Flawfinder: ignore va_end(arg); @@ -362,6 +380,7 @@ int icwmp_asprintf(char **s, const char *format, ...) FREE(str); if (*s == NULL) return -1; + return 0; } @@ -935,9 +954,9 @@ static void ubus_network_interface_callback(struct ubus_request *req __attribute if (!CWMP_STRLEN(l3_device)) return; - snprintf(cwmp_main->net.interface, sizeof(cwmp_main->net.interface), "%s", l3_device); + snprintf(cwmp_ctx.net.interface, sizeof(cwmp_ctx.net.interface), "%s", l3_device); - CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s && l3_name: %s", cwmp_main->conf.default_wan_iface, cwmp_main->net.interface); + CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s && l3_name: %s", cwmp_ctx.conf.default_wan_iface, cwmp_ctx.net.interface); } static bool is_ipv6_addr_available(const char *device) @@ -990,27 +1009,27 @@ static bool is_ipv6_addr_available(const char *device) bool is_ipv6_enabled(void) { - if (cwmp_main->conf.force_ipv4 == true) + if (cwmp_ctx.conf.force_ipv4 == true) return false; - if (CWMP_STRLEN(cwmp_main->net.interface) == 0) { + if (CWMP_STRLEN(cwmp_ctx.net.interface) == 0) { struct blob_buf b = {0}; char network_interface[64]; CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); blob_buf_init(&b, 0); - snprintf(network_interface, sizeof(network_interface), "network.interface.%s", cwmp_main->conf.default_wan_iface); + snprintf(network_interface, sizeof(network_interface), "network.interface.%s", cwmp_ctx.conf.default_wan_iface); int e = icwmp_ubus_invoke(network_interface, "status", b.head, ubus_network_interface_callback, NULL); blob_buf_free(&b); - if (e != 0 || CWMP_STRLEN(cwmp_main->net.interface) == 0) + if (e != 0 || CWMP_STRLEN(cwmp_ctx.net.interface) == 0) return false; } - if (!is_ipv6_addr_available(cwmp_main->net.interface)) + if (!is_ipv6_addr_available(cwmp_ctx.net.interface)) return false; return true; @@ -1019,8 +1038,8 @@ bool is_ipv6_enabled(void) bool is_ipv6_status_changed(void) { bool curr_ipv6_status = is_ipv6_enabled(); - bool ipv6_status_changed = (curr_ipv6_status != cwmp_main->net.ipv6_status); - cwmp_main->net.ipv6_status = curr_ipv6_status; + bool ipv6_status_changed = (curr_ipv6_status != cwmp_ctx.net.ipv6_status); + cwmp_ctx.net.ipv6_status = curr_ipv6_status; return ipv6_status_changed; } diff --git a/src/common.h b/src/common.h index 645aa95..b6e498c 100644 --- a/src/common.h +++ b/src/common.h @@ -629,12 +629,14 @@ typedef struct { char path[1024]; } path_list_t; -extern struct cwmp *cwmp_main; +extern struct cwmp cwmp_ctx; extern unsigned int flashsize; extern struct FAULT_CPE FAULT_CPE_ARRAY[]; extern struct cwmp_namespaces 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, + const char *param_type, bool writable); void add_dm_parameter_to_list(struct list_head *head, const char *param_name, const char *param_data, const char *param_type, int notification, bool writable); void add_dm_alias_to_list(struct list_head *head, char *param_name, char *param_data, char **l_param, char **l_trans); diff --git a/src/config.c b/src/config.c index 2b3e983..17abee9 100755 --- a/src/config.c +++ b/src/config.c @@ -29,11 +29,11 @@ static void set_cr_incoming_rule(const char *rule) { if (CWMP_LSTRCASECMP(rule, "ip_only") == 0) { - cwmp_main->cr_policy = CR_POLICY_IP_Only; + cwmp_ctx.cr_policy = CR_POLICY_IP_Only; } else if (CWMP_LSTRCASECMP(rule, "ip_port") == 0) { - cwmp_main->cr_policy = CR_POLICY_BOTH; + cwmp_ctx.cr_policy = CR_POLICY_BOTH; } else { - cwmp_main->cr_policy = CR_POLICY_Port_Only; // Default case + cwmp_ctx.cr_policy = CR_POLICY_Port_Only; // Default case } } @@ -59,25 +59,25 @@ int get_preinit_config() get_uci_path_value(NULL, UCI_CPE_ENABLE_SYSLOG, value, BUF_SIZE_256); log_set_on_syslog(value); - get_uci_path_value(NULL, UCI_CPE_DEFAULT_WAN_IFACE, cwmp_main->conf.default_wan_iface, BUF_SIZE_32); - if (CWMP_STRLEN(cwmp_main->conf.default_wan_iface) == 0) { - CWMP_STRNCMP(cwmp_main->conf.default_wan_iface, "wan", sizeof(cwmp_main->conf.default_wan_iface)); + get_uci_path_value(NULL, UCI_CPE_DEFAULT_WAN_IFACE, cwmp_ctx.conf.default_wan_iface, BUF_SIZE_32); + if (CWMP_STRLEN(cwmp_ctx.conf.default_wan_iface) == 0) { + CWMP_STRNCMP(cwmp_ctx.conf.default_wan_iface, "wan", sizeof(cwmp_ctx.conf.default_wan_iface)); } get_uci_path_value(NULL, UCI_CPE_INCOMING_RULE, value, BUF_SIZE_256); set_cr_incoming_rule(value); - cwmp_main->conf.amd_version = DEFAULT_AMD_VERSION; + cwmp_ctx.conf.amd_version = DEFAULT_AMD_VERSION; get_uci_path_value(NULL, UCI_CPE_AMD_VERSION, value, BUF_SIZE_256); if (CWMP_STRLEN(value) != 0) { int a = (int)strtol(value, NULL, 10); - cwmp_main->conf.amd_version = (a >= 1 && a <= 6) ? a : DEFAULT_AMD_VERSION; + cwmp_ctx.conf.amd_version = (a >= 1 && a <= 6) ? a : DEFAULT_AMD_VERSION; } - cwmp_main->conf.supported_amd_version = cwmp_main->conf.amd_version; + cwmp_ctx.conf.supported_amd_version = cwmp_ctx.conf.amd_version; - CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", cwmp_main->conf.default_wan_iface); - CWMP_LOG(DEBUG, "CWMP CONFIG - amendement version: %d", cwmp_main->conf.amd_version); + CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", cwmp_ctx.conf.default_wan_iface); + CWMP_LOG(DEBUG, "CWMP CONFIG - amendement version: %d", cwmp_ctx.conf.amd_version); return CWMP_OK; } @@ -100,14 +100,14 @@ void cwmp_config_load() if (cwmp_stop == true) return; - cwmp_main->net.ipv6_status = is_ipv6_enabled(); + cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); error = icwmp_check_http_connection(); while (error != CWMP_OK && cwmp_stop != true) { CWMP_LOG(DEBUG, "Init: failed to check http connection"); sleep(UCI_OPTION_READ_INTERVAL); global_conf_init(); - cwmp_main->net.ipv6_status = is_ipv6_enabled(); + cwmp_ctx.net.ipv6_status = is_ipv6_enabled(); error = icwmp_check_http_connection(); } } @@ -133,18 +133,18 @@ static void cwmp_get_device_info(const char *param, char *value, size_t size) { int cwmp_get_deviceid() { - cwmp_get_device_info("Device.DeviceInfo.Manufacturer", cwmp_main->deviceid.manufacturer, sizeof(cwmp_main->deviceid.manufacturer)); - cwmp_get_device_info("Device.DeviceInfo.SerialNumber", cwmp_main->deviceid.serialnumber, sizeof(cwmp_main->deviceid.serialnumber)); - cwmp_get_device_info("Device.DeviceInfo.ProductClass", cwmp_main->deviceid.productclass, sizeof(cwmp_main->deviceid.productclass)); - cwmp_get_device_info("Device.DeviceInfo.ManufacturerOUI", cwmp_main->deviceid.oui, sizeof(cwmp_main->deviceid.oui)); - cwmp_get_device_info("Device.DeviceInfo.SoftwareVersion", cwmp_main->deviceid.softwareversion, sizeof(cwmp_main->deviceid.softwareversion)); + cwmp_get_device_info("Device.DeviceInfo.Manufacturer", cwmp_ctx.deviceid.manufacturer, sizeof(cwmp_ctx.deviceid.manufacturer)); + cwmp_get_device_info("Device.DeviceInfo.SerialNumber", cwmp_ctx.deviceid.serialnumber, sizeof(cwmp_ctx.deviceid.serialnumber)); + cwmp_get_device_info("Device.DeviceInfo.ProductClass", cwmp_ctx.deviceid.productclass, sizeof(cwmp_ctx.deviceid.productclass)); + cwmp_get_device_info("Device.DeviceInfo.ManufacturerOUI", cwmp_ctx.deviceid.oui, sizeof(cwmp_ctx.deviceid.oui)); + cwmp_get_device_info("Device.DeviceInfo.SoftwareVersion", cwmp_ctx.deviceid.softwareversion, sizeof(cwmp_ctx.deviceid.softwareversion)); return CWMP_OK; } int cwmp_config_reload() { - CWMP_MEMSET(&cwmp_main->env, 0, sizeof(struct env)); + CWMP_MEMSET(&cwmp_ctx.env, 0, sizeof(struct env)); global_conf_init(); diff --git a/src/cwmp.c b/src/cwmp.c index 4baeefd..631d228 100644 --- a/src/cwmp.c +++ b/src/cwmp.c @@ -137,7 +137,7 @@ static void wait_for_time_sync(void) { struct cwmp_dm_parameter cwmp_dm_param = {0}; - int loop_count = (cwmp_main->conf.clock_sync_timeout / 2); + int loop_count = (cwmp_ctx.conf.clock_sync_timeout / 2); if (loop_count == 0) return; @@ -173,12 +173,8 @@ static int cwmp_init(void) { openlog("cwmp", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); - cwmp_main = (struct cwmp *)calloc(1, sizeof(struct cwmp)); - - CWMP_MEMSET(cwmp_main, 0, sizeof(struct cwmp)); - - cwmp_main->curr_delay_reboot = -1; - cwmp_main->curr_schedule_reboot = 0; + cwmp_ctx.curr_delay_reboot = -1; + cwmp_ctx.curr_schedule_reboot = 0; get_preinit_config(); @@ -189,9 +185,9 @@ static int cwmp_init(void) /* Only One instance should run*/ // cppcheck-suppress cert-MSC24-C - cwmp_main->pid_file = fopen("/var/run/icwmpd.pid", "w+"); - fcntl(fileno(cwmp_main->pid_file), F_SETFD, fcntl(fileno(cwmp_main->pid_file), F_GETFD) | FD_CLOEXEC); - int rc = flock(fileno(cwmp_main->pid_file), LOCK_EX | LOCK_NB); + cwmp_ctx.pid_file = fopen("/var/run/icwmpd.pid", "w+"); + fcntl(fileno(cwmp_ctx.pid_file), F_SETFD, fcntl(fileno(cwmp_ctx.pid_file), F_GETFD) | FD_CLOEXEC); + int rc = flock(fileno(cwmp_ctx.pid_file), LOCK_EX | LOCK_NB); if (rc) { if (EWOULDBLOCK != errno) { const char *piderr = "PID file creation failed: Quit the daemon!"; @@ -202,8 +198,8 @@ static int cwmp_init(void) exit(EXIT_SUCCESS); } - if (cwmp_main->pid_file) - fclose(cwmp_main->pid_file); + if (cwmp_ctx.pid_file) + fclose(cwmp_ctx.pid_file); CWMP_LOG(DEBUG, "Loading icwmpd configuration"); cwmp_config_load(); @@ -211,12 +207,12 @@ static int cwmp_init(void) wait_for_time_sync(); - cwmp_main->prev_periodic_enable = cwmp_main->conf.periodic_enable; - cwmp_main->prev_periodic_interval = cwmp_main->conf.period; - cwmp_main->prev_periodic_time = cwmp_main->conf.time; - cwmp_main->prev_heartbeat_enable = cwmp_main->conf.heart_beat_enable; - cwmp_main->prev_heartbeat_interval = cwmp_main->conf.heartbeat_interval; - cwmp_main->prev_heartbeat_time = cwmp_main->conf.heart_time; + cwmp_ctx.prev_periodic_enable = cwmp_ctx.conf.periodic_enable; + cwmp_ctx.prev_periodic_interval = cwmp_ctx.conf.period; + cwmp_ctx.prev_periodic_time = cwmp_ctx.conf.time; + cwmp_ctx.prev_heartbeat_enable = cwmp_ctx.conf.heart_beat_enable; + cwmp_ctx.prev_heartbeat_interval = cwmp_ctx.conf.heartbeat_interval; + cwmp_ctx.prev_heartbeat_time = cwmp_ctx.conf.heart_time; if (cwmp_stop == true) return CWMP_GEN_ERR; @@ -243,7 +239,7 @@ static int cwmp_init(void) CWMP_MEMSET(&du_uuid_list, 0, sizeof(struct list_head)); INIT_LIST_HEAD(&du_uuid_list); - cwmp_main->start_time = time(NULL); + cwmp_ctx.start_time = time(NULL); return CWMP_OK; } @@ -259,7 +255,6 @@ static void cwmp_free() rpc_exit(); clean_cwmp_session_structure(); icwmp_free_critical_services(); - FREE(cwmp_main); CWMP_LOG(INFO, "EXIT ICWMP"); closelog(); } @@ -268,7 +263,7 @@ void cwmp_exit() { cwmp_stop = true; - if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) + if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) http_set_timeout(); uloop_timeout_cancel(&retry_session_timer); @@ -279,10 +274,10 @@ void cwmp_exit() clean_interface_update(); clean_du_uuid_list(); clean_force_inform_list(); - FREE(cwmp_main->ev); - FREE(cwmp_main->intf_ev); + FREE(cwmp_ctx.ev); + FREE(cwmp_ctx.intf_ev); uloop_end(); - shutdown(cwmp_main->cr_socket_desc, SHUT_RDWR); + shutdown(cwmp_ctx.cr_socket_desc, SHUT_RDWR); FREE(global_session_event); /* Free all memory allocation */ @@ -291,8 +286,9 @@ void cwmp_exit() int main(int argc, char **argv) { - int error; - struct env env; + int error = 0; + + CWMP_MEMSET(&cwmp_ctx, 0, sizeof(struct cwmp)); error = icwmp_connect_ubus(); if (error) @@ -304,8 +300,7 @@ int main(int argc, char **argv) return error; } - CWMP_MEMSET(&env, 0, sizeof(struct env)); - if ((error = global_env_init(argc, argv, &env))) { + if ((error = global_env_init(argc, argv, &(cwmp_ctx.env)))) { icwmp_free_ubus(); return error; } @@ -320,8 +315,6 @@ int main(int argc, char **argv) return error; } - CWMP_MEMCPY(&(cwmp_main->env), &env, sizeof(struct env)); - if ((error = cwmp_init_backup_session(NULL, ALL))) { icwmp_free_ubus(); return error; diff --git a/src/cwmp_du_state.c b/src/cwmp_du_state.c index b60e862..752cfe4 100644 --- a/src/cwmp_du_state.c +++ b/src/cwmp_du_state.c @@ -462,11 +462,11 @@ int change_du_state_fault(struct change_du_state *pchange_du_state, struct du_st res->fault = error; res->fault_msg = strdup("Timeout expired"); } - if ((cwmp_main->cdu_complete_id < 0) || (cwmp_main->cdu_complete_id >= MAX_INT_ID)) { - cwmp_main->cdu_complete_id = 0; + if ((cwmp_ctx.cdu_complete_id < 0) || (cwmp_ctx.cdu_complete_id >= MAX_INT_ID)) { + cwmp_ctx.cdu_complete_id = 0; } - cwmp_main->cdu_complete_id++; - (*pdu_state_change_complete)->id = cwmp_main->cdu_complete_id; + cwmp_ctx.cdu_complete_id++; + (*pdu_state_change_complete)->id = cwmp_ctx.cdu_complete_id; bkp_session_insert_du_state_change_complete(*pdu_state_change_complete); bkp_session_save(); //cwmp_root_cause_changedustate_complete(*pdu_state_change_complete); @@ -688,11 +688,11 @@ void change_du_state_execute(struct uloop_timeout *utimeout) } bkp_session_delete_element("change_du_state", pchange_du_state->id); bkp_session_save(); - if ((cwmp_main->cdu_complete_id < 0) || (cwmp_main->cdu_complete_id >= MAX_INT_ID)) { - cwmp_main->cdu_complete_id = 0; + if ((cwmp_ctx.cdu_complete_id < 0) || (cwmp_ctx.cdu_complete_id >= MAX_INT_ID)) { + cwmp_ctx.cdu_complete_id = 0; } - cwmp_main->cdu_complete_id++; - pdu_state_change_complete->id = cwmp_main->cdu_complete_id; + cwmp_ctx.cdu_complete_id++; + pdu_state_change_complete->id = cwmp_ctx.cdu_complete_id; bkp_session_insert_du_state_change_complete(pdu_state_change_complete); bkp_session_save(); //cwmp_root_cause_changedustate_complete(pdu_state_change_complete); diff --git a/src/cwmp_event.c b/src/cwmp_event.c index e4387ec..be00c5d 100644 --- a/src/cwmp_event.c +++ b/src/cwmp_event.c @@ -17,7 +17,7 @@ static struct event_container *__cwmp_add_event_container(int event_code, const char *command_key) { struct event_container *event_container = NULL; - list_for_each_entry(event_container, &cwmp_main->session->events, list) { + list_for_each_entry(event_container, &cwmp_ctx.session->events, list) { if (event_container->code == event_code) { return event_container; } @@ -30,15 +30,15 @@ static struct event_container *__cwmp_add_event_container(int event_code, const return NULL; } INIT_LIST_HEAD(&(event_container->head_dm_parameter)); - list_add_tail(&(event_container->list), &(cwmp_main->session->events)); + list_add_tail(&(event_container->list), &(cwmp_ctx.session->events)); event_container->code = event_code; event_container->command_key = command_key ? strdup(command_key) : strdup(""); event_container->next_session = true; - if ((cwmp_main->event_id < 0) || (cwmp_main->event_id >= MAX_INT_ID)) { - cwmp_main->event_id = 0; + if ((cwmp_ctx.event_id < 0) || (cwmp_ctx.event_id >= MAX_INT_ID)) { + cwmp_ctx.event_id = 0; } - cwmp_main->event_id++; - event_container->id = cwmp_main->event_id; + cwmp_ctx.event_id++; + event_container->id = cwmp_ctx.event_id; return event_container; } @@ -52,7 +52,7 @@ void move_next_session_events_to_actual_session() { struct event_container *event_container; - struct list_head *event_container_list = &(cwmp_main->session->events); + struct list_head *event_container_list = &(cwmp_ctx.session->events); list_for_each_entry (event_container, event_container_list, list) { event_container->next_session = false; } @@ -61,8 +61,8 @@ void move_next_session_events_to_actual_session() int cwmp_remove_all_session_events() { CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__); - struct list_head *events_ptr = cwmp_main->session->events.next; - while (events_ptr != &cwmp_main->session->events) { + struct list_head *events_ptr = cwmp_ctx.session->events.next; + while (events_ptr != &cwmp_ctx.session->events) { struct event_container *event_container; event_container = list_entry(events_ptr, struct event_container, list); if (event_container->code == EVENT_IDX_14HEARTBEAT || event_container->next_session) { @@ -74,7 +74,7 @@ int cwmp_remove_all_session_events() cwmp_free_all_dm_parameter_list(&(event_container->head_dm_parameter)); list_del(&(event_container->list)); free(event_container); - events_ptr = cwmp_main->session->events.next; + events_ptr = cwmp_ctx.session->events.next; } bkp_session_save(); CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__); @@ -84,9 +84,9 @@ int cwmp_remove_all_session_events() int remove_single_event(int event_code) { CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__); - while (cwmp_main->session->events.next != &cwmp_main->session->events) { + while (cwmp_ctx.session->events.next != &cwmp_ctx.session->events) { struct event_container *event_container; - event_container = list_entry(cwmp_main->session->events.next, struct event_container, list); + event_container = list_entry(cwmp_ctx.session->events.next, struct event_container, list); if (event_container->next_session) continue; if (event_container->code == event_code) { diff --git a/src/cwmp_http.c b/src/cwmp_http.c index 52c91b6..05904b0 100644 --- a/src/cwmp_http.c +++ b/src/cwmp_http.c @@ -27,7 +27,7 @@ void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsi void http_server_start_uloop(void) { icwmp_http_server_init(); - http_event6.fd = cwmp_main->cr_socket_desc; + http_event6.fd = cwmp_ctx.cr_socket_desc; http_event6.cb = http_server_listen_uloop; uloop_fd_add(&http_event6, ULOOP_READ | ULOOP_EDGE_TRIGGER); } @@ -53,13 +53,13 @@ void http_server_stop(void) static void set_http_ip_resolve(long ip_resolve) { - cwmp_main->net.ip_resolve = ip_resolve; + cwmp_ctx.net.ip_resolve = ip_resolve; set_uci_path_value(VARSTATE_CONFIG, "icwmp.acs.ip_version", (ip_resolve == CURL_IPRESOLVE_V6) ? "6" : "4"); } int icwmp_check_http_connection(void) { - if (!cwmp_main->net.ipv6_status) { + if (!cwmp_ctx.net.ipv6_status) { set_http_ip_resolve(CURL_IPRESOLVE_V4); return CWMP_OK; } @@ -70,13 +70,13 @@ int icwmp_check_http_connection(void) if(c) { CURLcode ret; curl_easy_setopt(c, CURLOPT_FAILONERROR, true); - curl_easy_setopt(c, CURLOPT_URL, cwmp_main->conf.acs_url); + curl_easy_setopt(c, CURLOPT_URL, cwmp_ctx.conf.acs_url); curl_easy_setopt(c, CURLOPT_CONNECT_ONLY, 1L); curl_easy_setopt(c, CURLOPT_IPRESOLVE, resolve); curl_easy_setopt(c, CURLOPT_TIMEOUT, 2); - if (cwmp_main->net.use_curl_ifname && CWMP_STRLEN(cwmp_main->net.interface)) - curl_easy_setopt(c, CURLOPT_INTERFACE, cwmp_main->net.interface); + if (cwmp_ctx.net.use_curl_ifname && CWMP_STRLEN(cwmp_ctx.net.interface)) + curl_easy_setopt(c, CURLOPT_INTERFACE, cwmp_ctx.net.interface); ret = curl_easy_perform(c); if(ret == CURLE_OK) { diff --git a/src/datamodel_interface.c b/src/datamodel_interface.c index 7508b6c..8b42bb5 100755 --- a/src/datamodel_interface.c +++ b/src/datamodel_interface.c @@ -59,8 +59,8 @@ static int get_instance_mode(void) { int mode = INSTANCE_MODE_NUMBER; - if (cwmp_main->conf.amd_version >= 5) - mode = cwmp_main->conf.instance_mode; + if (cwmp_ctx.conf.amd_version >= 5) + mode = cwmp_ctx.conf.instance_mode; return mode; } @@ -187,7 +187,7 @@ static void ubus_get_parameter_callback(struct ubus_request *req, int type __att char *param_type = tb[2] ? blobmsg_get_string(tb[2]) : ""; bool writable = strcmp(param_value, "1") == 0 ? true : false; - add_dm_parameter_to_list(result->parameters_list, param_name, param_value, param_type, 0, writable); + add_dm_parameter_to_list_without_check(result->parameters_list, param_name, param_value, param_type, writable); if (inst_mode == INSTANCE_MODE_ALIAS) { /* in GPN alias values comes in tb[4] i.e the output field */ @@ -333,7 +333,7 @@ int instantiate_param_name(const char *param, char **inst_path) return CWMP_OK; /* Alias mode not supported */ - if (cwmp_main->conf.amd_version < 5 && CWMP_STRSTR(param, "[") != NULL) + if (cwmp_ctx.conf.amd_version < 5 && CWMP_STRSTR(param, "[") != NULL) return CWMP_GEN_ERR; snprintf(orig_path, sizeof(orig_path), "%s", param); diff --git a/src/diagnostic.c b/src/diagnostic.c index 01b1beb..2d84e15 100644 --- a/src/diagnostic.c +++ b/src/diagnostic.c @@ -291,7 +291,7 @@ int cwmp_wifi_neighboring__diagnostics(void) return -1; CWMP_LOG(INFO, "WiFi neighboring diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -301,7 +301,7 @@ int cwmp_packet_capture_diagnostics(void) return -1; CWMP_LOG(INFO, "packet capture diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -311,7 +311,7 @@ int cwmp_selftest_diagnostics(void) return -1; CWMP_LOG(INFO, "self test diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -321,7 +321,7 @@ int cwmp_ip_layer_capacity_diagnostics(void) return -1; CWMP_LOG(INFO, "IP layer capacity diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -331,7 +331,7 @@ int cwmp_download_diagnostics(void) return -1; CWMP_LOG(INFO, "Download diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -341,7 +341,7 @@ int cwmp_upload_diagnostics(void) return -1; CWMP_LOG(INFO, "Upload diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -351,7 +351,7 @@ int cwmp_ip_ping_diagnostics(void) return -1; CWMP_LOG(INFO, "IPPing diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -361,7 +361,7 @@ int cwmp_nslookup_diagnostics(void) return -1; CWMP_LOG(INFO, "Nslookup diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -371,7 +371,7 @@ int cwmp_traceroute_diagnostics(void) return -1; CWMP_LOG(INFO, "Trace Route diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -381,7 +381,7 @@ int cwmp_udp_echo_diagnostics(void) return -1; CWMP_LOG(INFO, "UDPEcho diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } @@ -391,6 +391,6 @@ int cwmp_serverselection_diagnostics(void) return -1; CWMP_LOG(INFO, "Server Selection diagnostic is successfully executed"); - cwmp_main->diag_session = true; + cwmp_ctx.diag_session = true; return 0; } diff --git a/src/download.c b/src/download.c index 062e098..7c48676 100644 --- a/src/download.c +++ b/src/download.c @@ -138,8 +138,8 @@ int download_file_in_subprocess(const char *file_path, const char *url, const ch blobmsg_add_string(&bbuf, "username", username ? username : ""); blobmsg_add_string(&bbuf, "password", password ? password : ""); - if (cwmp_main->net.use_curl_ifname && CWMP_STRLEN(cwmp_main->net.interface)) - blobmsg_add_string(&bbuf, "interface", cwmp_main->net.interface); + if (cwmp_ctx.net.use_curl_ifname && CWMP_STRLEN(cwmp_ctx.net.interface)) + blobmsg_add_string(&bbuf, "interface", cwmp_ctx.net.interface); char *download_task = blobmsg_format_json(bbuf.head, true); blob_buf_free(&bbuf); @@ -326,7 +326,7 @@ int cwmp_apply_firmware() struct blob_buf b = { 0 }; CWMP_MEMSET(&b, 0, sizeof(struct blob_buf)); blob_buf_init(&b, 0); - blobmsg_add_u8(&b, "keep", cwmp_main->conf.fw_upgrade_keep_settings); + blobmsg_add_u8(&b, "keep", cwmp_ctx.conf.fw_upgrade_keep_settings); CWMP_LOG(INFO, "Apply downloaded image ..."); e = icwmp_ubus_invoke("rpc-sys", "upgrade_start", b.head, NULL, NULL); @@ -414,7 +414,7 @@ int cwmp_apply_multiple_firmware() bb_add_string(&b, "path", FIRMWARE_UPGRADE_IMAGE); blobmsg_add_u8(&b, "auto_activate", false); blobmsg_add_u32(&b, "bank", bank_id); - blobmsg_add_u8(&b, "keep_settings", cwmp_main->conf.fw_upgrade_keep_settings); + blobmsg_add_u8(&b, "keep_settings", cwmp_ctx.conf.fw_upgrade_keep_settings); e = icwmp_ubus_invoke("fwbank", "upgrade", b.head, NULL, NULL); blob_buf_free(&b); @@ -578,14 +578,14 @@ int apply_downloaded_file(struct download *pdownload, char *download_file_name, char err_msg[256] = {0}; if (pdownload->file_type[0] == '1') { - ptransfer_complete->old_software_version = cwmp_main->deviceid.softwareversion; + ptransfer_complete->old_software_version = cwmp_ctx.deviceid.softwareversion; } if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); @@ -683,11 +683,11 @@ int apply_downloaded_file(struct download *pdownload, char *download_file_name, ptransfer_complete->fault_code = error; } if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } ptransfer_complete->fault_string = strdup(err_msg); @@ -711,11 +711,11 @@ struct transfer_complete *set_download_error_transfer_complete(struct download * ptransfer_complete->fault_code = ltype == TYPE_DOWNLOAD ? FAULT_CPE_DOWNLOAD_FAILURE : FAULT_CPE_DOWNLOAD_FAIL_WITHIN_TIME_WINDOW; ptransfer_complete->type = ltype; if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); cwmp_root_cause_transfer_complete(ptransfer_complete); @@ -838,11 +838,11 @@ void cwmp_start_download(struct uloop_timeout *timeout) if (error != FAULT_CPE_NO_FAULT) { CWMP_LOG(ERROR, "Error while downloading the file: %s", pdownload->url); if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); @@ -853,11 +853,11 @@ void cwmp_start_download(struct uloop_timeout *timeout) if (error != FAULT_CPE_NO_FAULT) { CWMP_LOG(ERROR, "Error while applying the downloaded file: %s", download_file_name); if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); @@ -964,11 +964,11 @@ void cwmp_start_schedule_download(struct uloop_timeout *timeout) ptransfer_complete->type = TYPE_DOWNLOAD; ptransfer_complete->fault_code = FAULT_CPE_INTERNAL_ERROR; if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); @@ -985,11 +985,11 @@ retry: return; } else { if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); diff --git a/src/event.c b/src/event.c index 56eff4f..4edcc30 100644 --- a/src/event.c +++ b/src/event.c @@ -71,9 +71,9 @@ void cwmp_save_event_container(struct event_container *event_container) static int cwmp_root_cause_event_boot(void) { - if (cwmp_main->env.boot == CWMP_START_BOOT) { + if (cwmp_ctx.env.boot == CWMP_START_BOOT) { struct event_container *event_container; - cwmp_main->env.boot = 0; + cwmp_ctx.env.boot = 0; event_container = cwmp_add_event_container(EVENT_IDX_1BOOT, ""); if (event_container == NULL) { @@ -90,12 +90,12 @@ int event_remove_noretry_event_container() { struct list_head *ilist, *q; - list_for_each_safe (ilist, q, &(cwmp_main->session->events)) { + list_for_each_safe (ilist, q, &(cwmp_ctx.session->events)) { struct event_container *event_container; event_container = list_entry(ilist, struct event_container, list); if (EVENT_CONST[event_container->code].CODE[0] == '6') - cwmp_main->cwmp_cr_event = 1; + cwmp_ctx.cwmp_cr_event = 1; if (EVENT_CONST[event_container->code].RETRY == 0) { if (event_container->command_key) @@ -114,7 +114,7 @@ static int cwmp_root_cause_event_bootstrap(void) cwmp_load_saved_session(&acsurl, ACS); - if (acsurl == NULL || CWMP_STRCMP(cwmp_main->conf.acs_url, acsurl) != 0) { + if (acsurl == NULL || CWMP_STRCMP(cwmp_ctx.conf.acs_url, acsurl) != 0) { struct event_container *event_container; event_container = cwmp_add_event_container(EVENT_IDX_0BOOTSTRAP, ""); if (event_container == NULL) { @@ -261,16 +261,16 @@ int cwmp_root_cause_schedule_inform(struct schedule_inform *schedule_inform) static int cwmp_root_cause_get_rpc_method(void ) { - if (cwmp_main->env.periodic == CWMP_START_PERIODIC) { + if (cwmp_ctx.env.periodic == CWMP_START_PERIODIC) { struct event_container *event_container; - cwmp_main->env.periodic = 0; + cwmp_ctx.env.periodic = 0; event_container = cwmp_add_event_container(EVENT_IDX_2PERIODIC, ""); if (event_container == NULL) return CWMP_MEM_ERR; cwmp_save_event_container(event_container); - if (cwmp_main->conf.acs_getrpc && cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL) + if (cwmp_ctx.conf.acs_getrpc && cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL) return CWMP_MEM_ERR; } @@ -280,7 +280,7 @@ static int cwmp_root_cause_get_rpc_method(void ) bool event_exist_in_list(int event) { struct event_container *event_container = NULL; - list_for_each_entry (event_container, &cwmp_main->session->events, list) { + list_for_each_entry (event_container, &cwmp_ctx.session->events, list) { if (event_container->code == event) return true; } @@ -292,15 +292,15 @@ static int cwmp_root_cause_event_periodic(void) char local_time[27] = { 0 }; struct tm *t_tm; - if (cwmp_main->cwmp_period == cwmp_main->conf.period && cwmp_main->cwmp_periodic_enable == cwmp_main->conf.periodic_enable && cwmp_main->cwmp_periodic_time == cwmp_main->conf.time) + if (cwmp_ctx.cwmp_period == cwmp_ctx.conf.period && cwmp_ctx.cwmp_periodic_enable == cwmp_ctx.conf.periodic_enable && cwmp_ctx.cwmp_periodic_time == cwmp_ctx.conf.time) return CWMP_OK; - cwmp_main->cwmp_period = cwmp_main->conf.period; - cwmp_main->cwmp_periodic_enable = cwmp_main->conf.periodic_enable; - cwmp_main->cwmp_periodic_time = cwmp_main->conf.time; - CWMP_LOG(INFO, cwmp_main->cwmp_periodic_enable ? "Periodic event is enabled. Interval period = %ds" : "Periodic event is disabled", cwmp_main->cwmp_period); + cwmp_ctx.cwmp_period = cwmp_ctx.conf.period; + cwmp_ctx.cwmp_periodic_enable = cwmp_ctx.conf.periodic_enable; + cwmp_ctx.cwmp_periodic_time = cwmp_ctx.conf.time; + CWMP_LOG(INFO, cwmp_ctx.cwmp_periodic_enable ? "Periodic event is enabled. Interval period = %ds" : "Periodic event is disabled", cwmp_ctx.cwmp_period); - t_tm = localtime(&cwmp_main->cwmp_periodic_time); + t_tm = localtime(&cwmp_ctx.cwmp_periodic_time); if (t_tm == NULL) return CWMP_GEN_ERR; @@ -312,7 +312,7 @@ static int cwmp_root_cause_event_periodic(void) local_time[22] = ':'; local_time[26] = '\0'; - CWMP_LOG(INFO, cwmp_main->cwmp_periodic_time ? "Periodic time is %s" : "Periodic time is Unknown", local_time); + CWMP_LOG(INFO, cwmp_ctx.cwmp_periodic_time ? "Periodic time is %s" : "Periodic time is Unknown", local_time); return CWMP_OK; } diff --git a/src/heartbeat.c b/src/heartbeat.c index 7f1710d..afe54af 100644 --- a/src/heartbeat.c +++ b/src/heartbeat.c @@ -31,7 +31,7 @@ long int cwmp_heartbeat_session_time(void) long int heartbeat_report; time_t now = time(NULL); struct tm *now_tm = gmtime((const time_t *)&now); - struct tm *heart_time = gmtime((const time_t *)&cwmp_main->conf.heart_time); + struct tm *heart_time = gmtime((const time_t *)&cwmp_ctx.conf.heart_time); struct tm heart_init_tm = {.tm_year = now_tm->tm_year, .tm_mon = now_tm->tm_mon, .tm_mday = now_tm->tm_mday, .tm_hour = heart_time->tm_hour, .tm_min = heart_time->tm_min, .tm_sec = heart_time->tm_sec}; time_t heart_init_time = mktime(&heart_init_tm); if (heart_init_time - mktime(now_tm) < 0) { @@ -46,19 +46,19 @@ long int cwmp_heartbeat_session_time(void) void cwmp_heartbeat_session_timer(struct uloop_timeout *timeout __attribute__((unused))) { - if (cwmp_main->conf.heart_beat_enable) { + if (cwmp_ctx.conf.heart_beat_enable) { //HEARTBEAT event must wait a Non-HEARTBEAT Inform is being retried to be completed - if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) { - cwmp_main->session->session_status.next_heartbeat = true; - cwmp_main->session->session_status.is_heartbeat = false; + if (cwmp_ctx.session->session_status.last_status == SESSION_FAILURE) { + cwmp_ctx.session->session_status.next_heartbeat = true; + cwmp_ctx.session->session_status.is_heartbeat = false; return; } //struct session_timer_event *heartbeat_inform_event = calloc(1, sizeof(struct session_timer_event)); - uloop_timeout_set(&heartbeat_session_timer, cwmp_main->conf.heartbeat_interval * 1000); + uloop_timeout_set(&heartbeat_session_timer, cwmp_ctx.conf.heartbeat_interval * 1000); - cwmp_main->session->session_status.next_heartbeat = false; - cwmp_main->session->session_status.is_heartbeat = true; + cwmp_ctx.session->session_status.next_heartbeat = false; + cwmp_ctx.session->session_status.is_heartbeat = true; cwmp_add_event_container(EVENT_IDX_14HEARTBEAT, ""); start_cwmp_session(); } @@ -67,11 +67,11 @@ void cwmp_heartbeat_session_timer(struct uloop_timeout *timeout __attribute__(( void intiate_heartbeat_procedures() { uloop_timeout_cancel(&heartbeat_session_timer); - if (cwmp_main->conf.heart_beat_enable) { - if (cwmp_main->conf.heart_time == 0) { - uloop_timeout_set(&heartbeat_session_timer, cwmp_main->conf.heartbeat_interval * 1000); + if (cwmp_ctx.conf.heart_beat_enable) { + if (cwmp_ctx.conf.heart_time == 0) { + uloop_timeout_set(&heartbeat_session_timer, cwmp_ctx.conf.heartbeat_interval * 1000); } else { - time_t hearttime_interval = cwmp_main->conf.heart_time - time(NULL); + time_t hearttime_interval = cwmp_ctx.conf.heart_time - time(NULL); if (hearttime_interval >= 0) { uloop_timeout_set(&heartbeat_session_timer, hearttime_interval * 1000); } else { @@ -83,22 +83,22 @@ void intiate_heartbeat_procedures() void reinit_heartbeat_procedures() { - if (cwmp_main->conf.heart_beat_enable) { - if (!cwmp_main->prev_heartbeat_enable || (cwmp_main->prev_heartbeat_interval != cwmp_main->conf.heartbeat_interval) || (cwmp_main->prev_heartbeat_time != cwmp_main->conf.heart_time)) { - cwmp_main->heart_session = true; - if ((cwmp_main->prev_heartbeat_time != cwmp_main->conf.heart_time) && cwmp_main->conf.heart_time != 0) { - time_t hearttime_interval = cwmp_main->conf.heart_time - time(NULL); + if (cwmp_ctx.conf.heart_beat_enable) { + if (!cwmp_ctx.prev_heartbeat_enable || (cwmp_ctx.prev_heartbeat_interval != cwmp_ctx.conf.heartbeat_interval) || (cwmp_ctx.prev_heartbeat_time != cwmp_ctx.conf.heart_time)) { + cwmp_ctx.heart_session = true; + if ((cwmp_ctx.prev_heartbeat_time != cwmp_ctx.conf.heart_time) && cwmp_ctx.conf.heart_time != 0) { + time_t hearttime_interval = cwmp_ctx.conf.heart_time - time(NULL); if (hearttime_interval >= 0) - cwmp_main->heart_session_interval = hearttime_interval; + cwmp_ctx.heart_session_interval = hearttime_interval; else - cwmp_main->heart_session_interval = cwmp_heartbeat_session_time(); + cwmp_ctx.heart_session_interval = cwmp_heartbeat_session_time(); } else - cwmp_main->heart_session_interval = cwmp_main->conf.heartbeat_interval; + cwmp_ctx.heart_session_interval = cwmp_ctx.conf.heartbeat_interval; } } else uloop_timeout_cancel(&heartbeat_session_timer); - cwmp_main->prev_heartbeat_enable = cwmp_main->conf.heart_beat_enable; - cwmp_main->prev_heartbeat_interval = cwmp_main->conf.heartbeat_interval; - cwmp_main->prev_heartbeat_time = cwmp_main->conf.heart_time; + cwmp_ctx.prev_heartbeat_enable = cwmp_ctx.conf.heart_beat_enable; + cwmp_ctx.prev_heartbeat_interval = cwmp_ctx.conf.heartbeat_interval; + cwmp_ctx.prev_heartbeat_time = cwmp_ctx.conf.heart_time; } diff --git a/src/http.c b/src/http.c index f4be889..c18437e 100644 --- a/src/http.c +++ b/src/http.c @@ -43,10 +43,10 @@ void http_set_timeout(void) int icwmp_http_client_init() { - if (CWMP_STRLEN(cwmp_main->conf.acs_url) == 0) + if (CWMP_STRLEN(cwmp_ctx.conf.acs_url) == 0) return -1; - CWMP_LOG(INFO, "ACS url: %s", cwmp_main->conf.acs_url); + CWMP_LOG(INFO, "ACS url: %s", cwmp_ctx.conf.acs_url); curl_global_init(CURL_GLOBAL_SSL); curl_glob_init = true; @@ -103,17 +103,17 @@ static size_t http_get_response(void *buffer, size_t size, size_t rxed, void *us static void http_set_security_options() { - curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp_main->conf.acs_userid); - curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp_main->conf.acs_passwd); + curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp_ctx.conf.acs_userid); + curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp_ctx.conf.acs_passwd); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); - if (CWMP_STRLEN(cwmp_main->conf.acs_ssl_capath) !=0 ) { - curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp_main->conf.acs_ssl_capath); - } else if (CWMP_STRLEN(cwmp_main->conf.acs_ssl_cabundle) != 0) { - curl_easy_setopt(curl, CURLOPT_CAINFO, cwmp_main->conf.acs_ssl_cabundle); + if (CWMP_STRLEN(cwmp_ctx.conf.acs_ssl_capath) !=0 ) { + curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp_ctx.conf.acs_ssl_capath); + } else if (CWMP_STRLEN(cwmp_ctx.conf.acs_ssl_cabundle) != 0) { + curl_easy_setopt(curl, CURLOPT_CAINFO, cwmp_ctx.conf.acs_ssl_cabundle); } - if (cwmp_main->conf.insecure_enable) { + if (cwmp_ctx.conf.insecure_enable) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); } @@ -121,7 +121,7 @@ static void http_set_security_options() static void http_set_connection_options() { - curl_easy_setopt(curl, CURLOPT_URL, cwmp_main->conf.acs_url); + curl_easy_setopt(curl, CURLOPT_URL, cwmp_ctx.conf.acs_url); curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT); @@ -130,11 +130,11 @@ static void http_set_connection_options() curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_NOBODY, 0); - curl_easy_setopt(curl, CURLOPT_IPRESOLVE, cwmp_main->net.ip_resolve); + curl_easy_setopt(curl, CURLOPT_IPRESOLVE, cwmp_ctx.net.ip_resolve); - if (cwmp_main->net.use_curl_ifname && CWMP_STRLEN(cwmp_main->net.interface)) - curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp_main->net.interface); + if (cwmp_ctx.net.use_curl_ifname && CWMP_STRLEN(cwmp_ctx.net.interface)) + curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp_ctx.net.interface); } static bool valid_cookie_path(const char *cookie) @@ -232,7 +232,7 @@ static void http_filter_valid_cookie() static void http_set_header_list_options() { - switch (cwmp_main->conf.compression) { + switch (cwmp_ctx.conf.compression) { case COMP_NONE: break; case COMP_GZIP: @@ -277,7 +277,7 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in) if (!header_list) return -1; - if (cwmp_main->conf.http_disable_100continue) { + if (cwmp_ctx.conf.http_disable_100continue) { header_list = curl_slist_append(header_list, "Expect:"); if (!header_list) return -1; @@ -311,8 +311,8 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in) curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip); if (CWMP_STRLEN(ip)) { - if (cwmp_main->ip_acs[0] == '\0' || strcmp(cwmp_main->ip_acs, ip) != 0) { - CWMP_STRNCPY(cwmp_main->ip_acs, ip, sizeof(cwmp_main->ip_acs)); + if (cwmp_ctx.ip_acs[0] == '\0' || strcmp(cwmp_ctx.ip_acs, ip) != 0) { + CWMP_STRNCPY(cwmp_ctx.ip_acs, ip, sizeof(cwmp_ctx.ip_acs)); tmp = inet_pton(AF_INET, ip, buf); if (tmp == 1) { tmp = 0; @@ -321,13 +321,13 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in) } if (tmp) { - set_uci_path_value(VARSTATE_CONFIG, "icwmp.acs.ip6", cwmp_main->ip_acs); + set_uci_path_value(VARSTATE_CONFIG, "icwmp.acs.ip6", cwmp_ctx.ip_acs); } else { - set_uci_path_value(VARSTATE_CONFIG, "icwmp.acs.ip", cwmp_main->ip_acs); + set_uci_path_value(VARSTATE_CONFIG, "icwmp.acs.ip", cwmp_ctx.ip_acs); } // Trigger firewall to reload firewall.cwmp - if (cwmp_main->cr_policy != CR_POLICY_Port_Only) { + if (cwmp_ctx.cr_policy != CR_POLICY_Port_Only) { // Flawfinder: ignore FILE *pp = popen(FIREWALL_CWMP, "r"); if (pp) { @@ -343,7 +343,7 @@ int icwmp_http_send_message(char *msg_out, int msg_out_len, char **msg_in) } if (http_code == 415) { - cwmp_main->conf.compression = COMP_NONE; + cwmp_ctx.conf.compression = COMP_NONE; goto error; } if (http_code != 200 && http_code != 204) @@ -404,10 +404,10 @@ static void http_cr_new_client(int client, bool service_available) int status = 0; pthread_mutex_lock(&mutex_config_load); - char *username = (strlen(cwmp_main->conf.cpe_userid) != 0) ? strdup(cwmp_main->conf.cpe_userid) : NULL; - char *password = (strlen(cwmp_main->conf.cpe_passwd) != 0) ? strdup(cwmp_main->conf.cpe_passwd) : NULL; - char *cr_path = (strlen(cwmp_main->conf.connection_request_path) != 0) ? strdup(cwmp_main->conf.connection_request_path) : NULL; - int cr_timeout = cwmp_main->conf.cr_timeout; + char *username = (strlen(cwmp_ctx.conf.cpe_userid) != 0) ? strdup(cwmp_ctx.conf.cpe_userid) : NULL; + char *password = (strlen(cwmp_ctx.conf.cpe_passwd) != 0) ? strdup(cwmp_ctx.conf.cpe_passwd) : NULL; + char *cr_path = (strlen(cwmp_ctx.conf.connection_request_path) != 0) ? strdup(cwmp_ctx.conf.connection_request_path) : NULL; + int cr_timeout = cwmp_ctx.conf.cr_timeout; pthread_mutex_unlock(&mutex_config_load); if (!username || !password) { @@ -568,7 +568,7 @@ static void http_cr_new_client(int client, bool service_available) } CWMP_LOG(DEBUG, "Received host: (%s)", request_host); - int auth_check = validate_http_digest_auth("GET", cr_path, auth_digest_buffer + strlen("Authorization: Digest "), REALM, username, password, cwmp_main->conf.session_timeout, request_host); + int auth_check = validate_http_digest_auth("GET", cr_path, auth_digest_buffer + strlen("Authorization: Digest "), REALM, username, password, cwmp_ctx.conf.session_timeout, request_host); if (auth_check == -1) { /* invalid nonce */ CWMP_LOG(INFO, "Auth check failed for incoming CR"); @@ -637,26 +637,26 @@ void icwmp_http_server_init(void) { struct sockaddr_in6 server = { 0 }; unsigned short cr_port; - unsigned short prev_cr_port = (unsigned short)(cwmp_main->conf.connection_request_port); + unsigned short prev_cr_port = (unsigned short)(cwmp_ctx.conf.connection_request_port); for (;;) { - cr_port = (unsigned short)(cwmp_main->conf.connection_request_port); + cr_port = (unsigned short)(cwmp_ctx.conf.connection_request_port); unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port) ? 1 : 0; //Create socket if (cwmp_stop) return; - cwmp_main->cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0); - if (cwmp_main->cr_socket_desc == -1) { + cwmp_ctx.cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0); + if (cwmp_ctx.cr_socket_desc == -1) { CWMP_LOG(ERROR, "Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno)); sleep(1); continue; } - fcntl(cwmp_main->cr_socket_desc, F_SETFD, fcntl(cwmp_main->cr_socket_desc, F_GETFD) | FD_CLOEXEC); + fcntl(cwmp_ctx.cr_socket_desc, F_SETFD, fcntl(cwmp_ctx.cr_socket_desc, F_GETFD) | FD_CLOEXEC); int reusaddr = 1; - if (setsockopt(cwmp_main->cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) { + if (setsockopt(cwmp_ctx.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) { CWMP_LOG(WARNING, "setsockopt(SO_REUSEADDR) failed"); } @@ -670,7 +670,7 @@ void icwmp_http_server_init(void) server.sin6_port = htons(cr_port); //Bind - if (bind(cwmp_main->cr_socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { + if (bind(cwmp_ctx.cr_socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { //print the error message CWMP_LOG(ERROR, "Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno)); cr_port = DEFAULT_CONNECTION_REQUEST_PORT + i; @@ -707,7 +707,7 @@ void icwmp_http_server_listen(void) struct sockaddr_in6 client; //Listen - listen(cwmp_main->cr_socket_desc, 5); + listen(cwmp_ctx.cr_socket_desc, 5); //Accept and incoming connection c = sizeof(struct sockaddr_in); @@ -715,12 +715,12 @@ void icwmp_http_server_listen(void) if (cwmp_stop) return; - int client_sock = accept(cwmp_main->cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c); + int client_sock = accept(cwmp_ctx.cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c); if (client_sock < 0) { CWMP_LOG(ERROR, "Could not accept connections for Connection Request!"); - shutdown(cwmp_main->cr_socket_desc, SHUT_RDWR); + shutdown(cwmp_ctx.cr_socket_desc, SHUT_RDWR); icwmp_http_server_init(); - listen(cwmp_main->cr_socket_desc, 5); + listen(cwmp_ctx.cr_socket_desc, 5); cr_request = 0; restrict_start_time = 0; continue; diff --git a/src/notifications.c b/src/notifications.c index ccb76f4..c4e8ee6 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -472,8 +472,8 @@ void load_custom_notify_json(void) struct blob_attr *custom_notify_list = NULL; int rem = 0; - cwmp_main->custom_notify_active = false; - if (!file_exists(cwmp_main->conf.custom_notify_json)) + cwmp_ctx.custom_notify_active = false; + if (!file_exists(cwmp_ctx.conf.custom_notify_json)) return; // Check for custom notification success import marker @@ -484,8 +484,8 @@ void load_custom_notify_json(void) blob_buf_init(&bbuf, 0); // Create success marker in temp area, so that it can be in sync with backup script - if (blobmsg_add_json_from_file(&bbuf, cwmp_main->conf.custom_notify_json) == false) { - CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_main->conf.custom_notify_json); + if (blobmsg_add_json_from_file(&bbuf, cwmp_ctx.conf.custom_notify_json) == false) { + CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_ctx.conf.custom_notify_json); blob_buf_free(&bbuf); creat(RUN_NOTIFY_MARKER, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); return; @@ -498,7 +498,7 @@ void load_custom_notify_json(void) blobmsg_parse(p_notif, 1, tb_notif, blobmsg_data(bbuf.head), blobmsg_len(bbuf.head)); if (tb_notif[0] == NULL) { - CWMP_LOG(WARNING, "The JSON file %s doesn't contain a notify parameters list", cwmp_main->conf.custom_notify_json); + CWMP_LOG(WARNING, "The JSON file %s doesn't contain a notify parameters list", cwmp_ctx.conf.custom_notify_json); blob_buf_free(&bbuf); creat(RUN_NOTIFY_MARKER, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); return; @@ -532,7 +532,7 @@ void load_custom_notify_json(void) cwmp_free_all_dm_parameter_list(¬ification_list_head); creat(RUN_NOTIFY_MARKER, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - cwmp_main->custom_notify_active = true; + cwmp_ctx.custom_notify_active = true; } void set_default_forced_active_parameters_notifications() @@ -618,10 +618,10 @@ int check_value_change(void) } if ((notification >= 1) && (dm_value != NULL) && value && (strcmp(dm_value, value) != 0)) { - if (cwmp_main->conf.md_notif_limit > 0 && CWMP_STRCMP(parameter, MANAGEABLE_DEVICES_NBRE) == 0 && notification == 2) { - unsigned int time_from_last_vc = time(NULL) - cwmp_main->md_value_change_last_time; - if ((cwmp_main->md_value_change_last_time <= 0) || (time_from_last_vc >= cwmp_main->conf.md_notif_limit)) { - cwmp_main->md_value_change_last_time = time(NULL); + if (cwmp_ctx.conf.md_notif_limit > 0 && CWMP_STRCMP(parameter, MANAGEABLE_DEVICES_NBRE) == 0 && notification == 2) { + unsigned int time_from_last_vc = time(NULL) - cwmp_ctx.md_value_change_last_time; + if ((cwmp_ctx.md_value_change_last_time <= 0) || (time_from_last_vc >= cwmp_ctx.conf.md_notif_limit)) { + cwmp_ctx.md_value_change_last_time = time(NULL); add_list_value_change(MANAGEABLE_DEVICES_NBRE, dm_value, dm_type); notif_ret |= NOTIF_ACTIVE; } @@ -650,14 +650,17 @@ int check_value_change(void) return notif_ret; } -void cwmp_prepare_value_change() +void cwmp_prepare_value_change(void) { struct event_container *event_container; + if (list_value_change.next == &(list_value_change)) return; + event_container = cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, ""); if (!event_container) return; + list_splice_init(&(list_value_change), &(event_container->head_dm_parameter)); cwmp_save_event_container(event_container); } @@ -673,7 +676,7 @@ void sotfware_version_value_change(struct transfer_complete *p) if (!p->old_software_version || p->old_software_version[0] == 0) return; - current_software_version = cwmp_main->deviceid.softwareversion; + current_software_version = cwmp_ctx.deviceid.softwareversion; if (p->old_software_version && current_software_version && strcmp(p->old_software_version, current_software_version) != 0) cwmp_add_event_container(EVENT_IDX_4VALUE_CHANGE, ""); } @@ -715,22 +718,22 @@ void periodic_check_notifiy(struct uloop_timeout *timeout __attribute__((unused cwmp_update_enabled_notify_file(); if (is_notify & NOTIF_ACTIVE) { send_active_value_change(); - int last_session_interval = time(NULL) - cwmp_main->session->session_status.last_end_time; - if (!cwmp_main->throttle_session_triggered && (cwmp_main->session->session_status.last_status == SESSION_SUCCESS) && (cwmp_main->conf.active_notif_throttle > 0)) { - cwmp_main->throttle_session_triggered = true; - if (last_session_interval < cwmp_main->conf.active_notif_throttle) - trigger_cwmp_throttle_session_timer(cwmp_main->conf.active_notif_throttle - last_session_interval); + int last_session_interval = time(NULL) - cwmp_ctx.session->session_status.last_end_time; + if (!cwmp_ctx.throttle_session_triggered && (cwmp_ctx.session->session_status.last_status == SESSION_SUCCESS) && (cwmp_ctx.conf.active_notif_throttle > 0)) { + cwmp_ctx.throttle_session_triggered = true; + if (last_session_interval < cwmp_ctx.conf.active_notif_throttle) + trigger_cwmp_throttle_session_timer(cwmp_ctx.conf.active_notif_throttle - last_session_interval); else trigger_cwmp_throttle_session_timer(0); } - else if (cwmp_main->conf.active_notif_throttle == 0) + else if (cwmp_ctx.conf.active_notif_throttle == 0) trigger_cwmp_session_timer(); } if (is_notify & NOTIF_LW_ACTIVE) cwmp_lwnotification(); - uloop_timeout_set(&check_notify_timer, cwmp_main->conf.periodic_notify_interval * 1000); + uloop_timeout_set(&check_notify_timer, cwmp_ctx.conf.periodic_notify_interval * 1000); } void trigger_periodic_notify_check() @@ -767,7 +770,7 @@ void add_lw_list_value_change(char *param_name, char *param_data, char *param_ty static void udplw_server_param(struct addrinfo **res) { struct addrinfo hints = { 0 }; - struct config *conf = &(cwmp_main->conf); + struct config *conf = &(cwmp_ctx.conf); char port[32]; hints.ai_family = AF_UNSPEC; @@ -831,7 +834,7 @@ void cwmp_lwnotification() char signature[41]; struct addrinfo *servaddr; struct config *conf; - conf = &(cwmp_main->conf); + conf = &(cwmp_ctx.conf); udplw_server_param(&servaddr); xml_prepare_lwnotification_message(&msg_out); diff --git a/src/notifications.h b/src/notifications.h index f204a31..ada067e 100644 --- a/src/notifications.h +++ b/src/notifications.h @@ -50,6 +50,6 @@ char *calculate_lwnotification_cnonce(); void clean_list_param_notify(); void init_list_param_notify(); void reinit_list_param_notify(); -void cwmp_prepare_value_change(); +void cwmp_prepare_value_change(void); void trigger_periodic_notify_check(); #endif /* SRC_INC_NOTIFICATIONS_H_ */ diff --git a/src/reboot.c b/src/reboot.c index b0df9b2..ccc32a1 100644 --- a/src/reboot.c +++ b/src/reboot.c @@ -24,7 +24,7 @@ struct uloop_timeout delay_reboot_timer = { .cb = cwmp_delay_reboot }; void cwmp_schedule_reboot(struct uloop_timeout *timeout __attribute__((unused))) { set_uci_path_value(NULL, "cwmp.cpe.schedule_reboot", "0001-01-01T00:00:00Z"); - if (time(NULL) > cwmp_main->conf.schedule_reboot) + if (time(NULL) > cwmp_ctx.conf.schedule_reboot) return; cwmp_reboot("schedule_reboot"); } @@ -32,7 +32,7 @@ void cwmp_schedule_reboot(struct uloop_timeout *timeout __attribute__((unused)) void cwmp_delay_reboot(struct uloop_timeout *timeout __attribute__((unused))) { set_uci_path_value(NULL, "cwmp.cpe.delay_reboot", "-1"); - if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) { + if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) { cwmp_set_end_session(END_SESSION_REBOOT); } else { cwmp_reboot("delay_reboot"); @@ -42,16 +42,16 @@ void cwmp_delay_reboot(struct uloop_timeout *timeout __attribute__((unused))) void launch_reboot_methods() { - if (cwmp_main->conf.delay_reboot != cwmp_main->curr_delay_reboot && cwmp_main->conf.delay_reboot > 0) { - CWMP_LOG(INFO, "The device will reboot after %ld seconds", cwmp_main->conf.delay_reboot); - cwmp_main->curr_delay_reboot = cwmp_main->conf.delay_reboot; + if (cwmp_ctx.conf.delay_reboot != cwmp_ctx.curr_delay_reboot && cwmp_ctx.conf.delay_reboot > 0) { + CWMP_LOG(INFO, "The device will reboot after %ld seconds", cwmp_ctx.conf.delay_reboot); + cwmp_ctx.curr_delay_reboot = cwmp_ctx.conf.delay_reboot; uloop_timeout_cancel(&delay_reboot_timer); - uloop_timeout_set(&delay_reboot_timer, cwmp_main->conf.delay_reboot * 1000); + uloop_timeout_set(&delay_reboot_timer, cwmp_ctx.conf.delay_reboot * 1000); } - if (cwmp_main->conf.schedule_reboot != cwmp_main->curr_schedule_reboot && (cwmp_main->conf.schedule_reboot - time(NULL)) > 0) { - cwmp_main->curr_schedule_reboot = cwmp_main->conf.schedule_reboot; - time_t remaining_time = cwmp_main->conf.schedule_reboot - time(NULL); + if (cwmp_ctx.conf.schedule_reboot != cwmp_ctx.curr_schedule_reboot && (cwmp_ctx.conf.schedule_reboot - time(NULL)) > 0) { + cwmp_ctx.curr_schedule_reboot = cwmp_ctx.conf.schedule_reboot; + time_t remaining_time = cwmp_ctx.conf.schedule_reboot - time(NULL); CWMP_LOG(INFO, "The device will reboot after %ld seconds", remaining_time); uloop_timeout_cancel(&schedule_reboot_timer); uloop_timeout_set(&schedule_reboot_timer, remaining_time * 1000); diff --git a/src/rpc.c b/src/rpc.c index 8802bd9..19c181b 100755 --- a/src/rpc.c +++ b/src/rpc.c @@ -101,27 +101,27 @@ int xml_handle_message() char buf[128] = {0}; int i; mxml_node_t *b; - struct config *conf = &(cwmp_main->conf); + struct config *conf = &(cwmp_ctx.conf); /* get method */ snprintf(buf, sizeof(buf), "%s:%s", ns.soap_env, "Body"); if (strlen(buf) == 0) { - cwmp_main->session->fault_code = FAULT_CPE_INTERNAL_ERROR; + cwmp_ctx.session->fault_code = FAULT_CPE_INTERNAL_ERROR; goto fault; } - b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, buf, NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, buf, NULL, NULL, MXML_DESCEND); if (!b) { CWMP_LOG(INFO, "Invalid received message"); - cwmp_main->session->fault_code = FAULT_CPE_REQUEST_DENIED; + cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED; goto fault; } - cwmp_main->session->body_in = b; + cwmp_ctx.session->body_in = b; while (1) { - b = mxmlWalkNext(b, cwmp_main->session->body_in, MXML_DESCEND_FIRST); + b = mxmlWalkNext(b, cwmp_ctx.session->body_in, MXML_DESCEND_FIRST); if (!b) goto error; if (mxmlGetType(b) == MXML_ELEMENT) @@ -143,41 +143,41 @@ int xml_handle_message() if (CWMP_STRLEN(ns.cwmp) != ns_len) { CWMP_LOG(INFO, "Namespace length is not matched in string (%s) and expected (%s)", c, ns.cwmp); - cwmp_main->session->fault_code = FAULT_CPE_REQUEST_DENIED; + 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); - cwmp_main->session->fault_code = FAULT_CPE_REQUEST_DENIED; + cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED; goto fault; } c = tmp + 1; } else { CWMP_LOG(INFO, "Can not convert QName to local part with received string (%s)", c); - cwmp_main->session->fault_code = FAULT_CPE_REQUEST_DENIED; + cwmp_ctx.session->fault_code = FAULT_CPE_REQUEST_DENIED; goto fault; } CWMP_LOG(INFO, "SOAP RPC message: %s", c); for (i = 1; i < __RPC_CPE_MAX; i++) { if (i != RPC_CPE_FAULT && c && CWMP_STRCMP(c, rpc_cpe_methods[i].name) == 0 && rpc_cpe_methods[i].amd <= conf->supported_amd_version) { CWMP_LOG(INFO, "%s RPC is supported", c); - cwmp_main->session->rpc_cpe = build_sessin_rcp_cpe(i); - if (cwmp_main->session->rpc_cpe == NULL) + cwmp_ctx.session->rpc_cpe = build_sessin_rcp_cpe(i); + if (cwmp_ctx.session->rpc_cpe == NULL) goto error; break; } } - if (!cwmp_main->session->rpc_cpe) { + if (!cwmp_ctx.session->rpc_cpe) { CWMP_LOG(INFO, "%s RPC is not supported", c); - cwmp_main->session->fault_code = FAULT_CPE_METHOD_NOT_SUPPORTED; + cwmp_ctx.session->fault_code = FAULT_CPE_METHOD_NOT_SUPPORTED; goto fault; } return 0; fault: - cwmp_main->session->rpc_cpe = build_sessin_rcp_cpe(RPC_CPE_FAULT); - if (cwmp_main->session->rpc_cpe == NULL) + cwmp_ctx.session->rpc_cpe = build_sessin_rcp_cpe(RPC_CPE_FAULT); + if (cwmp_ctx.session->rpc_cpe == NULL) goto error; return 0; error: @@ -309,10 +309,10 @@ static void load_inform_xml_schema(mxml_node_t **tree) struct xml_data_struct inform_xml_attrs = {0}; - char *manufacturer = cwmp_main->deviceid.manufacturer; - char *oui = cwmp_main->deviceid.oui; - char *product_class = cwmp_main->deviceid.productclass; - char *serial_number = cwmp_main->deviceid.serialnumber; + char *manufacturer = cwmp_ctx.deviceid.manufacturer; + char *oui = cwmp_ctx.deviceid.oui; + char *product_class = cwmp_ctx.deviceid.productclass; + char *serial_number = cwmp_ctx.deviceid.serialnumber; int max_env = 1; char current_time[26] = {0}; get_time(time(NULL), current_time, sizeof(current_time)); @@ -324,10 +324,10 @@ static void load_inform_xml_schema(mxml_node_t **tree) inform_xml_attrs.serial_number = &serial_number; inform_xml_attrs.max_envelopes = &max_env; inform_xml_attrs.current_time = &str_time; - inform_xml_attrs.retry_count = &cwmp_main->retry_count_session; + inform_xml_attrs.retry_count = &cwmp_ctx.retry_count_session; LIST_HEAD(xml_events_list); - event_container_list_to_xml_data_list(&(cwmp_main->session->events), &xml_events_list); + event_container_list_to_xml_data_list(&(cwmp_ctx.session->events), &xml_events_list); inform_xml_attrs.data_list = &xml_events_list; fault = build_xml_node_data(SOAP_INFORM_CWMP, inform, &inform_xml_attrs); @@ -345,7 +345,7 @@ static void load_inform_xml_schema(mxml_node_t **tree) struct cwmp_dm_parameter *dm_parameter; int size = 0; - list_for_each (ilist, &(cwmp_main->session->events)) { + list_for_each (ilist, &(cwmp_ctx.session->events)) { struct event_container *event_container = list_entry(ilist, struct event_container, list); list_for_each (jlist, &(event_container->head_dm_parameter)) { dm_parameter = list_entry(jlist, struct cwmp_dm_parameter, list); @@ -373,7 +373,7 @@ static void load_inform_xml_schema(mxml_node_t **tree) } //only forced inform parameters are included in heartbeat inform session - if (cwmp_main->session->session_status.is_heartbeat) + if (cwmp_ctx.session->session_status.is_heartbeat) goto end; struct cwmp_dm_parameter *param_iter = NULL; @@ -395,7 +395,7 @@ static void load_inform_xml_schema(mxml_node_t **tree) continue; char *events_str_list = param_iter->value; - if (!check_inform_parameter_events_list_corresponding(events_str_list, &(cwmp_main->session->events))) + if (!check_inform_parameter_events_list_corresponding(events_str_list, &(cwmp_ctx.session->events))) continue; struct list_head *data_list = ¶meters_list; @@ -461,7 +461,7 @@ int cwmp_rpc_acs_prepare_message_inform(struct rpc *this __attribute__((unused)) { mxml_node_t *tree; - if (cwmp_main->session == NULL) + if (cwmp_ctx.session == NULL) return -1; load_inform_xml_schema(&tree); @@ -469,7 +469,7 @@ int cwmp_rpc_acs_prepare_message_inform(struct rpc *this __attribute__((unused)) if (!tree) goto error; - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; @@ -485,7 +485,7 @@ int cwmp_rpc_acs_parse_response_inform(struct rpc *this __attribute__((unused))) char *c; const char *cwmp_urn; - tree = cwmp_main->session->tree_in; + tree = cwmp_ctx.session->tree_in; if (!tree) goto error; b = mxmlFindElement(tree, tree, "MaxEnvelopes", NULL, NULL, MXML_DESCEND); @@ -494,32 +494,32 @@ int cwmp_rpc_acs_parse_response_inform(struct rpc *this __attribute__((unused))) b = mxmlWalkNext(b, tree, MXML_DESCEND_FIRST); if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b)) goto error; - if (cwmp_main->conf.supported_amd_version == 1) { - cwmp_main->conf.amd_version = 1; + if (cwmp_ctx.conf.supported_amd_version == 1) { + cwmp_ctx.conf.amd_version = 1; return 0; } b = mxmlFindElement(tree, tree, "UseCWMPVersion", NULL, NULL, MXML_DESCEND); - if (b && cwmp_main->conf.supported_amd_version >= 5) { //IF supported version !=5 acs response dosen't contain UseCWMPVersion + if (b && cwmp_ctx.conf.supported_amd_version >= 5) { //IF supported version !=5 acs response dosen't contain UseCWMPVersion b = mxmlWalkNext(b, tree, MXML_DESCEND_FIRST); if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b)) goto error; c = (char *) mxmlGetOpaque(b); if (c && *(c + 1) == '.') { c += 2; - cwmp_main->conf.amd_version = (int)strtol(c, NULL, 10) + 1; + cwmp_ctx.conf.amd_version = (int)strtol(c, NULL, 10) + 1; return 0; } goto error; } b = mxmlFindElement(tree, tree, "cwmp:UseCWMPVersion", NULL, NULL, MXML_DESCEND); - if (b && cwmp_main->conf.supported_amd_version >= 5) { //IF supported version !=5 acs response dosen't contain UseCWMPVersion + if (b && cwmp_ctx.conf.supported_amd_version >= 5) { //IF supported version !=5 acs response dosen't contain UseCWMPVersion b = mxmlWalkNext(b, tree, MXML_DESCEND_FIRST); if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b)) goto error; c = (char *) mxmlGetOpaque(b); if (c && *(c + 1) == '.') { c += 2; - cwmp_main->conf.amd_version = (int)strtol(c, NULL, 10) + 1; + cwmp_ctx.conf.amd_version = (int)strtol(c, NULL, 10) + 1; return 0; } goto error; @@ -532,27 +532,27 @@ int cwmp_rpc_acs_parse_response_inform(struct rpc *this __attribute__((unused))) } } if (i == 0) { - cwmp_main->conf.amd_version = i + 1; + cwmp_ctx.conf.amd_version = i + 1; } else if (i >= 1 && i <= 3) { - switch (cwmp_main->conf.supported_amd_version) { + switch (cwmp_ctx.conf.supported_amd_version) { case 1: - cwmp_main->conf.amd_version = 1; //Already done + cwmp_ctx.conf.amd_version = 1; //Already done break; case 2: case 3: case 4: //MIN ACS CPE - if (cwmp_main->conf.supported_amd_version <= i + 1) - cwmp_main->conf.amd_version = cwmp_main->conf.supported_amd_version; + if (cwmp_ctx.conf.supported_amd_version <= i + 1) + cwmp_ctx.conf.amd_version = cwmp_ctx.conf.supported_amd_version; else - cwmp_main->conf.amd_version = i + 1; + cwmp_ctx.conf.amd_version = i + 1; break; case 5: - cwmp_main->conf.amd_version = i + 1; + cwmp_ctx.conf.amd_version = i + 1; break; } } else if (i >= 4) { - cwmp_main->conf.amd_version = cwmp_main->conf.supported_amd_version; + cwmp_ctx.conf.amd_version = cwmp_ctx.conf.supported_amd_version; } return 0; @@ -587,7 +587,7 @@ void set_not_known_acs_support() int cwmp_rpc_acs_parse_response_get_rpc_methods(struct rpc *this __attribute__((unused))) { mxml_node_t *tree, *b; - tree = cwmp_main->session->tree_in; + tree = cwmp_ctx.session->tree_in; b = mxmlFindElement(tree, tree, "cwmp:GetRPCMethodsResponse", NULL, NULL, MXML_DESCEND); if (!b) @@ -627,13 +627,13 @@ int cwmp_rpc_acs_prepare_get_rpc_methods(struct rpc *rpc __attribute__((unused)) n = mxmlFindElement(tree, tree, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); if (!n) return -1; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_main->conf.amd_version) - 1]); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_ctx.conf.amd_version) - 1]); n = build_top_body_soap_request(tree, "GetRPCMethods"); if (!n) return -1; - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; } @@ -655,7 +655,7 @@ int cwmp_rpc_acs_prepare_transfer_complete(struct rpc *rpc) n = mxmlFindElement(tree, tree, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_main->conf.amd_version) - 1]); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_ctx.conf.amd_version) - 1]); n = build_top_body_soap_request(tree, "TransferComplete"); if (!n) @@ -684,7 +684,7 @@ int cwmp_rpc_acs_prepare_transfer_complete(struct rpc *rpc) goto error; FREE(faultstring); - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; @@ -706,7 +706,7 @@ int cwmp_rpc_acs_prepare_autonomous_transfer_complete(struct rpc *rpc) if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_main->conf.amd_version) - 1]); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_ctx.conf.amd_version) - 1]); n = build_top_body_soap_request(tree, "AutonomousTransferComplete"); if (!n) @@ -732,7 +732,7 @@ int cwmp_rpc_acs_prepare_autonomous_transfer_complete(struct rpc *rpc) goto error; } - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; error: @@ -761,7 +761,7 @@ int cwmp_rpc_acs_prepare_du_state_change_complete(struct rpc *rpc) if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_main->conf.amd_version) - 1]); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_ctx.conf.amd_version) - 1]); n = build_top_body_soap_request(tree, "DUStateChangeComplete"); if (!n) @@ -782,7 +782,7 @@ int cwmp_rpc_acs_prepare_du_state_change_complete(struct rpc *rpc) } cwmp_free_all_xml_data_list(&opt_result_list); - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; error: @@ -806,7 +806,7 @@ int cwmp_rpc_acs_prepare_autonomous_du_state_change_complete(struct rpc *rpc) if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_main->conf.amd_version) - 1]); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp_ctx.conf.amd_version) - 1]); n = build_top_body_soap_request(tree, "AutonomousDUStateChangeComplete"); if (!n) @@ -832,7 +832,7 @@ int cwmp_rpc_acs_prepare_autonomous_du_state_change_complete(struct rpc *rpc) goto error; } - cwmp_main->session->tree_out = tree; + cwmp_ctx.session->tree_out = tree; return 0; error: @@ -849,12 +849,12 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct rpc *rpc) int counter = 0; const char *err_msg = NULL; - if (cwmp_main->session->tree_out == NULL) { + if (cwmp_ctx.session->tree_out == NULL) { err_msg = "Output xml tree does not exist"; goto fault; } - b = build_top_body_soap_response(cwmp_main->session->tree_out, "GetParameterValues"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "GetParameterValues"); if (b == NULL) { err_msg = "Failed to populate the SOAP message for GPV response"; goto fault; @@ -868,7 +868,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct rpc *rpc) gpv_xml_attrs.validations = gpv_validation; gpv_xml_attrs.nbre_validations = 1; - fault_code = load_xml_node_data(SOAP_REQ_GPV, cwmp_main->session->body_in, &gpv_xml_attrs); + fault_code = load_xml_node_data(SOAP_REQ_GPV, cwmp_ctx.session->body_in, &gpv_xml_attrs); if (fault_code) { err_msg = "Failed to load the attributes from GPV requests message"; goto fault; @@ -924,7 +924,7 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct rpc *rpc) gpn_xml_attrs.validations = gpn_validation; gpn_xml_attrs.nbre_validations = 2; - fault_code = load_xml_node_data(SOAP_REQ_GPN, cwmp_main->session->body_in, &gpn_xml_attrs); + fault_code = load_xml_node_data(SOAP_REQ_GPN, cwmp_ctx.session->body_in, &gpn_xml_attrs); if (fault_code != CWMP_OK) { err_msg = "Failed to load attributes from GPN request message"; goto fault; @@ -984,12 +984,12 @@ build_response: FREE(parameter_name); - if (cwmp_main->session->tree_out == NULL) { + if (cwmp_ctx.session->tree_out == NULL) { err_msg = "Output xml tree does not exist"; goto fault; } - n = build_top_body_soap_response(cwmp_main->session->tree_out, "GetParameterNames"); + n = build_top_body_soap_response(cwmp_ctx.session->tree_out, "GetParameterNames"); if (!n) { fault_code = FAULT_CPE_INTERNAL_ERROR; @@ -1046,9 +1046,9 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct rpc *rpc) int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR; const char *err_msg = NULL; - b = cwmp_main->session->body_in; + b = cwmp_ctx.session->body_in; - n = build_top_body_soap_response(cwmp_main->session->tree_out, "GetParameterAttributes"); + n = build_top_body_soap_response(cwmp_ctx.session->tree_out, "GetParameterAttributes"); if (!n) { err_msg = "Failed to build SOAP message for GetParameterAttributes response"; goto fault; @@ -1107,7 +1107,7 @@ int is_duplicated_parameter(mxml_node_t *param_node) { mxml_node_t *b = param_node; const char *node_name = param_node ? mxmlGetElement(param_node) : NULL; - while ((b = mxmlWalkNext(b, cwmp_main->session->body_in, MXML_DESCEND))) { + while ((b = mxmlWalkNext(b, cwmp_ctx.session->body_in, MXML_DESCEND))) { const char *node_opaque = mxmlGetOpaque(b); mxml_node_t *parent = mxmlGetParent(b); mxml_type_t node_type = mxmlGetType(b); @@ -1140,7 +1140,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct rpc *rpc) spv_xml_attrs.validations = spv_validation; spv_xml_attrs.nbre_validations = 2; - fault_code = load_xml_node_data(SOAP_REQ_SPV, cwmp_main->session->body_in, &spv_xml_attrs); + fault_code = load_xml_node_data(SOAP_REQ_SPV, cwmp_ctx.session->body_in, &spv_xml_attrs); if (fault_code) { err_msg = "Failed to load attributes from SPV request message"; goto fault; @@ -1177,7 +1177,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct rpc *rpc) status = 1; } - b = build_top_body_soap_response(cwmp_main->session->tree_out, "SetParameterValues"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "SetParameterValues"); if (!b) { fault_code = FAULT_CPE_INTERNAL_ERROR; @@ -1228,7 +1228,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc) goto fault; } - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (!n) { err_msg = "SetParameterAttributes element does not exist in xml input tree"; @@ -1263,7 +1263,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc) } cwmp_free_all_xml_data_list(&prameters_xml_list); - mxml_node_t *resp = build_top_body_soap_response(cwmp_main->session->tree_out, "SetParameterAttributes"); + mxml_node_t *resp = build_top_body_soap_response(cwmp_ctx.session->tree_out, "SetParameterAttributes"); if (!resp) { err_msg = "Failed to populate SOAP response for SetParameterAttributes request"; goto fault; @@ -1298,7 +1298,7 @@ int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc) add_obj_xml_attrs.validations = gpn_validation; add_obj_xml_attrs.nbre_validations = 2; - int fault_code = load_xml_node_data(SOAP_REQ_ADDOBJ, cwmp_main->session->body_in, &add_obj_xml_attrs); + int fault_code = load_xml_node_data(SOAP_REQ_ADDOBJ, cwmp_ctx.session->body_in, &add_obj_xml_attrs); if (fault_code) { err_msg = "Failed to load data from AddObject request message"; @@ -1325,7 +1325,7 @@ int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc) goto fault; } - b = build_top_body_soap_response(cwmp_main->session->tree_out, "AddObject"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "AddObject"); if (!b) { err_msg = "Failed to build SOAP message for AddObject response"; @@ -1384,7 +1384,7 @@ int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc) del_obj_xml_attrs.validations = gpn_validation; del_obj_xml_attrs.nbre_validations = 2; - int fault_code = load_xml_node_data(SOAP_REQ_DELOBJ, cwmp_main->session->body_in, &del_obj_xml_attrs); + int fault_code = load_xml_node_data(SOAP_REQ_DELOBJ, cwmp_ctx.session->body_in, &del_obj_xml_attrs); if (fault_code) { err_msg = "Failed to load data from DeleteObject request message"; @@ -1404,7 +1404,7 @@ int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc) goto fault; } set_rpc_parameter_key(parameter_key); - b = build_top_body_soap_response(cwmp_main->session->tree_out, "DeleteObject"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "DeleteObject"); if (!b) { fault_code = FAULT_CPE_INTERNAL_ERROR; @@ -1449,7 +1449,7 @@ int cwmp_handle_rpc_cpe_get_rpc_methods(struct rpc *rpc) int fault_code = FAULT_CPE_INTERNAL_ERROR; const char *err_msg = NULL; - n = build_top_body_soap_response(cwmp_main->session->tree_out, "GetRPCMethods"); + n = build_top_body_soap_response(cwmp_ctx.session->tree_out, "GetRPCMethods"); if (!n) { err_msg = "Failed to prepare SOAP response message for GetRPCMethods"; @@ -1511,7 +1511,7 @@ int cwmp_handle_rpc_cpe_factory_reset(struct rpc *rpc) mxml_node_t *b; const char *err_msg = NULL; - b = build_top_body_soap_response(cwmp_main->session->tree_out, "FactoryReset"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "FactoryReset"); if (!b) { err_msg = "Failed to build SOAP message for FactoryReset response"; @@ -1538,7 +1538,7 @@ int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct rpc *rpc) { mxml_node_t *b; - b = build_top_body_soap_response(cwmp_main->session->tree_out, "X_FactoryResetSoft"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "X_FactoryResetSoft"); if (!b) goto fault; @@ -1571,7 +1571,7 @@ int cwmp_handle_rpc_cpe_cancel_transfer(struct rpc *rpc) canceltrancer_obj_xml_attrs.validations = canceltransfer_validation; canceltrancer_obj_xml_attrs.nbre_validations = 1; - int fault_code = load_xml_node_data(SOAP_REQ_CANCELTRANSFER, cwmp_main->session->body_in, &canceltrancer_obj_xml_attrs); + int fault_code = load_xml_node_data(SOAP_REQ_CANCELTRANSFER, cwmp_ctx.session->body_in, &canceltrancer_obj_xml_attrs); if (command_key) cancel_transfer(command_key); @@ -1581,7 +1581,7 @@ int cwmp_handle_rpc_cpe_cancel_transfer(struct rpc *rpc) goto fault; } - b = build_top_body_soap_response(cwmp_main->session->tree_out, "CancelTransfer"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "CancelTransfer"); if (!b) { fault_code = FAULT_CPE_INTERNAL_ERROR; @@ -1651,7 +1651,7 @@ int cwmp_handle_rpc_cpe_reboot(struct rpc *rpc) reboot_obj_xml_attrs.validations = reboot_validation; reboot_obj_xml_attrs.nbre_validations = 1; - int fault_code = load_xml_node_data(SOAP_REQ_REBOOT, cwmp_main->session->body_in, &reboot_obj_xml_attrs); + int fault_code = load_xml_node_data(SOAP_REQ_REBOOT, cwmp_ctx.session->body_in, &reboot_obj_xml_attrs); if (fault_code) { err_msg = "Failed to load data from reboot request"; @@ -1668,7 +1668,7 @@ int cwmp_handle_rpc_cpe_reboot(struct rpc *rpc) cwmp_save_event_container(event_container); - b = build_top_body_soap_response(cwmp_main->session->tree_out, "Reboot"); + b = build_top_body_soap_response(cwmp_ctx.session->tree_out, "Reboot"); if (!b) { err_msg = "Failed to build the SOAP message for reboot response"; @@ -1712,7 +1712,7 @@ int cwmp_handle_rpc_cpe_schedule_inform(struct rpc *rpc) schedinform_obj_xml_attrs.validations = schedinform_validation; schedinform_obj_xml_attrs.nbre_validations = 2; - fault = load_xml_node_data(SOAP_REQ_SCHEDINF, cwmp_main->session->body_in, &schedinform_obj_xml_attrs); + fault = load_xml_node_data(SOAP_REQ_SCHEDINF, cwmp_ctx.session->body_in, &schedinform_obj_xml_attrs); if (fault) { snprintf(err_msg, sizeof(err_msg), "Failed to load data from ScheduleInform request message"); @@ -1734,7 +1734,7 @@ int cwmp_handle_rpc_cpe_schedule_inform(struct rpc *rpc) } } - n = build_top_body_soap_response(cwmp_main->session->tree_out, "ScheduleInform"); + n = build_top_body_soap_response(cwmp_ctx.session->tree_out, "ScheduleInform"); if (!n) { snprintf(err_msg, sizeof(err_msg), "Failed to build SOAP message for ScheduleInform response"); @@ -1751,11 +1751,11 @@ int cwmp_handle_rpc_cpe_schedule_inform(struct rpc *rpc) schedule_inform->handler_timer.cb = cwmp_start_schedule_inform; schedule_inform->commandKey = CWMP_STRDUP(command_key); schedule_inform->scheduled_time = scheduled_time; - if ((cwmp_main->sched_inform_id < 0) || (cwmp_main->sched_inform_id >= MAX_INT_ID)) { - cwmp_main->sched_inform_id = 0; + if ((cwmp_ctx.sched_inform_id < 0) || (cwmp_ctx.sched_inform_id >= MAX_INT_ID)) { + cwmp_ctx.sched_inform_id = 0; } - cwmp_main->sched_inform_id++; - schedule_inform->id = cwmp_main->sched_inform_id; + cwmp_ctx.sched_inform_id++; + schedule_inform->id = cwmp_ctx.sched_inform_id; list_add(&(schedule_inform->list), ilist->prev); bkp_session_insert_schedule_inform(schedule_inform->id, schedule_inform->scheduled_time, schedule_inform->commandKey); bkp_session_save(); @@ -1789,7 +1789,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc) goto fault; } - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (!n) { error = FAULT_CPE_INTERNAL_ERROR; snprintf(err_msg, sizeof(err_msg), "ChangeDUState element does not exist in input xml tree"); @@ -1823,7 +1823,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc) xml_data_list_to_cdu_operations_list(&xml_list_operations, &change_du_state->list_operation); - t = build_top_body_soap_response(cwmp_main->session->tree_out, "ChangeDUState"); + t = build_top_body_soap_response(cwmp_ctx.session->tree_out, "ChangeDUState"); if (!t) { error = FAULT_CPE_INTERNAL_ERROR; @@ -1834,11 +1834,11 @@ int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc) change_du_state->handler_timer.cb = change_du_state_execute; list_add_tail(&(change_du_state->list), &(list_change_du_state)); - if ((cwmp_main->cdu_id < 0) || (cwmp_main->cdu_id >= MAX_INT_ID)) { - cwmp_main->cdu_id = 0; + if ((cwmp_ctx.cdu_id < 0) || (cwmp_ctx.cdu_id >= MAX_INT_ID)) { + cwmp_ctx.cdu_id = 0; } - cwmp_main->cdu_id++; - change_du_state->id = cwmp_main->cdu_id; + cwmp_ctx.cdu_id++; + change_du_state->id = cwmp_ctx.cdu_id; bkp_session_insert_change_du_state(change_du_state); bkp_session_save(); cwmp_set_end_session(END_SESSION_CDU); @@ -1876,7 +1876,7 @@ int cwmp_handle_rpc_cpe_download(struct rpc *rpc) goto fault; } - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (!n) { error = FAULT_CPE_INTERNAL_ERROR; @@ -1930,7 +1930,7 @@ int cwmp_handle_rpc_cpe_download(struct rpc *rpc) if (error != FAULT_CPE_NO_FAULT) goto fault; - mxml_node_t *t = build_top_body_soap_response(cwmp_main->session->tree_out, "Download"); + mxml_node_t *t = build_top_body_soap_response(cwmp_ctx.session->tree_out, "Download"); if (!t) { error = FAULT_CPE_INTERNAL_ERROR; snprintf(err_msg, sizeof(err_msg), "Failed to populate download response SOAP message"); @@ -1973,11 +1973,11 @@ int cwmp_handle_rpc_cpe_download(struct rpc *rpc) download->scheduled_time = scheduled_time; } download->handler_timer.cb = cwmp_start_download; - if ((cwmp_main->download_id < 0) || (cwmp_main->download_id >= MAX_INT_ID)) { - cwmp_main->download_id = 0; + if ((cwmp_ctx.download_id < 0) || (cwmp_ctx.download_id >= MAX_INT_ID)) { + cwmp_ctx.download_id = 0; } - cwmp_main->download_id++; - download->id = cwmp_main->download_id; + cwmp_ctx.download_id++; + download->id = cwmp_ctx.download_id; bkp_session_insert_download(download); bkp_session_save(); if (download_delay != 0) { @@ -2020,7 +2020,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc) goto fault; } - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (!n) { error = FAULT_CPE_INTERNAL_ERROR; @@ -2114,7 +2114,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc) if (error != FAULT_CPE_NO_FAULT) goto fault; - t = build_top_body_soap_response(cwmp_main->session->tree_out, "ScheduleDownload"); + t = build_top_body_soap_response(cwmp_ctx.session->tree_out, "ScheduleDownload"); if (!t) { error = FAULT_CPE_INTERNAL_ERROR; @@ -2131,11 +2131,11 @@ int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc) schedule_download->timewindowstruct[i].windowend = time(NULL) + schedule_download_delay[i * 2 + 1]; } schedule_download->handler_timer.cb = cwmp_start_schedule_download; - if ((cwmp_main->sched_download_id < 0) || (cwmp_main->sched_download_id >= MAX_INT_ID)) { - cwmp_main->sched_download_id = 0; + if ((cwmp_ctx.sched_download_id < 0) || (cwmp_ctx.sched_download_id >= MAX_INT_ID)) { + cwmp_ctx.sched_download_id = 0; } - cwmp_main->sched_download_id++; - schedule_download->id = cwmp_main->sched_download_id; + cwmp_ctx.sched_download_id++; + schedule_download->id = cwmp_ctx.sched_download_id; bkp_session_insert_schedule_download(schedule_download); bkp_session_save(); if (schedule_download_delay[0] != 0) { @@ -2183,7 +2183,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc) goto fault; } - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (!n) { error = FAULT_CPE_INTERNAL_ERROR; @@ -2237,7 +2237,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc) if (error != FAULT_CPE_NO_FAULT) goto fault; - mxml_node_t *t = build_top_body_soap_response(cwmp_main->session->tree_out, "Upload"); + mxml_node_t *t = build_top_body_soap_response(cwmp_ctx.session->tree_out, "Upload"); if (t == NULL) { snprintf(err_msg, sizeof(err_msg), "Failed to build SOAP message for upload response"); error = FAULT_CPE_INTERNAL_ERROR; @@ -2279,11 +2279,11 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc) count_upload_queue++; upload->scheduled_time = scheduled_time; } - if ((cwmp_main->upload_id < 0) || (cwmp_main->upload_id >= MAX_INT_ID)) { - cwmp_main->upload_id = 0; + if ((cwmp_ctx.upload_id < 0) || (cwmp_ctx.upload_id >= MAX_INT_ID)) { + cwmp_ctx.upload_id = 0; } - cwmp_main->upload_id++; - upload->id = cwmp_main->upload_id; + cwmp_ctx.upload_id++; + upload->id = cwmp_ctx.upload_id; bkp_session_insert_upload(upload); bkp_session_save(); upload->handler_timer.cb = cwmp_start_upload; @@ -2316,17 +2316,17 @@ int cwmp_handle_rpc_cpe_fault(struct rpc *rpc) { mxml_node_t *body; - body = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND); + body = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND); struct xml_data_struct fault_xml_attrs = {0}; - char *faultcode = (FAULT_CPE_ARRAY[cwmp_main->session->fault_code].TYPE == FAULT_CPE_TYPE_CLIENT) ? "Client" : "Server"; + char *faultcode = (FAULT_CPE_ARRAY[cwmp_ctx.session->fault_code].TYPE == FAULT_CPE_TYPE_CLIENT) ? "Client" : "Server"; char *faultstring = strdup("CWMP fault"); if (!faultstring) { return -1; } - int fault_code = (int)strtol(cwmp_main->session->fault_code ? FAULT_CPE_ARRAY[cwmp_main->session->fault_code].CODE : "0", NULL, 10); - char *fault_string = CWMP_STRLEN(cwmp_main->session->fault_msg) ? strdup(cwmp_main->session->fault_msg) : strdup(FAULT_CPE_ARRAY[cwmp_main->session->fault_code].DESCRIPTION); + int fault_code = (int)strtol(cwmp_ctx.session->fault_code ? FAULT_CPE_ARRAY[cwmp_ctx.session->fault_code].CODE : "0", NULL, 10); + char *fault_string = CWMP_STRLEN(cwmp_ctx.session->fault_msg) ? strdup(cwmp_ctx.session->fault_msg) : strdup(FAULT_CPE_ARRAY[cwmp_ctx.session->fault_code].DESCRIPTION); fault_xml_attrs.fault_code = &fault_code; fault_xml_attrs.fault_string = &fault_string; @@ -2347,7 +2347,7 @@ int cwmp_handle_rpc_cpe_fault(struct rpc *rpc) spv_fault_xml_attrs.data_list = &spv_fault_xml_data_list; - body = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:Fault", NULL, NULL, MXML_DESCEND); + body = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "cwmp:Fault", NULL, NULL, MXML_DESCEND); if (body == NULL) return -1; @@ -2365,12 +2365,12 @@ int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code, const char *f { CWMP_LOG(INFO, "Fault detected"); - cwmp_main->session->fault_code = fault_code; - snprintf(cwmp_main->session->fault_msg, sizeof(cwmp_main->session->fault_msg), "%s", fault_msg ? fault_msg : ""); + cwmp_ctx.session->fault_code = fault_code; + snprintf(cwmp_ctx.session->fault_msg, sizeof(cwmp_ctx.session->fault_msg), "%s", fault_msg ? fault_msg : ""); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_out); - if (xml_prepare_msg_out(cwmp_main->session)) + if (xml_prepare_msg_out(cwmp_ctx.session)) return -1; CWMP_LOG(INFO, "Preparing the Fault message"); @@ -2417,14 +2417,14 @@ void load_forced_inform_json(void) struct blob_attr *forced_inform_list = NULL; int rem = 0; - if (!file_exists(cwmp_main->conf.forced_inform_json)) + if (!file_exists(cwmp_ctx.conf.forced_inform_json)) return; CWMP_MEMSET(&bbuf, 0, sizeof(struct blob_buf)); blob_buf_init(&bbuf, 0); - if (blobmsg_add_json_from_file(&bbuf, cwmp_main->conf.forced_inform_json) == false) { - CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_main->conf.forced_inform_json); + if (blobmsg_add_json_from_file(&bbuf, cwmp_ctx.conf.forced_inform_json) == false) { + CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp_ctx.conf.forced_inform_json); blob_buf_free(&bbuf); return; } @@ -2434,7 +2434,7 @@ void load_forced_inform_json(void) blobmsg_parse(p, 1, tb, blobmsg_data(bbuf.head), blobmsg_len(bbuf.head)); if (tb[0] == NULL) { - CWMP_LOG(WARNING, "The JSON file %s doesn't contain a forced inform parameters list", cwmp_main->conf.forced_inform_json); + CWMP_LOG(WARNING, "The JSON file %s doesn't contain a forced inform parameters list", cwmp_ctx.conf.forced_inform_json); blob_buf_free(&bbuf); return; } diff --git a/src/session.c b/src/session.c index 3d3d87c..b3207d8 100644 --- a/src/session.c +++ b/src/session.c @@ -53,13 +53,13 @@ unsigned int end_session_flag = 0; int create_cwmp_session_structure() { - cwmp_main->session = calloc(1, sizeof(struct session)); - if (cwmp_main->session == NULL) + cwmp_ctx.session = calloc(1, sizeof(struct session)); + if (cwmp_ctx.session == NULL) return CWMP_GEN_ERR; - INIT_LIST_HEAD(&(cwmp_main->session->events)); - INIT_LIST_HEAD(&(cwmp_main->session->head_rpc_acs)); - cwmp_main->session->session_status.is_heartbeat = false; - cwmp_main->session->session_status.next_heartbeat = false; + INIT_LIST_HEAD(&(cwmp_ctx.session->events)); + INIT_LIST_HEAD(&(cwmp_ctx.session->head_rpc_acs)); + cwmp_ctx.session->session_status.is_heartbeat = false; + cwmp_ctx.session->session_status.next_heartbeat = false; return CWMP_OK; } @@ -67,12 +67,12 @@ int cwmp_session_init() { struct rpc *rpc_acs; - cwmp_main->cwmp_cr_event = 0; + cwmp_ctx.cwmp_cr_event = 0; /* * Set Required methods as initial value of */ - if (cwmp_main->conf.acs_getrpc) { + if (cwmp_ctx.conf.acs_getrpc) { rpc_acs = cwmp_add_session_rpc_acs_head(RPC_ACS_GET_RPC_METHODS); if (rpc_acs == NULL) return CWMP_GEN_ERR; @@ -82,7 +82,7 @@ int cwmp_session_init() if (rpc_acs == NULL) return CWMP_GEN_ERR; - cwmp_main->session->rpc_cpe = NULL; + cwmp_ctx.session->rpc_cpe = NULL; set_cwmp_session_status(SESSION_RUNNING, 0); return CWMP_OK; @@ -90,7 +90,7 @@ int cwmp_session_init() int clean_cwmp_session_structure() { - FREE(cwmp_main->session); + FREE(cwmp_ctx.session); return 0; } @@ -133,7 +133,7 @@ int cwmp_schedule_rpc() } while (1) { - list_for_each (ilist, &(cwmp_main->session->head_rpc_acs)) { + list_for_each (ilist, &(cwmp_ctx.session->head_rpc_acs)) { rpc_acs = list_entry(ilist, struct rpc, list); if (rpc_acs_methods[rpc_acs->type].acs_support == RPC_ACS_NOT_SUPPORT) { CWMP_LOG(WARNING, "The RPC method %s is not included in the RPCs list supported by the ACS", rpc_acs_methods[rpc_acs->type].name); @@ -163,35 +163,35 @@ int cwmp_schedule_rpc() if (rpc_acs_methods[rpc_acs->type].extra_clean != NULL) rpc_acs_methods[rpc_acs->type].extra_clean(rpc_acs); cwmp_session_rpc_destructor(rpc_acs); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); - if (cwmp_main->session->hold_request || cwmp_stop) + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); + if (cwmp_ctx.session->hold_request || cwmp_stop) break; } CWMP_LOG(INFO, "Send empty message to the ACS"); if (xml_send_message(NULL) || cwmp_stop) goto retry; - if (!cwmp_main->session->tree_in || cwmp_stop) + if (!cwmp_ctx.session->tree_in || cwmp_stop) goto next; CWMP_LOG(INFO, "Receive request from the ACS"); if (xml_handle_message() || cwmp_stop) goto retry; - while (cwmp_main->session->rpc_cpe) { - CWMP_LOG(INFO, "Preparing the %s%s message", rpc_cpe_methods[cwmp_main->session->rpc_cpe->type].name, (cwmp_main->session->rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : ""); - if (cwmp_rpc_cpe_handle_message(cwmp_main->session->rpc_cpe) || cwmp_stop) + 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) || cwmp_stop) goto retry; - MXML_DELETE(cwmp_main->session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_in); - CWMP_LOG(INFO, "Send the %s%s message to the ACS", rpc_cpe_methods[cwmp_main->session->rpc_cpe->type].name, (cwmp_main->session->rpc_cpe->type != RPC_CPE_FAULT) ? "Response" : ""); - if (xml_send_message(cwmp_main->session->rpc_cpe) || cwmp_stop) + 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) || cwmp_stop) goto retry; - MXML_DELETE(cwmp_main->session->tree_out); - FREE(cwmp_main->session->rpc_cpe); + MXML_DELETE(cwmp_ctx.session->tree_out); + FREE(cwmp_ctx.session->rpc_cpe); - if (!cwmp_main->session->tree_in || cwmp_stop) + if (!cwmp_ctx.session->tree_in || cwmp_stop) break; CWMP_LOG(INFO, "Receive request from the ACS"); @@ -200,26 +200,26 @@ int cwmp_schedule_rpc() } next: - if (cwmp_main->session->head_rpc_acs.next == &(cwmp_main->session->head_rpc_acs)) + if (cwmp_ctx.session->head_rpc_acs.next == &(cwmp_ctx.session->head_rpc_acs)) break; - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); } - cwmp_main->session->error = CWMP_OK; + cwmp_ctx.session->error = CWMP_OK; goto end; retry: CWMP_LOG(INFO, "RPC Failed"); - cwmp_main->session->error = CWMP_RETRY_SESSION; + cwmp_ctx.session->error = CWMP_RETRY_SESSION; event_remove_noretry_event_container(); end: - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); icwmp_http_client_exit(); xml_exit(); - return cwmp_main->session->error; + return cwmp_ctx.session->error; } static int cwmp_get_retry_interval(void) @@ -227,9 +227,9 @@ static int cwmp_get_retry_interval(void) unsigned int retry_count = 0; double min = 0; double max = 0; - int m = cwmp_main->conf.retry_min_wait_interval; - int k = cwmp_main->conf.retry_interval_multiplier; - int exp = cwmp_main->retry_count_session; + int m = cwmp_ctx.conf.retry_min_wait_interval; + int k = cwmp_ctx.conf.retry_interval_multiplier; + int exp = cwmp_ctx.retry_count_session; if (exp == 0) return MAX_INT32; @@ -276,33 +276,32 @@ static void set_cwmp_session_status_state(int status) void set_cwmp_session_status(int status, int retry_time) { - CWMP_LOG(DEBUG, "%s:%d entry", __func__, __LINE__); - cwmp_main->session->session_status.last_status = status; + cwmp_ctx.session->session_status.last_status = status; set_cwmp_session_status_state(status); + if (status == SESSION_SUCCESS) { - cwmp_main->session->session_status.last_end_time = time(NULL); - cwmp_main->session->session_status.next_retry = 0; - cwmp_main->session->session_status.success_session++; + cwmp_ctx.session->session_status.last_end_time = time(NULL); + cwmp_ctx.session->session_status.next_retry = 0; + cwmp_ctx.session->session_status.success_session++; } else if (status == SESSION_RUNNING) { - cwmp_main->session->session_status.last_end_time = 0; - cwmp_main->session->session_status.next_retry = 0; - cwmp_main->session->session_status.last_start_time = time(NULL); + cwmp_ctx.session->session_status.last_end_time = 0; + cwmp_ctx.session->session_status.next_retry = 0; + cwmp_ctx.session->session_status.last_start_time = time(NULL); } else { - cwmp_main->session->session_status.last_end_time = time(NULL); - cwmp_main->session->session_status.next_retry = time(NULL) + retry_time; - cwmp_main->session->session_status.failure_session++; + cwmp_ctx.session->session_status.last_end_time = time(NULL); + cwmp_ctx.session->session_status.next_retry = time(NULL) + retry_time; + cwmp_ctx.session->session_status.failure_session++; } - CWMP_LOG(DEBUG, "%s:%d exit", __func__, __LINE__); } void rpc_exit() { - if (cwmp_main == NULL || cwmp_main->session == NULL) + if (cwmp_ctx.session == NULL) return; - if (!list_empty(&(cwmp_main->session->head_rpc_acs))) { - while (cwmp_main->session->head_rpc_acs.next != &(cwmp_main->session->head_rpc_acs)) { - struct rpc *rpc = list_entry(cwmp_main->session->head_rpc_acs.next, struct rpc, list); + if (!list_empty(&(cwmp_ctx.session->head_rpc_acs))) { + while (cwmp_ctx.session->head_rpc_acs.next != &(cwmp_ctx.session->head_rpc_acs)) { + struct rpc *rpc = list_entry(cwmp_ctx.session->head_rpc_acs.next, struct rpc, list); if (!rpc) break; if (rpc_acs_methods[rpc->type].extra_clean != NULL) @@ -310,17 +309,17 @@ void rpc_exit() cwmp_session_rpc_destructor(rpc); } } - FREE(cwmp_main->session->rpc_cpe); + FREE(cwmp_ctx.session->rpc_cpe); } static void schedule_session_retry(void) { - cwmp_main->retry_count_session++; + cwmp_ctx.retry_count_session++; int t = cwmp_get_retry_interval(); - CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_main->retry_count_session, t); + CWMP_LOG(INFO, "Retry session, retry count = %d, retry in %ds", cwmp_ctx.retry_count_session, t); trigger_periodic_notify_check(); - if (!cwmp_main->session->session_status.is_heartbeat) { + if (!cwmp_ctx.session->session_status.is_heartbeat) { set_cwmp_session_status(SESSION_FAILURE, t); uloop_timeout_set(&retry_session_timer, 1000 * t); } else { @@ -341,7 +340,7 @@ void start_cwmp_session(void) return; } - if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) { + if (cwmp_ctx.session->session_status.last_status == SESSION_FAILURE) { cwmp_config_load(); } @@ -357,17 +356,17 @@ void start_cwmp_session(void) /* * Value changes */ - if (!cwmp_main->session->session_status.is_heartbeat) { + if (!cwmp_ctx.session->session_status.is_heartbeat) { int is_notify = 0; if (file_exists(DM_ENABLED_NOTIFY)) { if (!event_exist_in_list(EVENT_IDX_4VALUE_CHANGE)) is_notify = check_value_change(); } - if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp_main->custom_notify_active) { - cwmp_main->custom_notify_active = false; + if (is_notify > 0 || !file_exists(DM_ENABLED_NOTIFY) || cwmp_ctx.custom_notify_active) { + cwmp_ctx.custom_notify_active = false; cwmp_update_enabled_notify_file(); } - cwmp_prepare_value_change(cwmp_main); + cwmp_prepare_value_change(); clean_list_value_change(); } /* @@ -400,49 +399,49 @@ void start_cwmp_session(void) return; } - if (cwmp_main->session->error == CWMP_RETRY_SESSION && (!list_empty(&(cwmp_main->session->events)) || (list_empty(&(cwmp_main->session->events)) && cwmp_main->cwmp_cr_event == 0))) { //CWMP Retry session + if (cwmp_ctx.session->error == CWMP_RETRY_SESSION && (!list_empty(&(cwmp_ctx.session->events)) || (list_empty(&(cwmp_ctx.session->events)) && cwmp_ctx.cwmp_cr_event == 0))) { //CWMP Retry session schedule_session_retry(); } else { save_acs_bkp_config(); - if (!cwmp_main->session->session_status.is_heartbeat) { + if (!cwmp_ctx.session->session_status.is_heartbeat) { cwmp_remove_all_session_events(); } else { remove_single_event(EVENT_IDX_14HEARTBEAT); } - cwmp_main->retry_count_session = 0; + cwmp_ctx.retry_count_session = 0; set_cwmp_session_status(SESSION_SUCCESS, 0); - if (cwmp_main->throttle_session_triggered == true) { - cwmp_main->throttle_session_triggered = false; - if (!cwmp_main->throttle_session) { + if (cwmp_ctx.throttle_session_triggered == true) { + cwmp_ctx.throttle_session_triggered = false; + if (!cwmp_ctx.throttle_session) { uloop_timeout_cancel(&throttle_session_timer); } else { - cwmp_main->throttle_session = false; + cwmp_ctx.throttle_session = false; } } } run_session_end_func(); cwmp_session_exit(); - if (cwmp_main->acs_changed) { + if (cwmp_ctx.acs_changed) { CWMP_LOG(INFO, "%s: Schedule session with new ACS since URL changed", __func__); uloop_timeout_cancel(&heartbeat_session_timer); - cwmp_main->session->session_status.next_heartbeat = true; - cwmp_main->session->session_status.is_heartbeat = false; - cwmp_main->retry_count_session = 0; + cwmp_ctx.session->session_status.next_heartbeat = true; + cwmp_ctx.session->session_status.is_heartbeat = false; + cwmp_ctx.retry_count_session = 0; trigger_cwmp_session_timer(); - cwmp_main->acs_changed = false; + cwmp_ctx.acs_changed = false; return; } CWMP_LOG(INFO, "Waiting the next session"); - if (cwmp_main->session->session_status.next_heartbeat && (cwmp_main->session->session_status.last_status == SESSION_SUCCESS)) { - cwmp_main->session->session_status.next_heartbeat = false; + if (cwmp_ctx.session->session_status.next_heartbeat && (cwmp_ctx.session->session_status.last_status == SESSION_SUCCESS)) { + cwmp_ctx.session->session_status.next_heartbeat = false; uloop_timeout_cancel(&heartbeat_session_timer); uloop_timeout_set(&heartbeat_session_timer, 1000); } else { - cwmp_main->session->session_status.is_heartbeat = false; + cwmp_ctx.session->session_status.is_heartbeat = false; trigger_periodic_notify_check(); } } @@ -461,14 +460,14 @@ void trigger_cwmp_throttle_session_timer(unsigned int delay) void cwmp_schedule_session(struct uloop_timeout *timeout __attribute__((unused))) { - cwmp_main->throttle_session = false; + cwmp_ctx.throttle_session = false; start_cwmp_session(); } void cwmp_schedule_throttle_session(struct uloop_timeout *timeout __attribute__((unused))) { - cwmp_main->throttle_session = true; + cwmp_ctx.throttle_session = true; start_cwmp_session(); } @@ -498,8 +497,8 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout) struct schedule_inform *schedule_inform = (struct schedule_inform *)session_event->extra_data; cwmp_root_cause_schedule_inform(schedule_inform); } else if (session_event->event == EVENT_IDX_14HEARTBEAT) { - cwmp_main->session->session_status.next_heartbeat = false; - cwmp_main->session->session_status.is_heartbeat = true; + cwmp_ctx.session->session_status.next_heartbeat = false; + cwmp_ctx.session->session_status.is_heartbeat = true; cwmp_add_event_container(EVENT_IDX_14HEARTBEAT, ""); start_cwmp_session(); return; @@ -524,11 +523,11 @@ void cwmp_schedule_session_with_event(struct uloop_timeout *timeout) static void cwmp_periodic_session_timer(struct uloop_timeout *timeout __attribute__((unused))) { - if (cwmp_main->conf.periodic_enable && cwmp_main->conf.period > 0) { - cwmp_main->session->session_status.next_periodic = time(NULL) + cwmp_main->conf.period; - uloop_timeout_set(&periodic_session_timer, cwmp_main->conf.period * 1000); + if (cwmp_ctx.conf.periodic_enable && cwmp_ctx.conf.period > 0) { + cwmp_ctx.session->session_status.next_periodic = time(NULL) + cwmp_ctx.conf.period; + uloop_timeout_set(&periodic_session_timer, cwmp_ctx.conf.period * 1000); } - if (cwmp_main->conf.periodic_enable) { + if (cwmp_ctx.conf.periodic_enable) { struct session_timer_event *periodic_inform_event = calloc(1, sizeof(struct session_timer_event)); periodic_inform_event->session_timer_evt.cb = cwmp_schedule_session_with_event; @@ -542,47 +541,47 @@ long int cwmp_periodic_session_time(void) long int delta_time; long int periodic_time; - delta_time = time(NULL) - cwmp_main->conf.time; + delta_time = time(NULL) - cwmp_ctx.conf.time; if(delta_time > 0) - periodic_time = cwmp_main->conf.period - (delta_time % cwmp_main->conf.period); + periodic_time = cwmp_ctx.conf.period - (delta_time % cwmp_ctx.conf.period); else - periodic_time = (-delta_time) % cwmp_main->conf.period; + periodic_time = (-delta_time) % cwmp_ctx.conf.period; - cwmp_main->session->session_status.next_periodic = time(NULL) + periodic_time; + cwmp_ctx.session->session_status.next_periodic = time(NULL) + periodic_time; return periodic_time; } void initiate_cwmp_periodic_session_feature() { uloop_timeout_cancel(&periodic_session_timer); - if (cwmp_main->conf.periodic_enable && cwmp_main->conf.period > 0) { - if (cwmp_main->conf.time > 0){ - CWMP_LOG(INFO, "Init periodic inform: periodic_inform time = %ld, interval = %d", cwmp_main->conf.time, cwmp_main->conf.period); + if (cwmp_ctx.conf.periodic_enable && cwmp_ctx.conf.period > 0) { + if (cwmp_ctx.conf.time > 0){ + CWMP_LOG(INFO, "Init periodic inform: periodic_inform time = %ld, interval = %d", cwmp_ctx.conf.time, cwmp_ctx.conf.period); uloop_timeout_set(&periodic_session_timer, cwmp_periodic_session_time() * 1000); } else { - CWMP_LOG(INFO, "Init periodic inform: interval = %d", cwmp_main->conf.period); - cwmp_main->session->session_status.next_periodic = time(NULL) + cwmp_main->conf.period; - uloop_timeout_set(&periodic_session_timer, cwmp_main->conf.period * 1000); + CWMP_LOG(INFO, "Init periodic inform: interval = %d", cwmp_ctx.conf.period); + cwmp_ctx.session->session_status.next_periodic = time(NULL) + cwmp_ctx.conf.period; + uloop_timeout_set(&periodic_session_timer, cwmp_ctx.conf.period * 1000); } } } void reinit_cwmp_periodic_session_feature() { - if (cwmp_main->conf.periodic_enable) { - if (!cwmp_main->prev_periodic_enable || (cwmp_main->prev_periodic_interval != cwmp_main->conf.period) || (cwmp_main->prev_periodic_time != cwmp_main->conf.time)) { + if (cwmp_ctx.conf.periodic_enable) { + if (!cwmp_ctx.prev_periodic_enable || (cwmp_ctx.prev_periodic_interval != cwmp_ctx.conf.period) || (cwmp_ctx.prev_periodic_time != cwmp_ctx.conf.time)) { uloop_timeout_cancel(&periodic_session_timer); - if ((cwmp_main->prev_periodic_time != cwmp_main->conf.time) && cwmp_main->conf.time > 0) + if ((cwmp_ctx.prev_periodic_time != cwmp_ctx.conf.time) && cwmp_ctx.conf.time > 0) uloop_timeout_set(&periodic_session_timer, cwmp_periodic_session_time() * 1000); else - uloop_timeout_set(&periodic_session_timer, cwmp_main->conf.period * 1000); + uloop_timeout_set(&periodic_session_timer, cwmp_ctx.conf.period * 1000); } } else uloop_timeout_cancel(&periodic_session_timer); - cwmp_main->prev_periodic_enable = cwmp_main->conf.periodic_enable; - cwmp_main->prev_periodic_interval = cwmp_main->conf.period; - cwmp_main->prev_periodic_time = cwmp_main->conf.time; + cwmp_ctx.prev_periodic_enable = cwmp_ctx.conf.periodic_enable; + cwmp_ctx.prev_periodic_interval = cwmp_ctx.conf.period; + cwmp_ctx.prev_periodic_time = cwmp_ctx.conf.time; } struct rpc *build_sessin_rcp_cpe(int type) @@ -605,7 +604,7 @@ struct rpc *cwmp_add_session_rpc_acs(int type) return NULL; } rpc_acs->type = type; - list_add_tail(&(rpc_acs->list), &(cwmp_main->session->head_rpc_acs)); + list_add_tail(&(rpc_acs->list), &(cwmp_ctx.session->head_rpc_acs)); return rpc_acs; } @@ -630,7 +629,7 @@ struct rpc *cwmp_add_session_rpc_acs_head(int type) return NULL; } rpc_acs->type = type; - list_add(&(rpc_acs->list), &(cwmp_main->session->head_rpc_acs)); + list_add(&(rpc_acs->list), &(cwmp_ctx.session->head_rpc_acs)); return rpc_acs; } @@ -725,12 +724,12 @@ int run_session_end_func(void) cwmp_selftest_diagnostics(); } - if (cwmp_main->diag_session) { + if (cwmp_ctx.diag_session) { struct session_timer_event *periodic_inform_event = calloc(1, sizeof(struct session_timer_event)); periodic_inform_event->session_timer_evt.cb = cwmp_schedule_session_with_event; periodic_inform_event->event = EVENT_IDX_8DIAGNOSTICS_COMPLETE; trigger_cwmp_session_timer_with_event(&periodic_inform_event->session_timer_evt); - cwmp_main->diag_session = false; + cwmp_ctx.diag_session = false; } if (end_session_flag & END_SESSION_DOWNLOAD) { @@ -758,10 +757,10 @@ int run_session_end_func(void) apply_change_du_state(); } - if (cwmp_main->heart_session) { + if (cwmp_ctx.heart_session) { uloop_timeout_cancel(&heartbeat_session_timer); - uloop_timeout_set(&heartbeat_session_timer, cwmp_main->heart_session_interval * 1000); - cwmp_main->heart_session = false; + uloop_timeout_set(&heartbeat_session_timer, cwmp_ctx.heart_session_interval * 1000); + cwmp_ctx.heart_session = false; } if (end_session_flag & END_SESSION_REBOOT) { diff --git a/src/ssl_utils.c b/src/ssl_utils.c index 1006026..a4ddc45 100644 --- a/src/ssl_utils.c +++ b/src/ssl_utils.c @@ -54,7 +54,7 @@ void message_compute_signature(char *msg_out, char *signature, size_t len) int result_len = 20; unsigned char result[EVP_MAX_MD_SIZE] = {0}; - HMAC(EVP_sha1(), cwmp_main->conf.acs_passwd, CWMP_STRLEN(cwmp_main->conf.acs_passwd), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result, NULL); + HMAC(EVP_sha1(), cwmp_ctx.conf.acs_passwd, CWMP_STRLEN(cwmp_ctx.conf.acs_passwd), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result, NULL); for (int i = 0; i < result_len; i++) { if (len - CWMP_STRLEN(signature) < 3) // each time 2 hex chars + '\0' at end so needed space is 3 bytes diff --git a/src/ubus_utils.c b/src/ubus_utils.c index e9755ba..4d772e5 100644 --- a/src/ubus_utils.c +++ b/src/ubus_utils.c @@ -61,11 +61,11 @@ static void interface_update_handler(struct ubus_context *ctx __attribute__((unu const char *intf_name = blobmsg_get_string(tb[0]); const char *intf_up = blobmsg_get_string(tb[1]); - if (CWMP_STRCMP(intf_up, "ifup") != 0 || CWMP_STRCMP(cwmp_main->conf.default_wan_iface, intf_name) != 0) + if (CWMP_STRCMP(intf_up, "ifup") != 0 || CWMP_STRCMP(cwmp_ctx.conf.default_wan_iface, intf_name) != 0) return; /* If the last session was failure then schedule a session */ - if (cwmp_main->session->session_status.last_status == SESSION_FAILURE) { + if (cwmp_ctx.session->session_status.last_status == SESSION_FAILURE) { CWMP_LOG(INFO, "Schedule session for interface_update on %s, since last session was failure", intf_name); trigger_cwmp_session_timer(); } @@ -74,7 +74,7 @@ static void interface_update_handler(struct ubus_context *ctx __attribute__((unu static int reload_cmd(struct blob_buf *b) { CWMP_LOG(INFO, "triggered ubus reload"); - if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) { + if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) { cwmp_set_end_session(END_SESSION_RELOAD); blobmsg_add_u32(b, "status", 0); blobmsg_add_string(b, "info", "Session running, reload at the end of the session"); @@ -89,15 +89,15 @@ static int reload_cmd(struct blob_buf *b) blobmsg_add_u32(b, "status", 0); blobmsg_add_string(b, "info", "icwmpd config reloaded"); - if (cwmp_main->acs_changed) { + if (cwmp_ctx.acs_changed) { CWMP_LOG(INFO, "%s: Schedule session with new ACS since URL changed", __func__); uloop_timeout_cancel(&session_timer); - cwmp_main->retry_count_session = 0; + cwmp_ctx.retry_count_session = 0; uloop_timeout_cancel(&heartbeat_session_timer); - cwmp_main->session->session_status.next_heartbeat = true; - cwmp_main->session->session_status.is_heartbeat = false; + cwmp_ctx.session->session_status.next_heartbeat = true; + cwmp_ctx.session->session_status.is_heartbeat = false; trigger_cwmp_session_timer(); - cwmp_main->acs_changed = false; + cwmp_ctx.acs_changed = false; } } } @@ -212,7 +212,7 @@ static time_t get_next_session_time() sched_time = schedule_inform->scheduled_time; } - time_t next_time = get_nonzero_min_time(sched_time, cwmp_main->session->session_status.next_retry, cwmp_main->session->session_status.next_periodic); + time_t next_time = get_nonzero_min_time(sched_time, cwmp_ctx.session->session_status.next_retry, cwmp_ctx.session->session_status.next_periodic); return next_time; } @@ -225,12 +225,12 @@ static void bb_add_icwmp_status(struct blob_buf *bb) } char start_time[26] = {0}; - get_time(cwmp_main->start_time, start_time, sizeof(start_time)); + get_time(cwmp_ctx.start_time, start_time, sizeof(start_time)); void *tbl = blobmsg_open_table(bb, "cwmp"); bb_add_string(bb, "status", "up"); bb_add_string(bb, "start_time", start_time); - bb_add_string(bb, "acs_url", cwmp_main->conf.acs_url); + bb_add_string(bb, "acs_url", cwmp_ctx.conf.acs_url); blobmsg_close_table(bb, tbl); } @@ -241,16 +241,16 @@ static void bb_add_icwmp_last_session(struct blob_buf *bb) char end_time[26] = {0}; void *tbl = blobmsg_open_table(bb, "last_session"); - const char *status = cwmp_main->session->session_status.last_start_time ? arr_session_status[cwmp_main->session->session_status.last_status] : "N/A"; + const char *status = cwmp_ctx.session->session_status.last_start_time ? arr_session_status[cwmp_ctx.session->session_status.last_status] : "N/A"; - if (cwmp_main->session->session_status.last_start_time) { - get_time(cwmp_main->session->session_status.last_start_time, start_time, sizeof(start_time)); + if (cwmp_ctx.session->session_status.last_start_time) { + get_time(cwmp_ctx.session->session_status.last_start_time, start_time, sizeof(start_time)); } else { snprintf(start_time, sizeof(start_time), "N/A"); } - if (cwmp_main->session->session_status.last_end_time) { - get_time(cwmp_main->session->session_status.last_end_time, end_time, sizeof(end_time)); + if (cwmp_ctx.session->session_status.last_end_time) { + get_time(cwmp_ctx.session->session_status.last_end_time, end_time, sizeof(end_time)); } else { snprintf(end_time, sizeof(end_time), "N/A"); } @@ -282,9 +282,9 @@ static void bb_add_icwmp_next_session(struct blob_buf *bb) static void bb_add_icwmp_statistics(struct blob_buf *bb) { void *tbl = blobmsg_open_table(bb, "statistics"); - blobmsg_add_u32(bb, "success_sessions", cwmp_main->session->session_status.success_session); - blobmsg_add_u32(bb, "failure_sessions", cwmp_main->session->session_status.failure_session); - blobmsg_add_u32(bb, "total_sessions", cwmp_main->session->session_status.success_session + cwmp_main->session->session_status.failure_session); + blobmsg_add_u32(bb, "success_sessions", cwmp_ctx.session->session_status.success_session); + blobmsg_add_u32(bb, "failure_sessions", cwmp_ctx.session->session_status.failure_session); + blobmsg_add_u32(bb, "total_sessions", cwmp_ctx.session->session_status.success_session + cwmp_ctx.session->session_status.failure_session); blobmsg_close_table(bb, tbl); } @@ -321,7 +321,7 @@ static const struct blobmsg_policy icwmp_inform_policy[] = { static int icwmp_inform_get_rpc_method(struct blob_buf *bb) { - if (cwmp_main->conf.acs_getrpc && cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL) + if (cwmp_ctx.conf.acs_getrpc && cwmp_add_session_rpc_acs(RPC_ACS_GET_RPC_METHODS) == NULL) return -1; blobmsg_add_u32(bb, "status", 1); @@ -334,7 +334,7 @@ static int icwmp_inform_event(struct blob_buf *bb, const char *event) { int event_code = cwmp_get_int_event_code(event); if (event_code != -1) { - if (cwmp_main->session->session_status.last_status == SESSION_RUNNING) { + if (cwmp_ctx.session->session_status.last_status == SESSION_RUNNING) { blobmsg_add_u32(bb, "status", 1); blobmsg_add_string(bb, "info", "Session already running, event will be sent at the end of the session"); } else { @@ -472,14 +472,14 @@ int icwmp_ubus_invoke(const char *obj, const char *method, struct blob_attr *msg int initiate_autonomous_complpolicy(void) { - cwmp_main->ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler)); - if (cwmp_main->ev == NULL) + cwmp_ctx.ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler)); + if (cwmp_ctx.ev == NULL) return -1; - CWMP_MEMSET(cwmp_main->ev, 0, sizeof(struct ubus_event_handler)); - cwmp_main->ev->cb = autonomous_notification_handler; + CWMP_MEMSET(cwmp_ctx.ev, 0, sizeof(struct ubus_event_handler)); + cwmp_ctx.ev->cb = autonomous_notification_handler; - int ret = ubus_register_event_handler(ubus_ctx, cwmp_main->ev, "bbfdm.event"); + int ret = ubus_register_event_handler(ubus_ctx, cwmp_ctx.ev, "bbfdm.event"); if (ret) { return -1; } @@ -489,22 +489,22 @@ int initiate_autonomous_complpolicy(void) void clean_autonomous_complpolicy(void) { - if (cwmp_main->ev == NULL) + if (cwmp_ctx.ev == NULL) return; - ubus_unregister_event_handler(ubus_ctx, cwmp_main->ev); + ubus_unregister_event_handler(ubus_ctx, cwmp_ctx.ev); } int initiate_interface_update(void) { - cwmp_main->intf_ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler)); - if (cwmp_main->intf_ev == NULL) + cwmp_ctx.intf_ev = (struct ubus_event_handler *)malloc(sizeof(struct ubus_event_handler)); + if (cwmp_ctx.intf_ev == NULL) return -1; - CWMP_MEMSET(cwmp_main->intf_ev, 0, sizeof(struct ubus_event_handler)); - cwmp_main->intf_ev->cb = interface_update_handler; + CWMP_MEMSET(cwmp_ctx.intf_ev, 0, sizeof(struct ubus_event_handler)); + cwmp_ctx.intf_ev->cb = interface_update_handler; - int ret = ubus_register_event_handler(ubus_ctx, cwmp_main->intf_ev, "network.interface"); + int ret = ubus_register_event_handler(ubus_ctx, cwmp_ctx.intf_ev, "network.interface"); if (ret) { return -1; } @@ -514,10 +514,10 @@ int initiate_interface_update(void) void clean_interface_update(void) { - if (cwmp_main->intf_ev == NULL) + if (cwmp_ctx.intf_ev == NULL) return; - ubus_unregister_event_handler(ubus_ctx, cwmp_main->intf_ev); + ubus_unregister_event_handler(ubus_ctx, cwmp_ctx.intf_ev); } static void lookup_event_cb(struct ubus_context *ctx __attribute__((unused)), diff --git a/src/uci_utils.c b/src/uci_utils.c index 4b55473..b03c266 100644 --- a/src/uci_utils.c +++ b/src/uci_utils.c @@ -106,114 +106,114 @@ static void config_get_acs_elements(struct uci_section *s) CWMP_MEMSET(acs_tb, 0, sizeof(acs_tb)); uci_parse_section(s, acs_opts, __MAX_NUM_UCI_ACS_ATTRS, acs_tb); - cwmp_main->conf.http_disable_100continue = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_HTTP_DISABLE_100CONTINUE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs http disable 100continue: %d", cwmp_main->conf.http_disable_100continue); + cwmp_ctx.conf.http_disable_100continue = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_HTTP_DISABLE_100CONTINUE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs http disable 100continue: %d", cwmp_ctx.conf.http_disable_100continue); - cwmp_main->conf.insecure_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_INSECURE_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs insecure enable: %d", cwmp_main->conf.insecure_enable); + cwmp_ctx.conf.insecure_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_INSECURE_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs insecure enable: %d", cwmp_ctx.conf.insecure_enable); - cwmp_main->conf.dhcp_discovery = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_DISCOVERY])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs dhcp discovery: %d", cwmp_main->conf.dhcp_discovery); + cwmp_ctx.conf.dhcp_discovery = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_DISCOVERY])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs dhcp discovery: %d", cwmp_ctx.conf.dhcp_discovery); char *get_rpc = get_value_from_uci_option(acs_tb[UCI_ACS_GETRPC]); - cwmp_main->conf.acs_getrpc = CWMP_STRLEN(get_rpc) ? str_to_bool(get_rpc) : true; - CWMP_LOG(DEBUG, "CWMP CONFIG - acs get rpc: %d", cwmp_main->conf.acs_getrpc); + cwmp_ctx.conf.acs_getrpc = CWMP_STRLEN(get_rpc) ? str_to_bool(get_rpc) : true; + CWMP_LOG(DEBUG, "CWMP CONFIG - acs get rpc: %d", cwmp_ctx.conf.acs_getrpc); char *url = get_value_from_uci_option(acs_tb[UCI_ACS_URL]); char *dhcp_url = get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_URL]); - char *new_url = cwmp_main->conf.dhcp_discovery ? (CWMP_STRLEN(dhcp_url) ? dhcp_url : url) : url; + char *new_url = cwmp_ctx.conf.dhcp_discovery ? (CWMP_STRLEN(dhcp_url) ? dhcp_url : url) : url; - if (CWMP_STRCMP(cwmp_main->conf.acs_url, new_url) != 0) { - if (CWMP_STRLEN(cwmp_main->conf.acs_url) != 0 && CWMP_STRLEN(new_url) != 0) - cwmp_main->acs_changed = true; + if (CWMP_STRCMP(cwmp_ctx.conf.acs_url, new_url) != 0) { + if (CWMP_STRLEN(cwmp_ctx.conf.acs_url) != 0 && CWMP_STRLEN(new_url) != 0) + cwmp_ctx.acs_changed = true; - snprintf(cwmp_main->conf.acs_url, sizeof(cwmp_main->conf.acs_url), "%s", new_url); + snprintf(cwmp_ctx.conf.acs_url, sizeof(cwmp_ctx.conf.acs_url), "%s", new_url); } - CWMP_LOG(DEBUG, "CWMP CONFIG - acs url: %s", cwmp_main->conf.acs_url); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs url: %s", cwmp_ctx.conf.acs_url); - snprintf(cwmp_main->conf.acs_userid, sizeof(cwmp_main->conf.acs_userid), "%s", get_value_from_uci_option(acs_tb[UCI_ACS_USERID])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs username: %s", cwmp_main->conf.acs_userid); + snprintf(cwmp_ctx.conf.acs_userid, sizeof(cwmp_ctx.conf.acs_userid), "%s", get_value_from_uci_option(acs_tb[UCI_ACS_USERID])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs username: %s", cwmp_ctx.conf.acs_userid); - snprintf(cwmp_main->conf.acs_passwd, sizeof(cwmp_main->conf.acs_passwd), "%s", get_value_from_uci_option(acs_tb[UCI_ACS_PASSWR])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs password: %s", cwmp_main->conf.acs_passwd); + snprintf(cwmp_ctx.conf.acs_passwd, sizeof(cwmp_ctx.conf.acs_passwd), "%s", get_value_from_uci_option(acs_tb[UCI_ACS_PASSWR])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs password: %s", cwmp_ctx.conf.acs_passwd); char *cert = get_value_from_uci_option(acs_tb[UCI_ACS_SSL_CAPATH]); if (folder_exists(cert) == true) { - snprintf(cwmp_main->conf.acs_ssl_capath, sizeof(cwmp_main->conf.acs_ssl_capath), "%s", cert); + snprintf(cwmp_ctx.conf.acs_ssl_capath, sizeof(cwmp_ctx.conf.acs_ssl_capath), "%s", cert); } else if (file_exists(cert) == true) { - snprintf(cwmp_main->conf.acs_ssl_cabundle, sizeof(cwmp_main->conf.acs_ssl_cabundle), "%s", cert); + snprintf(cwmp_ctx.conf.acs_ssl_cabundle, sizeof(cwmp_ctx.conf.acs_ssl_cabundle), "%s", cert); } CWMP_LOG(DEBUG, "CWMP CONFIG - acs ssl capath: %s", cert); - cwmp_main->conf.retry_min_wait_interval = DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL; + cwmp_ctx.conf.retry_min_wait_interval = DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL; char *acs_retry_min_wait_interval = get_value_from_uci_option(acs_tb[UCI_ACS_RETRY_MIN_WAIT_INTERVAL]); char *acs_dhcp_retry_min_wait_interval = get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_RETRY_MIN_WAIT_INTERVAL]); - char *op_interval = cwmp_main->conf.dhcp_discovery ? acs_dhcp_retry_min_wait_interval : acs_retry_min_wait_interval; + char *op_interval = cwmp_ctx.conf.dhcp_discovery ? acs_dhcp_retry_min_wait_interval : acs_retry_min_wait_interval; if (strlen(op_interval) != 0) { - if (cwmp_main->conf.amd_version >= AMD_3) { + if (cwmp_ctx.conf.amd_version >= AMD_3) { int a = (int)strtol(op_interval, NULL, 10); - cwmp_main->conf.retry_min_wait_interval = (a <= 65535 && a >= 1) ? a : DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL; + cwmp_ctx.conf.retry_min_wait_interval = (a <= 65535 && a >= 1) ? a : DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL; } } - CWMP_LOG(DEBUG, "CWMP CONFIG - acs retry minimum wait interval: %d", cwmp_main->conf.retry_min_wait_interval); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs retry minimum wait interval: %d", cwmp_ctx.conf.retry_min_wait_interval); - cwmp_main->conf.retry_interval_multiplier = DEFAULT_RETRY_INTERVAL_MULTIPLIER; + cwmp_ctx.conf.retry_interval_multiplier = DEFAULT_RETRY_INTERVAL_MULTIPLIER; char *acs_retry_interval_multiplier = get_value_from_uci_option(acs_tb[UCI_ACS_RETRY_INTERVAL_MULTIPLIER]); char *acs_dhcp_retry_interval_multiplier = get_value_from_uci_option(acs_tb[UCI_ACS_DHCP_RETRY_INTERVAL_MULTIPLIER]); - char *op_multi = cwmp_main->conf.dhcp_discovery ? acs_dhcp_retry_interval_multiplier : acs_retry_interval_multiplier; + char *op_multi = cwmp_ctx.conf.dhcp_discovery ? acs_dhcp_retry_interval_multiplier : acs_retry_interval_multiplier; if (strlen(op_multi) != 0) { - if (cwmp_main->conf.amd_version >= AMD_3) { + if (cwmp_ctx.conf.amd_version >= AMD_3) { int a = (int)strtol(op_multi, NULL, 10); - cwmp_main->conf.retry_interval_multiplier = (a <= 65535 && a >= 1000) ? a : DEFAULT_RETRY_INTERVAL_MULTIPLIER; + cwmp_ctx.conf.retry_interval_multiplier = (a <= 65535 && a >= 1000) ? a : DEFAULT_RETRY_INTERVAL_MULTIPLIER; } } - CWMP_LOG(DEBUG, "CWMP CONFIG - acs retry interval multiplier: %d", cwmp_main->conf.retry_interval_multiplier); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs retry interval multiplier: %d", cwmp_ctx.conf.retry_interval_multiplier); - cwmp_main->conf.compression = COMP_NONE; + cwmp_ctx.conf.compression = COMP_NONE; char *acs_comp = get_value_from_uci_option(acs_tb[UCI_ACS_COMPRESSION]); - if (cwmp_main->conf.amd_version >= AMD_5 && strlen(acs_comp) != 0) { + if (cwmp_ctx.conf.amd_version >= AMD_5 && strlen(acs_comp) != 0) { if (strcasecmp(acs_comp, "gzip") == 0) { - cwmp_main->conf.compression = COMP_GZIP; + cwmp_ctx.conf.compression = COMP_GZIP; } else if (strcasecmp(acs_comp, "deflate") == 0) { - cwmp_main->conf.compression = COMP_DEFLATE; + cwmp_ctx.conf.compression = COMP_DEFLATE; } else { - cwmp_main->conf.compression = COMP_NONE; + cwmp_ctx.conf.compression = COMP_NONE; } } - cwmp_main->conf.time = 0; + cwmp_ctx.conf.time = 0; char *time = get_value_from_uci_option(acs_tb[UCI_ACS_PERIODIC_INFORM_TIME]); if (strlen(time) != 0) { - cwmp_main->conf.time = convert_datetime_to_timestamp(time); + cwmp_ctx.conf.time = convert_datetime_to_timestamp(time); } - cwmp_main->conf.period = PERIOD_INFORM_DEFAULT; + cwmp_ctx.conf.period = PERIOD_INFORM_DEFAULT; char *inform_interval = get_value_from_uci_option(acs_tb[UCI_ACS_PERIODIC_INFORM_INTERVAL]); if (strlen(inform_interval) != 0) { int a = (int)strtol(inform_interval, NULL, 10); - cwmp_main->conf.period = (a >= PERIOD_INFORM_MIN) ? a : PERIOD_INFORM_DEFAULT; + cwmp_ctx.conf.period = (a >= PERIOD_INFORM_MIN) ? a : PERIOD_INFORM_DEFAULT; } - CWMP_LOG(DEBUG, "CWMP CONFIG - acs periodic inform: %d", cwmp_main->conf.period); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs periodic inform: %d", cwmp_ctx.conf.period); - cwmp_main->conf.periodic_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_PERIODIC_INFORM_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs periodic enable: %d", cwmp_main->conf.periodic_enable); + cwmp_ctx.conf.periodic_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_PERIODIC_INFORM_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs periodic enable: %d", cwmp_ctx.conf.periodic_enable); - cwmp_main->conf.heart_beat_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_HEARTBEAT_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs heart beat enable: %d", cwmp_main->conf.heart_beat_enable); + cwmp_ctx.conf.heart_beat_enable = str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_HEARTBEAT_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs heart beat enable: %d", cwmp_ctx.conf.heart_beat_enable); - cwmp_main->conf.heartbeat_interval = 30; + cwmp_ctx.conf.heartbeat_interval = 30; char *heartbeat_interval = get_value_from_uci_option(acs_tb[UCI_ACS_HEARTBEAT_INTERVAL]); if (strlen(heartbeat_interval) != 0) { int a = (int)strtol(heartbeat_interval, NULL, 10); - cwmp_main->conf.heartbeat_interval = a; + cwmp_ctx.conf.heartbeat_interval = a; } - CWMP_LOG(DEBUG, "CWMP CONFIG - acs heartbeat interval: %d", cwmp_main->conf.heartbeat_interval); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs heartbeat interval: %d", cwmp_ctx.conf.heartbeat_interval); - cwmp_main->conf.heart_time = 0; + cwmp_ctx.conf.heart_time = 0; char *heartbeat_time = get_value_from_uci_option(acs_tb[UCI_ACS_HEARTBEAT_TIME]); if (strlen(heartbeat_time) != 0) { - cwmp_main->conf.heart_time = convert_datetime_to_timestamp(heartbeat_time); + cwmp_ctx.conf.heart_time = convert_datetime_to_timestamp(heartbeat_time); } } @@ -275,143 +275,143 @@ static void config_get_cpe_elements(struct uci_section *s) CWMP_MEMSET(cpe_tb, 0, sizeof(cpe_tb)); uci_parse_section(s, cpe_opts, __MAX_NUM_UCI_CPE_ATTRS, cpe_tb); - snprintf(cwmp_main->conf.cpe_userid, sizeof(cwmp_main->conf.cpe_userid), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_USER_ID])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe username: %s", cwmp_main->conf.cpe_userid); + snprintf(cwmp_ctx.conf.cpe_userid, sizeof(cwmp_ctx.conf.cpe_userid), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_USER_ID])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe username: %s", cwmp_ctx.conf.cpe_userid); - snprintf(cwmp_main->conf.cpe_passwd, sizeof(cwmp_main->conf.cpe_passwd), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_PASSWD])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe password: %s", cwmp_main->conf.cpe_passwd); + snprintf(cwmp_ctx.conf.cpe_passwd, sizeof(cwmp_ctx.conf.cpe_passwd), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_PASSWD])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe password: %s", cwmp_ctx.conf.cpe_passwd); - cwmp_main->conf.cr_timeout = DEFAULT_CR_TIMEOUT; + cwmp_ctx.conf.cr_timeout = DEFAULT_CR_TIMEOUT; char *tm_out = get_value_from_uci_option(cpe_tb[UCI_CPE_CON_REQ_TIMEOUT]); if (strlen(tm_out) != 0) { int a = strtod(tm_out, NULL); if (a > 0) { - cwmp_main->conf.cr_timeout = a; + cwmp_ctx.conf.cr_timeout = a; } } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request timeout: %d", cwmp_main->conf.cr_timeout); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request timeout: %d", cwmp_ctx.conf.cr_timeout); - cwmp_main->conf.connection_request_port = DEFAULT_CONNECTION_REQUEST_PORT; + cwmp_ctx.conf.connection_request_port = DEFAULT_CONNECTION_REQUEST_PORT; char *port = get_value_from_uci_option(cpe_tb[UCI_CPE_PORT]); if (strlen(port) != 0) { int a = (int)strtol(port, NULL, 10); - cwmp_main->conf.connection_request_port = (a != 0) ? a : DEFAULT_CONNECTION_REQUEST_PORT; + cwmp_ctx.conf.connection_request_port = (a != 0) ? a : DEFAULT_CONNECTION_REQUEST_PORT; } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request port: %d", cwmp_main->conf.connection_request_port); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request port: %d", cwmp_ctx.conf.connection_request_port); char *crpath = get_value_from_uci_option(cpe_tb[UCI_CPE_CRPATH]); if (CWMP_STRLEN(crpath) == 0) { - snprintf(cwmp_main->conf.connection_request_path, sizeof(cwmp_main->conf.connection_request_path), "/"); + snprintf(cwmp_ctx.conf.connection_request_path, sizeof(cwmp_ctx.conf.connection_request_path), "/"); } else { if (crpath[0] == '/') { crpath = crpath + 1; } - snprintf(cwmp_main->conf.connection_request_path, sizeof(cwmp_main->conf.connection_request_path), "/%s", crpath); + snprintf(cwmp_ctx.conf.connection_request_path, sizeof(cwmp_ctx.conf.connection_request_path), "/%s", crpath); } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request path: %s", cwmp_main->conf.connection_request_path); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe connection request path: %s", cwmp_ctx.conf.connection_request_path); - cwmp_main->conf.periodic_notify_enable = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_NOTIFY_PERIODIC_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe periodic notify enable: %d", cwmp_main->conf.periodic_notify_enable); + cwmp_ctx.conf.periodic_notify_enable = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_NOTIFY_PERIODIC_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe periodic notify enable: %d", cwmp_ctx.conf.periodic_notify_enable); - cwmp_main->conf.periodic_notify_interval = DEFAULT_NOTIFY_PERIOD; + cwmp_ctx.conf.periodic_notify_interval = DEFAULT_NOTIFY_PERIOD; char *notify_period = get_value_from_uci_option(cpe_tb[UCI_CPE_NOTIFY_PERIOD]); if (strlen(notify_period) != 0) { int a = (int)strtol(notify_period, NULL, 10); - cwmp_main->conf.periodic_notify_interval = (a != 0) ? a : DEFAULT_NOTIFY_PERIOD; + cwmp_ctx.conf.periodic_notify_interval = (a != 0) ? a : DEFAULT_NOTIFY_PERIOD; } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe periodic notify interval: %d", cwmp_main->conf.periodic_notify_interval); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe periodic notify interval: %d", cwmp_ctx.conf.periodic_notify_interval); - cwmp_main->conf.schedule_reboot = 0; + cwmp_ctx.conf.schedule_reboot = 0; char *schedule_reboot = get_value_from_uci_option(cpe_tb[UCI_CPE_SCHEDULE_REBOOT]); if (strlen(schedule_reboot) != 0) { - cwmp_main->conf.schedule_reboot = convert_datetime_to_timestamp(schedule_reboot); + cwmp_ctx.conf.schedule_reboot = convert_datetime_to_timestamp(schedule_reboot); } - cwmp_main->conf.delay_reboot = -1; + cwmp_ctx.conf.delay_reboot = -1; char *delay_reboot = get_value_from_uci_option(cpe_tb[UCI_CPE_DELAY_REBOOT]); if (strlen(delay_reboot) != 0) { int a = (int)strtol(delay_reboot, NULL, 10); - cwmp_main->conf.delay_reboot = (a > 0) ? a : -1; + cwmp_ctx.conf.delay_reboot = (a > 0) ? a : -1; } - cwmp_main->conf.active_notif_throttle = 0; + cwmp_ctx.conf.active_notif_throttle = 0; char *notify_thottle = get_value_from_uci_option(cpe_tb[UCI_CPE_ACTIVE_NOTIF_THROTTLE]); if (strlen(notify_thottle) != 0) { int a = (int)strtol(notify_thottle, NULL, 10); - cwmp_main->conf.active_notif_throttle = (a > 0) ? a : 0; + cwmp_ctx.conf.active_notif_throttle = (a > 0) ? a : 0; } - cwmp_main->conf.md_notif_limit = 0; + cwmp_ctx.conf.md_notif_limit = 0; char *notify_limit = get_value_from_uci_option(cpe_tb[UCI_CPE_MANAGEABLE_DEVICES_NOTIF_LIMIT]); if (strlen(notify_limit) != 0) { int a = (int)strtol(notify_limit, NULL, 10); - cwmp_main->conf.md_notif_limit = (a > 0) ? a : 0; + cwmp_ctx.conf.md_notif_limit = (a > 0) ? a : 0; } - cwmp_main->conf.session_timeout = DEFAULT_SESSION_TIMEOUT; + cwmp_ctx.conf.session_timeout = DEFAULT_SESSION_TIMEOUT; char *session_timeout = get_value_from_uci_option(cpe_tb[UCI_CPE_SESSION_TIMEOUT]); if (strlen(session_timeout) != 0) { int a = (int)strtol(session_timeout, NULL, 10); - cwmp_main->conf.session_timeout = (a >= 1) ? a : DEFAULT_SESSION_TIMEOUT; + cwmp_ctx.conf.session_timeout = (a >= 1) ? a : DEFAULT_SESSION_TIMEOUT; } - cwmp_main->conf.instance_mode = DEFAULT_INSTANCE_MODE; + cwmp_ctx.conf.instance_mode = DEFAULT_INSTANCE_MODE; char *instance_mode = get_value_from_uci_option(cpe_tb[UCI_CPE_INSTANCE_MODE]); if (strlen(instance_mode) != 0) { if (CWMP_STRCMP(instance_mode, "InstanceNumber") == 0) { - cwmp_main->conf.instance_mode = INSTANCE_MODE_NUMBER; + cwmp_ctx.conf.instance_mode = INSTANCE_MODE_NUMBER; } else { - cwmp_main->conf.instance_mode = INSTANCE_MODE_ALIAS; + cwmp_ctx.conf.instance_mode = INSTANCE_MODE_ALIAS; } } - snprintf(cwmp_main->conf.custom_notify_json, sizeof(cwmp_main->conf.custom_notify_json), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_JSON_CUSTOM_NOTIFY_FILE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe custom notify json path: %s", cwmp_main->conf.custom_notify_json); + snprintf(cwmp_ctx.conf.custom_notify_json, sizeof(cwmp_ctx.conf.custom_notify_json), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_JSON_CUSTOM_NOTIFY_FILE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe custom notify json path: %s", cwmp_ctx.conf.custom_notify_json); - snprintf(cwmp_main->conf.forced_inform_json, sizeof(cwmp_main->conf.forced_inform_json), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_JSON_FORCED_INFORM_FILE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe forced inform json path: %s", cwmp_main->conf.forced_inform_json); + snprintf(cwmp_ctx.conf.forced_inform_json, sizeof(cwmp_ctx.conf.forced_inform_json), "%s", get_value_from_uci_option(cpe_tb[UCI_CPE_JSON_FORCED_INFORM_FILE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe forced inform json path: %s", cwmp_ctx.conf.forced_inform_json); - cwmp_main->conf.force_ipv4 = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_FORCE_IPV4])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe force ipv4 enable: %d", cwmp_main->conf.force_ipv4); + cwmp_ctx.conf.force_ipv4 = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_FORCE_IPV4])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe force ipv4 enable: %d", cwmp_ctx.conf.force_ipv4); - cwmp_main->conf.fw_upgrade_keep_settings = cpe_tb[UCI_CPE_KEEP_SETTINGS] ? str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_KEEP_SETTINGS])) : true; - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe keep settings enable: %d", cwmp_main->conf.fw_upgrade_keep_settings); + cwmp_ctx.conf.fw_upgrade_keep_settings = cpe_tb[UCI_CPE_KEEP_SETTINGS] ? str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_KEEP_SETTINGS])) : true; + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe keep settings enable: %d", cwmp_ctx.conf.fw_upgrade_keep_settings); char *value = get_value_from_uci_option(cpe_tb[UCI_CPE_INTERFACE]); - if ((CWMP_STRLEN(cwmp_main->net.interface) == 0) && (CWMP_STRLEN(value) != 0)) { - snprintf(cwmp_main->net.interface, sizeof(cwmp_main->net.interface), "%s", value); + if ((CWMP_STRLEN(cwmp_ctx.net.interface) == 0) && (CWMP_STRLEN(value) != 0)) { + snprintf(cwmp_ctx.net.interface, sizeof(cwmp_ctx.net.interface), "%s", value); } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe INTERFACE resolved[%s], defined [%s]", cwmp_main->net.interface, value); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe INTERFACE resolved[%s], defined [%s]", cwmp_ctx.net.interface, value); value = get_value_from_uci_option(cpe_tb[UCI_CPE_DEFAULT_WAN_IFACE]); char *wan_intf = CWMP_STRLEN(value) ? value : "wan"; - if (strcmp(cwmp_main->conf.default_wan_iface, wan_intf) != 0) { - snprintf(cwmp_main->conf.default_wan_iface, sizeof(cwmp_main->conf.default_wan_iface), "%s", wan_intf); + if (strcmp(cwmp_ctx.conf.default_wan_iface, wan_intf) != 0) { + snprintf(cwmp_ctx.conf.default_wan_iface, sizeof(cwmp_ctx.conf.default_wan_iface), "%s", wan_intf); } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe default_wan_interface: %s", cwmp_main->conf.default_wan_iface); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe default_wan_interface: %s", cwmp_ctx.conf.default_wan_iface); - cwmp_main->net.use_curl_ifname = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_USE_CURL_IFNAME])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe use ifname in curl: %d", cwmp_main->net.use_curl_ifname); + cwmp_ctx.net.use_curl_ifname = str_to_bool(get_value_from_uci_option(cpe_tb[UCI_CPE_USE_CURL_IFNAME])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe use ifname in curl: %d", cwmp_ctx.net.use_curl_ifname); - cwmp_main->conf.clock_sync_timeout = DEFAULT_SYNC_TIMEOUT; + cwmp_ctx.conf.clock_sync_timeout = DEFAULT_SYNC_TIMEOUT; char *sync_time = get_value_from_uci_option(cpe_tb[UCI_CPE_CLOCK_SYNC_TIMEOUT]); if (CWMP_STRLEN(sync_time) != 0) { int val = (int)strtol(sync_time, NULL, 10); if (val >= 0 && val <= 180) { - cwmp_main->conf.clock_sync_timeout = val; + cwmp_ctx.conf.clock_sync_timeout = val; } } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe clock_sync_timeout: %d", cwmp_main->conf.clock_sync_timeout); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe clock_sync_timeout: %d", cwmp_ctx.conf.clock_sync_timeout); - cwmp_main->conf.enable = true; + cwmp_ctx.conf.enable = true; char *cwmp_enable = get_value_from_uci_option(cpe_tb[UCI_CPE_ENABLE]); if (CWMP_STRLEN(cwmp_enable) != 0) { - cwmp_main->conf.enable = str_to_bool(cwmp_enable); + cwmp_ctx.conf.enable = str_to_bool(cwmp_enable); } - CWMP_LOG(DEBUG, "CWMP CONFIG - cpe enable: %d", cwmp_main->conf.enable); + CWMP_LOG(DEBUG, "CWMP CONFIG - cpe enable: %d", cwmp_ctx.conf.enable); } static void config_get_lwn_elements(struct uci_section *s) @@ -434,19 +434,19 @@ static void config_get_lwn_elements(struct uci_section *s) CWMP_MEMSET(lwn_tb, 0, sizeof(lwn_tb)); uci_parse_section(s, acs_opts, __MAX_NUM_UCI_LWN_ATTRS, lwn_tb); - cwmp_main->conf.lwn_enable = str_to_bool(get_value_from_uci_option(lwn_tb[UCI_LWN_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - lwn enable: %d", cwmp_main->conf.lwn_enable); + cwmp_ctx.conf.lwn_enable = str_to_bool(get_value_from_uci_option(lwn_tb[UCI_LWN_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - lwn enable: %d", cwmp_ctx.conf.lwn_enable); - snprintf(cwmp_main->conf.lwn_hostname, sizeof(cwmp_main->conf.lwn_hostname), "%s", get_value_from_uci_option(lwn_tb[UCI_LWN_HOSTNAME])); - CWMP_LOG(DEBUG, "CWMP CONFIG - lwn hostname: %s", cwmp_main->conf.lwn_hostname); + snprintf(cwmp_ctx.conf.lwn_hostname, sizeof(cwmp_ctx.conf.lwn_hostname), "%s", get_value_from_uci_option(lwn_tb[UCI_LWN_HOSTNAME])); + CWMP_LOG(DEBUG, "CWMP CONFIG - lwn hostname: %s", cwmp_ctx.conf.lwn_hostname); - cwmp_main->conf.lwn_port = DEFAULT_LWN_PORT; + cwmp_ctx.conf.lwn_port = DEFAULT_LWN_PORT; char *port = get_value_from_uci_option(lwn_tb[UCI_LWN_PORT]); if (strlen(port) != 0) { int a = (int)strtol(port, NULL, 10); - cwmp_main->conf.lwn_port = a; + cwmp_ctx.conf.lwn_port = a; } - CWMP_LOG(DEBUG, "CWMP CONFIG - lwn port: %d", cwmp_main->conf.lwn_port); + CWMP_LOG(DEBUG, "CWMP CONFIG - lwn port: %d", cwmp_ctx.conf.lwn_port); } static void config_get_tc_elements(struct uci_section *s) @@ -471,17 +471,17 @@ static void config_get_tc_elements(struct uci_section *s) CWMP_MEMSET(tc_tb, 0, sizeof(tc_tb)); uci_parse_section(s, acs_opts, __MAX_NUM_UCI_TC_ATTRS, tc_tb); - cwmp_main->conf.auto_tc_enable = str_to_bool(get_value_from_uci_option(tc_tb[UCI_TC_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - tc enable: %d", cwmp_main->conf.auto_tc_enable); + cwmp_ctx.conf.auto_tc_enable = str_to_bool(get_value_from_uci_option(tc_tb[UCI_TC_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - tc enable: %d", cwmp_ctx.conf.auto_tc_enable); - snprintf(cwmp_main->conf.auto_tc_transfer_type, sizeof(cwmp_main->conf.auto_tc_transfer_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_TRANSFERTYPE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - tc transfer type: %s", cwmp_main->conf.auto_tc_transfer_type); + snprintf(cwmp_ctx.conf.auto_tc_transfer_type, sizeof(cwmp_ctx.conf.auto_tc_transfer_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_TRANSFERTYPE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - tc transfer type: %s", cwmp_ctx.conf.auto_tc_transfer_type); - snprintf(cwmp_main->conf.auto_tc_result_type, sizeof(cwmp_main->conf.auto_tc_result_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_RESULTTYPE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - tc result type: %s", cwmp_main->conf.auto_tc_result_type); + snprintf(cwmp_ctx.conf.auto_tc_result_type, sizeof(cwmp_ctx.conf.auto_tc_result_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_RESULTTYPE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - tc result type: %s", cwmp_ctx.conf.auto_tc_result_type); - snprintf(cwmp_main->conf.auto_tc_file_type, sizeof(cwmp_main->conf.auto_tc_file_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_FILETYPE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - tc file type: %s", cwmp_main->conf.auto_tc_file_type); + snprintf(cwmp_ctx.conf.auto_tc_file_type, sizeof(cwmp_ctx.conf.auto_tc_file_type), "%s", get_value_from_uci_option(tc_tb[UCI_TC_FILETYPE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - tc file type: %s", cwmp_ctx.conf.auto_tc_file_type); } static void config_get_cds_elements(struct uci_section *s) @@ -506,17 +506,17 @@ static void config_get_cds_elements(struct uci_section *s) CWMP_MEMSET(cds_tb, 0, sizeof(cds_tb)); uci_parse_section(s, cdu_opts, __MAX_NUM_UCI_CDS_ATTRS, cds_tb); - cwmp_main->conf.auto_cdu_enable = str_to_bool(get_value_from_uci_option(cds_tb[UCI_CDS_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cds enable: %d", cwmp_main->conf.auto_cdu_enable); + cwmp_ctx.conf.auto_cdu_enable = str_to_bool(get_value_from_uci_option(cds_tb[UCI_CDS_ENABLE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cds enable: %d", cwmp_ctx.conf.auto_cdu_enable); - snprintf(cwmp_main->conf.auto_cdu_oprt_type, sizeof(cwmp_main->conf.auto_cdu_oprt_type), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_OPTYPE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cds operation type: %s", cwmp_main->conf.auto_cdu_oprt_type); + snprintf(cwmp_ctx.conf.auto_cdu_oprt_type, sizeof(cwmp_ctx.conf.auto_cdu_oprt_type), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_OPTYPE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cds operation type: %s", cwmp_ctx.conf.auto_cdu_oprt_type); - snprintf(cwmp_main->conf.auto_cdu_result_type, sizeof(cwmp_main->conf.auto_cdu_result_type), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_RESULTYPE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cds result type: %s", cwmp_main->conf.auto_cdu_result_type); + snprintf(cwmp_ctx.conf.auto_cdu_result_type, sizeof(cwmp_ctx.conf.auto_cdu_result_type), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_RESULTYPE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cds result type: %s", cwmp_ctx.conf.auto_cdu_result_type); - snprintf(cwmp_main->conf.auto_cdu_fault_code, sizeof(cwmp_main->conf.auto_cdu_fault_code), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_FAULTCODE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - cds fault type: %s", cwmp_main->conf.auto_cdu_fault_code); + snprintf(cwmp_ctx.conf.auto_cdu_fault_code, sizeof(cwmp_ctx.conf.auto_cdu_fault_code), "%s", get_value_from_uci_option(cds_tb[UCI_CDS_FAULTCODE])); + CWMP_LOG(DEBUG, "CWMP CONFIG - cds fault type: %s", cwmp_ctx.conf.auto_cdu_fault_code); } static int _export_uci_package(struct uci_context *uci_ctx, char *package, const char *output_path) @@ -924,7 +924,7 @@ exit: } pthread_mutex_unlock(&mutex_config_load); - if (cwmp_main->conf.enable == false) { + if (cwmp_ctx.conf.enable == false) { CWMP_LOG(INFO, "icwmp service has been disabled."); stop_service(); } diff --git a/src/upload.c b/src/upload.c index 376db08..3179dc8 100644 --- a/src/upload.c +++ b/src/upload.c @@ -200,8 +200,8 @@ int upload_file_in_subprocess(const char *file_path, const char *url, const char blobmsg_add_string(&bbuf, "username", username); blobmsg_add_string(&bbuf, "password", password); - if (cwmp_main->net.use_curl_ifname && CWMP_STRLEN(cwmp_main->net.interface)) - blobmsg_add_string(&bbuf, "interface", cwmp_main->net.interface); + if (cwmp_ctx.net.use_curl_ifname && CWMP_STRLEN(cwmp_ctx.net.interface)) + blobmsg_add_string(&bbuf, "interface", cwmp_ctx.net.interface); char *upload_task = blobmsg_format_json(bbuf.head, true); blob_buf_free(&bbuf); @@ -368,11 +368,11 @@ void cwmp_start_upload(struct uloop_timeout *timeout) CWMP_LOG(ERROR, "Error while uploading the file: %s", pupload->url); } if (ptransfer_complete->id <= 0) { - if ((cwmp_main->tc_id < 0) || (cwmp_main->tc_id >= MAX_INT_ID)) { - cwmp_main->tc_id = 0; + if ((cwmp_ctx.tc_id < 0) || (cwmp_ctx.tc_id >= MAX_INT_ID)) { + cwmp_ctx.tc_id = 0; } - cwmp_main->tc_id++; - ptransfer_complete->id = cwmp_main->tc_id; + cwmp_ctx.tc_id++; + ptransfer_complete->id = cwmp_ctx.tc_id; } bkp_session_insert_transfer_complete(ptransfer_complete); bkp_session_save(); diff --git a/src/xml.c b/src/xml.c index c20d0b7..6bd433e 100644 --- a/src/xml.c +++ b/src/xml.c @@ -527,7 +527,7 @@ int build_inform_env_header(mxml_node_t *b, struct xml_data_struct *xml_attrs) { if (b == NULL || xml_attrs == NULL) return FAULT_CPE_INTERNAL_ERROR; - int amd_version = cwmp_main->conf.supported_amd_version ? cwmp_main->conf.supported_amd_version : DEFAULT_AMD_VERSION; + int amd_version = cwmp_ctx.conf.supported_amd_version ? cwmp_ctx.conf.supported_amd_version : DEFAULT_AMD_VERSION; mxml_node_t **envelope = xml_attrs->xml_env; *envelope = b; @@ -555,7 +555,7 @@ int build_inform_env_header(mxml_node_t *b, struct xml_data_struct *xml_attrs) return FAULT_CPE_INTERNAL_ERROR; mxmlElementSetAttr(node, "soap_env:mustUnderstand", "0"); - node = mxmlNewInteger(node, cwmp_main->conf.session_timeout ? cwmp_main->conf.session_timeout : 60); + node = mxmlNewInteger(node, cwmp_ctx.conf.session_timeout ? cwmp_ctx.conf.session_timeout : 60); if (!node) return FAULT_CPE_INTERNAL_ERROR; } @@ -1134,9 +1134,9 @@ void event_container_list_to_xml_data_list(struct list_head *event_container_lis list_for_each_entry (event_container, event_container_list, list) { // cppcheck-suppress uninitvar - if (cwmp_main->session->session_status.is_heartbeat && event_container->code != EVENT_IDX_14HEARTBEAT) + if (cwmp_ctx.session->session_status.is_heartbeat && event_container->code != EVENT_IDX_14HEARTBEAT) continue; - if ((!cwmp_main->session->session_status.is_heartbeat) && (event_container->code == EVENT_IDX_14HEARTBEAT)) + if ((!cwmp_ctx.session->session_status.is_heartbeat) && (event_container->code == EVENT_IDX_14HEARTBEAT)) continue; struct xml_list_data *xml_data = calloc(1, sizeof(struct xml_list_data)); if (xml_data == NULL) @@ -1480,15 +1480,15 @@ int xml_send_message(struct rpc *rpc) int msg_out_len = 0, f, r = 0; mxml_node_t *b; - if (cwmp_main->session == NULL) { + if (cwmp_ctx.session == NULL) { CWMP_LOG(ERROR, "cwmp session not exist"); return -1; } - if (cwmp_main->session->tree_out) { + if (cwmp_ctx.session->tree_out) { unsigned char *zmsg_out; - msg_out = convert_xml_node_to_string(cwmp_main->session->tree_out, whitespace_cb); + msg_out = convert_xml_node_to_string(cwmp_ctx.session->tree_out, whitespace_cb); FREE(g_tab_space); if (msg_out == NULL) { CWMP_LOG(ERROR, "%s: msg_out is null", __FUNCTION__); @@ -1496,8 +1496,8 @@ int xml_send_message(struct rpc *rpc) } CWMP_LOG_XML_MSG(DEBUG, msg_out, XML_MSG_OUT); - if (cwmp_main->conf.compression != COMP_NONE) { - if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp_main->conf.compression)) { + if (cwmp_ctx.conf.compression != COMP_NONE) { + if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp_ctx.conf.compression)) { return -1; } FREE(msg_out); @@ -1536,35 +1536,35 @@ int xml_send_message(struct rpc *rpc) } } - cwmp_main->session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK); - if (!cwmp_main->session->tree_in) + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, msg_in, MXML_OPAQUE_CALLBACK); + if (!cwmp_ctx.session->tree_in) goto error; - if (xml_recreate_namespace(cwmp_main->session->tree_in) == -1) { + if (xml_recreate_namespace(cwmp_ctx.session->tree_in) == -1) { CWMP_LOG(ERROR, "Failed to get ns parameters"); goto error; } /* get NoMoreRequests or HolRequest*/ - cwmp_main->session->hold_request = false; + cwmp_ctx.session->hold_request = false; if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "NoMoreRequests") == -1) goto error; - b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (b) { - b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST); + b = mxmlWalkNext(b, cwmp_ctx.session->tree_in, MXML_DESCEND_FIRST); const char *bname = b ? mxmlGetOpaque(b) : NULL; if (b && mxmlGetType(b) == MXML_OPAQUE && bname) - cwmp_main->session->hold_request = (int)strtol(bname, NULL, 10); + cwmp_ctx.session->hold_request = (int)strtol(bname, NULL, 10); } else { if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "HoldRequests") == -1) goto error; - b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); const char *bname = b ? mxmlGetOpaque(b) : NULL; if (b) { - b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST); + b = mxmlWalkNext(b, cwmp_ctx.session->tree_in, MXML_DESCEND_FIRST); if (b && mxmlGetType(b) == MXML_OPAQUE && bname) - cwmp_main->session->hold_request = (int)strtol(bname, NULL, 10); + cwmp_ctx.session->hold_request = (int)strtol(bname, NULL, 10); } } @@ -1581,20 +1581,20 @@ error: int xml_prepare_msg_out() { - struct config *conf = &(cwmp_main->conf); + struct config *conf = &(cwmp_ctx.conf); mxml_node_t *n; - load_response_xml_schema(&cwmp_main->session->tree_out); - if (!cwmp_main->session->tree_out) + load_response_xml_schema(&cwmp_ctx.session->tree_out); + if (!cwmp_ctx.session->tree_out) return -1; - n = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + n = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); if (!n) { return -1; } mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(conf->amd_version) - 1]); - if (!cwmp_main->session->tree_out) + if (!cwmp_ctx.session->tree_out) return -1; return 0; @@ -1607,10 +1607,10 @@ int xml_set_cwmp_id() int pid_t = getpid(); /* define cwmp id */ - if (snprintf(c, sizeof(c), "%d.%u", pid_t, ++(cwmp_main->cwmp_id)) == -1) + if (snprintf(c, sizeof(c), "%d.%u", pid_t, ++(cwmp_ctx.cwmp_id)) == -1) return -1; - b = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND); if (!b) return -1; @@ -1630,16 +1630,16 @@ int xml_set_cwmp_id_rpc_cpe() if (snprintf(c, sizeof(c), "%s:%s", ns.cwmp, "ID") == -1) return -1; - b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); if (b) { /* ACS send ID parameter */ - b = mxmlWalkNext(b, cwmp_main->session->tree_in, MXML_DESCEND_FIRST); + b = mxmlWalkNext(b, cwmp_ctx.session->tree_in, MXML_DESCEND_FIRST); if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b)) return 0; snprintf(c, sizeof(c), "%s", mxmlGetOpaque(b)); - b = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND); + b = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "cwmp:ID", NULL, NULL, MXML_DESCEND); if (!b) return -1; @@ -1731,7 +1731,7 @@ int xml_prepare_lwnotification_message(char **msg_out) void load_notification_xml_schema(mxml_node_t **tree) { char declaration[1024] = {0}; - struct config *conf = &(cwmp_main->conf); + struct config *conf = &(cwmp_ctx.conf); char *c = NULL; if (tree == NULL) @@ -1811,7 +1811,7 @@ void load_notification_xml_schema(mxml_node_t **tree) return; } - if (NULL == mxmlNewOpaque(oui, cwmp_main->deviceid.oui)) { + if (NULL == mxmlNewOpaque(oui, cwmp_ctx.deviceid.oui)) { MXML_DELETE(xml); return; } @@ -1822,7 +1822,7 @@ void load_notification_xml_schema(mxml_node_t **tree) return; } - if (NULL == mxmlNewOpaque(pclass, cwmp_main->deviceid.productclass)) { + if (NULL == mxmlNewOpaque(pclass, cwmp_ctx.deviceid.productclass)) { MXML_DELETE(xml); return; } @@ -1833,7 +1833,7 @@ void load_notification_xml_schema(mxml_node_t **tree) return; } - if (NULL == mxmlNewOpaque(slno, cwmp_main->deviceid.serialnumber)) { + if (NULL == mxmlNewOpaque(slno, cwmp_ctx.deviceid.serialnumber)) { MXML_DELETE(xml); return; } diff --git a/test/cmocka/icwmp_backup_session_unit_test.c b/test/cmocka/icwmp_backup_session_unit_test.c index f88d3b3..a743940 100644 --- a/test/cmocka/icwmp_backup_session_unit_test.c +++ b/test/cmocka/icwmp_backup_session_unit_test.c @@ -21,11 +21,8 @@ #include "config.h" #include "event.h" -static struct cwmp cwmp_main_test = { 0 }; - static int bkp_session_unit_tests_init(void **state) { - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); create_cwmp_session_structure(); return 0; } @@ -34,7 +31,6 @@ static int bkp_session_unit_tests_clean(void **state) { icwmp_cleanmem(); clean_cwmp_session_structure(); - FREE(cwmp_main); return 0; } diff --git a/test/cmocka/icwmp_cli_unit_test.c b/test/cmocka/icwmp_cli_unit_test.c index 2f589d1..7b43022 100644 --- a/test/cmocka/icwmp_cli_unit_test.c +++ b/test/cmocka/icwmp_cli_unit_test.c @@ -49,9 +49,7 @@ static void restore_output() static int cwmp_cli_unit_tests_init(void **state) { - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); create_cwmp_session_structure(); - memcpy(&(cwmp_main->env), &cwmp_main, sizeof(struct env)); cwmp_session_init(); return 0; } @@ -59,8 +57,7 @@ static int cwmp_cli_unit_tests_init(void **state) static int cwmp_cli_unit_tests_clean(void **state) { cwmp_session_exit(); - FREE(cwmp_main->session); - FREE(cwmp_main); + FREE(cwmp_ctx.session); FREE(add_instance); return 0; } diff --git a/test/cmocka/icwmp_datamodel_interface_unit_test.c b/test/cmocka/icwmp_datamodel_interface_unit_test.c index 1da8ab5..01762ec 100644 --- a/test/cmocka/icwmp_datamodel_interface_unit_test.c +++ b/test/cmocka/icwmp_datamodel_interface_unit_test.c @@ -31,7 +31,6 @@ static LIST_HEAD(xml_param_list); static int dm_iface_unit_tests_init(void **state) { - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); create_cwmp_session_structure(); cwmp_session_init(); get_global_config(); @@ -45,7 +44,6 @@ static int dm_iface_unit_tests_clean(void **state) cwmp_free_all_xml_data_list(&xml_param_list); cwmp_session_exit(); clean_cwmp_session_structure(); - FREE(cwmp_main); return 0; } diff --git a/test/cmocka/icwmp_download_unit_test.c b/test/cmocka/icwmp_download_unit_test.c index a9e6274..62d9427 100644 --- a/test/cmocka/icwmp_download_unit_test.c +++ b/test/cmocka/icwmp_download_unit_test.c @@ -48,7 +48,6 @@ static void free_download(struct download *p) static int download_unit_test_init(void **state) { - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); return 0; } @@ -59,7 +58,6 @@ static int download_unit_tests_clean(void **state) free_transfer_complete(transfer_complete_test); remove(ICWMP_DOWNLOAD_FILE); remove(FIRMWARE_UPGRADE_IMAGE); - FREE(cwmp_main); return 0; } diff --git a/test/cmocka/icwmp_notifications_unit_test.c b/test/cmocka/icwmp_notifications_unit_test.c index 49ffacb..9f7e9e2 100644 --- a/test/cmocka/icwmp_notifications_unit_test.c +++ b/test/cmocka/icwmp_notifications_unit_test.c @@ -28,9 +28,7 @@ LIST_HEAD(parameters_list); static int cwmp_notifications_unit_tests_init(void **state) { - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); create_cwmp_session_structure(); - memcpy(&(cwmp_main->env), &cwmp_main, sizeof(struct env)); cwmp_session_init(); return 0; } @@ -41,8 +39,7 @@ static int cwmp_notifications_unit_tests_clean(void **state) clean_list_value_change(); cwmp_free_all_dm_parameter_list(¶meters_list); cwmp_session_exit(); - FREE(cwmp_main->session); - FREE(cwmp_main); + FREE(cwmp_ctx.session); return 0; } diff --git a/test/cmocka/icwmp_soap_msg_unit_test.c b/test/cmocka/icwmp_soap_msg_unit_test.c index c011752..08e7809 100644 --- a/test/cmocka/icwmp_soap_msg_unit_test.c +++ b/test/cmocka/icwmp_soap_msg_unit_test.c @@ -50,9 +50,9 @@ static void clean_name_space() static void unit_test_remove_all_session_events() { - while (cwmp_main->session->events.next != &(cwmp_main->session->events)) { + while (cwmp_ctx.session->events.next != &(cwmp_ctx.session->events)) { struct event_container *event_container; - event_container = list_entry(cwmp_main->session->events.next, struct event_container, list); + event_container = list_entry(cwmp_ctx.session->events.next, struct event_container, list); free(event_container->command_key); cwmp_free_all_dm_parameter_list(&(event_container->head_dm_parameter)); list_del(&(event_container->list)); @@ -75,9 +75,7 @@ static int soap_unit_tests_init(void **state) load_default_forced_inform(); load_forced_inform_json(); - cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp)); create_cwmp_session_structure(); - memcpy(&(cwmp_main->env), &cwmp_main, sizeof(struct env)); cwmp_session_init(); log_set_severity_idx("DEBUG"); return 0; @@ -88,8 +86,7 @@ static int soap_unit_tests_clean(void **state) clean_name_space(); cwmp_session_exit(); clean_force_inform_list(); - FREE(cwmp_main->session); - FREE(cwmp_main); + FREE(cwmp_ctx.session); return 0; } @@ -122,10 +119,10 @@ static void soap_inform_message_test(void **state) mxml_node_t *env = NULL, *n = NULL, *device_id = NULL, *cwmp_inform = NULL; struct rpc *rpc_acs; - rpc_acs = list_entry(&(cwmp_main->session->head_rpc_acs), struct rpc, list); + rpc_acs = list_entry(&(cwmp_ctx.session->head_rpc_acs), struct rpc, list); cwmp_rpc_acs_prepare_message_inform(rpc_acs); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -155,8 +152,8 @@ static void soap_inform_message_test(void **state) n = mxmlFindElement(cwmp_inform, cwmp_inform, "ParameterList", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); unit_test_end_test_destruction(); } @@ -167,8 +164,8 @@ static void prepare_session_for_rpc_method_call() char c[128]; snprintf(c, sizeof(c), "%s:%s", ns.soap_env, "Body"); - b = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, c, NULL, NULL, MXML_DESCEND); - cwmp_main->session->body_in = b; + b = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, c, NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->body_in = b; xml_prepare_msg_out(); } @@ -177,9 +174,9 @@ static void prepare_gpv_soap_request(char *parameters[], int len) mxml_node_t *params = NULL, *n = NULL; int i; - cwmp_main->session->tree_in = mxmlLoadString(NULL, CWMP_GETPARAMETERVALUES_REQ, MXML_OPAQUE_CALLBACK); - xml_recreate_namespace(cwmp_main->session->tree_in); - params = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, "ParameterNames", NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, CWMP_GETPARAMETERVALUES_REQ, MXML_OPAQUE_CALLBACK); + xml_recreate_namespace(cwmp_ctx.session->tree_in); + params = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, "ParameterNames", NULL, NULL, MXML_DESCEND); for (i = 0; i < len; i++) { n = mxmlNewElement(params, "string"); n = mxmlNewOpaque(n, parameters[i]); @@ -203,7 +200,7 @@ static void soap_get_param_value_message_test(void **state) int ret = cwmp_handle_rpc_cpe_get_parameter_values(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -224,8 +221,8 @@ static void soap_get_param_value_message_test(void **state) value = mxmlFindElement(n, n, "Value", NULL, NULL, MXML_DESCEND); assert_non_null(value); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Wrong parameter path @@ -240,7 +237,7 @@ static void soap_get_param_value_message_test(void **state) ret = cwmp_handle_rpc_cpe_get_parameter_values(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -264,9 +261,9 @@ static void soap_get_param_value_message_test(void **state) detail_string = mxmlFindElement(detail, detail, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(detail_string); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); - cwmp_main->session->head_rpc_acs.next = NULL; + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); + cwmp_ctx.session->head_rpc_acs.next = NULL; unit_test_end_test_destruction(); clean_name_space(); @@ -276,9 +273,9 @@ static void prepare_addobj_soap_request(char *object, char *parameter_key) { mxml_node_t *add_node = NULL, *n = NULL; - cwmp_main->session->tree_in = mxmlLoadString(NULL, CWMP_ADDOBJECT_REQ, MXML_OPAQUE_CALLBACK); - xml_recreate_namespace(cwmp_main->session->tree_in); - add_node = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, "cwmp:AddObject", NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, CWMP_ADDOBJECT_REQ, MXML_OPAQUE_CALLBACK); + xml_recreate_namespace(cwmp_ctx.session->tree_in); + add_node = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, "cwmp:AddObject", NULL, NULL, MXML_DESCEND); n = mxmlFindElement(add_node, add_node, "ObjectName", NULL, NULL, MXML_DESCEND); n = mxmlNewOpaque(n, object); n = mxmlFindElement(add_node, add_node, "ParameterKey", NULL, NULL, MXML_DESCEND); @@ -300,7 +297,7 @@ static void soap_add_object_message_test(void **state) assert_int_equal(ret, 0); icwmp_restart_services(RELOAD_IMMIDIATE, true, false); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -316,8 +313,8 @@ static void soap_add_object_message_test(void **state) n = mxmlFindElement(add_resp, add_resp, "Status", NULL, NULL, MXML_DESCEND); assert_non_null(n); assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "0"); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Wrong object path @@ -330,7 +327,7 @@ static void soap_add_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_add_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -349,8 +346,8 @@ static void soap_add_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9005"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Not writable & Valid object path @@ -362,7 +359,7 @@ static void soap_add_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_add_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -381,8 +378,8 @@ static void soap_add_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9005"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Invalid parameterkey @@ -394,7 +391,7 @@ static void soap_add_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_add_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -413,10 +410,10 @@ static void soap_add_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9003"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); - cwmp_main->session->head_rpc_acs.next = NULL; + cwmp_ctx.session->head_rpc_acs.next = NULL; unit_test_end_test_destruction(); clean_name_space(); } @@ -425,9 +422,9 @@ static void prepare_delobj_soap_request(char *object, char *parameter_key) { mxml_node_t *del_node = NULL, *n = NULL; - cwmp_main->session->tree_in = mxmlLoadString(NULL, CWMP_DELOBJECT_REQ, MXML_OPAQUE_CALLBACK); - xml_recreate_namespace(cwmp_main->session->tree_in); - del_node = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, "cwmp:DeleteObject", NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, CWMP_DELOBJECT_REQ, MXML_OPAQUE_CALLBACK); + xml_recreate_namespace(cwmp_ctx.session->tree_in); + del_node = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, "cwmp:DeleteObject", NULL, NULL, MXML_DESCEND); n = mxmlFindElement(del_node, del_node, "ObjectName", NULL, NULL, MXML_DESCEND); n = mxmlNewOpaque(n, object); n = mxmlFindElement(del_node, del_node, "ParameterKey", NULL, NULL, MXML_DESCEND); @@ -452,7 +449,7 @@ static void soap_delete_object_message_test(void **state) assert_int_equal(ret, 0); icwmp_restart_services(RELOAD_IMMIDIATE, true, false); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -465,8 +462,8 @@ static void soap_delete_object_message_test(void **state) n = mxmlFindElement(add_resp, add_resp, "Status", NULL, NULL, MXML_DESCEND); assert_non_null(n); assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "1"); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Wrong object path @@ -479,7 +476,7 @@ static void soap_delete_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_delete_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -498,8 +495,8 @@ static void soap_delete_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9005"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Not writable & Valid object path @@ -511,7 +508,7 @@ static void soap_delete_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_delete_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -530,8 +527,8 @@ static void soap_delete_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9005"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Invalid parameterkey @@ -543,7 +540,7 @@ static void soap_delete_object_message_test(void **state) ret = cwmp_handle_rpc_cpe_delete_object(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -562,10 +559,10 @@ static void soap_delete_object_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(n)), "9003"); n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); - cwmp_main->session->head_rpc_acs.next = NULL; + cwmp_ctx.session->head_rpc_acs.next = NULL; unit_test_end_test_destruction(); clean_name_space(); } @@ -574,9 +571,9 @@ static void prepare_gpa_soap_request(char *parameter) { mxml_node_t *n = NULL; - cwmp_main->session->tree_in = mxmlLoadString(NULL, CWMP_GETATTRIBUTES_REQ, MXML_OPAQUE_CALLBACK); - xml_recreate_namespace(cwmp_main->session->tree_in); - n = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, "cwmp:GetParameterAttributes", NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, CWMP_GETATTRIBUTES_REQ, MXML_OPAQUE_CALLBACK); + xml_recreate_namespace(cwmp_ctx.session->tree_in); + n = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, "cwmp:GetParameterAttributes", NULL, NULL, MXML_DESCEND); n = mxmlFindElement(n, n, "ParameterNames", NULL, NULL, MXML_DESCEND); n = mxmlNewElement(n, "string"); n = mxmlNewOpaque(n, parameter); @@ -597,7 +594,7 @@ static void soap_get_parameter_attributes_message_test(void **state) int ret = cwmp_handle_rpc_cpe_get_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -619,8 +616,8 @@ static void soap_get_parameter_attributes_message_test(void **state) n = mxmlFindElement(param_attr, param_attr, "AccessList", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Not Valid path @@ -635,7 +632,7 @@ static void soap_get_parameter_attributes_message_test(void **state) ret = cwmp_handle_rpc_cpe_get_parameter_values(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -658,10 +655,10 @@ static void soap_get_parameter_attributes_message_test(void **state) assert_string_equal(mxmlGetOpaque(mxmlGetFirstChild(detail_code)), "9005"); detail_string = mxmlFindElement(detail, detail, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(detail_string); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); - cwmp_main->session->head_rpc_acs.next = NULL; + cwmp_ctx.session->head_rpc_acs.next = NULL; unit_test_end_test_destruction(); clean_name_space(); } @@ -670,9 +667,9 @@ static void prepare_spa_soap_request(char *parameter, char *notification, char * { mxml_node_t *n = NULL, *set_attr = NULL; - cwmp_main->session->tree_in = mxmlLoadString(NULL, CWMP_SETATTRIBUTES_REQ, MXML_OPAQUE_CALLBACK); - xml_recreate_namespace(cwmp_main->session->tree_in); - set_attr = mxmlFindElement(cwmp_main->session->tree_in, cwmp_main->session->tree_in, "SetParameterAttributesStruct", NULL, NULL, MXML_DESCEND); + cwmp_ctx.session->tree_in = mxmlLoadString(NULL, CWMP_SETATTRIBUTES_REQ, MXML_OPAQUE_CALLBACK); + xml_recreate_namespace(cwmp_ctx.session->tree_in); + set_attr = mxmlFindElement(cwmp_ctx.session->tree_in, cwmp_ctx.session->tree_in, "SetParameterAttributesStruct", NULL, NULL, MXML_DESCEND); n = mxmlFindElement(set_attr, set_attr, "Name", NULL, NULL, MXML_DESCEND); n = mxmlNewOpaque(n, parameter); n = mxmlFindElement(set_attr, set_attr, "Notification", NULL, NULL, MXML_DESCEND); @@ -696,7 +693,7 @@ static void soap_set_parameter_attributes_message_test(void **state) int ret = cwmp_handle_rpc_cpe_set_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -707,8 +704,8 @@ static void soap_set_parameter_attributes_message_test(void **state) n = mxmlFindElement(n, n, "cwmp:SetParameterAttributesResponse", NULL, NULL, MXML_DESCEND); assert_non_null(n); assert_null(mxmlGetFirstChild(n)); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Not Valid path @@ -720,7 +717,7 @@ static void soap_set_parameter_attributes_message_test(void **state) ret = cwmp_handle_rpc_cpe_set_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -740,8 +737,8 @@ static void soap_set_parameter_attributes_message_test(void **state) n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Not Valid Notification value @@ -752,7 +749,7 @@ static void soap_set_parameter_attributes_message_test(void **state) ret = cwmp_handle_rpc_cpe_set_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -772,8 +769,8 @@ static void soap_set_parameter_attributes_message_test(void **state) n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Invalid Notification String @@ -785,7 +782,7 @@ static void soap_set_parameter_attributes_message_test(void **state) ret = cwmp_handle_rpc_cpe_set_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -805,8 +802,8 @@ static void soap_set_parameter_attributes_message_test(void **state) n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); /* * Invalid NotificationChange @@ -818,7 +815,7 @@ static void soap_set_parameter_attributes_message_test(void **state) ret = cwmp_handle_rpc_cpe_set_parameter_attributes(rpc_cpe); assert_int_equal(ret, 0); - env = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); + env = mxmlFindElement(cwmp_ctx.session->tree_out, cwmp_ctx.session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); assert_non_null(env); n = mxmlFindElement(env, env, "soap_env:Header", NULL, NULL, MXML_DESCEND); assert_non_null(n); @@ -838,10 +835,10 @@ static void soap_set_parameter_attributes_message_test(void **state) n = mxmlFindElement(cwmp_fault, cwmp_fault, "FaultString", NULL, NULL, MXML_DESCEND); assert_non_null(n); - MXML_DELETE(cwmp_main->session->tree_in); - MXML_DELETE(cwmp_main->session->tree_out); + MXML_DELETE(cwmp_ctx.session->tree_in); + MXML_DELETE(cwmp_ctx.session->tree_out); - cwmp_main->session->head_rpc_acs.next = NULL; + cwmp_ctx.session->head_rpc_acs.next = NULL; unit_test_end_test_destruction(); clean_name_space(); }