mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Align with new bbfdm changes
This commit is contained in:
parent
ef78476270
commit
81d66bc1e8
14 changed files with 241 additions and 223 deletions
18
src/common.c
18
src/common.c
|
|
@ -154,7 +154,7 @@ void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *pa
|
|||
dm_parameter->writable = writable;
|
||||
}
|
||||
|
||||
void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter)
|
||||
static void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter)
|
||||
{
|
||||
list_del(&dm_parameter->list);
|
||||
FREE(dm_parameter->name);
|
||||
|
|
@ -176,22 +176,21 @@ void cwmp_free_all_dm_parameter_list(struct list_head *list)
|
|||
/*
|
||||
* List Fault parameter
|
||||
*/
|
||||
void cwmp_add_list_fault_param(char *param, int fault, struct list_head *list_set_value_fault)
|
||||
void cwmp_add_list_fault_param(char *param_name, char *fault_msg, int fault_code, struct list_head *list_set_value_fault)
|
||||
{
|
||||
struct cwmp_param_fault *param_fault;
|
||||
if (param == NULL)
|
||||
param = "";
|
||||
struct cwmp_param_fault *param_fault = NULL;
|
||||
|
||||
param_fault = calloc(1, sizeof(struct cwmp_param_fault));
|
||||
list_add_tail(¶m_fault->list, list_set_value_fault);
|
||||
param_fault->name = strdup(param);
|
||||
param_fault->fault = fault;
|
||||
|
||||
snprintf(param_fault->path_name, sizeof(param_fault->path_name), "%s", param_name ? param_name : "");
|
||||
snprintf(param_fault->fault_msg, sizeof(param_fault->fault_msg), "%s", fault_msg ? fault_msg : "");
|
||||
param_fault->fault_code = fault_code;
|
||||
}
|
||||
|
||||
void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault)
|
||||
static void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault)
|
||||
{
|
||||
list_del(¶m_fault->list);
|
||||
free(param_fault->name);
|
||||
free(param_fault);
|
||||
}
|
||||
|
||||
|
|
@ -450,6 +449,7 @@ int cwmp_get_fault_code_by_string(char *fault_code)
|
|||
|
||||
if (fault_code == NULL)
|
||||
return FAULT_CPE_NO_FAULT;
|
||||
|
||||
for (i = 1; i < __FAULT_CPE_MAX; i++) {
|
||||
if (strcmp(FAULT_CPE_ARRAY[i].CODE, fault_code) == 0)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -259,8 +259,9 @@ typedef struct rpc {
|
|||
|
||||
struct cwmp_param_fault {
|
||||
struct list_head list;
|
||||
char *name;
|
||||
int fault;
|
||||
char path_name[1024];
|
||||
char fault_msg[256];
|
||||
int fault_code;
|
||||
};
|
||||
|
||||
struct cwmp_dm_parameter {
|
||||
|
|
@ -593,11 +594,9 @@ extern struct cwmp_namespaces ns;
|
|||
extern struct session_timer_event *global_session_event;
|
||||
|
||||
void add_dm_parameter_to_list(struct list_head *head, char *param_name, char *param_data, char *param_type, int notification, bool writable);
|
||||
void delete_dm_parameter_from_list(struct cwmp_dm_parameter *dm_parameter);
|
||||
void cwmp_free_all_dm_parameter_list(struct list_head *list);
|
||||
int global_env_init(int argc, char **argv, struct env *env);
|
||||
void cwmp_add_list_fault_param(char *param, int fault, struct list_head *list_set_value_fault);
|
||||
void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault);
|
||||
void cwmp_add_list_fault_param(char *param_name, char *fault_msg, int fault_code, struct list_head *list_set_value_fault);
|
||||
void cwmp_free_all_list_param_fault(struct list_head *list_param_fault);
|
||||
int cwmp_asprintf(char **s, const char *format, ...);
|
||||
bool folder_exists(const char *path);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include "common.h"
|
||||
#include "cwmp_cli.h"
|
||||
#include "datamodel_interface.h"
|
||||
#include "cwmp_uci.h"
|
||||
#include "notifications.h"
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ static void display_get_cmd_result(struct cmd_input in __attribute__((unused)),
|
|||
/*
|
||||
* Set_Values
|
||||
*/
|
||||
char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)))
|
||||
char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res)
|
||||
{
|
||||
if (CWMP_STRLEN(in.first_input) == 0 || CWMP_STRLEN(in.second_input) == 0)
|
||||
return "9003";
|
||||
|
|
@ -86,15 +85,17 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__
|
|||
int fault_idx = cwmp_set_parameter_value(in.first_input, in.second_input, &faults_list);
|
||||
if (fault_idx != FAULT_CPE_NO_FAULT) {
|
||||
struct cwmp_param_fault *param_fault = NULL;
|
||||
char fault[5] = {0};
|
||||
char *fault = NULL;
|
||||
|
||||
list_for_each_entry (param_fault, &faults_list, list) {
|
||||
snprintf(fault, sizeof(fault), "%d", param_fault->fault);
|
||||
res->obj_res.fault_code = param_fault->fault_code;
|
||||
snprintf(res->obj_res.fault_msg, sizeof(res->obj_res.fault_msg), "%s", param_fault->fault_msg);
|
||||
break;
|
||||
}
|
||||
cwmp_free_all_list_param_fault(&faults_list);
|
||||
|
||||
return icwmp_strdup(fault);
|
||||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
return fault;
|
||||
}
|
||||
|
||||
set_rpc_parameter_key(in.third_input);
|
||||
|
|
@ -102,14 +103,15 @@ char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void display_set_cmd_result(struct cmd_input in, union cmd_result res __attribute__((unused)), char *fault)
|
||||
static void display_set_cmd_result(struct cmd_input in, union cmd_result res, char *fault)
|
||||
{
|
||||
if (fault == NULL) {
|
||||
fprintf(stdout, "Set value is successfully done\n");
|
||||
fprintf(stdout, "%s => %s\n", in.first_input, in.second_input);
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
|
||||
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, res.obj_res.fault_msg);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -120,9 +122,13 @@ char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
if (in.first_input == NULL)
|
||||
return "9003";
|
||||
|
||||
char *fault = cwmp_add_object(in.first_input, &(res->instance));
|
||||
if (fault != NULL)
|
||||
bool status = cwmp_add_object(in.first_input, &res->obj_res);
|
||||
if (!status) {
|
||||
char *fault = NULL;
|
||||
|
||||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
return fault;
|
||||
}
|
||||
|
||||
set_rpc_parameter_key(in.second_input);
|
||||
|
||||
|
|
@ -132,41 +138,46 @@ char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res)
|
|||
static void display_add_cmd_result(struct cmd_input in, union cmd_result res, char *fault)
|
||||
{
|
||||
if (fault != NULL) {
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, strlen(res.obj_res.fault_msg) ? res.obj_res.fault_msg : get_fault_message_by_fault_code(fault));
|
||||
return;
|
||||
}
|
||||
|
||||
if (in.first_input[strlen(in.first_input) - 1] == '.')
|
||||
fprintf(stdout, "Added %s%s.\n", in.first_input, res.instance);
|
||||
fprintf(stdout, "Added %s%s.\n", in.first_input, res.obj_res.instance);
|
||||
else
|
||||
fprintf(stdout, "Added %s.%s.\n", in.first_input, res.instance);
|
||||
fprintf(stdout, "Added %s.%s.\n", in.first_input, res.obj_res.instance);
|
||||
|
||||
FREE(res.instance);
|
||||
FREE(res.obj_res.instance);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete_Object
|
||||
*/
|
||||
char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)))
|
||||
char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res)
|
||||
{
|
||||
if (in.first_input == NULL)
|
||||
return "9003";
|
||||
|
||||
char *fault = cwmp_delete_object(in.first_input);
|
||||
if (fault != NULL)
|
||||
bool status = cwmp_delete_object(in.first_input, &res->obj_res);
|
||||
if (!status) {
|
||||
char *fault = NULL;
|
||||
|
||||
icwmp_asprintf(&fault, "%d", res->obj_res.fault_code);
|
||||
return fault;
|
||||
}
|
||||
|
||||
set_rpc_parameter_key(in.second_input);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void display_del_cmd_result(struct cmd_input in, union cmd_result res __attribute__((unused)), char *fault)
|
||||
static void display_del_cmd_result(struct cmd_input in, union cmd_result res, char *fault)
|
||||
{
|
||||
if (fault != NULL) {
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, get_fault_message_by_fault_code(fault));
|
||||
fprintf(stderr, "Fault %s: %s\n", fault, strlen(res.obj_res.fault_msg) ? res.obj_res.fault_msg : get_fault_message_by_fault_code(fault));
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Deleted %s\n", in.first_input);
|
||||
}
|
||||
|
||||
|
|
@ -288,8 +299,9 @@ char *execute_cwmp_cli_command(char *cmd, char *args[])
|
|||
struct cmd_input cmd_in = {
|
||||
args[0] ? args[0] : NULL,
|
||||
args[0] && args[1] ? args[1] : NULL,
|
||||
args[0] && args[1] && args[2] ? args[2] : NULL };
|
||||
union cmd_result cmd_out = { 0 };
|
||||
args[0] && args[1] && args[2] ? args[2] : NULL
|
||||
};
|
||||
union cmd_result cmd_out = {0};
|
||||
char *fault = NULL, *fault_ret = NULL;
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(icwmp_commands); i++) {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,11 @@
|
|||
#ifndef CWMP_CLI
|
||||
#define CWMP_CLI
|
||||
|
||||
#include "datamodel_interface.h"
|
||||
|
||||
union cmd_result {
|
||||
struct list_head *param_list;
|
||||
char *instance;
|
||||
struct object_result obj_res;
|
||||
};
|
||||
|
||||
struct cmd_input {
|
||||
|
|
@ -24,9 +26,9 @@ struct cmd_input {
|
|||
};
|
||||
|
||||
char *cmd_get_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)));
|
||||
char *cmd_set_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
char *cmd_add_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)));
|
||||
char *cmd_del_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
char *cmd_get_notif_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
char *cmd_set_notif_exec_func(struct cmd_input in, union cmd_result *res __attribute__((unused)));
|
||||
char *cmd_get_names_exec_func(struct cmd_input in, union cmd_result *res);
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ static int set_management_server_url(char *refparam, struct dmctx *ctx, void *da
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
|
|
@ -291,7 +291,7 @@ static int set_management_server_username(char *refparam, struct dmctx *ctx, voi
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -306,7 +306,7 @@ static int set_management_server_passwd(char *refparam, struct dmctx *ctx, void
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -327,7 +327,7 @@ static int set_management_server_schedule_reboot(char *refparam, struct dmctx *c
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_dateTime(value))
|
||||
if (bbfdm_validate_dateTime(ctx, value))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
|
|
@ -348,7 +348,7 @@ static int set_management_server_delay_reboot(char *refparam, struct dmctx *ctx,
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_int(value, RANGE_ARGS{{"-1",NULL}}, 1))
|
||||
if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1",NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
|
|
@ -378,7 +378,7 @@ static int set_management_server_periodic_inform_enable(char *refparam, struct d
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -400,7 +400,7 @@ static int set_management_server_periodic_inform_interval(char *refparam, struct
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -421,7 +421,7 @@ static int set_management_server_periodic_inform_time(char *refparam, struct dmc
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_dateTime(value))
|
||||
if (bbfdm_validate_dateTime(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -499,7 +499,7 @@ static int set_management_server_connection_request_username(char *refparam, str
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -514,7 +514,7 @@ static int set_management_server_connection_request_passwd(char *refparam, struc
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -535,7 +535,7 @@ static int set_upgrades_managed(char *refparam, struct dmctx *ctx, void *data, c
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -567,7 +567,7 @@ static int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data,
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, NULL, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -591,7 +591,7 @@ static int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *ins
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 256, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 256, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -612,7 +612,7 @@ static int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *ins
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{NULL,NULL}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{NULL,NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -639,7 +639,7 @@ static int set_management_server_http_compression(char *refparam, struct dmctx *
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, -1, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, -1, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -674,7 +674,7 @@ static int set_management_server_retry_min_wait_interval(char *refparam, struct
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1","65535"}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1","65535"}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -707,7 +707,7 @@ static int set_management_server_retry_interval_multiplier(char *refparam, struc
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1000","65535"}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1000","65535"}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -736,7 +736,7 @@ static int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, -1, InstanceMode, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, -1, InstanceMode, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -772,7 +772,7 @@ static int set_management_server_enable_cwmp(char *refparam, struct dmctx *ctx,
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -818,7 +818,7 @@ static int set_default_active_notification_throttle(char *refparam, struct dmctx
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -838,7 +838,7 @@ static int set_manageable_device_notification_limit(char *refparam, struct dmctx
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1",NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -858,7 +858,7 @@ static int set_heart_beat_policy_enable(char *refparam, struct dmctx *ctx, void
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -879,7 +879,7 @@ static int set_heart_beat_policy_reporting_interval(char *refparam, struct dmctx
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"20",NULL}}, 1))
|
||||
if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"20",NULL}}, 1))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -899,7 +899,7 @@ static int set_heart_beat_policy_initiation_time(char *refparam, struct dmctx *c
|
|||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_dateTime(value))
|
||||
if (bbfdm_validate_dateTime(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -960,7 +960,7 @@ static int set_inform_parameter_enable(char *refparam, struct dmctx *ctx, void *
|
|||
struct dmmap_dup *inform_param_args = (struct dmmap_dup *)data;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -984,7 +984,7 @@ static int set_inform_parameter_alias(char *refparam, struct dmctx *ctx, void *d
|
|||
struct dmmap_dup *inform_param_args = (struct dmmap_dup *)data;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, 64, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1006,7 +1006,7 @@ static int set_inform_parameter_parameter_name(char *refparam, struct dmctx *ctx
|
|||
struct dmmap_dup *inform_param_args = (struct dmmap_dup *)data;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, Forced_Inform_Parmeters, NULL) == 0)
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, Forced_Inform_Parmeters, NULL) == 0)
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1027,7 +1027,7 @@ static int set_inform_parameter_event_list(char *refparam, struct dmctx *ctx, vo
|
|||
struct dmmap_dup *inform_param_args = (struct dmmap_dup *)data;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, CWMP_EVENTS, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, CWMP_EVENTS, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1111,7 +1111,7 @@ static int set_transfer_compl_policy_enable(char *refparam, struct dmctx *ctx, v
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1129,7 +1129,7 @@ static int set_transfer_compl_policy_type_filter(char *refparam, struct dmctx *c
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, TCTransferType, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, TCTransferType, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1146,7 +1146,7 @@ static int set_transfer_compl_policy_result_type_filter(char *refparam, struct d
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, -1, TCResultType, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, -1, TCResultType, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1163,7 +1163,7 @@ static int set_transfer_compl_policy_file_type_filter(char *refparam, struct dmc
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, TCFileType, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, TCFileType, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1211,7 +1211,7 @@ static int set_du_state_change_compl_policy_enable(char *refparam, struct dmctx
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
if (bbfdm_validate_boolean(ctx, value))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1229,7 +1229,7 @@ static int set_du_state_change_compl_policy_operation_type_filter(char *refparam
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, DUStateOperationType, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, DUStateOperationType, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1246,7 +1246,7 @@ static int set_du_state_change_compl_policy_result_type_filter(char *refparam, s
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, -1, DUStateResultType, NULL))
|
||||
if (bbfdm_validate_string(ctx, value, -1, -1, DUStateResultType, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
@ -1263,7 +1263,7 @@ static int set_du_state_change_compl_policy_fault_code_filter(char *refparam, st
|
|||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string_list(value, -1, -1, -1, -1, -1, DUStateFaultCode, NULL))
|
||||
if (bbfdm_validate_string_list(ctx, value, -1, -1, -1, -1, -1, DUStateFaultCode, NULL))
|
||||
return FAULT_9007;
|
||||
return 0;
|
||||
case VALUESET:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@
|
|||
|
||||
unsigned int transaction_id = 0;
|
||||
|
||||
struct object_result {
|
||||
char **instance;
|
||||
int error;
|
||||
};
|
||||
|
||||
struct list_params_result {
|
||||
struct list_head *parameters_list;
|
||||
int error;
|
||||
|
|
@ -56,21 +51,6 @@ static struct blob_attr *get_results_array(struct blob_attr *msg)
|
|||
return tb[0];
|
||||
}
|
||||
|
||||
int get_fault_value(struct blob_attr *msg)
|
||||
{
|
||||
struct blob_attr *tb[1] = {0};
|
||||
const struct blobmsg_policy p[1] = {
|
||||
{ "fault", BLOBMSG_TYPE_INT32 }
|
||||
};
|
||||
|
||||
if (msg == NULL)
|
||||
return FAULT_CPE_INTERNAL_ERROR;
|
||||
|
||||
blobmsg_parse(p, 1, tb, blobmsg_data(msg), blobmsg_len(msg));
|
||||
|
||||
return tb[0] ? blobmsg_get_u32(tb[0]) : FAULT_CPE_NO_FAULT;
|
||||
}
|
||||
|
||||
static void prepare_optional_table(struct blob_buf *b)
|
||||
{
|
||||
void *table = blobmsg_open_table(b, "optional");
|
||||
|
|
@ -386,10 +366,11 @@ static void ubus_set_value_callback(struct ubus_request *req, int type __attribu
|
|||
{
|
||||
struct blob_attr *cur = NULL;
|
||||
int rem = 0;
|
||||
const struct blobmsg_policy p[3] = {
|
||||
const struct blobmsg_policy p[4] = {
|
||||
{ "path", BLOBMSG_TYPE_STRING },
|
||||
{ "data", BLOBMSG_TYPE_STRING },
|
||||
{ "fault", BLOBMSG_TYPE_INT32 }
|
||||
{ "fault", BLOBMSG_TYPE_INT32 },
|
||||
{ "fault_msg", BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
if (msg == NULL || req == NULL)
|
||||
|
|
@ -404,9 +385,9 @@ static void ubus_set_value_callback(struct ubus_request *req, int type __attribu
|
|||
}
|
||||
|
||||
blobmsg_for_each_attr(cur, parameters, rem) {
|
||||
struct blob_attr *tb[3] = {0};
|
||||
struct blob_attr *tb[4] = {0};
|
||||
|
||||
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
|
||||
blobmsg_parse(p, 4, tb, blobmsg_data(cur), blobmsg_len(cur));
|
||||
|
||||
if (!tb[0]) {
|
||||
result->status = false;
|
||||
|
|
@ -418,7 +399,7 @@ static void ubus_set_value_callback(struct ubus_request *req, int type __attribu
|
|||
result->status = false;
|
||||
if (!tb[2]) continue;
|
||||
|
||||
cwmp_add_list_fault_param(blobmsg_get_string(tb[0]), blobmsg_get_u32(tb[2]), result->faults_list);
|
||||
cwmp_add_list_fault_param(blobmsg_get_string(tb[0]), blobmsg_get_string(tb[3]), blobmsg_get_u32(tb[2]), result->faults_list);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -483,9 +464,10 @@ static void ubus_objects_callback(struct ubus_request *req, int type __attribute
|
|||
{
|
||||
struct blob_attr *cur = NULL;
|
||||
int rem = 0;
|
||||
const struct blobmsg_policy p[2] = {
|
||||
const struct blobmsg_policy p[3] = {
|
||||
{ "data", BLOBMSG_TYPE_STRING },
|
||||
{ "fault", BLOBMSG_TYPE_INT32 }
|
||||
{ "fault", BLOBMSG_TYPE_INT32 },
|
||||
{ "fault_msg", BLOBMSG_TYPE_STRING },
|
||||
};
|
||||
|
||||
if (msg == NULL || req == NULL)
|
||||
|
|
@ -495,33 +477,28 @@ static void ubus_objects_callback(struct ubus_request *req, int type __attribute
|
|||
struct blob_attr *objects = get_results_array(msg);
|
||||
|
||||
if (objects == NULL) {
|
||||
result->error = FAULT_CPE_INTERNAL_ERROR;
|
||||
result->fault_code = FAULT_9002;
|
||||
return;
|
||||
}
|
||||
|
||||
blobmsg_for_each_attr(cur, objects, rem) {
|
||||
struct blob_attr *tb[2] = {0};
|
||||
struct blob_attr *tb[3] = {0};
|
||||
|
||||
blobmsg_parse(p, 2, tb, blobmsg_data(cur), blobmsg_len(cur));
|
||||
blobmsg_parse(p, 3, tb, blobmsg_data(cur), blobmsg_len(cur));
|
||||
|
||||
if (tb[1]) {
|
||||
result->error = blobmsg_get_u32(tb[1]);
|
||||
result->fault_code = blobmsg_get_u32(tb[1]);
|
||||
snprintf(result->fault_msg, sizeof(result->fault_msg), "%s", tb[2] ? blobmsg_get_string(tb[2]) : "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tb[0] && result->instance) {
|
||||
char **instance = result->instance;
|
||||
*instance = strdup(blobmsg_get_string(tb[0]));
|
||||
}
|
||||
if (tb[0])
|
||||
result->instance = strdup(blobmsg_get_string(tb[0]));
|
||||
}
|
||||
}
|
||||
|
||||
char *cwmp_add_object(const char *object_name, char **instance)
|
||||
bool cwmp_add_object(const char *object_name, struct object_result *res)
|
||||
{
|
||||
struct object_result add_result = {
|
||||
.instance = instance,
|
||||
.error = FAULT_CPE_NO_FAULT
|
||||
};
|
||||
struct blob_buf b = {0};
|
||||
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
|
|
@ -530,33 +507,25 @@ char *cwmp_add_object(const char *object_name, char **instance)
|
|||
bb_add_string(&b, "path", object_name);
|
||||
prepare_optional_table(&b);
|
||||
|
||||
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "add", b.head, ubus_objects_callback, &add_result);
|
||||
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "add", b.head, ubus_objects_callback, res);
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "add_object ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (add_result.error) {
|
||||
char buf[8] = {0};
|
||||
|
||||
CWMP_LOG(WARNING, "Add Object (%s) failed: fault_code: %d", object_name, add_result.error);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d", add_result.error);
|
||||
return icwmp_strdup(buf);
|
||||
if (res->fault_code) {
|
||||
CWMP_LOG(WARNING, "Add Object (%s) failed: fault_code: %d", object_name, res->fault_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
char *cwmp_delete_object(const char *object_name)
|
||||
bool cwmp_delete_object(const char *object_name, struct object_result *res)
|
||||
{
|
||||
struct object_result del_result = {
|
||||
.instance = NULL,
|
||||
.error = FAULT_CPE_NO_FAULT
|
||||
};
|
||||
struct blob_buf b = {0};
|
||||
|
||||
memset(&b, 0, sizeof(struct blob_buf));
|
||||
|
|
@ -565,23 +534,19 @@ char *cwmp_delete_object(const char *object_name)
|
|||
bb_add_string(&b, "path", object_name);
|
||||
prepare_optional_table(&b);
|
||||
|
||||
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "del", b.head, ubus_objects_callback, &del_result);
|
||||
int e = icwmp_ubus_invoke(BBFDM_OBJECT_NAME, "del", b.head, ubus_objects_callback, res);
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
if (e < 0) {
|
||||
CWMP_LOG(INFO, "delete object ubus method failed: Ubus err code: %d", e);
|
||||
return "9002";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (del_result.error) {
|
||||
char buf[8] = {0};
|
||||
|
||||
CWMP_LOG(WARNING, "Delete Object (%s) failed: fault_code: %d", object_name, del_result.error);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d", del_result.error);
|
||||
return icwmp_strdup(buf);
|
||||
if (res->fault_code) {
|
||||
CWMP_LOG(WARNING, "Delete Object (%s) failed: fault_code: %d", object_name, res->fault_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
struct object_result {
|
||||
char *instance;
|
||||
char fault_msg[256];
|
||||
int fault_code;
|
||||
};
|
||||
|
||||
extern unsigned int transaction_id;
|
||||
|
||||
bool cwmp_transaction(const char *cmd, bool restart_services);
|
||||
|
|
@ -27,7 +33,7 @@ char *cwmp_get_parameter_names(const char *parameter_name, bool next_level, stru
|
|||
int cwmp_set_parameter_value(const char *parameter_name, const char *parameter_value, struct list_head *faults_list);
|
||||
int cwmp_set_multi_parameters_value(struct list_head *parameters_values_list, struct list_head *faults_list);
|
||||
|
||||
char *cwmp_add_object(const char *object_name, char **instance);
|
||||
char *cwmp_delete_object(const char *object_name);
|
||||
bool cwmp_add_object(const char *object_name, struct object_result *res);
|
||||
bool cwmp_delete_object(const char *object_name, struct object_result *res);
|
||||
|
||||
#endif /* SRC_DATAMODELIFACE_H_ */
|
||||
|
|
|
|||
85
src/rpc.c
85
src/rpc.c
|
|
@ -821,7 +821,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -891,7 +891,7 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_all_dm_parameter_list(¶meters_list);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -942,7 +942,7 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1043,7 +1043,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_all_dm_parameter_list(&list_set_param_value);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
ret = -1;
|
||||
|
||||
cwmp_free_all_list_param_fault(rpc->list_set_value_fault);
|
||||
|
|
@ -1102,7 +1102,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
|
|
@ -1113,11 +1113,11 @@ fault:
|
|||
*/
|
||||
int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc)
|
||||
{
|
||||
mxml_node_t *b;
|
||||
mxml_node_t *b = NULL;
|
||||
char *object_name = NULL;
|
||||
char *parameter_key = NULL;
|
||||
int fault_code = FAULT_CPE_INTERNAL_ERROR, ret = 0;
|
||||
char *instance = NULL;
|
||||
struct object_result res = {0};
|
||||
|
||||
struct xml_data_struct add_obj_xml_attrs = {0};
|
||||
add_obj_xml_attrs.object_name = &object_name;
|
||||
|
|
@ -1135,9 +1135,9 @@ int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc)
|
|||
goto fault;
|
||||
|
||||
if (object_name) {
|
||||
char *err = cwmp_add_object(object_name, &instance);
|
||||
if (err) {
|
||||
fault_code = cwmp_get_fault_code_by_string(err);
|
||||
bool err = cwmp_add_object(object_name, &res);
|
||||
if (!err) {
|
||||
fault_code = cwmp_get_fault_code(res.fault_code);
|
||||
goto fault;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1146,16 +1146,19 @@ int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc)
|
|||
}
|
||||
|
||||
set_rpc_parameter_key(parameter_key);
|
||||
if (instance == NULL)
|
||||
|
||||
if (res.instance == NULL)
|
||||
goto fault;
|
||||
|
||||
b = build_top_body_soap_response(cwmp_main->session->tree_out, "AddObject");
|
||||
|
||||
if (!b)
|
||||
goto fault;
|
||||
|
||||
int instance_int = atoi(instance);
|
||||
int status = 0;
|
||||
struct xml_data_struct add_resp_xml_attrs = {0};
|
||||
int instance_int = atoi(res.instance);
|
||||
int status = 0;
|
||||
|
||||
add_resp_xml_attrs.instance = &instance_int;
|
||||
add_resp_xml_attrs.status = &status;
|
||||
|
||||
|
|
@ -1167,19 +1170,19 @@ int cwmp_handle_rpc_cpe_add_object(struct rpc *rpc)
|
|||
goto fault;
|
||||
|
||||
char object_path[1024] = {0};
|
||||
snprintf(object_path, sizeof(object_path), "%s%s.", object_name, instance);
|
||||
snprintf(object_path, sizeof(object_path), "%s%s.", object_name, res.instance);
|
||||
cwmp_set_parameter_attributes(object_path, 0);
|
||||
FREE(object_name);
|
||||
FREE(parameter_key);
|
||||
FREE(instance);
|
||||
FREE(res.instance);
|
||||
cwmp_set_end_session(END_SESSION_RESTART_SERVICES);
|
||||
return 0;
|
||||
|
||||
fault:
|
||||
FREE(object_name);
|
||||
FREE(parameter_key);
|
||||
FREE(instance);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
FREE(res.instance);
|
||||
if (cwmp_create_fault_message(rpc, fault_code, res.fault_msg))
|
||||
ret = -1;
|
||||
|
||||
cwmp_transaction("abort", false);
|
||||
|
|
@ -1195,6 +1198,7 @@ int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc)
|
|||
char *object_name = NULL;
|
||||
char *parameter_key = NULL;
|
||||
int fault_code = FAULT_CPE_INTERNAL_ERROR, ret = 0;
|
||||
struct object_result res = {0};
|
||||
|
||||
struct xml_data_struct del_obj_xml_attrs = {0};
|
||||
del_obj_xml_attrs.object_name = &object_name;
|
||||
|
|
@ -1212,9 +1216,9 @@ int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc)
|
|||
goto fault;
|
||||
|
||||
if (object_name) {
|
||||
char *err = cwmp_delete_object(object_name);
|
||||
if (err) {
|
||||
fault_code = cwmp_get_fault_code_by_string(err);
|
||||
bool err = cwmp_delete_object(object_name, &res);
|
||||
if (!err) {
|
||||
fault_code = cwmp_get_fault_code(res.fault_code);
|
||||
goto fault;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1249,7 +1253,7 @@ int cwmp_handle_rpc_cpe_delete_object(struct rpc *rpc)
|
|||
fault:
|
||||
FREE(object_name);
|
||||
FREE(parameter_key);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, res.fault_msg))
|
||||
ret = -1;
|
||||
|
||||
cwmp_transaction("abort", false);
|
||||
|
|
@ -1301,7 +1305,7 @@ int cwmp_handle_rpc_cpe_get_rpc_methods(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1324,7 +1328,7 @@ int cwmp_handle_rpc_cpe_factory_reset(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, FAULT_CPE_INTERNAL_ERROR))
|
||||
if (cwmp_create_fault_message(rpc, FAULT_CPE_INTERNAL_ERROR, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1349,7 +1353,7 @@ int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
if (cwmp_create_fault_message(rpc, FAULT_CPE_INTERNAL_ERROR))
|
||||
if (cwmp_create_fault_message(rpc, FAULT_CPE_INTERNAL_ERROR, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1392,7 +1396,7 @@ int cwmp_handle_rpc_cpe_cancel_transfer(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
FREE(command_key);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1476,7 +1480,7 @@ int cwmp_handle_rpc_cpe_reboot(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
FREE(command_key);
|
||||
if (cwmp_create_fault_message(rpc, fault_code))
|
||||
if (cwmp_create_fault_message(rpc, fault_code, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1552,7 +1556,7 @@ int cwmp_handle_rpc_cpe_schedule_inform(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
FREE(command_key);
|
||||
if (cwmp_create_fault_message(rpc, fault))
|
||||
if (cwmp_create_fault_message(rpc, fault, ""))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
|
@ -1623,7 +1627,7 @@ int cwmp_handle_rpc_cpe_change_du_state(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_change_du_state_request(change_du_state);
|
||||
if (cwmp_create_fault_message(rpc, error))
|
||||
if (cwmp_create_fault_message(rpc, error, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1742,7 +1746,7 @@ int cwmp_handle_rpc_cpe_download(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_download_request(download);
|
||||
if (cwmp_create_fault_message(rpc, error))
|
||||
if (cwmp_create_fault_message(rpc, error, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1876,7 +1880,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_schedule_download_request(schedule_download);
|
||||
if (cwmp_create_fault_message(rpc, error))
|
||||
if (cwmp_create_fault_message(rpc, error, ""))
|
||||
goto error;
|
||||
return 0;
|
||||
|
||||
|
|
@ -1995,7 +1999,7 @@ int cwmp_handle_rpc_cpe_upload(struct rpc *rpc)
|
|||
|
||||
fault:
|
||||
cwmp_free_upload_request(upload);
|
||||
if (cwmp_create_fault_message(rpc, error))
|
||||
if (cwmp_create_fault_message(rpc, error, ""))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2010,10 +2014,13 @@ int cwmp_handle_rpc_cpe_fault(struct rpc *rpc)
|
|||
|
||||
body = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
|
||||
struct xml_data_struct fault_xml_attrs = {0};
|
||||
|
||||
char *faultcode = (FAULT_CPE_ARRAY[cwmp_main->session->fault_code].TYPE == FAULT_CPE_TYPE_CLIENT) ? "Client" : "Server";
|
||||
char *faultstring = "CWMP fault";
|
||||
|
||||
int fault_code = atoi(cwmp_main->session->fault_code ? FAULT_CPE_ARRAY[cwmp_main->session->fault_code].CODE : "0");
|
||||
char *fault_string = strdup(FAULT_CPE_ARRAY[cwmp_main->session->fault_code].DESCRIPTION);
|
||||
char *fault_string = strlen(cwmp_main->session->fault_msg) ? strdup(cwmp_main->session->fault_msg) : strdup(FAULT_CPE_ARRAY[cwmp_main->session->fault_code].DESCRIPTION);
|
||||
|
||||
fault_xml_attrs.fault_code = &fault_code;
|
||||
fault_xml_attrs.fault_string = &fault_string;
|
||||
fault_xml_attrs.faultcode = &faultcode;
|
||||
|
|
@ -2025,26 +2032,33 @@ int cwmp_handle_rpc_cpe_fault(struct rpc *rpc)
|
|||
return -1;
|
||||
|
||||
if (rpc->type == RPC_CPE_SET_PARAMETER_VALUES) {
|
||||
LIST_HEAD(spv_fault_xml_data_list);
|
||||
cwmp_param_fault_list_to_xml_data_list(rpc->list_set_value_fault, &spv_fault_xml_data_list);
|
||||
struct xml_data_struct spv_fault_xml_attrs = {0};
|
||||
LIST_HEAD(spv_fault_xml_data_list);
|
||||
|
||||
cwmp_param_fault_list_to_xml_data_list(rpc->list_set_value_fault, &spv_fault_xml_data_list);
|
||||
|
||||
spv_fault_xml_attrs.data_list = &spv_fault_xml_data_list;
|
||||
|
||||
body = mxmlFindElement(cwmp_main->session->tree_out, cwmp_main->session->tree_out, "cwmp:Fault", NULL, NULL, MXML_DESCEND);
|
||||
if (body == NULL)
|
||||
return -1;
|
||||
|
||||
fault = build_xml_node_data(SOAP_SPV_FAULT, body, &spv_fault_xml_attrs);
|
||||
if (fault)
|
||||
return -1;
|
||||
|
||||
cwmp_free_all_xml_data_list(&spv_fault_xml_data_list);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code)
|
||||
int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code, char *fault_msg)
|
||||
{
|
||||
CWMP_LOG(INFO, "Fault detected");
|
||||
|
||||
cwmp_main->session->fault_code = fault_code;
|
||||
snprintf(cwmp_main->session->fault_msg, sizeof(cwmp_main->session->fault_msg), "%s", fault_msg);
|
||||
|
||||
MXML_DELETE(cwmp_main->session->tree_out);
|
||||
|
||||
|
|
@ -2054,6 +2068,7 @@ int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code)
|
|||
CWMP_LOG(INFO, "Preparing the Fault message");
|
||||
if (rpc_cpe_methods[RPC_CPE_FAULT].handler(rpc_cpe))
|
||||
return -1;
|
||||
|
||||
rpc_cpe->type = RPC_CPE_FAULT;
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,6 @@ int cwmp_rpc_acs_prepare_autonomous_du_state_change_complete(struct rpc *rpc);
|
|||
int cwmp_rpc_acs_prepare_autonomous_transfer_complete(struct rpc *rpc);
|
||||
|
||||
int xml_handle_message();
|
||||
int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code);
|
||||
int cwmp_create_fault_message(struct rpc *rpc_cpe, int fault_code, char *fault_msg);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ struct uloop_timeout session_timer = { .cb = cwmp_schedule_session };
|
|||
struct uloop_timeout periodic_session_timer = { .cb = cwmp_periodic_session_timer };
|
||||
struct uloop_timeout retry_session_timer = { .cb = cwmp_schedule_session };
|
||||
struct uloop_timeout throttle_session_timer = { .cb = cwmp_schedule_throttle_session };
|
||||
//struct session_timer_event session_timer_evt = {.session_timer_evt = {.cb = cwmp_schedule_session_with_event}, .event = -1};
|
||||
|
||||
unsigned int end_session_flag = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ typedef struct session {
|
|||
mxml_node_t *tree_in;
|
||||
mxml_node_t *tree_out;
|
||||
mxml_node_t *body_in;
|
||||
char fault_msg[256];
|
||||
bool hold_request;
|
||||
int fault_code;
|
||||
int error;
|
||||
|
|
|
|||
14
src/xml.c
14
src/xml.c
|
|
@ -920,18 +920,18 @@ int load_xml_node_data(int node_ref, mxml_node_t *node, struct xml_data_struct *
|
|||
void cwmp_param_fault_list_to_xml_data_list(struct list_head *param_fault_list, struct list_head *xml_data_list)
|
||||
{
|
||||
struct cwmp_param_fault *param_fault = NULL;
|
||||
list_for_each_entry (param_fault, param_fault_list, list) {
|
||||
if (!param_fault->fault)
|
||||
continue;
|
||||
|
||||
struct xml_list_data *xml_data;
|
||||
list_for_each_entry (param_fault, param_fault_list, list) {
|
||||
struct xml_list_data *xml_data = NULL;
|
||||
|
||||
xml_data = calloc(1, sizeof(struct xml_list_data));
|
||||
list_add_tail(&xml_data->list, xml_data_list);
|
||||
int idx = cwmp_get_fault_code(param_fault->fault);
|
||||
xml_data->param_name = strdup(param_fault->name);
|
||||
|
||||
int idx = cwmp_get_fault_code(param_fault->fault_code);
|
||||
|
||||
xml_data->param_name = strdup(param_fault->path_name);
|
||||
xml_data->fault_code = atoi(FAULT_CPE_ARRAY[idx].CODE);
|
||||
xml_data->fault_string = strdup(FAULT_CPE_ARRAY[idx].DESCRIPTION);
|
||||
xml_data->fault_string = strlen(param_fault->fault_msg) ? strdup(param_fault->fault_msg) : strdup(FAULT_CPE_ARRAY[idx].DESCRIPTION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ static void cwmp_add_cli_unit_test(void **state)
|
|||
fault = cmd_add_exec_func(input_null, &cmd_add_out_1);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9003");
|
||||
assert_null(cmd_add_out_1.instance);
|
||||
assert_null(cmd_add_out_1.obj_res.instance);
|
||||
|
||||
/*
|
||||
* Add: input is valid object path
|
||||
|
|
@ -251,9 +251,9 @@ static void cwmp_add_cli_unit_test(void **state)
|
|||
union cmd_result cmd_add_out_2 = { 0 };
|
||||
fault = cmd_add_exec_func(input_valid, &cmd_add_out_2);
|
||||
assert_null(fault);
|
||||
assert_non_null(cmd_add_out_2.instance);
|
||||
assert_int_equal(atoi(cmd_add_out_2.instance) > 0, 1);
|
||||
add_instance = cmd_add_out_2.instance;
|
||||
assert_non_null(cmd_add_out_2.obj_res.instance);
|
||||
assert_int_equal(atoi(cmd_add_out_2.obj_res.instance) > 0, 1);
|
||||
add_instance = cmd_add_out_2.obj_res.instance;
|
||||
|
||||
/*
|
||||
* Add: input is invalid object path
|
||||
|
|
@ -263,7 +263,7 @@ static void cwmp_add_cli_unit_test(void **state)
|
|||
fault = cmd_add_exec_func(input_invalid_param_path, &cmd_add_out_3);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
assert_null(cmd_add_out_3.instance);
|
||||
assert_null(cmd_add_out_3.obj_res.instance);
|
||||
|
||||
/*
|
||||
* Add: input is non writable object path
|
||||
|
|
@ -273,7 +273,7 @@ static void cwmp_add_cli_unit_test(void **state)
|
|||
fault = cmd_add_exec_func(input_read_only_obj, &cmd_add_out_4);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
assert_null(cmd_add_out_4.instance);
|
||||
assert_null(cmd_add_out_4.obj_res.instance);
|
||||
restore_output();
|
||||
}
|
||||
|
||||
|
|
@ -290,7 +290,7 @@ static void cwmp_del_cli_unit_test(void **state)
|
|||
fault = cmd_del_exec_func(input_null, &cmd_del_out_1);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9003");
|
||||
assert_null(cmd_del_out_1.instance);
|
||||
assert_null(cmd_del_out_1.obj_res.instance);
|
||||
|
||||
/*
|
||||
* Delete: input is valid object path
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ static void dm_set_multiple_parameter_values_test(void **state)
|
|||
fault = cwmp_set_multi_parameters_value(&list_set_param_value, &faults_array);
|
||||
assert_non_null(fault);
|
||||
list_for_each_entry (param_fault, &faults_array, list) {
|
||||
fault_code = param_fault->fault;
|
||||
fault_name = param_fault->name;
|
||||
fault_code = param_fault->fault_code;
|
||||
fault_name = param_fault->path_name;
|
||||
break;
|
||||
}
|
||||
assert_int_not_equal(fault, 0);
|
||||
|
|
@ -154,8 +154,8 @@ static void dm_set_multiple_parameter_values_test(void **state)
|
|||
fault = cwmp_set_multi_parameters_value(&list_set_param_value,&faults_array);
|
||||
assert_int_not_equal(fault, 0);
|
||||
list_for_each_entry (param_fault, &faults_array, list) {
|
||||
fault_code = param_fault->fault;
|
||||
fault_name = param_fault->name;
|
||||
fault_code = param_fault->fault_code;
|
||||
fault_name = param_fault->path_name;
|
||||
break;
|
||||
}
|
||||
assert_int_not_equal(fault, 0);
|
||||
|
|
@ -177,8 +177,8 @@ static void dm_set_multiple_parameter_values_test(void **state)
|
|||
fault = cwmp_set_multi_parameters_value(&list_set_param_value, &faults_array);
|
||||
assert_non_null(fault);
|
||||
list_for_each_entry (param_fault, &faults_array, list) {
|
||||
fault_code = param_fault->fault;
|
||||
fault_name = param_fault->name;
|
||||
fault_code = param_fault->fault_code;
|
||||
fault_name = param_fault->path_name;
|
||||
break;
|
||||
}
|
||||
assert_int_not_equal(fault, 0);
|
||||
|
|
@ -216,7 +216,7 @@ static void dm_set_multiple_parameter_values_test(void **state)
|
|||
fault = cwmp_set_multi_parameters_value(&list_set_param_value, &faults_array);
|
||||
assert_int_not_equal(fault, 0);
|
||||
list_for_each_entry (param_fault, &faults_array, list) {
|
||||
assert_in_set(param_fault->fault, faults_values, 3);
|
||||
assert_in_set(param_fault->fault_code, faults_values, 3);
|
||||
}
|
||||
cwmp_transaction("commit", true);
|
||||
cwmp_free_all_dm_parameter_list(&list_set_param_value);
|
||||
|
|
@ -224,70 +224,89 @@ static void dm_set_multiple_parameter_values_test(void **state)
|
|||
|
||||
static void dm_add_object_test(void **state)
|
||||
{
|
||||
char *instance = NULL;
|
||||
char *fault;
|
||||
struct object_result res = {0};
|
||||
bool status = false;
|
||||
|
||||
/*
|
||||
* Add valid path and writable object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_add_object("Device.WiFi.SSID.", &instance);
|
||||
assert_non_null(instance);
|
||||
assert_null(fault);
|
||||
status = cwmp_add_object("Device.WiFi.SSID.", &res);
|
||||
assert_non_null(res.instance);
|
||||
assert_true(status);
|
||||
cwmp_transaction("commit", false);
|
||||
FREE(instance);
|
||||
FREE(res.instance);
|
||||
|
||||
/*
|
||||
* Add not valid path object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_add_object("Device.WiFi.SIDl.", &instance);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
assert_null(instance);
|
||||
status = cwmp_add_object("Device.WiFi.SIDl.", &res);
|
||||
assert_false(status);
|
||||
assert_int_equal(res.fault_code, FAULT_9005);
|
||||
assert_null(res.instance);
|
||||
cwmp_transaction("commit", false);
|
||||
FREE(instance);
|
||||
FREE(res.instance);
|
||||
|
||||
/*
|
||||
* Add valid path not writable object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_add_object("Device.DeviceInfo.Processor.", &instance);
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
assert_null(instance);
|
||||
status = cwmp_add_object("Device.DeviceInfo.Processor.", &res);
|
||||
assert_false(status);
|
||||
assert_int_equal(res.fault_code, FAULT_9005);
|
||||
assert_null(res.instance);
|
||||
cwmp_transaction("commit", false);
|
||||
FREE(instance);
|
||||
FREE(res.instance);
|
||||
}
|
||||
|
||||
static void dm_delete_object_test(void **state)
|
||||
{
|
||||
char *fault = NULL;
|
||||
struct object_result res = {0};
|
||||
bool status = false;
|
||||
|
||||
/*
|
||||
* Delete valid path and writable object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_delete_object("Device.WiFi.SSID.2.");
|
||||
assert_null(fault);
|
||||
status = cwmp_delete_object("Device.WiFi.SSID.2.", &res);
|
||||
assert_true(status);
|
||||
cwmp_transaction("commit", true);
|
||||
|
||||
/*
|
||||
* Delete not valid path object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_delete_object("Device.WiFi.SIDl.3.");
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
status = cwmp_delete_object("Device.WiFi.SIDl.3.", &res);
|
||||
assert_false(status);
|
||||
assert_int_equal(res.fault_code, FAULT_9005);
|
||||
cwmp_transaction("commit", true);
|
||||
|
||||
/*
|
||||
* Delte valid path not writable object
|
||||
*/
|
||||
|
||||
memset(&res, 0, sizeof(struct object_result));
|
||||
|
||||
cwmp_transaction("start", false);
|
||||
fault = cwmp_delete_object("Device.DeviceInfo.Processor.2.");
|
||||
assert_non_null(fault);
|
||||
assert_string_equal(fault, "9005");
|
||||
status = cwmp_delete_object("Device.DeviceInfo.Processor.2.", &res);
|
||||
assert_false(status);
|
||||
assert_int_equal(res.fault_code, FAULT_9005);
|
||||
cwmp_transaction("commit", true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue