mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-01-28 01:27:16 +01:00
Updated notification handling
This commit is contained in:
parent
91e473e780
commit
24984b7cd7
21 changed files with 498 additions and 274 deletions
29
common.c
29
common.c
|
|
@ -272,7 +272,13 @@ void get_firewall_zone_name_by_wan_iface(char *if_wan, char **zone_name)
|
|||
|
||||
if (if_wan == NULL)
|
||||
if_wan = "wan";
|
||||
cwmp_uci_foreach_sections("firewall", "zone", UCI_STANDARD_CONFIG, s)
|
||||
|
||||
struct uci_paths conf_path;
|
||||
int ret = cwmp_uci_standard_init(&conf_path);
|
||||
if (ret != 0)
|
||||
return;
|
||||
|
||||
cwmp_uci_foreach_sections("firewall", "zone", conf_path.uci_ctx, s)
|
||||
{
|
||||
cwmp_uci_get_value_by_section_string(s, "network", &network);
|
||||
if (network == NULL)
|
||||
|
|
@ -282,12 +288,15 @@ void get_firewall_zone_name_by_wan_iface(char *if_wan, char **zone_name)
|
|||
if (strcmp(net, if_wan) == 0) {
|
||||
cwmp_uci_get_value_by_section_string(s, "name", zone_name);
|
||||
icwmp_free(network);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return;
|
||||
}
|
||||
net = strtok(NULL, " ");
|
||||
}
|
||||
icwmp_free(network);
|
||||
}
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -295,16 +304,16 @@ void get_firewall_zone_name_by_wan_iface(char *if_wan, char **zone_name)
|
|||
*/
|
||||
void cwmp_reboot(char *command_key)
|
||||
{
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "ParameterKey", command_key ? command_key : "");
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
cwmp_uci_set_value("cwmp", "cpe", "ParameterKey", command_key ? command_key : "");
|
||||
|
||||
struct blob_buf b = { 0 };
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
icwmp_ubus_invoke("rpc-sys", "reboot", b.head, NULL, NULL);
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -314,11 +323,12 @@ void cwmp_factory_reset() //use the ubus rpc-sys factory
|
|||
{
|
||||
struct blob_buf b = { 0 };
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
icwmp_ubus_invoke("rpc-sys", "factory", b.head, NULL, NULL);
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
long int get_file_size(char *file_name)
|
||||
|
|
@ -619,9 +629,8 @@ void icwmp_restart_services()
|
|||
}
|
||||
}
|
||||
if (g_firewall_restart) {
|
||||
CWMP_LOG(INFO, "Initiating Firewall restart");
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "in_progress");
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
CWMP_LOG(INFO, "Initiating Firewall restart");
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "in_progress");
|
||||
}
|
||||
icwmp_free_list_services();
|
||||
}
|
||||
|
|
|
|||
2
config.c
2
config.c
|
|
@ -589,12 +589,10 @@ void cwmp_config_load(struct cwmp *cwmp)
|
|||
{
|
||||
int ret;
|
||||
|
||||
cwmp_uci_reinit();
|
||||
ret = global_conf_init(cwmp);
|
||||
while (ret != CWMP_OK && thread_end != true) {
|
||||
CWMP_LOG(DEBUG, "Error reading uci ret = %d", ret);
|
||||
sleep(UCI_OPTION_READ_INTERVAL);
|
||||
cwmp_uci_reinit();
|
||||
ret = global_conf_init(cwmp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
cwmp.c
14
cwmp.c
|
|
@ -63,7 +63,6 @@ static void set_cwmp_session_status_state(int status)
|
|||
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
|
||||
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
|
||||
cwmp_uci_reinit();
|
||||
cwmp_uci_add_section_with_specific_name("cwmp", "sess_status", "sess_status", UCI_VARSTATE_CONFIG);
|
||||
|
||||
switch (status) {
|
||||
|
|
@ -82,8 +81,6 @@ static void set_cwmp_session_status_state(int status)
|
|||
}
|
||||
|
||||
cwmp_uci_set_varstate_value("cwmp", "sess_status", "current_status", state ? state : "N/A");
|
||||
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
}
|
||||
|
||||
static void cwmp_invoke_intf_reset(char *path)
|
||||
|
|
@ -224,7 +221,6 @@ end:
|
|||
|
||||
int get_firewall_restart_state(char **state)
|
||||
{
|
||||
cwmp_uci_reinit();
|
||||
return uci_get_state_value(UCI_CPE_FIREWALL_RESTART_STATE, state);
|
||||
}
|
||||
|
||||
|
|
@ -256,7 +252,6 @@ void check_firewall_restart_state()
|
|||
if (init == false) { // In case of timeout reset the firewall_restart flag
|
||||
CWMP_LOG(ERROR, "Firewall restart took longer than usual");
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "firewall_restart", "init");
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +371,6 @@ int run_session_end_func(void)
|
|||
|
||||
if (end_session_flag & END_SESSION_RELOAD) {
|
||||
CWMP_LOG(INFO, "Config reload: end session request");
|
||||
cwmp_uci_reinit();
|
||||
if (cwmp_apply_acs_changes() != CWMP_OK) {
|
||||
CWMP_LOG(ERROR, "config reload failed at session end");
|
||||
}
|
||||
|
|
@ -457,7 +451,6 @@ int run_session_end_func(void)
|
|||
|
||||
INIT_LIST_HEAD(&intf_reset_list);
|
||||
|
||||
cwmp_uci_exit();
|
||||
icwmp_cleanmem();
|
||||
end_session_flag = 0;
|
||||
return CWMP_OK;
|
||||
|
|
@ -533,19 +526,16 @@ static void cwmp_schedule_session(struct cwmp *cwmp)
|
|||
|
||||
if (file_exists(fc_cookies))
|
||||
remove(fc_cookies);
|
||||
cwmp_uci_init();
|
||||
CWMP_LOG(INFO, "Start session");
|
||||
|
||||
uci_get_value(UCI_CPE_EXEC_DOWNLOAD, &exec_download);
|
||||
if (exec_download && strcmp(exec_download, "1") == 0) {
|
||||
CWMP_LOG(INFO, "Firmware downloaded and applied successfully");
|
||||
cwmp_uci_set_value("cwmp", "cpe", "exec_download", "0");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
}
|
||||
FREE(exec_download);
|
||||
error = cwmp_schedule_rpc(cwmp, session);
|
||||
CWMP_LOG(INFO, "End session");
|
||||
cwmp_uci_exit();
|
||||
|
||||
if (thread_end) {
|
||||
event_remove_all_event_container(session, RPC_SEND);
|
||||
|
|
@ -951,7 +941,6 @@ static void cwmp_free(struct cwmp *cwmp)
|
|||
|
||||
clean_custom_inform_parameters();
|
||||
icwmp_cleanmem();
|
||||
cwmp_uci_exit();
|
||||
}
|
||||
|
||||
static void icwmp_signal_handler(int signal_num)
|
||||
|
|
@ -987,14 +976,11 @@ static void configure_var_state(struct cwmp *cwmp)
|
|||
if (!file_exists(VARSTATE_CONFIG"/cwmp"))
|
||||
creat(VARSTATE_CONFIG"/cwmp", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
|
||||
cwmp_uci_reinit();
|
||||
cwmp_uci_add_section_with_specific_name("cwmp", "acs", "acs", UCI_VARSTATE_CONFIG);
|
||||
cwmp_uci_add_section_with_specific_name("cwmp", "cpe", "cpe", UCI_VARSTATE_CONFIG);
|
||||
|
||||
get_firewall_zone_name_by_wan_iface(cwmp->conf.default_wan_iface, &zone_name);
|
||||
cwmp_uci_set_varstate_value("cwmp", "acs", "zonename", zone_name ? zone_name : "wan");
|
||||
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
|
|||
|
|
@ -312,7 +312,6 @@ char* execute_cwmp_cli_command(char *cmd, char *args[])
|
|||
char *fault = NULL, *fault_ret = NULL;
|
||||
size_t i;
|
||||
size_t commands_array_size = sizeof(icwmp_commands) / sizeof(struct cwmp_cli_command_struct);
|
||||
cwmp_uci_init();
|
||||
for (i = 0; i < commands_array_size; i++) {
|
||||
if (strcmp(icwmp_commands[i].command_name, cmd) == 0) {
|
||||
fault = icwmp_commands[i].cmd_exec_func(cmd_in, &cmd_out);
|
||||
|
|
@ -329,6 +328,5 @@ cli_help:
|
|||
|
||||
cli_end:
|
||||
icwmp_cleanmem();
|
||||
cwmp_uci_exit();
|
||||
return fault_ret;
|
||||
}
|
||||
|
|
|
|||
523
cwmp_uci.c
523
cwmp_uci.c
|
|
@ -15,11 +15,6 @@
|
|||
#include "cwmp_uci.h"
|
||||
#include "log.h"
|
||||
|
||||
struct uci_paths uci_save_conf_paths[] = {
|
||||
[UCI_STANDARD_CONFIG] = { "/etc/config", "/tmp/.uci", NULL },
|
||||
[UCI_VARSTATE_CONFIG] = { "/var/state", NULL, NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
* UCI LOOKUP
|
||||
*/
|
||||
|
|
@ -105,68 +100,95 @@ lookup:
|
|||
* UCI INIT EXIT
|
||||
*/
|
||||
|
||||
void cwmp_uci_init_by_config(int config)
|
||||
int cwmp_uci_standard_init(struct uci_paths *conf_path)
|
||||
{
|
||||
if(uci_save_conf_paths[config].uci_ctx != NULL)
|
||||
return;
|
||||
uci_save_conf_paths[config].uci_ctx = uci_alloc_context();
|
||||
if ( uci_save_conf_paths[config].uci_ctx == NULL)
|
||||
return;
|
||||
uci_add_delta_path(uci_save_conf_paths[config].uci_ctx, uci_save_conf_paths[config].uci_ctx->savedir);
|
||||
uci_set_savedir(uci_save_conf_paths[config].uci_ctx, uci_save_conf_paths[config].save_dir);
|
||||
uci_set_confdir(uci_save_conf_paths[config].uci_ctx, uci_save_conf_paths[config].conf_dir);
|
||||
}
|
||||
if (conf_path == NULL)
|
||||
return -1;
|
||||
|
||||
void cwmp_uci_exit_by_config(int config)
|
||||
{
|
||||
if (uci_save_conf_paths[config].uci_ctx) {
|
||||
uci_free_context(uci_save_conf_paths[config].uci_ctx);
|
||||
uci_save_conf_paths[config].uci_ctx = NULL;
|
||||
}
|
||||
}
|
||||
memset(conf_path, 0, sizeof(struct uci_paths));
|
||||
|
||||
int cwmp_uci_init(void)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
conf_path->uci_ctx = NULL;
|
||||
conf_path->conf_dir = "/etc/config";
|
||||
conf_path->save_dir = "/tmp/.uci";
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(uci_save_conf_paths); i++) {
|
||||
cwmp_uci_init_by_config(i);
|
||||
}
|
||||
conf_path->uci_ctx = uci_alloc_context();
|
||||
if (conf_path->uci_ctx == NULL)
|
||||
return -1;
|
||||
|
||||
uci_add_delta_path(conf_path->uci_ctx, conf_path->uci_ctx->savedir);
|
||||
uci_set_savedir(conf_path->uci_ctx, conf_path->save_dir);
|
||||
uci_set_confdir(conf_path->uci_ctx, conf_path->conf_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cwmp_uci_exit(void)
|
||||
int cwmp_uci_varstate_init(struct uci_paths *conf_path)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
if (conf_path == NULL)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(uci_save_conf_paths); i++) {
|
||||
cwmp_uci_exit_by_config(i);
|
||||
}
|
||||
memset(conf_path, 0, sizeof(struct uci_paths));
|
||||
|
||||
conf_path->uci_ctx = NULL;
|
||||
conf_path->conf_dir = "/var/state";
|
||||
conf_path->save_dir = NULL;
|
||||
|
||||
conf_path->uci_ctx = uci_alloc_context();
|
||||
if (conf_path->uci_ctx == NULL)
|
||||
return -1;
|
||||
|
||||
uci_add_delta_path(conf_path->uci_ctx, conf_path->uci_ctx->savedir);
|
||||
uci_set_savedir(conf_path->uci_ctx, conf_path->save_dir);
|
||||
uci_set_confdir(conf_path->uci_ctx, conf_path->conf_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cwmp_uci_reinit(void)
|
||||
int cwmp_uci_etccwmpd_init(struct uci_paths *conf_path)
|
||||
{
|
||||
cwmp_uci_exit();
|
||||
cwmp_uci_init();
|
||||
if (conf_path == NULL)
|
||||
return -1;
|
||||
|
||||
memset(conf_path, 0, sizeof(struct uci_paths));
|
||||
|
||||
conf_path->uci_ctx = NULL;
|
||||
conf_path->conf_dir = "/etc/icwmpd";
|
||||
conf_path->save_dir = NULL;
|
||||
|
||||
conf_path->uci_ctx = uci_alloc_context();
|
||||
if (conf_path->uci_ctx == NULL)
|
||||
return -1;
|
||||
|
||||
uci_add_delta_path(conf_path->uci_ctx, conf_path->uci_ctx->savedir);
|
||||
uci_set_savedir(conf_path->uci_ctx, conf_path->save_dir);
|
||||
uci_set_confdir(conf_path->uci_ctx, conf_path->conf_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void cwmp_uci_exit(struct uci_paths *conf_path)
|
||||
{
|
||||
if (conf_path == NULL)
|
||||
return;
|
||||
|
||||
if (conf_path->uci_ctx == NULL)
|
||||
return;
|
||||
|
||||
uci_free_context(conf_path->uci_ctx);
|
||||
conf_path->uci_ctx = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* UCI GET option value
|
||||
*/
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, uci_config_paths uci_type, char **value)
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, struct uci_context *uci_ctx, char **value)
|
||||
{
|
||||
struct uci_ptr ptr = { 0 };
|
||||
|
||||
if (package == NULL || section == NULL || option == NULL) {
|
||||
if (package == NULL || section == NULL || option == NULL || uci_ctx == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
if (uci_save_conf_paths[uci_type].uci_ctx == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, NULL) != UCI_OK) {
|
||||
if (cwmp_uci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL) != UCI_OK) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_PARSE;
|
||||
}
|
||||
|
|
@ -181,7 +203,7 @@ int cwmp_uci_get_option_value_string(char *package, char *section, char *option,
|
|||
return UCI_OK;
|
||||
}
|
||||
|
||||
int cwmp_uci_get_value_by_path(char *path, uci_config_paths uci_type, char **value)
|
||||
int cwmp_uci_get_value_by_path(char *path, struct uci_context *uci_ctx, char **value)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
char *s;
|
||||
|
|
@ -192,12 +214,12 @@ int cwmp_uci_get_value_by_path(char *path, uci_config_paths uci_type, char **val
|
|||
CWMP_LOG(ERROR, "the entered path argument is empty");
|
||||
return UCI_ERR_IO;
|
||||
}
|
||||
if (uci_save_conf_paths[uci_type].uci_ctx == NULL) {
|
||||
if (uci_ctx == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
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_ctx, &ptr, s, true) != UCI_OK) {
|
||||
CWMP_LOG(ERROR, "Error occurred in uci get %s", path);
|
||||
free(s);
|
||||
return UCI_ERR_PARSE;
|
||||
|
|
@ -216,24 +238,38 @@ int cwmp_uci_get_value_by_path(char *path, uci_config_paths uci_type, char **val
|
|||
int uci_get_state_value(char *path, char **value)
|
||||
{
|
||||
int error;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (path == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
error = cwmp_uci_get_value_by_path(path, UCI_VARSTATE_CONFIG, value);
|
||||
|
||||
if (cwmp_uci_varstate_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
error = cwmp_uci_get_value_by_path(path, conf_path.uci_ctx, value);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int uci_get_value(char *path, char **value)
|
||||
{
|
||||
int error;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (path == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
error = cwmp_uci_get_value_by_path(path, UCI_STANDARD_CONFIG, value);
|
||||
|
||||
if (cwmp_uci_standard_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
error = cwmp_uci_get_value_by_path(path, conf_path.uci_ctx, value);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
@ -311,52 +347,72 @@ int cwmp_uci_get_value_by_section_list(struct uci_section *s, char *option, stru
|
|||
/*
|
||||
* UCI Set option value
|
||||
*/
|
||||
int cwmp_uci_set_value_string(char *package, char *section, char *option, char *value, uci_config_paths uci_type)
|
||||
int cwmp_uci_set_value_string(char *package, char *section, char *option, char *value, struct uci_context *uci_ctx)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
|
||||
if (package == NULL || section == NULL || option == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
if (uci_save_conf_paths[uci_type].uci_ctx == NULL)
|
||||
if (uci_ctx == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value))
|
||||
if (cwmp_uci_lookup_ptr(uci_ctx, &ptr, package, section, option, value))
|
||||
return UCI_ERR_PARSE;
|
||||
if (uci_set(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK)
|
||||
if (uci_set(uci_ctx, &ptr) != UCI_OK)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
if (ptr.o)
|
||||
if (ptr.o) {
|
||||
uci_commit(uci_ctx, &ptr.p, false);
|
||||
return UCI_OK;
|
||||
}
|
||||
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
int cwmp_uci_set_value(char *package, char *section, char *option, char *value)
|
||||
{
|
||||
return cwmp_uci_set_value_string(package, section, option, value, UCI_STANDARD_CONFIG);
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_standard_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
int ret = cwmp_uci_set_value_string(package, section, option, value, conf_path.uci_ctx);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cwmp_uci_set_varstate_value(char *package, char*section, char *option, char *value)
|
||||
{
|
||||
return cwmp_uci_set_value_string(package, section, option, value, UCI_VARSTATE_CONFIG);
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_varstate_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
int ret = cwmp_uci_set_value_string(package, section, option, value, conf_path.uci_ctx);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int uci_set_value_by_path(char *path, char *value, uci_config_paths uci_type)
|
||||
int uci_set_value_by_path(char *path, char *value, struct uci_context *uci_ctx)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
int ret = UCI_OK;
|
||||
|
||||
if (path == NULL)
|
||||
if (path == NULL || uci_ctx == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
char cmd[256];
|
||||
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)
|
||||
if (uci_lookup_ptr(uci_ctx, &ptr, cmd, true) != UCI_OK)
|
||||
return UCI_ERR_PARSE;
|
||||
|
||||
ret = uci_set(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
|
||||
ret = uci_set(uci_ctx, &ptr);
|
||||
|
||||
if (ret == UCI_OK) {
|
||||
ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p);
|
||||
ret = uci_save(uci_ctx, ptr.p);
|
||||
} else {
|
||||
CWMP_LOG(ERROR, "UCI delete not succeed %s", path);
|
||||
CWMP_LOG(ERROR, "UCI set not succeed %s", path);
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -364,12 +420,28 @@ int uci_set_value_by_path(char *path, char *value, uci_config_paths uci_type)
|
|||
|
||||
int cwmp_uci_set_value_by_path(char *path, char *value)
|
||||
{
|
||||
return uci_set_value_by_path(path, value, UCI_STANDARD_CONFIG);
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_standard_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
int ret = uci_set_value_by_path(path, value, conf_path.uci_ctx);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cwmp_uci_set_varstate_value_by_path(char *path, char *value)
|
||||
{
|
||||
return uci_set_value_by_path(path, value, UCI_VARSTATE_CONFIG);
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_varstate_init(&conf_path) != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
int ret = uci_set_value_by_path(path, value, conf_path.uci_ctx);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -442,7 +514,7 @@ char *cwmp_uci_list_to_string(struct uci_list *list, char *delimitor)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
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, struct uci_context *uci_ctx, struct uci_list **value)
|
||||
{
|
||||
struct uci_element *e = NULL;
|
||||
struct uci_ptr ptr = {0};
|
||||
|
|
@ -458,7 +530,7 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, u
|
|||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, NULL))
|
||||
if (cwmp_uci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL))
|
||||
return UCI_ERR_PARSE;
|
||||
|
||||
if (ptr.o) {
|
||||
|
|
@ -498,130 +570,236 @@ int cwmp_uci_get_option_value_list(char *package, char *section, char *option, u
|
|||
return option_type;
|
||||
}
|
||||
|
||||
int cwmp_uci_get_cwmp_standard_option_value_list(char *package, char *section, char *option, struct uci_list **value)
|
||||
static int _init_uci_by_type(uci_config_paths uci_type, struct uci_paths *conf)
|
||||
{
|
||||
return cwmp_uci_get_option_value_list(package, section, option, UCI_STANDARD_CONFIG, value);
|
||||
}
|
||||
int ret = 0;
|
||||
|
||||
int cwmp_uci_get_cwmp_varstate_option_value_list(char *package, char *section, char *option, struct uci_list **value)
|
||||
{
|
||||
return cwmp_uci_get_option_value_list(package, section, option, UCI_VARSTATE_CONFIG, value);
|
||||
if (uci_type == UCI_STANDARD_CONFIG) {
|
||||
ret = cwmp_uci_standard_init(conf);
|
||||
} else if (uci_type == UCI_ETCICWMPD_CONFIG) {
|
||||
ret = cwmp_uci_etccwmpd_init(conf);
|
||||
} else if (uci_type == UCI_VARSTATE_CONFIG) {
|
||||
ret = cwmp_uci_varstate_init(conf);
|
||||
} else {
|
||||
CWMP_LOG(INFO, "Failed to init the config type[%d]", uci_type);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cwmp_uci_add_list_value(char *package, char *section, char *option, char *value, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
int error = UCI_OK;
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
if (package == NULL || section == NULL || option == NULL)
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value))
|
||||
|
||||
if (package == NULL || section == NULL || option == NULL) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
if (cwmp_uci_lookup_ptr(conf_path.uci_ctx, &ptr, package, section, option, value)) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_PARSE;
|
||||
}
|
||||
|
||||
error = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
|
||||
if (error != UCI_OK)
|
||||
error = uci_add_list(conf_path.uci_ctx, &ptr);
|
||||
if (error != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return error;
|
||||
}
|
||||
|
||||
uci_commit(conf_path.uci_ctx, &ptr.p, false);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_OK;
|
||||
}
|
||||
|
||||
int cwmp_uci_del_list_value(char *package, char *section, char *option, char *value, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
if (package == NULL || section == NULL || option == NULL)
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, option, value))
|
||||
return -1;
|
||||
if (package == NULL || section == NULL || option == NULL) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
if (uci_del_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr) != UCI_OK)
|
||||
if (cwmp_uci_lookup_ptr(conf_path.uci_ctx, &ptr, package, section, option, value)) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uci_del_list(conf_path.uci_ctx, &ptr) != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uci_commit(conf_path.uci_ctx, &ptr.p, false);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uci_add_list_value(char *cmd, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
int ret = UCI_OK;
|
||||
int error = UCI_OK;
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
if (cmd == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, cmd, true) != UCI_OK)
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (uci_lookup_ptr(conf_path.uci_ctx, &ptr, cmd, true) != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_PARSE;
|
||||
}
|
||||
|
||||
ret = uci_add_list(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
|
||||
error = uci_add_list(conf_path.uci_ctx, &ptr);
|
||||
|
||||
if (ret == UCI_OK) {
|
||||
ret = uci_save(uci_save_conf_paths[uci_type].uci_ctx, ptr.p);
|
||||
if (error == UCI_OK) {
|
||||
error = uci_save(conf_path.uci_ctx, ptr.p);
|
||||
} else {
|
||||
CWMP_LOG(ERROR, "UCI delete not succeed %s", cmd);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
return ret;
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* UCI ADD Section
|
||||
*/
|
||||
static int cwmp_uci_rename_section_by_section(struct uci_section *s, char *value, struct uci_context *uci_ctx)
|
||||
{
|
||||
struct uci_ptr up = {0};
|
||||
|
||||
if (s == NULL || value == NULL || uci_ctx == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (cwmp_uci_lookup_ptr_by_section(uci_ctx, &up, s, NULL, value) == -1) {
|
||||
return UCI_ERR_PARSE;
|
||||
}
|
||||
|
||||
if (uci_rename(uci_ctx, &up) != UCI_OK) {
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
return UCI_OK;
|
||||
}
|
||||
|
||||
static int add_section_helper(struct uci_paths *conf_path, char *package, char * stype, struct uci_section **s, struct uci_ptr *ptr)
|
||||
{
|
||||
char fname[128] = {0};
|
||||
snprintf(fname, sizeof(fname), "%s/%s", conf_path->conf_dir, package);
|
||||
|
||||
if (!file_exists(fname)) {
|
||||
FILE *fptr = fopen(fname, "w");
|
||||
if (fptr) {
|
||||
fclose(fptr);
|
||||
} else {
|
||||
return UCI_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (cwmp_uci_lookup_ptr(conf_path->uci_ctx, ptr, package, NULL, NULL, NULL) == 0
|
||||
&& uci_add_section(conf_path->uci_ctx, ptr->p, stype, s) == UCI_OK) {
|
||||
CWMP_LOG(INFO, "New uci section %s added successfully", stype);
|
||||
} else {
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
return UCI_OK;
|
||||
}
|
||||
|
||||
int cwmp_uci_add_section(char *package, char *stype, uci_config_paths uci_type , struct uci_section **s)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
char fname[128];
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
*s = NULL;
|
||||
|
||||
if (package == NULL || stype == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
snprintf(fname, sizeof(fname), "%s/%s", uci_save_conf_paths[uci_type].conf_dir, package);
|
||||
|
||||
if (!file_exists(fname)) {
|
||||
FILE *fptr = fopen(fname, "w");
|
||||
if (fptr)
|
||||
fclose(fptr);
|
||||
else
|
||||
return UCI_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, NULL, NULL, NULL) == 0
|
||||
&& uci_add_section(uci_save_conf_paths[uci_type].uci_ctx, ptr.p, stype, s) == UCI_OK) {
|
||||
CWMP_LOG(INFO, "New uci section %s added successfully", stype);
|
||||
}
|
||||
else
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (UCI_OK == add_section_helper(&conf_path, package, stype, s, &ptr))
|
||||
uci_commit(conf_path.uci_ctx, &ptr.p, false);
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_OK;
|
||||
}
|
||||
|
||||
int cwmp_uci_add_section_rename(char *package, char *stype, uci_config_paths uci_type , struct uci_section **s, char *name)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
*s = NULL;
|
||||
|
||||
if (package == NULL || stype == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (UCI_OK == add_section_helper(&conf_path, package, stype, s, &ptr)) {
|
||||
if (cwmp_uci_rename_section_by_section(*s, name, conf_path.uci_ctx) != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
uci_commit(conf_path.uci_ctx, &ptr.p, false);
|
||||
}
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return UCI_OK;
|
||||
}
|
||||
struct uci_section* get_section_by_section_name(char *package, char *stype, char* sname, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_section *s;
|
||||
|
||||
if (package == NULL || stype == NULL || sname == NULL)
|
||||
return NULL;
|
||||
cwmp_uci_foreach_sections(package, stype, uci_type, s) {
|
||||
if (strcmp(section_name(s), sname) == 0)
|
||||
|
||||
struct uci_paths conf_path;
|
||||
int ret = 0;
|
||||
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return NULL;
|
||||
|
||||
cwmp_uci_foreach_sections(package, stype, conf_path.uci_ctx, s) {
|
||||
if (strcmp(section_name(s), sname) == 0) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int cwmp_uci_rename_section_by_section(struct uci_section *s, char *value, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_ptr up = {0};
|
||||
|
||||
if (s == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (cwmp_uci_lookup_ptr_by_section(uci_save_conf_paths[uci_type].uci_ctx, &up, s, NULL, value) == -1)
|
||||
return UCI_ERR_PARSE;
|
||||
if (uci_rename(uci_save_conf_paths[uci_type].uci_ctx, &up) != UCI_OK)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
return UCI_OK;
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cwmp_uci_add_section_with_specific_name(char *package, char *stype, char *section_name, uci_config_paths uci_type)
|
||||
|
|
@ -632,10 +810,7 @@ int cwmp_uci_add_section_with_specific_name(char *package, char *stype, char *se
|
|||
return 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)
|
||||
return UCI_ERR_UNKNOWN;
|
||||
|
||||
return cwmp_uci_rename_section_by_section(s, section_name, uci_type);
|
||||
return cwmp_uci_add_section_rename(package, stype, uci_type, &s, section_name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -644,46 +819,67 @@ int cwmp_uci_add_section_with_specific_name(char *package, char *stype, char *se
|
|||
int uci_delete_value(char *path, int uci_type)
|
||||
{
|
||||
struct uci_ptr ptr;
|
||||
int ret = UCI_OK;
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
if (path == NULL)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, path, true) != UCI_OK)
|
||||
return CWMP_GEN_ERR;
|
||||
|
||||
ret = uci_delete(uci_save_conf_paths[uci_type].uci_ctx, &ptr);
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
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);
|
||||
if (uci_lookup_ptr(conf_path.uci_ctx, &ptr, path, true) != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
return ret;
|
||||
|
||||
int error = uci_delete(conf_path.uci_ctx, &ptr);
|
||||
|
||||
if (error == UCI_OK) {
|
||||
error = uci_save(conf_path.uci_ctx, ptr.p);
|
||||
} else {
|
||||
CWMP_LOG(ERROR, "UCI delete not succeed %s", path);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return error;
|
||||
}
|
||||
|
||||
int cwmp_uci_get_section_type(char *package, char *section, uci_config_paths uci_type, char **value)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
struct uci_paths conf_path;
|
||||
int ret = -1;
|
||||
|
||||
if (package == NULL || section == NULL) {
|
||||
*value = NULL;
|
||||
return UCI_ERR_NOTFOUND;
|
||||
}
|
||||
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, section, NULL, NULL)) {
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0)
|
||||
return UCI_ERR_NOTFOUND;
|
||||
|
||||
if (cwmp_uci_lookup_ptr(conf_path.uci_ctx, &ptr, package, section, NULL, NULL)) {
|
||||
*value = "";
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ptr.s) {
|
||||
*value = icwmp_strdup(ptr.s->type ? ptr.s->type : "");
|
||||
} else {
|
||||
*value = "";
|
||||
}
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
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)
|
||||
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, struct uci_context *uci_ctx, int walk)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
struct uci_element *e, *m;
|
||||
|
|
@ -693,7 +889,7 @@ struct uci_section *cwmp_uci_walk_section(char *package, char *stype, void *arg1
|
|||
struct uci_ptr ptr = { 0 };
|
||||
|
||||
if (walk == CWMP_GET_FIRST_SECTION) {
|
||||
if (cwmp_uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK)
|
||||
if (cwmp_uci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK)
|
||||
goto end;
|
||||
|
||||
list_section = &(ptr.p)->sections;
|
||||
|
|
@ -759,49 +955,43 @@ end:
|
|||
return s;
|
||||
}
|
||||
|
||||
int cwmp_commit_package(char *package, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_ptr ptr = { 0 };
|
||||
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, true) != UCI_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uci_commit(uci_save_conf_paths[uci_type].uci_ctx, &ptr.p, false) != UCI_OK) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_uci_import(char *package_name, const char *input_path, uci_config_paths uci_type)
|
||||
{
|
||||
struct uci_package *package = NULL;
|
||||
struct uci_element *e = NULL;
|
||||
int ret = CWMP_OK;
|
||||
int ret = CWMP_OK, err = -1;
|
||||
FILE *input = fopen(input_path, "r");
|
||||
if (!input)
|
||||
return -1;
|
||||
|
||||
if (uci_save_conf_paths[uci_type].uci_ctx == NULL)
|
||||
goto end;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (uci_import(uci_save_conf_paths[uci_type].uci_ctx, input, package_name, &package, (package_name != NULL)) != UCI_OK) {
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (err != 0) {
|
||||
fclose(input);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (uci_import(conf_path.uci_ctx, input, package_name, &package, (package_name != NULL)) != UCI_OK) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (uci_save_conf_paths[uci_type].uci_ctx == NULL) {
|
||||
if (conf_path.uci_ctx == NULL) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
uci_foreach_element(&uci_save_conf_paths[uci_type].uci_ctx->root, e)
|
||||
|
||||
uci_foreach_element(&conf_path.uci_ctx->root, 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(conf_path.uci_ctx, &p, true) != UCI_OK)
|
||||
ret = CWMP_GEN_ERR;
|
||||
}
|
||||
|
||||
end:
|
||||
fclose(input);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -813,16 +1003,25 @@ int cwmp_uci_export_package(char *package, const char *output_path, uci_config_p
|
|||
if (!out)
|
||||
return -1;
|
||||
|
||||
if (uci_lookup_ptr(uci_save_conf_paths[uci_type].uci_ctx, &ptr, package, true) != UCI_OK) {
|
||||
struct uci_paths conf_path;
|
||||
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0) {
|
||||
fclose(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (uci_lookup_ptr(conf_path.uci_ctx, &ptr, package, true) != UCI_OK) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (uci_export(uci_save_conf_paths[uci_type].uci_ctx, out, ptr.p, true) != UCI_OK)
|
||||
if (uci_export(conf_path.uci_ctx, out, ptr.p, true) != UCI_OK)
|
||||
ret = -1;
|
||||
|
||||
end:
|
||||
fclose(out);
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -830,10 +1029,20 @@ int cwmp_uci_export(const char *output_path, uci_config_paths uci_type)
|
|||
{
|
||||
char **configs = NULL;
|
||||
char **p;
|
||||
struct uci_paths conf_path;
|
||||
int ret = 0;
|
||||
|
||||
if (uci_list_configs(uci_save_conf_paths[uci_type].uci_ctx, &configs) != UCI_OK)
|
||||
ret = _init_uci_by_type(uci_type, &conf_path);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uci_list_configs(conf_path.uci_ctx, &configs) != UCI_OK) {
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cwmp_uci_exit(&conf_path);
|
||||
if (configs == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -350,7 +350,6 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *d
|
|||
bkp_session_save();
|
||||
if (strcmp(pdownload->file_type, FIRMWARE_UPGRADE_IMAGE_FILE_TYPE) == 0) {
|
||||
cwmp_uci_set_value("cwmp", "cpe", "exec_download", "1");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
if (cwmp_apply_firmware() != 0)
|
||||
error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED;
|
||||
|
||||
|
|
@ -363,7 +362,6 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *d
|
|||
//TODO Not Supported
|
||||
error = FAULT_CPE_NO_FAULT;
|
||||
} else if (strcmp(pdownload->file_type, VENDOR_CONFIG_FILE_TYPE) == 0) {
|
||||
cwmp_uci_init();
|
||||
int err = CWMP_OK;
|
||||
if (download_file_name != NULL) {
|
||||
char file_path[512];
|
||||
|
|
@ -375,7 +373,6 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *d
|
|||
remove(VENDOR_CONFIG_FILE);
|
||||
}
|
||||
|
||||
cwmp_uci_exit();
|
||||
if (err == CWMP_OK)
|
||||
error = FAULT_CPE_NO_FAULT;
|
||||
else if (err == CWMP_GEN_ERR)
|
||||
|
|
@ -399,8 +396,7 @@ int apply_downloaded_file(struct cwmp *cwmp, struct download *pdownload, char *d
|
|||
error = FAULT_CPE_INVALID_ARGUMENTS;
|
||||
|
||||
if ((error == FAULT_CPE_NO_FAULT) && (pdownload->file_type[0] == '1' || pdownload->file_type[0] == '3')) {
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "ParameterKey", pdownload->command_key ? pdownload->command_key : "");
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
cwmp_uci_set_value("cwmp", "cpe", "ParameterKey", pdownload->command_key ? pdownload->command_key : "");
|
||||
if (pdownload->file_type[0] == '3') {
|
||||
CWMP_LOG(INFO, "Download and apply new vendor config file is done successfully");
|
||||
cwmp_root_cause_transfer_complete(cwmp, ptransfer_complete);
|
||||
|
|
@ -793,7 +789,6 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
|
|||
|
||||
if (strcmp(apply_download->file_type, FIRMWARE_UPGRADE_IMAGE_FILE_TYPE) == 0) {
|
||||
cwmp_uci_set_value("cwmp", "cpe", "exec_download", "1");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
cwmp_apply_firmware();
|
||||
sleep(70);
|
||||
error = FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED;
|
||||
|
|
@ -801,9 +796,7 @@ void *thread_cwmp_rpc_cpe_apply_schedule_download(void *v)
|
|||
//TODO Not Supported
|
||||
error = FAULT_CPE_NO_FAULT;
|
||||
} else if (strcmp(apply_download->file_type, VENDOR_CONFIG_FILE_TYPE) == 0) {
|
||||
cwmp_uci_init();
|
||||
int err = cwmp_uci_import(NULL, VENDOR_CONFIG_FILE, UCI_STANDARD_CONFIG);
|
||||
cwmp_uci_exit();
|
||||
if (err == CWMP_OK)
|
||||
error = FAULT_CPE_NO_FAULT;
|
||||
else if (err == CWMP_GEN_ERR)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ supervisorctl status all
|
|||
echo "Clean cmocka"
|
||||
make clean -C test/cmocka/
|
||||
|
||||
if [ ! -f /etc/icwmpd/cwmp_notifications ]; then touch /etc/icwmpd/cwmp_notifications; fi
|
||||
|
||||
echo "Running unit test"
|
||||
make -C test/cmocka all
|
||||
check_ret $?
|
||||
|
|
|
|||
|
|
@ -115,11 +115,9 @@ void *thread_heartbeat_session(void *v __attribute__((unused)))
|
|||
if (file_exists(fc_cookies))
|
||||
remove(fc_cookies);
|
||||
|
||||
cwmp_uci_init();
|
||||
CWMP_LOG(INFO, "Start HEARTBEAT session");
|
||||
int error = cwmp_schedule_rpc(&cwmp_main, heartbeat_session);
|
||||
CWMP_LOG(INFO, "End HEARTBEAT session");
|
||||
cwmp_uci_exit();
|
||||
|
||||
if (thread_end) {
|
||||
event_remove_all_event_container(heartbeat_session, RPC_SEND);
|
||||
|
|
|
|||
3
http.c
3
http.c
|
|
@ -91,7 +91,6 @@ int http_client_init(struct cwmp *cwmp)
|
|||
int tmp = inet_pton(AF_INET, ip, buf);
|
||||
|
||||
cwmp_uci_set_value("cwmp", "acs", "ip_version", (tmp == 1) ? "4" : "6");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -239,7 +238,6 @@ int http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len, char **
|
|||
tmp = inet_pton(AF_INET6, ip, buf);
|
||||
|
||||
cwmp_uci_set_varstate_value("cwmp", "acs", tmp ? "ip6" : "ip", ip_acs);
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
|
||||
// Trigger firewall to reload firewall.cwmp
|
||||
struct blob_buf b = { 0 };
|
||||
|
|
@ -454,7 +452,6 @@ void http_server_init(void)
|
|||
snprintf(cr_port_str, 6, "%hu", cr_port);
|
||||
cr_port_str[5] = '\0';
|
||||
cwmp_uci_set_value("cwmp", "cpe", "port", cr_port_str);
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
connection_request_port_value_change(&cwmp_main, cr_port);
|
||||
CWMP_LOG(INFO, "Connection Request server initiated with the port: %d", cr_port);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@
|
|||
typedef enum uci_config_paths
|
||||
{
|
||||
UCI_STANDARD_CONFIG,
|
||||
UCI_VARSTATE_CONFIG
|
||||
UCI_VARSTATE_CONFIG,
|
||||
UCI_ETCICWMPD_CONFIG
|
||||
}uci_config_paths;
|
||||
|
||||
enum uci_val_type
|
||||
|
|
@ -115,22 +116,20 @@ struct uci_paths {
|
|||
struct uci_context *uci_ctx;
|
||||
};
|
||||
|
||||
extern struct uci_paths uci_save_conf_paths[];
|
||||
int cwmp_uci_init();
|
||||
void cwmp_uci_exit(void);
|
||||
void cwmp_uci_reinit(void);
|
||||
int cwmp_uci_standard_init(struct uci_paths *conf_path);
|
||||
int cwmp_uci_varstate_init(struct uci_paths *conf_path);
|
||||
int cwmp_uci_etccwmpd_init(struct uci_paths *conf_path);
|
||||
void cwmp_uci_exit(struct uci_paths *conf_path);
|
||||
int cwmp_uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);
|
||||
int cwmp_uci_get_cwmp_standard_option_value_list(char *package, char *section, char *option, struct uci_list **value);
|
||||
int cwmp_uci_get_cwmp_varstate_option_value_list(char *package, char *section, char *option, struct uci_list **value);
|
||||
int cwmp_uci_get_option_value_list(char *package, char *section, char *option, struct uci_context *uci_ctx, struct uci_list **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_set_value_by_path(char *cmd, char *value, struct uci_context *uci_ctx);
|
||||
int cwmp_uci_set_value_by_path(char *path, char *value);
|
||||
int cwmp_uci_set_varstate_value_by_path(char *path, char *value);
|
||||
int uci_get_value(char *cmd, char **value);
|
||||
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);
|
||||
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, struct uci_context *uci_ctx, int walk);
|
||||
int cwmp_uci_get_value_by_section_string(struct uci_section *s, char *option, char **value);
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, uci_config_paths uci_type, char **value);
|
||||
int cwmp_commit_package(char *package, uci_config_paths uci_type);
|
||||
int cwmp_uci_get_option_value_string(char *package, char *section, char *option, struct uci_context *uci_ctx, char **value);
|
||||
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(const char *output_path, uci_config_paths uci_type);
|
||||
|
|
@ -147,12 +146,12 @@ void cwmp_uci_list_init(struct uci_list *ptr);
|
|||
void cwmp_uci_list_add(struct uci_list *head, struct uci_list *ptr);
|
||||
struct uci_section* get_section_by_section_name(char *package, char *stype, char* sname, uci_config_paths uci_type);
|
||||
|
||||
#define cwmp_uci_path_foreach_option_eq(package, stype, option, val, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, NULL, UCI_STANDARD_CONFIG, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, section, UCI_STANDARD_CONFIG, CWMP_GET_NEXT_SECTION))
|
||||
#define cwmp_uci_path_foreach_option_eq(package, stype, option, val, uci_ctx, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, NULL, uci_ctx, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, option, val, CWMP_CMP_OPTION_EQUAL, NULL, section, uci_ctx, CWMP_GET_NEXT_SECTION))
|
||||
|
||||
#define cwmp_uci_foreach_sections(package, stype, uci_type, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, NULL, uci_type, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, section, uci_type, CWMP_GET_NEXT_SECTION))
|
||||
#define cwmp_uci_foreach_sections(package, stype, uci_ctx, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, NULL, uci_ctx, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, section, uci_ctx, CWMP_GET_NEXT_SECTION))
|
||||
|
||||
#define cwmp_uci_foreach_varstate_sections(package, stype, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, NULL, UCI_VARSTATE_CONFIG, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, section, UCI_VARSTATE_CONFIG, CWMP_GET_NEXT_SECTION))
|
||||
#define cwmp_uci_foreach_varstate_sections(package, stype, uci_ctx, section) \
|
||||
for (section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, NULL, uci_ctx, CWMP_GET_FIRST_SECTION); section != NULL; section = cwmp_uci_walk_section(package, stype, NULL, NULL, CWMP_CMP_SECTION, NULL, section, uci_ctx, CWMP_GET_NEXT_SECTION))
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#define CWMP_NOTIFICATIONS_PACKAGE "/etc/icwmpd/cwmp_notifications"
|
||||
|
||||
enum NOTIFICATION_STATUS
|
||||
{
|
||||
NOTIF_NONE = 0,
|
||||
|
|
@ -48,6 +50,7 @@ extern struct list_head list_param_obj_notify;
|
|||
#define DM_ENABLED_NOTIFY "/var/run/icwmpd/dm_enabled_notify"
|
||||
#define NOTIFY_MARKER "/etc/icwmpd/icwmpd_notify_import_marker"
|
||||
#define RUN_NOTIFY_MARKER "/var/run/icwmpd/icwmpd_notify_import_marker"
|
||||
int create_cwmp_notifications_file();
|
||||
void ubus_check_value_change_callback(struct ubus_request *req, int type, struct blob_attr *msg);
|
||||
void cwmp_update_enabled_notify_file(void);
|
||||
int check_value_change(void);
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
|||
FREE(cwmp_main.conf.ip);
|
||||
cwmp_main.conf.ip = strdup(if_addr);
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "ip", cwmp_main.conf.ip);
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
connection_request_ip_value_change(&cwmp_main, IPv4);
|
||||
break;
|
||||
}
|
||||
|
|
@ -142,7 +141,6 @@ static void freecwmp_netlink_interface(struct nlmsghdr *nlh)
|
|||
FREE(cwmp_main.conf.ipv6);
|
||||
cwmp_main.conf.ipv6 = strdup(pradd_v6);
|
||||
cwmp_uci_set_varstate_value("cwmp", "cpe", "ipv6", cwmp_main.conf.ip);
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
connection_request_ip_value_change(&cwmp_main, IPv6);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,18 @@ char *check_valid_parameter_path(char *parameter_name)
|
|||
return error;
|
||||
}
|
||||
|
||||
int create_cwmp_notifications_file()
|
||||
{
|
||||
if (!file_exists(CWMP_NOTIFICATIONS_PACKAGE)) {
|
||||
FILE *fptr = fopen(CWMP_NOTIFICATIONS_PACKAGE, "w+");
|
||||
if (fptr)
|
||||
fclose(fptr);
|
||||
else
|
||||
return CWMP_GEN_ERR;
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* SetParameterAttributes
|
||||
*/
|
||||
|
|
@ -98,20 +110,18 @@ int add_uci_option_notification(char *parameter_name, int notification)
|
|||
{
|
||||
char *notification_type = NULL;
|
||||
struct uci_section *s = NULL;
|
||||
int ret = 0;
|
||||
int ret;
|
||||
|
||||
ret = cwmp_uci_get_section_type("cwmp", "@notifications[0]", UCI_VARSTATE_CONFIG, ¬ification_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_get_section_type("cwmp_notifications", "@notifications[0]", UCI_ETCICWMPD_CONFIG, ¬ification_type);
|
||||
if (notification_type == NULL || notification_type[0] == '\0' || ret != 0) {
|
||||
cwmp_uci_add_section("cwmp_notifications", "notifications", UCI_ETCICWMPD_CONFIG, &s);
|
||||
}
|
||||
ret = cwmp_uci_add_list_value("cwmp", "@notifications[0]", notifications[notification], parameter_name, UCI_VARSTATE_CONFIG);
|
||||
if (ret != UCI_OK)
|
||||
ret = cwmp_uci_add_list_value("cwmp_notifications", "@notifications[0]", notifications[notification], parameter_name, UCI_ETCICWMPD_CONFIG);
|
||||
if (ret != UCI_OK) {
|
||||
CWMP_LOG(INFO, "Failed to add notification");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -120,22 +130,34 @@ bool check_parent_with_different_notification(char *parameter_name, int notifica
|
|||
struct uci_list *list_notif = NULL;
|
||||
struct uci_element *e = NULL;
|
||||
int i;
|
||||
bool ret = false;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_etccwmpd_init(&conf_path) != 0)
|
||||
return ret;
|
||||
|
||||
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);
|
||||
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], conf_path.uci_ctx, &list_notif);
|
||||
if (list_notif) {
|
||||
uci_foreach_element(list_notif, e) {
|
||||
if (parameter_is_subobject_of_parameter(e->name, parameter_name))
|
||||
return true;
|
||||
if (parameter_is_subobject_of_parameter(e->name, parameter_name)) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (option_type == UCI_TYPE_STRING)
|
||||
cwmp_free_uci_list(list_notif);
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool update_notifications_list(char *parameter_name, int notification)
|
||||
|
|
@ -145,28 +167,34 @@ bool update_notifications_list(char *parameter_name, int notification)
|
|||
int i;
|
||||
char *ename = NULL;
|
||||
bool update_ret = true;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (parameter_name == NULL)
|
||||
parameter_name = "Device.";
|
||||
|
||||
if (cwmp_uci_etccwmpd_init(&conf_path) != 0)
|
||||
return update_ret;
|
||||
|
||||
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);
|
||||
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], conf_path.uci_ctx, &list_notif);
|
||||
if (list_notif) {
|
||||
uci_foreach_element_safe(list_notif, tmp, e) {
|
||||
if (e->name == NULL)
|
||||
continue;
|
||||
ename = strdup(e->name);
|
||||
if ((strcmp(parameter_name, e->name) == 0 && (i != notification)) || parameter_is_subobject_of_parameter(parameter_name, e->name))
|
||||
cwmp_uci_del_list_value("cwmp", "@notifications[0]", notifications[i], e->name, UCI_VARSTATE_CONFIG);
|
||||
if (ename && (strcmp(parameter_name, ename) == 0 || parameter_is_subobject_of_parameter(ename, parameter_name) ) && (i == notification))
|
||||
cwmp_uci_del_list_value("cwmp_notifications", "@notifications[0]", notifications[i], e->name, UCI_ETCICWMPD_CONFIG);
|
||||
if (ename && (strcmp(parameter_name, ename) == 0 || parameter_is_subobject_of_parameter(ename, parameter_name) ) && (i == notification)) {
|
||||
update_ret = false;
|
||||
}
|
||||
FREE(ename);
|
||||
}
|
||||
cwmp_commit_package("cwmp", UCI_VARSTATE_CONFIG);
|
||||
}
|
||||
if (option_type == UCI_TYPE_STRING)
|
||||
cwmp_free_uci_list(list_notif);
|
||||
}
|
||||
cwmp_uci_exit(&conf_path);
|
||||
|
||||
if (update_ret && notification == 0 && !check_parent_with_different_notification(parameter_name, 0))
|
||||
update_ret = false;
|
||||
|
|
@ -202,13 +230,18 @@ int get_parameter_family_notifications(char *parameter_name, struct list_head *c
|
|||
struct uci_element *e = NULL;
|
||||
int i, notif_ret = 0;
|
||||
char *parent_param = NULL;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (parameter_name == NULL)
|
||||
parameter_name = "Device.";
|
||||
|
||||
if (cwmp_uci_etccwmpd_init(&conf_path) != 0)
|
||||
return notif_ret;
|
||||
|
||||
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);
|
||||
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], conf_path.uci_ctx, &list_notif);
|
||||
if (list_notif) {
|
||||
uci_foreach_element(list_notif, e) {
|
||||
if (parameter_is_subobject_of_parameter(parameter_name, e->name)) {
|
||||
|
|
@ -225,6 +258,7 @@ int get_parameter_family_notifications(char *parameter_name, struct list_head *c
|
|||
if (option_type == UCI_TYPE_STRING)
|
||||
cwmp_free_uci_list(list_notif);
|
||||
}
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return notif_ret;
|
||||
}
|
||||
|
||||
|
|
@ -327,11 +361,14 @@ void create_list_param_obj_notify()
|
|||
struct uci_list *list_notif = NULL;
|
||||
struct uci_element *e = NULL;
|
||||
int i;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_etccwmpd_init(&conf_path) != 0)
|
||||
return;
|
||||
|
||||
cwmp_uci_reinit();
|
||||
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);
|
||||
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications[i], conf_path.uci_ctx, &list_notif);
|
||||
if (list_notif) {
|
||||
uci_foreach_element(list_notif, e) {
|
||||
add_dm_parameter_to_list(&list_param_obj_notify, e->name, "", "", i, false);
|
||||
|
|
@ -340,6 +377,7 @@ void create_list_param_obj_notify()
|
|||
cwmp_free_uci_list(list_notif);
|
||||
}
|
||||
}
|
||||
cwmp_uci_exit(&conf_path);
|
||||
}
|
||||
|
||||
char* update_list_param_leaf_notify_with_sub_parameter_list(struct list_head *list_param_leaf_notify, char* parent_parameter, int parent_notification, bool parent_forced_notif, void (*update_notify_file_line_arg)(FILE *notify_file, char *param_name, char *param_type, char *param_value, int notification), FILE* notify_file_arg)
|
||||
|
|
|
|||
2
reboot.c
2
reboot.c
|
|
@ -26,7 +26,6 @@ static void *thread_delay_reboot(void *arg)
|
|||
CWMP_LOG(INFO, "The device will reboot after %d seconds", cwmp->conf.delay_reboot);
|
||||
sleep(cwmp->conf.delay_reboot);
|
||||
cwmp_uci_set_value("cwmp", "cpe", "delay_reboot", "-1");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
/* check if the session is running before calling reboot method */
|
||||
/* if the session is in progress, wait until the end of the session */
|
||||
/* else calling reboot method */
|
||||
|
|
@ -68,7 +67,6 @@ static void *thread_schedule_reboot(void *arg)
|
|||
CWMP_LOG(INFO, "The device will reboot after %ld seconds", remaining_time);
|
||||
sleep(remaining_time);
|
||||
cwmp_uci_set_value("cwmp", "cpe", "schedule_reboot", "0001-01-01T00:00:00Z");
|
||||
cwmp_commit_package("cwmp", UCI_STANDARD_CONFIG);
|
||||
|
||||
/* check if the session is running before calling reboot method */
|
||||
/* if the session is in progress, wait until the end of the session */
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ static void restore_output()
|
|||
|
||||
static int cwmp_cli_unit_tests_init(void **state)
|
||||
{
|
||||
cwmp_uci_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +58,6 @@ static int cwmp_cli_unit_tests_clean(void **state)
|
|||
icwmp_cleanmem();
|
||||
FREE(add_instance);
|
||||
icwmp_free_list_services();
|
||||
cwmp_uci_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ LIST_HEAD(parameters_list);
|
|||
|
||||
static int cwmp_notifications_unit_tests_init(void **state)
|
||||
{
|
||||
cwmp_uci_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +33,6 @@ static int cwmp_notifications_unit_tests_clean(void **state)
|
|||
{
|
||||
icwmp_cleanmem();
|
||||
cwmp_free_all_dm_parameter_list(¶meters_list);
|
||||
cwmp_uci_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -95,9 +93,14 @@ static int get_parameter_notification_from_notifications_uci_list(char *paramete
|
|||
int i, notification = 0;
|
||||
struct uci_list *list_notif;
|
||||
struct uci_element *e;
|
||||
struct uci_paths conf_path;
|
||||
|
||||
if (cwmp_uci_etccwmpd_init(&conf_path) != 0)
|
||||
return -1;
|
||||
|
||||
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);
|
||||
option_type = cwmp_uci_get_option_value_list("cwmp_notifications", "@notifications[0]", notifications_test[i], conf_path.uci_ctx, &list_notif);
|
||||
if (list_notif) {
|
||||
uci_foreach_element(list_notif, e) {
|
||||
if (strcmp(e->name, parameter_name) == 0) {
|
||||
|
|
@ -111,6 +114,7 @@ static int get_parameter_notification_from_notifications_uci_list(char *paramete
|
|||
if(notification > 0)
|
||||
break;
|
||||
}
|
||||
cwmp_uci_exit(&conf_path);
|
||||
return notification;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ static int soap_unit_tests_init(void **state)
|
|||
cwmp_test = &cwmp_main_test;
|
||||
INIT_LIST_HEAD(&(cwmp_test->head_session_queue));
|
||||
memcpy(&(cwmp_test->env), &cwmp_test, sizeof(struct env));
|
||||
cwmp_uci_init();
|
||||
log_set_severity_idx("DEBUG");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -117,7 +116,6 @@ static int soap_unit_tests_clean(void **state)
|
|||
icwmp_free_list_services();
|
||||
clean_name_space();
|
||||
clean_config();
|
||||
cwmp_uci_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* Copyright (C) 2013-2021 iopsys Software Solutions AB
|
||||
* Author Omar Kallel <omar.kallel@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
|
@ -24,14 +24,12 @@ static struct uci_list *list = NULL;
|
|||
|
||||
static int cwmp_uci_unit_tests_init(void **state)
|
||||
{
|
||||
cwmp_uci_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cwmp_uci_unit_tests_clean(void **state)
|
||||
{
|
||||
icwmp_cleanmem();
|
||||
cwmp_uci_exit();
|
||||
if (list != NULL)
|
||||
cwmp_free_uci_list(list);
|
||||
return 0;
|
||||
|
|
@ -59,15 +57,15 @@ static void cwmp_uci_get_tests(void **state)
|
|||
assert_int_equal(error, UCI_OK);
|
||||
assert_null(value);
|
||||
|
||||
error = cwmp_uci_get_option_value_string("cwmp", "acs", "dhcp_url", UCI_VARSTATE_CONFIG, &value);
|
||||
error = uci_get_state_value(UCI_DHCP_ACS_URL, &value);
|
||||
assert_int_equal(error, UCI_OK);
|
||||
assert_string_equal(value, "http://192.168.103.160:8080/openacs/acs");
|
||||
|
||||
error = cwmp_uci_get_option_value_string("cwmp", "cpe", "userid", UCI_STANDARD_CONFIG, &value);
|
||||
error = uci_get_value(UCI_CPE_USERID_PATH, &value);
|
||||
assert_int_equal(error, UCI_OK);
|
||||
assert_string_equal(value, "iopsys");
|
||||
|
||||
error = cwmp_uci_get_option_value_string("cwmp", "wrong_section", "wrong_option", UCI_STANDARD_CONFIG, &value);
|
||||
error = cwmp_uci_get_option_value_string("cwmp.wrong_section.wrong_option", &value);
|
||||
assert_int_equal(error, UCI_ERR_NOTFOUND);
|
||||
assert_null(value);
|
||||
|
||||
|
|
@ -215,3 +213,8 @@ int icwmp_uci_test(void)
|
|||
|
||||
return cmocka_run_group_tests(tests, cwmp_uci_unit_tests_init, cwmp_uci_unit_tests_clean);
|
||||
}
|
||||
#endif
|
||||
int icwmp_uci_test(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ exec_cmd cp test/files/etc/icwmpd/custom_notification* /etc/icwmpd
|
|||
# Test a valid custom notification json file
|
||||
#
|
||||
rm /var/log/icwmpd.log
|
||||
uci -c /var/state delete cwmp.@notifications[0]
|
||||
uci -c /var/state commit cwmp
|
||||
uci -c /etc/icwmpd delete cwmp_notifications.@notifications[0]
|
||||
uci -c /etc/icwmpd commit cwmp_notifications
|
||||
|
||||
exec_cmd uci set cwmp.cpe.custom_notify_json="/etc/icwmpd/custom_notification_valid.json"
|
||||
uci commit cwmp
|
||||
|
|
@ -29,12 +29,12 @@ supervisorctl stop icwmpd
|
|||
|
||||
check_valgrind_xml
|
||||
|
||||
notif1=`uci -c /var/state get cwmp.@notifications[0].active | grep "Device.Users."`
|
||||
notif1=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].active | grep "Device.Users."`
|
||||
if [[ $notif1 != *"Device.Users."* ]]; then
|
||||
echo "FAIL: active notifications list doesn't contain Device.Users. parameter"
|
||||
exit 1
|
||||
fi
|
||||
notif2=`uci -c /var/state get cwmp.@notifications[0].passive | grep "Device.WiFi.SSID.1.SSID"`
|
||||
notif2=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].passive | grep "Device.WiFi.SSID.1.SSID"`
|
||||
if [[ $notif2 != *"Device.WiFi.SSID.1.SSID"* ]]; then
|
||||
echo "FAIL: active notifications list doesn't contain Device.WiFi.SSID.1.SSID parameter"
|
||||
exit 1
|
||||
|
|
@ -48,8 +48,8 @@ echo "PASS test valid custom notification json file"
|
|||
# Test custom notification invalid json file
|
||||
#
|
||||
rm /var/log/icwmpd.log
|
||||
uci -c /var/state delete cwmp.@notifications[0]
|
||||
uci -c /var/state commit cwmp
|
||||
uci -c /etc/icwmpd delete cwmp_notifications.@notifications[0]
|
||||
uci -c /etc/icwmpd commit cwmp_notifications
|
||||
|
||||
exec_cmd uci set cwmp.cpe.custom_notify_json="/etc/icwmpd/custom_notification_invalid_json.json"
|
||||
uci commit cwmp
|
||||
|
|
@ -62,12 +62,12 @@ supervisorctl stop icwmpd
|
|||
|
||||
check_valgrind_xml
|
||||
|
||||
notif1=`uci -c /var/state get cwmp.@notifications[0].active | grep "Device.Users."`
|
||||
notif1=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].active | grep "Device.Users."`
|
||||
if [[ $notif1 == *"Device.Users."* ]]; then
|
||||
echo "FAIL: the json file is invalid, the active notifcation list shouldn't contain Device.Users. parameter"
|
||||
exit 1
|
||||
fi
|
||||
notif2=`uci -c /var/state get cwmp.@notifications[0].passive | grep "Device.WiFi.SSID.1.SSID"`
|
||||
notif2=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].passive | grep "Device.WiFi.SSID.1.SSID"`
|
||||
if [[ $notif2 == *"Device.WiFi.SSID.1.SSID"* ]]; then
|
||||
echo "FAIL: the json file is invalid, the active notifcation list shouldn't contain Device.WiFi.SSID.1.SSID parameter"
|
||||
exit 1
|
||||
|
|
@ -87,8 +87,8 @@ rm /etc/icwmpd/icwmpd_notify
|
|||
# Test custom notification json file containing forced active notification
|
||||
#
|
||||
rm /var/log/icwmpd.log
|
||||
uci -c /var/state delete cwmp.@notifications[0]
|
||||
uci -c /var/state commit cwmp
|
||||
uci -c /etc/icwmpd delete cwmp_notifications.@notifications[0]
|
||||
uci -c /etc/icwmpd commit cwmp_notifications
|
||||
|
||||
exec_cmd uci set cwmp.cpe.custom_notify_json="/etc/icwmpd/custom_notification_forced.json"
|
||||
uci commit cwmp
|
||||
|
|
@ -100,12 +100,12 @@ supervisorctl stop icwmpd
|
|||
|
||||
check_valgrind_xml
|
||||
|
||||
notif1=`uci -c /var/state get cwmp.@notifications[0].active | grep "Device.Users."`
|
||||
notif1=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].active | grep "Device.Users."`
|
||||
if [[ $notif1 != *"Device.Users."* ]]; then
|
||||
echo "FAIL: active notifications list doesn't contain Device.Users. parameter"
|
||||
exit 1
|
||||
fi
|
||||
notif2=`uci -c /var/state get cwmp.@notifications[0].passive | grep "Device.DeviceInfo.ProvisioningCode"`
|
||||
notif2=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].passive | grep "Device.DeviceInfo.ProvisioningCode"`
|
||||
if [[ $notif2 == *"Device.DeviceInfo.ProvisioningCode"* ]]; then
|
||||
echo "FAIL: passive notifications list contains Device.DeviceInfo.ProvisioningCode while it's a forced active notification paramter"
|
||||
exit 1
|
||||
|
|
@ -125,8 +125,8 @@ rm /etc/icwmpd/icwmpd_notify
|
|||
# Test custom notification json file containing invalid parameter path
|
||||
#
|
||||
rm /var/log/icwmpd.log
|
||||
uci -c /var/state delete cwmp.@notifications[0]
|
||||
uci -c /var/state commit cwmp
|
||||
uci -c /etc/icwmpd delete cwmp_notifications.@notifications[0]
|
||||
uci -c /etc/icwmpd commit cwmp_notifications
|
||||
|
||||
exec_cmd uci set cwmp.cpe.custom_notify_json="/etc/icwmpd/custom_notification_invalid_parameter.json"
|
||||
uci commit cwmp
|
||||
|
|
@ -138,12 +138,12 @@ supervisorctl stop icwmpd
|
|||
|
||||
check_valgrind_xml
|
||||
|
||||
notif1=`uci -c /var/state get cwmp.@notifications[0].active | grep "Device.Users."`
|
||||
notif1=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].active | grep "Device.Users."`
|
||||
if [[ $notif1 != *"Device.Users."* ]]; then
|
||||
echo "FAIL: active notifications list doesn't contain Device.Users. parameter"
|
||||
exit 1
|
||||
fi
|
||||
notif2=`uci -c /var/state get cwmp.@notifications[0].passive | grep "Device.WiFi.SSID.1.SD"`
|
||||
notif2=`uci -c /etc/icwmpd get cwmp_notifications.@notifications[0].passive | grep "Device.WiFi.SSID.1.SD"`
|
||||
if [[ $notif2 == *"Device.WiFi.SSID.1.SD"* ]]; then
|
||||
echo "FAIL: passive notifications list contains Device.WiFi.SSID.1.SD while it's a wrong parameter path"
|
||||
exit 1
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ static int reload_cmd(struct blob_buf *b)
|
|||
} else {
|
||||
int error = CWMP_OK;
|
||||
pthread_mutex_lock(&(cwmp_main.mutex_session_queue));
|
||||
cwmp_uci_reinit();
|
||||
error = cwmp_apply_acs_changes();
|
||||
pthread_mutex_unlock(&(cwmp_main.mutex_session_queue));
|
||||
if (error != CWMP_OK) {
|
||||
|
|
|
|||
4
upload.c
4
upload.c
|
|
@ -137,9 +137,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
|
|||
}
|
||||
if (pupload->file_type[0] == '1') {
|
||||
snprintf(file_path, sizeof(file_path), "/tmp/all_configs");
|
||||
cwmp_uci_init();
|
||||
cwmp_uci_export(file_path, UCI_STANDARD_CONFIG);
|
||||
cwmp_uci_exit();
|
||||
} else if (pupload->file_type[0] == '2') {
|
||||
snprintf(file_path, sizeof(file_path), "/tmp/syslog");
|
||||
copy("/var/log/syslog", file_path);
|
||||
|
|
@ -147,9 +145,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
|
|||
lookup_vcf_name(pupload->f_instance, &name);
|
||||
if (name && strlen(name) > 0) {
|
||||
snprintf(file_path, sizeof(file_path), "/tmp/%s", name);
|
||||
cwmp_uci_init();
|
||||
cwmp_uci_export_package(name, file_path, UCI_STANDARD_CONFIG);
|
||||
cwmp_uci_exit();
|
||||
FREE(name);
|
||||
} else {
|
||||
error = FAULT_CPE_UPLOAD_FAILURE;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue