From bcabb381a69f9bd655976a169fe82209c951d1b3 Mon Sep 17 00:00:00 2001 From: zribiahmed Date: Sun, 17 Feb 2013 08:28:04 +0000 Subject: [PATCH] fix bug set notification and set parameter value --- src/event.c | 14 ++----------- src/external.c | 14 ------------- src/inc/cwmp.h | 2 +- src/inc/external.h | 1 - src/scripts/freecwmp.sh | 6 +++++- src/scripts/functions/common | 26 ++++++++++++++++++++++--- src/scripts/functions/management_server | 6 +++--- src/ubus.c | 6 ++++++ 8 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/event.c b/src/event.c index 04b21b9..05684ba 100644 --- a/src/event.c +++ b/src/event.c @@ -134,37 +134,27 @@ void parameter_container_delete_all(struct list_head *list) } } -void cwmp_add_notification (char *name, char *value, char *type) +void cwmp_add_notification (char *name, char *value, char *attribute, char *type) { char *notification = NULL; struct event_container *event_container; struct cwmp *cwmp = &cwmp_main; - external_get_action_data("notification", name, ¬ification, - cwmp_handle_getParamAttributes); - if (!notification || notification[0]=='0') - { - free(notification); - return; - } external_add_list_value_change(name, value, type); pthread_mutex_lock (&(cwmp->mutex_session_queue)); - if (notification[0]=='2') + if (attribute[0]=='2') { event_container = cwmp_add_event_container(cwmp, EVENT_IDX_4VALUE_CHANGE, ""); if (event_container == NULL) { pthread_mutex_unlock (&(cwmp->mutex_session_queue)); - free(notification); return; } cwmp_save_event_container(cwmp,event_container); pthread_mutex_unlock (&(cwmp->mutex_session_queue)); pthread_cond_signal(&(cwmp->threshold_session_send)); - free(notification); return; } - free(notification); pthread_mutex_unlock (&(cwmp->mutex_session_queue)); } diff --git a/src/external.c b/src/external.c index 67928cf..067ca26 100644 --- a/src/external.c +++ b/src/external.c @@ -212,20 +212,6 @@ error: return -1; } -int external_get_action_data(char *action, char *name, char **value, int external_handler(char *msg)) -{ - struct parameter_container *parameter_container; - external_get_action(action, name, NULL, external_handler); - if (external_list_parameter.next!=&external_list_parameter) { - parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list); - if (parameter_container->data) - *value = strdup(parameter_container->data); - parameter_container_delete(parameter_container); - } - external_free_list_parameter(); - return 0; -} - int external_get_action_write(char *action, char *name, char *arg) { pthread_mutex_lock(&external_mutex_exec); diff --git a/src/inc/cwmp.h b/src/inc/cwmp.h index f1c43d3..370f815 100644 --- a/src/inc/cwmp.h +++ b/src/inc/cwmp.h @@ -198,7 +198,7 @@ struct event_container *cwmp_add_event_container (struct cwmp *cwmp, int event_i int event_remove_all_event_container(struct session *session, int rem_from); void cwmp_save_event_container (struct cwmp *cwmp,struct event_container *event_container); void *thread_event_periodic (void *v); -void cwmp_add_notification (char *name, char *value, char *type); +void cwmp_add_notification (char *name, char *value, char *attribute, char *type); int netlink_init(void); char * mix_get_time(void); diff --git a/src/inc/external.h b/src/inc/external.h index 05c2119..1ff3ee7 100644 --- a/src/inc/external.h +++ b/src/inc/external.h @@ -37,7 +37,6 @@ void external_fetch_addObjectResp (char **instance, char **status, char **fault) void external_delObjectResp (char *status, char *fault); void external_fetch_delObjectResp (char **status, char **fault); int external_get_action(char *action, char *name, char *arg, int external_handler(char *msg)); -int external_get_action_data(char *action, char *name, char **value, int external_handler(char *msg)); int external_get_action_write(char *action, char *name, char *arg); int external_get_action_execute(int external_handler(char *msg)); int external_set_action_write(char *action, char *name, char *value, char *change); diff --git a/src/scripts/freecwmp.sh b/src/scripts/freecwmp.sh index d63d48e..fe066c7 100644 --- a/src/scripts/freecwmp.sh +++ b/src/scripts/freecwmp.sh @@ -496,7 +496,11 @@ if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then if [ "$__fault_count" = "0" ]; then # applying /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit - freecwmp_output "" "" "" "" "" "0" + if [ "$action" = "apply_notification" ]; then + freecwmp_output "" "" "" "" "" "" "" "0" + elif [ "$action" = "apply_value" ]; then + freecwmp_output "" "" "" "" "" "0" + fi else let n=$__fault_count-1 for i in `seq 0 $n` diff --git a/src/scripts/functions/common b/src/scripts/functions/common index 09d5075..2d1ea37 100644 --- a/src/scripts/functions/common +++ b/src/scripts/functions/common @@ -43,8 +43,9 @@ freecwmp_output() { local fault_code="$5" local status="$6" local instance="$7" + local success="$8" - echo `freecwmp_json_output "$parameter" "$value" "$permissions" "$type" "$fault_code" "$status" "$instance"` + echo `freecwmp_json_output "$parameter" "$value" "$permissions" "$type" "$fault_code" "$status" "$instance" "$success"` fi } @@ -58,6 +59,7 @@ freecwmp_json_output() { local fault_code="$5" local status="$6" local instance="$7" + local success="$8" if [ "$type" = "" ]; then type="xsd:string" @@ -104,13 +106,19 @@ freecwmp_json_output() { json_close_object MSG=`json_dump` ;; - apply_value|\ - apply_notification) + apply_value) json_init json_add_string "status" "$status" json_close_object MSG=`json_dump` ;; + apply_notification) + json_init + json_add_string "success" "$success" + json_add_string "fault_code" "$fault_code" + json_close_object + MSG=`json_dump` + ;; esac echo "$MSG" @@ -341,6 +349,18 @@ freecwmp_get_parameter_notification() { eval "export -- \"$_dest=$_val\"" } +freecwmp_notify() { + local parm="$1" + local val="$2" + local attribute + local type="$3" + + freecwmp_get_parameter_notification "attribute" "$parm" + if [ "$attribute" != "0" ];then + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 notify '{ "parameter": "'$parm'", "value": "'$val'", "attribute": "'$attribute'", "type": "'$type'" }' & + fi +} + freecwmp_set_parameter_notification() { local _parm="$1" local _val="$2" diff --git a/src/scripts/functions/management_server b/src/scripts/functions/management_server index 4831285..5bc3b9d 100644 --- a/src/scripts/functions/management_server +++ b/src/scripts/functions/management_server @@ -30,7 +30,7 @@ case "$action" in set_value) local url=$1 /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.acs.url="$url" - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 notify '{ "parameter": "'$parm'", "value": "'$url'", "type": "'$type'" }' 2>&1 > /dev/null & + freecwmp_notify "$parm" "$url" "$type" ;; set_notification) local val=$1 @@ -129,7 +129,7 @@ case "$action" in set_value) local val=$1 /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set cwmp.acs.ParameterKey="$val" - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 notify '{ "parameter": "'$parm'", "value": "'$val'", "type": "'$type'" }' 2>&1 > /dev/null + freecwmp_notify "$parm" "$val" "$type" ;; set_notification) local val=$1 @@ -782,7 +782,7 @@ get_management_server_generic() { check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi freecwmp_get_parameter_value "val" "$1" - ubus_freecwmp_output "$1" "$val" + freecwmp_output "$1" "$val" return $FAULT_CPE_NO_FAULT } diff --git a/src/ubus.c b/src/ubus.c index ce9bf48..614a3c8 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -25,6 +25,7 @@ static struct blob_buf b; enum notify { NOTIFY_PARAM, NOTIFY_VALUE, + NOTIFY_ATTRIB, NOTIFY_TYPE, __NOTIFY_MAX }; @@ -32,6 +33,7 @@ enum notify { static const struct blobmsg_policy notify_policy[] = { [NOTIFY_PARAM] = { .name = "parameter", .type = BLOBMSG_TYPE_STRING }, [NOTIFY_VALUE] = { .name = "value", .type = BLOBMSG_TYPE_STRING }, + [NOTIFY_ATTRIB] = { .name = "attribute", .type = BLOBMSG_TYPE_STRING }, [NOTIFY_TYPE] = { .name = "type", .type = BLOBMSG_TYPE_STRING }, }; @@ -48,10 +50,14 @@ cwmp_handle_notify(struct ubus_context *ctx, struct ubus_object *obj, if (!tb[NOTIFY_PARAM]) return UBUS_STATUS_INVALID_ARGUMENT; + if (!tb[NOTIFY_ATTRIB]) + return UBUS_STATUS_INVALID_ARGUMENT; + CWMP_LOG(INFO, "triggered ubus notification parameter %s", blobmsg_data(tb[NOTIFY_PARAM])); cwmp_add_notification(blobmsg_data(tb[NOTIFY_PARAM]), tb[NOTIFY_VALUE]? blobmsg_data(tb[NOTIFY_VALUE]) : NULL, + blobmsg_data(tb[NOTIFY_ATTRIB]), tb[NOTIFY_TYPE]? blobmsg_data(tb[NOTIFY_TYPE]) : NULL); return 0;