Ticket refs #6614: icwmp: fix static code anlysis issues generated by cpp check

This commit is contained in:
Omar Kallel 2021-11-22 15:27:44 +01:00
parent 64310c6cf5
commit 4bef706ddf
25 changed files with 224 additions and 217 deletions

View file

@ -124,18 +124,19 @@ void load_specific_backup_attributes(mxml_node_t *tree, struct backup_attributes
mxml_node_t *b = tree, *c;
int idx = -1;
void **ptr;
char **str;
int *intgr;
bool *bol;
time_t *time;
b = mxmlWalkNext(b, tree, MXML_DESCEND);
while (b) {
if (b && b->type == MXML_ELEMENT) {
if (b->type == MXML_ELEMENT) {
idx = get_bkp_attribute_index_type(b->value.element.name);
c = mxmlWalkNext(b, b, MXML_DESCEND);
if (c && c->type == MXML_OPAQUE) {
if (c->value.opaque != NULL) {
char **str;
int *intgr;
bool *bol;
time_t *time;
ptr = (void **)((char *)bkp_attrs + idx * sizeof(char *));
switch (bkp_attrs_names[idx].bkp_type) {
case BKP_STRING:
@ -205,7 +206,7 @@ mxml_node_t *bkp_session_node_found(mxml_node_t *tree, char *name, struct search
return NULL;
b = mxmlFindElement(b, b, name, NULL, NULL, MXML_DESCEND_FIRST);
while (b) {
if (b && b->child) {
if (b->child) {
c = b->child;
i = 0;
while (c && i < size) {
@ -310,7 +311,7 @@ void bkp_session_move_inform_to_inform_send()
pthread_mutex_lock(&mutex_backup_session);
while (b) {
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "queue_event") && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "cwmp")) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "queue_event") && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "cwmp")) {
FREE(b->value.element.name);
b->value.element.name = strdup("send_event");
}
@ -325,7 +326,7 @@ void bkp_session_move_inform_to_inform_queue()
pthread_mutex_lock(&mutex_backup_session);
while (b) {
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "send_event") && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "cwmp")) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "send_event") && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "cwmp")) {
FREE(b->value.element.name);
b->value.element.name = strdup("queue_event");
}
@ -663,7 +664,7 @@ void bkp_session_insert_du_state_change_complete(struct du_state_change_complete
{
char schedule_time[128], resolved[8], fault_code[8];
struct opresult *p;
mxml_node_t *b, *n;
mxml_node_t *b;
pthread_mutex_lock(&mutex_backup_session);
sprintf(schedule_time, "%lld", (long long int)pdu_state_change_complete->timeout);
@ -671,6 +672,7 @@ void bkp_session_insert_du_state_change_complete(struct du_state_change_complete
bkp_session_insert(b, "command_key", pdu_state_change_complete->command_key);
bkp_session_insert(b, "time", schedule_time);
list_for_each_entry (p, &(pdu_state_change_complete->list_opresult), list) {
mxml_node_t *n;
n = bkp_session_insert(b, "opresult", NULL);
sprintf(resolved, "%d", p->resolved);
sprintf(fault_code, "%d", p->fault);
@ -796,7 +798,7 @@ void load_queue_event(mxml_node_t *tree, struct cwmp *cwmp)
b = mxmlWalkNext(b, tree, MXML_DESCEND);
while (b) {
if (b && b->type == MXML_ELEMENT) {
if (b->type == MXML_ELEMENT) {
if (strcmp(b->value.element.name, "command_key") == 0) {
if (idx != -1) {
if (EVENT_CONST[idx].RETRY & EVENT_RETRY_AFTER_REBOOT) {
@ -974,7 +976,7 @@ void load_change_du_state(mxml_node_t *tree)
b = mxmlWalkNext(b, tree, MXML_DESCEND);
while (b) {
if (b && b->type == MXML_ELEMENT) {
if (b->type == MXML_ELEMENT) {
if (strcmp(b->value.element.name, "update") == 0) {
elem = (operations *)calloc(1, sizeof(operations));
elem->type = DU_UPDATE;
@ -1016,7 +1018,7 @@ void load_du_state_change_complete(mxml_node_t *tree, struct cwmp *cwmp)
b = mxmlWalkNext(b, tree, MXML_DESCEND);
while (b) {
if (b && b->type == MXML_ELEMENT) {
if (b->type == MXML_ELEMENT) {
if (strcmp(b->value.element.name, "opresult") == 0) {
elem = (opresult *)calloc(1, sizeof(opresult));
list_add_tail(&(elem->list), &(du_state_change_complete_request->list_opresult));
@ -1077,14 +1079,13 @@ void bkp_session_create_file()
int bkp_session_check_file()
{
FILE *pFile;
if (!file_exists(CWMP_BKP_FILE)) {
bkp_session_create_file();
return -1;
}
if (bkp_tree == NULL) {
FILE *pFile;
pFile = fopen(CWMP_BKP_FILE, "r");
bkp_tree = mxmlLoadFile(NULL, pFile, MXML_OPAQUE_CALLBACK);
fclose(pFile);

View file

@ -26,6 +26,10 @@
#include "cwmp_cli.h"
#include "cwmp_du_state.h"
#ifndef CWMP_REVISION
#define CWMP_REVISION "8.2.10"
#endif
char *commandKey = NULL;
bool thread_end = false;
bool signal_exit = false;
@ -152,8 +156,9 @@ void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *pa
{
struct cwmp_dm_parameter *dm_parameter;
struct list_head *ilist;
int cmp;
list_for_each (ilist, head) {
int cmp;
dm_parameter = list_entry(ilist, struct cwmp_dm_parameter, list);
cmp = strcmp(dm_parameter->name, param_name);
if (cmp == 0) {
@ -173,8 +178,8 @@ void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *pa
dm_parameter->name = strdup(param_name);
if (param_val)
dm_parameter->value = strdup(param_val);
if (param_type)
dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
dm_parameter->notification = notification;
dm_parameter->writable = writable;
}
@ -190,8 +195,8 @@ void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter)
void cwmp_free_all_dm_parameter_list(struct list_head *list)
{
struct cwmp_dm_parameter *dm_parameter;
while (list->next != list) {
struct cwmp_dm_parameter *dm_parameter;
dm_parameter = list_entry(list->next, struct cwmp_dm_parameter, list);
delete_dm_parameter_from_list(dm_parameter);
}
@ -221,8 +226,8 @@ void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault)
void cwmp_free_all_list_param_fault(struct list_head *list_param_fault)
{
struct cwmp_param_fault *param_fault;
while (list_param_fault->next != list_param_fault) {
struct cwmp_param_fault *param_fault;
param_fault = list_entry(list_param_fault->next, struct cwmp_param_fault, list);
cwmp_del_list_fault_param(param_fault);
}
@ -237,6 +242,8 @@ int cwmp_asprintf(char **s, const char *format, ...)
va_copy(argcopy, arg);
size = vsnprintf(NULL, 0, format, argcopy);
if (size < 0) {
va_end(argcopy);
va_end(arg);
return -1;
}
va_end(argcopy);
@ -264,13 +271,6 @@ size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
return written;
}
struct transfer_status {
CURL *easy;
int halted;
int counter; /* count write callback invokes */
int please; /* number of times xferinfo is called while halted */
};
void get_firewall_zone_name_by_wan_iface(char *if_wan, char **zone_name)
{
struct uci_section *s;
@ -336,8 +336,8 @@ int opkg_install_package(char *package_path)
CWMP_LOG(INFO, "Apply downloaded config ...");
snprintf(cmd, sizeof(cmd), "opkg --force-depends --force-maintainer install %s", package_path);
if (cmd == NULL)
int ret = snprintf(cmd, sizeof(cmd), "opkg --force-depends --force-maintainer install %s", package_path);
if (ret < 0 || ret > 512)
return -1;
fp = popen(cmd, "r");
if (fp == NULL) {
@ -505,8 +505,10 @@ int icwmp_asprintf(char **s, const char *format, ...)
size = vsnprintf(NULL, 0, format, argcopy);
va_end(argcopy);
if (size < 0)
if (size < 0) {
va_end(arg);
return -1;
}
str = (char *)calloc(sizeof(char), size + 1);
vsnprintf(str, size + 1, format, arg);
va_end(arg);

View file

@ -143,11 +143,9 @@ int get_global_config(struct config *conf)
}
if ((error = uci_get_value(UCI_CPE_AMD_VERSION, &value)) == CWMP_OK) {
int a = 0;
conf->amd_version = DEFAULT_AMD_VERSION;
if (value != NULL) {
a = atoi(value);
int a = atoi(value);
if (a >= 1) {
conf->amd_version = a;
}
@ -182,7 +180,7 @@ int get_global_config(struct config *conf)
conf->retry_min_wait_interval = DEFAULT_RETRY_MINIMUM_WAIT_INTERVAL;
if (conf->amd_version >= AMD_3 && value != NULL) {
int a = atoi(value);
if (a <= 65535 || a >= 1) {
if (a <= 65535 && a >= 1) {
conf->retry_min_wait_interval = a;
}
}
@ -197,7 +195,7 @@ int get_global_config(struct config *conf)
conf->retry_interval_multiplier = DEFAULT_RETRY_INTERVAL_MULTIPLIER;
if (conf->amd_version >= AMD_3 && value != NULL) {
int a = atoi(value);
if (a <= 65535 || a >= 1000) {
if (a <= 65535 && a >= 1000) {
conf->retry_interval_multiplier = a;
}
}
@ -481,11 +479,9 @@ int get_global_config(struct config *conf)
}
if ((error = uci_get_value(UCI_CPE_SESSION_TIMEOUT, &value)) == CWMP_OK) {
int a = 0;
conf->session_timeout = DEFAULT_SESSION_TIMEOUT;
if (value != NULL) {
a = atoi(value);
int a = atoi(value);
if (a >= 1) {
conf->session_timeout = a;
}
@ -529,10 +525,8 @@ int get_global_config(struct config *conf)
}
if ((error = uci_get_value(LW_NOTIFICATION_PORT, &value)) == CWMP_OK) {
int a = 0;
if (value != NULL) {
a = atoi(value);
int a = atoi(value);
conf->lw_notification_port = a;
FREE(value);
} else {

8
cwmp.c
View file

@ -321,8 +321,6 @@ int run_session_end_func(void)
static void cwmp_schedule_session(struct cwmp *cwmp)
{
struct list_head *ilist;
struct session *session;
int t, error = CWMP_OK;
static struct timespec time_to_wait = { 0, 0 };
bool retry = false;
@ -331,6 +329,9 @@ static void cwmp_schedule_session(struct cwmp *cwmp)
cwmp->cwmp_cr_event = 0;
while (1) {
struct list_head *ilist;
struct session *session;
pthread_mutex_lock(&(cwmp->mutex_session_send));
ilist = (&(cwmp->head_session_queue))->next;
while ((ilist == &(cwmp->head_session_queue)) || retry) {
@ -653,11 +654,10 @@ static void cwmp_free(struct cwmp *cwmp)
static void *thread_cwmp_signal_handler_thread(void *arg)
{
sigset_t *set = (sigset_t *)arg;
int s, signal_num;
for (;;) {
int s, signal_num;
s = sigwait(set, &signal_num);
if (s == -1) {
CWMP_LOG(ERROR, "Error in sigwait");

View file

@ -77,7 +77,7 @@ void display_get_cmd_result(struct cmd_input in __attribute__((unused)), union c
char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)))
{
int flag;
if (in.first_input == NULL || in.second_input == NULL || strlen(in.first_input) <= 0 || strlen(in.second_input) <= 0)
if (in.first_input == NULL || in.second_input == NULL || strlen(in.first_input) == 0 || strlen(in.second_input) == 0)
return "9003";
if (transaction_id == 0) {
if (!cwmp_transaction_start("cwmp"))
@ -301,7 +301,7 @@ const struct cwmp_cli_command_struct icwmp_commands[] = {
char* execute_cwmp_cli_command(char *cmd, char *args[])
{
if (!cmd || strlen(cmd) <= 0) {
if (!cmd || strlen(cmd) == 0) {
printf("You must add a command as input: \n\n");
goto cli_help;
}

View file

@ -249,7 +249,7 @@ static char *get_exec_env_name(char *environment_path)
static int cwmp_launch_du_install(char *url, char *uuid, char *user, char *pass, char *env, char **package_version, char **package_name, char **package_uuid, char **package_env, struct opresult **pchange_du_state_complete)
{
int i, error = FAULT_CPE_NO_FAULT;
int error = FAULT_CPE_NO_FAULT;
char *fault_code;
(*pchange_du_state_complete)->start_time = strdup(mix_get_time());
@ -258,6 +258,7 @@ static int cwmp_launch_du_install(char *url, char *uuid, char *user, char *pass,
if (fault_code != NULL) {
if (fault_code[0] == '9') {
int i;
for (i = 1; i < __FAULT_CPE_MAX; i++) {
if (strcmp(FAULT_CPE_ARRAY[i].CODE, fault_code) == 0) {
error = i;
@ -272,7 +273,7 @@ static int cwmp_launch_du_install(char *url, char *uuid, char *user, char *pass,
static int cwmp_launch_du_update(char *uuid, char *url, char *user, char *pass, char **package_version, char **package_name, char **package_uuid, char **package_env, struct opresult **pchange_du_state_complete)
{
int i, error = FAULT_CPE_NO_FAULT;
int error = FAULT_CPE_NO_FAULT;
char *fault_code;
(*pchange_du_state_complete)->start_time = strdup(mix_get_time());
@ -280,6 +281,7 @@ static int cwmp_launch_du_update(char *uuid, char *url, char *user, char *pass,
cwmp_du_update(url, uuid, user, pass, package_version, package_name, package_uuid, package_env, &fault_code);
if (fault_code != NULL) {
if (fault_code[0] == '9') {
int i;
for (i = 1; i < __FAULT_CPE_MAX; i++) {
if (strcmp(FAULT_CPE_ARRAY[i].CODE, fault_code) == 0) {
error = i;
@ -294,7 +296,7 @@ static int cwmp_launch_du_update(char *uuid, char *url, char *user, char *pass,
static int cwmp_launch_du_uninstall(char *package_name, char *package_env, struct opresult **pchange_du_state_complete)
{
int i, error = FAULT_CPE_NO_FAULT;
int error = FAULT_CPE_NO_FAULT;
char *fault_code;
(*pchange_du_state_complete)->start_time = strdup(mix_get_time());
@ -303,6 +305,7 @@ static int cwmp_launch_du_uninstall(char *package_name, char *package_env, struc
if (fault_code != NULL) {
if (fault_code[0] == '9') {
int i;
for (i = 1; i < __FAULT_CPE_MAX; i++) {
if (strcmp(FAULT_CPE_ARRAY[i].CODE, fault_code) == 0) {
error = i;
@ -484,7 +487,7 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
du_ref = (package_name && package_env) ? get_deployment_unit_reference(package_name, package_env) : NULL;
res->du_ref = strdup(du_ref ? du_ref : "");
res->uuid = strdup(p->uuid);
res->version = strdup(package_version ? package_version : "");
res->version = strdup(package_version);
res->complete_time = strdup(mix_get_time());
res->fault = error;
FREE(du_ref);
@ -526,8 +529,8 @@ void *thread_cwmp_rpc_cpe_change_du_state(void *v)
int cwmp_rpc_acs_destroy_data_du_state_change_complete(struct session *session __attribute__((unused)), struct rpc *rpc)
{
struct du_state_change_complete *p;
if (rpc->extra_data != NULL) {
struct du_state_change_complete *p;
p = (struct du_state_change_complete *)rpc->extra_data;
bkp_session_delete_du_state_change_complete(p);
bkp_session_save();

View file

@ -612,9 +612,8 @@ int cwmp_uci_get_section_type(char *package, char *section, uci_config_paths uci
*value = icwmp_strdup(ptr.s->type);
} else {
*value = "";
return -1;
}
return 0;
return UCI_OK;
}
struct uci_section *cwmp_uci_walk_section(char *package, char *stype, void *arg1, void *arg2, int cmp, int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, uci_config_paths uci_type, int walk)

View file

@ -160,7 +160,7 @@ void ubus_transaction_commit_callback(struct ubus_request *req __attribute__((un
blobmsg_for_each_attr(cur, updated_services, rem)
{
char *service_name = blobmsg_get_string(cur);
if (!service_name || strlen(service_name) <= 0 || strcmp(service_name, "cwmp") == 0)
if (!service_name || strlen(service_name) == 0 || strcmp(service_name, "cwmp") == 0)
continue;
CWMP_LOG(INFO, "Detected service: %s will be restarted in the end session", service_name);
/*Add the service to the list*/
@ -407,11 +407,11 @@ void ubus_setm_values_callback(struct ubus_request *req, int type __attribute__(
int rem;
blobmsg_for_each_attr(cur, faults_params, rem)
{
struct blob_attr *tb[3] = { NULL, NULL, NULL };
blobmsg_parse(pfault, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
if (!tb[0] || !tb[1])
struct blob_attr *tbi[3] = { NULL, NULL, NULL };
blobmsg_parse(pfault, 3, tbi, blobmsg_data(cur), blobmsg_len(cur));
if (!tbi[0] || !tbi[1])
continue;
cwmp_add_list_fault_param(blobmsg_get_string(tb[0]), blobmsg_get_u32(tb[1]), set_result->faults_list);
cwmp_add_list_fault_param(blobmsg_get_string(tbi[0]), blobmsg_get_u32(tbi[1]), set_result->faults_list);
}
}

View file

@ -64,9 +64,9 @@ static time_t mhd_monotonic_time(void)
static void cvthex(const unsigned char *bin, size_t len, char *hex)
{
size_t i;
unsigned int j;
for (i = 0; i < len; ++i) {
unsigned int j;
j = (bin[i] >> 4) & 0x0f;
hex[i * 2] = j <= 9 ? (j + '0') : (j + 'a' - 10);
j = bin[i] & 0x0f;
@ -136,7 +136,6 @@ static int lookup_sub_value(char *dest, size_t size, const char *data, const cha
size_t len;
const char *ptr;
const char *eq;
const char *q1;
const char *q2;
const char *qn;
@ -146,6 +145,7 @@ static int lookup_sub_value(char *dest, size_t size, const char *data, const cha
keylen = strlen(key);
ptr = data;
while ('\0' != *ptr) {
const char *q1;
if (NULL == (eq = strchr(ptr, '=')))
return 0;
q1 = eq + 1;
@ -288,17 +288,16 @@ int http_digest_auth_fail_response(FILE *fp, const char *http_method, const char
{
size_t hlen;
char nonce[HASH_MD5_HEX_LEN + 9];
int signal_stale = 0;
/* Generating the server nonce */
calculate_nonce((uint32_t)mhd_monotonic_time(), http_method, nonce_privacy_key, strlen(nonce_privacy_key), url, realm, nonce);
/* Building the authentication header */
hlen = snprintf(NULL, 0, "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s", realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
hlen = snprintf(NULL, 0, "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"", realm, nonce, opaque);
{
char header[hlen + 1];
snprintf(header, sizeof(header), "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"%s", realm, nonce, opaque, signal_stale ? ",stale=\"true\"" : "");
snprintf(header, sizeof(header), "Digest realm=\"%s\",qop=\"auth\",nonce=\"%s\",opaque=\"%s\"", realm, nonce, opaque);
DD(DEBUG, "%s: header: %s", __FUNCTION__, header);
@ -328,17 +327,7 @@ int http_digest_auth_check(const char *http_method, const char *url, const char
size_t len;
char *end;
char nonce[MAX_NONCE_LENGTH];
char cnonce[MAX_NONCE_LENGTH];
char qop[15]; /* auth,auth-int */
char nc[20];
char response[MAX_AUTH_RESPONSE_LENGTH];
char ha1[HASH_MD5_HEX_LEN + 1];
char respexp[HASH_MD5_HEX_LEN + 1];
char noncehashexp[HASH_MD5_HEX_LEN + 9];
uint32_t nonce_time;
uint32_t t;
size_t left; /* number of characters left in 'header' for 'uri' */
unsigned long int nci;
DD(DEBUG, "%s: header: %s", __FUNCTION__, header);
@ -368,6 +357,16 @@ int http_digest_auth_check(const char *http_method, const char *url, const char
{
char uri[left];
char cnonce[MAX_NONCE_LENGTH];
char qop[15]; /* auth,auth-int */
char nc[20];
char response[MAX_AUTH_RESPONSE_LENGTH];
char ha1[HASH_MD5_HEX_LEN + 1];
char respexp[HASH_MD5_HEX_LEN + 1];
char noncehashexp[HASH_MD5_HEX_LEN + 9];
uint32_t nonce_time;
unsigned long int nci;
uint32_t t;
if (0 == lookup_sub_value(uri, sizeof(uri), header, "uri"))
return MHD_NO;

View file

@ -40,11 +40,11 @@ int download_file(const char *file_path, const char *url, const char *username,
int res_code = 0;
CURL *curl = curl_easy_init();
if (curl) {
char userpass[1024];
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
if (username != NULL && strlen(username) > 0) {
char userpass[1024];
snprintf(userpass, sizeof(userpass), "%s:%s", username, password);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
}
@ -84,7 +84,7 @@ void ubus_check_image_callback(struct ubus_request *req, int type __attribute__(
int cwmp_check_image()
{
int code, e;
int code = 0, e;
CWMP_LOG(INFO, "Check downloaded image ...");
e = cwmp_ubus_call("rpc-sys", "upgrade_test", CWMP_UBUS_ARGS{ {} }, 0, ubus_check_image_callback, &code);
if (e != 0) {
@ -263,7 +263,8 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, struct
if (cwmp_apply_firmware() != 0)
error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED;
sleep(70);
error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED;
if (error == FAULT_CPE_NO_FAULT)
error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED;
} else if (strcmp(pdownload->file_type, WEB_CONTENT_FILE_TYPE) == 0) {
//TODO Not Supported
error = FAULT_CPE_NO_FAULT;
@ -409,7 +410,7 @@ int cwmp_add_apply_schedule_download(struct download *schedule_download, char *s
apply_schedule_download = calloc(1, sizeof(struct apply_schedule_download));
if (apply_schedule_download == NULL) {
error = FAULT_CPE_INTERNAL_ERROR;
goto fault;
goto end;
}
if (error == FAULT_CPE_NO_FAULT) {
pthread_mutex_lock(&mutex_apply_schedule_download);
@ -428,8 +429,7 @@ int cwmp_add_apply_schedule_download(struct download *schedule_download, char *s
pthread_mutex_unlock(&mutex_apply_schedule_download);
pthread_cond_signal(&threshold_apply_schedule_download);
}
return 0;
fault:
end:
cwmp_free_apply_schedule_download_request(apply_schedule_download);
return 0;
}
@ -438,7 +438,6 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
{
struct cwmp *cwmp = (struct cwmp *)v;
struct timespec download_timeout = { 0, 0 };
time_t current_time;
int error = FAULT_CPE_NO_FAULT;
struct transfer_complete *ptransfer_complete;
int min_time = 0;
@ -446,6 +445,7 @@ void *thread_cwmp_rpc_cpe_schedule_download(void *v)
struct download *p, *_p;
for (;;) {
time_t current_time;
if (thread_end)
break;
@ -588,7 +588,6 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
{
struct cwmp *cwmp = (struct cwmp *)v;
struct timespec apply_timeout = { 0, 0 };
time_t current_time;
int error = FAULT_CPE_NO_FAULT;
struct transfer_complete *ptransfer_complete;
int min_time = 0;
@ -596,6 +595,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
struct apply_schedule_download *p, *_p;
for (;;) {
time_t current_time;
if (thread_end)
break;
@ -804,10 +804,9 @@ int cwmp_free_apply_schedule_download_request(struct apply_schedule_download *ap
int cwmp_scheduledDownload_remove_all()
{
struct download *download;
pthread_mutex_lock(&mutex_download);
while (list_download.next != &(list_download)) {
struct download *download;
download = list_entry(list_download.next, struct download, list);
list_del(&(download->list));
bkp_session_delete_download(download);
@ -822,10 +821,9 @@ int cwmp_scheduledDownload_remove_all()
int cwmp_scheduled_Download_remove_all()
{
struct download *schedule_download;
pthread_mutex_lock(&mutex_schedule_download);
while (list_schedule_download.next != &(list_schedule_download)) {
struct download *schedule_download;
schedule_download = list_entry(list_schedule_download.next, struct download, list);
list_del(&(schedule_download->list));
bkp_session_delete_schedule_download(schedule_download);
@ -840,10 +838,9 @@ int cwmp_scheduled_Download_remove_all()
int cwmp_apply_scheduled_Download_remove_all()
{
struct apply_schedule_download *apply_schedule_download;
pthread_mutex_lock(&mutex_apply_schedule_download);
while (list_apply_schedule_download.next != &(list_apply_schedule_download)) {
struct apply_schedule_download *apply_schedule_download;
apply_schedule_download = list_entry(list_apply_schedule_download.next, struct apply_schedule_download, list);
list_del(&(apply_schedule_download->list));
bkp_session_delete_apply_schedule_download(apply_schedule_download);
@ -858,9 +855,8 @@ int cwmp_apply_scheduled_Download_remove_all()
int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session __attribute__((unused)), struct rpc *rpc)
{
struct transfer_complete *p;
if (rpc->extra_data != NULL) {
p = (struct transfer_complete *)rpc->extra_data;
struct transfer_complete *p = (struct transfer_complete *)rpc->extra_data;
bkp_session_delete_transfer_complete(p);
bkp_session_save();
FREE(p->command_key);

32
event.c
View file

@ -44,14 +44,14 @@ const struct EVENT_CONST_STRUCT EVENT_CONST[] = {[EVENT_IDX_0BOOTSTRAP] = { "0 B
void cwmp_save_event_container(struct event_container *event_container) //to be moved to backupsession
{
struct list_head *ilist;
struct cwmp_dm_parameter *dm_parameter;
mxml_node_t *b;
if (EVENT_CONST[event_container->code].RETRY & EVENT_RETRY_AFTER_REBOOT) {
struct list_head *ilist;
mxml_node_t *b;
b = bkp_session_insert_event(event_container->code, event_container->command_key, event_container->id, "queue");
list_for_each (ilist, &(event_container->head_dm_parameter)) {
struct cwmp_dm_parameter *dm_parameter;
dm_parameter = list_entry(ilist, struct cwmp_dm_parameter, list);
bkp_session_insert_parameter(b, dm_parameter->name);
}
@ -118,8 +118,8 @@ void cwmp_root_cause_event_ipdiagnostic(void)
int cwmp_root_cause_event_boot(struct cwmp *cwmp)
{
struct event_container *event_container;
if (cwmp->env.boot == CWMP_START_BOOT) {
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->env.boot = 0;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_1BOOT, "");
@ -135,9 +135,8 @@ int cwmp_root_cause_event_boot(struct cwmp *cwmp)
int event_remove_all_event_container(struct session *session, int rem_from)
{
struct event_container *event_container;
while (session->head_event_container.next != &(session->head_event_container)) {
struct event_container *event_container;
event_container = list_entry(session->head_event_container.next, struct event_container, list);
bkp_session_delete_event(event_container->id, rem_from ? "send" : "queue");
free(event_container->command_key);
@ -151,10 +150,10 @@ int event_remove_all_event_container(struct session *session, int rem_from)
int event_remove_noretry_event_container(struct session *session, struct cwmp *cwmp)
{
struct event_container *event_container;
struct list_head *ilist, *q;
list_for_each_safe (ilist, q, &(session->head_event_container)) {
struct event_container *event_container;
event_container = list_entry(ilist, struct event_container, list);
if (EVENT_CONST[event_container->code].CODE[0] == '6')
@ -172,19 +171,20 @@ int event_remove_noretry_event_container(struct session *session, struct cwmp *c
int cwmp_root_cause_event_bootstrap(struct cwmp *cwmp)
{
struct event_container *event_container;
char *acsurl = NULL;
int cmp = 0;
struct event_container *event_container;
struct session *session;
cwmp_load_saved_session(cwmp, &acsurl, ACS);
if (acsurl == NULL)
save_acs_bkp_config(cwmp);
if (acsurl == NULL || ((acsurl != NULL) && (cmp = strcmp(cwmp->conf.acsurl, acsurl)))) {
if (acsurl == NULL || ((cmp = strcmp(cwmp->conf.acsurl, 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;
session = list_entry(cwmp->head_event_container, struct session, head_event_container);
event_remove_all_event_container(session, RPC_QUEUE);
}
@ -303,10 +303,10 @@ int cwmp_root_cause_changedustate_complete(struct cwmp *cwmp, struct du_state_ch
int cwmp_root_cause_get_rpc_method(struct cwmp *cwmp)
{
struct event_container *event_container;
struct session *session;
if (cwmp->env.periodic == CWMP_START_PERIODIC) {
struct event_container *event_container;
struct session *session;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->env.periodic = 0;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_2PERIODIC, "");
@ -433,7 +433,6 @@ int cwmp_root_cause_event_periodic(struct cwmp *cwmp)
void connection_request_ip_value_change(struct cwmp *cwmp, int version)
{
char *bip = NULL;
struct event_container *event_container;
char *ip_version = (version == IPv6) ? "ipv6" : "ip";
char *ip_value = (version == IPv6) ? cwmp->conf.ipv6 : cwmp->conf.ip;
@ -448,6 +447,7 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version)
return;
}
if (strcmp(bip, ip_value) != 0) {
struct event_container *event_container;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
@ -467,7 +467,6 @@ void connection_request_ip_value_change(struct cwmp *cwmp, int version)
void connection_request_port_value_change(struct cwmp *cwmp, int port)
{
char *bport = NULL;
struct event_container *event_container;
char bufport[16];
snprintf(bufport, sizeof(bufport), "%d", port);
@ -480,6 +479,7 @@ void connection_request_port_value_change(struct cwmp *cwmp, int port)
return;
}
if (strcmp(bport, bufport) != 0) {
struct event_container *event_container;
event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, "");
if (event_container == NULL) {
FREE(bport);

14
http.c
View file

@ -49,7 +49,7 @@ int http_client_init(struct cwmp *cwmp)
{
char *dhcp_dis = NULL;
char *acs_var_stat = NULL;
unsigned char buf[sizeof(struct in6_addr)];
uci_get_value(UCI_DHCP_DISCOVERY_PATH, &dhcp_dis);
if (dhcp_dis && cwmp->retry_count_session > 0 && strcmp(dhcp_dis, "enable") == 0) {
@ -86,6 +86,8 @@ int http_client_init(struct cwmp *cwmp)
return -1;
if (cwmp->conf.ipv6_enable) {
unsigned char buf[sizeof(struct in6_addr)];
char *ip = NULL;
curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, HTTP_TIMEOUT);
@ -150,14 +152,12 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
if (!http_c.header_list)
return -1;
#ifdef ACS_FUSION
char *expect_header = "Expect:";
http_c.header_list = curl_slist_append(http_c.header_list, expect_header);
http_c.header_list = curl_slist_append(http_c.header_list, "Expect:");
if (!http_c.header_list)
return -1;
#endif /* ACS_FUSION */
if (cwmp->conf.http_disable_100continue) {
char *expect_header = "Expect:";
http_c.header_list = curl_slist_append(http_c.header_list, expect_header);
http_c.header_list = curl_slist_append(http_c.header_list, "Expect:");
if (!http_c.header_list)
return -1;
}
@ -407,8 +407,6 @@ void http_server_listen(void)
int client_sock, c;
static int cr_request = 0;
static time_t restrict_start_time = 0;
time_t current_time;
bool service_available;
struct sockaddr_in6 client;
//Listen
@ -417,6 +415,8 @@ void http_server_listen(void)
//Accept and incoming connection
c = sizeof(struct sockaddr_in);
while ((client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) {
bool service_available;
time_t current_time;
if (thread_end)
return;

View file

@ -34,11 +34,9 @@ static void kernel_api_cwmp_value_change_listener(struct sk_buff *skb)
{
struct nlmsghdr *nlh;
int pid;
struct sk_buff *skb_out;
int msg_size;
char *msg;
char *recv;
int i, res;
int i;
nlh = (struct nlmsghdr *)skb->data;
recv = (char *)nlmsg_data(nlh);
@ -58,6 +56,9 @@ static void kernel_api_cwmp_value_change_listener(struct sk_buff *skb)
mutex_lock(&(kernel_cwmp_input.mutex));
for (i = 0; i <= kernel_cwmp_input.argc; i++) {
struct sk_buff *skb_out;
int msg_size, res;
if (i < kernel_cwmp_input.argc) {
msg = kernel_cwmp_input.argv[i];
} else {

2
md5.c
View file

@ -29,8 +29,8 @@
*/
static void byteReverse(unsigned char *buf, unsigned longs)
{
uint32_t t;
do {
uint32_t t;
t = (uint32_t)((unsigned)buf[3] << 8 | buf[2]) << 16 | ((unsigned)buf[1] << 8 | buf[0]);
*(uint32_t *)buf = t;
buf += 4;

View file

@ -56,24 +56,31 @@ static int itfcmp(char *itf1, char *itf2)
index = (int)(str - itf1);
if (!index)
goto end;
buf1 = malloc(index);
strncpy(buf1, itf1, index);
if (!buf1)
goto end;
strncpy(buf1, itf1, index);
buf1[index] = '\0';
if (itf2[0] == '\0')
goto end;
str = strchr(itf2, '.');
if (str == NULL)
goto end;
index = (int)(str - itf2);
if (!index)
goto end;
buf2 = malloc(index);
if (!buf2)
goto end;
buf2[index] = '\0';
strncpy(buf2, itf1, index);
buf2[index] = '\0';
if (strcmp(buf1, buf2) == 0)
status = 0;
end:
@ -94,7 +101,6 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
memset(&if_name, 0, sizeof(if_name));
memset(&if_addr, 0, sizeof(if_addr));
char pradd_v6[128];
if (ifa->ifa_family == AF_INET) { //CASE IPv4
while (rtl && RTA_OK(rth, rtl)) {
if (rth->rta_type != IFA_LOCAL) {
@ -127,6 +133,7 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
}
} else { //CASE IPv6
while (rtl && RTA_OK(rth, rtl)) {
char pradd_v6[128];
if (rth->rta_type != IFA_ADDRESS || ifa->ifa_scope == RT_SCOPE_LINK) {
rth = RTA_NEXT(rth, rtl);
continue;

View file

@ -82,10 +82,16 @@ int add_uci_option_notification(char *parameter_name, int notification)
int ret = 0;
ret = cwmp_uci_get_section_type("cwmp", "@notifications[0]", UCI_VARSTATE_CONFIG, &notification_type);
if (ret != UCI_OK)
return -1;
if (notification_type == NULL || notification_type[0] == '\0') {
cwmp_uci_add_section("cwmp", "notifications", UCI_VARSTATE_CONFIG, &s);
}
ret = cwmp_uci_add_list_value("cwmp", "@notifications[0]", notifications[notification], parameter_name, UCI_VARSTATE_CONFIG);
if (ret != UCI_OK)
return -1;
ret = cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
return ret;
}
@ -95,8 +101,9 @@ bool check_parent_with_different_notification(char *parameter_name, int notifica
struct uci_list *list_notif;
struct uci_element *e = NULL;
int i;
int option_type;
for (i = 0; i < 7; i++) {
int option_type;
if (i == notification)
continue;
option_type = cwmp_uci_get_cwmp_varstate_option_value_list("cwmp", "@notifications[0]", notifications[i], &list_notif);
@ -116,11 +123,12 @@ bool update_notifications_list(char *parameter_name, int notification)
{
struct uci_list *list_notif;
struct uci_element *e = NULL, *tmp = NULL;
int i, option_type;
int i;
char *ename = NULL;
bool update_ret = true;
for (i = 0; i < 7; i++) {
int option_type;
option_type = cwmp_uci_get_cwmp_varstate_option_value_list("cwmp", "@notifications[0]", notifications[i], &list_notif);
if (list_notif) {
uci_foreach_element_safe(list_notif, tmp, e) {
@ -169,10 +177,12 @@ int get_parameter_family_notifications(char *parameter_name, struct list_head *c
struct uci_list *list_notif;
struct uci_element *e = NULL;
int i, notif_ret = 0, option_type;
int i, notif_ret = 0;
char *parent_param = NULL;
for (i = 0; i < 7; i++) {
int option_type;
option_type = cwmp_uci_get_cwmp_varstate_option_value_list("cwmp", "@notifications[0]", notifications[i], &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
@ -221,7 +231,6 @@ char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *para
return error;
LIST_HEAD(childs_notifs);
int notification = get_parameter_family_notifications(parameter_name, &childs_notifs);
int notif_leaf;
LIST_HEAD(params_list);
error = cwmp_get_parameter_values(parameter_name, &params_list);
if (error != NULL) {
@ -230,6 +239,7 @@ char *cwmp_get_parameter_attributes(char *parameter_name, struct list_head *para
}
struct cwmp_dm_parameter *param_value = NULL;
list_for_each_entry (param_value, &params_list, list) {
int notif_leaf;
notif_leaf = check_parameter_forced_notification(param_value->name);
if (notif_leaf > 0) {
add_dm_parameter_to_list(parameters_list, param_value->name, "", "", notif_leaf, false);
@ -274,8 +284,9 @@ void create_list_param_obj_notify()
{
struct uci_list *list_notif;
struct uci_element *e = NULL;
int i, option_type;
int i;
for (i = 0; i < 7; i++) {
int option_type;
option_type = cwmp_uci_get_cwmp_varstate_option_value_list("cwmp", "@notifications[0]", notifications[i], &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
@ -687,8 +698,8 @@ void del_list_lw_notify(struct cwmp_dm_parameter *dm_parameter)
static void free_all_list_lw_notify()
{
struct cwmp_dm_parameter *dm_parameter;
while (list_lw_value_change.next != &list_lw_value_change) {
struct cwmp_dm_parameter *dm_parameter;
dm_parameter = list_entry(list_lw_value_change.next, struct cwmp_dm_parameter, list);
del_list_lw_notify(dm_parameter);
}
@ -706,7 +717,7 @@ void cwmp_lwnotification()
udplw_server_param(&servaddr);
xml_prepare_lwnotification_message(&msg_out);
message_compute_signature(msg_out, signature);
snprintf(msg, sizeof(msg), "%s \n %s: %s \n %s: %s \n %s: %zd\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);
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);
send_udp_message(servaddr, msg);
free_all_list_lw_notify();

View file

@ -160,7 +160,7 @@ static int xml_prepare_events_inform(struct session *session, mxml_node_t *tree)
{
mxml_node_t *node, *b1, *b2;
char c[128];
int n = 0;
unsigned int n = 0;
struct list_head *ilist;
struct event_container *event_container;
struct cwmp *cwmp = &cwmp_main;
@ -764,10 +764,10 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
#endif
LIST_HEAD(parameters_list);
while (b) {
if (b && b->type == MXML_OPAQUE && b->parent->type == MXML_ELEMENT && b->value.opaque && !strcmp(b->parent->value.element.name, "string")) {
if (b->type == MXML_OPAQUE && b->parent->type == MXML_ELEMENT && b->value.opaque && !strcmp(b->parent->value.element.name, "string")) {
parameter_name = b->value.opaque;
}
if (b && b->type == MXML_ELEMENT && /* added in order to support GetParameterValues with empty string*/
if (b->type == MXML_ELEMENT && /* added in order to support GetParameterValues with empty string*/
!strcmp(b->value.element.name, "string") && !b->child) {
parameter_name = "";
}
@ -865,13 +865,13 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
#endif
while (b) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterPath")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterPath")) {
parameter_name = b->value.opaque;
}
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "ParameterPath") && !b->child) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "ParameterPath") && !b->child) {
parameter_name = "";
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "NextLevel")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "NextLevel")) {
NextLevel = b->value.opaque;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
@ -968,10 +968,10 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
#endif
while (b) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "string")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "string")) {
parameter_name = b->value.opaque;
}
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "string") && !b->child) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "string") && !b->child) {
parameter_name = "";
}
if (parameter_name) {
@ -1052,7 +1052,7 @@ static int is_duplicated_parameter(mxml_node_t *param_node, struct session *sess
{
mxml_node_t *b = param_node;
while ((b = mxmlWalkNext(b, session->body_in, MXML_DESCEND))) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
if (strcmp(b->value.opaque, param_node->value.opaque) == 0)
return -1;
}
@ -1079,7 +1079,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
rpc->list_set_value_fault = &list_fault_param;
LIST_HEAD(list_set_param_value);
while (b) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
parameter_name = icwmp_strdup(b->value.opaque);
if (is_duplicated_parameter(b, session)) {
fault_code = FAULT_CPE_INVALID_ARGUMENTS;
@ -1092,13 +1092,10 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Value")) {
int whitespace = 0;
parameter_value = icwmp_strdup((char *)mxmlGetOpaque(b));
n = b->parent;
while ((b = mxmlWalkNext(b, n, MXML_DESCEND))) {
v = (char *)mxmlGetOpaque(b);
if (!whitespace)
break;
icwmp_asprintf(&c, "%s %s", parameter_value, v);
parameter_value = icwmp_strdup(c);
}
@ -1200,27 +1197,27 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
b = n;
while (b != NULL) {
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "SetParameterAttributesStruct")) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "SetParameterAttributesStruct")) {
parameter_name = NULL;
parameter_notification = NULL;
notification_change = NULL;
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Name")) {
parameter_name = b->value.opaque;
}
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 = "";
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "NotificationChange")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "NotificationChange")) {
notification_change = b->value.opaque;
}
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "NotificationChange") && !b->child) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "NotificationChange") && !b->child) {
notification_change = "";
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Notification")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "Notification")) {
parameter_notification = b->value.opaque;
}
if (b && b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Notification") && !b->child) {
if (b->type == MXML_ELEMENT && !strcmp(b->value.element.name, "Notification") && !b->child) {
parameter_notification = "";
}
if (parameter_name && parameter_notification && notification_change) {
@ -1275,10 +1272,10 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc)
b = session->body_in;
while (b) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterKey")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterKey")) {
parameter_key = b->value.opaque;
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ObjectName")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ObjectName")) {
object_name = b->value.opaque;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
@ -1363,10 +1360,10 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc)
b = session->body_in;
while (b) {
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ObjectName")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ObjectName")) {
object_name = b->value.opaque;
}
if (b && b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterKey")) {
if (b->type == MXML_OPAQUE && b->value.opaque && b->parent->type == MXML_ELEMENT && !strcmp(b->parent->value.element.name, "ParameterKey")) {
parameter_key = b->value.opaque;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
@ -1553,7 +1550,7 @@ int cwmp_handle_rpc_cpe_cancel_transfer(struct session *session, struct rpc *rpc
b = session->body_in;
while (b) {
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")) {
command_key = b->value.opaque;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
@ -1584,13 +1581,11 @@ error:
int cancel_transfer(char *key)
{
struct upload *pupload;
struct download *pdownload;
struct list_head *ilist, *q;
if (list_download.next != &(list_download)) {
list_for_each_safe (ilist, q, &(list_download)) {
pdownload = list_entry(ilist, struct download, list);
struct download *pdownload = list_entry(ilist, struct download, list);
if (strcmp(pdownload->command_key, key) == 0) {
pthread_mutex_lock(&mutex_download);
bkp_session_delete_download(pdownload);
@ -1605,7 +1600,7 @@ int cancel_transfer(char *key)
}
if (list_upload.next != &(list_upload)) {
list_for_each_safe (ilist, q, &(list_upload)) {
pupload = list_entry(ilist, struct upload, list);
struct upload *pupload = list_entry(ilist, struct upload, list);
if (strcmp(pupload->command_key, key) == 0) {
pthread_mutex_lock(&mutex_upload);
bkp_session_delete_upload(pupload);
@ -1635,7 +1630,7 @@ int cwmp_handle_rpc_cpe_reboot(struct session *session, struct rpc *rpc)
b = session->body_in;
while (b) {
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")) {
command_key = b->value.opaque;
commandKey = icwmp_strdup(b->value.opaque);
}
@ -1687,16 +1682,16 @@ int cwmp_handle_rpc_cpe_schedule_inform(struct session *session, struct rpc *rpc
time_t scheduled_time;
struct list_head *ilist;
int fault = FAULT_CPE_NO_FAULT;
unsigned int delay_seconds = 0;
int delay_seconds = 0;
pthread_mutex_lock(&mutex_schedule_inform);
while (b) {
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")) {
command_key = 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")) {
delay_seconds = atoi(b->value.opaque);
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
@ -1794,7 +1789,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc
while (b != NULL) {
t = b;
if (b && b->type == MXML_ELEMENT && strcmp(b->value.element.name, "Operations") == 0) {
if (b->type == MXML_ELEMENT && strcmp(b->value.element.name, "Operations") == 0) {
char *operation = (char *)mxmlElementGetAttrValue(b, "xsi:type");
if (!strcmp(operation, "cwmp:InstallOpStruct")) {
elem = (operations *)calloc(1, sizeof(operations));
@ -1802,19 +1797,19 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc
list_add_tail(&(elem->list), &(change_du_state->list_operation));
t = mxmlWalkNext(t, b, MXML_DESCEND);
while (t) {
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "URL")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "URL")) {
elem->url = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
elem->uuid = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Username")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Username")) {
elem->username = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->parent->type == MXML_ELEMENT && t->value.opaque && !strcmp(t->parent->value.element.name, "Password")) {
if (t->type == MXML_OPAQUE && t->parent->type == MXML_ELEMENT && t->value.opaque && !strcmp(t->parent->value.element.name, "Password")) {
elem->password = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "ExecutionEnvRef")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "ExecutionEnvRef")) {
elem->executionenvref = strdup(t->value.opaque);
}
t = mxmlWalkNext(t, b, MXML_DESCEND);
@ -1825,20 +1820,20 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc
list_add_tail(&(elem->list), &(change_du_state->list_operation));
t = mxmlWalkNext(t, b, MXML_DESCEND);
while (t) {
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Username")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Username")) {
elem->username = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Version")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Version")) {
elem->version = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "URL")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "URL")) {
elem->url = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Password")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Password")) {
elem->password = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
elem->uuid = strdup(t->value.opaque);
}
@ -1850,13 +1845,13 @@ int cwmp_handle_rpc_cpe_change_du_state(struct session *session, struct rpc *rpc
list_add_tail(&(elem->list), &(change_du_state->list_operation));
t = mxmlWalkNext(t, b, MXML_DESCEND);
while (t) {
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Version")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "Version")) {
elem->version = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "ExecutionEnvRef")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "ExecutionEnvRef")) {
elem->executionenvref = strdup(t->value.opaque);
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "UUID")) {
elem->uuid = strdup(t->value.opaque);
}
t = mxmlWalkNext(t, b, MXML_DESCEND);
@ -1972,7 +1967,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc)
}
while (b != NULL) {
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")) {
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")) {
@ -2039,7 +2034,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc)
error = FAULT_CPE_INVALID_ARGUMENTS;
} else if (count_download_queue >= MAX_DOWNLOAD_QUEUE) {
error = FAULT_CPE_RESOURCES_EXCEEDED;
} else if ((download->url == NULL || ((download->url != NULL) && (strcmp(download->url, "") == 0)))) {
} else if (download->url == NULL || (strcmp(download->url, "") == 0)) {
error = FAULT_CPE_REQUEST_DENIED;
} else if (strstr(download->url, "@") != NULL) {
error = FAULT_CPE_INVALID_ARGUMENTS;
@ -2123,7 +2118,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
while (b != NULL) {
t = b;
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")) {
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")) {
@ -2157,15 +2152,15 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
return -1; //TO CHECK*/
t = mxmlWalkNext(t, b, MXML_DESCEND);
while (t) {
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowStart")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowStart")) {
schedule_download_delay[j] = atol(t->value.opaque);
j++;
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowEnd")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowEnd")) {
schedule_download_delay[j] = atol(t->value.opaque);
j++;
}
if (t && t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowMode")) {
if (t->type == MXML_OPAQUE && t->value.opaque && t->parent->type == MXML_ELEMENT && !strcmp(t->parent->value.element.name, "WindowMode")) {
if (schedule_download->timewindowstruct[i].windowmode == NULL) {
schedule_download->timewindowstruct[i].windowmode = strdup(t->value.opaque);
if (i == 0)
@ -2227,7 +2222,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
error = FAULT_CPE_REQUEST_DENIED;
} else if (count_download_queue >= MAX_DOWNLOAD_QUEUE) {
error = FAULT_CPE_RESOURCES_EXCEEDED;
} else if ((schedule_download->url == NULL || ((schedule_download->url != NULL) && (strcmp(schedule_download->url, "") == 0)))) {
} else if (schedule_download->url == NULL || (strcmp(schedule_download->url, "") == 0)) {
error = FAULT_CPE_REQUEST_DENIED;
} else if (strstr(schedule_download->url, "@") != NULL) {
error = FAULT_CPE_INVALID_ARGUMENTS;
@ -2320,10 +2315,10 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
}
upload->f_instance = strdup("");
while (b != NULL) {
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")) {
upload->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 (upload->file_type == NULL) {
upload->file_type = strdup(b->value.opaque);
file_type = icwmp_strdup(b->value.opaque);
@ -2381,7 +2376,7 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
error = FAULT_CPE_REQUEST_DENIED;
} else if (count_download_queue >= MAX_DOWNLOAD_QUEUE) {
error = FAULT_CPE_RESOURCES_EXCEEDED;
} else if ((upload->url == NULL || ((upload->url != NULL) && (strcmp(upload->url, "") == 0)))) {
} else if (upload->url == NULL || (strcmp(upload->url, "") == 0)) {
error = FAULT_CPE_REQUEST_DENIED;
} else if (strstr(upload->url, "@") != NULL) {
error = FAULT_CPE_INVALID_ARGUMENTS;
@ -2441,8 +2436,6 @@ fault:
int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
{
mxml_node_t *b, *t, *u, *body;
struct cwmp_param_fault *param_fault;
int idx;
body = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
@ -2492,9 +2485,12 @@ int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
if (rpc->type == RPC_CPE_SET_PARAMETER_VALUES) {
while (rpc->list_set_value_fault->next != rpc->list_set_value_fault) {
struct cwmp_param_fault *param_fault;
param_fault = list_entry(rpc->list_set_value_fault->next, struct cwmp_param_fault, list);
if (param_fault->fault) {
int idx;
idx = cwmp_get_fault_code(param_fault->fault);
t = mxmlNewElement(b, "SetParameterValuesFault");

View file

@ -94,10 +94,9 @@ void *thread_cwmp_rpc_cpe_scheduleInform(void *v)
int cwmp_scheduleInform_remove_all()
{
struct schedule_inform *schedule_inform;
pthread_mutex_lock(&mutex_schedule_inform);
while (list_schedule_inform.next != &(list_schedule_inform)) {
struct schedule_inform *schedule_inform;
schedule_inform = list_entry(list_schedule_inform.next, struct schedule_inform, list);
list_del(&(schedule_inform->list));

View file

@ -147,10 +147,8 @@ int cwmp_session_destructor(struct session *session)
int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *session)
{
struct list_head *ilist, *jlist;
struct rpc *rpc_acs, *queue_rpc_acs, *rpc_cpe;
struct event_container *event_container_old, *event_container_new;
struct rpc *rpc_acs, *queue_rpc_acs;
struct session *session_queue;
bool dup;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
cwmp->retry_count_session++;
@ -175,6 +173,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio
}
}
while (session->head_rpc_cpe.next != &(session->head_rpc_cpe)) {
struct rpc *rpc_cpe;
rpc_cpe = list_entry(session->head_rpc_cpe.next, struct rpc, list);
cwmp_session_rpc_destructor(rpc_cpe);
}
@ -184,6 +183,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio
return CWMP_OK;
}
list_for_each (ilist, &(session->head_event_container)) {
struct event_container *event_container_new, *event_container_old;
event_container_old = list_entry(ilist, struct event_container, list);
event_container_new = cwmp_add_event_container(cwmp, event_container_old->code, event_container_old->command_key);
if (event_container_new == NULL) {
@ -196,6 +196,7 @@ int cwmp_move_session_to_session_queue(struct cwmp *cwmp, struct session *sessio
session_queue = list_entry(cwmp->head_event_container, struct session, head_event_container);
list_for_each (ilist, &(session->head_rpc_acs)) {
rpc_acs = list_entry(ilist, struct rpc, list);
bool dup;
dup = false;
list_for_each (jlist, &(session_queue->head_rpc_acs)) {
queue_rpc_acs = list_entry(jlist, struct rpc, list);

View file

@ -44,7 +44,6 @@ void free_download(struct download *p)
icwmp_free(p->password);
icwmp_free(p->url);
icwmp_free(p);
p = NULL;
}
static int download_unit_tests_clean(void **state)

View file

@ -92,10 +92,11 @@ int get_parameter_notification_from_list_head(struct list_head *params_list, cha
int get_parameter_notification_from_notifications_uci_list(char *parameter_name)
{
int i, option_type, notification = 0;
int i, notification = 0;
struct uci_list *list_notif;
struct uci_element *e;
for (i = 0; i < 7; i++) {
int option_type;
option_type = cwmp_uci_get_cwmp_varstate_option_value_list("cwmp", "@notifications[0]", notifications_test[i], &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {

View file

@ -67,9 +67,8 @@ void clean_name_space()
void unit_test_remove_all_events_by_session(struct session *session)
{
struct event_container *event_container;
while (session->head_event_container.next != &(session->head_event_container)) {
struct event_container *event_container;
event_container = list_entry(session->head_event_container.next, struct event_container, list);
free(event_container->command_key);
cwmp_free_all_dm_parameter_list(&(event_container->head_dm_parameter));
@ -122,7 +121,6 @@ static int soap_unit_tests_clean(void **state)
*/
static void get_config_test(void **state)
{
struct cwmp *cwmp_test = &cwmp_main_test;
int error = get_global_config(&(cwmp_test->conf));
assert_int_equal(error, CWMP_OK);
log_set_severity_idx("INFO");
@ -130,7 +128,6 @@ static void get_config_test(void **state)
static void get_deviceid_test(void **state)
{
struct cwmp *cwmp_test = &cwmp_main_test;
int error = cwmp_get_deviceid(cwmp_test);
assert_int_equal(error, CWMP_OK);
}
@ -1123,11 +1120,10 @@ static void prepare_download_soap_request(struct session *session, char *url, ch
void free_download()
{
struct download *download;
struct list_head *ilist, *q;
if (list_download.next != &(list_download)) {
struct list_head *ilist, *q;
list_for_each_safe (ilist, q, &(list_download)) {
struct download *download;
download = list_entry(ilist, struct download, list);
bkp_session_delete_download(download);
cwmp_free_download_request(download);

27
ubus.c
View file

@ -28,7 +28,6 @@
#include "rpc_soap.h"
static struct ubus_context *ctx = NULL;
static struct blob_buf b;
static const char *arr_session_status[] = {
[SESSION_WAITING] = "waiting",
@ -50,6 +49,7 @@ static const struct blobmsg_policy command_policy[] = {
static int cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj __attribute__((unused)), struct ubus_request_data *req, const char *method __attribute__((unused)), struct blob_attr *msg)
{
struct blob_attr *tb[__COMMAND_MAX];
static struct blob_buf b;
blobmsg_parse(command_policy, ARRAYSIZEOF(command_policy), tb, blob_data(msg), blob_len(msg));
@ -154,6 +154,7 @@ static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj
{
void *c;
time_t ntime = 0;
static struct blob_buf b;
blob_buf_init(&b, 0);
@ -205,8 +206,7 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
struct blob_attr *tb[__INFORM_MAX];
bool grm = false;
char *event = "";
struct event_container *event_container;
struct session *session;
static struct blob_buf b;
blob_buf_init(&b, 0);
@ -219,6 +219,9 @@ static int cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj
event = blobmsg_data(tb[INFORM_EVENT]);
}
if (grm) {
struct event_container *event_container;
struct session *session;
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
event_container = cwmp_add_event_container(&cwmp_main, EVENT_IDX_2PERIODIC, "");
if (event_container == NULL) {
@ -314,11 +317,9 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
struct ubus_context *ubus_ctx = NULL;
if (ubus_ctx == NULL) {
ubus_ctx = ubus_connect(NULL);
if (ubus_ctx == NULL)
return -1;
}
ubus_ctx = ubus_connect(NULL);
if (ubus_ctx == NULL)
return -1;
blob_buf_init(&b, 0);
for (i = 0; i < u_args_size; i++) {
@ -327,13 +328,14 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
else if (u_args[i].type == UBUS_Integer) {
blobmsg_add_u32(&b, u_args[i].key, u_args[i].val.int_val);
} else if (u_args[i].type == UBUS_Array_Obj || u_args[i].type == UBUS_Array_Str) {
void *a, *t;
void *a;
int j;
a = blobmsg_open_array(&b, u_args[i].key);
if (u_args[i].type == UBUS_Array_Obj) {
void *t;
t = blobmsg_open_table(&b, "");
for (j = 0; j < ARRAY_MAX; j++) {
if (u_args[i].val.array_value[j].param_value.key == NULL || strlen(u_args[i].val.array_value[j].param_value.key) <= 0)
if (u_args[i].val.array_value[j].param_value.key == NULL || strlen(u_args[i].val.array_value[j].param_value.key) == 0)
break;
blobmsg_add_string(&b, u_args[i].val.array_value[j].param_value.key, u_args[i].val.array_value[j].param_value.value);
}
@ -341,7 +343,7 @@ int cwmp_ubus_call(const char *obj, const char *method, const struct cwmp_ubus_a
}
if (u_args[i].type == UBUS_Array_Str) {
for (j = 0; j < ARRAY_MAX; j++) {
if (u_args[i].val.array_value[j].str_value == NULL || strlen(u_args[i].val.array_value[j].str_value) <= 0)
if (u_args[i].val.array_value[j].str_value == NULL || strlen(u_args[i].val.array_value[j].str_value) == 0)
break;
blobmsg_add_string(&b, NULL, u_args[i].val.array_value[j].str_value);
}
@ -349,9 +351,10 @@ 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;
void *a, *t;
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) {
void *t;
if (!param_value->name)
break;
t = blobmsg_open_table(&b, "");

View file

@ -99,7 +99,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
struct transfer_complete *p;
char *name = "";
upload_startTime = mix_get_time();
char file_path[128];
char file_path[128] = {'\0'};
bkp_session_delete_upload(pupload);
bkp_session_save();
@ -131,7 +131,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
} else
error = FAULT_CPE_UPLOAD_FAILURE;
}
if (error != FAULT_CPE_NO_FAULT || strlen(file_path) <= 0) {
if (error != FAULT_CPE_NO_FAULT || strlen(file_path) == 0) {
error = FAULT_CPE_UPLOAD_FAILURE;
goto end_upload;
}
@ -272,10 +272,9 @@ int cwmp_free_upload_request(struct upload *upload)
int cwmp_scheduledUpload_remove_all()
{
struct upload *upload;
pthread_mutex_lock(&mutex_upload);
while (list_upload.next != &(list_upload)) {
struct upload *upload;
upload = list_entry(list_upload.next, struct upload, list);
list_del(&(upload->list));
bkp_session_delete_upload(upload);

4
xml.c
View file

@ -50,11 +50,11 @@ mxmlFindElementOpaque(mxml_node_t *node, /* I - Current node */
int xml_recreate_namespace(mxml_node_t *tree)
{
const char *cwmp_urn;
char *c;
int i;
mxml_node_t *b = tree;
do {
char *c;
FREE(ns.soap_env);
FREE(ns.soap_enc);
FREE(ns.xsd);
@ -211,13 +211,13 @@ int xml_prepare_msg_out(struct session *session)
struct cwmp *cwmp = &cwmp_main;
struct config *conf;
conf = &(cwmp->conf);
mxml_node_t *n;
#ifdef DUMMY_MODE
FILE *fp;
fp = fopen("./ext/soap_msg_templates/cwmp_response_message.xml", "r");
session->tree_out = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
fclose(fp);
#else
mxml_node_t *n;
session->tree_out = mxmlLoadString(NULL, CWMP_RESPONSE_MESSAGE, MXML_OPAQUE_CALLBACK);
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Envelope", NULL, NULL, MXML_DESCEND);
if (!n) {