uci: add logs and fix function order in cwmp init

This commit is contained in:
Amin Ben Romdhane 2023-12-08 17:35:01 +01:00
parent e5ed4c3c89
commit 8af10a0f7a
7 changed files with 211 additions and 161 deletions

View file

@ -238,10 +238,6 @@ static int cwmp_init(void)
if ((error = create_cwmp_notifications_package())) if ((error = create_cwmp_notifications_package()))
return error; return error;
CWMP_LOG(DEBUG, "Loading icwmpd configuration");
cwmp_config_load();
CWMP_LOG(DEBUG, "Successfully load icwmpd configuration");
cwmp_main->prev_periodic_enable = cwmp_main->conf.periodic_enable; cwmp_main->prev_periodic_enable = cwmp_main->conf.periodic_enable;
cwmp_main->prev_periodic_interval = cwmp_main->conf.period; cwmp_main->prev_periodic_interval = cwmp_main->conf.period;
cwmp_main->prev_periodic_time = cwmp_main->conf.time; cwmp_main->prev_periodic_time = cwmp_main->conf.time;
@ -252,10 +248,14 @@ static int cwmp_init(void)
if (cwmp_stop == true) if (cwmp_stop == true)
return CWMP_GEN_ERR; return CWMP_GEN_ERR;
cwmp_get_deviceid();
cwmp_uci_init(); cwmp_uci_init();
CWMP_LOG(DEBUG, "Loading icwmpd configuration");
cwmp_config_load();
CWMP_LOG(DEBUG, "Successfully load icwmpd configuration");
cwmp_get_deviceid();
/* Load default force inform parameters */ /* Load default force inform parameters */
CWMP_MEMSET(&force_inform_list, 0, sizeof(struct list_head)); CWMP_MEMSET(&force_inform_list, 0, sizeof(struct list_head));
INIT_LIST_HEAD(&force_inform_list); INIT_LIST_HEAD(&force_inform_list);

View file

@ -15,23 +15,8 @@
#include "log.h" #include "log.h"
#include "cwmp_uci.h" #include "cwmp_uci.h"
struct uloop_fd http_event6;
pthread_t http_cr_server_thread; pthread_t http_cr_server_thread;
void http_server_listen_uloop(struct uloop_fd *ufd __attribute__((unused)), unsigned events __attribute__((unused)))
{
icwmp_http_server_listen();
}
void http_server_start_uloop(void)
{
icwmp_http_server_init();
http_event6.fd = cwmp_main->cr_socket_desc;
http_event6.cb = http_server_listen_uloop;
uloop_fd_add(&http_event6, ULOOP_READ | ULOOP_EDGE_TRIGGER);
}
static void *thread_http_cr_server_listen(void *v __attribute__((unused))) static void *thread_http_cr_server_listen(void *v __attribute__((unused)))
{ {
icwmp_http_server_listen(); icwmp_http_server_listen();

View file

@ -17,6 +17,10 @@
#include "cwmp_uci.h" #include "cwmp_uci.h"
#include "log.h" #include "log.h"
#define RETURN_UCI_ERR(ERR) \
CWMP_LOG(ERROR, "UCI error occurred in %s:%d (%d)", __func__, __LINE__, ERR) \
return ERR;
static struct uci_paths uci_save_conf_paths[] = { static struct uci_paths uci_save_conf_paths[] = {
[UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci", NULL }, [UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci", NULL },
[UCI_VARSTATE_CONFIG] = { "/var/state", NULL, NULL }, [UCI_VARSTATE_CONFIG] = { "/var/state", NULL, NULL },
@ -228,33 +232,34 @@ void cwmp_uci_reinit(void)
/* /*
* UCI GET option value * UCI GET option value
*/ */
int cwmp_uci_get_value_by_path(char *path, uci_config_paths uci_type, char **value) static int cwmp_uci_get_value_by_path(char *path, uci_config_paths uci_type, char **value)
{ {
struct uci_ptr ptr; struct uci_ptr ptr = {0};;
char *s;
CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
*value = NULL; *value = NULL;
if (path == NULL) if (path == NULL) {
return UCI_ERR_NOTFOUND; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
s = strdup(path); char *s = strdup(path);
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, s, true) != UCI_OK) { if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, s, true) != UCI_OK) {
CWMP_LOG(ERROR, "Error occurred in uci get %s", path);
free(s); free(s);
return UCI_ERR_PARSE; RETURN_UCI_ERR(UCI_ERR_PARSE);
} }
free(s); free(s);
if (ptr.flags & UCI_LOOKUP_COMPLETE) { if (ptr.flags & UCI_LOOKUP_COMPLETE) {
if (ptr.o == NULL || ptr.o->v.string == NULL) { if (ptr.o == NULL || ptr.o->v.string == NULL) {
CWMP_LOG(INFO, "%s not found or empty value", path); RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
return UCI_OK;
} }
*value = strdup(ptr.o->v.string); *value = strdup(ptr.o->v.string);
return UCI_OK; return UCI_OK;
} }
return UCI_ERR_NOTFOUND;
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
} }
int uci_get_state_value(char *path, char **value) int uci_get_state_value(char *path, char **value)
@ -269,15 +274,15 @@ int uci_get_value(char *path, char **value)
int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, char **value) int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, char **value)
{ {
struct uci_element *e; struct uci_element *e = NULL;
struct uci_option *o; struct uci_option *o = NULL;
*value = NULL; *value = NULL;
if (s == NULL || option == NULL) if (s == NULL || option == NULL)
goto not_found; goto not_found;
uci_foreach_element(&s->options, e) uci_foreach_element(&s->options, e) {
{
o = (uci_to_option(e)); o = (uci_to_option(e));
if (o && !CWMP_STRCMP(o->e.name, option)) { if (o && !CWMP_STRCMP(o->e.name, option)) {
if (o->type == UCI_TYPE_LIST) { if (o->type == UCI_TYPE_LIST) {
@ -291,7 +296,7 @@ int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, ch
not_found: not_found:
*value = NULL; *value = NULL;
return UCI_ERR_NOTFOUND; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
} }
int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value) int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value)
@ -304,11 +309,11 @@ int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, stru
*value = NULL; *value = NULL;
if (s == NULL || option == NULL) if (s == NULL || option == NULL) {
return -1; RETURN_UCI_ERR(-1);
}
uci_foreach_element(&s->options, e) uci_foreach_element(&s->options, e) {
{
o = (uci_to_option(e)); o = (uci_to_option(e));
if (o && CWMP_STRCMP(o->e.name, option) == 0) { if (o && CWMP_STRCMP(o->e.name, option) == 0) {
switch (o->type) { switch (o->type) {
@ -331,11 +336,12 @@ int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, stru
*value = list; *value = list;
return 0; return 0;
default: default:
return -1; RETURN_UCI_ERR(-1);
} }
} }
} }
return -1;
RETURN_UCI_ERR(-1);
} }
/* /*
@ -345,15 +351,21 @@ int cwmp_uci_set_value_string(char *package, char *section, char *option, char *
{ {
struct uci_ptr ptr = {0}; struct uci_ptr ptr = {0};
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section == NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section == NULL) {
return UCI_ERR_PARSE; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
if (uci_set(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK) }
return UCI_ERR_NOTFOUND;
if (ptr.o) if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) {
RETURN_UCI_ERR(UCI_ERR_PARSE);
}
if (uci_set(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK) {
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
return UCI_OK; return UCI_OK;
return UCI_ERR_NOTFOUND;
} }
int cwmp_uci_set_value(char *package, char *section, char *option, char *value) int cwmp_uci_set_value(char *package, char *section, char *option, char *value)
@ -366,30 +378,6 @@ int cwmp_uci_set_varstate_value(char *package, char *section, char *option, char
return cwmp_uci_set_value_string(package, section, option, value, UCI_VARSTATE_CONFIG); return cwmp_uci_set_value_string(package, section, option, value, UCI_VARSTATE_CONFIG);
} }
int uci_set_value_by_path(char *path, char *value, uci_config_paths uci_type)
{
struct uci_ptr ptr;
int ret = UCI_OK;
char cmd[256];
if (path == NULL || value == NULL)
return UCI_ERR_NOTFOUND;
snprintf(cmd, sizeof(cmd), "%s=%s", path, value);
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, cmd, true) != UCI_OK) {
return UCI_ERR_PARSE;
}
ret = uci_set(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
if (ret == UCI_OK) {
ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p);
} else {
CWMP_LOG(ERROR, "UCI delete not succeed %s", path);
return UCI_ERR_NOTFOUND;
}
return ret;
}
int cwmp_uci_get_option_value_list(char *package, char *section, char *option, uci_config_paths uci_type, struct uci_list **value) int cwmp_uci_get_option_value_list(char *package, char *section, char *option, uci_config_paths uci_type, struct uci_list **value)
{ {
struct uci_element *e = NULL; struct uci_element *e = NULL;
@ -399,10 +387,13 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, u
int option_type; int option_type;
*value = NULL; *value = NULL;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) {
return UCI_ERR_NOTFOUND; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, NULL)) }
return UCI_ERR_PARSE;
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, NULL)) {
RETURN_UCI_ERR(UCI_ERR_PARSE);
}
if (ptr.o) { if (ptr.o) {
switch(ptr.o->type) { switch(ptr.o->type) {
@ -433,6 +424,7 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, u
} else { } else {
return UCI_ERR_NOTFOUND; return UCI_ERR_NOTFOUND;
} }
return option_type; return option_type;
} }
@ -441,15 +433,20 @@ int cwmp_uci_add_list_value(char *package, char *section, char *option, char *va
struct uci_ptr ptr = {0}; struct uci_ptr ptr = {0};
int error = UCI_OK; int error = UCI_OK;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) {
return UCI_ERR_PARSE; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) {
RETURN_UCI_ERR(UCI_ERR_PARSE);
}
error = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr); error = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
if (error != UCI_OK) if (error != UCI_OK) {
return error; RETURN_UCI_ERR(error);
}
return UCI_OK; return UCI_OK;
} }
@ -458,37 +455,51 @@ int cwmp_uci_del_list_value(char *package, char *section, char *option, char *va
{ {
struct uci_ptr ptr = {0}; struct uci_ptr ptr = {0};
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section ==NULL || option ==NULL) {
return -1; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
if (uci_del_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK) if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value)) {
return -1; RETURN_UCI_ERR(-1);
}
if (uci_del_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK) {
RETURN_UCI_ERR(-1);
}
return 0; return 0;
} }
int uci_add_list_value(char *cmd, uci_config_paths uci_type) int uci_add_list_value(char *cmd, uci_config_paths uci_type)
{ {
struct uci_ptr ptr; struct uci_ptr ptr = {0};
int ret = UCI_OK; int ret = UCI_OK;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || cmd == NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, cmd, true) != UCI_OK) { if (uci_save_conf_paths[uci_type].uci_ctx == NULL || cmd == NULL) {
return UCI_ERR_PARSE; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
} }
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, cmd, true) != UCI_OK) {
RETURN_UCI_ERR(UCI_ERR_PARSE);
}
ret = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr); ret = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
if (ret == UCI_OK) { if (ret == UCI_OK) {
ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p); ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p);
} else { } else {
CWMP_LOG(ERROR, "UCI delete not succeed %s", cmd); RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
return UCI_ERR_NOTFOUND;
} }
return ret;
if (ret) {
RETURN_UCI_ERR(ret);
}
return UCI_OK;
} }
/* /*
@ -502,31 +513,37 @@ int cwmp_uci_add_section(char *package, char *stype, uci_config_paths uci_type ,
*s = NULL; *s = NULL;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || stype == NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || stype == NULL) {
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
snprintf(fname, sizeof(fname), "%s/%s", uci_save_conf_paths[uci_type].conf_dir, package); snprintf(fname, sizeof(fname), "%s/%s", uci_save_conf_paths[uci_type].conf_dir, package);
if (!file_exists(fname)) { if (!file_exists(fname)) {
FILE *fptr = fopen(fname, "w"); FILE *fptr = fopen(fname, "w");
if (fptr) if (fptr) {
fclose(fptr); fclose(fptr);
else } else {
return UCI_ERR_UNKNOWN; RETURN_UCI_ERR(UCI_ERR_UNKNOWN);
}
} }
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, NULL, NULL, NULL) == 0 if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK) {
&& uci_add_section(uci_save_conf_paths[uci_type].uci_ctx, ptr.p, stype, s) == UCI_OK) { RETURN_UCI_ERR(UCI_ERR_PARSE);
CWMP_LOG(INFO, "New uci section %s added successfully", stype); }
if (uci_add_section(uci_save_conf_paths[uci_type].uci_ctx, ptr.p, stype, s) != UCI_OK) {
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
} }
else
return UCI_ERR_NOTFOUND;
return UCI_OK; return UCI_OK;
} }
static struct uci_section* get_section_by_section_name(char *package, char *stype, char* sname, uci_config_paths uci_type) static struct uci_section* get_section_by_section_name(char *package, char *stype, char* sname, uci_config_paths uci_type)
{ {
struct uci_section *s; struct uci_section *s = NULL;
if (package == NULL || stype == NULL || sname == NULL) if (package == NULL || stype == NULL || sname == NULL)
return NULL; return NULL;
@ -542,14 +559,21 @@ static struct uci_section* get_section_by_section_name(char *package, char *styp
int cwmp_uci_rename_section_by_section(struct uci_section *s, char *value, uci_config_paths uci_type) int cwmp_uci_rename_section_by_section(struct uci_section *s, char *value, uci_config_paths uci_type)
{ {
struct uci_ptr up = {0}; struct uci_ptr ptr = {0};
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || s == NULL || value == NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (cwmp_uci_lookup_ptr_by_section(uci_save_conf_paths[uci_type].uci_ctx, &up, s, NULL, value) == -1) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || s == NULL || value == NULL) {
return UCI_ERR_PARSE; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
if (uci_rename(uci_save_conf_paths[uci_type].uci_ctx, &up) != UCI_OK) }
return UCI_ERR_NOTFOUND;
if (cwmp_uci_lookup_ptr_by_section(uci_save_conf_paths[uci_type].uci_ctx, &ptr, s, NULL, value) == -1) {
RETURN_UCI_ERR(UCI_ERR_PARSE);
}
if (uci_rename(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK) {
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);;
}
return UCI_OK; return UCI_OK;
} }
@ -558,12 +582,17 @@ int cwmp_uci_add_section_with_specific_name(char *package, char *stype, char *se
{ {
struct uci_section *s = NULL; struct uci_section *s = NULL;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || stype == NULL) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || stype == NULL) {
return UCI_ERR_NOTFOUND; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
if (get_section_by_section_name(package, stype, section_name, uci_type) != NULL) }
return UCI_ERR_DUPLICATE;
if (cwmp_uci_add_section(package, stype, uci_type, &s) != UCI_OK) if (get_section_by_section_name(package, stype, section_name, uci_type) != NULL) {
return UCI_ERR_UNKNOWN; return UCI_OK;
}
if (cwmp_uci_add_section(package, stype, uci_type, &s) != UCI_OK) {
RETURN_UCI_ERR(UCI_ERR_UNKNOWN);
}
return cwmp_uci_rename_section_by_section(s, section_name, uci_type); return cwmp_uci_rename_section_by_section(s, section_name, uci_type);
} }
@ -573,39 +602,55 @@ int cwmp_uci_add_section_with_specific_name(char *package, char *stype, char *se
*/ */
int uci_delete_value(char *path, int uci_type) int uci_delete_value(char *path, int uci_type)
{ {
struct uci_ptr ptr; struct uci_ptr ptr = {0};
int ret = UCI_OK; int ret = UCI_OK;
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || path == NULL) CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
return UCI_ERR_NOTFOUND;
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, path, true) != UCI_OK) if (uci_save_conf_paths[uci_type].uci_ctx == NULL || path == NULL) {
return CWMP_GEN_ERR; RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, path, true) != UCI_OK) {
RETURN_UCI_ERR(CWMP_GEN_ERR);
}
ret = uci_delete(uci_save_conf_paths[uci_type].uci_ctx, &ptr); ret = uci_delete(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
if (ret == UCI_OK) { if (ret == UCI_OK) {
ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p); ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p);
} else { } else {
CWMP_LOG(ERROR, "UCI delete not succeed %s", path); RETURN_UCI_ERR(CWMP_GEN_ERR);
return CWMP_GEN_ERR;
} }
if (ret) {
RETURN_UCI_ERR(ret);
}
return ret; return ret;
} }
int cwmp_uci_get_section_type(char *package, char *section, uci_config_paths uci_type, char **value) int cwmp_uci_get_section_type(char *package, char *section, uci_config_paths uci_type, char **value)
{ {
struct uci_ptr ptr = {0}; struct uci_ptr ptr = {0};
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section == NULL)
return UCI_ERR_NOTFOUND; CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
if (uci_save_conf_paths[uci_type].uci_ctx == NULL || package == NULL || section == NULL) {
RETURN_UCI_ERR(UCI_ERR_NOTFOUND);
}
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, NULL, NULL)) { if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, NULL, NULL)) {
*value = ""; *value = "";
return -1; RETURN_UCI_ERR(UCI_ERR_PARSE);
} }
if (ptr.s) { if (ptr.s) {
*value = icwmp_strdup(ptr.s->type); *value = icwmp_strdup(ptr.s->type);
} else { } else {
*value = ""; *value = "";
} }
return UCI_OK; return UCI_OK;
} }
@ -646,15 +691,18 @@ end:
int cwmp_commit_package(char *package, uci_config_paths uci_type) int cwmp_commit_package(char *package, uci_config_paths uci_type)
{ {
struct uci_ptr ptr = { 0 }; struct uci_ptr ptr = {0};
CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, true) != UCI_OK) { if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, true) != UCI_OK) {
return -1; RETURN_UCI_ERR(-1);
} }
if (uci_commit(uci_save_conf_paths[uci_type].uci_ctx, &ptr.p, false) != UCI_OK) { if (uci_commit(uci_save_conf_paths[uci_type].uci_ctx, &ptr.p, false) != UCI_OK) {
return -1; RETURN_UCI_ERR(-1);
} }
return 0; return 0;
} }
@ -663,11 +711,15 @@ int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths
struct uci_package *package = NULL; struct uci_package *package = NULL;
struct uci_element *e = NULL; struct uci_element *e = NULL;
int ret = CWMP_OK; int ret = CWMP_OK;
if (input_path == NULL)
return -1; if (input_path == NULL) {
RETURN_UCI_ERR(-1);
}
FILE *input = fopen(input_path, "r"); FILE *input = fopen(input_path, "r");
if (!input) if (!input) {
return -1; RETURN_UCI_ERR(-1);
}
if (uci_save_conf_paths[uci_type].uci_ctx == NULL) { if (uci_save_conf_paths[uci_type].uci_ctx == NULL) {
ret = -1; ret = -1;
@ -683,8 +735,7 @@ int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths
goto end; goto end;
} }
uci_foreach_element(&uci_save_conf_paths[uci_type].uci_ctx->root, e) uci_foreach_element(&uci_save_conf_paths[uci_type].uci_ctx->root, e) {
{
struct uci_package *p = uci_to_package(e); struct uci_package *p = uci_to_package(e);
if (uci_commit(uci_save_conf_paths[uci_type].uci_ctx, &p, true) != UCI_OK) if (uci_commit(uci_save_conf_paths[uci_type].uci_ctx, &p, true) != UCI_OK)
ret = CWMP_GEN_ERR; ret = CWMP_GEN_ERR;
@ -692,18 +743,29 @@ int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths
end: end:
fclose(input); fclose(input);
if (ret) {
RETURN_UCI_ERR(ret);
}
return ret; return ret;
} }
int cwmp_uci_export_package(char *package, const char *output_path, uci_config_paths uci_type) int cwmp_uci_export_package(char *package, const char *output_path, uci_config_paths uci_type)
{ {
struct uci_ptr ptr = { 0 }; struct uci_ptr ptr = {0};
int ret = 0; int ret = 0;
if (output_path == NULL)
return -1; CWMP_MEMSET(&ptr, 0, sizeof(struct uci_ptr));
if (output_path == NULL) {
RETURN_UCI_ERR(-1);
}
FILE *out = fopen(output_path, "a"); FILE *out = fopen(output_path, "a");
if (!out) if (!out) {
return -1; RETURN_UCI_ERR(-1);
}
if (uci_save_conf_paths[uci_type].uci_ctx == NULL) { if (uci_save_conf_paths[uci_type].uci_ctx == NULL) {
ret = -1; ret = -1;
@ -720,6 +782,11 @@ int cwmp_uci_export_package(char *package, const char *output_path, uci_config_p
end: end:
fclose(out); fclose(out);
if (ret) {
RETURN_UCI_ERR(ret);
}
return ret; return ret;
} }
@ -728,11 +795,13 @@ int cwmp_uci_export(const char *output_path, uci_config_paths uci_type)
char **configs = NULL; char **configs = NULL;
char **p; char **p;
if (uci_list_configs(uci_save_conf_paths[uci_type].uci_ctx, &configs) != UCI_OK) if (uci_list_configs(uci_save_conf_paths[uci_type].uci_ctx, &configs) != UCI_OK) {
return -1; RETURN_UCI_ERR(-1);
}
if (configs == NULL) if (configs == NULL) {
return -1; RETURN_UCI_ERR(-1);
}
for (p = configs; *p; p++) for (p = configs; *p; p++)
cwmp_uci_export_package(*p, output_path, uci_type); cwmp_uci_export_package(*p, output_path, uci_type);

View file

@ -56,8 +56,6 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, u
int uci_get_state_value(char *cmd, char **value); int uci_get_state_value(char *cmd, char **value);
int uci_set_value_by_path(char *cmd, char *value, uci_config_paths uci_type);
int uci_get_value(char *cmd, char **value); int uci_get_value(char *cmd, char **value);
struct uci_section *cwmp_uci_walk_section(char *package, char *stype, struct uci_section *prev_section, uci_config_paths uci_type, int walk); struct uci_section *cwmp_uci_walk_section(char *package, char *stype, struct uci_section *prev_section, uci_config_paths uci_type, int walk);
@ -67,7 +65,6 @@ int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, ch
int cwmp_commit_package(char *package, uci_config_paths uci_type); int cwmp_commit_package(char *package, uci_config_paths uci_type);
int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths uci_type); int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths uci_type);
int cwmp_uci_export_package(char *package, const char *output_path, uci_config_paths uci_type); int cwmp_uci_export_package(char *package, const char *output_path, uci_config_paths uci_type);
int cwmp_uci_export(const char *output_path, uci_config_paths uci_type); int cwmp_uci_export(const char *output_path, uci_config_paths uci_type);
void cwmp_free_uci_list(struct uci_list *list); void cwmp_free_uci_list(struct uci_list *list);

View file

@ -141,7 +141,7 @@ bool check_parent_with_different_notification(char *parameter_name, int notifica
struct uci_list *list_notif = NULL; struct uci_list *list_notif = NULL;
struct uci_element *e = NULL; struct uci_element *e = NULL;
int i; int i;
for (i = 0; i < 7; i++) { for (i = 0; i < ARRAY_SIZE(notifications); i++) {
int option_type; int option_type;
if (i == notification) if (i == notification)
@ -172,7 +172,7 @@ bool update_notifications_list(char *parameter_name, int notification)
/* /*
* Parse all possible lists of of notifications one by one * Parse all possible lists of of notifications one by one
*/ */
for (i = 0; i < 7; i++) { for (i = 0; i < ARRAY_SIZE(notifications); i++) {
int option_type; int option_type;
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif); option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif);
@ -234,7 +234,7 @@ int get_parameter_family_notifications(char *parameter_name, struct list_head *c
if (parameter_name == NULL) if (parameter_name == NULL)
parameter_name = "Device."; parameter_name = "Device.";
for (i = 0; i < 7; i++) { for (i = 0; i < ARRAY_SIZE(notifications); i++) {
int option_type; int option_type;
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif); option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif);
@ -357,7 +357,7 @@ void create_list_param_obj_notify()
struct uci_element *e = NULL; struct uci_element *e = NULL;
int i; int i;
for (i = 0; i < 7; i++) { for (i = 0; i < ARRAY_SIZE(notifications); i++) {
int option_type; int option_type;
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif); option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], UCI_ETCICWMPD_CONFIG, &list_notif);
if (list_notif) { if (list_notif) {

View file

@ -118,7 +118,7 @@ static int cwmp_rpc_cpe_handle_message(struct rpc *rpc_cpe)
return 0; return 0;
} }
int cwmp_schedule_rpc() static int cwmp_schedule_rpc()
{ {
struct list_head *ilist; struct list_head *ilist;
struct rpc *rpc_acs; struct rpc *rpc_acs;

View file

@ -112,7 +112,6 @@ int clean_cwmp_session_structure();
void set_cwmp_session_status(int status, int retry_time); void set_cwmp_session_status(int status, int retry_time);
int cwmp_session_init(); int cwmp_session_init();
int cwmp_session_exit(); int cwmp_session_exit();
int cwmp_schedule_rpc();
int cwmp_apply_acs_changes(void); int cwmp_apply_acs_changes(void);
void rpc_exit(); void rpc_exit();
void trigger_cwmp_restart_timer(void); void trigger_cwmp_restart_timer(void);