Reuse existing functions to get values

This commit is contained in:
vdutta 2022-01-11 12:57:03 +05:30
parent a6b7d8db4d
commit a488c1e1b0
4 changed files with 52 additions and 34 deletions

View file

@ -626,11 +626,11 @@ end:
int cwmp_get_deviceid(struct cwmp *cwmp)
{
cwmp_usp_get_single("Device.DeviceInfo.Manufacturer", &cwmp->deviceid.manufacturer);
cwmp_usp_get_single("Device.DeviceInfo.SerialNumber", &cwmp->deviceid.serialnumber);
cwmp_usp_get_single("Device.DeviceInfo.ProductClass", &cwmp->deviceid.productclass);
cwmp_usp_get_single("Device.DeviceInfo.ManufacturerOUI", &cwmp->deviceid.oui);
cwmp_usp_get_single("Device.DeviceInfo.SoftwareVersion", &cwmp->deviceid.softwareversion);
cwmp_get_leaf_value("Device.DeviceInfo.Manufacturer", &cwmp->deviceid.manufacturer);
cwmp_get_leaf_value("Device.DeviceInfo.SerialNumber", &cwmp->deviceid.serialnumber);
cwmp_get_leaf_value("Device.DeviceInfo.ProductClass", &cwmp->deviceid.productclass);
cwmp_get_leaf_value("Device.DeviceInfo.ManufacturerOUI", &cwmp->deviceid.oui);
cwmp_get_leaf_value("Device.DeviceInfo.SoftwareVersion", &cwmp->deviceid.softwareversion);
return CWMP_OK;
}

15
cwmp.c
View file

@ -445,7 +445,6 @@ void load_forced_inform_json_file(struct cwmp *cwmp)
struct blob_attr *cur;
struct blob_attr *custom_forced_inform_list = NULL;
int rem;
struct cwmp_dm_parameter cwmp_dm_param = { 0 };
if (cwmp->conf.forced_inform_json_file == NULL || !file_exists(cwmp->conf.forced_inform_json_file))
return;
@ -473,17 +472,19 @@ void load_forced_inform_json_file(struct cwmp *cwmp)
blobmsg_for_each_attr(cur, custom_forced_inform_list, rem)
{
char parameter_path[128];
char *val = NULL;
snprintf(parameter_path, sizeof(parameter_path), "%s", blobmsg_get_string(cur));
if (parameter_path[strlen(parameter_path)-1] == '.') {
CWMP_LOG(WARNING, "%s is rejected as inform parameter. Only leaf parameters are allowed.", parameter_path);
continue;
}
char *fault = cwmp_get_single_parameter_value(parameter_path, &cwmp_dm_param);
if (fault != NULL) {
int fault = cwmp_get_leaf_value(parameter_path, &val);
if (fault != 0) {
CWMP_LOG(WARNING, "%s is rejected as inform parameter. Wrong parameter path.", parameter_path);
continue;
}
custom_forced_inform_parameters[nbre_custom_inform++] = strdup(parameter_path);
FREE(val);
}
blob_buf_free(&bbuf);
@ -495,7 +496,6 @@ void load_boot_inform_json_file(struct cwmp *cwmp)
struct blob_attr *cur;
struct blob_attr *custom_boot_inform_list = NULL;
int rem;
struct cwmp_dm_parameter cwmp_dm_param = { 0 };
if (cwmp->conf.boot_inform_json_file == NULL || !file_exists(cwmp->conf.boot_inform_json_file))
return;
@ -524,17 +524,20 @@ void load_boot_inform_json_file(struct cwmp *cwmp)
blobmsg_for_each_attr(cur, custom_boot_inform_list, rem)
{
char parameter_path[128];
char *val = NULL;
snprintf(parameter_path, sizeof(parameter_path), "%s", blobmsg_get_string(cur));
if (parameter_path[strlen(parameter_path)-1] == '.') {
CWMP_LOG(WARNING, "%s is rejected as inform parameter. Only leaf parameters are allowed.", parameter_path);
continue;
}
char *fault = cwmp_get_single_parameter_value(parameter_path, &cwmp_dm_param);
if (fault != NULL) {
int fault = cwmp_get_leaf_value(parameter_path, &val);
if (fault != 0) {
CWMP_LOG(WARNING, "%s is rejected as inform parameter. Wrong parameter path.", parameter_path);
continue;
}
boot_inform_parameters[nbre_boot_inform++] = strdup(parameter_path);
FREE(val);
}
blob_buf_free(&bbuf);
}

View file

@ -305,6 +305,43 @@ char *cwmp_get_single_parameter_value(char *parameter_name, struct cwmp_dm_param
return NULL;
}
int cwmp_get_leaf_value(char *leaf, char **value)
{
struct cwmp_dm_parameter dm_param = {0};
size_t llen;
if (leaf == NULL || value == NULL) {
CWMP_LOG(INFO, "Empty parameter/value in arguments")
return FAULT_CPE_INVALID_ARGUMENTS;
}
llen = strlen(leaf);
if (llen == 0) {
CWMP_LOG(INFO, "Empty parameter in arguments")
return FAULT_CPE_INVALID_ARGUMENTS;
}
if (leaf[llen - 1] == '.') {
CWMP_LOG(INFO, "Non-leaf parameter parameter")
return FAULT_CPE_INVALID_ARGUMENTS;
}
cwmp_get_single_parameter_value(leaf, &dm_param);
if (dm_param.name == NULL) {
CWMP_LOG(INFO, "Fault in getting the parameter %s", leaf)
return FAULT_CPE_INTERNAL_ERROR;
}
if (strncmp(leaf, dm_param.name, llen) == 0) {
*value = (dm_param.value) ? strdup(dm_param.value) : strdup("");
} else {
CWMP_LOG(WARNING, "Param %s, does not return a value", leaf);
return FAULT_CPE_INTERNAL_ERROR;
}
return 0;
}
/*
* Get parameter Values/Names/Notify
*/
@ -506,25 +543,3 @@ char *cwmp_delete_object(char *object_name, char *key)
return NULL;
}
int cwmp_usp_get_single(char *param, char **value)
{
struct cwmp_dm_parameter *pv = NULL;
LIST_HEAD(params_list);
if (param == NULL || value == NULL)
return -1;
cwmp_get_parameter_values(param, &params_list);
list_for_each_entry (pv, &params_list, list) {
if (strncmp(param, pv->name, strlen(param)) == 0) {
*value = (pv->value)?strdup(pv->value):strdup("");
break;
}
}
cwmp_free_all_dm_parameter_list(&params_list);
return 0;
}

View file

@ -12,7 +12,7 @@ bool cwmp_transaction_commit();
bool cwmp_transaction_abort();
bool cwmp_transaction_status();
char *cwmp_get_parameter_values(char *parameter_name, struct list_head *parameters_list);
int cwmp_usp_get_single(char *param, char **value);
int cwmp_get_leaf_value(char *leaf, char **value);
char *cwmp_get_multiple_parameters_values(struct list_head *arg_params_list, struct list_head *parameters_list);
char *cwmp_get_single_parameter_value(char *parameter_name, struct cwmp_dm_parameter *dm_parameter);
int cwmp_set_multiple_parameters_values(struct list_head *parameters_values_list, char *parameter_key, int *flag, struct list_head *faults_list);