From ff529fe94eed97b1b7b9e702fa64aded5e6bbbaf Mon Sep 17 00:00:00 2001 From: Anis Ellouze Date: Mon, 31 Aug 2015 11:41:43 +0100 Subject: [PATCH] support linker in the param value get (when value is another param path) --- config.c | 6 ++-- dm/dmcwmp.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++- dm/dmcwmp.h | 4 +++ dm/dmentry.c | 42 ++++++++++++++++++++++++++ dm/dmentry.h | 2 ++ 5 files changed, 134 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index 6f6a6ec..5475eea 100644 --- a/config.c +++ b/config.c @@ -731,13 +731,11 @@ int save_acs_bkp_config(struct cwmp *cwmp) } int cwmp_get_deviceid(struct cwmp *cwmp) { - dm_global_init(); 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()); - dm_global_clean(); return CWMP_OK; } @@ -774,7 +772,10 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp) { return error; } + dm_global_init(); cwmp_get_deviceid(cwmp); + dm_entry_load_enabled_notify(); + dm_global_clean(); return CWMP_OK; } @@ -787,5 +788,6 @@ int cwmp_config_reload(struct cwmp *cwmp) { return error; } + dm_entry_load_enabled_notify(); return CWMP_OK; } diff --git a/dm/dmcwmp.c b/dm/dmcwmp.c index cc9d410..1bd358d 100644 --- a/dm/dmcwmp.c +++ b/dm/dmcwmp.c @@ -60,6 +60,10 @@ static int set_notification_check_obj(DMOBJECT_API_ARGS); static int set_notification_check_param(DMPARAM_API_ARGS); static int enabled_notify_check_obj(DMOBJECT_API_ARGS); static int enabled_notify_check_param(DMPARAM_API_ARGS); +static int get_linker_check_obj(DMOBJECT_API_ARGS); +static int get_linker_check_param(DMOBJECT_API_ARGS); +static int get_linker_value_check_obj(DMOBJECT_API_ARGS); +static int get_linker_value_check_param(DMOBJECT_API_ARGS); LIST_HEAD(list_enabled_notify); @@ -997,7 +1001,7 @@ int dm_entry_enabled_notify(struct dmctx *ctx) ctx->method_param = &enabled_notify_check_param; for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { if (!prefix_methods[i].enable) continue; - prefix_methods[i].method(ctx); + prefix_methods[i].method(ctx); } return 0; } @@ -1031,3 +1035,80 @@ static int enabled_notify_check_param(DMPARAM_API_ARGS) dmfree(full_param); return 0; } + +/****************** + * get linker param + *****************/ +int dm_entry_get_linker(struct dmctx *ctx) +{ + int i; + ctx->method_obj = &get_linker_check_obj; + ctx->method_param = &get_linker_check_param; + for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { + if (!prefix_methods[i].enable) continue; + int ret = prefix_methods[i].method(ctx); + if (ctx->stop) + return ret; + } + return 0; +} + +static int get_linker_check_obj(DMOBJECT_API_ARGS) +{ + if (linker && strcmp(linker, ctx->linker) == 0) { + ctx->linker_param = dmstrdup(ctx->current_obj); + ctx->stop = true; + return 0; + } + return FAULT_9005; +} + +static int get_linker_check_param(DMPARAM_API_ARGS) +{ + if (linker && strcmp(linker, ctx->linker) == 0) { + dmastrcat(&(ctx->linker_param), ctx->current_obj, lastname); + ctx->stop = true; + return 0; + } + return FAULT_9005; +} + +/****************** + * get linker value + *****************/ +int dm_entry_get_linker_value(struct dmctx *ctx) +{ + int i; + ctx->method_obj = &get_linker_value_check_obj; + ctx->method_param = &get_linker_value_check_param; + for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { + if (!prefix_methods[i].enable) continue; + int ret = prefix_methods[i].method(ctx); + if (ctx->stop) + return ret; + } + return 0; +} + +static int get_linker_value_check_obj(DMOBJECT_API_ARGS) +{ + if (linker && strcmp(ctx->current_obj, ctx->in_param) == 0) { + ctx->linker = dmstrdup(linker); + ctx->stop = true; + return 0; + } + return FAULT_9005; +} + +static int get_linker_value_check_param(DMPARAM_API_ARGS) +{ + char *refparam; + dmastrcat(&refparam, ctx->current_obj, lastname); + if (linker && strcmp(refparam, ctx->in_param) == 0) { + ctx->linker = dmstrdup(linker); + ctx->stop = true; + return 0; + } + return FAULT_9005; +} + diff --git a/dm/dmcwmp.h b/dm/dmcwmp.h index 38c02a7..4e35aa2 100644 --- a/dm/dmcwmp.h +++ b/dm/dmcwmp.h @@ -123,6 +123,8 @@ struct dmctx char *in_notification; char *in_value; char *addobj_instance; + char *linker; + char *linker_param; char current_obj[512]; }; @@ -204,6 +206,8 @@ int dm_entry_set_value(struct dmctx *ctx); int dm_entry_set_notification(struct dmctx *ctx); int dm_entry_set_prefix_methods_enable(void); int dm_entry_enabled_notify(struct dmctx *ctx); +int dm_entry_get_linker(struct dmctx *ctx); +int dm_entry_get_linker_value(struct dmctx *ctx); void free_all_list_enabled_notify(); void dm_update_enabled_notify(struct dm_enabled_notify *p, char *new_value); void dm_update_enabled_notify_byname(char *name, char *new_value); diff --git a/dm/dmentry.c b/dm/dmentry.c index b51534a..b2ee3f3 100644 --- a/dm/dmentry.c +++ b/dm/dmentry.c @@ -186,6 +186,48 @@ int dm_entry_load_enabled_notify() return 0; } +int adm_entry_get_linker_param(char *param, char *linker, char **value) +{ + struct dmctx dmctx = {0}; + + dm_ctx_init(&dmctx); + dmctx.in_param = param ? param : ""; + dmctx.linker = linker; + + + if (dmctx.in_param[0] == '\0') { + dmctx.tree = true; + } else { + dmctx.tree = false; + } + + dm_entry_get_linker(&dmctx); + *value = dmctx.linker_param; + + dm_ctx_clean(&dmctx); + return 0; +} + +int adm_entry_get_linker_value(char *param, char **value) +{ + struct dmctx dmctx = {0}; + *value = NULL; + + if (!param || param[0] == '\0') { + return 0; + } + + dm_ctx_init(&dmctx); + dmctx.in_param = param; + dmctx.tree = false; + + dm_entry_get_linker_value(&dmctx); + *value = dmctx.linker; + + dm_ctx_clean(&dmctx); + return 0; +} + int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out) { if (!out) return 0; diff --git a/dm/dmentry.h b/dm/dmentry.h index 5c8099c..0c4ac7c 100644 --- a/dm/dmentry.h +++ b/dm/dmentry.h @@ -8,6 +8,8 @@ int dm_ctx_init(struct dmctx *ctx); int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2); int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2); int dm_entry_load_enabled_notify(); +int adm_entry_get_linker_param(char *param, char *linker, char **value); +int adm_entry_get_linker_value(char *param, char **value); int dm_ctx_clean(struct dmctx *ctx); int dm_global_clean(void); void dm_entry_cli(int argc, char** argv);