diff --git a/config.c b/config.c index dcf8cde..74b4334 100644 --- a/config.c +++ b/config.c @@ -1031,6 +1031,84 @@ int get_lwn_config(struct config *conf) return CWMP_OK; } +static inline bool cwmp_check_section_name(const char *str, bool name) +{ + if (!*str) + return false; + for (; *str; str++) { + unsigned char c = *str; + if (isalnum(c) || c == '_') + continue; + if (name || (c < 33) || (c > 126)) + return false; + } + return true; +} + +int cwmp_uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value) +{ + /*value*/ + ptr->value = value; + + /*package*/ + if (!package) + return -1; + ptr->package = package; + + /*section*/ + if (!section || !section[0]) { + ptr->target = UCI_TYPE_PACKAGE; + goto lookup; + } + ptr->section = section; + if (ptr->section && !cwmp_check_section_name(ptr->section , true)) + ptr->flags |= UCI_LOOKUP_EXTENDED; + + /*option*/ + if (!option || !option[0]) { + ptr->target = UCI_TYPE_SECTION; + goto lookup; + } + ptr->target = UCI_TYPE_OPTION; + ptr->option = option; + +lookup: + if (uci_lookup_ptr(ctx, ptr, NULL, true) != UCI_OK || !UCI_LOOKUP_COMPLETE) { + return -1; + } + return 0; +} + +char* cwmp_db_get_value_string(char *package, char *section, char *option) +{ + struct uci_context *uci_ctx = uci_alloc_context(); + + struct uci_option *o = NULL; + struct uci_element *e; + struct uci_ptr ptr = {0}; + + uci_ctx->confdir = "/lib/db/config"; + + if (cwmp_uci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) + return ""; + + e = ptr.last; + switch(e->type) { + case UCI_TYPE_OPTION: + o = ptr.o; + break; + default: + break; + } + + + if (o) + return o->v.string ? o->v.string : ""; + else { + return ""; + } +} + int global_env_init (int argc, char** argv, struct env *env) { unsigned char command_input = 0; @@ -1207,14 +1285,11 @@ int save_acs_bkp_config(struct cwmp *cwmp) } int cwmp_get_deviceid(struct cwmp *cwmp) { - struct dmctx dmctx = {0}; - cwmp_dm_ctx_init(cwmp, &dmctx); - cwmp->deviceid.manufacturer = strdup(get_deviceid_manufacturer()); //TODO free - cwmp->deviceid.serialnumber = strdup(get_deviceid_serialnumber()); - cwmp->deviceid.productclass = strdup(get_deviceid_productclass()); - cwmp->deviceid.oui = strdup(get_deviceid_manufactureroui()); - cwmp->deviceid.softwareversion = strdup(get_softwareversion()); - cwmp_dm_ctx_clean(&dmctx); + 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")); return CWMP_OK; }