diff --git a/bin/Makefile.am b/bin/Makefile.am index 21a9ea6..49b07ad 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -16,7 +16,7 @@ icwmpd_SOURCES = \ ../ubus.c \ ../xml.c \ ../diagnostic.c \ - ../datamodelIface.c \ + ../datamodel_interface.c \ ../zlib.c icwmpd_CFLAGS = \ diff --git a/datamodelIface.c b/datamodel_interface.c similarity index 97% rename from datamodelIface.c rename to datamodel_interface.c index 42195ed..1459c94 100644 --- a/datamodelIface.c +++ b/datamodel_interface.c @@ -1,4 +1,4 @@ -#include "datamodelIface.h" +#include "datamodel_interface.h" char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters) { @@ -21,7 +21,7 @@ char* cwmp_get_parameter_values(char *parameter_name, json_object **parameters) char* cwmp_set_parameter_value(char* parameter_name, char* value, char* parameter_key) { json_object *set_res; - int e = cwmp_ubus_call("usp.raw", "set", CWMP_UBUS_ARGS{{"path", {.str_val=parameter_name}, UBUS_String},{"value", value, UBUS_String}, {"key", parameter_key, UBUS_String}}, 2, &set_res); + int e = cwmp_ubus_call("usp.raw", "set", CWMP_UBUS_ARGS{{"path", {.str_val=parameter_name}, UBUS_String},{"value", {.str_val=value}, UBUS_String}, {"key", {.str_val=parameter_key}, UBUS_String}}, 3, &set_res); if (e < 0 || set_res == NULL) return "9002"; diff --git a/inc/datamodelIface.h b/inc/datamodel_interface.h similarity index 100% rename from inc/datamodelIface.h rename to inc/datamodel_interface.h diff --git a/inc/ubus.h b/inc/ubus.h index f8a75a1..63ff8dc 100644 --- a/inc/ubus.h +++ b/inc/ubus.h @@ -1,5 +1,15 @@ -#ifndef UBUS_H_ -#define UBUS_H_ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Copyright (C) 2012 Luka Perkov + */ + + +#ifndef _FREECWMP_UBUS_H__ +#define _FREECWMP_UBUS_H__ #include #define ARRAY_MAX 8 diff --git a/inc/xml.h b/inc/xml.h index 55b644a..a97f66d 100644 --- a/inc/xml.h +++ b/inc/xml.h @@ -120,6 +120,12 @@ struct cwmp_param_fault { int fault; }; +struct cwmp_param_value { + struct list_head list; + char *param; + char *value; +}; + struct rpc_cpe_method { const char *name; int (*handler)(struct session *session, struct rpc *rpc); diff --git a/xml.c b/xml.c index 8b52f92..441b45e 100644 --- a/xml.c +++ b/xml.c @@ -34,7 +34,7 @@ #include #include #endif -#include "datamodelIface.h" +#include "datamodel_interface.h" LIST_HEAD(list_download); LIST_HEAD(list_upload); @@ -158,6 +158,36 @@ void cwmp_del_list_fault_param(struct cwmp_param_fault *param_fault) free(param_fault->name); free(param_fault); } + +void cwmp_add_list_param_value(char *param, char* value, struct list_head *list_param_value) +{ + struct cwmp_param_value *param_value = NULL; + if (param == NULL) + param = ""; + + param_value = calloc(1, sizeof(struct cwmp_param_value)); + list_add_tail(¶m_value->list, list_param_value); + param_value->param = strdup(param); + param_value->value = strdup(value); +} + +void cwmp_del_list_param_value(struct cwmp_param_value *param_value) +{ + list_del(¶m_value->list); + free(param_value->param); + free(param_value->value); + free(param_value); +} + +void cwmp_free_all_list_param_value(struct list_head *list_param_value) +{ + struct cwmp_param_value *param_value; + while (list_param_value->next != list_param_value) { + param_value = list_entry(list_param_value->next, struct cwmp_param_value, list); + cwmp_del_list_param_value(param_value); + } +} + static mxml_node_t * /* O - Element node or NULL */ mxmlFindElementOpaque(mxml_node_t *node, /* I - Current node */ mxml_node_t *top, /* I - Top node */ @@ -1537,6 +1567,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc LIST_HEAD(list_fault_param); rpc->list_set_value_fault = &list_fault_param; + LIST_HEAD(list_param_value); while (b) { if (b && b->type == MXML_OPAQUE && b->value.opaque && @@ -1578,30 +1609,35 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc parameter_value = strdup(""); } if (parameter_name && parameter_value) { - char *err = cwmp_set_parameter_value(parameter_name, parameter_value, parameter_key); - if (err) { - cwmp_add_list_fault_param(parameter_name, atoi(err), rpc->list_set_value_fault); - fault_code = FAULT_CPE_INVALID_ARGUMENTS; - } + cwmp_add_list_param_value(parameter_name, parameter_value, &list_param_value); parameter_name = NULL; FREE(parameter_value); } b = mxmlWalkNext(b, session->body_in, MXML_DESCEND); } - if (fault_code == FAULT_CPE_INVALID_ARGUMENTS) { - goto fault; - } - b = mxmlFindElement(session->body_in, session->body_in, "ParameterKey", NULL, NULL, MXML_DESCEND); if(!b) { fault_code = FAULT_CPE_REQUEST_DENIED; goto fault; } - b = mxmlWalkNext(b, session->tree_in, MXML_DESCEND_FIRST); if (b && b->type == MXML_OPAQUE && b->value.opaque) parameter_key = b->value.opaque; + struct cwmp_param_value *param_value; + + list_for_each_entry(param_value, &list_param_value, list) { + char *err = cwmp_set_parameter_value(param_value->param, param_value->value, parameter_key); + if (err) { + cwmp_add_list_fault_param(parameter_name, atoi(err), rpc->list_set_value_fault); + fault_code = FAULT_CPE_INVALID_ARGUMENTS; + } + } + + cwmp_free_all_list_param_value(&list_param_value); + if (fault_code == FAULT_CPE_INVALID_ARGUMENTS) { + goto fault; + } b = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);