From 8fe0cf54ea0c56b8bdc8b9825ab28ab3392da2e2 Mon Sep 17 00:00:00 2001 From: Omar Kallel Date: Mon, 7 Mar 2022 16:07:24 +0100 Subject: [PATCH] Ticket refs #7501: icwmp: Fix static code warnings with cppcheck-2.7 --- .gitlab-ci.yml | 4 +- backupSession.c | 22 ++++---- common.c | 51 +++++++++++++----- config.c | 36 ++----------- cwmp.c | 54 ++++++++++--------- cwmp_cli.c | 14 ++--- cwmp_du_state.c | 19 ++++--- cwmp_uci.c | 16 ++++-- cwmp_zlib.c | 3 ++ datamodel_interface.c | 5 +- diagnostic.c | 10 ++-- digestauth.c | 8 +-- download.c | 8 +-- event.c | 17 +++--- http.c | 13 ++--- inc/common.h | 9 ++-- inc/config.h | 3 +- inc/cwmp_cli.h | 1 - inc/cwmp_du_state.h | 2 + inc/cwmp_uci.h | 2 + inc/datamodel_interface.h | 1 + inc/download.h | 2 + inc/event.h | 2 + inc/http.h | 1 + inc/md5.h | 7 +-- inc/notifications.h | 5 +- inc/rpc_soap.h | 2 - inc/sched_inform.h | 2 + ssl_utils.h => inc/ssl_utils.h | 0 inc/ubus.h | 6 ++- inc/upload.h | 2 + inc/xml.h | 4 +- log.c | 11 ++-- md5.c | 3 ++ netlink.c | 27 ++++------ notifications.c | 30 ++++++----- reboot.c | 5 +- rpc_soap.c | 75 +++++++++++++------------- sched_inform.c | 3 +- session.c | 10 ++-- ssl_utils.c | 3 +- test/cmocka/icwmp_soap_msg_unit_test.c | 2 + ubus.c | 21 ++++---- upload.c | 22 ++++---- xml.c | 6 +-- 45 files changed, 282 insertions(+), 267 deletions(-) rename ssl_utils.h => inc/ssl_utils.h (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 633a1bc..7960585 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,8 +4,8 @@ include: variables: DEBUG: 'TRUE' - COMMON_IMAGE: "iopsys/code-analysis:0.25" - RUN_CPPCHECK: "cppcheck --enable=all --inline-suppr --include=/usr/include/uci.h --suppress=unusedFunction -i ./test/" + COMMON_IMAGE: "iopsys/code-analysis:0.27" + RUN_CPPCHECK: "cppcheck --force --enable=all --error-exitcode=1 -D_GNU_SOURCE --include=/usr/include/libubox/list.h --include=/usr/include/uci.h -I ./inc --suppress=unusedFunction -i ./test/ --inline-suppr" SOURCE_FOLDER: "." CWMP_WORKER_PROCESSES: 1 NBI_WORKER_PROCESSES: 1 diff --git a/backupSession.c b/backupSession.c index f58c674..3cbecd7 100644 --- a/backupSession.c +++ b/backupSession.c @@ -11,17 +11,16 @@ */ #include -#include #include "backupSession.h" #include "log.h" -#include "notifications.h" #include "event.h" -#include "download.h" -#include "cwmp_du_state.h" -#include "rpc_soap.h" -#include "upload.h" #include "sched_inform.h" +#include "download.h" +#include "upload.h" +#include "cwmp_du_state.h" +#include "notifications.h" +#include "xml.h" static mxml_node_t *bkp_tree = NULL; pthread_mutex_t mutex_backup_session = PTHREAD_MUTEX_INITIALIZER; @@ -521,7 +520,7 @@ void bkp_session_delete_apply_schedule_download(struct apply_schedule_download * void bkp_session_insert_change_du_state(struct change_du_state *pchange_du_state) { - struct operations *p = NULL; + struct operations *p; char schedule_time[128]; mxml_node_t *b, *n; @@ -530,7 +529,6 @@ void bkp_session_insert_change_du_state(struct change_du_state *pchange_du_state b = bkp_session_insert(bkp_tree, "change_du_state", NULL); bkp_session_insert(b, "command_key", pchange_du_state->command_key); bkp_session_insert(b, "time", schedule_time); - list_for_each_entry (p, &(pchange_du_state->list_operation), list) { if (p->type == DU_INSTALL) { n = bkp_session_insert(b, "install", NULL); @@ -663,7 +661,7 @@ void bkp_session_delete_upload(struct upload *pupload) void bkp_session_insert_du_state_change_complete(struct du_state_change_complete *pdu_state_change_complete) { char schedule_time[128], resolved[8], fault_code[8]; - struct opresult *p = NULL; + struct opresult *p; mxml_node_t *b; pthread_mutex_lock(&mutex_backup_session); @@ -800,6 +798,10 @@ void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp) while (b) { if (b->type == MXML_ELEMENT) { if (strcmp(b->value.element.name, "command_key") == 0) { + /* + * This condition is not always false. + * while the value of idx can be changed while call of load_specific_backup_attributes. + */ // cppcheck-suppress knownConditionTrueFalse if (idx != -1) { if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) { @@ -830,7 +832,7 @@ void load_schedule_inform(mxml_node_t *tree) char *command_key = NULL; time_t scheduled_time = 0; struct schedule_inform *schedule_inform = NULL; - struct list_head *ilist = NULL; + struct list_head *ilist; struct backup_attributes bkp_attrs = { .command_key = &command_key, .time = &scheduled_time }; load_specific_backup_attributes(tree, &bkp_attrs); diff --git a/common.c b/common.c index da3a015..7a510c3 100755 --- a/common.c +++ b/common.c @@ -8,23 +8,20 @@ * Author Omar Kallel * */ -#include -#include -#include -#include -#include -#include + #include -#include -#include -#include +#include +#include +#include +#include +#include #include "common.h" +#include "cwmp_cli.h" #include "cwmp_uci.h" #include "ubus.h" #include "log.h" -#include "cwmp_cli.h" -#include "cwmp_du_state.h" + #ifndef CWMP_REVISION #define CWMP_REVISION "8.2.10" @@ -586,7 +583,7 @@ void icwmp_restart_services() } } if (g_firewall_restart) { - CWMP_LOG(INFO, "Initiating Firewall restart") + CWMP_LOG(INFO, "Initiating Firewall restart"); cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "in_progress"); cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG); } @@ -691,3 +688,33 @@ int copy_file(char *source_file, char *target_file) fclose(target); return 0; } + +void ubus_network_interface_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg) +{ + const struct blobmsg_policy p[1] = { { "device", BLOBMSG_TYPE_STRING } }; + struct blob_attr *tb[1] = { NULL }; + blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg)); + if (!tb[0]) { + cwmp_main.conf.interface = NULL; + CWMP_LOG(DEBUG, "CWMP IFACE - interface: NOT FOUND"); + return; + } + + FREE(cwmp_main.conf.interface); + cwmp_main.conf.interface = strdup(blobmsg_get_string(tb[0])); + CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", cwmp_main.conf.interface); +} + +int get_connection_interface() +{ + int e = cwmp_ubus_call("network.interface", "status", CWMP_UBUS_ARGS{ { "interface", { .str_val = cwmp_main.conf.default_wan_iface }, UBUS_String } }, 1, ubus_network_interface_callback, NULL); + if (e != 0) { + CWMP_LOG(INFO, "Get network interface from network.interface ubus method failed. Ubus err code: %d", e); + return -1; + } + if (cwmp_main.conf.interface == NULL) { + CWMP_LOG(INFO, "Not able to get the network interface from network.interface ubus method."); + return -1; + } + return CWMP_OK; +} diff --git a/config.c b/config.c index 53c000d..f00e1a4 100755 --- a/config.c +++ b/config.c @@ -9,13 +9,13 @@ * Author Ahmed Zribi * Author Omar Kallel */ +#include +#include #include "config.h" -#include "cwmp_uci.h" #include "log.h" #include "reboot.h" #include "datamodel_interface.h" -#include "ubus.h" pthread_mutex_t mutex_config_load = PTHREAD_MUTEX_INITIALIZER; @@ -592,36 +592,6 @@ int get_global_config(struct config *conf) return CWMP_OK; } -void ubus_network_interface_callback(struct ubus_request *req __attribute__((unused)), int type __attribute__((unused)), struct blob_attr *msg) -{ - const struct blobmsg_policy p[1] = { { "device", BLOBMSG_TYPE_STRING } }; - struct blob_attr *tb[1] = { NULL }; - blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg)); - if (!tb[0]) { - cwmp_main.conf.interface = NULL; - CWMP_LOG(DEBUG, "CWMP IFACE - interface: NOT FOUND"); - return; - } - - FREE(cwmp_main.conf.interface); - cwmp_main.conf.interface = strdup(blobmsg_get_string(tb[0])); - CWMP_LOG(DEBUG, "CWMP IFACE - interface: %s", cwmp_main.conf.interface); -} - -int get_connection_interface() -{ - int e = cwmp_ubus_call("network.interface", "status", CWMP_UBUS_ARGS{ { "interface", { .str_val = cwmp_main.conf.default_wan_iface }, UBUS_String } }, 1, ubus_network_interface_callback, NULL); - if (e != 0) { - CWMP_LOG(INFO, "Get network interface from network.interface ubus method failed. Ubus err code: %d", e); - return -1; - } - if (cwmp_main.conf.interface == NULL) { - CWMP_LOG(INFO, "Not able to get the network interface from network.interface ubus method."); - return -1; - } - return CWMP_OK; -} - int reload_networking_config() { int error; @@ -640,7 +610,7 @@ int reload_networking_config() return error; } - if ((error = get_connection_interface())) + if (get_connection_interface() == -1) return -1; return CWMP_OK; } diff --git a/cwmp.c b/cwmp.c index 011791f..b08c008 100644 --- a/cwmp.c +++ b/cwmp.c @@ -10,31 +10,32 @@ * Author Omar Kallel */ -#include -#include -#include #include -#include +#include #include #include +#include #include "common.h" -#include "session.h" -#include "backupSession.h" -#include "http.h" -#include "diagnostic.h" -#include "config.h" -#include "ubus.h" -#include "log.h" -#include "notifications.h" -#include "cwmp_uci.h" -#include "cwmp_du_state.h" -#include "download.h" -#include "upload.h" -#include "sched_inform.h" -#include "rpc_soap.h" -#include "digestauth.h" #include "ssl_utils.h" +#include "xml.h" +#include "notifications.h" +#include "event.h" +#include "cwmp_uci.h" +#include "log.h" +#include "session.h" +#include "diagnostic.h" +#include "http.h" +#include "rpc_soap.h" +#include "config.h" +#include "backupSession.h" +#include "ubus.h" +#include "digestauth.h" +#include "upload.h" +#include "download.h" +#include "sched_inform.h" +#include "datamodel_interface.h" +#include "cwmp_du_state.h" static pthread_t periodic_event_thread; static pthread_t scheduleInform_thread; @@ -154,7 +155,6 @@ static int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session) while (1) { list_for_each (ilist, &(session->head_rpc_acs)) { - rpc_acs = list_entry(ilist, struct rpc, list); if (!rpc_acs->type || thread_end) goto retry; @@ -171,6 +171,11 @@ static int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session) goto retry; CWMP_LOG(INFO, "Get the %sResponse message from the ACS", rpc_acs_methods[rpc_acs->type].name); + /* + * This condition is not always false. + * while the value of idx can be changed to true in the exit of icwmp. + */ + // cppcheck-suppress knownConditionTrueFalse if (rpc_acs_methods[rpc_acs->type].parse_response || thread_end) if (rpc_acs_methods[rpc_acs->type].parse_response(cwmp, session, rpc_acs)) goto retry; @@ -200,7 +205,6 @@ static int cwmp_schedule_rpc(struct cwmp *cwmp, struct session *session) goto retry; while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) { - rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list); if (!rpc_cpe->type || thread_end) goto retry; @@ -516,19 +520,19 @@ void load_boot_inform_json_file(struct cwmp *cwmp) blob_buf_free(&bbuf); return; } + 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]) - return; - custom_boot_inform_list = tb[0]; - if (custom_boot_inform_list == NULL) { + if (tb[0] == NULL) { CWMP_LOG(WARNING, "The JSON file %s doesn't contain a boot inform parameters list", cwmp->conf.custom_notify_json); blob_buf_free(&bbuf); return; } + custom_boot_inform_list = tb[0]; + blobmsg_for_each_attr(cur, custom_boot_inform_list, rem) { char parameter_path[128]; diff --git a/cwmp_cli.c b/cwmp_cli.c index 1dc6bb2..f566275 100644 --- a/cwmp_cli.c +++ b/cwmp_cli.c @@ -8,13 +8,13 @@ * Author Omar Kallel */ -#include +#include #include "common.h" -#include "datamodel_interface.h" -#include "notifications.h" #include "cwmp_cli.h" +#include "datamodel_interface.h" #include "cwmp_uci.h" +#include "notifications.h" LIST_HEAD(parameters_list); @@ -64,7 +64,7 @@ void display_get_cmd_result(struct cmd_input in __attribute__((unused)), union c fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); return; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, res.param_list, list) { fprintf(stdout, "%s => %s\n", param_value->name, param_value->value); } @@ -89,7 +89,7 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__ int fault_idx = cwmp_set_multiple_parameters_values(&list_set_param_value, "set_key", &flag, &faults_list); cwmp_free_all_dm_parameter_list(&list_set_param_value); if (fault_idx != FAULT_CPE_NO_FAULT) { - struct cwmp_param_fault *param_fault = NULL; + struct cwmp_param_fault *param_fault; char fault[5] = {0}; list_for_each_entry (param_fault, &faults_list, list) { snprintf(fault, sizeof(fault), "%d", param_fault->fault); @@ -204,7 +204,7 @@ void display_get_notif_cmd_result(struct cmd_input in __attribute__((unused)), u fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); return; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, res.param_list, list) { fprintf(stdout, "%s => %s\n", param_value->name, param_value->notification == 2 ? "active" : param_value->notification == 1 ? "passive" : "off"); } @@ -266,7 +266,7 @@ void display_get_names_cmd_result(struct cmd_input in __attribute__((unused)), u fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault)); return; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, res.param_list, list) { fprintf(stdout, "%s => %s\n", param_value->name, param_value->writable ? "writable" : "not-writable"); } diff --git a/cwmp_du_state.c b/cwmp_du_state.c index 5255d67..6f8f5e0 100644 --- a/cwmp_du_state.c +++ b/cwmp_du_state.c @@ -8,16 +8,15 @@ * Author Omar Kallel */ -#include #include +#include -#include "common.h" -#include "ubus.h" #include "cwmp_du_state.h" +#include "ubus.h" #include "log.h" -#include "backupSession.h" -#include "cwmp_time.h" #include "datamodel_interface.h" +#include "cwmp_time.h" +#include "backupSession.h" #include "event.h" LIST_HEAD(list_change_du_state); @@ -117,7 +116,7 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param if (err) return NULL; - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; char instance[8]; list_for_each_entry (param_value, sw_parameters, list) { snprintf(instance, (size_t)(strchr(param_value->name + strlen("Device.SoftwareModules.DeploymentUnit."), '.') - param_value->name - strlen("Device.SoftwareModules.DeploymentUnit.") + 1), "%s", (char *)(param_value->name + strlen("Device.SoftwareModules.DeploymentUnit."))); @@ -138,7 +137,7 @@ static int get_deployment_unit_name_version(char *uuid, char **name, char **vers snprintf(version_param, sizeof(version_param), "Device.SoftwareModules.DeploymentUnit.%s.Version", sw_by_uuid_instance); snprintf(environment_param, sizeof(environment_param), "Device.SoftwareModules.DeploymentUnit.%s.ExecutionEnvRef", sw_by_uuid_instance); - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, &sw_parameters, list) { if (strcmp(param_value->name, name_param) == 0) { *name = strdup(param_value->value); @@ -169,7 +168,7 @@ static char *get_softwaremodules_uuid(char *url) snprintf(uuid_param, sizeof(uuid_param), "Device.SoftwareModules.DeploymentUnit.%s.UUID", sw_by_url_instance); - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, &sw_parameters, list) { if (strcmp(param_value->name, uuid_param) == 0) { uuid = strdup(param_value->value); @@ -191,7 +190,7 @@ static char *get_softwaremodules_url(char *uuid) snprintf(url_param, sizeof(url_param), "Device.SoftwareModules.DeploymentUnit.%s.URL", sw_by_uuid_instance); - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, &sw_parameters, list) { if (strcmp(param_value->name, url_param) == 0) { url = strdup(param_value->value); @@ -235,7 +234,7 @@ static char *get_exec_env_name(char *environment_path) if (err) return strdup(""); - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; snprintf(env_param, sizeof(env_param), "%sName", environment_path); list_for_each_entry (param_value, &environment_list, list) { if (strcmp(param_value->name, env_param) == 0) { diff --git a/cwmp_uci.c b/cwmp_uci.c index 96d3f7f..5b33521 100644 --- a/cwmp_uci.c +++ b/cwmp_uci.c @@ -8,9 +8,12 @@ * Author Omar Kallel */ #include +#include +#include + #include "common.h" -#include "log.h" #include "cwmp_uci.h" +#include "log.h" struct uci_paths uci_save_conf_paths[] = { [UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci", NULL }, @@ -213,7 +216,7 @@ int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, ch struct uci_option *o; *value = NULL; - if (s == NULL || option == NULL) + if (s == NULL || &s->options == NULL || option == NULL) goto not_found; uci_foreach_element(&s->options, e) @@ -374,13 +377,16 @@ void cwmp_delete_uci_element_from_list(struct uci_element *e) void cwmp_free_uci_list(struct uci_list *list) { struct uci_element *e = NULL, *tmp = NULL; - + if (list == NULL) + return; uci_foreach_element_safe(list, e, tmp) cwmp_delete_uci_element_from_list(e); } char *cwmp_uci_list_to_string(struct uci_list *list, char *delimitor) { + if (delimitor == NULL) + return NULL; if (list && !uci_list_empty(list)) { struct uci_element *e = NULL; char list_val[512] = { 0 }; @@ -704,6 +710,10 @@ int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths goto end; } + if (uci_save_conf_paths[uci_type].uci_ctx == NULL) { + ret = -1; + goto end; + } uci_foreach_element(&uci_save_conf_paths[uci_type].uci_ctx->root, e) { struct uci_package *p = uci_to_package(e); diff --git a/cwmp_zlib.c b/cwmp_zlib.c index 68be8ea..7495fa5 100644 --- a/cwmp_zlib.c +++ b/cwmp_zlib.c @@ -9,6 +9,9 @@ */ #include +#include +#include + #include "common.h" #include "log.h" diff --git a/datamodel_interface.c b/datamodel_interface.c index 8dc18fc..9c48222 100755 --- a/datamodel_interface.c +++ b/datamodel_interface.c @@ -8,10 +8,11 @@ * Author Omar Kallel */ +#include + #include "datamodel_interface.h" -#include "log.h" #include "ubus.h" -#include "notifications.h" +#include "log.h" int transaction_id = 0; diff --git a/diagnostic.c b/diagnostic.c index 440af8d..08c355b 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -9,17 +9,13 @@ * Author: Amin Ben Ramdhane * Author: Omar Kallel */ -#include -#include +#include + #include "common.h" #include "diagnostic.h" -#include "config.h" -#include "datamodel_interface.h" #include "ubus.h" -#include "cwmp_uci.h" -#include "event.h" -#include "rpc_soap.h" #include "log.h" +#include "event.h" struct diagnostic_input { char *input_name; diff --git a/digestauth.c b/digestauth.c index 9739d8f..7133ef1 100644 --- a/digestauth.c +++ b/digestauth.c @@ -10,16 +10,16 @@ * */ -#include #include -#include +#include +#include #include +#include "log.h" #include "common.h" #include "digestauth.h" -#include "md5.h" -#include "log.h" #include "ssl_utils.h" +#include "md5.h" #define HASH_MD5_HEX_LEN (2 * MD5_DIGEST_SIZE) diff --git a/download.c b/download.c index 15d95ff..da645f6 100644 --- a/download.c +++ b/download.c @@ -9,16 +9,16 @@ */ #include +#include +#include -#include "common.h" #include "download.h" +#include "ubus.h" #include "cwmp_uci.h" #include "backupSession.h" -#include "ubus.h" -#include "log.h" #include "cwmp_time.h" +#include "log.h" #include "event.h" -#include "cwmp_uci.h" LIST_HEAD(list_download); LIST_HEAD(list_schedule_download); diff --git a/event.c b/event.c index ac674a9..5990f3a 100644 --- a/event.c +++ b/event.c @@ -11,17 +11,12 @@ * */ -#include - #include "backupSession.h" -#include "log.h" #include "event.h" -#include "session.h" -#include "cwmp_du_state.h" -#include "download.h" -#include "rpc_soap.h" -#include "upload.h" #include "sched_inform.h" +#include "download.h" +#include "upload.h" +#include "log.h" const struct EVENT_CONST_STRUCT EVENT_CONST[] = {[EVENT_IDX_0BOOTSTRAP] = { "0 BOOTSTRAP", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL | EVENT_RETRY_AFTER_REBOOT }, [EVENT_IDX_1BOOT] = { "1 BOOT", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL }, @@ -62,17 +57,17 @@ void cwmp_save_event_container(struct event_container *event_container) //to be struct event_container *cwmp_add_event_container(struct cwmp *cwmp, int event_code, char *command_key) { struct event_container *event_container; - struct session *session; struct list_head *ilist; if (cwmp->head_event_container == NULL) { + struct session *session; session = cwmp_add_queue_session(cwmp); if (session == NULL) { return NULL; } cwmp->head_event_container = &(session->head_event_container); } - session = list_entry(cwmp->head_event_container, struct session, head_event_container); + //session = list_entry(cwmp->head_event_container, struct session, head_event_container); list_for_each (ilist, cwmp->head_event_container) { event_container = list_entry(ilist, struct event_container, list); if (event_container->code == event_code && EVENT_CONST[event_code].TYPE == EVENT_TYPE_SINGLE) { @@ -386,7 +381,7 @@ void *thread_event_periodic(void *v) bool event_exist_in_list(struct cwmp *cwmp, int event) { - struct event_container *event_container = NULL; + struct event_container *event_container; list_for_each_entry (event_container, cwmp->head_event_container, list) { if (event_container->code == event) return true; diff --git a/http.c b/http.c index 685252c..bc5e32c 100644 --- a/http.c +++ b/http.c @@ -10,21 +10,18 @@ * Author Omar Kallel * Copyright (C) 2011-2012 Luka Perkov */ - #include -#include #include -#include +#include #include -#include -#include "log.h" -#include "config.h" -#include "event.h" #include "http.h" -#include "digestauth.h" #include "cwmp_uci.h" +#include "log.h" +#include "event.h" #include "ubus.h" +#include "config.h" +#include "digestauth.h" #define REALM "authenticate@cwmp" #define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" diff --git a/inc/common.h b/inc/common.h index be58378..f64434d 100644 --- a/inc/common.h +++ b/inc/common.h @@ -11,15 +11,11 @@ #ifndef __CCOMMON_H #define __CCOMMON_H +#include #include -#include -#include -#include -#include -#include #include +#include #include -#include #ifndef CWMP_VERSION #define CWMP_VERSION "3.0.0" @@ -491,6 +487,7 @@ void load_forced_inform_json_file(struct cwmp *cwmp); void clean_custom_inform_parameters(); char *string_to_hex(const unsigned char *str, size_t size); int copy_file(char *source_file, char *target_file); +int get_connection_interface(); #ifndef FREE #define FREE(x) \ do { \ diff --git a/inc/config.h b/inc/config.h index 61083e0..034e537 100755 --- a/inc/config.h +++ b/inc/config.h @@ -13,8 +13,7 @@ #ifndef _CONFIG_H__ #define _CONFIG_H__ -#include -#include "common.h" +#include "cwmp_uci.h" extern pthread_mutex_t mutex_config_load; diff --git a/inc/cwmp_cli.h b/inc/cwmp_cli.h index 556abd8..d6fde40 100644 --- a/inc/cwmp_cli.h +++ b/inc/cwmp_cli.h @@ -11,7 +11,6 @@ struct cmd_input { char *second_input; }; - char *cmd_get_exec_func(struct cmd_input in, union cmd_result *res); char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused))); char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res); diff --git a/inc/cwmp_du_state.h b/inc/cwmp_du_state.h index 09a0533..66526f0 100644 --- a/inc/cwmp_du_state.h +++ b/inc/cwmp_du_state.h @@ -11,6 +11,8 @@ #ifndef CWMP_DU_STATE_H #define CWMP_DU_STATE_H +#include "common.h" + extern struct list_head list_change_du_state; extern pthread_mutex_t mutex_change_du_state; extern pthread_cond_t threshold_change_du_state; diff --git a/inc/cwmp_uci.h b/inc/cwmp_uci.h index c7b423b..358b2fd 100644 --- a/inc/cwmp_uci.h +++ b/inc/cwmp_uci.h @@ -14,6 +14,8 @@ #include +#include "common.h" + //struct uci_context *cwmp_uci_ctx = ((void *)0); #define UCI_DHCP_DISCOVERY_PATH "cwmp.acs.dhcp_discovery" #define UCI_ACS_URL_PATH "cwmp.acs.url" diff --git a/inc/datamodel_interface.h b/inc/datamodel_interface.h index 417f589..6d76b6e 100644 --- a/inc/datamodel_interface.h +++ b/inc/datamodel_interface.h @@ -1,5 +1,6 @@ #ifndef SRC_DATAMODELIFACE_H_ #define SRC_DATAMODELIFACE_H_ + #include "common.h" #define DM_ROOT_OBJ "Device." diff --git a/inc/download.h b/inc/download.h index c8efee7..241b66e 100644 --- a/inc/download.h +++ b/inc/download.h @@ -1,6 +1,8 @@ #ifndef CWMP_DOWNLOAD_H #define CWMP_DOWNLOAD_H +#include "common.h" + #define DOWNLOAD_PROTOCOL_HTTP "http://" #define DOWNLOAD_PROTOCOL_HTTPS "https://" #define DOWNLOAD_PROTOCOL_FTP "ftp://" diff --git a/inc/event.h b/inc/event.h index e4f6cfa..3e90f36 100644 --- a/inc/event.h +++ b/inc/event.h @@ -11,7 +11,9 @@ #ifndef EVENT_H_ #define EVENT_H_ + #include "common.h" +#include "session.h" typedef struct event_container { struct list_head list; diff --git a/inc/http.h b/inc/http.h index 25eddac..3b79a31 100644 --- a/inc/http.h +++ b/inc/http.h @@ -11,6 +11,7 @@ #define _FREECWMP_HTTP_H__ #include "common.h" + extern char *fc_cookies; #define HTTP_TIMEOUT 30 diff --git a/inc/md5.h b/inc/md5.h index a0132bd..b3670fe 100644 --- a/inc/md5.h +++ b/inc/md5.h @@ -18,15 +18,12 @@ #ifndef MD5_H #define MD5_H -#include -#include -#include -#include - #ifdef WORDS_BIGENDIAN #define HIGHFIRST #endif +#include + #define MD5_DIGEST_SIZE 16 struct MD5Context { diff --git a/inc/notifications.h b/inc/notifications.h index 2629a79..a07cb7e 100644 --- a/inc/notifications.h +++ b/inc/notifications.h @@ -11,15 +11,12 @@ #ifndef NOTIFICATIONS_H_ #define NOTIFICATIONS_H_ -#include + #include #include #include #include "common.h" -#include "event.h" -#include "datamodel_interface.h" -#include "rpc_soap.h" enum NOTIFICATION_STATUS { diff --git a/inc/rpc_soap.h b/inc/rpc_soap.h index c7d2eef..b7a66ae 100644 --- a/inc/rpc_soap.h +++ b/inc/rpc_soap.h @@ -14,10 +14,8 @@ #ifndef __RPC__SOAP__H_ #define __RPC__SOAP__H_ -#include #include "common.h" #include "session.h" -#include "xml.h" #define MAX_NBRE_CUSTOM_INFORM 256 extern char *custom_forced_inform_parameters[MAX_NBRE_CUSTOM_INFORM]; diff --git a/inc/sched_inform.h b/inc/sched_inform.h index 269448e..dad0c0e 100644 --- a/inc/sched_inform.h +++ b/inc/sched_inform.h @@ -11,6 +11,8 @@ #ifndef CWMP_SCHED_INFORM_H #define CWMP_SCHED_INFORM_H +#include "common.h" + extern struct list_head list_schedule_inform; extern pthread_mutex_t mutex_schedule_inform; extern pthread_cond_t threshold_schedule_inform; diff --git a/ssl_utils.h b/inc/ssl_utils.h similarity index 100% rename from ssl_utils.h rename to inc/ssl_utils.h diff --git a/inc/ubus.h b/inc/ubus.h index 68c3101..f9b395f 100644 --- a/inc/ubus.h +++ b/inc/ubus.h @@ -11,11 +11,15 @@ */ #ifndef _FREECWMP_UBUS_H__ #define _FREECWMP_UBUS_H__ +#include +/* #include #include -#include #include "common.h" +*/ +#include "common.h" + #define ARRAY_MAX 8 int cwmp_ubus_init(struct cwmp *cwmp); diff --git a/inc/upload.h b/inc/upload.h index c643af5..e061b78 100644 --- a/inc/upload.h +++ b/inc/upload.h @@ -11,6 +11,8 @@ #ifndef CWMP_UPLOAD_H #define CWMP_UPLOAD_H +#include "common.h" + extern struct list_head list_upload; extern pthread_mutex_t mutex_upload; extern pthread_cond_t threshold_upload; diff --git a/inc/xml.h b/inc/xml.h index 231f464..264bd51 100644 --- a/inc/xml.h +++ b/inc/xml.h @@ -2,10 +2,8 @@ #define __XML__H_ #include -#include -#include - #include "session.h" +#include "common.h" #define CWMP_MXML_TAB_SPACE " " #define MAX_SCHEDULE_INFORM_QUEUE 10 diff --git a/log.c b/log.c index 1947312..9d62b67 100644 --- a/log.c +++ b/log.c @@ -10,13 +10,14 @@ * */ -#include -#include #include -#include -#include -#include "common.h" +#include +#include +#include +#include + #include "log.h" +#include "common.h" static char *SEVERITY_NAMES[8] = { "[EMERG] ", "[ALERT] ", "[CRITIC] ", "[ERROR] ", "[WARNING]", "[NOTICE] ", "[INFO] ", "[DEBUG] " }; static int log_severity = DEFAULT_LOG_SEVERITY; diff --git a/md5.c b/md5.c index d101666..12a6834 100644 --- a/md5.c +++ b/md5.c @@ -15,6 +15,9 @@ * will fill a supplied 16-byte array with the digest. */ + +#include + #include "md5.h" #if __BYTE_ORDER == __BIG_ENDIAN diff --git a/netlink.c b/netlink.c index 2a68685..ca5641d 100644 --- a/netlink.c +++ b/netlink.c @@ -11,29 +11,20 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#include #include -#include -#include -#include -#include - +#include +#include #include -#include -#include "http.h" -#include "log.h" -#include "config.h" -#include "event.h" +#include +#include + +#include "netlink.h" #include "cwmp_uci.h" +#include "log.h" +#include "event.h" static int itfcmp(char *itf1, char *itf2); static void netlink_new_msg(struct uloop_fd *ufd, unsigned events); diff --git a/notifications.c b/notifications.c index 3a91846..1d1d3b0 100644 --- a/notifications.c +++ b/notifications.c @@ -8,17 +8,17 @@ * Author Omar Kallel * */ -#include + #include -#include -#include #include #include "notifications.h" -#include "ubus.h" #include "cwmp_uci.h" -#include "log.h" +#include "datamodel_interface.h" #include "ssl_utils.h" +#include "log.h" +#include "event.h" +#include "xml.h" LIST_HEAD(list_value_change); LIST_HEAD(list_lw_value_change); @@ -206,7 +206,9 @@ int get_parameter_leaf_notification_from_childs_list(char *parameter_name, struc { char *parent = NULL; int ret_notif = -1; - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; + if (childs_list == NULL) + return -1; list_for_each_entry (param_value, childs_list, list) { if (strcmp(param_value->name, parameter_name) == 0) { ret_notif = param_value->notification; @@ -236,7 +238,7 @@ char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *para cwmp_free_all_dm_parameter_list(&childs_notifs); return error; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, ¶ms_list, list) { int notif_leaf; notif_leaf = check_parameter_forced_notification(param_value->name); @@ -263,11 +265,13 @@ char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *para bool parameter_is_other_notif_object_child(char *parent, char *parameter) { struct list_head list_iter, *list_ptr; - // cppcheck-suppress unreadVariable list_iter.next = list_param_obj_notify.next; list_iter.prev = list_param_obj_notify.prev; - struct cwmp_dm_parameter *dm_parameter = NULL; while (list_iter.prev != &list_param_obj_notify) { + struct cwmp_dm_parameter *dm_parameter; + if (list_iter.prev == NULL) + continue; + dm_parameter = list_entry(list_iter.prev, struct cwmp_dm_parameter, list); list_ptr = list_iter.prev; list_iter.prev = list_ptr->prev; @@ -300,7 +304,7 @@ void create_list_param_obj_notify() char* updated_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, struct cwmp_dm_parameter parent_parameter, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg) { - struct cwmp_dm_parameter *param_iter = NULL; + struct cwmp_dm_parameter *param_iter; LIST_HEAD(params_list); char *err = cwmp_get_parameter_values(parent_parameter.name, ¶ms_list); if (err) @@ -319,7 +323,7 @@ char* updated_list_param_leaf_notify_with_sub_parameter_list(struct list_head *l void create_list_param_leaf_notify(struct list_head *list_param_leaf_notify, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg) { - struct cwmp_dm_parameter *param_iter = NULL; + struct cwmp_dm_parameter *param_iter; int i; for (i = 0; i < (int)ARRAY_SIZE(forced_notifications_parameters); i++) @@ -453,7 +457,7 @@ void load_custom_notify_json(struct cwmp *cwmp) */ void get_parameter_value_from_parameters_list(struct list_head *params_list, char *parameter_name, char **value, char **type) { - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, params_list, list) { if (param_value->name == NULL) continue; @@ -682,6 +686,8 @@ static void free_all_list_lw_notify() { while (list_lw_value_change.next != &list_lw_value_change) { struct cwmp_dm_parameter *dm_parameter; + if (list_lw_value_change.next == NULL) + continue; dm_parameter = list_entry(list_lw_value_change.next, struct cwmp_dm_parameter, list); del_list_lw_notify(dm_parameter); } diff --git a/reboot.c b/reboot.c index 1b293c7..837fd82 100644 --- a/reboot.c +++ b/reboot.c @@ -9,11 +9,10 @@ */ #include -#include -#include "session.h" +#include "reboot.h" #include "cwmp_uci.h" #include "log.h" -#include "reboot.h" +#include "session.h" static pthread_t delay_reboot_thread; static pthread_t delay_schedule_thread; diff --git a/rpc_soap.c b/rpc_soap.c index b9c94a8..c561770 100755 --- a/rpc_soap.c +++ b/rpc_soap.c @@ -12,25 +12,22 @@ * Copyright (C) 2011-2012 Luka Perkov * Copyright (C) 2012 Jonas Gorski */ -#include #include "rpc_soap.h" - -#include "http.h" -#include "cwmp_time.h" -#include "cwmp_zlib.h" -#include "notifications.h" -#include "messages.h" -#include "backupSession.h" -#include "log.h" -#include "datamodel_interface.h" -#include "cwmp_uci.h" -#include "diagnostic.h" -#include "ubus.h" -#include "cwmp_du_state.h" #include "download.h" +#include "cwmp_du_state.h" +#include "log.h" +#include "event.h" +#include "cwmp_time.h" +#include "datamodel_interface.h" +#include "messages.h" +#include "event.h" +#include "xml.h" +#include "backupSession.h" +#include "notifications.h" #include "upload.h" #include "sched_inform.h" +#include "diagnostic.h" #define PROCESSING_DELAY (1) // In download/upload the message enqueued before sending the response, which cause the download/upload // to start just before the time. This delay is to compensate the time lapsed during the message enqueue and response @@ -254,6 +251,7 @@ create_value: return 0; } +// cppcheck-suppress constParameter int cwmp_rpc_acs_prepare_message_inform(struct cwmp *cwmp, struct session *session, struct rpc *this) { struct cwmp_dm_parameter *dm_parameter; @@ -782,7 +780,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc fault_code = cwmp_get_fault_code_by_string(err); goto fault; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, ¶meters_list, list) { n = mxmlNewElement(parameter_list, "ParameterValueStruct"); if (!n) @@ -894,7 +892,7 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc goto fault; } } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, ¶meters_list, list) { n = mxmlNewElement(parameter_list, "ParameterInfoStruct"); if (!n) @@ -985,7 +983,7 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct fault_code = cwmp_get_fault_code_by_string(err); goto fault; } - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, ¶meters_list, list) { n = mxmlNewElement(parameter_list, "ParameterAttributeStruct"); if (!n) @@ -1080,6 +1078,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc } LIST_HEAD(list_fault_param); + // cppcheck-suppress autoVariables rpc->list_set_value_fault = &list_fault_param; LIST_HEAD(list_set_param_value); while (b) { @@ -1091,11 +1090,11 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc } } - if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Name") && !b->child) { + if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Name") && !b->child) { parameter_name = icwmp_strdup(""); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Value")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Value")) { parameter_value = icwmp_strdup((char *)mxmlGetOpaque(b)); n = b->parent; while ((b = mxmlWalkNext(b, n, MXML_DESCEND))) { @@ -1105,7 +1104,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc } b = n->last_child; } - if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Value") && !b->child) { + if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Value") && !b->child) { parameter_value = icwmp_strdup(""); } if (parameter_name && parameter_value) { @@ -1608,7 +1607,7 @@ int cancel_transfer(char *key) if (strcmp(pupload->command_key, key) == 0) { pthread_mutex_lock(&mutex_upload); bkp_session_delete_upload(pupload); - bkp_session_save(); //is it needed + bkp_session_save(); list_del(&(pupload->list)); if (pupload->scheduled_time != 0) count_download_queue--; @@ -1862,7 +1861,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc } } } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "CommandKey")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "CommandKey")) { change_du_state->command_key = strdup(b->value.opaque); } b = mxmlWalkNext(b, n, MXML_DESCEND); @@ -1974,7 +1973,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc) if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "CommandKey")) { download->command_key = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileType")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileType")) { if (download->file_type == NULL) { download->file_type = strdup(b->value.opaque); file_type = icwmp_strdup(b->value.opaque); @@ -1986,20 +1985,20 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc) } } } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { download->url = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { download->username = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { download->password = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileSize")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileSize")) { str_file_size = strdup(b->value.opaque ? b->value.opaque: "0"); download->file_size = atoi(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "DelaySeconds")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "DelaySeconds")) { str_download_delay = strdup(b->value.opaque ? b->value.opaque: "0"); download_delay = atol(b->value.opaque); } @@ -2125,7 +2124,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "CommandKey")) { schedule_download->command_key = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileType")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileType")) { if (schedule_download->file_type != NULL) { tmp = file_type; if (cwmp_asprintf(&file_type, "%s %s", tmp, b->value.opaque) == -1) { @@ -2137,21 +2136,21 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r file_type = icwmp_strdup(b->value.opaque); } } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { schedule_download->url = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { schedule_download->username = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { schedule_download->password = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileSize")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "FileSize")) { str_file_size = strdup(b->value.opaque); schedule_download->file_size = atoi(b->value.opaque); } - if (b && b->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "TimeWindowList")) { + if (b->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "TimeWindowList")) { if (!t) return -1; //TO CHECK*/ t = mxmlWalkNext(t, b, MXML_DESCEND); @@ -2335,16 +2334,16 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc) } } } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "URL")) { upload->url = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Username")) { upload->username = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Password")) { upload->password = strdup(b->value.opaque); } - if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "DelaySeconds")) { + if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "DelaySeconds")) { str_upload_delay = strdup(b->value.opaque); upload_delay = atol(b->value.opaque); } diff --git a/sched_inform.c b/sched_inform.c index 1fb212f..a3b9033 100644 --- a/sched_inform.c +++ b/sched_inform.c @@ -8,11 +8,10 @@ * Author Omar Kallel */ -#include "common.h" #include "sched_inform.h" -#include "log.h" #include "backupSession.h" #include "event.h" +#include "log.h" LIST_HEAD(list_schedule_inform); pthread_mutex_t mutex_schedule_inform = PTHREAD_MUTEX_INITIALIZER; diff --git a/session.c b/session.c index 27337df..c12b498 100644 --- a/session.c +++ b/session.c @@ -9,11 +9,13 @@ * */ +#include + #include "session.h" -#include "event.h" -#include "backupSession.h" #include "config.h" +#include "event.h" #include "rpc_soap.h" +#include "backupSession.h" unsigned int end_session_flag = 0; @@ -162,13 +164,13 @@ 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 ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) { + if (cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM) == NULL) { pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } } } else { - if ((rpc_acs = cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM)) == NULL) { + if (cwmp_add_session_rpc_acs_head(session, RPC_ACS_INFORM) == NULL) { pthread_mutex_unlock(&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } diff --git a/ssl_utils.c b/ssl_utils.c index 1d38cd7..c9aa9d5 100644 --- a/ssl_utils.c +++ b/ssl_utils.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "common.h" #include "log.h" @@ -38,7 +39,7 @@ char *generate_random_string(size_t size) int written = RAND_bytes(buf, size); if (written != 1) { - printf("Failed to get random bytes"); + CWMP_LOG(ERROR,"Failed to get random bytes"); goto end; } diff --git a/test/cmocka/icwmp_soap_msg_unit_test.c b/test/cmocka/icwmp_soap_msg_unit_test.c index a951aca..0f9466e 100644 --- a/test/cmocka/icwmp_soap_msg_unit_test.c +++ b/test/cmocka/icwmp_soap_msg_unit_test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "rpc_soap.h" #include "event.h" @@ -22,6 +23,7 @@ #include "log.h" #include "download.h" #include "cwmp_uci.h" +#include "xml.h" #include "icwmp_soap_msg_unit_test.h" diff --git a/ubus.c b/ubus.c index 3b9044c..c549088 100755 --- a/ubus.c +++ b/ubus.c @@ -11,21 +11,22 @@ * Copyright (C) 2012 Luka Perkov */ +#include +#include #include +#include #include "ubus.h" #include "session.h" #include "log.h" -#include "netlink.h" -#include "cwmp_time.h" -#include "event.h" -#include "backupSession.h" #include "sched_inform.h" -#include "cwmp_du_state.h" +#include "http.h" #include "download.h" #include "upload.h" -#include "http.h" -#include "rpc_soap.h" +#include "cwmp_du_state.h" +#include "netlink.h" +#include "event.h" +#include "cwmp_time.h" static struct ubus_context *ctx = NULL; @@ -354,7 +355,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a } blobmsg_close_array(&b, a); } else if (u_args[i].type == UBUS_List_Param_Set) { - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; void *a; a = blobmsg_open_array(&b, u_args[i].key); list_for_each_entry (param_value, u_args[i].val.param_value_list, list) { @@ -368,7 +369,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a } blobmsg_close_array(&b, a); } else if (u_args[i].type == UBUS_List_Param_Get) { - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; void *a; a = blobmsg_open_array(&b, u_args[i].key); list_for_each_entry (param_value, u_args[i].val.param_value_list, list) { @@ -378,7 +379,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a } blobmsg_close_array(&b, a); } else if (u_args[i].type == UBUS_Obj_Obj) { - struct cwmp_dm_parameter *param_value = NULL; + struct cwmp_dm_parameter *param_value; json_object *input_json_obj = json_object_new_object(); list_for_each_entry (param_value, u_args[i].val.param_value_list, list) { if (!param_value->name) diff --git a/upload.c b/upload.c index 2f11090..be32575 100644 --- a/upload.c +++ b/upload.c @@ -8,18 +8,17 @@ * Author Omar Kallel */ -#include #include +#include -#include "common.h" #include "upload.h" -#include "datamodel_interface.h" #include "download.h" -#include "log.h" #include "cwmp_time.h" +#include "datamodel_interface.h" +#include "log.h" #include "backupSession.h" -#include "cwmp_uci.h" #include "event.h" +#include "cwmp_uci.h" #define CURL_TIMEOUT 20 @@ -34,9 +33,11 @@ int lookup_vcf_name(char *instance, char **value) char *err = NULL; LIST_HEAD(vcf_parameters); snprintf(vcf_name_parameter, sizeof(vcf_name_parameter), "Device.DeviceInfo.VendorConfigFile.%s.Name", instance); - if ((err = cwmp_get_parameter_values(vcf_name_parameter, &vcf_parameters)) != NULL) + if (cwmp_get_parameter_values(vcf_name_parameter, &vcf_parameters) != NULL) { + CWMP_LOG(ERROR, "Not able to get the value of the parameter %s : %s", vcf_name_parameter, err); return -1; - struct cwmp_dm_parameter *param_value = NULL; + } + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, &vcf_parameters, list) { *value = strdup(param_value->value); break; @@ -51,9 +52,11 @@ int lookup_vlf_name(char *instance, char **value) char *err = NULL; LIST_HEAD(vlf_parameters); snprintf(vlf_name_parameter, sizeof(vlf_name_parameter), "Device.DeviceInfo.VendorLogFile.%s.Name", instance); - if ((err = cwmp_get_parameter_values(vlf_name_parameter, &vlf_parameters)) != NULL) + if (cwmp_get_parameter_values(vlf_name_parameter, &vlf_parameters) != NULL) { + CWMP_LOG(ERROR, "Not able to get the value of the parameter %s : %s", vlf_name_parameter, err); return -1; - struct cwmp_dm_parameter *param_value = NULL; + } + struct cwmp_dm_parameter *param_value; list_for_each_entry (param_value, &vlf_parameters, list) { *value = strdup(param_value->value); break; @@ -108,6 +111,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans name = NULL; lookup_vcf_name(pupload->f_instance, &name); if (name && strlen(name) > 0) { + // cppcheck-suppress uninitvar snprintf(file_path, sizeof(file_path), "/tmp/%s", name); cwmp_uci_export_package(name, file_path, UCI_STANDARD_CONFIG); FREE(name); diff --git a/xml.c b/xml.c index 924c320..6b326a5 100644 --- a/xml.c +++ b/xml.c @@ -9,13 +9,13 @@ * Author Ahmed Zribi * Author Omar Kallel */ + #include "xml.h" -#include "common.h" #include "log.h" -#include "cwmp_zlib.h" -#include "http.h" #include "notifications.h" #include "messages.h" +#include "http.h" +#include "cwmp_zlib.h" static const char *soap_env_url = "http://schemas.xmlsoap.org/soap/envelope/"; static const char *soap_enc_url = "http://schemas.xmlsoap.org/soap/encoding/";