freecwmp
[Top] [All Lists]

[PATCH v2 01/10] Add ubus listner get_parameter_values.

To: freecwmp@linux-mips.org
Subject: [PATCH v2 01/10] Add ubus listner get_parameter_values.
From: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
Date: Fri, 28 Dec 2012 16:59:38 +0100
Cc: freecwmp@lukaperkov.net, jogo@openwrt.org, Mohamed <mohamed.kallel@pivasoftware.com>, Ahmed Zribi <ahmed.zribi@pivasoftware.com>
In-reply-to: <1356710387-3043-1-git-send-email-mohamed.kallel@pivasoftware.com>
Original-recipient: rfc822;freecwmp@linux-mips.org
References: <1356710387-3043-1-git-send-email-mohamed.kallel@pivasoftware.com>
Sender: freecwmp-bounce@linux-mips.org
From: Mohamed <mohamed.kallel@pivasoftware.com>

The  ubus listner get_parameter_values  allows to get the freecwmp output from 
extenal command.
Contributed by Inteno Broadband Technology AB/

Signed-off-by: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
Signed-off-by: Ahmed Zribi <ahmed.zribi@pivasoftware.com>
---
 src/external.c |   32 ++++++++++++++++++++++++++++++++
 src/external.h |   16 ++++++++++++++++
 src/ubus.c     |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/src/external.c b/src/external.c
index 2abed40..46a4931 100644
--- a/src/external.c
+++ b/src/external.c
@@ -25,6 +25,38 @@
 #include "freecwmp.h"
 
 static struct uloop_process uproc;
+LIST_HEAD(external_list_parameter);
+
+void external_add_list_paramameter(char *param_name, char *param_data, char 
*param_type, char *fault_code)
+{
+       struct external_parameter *external_parameter;
+       struct list_head *ilist; int i =0;
+       external_parameter = calloc(1, sizeof(struct external_parameter));
+       list_add_tail(&external_parameter->list, &external_list_parameter);
+       if (param_name) external_parameter->name = strdup(param_name);
+       if (param_data) external_parameter->data = strdup(param_data);
+       if (param_type) external_parameter->type = strdup(param_type);
+       if (fault_code) external_parameter->fault_code = strdup(fault_code);
+}
+
+void external_parameter_delete(struct external_parameter *external_parameter)
+{
+       list_del(&external_parameter->list);
+       free(external_parameter->name);
+       free(external_parameter->data);
+       free(external_parameter->type);
+       free(external_parameter->fault_code);
+       free(external_parameter);
+}
+
+void external_free_list_parameter()
+{
+       struct external_parameter *external_parameter;
+       while (external_list_parameter.next != &external_list_parameter) {
+               external_parameter = list_entry(external_list_parameter.next, 
struct external_parameter, list);
+               external_parameter_delete(external_parameter);
+       }
+}
 
 int external_get_action(char *action, char *name, char **value)
 {
diff --git a/src/external.h b/src/external.h
index 8606266..0e09415 100644
--- a/src/external.h
+++ b/src/external.h
@@ -9,6 +9,7 @@
 
 #ifndef _FREECWMP_EXTERNAL_H__
 #define _FREECWMP_EXTERNAL_H__
+#include <libubox/list.h>
 
 #ifdef DUMMY_MODE
 static char *fc_script = "./ext/openwrt/scripts/freecwmp.sh";
@@ -17,11 +18,26 @@ static char *fc_script = "/usr/sbin/freecwmp";
 #endif
 static char *fc_script_set_actions = "/tmp/freecwmp_set_action_values.sh";
 
+/*
+ * external_parameter structure is used to get data from external command when 
a parameter method is triggered
+ * The (*data) is used as notification for GetParameterAttribute; as writable 
for GetParameterNames; as value for GetParameterValues
+ */
+struct external_parameter {
+       struct list_head list;
+       char *name;
+       char *data;
+       char *type;
+       char *fault_code;
+};
+
 int external_get_action(char *action, char *name, char **value);
 int external_set_action_write(char *action, char *name, char *value);
 int external_set_action_execute();
 int external_simple(char *arg);
 int external_download(char *url, char *size);
+void external_add_list_paramameter(char *param_name, char *param_data, char 
*param_type, char *fault_code);
+void external_free_list_parameter();
+void external_parameter_delete(struct external_parameter *external_parameter);
 
 #endif
 
diff --git a/src/ubus.c b/src/ubus.c
index 13f0a54..3cc3c69 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -16,6 +16,7 @@
 #include "config.h"
 #include "cwmp.h"
 #include "freecwmp.h"
+#include "external.h"
 
 static struct ubus_context *ctx = NULL;
 static struct ubus_object main_object;
@@ -155,10 +156,51 @@ freecwmpd_handle_command(struct ubus_context *ctx, struct 
ubus_object *obj,
        return 0;
 }
 
+static enum get_param_values {
+       GET_PARAM_VALUES_PARAM,
+       GET_PARAM_VALUES_VALUE,
+       GET_PARAM_VALUES_TYPE,
+       GET_PARAM_VALUES_FAULT,
+       __GET_PARAM_VALUES_MAX
+};
+
+static const struct blobmsg_policy get_param_values_policy[] = {
+       [GET_PARAM_VALUES_PARAM] = { .name = "parameter", .type = 
BLOBMSG_TYPE_STRING },
+       [GET_PARAM_VALUES_VALUE] = { .name = "value", .type = 
BLOBMSG_TYPE_STRING },
+       [GET_PARAM_VALUES_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING 
},
+       [GET_PARAM_VALUES_FAULT] = { .name = "fault_code", .type = 
BLOBMSG_TYPE_STRING },
+};
+
+static int
+freecwmpd_handle_get_param_values(struct ubus_context *ctx, struct ubus_object 
*obj,
+                       struct ubus_request_data *req, const char *method,
+                       struct blob_attr *msg)
+{
+       struct blob_attr *tb[__GET_PARAM_VALUES_MAX];
+
+       blobmsg_parse(get_param_values_policy, 
ARRAY_SIZE(get_param_values_policy), tb,
+                     blob_data(msg), blob_len(msg));
+
+       if (!tb[GET_PARAM_VALUES_PARAM])
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
+       lfc_log_message(NAME, L_NOTICE,
+                            "triggered ubus get_parameter_values for the 
parameter %s\n",
+                            blobmsg_data(tb[GET_PARAM_VALUES_PARAM]));
+
+       external_add_list_paramameter(blobmsg_data(tb[GET_PARAM_VALUES_PARAM]),
+                       tb[GET_PARAM_VALUES_VALUE] ? 
blobmsg_data(tb[GET_PARAM_VALUES_VALUE]) : NULL,
+                       tb[GET_PARAM_VALUES_TYPE] ? 
blobmsg_data(tb[GET_PARAM_VALUES_TYPE]) : "xsd:string",
+                       tb[GET_PARAM_VALUES_FAULT] ? 
blobmsg_data(tb[GET_PARAM_VALUES_FAULT]) : NULL);
+
+       return 0;
+}
+
 static const struct ubus_method freecwmp_methods[] = {
        UBUS_METHOD("notify", freecwmpd_handle_notify, notify_policy),
        UBUS_METHOD("inform", freecwmpd_handle_inform, inform_policy),
        UBUS_METHOD("command", freecwmpd_handle_command, command_policy),
+       UBUS_METHOD("get_parameter_values", freecwmpd_handle_get_param_values, 
get_param_values_policy),
 };
 
 static struct ubus_object_type main_object_type =
-- 
1.7.4.1


<Prev in Thread] Current Thread [Next in Thread>