diff --git a/backupSession.c b/backupSession.c index a93f36f..acc4842 100644 --- a/backupSession.c +++ b/backupSession.c @@ -764,10 +764,14 @@ void bkp_session_delete_transfer_complete(struct transfer_complete *ptransfer_co int save_acs_bkp_config(struct cwmp *cwmp) { struct config *conf; + char *url = NULL; conf = &(cwmp->conf); - bkp_session_simple_insert("acs", "url", conf->acsurl); + global_string_param_read(&conf->acsurl, &url); + bkp_session_simple_insert("acs", "url", url); bkp_session_save(); + + FREE(url); return CWMP_OK; } diff --git a/common.c b/common.c index 476441a..ba96c3a 100755 --- a/common.c +++ b/common.c @@ -35,6 +35,7 @@ static int nbre_services = 0; static char *list_services[MAX_NBRE_SERVICES] = { 0 }; LIST_HEAD(cwmp_memory_list); extern bool g_firewall_restart; +pthread_mutex_t mutex_global_config = PTHREAD_MUTEX_INITIALIZER; struct cwmp_mem { struct list_head list; @@ -133,6 +134,121 @@ int global_env_init(int argc, char **argv, struct env *env) return CWMP_OK; } +int global_int_param_read(const int *param) +{ + int val = 0; + + pthread_mutex_lock(&mutex_global_config); + val = *param; + pthread_mutex_unlock(&mutex_global_config); + + return val; +} + +void global_string_param_read(char **param, char **val) +{ + if (param == NULL || *param == NULL || val == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + *val = CWMP_STRDUP(*param); + pthread_mutex_unlock(&mutex_global_config); +} + +bool global_bool_param_read(const bool *param) +{ + bool val = 0; + + pthread_mutex_lock(&mutex_global_config); + val = *param; + pthread_mutex_unlock(&mutex_global_config); + + return val; +} + +time_t global_time_param_read(const time_t *param) +{ + time_t val = 0; + + pthread_mutex_lock(&mutex_global_config); + val = *param; + pthread_mutex_unlock(&mutex_global_config); + + return val; +} + +unsigned int global_uint_param_read(const unsigned int *param) +{ + unsigned int val = 0; + + pthread_mutex_lock(&mutex_global_config); + val = *param; + pthread_mutex_unlock(&mutex_global_config); + + return val; +} + +void global_string_param_write(char **param, char *value) +{ + if (param == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + if (CWMP_STRLEN(value) == 0) { + FREE(*param); + } else { + *param = CWMP_STRDUP(value); + } + pthread_mutex_unlock(&mutex_global_config); +} + +void global_bool_param_write(bool *param, bool value) +{ + if (param == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + *param = value; + pthread_mutex_unlock(&mutex_global_config); +} + +void global_time_param_write(time_t *param, time_t value) +{ + if (param == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + *param = value; + pthread_mutex_unlock(&mutex_global_config); +} + +void global_int_param_write(int *param, int value) +{ + if (param == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + *param = value; + pthread_mutex_unlock(&mutex_global_config); +} + +void global_uint_param_write(unsigned int *param, unsigned int value) +{ + if (param == NULL) + return; + + pthread_mutex_lock(&mutex_global_config); + *param = value; + pthread_mutex_unlock(&mutex_global_config); +} + +void global_string_param_free(char **param) +{ + pthread_mutex_lock(&mutex_global_config); + FREE(*param); + pthread_mutex_unlock(&mutex_global_config); +} + /* * List dm_paramter */ @@ -752,10 +868,13 @@ void ubus_network_interface_callback(struct ubus_request *req __attribute__((unu // Only update the interface if its not empty if (CWMP_STRLEN(l3_device)) { - cwmp_main.conf.interface = strdup(l3_device); + global_string_param_write(&cwmp_main.conf.interface, l3_device); } - CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", cwmp_main.conf.interface); + char *intf = NULL; + global_string_param_read(&cwmp_main.conf.interface, &intf); + CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", intf); + FREE(intf); } int get_connection_interface(char *iface) @@ -772,7 +891,7 @@ int get_connection_interface(char *iface) char ubus_obj[100] = {0}; snprintf(ubus_obj, sizeof(ubus_obj), "network.interface.%s", iface); - FREE(cwmp_main.conf.interface); + global_string_param_free(&cwmp_main.conf.interface); int e = icwmp_ubus_invoke(ubus_obj, "status", b.head, ubus_network_interface_callback, NULL); blob_buf_free(&b); @@ -780,9 +899,15 @@ int get_connection_interface(char *iface) if (e != 0) { return -1; } - if (cwmp_main.conf.interface == NULL) { + + char *tmp = NULL; + global_string_param_read(&cwmp_main.conf.interface, &tmp); + if (CWMP_STRLEN(tmp) == 0) { + FREE(tmp); return -1; } + + FREE(tmp); return CWMP_OK; } diff --git a/config.c b/config.c index 3d45624..efc47cd 100755 --- a/config.c +++ b/config.c @@ -21,8 +21,6 @@ #include "datamodel_interface.h" #include "heartbeat.h" -pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER; - static char* get_value_from_uci_option(struct uci_option *tb) { if (tb == NULL) return NULL; @@ -36,6 +34,8 @@ static char* get_value_from_uci_option(struct uci_option *tb) { static void config_get_cpe_elements(struct config *conf, struct uci_section *s) { + char *val = NULL; + enum { UCI_CPE_UBUS_SOCKET_PATH, UCI_CPE_LOG_FILE_NAME, @@ -64,8 +64,10 @@ static void config_get_cpe_elements(struct config *conf, struct uci_section *s) struct uci_option *cpe_tb[__MAX_NUM_UCI_CPE_ATTRS] = {0}; uci_parse_section(s, cpe_opts, __MAX_NUM_UCI_CPE_ATTRS, cpe_tb); - conf->ubus_socket = CWMP_STRDUP(get_value_from_uci_option(cpe_tb[UCI_CPE_UBUS_SOCKET_PATH])); - CWMP_LOG(DEBUG, "CWMP CONFIG - ubus socket: %s", conf->ubus_socket ? conf->ubus_socket : ""); + global_string_param_write(&conf->ubus_socket, get_value_from_uci_option(cpe_tb[UCI_CPE_UBUS_SOCKET_PATH])); + global_string_param_read(&conf->ubus_socket, &val); + CWMP_LOG(DEBUG, "CWMP CONFIG - ubus socket: %s", val); + FREE(val); log_set_log_file_name(get_value_from_uci_option(cpe_tb[UCI_CPE_LOG_FILE_NAME])); @@ -79,27 +81,34 @@ static void config_get_cpe_elements(struct config *conf, struct uci_section *s) log_set_on_syslog(get_value_from_uci_option(cpe_tb[UCI_CPE_ENABLE_SYSLOG])); - conf->amd_version = DEFAULT_AMD_VERSION; + global_int_param_write(&conf->amd_version, DEFAULT_AMD_VERSION); char *version = get_value_from_uci_option(cpe_tb[UCI_CPE_AMD_VERSION]); if (version != NULL) { int a = atoi(version); if (a >= 1 && a <= 6) { - conf->amd_version = a; + global_int_param_write(&conf->amd_version, a); } } - conf->supported_amd_version = conf->amd_version; - CWMP_LOG(DEBUG, "CWMP CONFIG - amendement version: %d", conf->amd_version); + + int amd_ver = global_int_param_read(&conf->amd_version); + global_int_param_write(&conf->supported_amd_version, amd_ver); + CWMP_LOG(DEBUG, "CWMP CONFIG - amendement version: %d", amd_ver); if (cpe_tb[UCI_CPE_DEFAULT_WAN_IFACE]) { char *default_wan_iface = get_value_from_uci_option(cpe_tb[UCI_CPE_DEFAULT_WAN_IFACE]); - conf->default_wan_iface = strdup(default_wan_iface ? default_wan_iface : "wan"); + global_string_param_write(&conf->default_wan_iface, default_wan_iface ? default_wan_iface : "wan"); } else { - conf->default_wan_iface = strdup("wan"); + global_string_param_write(&conf->default_wan_iface, "wan"); } - CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", conf->default_wan_iface); + + global_string_param_read(&conf->default_wan_iface, &val); + CWMP_LOG(DEBUG, "CWMP CONFIG - default wan interface: %s", val); + FREE(val); } static void config_get_acs_elements(struct config *conf, struct uci_section *s) { + char *val = NULL; + enum { UCI_ACS_IPV6_ENABLE, UCI_ACS_SSL_CAPATH, @@ -119,17 +128,22 @@ static void config_get_acs_elements(struct config *conf, struct uci_section *s) memset(acs_tb, 0, sizeof(acs_tb)); uci_parse_section(s, acs_opts, __MAX_NUM_UCI_ACS_ATTRS, acs_tb); - conf->ipv6_enable = uci_str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_IPV6_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - ipv6 enable: %d", conf->ipv6_enable); + global_bool_param_write(&conf->ipv6_enable, uci_str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_IPV6_ENABLE]))); + bool v6_enable = global_bool_param_read(&conf->ipv6_enable); + CWMP_LOG(DEBUG, "CWMP CONFIG - ipv6 enable: %d", v6_enable); - conf->acs_ssl_capath = CWMP_STRDUP(get_value_from_uci_option(acs_tb[UCI_ACS_SSL_CAPATH])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs ssl cpath: %s", conf->acs_ssl_capath ? conf->acs_ssl_capath : ""); + global_string_param_write(&conf->acs_ssl_capath, get_value_from_uci_option(acs_tb[UCI_ACS_SSL_CAPATH])); + global_string_param_read(&conf->acs_ssl_capath, &val); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs ssl cpath: %s", val); + FREE(val); - conf->http_disable_100continue = uci_str_to_bool(get_value_from_uci_option(acs_tb[HTTP_DISABLE_100CONTINUE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - http disable 100continue: %d", conf->http_disable_100continue); + global_bool_param_write(&conf->http_disable_100continue, uci_str_to_bool(get_value_from_uci_option(acs_tb[HTTP_DISABLE_100CONTINUE]))); + bool http_100_enable = global_bool_param_read(&conf->http_disable_100continue); + CWMP_LOG(DEBUG, "CWMP CONFIG - http disable 100continue: %d", http_100_enable); - conf->insecure_enable = uci_str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_INSECURE_ENABLE])); - CWMP_LOG(DEBUG, "CWMP CONFIG - acs insecure enable: %d", conf->insecure_enable); + global_bool_param_write(&conf->insecure_enable, uci_str_to_bool(get_value_from_uci_option(acs_tb[UCI_ACS_INSECURE_ENABLE]))); + bool insecure_en = global_bool_param_read(&conf->insecure_enable); + CWMP_LOG(DEBUG, "CWMP CONFIG - acs insecure enable: %d", insecure_en); } int get_preinit_config(struct config *conf) @@ -176,7 +190,7 @@ static char* get_alternate_option_value(bool discovery_enable, char *acs_val, ch int get_global_config(struct config *conf) { int error; - char *value = NULL, *value2 = NULL, *value3 = NULL; + char *value = NULL, *value2 = NULL, *value3 = NULL, *temp = NULL; if ((error = uci_get_value(UCI_CPE_CWMP_ENABLE, &value)) == CWMP_OK) { if (value != NULL && uci_str_to_bool(value) == false) { @@ -187,11 +201,14 @@ int get_global_config(struct config *conf) } FREE(value); - error = get_connection_interface(conf->default_wan_iface); + global_string_param_read(&conf->default_wan_iface, &temp); + error = get_connection_interface(temp); if (error != CWMP_OK) { - CWMP_LOG(DEBUG, "Failed to get interface [%s] details", conf->default_wan_iface); + CWMP_LOG(DEBUG, "Failed to get interface [%s] details", temp); + FREE(temp); return error; } + FREE(temp); bool discovery_enable = false; error = uci_get_value(UCI_DHCP_DISCOVERY_PATH, &value); @@ -203,18 +220,22 @@ int get_global_config(struct config *conf) uci_get_value(UCI_ACS_URL_PATH, &value2); uci_get_value(UCI_DHCP_ACS_URL, &value3); - FREE(conf->acsurl); - conf->acsurl = CWMP_STRDUP(get_alternate_option_value(discovery_enable, value2, value3)); + global_string_param_free(&conf->acsurl); + char *url = get_alternate_option_value(discovery_enable, value2, value3); + global_string_param_write(&conf->acsurl, url); FREE(value2); FREE(value3); - if (conf->acsurl == NULL) { + global_string_param_read(&conf->acsurl, &temp); + if (CWMP_STRLEN(url) == 0) { + FREE(temp); return CWMP_GEN_ERR; } + FREE(temp); if ((error = uci_get_value(UCI_ACS_GETRPC, &value)) == CWMP_OK) { - conf->acs_getrpc = uci_str_to_bool(value); + global_bool_param_write(&conf->acs_getrpc, uci_str_to_bool(value)); FREE(value); } else { return error; @@ -222,8 +243,8 @@ int get_global_config(struct config *conf) if ((error = uci_get_value(UCI_ACS_USERID_PATH, &value)) == CWMP_OK) { if (value != NULL) { - FREE(conf->acs_userid); - conf->acs_userid = strdup(value); + global_string_param_free(&conf->acs_userid); + global_string_param_write(&conf->acs_userid, value); FREE(value); } } else { @@ -232,8 +253,8 @@ int get_global_config(struct config *conf) if ((error = uci_get_value(UCI_ACS_PASSWD_PATH, &value)) == CWMP_OK) { if (value != NULL) { - FREE(conf->acs_passwd); - conf->acs_passwd = strdup(value); + global_string_param_free(&conf->acs_passwd); + global_string_param_write(&conf->acs_passwd, value); FREE(value); } } else { @@ -241,31 +262,31 @@ int get_global_config(struct config *conf) } if ((error = uci_get_value(UCI_ACS_COMPRESSION, &value)) == CWMP_OK) { - conf->compression = COMP_NONE; - if (conf->amd_version >= AMD_5 && value != NULL) { + global_int_param_write(&conf->compression, COMP_NONE); + if (global_int_param_read(&conf->amd_version) >= AMD_5 && value != NULL) { if (0 == strcasecmp(value, "gzip")) { - conf->compression = COMP_GZIP; + global_int_param_write(&conf->compression, COMP_GZIP); } else if (0 == strcasecmp(value, "deflate")) { - conf->compression = COMP_DEFLATE; + global_int_param_write(&conf->compression, COMP_DEFLATE); } else { - conf->compression = COMP_NONE; + global_int_param_write(&conf->compression, COMP_NONE); } } FREE(value); } else { - conf->compression = COMP_NONE; + global_int_param_write(&conf->compression, COMP_NONE); } - conf->retry_min_wait_interval = DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL; + global_int_param_write(&conf->retry_min_wait_interval, DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL); uci_get_value(UCI_ACS_RETRY_MIN_WAIT_INTERVAL, &value2); uci_get_value(UCI_DHCP_ACS_RETRY_MIN_WAIT_INTERVAL, &value3); char *op_interval = get_alternate_option_value(discovery_enable, value2, value3); if (op_interval != NULL) { - if (conf->amd_version >= AMD_3) { + if (global_int_param_read(&conf->amd_version) >= AMD_3) { int a = atoi(op_interval); if (a <= 65535 && a >= 1) { - conf->retry_min_wait_interval = a; + global_int_param_write(&conf->retry_min_wait_interval, a); } } } @@ -273,16 +294,16 @@ int get_global_config(struct config *conf) FREE(value2); FREE(value3); - conf->retry_interval_multiplier = DEFAULT_RETRY_INTERVAL_MULTIPLIER; + global_int_param_write(&conf->retry_interval_multiplier, DEFAULT_RETRY_INTERVAL_MULTIPLIER); uci_get_value(UCI_ACS_RETRY_INTERVAL_MULTIPLIER, &value2); uci_get_value(UCI_DHCP_ACS_RETRY_INTERVAL_MULTIPLIER, &value3); char *op_multi = get_alternate_option_value(discovery_enable, value2, value3); if (op_multi != NULL) { - if (conf->amd_version >= AMD_3) { + if (global_int_param_read(&conf->amd_version) >= AMD_3) { int a = atoi(op_multi); if (a <= 65535 && a >= 1000) { - conf->retry_interval_multiplier = a; + global_int_param_write(&conf->retry_interval_multiplier, a); } } } @@ -291,24 +312,24 @@ int get_global_config(struct config *conf) FREE(value3); if ((error = uci_get_value(UCI_CPE_USERID_PATH, &value)) == CWMP_OK) { - FREE(conf->cpe_userid); + global_string_param_free(&conf->cpe_userid); if (value != NULL) { - conf->cpe_userid = strdup(value); + global_string_param_write(&conf->cpe_userid, value); FREE(value); } else { - conf->cpe_userid = strdup(""); + global_string_param_write(&conf->cpe_userid, ""); } } else { return error; } if ((error = uci_get_value(UCI_CPE_PASSWD_PATH, &value)) == CWMP_OK) { - FREE(conf->cpe_passwd); + global_string_param_free(&conf->cpe_passwd); if (value != NULL) { - conf->cpe_passwd = strdup(value); + global_string_param_write(&conf->cpe_passwd, value); FREE(value); } else { - conf->cpe_passwd = strdup(""); + global_string_param_write(&conf->cpe_passwd, ""); } } else { return error; @@ -324,25 +345,25 @@ int get_global_config(struct config *conf) if (a == 0) { CWMP_LOG(INFO, "Set the connection request port to the default value: %d", DEFAULT_CONNECTION_REQUEST_PORT); - conf->connection_request_port = DEFAULT_CONNECTION_REQUEST_PORT; + global_int_param_write(&conf->connection_request_port, DEFAULT_CONNECTION_REQUEST_PORT); } else { - conf->connection_request_port = a; + global_int_param_write(&conf->connection_request_port, a); } } else { return error; } if ((error = uci_get_value(UCI_CPE_CRPATH_PATH, &value)) == CWMP_OK) { - FREE(conf->connection_request_path); + global_string_param_free(&conf->connection_request_path); if (value == NULL) - conf->connection_request_path = strdup("/"); + global_string_param_write(&conf->connection_request_path, "/"); else { if (value[0] == '/') - conf->connection_request_path = strdup(value); + global_string_param_write(&conf->connection_request_path, value); else { char cr_path[512]; snprintf(cr_path, sizeof(cr_path), "/%s", value); - conf->connection_request_path = strdup(cr_path); + global_string_param_write(&conf->connection_request_path, cr_path); } FREE(value); } @@ -356,7 +377,7 @@ int get_global_config(struct config *conf) a = uci_str_to_bool(value); FREE(value); } - conf->periodic_notify_enable = a; + global_bool_param_write(&conf->periodic_notify_enable, a); } else { return error; } @@ -371,9 +392,9 @@ int get_global_config(struct config *conf) if (a == 0) { CWMP_LOG(INFO, "Set notify period to the default value: %d", DEFAULT_NOTIFY_PERIOD); - conf->periodic_notify_interval = DEFAULT_NOTIFY_PERIOD; + global_int_param_write(&conf->periodic_notify_interval, DEFAULT_NOTIFY_PERIOD); } else { - conf->periodic_notify_interval = a; + global_int_param_write(&conf->periodic_notify_interval, a); } } else { return error; @@ -381,10 +402,10 @@ int get_global_config(struct config *conf) if ((error = uci_get_value(UCI_PERIODIC_INFORM_TIME_PATH, &value)) == CWMP_OK) { if (value != NULL) { - conf->time = convert_datetime_to_timestamp(value); + global_time_param_write(&conf->time, convert_datetime_to_timestamp(value)); FREE(value); } else { - conf->time = 0; + global_time_param_write(&conf->time, 0); } } else { return error; @@ -392,7 +413,7 @@ int get_global_config(struct config *conf) char *entropy = generate_random_string(sizeof(unsigned int)); if (entropy != NULL) { - conf->periodic_entropy = (unsigned int)strtoul(entropy, NULL, 16); + global_uint_param_write(&conf->periodic_entropy, (unsigned int)strtoul(entropy, NULL, 16)); free(entropy); } @@ -405,17 +426,17 @@ int get_global_config(struct config *conf) } if (a >= PERIOD_INFORM_MIN) { - conf->period = a; + global_int_param_write(&conf->period, a); } else { CWMP_LOG(ERROR, "Period interval of periodic inform should be > %ds. Set to default: %ds", PERIOD_INFORM_MIN, PERIOD_INFORM_DEFAULT); - conf->period = PERIOD_INFORM_DEFAULT; + global_int_param_write(&conf->period, PERIOD_INFORM_DEFAULT); } } else { return error; } if ((error = uci_get_value(UCI_PERIODIC_INFORM_ENABLE_PATH, &value)) == CWMP_OK) { - conf->periodic_enable = uci_str_to_bool(value); + global_bool_param_write(&conf->periodic_enable, uci_str_to_bool(value)); FREE(value); } else { return error; @@ -424,24 +445,24 @@ int get_global_config(struct config *conf) if ((error = uci_get_value(UCI_CPE_INSTANCE_MODE, &value)) == CWMP_OK) { if (value != NULL) { if (0 == strcmp(value, "InstanceNumber")) { - conf->instance_mode = INSTANCE_MODE_NUMBER; + global_uint_param_write(&conf->instance_mode, INSTANCE_MODE_NUMBER); } else { - conf->instance_mode = INSTANCE_MODE_ALIAS; + global_uint_param_write(&conf->instance_mode, INSTANCE_MODE_ALIAS); } FREE(value); } else { - conf->instance_mode = DEFAULT_INSTANCE_MODE; + global_uint_param_write(&conf->instance_mode, DEFAULT_INSTANCE_MODE); } } else { return error; } if ((error = uci_get_value(UCI_CPE_SESSION_TIMEOUT, &value)) == CWMP_OK) { - conf->session_timeout = DEFAULT_SESSION_TIMEOUT; + global_uint_param_write(&conf->session_timeout, DEFAULT_SESSION_TIMEOUT); if (value != NULL) { int a = atoi(value); if (a >= 1) { - conf->session_timeout = a; + global_uint_param_write(&conf->session_timeout, a); } FREE(value); } @@ -450,19 +471,21 @@ int get_global_config(struct config *conf) } if ((error = uci_get_value(LW_NOTIFICATION_ENABLE, &value)) == CWMP_OK) { - conf->lw_notification_enable = uci_str_to_bool(value); + global_bool_param_write(&conf->lw_notification_enable, uci_str_to_bool(value)); FREE(value); } else { return error; } if ((error = uci_get_value(LW_NOTIFICATION_HOSTNAME, &value)) == CWMP_OK) { - FREE(conf->lw_notification_hostname); + global_string_param_free(&conf->lw_notification_hostname); if (value != NULL) { - conf->lw_notification_hostname = strdup(value); + global_string_param_write(&conf->lw_notification_hostname, value); FREE(value); } else { - conf->lw_notification_hostname = strdup(conf->acsurl ? conf->acsurl : ""); + global_string_param_read(&conf->acsurl, &temp); + global_string_param_write(&conf->lw_notification_hostname, temp); + FREE(temp); } } else { return error; @@ -471,10 +494,10 @@ int get_global_config(struct config *conf) if ((error = uci_get_value(LW_NOTIFICATION_PORT, &value)) == CWMP_OK) { if (value != NULL) { int a = atoi(value); - conf->lw_notification_port = a; + global_int_param_write(&conf->lw_notification_port, a); FREE(value); } else { - conf->lw_notification_port = DEFAULT_LWN_PORT; + global_int_param_write(&conf->lw_notification_port, DEFAULT_LWN_PORT); } } else { return error; @@ -482,10 +505,10 @@ int get_global_config(struct config *conf) if (uci_get_value(UCI_CPE_SCHEDULE_REBOOT, &value) == CWMP_OK) { if (value != NULL) { - conf->schedule_reboot = convert_datetime_to_timestamp(value); + global_time_param_write(&conf->schedule_reboot, convert_datetime_to_timestamp(value)); FREE(value); } else { - conf->schedule_reboot = 0; + global_time_param_write(&conf->schedule_reboot, 0); } } else { return error; @@ -499,41 +522,41 @@ int get_global_config(struct config *conf) FREE(value); } - conf->delay_reboot = delay; + global_int_param_write(&conf->delay_reboot, delay); } else { return error; } if (uci_get_value(UCI_CPE_FORCED_INFORM_JSON, &value) == CWMP_OK) { - FREE(conf->forced_inform_json_file); + global_string_param_free(&conf->forced_inform_json_file); if (value != NULL) { - conf->forced_inform_json_file = strdup(value); + global_string_param_write(&conf->forced_inform_json_file, value); FREE(value); } else { - conf->forced_inform_json_file = NULL; + global_string_param_write(&conf->forced_inform_json_file, NULL); } } if (uci_get_value(UCI_CPE_BOOT_INFORM_JSON, &value) == CWMP_OK) { - FREE(conf->boot_inform_json_file); + global_string_param_free(&conf->boot_inform_json_file); if (value != NULL) { - conf->boot_inform_json_file = strdup(value); + global_string_param_write(&conf->boot_inform_json_file, value); FREE(value); } else { - conf->boot_inform_json_file = NULL; + global_string_param_write(&conf->boot_inform_json_file, NULL); } } if (uci_get_value(UCI_CPE_JSON_CUSTOM_NOTIFY_FILE, &value) == CWMP_OK) { - FREE(conf->custom_notify_json); + global_string_param_free(&conf->custom_notify_json); if (value != NULL) { - conf->custom_notify_json = strdup(value); + global_string_param_write(&conf->custom_notify_json, value); FREE(value); } else { - conf->custom_notify_json = NULL; + global_string_param_write(&conf->custom_notify_json, NULL); } } if ((error = uci_get_value(UCI_ACS_HEARTBEAT_ENABLE, &value)) == CWMP_OK) { - conf->heart_beat_enable = uci_str_to_bool(value); + global_bool_param_write(&conf->heart_beat_enable, uci_str_to_bool(value)); FREE(value); } else { return error; @@ -546,17 +569,17 @@ int get_global_config(struct config *conf) a = atoi(value); FREE(value); } - conf->heartbeat_interval = a; + global_int_param_write(&conf->heartbeat_interval, a); } else { return error; } if ((error = uci_get_value(UCI_ACS_HEARTBEAT_TIME, &value)) == CWMP_OK) { if (value != NULL) { - conf->heart_time = convert_datetime_to_timestamp(value); + global_time_param_write(&conf->heart_time, convert_datetime_to_timestamp(value)); FREE(value); } else { - conf->heart_time = 0; + global_time_param_write(&conf->heart_time, 0); } } else { return error; @@ -568,8 +591,6 @@ int global_conf_init(struct cwmp *cwmp) { int error = CWMP_OK; - pthread_mutex_lock(&mutex_config_load); - if ((error = get_global_config(&(cwmp->conf)))) { cwmp->init_complete = false; goto end; @@ -580,8 +601,6 @@ int global_conf_init(struct cwmp *cwmp) launch_reboot_methods(cwmp); end: - pthread_mutex_unlock(&mutex_config_load); - return error; } diff --git a/cwmp.c b/cwmp.c index faf1694..bb9d417 100644 --- a/cwmp.c +++ b/cwmp.c @@ -165,8 +165,8 @@ int cwmp_get_retry_interval(struct cwmp *cwmp, bool heart_beat) unsigned int retry_count = 0; double min = 0; double max = 0; - int m = cwmp->conf.retry_min_wait_interval; - int k = cwmp->conf.retry_interval_multiplier; + int m = global_int_param_read(&cwmp->conf.retry_min_wait_interval); + int k = global_int_param_read(&cwmp->conf.retry_interval_multiplier); int exp; if (heart_beat) exp = heart_beat_retry_count_session; @@ -597,21 +597,28 @@ static void check_exit_timer_expiry(struct uloop_timeout *timeout) static void *thread_uloop_run(void *v __attribute__((unused))) { + char *temp = NULL; + uloop_init(); if (netlink_init()) { CWMP_LOG(ERROR, "netlink initialization failed"); } - if (cwmp_main.conf.ipv6_enable) { + bool v6_enable = global_bool_param_read(&cwmp_main.conf.ipv6_enable); + if (v6_enable) { if (netlink_init_v6()) { CWMP_LOG(ERROR, "netlink initialization failed"); } } - ctx = ubus_connect(cwmp_main.conf.ubus_socket); - if (!ctx) + global_string_param_read(&cwmp_main.conf.ubus_socket, &temp); + ctx = ubus_connect(temp); + if (!ctx) { + FREE(temp); return NULL; + } + FREE(temp); ubus_add_uloop(ctx); @@ -641,24 +648,33 @@ void load_forced_inform_json_file(struct cwmp *cwmp) struct blob_attr *cur; struct blob_attr *custom_forced_inform_list = NULL; int rem; + char *temp = NULL; - if (cwmp->conf.forced_inform_json_file == NULL || !file_exists(cwmp->conf.forced_inform_json_file)) + global_string_param_read(&cwmp->conf.forced_inform_json_file, &temp); + if (CWMP_STRLEN(temp) == 0 || !file_exists(temp)) { + FREE(temp); return; + } memset(&bbuf, 0, sizeof(struct blob_buf)); blob_buf_init(&bbuf, 0); - if (blobmsg_add_json_from_file(&bbuf, cwmp->conf.forced_inform_json_file) == false) { - CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.forced_inform_json_file); + if (blobmsg_add_json_from_file(&bbuf, temp) == false) { + CWMP_LOG(WARNING, "The file %s is not a valid JSON file", temp); blob_buf_free(&bbuf); + FREE(temp); return; } + + FREE(temp); const struct blobmsg_policy p[1] = { { "forced_inform", BLOBMSG_TYPE_ARRAY } }; struct blob_attr *tb[1] = { NULL }; 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->conf.custom_notify_json); + global_string_param_read(&cwmp->conf.custom_notify_json, &temp); + CWMP_LOG(WARNING, "The JSON file %s doesn't contain a forced inform parameters list", temp); blob_buf_free(&bbuf); + FREE(temp); return; } @@ -682,7 +698,6 @@ void load_forced_inform_json_file(struct cwmp *cwmp) FREE(val); } blob_buf_free(&bbuf); - } void load_boot_inform_json_file(struct cwmp *cwmp) @@ -691,26 +706,34 @@ void load_boot_inform_json_file(struct cwmp *cwmp) struct blob_attr *cur; struct blob_attr *custom_boot_inform_list = NULL; int rem; + char *temp = NULL; - if (cwmp->conf.boot_inform_json_file == NULL || !file_exists(cwmp->conf.boot_inform_json_file)) + global_string_param_read(&cwmp->conf.boot_inform_json_file, &temp); + if (CWMP_STRLEN(temp) == 0 || !file_exists(temp)) { + FREE(temp); return; + } memset(&bbuf, 0, sizeof(struct blob_buf)); blob_buf_init(&bbuf, 0); - if (blobmsg_add_json_from_file(&bbuf, cwmp->conf.boot_inform_json_file) == false) { - CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.boot_inform_json_file); + if (blobmsg_add_json_from_file(&bbuf, temp) == false) { + CWMP_LOG(WARNING, "The file %s is not a valid JSON file", temp); blob_buf_free(&bbuf); + FREE(temp); return; } + FREE(temp); const struct blobmsg_policy p[1] = { { "boot_inform", BLOBMSG_TYPE_ARRAY } }; struct blob_attr *tb[1] = { NULL }; 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 boot inform parameters list", cwmp->conf.custom_notify_json); + global_string_param_read(&cwmp->conf.custom_notify_json, &temp); + CWMP_LOG(WARNING, "The JSON file %s doesn't contain a boot inform parameters list", temp); blob_buf_free(&bbuf); + FREE(temp); return; } @@ -915,21 +938,21 @@ static void cwmp_free(struct cwmp *cwmp) FREE(cwmp->deviceid.productclass); FREE(cwmp->deviceid.oui); FREE(cwmp->deviceid.softwareversion); - FREE(cwmp->conf.lw_notification_hostname); - FREE(cwmp->conf.ip); - FREE(cwmp->conf.ipv6); - FREE(cwmp->conf.acsurl); - FREE(cwmp->conf.acs_userid); - FREE(cwmp->conf.acs_passwd); - FREE(cwmp->conf.interface); - FREE(cwmp->conf.cpe_userid); - FREE(cwmp->conf.cpe_passwd); - FREE(cwmp->conf.ubus_socket); - FREE(cwmp->conf.connection_request_path); - FREE(cwmp->conf.default_wan_iface); - FREE(cwmp->conf.forced_inform_json_file); - FREE(cwmp->conf.custom_notify_json); - FREE(cwmp->conf.boot_inform_json_file); + global_string_param_free(&cwmp->conf.lw_notification_hostname); + global_string_param_free(&cwmp->conf.ip); + global_string_param_free(&cwmp->conf.ipv6); + global_string_param_free(&cwmp->conf.acsurl); + global_string_param_free(&cwmp->conf.acs_userid); + global_string_param_free(&cwmp->conf.acs_passwd); + global_string_param_free(&cwmp->conf.interface); + global_string_param_free(&cwmp->conf.cpe_userid); + global_string_param_free(&cwmp->conf.cpe_passwd); + global_string_param_free(&cwmp->conf.ubus_socket); + global_string_param_free(&cwmp->conf.connection_request_path); + global_string_param_free(&cwmp->conf.default_wan_iface); + global_string_param_free(&cwmp->conf.forced_inform_json_file); + global_string_param_free(&cwmp->conf.custom_notify_json); + global_string_param_free(&cwmp->conf.boot_inform_json_file); FREE(nonce_key); clean_list_param_notify(); bkp_tree_clean(); @@ -979,8 +1002,11 @@ static void configure_var_state(struct cwmp *cwmp) cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG); cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG); - get_firewall_zone_name_by_wan_iface(cwmp->conf.default_wan_iface, &zone_name); + char *def_wan_intf = NULL; + global_string_param_read(&cwmp->conf.default_wan_iface, &def_wan_intf); + get_firewall_zone_name_by_wan_iface(def_wan_intf, &zone_name); cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan"); + FREE(def_wan_intf); } int main(int argc, char **argv) diff --git a/datamodel_interface.c b/datamodel_interface.c index 4584f46..7543497 100755 --- a/datamodel_interface.c +++ b/datamodel_interface.c @@ -363,7 +363,8 @@ char *cwmp_get_single_parameter_value(char *parameter_name, struct cwmp_dm_param blob_buf_init(&b, 0); bb_add_string(&b, "path", !parameter_name || parameter_name[0] == '\0' ? DM_ROOT_OBJ : parameter_name); bb_add_string(&b, "proto", "cwmp"); - blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp->conf.instance_mode); + blobmsg_add_u32(&b, "instance_mode", mode); e = icwmp_ubus_invoke(USP_OBJECT_NAME, "get", b.head, ubus_get_single_parameter_callback, dm_parameter); blob_buf_free(&b); @@ -457,7 +458,8 @@ char *cwmp_get_parameter_values(char *parameter_name, struct list_head *paramete blob_buf_init(&b, 0); bb_add_string(&b, "path", param); bb_add_string(&b, "proto", "cwmp"); - blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp->conf.instance_mode); + blobmsg_add_u32(&b, "instance_mode", mode); e = icwmp_ubus_invoke(USP_OBJECT_NAME, "get", b.head, ubus_get_parameter_callback, &get_result); blob_buf_free(&b); @@ -491,7 +493,8 @@ char *cwmp_get_multiple_parameters_values(struct list_head *arg_params_list, str blobmsg_add_string(&b, NULL, param_value->name); } blobmsg_close_array(&b, arr); - blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp->conf.instance_mode); + blobmsg_add_u32(&b, "instance_mode", mode); e = icwmp_ubus_invoke(USP_OBJECT_NAME, "getm_values", b.head, ubus_get_parameter_callback, &get_result ); blob_buf_free(&b); @@ -521,7 +524,8 @@ char *cwmp_get_parameter_names(char *object_name, bool next_level, struct list_h bb_add_string(&b, "path", object); blobmsg_add_u8(&b, "next-level", next_level); bb_add_string(&b, "proto", "cwmp"); - blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp->conf.instance_mode); + blobmsg_add_u32(&b, "instance_mode", mode); e = icwmp_ubus_invoke(USP_OBJECT_NAME, "object_names", b.head, ubus_get_parameter_callback, &get_result); blob_buf_free(&b); @@ -603,7 +607,8 @@ int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list bb_add_string(&b, "key", parameter_key ? parameter_key : ""); blobmsg_add_u32(&b, "transaction_id", transaction_id); bb_add_string(&b, "proto", "cwmp"); - blobmsg_add_u32(&b, "instance_mode", cwmp->conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp->conf.instance_mode); + blobmsg_add_u32(&b, "instance_mode", mode); e = icwmp_ubus_invoke(USP_OBJECT_NAME, "setm_values", b.head, ubus_setm_values_callback, &set_result); blob_buf_free(&b); @@ -670,7 +675,8 @@ static void prepare_add_delete_blobmsg(struct blob_buf *b, char *object_name, ch bb_add_string(b, "key", key ? key : ""); blobmsg_add_u32(b, "transaction_id", transaction_id); bb_add_string(b, "proto", "cwmp"); - blobmsg_add_u32(b, "instance_mode", cwmp_main.conf.instance_mode); + unsigned int mode = global_uint_param_read(&cwmp_main.conf.instance_mode); + blobmsg_add_u32(b, "instance_mode", mode); } char *cwmp_add_object(char *object_name, char *key, char **instance) diff --git a/event.c b/event.c index 52e53a5..88da970 100644 --- a/event.c +++ b/event.c @@ -185,7 +185,9 @@ int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp) if (acsurl == NULL) save_acs_bkp_config(cwmp); - if (acsurl == NULL || ((cmp = CWMP_STRCMP(cwmp->conf.acsurl, acsurl)) != 0)) { + char *conf_url = NULL; + global_string_param_read(&cwmp->conf.acsurl, &conf_url); + if (acsurl == NULL || ((cmp = CWMP_STRCMP(conf_url, acsurl)) != 0)) { pthread_mutex_lock(&(cwmp->mutex_session_queue)); if (cwmp->head_event_container != NULL && cwmp->head_session_queue.next != &(cwmp->head_session_queue)) { struct session *session; @@ -209,6 +211,7 @@ int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp) } else { FREE(acsurl); } + FREE(conf_url); if (cmp) { pthread_mutex_lock(&(cwmp->mutex_session_queue)); @@ -329,7 +332,7 @@ int cwmp_root_cause_get_rpc_method(struct cwmp *cwmp) } cwmp_save_event_container(event_container); session = list_entry(cwmp->head_event_container, struct session, head_event_container); - if (cwmp->conf.acs_getrpc && cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) { + if (global_bool_param_read(&cwmp->conf.acs_getrpc) && cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) { pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -351,18 +354,19 @@ void *thread_event_periodic(void *v) long int delta_time; time_t unknown_time; - periodic_interval = cwmp->conf.period; - periodic_enable = cwmp->conf.periodic_enable; - periodic_time = cwmp->conf.time; + periodic_interval = global_int_param_read(&cwmp->conf.period); + periodic_enable = global_bool_param_read(&cwmp->conf.periodic_enable); + periodic_time = global_time_param_read(&cwmp->conf.time); unknown_time = convert_datetime_to_timestamp("0001-01-01T00:00:00Z"); for (;;) { pthread_mutex_lock(&(cwmp->mutex_periodic)); - if (cwmp->conf.periodic_enable) { + if (periodic_enable) { current_time = time(NULL); if (periodic_time != 0) { if (periodic_time == unknown_time) { - delta_time = (current_time + cwmp->conf.periodic_entropy) % periodic_interval; + unsigned int periodic_entropy = global_uint_param_read(&cwmp->conf.periodic_entropy); + delta_time = (current_time + periodic_entropy) % periodic_interval; } else { delta_time = (current_time - periodic_time) % periodic_interval; } @@ -385,10 +389,10 @@ void *thread_event_periodic(void *v) if (thread_end) break; - if (periodic_interval != cwmp->conf.period || periodic_enable != cwmp->conf.periodic_enable || periodic_time != cwmp->conf.time) { - periodic_enable = cwmp->conf.periodic_enable; - periodic_interval = cwmp->conf.period; - periodic_time = cwmp->conf.time; + if (periodic_interval != global_int_param_read(&cwmp->conf.period) || periodic_enable != global_bool_param_read(&cwmp->conf.periodic_enable) || periodic_time != global_time_param_read(&cwmp->conf.time)) { + periodic_enable = global_bool_param_read(&cwmp->conf.periodic_enable); + periodic_interval = global_int_param_read(&cwmp->conf.period); + periodic_time = global_time_param_read(&cwmp->conf.time); continue; } CWMP_LOG(INFO, "Periodic thread: add periodic event in the queue"); @@ -420,13 +424,13 @@ int cwmp_root_cause_event_periodic(struct cwmp *cwmp) char local_time[27] = { 0 }; struct tm *t_tm; - if (cwmp->cwmp_period == cwmp->conf.period && cwmp->cwmp_periodic_enable == cwmp->conf.periodic_enable && cwmp->cwmp_periodic_time == cwmp->conf.time) + if (cwmp->cwmp_period == global_int_param_read(&cwmp->conf.period) && cwmp->cwmp_periodic_enable == global_bool_param_read(&cwmp->conf.periodic_enable) && cwmp->cwmp_periodic_time == global_time_param_read(&cwmp->conf.time)) return CWMP_OK; pthread_mutex_lock(&(cwmp->mutex_periodic)); - cwmp->cwmp_period = cwmp->conf.period; - cwmp->cwmp_periodic_enable = cwmp->conf.periodic_enable; - cwmp->cwmp_periodic_time = cwmp->conf.time; + cwmp->cwmp_period = global_int_param_read(&cwmp->conf.period); + cwmp->cwmp_periodic_enable = global_bool_param_read(&cwmp->conf.periodic_enable); + cwmp->cwmp_periodic_time = global_time_param_read(&cwmp->conf.time); CWMP_LOG(INFO, cwmp->cwmp_periodic_enable ? "Periodic event is enabled. Interval period = %ds" : "Periodic event is disabled", cwmp->cwmp_period); t_tm = localtime(&cwmp->cwmp_periodic_time); @@ -451,7 +455,8 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version) { char *bip = NULL; char *ip_version = (version == IPv6) ? "ipv6" : "ip"; - char *ip_value = (version == IPv6) ? cwmp->conf.ipv6 : cwmp->conf.ip; + char *ip_value = NULL; + (version == IPv6) ? global_string_param_read(&cwmp->conf.ipv6, &ip_value) : global_string_param_read(&cwmp->conf.ip, &ip_value); if (version == IPv6) cwmp_load_saved_session(cwmp, &bip, CR_IPv6); @@ -481,6 +486,7 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version) pthread_cond_signal(&(cwmp->threshold_session_send)); } FREE(bip); + FREE(ip_value); } void connection_request_port_value_change(struct cwmp *cwmp, int port) diff --git a/heartbeat.c b/heartbeat.c index 9784458..7845ad6 100644 --- a/heartbeat.c +++ b/heartbeat.c @@ -22,7 +22,8 @@ static struct session_status heart_beat_session_status = {0}; void check_trigger_heartbeat_session() { - if (cwmp_main.conf.heart_beat_enable && !old_heartbeat_enable) + bool enable = global_bool_param_read(&cwmp_main.conf.heart_beat_enable); + if (enable && !old_heartbeat_enable) pthread_cond_signal(&threshold_heartbeat_session); } @@ -55,8 +56,9 @@ void *thread_heartbeat_session(void *v __attribute__((unused))) if (thread_end) break; - if (cwmp_main.conf.heart_beat_enable) { - heartbeat_interval.tv_sec = time(NULL) + cwmp_main.conf.heartbeat_interval; + bool enable = global_bool_param_read(&cwmp_main.conf.heart_beat_enable); + if (enable) { + heartbeat_interval.tv_sec = time(NULL) + global_int_param_read(&cwmp_main.conf.heartbeat_interval); pthread_mutex_lock(&mutex_heartbeat); pthread_cond_timedwait(&threshold_heartbeat_session, &mutex_heartbeat, &heartbeat_interval); if (thread_end) @@ -151,7 +153,7 @@ void *thread_heartbeat_session(void *v __attribute__((unused))) heart_beat_session_status.last_status = SESSION_SUCCESS; heart_beat_session_status.next_retry = 0; heart_beat_session_status.success_session++; - heartbeat_interval.tv_sec = time(NULL) + cwmp_main.conf.heartbeat_interval; + heartbeat_interval.tv_sec = time(NULL) + global_int_param_read(&cwmp_main.conf.heartbeat_interval); pthread_mutex_unlock(&mutex_heartbeat_session); pthread_mutex_unlock(&mutex_heartbeat); } else { diff --git a/http.c b/http.c index dc12e27..e6962d1 100644 --- a/http.c +++ b/http.c @@ -45,6 +45,8 @@ int http_client_init(struct cwmp *cwmp) char *acs_var_stat = NULL; uci_get_value(UCI_DHCP_DISCOVERY_PATH, &dhcp_dis); + char *url = NULL; + global_string_param_read(&cwmp->conf.acsurl, &url); if (dhcp_dis && cwmp->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) { uci_get_state_value(UCI_DHCP_ACS_URL, &acs_var_stat); @@ -52,20 +54,24 @@ int http_client_init(struct cwmp *cwmp) if (icwmp_asprintf(&http_c.url, "%s", acs_var_stat) == -1) { free(acs_var_stat); FREE(dhcp_dis); + FREE(url); return -1; } } else { - if (cwmp->conf.acsurl == NULL || icwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) { + if (CWMP_STRLEN(url) == 0 || icwmp_asprintf(&http_c.url, "%s", url) == -1) { FREE(dhcp_dis); + FREE(url); return -1; } } } else { - if (cwmp->conf.acsurl == NULL || icwmp_asprintf(&http_c.url, "%s", cwmp->conf.acsurl) == -1) { + if (url == NULL || icwmp_asprintf(&http_c.url, "%s", url) == -1) { FREE(dhcp_dis); + FREE(url); return -1; } } + FREE(url); if (dhcp_dis) free(dhcp_dis); @@ -79,7 +85,8 @@ int http_client_init(struct cwmp *cwmp) if (!curl) return -1; - if (cwmp->conf.ipv6_enable) { + bool v6_enable = global_bool_param_read(&cwmp->conf.ipv6_enable); + if (v6_enable) { unsigned char buf[sizeof(struct in6_addr)]; char *ip = NULL; @@ -146,7 +153,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char ** CURLcode res; long http_code = 0; static char ip_acs[128] = { 0 }; - char *ip = NULL; + char *ip = NULL, *temp = NULL; char errbuf[CURL_ERROR_SIZE]; http_c.header_list = NULL; @@ -157,21 +164,25 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char ** if (!http_c.header_list) return -1; - if (cwmp->conf.http_disable_100continue) { + if (global_bool_param_read(&cwmp->conf.http_disable_100continue)) { http_c.header_list = curl_slist_append(http_c.header_list, "Expect:"); if (!http_c.header_list) return -1; } curl_easy_setopt(curl, CURLOPT_URL, http_c.url); - curl_easy_setopt(curl, CURLOPT_USERNAME, cwmp->conf.acs_userid); - curl_easy_setopt(curl, CURLOPT_PASSWORD, cwmp->conf.acs_passwd); + global_string_param_read(&cwmp->conf.acs_userid, &temp); + curl_easy_setopt(curl, CURLOPT_USERNAME, temp); + FREE(temp); + global_string_param_read(&cwmp->conf.acs_passwd, &temp); + curl_easy_setopt(curl, CURLOPT_PASSWORD, temp); + FREE(temp); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST); curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, HTTP_TIMEOUT); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL); curl_easy_setopt(curl, CURLOPT_NOBODY, 0); - switch (cwmp->conf.compression) { + switch (global_int_param_read(&cwmp->conf.compression)) { case COMP_NONE: break; case COMP_GZIP: @@ -201,14 +212,18 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char ** curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies); curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies); - if (cwmp->conf.acs_ssl_capath) - curl_easy_setopt(curl, CURLOPT_CAPATH, cwmp->conf.acs_ssl_capath); - if (cwmp->conf.insecure_enable) { + global_string_param_read(&cwmp->conf.acs_ssl_capath, &temp); + if (CWMP_STRLEN(temp) != 0) + curl_easy_setopt(curl, CURLOPT_CAPATH, temp); + if (global_bool_param_read(&cwmp->conf.insecure_enable)) { curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); } + FREE(temp); - curl_easy_setopt(curl, CURLOPT_INTERFACE, cwmp->conf.interface); + global_string_param_read(&cwmp->conf.interface, &temp); + curl_easy_setopt(curl, CURLOPT_INTERFACE, temp); + FREE(temp); *msg_in = (char *)calloc(1, sizeof(char)); res = curl_easy_perform(curl); @@ -255,7 +270,7 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char ** } if (http_code == 415) { - cwmp->conf.compression = COMP_NONE; + global_int_param_write(&cwmp->conf.compression, COMP_NONE); goto error; } if (http_code != 200 && http_code != 204) @@ -301,6 +316,7 @@ static void http_cr_new_client(int client, bool service_available) bool method_is_get = false; bool internal_error = false; char cr_http_get_head[HTTP_GET_HDR_LEN] = {0}; + char *temp = NULL; fp = fdopen(client, "r+"); if (fp == NULL) { @@ -308,8 +324,10 @@ static void http_cr_new_client(int client, bool service_available) service_available = false; goto http_end; } - char *username = cwmp_main.conf.cpe_userid; - char *password = cwmp_main.conf.cpe_passwd; + char *username = NULL; + global_string_param_read(&cwmp_main.conf.cpe_userid, &username); + char *password = NULL; + global_string_param_read(&cwmp_main.conf.cpe_passwd, &password); memset(auth_digest_buffer, 0, BUFSIZ); if (!username || !password) { @@ -318,7 +336,10 @@ static void http_cr_new_client(int client, bool service_available) service_available = false; goto http_end; } - snprintf(cr_http_get_head, sizeof(cr_http_get_head), "GET %s HTTP/1.1", cwmp_main.conf.connection_request_path); + + global_string_param_read(&cwmp_main.conf.connection_request_path, &temp); + snprintf(cr_http_get_head, sizeof(cr_http_get_head), "GET %s HTTP/1.1", temp); + FREE(temp); while (fgets(buffer, sizeof(buffer), fp)) { if (buffer[0] == '\r' || buffer[0] == '\n') { /* end of http request (empty line) */ @@ -369,6 +390,8 @@ static void http_cr_new_client(int client, bool service_available) else auth_status = 0; http_end: + FREE(username); + FREE(password); if (!service_available || !method_is_get) { CWMP_LOG(INFO, "Receive Connection Request: Return 503 Service Unavailable"); if (fp) { @@ -413,7 +436,7 @@ void http_server_init(void) unsigned short cr_port; for (;;) { - cr_port = (unsigned short)(cwmp_main.conf.connection_request_port); + cr_port = (unsigned short)global_int_param_read(&cwmp_main.conf.connection_request_port); unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port) ? 1 : 0; //Create socket cwmp_main.cr_socket_desc = socket(AF_INET6, SOCK_STREAM, 0); diff --git a/inc/common.h b/inc/common.h index 8c8c666..7d45eca 100644 --- a/inc/common.h +++ b/inc/common.h @@ -547,5 +547,16 @@ int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session); int run_session_end_func(void); void set_interface_reset_request(char *param_name, char *value); bool uci_str_to_bool(char *value); +bool global_bool_param_read(const bool *param); +void global_string_param_read(char **param, char **val); +int global_int_param_read(const int *param); +time_t global_time_param_read(const time_t *param); +unsigned int global_uint_param_read(const unsigned int *param); +void global_bool_param_write(bool *param, bool value); +void global_string_param_write(char **param, char *value); +void global_int_param_write(int *param, int value); +void global_time_param_write(time_t *param, time_t value); +void global_uint_param_write(unsigned int *param, unsigned int value); +void global_string_param_free(char **param); #endif diff --git a/inc/config.h b/inc/config.h index 41858bb..6ae6719 100755 --- a/inc/config.h +++ b/inc/config.h @@ -15,8 +15,6 @@ #include "cwmp_uci.h" -extern pthread_mutex_t mutex_config_load; - int global_conf_init(struct cwmp *cwmp); int get_global_config(struct config *conf); int cwmp_get_deviceid(struct cwmp *cwmp); diff --git a/netlink.c b/netlink.c index e34b8d0..59563fe 100644 --- a/netlink.c +++ b/netlink.c @@ -111,16 +111,20 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh) } if_indextoname(ifa->ifa_index, if_name); - if (itfcmp(cwmp_main.conf.interface, if_name)) { + char *intf = NULL; + global_string_param_read(&cwmp_main.conf.interface, &intf); + if (itfcmp(intf, if_name)) { rth = RTA_NEXT(rth, rtl); + FREE(intf); continue; } + FREE(intf); inet_ntop(AF_INET, &(addr), if_addr, INET_ADDRSTRLEN); - FREE(cwmp_main.conf.ip); - cwmp_main.conf.ip = strdup(if_addr); - cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", cwmp_main.conf.ip); + global_string_param_free(&cwmp_main.conf.ip); + global_string_param_write(&cwmp_main.conf.ip, if_addr); + cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", if_addr); connection_request_ip_value_change(&cwmp_main, IPv4); break; } @@ -133,14 +137,18 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh) } inet_ntop(AF_INET6, RTA_DATA(rth), pradd_v6, sizeof(pradd_v6)); if_indextoname(ifa->ifa_index, if_name); - if (strncmp(cwmp_main.conf.interface, if_name, IFNAMSIZ)) { + char *intf = NULL; + global_string_param_read(&cwmp_main.conf.interface, &intf); + if (strncmp(intf, if_name, IFNAMSIZ)) { rth = RTA_NEXT(rth, rtl); + FREE(intf); continue; } + FREE(intf); - FREE(cwmp_main.conf.ipv6); - cwmp_main.conf.ipv6 = strdup(pradd_v6); - cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", cwmp_main.conf.ip); + global_string_param_free(&cwmp_main.conf.ipv6); + global_string_param_write(&cwmp_main.conf.ipv6, pradd_v6); + cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", pradd_v6); connection_request_ip_value_change(&cwmp_main, IPv6); break; } diff --git a/notifications.c b/notifications.c index dc37021..f945b2e 100644 --- a/notifications.c +++ b/notifications.c @@ -476,21 +476,28 @@ void load_custom_notify_json(struct cwmp *cwmp) int rem; cwmp->custom_notify_active = false; - if (cwmp->conf.custom_notify_json == NULL || !file_exists(cwmp->conf.custom_notify_json)) + char *cust_notify_json = NULL; + global_string_param_read(&cwmp->conf.custom_notify_json, &cust_notify_json); + if (CWMP_STRLEN(cust_notify_json) == 0 || !file_exists(cust_notify_json)) { + FREE(cust_notify_json); return; + } // Check for custom notification success import marker - if (file_exists(NOTIFY_MARKER) == true) + if (file_exists(NOTIFY_MARKER) == true) { + FREE(cust_notify_json); return; + } memset(&bbuf, 0, sizeof(struct blob_buf)); 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->conf.custom_notify_json) == false) { - CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cwmp->conf.custom_notify_json); + if (blobmsg_add_json_from_file(&bbuf, cust_notify_json) == false) { + CWMP_LOG(WARNING, "The file %s is not a valid JSON file", cust_notify_json); blob_buf_free(&bbuf); creat(RUN_NOTIFY_MARKER, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + FREE(cust_notify_json); return; } @@ -498,11 +505,13 @@ void load_custom_notify_json(struct cwmp *cwmp) struct blob_attr *tb_notif[1] = { NULL}; 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->conf.custom_notify_json); + CWMP_LOG(WARNING, "The JSON file %s doesn't contain a notify parameters list", cust_notify_json); blob_buf_free(&bbuf); creat(RUN_NOTIFY_MARKER, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + FREE(cust_notify_json); return; } + FREE(cust_notify_json); custom_notify_list = tb_notif[0]; const struct blobmsg_policy p[2] = { { "parameter", BLOBMSG_TYPE_STRING }, { "notify_type", BLOBMSG_TYPE_STRING } }; @@ -674,8 +683,8 @@ void *thread_periodic_check_notify(void *v) time_t current_time; int is_notify; - periodic_interval = cwmp->conf.periodic_notify_interval; - periodic_enable = cwmp->conf.periodic_notify_enable; + periodic_interval = global_int_param_read(&cwmp->conf.periodic_notify_interval); + periodic_enable = global_bool_param_read(&cwmp->conf.periodic_notify_enable); for (;;) { if (periodic_enable) { @@ -752,8 +761,11 @@ static void udplw_server_param(struct addrinfo **res) conf = &(cwmp->conf); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; - snprintf(port, sizeof(port), "%d", conf->lw_notification_port); - getaddrinfo(conf->lw_notification_hostname, port, &hints, res); + snprintf(port, sizeof(port), "%d", global_int_param_read(&conf->lw_notification_port)); + char *hostname = NULL; + global_string_param_read(&conf->lw_notification_hostname, &hostname); + getaddrinfo(hostname, port, &hints, res); + FREE(hostname); } char *calculate_lwnotification_cnonce() @@ -823,8 +835,10 @@ void cwmp_lwnotification() return; } message_compute_signature(msg_out, signature, sizeof(signature)); - snprintf(msg, sizeof(msg), "%s \n %s: %s \n %s: %s \n %s: %zu\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", conf->lw_notification_hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out); - + char *hostname = NULL; + global_string_param_read(&conf->lw_notification_hostname, &hostname); + snprintf(msg, sizeof(msg), "%s \n %s: %s \n %s: %s \n %s: %zu\n %s: %s\n\n%s", "POST /HTTPS/1.1", "HOST", hostname, "Content-Type", "test/xml; charset=utf-8", "Content-Lenght", strlen(msg_out), "Signature", signature, msg_out); + FREE(hostname); send_udp_message(servaddr, msg); free_all_list_lw_notify(); //freeaddrinfo(servaddr); //To check diff --git a/reboot.c b/reboot.c index d02a14f..2b34b39 100644 --- a/reboot.c +++ b/reboot.c @@ -23,8 +23,9 @@ static void *thread_delay_reboot(void *arg) { struct cwmp *cwmp = (struct cwmp *)arg; - CWMP_LOG(INFO, "The device will reboot after %d seconds", cwmp->conf.delay_reboot); - sleep(cwmp->conf.delay_reboot); + int delay_reboot = global_int_param_read(&cwmp->conf.delay_reboot); + CWMP_LOG(INFO, "The device will reboot after %d seconds", delay_reboot); + sleep(delay_reboot); cwmp_uci_set_value("cwmp", "cpe", "delay_reboot", "-1"); /* check if the session is running before calling reboot method */ /* if the session is in progress, wait until the end of the session */ @@ -62,7 +63,7 @@ static void create_delay_reboot_thread(struct cwmp *cwmp, bool thread_exist) static void *thread_schedule_reboot(void *arg) { struct cwmp *cwmp = (struct cwmp *)arg; - time_t remaining_time = cwmp->conf.schedule_reboot - time(NULL); + time_t remaining_time = global_time_param_read(&cwmp->conf.schedule_reboot) - time(NULL); CWMP_LOG(INFO, "The device will reboot after %ld seconds", remaining_time); sleep(remaining_time); @@ -103,16 +104,18 @@ static void create_schedule_reboot_thread(struct cwmp *cwmp, bool thread_exist) void launch_reboot_methods(struct cwmp *cwmp) { + int delay_reboot = global_int_param_read(&cwmp->conf.delay_reboot); + time_t schedule_reboot = global_time_param_read(&cwmp->conf.schedule_reboot); - if (cwmp->conf.delay_reboot != g_curr_delay_reboot && cwmp->conf.delay_reboot > 0) { + if (delay_reboot != g_curr_delay_reboot && delay_reboot > 0) { create_delay_reboot_thread(cwmp, (g_curr_delay_reboot != -1)); - g_curr_delay_reboot = cwmp->conf.delay_reboot; + g_curr_delay_reboot = delay_reboot; } - if (cwmp->conf.schedule_reboot != g_curr_schedule_redoot && (cwmp->conf.schedule_reboot - time(NULL)) > 0) { + if (schedule_reboot != g_curr_schedule_redoot && (schedule_reboot - time(NULL)) > 0) { create_schedule_reboot_thread(cwmp, (g_curr_schedule_redoot != 0)); - g_curr_schedule_redoot = cwmp->conf.schedule_reboot; + g_curr_schedule_redoot = schedule_reboot; } } diff --git a/rpc_soap.c b/rpc_soap.c index 14e9c51..3acce60 100755 --- a/rpc_soap.c +++ b/rpc_soap.c @@ -131,7 +131,7 @@ int xml_handle_message(struct session *session) CWMP_LOG(INFO, "SOAP RPC message: %s", c); rpc_cpe = NULL; for (i = 1; i < __RPC_CPE_MAX; i++) { - if (i != RPC_CPE_FAULT && c && strcmp(c, rpc_cpe_methods[i].name) == 0 && rpc_cpe_methods[i].amd <= conf->supported_amd_version) { + if (i != RPC_CPE_FAULT && c && strcmp(c, rpc_cpe_methods[i].name) == 0 && rpc_cpe_methods[i].amd <= global_int_param_read(&conf->supported_amd_version)) { CWMP_LOG(INFO, "%s RPC is supported", c); rpc_cpe = cwmp_add_session_rpc_cpe(session, i); if (rpc_cpe == NULL) @@ -275,7 +275,8 @@ static void load_inform_xml_schema(mxml_node_t **tree, struct cwmp *cwmp, struct mxmlElementSetAttr(envelope, "xmlns:soap_enc", "http://schemas.xmlsoap.org/soap/encoding/"); mxmlElementSetAttr(envelope, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); mxmlElementSetAttr(envelope, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - mxmlElementSetAttr(envelope, "xmlns:cwmp", cwmp_urls[(cwmp->conf.supported_amd_version) - 1]); + int amd_ver = global_int_param_read(&cwmp->conf.supported_amd_version); + mxmlElementSetAttr(envelope, "xmlns:cwmp", cwmp_urls[amd_ver - 1]); mxml_node_t *header = mxmlNewElement(envelope, "soap_env:Header"); if (header == NULL) { @@ -292,7 +293,7 @@ static void load_inform_xml_schema(mxml_node_t **tree, struct cwmp *cwmp, struct mxmlElementSetAttr(id, "soap_env:mustUnderstand", "1"); mxml_node_t *node = NULL; - if (cwmp->conf.supported_amd_version >= 4) { + if (amd_ver >= 4) { node = mxmlNewElement(header, "cwmp:SessionTimeout"); if (!node) { MXML_DELETE(xml); @@ -300,14 +301,15 @@ static void load_inform_xml_schema(mxml_node_t **tree, struct cwmp *cwmp, struct } mxmlElementSetAttr(node, "soap_env:mustUnderstand", "0"); - node = mxmlNewInteger(node, cwmp->conf.session_timeout); + unsigned int sess_timeout = global_uint_param_read(&cwmp->conf.session_timeout); + node = mxmlNewInteger(node, sess_timeout); if (!node) { MXML_DELETE(xml); return; } } - if (cwmp->conf.supported_amd_version >= 5) { + if (amd_ver >= 5) { node = mxmlNewElement(header, "cwmp:SupportedCWMPVersions"); if (!node) { MXML_DELETE(xml); @@ -315,7 +317,7 @@ static void load_inform_xml_schema(mxml_node_t **tree, struct cwmp *cwmp, struct } mxmlElementSetAttr(node, "soap_env:mustUnderstand", "0"); - node = mxmlNewOpaque(node, xml_get_cwmp_version(cwmp->conf.supported_amd_version)); + node = mxmlNewOpaque(node, xml_get_cwmp_version(amd_ver)); if (!node) { MXML_DELETE(xml); return; @@ -545,19 +547,21 @@ int cwmp_rpc_acs_parse_response_inform(struct cwmp *cwmp, struct session *sessio b = mxmlWalkNext(b, tree, MXML_DESCEND_FIRST); if (!b || mxmlGetType(b) != MXML_OPAQUE || !mxmlGetOpaque(b)) goto error; - if (cwmp->conf.supported_amd_version == 1) { - cwmp->conf.amd_version = 1; + + int supported_amd_version = global_int_param_read(&cwmp->conf.supported_amd_version); + if (supported_amd_version == 1) { + global_int_param_write(&cwmp->conf.amd_version, 1); return 0; } b = mxmlFindElement(tree, tree, "UseCWMPVersion", NULL, NULL, MXML_DESCEND); - if (b && cwmp->conf.supported_amd_version >= 5) { //IF supported version !=5 acs response dosen't contain UseCWMPVersion + if (b && 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->conf.amd_version = atoi(c) + 1; + global_int_param_write(&cwmp->conf.amd_version, atoi(c) + 1); return 0; } goto error; @@ -570,28 +574,28 @@ int cwmp_rpc_acs_parse_response_inform(struct cwmp *cwmp, struct session *sessio } } if (i == 0) { - cwmp->conf.amd_version = i + 1; + global_int_param_write(&cwmp->conf.amd_version, i + 1); } else if (i >= 1 && i <= 3) { - switch (cwmp->conf.supported_amd_version) { + switch (supported_amd_version) { case 1: - cwmp->conf.amd_version = 1; //Already done + global_int_param_write(&cwmp->conf.amd_version, 1); //Already done break; case 2: case 3: case 4: //MIN ACS CPE - if (cwmp->conf.supported_amd_version <= i + 1) - cwmp->conf.amd_version = cwmp->conf.supported_amd_version; + if (supported_amd_version <= i + 1) + global_int_param_write(&cwmp->conf.amd_version, supported_amd_version); else - cwmp->conf.amd_version = i + 1; + global_int_param_write(&cwmp->conf.amd_version, i + 1); break; //(cwmp->supported_conf.amd_version < i+1) ?"cwmp->conf.amd_version":"i+1"; case 5: - cwmp->conf.amd_version = i + 1; + global_int_param_write(&cwmp->conf.amd_version, i + 1); break; } } else if (i >= 4) { - cwmp->conf.amd_version = cwmp->conf.supported_amd_version; + global_int_param_write(&cwmp->conf.amd_version, supported_amd_version); } return 0; @@ -666,7 +670,9 @@ int cwmp_rpc_acs_prepare_get_rpc_methods(struct cwmp *cwmp, struct session *sess n = mxmlFindElement(tree, tree, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); if (!n) return -1; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp->conf.amd_version) - 1]); + + int amd_version = global_int_param_read(&cwmp->conf.amd_version); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[amd_version - 1]); n = mxmlFindElement(tree, tree, "soap_env:Body", NULL, NULL, MXML_DESCEND); if (!n) return -1; @@ -697,7 +703,8 @@ int cwmp_rpc_acs_prepare_transfer_complete(struct cwmp *cwmp, struct session *se n = mxmlFindElement(tree, tree, "soap_env:Envelope", NULL, NULL, MXML_DESCEND); if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp->conf.amd_version) - 1]); + int amd_version = global_int_param_read(&cwmp->conf.amd_version); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[amd_version - 1]); n = mxmlFindElement(tree, tree, "soap_env:Body", NULL, NULL, MXML_DESCEND); if (!n) @@ -792,7 +799,8 @@ int cwmp_rpc_acs_prepare_du_state_change_complete(struct cwmp *cwmp, struct sess if (!n) goto error; - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(cwmp->conf.amd_version) - 1]); + int amd_version = global_int_param_read(&cwmp->conf.amd_version); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[amd_version - 1]); n = mxmlFindElement(tree, tree, "soap_env:Body", NULL, NULL, MXML_DESCEND); if (!n) goto error; diff --git a/session.c b/session.c index a321bff..ecb28c5 100644 --- a/session.c +++ b/session.c @@ -55,7 +55,7 @@ int cwmp_apply_acs_changes(void) { int error; - old_heartbeat_enable = cwmp_main.conf.heart_beat_enable; + old_heartbeat_enable = global_bool_param_read(&cwmp_main.conf.heart_beat_enable); if ((error = cwmp_config_reload(&cwmp_main))) return error; @@ -112,7 +112,7 @@ struct session *cwmp_add_queue_session(struct cwmp *cwmp) /* * Set Required methods as initial value of */ - if (cwmp->conf.acs_getrpc) { + if (global_bool_param_read(&cwmp->conf.acs_getrpc)) { rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_GET_RPC_METHODS); if (rpc_acs == NULL) { FREE(session); @@ -167,6 +167,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio struct list_head *ilist, *jlist; struct rpc *rpc_acs, *queue_rpc_acs; struct session *session_queue; + bool acs_getrpc = global_bool_param_read(&cwmp->conf.acs_getrpc); pthread_mutex_lock(&(cwmp->mutex_session_queue)); cwmp->retry_count_session++; @@ -179,7 +180,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio if (session->head_rpc_acs.next != &(session->head_rpc_acs)) { rpc_acs = list_entry(session->head_rpc_acs.next, struct rpc, list); if (rpc_acs->type != RPC_ACS_INFORM) { - if (cwmp->conf.acs_getrpc && cwmp_add_session_rpc_acs_head(session, RPC_ACS_GET_RPC_METHODS) == NULL) { + if (acs_getrpc && cwmp_add_session_rpc_acs_head(session, RPC_ACS_GET_RPC_METHODS) == NULL) { pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } @@ -189,7 +190,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio } } } else { - if (cwmp->conf.acs_getrpc && cwmp_add_session_rpc_acs_head(session, RPC_ACS_GET_RPC_METHODS) == NULL) { + if (acs_getrpc && cwmp_add_session_rpc_acs_head(session, RPC_ACS_GET_RPC_METHODS) == NULL) { pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } diff --git a/ssl_utils.c b/ssl_utils.c index 175fabf..fc3ccb8 100644 --- a/ssl_utils.c +++ b/ssl_utils.c @@ -121,18 +121,23 @@ void message_compute_signature(char *msg_out, char *signature, size_t len) struct cwmp *cwmp = &cwmp_main; struct config *conf; conf = &(cwmp->conf); + char *password = NULL; + + global_string_param_read(&conf->acs_passwd, &password); #ifdef LMBEDTLS unsigned char result[MBEDTLS_MD_MAX_SIZE] = {0}; const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1); - mbedtls_md_hmac(md_info, (unsigned char *)conf->acs_passwd, CWMP_STRLEN(conf->acs_passwd), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result); + mbedtls_md_hmac(md_info, (unsigned char *)password, CWMP_STRLEN(password), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result); #else unsigned char result[EVP_MAX_MD_SIZE] = {0}; - HMAC(EVP_sha1(), conf->acs_passwd, CWMP_STRLEN(conf->acs_passwd), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result, NULL); + HMAC(EVP_sha1(), password, CWMP_STRLEN(password), (unsigned char *)msg_out, CWMP_STRLEN(msg_out), result, NULL); #endif + FREE(password); + 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 break; diff --git a/ubus_utils.c b/ubus_utils.c index 8c6d788..c21576c 100644 --- a/ubus_utils.c +++ b/ubus_utils.c @@ -183,7 +183,10 @@ static void bb_add_icwmp_status(struct blob_buf *bb) void *tbl = blobmsg_open_table(bb, "cwmp"); bb_add_string(bb, "status", cwmp_main.init_complete ? "up" : "init"); bb_add_string(bb, "start_time", get_time(cwmp_main.start_time)); - bb_add_string(bb, "acs_url", cwmp_main.conf.acsurl); + char *acs_url = NULL; + global_string_param_read(&cwmp_main.conf.acsurl, &acs_url); + bb_add_string(bb, "acs_url", acs_url); + FREE(acs_url); blobmsg_close_table(bb, tbl); } @@ -279,7 +282,8 @@ static void icwmp_inform_get_rpc_method(struct ubus_context *ctx, struct ubus_re cwmp_save_event_container(event_container); session = list_entry(cwmp_main.head_event_container, struct session, head_event_container); - if (cwmp_main.conf.acs_getrpc && cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) { + bool acs_getrpc = global_bool_param_read(&cwmp_main.conf.acs_getrpc); + if (acs_getrpc && cwmp_add_session_rpc_acs(session, RPC_ACS_GET_RPC_METHODS) == NULL) { pthread_mutex_unlock(&(cwmp_main.mutex_session_queue)); return; } diff --git a/xml.c b/xml.c index 178e64a..084a239 100644 --- a/xml.c +++ b/xml.c @@ -138,13 +138,14 @@ int xml_send_message(struct cwmp *cwmp, struct session *session, struct rpc *rpc char c[512]; int msg_out_len = 0, f, r = 0; mxml_node_t *b; + int compression = global_int_param_read(&cwmp->conf.compression); if (session->tree_out) { unsigned char *zmsg_out; msg_out = mxmlSaveAllocString(session->tree_out, whitespace_cb); CWMP_LOG_XML_MSG(DEBUG, msg_out, XML_MSG_OUT); - if (cwmp->conf.compression != COMP_NONE) { - if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, cwmp->conf.compression)) { + if (compression != COMP_NONE) { + if (zlib_compress(msg_out, &zmsg_out, &msg_out_len, compression)) { return -1; } FREE(msg_out); @@ -236,7 +237,8 @@ int xml_prepare_msg_out(struct session *session) return -1; } - mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[(conf->amd_version) - 1]); + int amd_version = global_int_param_read(&conf->amd_version); + mxmlElementSetAttr(n, "xmlns:cwmp", cwmp_urls[amd_version - 1]); if (!session->tree_out) return -1; @@ -464,10 +466,14 @@ void load_notification_xml_schema(mxml_node_t **tree) return; } - if (NULL == mxmlNewOpaque(un, conf->acs_userid)) { + char *acs_userid = NULL; + global_string_param_read(&conf->acs_userid, &acs_userid); + if (NULL == mxmlNewOpaque(un, acs_userid)) { + FREE(acs_userid); MXML_DELETE(xml); return; } + FREE(acs_userid); mxml_node_t *cn = mxmlNewElement(notification, "CN"); if (cn == NULL) {