Hi Luka
ubus data model patch [01/27] enclosed
Regards
MOHAMED Kallel
------------------------ubus data model patch [01/27]
---------------------------------
>From 18e2d931a89158a69e7f25705dbf2dbb1f41d3fd Mon Sep 17 00:00:00 2001
From: Mohamed <mohamed.kallel@pivasoftware.com>
Date: Fri, 30 Nov 2012 18:33:01 +0100
Subject: [PATCH 01/27] add ubus listner get_parameter_values. This
listener allows to get the freecwmp output from extenal command.
Contributed by Inteno Broadband Technology AB
Signed-off-by: Mohamed <mohamed.kallel@pivasoftware.com>
---
src/external.c | 13 +++++++++++++
src/external.h | 10 ++++++++++
src/ubus.c | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/src/external.c b/src/external.c
index 9ac7b36..c9c768f 100644
--- a/src/external.c
+++ b/src/external.c
@@ -25,6 +25,19 @@
#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);
+}
int external_get_action(char *action, char *name, char **value)
{
diff --git a/src/external.h b/src/external.h
index 8606266..64b4c6b 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,20 @@ static char *fc_script = "/usr/sbin/freecwmp";
#endif
static char *fc_script_set_actions = "/tmp/freecwmp_set_action_values.sh";
+struct external_parameter {
+ struct list_head list;
+ char *name;
+ char *data; /* notification for GetParameterAttribute; writable for
GetParameterNames; value for GetParameterValues*/
+ 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);
#endif
diff --git a/src/ubus.c b/src/ubus.c
index c10170d..d5437f9 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;
@@ -157,10 +158,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;
+
+ freecwmp_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
|