Fix db get of deviceid uci options

This commit is contained in:
Omar Kallel 2021-01-19 17:23:31 +01:00
parent fc7687de2d
commit 0652f760cd
4 changed files with 15 additions and 5 deletions

View file

@ -9,6 +9,7 @@
*
*/
#include <getopt.h>
#include <sys/stat.h>
#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));
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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) \