diff --git a/common.c b/common.c index 0076d89..11e5a03 100644 --- a/common.c +++ b/common.c @@ -9,6 +9,7 @@ * */ #include +#include #include "common.h" @@ -191,3 +192,10 @@ int cwmp_asprintf(char **s, const char *format, ...) return -1; return 0; } + +bool folder_exists(const char *path) +{ + struct stat folder_stat; + + return (stat(path, &folder_stat) == 0 && S_ISDIR(folder_stat.st_mode)); +} diff --git a/config.c b/config.c index 59e0ead..9482d1c 100644 --- a/config.c +++ b/config.c @@ -517,11 +517,16 @@ int global_conf_init(struct config *conf) int cwmp_get_deviceid(struct cwmp *cwmp) { + if (folder_exists("/lib/db/config")) + cwmp_uci_init(UCI_DB_CONFIG); + else + cwmp_uci_init(UCI_BOARD_DB_CONFIG); cwmp->deviceid.manufacturer = strdup(cwmp_db_get_value_string("device", "deviceinfo", "Manufacturer")); //TODO free cwmp->deviceid.serialnumber = strdup(cwmp_db_get_value_string("device", "deviceinfo", "SerialNumber")); cwmp->deviceid.productclass = strdup(cwmp_db_get_value_string("device", "deviceinfo", "ProductClass")); cwmp->deviceid.oui = strdup(cwmp_db_get_value_string("device", "deviceinfo", "ManufacturerOUI")); cwmp->deviceid.softwareversion = strdup(cwmp_db_get_value_string("device", "deviceinfo", "SoftwareVersion")); + cwmp_uci_exit(); return CWMP_OK; } diff --git a/cwmp_uci.c b/cwmp_uci.c index 706e0a3..67d3c70 100644 --- a/cwmp_uci.c +++ b/cwmp_uci.c @@ -141,15 +141,11 @@ int cwmp_uci_get_option_value_string(char *package, char *section, char *option, char *cwmp_db_get_value_string(char *package, char *section, char *option) { - struct uci_context *ucictx = uci_alloc_context(); - struct uci_option *o = NULL; struct uci_element *e; struct uci_ptr ptr = { 0 }; - ucictx->confdir = LIB_DB_CONFIG; - - if (cwmp_uci_lookup_ptr(ucictx, &ptr, package, section, option, NULL)) + if (cwmp_uci_lookup_ptr(cwmp_uci_ctx, &ptr, package, section, option, NULL)) return ""; e = ptr.last; diff --git a/inc/common.h b/inc/common.h index 1788a3b..4f1ddfa 100644 --- a/inc/common.h +++ b/inc/common.h @@ -449,6 +449,7 @@ void cwmp_add_list_param_value(char *param, char *value, struct list_head *list_ void cwmp_del_list_param_value(struct cwmp_param_value *param_value); void cwmp_free_all_list_param_value(struct list_head *list_param_value); int cwmp_asprintf(char **s, const char *format, ...); +bool folder_exists(const char *path); #ifndef FREE #define FREE(x) \