Make check_value_change independent from libbbfdm

This commit is contained in:
Omar Kallel 2020-12-17 12:10:10 +01:00
parent 19ad191129
commit 0895db688f
13 changed files with 192 additions and 133 deletions

View file

@ -78,6 +78,7 @@ It defines **acs configuration** (like acs url, acs username, etc...). The possi
| `insecure_enable` | boolean | if set to **1**, the CPE checks the validity of the ACS certificates. |
| `http_disable_100continue` | boolean | if set to **1**, disables the http 100 continue behaviour. |
| `dhcp_url` | string | the **url** of ACS server received from the DHCP server Option 43 when **'dhcp_discovery'** option is enabled. This option is updated automatically by the daemon. |
| `ip_version` | string | ip_version of ConnectionRequestURL
### cwmp cpe section ###
@ -295,55 +296,12 @@ root@iopsys:~# icwmpd --help
Usage: icwmpd [OPTIONS]
-b, --boot-event (CWMP daemon) Start CWMP with BOOT event
-g, --get-rpc-methods (CWMP daemon) Start CWMP with GetRPCMethods request to ACS
-c, --command-input (DataModel CLI) Execute data model rpc(s) with commands input
-m, --shell-cli <data model rpc> (DataModel CLI) Execute data model RPC command directly from shell.
-a, --alias-based-addressing (DataModel CLI) Alias based addressing supported
-N, --instance-mode-number (DataModel CLI) Instance mode is Number (Enabled by default)
-A, --instance-mode-alias (DataModel CLI) Instance mode is Alias
-M, --amendment <amendment version> (DataModel CLI) Amendment version (Default amendment version is 2)
-U, --upnp (DataModel CLI) Use UPNP data model paths
-u, --user-acl <public|basic|xxxadmin|superadmin> (DataModel CLI) user access level. Default: superadmin
-t, --time-tracking (DataModel CLI) Tracking time of RPC commands
-E, --evaluating-test (DataModel CLI) Evaluating test format
-f, --file <file path> (DataModel CLI) Execute data model rpc(s) from file
-w, --wep <strength> <passphrase> (WEP KEY GEN) Generate wep keys
-h, --help Display this help text
-v, --version Display the version
root@iopsys:~#
```
For example `'-m'` option is used to execute the datamodel **(libbbfdm)** RPC method through CLI.
if -m is followed by an integer different from 0, so the command result is displayed as output as following:
```
root@iopsys:~# icwmpd -m 1 get_value Device.Time.
{ "parameter": "Device.Time.CurrentLocalTime", "value": "2020-07-08T08:00:39Z", "type": "xsd:dateTime" }
{ "parameter": "Device.Time.Enable", "value": "1", "type": "xsd:boolean" }
{ "parameter": "Device.Time.LocalTimeZone", "value": "CET-1CEST,M3.5.0,M10.5.0/3", "type": "xsd:string" }
{ "parameter": "Device.Time.NTPServer1", "value": "ntp1.sth.netnod.se", "type": "xsd:string" }
{ "parameter": "Device.Time.NTPServer2", "value": "ntp1.gbg.netnod.se", "type": "xsd:string" }
{ "parameter": "Device.Time.NTPServer3", "value": "", "type": "xsd:string" }
{ "parameter": "Device.Time.NTPServer4", "value": "", "type": "xsd:string" }
{ "parameter": "Device.Time.NTPServer5", "value": "", "type": "xsd:string" }
{ "parameter": "Device.Time.Status", "value": "Synchronized", "type": "xsd:string" }
{ "parameter": "Device.Time.X_IOPSYS_EU_LocalTimeZoneName", "value": "Europe/Stockholm", "type": "xsd:string" }
{ "parameter": "Device.Time.X_IOPSYS_EU_SourceInterface", "value": "", "type": "xsd:string" }
root@iopsys:~#
root@iopsys:~# icwmpd -m 1 set_value key Device.Time.Enable 0
{ "status": "1" }
root@iopsys:~#
```
if -m is followed by 0 so no output is displayed in the terminal:
```
root@iopsys:~# icwmpd -m 0 set_value setkey Device.Time.Enable 1
root@iopsys:~#
```
And in this case when -m is followed by 0, the icwmpd command is faster.
Another way to use icwmp cli is via the script `'icwmp'` that can be runned as follow:
There's an icwmp cli that can be called via the script `'icwmp'` as follow:
```
root@iopsys:~# icwmp get Device.Time.
@ -361,43 +319,6 @@ root@iopsys:~# icwmp get Device.Time.
root@iopsys:~#
```
**NOTE: It's the same, whether to use icwmp script or icwmpd command for connecting to datamodel**
```
root@iopsys:~# icwmpd -m 1 inform
{ "parameter": "Device.DeviceInfo.HardwareVersion", "value": "DG400PRIMEA", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.Manufacturer", "value": "iopsys", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ManufacturerOUI", "value": "201F31", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ModelName", "value": "DG400PRIMEA", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ProductClass", "value": "DG400PRIME", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ProvisioningCode", "value": "", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SerialNumber", "value": "J814001008", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SoftwareVersion", "value": "DG400PRIME-A-IOPSYS-4.4.0RC1-191205_1004", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SpecVersion", "value": "1.0", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.AliasBasedAddressing", "value": "false", "type": "xsd:boolean" }
{ "parameter": "Device.ManagementServer.ConnReqJabberID", "value": "", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ConnReqXMPPConnection", "value": "Device.XMPP.Connection.", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ConnectionRequestURL", "value": "http://192.168.117.45:7547/", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ParameterKey", "value": "", "type": "xsd:string" }
root@iopsys:~#
root@iopsys:~# icwmp inform
{ "parameter": "Device.DeviceInfo.HardwareVersion", "value": "DG400PRIMEA", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.Manufacturer", "value": "iopsys", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ManufacturerOUI", "value": "201F31", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ModelName", "value": "DG400PRIMEA", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ProductClass", "value": "DG400PRIME", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.ProvisioningCode", "value": "", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SerialNumber", "value": "J814001008", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SoftwareVersion", "value": "DG400PRIME-A-IOPSYS-4.4.0RC1-191205_1004", "type": "xsd:string" }
{ "parameter": "Device.DeviceInfo.SpecVersion", "value": "1.0", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.AliasBasedAddressing", "value": "false", "type": "xsd:boolean" }
{ "parameter": "Device.ManagementServer.ConnReqJabberID", "value": "", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ConnReqXMPPConnection", "value": "Device.XMPP.Connection.", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ConnectionRequestURL", "value": "http://192.168.117.45:7547/", "type": "xsd:string" }
{ "parameter": "Device.ManagementServer.ParameterKey", "value": "", "type": "xsd:string" }
root@iopsys:~#
```
## Dependencies ##
To successfully build icwmp, the following libraries are needed:
@ -410,7 +331,6 @@ To successfully build icwmp, the following libraries are needed:
| libjson-c | https://s3.amazonaws.com/json-c_releases | MIT |
| libopenssl | http://ftp.fi.muni.cz/pub/openssl/source/ | OpenSSL |
| libcurl | https://dl.uxnr.de/mirror/curl | MIT |
| libbbfdm | https://dev.iopsys.eu/iopsys/bbf.git | LGPL 2.1 |
| libmicroxml | https://dev.freecwmp.org/microxml | LGPL 2.0 |
| libpthread | | |

7
cwmp.c
View file

@ -176,7 +176,7 @@ void cwmp_schedule_session (struct cwmp *cwmp)
is_notify = check_value_change();
}
if(is_notify>0 || access(DM_ENABLED_NOTIFY, F_OK ) < 0)
cwmp_update_enabled_notify_file(cwmp->conf.instance_mode);
cwmp_update_enabled_notify_file();
cwmp_prepare_value_change(cwmp);
free_dm_parameter_all_fromlist(&list_value_change);
if ((error = cwmp_move_session_to_session_send (cwmp, session))) {
@ -573,7 +573,7 @@ int run_session_end_func ()
if (end_session_flag & END_SESSION_SET_NOTIFICATION_UPDATE) {
CWMP_LOG (INFO,"SetParameterAttributes end session: update enabled notify file");
cwmp_update_enabled_notify_file(cwmp_main.conf.instance_mode);
cwmp_update_enabled_notify_file();
}
if (end_session_flag & END_SESSION_TRANSACTION_COMMIT) {
cwmp_transaction_commit();
@ -675,7 +675,6 @@ int cwmp_exit(void)
int main(int argc, char **argv)
{
struct cwmp *cwmp = &cwmp_main;
int error;
pthread_t periodic_event_thread;
@ -692,7 +691,7 @@ int main(int argc, char **argv)
struct sigaction act = {0};
if ((error = cwmp_init(argc, argv, cwmp)))
return error;
return error;
CWMP_LOG(INFO,"STARTING ICWMP with PID :%d", getpid());
cwmp->start_time = time(NULL);

View file

@ -13,6 +13,9 @@
bool transaction_started = false;
int transaction_id = 0;
json_object *old_list_notify = NULL;
json_object *actual_list_notify = NULL;
/*
* Transaction Functions
*/
@ -299,8 +302,14 @@ char* cwmp_set_parameter_attributes(char* parameter_name, char* notification)
/*
* Init Notify Function
*/
int cwmp_update_enabled_notify_file(int instance_mode)
int cwmp_update_enabled_list_notify(int instance_mode, int notify_type)
{
int e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{{"instance_mode", {.int_val=instance_mode}, UBUS_Integer}}, 1, NULL);
int e;
json_object *list_notif_obj = NULL;
e = cwmp_ubus_call("usp.raw", "list_notify", CWMP_UBUS_ARGS{{"instance_mode", {.int_val=instance_mode}, UBUS_Integer}}, 1, &list_notif_obj);
if (notify_type == OLD_LIST_NOTIFY)
json_object_object_get_ex(list_notif_obj, "parameters", &old_list_notify);
else
json_object_object_get_ex(list_notif_obj, "parameters", &actual_list_notify);
return e;
}

119
event.c
View file

@ -140,7 +140,7 @@ void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *par
_list_add(&dm_parameter->list, ilist->prev, ilist);
if (param_name) dm_parameter->name = strdup(param_name);
if (param_data) dm_parameter->data = strdup(param_data);
if (param_type) dm_parameter->type = param_type ? param_type : "xsd:string";
if (param_type) dm_parameter->type = strdup(param_type ? param_type : "xsd:string");
}
void delete_dm_parameter_fromlist(struct cwmp_dm_parameter *dm_parameter)
@ -148,6 +148,7 @@ void delete_dm_parameter_fromlist(struct cwmp_dm_parameter *dm_parameter)
list_del(&dm_parameter->list);
free(dm_parameter->name);
free(dm_parameter->data);
free(dm_parameter->type);
free(dm_parameter);
}
@ -265,65 +266,109 @@ void cwmp_lwnotification()
FREE(msg_out);
}
int cwmp_update_enabled_notify_file()
{
struct cwmp *cwmp = &cwmp_main;
FILE *fp;
json_object *param_obj = NULL, *param_name_obj = NULL, *value_obj = NULL, *type_obj = NULL, *notification_obj = NULL;
int e = cwmp_update_enabled_list_notify(cwmp->conf.instance_mode, OLD_LIST_NOTIFY);
if (e)
return 0;
remove(DM_ENABLED_NOTIFY);
fp = fopen(DM_ENABLED_NOTIFY, "a");
if (fp == NULL) {
return 0;
}
foreach_jsonobj_in_array(param_obj, old_list_notify) {
json_object_object_get_ex(param_obj, "parameter", &param_name_obj);
if (!param_name_obj || strlen((char*)json_object_get_string(param_name_obj))<=0)
continue;
json_object_object_get_ex(param_obj, "value", &value_obj);
json_object_object_get_ex(param_obj, "type", &type_obj);
json_object_object_get_ex(param_obj, "notification", &notification_obj);
cwmp_json_fprintf(fp, 4, CWMP_JSON_ARGS{{"parameter", (char*)json_object_get_string(param_name_obj)}, {"notification", notification_obj?(char*)json_object_get_string(notification_obj):""}, {"value", value_obj?(char*)json_object_get_string(value_obj):""}, {"type", type_obj?(char*)json_object_get_string(type_obj):""}});
}
fclose(fp);
return 1;
}
void get_parameter_value_from_parameters_list(json_object* list_params_obj, char* parameter_name, struct cwmp_dm_parameter **ret_dm_param)
{
json_object *param_obj = NULL, *param_name_obj = NULL, *value_obj = NULL, *type_obj = NULL;
foreach_jsonobj_in_array(param_obj, list_params_obj) {
json_object_object_get_ex(param_obj, "parameter", &param_name_obj);
if (!param_name_obj || strlen((char*)json_object_get_string(param_name_obj))<=0)
continue;
if (strcmp((char*)json_object_get_string(param_name_obj), parameter_name) != 0)
continue;
*ret_dm_param = (struct cwmp_dm_parameter*) calloc(1,sizeof(struct cwmp_dm_parameter));
json_object_object_get_ex(param_obj, "value", &value_obj);
(*ret_dm_param)->name = strdup(parameter_name);
(*ret_dm_param)->data = strdup(value_obj?(char*)json_object_get_string(value_obj):"");
json_object_object_get_ex(param_obj, "type", &type_obj);
(*ret_dm_param)->type = strdup(type_obj?(char*)json_object_get_string(type_obj):"");
break;
}
}
int check_value_change(void)
{
int fault;
FILE *fp;
char buf[512];
char *parameter, *notification = NULL, *value = NULL, *jval = NULL;
struct cwmp *cwmp = &cwmp_main;
struct dm_parameter *dm_parameter;
struct dmctx dmctx = {0};
bool first_iteration =true;
struct cwmp_dm_parameter *dm_parameter = NULL;
json_object *buf_json_obj = NULL;
int is_notify = 0;
fp = fopen(DM_ENABLED_NOTIFY, "r");
if (fp == NULL)
return false;
dm_ctx_init(&dmctx, DM_CWMP, cwmp->conf.amd_version, cwmp->conf.instance_mode);
cwmp_update_enabled_list_notify(cwmp->conf.instance_mode, ACTUAL_LIST_NOTIFY);
while (fgets(buf, 512, fp) != NULL) {
if (!first_iteration)
dm_ctx_init_list_parameter(&dmctx);
first_iteration = false;
dmctx.in_param = "";
int len = strlen(buf);
if (len)
buf[len-1] = '\0';
dmjson_parse_init(buf);
dmjson_get_string("parameter", &jval);
if(!jval || jval[0] == '\0')
buf_json_obj = json_tokener_parse((char*)buf);
cwmp_json_obj_init(buf, &buf_json_obj);
cwmp_json_get_string(buf_json_obj, "parameter", &parameter);
if(parameter == NULL || parameter[0] == '\0')
continue;
parameter = strdup(jval?jval:"");
dmjson_get_string("value", &jval);
value = strdup(jval?jval:"");
dmjson_get_string("notification", &jval);
notification = strdup(jval?jval:"");
dmjson_parse_fini();
fault = dmentry_get_parameter_leaf_value(&dmctx, parameter);
if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
if (notification && strlen(notification)>0 && notification[0] >= '1' && strcmp(dm_parameter->data, value) != 0){
if (notification[0] == '1' || notification[0] == '2')
add_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
if (notification[0] >= '3' )
add_lw_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
cwmp_json_get_string(buf_json_obj, "value", &value);
cwmp_json_get_string(buf_json_obj, "notification", &notification);
if (notification[0] == '1')
is_notify |= NOTIF_PASSIVE;
if (notification[0] == '2')
is_notify |= NOTIF_ACTIVE;
cwmp_json_obj_clean(&buf_json_obj);
get_parameter_value_from_parameters_list(actual_list_notify, parameter, &dm_parameter);
if (dm_parameter == NULL)
continue;
if (notification[0] == '5' || notification[0] == '6')
is_notify |= NOTIF_LW_ACTIVE;
}
if (notification && (strlen(notification) > 0) && (notification[0] >= '1') && (strcmp(dm_parameter->data, value) != 0)){
if (notification[0] == '1' || notification[0] == '2')
add_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
if (notification[0] >= '3' )
add_lw_list_value_change(parameter, dm_parameter->data, dm_parameter->type);
if (notification[0] == '1')
is_notify |= NOTIF_PASSIVE;
if (notification[0] == '2')
is_notify |= NOTIF_ACTIVE;
if (notification[0] == '5' || notification[0] == '6')
is_notify |= NOTIF_LW_ACTIVE;
}
FREE(value);
FREE(notification);
FREE(parameter);
dm_ctx_clean_list_parameter(&dmctx);
FREE(dm_parameter->name);
FREE(dm_parameter->data);
FREE(dm_parameter->type);
FREE(dm_parameter);
}
dm_ctx_clean(&dmctx);
fclose(fp);
return is_notify;
}
@ -645,7 +690,7 @@ void *thread_periodic_check_notify (void *v)
pthread_mutex_lock(&(cwmp->mutex_session_send));
is_notify = check_value_change();
if (is_notify > 0)
cwmp_update_enabled_notify_file(cwmp->conf.instance_mode);
cwmp_update_enabled_notify_file();
pthread_mutex_unlock(&(cwmp->mutex_session_send));
if (is_notify & NOTIF_ACTIVE)
send_active_value_change();

View file

@ -4,7 +4,7 @@
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*

View file

@ -1,8 +1,8 @@
#ifndef __COMMON_H
#define __COMMON_H
#include <libbbfdm/dmdiagnostics.h>
#include <libbbfdm/dmentry.h>
#include <libbbfdm/dmbbfcommon.h>
#define DM_ENABLED_NOTIFY "/etc/icwmpd/.dm_enabled_notify"
enum cwmp_ret_err {
CWMP_OK, /* No Error */
CWMP_GEN_ERR, /* General Error */

View file

@ -7,7 +7,7 @@
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef _CWMP_H__
@ -333,4 +333,5 @@ void cwmp_set_end_session(unsigned int flag);
bool event_exist_in_list(struct cwmp *cwmp, int event);
void *thread_periodic_check_notify (void *v);
void free_dm_parameter_all_fromlist(struct list_head *list);
int cwmp_update_enabled_notify_file();
#endif /* _CWMP_H__ */

View file

@ -1,3 +1,14 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
*/
#ifndef __CWMPUCI_H
#define __CWMPUCI_H
#include <string.h>

View file

@ -9,6 +9,13 @@
#define DM_ROOT_OBJ "Device."
extern bool transaction_started;
extern int transaction_id;
extern json_object *old_list_notify;
extern json_object *actual_list_notify;
enum notify_type {
OLD_LIST_NOTIFY,
ACTUAL_LIST_NOTIFY
};
int cwmp_transaction_start(char *app);
int cwmp_transaction_commit();
@ -22,6 +29,6 @@ char* cwmp_delete_object(char* object_name, char* key);
char* cwmp_get_parameter_names(char* object_name, bool next_level, json_object **parameters);
char* cwmp_get_parameter_attributes(char* parameter_name, json_object **parameters);
char* cwmp_set_parameter_attributes(char* parameter_name, char* notification);
int cwmp_update_enabled_notify_file(int instance_mode);
int cwmp_update_enabled_list_notify(int instance_moden, int notify_type);
#endif /* SRC_DATAMODELIFACE_H_ */

View file

@ -7,12 +7,19 @@
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
*/
#ifndef _JSHN_H__
#define _JSHN_H__
#include <stdio.h>
struct cwmp_json_arg {
char *key;
char *val;
};
#define CWMP_JSON_ARGS (struct cwmp_json_arg[])
int cwmp_handle_downloadFault(char *msg);
int cwmp_handle_uploadFault(char *msg);
int cwmp_handle_dustate_changeFault(char *msg);
@ -24,6 +31,10 @@ int cwmp_handle_getParamAttributes(char *msg);
int cwmp_handle_setParamAttributes(char *msg);
int cwmp_handle_addObject(char *msg);
int cwmp_handle_delObject(char *msg);
void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[]);
void cwmp_json_get_string(json_object *obj, char* key, char** value);
void cwmp_json_obj_init(char *str, json_object **obj);
void cwmp_json_obj_clean(json_object **obj);
#define foreach_jsonobj_in_array(param_obj, parameters) \
int k, array_length = json_object_array_length(parameters); \

View file

@ -4,10 +4,11 @@
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2013-2020 iopsys Software Solutions AB
* Author Omar Kallel <omar.kallel@pivasoftware.com>
*
* Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
*/
#ifndef _FREECWMP_UBUS_H__
#define _FREECWMP_UBUS_H__
#include <stdbool.h>

54
jshn.c
View file

@ -178,3 +178,57 @@ error:
jshn_message_delete();
return -1;
}
void cwmp_json_obj_init(char *str, json_object **obj)
{
if (*obj) {
json_object_put(*obj);
*obj = NULL;
}
*obj = json_tokener_parse(str);
}
void cwmp_json_obj_clean(json_object **obj)
{
if (*obj) {
json_object_put(*obj);
*obj = NULL;
}
}
void cwmp_add_json_obj(json_object *json_obj_out, char *object, char *string)
{
if (object != NULL && string != NULL) {
json_object *json_obj_tmp = json_object_new_string(string);
json_object_object_add(json_obj_out, object, json_obj_tmp);
}
}
void cwmp_json_fprintf(FILE *fp, int argc, struct cwmp_json_arg cwmp_arg[])
{
int i;
char *arg;
json_object *json_obj_out = json_object_new_object();
if (json_obj_out == NULL)
return;
if (argc) {
for (i = 0; i < argc; i++) {
cwmp_add_json_obj(json_obj_out, cwmp_arg[i].key, cwmp_arg[i].val);
}
arg = (char *)json_object_to_json_string(json_obj_out);
fprintf(fp, "%s\n", arg);
}
json_object_put(json_obj_out);
}
void cwmp_json_get_string(json_object *obj, char* key, char** value)
{
json_object *key_obj = NULL;
json_object_object_get_ex(obj, key, &key_obj);
*value = strdup(key_obj?(char*)json_object_get_string(key_obj):"");
if (key_obj) {
json_object_put(key_obj);
key_obj = NULL;
}
}

1
ubus.c
View file

@ -7,6 +7,7 @@
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Author Omar Kallel <omar.kallel@pivasoftware.com>
* Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
*/