freecwmp
[Top] [All Lists]

Re: [PATCH 25/27] add ubus listner for set parameter attribute Contribut

To: mohamed.kallel@pivasoftware.com
Subject: Re: [PATCH 25/27] add ubus listner for set parameter attribute Contributed by Inteno Broadband Technology AB & PIVA SOFTWARE
From: Luka Perkov <freecwmp@lukaperkov.net>
Date: Sat, 8 Dec 2012 12:12:41 +0100
Cc: freecwmp@linux-mips.org, ahmed.zribi@pivasoftware.com, freecwmp@lukaperkov.net, jogo@openwrt.org
In-reply-to: <1354809292-2467-26-git-send-email-mohamed.kallel@pivasoftware.com>
Mail-followup-to: mohamed.kallel@pivasoftware.com, freecwmp@linux-mips.org, ahmed.zribi@pivasoftware.com, jogo@openwrt.org
Original-recipient: rfc822;freecwmp@linux-mips.org
References: <mohamed.kallel@pivasoftware.com> <1354809292-2467-1-git-send-email-mohamed.kallel@pivasoftware.com> <1354809292-2467-26-git-send-email-mohamed.kallel@pivasoftware.com>
Sender: freecwmp-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
Missing commit message. Contributed by must go in commit message and not
in subject.

On Thu, Dec 06, 2012 at 04:54:50PM +0100, Mohamed wrote:
> 
> Signed-off-by: Mohamed <mohamed.kallel@pivasoftware.com>
> Signed-off-by: Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
> ---
>  src/external.c |   16 ++++++++++++++++
>  src/external.h |    2 ++
>  src/ubus.c     |   31 +++++++++++++++++++++++++++++++
>  src/xml.c      |   20 +++++++++++++++++---
>  4 files changed, 66 insertions(+), 3 deletions(-)
> 
> diff --git a/src/external.c b/src/external.c
> index 7eec751..a033781 100644
> --- a/src/external.c
> +++ b/src/external.c
> @@ -75,6 +75,22 @@ void external_fetch_set_param_val_resp_status(char 
> **status)
>       external_method_status = NULL;
>  }
>  
> +void external_set_param_attr_resp (char *status, char *fault)
> +{
> +     free(external_method_status);
> +     external_method_status = status ? strdup(status) : NULL;
> +     free(external_method_fault);
> +     external_method_fault = fault ? strdup(fault) : NULL;
> +}
> +
> +void external_fetch_set_param_attr_resp (char **status, char **fault)
> +{
> +     *status = external_method_status;
> +     external_method_status = NULL;
> +     *fault = external_method_fault;
> +     external_method_fault = NULL;
> +}
> +
>  int external_get_action_data(char *action, char *name, char **value)
>  {
>       struct external_parameter *external_parameter;
> diff --git a/src/external.h b/src/external.h
> index 77165ee..489d215 100644
> --- a/src/external.h
> +++ b/src/external.h
> @@ -30,6 +30,8 @@ struct external_parameter {
>  
>  void external_set_param_val_resp_status (char *status);
>  void external_fetch_set_param_val_resp_status (char **status);
> +void external_set_param_attr_resp (char *status, char *fault);
> +void external_fetch_set_param_attr_resp (char **status, char **fault);
>  int external_get_action(char *action, char *name, char *arg);
>  int external_get_action_data(char *action, char *name, char **value);
>  int external_get_action_write(char *action, char *name, char *arg);
> diff --git a/src/ubus.c b/src/ubus.c
> index e852ed4..8502805 100644
> --- a/src/ubus.c
> +++ b/src/ubus.c
> @@ -281,6 +281,36 @@ freecwmpd_handle_get_param_attributes(struct 
> ubus_context *ctx, struct ubus_obje
>       return 0;
>  }
>  
> +static enum set_param_attributes {
> +     SET_PARAM_ATTRIBUTES_SUCCESS,
> +     SET_PARAM_ATTRIBUTES_FAULT,
> +     __SET_PARAM_ATTRIBUTES_MAX
> +};
> +
> +static const struct blobmsg_policy set_param_attributes_policy[] = {
> +             [SET_PARAM_ATTRIBUTES_SUCCESS] = { .name = "success", .type = 
> BLOBMSG_TYPE_STRING },

Too many tabs.

> +     [SET_PARAM_ATTRIBUTES_FAULT] = { .name = "fault_code", .type = 
> BLOBMSG_TYPE_STRING },
> +};
> +
> +static int
> +freecwmpd_handle_set_param_attributes(struct ubus_context *ctx, struct 
> ubus_object *obj,
> +                     struct ubus_request_data *req, const char *method,
> +                     struct blob_attr *msg)
> +{
> +     struct blob_attr *tb[__SET_PARAM_ATTRIBUTES_MAX];
> +
> +     blobmsg_parse(set_param_attributes_policy, 
> ARRAY_SIZE(set_param_attributes_policy), tb,
> +                   blob_data(msg), blob_len(msg));
> +
> +     freecwmp_log_message(NAME, L_NOTICE,
> +                          "triggered ubus set_parameter_attributes\n");
> +
> +     external_set_param_attr_resp(tb[SET_PARAM_ATTRIBUTES_SUCCESS] ? 
> blobmsg_data(tb[SET_PARAM_ATTRIBUTES_SUCCESS]) : NULL,
> +                     tb[SET_PARAM_ATTRIBUTES_FAULT] ? 
> blobmsg_data(tb[SET_PARAM_ATTRIBUTES_FAULT]) : NULL);
> +
> +     return 0;
> +}
> +
>  static enum set_param_values_fault {
>       SET_PARAM_VALUES_FAULT_PARAM,
>       SET_PARAM_VALUES_FAULT__FAULT,
> @@ -361,6 +391,7 @@ static const struct ubus_method freecwmp_methods[] = {
>       UBUS_METHOD("set_parameter_values_status", 
> freecwmpd_handle_set_param_values_status, set_param_values_status_policy),
>       UBUS_METHOD("get_parameter_names", freecwmpd_handle_get_param_names, 
> get_param_names_policy),
>       UBUS_METHOD("get_parameter_attributes", 
> freecwmpd_handle_get_param_attributes, get_param_attributes_policy),
> +     UBUS_METHOD("set_parameter_attributes", 
> freecwmpd_handle_set_param_attributes, set_param_attributes_policy),
>  };
>  
>  static struct ubus_object_type main_object_type =
> diff --git a/src/xml.c b/src/xml.c
> index a8f82c7..e46c50c 100644
> --- a/src/xml.c
> +++ b/src/xml.c
> @@ -6,6 +6,7 @@
>   *
>   *   Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
>   *   Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
> + *  Copyright (C) 2012 Mohamed Kallel <mohamed.kallel@pivasoftware.com>

Tabs not spaces.

>   */
>  
>  #include <stdbool.h>
> @@ -861,7 +862,7 @@ static int 
> xml_handle_set_parameter_attributes(mxml_node_t *body_in,
>                                              mxml_node_t *tree_out) {
>  
>       mxml_node_t *n, *b = body_in;
> -     char *c, *parameter_name, *parameter_notification;
> +     char *c, *parameter_name, *parameter_notification, *success=NULL, 
> *fault=NULL;
>       uint8_t attr_notification_update;
>  
>       /* handle cwmp:SetParameterAttributes */
> @@ -913,15 +914,28 @@ static int 
> xml_handle_set_parameter_attributes(mxml_node_t *body_in,
>       if (external_set_action_execute("notification"))
>               return -1;
>  
> +     external_fetch_set_param_attr_resp(&success, &fault);
> +
> +     if (fault && fault[0]=='9') goto error; //TODO KMD return a fault 
> message here with fault indicated in the fault string

Fix spaces and comment.

> +
> +     if(!success) goto error; //TODO KMD return a fault message here

Fix comment.

> +
>       b = mxmlFindElement(tree_out, tree_out, "soap_env:Body", NULL, NULL, 
> MXML_DESCEND);
> -     if (!b) return -1;
> +     if (!b) goto error;
>  
>       b = mxmlNewElement(b, "cwmp:SetParameterAttributesResponse");
> -     if (!b) return -1;
> +     if (!b) goto error;
>  
>       config_load();
>  
> +     free(success);
> +     free(fault);
>       return 0;
> +
> +error:
> +     free(success);
> +     free(fault);
> +     return -1;
>  }
>  
>  static int xml_handle_download(mxml_node_t *body_in,
> -- 
> 1.7.4.1

Luka 

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