fix bug set notification and set parameter value

This commit is contained in:
zribiahmed 2013-02-17 08:28:04 +00:00
parent 5b8d8fcbf2
commit bcabb381a6
8 changed files with 40 additions and 35 deletions

View file

@ -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, &notification,
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));
}

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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`

View file

@ -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"

View file

@ -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
}

View file

@ -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;