bbf: cleanup

- fix flawfinder and cppcheck issues
 - remove all unused functions
This commit is contained in:
Amin Ben Ramdhane 2021-02-04 00:37:54 +01:00
parent a528164bad
commit 92d1f62cab
68 changed files with 926 additions and 5546 deletions

View file

@ -32,10 +32,8 @@ char *get_diagnostics_option_fallback_def(char *sec_name, char *option, char *de
void set_diagnostics_option(char *sec_name, char *option, char *value)
{
struct uci_section *section = NULL;
check_create_dmmap_package(DMMAP_DIAGNOSTIGS);
section = dmuci_walk_section_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
struct uci_section *section = dmuci_walk_section_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
if (!section)
dmuci_set_value_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, "", sec_name);
@ -44,10 +42,8 @@ void set_diagnostics_option(char *sec_name, char *option, char *value)
void init_diagnostics_operation(char *sec_name, char *operation_path)
{
struct uci_section *section = NULL;
check_create_dmmap_package(DMMAP_DIAGNOSTIGS);
section = dmuci_walk_section_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
struct uci_section *section = dmuci_walk_section_bbfdm(DMMAP_DIAGNOSTIGS, sec_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
if (section)
dmuci_delete_by_section_bbfdm(section, NULL, NULL);
@ -491,9 +487,9 @@ static void ftp_upload_per_packet(libtrace_packet_t *packet)
static int extract_stats(char *dump_file, int proto, int diagnostic_type)
{
libtrace_t *trace = NULL;
libtrace_packet_t *packet = NULL;
libtrace_packet_t *packet = trace_create_packet();
read_next = 1;
packet = trace_create_packet();
if (packet == NULL) {
libtrace_cleanup(trace, packet);
return -1;
@ -552,8 +548,9 @@ static char *get_default_gateway_device(void)
FILE *f = fopen(PROC_ROUTE, "r");
if (f != NULL) {
char line[100], *p, *c, *saveptr;
while(fgets(line , 100 , f)) {
char line[100] = {0}, *p = NULL, *c = NULL, *saveptr = NULL;
while(fgets(line, sizeof(line), f)) {
p = strtok_r(line, " \t", &saveptr);
c = strtok_r(NULL, " \t", &saveptr);
if (p && c && strcmp(c, "00000000") == 0) {

View file

@ -165,20 +165,6 @@ int dm_ctx_clean_sub(struct dmctx *ctx)
return dm_ctx_clean_custom(ctx, CTX_INIT_SUB);
}
int dmentry_get_parameter_leaf_value(struct dmctx *ctx, char *inparam)
{
int fault = 0;
if (!inparam) inparam = "";
ctx->in_param = inparam;
if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1)
fault = FAULT_9005;
else
fault = dm_entry_get_full_param_value(ctx);
return fault;
}
int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2)
{
int err = 0, fault = 0;
@ -280,8 +266,8 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2)
{
struct set_tmp *n = NULL, *p = NULL;
int fault = 0;
struct set_tmp *n, *p;
switch(cmd) {
case CMD_SET_VALUE:
@ -359,7 +345,7 @@ int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value)
int dm_entry_restart_services(void)
{
struct package_change *pc;
struct package_change *pc = NULL;
bbf_uci_commit_bbfdm();
@ -379,7 +365,7 @@ int dm_entry_restart_services(void)
int dm_entry_revert_changes(void)
{
struct package_change *pc;
struct package_change *pc = NULL;
bbf_uci_revert_bbfdm();
@ -391,49 +377,50 @@ int dm_entry_revert_changes(void)
return 0;
}
static int get_stats_folder(const char *path, bool is_json, int *file_count, unsigned long *size, unsigned long *date)
static int get_stats_folder(bool json_path, int *count, unsigned long *size)
{
struct stat stats;
struct dirent *entry;
DIR *dirp = NULL;
char buf[264] = {0};
int filecount = 0;
unsigned long filesize = 0, filedate = 0;
const char *path = json_path ? JSON_FOLDER_PATH : LIBRARY_FOLDER_PATH;
if (folder_exists(path)) {
dirp = opendir(path);
struct dirent *entry = NULL;
struct stat stats;
int file_count = 0;
unsigned long file_size = 0;
char buf[512] = {0};
DIR *dirp = opendir(path);
while ((entry = readdir(dirp)) != NULL) {
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, is_json ? ".json" : ".so"))) {
filecount++;
if ((entry->d_type == DT_REG) && (strstr(entry->d_name, json_path ? ".json" : ".so"))) {
file_count++;
snprintf(buf, sizeof(buf), "%s/%s", path, entry->d_name);
if (!stat(buf, &stats)) {
filesize = (filesize + stats.st_size) / 2;
filedate = (filedate + stats.st_mtime) / 2;
}
if (!stat(buf, &stats))
file_size += stats.st_size;
}
}
if (dirp) closedir(dirp);
*file_count = filecount;
*size = filesize;
*date = filedate;
if (dirp)
closedir(dirp);
*count = file_count;
*size = file_size;
return 1;
}
return 0;
}
static int check_stats_folder(const char *path, bool is_json)
static int check_stats_folder(bool json_path)
{
int file_count = 0;
unsigned long size = 0, date = 0;
char buf[128] = {0};
int count = 0;
unsigned long size = 0;
char buf[64] = {0};
if (!get_stats_folder(path, is_json, &file_count, &size, &date))
if (!get_stats_folder(json_path, &count, &size))
return 0;
snprintf(buf, sizeof(buf), "count:%d,sizes:%lu,date:%lu", file_count, size, date);
if (strcmp(buf, is_json ? json_hash : library_hash)) {
strcpy(is_json ? json_hash : library_hash, buf);
snprintf(buf, sizeof(buf), "count:%d,size:%lu", count, size);
if (strcmp(buf, json_path ? json_hash : library_hash) != 0) {
strncpy(json_path ? json_hash : library_hash, buf, 64);
return 1;
}
@ -443,13 +430,13 @@ static int check_stats_folder(const char *path, bool is_json)
int load_dynamic_arrays(struct dmctx *ctx)
{
// Load dynamic objects and parameters exposed via a JSON file
if (check_stats_folder(JSON_FOLDER_PATH, true)) {
if (check_stats_folder(true)) {
free_json_dynamic_arrays(tEntry181Obj);
load_json_dynamic_arrays(ctx);
}
// Load dynamic objects and parameters exposed via a library
if (check_stats_folder(LIBRARY_FOLDER_PATH, false)) {
if (check_stats_folder(false)) {
free_library_dynamic_arrays(tEntry181Obj);
load_library_dynamic_arrays(ctx);
}

View file

@ -37,7 +37,6 @@ int dm_ctx_clean(struct dmctx *ctx);
int dm_ctx_clean_sub(struct dmctx *ctx);
int load_dynamic_arrays(struct dmctx *ctx);
int free_dynamic_arrays(void);
int dmentry_get_parameter_leaf_value(struct dmctx *ctx, char *inparam);
void dm_ctx_init_list_parameter(struct dmctx *ctx);
void dm_ctx_clean_list_parameter(struct dmctx *ctx);

View file

@ -49,7 +49,8 @@ static void delete_json_data_from_list(struct dm_json_parameter *dm_json_paramet
static void free_json_data_from_list(struct list_head *dup_list)
{
struct dm_json_parameter *dm_json_parameter;
struct dm_json_parameter *dm_json_parameter = NULL;
while (dup_list->next != dup_list) {
dm_json_parameter = list_entry(dup_list->next, struct dm_json_parameter, list);
delete_json_data_from_list(dm_json_parameter);
@ -97,9 +98,9 @@ int free_json_dynamic_arrays(DMOBJ *dm_entryobj)
static void generate_prefixobj_and_obj_full_obj(char *full_obj, char **prefix_obj, char **obj)
{
char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *str = NULL;
char *pch = NULL, *pchr = NULL, *tmp_obj = NULL;
str = dmstrdupjson(full_obj);
char *str = dmstrdupjson(full_obj);
for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) {
if (pchr != NULL && *pchr != '\0') {
if (*prefix_obj == NULL) {
@ -119,9 +120,9 @@ static void generate_prefixobj_and_obj_full_obj(char *full_obj, char **prefix_ob
static char *generate_obj_without_instance(char *full_obj, bool is_obj)
{
char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *str = NULL, *obj = NULL;
char *pch = NULL, *pchr = NULL, *tmp_obj = NULL, *obj = NULL;
str = dmstrdupjson(full_obj);
char *str = dmstrdupjson(full_obj);
for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) {
if (atoi(pch) == 0) {
if (obj == NULL) {
@ -145,36 +146,6 @@ static char *generate_obj_without_instance(char *full_obj, bool is_obj)
return obj;
}
static char *replace_string(const char *str, const char *old_string, const char *new_string)
{
char *value;
int i, cnt = 0;
int new_string_len = strlen(new_string);
int old_string_len = strlen(old_string);
for (i = 0; str[i] != '\0'; i++) {
if (strstr(&str[i], old_string) == &str[i]) {
cnt++;
i += old_string_len - 1;
}
}
value = (char *)dmmallocjson(i + cnt * (new_string_len - old_string_len) + 1);
i = 0;
while (*str) {
if (strstr(str, old_string) == str) {
strcpy(&value[i], new_string);
i += new_string_len;
str += old_string_len;
}
else
value[i++] = *str++;
}
value[i] = '\0';
return value;
}
int get_index_of_available_entry(DMOBJ *jentryobj)
{
int idx = 0;
@ -191,7 +162,7 @@ static int check_json_root_obj(struct dmctx *ctx, char *in_param_json, DMOBJ **r
DMOBJ *root = ctx->dm_entryobj;
DMNODE node = {.current_object = ""};
full_obj = replace_string(in_param_json, ".{i}.", ".");
full_obj = replace_str(in_param_json, ".{i}.", ".");
if (strcmp(full_obj, "Device.") == 0)
prefix_obj = full_obj;
@ -213,7 +184,7 @@ static int check_json_root_obj(struct dmctx *ctx, char *in_param_json, DMOBJ **r
int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dm_json_parameter *pleaf;
struct dm_json_parameter *pleaf = NULL;
char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg5 = NULL, *arg6 = NULL;
char *obj = generate_obj_without_instance(parent_node->current_object, true);
@ -232,9 +203,9 @@ int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *
if (arg1 && strcmp(arg1, "uci") == 0) {
//UCI: arg1=type :: arg2=uci_file :: arg3=uci_section_type :: arg4=uci_dmmap_file :: arg5="" :: arg6=""
char buf_instance[64] = "", buf_alias[64] = "", *prefix_obj = NULL, *object = NULL;
char buf_instance[64], buf_alias[64], *prefix_obj = NULL, *object = NULL;
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
generate_prefixobj_and_obj_full_obj(parent_node->current_object, &prefix_obj, &object);
@ -263,16 +234,17 @@ int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *
//UBUS: arg1=type :: arg2=ubus_object :: arg3=ubus_method :: arg4=ubus_args1 :: arg5=ubus_args2 :: arg6=ubus_key
json_object *res = NULL, *dyn_obj = NULL, *arrobj = NULL;
char *inst, *max_inst = NULL;
int id = 0, j = 0;
char *max_inst = NULL;
if (arg2 && arg3 && arg4 && arg5)
dmubus_call(arg2, arg3, UBUS_ARGS{{arg4, arg5, String}}, 1, &res);
else
dmubus_call(arg2, arg3, UBUS_ARGS{{}}, 0, &res);
if (res && arg6) {
int id = 0, j = 0;
dmjson_foreach_obj_in_array(res, arrobj, dyn_obj, j, 1, arg6) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
char *inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dyn_obj, inst) == DM_STOP)
break;
}
@ -286,8 +258,7 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc
//UCI: arg1=type :: arg2=uci_file :: arg3=uci_section_type :: arg4=uci_dmmap_file :: arg5="" :: arg6=""
char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *prefix_obj = NULL, *object = NULL;
struct dm_json_parameter *pleaf;
char buf_instance[64] = "";
struct dm_json_parameter *pleaf = NULL;
char *obj = generate_obj_without_instance(refparam, true);
list_for_each_entry(pleaf, &json_list, list) {
@ -301,6 +272,8 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc
}
if (arg1 && strcmp(arg1, "uci") == 0) {
char buf_instance[64];
generate_prefixobj_and_obj_full_obj(refparam, &prefix_obj, &object);
snprintf(buf_instance, sizeof(buf_instance), "%s_instance", object);
for (int i = 0; buf_instance[i]; i++) {
@ -326,7 +299,7 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta
//UCI: arg1=type :: arg2=uci_file :: arg3=uci_section_type :: arg4=uci_dmmap_file :: arg5="" :: arg6=""
char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL;
struct dm_json_parameter *pleaf;
struct dm_json_parameter *pleaf = NULL;
char *obj = generate_obj_without_instance(refparam, true);
list_for_each_entry(pleaf, &json_list, list) {
@ -377,7 +350,7 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta
static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct dm_json_parameter *pleaf;
struct dm_json_parameter *pleaf = NULL;
char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg5 = NULL, *arg6 = NULL, *arg7 = NULL, *arg8 = NULL;
char *obj = generate_obj_without_instance(refparam, false);
@ -431,7 +404,7 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i
*opt = '\0';
snprintf(arg2_1, sizeof(arg2_1), "%s%d", arg2, atoi(instance) - 1);
} else {
strncpy(arg2_1, arg2, sizeof(arg2_1) - 1);
DM_STRNCPY(arg2_1, arg2, sizeof(arg2_1));
}
if (arg4 && arg5) {
@ -447,7 +420,7 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i
if (arg6) {
char arg6_1[128] = "";
strcpy(arg6_1, arg6);
DM_STRNCPY(arg6_1, arg6, sizeof(arg6_1));
char *opt = strchr(arg6_1, '.');
if (opt) {
*opt = '\0';
@ -469,7 +442,7 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i
static int setvalue_param(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct dm_json_parameter *pleaf;
struct dm_json_parameter *pleaf = NULL;
char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg6 = NULL, *arg7 = NULL, *arg8 = NULL;
char *obj = generate_obj_without_instance(refparam, false);
@ -693,13 +666,13 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, s
{
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys(12)*/
char *full_obj = NULL, *prfix_obj = NULL, *obj_str = NULL;
char *prfix_obj = NULL, *obj_str = NULL;
int obj_number = 0, param_number = 0, i = 0, j = 0;
DMOBJ *next_obj = NULL;
DMLEAF *next_leaf = NULL;
count_obj_param_under_jsonobj(jobj, &obj_number, &param_number);
full_obj = replace_string(object, ".{i}.", ".");
char *full_obj = replace_str(object, ".{i}.", ".");
generate_prefixobj_and_obj_full_obj(full_obj, &prfix_obj, &obj_str);
if (!pobj) return;
@ -781,10 +754,10 @@ static void parse_obj(char *object, json_object *jobj, DMOBJ *pobj, int index, s
int load_json_dynamic_arrays(struct dmctx *ctx)
{
struct dirent *ent;
DIR *dir = NULL;
if (folder_exists(JSON_FOLDER_PATH)) {
struct dirent *ent = NULL;
DIR *dir = NULL;
sysfs_foreach_file(JSON_FOLDER_PATH, dir, ent) {
if (strstr(ent->d_name, ".json")) {
DMOBJ *dm_entryobj = NULL;

View file

@ -65,7 +65,7 @@ static int get_index_of_available_dynamic_array(struct dm_obj_s **jentryobj)
int load_library_dynamic_arrays(struct dmctx *ctx)
{
struct dirent *ent;
struct dirent *ent = NULL;
DIR *dir = NULL;
if (folder_exists(LIBRARY_FOLDER_PATH)) {

View file

@ -29,11 +29,11 @@ inline void *__dmcallocjson(int n, size_t size)
return (void *)m->mem;
}
inline void *__dmreallocjson(void *old, size_t size)
inline void *__dmreallocjson(void *n, size_t size)
{
struct dmmemjson *m = NULL;
if (old != NULL) {
m = container_of(old, struct dmmemjson, mem);
if (n != NULL) {
m = container_of(n, struct dmmemjson, mem);
list_del(&m->list);
}
struct dmmemjson *new_m = realloc(m, sizeof(struct dmmemjson) + size);
@ -75,12 +75,21 @@ char *__dmstrdupjson(const char *s)
int __dmasprintfjson(char **s, const char *format, ...)
{
char buf[512];
int size;
char *str = NULL;
va_list arg;
va_start(arg,format);
vsprintf(buf, format, arg);
va_start(arg, format);
size = vasprintf(&str, format, arg);
va_end(arg);
*s = __dmstrdupjson(buf);
if (*s == NULL) return -1;
if (size < 0 || str == NULL)
return -1;
*s = __dmstrdupjson(str);
free(str);
if (*s == NULL)
return -1;
return 0;
}

View file

@ -90,7 +90,7 @@ static bool bbf_set_value(char *path, char *value)
static char *bbf_get_value_by_id(char *id)
{
struct dmctx dm_ctx = {0};
struct dm_parameter *n;
struct dm_parameter *n = NULL;
char *value = NULL;
bbf_init(&dm_ctx, id);
@ -106,7 +106,6 @@ static char *bbf_get_value_by_id(char *id)
static char *get_param_val_from_op_cmd(char *op_cmd, const char *param)
{
char *val = NULL;
char node[256] = {'\0'};
// Trim action from operation command
@ -115,11 +114,10 @@ static char *get_param_val_from_op_cmd(char *op_cmd, const char *param)
strncpy(node, op_cmd, ret - op_cmd +1);
// Append param name to the trimmed path
strcat(node, param);
strncat(node, param, sizeof(node) - strlen(node));
// Get parameter value
val = bbf_get_value_by_id(node);
return val;
return bbf_get_value_by_id(node);
}
static opr_ret_t reboot_device(struct dmctx *dmctx, char *path, json_object *input)
@ -144,10 +142,9 @@ static opr_ret_t network_interface_reset(struct dmctx *dmctx, char *path, json_o
bool status = false;
snprintf(cmd + strlen(cmd), NAME_MAX - strlen(cmd), "%s", ".");
char *zone = NULL;
zone = get_param_val_from_op_cmd(path, "Name");
char *zone = get_param_val_from_op_cmd(path, "Name");
if (zone) {
strcat(cmd, zone);
strncat(cmd, zone, NAME_MAX - strlen(cmd));
dmfree(zone);
} else {
return FAIL;
@ -190,20 +187,20 @@ static opr_ret_t ap_security_reset(struct dmctx *dmctx, char *path, json_object
len = ARRAY_SIZE(reset_params);
for (i = 0; i < len; i++) {
strncpy(reset_params[i].node, node, 255);
strcat(reset_params[i].node, reset_params[i].param);
DM_STRNCPY(reset_params[i].node, node, sizeof(reset_params[i].node));
strncat(reset_params[i].node, reset_params[i].param, 255 - strlen(reset_params[i].node));
}
const char *mode_enabled = "WPA2-Personal";
// Default mode - WPA2-Personal
strncpy(reset_params[0].value, mode_enabled, 255);
DM_STRNCPY(reset_params[0].value, mode_enabled, sizeof(reset_params[0].value));
// Get Default wpakey
db_get_value_string("hw", "board", "wpa_key", &wpakey);
// PreSharedKey and KeyPassphrase are kept same
strncpy(reset_params[1].value, wpakey, 255);
strncpy(reset_params[2].value, wpakey, 255);
DM_STRNCPY(reset_params[1].value, wpakey, sizeof(reset_params[1].value));
DM_STRNCPY(reset_params[2].value, wpakey, sizeof(reset_params[2].value));
for (i = 0; i < len; i++) {
bbf_set_value(reset_params[i].node, reset_params[i].value);
@ -222,9 +219,8 @@ static opr_ret_t dhcp_client_renew(struct dmctx *dmctx, char *path, json_object
static opr_ret_t vendor_conf_backup(struct dmctx *dmctx, char *path, json_object *input)
{
struct file_server fserver = {0};
char *vcf_name = NULL;
vcf_name = get_param_val_from_op_cmd(path, "Name");
char *vcf_name = get_param_val_from_op_cmd(path, "Name");
if (!vcf_name)
return FAIL;
@ -306,10 +302,11 @@ static void fill_wireless_scan_results(struct dmctx *dmctx, char *radio)
static opr_ret_t fetch_neighboring_wifi_diagnostic(struct dmctx *dmctx, char *path, json_object *input)
{
json_object *res = NULL, *radios = NULL, *arrobj = NULL;
int j = 0;
dmubus_call("wifi", "status", UBUS_ARGS{}, 0, &res);
if (res) {
int j = 0;
dmjson_foreach_obj_in_array(res, arrobj, radios, j, 1, "radios") {
fill_wireless_scan_results(dmctx, dmjson_get_value(radios, 1, "name"));
}
@ -1217,7 +1214,7 @@ static opr_ret_t do_operate(struct dmctx *dmctx, char *path, operation func, con
opr_ret_t operate_on_node(struct dmctx *dmctx, char *path, char *input)
{
struct op_cmd *save_pointer = NULL;
const struct op_cmd *op;
const struct op_cmd *op = NULL;
const size_t n = ARRAY_SIZE(operate_helper);
size_t i;

View file

@ -25,7 +25,7 @@
extern struct op_cmd *dynamic_operate;
struct wifi_security_params {
char node[255];
char node[256];
char *param;
char value[256];
};
@ -215,7 +215,7 @@ struct op_cmd {
const operation_args args;
};
int add_dynamic_operate(char *path, operation operate, char *optype);
int add_dynamic_operate(char *path, operation operate, char *type);
void operate_list_cmds(struct dmctx *dmctx);
opr_ret_t operate_on_node(struct dmctx *dmctx, char *path, char *input);

View file

@ -38,14 +38,14 @@ int init_supported_codecs()
json_object_object_foreach(res, key, value) {
if (value) {
const char *codec;
int min = 0, max = 0, increment = 0, ptime_default = 0, duration, total_len, len;
const char *codec = NULL;
int min = 0, max = 0, increment = 0, ptime_default = 0;
int size = sizeof(supported_codecs[codecs_num].packetization_period);
strncpy(supported_codecs[codecs_num].uci_name, key, sizeof(supported_codecs[codecs_num].uci_name) - 1);
DM_STRNCPY(supported_codecs[codecs_num].uci_name, key, sizeof(supported_codecs[codecs_num].uci_name) - 1);
json_object_object_foreach(value, sub_key, sub_value) {
if (sub_value && !strcasecmp(sub_key, "name") && (codec = json_object_get_string(sub_value)) != NULL) {
strncpy(supported_codecs[codecs_num].codec, codec, sizeof(supported_codecs[codecs_num].codec));
DM_STRNCPY(supported_codecs[codecs_num].codec, codec, sizeof(supported_codecs[codecs_num].codec));
} else if (sub_value && !strcasecmp(sub_key, "bitrate")) {
supported_codecs[codecs_num].bit_rate = json_object_get_int(sub_value);
} else if (sub_value && !strcasecmp(sub_key, "ptime_min")) {
@ -61,17 +61,19 @@ int init_supported_codecs()
// Construct packetization period
if (min > 0 && max > min) {
int duration = 0, total_len = 0;
if (increment <= 0)
increment = 10;
for (total_len = 0, duration = min; duration <= max; duration += increment) {
supported_codecs[codecs_num].ptime_default = (unsigned int)ptime_default;
len = snprintf(supported_codecs[codecs_num].packetization_period + total_len, size,
int len = snprintf(supported_codecs[codecs_num].packetization_period + total_len, size,
"%s%d", (duration == min) ? "" : ",", duration);
if (len > 0 && len < size) {
total_len += len;
size -= len;
} else {
TR104_DEBUG("supported_codecs[codecs_num].packetization_period = %s, "
BBF_DEBUG("supported_codecs[codecs_num].packetization_period = %s, "
"the size is too small\n", supported_codecs[codecs_num].packetization_period);
break;
}
@ -111,7 +113,7 @@ static void convert_src_dst(char *src_or_dst, size_t buf_size)
int init_call_log()
{
#define CHECK_RESULT(cond) if (!(cond)) { \
TR104_DEBUG("Invalid cdr [%s]\ncalling_number = [%s], called_number = [%s], " \
BBF_DEBUG("Invalid cdr [%s]\ncalling_number = [%s], called_number = [%s], " \
"start_time = [%s], end_time = %s\n", line, \
cdr.calling_num, cdr.called_num, cdr.start_time, end_time); \
continue; \
@ -135,7 +137,7 @@ int init_call_log()
fp = fopen(CALL_LOG_FILE, "r");
if (!fp) {
TR104_DEBUG("Call log file %s doesn't exist\n", CALL_LOG_FILE);
BBF_DEBUG("Call log file %s doesn't exist\n", CALL_LOG_FILE);
res = -1;
goto __ret;
}
@ -230,12 +232,12 @@ int init_call_log()
// Skip invalid call logs
if (cdr.calling_num[0] == '\0' || cdr.called_num[0] == '\0' ||
cdr.start_time[0] == '\0' || end_time[0] == '\0') {
TR104_DEBUG("Invalid CDR: [%s]\ncalling_number = [%s], called_number = [%s], "
BBF_DEBUG("Invalid CDR: [%s]\ncalling_number = [%s], called_number = [%s], "
"start_time = [%s], end_time = [%s]\n", line,
cdr.calling_num, cdr.called_num, cdr.start_time, end_time);
continue;
} else if (cdr.destination[0] == '\0' && strcasecmp(cdr.called_num, "h") == 0) {
TR104_DEBUG("Invalid CDR: [%s]\ncalled_number = [%s], destination = [%s]\n", line,
BBF_DEBUG("Invalid CDR: [%s]\ncalled_number = [%s], destination = [%s]\n", line,
cdr.called_num, cdr.destination);
continue;
}
@ -252,7 +254,7 @@ int init_call_log()
// Convert start time to ISO 8601 date-time format as per TR-181 data model
strftime(cdr.start_time, sizeof(cdr.start_time), "%Y-%m-%dT%H:%M:%SZ", &tm_start);
} else {
TR104_DEBUG("Invalid CDR: [%s]\nWrong start time and/or end time, [%s], [%s]\n",
BBF_DEBUG("Invalid CDR: [%s]\nWrong start time and/or end time, [%s], [%s]\n",
line, cdr.start_time, end_time);
continue;
}
@ -260,14 +262,14 @@ int init_call_log()
// Determine the call direction and used line
char *tel_line = NULL;
if ((tel_line = strcasestr(cdr.source, "TELCHAN")) != NULL) {
strncpy(cdr.direction, "Outgoing", sizeof(cdr.direction));
DM_STRNCPY(cdr.direction, "Outgoing", sizeof(cdr.direction));
} else if ((tel_line = strcasestr(cdr.destination, "TELCHAN")) != NULL) {
strncpy(cdr.direction, "Incoming", sizeof(cdr.direction));
DM_STRNCPY(cdr.direction, "Incoming", sizeof(cdr.direction));
} else {
TR104_DEBUG("Invalid CDR: [%s]\ndirection = [%s]\n", line, cdr.direction);
BBF_DEBUG("Invalid CDR: [%s]\ndirection = [%s]\n", line, cdr.direction);
continue;
}
strncpy(cdr.used_line, tel_line, sizeof(cdr.used_line) - 1);
DM_STRNCPY(cdr.used_line, tel_line, sizeof(cdr.used_line));
/*
* Convert the termination cause to a value specified in TR-104.
@ -278,17 +280,17 @@ int init_call_log()
* TODO: Asterisk needs to be changed in order to provide more TR-104 compliant call termination causes.
*/
if (strcasecmp(cdr.termination_cause, "NO ANSWER") == 0)
strncpy(cdr.termination_cause, "LocalTimeout", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "LocalTimeout", sizeof(cdr.termination_cause));
else if (strcasecmp(cdr.termination_cause, "FAILED") == 0)
strncpy(cdr.termination_cause, "LocalInternalError", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "LocalInternalError", sizeof(cdr.termination_cause));
else if (strcasecmp(cdr.termination_cause, "BUSY") == 0)
strncpy(cdr.termination_cause, "RemoteBusy", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "RemoteBusy", sizeof(cdr.termination_cause));
else if (strcasecmp(cdr.termination_cause, "ANSWERED") == 0)
strncpy(cdr.termination_cause, "RemoteDisconnect", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "RemoteDisconnect", sizeof(cdr.termination_cause));
else if (strcasecmp(cdr.termination_cause, "CONGESTION") == 0)
strncpy(cdr.termination_cause, "RemoteNetworkFailure", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "RemoteNetworkFailure", sizeof(cdr.termination_cause));
else
strncpy(cdr.termination_cause, "LocalInternalError", sizeof(cdr.termination_cause));
DM_STRNCPY(cdr.termination_cause, "LocalInternalError", sizeof(cdr.termination_cause));
// Convert source and destination
convert_src_dst(cdr.source, sizeof(cdr.source));
convert_src_dst(cdr.destination, sizeof(cdr.destination));

View file

@ -10,24 +10,10 @@
#include <libbbf_api/dmcommon.h>
#define ENABLE_TR104_DEBUG 0
#define TR104_UCI_PACKAGE "asterisk"
#define DEFAULT_SIP_PORT_STR "5060"
#define DEFAULT_SIP_REGISTER_EXPIRY_STR "300"
#if ENABLE_TR104_DEBUG
#define TR104_DEBUG(fmt, ...) do { \
FILE *fp = fopen("/tmp/bbf_tr104.log", "a"); \
if (fp) { \
fprintf(fp, "%s@%s:%d: " fmt, __func__, __FILE__, __LINE__, ##__VA_ARGS__); \
fclose(fp); \
} \
} while(0)
#else
#define TR104_DEBUG(fmt, ...)
#endif
struct codec_info {
char uci_name[16]; // Codec name used in UCI, i.e. alaw
char codec[16]; // Codec name, i.e. G.711ALaw

View file

@ -17,7 +17,7 @@
int browseVoiceServiceSIPProviderInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
@ -72,7 +72,7 @@ int delObjVoiceServiceSIPProvider(char *refparam, struct dmctx *ctx, void *data,
**************************************************************/
static int browseServicesVoiceServiceCallLogInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct call_log_entry *entry;
struct call_log_entry *entry = NULL;
char inst[16];
int i = 0;
@ -103,7 +103,7 @@ static int browseServicesVoiceServiceVoIPProfileInst(struct dmctx *dmctx, DMNODE
static int browseServicesVoiceServiceCodecProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
int i, j;
int has_codec_profile = 0;
@ -124,7 +124,6 @@ static int browseServicesVoiceServiceCodecProfileInst(struct dmctx *dmctx, DMNOD
char str[16];
// Not found. Add this codec in the UCI
dmuci_set_value(TR104_UCI_PACKAGE, codec->uci_name, "", "codec_profile");
TR104_DEBUG("Created a UCI section: %s\n", str);
dmuci_set_value(TR104_UCI_PACKAGE, codec->uci_name, "name", codec->codec);
snprintf(str, sizeof(str), "%u", codec->ptime_default);
dmuci_set_value(TR104_UCI_PACKAGE, codec->uci_name, "ptime", str);

View file

@ -29,7 +29,7 @@ static int get_voice_service_line_linker(char *refparam, struct dmctx *dmctx, vo
static int browseServicesVoiceServiceCallControlLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "tel_line", "dmmap_asterisk", &dup_list);
@ -61,7 +61,7 @@ static int browseServicesVoiceServiceCallControlOutgoingMapInst(struct dmctx *dm
static int browseServicesVoiceServiceCallControlNumberingPlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "tel_advanced", "dmmap_asterisk", &dup_list);
@ -81,7 +81,7 @@ static int browseServicesVoiceServiceCallControlNumberingPlanInst(struct dmctx *
static int browseServicesVoiceServiceCallControlCallingFeaturesSetInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "advanced_features", "dmmap_asterisk", &dup_list);
@ -101,7 +101,7 @@ static int browseServicesVoiceServiceCallControlCallingFeaturesSetInst(struct dm
static int browseServicesVoiceServiceCallControlCallingFeaturesSetSCREJInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "call_filter_rule_incoming", "dmmap_asterisk", &dup_list);
@ -122,65 +122,65 @@ static int browseServicesVoiceServiceCallControlCallingFeaturesSetSCREJInst(stru
**************************************************************/
static int addObjServicesVoiceServiceCallControlLine(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("VoiceService.1.CallControl.Line. can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.Line. can't be added or deleted\n");
return 0;
}
static int delObjServicesVoiceServiceCallControlLine(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("VoiceService.1.CallControl.Line. can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.Line. can't be added or deleted\n");
return 0;
}
static int addObjServicesVoiceServiceCallControlIncomingMap(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("VoiceService.1.CallControl.IncomingMap. has a 1:1 mapping to Services.VoiceService."
BBF_DEBUG("VoiceService.1.CallControl.IncomingMap. has a 1:1 mapping to Services.VoiceService."
"1.SIP.Client. so it can't be added or deleted\n");
return 0;
}
static int delObjServicesVoiceServiceCallControlIncomingMap(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("VoiceService.1.CallControl.IncomingMap. has a 1:1 mapping to Services.VoiceService."
BBF_DEBUG("VoiceService.1.CallControl.IncomingMap. has a 1:1 mapping to Services.VoiceService."
"1.SIP.Client. so it can't be added or deleted\n");
return 0;
}
static int addObjServicesVoiceServiceCallControlOutgoingMap(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("VoiceService.1.CallControl.OutgoingMap. has a 1:1 mapping to Services.VoiceService."
BBF_DEBUG("VoiceService.1.CallControl.OutgoingMap. has a 1:1 mapping to Services.VoiceService."
"1.SIP.Client. so it can't be added or deleted\n");
return 0;
}
static int delObjServicesVoiceServiceCallControlOutgoingMap(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("VoiceService.1.CallControl.OutgoingMap. has a 1:1 mapping to Services.VoiceService."
BBF_DEBUG("VoiceService.1.CallControl.OutgoingMap. has a 1:1 mapping to Services.VoiceService."
"1.SIP.Client. so it can't be added or deleted\n");
return 0;
}
static int addObjServicesVoiceServiceCallControlNumberingPlan(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("VoiceService.1.CallControl.NumberingPlan. has only one instance so it can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.NumberingPlan. has only one instance so it can't be added or deleted\n");
return 0;
}
static int delObjServicesVoiceServiceCallControlNumberingPlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("VoiceService.1.CallControl.NumberingPlan. has only one instance so it can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.NumberingPlan. has only one instance so it can't be added or deleted\n");
return 0;
}
static int addObjServicesVoiceServiceCallControlCallingFeaturesSet(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("VoiceService.1.CallControl.CallingFeatures.Set. has only one instance so it can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.CallingFeatures.Set. has only one instance so it can't be added or deleted\n");
return 0;
}
static int delObjServicesVoiceServiceCallControlCallingFeaturesSet(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("VoiceService.1.CallControl.CallingFeatures.Set. has only one instance so it can't be added or deleted\n");
BBF_DEBUG("VoiceService.1.CallControl.CallingFeatures.Set. has only one instance so it can't be added or deleted\n");
return 0;
}
@ -260,7 +260,7 @@ static int get_ServicesVoiceServiceCallControlLine_CallStatus(char *refparam, st
char *offhook = dmjson_get_value(res, 1, "offhook");
*value = *offhook == '1' ? "Connected" : "Idle";
} else {
TR104_DEBUG("dmubus_call() failed\n");
BBF_DEBUG("dmubus_call() failed\n");
}
return 0;

View file

@ -18,7 +18,7 @@
static int browseServicesVoiceServicePOTSFXSInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "tel_line", "dmmap_asterisk", &dup_list);
@ -26,7 +26,7 @@ static int browseServicesVoiceServicePOTSFXSInst(struct dmctx *dmctx, DMNODE *pa
char *line_name = NULL;
dmuci_get_value_by_section_string(p->config_section, "name", &line_name);
if (*line_name == '\0' || strcasestr(line_name, "DECT") == NULL) {
if (line_name && (*line_name == '\0' || strcasestr(line_name, "DECT") == NULL)) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "fxsinstance", "fxsalias");

View file

@ -44,7 +44,7 @@ static int browseServicesVoiceServiceSIPClientContactInst(struct dmctx *dmctx, D
static int browseServicesVoiceServiceSIPNetworkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
@ -79,7 +79,6 @@ static int addObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx
char *inst = get_last_instance_bbfdm("dmmap_asterisk", "sip_service_provider", "clientinstance");
snprintf(new_sec_name, sizeof(new_sec_name), "sip%d", (inst) ? atoi(inst) : 0);
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "", "sip_service_provider");
TR104_DEBUG("section name is [%s]. last inst = [%s]\n", new_sec_name, inst);
// Set default options
snprintf(value, sizeof(value), "account %d", (inst) ? atoi(inst) + 1 : 1);
@ -118,14 +117,14 @@ static int delObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx
static int addObjServicesVoiceServiceSIPNetwork(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
TR104_DEBUG("Each Services.VoiceService.1.SIP.Network object is bound to one Services.VoiceService"
BBF_DEBUG("Each Services.VoiceService.1.SIP.Network object is bound to one Services.VoiceService"
".1.SIP.Client object\n");
return 0;
}
static int delObjServicesVoiceServiceSIPNetwork(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
TR104_DEBUG("Each Services.VoiceService.1.SIP.Network object is bound to one Services.VoiceService"
BBF_DEBUG("Each Services.VoiceService.1.SIP.Network object is bound to one Services.VoiceService"
".1.SIP.Client object\n");
return 0;
}
@ -207,7 +206,7 @@ static int get_ServicesVoiceServiceSIPClient_Status(char *refparam, struct dmctx
dmfree(enabled);
} else {
// Get registration status from ubus
json_object *res = NULL, *sip, *client;
json_object *res = NULL, *sip = NULL, *client = NULL;
dmubus_call("voice.asterisk", "status", UBUS_ARGS{}, 0, &res);
if (res) {
@ -228,7 +227,7 @@ static int get_ServicesVoiceServiceSIPClient_Status(char *refparam, struct dmctx
}
}
} else {
TR104_DEBUG("dmubus_call() failed\n");
BBF_DEBUG("dmubus_call() failed\n");
}
}
@ -339,11 +338,11 @@ static int set_ServicesVoiceServiceSIPClientContact_Port(char *refparam, struct
static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *section = (struct uci_section *)data;
json_object *res = NULL, *sip, *client;
json_object *res = NULL, *sip = NULL, *client = NULL;
*value = "0001-01-01T00:00:00Z";
if (!section) {
TR104_DEBUG("section shall NOT be null\n");
BBF_DEBUG("section shall NOT be null\n");
return 0;
}
@ -371,7 +370,7 @@ static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, s
dmfree(period_str);
}
if (period <= 0) {
TR104_DEBUG("Use default registration expires\n");
BBF_DEBUG("Use default registration expires\n");
period = atoi(DEFAULT_SIP_REGISTER_EXPIRY_STR);
}
time_expires = time_last + period;
@ -381,7 +380,7 @@ static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, s
*value = dmstrdup(buf);
} else {
TR104_DEBUG("Unexpected time format: %s\n", last_reg_time);
BBF_DEBUG("Unexpected time format: %s\n", last_reg_time);
}
}
}
@ -394,10 +393,10 @@ static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, s
static int get_ServicesVoiceServiceSIPClientContact_UserAgent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *section = (struct uci_section *)data;
json_object *res = NULL, *sip, *client;
json_object *res = NULL, *sip = NULL, *client = NULL;
if (!section) {
TR104_DEBUG("section shall NOT be null\n");
BBF_DEBUG("section shall NOT be null\n");
return 0;
}
@ -410,7 +409,7 @@ static int get_ServicesVoiceServiceSIPClientContact_UserAgent(char *refparam, st
*value = dmjson_get_value(client, 1, "useragent");
}
} else {
TR104_DEBUG("dmubus_call() failed\n");
BBF_DEBUG("dmubus_call() failed\n");
}
return 0;
@ -466,18 +465,16 @@ static int get_server_address(struct uci_section *section, char *option, char **
static int set_server_address(struct uci_section *section, char *option, char *value)
{
char *old_value, *port, *new_value;
char *old_value = NULL;
dmuci_get_value_by_section_string(section, option, &old_value);
port = strchr(old_value, ':');
char *port = (old_value && *old_value) ? strchr(old_value, ':') : NULL;
if (port) {
char new_value[32] = {0};
port++;
new_value = (char *)dmmalloc(strlen(value) + strlen(port) + 2);
if (new_value) {
sprintf(new_value, "%s:%s", value, port);
dmuci_set_value_by_section(section, option, new_value);
dmfree(new_value);
}
snprintf(new_value, sizeof(new_value), "%s:%s", value, port);
dmuci_set_value_by_section(section, option, new_value);
} else {
dmuci_set_value_by_section(section, option, value);
}
@ -490,7 +487,7 @@ static int set_server_address(struct uci_section *section, char *option, char *v
static int get_server_port(struct uci_section *section, char *option, char **value)
{
char *domain, *port = NULL;
char *domain = NULL, *port = NULL;
dmuci_get_value_by_section_string(section, option, &domain);
if (domain && *domain) {
@ -499,10 +496,7 @@ static int get_server_port(struct uci_section *section, char *option, char **val
port++;
}
if (port && *port)
*value = dmstrdup(port);
else
*value = dmstrdup(DEFAULT_SIP_PORT_STR);
*value = dmstrdup((port && *port) ? port : DEFAULT_SIP_PORT_STR);
if (domain && *domain)
dmfree(domain);
@ -512,18 +506,15 @@ static int get_server_port(struct uci_section *section, char *option, char **val
static int set_server_port(struct uci_section *section, char *option, char *value)
{
char *old_value, *new_value, *tmp;
char *old_value = NULL, new_value[32] = {0};
dmuci_get_value_by_section_string(section, option, &old_value);
tmp = strchr(old_value, ':');
char *tmp = old_value ? strchr(old_value, ':') : NULL;
if (tmp)
*tmp = '\0';
new_value = (char *)dmmalloc(strlen(old_value) + strlen(value) + 2);
if (new_value) {
sprintf(new_value, "%s:%s", old_value, value);
dmuci_set_value_by_section(section, option, new_value);
dmfree(new_value);
}
snprintf(new_value, sizeof(new_value), "%s:%s", old_value ? old_value : "", value);
dmuci_set_value_by_section(section, option, new_value);
if (old_value && *old_value)
dmfree(old_value);
@ -857,7 +848,7 @@ static int get_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d
if (codec && len < sizeof(buf)) {
int res = snprintf(buf + len, sizeof(buf) - len, "%s%s", len == 0 ? "" : ",", codec);
if (res <= 0) {
TR104_DEBUG("buf might be too small\n");
BBF_DEBUG("buf might be too small\n");
dmfree(tmp);
return FAULT_9002;
}
@ -875,8 +866,8 @@ static int get_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d
static int set_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *codec_list = NULL, *token = NULL, *saveptr = NULL, *uci_name = NULL;
int res = 0;
char *codec_list = NULL, *token, *saveptr, *uci_name;
switch (action) {
case VALUECHECK:
@ -950,19 +941,11 @@ static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Origin(char *refparam, s
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.FQDNServer.Domain!UCI:asterisk/sip_service_provider,@i-1/domain*/
static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
if (!data) {
TR104_DEBUG("data shall NOT be null\n");
return 0;
}
return get_server_address(data, "domain", value);
}
static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
if (!data) {
TR104_DEBUG("data shall NOT be null\n");
return 0;
}
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 256, NULL, 0, NULL, 0))
@ -978,19 +961,11 @@ static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, s
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.FQDNServer.Port!UCI:asterisk/sip_service_provider,@i-1/domain*/
static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
if (!data) {
TR104_DEBUG("data shall NOT be null\n");
return 0;
}
return get_server_port(data, "domain", value);
}
static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
if (!data) {
TR104_DEBUG("data shall NOT be null\n");
return 0;
}
switch (action) {
case VALUECHECK:
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"0","65535"}}, 1))

View file

@ -1589,7 +1589,7 @@ static int get_IPDiagnosticsServerSelectionDiagnostics_MaximumResponseTime(char
static int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "RouteHops", s) {
@ -1605,7 +1605,7 @@ static int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNOD
static int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "DownloadPerConnection", s) {
@ -1621,7 +1621,7 @@ static int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct
static int browseIPDiagnosticsUploadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "UploadPerConnection", s) {

View file

@ -337,11 +337,12 @@ static int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
{
char *inst = NULL, *max_inst = NULL, *ifname;
struct atm_args curr_atm_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "atm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &ifname);
init_atm_link(&curr_atm_args, p->config_section, ifname);

View file

@ -182,7 +182,7 @@ static int get_last_inst(char *config, char *section, char *option1, char *optio
static int check_ifname_exist_in_br_ifname_list(char *ifname, char *s_name)
{
char *br_ifname_list, *pch, *spch;
struct uci_section *s;
struct uci_section *s = NULL;
uci_foreach_option_eq("network", "interface", "type", "bridge", s) {
if (strcmp(section_name(s), s_name) != 0)
@ -216,7 +216,7 @@ static int remove_bridge_sections(char *config, char *section, char *option, cha
char *get_last_instance_bridge_bbfdm(char* dmmap_package, char *section, char *opt_inst)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *instance = NULL, *last_inst = NULL;
// traverse all bridge config and return the last instance of bridge
@ -263,15 +263,16 @@ static int update_bridge_ifname(struct uci_section *br_sec, struct uci_section *
static int remove_ifname_from_bridge_section(struct uci_section *br_sec, char *baseifname)
{
char ifname_dup[128], *ptr, *ifname, *start, *end;
int pos = 0;
char ifname_dup[128] = {0}, *ifname = NULL, *start = NULL, *end = NULL;
dmuci_get_value_by_section_string(br_sec, "ifname", &ifname);
ptr = ifname_dup;
char *ptr = ifname_dup;
dmstrappendstr(ptr, ifname);
dmstrappendend(ptr);
if (is_strword_in_optionvalue(ifname_dup, baseifname)) {
int pos = 0;
start = strstr(ifname_dup, baseifname);
end = start + strlen(baseifname);
if (start != ifname_dup) {
@ -287,10 +288,10 @@ static int remove_ifname_from_bridge_section(struct uci_section *br_sec, char *b
static int add_new_ifname_to_bridge_section(struct uci_section *br_sec, char *new_ifname)
{
char ifname_dup[128], *ptr, *ifname;
char ifname_dup[128] = {0}, *ifname = NULL;
dmuci_get_value_by_section_string(br_sec, "ifname", &ifname);
ptr = ifname_dup;
char *ptr = ifname_dup;
dmstrappendstr(ptr, ifname);
dmstrappendend(ptr);
@ -452,7 +453,7 @@ static void sync_bridge_config_sections_with_dmmap_bridge_eq(char *package, char
* 3) Copy ifname of bridges in dmmap_bridge file
* 4) Now traverse the dmmap_bridge file and create a link list
*/
struct uci_section *s, *dmmap_sect, *ss;
struct uci_section *s = NULL, *dmmap_sect = NULL, *ss = NULL;
char *ifname, *section_name;
uci_foreach_option_eq(package, section_type, option_name, option_value, s) {
@ -484,7 +485,7 @@ static void sync_bridge_config_sections_with_dmmap_bridge_eq(char *package, char
void dmmap_synchronizeBridgingProviderBridge()
{
struct uci_section *s, *dmmap_br_sec, *dmmap_pr_br_sec;
struct uci_section *s = NULL, *dmmap_br_sec, *dmmap_pr_br_sec;
char *ifname;
uci_foreach_option_eq("network", "interface", "type", "bridge", s) {
@ -510,7 +511,6 @@ void dmmap_synchronizeBridgingProviderBridge()
char *pch, *spch;
struct uci_section *ss = NULL;
char svlan_device[128], cvlan_device[128], bridge_name[50];
char *ptr_svlan = svlan_device;
char *ptr_cvlan = cvlan_device;
char *last_inst_dmmap;
char current_inst[16], pr_br_alias[32];
@ -526,7 +526,7 @@ void dmmap_synchronizeBridgingProviderBridge()
// If type is 8021ad, add to svlan
if (strcmp(type,"8021ad") == 0) {
strcpy(ptr_svlan, pch);
DM_STRNCPY(svlan_device, pch, sizeof(svlan_device));
}
// If type is 8021q, add to cvlan
if (strcmp(type,"8021q") == 0) {
@ -619,10 +619,10 @@ static int is_wireless_ifname_exist(char *br_section_name, char *ifname)
static int is_bridge_pr_br_member(char *br_inst, char **pr_br_inst)
{
struct uci_section *sec;
struct uci_section *sec = NULL;
char *svlan;
struct uci_list *v = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
// Return provider bridge inst. if passed bridge inst. is a member of provider bridge
uci_path_foreach_sections(bbfdm, "dmmap_provider_bridge", "provider_bridge", sec) {
// Check if the passed bridge section is svlan
@ -637,9 +637,10 @@ static int is_bridge_pr_br_member(char *br_inst, char **pr_br_inst)
}
// Check if the passed bridge section is cvlan
bool found = false;
dmuci_get_value_by_section_list(sec, "cvlan_br_inst", &v);
if (v != NULL) {
bool found = false;
uci_foreach_element(v, e) {
if (strcmp(e->name, br_inst) == 0) {
found = true;
@ -809,7 +810,7 @@ static int dmmap_synchronizeBridgingBridgePort(struct dmctx *dmctx, DMNODE *pare
static void get_bridge_vlanport_device_section(struct uci_section *dmmap_section, struct uci_section **device_section)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *name, *device_name;
/* Get name from dmmap section */
@ -841,7 +842,7 @@ static void get_bridge_vlanport_device_section(struct uci_section *dmmap_section
static void get_bridge_port_device_section(struct uci_section *dmmap_section, struct uci_section **device_section)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *device;
/* Get device from dmmap section */
@ -1040,9 +1041,11 @@ static void remove_vlanport_section(struct uci_section *vlanport_dmmap_sec, stru
char *vid = strchr(device, '.');
if (vid) {
// Remove curr device from ifname list of bridge section
char new_ifname[128], *ifname;
char *ifname = NULL;
dmuci_get_value_by_section_string(bridge_sec, "ifname", &ifname);
if (ifname[0] != '\0') {
if (ifname && ifname[0] != '\0') {
char new_ifname[128] = {0};
remove_interface_from_ifname(device, ifname, new_ifname);
dmuci_set_value_by_section(bridge_sec, "ifname", new_ifname);
}
@ -1090,7 +1093,7 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi
char *option_val1 = NULL;
char *option_val2 = NULL;
char buf[50] = {0}; // for storing ifname
char *ptr;
char *ptr = NULL;
// Get candidate bridge instance
tokens = strsplit(value, ".", &length);
@ -1181,7 +1184,7 @@ static void restore_bridge_config(char *vlan_br_inst)
char *management, *device;
char **device_comma;
size_t length_comma, tmp_length;
char **tmp_list;
char **tmp_list = NULL;
char ifname[50] = {0};
char *ptr = ifname;
char *interface;
@ -1278,7 +1281,7 @@ void static get_rem_pr_br_instance(struct uci_section *sec, char *bridge_inst)
char *management, *device;
char **device_comma;
size_t length, tmp_length;
char **tmp_list;
char **tmp_list = NULL;
char ifname[50] = {0};
char *ptr = ifname;
int i;
@ -1346,10 +1349,10 @@ void static get_rem_pr_br_instance(struct uci_section *sec, char *bridge_inst)
// Function to remove a svlan/cvlan instance from Provider bridge
void rem_bridge_from_provider_bridge(char *bridge_inst)
{
struct uci_section *sec;
struct uci_section *sec = NULL;
char *svlan;
struct uci_list *v = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
// Traverse each provider bridge section and remove the passed bridge instance.
@ -1367,9 +1370,10 @@ void rem_bridge_from_provider_bridge(char *bridge_inst)
}
}
// Check if the passed bridge section is cvlan
bool found = false;
dmuci_get_value_by_section_list(sec, "cvlan_br_inst", &v);
if (v != NULL) {
bool found = false;
uci_foreach_element(v, e) {
if (strcmp(e->name, bridge_inst) == 0) {
found = true;
@ -1537,9 +1541,11 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat
dmuci_delete_by_section_unnamed_bbfdm(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, NULL, NULL);
} else {
// Remove ifname from ifname list of bridge section
char new_ifname[128], *ifname;
char *ifname = NULL;
dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_sec, "ifname", &ifname);
if (ifname[0] != '\0') {
if (ifname && ifname[0] != '\0') {
char new_ifname[128] = {0};
remove_interface_from_ifname(device, ifname, new_ifname);
dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_sec, "ifname", new_ifname);
}
@ -1726,9 +1732,8 @@ static int delObjBridgingBridgeVLAN(char *refparam, struct dmctx *ctx, void *dat
static int addObjBridgingProviderBridge(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *pr_br_sec = NULL;
char *last_instance = NULL;
last_instance = get_last_instance_bbfdm("dmmap_provider_bridge", "provider_bridge", "provider_bridge_instance");
char *last_instance = get_last_instance_bbfdm("dmmap_provider_bridge", "provider_bridge", "provider_bridge_instance");
// Add dmmap section
dmuci_add_section_bbfdm("dmmap_provider_bridge", "provider_bridge", &pr_br_sec);
@ -2291,7 +2296,7 @@ static void get_priority_list(char *uci_opt_name, void *data, char **value)
struct uci_element *e = NULL;
char uci_value[130], **priority = NULL;
size_t length;
int n;
unsigned pos = 0;
dmuci_get_value_by_section_list(((struct bridge_port_args *)data)->bridge_port_sec, uci_opt_name, &v);
if (v == NULL)
@ -2302,12 +2307,12 @@ static void get_priority_list(char *uci_opt_name, void *data, char **value)
uci_foreach_element(v, e) {
//delimiting priority which is in the form of x:y where y is the priority
priority = strsplit(e->name, ":", &length);
strcat(uci_value, priority[1]);
strcat(uci_value, ",");
if (length > 1)
pos += snprintf(&uci_value[pos], sizeof(uci_value) - pos, "%s,", priority[1]);
}
n = strlen(uci_value);
if (n != 0)
uci_value[n-1] = '\0';
if (pos)
uci_value[pos - 1] = 0;
dmasprintf(value, "%s", uci_value);
}
@ -2475,7 +2480,7 @@ static int set_BridgingBridgePort_PVID(char *refparam, struct dmctx *ctx, void *
dmasprintf(&new_name, "%s.%s", ifname, value);
/* Update VLANPort dmmap section if exist */
struct uci_section *vlanport_s;
struct uci_section *vlanport_s = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", ((struct bridge_port_args *)data)->br_inst, vlanport_s) {
char *vlan_name, *name;
dmuci_get_value_by_section_string(vlanport_s, "name", &vlan_name);
@ -2518,7 +2523,7 @@ static int get_BridgingBridgePort_TPID(char *refparam, struct dmctx *ctx, void *
static int configure_interface_type(struct uci_section *bridge_sec, struct uci_section *sec, char *interface, char *br_inst, char *value)
{
struct uci_section *s, *ss = NULL;
struct uci_section *s = NULL, *ss = NULL;
char *vid = NULL, *inner_vid = NULL;
dmuci_set_value_by_section(sec, "type", value);
@ -2739,7 +2744,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void
char *vid = strchr(pch, '.');
if (vid && strcmp(vid+1, curr_vid) == 0) {
remove_ifname_from_bridge_section(((struct bridge_vlan_args *)data)->bridge_sec, pch);
struct uci_section *device_s, *vlanport_s;
struct uci_section *device_s = NULL, *vlanport_s = NULL;
char *ifname, *new_name;
/* Update vid and name of device section */
@ -2761,7 +2766,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void
}
/* Update port section in dmmap */
struct uci_section *s;
struct uci_section *s = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", ((struct bridge_vlanport_args *)data)->br_inst, s) {
char *device;
dmuci_get_value_by_section_string(s, "device", &device);
@ -2833,12 +2838,13 @@ static int set_BridgingBridgeVLANPort_Alias(char *refparam, struct dmctx *ctx, v
static int get_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char linker[32], *vid = "";
char *vid = NULL;
/* Get vid from device network section */
dmuci_get_value_by_section_string(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "vid", &vid);
if (vid[0] != '\0') {
if (vid && vid[0] != '\0') {
char linker[32] = {0};
/* Get linker */
snprintf(linker, sizeof(linker),"br_%s:vlan_%s", ((struct bridge_vlanport_args *)data)->br_inst, (vid[0] != '\0') ? vid : "1");
adm_entry_get_linker_param(ctx, "Device.Bridging.Bridge.", linker, value);
@ -2890,7 +2896,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo
update_bridge_ifname(((struct bridge_vlanport_args *)data)->bridge_sec, ((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, 1);
/* Update port section in dmmap */
struct uci_section *s;
struct uci_section *s = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", ((struct bridge_vlanport_args *)data)->br_inst, s) {
char *device;
dmuci_get_value_by_section_string(s, "device", &device);
@ -2988,9 +2994,11 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo
dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "ifname", new_linker);
/* Update ifname list */
char new_ifname[128], *ifname;
char *ifname = NULL;
dmuci_get_value_by_section_string(((struct bridge_vlanport_args *)data)->bridge_sec, "ifname", &ifname);
if (ifname[0] != '\0') {
if (ifname && ifname[0] != '\0') {
char new_ifname[128] = {0};
remove_interface_from_ifname(new_linker, ifname, new_ifname);
dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_sec, "ifname", new_ifname);
}
@ -3179,11 +3187,10 @@ static int get_BridgingBridgeProviderBridge_CVLANcomponents(char *refparam, stru
static int set_BridgingBridgeProviderBridge_CVLANcomponents(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *bridge_linker = NULL;
char buf[strlen(value)+1];
char buf[256];
char *pch, *pchr;
strcpy(buf, value);
buf[strlen(value)] = '\0';
DM_STRNCPY(buf, value, sizeof(buf));
switch (action) {
case VALUECHECK:

View file

@ -203,16 +203,14 @@ int os__get_process_state(char* refparam, struct dmctx *ctx, void *data, char *i
int os__browseProcessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *processes = NULL, *arrobj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, inst) == DM_STOP)
break;
}
return 0;
}

View file

@ -97,12 +97,10 @@ static int get_device_active_fwimage(char *refparam, struct dmctx *ctx, void *da
/*#Device.DeviceInfo.UpTime!PROCFS:/proc/uptime*/
static int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE *fp = NULL;
char *pch, *spch, buf[64];
*value = "0";
fp = fopen(UPTIME, "r");
FILE *fp = fopen(UPTIME, "r");
if (fp != NULL) {
char *pch = NULL, *spch = NULL, buf[64] = {0};
if (fgets(buf, 64, fp) != NULL) {
pch = strtok_r(buf, ".", &spch);
*value = (pch) ? dmstrdup(pch) : "0";
@ -174,19 +172,19 @@ static int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *
static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir;
struct dirent *d_file;
char *config_name;
DIR *dir = NULL;
struct dirent *d_file = NULL;
char *config_name = NULL;
*value = "0001-01-01T00:00:00Z";
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &config_name);
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if (strcmp(config_name, d_file->d_name) == 0) {
if (config_name && strcmp(config_name, d_file->d_name) == 0) {
char date[sizeof("AAAA-MM-JJTHH:MM:SSZ")], path[280] = {0};
struct stat attr;
snprintf(path, sizeof(path), DEFAULT_CONFIG_DIR"%s", d_file->d_name);
snprintf(path, sizeof(path), "%s%s", DEFAULT_CONFIG_DIR, d_file->d_name);
stat(path, &attr);
strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%SZ", localtime(&attr.st_mtime));
*value = dmstrdup(date);
@ -233,8 +231,9 @@ static int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *in
static int check_file_dir(char *name)
{
DIR *dir;
struct dirent *d_file;
DIR *dir = NULL;
struct dirent *d_file = NULL;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if (strcmp(name, d_file->d_name) == 0) {
@ -292,8 +291,8 @@ static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
{
char *inst = NULL, *max_inst = NULL, *name;
struct uci_section *s = NULL, *del_sec = NULL;
DIR *dir;
struct dirent *d_file;
DIR *dir = NULL;
struct dirent *d_file = NULL;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
@ -329,8 +328,9 @@ static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *sys_log_sec, *dm_sec;
char *log_file,*log_size;
struct uci_section *sys_log_sec = NULL, *dm_sec = NULL;
char *log_file = NULL,*log_size = NULL;
char *inst = NULL, *max_inst = NULL;
int i = 1;
uci_foreach_sections("system", "system", sys_log_sec) {
@ -350,7 +350,6 @@ static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
}
}
uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) {
char *inst, *max_inst = NULL;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dm_sec, "vlf_instance", "vlf_alias");

View file

@ -297,7 +297,7 @@ static void dhcp_leases_assign_to_interface(struct dhcp_args *dhcp,
struct list_head *src,
const char *iface)
{
struct dhcp_lease *lease, *tmp;
struct dhcp_lease *lease = NULL, *tmp = NULL;
unsigned iface_addr;
unsigned iface_cidr;
unsigned iface_net;
@ -396,7 +396,7 @@ static int check_ipv4_in_dhcp_pool(struct uci_section *dhcp_sec, char *interface
static char *get_dhcp_network_from_relay_list(char *net_list)
{
struct uci_section *s;
struct uci_section *s = NULL;
char **net_list_arr, *v;
int i;
size_t length;
@ -591,7 +591,7 @@ static int addObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha
static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args*)data;
struct uci_section *s, *dmmap_section, *stmp;
struct uci_section *s = NULL, *dmmap_section = NULL, *stmp = NULL;
json_object *res, *jobj;
char *v;
@ -686,7 +686,7 @@ static int addObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void
static int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
char *list= NULL, *opt_value= NULL;
switch (del_action) {
@ -733,7 +733,7 @@ static int addObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *
static int delObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
char *list = NULL;
switch (del_action) {
@ -778,7 +778,7 @@ static int addObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void
static int delObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
char *opt_value = NULL;
struct uci_list *dhcp_options_list = NULL;
@ -1010,7 +1010,6 @@ static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
{
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end, value_addr;
int start = 0, limit = 0;
char buf[32] = {0};
switch (action) {
case VALUECHECK:
@ -1027,6 +1026,7 @@ static int set_DHCPv4ServerPool_MinAddress(char *refparam, struct dmctx *ctx, vo
unsigned value_net = ntohl(value_addr) & iface_bits;
if (value_net == iface_net) {
char buf[32] = {0};
unsigned dhcp_start = ntohl(value_addr) - iface_net;
unsigned dhcp_limit = start + limit - dhcp_start;
@ -1069,7 +1069,6 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
{
unsigned iface_addr, iface_bits, iface_net_start, iface_net_end, value_addr;
int start = 0, limit = 0;
char buf[32] = {0};
switch (action) {
case VALUECHECK:
@ -1086,6 +1085,7 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
unsigned value_net = ntohl(value_addr) & iface_bits;
if (value_net == iface_net) {
char buf_limit[32] = {0};
unsigned dhcp_limit = ntohl(value_addr) - iface_net - start + 1;
@ -1093,8 +1093,8 @@ static int set_DHCPv4ServerPool_MaxAddress(char *refparam, struct dmctx *ctx, vo
if ((int)dhcp_limit < 0)
return -1;
snprintf(buf, sizeof(buf), "%u", dhcp_limit);
dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "limit", buf);
snprintf(buf_limit, sizeof(buf_limit), "%u", dhcp_limit);
dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "limit", buf_limit);
}
@ -1173,7 +1173,7 @@ static int set_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx *
char *ip = NULL;
dmuci_get_value_by_section_string(s, "ip", &ip);
if (ip && ip[0] == '\0')
if (ip == NULL || *ip == '\0')
continue;
// Check if ip exists in the list value : yes -> skip it else delete it
@ -1184,10 +1184,8 @@ static int set_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx *
local_value = dmstrdup(value);
for (pch = strtok_r(local_value, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) {
bool host_exist = false;
// Check if host exists
host_exist = check_dhcp_host_option_exists(((struct dhcp_args *)data)->interface, "ip", pch);
bool host_exist = check_dhcp_host_option_exists(((struct dhcp_args *)data)->interface, "ip", pch);
// host exists -> skip it
if (host_exist)
@ -1366,7 +1364,7 @@ static int get_DHCPv4ServerPool_LeaseTime(char *refparam, struct dmctx *ctx, voi
*value = "-1";
dmuci_get_value_by_section_string(((struct dhcp_args *)data)->dhcp_sec, "leasetime", &ltime);
if (ltime && ltime[0] == '\0')
if (ltime == NULL || *ltime == '\0')
return 0;
if (strchr(ltime, 'd')) {
@ -1413,7 +1411,7 @@ static int set_DHCPv4ServerPool_LeaseTime(char *refparam, struct dmctx *ctx, voi
/*#Device.DHCPv4.Server.Pool.{i}.StaticAddressNumberOfEntries!UCI:dhcp/host/*/
static int get_DHCPv4ServerPool_StaticAddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int i = 0;
uci_foreach_option_eq("dhcp", "host", "dhcp", ((struct dhcp_args *)data)->interface, s) {
@ -1433,7 +1431,7 @@ static int get_DHCPv4ServerPool_StaticAddressNumberOfEntries(char *refparam, str
static int get_DHCPv4ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
int i = 0;
dmuci_get_value_by_section_list(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list);
@ -1666,7 +1664,7 @@ static int get_DHCPv4ServerPoolClient_OptionNumberOfEntries(char *refparam, stru
while (fgets(line, sizeof(line), f) != NULL) {
remove_new_line(line);
sscanf(line, "%24s vcid=%128s clid=%128s ucid=%128s",
sscanf(line, "%23s vcid=%127s clid=%127s ucid=%127s",
macaddr, vcid, clid, ucid);
if (strncmp(macaddr, (char *)args->lease->hwaddr, 24) == 0) {
@ -1724,7 +1722,7 @@ static int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *
static int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s, *dmmap_sect;
struct uci_section *s = NULL, *dmmap_sect = NULL;
int nbre_confs = 0, nbre_dmmaps = 0;
uci_foreach_option_eq("network", "interface", "proto", "dhcp", s) {
@ -2029,7 +2027,7 @@ static int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi
static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *pch, *spch = NULL, *list, *v, *opttagvalue, **sendopts, *oldopttagvalue;
char *pch, *spch = NULL, *list, *v = NULL, *opttagvalue, **sendopts = NULL, *oldopttagvalue;
size_t length;
switch (action) {
@ -2204,7 +2202,7 @@ static int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void
static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
char **buf = NULL;
size_t length;
@ -2229,7 +2227,7 @@ static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx,
static int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
char **buf = NULL, *opt_value;
size_t length;
bool test = false, b;
@ -2314,7 +2312,7 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi
char *opttagvalue, **option = NULL, *oldopttagvalue;
size_t length;
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
switch (action) {
case VALUECHECK:
@ -2358,7 +2356,7 @@ static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v
char *opttagvalue, **option = NULL, *oldopttagvalue;
size_t length;
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
char res[256] = {0};
switch (action) {
@ -2621,7 +2619,7 @@ static int get_DHCPv4Relay_Status(char *refparam, struct dmctx *ctx, void *data,
static int get_DHCPv4Relay_ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s, *dmmap_sect;
struct uci_section *s = NULL, *dmmap_sect = NULL;
int nbre_confs = 0, nbre_dmmaps = 0;
uci_foreach_option_eq("network", "interface", "proto", "relay", s) {
@ -2645,7 +2643,7 @@ static int browseDHCPv4ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
{
char *ignore = NULL, *interface, *inst = NULL, *max_inst = NULL, *v;
struct dhcp_args curr_dhcp_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(leases);
LIST_HEAD(dup_list);
@ -2686,7 +2684,7 @@ static int browseDHCPv4ServerPoolStaticAddressInst(struct dmctx *dmctx, DMNODE *
char *inst = NULL, *max_inst = NULL;
struct dhcp_host_args curr_dhcp_host_args = {0};
struct browse_args browse_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("dhcp", "host", "dmmap_dhcp", "dhcp", ((struct dhcp_args *)prev_data)->interface, &dup_list);
@ -2718,12 +2716,12 @@ static int browseDHCPv4ServerPoolStaticAddressInst(struct dmctx *dmctx, DMNODE *
static int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
const struct dhcp_args *dhcp = prev_data;
const struct dhcp_lease *lease;
const struct dhcp_lease *lease = NULL;
struct client_args client_args = {0};
char *inst = NULL, *max_inst = NULL;
int id = 0;
list_for_each_entry(lease, &dhcp->leases, list) {
struct client_args client_args;
char *inst, *max_inst = NULL;
init_dhcp_client_args(&client_args, lease);
@ -2737,9 +2735,9 @@ static int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *
static int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL;
char *max_inst = NULL;
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, 1);
char *inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, 1);
DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, inst);
return 0;
}
@ -2759,7 +2757,7 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p
while (fgets(line, sizeof(line), f) != NULL) {
remove_new_line(line);
sscanf(line, "%24s vcid=%128s clid=%128s ucid=%128s",
sscanf(line, "%23s vcid=%127s clid=%127s ucid=%127s",
macaddr, vcid, clid, ucid);
if (strncmp(macaddr, (char *)args->lease->hwaddr, 24) == 0) {
@ -2802,8 +2800,8 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p
/*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/
static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL, *ipv4addr = "", *mask4 = NULL;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL, *ipv4addr = "", *mask4 = NULL;
struct dmmap_dup *p = NULL;
json_object *res, *jobj;
struct dhcp_client_args dhcp_client_arg = {0};
LIST_HEAD(dup_list);
@ -2842,7 +2840,7 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct uci_section *dmmap_sect;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
struct browse_args browse_args = {0};
char *inst, *max_inst = NULL, *tag, *value, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL;
char *inst = NULL, *max_inst = NULL, *tag, *value, **sentopts = NULL, **buf = NULL, *tmp, *optionvalue, *v = NULL;
size_t length = 0, lgh2;
int i, j;
@ -2898,7 +2896,7 @@ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_n
struct uci_section *dmmap_sect;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
struct browse_args browse_args = {0};
char *inst, *max_inst = NULL, *tag, **reqtopts = NULL, *v = NULL;
char *inst = NULL, *max_inst = NULL, *tag, **reqtopts = NULL, *v = NULL;
size_t length = 0;
int i;
@ -2936,13 +2934,12 @@ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_n
static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
struct dhcp_args *curr_dhcp_args = (struct dhcp_args*)prev_data;
struct uci_section *dmmap_sect;
struct uci_section *dmmap_sect = NULL;
struct browse_args browse_args = {0};
char **tagvalue = NULL, *inst, *max_inst = NULL, *optionvalue = NULL, *tmp, *dhcpv4_tag, *dhcpv4_value;
size_t length;
int j;
char **tagvalue = NULL, *inst = NULL, *max_inst = NULL, *optionvalue = NULL, *tmp = NULL, *dhcpv4_tag, *dhcpv4_value;
size_t length = 0;
struct dhcp_client_option_args dhcp_client_opt_args = {0};
dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list);
@ -2959,6 +2956,8 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
}
optionvalue = dmstrdup(length > 1 ? tagvalue[1] : "");
if (length > 2) {
int j;
for (j = 2; j < length; j++) {
tmp = dmstrdup(optionvalue);
dmfree(optionvalue);
@ -2998,8 +2997,8 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *relay_ipv4addr = NULL, *relay_mask4 = NULL;
char *inst, *max_inst = NULL, *relay_network = NULL, *dhcp_network = NULL;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL, *relay_network = NULL, *dhcp_network = NULL;
struct dmmap_dup *p = NULL;
json_object *res, *jobj;
struct dhcp_client_args dhcp_relay_arg = {0};
LIST_HEAD(dup_list);

View file

@ -88,7 +88,7 @@ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void
struct dmmap_dup *p = NULL;
struct dhcpv6_client_args dhcpv6_client_arg = {0};
json_object *res, *jobj;
char *inst, *max_inst = NULL, *ipv6addr = NULL;
char *inst = NULL, *max_inst = NULL, *ipv6addr = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_dhcpv6", "proto", "dhcpv6", &dup_list);
@ -117,7 +117,7 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
{
char *ignore = NULL, *interface, *inst = NULL, *max_inst = NULL, *v;
struct dhcpv6_args curr_dhcp6_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dhcp", "dhcp", "dmmap_dhcpv6", &dup_list);
@ -149,7 +149,7 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args*)prev_data;
json_object *res, *res1, *jobj, *dev_obj= NULL, *net_obj= NULL;
json_object *res = NULL, *res1 = NULL, *jobj = NULL, *dev_obj = NULL, *net_obj = NULL;
struct clientv6_args curr_dhcp_client_args = {0};
int i = 0;
char *inst = NULL, *max_inst = NULL, *device;
@ -179,13 +179,12 @@ static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_
static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args*)prev_data;
struct uci_section *dmmap_sect;
struct uci_section *dmmap_sect = NULL;
struct browse_args browse_args = {0};
char **dhcpv6_option = NULL, *inst, *max_inst = NULL, *optionvalue= NULL, *tmp, *dhcpv6_tag, *dhcpv6_value;
char **dhcpv6_option = NULL, *inst = NULL, *max_inst = NULL, *optionvalue = NULL, *tmp = NULL, *dhcpv6_tag, *dhcpv6_value;
size_t length;
int j;
struct dhcpv6_client_option_args dhcpv6_client_opt_args = {0};
dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list);
@ -202,6 +201,8 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
}
optionvalue = dmstrdup(length > 1 ? dhcpv6_option[1] : "");
if (length > 2) {
int j;
for (j = 2; j < length; j++){
tmp = dmstrdup(optionvalue);
dmfree(optionvalue);
@ -301,7 +302,7 @@ static int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha
static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct dhcpv6_client_args *dhcpv6_client_args = (struct dhcpv6_client_args*)data;
struct uci_section *s, *dmmap_section, *ss = NULL;
struct uci_section *s = NULL, *dmmap_section, *ss = NULL;
int found = 0;
char *proto;
@ -432,7 +433,7 @@ static int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void
static int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
char *opt_value = NULL;
struct uci_list *dhcp_options_list = NULL;
@ -986,7 +987,7 @@ static int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *
static int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res, *res1, *jobj, *dev_obj = NULL, *next_obj = NULL;
json_object *res = NULL, *res1 = NULL, *jobj = NULL, *dev_obj = NULL, *next_obj = NULL;
char *device;
int i = 0;
@ -1012,7 +1013,7 @@ static int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmc
static int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
int i = 0;
dmuci_get_value_by_section_list(((struct dhcpv6_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list);
@ -1153,7 +1154,7 @@ static int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, st
static int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *dhcp_option_list;
struct uci_element *e;
struct uci_element *e = NULL;
char **buf = NULL;
size_t length;
@ -1180,8 +1181,8 @@ static int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx,
static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_list *dhcp_option_list;
struct uci_element *e;
char **buf, *opt_value;
struct uci_element *e = NULL;
char **buf = NULL, *opt_value;
size_t length;
bool test = false, b;
@ -1250,7 +1251,7 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi
char *opttagvalue, **option = NULL, *oldopttagvalue;
size_t length;
struct uci_list *dhcp_option_list= NULL;
struct uci_element *e;
struct uci_element *e = NULL;
switch (action) {
case VALUECHECK:
@ -1297,7 +1298,7 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v
char *opttagvalue, **option = NULL, *oldopttagvalue;
size_t length;
struct uci_list *dhcp_option_list = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
char res[256] = {0};
switch (action) {

View file

@ -30,17 +30,17 @@ static unsigned char is_dns_server_in_dmmap(char *chk_ip, char *chk_interface)
static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *jobj, *arrobj;
json_object *jobj, *arrobj = NULL;
struct uci_list *v;
struct uci_element *e;
struct uci_section *s = NULL, *sdns = NULL, *stmp, *ss;
char *ipdns, *str, *vip = NULL, *viface;
int j, found;
struct uci_element *e = NULL;
struct uci_section *s = NULL, *sdns = NULL, *stmp = NULL, *ss;
char *ipdns = NULL, *str, *vip = NULL, *viface;
int j = 0;
uci_path_foreach_sections_safe(bbfdm, "dmmap_dns", "dns_server", stmp, s) {
dmuci_get_value_by_section_string(s, "ip", &vip);
dmuci_get_value_by_section_string(s, "interface", &viface);
found = 0;
int found = 0;
uci_foreach_sections("network", "interface", ss) {
if (strcmp(section_name(ss), viface) != 0)
continue;
@ -104,7 +104,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa
static int browseDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
dmmap_synchronizeDNSClientRelayServer(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) {
@ -121,7 +121,7 @@ static int browseDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
static int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "NSLookupResult", s) {
@ -156,7 +156,7 @@ static int delete_dns_server(char *refparam, struct dmctx *ctx, void *data, char
struct uci_section *s = NULL, *ss = NULL, *stmp = NULL;
char *interface, *ip, *str;
struct uci_list *v;
struct uci_element *e, *tmp;
struct uci_element *e = NULL, *tmp = NULL;
switch (del_action) {
case DEL_INST:
@ -488,8 +488,8 @@ static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *i
{
char *str, *oip, *interface;
struct uci_list *v;
struct uci_element *e;
int count = 0, i = 0;
struct uci_element *e = NULL;
int count = 0;
char *dns[32] = {0};
switch (action) {
@ -518,6 +518,8 @@ static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *i
dmuci_delete("network", interface, "dns", NULL);
dmuci_get_value_by_section_string((struct uci_section *)data, "enable", &str);
if (str[0] == '1') {
int i = 0;
for (i = 0; i < count; i++) {
dmuci_add_list_value("network", interface, "dns", dns[i] ? dns[i] : "");
dmfree(dns[i]);

View file

@ -422,7 +422,7 @@ static char *get_dsl_standard(char *str)
/*#Device.DSL.Line.{i}.StandardsSupported!UBUS:dsl.line.1/status//standards_supported*/
static int get_DSLLine_StandardsSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *standards_supported, *pch, *spch, *tmp, *tmpPtr = NULL, *str = NULL;
char *standards_supported, *pch, *spch, *tmp = NULL, *tmpPtr = NULL, *str = NULL;
*value = "G.992.1_Annex_A";
standards_supported = get_dsl_value_array_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "standards_supported");
@ -982,7 +982,7 @@ static char *get_dsl_link_encapsulation_standard(char *str)
/*#Device.DSL.Channel.{i}.LinkEncapsulationSupported!UBUS:dsl.channel.1/status//link_encapsulation_supported*/
static int get_DSLChannel_LinkEncapsulationSupported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *link_encap,*pch, *spch, *tmp, *tmpPtr = NULL, *str = NULL;
char *link_encap,*pch, *spch, *tmp = NULL, *tmpPtr = NULL, *str = NULL;
*value = "G.994.1";
link_encap = get_dsl_value_array_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_supported");

View file

@ -36,7 +36,7 @@ static int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, voi
static int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ddns", "service", "dmmap_ddns", &dup_list);
@ -306,23 +306,26 @@ static int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ct
static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE *fp = NULL;
char line[256] = "", buf[1028] = "", buf_tmp[1024] = "", *pch = NULL, *spch = NULL;
char *pch = NULL, *spch = NULL;
*value = "";
fp = fopen(DDNS_PROVIDERS_FILE, "r");
FILE *fp = fopen(DDNS_PROVIDERS_FILE, "r");
if ( fp != NULL) {
char line[256] = {0};
char buf[1028] = {0};
char buf_tmp[1024] = {0};
while (fgets(line, 256, fp) != NULL) {
if (line[0] == '#')
continue;
pch = strtok_r(line, "\t", &spch);
pch= strstr(pch, "\"")+1;
pch[strchr(pch, '\"')-pch]=0;
pch = strstr(pch, "\"") + 1;
pch[strchr(pch, '\"')-pch] = 0;
if (strcmp(buf, "") == 0) {
snprintf(buf, sizeof(buf), "%s", pch);
} else {
strcpy(buf_tmp, buf);
DM_STRNCPY(buf_tmp, buf, sizeof(buf_tmp));
snprintf(buf, sizeof(buf), "%s,%s", buf_tmp, pch);
}
}
@ -359,19 +362,22 @@ static int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *
/*#Device.DynamicDNS.Client.{i}.Status!UCI:ddns/service,@i-1/enabled*/
static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
FILE* fp = NULL;
char buf[512] = "", path[64] = "", status[32] = "", *enable, *logdir = NULL;
char status[32] = {0}, *enable, *logdir = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
if (*enable == '\0' || strcmp(enable, "0") == 0) {
strcpy(status, "Disabled");
} else {
char path[64] = {0};
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
fp = fopen(path, "r");
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
strcpy(status, "Connecting");
while (fgets(buf, 512, fp) != NULL) {
if (strstr(buf, "Update successful"))
@ -818,24 +824,26 @@ static int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx,
static void set_server_address(struct uci_section *section, char *value)
{
char new[64], *dns_server;
char *dns_server = NULL;
dmuci_get_value_by_section_string(section, "dns_server", &dns_server);
if (*dns_server == '\0') {
if (dns_server && *dns_server == '\0') {
dmuci_set_value_by_section(section, "dns_server", value);
} else {
char *addr = strchr(dns_server, ':');
char new[64] = {0};
char *addr = dns_server ? strchr(dns_server, ':') : NULL;
if (addr)
snprintf(new, sizeof(new), "%s%s", value, addr);
else
strcpy(new, value);
DM_STRNCPY(new, value, sizeof(new));
dmuci_set_value_by_section(section, "dns_server", new);
}
}
static int set_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *service_name;
switch (action) {
@ -888,7 +896,7 @@ static void set_server_port(struct uci_section *section, char *value)
static int set_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *service_name;
switch (action) {

View file

@ -47,7 +47,7 @@ static inline int init_eth_rmon(struct eth_rmon_args *args, struct uci_section *
**************************************************************/
int is_vlan_termination_section(const char *name)
{
struct uci_section *s;
struct uci_section *s = NULL;
uci_foreach_sections("network", "interface", s) {
@ -124,7 +124,7 @@ static int check_section_in_curr_section(char *curr_section, char *section)
{
char *pch = NULL, *pchr = NULL, section_list[256] = {0};
strncpy(section_list, curr_section, sizeof(section_list) - 1);
DM_STRNCPY(section_list, curr_section, sizeof(section_list));
for (pch = strtok_r(section_list, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) {
if (strcmp(pch, section) == 0)
return 1;
@ -175,7 +175,7 @@ static void create_link(char *sec_name, char *mac_addr)
/* For all the Ethernet link objects pointing to same Ethernet Interface, only one ethernet link */
char intf[32] = {0};
strncpy(intf, device, sizeof(intf) - 1);
DM_STRNCPY(intf, device, sizeof(intf));
char *vid = strchr(intf, '.');
char *macvlan = strchr(intf, '_');
if (vid != NULL || !macvlan) {
@ -247,7 +247,7 @@ static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_nod
static char *get_vlan_last_instance_bbfdm(char *package, char *section, char *opt_inst)
{
struct uci_section *s, *confsect;
struct uci_section *s = NULL, *confsect;
char *inst = NULL, *last_inst = NULL, *type, *sect_name, *name;
uci_path_foreach_sections(bbfdm, package, section, s) {
@ -699,21 +699,18 @@ static int get_EthernetInterface_MACAddress(char *refparam, struct dmctx *ctx, v
static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *link_supported = NULL;
int rate = 0, arrlen = 0;
char *max_link, *autoneg;
int rate = 0;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "-1");
autoneg = dmjson_get_value(res, 1, "autoneg");
if (strcmp(autoneg, "true") == 0) {
char *autoneg = dmjson_get_value(res, 1, "autoneg");
if (autoneg && strcmp(autoneg, "true") == 0) {
*value = "-1";
} else {
json_object_object_get_ex(res, "link-supported", &link_supported);
if (link_supported)
arrlen = json_object_array_length(link_supported);
int arrlen = link_supported ? json_object_array_length(link_supported) : 0;
if (arrlen) {
max_link = dmjson_get_value_in_array_idx(link_supported, arrlen - 1, 0);
char *max_link = dmjson_get_value_in_array_idx(link_supported, arrlen - 1, 0);
sscanf(max_link, "%d%*s", &rate);
dmasprintf(value, "%d", rate);
}
@ -758,12 +755,12 @@ static int get_EthernetInterface_CurrentBitRate(char *refparam, struct dmctx *ct
static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL;
char mode, *speed, *autoneg;
char mode, *speed = NULL;
dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res);
DM_ASSERT(res, *value = "Auto");
autoneg = dmjson_get_value(res, 1, "autoneg");
if (strcmp(autoneg, "true") == 0) {
char *autoneg = dmjson_get_value(res, 1, "autoneg");
if (autoneg && strcmp(autoneg, "true") == 0) {
*value = "Auto";
} else {
speed = dmjson_get_value(res, 1, "speed");
@ -1046,20 +1043,20 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void
} else if (strncmp(value, "Device.Bridging.Bridge.", 23) == 0) {
char br_linker[250] = {0};
strncpy(br_linker, link_linker, sizeof(br_linker) - 1);
DM_STRNCPY(br_linker, link_linker, sizeof(br_linker));
char *bridge = strchr(br_linker, ':');
if (bridge) {
*bridge = '\0';
char br_inst[8] = {0};
strncpy(br_inst, br_linker+3, sizeof(br_inst) - 1);
DM_STRNCPY(br_inst, br_linker+3, sizeof(br_inst));
struct uci_section *port;
struct uci_section *port = NULL;
char *interface, *curr_interface;
// Remove the network section corresponding to this dmmap interface if exists
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &curr_interface);
struct uci_section *s, *tmp;
struct uci_section *s = NULL, *tmp = NULL;
uci_foreach_sections_safe("network", "interface", tmp, s) {
if (strcmp(section_name(s), curr_interface) == 0) {
char *proto;
@ -1279,7 +1276,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
uci_foreach_option_eq("network", "interface", "ifname", vlan_linker, s) {
dmuci_set_value_by_section(s, "ifname", new_name);
strncpy(sec_name, section_name(s), sizeof(sec_name) - 1);
DM_STRNCPY(sec_name, section_name(s), sizeof(sec_name));
break;
}
@ -1472,8 +1469,8 @@ static int set_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &name);
struct uci_section *s = NULL, *dmmap_s = NULL;
char *link_instance, new_name[16] = {0};
if (b && *name != '\0') {
char *link_instance = NULL, new_name[16] = {0};
int name_found = 0;
uci_foreach_option_eq("network", "interface", "ifname", name, s) {

View file

@ -244,7 +244,7 @@ static int get_FASTLine_LinkStatus(char *refparam, struct dmctx *ctx, void *data
/*#Device.FAST.Line.{i}.AllowedProfiles!UBUS:fast.line.1/status//allowed_profiles*/
static int get_FASTLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *allowed_profiles;
json_object *res = NULL, *allowed_profiles = NULL;
char list_profile[16], ubus_name[16], *profile = NULL;
unsigned pos = 0, idx = 0;

View file

@ -15,10 +15,9 @@
/***************************** Browse Functions ***********************************/
static int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *max_inst = NULL;
s = is_dmmap_section_exist("dmmap_firewall", "level");
struct uci_section *s = is_dmmap_section_exist("dmmap_firewall", "level");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "level", &s);
handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "firewall_level_instance", "firewall_level_alias");
@ -28,10 +27,9 @@ static int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_
static int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *max_inst = NULL;
s = is_dmmap_section_exist("dmmap_firewall", "chain");
struct uci_section *s = is_dmmap_section_exist("dmmap_firewall", "chain");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s);
handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "firewall_chain_instance", "firewall_chain_alias");
@ -42,8 +40,8 @@ static int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_
/*#Device.Firewall.Chain.{i}.Rule.{i}.!UCI:firewall/rule/dmmap_firewall*/
static int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list);
@ -342,7 +340,7 @@ static int get_FirewallChainRule_CreationDate(char *refparam, struct dmctx *ctx,
static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifaceobj = NULL, *src = NULL, buf[256] = "";
char *ifaceobj = NULL, *src = NULL, src_iface[256] = {0};
struct uci_list *net_list = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &src);
@ -368,23 +366,25 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da
}
if (net_list != NULL) {
struct uci_element *e;
struct uci_element *e = NULL;
unsigned pos = 0;
src_iface[0] = 0;
uci_foreach_element(net_list, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj);
if (ifaceobj == NULL)
continue;
if (*buf != '\0')
strcat(buf, ",");
strcat(buf, ifaceobj);
if (ifaceobj)
pos += snprintf(&src_iface[pos], sizeof(src_iface) - pos, "%s,", ifaceobj);
}
if (pos)
src_iface[pos - 1] = 0;
} else {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", src, &ifaceobj);
if (ifaceobj)
strcpy(buf, ifaceobj);
DM_STRNCPY(src_iface, ifaceobj, sizeof(src_iface));
}
*value = dmstrdup(buf);
*value = dmstrdup(src_iface);
return 0;
}
@ -398,7 +398,7 @@ static int get_rule_source_all_interfaces(char *refparam, struct dmctx *ctx, voi
static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ifaceobj = NULL, *dest = NULL, buf[256] = "";
char *ifaceobj = NULL, *dest = NULL, dst_iface[256] = {0};
struct uci_list *net_list = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &dest);
@ -424,23 +424,25 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data
}
if (net_list != NULL) {
struct uci_element *e;
struct uci_element *e = NULL;
unsigned pos = 0;
dst_iface[0] = 0;
uci_foreach_element(net_list, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj);
if (ifaceobj == NULL)
continue;
if (*buf != '\0')
strcat(buf, ",");
strcat(buf, ifaceobj);
if (ifaceobj)
pos += snprintf(&dst_iface[pos], sizeof(dst_iface) - pos, "%s,", ifaceobj);
}
if (pos)
dst_iface[pos - 1] = 0;
} else {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", dest, &ifaceobj);
if (ifaceobj)
strcpy(buf, ifaceobj);
DM_STRNCPY(dst_iface, ifaceobj, sizeof(dst_iface));
}
*value = dmstrdup(buf);
*value = dmstrdup(dst_iface);
return 0;
}
@ -474,7 +476,7 @@ static int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char
char buf[64], *pch, *destip;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
strcpy(buf, destip);
DM_STRNCPY(buf, destip, sizeof(buf));
pch = strchr(buf, '/');
if (pch) *pch = '\0';
*value = dmstrdup(buf);
@ -508,7 +510,7 @@ static int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha
char buf[64], *pch, *srcip;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
strcpy(buf, srcip);
DM_STRNCPY(buf, srcip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
*pch = '\0';
@ -636,8 +638,8 @@ static int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi
static int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *v= NULL;
struct uci_element *e;
char *ptr;
struct uci_element *e = NULL;
char *ptr = NULL;
dmasprintf(value, "%s", "");
dmuci_get_value_by_section_list((struct uci_section *)data, "icmp_type", &v);
@ -1136,12 +1138,12 @@ static int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
strcpy(buf, destip);
DM_STRNCPY(buf, destip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
snprintf(new, sizeof(new), "%s%s", value, pch);
else
strcpy(new, value);
DM_STRNCPY(new, value, sizeof(new));
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new);
break;
}
@ -1183,12 +1185,12 @@ static int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
strcpy(buf, srcip);
DM_STRNCPY(buf, srcip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
snprintf(new, sizeof(new), "%s%s", value, pch);
else
strcpy(new, value);
DM_STRNCPY(new, value, sizeof(new));
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new);
break;
}

View file

@ -17,9 +17,9 @@
static int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p= NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "proto", "gre", &dup_list);
list_for_each_entry(p, &dup_list, list) {
@ -35,7 +35,7 @@ static int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
struct uci_section *has_tunnel_interface_route(char *interface)
{
struct uci_section *s;
struct uci_section *s = NULL;
uci_foreach_option_eq("network", "route", "interface", interface, s) {
return s;
@ -46,8 +46,8 @@ struct uci_section *has_tunnel_interface_route(char *interface)
static int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *ifname= NULL;
struct dmmap_dup *p, *dm = (struct dmmap_dup *)prev_data;
struct uci_section *s;
struct dmmap_dup *p = NULL, *dm = (struct dmmap_dup *)prev_data;
struct uci_section *s = NULL;
struct browse_args browse_args = {0};
LIST_HEAD(dup_list);
@ -295,7 +295,7 @@ static int get_GRETunnel_ConnectedRemoteEndpoint(char *refparam, struct dmctx *c
static int get_GRETunnel_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *ifname;
int i = 0;

View file

@ -22,12 +22,10 @@ int os__browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
int id = 0, i = 0;
dmubus_call("router.network", "hosts", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, host_obj, i, 1, "hosts") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, arrobj, host_obj, i, 1, "hosts") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, inst) == DM_STOP)
break;
}
return 0;
}
@ -35,7 +33,7 @@ int os__browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev
/*#Device.Hosts.Host.{i}.IPv4Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv4addr*/
int os__browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr, *host_obj = (json_object *)prev_data;
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL, *ipv4addr = NULL;
int id = 0, i = 0;
@ -50,7 +48,7 @@ int os__browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node,
/*#Device.Hosts.Host.{i}.IPv6Address.{i}.!UBUS:router.network/hosts//hosts[@i-1].ipv6addr*/
int os__browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr, *host_obj = (json_object *)prev_data;
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL, *ipv6addr = NULL;
int id = 0, i = 0;

View file

@ -129,18 +129,3 @@ int os__get_HostsHostWANStats_PacketsReceived(char *refparam, struct dmctx *ctx,
{
return not_implemented(value);
}
int os__get_HostsHostWANStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}
int os__get_HostsHostWANStats_RetransCount(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}
int os__get_HostsHostWANStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}

View file

@ -64,12 +64,10 @@ static int browseIEEE1905ALInterfaceLinkInst(struct dmctx *dmctx, DMNODE *parent
int id = 0, i = 0;
dmubus_call((char *)prev_data, "link_info", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, link_obj, i, 1, "links") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)link_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, arrobj, link_obj, i, 1, "links") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)link_obj, inst) == DM_STOP)
break;
}
return 0;
}
@ -78,7 +76,7 @@ static int browseIEEE1905ALInterfaceLinkInst(struct dmctx *dmctx, DMNODE *parent
static int browseIEEE1905ALForwardingTableForwardingRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ieee1905", "forwarding_rule", "dmmap_forwarding_rule", &dup_list);
@ -102,13 +100,11 @@ static int browseIEEE1905ALNetworkTopologyChangeLogInst(struct dmctx *dmctx, DMN
int id = 0, i = 0;
dmubus_call("topology", "changelog", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "changelog") {
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "changelog") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;
}
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;
}
return 0;
}
@ -122,13 +118,11 @@ static int browseIEEE1905ALNetworkTopologyNonIEEE1905NeighborInst(struct dmctx *
dmubus_call("topology", "dump", UBUS_ARGS{}, 0, &res_self);
if (res_self)
json_object_object_get_ex(res_self, "self", &res);
if (res) {
dmjson_foreach_value_in_array(res, arrobj, obj, i, 1, "non1905_neighbors") {
dmjson_foreach_value_in_array(res, arrobj, obj, i, 1, "non1905_neighbors") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;
}
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;
}
return 0;
}
@ -140,13 +134,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInst(struct dmctx *dmctx
int id = 0, i = 0;
dmubus_call("topology", "dump", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, node, i, 1, "nodes") {
dmjson_foreach_obj_in_array(res, arrobj, node, i, 1, "nodes") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)node, inst) == DM_STOP)
break;
}
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)node, inst) == DM_STOP)
break;
}
return 0;
}
@ -206,7 +198,7 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInterfaceInst(struct dmc
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceNonIEEE1905NeighborInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj, *node = (json_object *)prev_data;
json_object *arrobj = NULL, *node = (json_object *)prev_data;
struct param_node param_st = {.node = node};
char *inst = NULL, *max_inst = NULL, *non1905_neighbor = NULL;
int id = 0, i = 0;
@ -1463,7 +1455,7 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceIEEE1905NeighborMetric_RSS
static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceBridgingTuple_InterfaceList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *tuple;
json_object *tuple = NULL;
char *tuple_mac = NULL, *interface = NULL;
char list_val[512];
int i = 0;

View file

@ -91,8 +91,7 @@ static struct uci_section *create_dmmap_interface_stack_section(char *curr_inst)
static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_node, char *higherlayer, char *lowerlayer, char *higheralias, char *loweralias, char *max_inst, int *instance)
{
struct interfacestack_data intf_stack_data = {0};
struct uci_section *dmmap_s = NULL;
char *inst = NULL, buf_instance[16] = {0};
char buf_instance[16] = {0};
// fill interface stack data
intf_stack_data.higherlayer = higherlayer;
@ -102,10 +101,10 @@ static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE
// create dmmap section
snprintf(buf_instance, sizeof(buf_instance), "%d", ++(*instance));
dmmap_s = create_dmmap_interface_stack_section(buf_instance);
struct uci_section *dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
char *inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
@ -178,7 +177,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (device[0] != '\0' && found == 0) {
// The lower layer is Device.Ethernet.Link.{i}.
char linker[32] = {0};
strncpy(linker, device, sizeof(linker) - 1);
DM_STRNCPY(linker, device, sizeof(linker));
char *vid = strchr(linker, '.');
if (vid) *vid = '\0';
adm_entry_get_linker_param(dmctx, "Device.Ethernet.Link.", linker, &value);
@ -230,7 +229,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
if (found == 0) {
// The lower layer is Device.Ethernet.Link.{i}.
char linker[32] = {0};
strncpy(linker, ppp_device, sizeof(linker) - 1);
DM_STRNCPY(linker, ppp_device, sizeof(linker));
char *vid = strchr(linker, '.');
if (vid) *vid = '\0';
adm_entry_get_linker_param(dmctx, "Device.Ethernet.Link.", linker, &value);
@ -304,7 +303,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
// The lower layer is Device.Bridging.Bridge.{i}.Port.{i}.
char *int_name;
dmuci_get_value_by_section_string(s, "section_name", &int_name);
struct uci_section *dmmap_section, *port;
struct uci_section *dmmap_section, *port = NULL;
get_dmmap_section_of_config_section("dmmap_bridge", "bridge", int_name, &dmmap_section);
@ -419,7 +418,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
// The lower layer is Device.Ethernet.Interface.{i}.
adm_entry_get_linker_param(dmctx, "Device.Ethernet.Interface.", device, &value);
if (value != NULL) {
strncpy(package, "ports", sizeof(package) - 1);
DM_STRNCPY(package, "ports", sizeof(package));
struct uci_section *port_s = NULL;
uci_foreach_option_eq("ports", "ethport", "ifname", device, port_s) {
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");
@ -434,7 +433,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
adm_entry_get_linker_param(dmctx, "Device.WiFi.SSID.", device, &value);
if (!found && value != NULL) {
strncpy(package, "wireless", sizeof(package) - 1);
DM_STRNCPY(package, "wireless", sizeof(package));
struct uci_section *wl_s = NULL;
uci_foreach_option_eq("wireless", "wifi-iface", "ifname", device, wl_s) {
loweralias = get_alias_by_section("dmmap_wireless", "wifi-iface", wl_s, "ssidalias");
@ -452,7 +451,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
if (!found && value != NULL) {
strncpy(package, "dsl:atm", sizeof(package) - 1);
DM_STRNCPY(package, "dsl:atm", sizeof(package));
struct uci_section *dsl_s = NULL;
uci_foreach_option_eq("dsl", "atm-device", "device", device, dsl_s) {
loweralias = get_alias_by_section("dmmap_dsl", "atm-device", dsl_s, "atmlinkalias");
@ -470,7 +469,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
if (!found && value != NULL) {
strncpy(package, "dsl:ptm", sizeof(package) - 1);
DM_STRNCPY(package, "dsl:ptm", sizeof(package));
struct uci_section *dsl_s = NULL;
uci_foreach_option_eq("dsl", "ptm-device", "device", device, dsl_s) {
loweralias = get_alias_by_section("dmmap_dsl", "ptm-device", dsl_s, "ptmlinkalias");
@ -488,7 +487,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
}
if (!found && value != NULL) {
strncpy(package, "ports", sizeof(package) - 1);
DM_STRNCPY(package, "ports", sizeof(package));
struct uci_section *port_s = NULL;
uci_foreach_option_eq("ports", "ethport", "ifname", device, port_s) {
loweralias = get_alias_by_section("dmmap_ports", "ethport", port_s, "eth_port_alias");

View file

@ -292,13 +292,12 @@ static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void)
json_object *res = NULL, *ipv6_prefix_obj = NULL, *arrobj = NULL;
struct uci_section *s = NULL, *ss = NULL, *stmp = NULL;
char *dmmap_intf_s, *dmmap_address, *ip6prefix = NULL, ipv6_prefix[256] = {0};
bool found = false;
int i = 0;
uci_path_foreach_sections_safe(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &dmmap_intf_s);
dmuci_get_value_by_section_string(s, "address", &dmmap_address);
found = false;
bool found = false;
ss = get_origin_section_from_config("network", "interface", dmmap_intf_s);
dmuci_get_value_by_section_string(ss, "ip6prefix", &ip6prefix);
@ -523,7 +522,7 @@ static int delObjIPInterfaceIPv6(void *data, unsigned char del_action, char *dmm
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec))))
if (strcmp(proto, "static") != 0 || interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec)))
return FAULT_9001;
dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ifname", &ifname);
@ -537,7 +536,7 @@ static int delObjIPInterfaceIPv6(void *data, unsigned char del_action, char *dmm
break;
case DEL_ALL:
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
if (strcmp(proto, "static") != 0 || (strcmp(proto, "static") == 0 && interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data))))
if (strcmp(proto, "static") != 0 || interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data)))
return FAULT_9001;
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
@ -573,7 +572,7 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
{
char *inst = NULL, *max_inst = NULL;
char *proto, *ifname;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list);
@ -900,16 +899,18 @@ static int delObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char
static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *last_inst = NULL, *ip_inst, ipv4_name[64] = {0}, buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv4;
char *ip_inst = NULL, ipv4_name[64] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv4 = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv4", "intf_ipv4", "ipv4_instance", "parent_section", section_name((struct uci_section *)data));
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv4", "intf_ipv4", "ipv4_instance", "parent_section", section_name((struct uci_section *)data));
if (last_inst) {
char buf[32] = {0};
snprintf(ipv4_name, sizeof(ipv4_name), "ip_interface_%s_ipv4_%d", ip_inst, atoi(last_inst) + 1);
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
@ -989,14 +990,14 @@ static int delObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void
static int addObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *last_inst = NULL, *ip_inst, ipv6_name[64] = {0}, buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6;
char *ip_inst = NULL, ipv6_name[64] = {0}, buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6 = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6", "intf_ipv6", "ipv6_instance", "parent_section", section_name((struct uci_section *)data));
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6", "intf_ipv6", "ipv6_instance", "parent_section", section_name((struct uci_section *)data));
snprintf(ipv6_name, sizeof(ipv6_name), "ip_interface_%s_ipv6_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1);
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
@ -1024,14 +1025,14 @@ static int delObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void
static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
char *last_inst = NULL, *ip_inst, ipv6_prefix_name[64] = {0}, buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6_prefix;
char *ip_inst = NULL, ipv6_prefix_name[64] = {0}, buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6_prefix = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "ipv6_prefix_instance", "parent_section", section_name((struct uci_section *)data));
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "ipv6_prefix_instance", "parent_section", section_name((struct uci_section *)data));
snprintf(ipv6_prefix_name, sizeof(ipv6_prefix_name), "ip_interface_%s_ipv6_prefix_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1);
snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data));
@ -1384,7 +1385,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
if (device[0] != '\0') {
char linker[32] = {0};
strncpy(linker, device, sizeof(linker) - 1);
DM_STRNCPY(linker, device, sizeof(linker));
char *vid = strchr(linker, '.');
if (vid) *vid = '\0';
adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", linker, value);
@ -1437,7 +1438,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
} else {
// Check if there is an interface that has the same name of device ==> if yes, remove it
char device[32] = {0};
strncpy(device, ip_linker, sizeof(device) - 1);
DM_STRNCPY(device, ip_linker, sizeof(device));
char *vid = strchr(device, '.');
if (vid) {
*vid = '\0';

View file

@ -662,7 +662,7 @@ static int set_management_server_conn_rep_allowed_jabber_id(char *refparam, stru
static int get_management_server_conn_req_jabber_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *username, *domain, *resource, *tmpPtr = NULL, *strResponse = NULL;
uci_foreach_sections("xmpp", "xmpp_connection", s) {

View file

@ -221,21 +221,26 @@ static int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, vo
static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *v = NULL;
struct uci_element *e;
char *ifaceobj, buf[256] = "";
char buf[256];
unsigned pos = 0;
*value = "";
buf[0] = 0;
dmuci_get_value_by_section_list((struct uci_section *)data, "network", &v);
if (v == NULL)
return 0;
uci_foreach_element(v, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN
if (ifaceobj == NULL)
continue;
if (*buf != '\0')
strcat(buf, ",");
strcat(buf, ifaceobj);
if (v) {
struct uci_element *e = NULL;
char *ifaceobj = NULL;
uci_foreach_element(v, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN
if (ifaceobj)
pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", ifaceobj);
}
}
/* cut tailing ',' */
if (pos)
buf[pos - 1] = 0;
*value = dmstrdup(buf);
return 0;
}
@ -250,7 +255,7 @@ static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx
return FAULT_9007;
return 0;
case VALUESET:
strcpy(buf, value);
DM_STRNCPY(buf, value, sizeof(buf));
dmuci_set_value_by_section((struct uci_section *)data, "network", "");
for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) {
adm_entry_get_linker_value(ctx, pch, &iface);
@ -332,14 +337,14 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi
{
struct uci_section *s = NULL;
struct uci_list *v = NULL;
struct uci_element *e;
char *zone_name = NULL, *name = NULL, *ifaceobj = NULL, *src_dip = NULL;
char buf[256] = "";
char *zone_name = NULL, *name = NULL, *src_dip = NULL, buf[256];
unsigned pos = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", &src_dip);
if (src_dip && strcmp(src_dip, "*") == 0)
return 0;
buf[0] = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone_name);
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "name", &name);
@ -348,16 +353,22 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi
break;
}
}
if (v == NULL)
return 0;
uci_foreach_element(v, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN
if (ifaceobj == NULL)
continue;
if (*buf != '\0')
strcat(buf, ",");
strcat(buf, ifaceobj);
if (v) {
struct uci_element *e = NULL;
char *ifaceobj = NULL;
uci_foreach_element(v, e) {
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", e->name, &ifaceobj); // MEM WILL BE FREED IN DMMEMCLEAN
if (ifaceobj)
pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", ifaceobj);
}
}
/* cut tailing ',' */
if (pos)
buf[pos - 1] = 0;
*value = dmstrdup(buf);
return 0;
}
@ -628,8 +639,8 @@ static int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, v
/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/
static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list);
@ -648,8 +659,8 @@ static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node,
/*#Device.NAT.PortMapping.{i}.!UCI:firewall/redirect/dmmap_firewall*/
static int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL, *target;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL, *target;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list);

View file

@ -102,9 +102,6 @@ int os__get_access_point_associative_device_statistics_tx_packets(char *refparam
int os__get_access_point_associative_device_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_access_point_associative_device_statistics_tx_errors(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_access_point_associative_device_statistics_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os__get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
@ -333,7 +330,6 @@ int os_get_QoSQueueStats_OutputPackets(char *refparam, struct dmctx *ctx, void *
int os_get_QoSQueueStats_OutputBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os_get_QoSQueueStats_DroppedPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os_get_QoSQueueStats_DroppedBytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
//int os_get_QoSQueueStats_QueueOccupancyPackets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
int os_browseQoSQueueInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int os_browseQoSShaperInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance);
int os_addObjQoSQueue(char *refparam, struct dmctx *ctx, void *data, char **instance);

View file

@ -304,7 +304,7 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
static int get_PPP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *proto;
int nbre = 0;
@ -454,7 +454,7 @@ static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, c
static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *proto;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list);

View file

@ -245,7 +245,7 @@ static int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
{
char *inst = NULL, *max_inst = NULL, *ifname;
struct ptm_args curr_ptm_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "ptm-device", "dmmap_dsl", &dup_list);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -184,7 +184,7 @@ static int parse_proc_route6_line(const char *line, char *ipstr, char *gwstr, ch
gw[3] = htonl(gw[3]);
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
sprintf(ipstr, "%s/%u", ipbuf, prefix);
snprintf(ipstr, INET6_ADDRSTRLEN + 8, "%s/%u", ipbuf, prefix);
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
return 0;
@ -264,19 +264,19 @@ static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst
static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
struct proc_routing proute = {0};
json_object *jobj;
FILE* fp = NULL;
char *target, *iface, *str, line[MAX_PROC_ROUTING];
int found, lines;
char *target = NULL, *iface = NULL, *str = NULL, line[MAX_PROC_ROUTING] = {0};
int lines;
uci_path_foreach_sections_safe(bbfdm, "dmmap_route_forwarding", "route_dynamic", stmp, s) {
dmuci_get_value_by_section_string(s, "target", &target);
dmuci_get_value_by_section_string(s, "device", &iface);
found = 0;
fp = fopen(PROC_ROUTE, "r");
if ( fp != NULL) {
bool found = false;
lines = 0;
while (fgets(line, MAX_PROC_ROUTING, fp) != NULL) {
if (line[0] == '\n' || lines == 0) { /* skip the first line or skip the line if it's empty */
@ -285,7 +285,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
}
parse_proc_route_line(line, &proute);
if ((strcmp(iface, proute.iface) == 0) && strcmp(target, proute.destination) == 0) {
found = 1;
found = true;
break;
}
}
@ -449,7 +449,7 @@ static int get_RoutingRouter_Status(char *refparam, struct dmctx *ctx, void *dat
/*#Device.Routing.Router.{i}.IPv4ForwardingNumberOfEntries!UCI:network/route/*/
static int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("network", "route", s) {
@ -469,7 +469,7 @@ static int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struc
/*#Device.Routing.Router.{i}.IPv6ForwardingNumberOfEntries!UCI:network/route6/*/
static int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("network", "route6", s) {
@ -1216,7 +1216,7 @@ static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
struct uci_section *ss = NULL;
bool find_max = true, ipv4_forwarding = true;
struct routingfwdargs curr_routefwdargs = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
@ -1271,7 +1271,7 @@ static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, vo
struct uci_section *ss = NULL;
bool find_max = true, ipv4_forwarding = false;
struct routingfwdargs curr_route6fwdargs = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
@ -1322,7 +1322,7 @@ end:
static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
uci_foreach_sections("network", "interface", s) {

View file

@ -158,7 +158,7 @@ static char *get_certificate_pk(mbedtls_pk_type_t sig_pk)
static void get_certificate_paths(void)
{
struct uci_section *s;
struct uci_section *s = NULL;
int cidx;
for (cidx=0; cidx<MAX_CERT; cidx++)
@ -175,7 +175,7 @@ static void get_certificate_paths(void)
break;
if(!file_exists(cert) || !is_regular_file(cert))
continue;
strncpy(certifcates_paths[cidx], cert, 256);
DM_STRNCPY(certifcates_paths[cidx], cert, 256);
cidx++;
}
@ -188,7 +188,7 @@ static void get_certificate_paths(void)
break;
if(!file_exists(cert) || !is_regular_file(cert))
continue;
strncpy(certifcates_paths[cidx], cert, 256);
DM_STRNCPY(certifcates_paths[cidx], cert, 256);
cidx++;
}
@ -201,7 +201,7 @@ static void get_certificate_paths(void)
break;
if(!file_exists(cert) || !is_regular_file(cert))
continue;
strncpy(certifcates_paths[cidx], cert, 256);
DM_STRNCPY(certifcates_paths[cidx], cert, 256);
cidx++;
}
}
@ -219,8 +219,7 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod
if(!strlen(certifcates_paths[i]))
break;
#ifdef LOPENSSL
FILE *fp = NULL;
fp = fopen(certifcates_paths[i], "r");
FILE *fp = fopen(certifcates_paths[i], "r");
if (fp == NULL)
continue;
X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
@ -284,8 +283,7 @@ static int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx
if(!strlen(certifcates_paths[i]))
break;
#ifdef LOPENSSL
FILE *fp = NULL;
fp = fopen(certifcates_paths[i], "r");
FILE *fp = fopen(certifcates_paths[i], "r");
if (fp == NULL)
continue;
X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);

View file

@ -35,7 +35,7 @@ static int get_du_linker(char *refparam, struct dmctx *dmctx, void *data, char *
static int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, env = 0;
dmubus_call("swmodules", "environment", UBUS_ARGS{}, 0, &res);
@ -50,7 +50,7 @@ static int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_
static int browseSoftwareModulesDeploymentUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, du = 0;
dmubus_call("swmodules", "du_list", UBUS_ARGS{}, 0, &res);
@ -65,7 +65,7 @@ static int browseSoftwareModulesDeploymentUnitInst(struct dmctx *dmctx, DMNODE *
static int browseSoftwareModulesExecutionUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, eu = 0;
dmubus_call("swmodules", "eu_list", UBUS_ARGS{}, 0, &res);
@ -210,12 +210,12 @@ static int set_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, v
static int get_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *env_name, *name = NULL;
char *env_name = NULL;
name = dmjson_get_value((json_object *)data, 1, "name");
char *name = dmjson_get_value((json_object *)data, 1, "name");
uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "environment", s) {
dmuci_get_value_by_section_string(s, "name", &env_name);
if (name && strcmp(env_name, name) == 0) {
if (name && env_name && strcmp(env_name, name) == 0) {
dmuci_get_value_by_section_string(s, "alias", value);
break;
}
@ -332,7 +332,7 @@ static int get_SoftwareModulesExecEnv_ActiveExecutionUnits(char *refparam, struc
char *environment = dmjson_get_value(du_obj, 1, "environment");
if (strcmp(environment, curr_env) == 0)
pos += snprintf(&eu_list[pos], sizeof(eu_list) - pos, "Device.SoftwareModules.ExecutionUnit.%d,", eu+1);
pos += snprintf(&eu_list[pos], sizeof(eu_list) - pos, "Device.SoftwareModules.ExecutionUnit.%u,", eu+1);
}
if (pos)
@ -359,14 +359,14 @@ static int get_SoftwareModulesDeploymentUnit_DUID(char *refparam, struct dmctx *
static int get_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *du_name, *du_env, *environment = NULL, *name = NULL;
char *du_name = NULL, *du_env = NULL;
name = dmjson_get_value((json_object *)data, 1, "name");
environment = dmjson_get_value((json_object *)data, 1, "environment");
char *name = dmjson_get_value((json_object *)data, 1, "name");
char *environment = dmjson_get_value((json_object *)data, 1, "environment");
uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "deployment_unit", s) {
dmuci_get_value_by_section_string(s, "name", &du_name);
dmuci_get_value_by_section_string(s, "environment", &du_env);
if (name && (strcmp(du_name, name) == 0) && (environment && strcmp(du_env, environment) == 0)) {
if (name && du_name && (strcmp(du_name, name) == 0) && (environment && du_env && strcmp(du_env, environment) == 0)) {
dmuci_get_value_by_section_string(s, "alias", value);
break;
}
@ -466,18 +466,18 @@ static int get_SoftwareModulesDeploymentUnit_VendorConfigList(char *refparam, st
static int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
char *environment, *name, *curr_environment, *curr_name;
char *environment = NULL, *name = NULL;
int eu = 0;
curr_name = dmjson_get_value((json_object *)data, 1, "name");
curr_environment = dmjson_get_value((json_object *)data, 1, "environment");
char *curr_name = dmjson_get_value((json_object *)data, 1, "name");
char *curr_environment = dmjson_get_value((json_object *)data, 1, "environment");
dmubus_call("swmodules", "eu_list", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, arrobj, du_obj, eu, 1, "execution_unit") {
name = dmjson_get_value(du_obj, 1, "name");
environment = dmjson_get_value(du_obj, 1, "environment");
if ((strcmp(name, curr_name) == 0) && (strcmp(environment, curr_environment) == 0)) {
if ((name && curr_name && strcmp(name, curr_name) == 0) && (environment && curr_environment && strcmp(environment, curr_environment) == 0)) {
dmasprintf(value, "Device.SoftwareModules.ExecutionUnit.%d", eu+1);
break;
}
@ -505,14 +505,14 @@ static int get_SoftwareModulesExecutionUnit_EUID(char *refparam, struct dmctx *c
static int get_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *eu_euid, *eu_env, *environment = NULL, *euid = NULL;
char *eu_euid = NULL, *eu_env = NULL;
euid = dmjson_get_value((json_object *)data, 1, "euid");
environment = dmjson_get_value((json_object *)data, 1, "environment");
char *euid = dmjson_get_value((json_object *)data, 1, "euid");
char *environment = dmjson_get_value((json_object *)data, 1, "environment");
uci_path_foreach_sections(bbfdm, "dmmap_sw_modules", "execution_unit", s) {
dmuci_get_value_by_section_string(s, "euid", &eu_euid);
dmuci_get_value_by_section_string(s, "environment", &eu_env);
if ((euid && strcmp(eu_euid, euid) == 0) && (environment && strcmp(eu_env, environment) == 0)) {
if ((euid && eu_euid && strcmp(eu_euid, euid) == 0) && (environment && eu_env && strcmp(eu_env, environment) == 0)) {
dmuci_get_value_by_section_string(s, "alias", value);
break;
}
@ -614,18 +614,18 @@ static int get_SoftwareModulesExecutionUnit_MemoryInUse(char *refparam, struct d
static int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *du_obj = NULL, *arrobj = NULL;
char *environment, *name, *curr_environment, *curr_name;
int du = 0;
char *environment = NULL, *name = NULL;
int du = 0;
curr_name = dmjson_get_value((json_object *)data, 1, "name");
curr_environment = dmjson_get_value((json_object *)data, 1, "environment");
char *curr_name = dmjson_get_value((json_object *)data, 1, "name");
char *curr_environment = dmjson_get_value((json_object *)data, 1, "environment");
dmubus_call("swmodules", "du_list", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, arrobj, du_obj, du, 1, "deployment_unit") {
name = dmjson_get_value(du_obj, 1, "name");
environment = dmjson_get_value(du_obj, 1, "environment");
if ((strcmp(name, curr_name) == 0) && (strcmp(environment, curr_environment) == 0)) {
if ((name && curr_name && strcmp(name, curr_name) == 0) && (environment && curr_environment && strcmp(environment, curr_environment) == 0)) {
dmasprintf(value, "Device.SoftwareModules.DeploymentUnit.%d", du+1);
break;
}
@ -636,15 +636,15 @@ static int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dm
static int get_SoftwareModulesExecutionUnit_AssociatedProcessList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *processes_obj = NULL, *arrobj = NULL;
char *euid, *pid;
char *pid = NULL;
int process = 0;
euid = dmjson_get_value((json_object *)data, 1, "euid");
char *euid = dmjson_get_value((json_object *)data, 1, "euid");
dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "");
dmjson_foreach_obj_in_array(res, arrobj, processes_obj, process, 1, "processes") {
pid = dmjson_get_value(processes_obj, 1, "pid");
if (strcmp(euid, pid) == 0) {
if (pid && euid && strcmp(euid, pid) == 0) {
dmasprintf(value, "Device.DeviceInfo.ProcessStatus.Process.%d", process+1);
break;
}

View file

@ -94,12 +94,13 @@ static int get_local_time_zone_name(char *refparam, struct dmctx *ctx, void *dat
static int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int index)
{
bool found = 0;
int element = 0;
struct uci_list *v;
struct uci_element *e;
struct uci_element *e = NULL;
dmuci_get_option_value_list("system","ntp","server", &v);
if (v) {
int element = 0;
uci_foreach_element(v, e) {
element++;
if (element == index) {
@ -178,7 +179,7 @@ static int set_time_source_interface(char *refparam, struct dmctx *ctx, void *da
static int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *value, int index)
{
struct uci_list *v;
struct uci_element *e;
struct uci_element *e = NULL;
int count = 0, i = 0;
char *ntp[5] = {0};

View file

@ -151,7 +151,7 @@ static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_nod
json_object *res = NULL, *devices = NULL, *device = NULL;
struct upnpdiscovery upnp_dev = {};
char *dev_descurl = NULL, *dev_st = NULL, *dev_usn = NULL, *inst = NULL, *max_inst = NULL;
char **stparams = NULL, **uuid, **urn;
char **stparams = NULL, **uuid = NULL, **urn = NULL;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
int i;
@ -197,7 +197,7 @@ static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_no
json_object *res = NULL, *services = NULL, *service = NULL;
struct upnpdiscovery upnp_dev = {};
char *srv_descurl = NULL, *srv_st = NULL, *srv_usn = NULL, *inst = NULL, *max_inst = NULL;
char **stparams = NULL, **uuid, **urn;
char **stparams = NULL, **uuid = NULL, **urn = NULL;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
int i;
@ -439,7 +439,7 @@ static int set_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data,
static int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int nbre = 0, i;
int nbre = 0;
char *is_root_device = NULL;
json_object *res = NULL, *devices = NULL, *device = NULL;
@ -453,7 +453,9 @@ static int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dm
return 0;
size_t nbre_devices = json_object_array_length(devices);
if (nbre_devices > 0){
if (nbre_devices > 0) {
int i;
for (i = 0; i < nbre_devices; i++){
device = json_object_array_get_idx(devices, i);
is_root_device = dmjson_get_value(device, 1, "is_root_device");

View file

@ -117,14 +117,14 @@ static void writeFileContent(const char *filepath, const char *data)
static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir;
struct dirent *ent;
DIR *dir = NULL;
struct dirent *ent = NULL;
char *iface_path, *statistics_path, *max_inst = NULL, *inst = NULL;
size_t length;
char **foldersplit;
struct usb_interface iface= {};
LIST_HEAD(dup_list);
struct sysfs_dmsection *p;
struct sysfs_dmsection *p = NULL;
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "usb_iface_link", "usb_iface_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
@ -136,11 +136,10 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
iface_name[0] = 0;
snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name);
if (!folder_exists(netfolderpath)) {
//dmuci_delete_by_section_unnamed_bbfdm(p->dm, NULL, NULL);
if (!folder_exists(netfolderpath))
continue;
}
if(p->dmmap_section){
if (p->dmmap_section) {
foldersplit= strsplit(p->sysfs_folder_name, ":", &length);
snprintf(port_link, sizeof(port_link), "%s", foldersplit[0]);
}
@ -175,7 +174,7 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
{
char *max_inst = NULL, *inst = NULL;
struct usb_port port = {0};
struct sysfs_dmsection *p;
struct sysfs_dmsection *p = NULL;
LIST_HEAD(dup_list);
regex_t regex1 = {};
regex_t regex2 = {};
@ -210,7 +209,7 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct sysfs_dmsection *p;
struct sysfs_dmsection *p = NULL;
char *inst = NULL, *max_inst = NULL;
struct usb_port port = {0};
LIST_HEAD(dup_list);
@ -236,11 +235,11 @@ static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, v
static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, int is_root, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
DIR *dir;
struct dirent *ent;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_sect = NULL;
DIR *dir = NULL;
struct dirent *ent = NULL;
char *v, *sysfs_repo_path, *instance = NULL;
struct sysfs_dmsection *p;
struct sysfs_dmsection *p = NULL;
regex_t regex1 = {}, regex2 = {};
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
@ -277,7 +276,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
/*
* Add system and dmmap sections to the list
*/
if (instance == NULL || strlen(instance) <= 0)
if (instance == NULL || *instance == '\0')
add_sysfs_section_list(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_repo_path);
else
add_sysfs_section_list(dup_list, dmmap_sect, ent->d_name, sysfs_repo_path);
@ -309,7 +308,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
static int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct sysfs_dmsection *p;
struct sysfs_dmsection *p = NULL;
char *instance = NULL, *instnbr = NULL, *parent_host_instance = NULL;
struct usb_port port= {};
struct usb_port *prev_port = (struct usb_port *)prev_data;
@ -367,8 +366,8 @@ static int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMN
static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir;
struct dirent *ent;
DIR *dir = NULL;
struct dirent *ent = NULL;
struct usb_port *usb_dev = (struct usb_port*)prev_data;
struct usb_port port = {0};
char *sysfs_rep_path, *inst = NULL, *max_inst = NULL;
@ -412,35 +411,30 @@ static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *d
**************************************************************/
static int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir;
struct dirent *ent;
char filename[276] = {0};
char buffer[64];
int nbre= 0;
ssize_t rc;
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre = 0;
if ((dir = opendir ("/sys/class/net")) == NULL)
return 0;
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
char netfolderpath[512] = {0};
while ((ent = readdir (dir)) != NULL) {
snprintf(filename, sizeof(filename), "/sys/class/net/%s", ent->d_name);
rc = readlink (filename, buffer, sizeof(buffer) - 1);
if (rc > 0) {
buffer[rc] = 0;
if (*(ent->d_name) == '.')
continue;
if(strstr(buffer, "/usb"))
nbre++;
}
snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, ent->d_name);
if (folder_exists(netfolderpath))
nbre++;
}
closedir(dir);
dmasprintf(value, "%d", nbre);
return 0;
}
static int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir;
struct dirent *ent;
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre = 0;
regex_t regex1 = {};
regex_t regex2 = {};
@ -462,11 +456,6 @@ static int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *
return 0;
}
static int isfileexist(const char *filepath)
{
return access(filepath, F_OK) == 0;
}
static int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char carrier[8];
@ -704,8 +693,8 @@ static int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char
static int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir;
struct dirent *ent;
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre= 0;
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
@ -825,7 +814,7 @@ static int set_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmct
string_to_bool(value, &b);
char *filepath;
dmasprintf(&filepath, "%s/power/level", host->folder_path);
if (!isfileexist(filepath))
if (!file_exists(filepath))
break;
writeFileContent(filepath, b?"on":"suspend");
break;
@ -848,8 +837,8 @@ static int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, voi
static int get_number_devices(char *folderpath, int *nbre)
{
DIR *dir;
struct dirent *ent;
DIR *dir = NULL;
struct dirent *ent = NULL;
regex_t regex1 = {};
regex_t regex2 = {};

View file

@ -31,7 +31,7 @@ static void add_default_rule(char *port, char *enable, char *owsd)
static int get_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
char *rule_name, *rule_enabled;
uci_foreach_sections("firewall", "rule", ss) {
@ -74,7 +74,7 @@ static int set_userint_remoteaccesss_enable(char *refparam, struct dmctx *ctx, v
static int get_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
char *rule_name, *dest_port;
uci_foreach_sections("firewall", "rule", ss) {
@ -117,33 +117,31 @@ static int set_userint_remoteaccesss_port(char *refparam, struct dmctx *ctx, voi
return 0;
}
static int get_supportedprotocols(void)
static bool get_supportedprotocols(void)
{
char *cert, *key, *ca;
int found_https = 0;
char *cert = NULL, *key = NULL, *ca = NULL;
if ((dmuci_get_option_value_string("owsd", "wan_https", "cert", &cert) == 0 && *cert != '\0' && access(cert, F_OK) != -1) ||
(dmuci_get_option_value_string("owsd", "wan_https", "key", &key) == 0 && *key != '\0' && access(key, F_OK) != -1) ||
(dmuci_get_option_value_string("owsd", "wan_https", "ca", &ca) == 0 && *ca != '\0' && access(ca, F_OK) != -1))
found_https = 1;
dmuci_get_option_value_string("owsd", "wan_https", "cert", &cert);
dmuci_get_option_value_string("owsd", "wan_https", "key", &key);
dmuci_get_option_value_string("owsd", "wan_https", "ca", &ca);
return found_https;
if ((cert && *cert && file_exists(cert)) ||
(key && *key && file_exists(key)) ||
(ca && *ca && file_exists(ca)))
return true;
return false;
}
static int get_userint_remoteaccesss_supportedprotocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int found = get_supportedprotocols();
if (found) {
*value = "HTTP,HTTPS";
return 0;
}
*value = "HTTP";
*value = (get_supportedprotocols()) ? "HTTP,HTTPS" : "HTTP";
return 0;
}
static int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
char *rule_name, *rule_owsd;
uci_foreach_sections("firewall", "rule", ss) {
@ -164,16 +162,13 @@ static int get_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx,
static int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ss;
char *rule_name, *name_http;
int found;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, -1, SupportedProtocols, 2, NULL, 0))
return FAULT_9007;
found = get_supportedprotocols();
if (found) {
if (get_supportedprotocols()) {
if ((strcmp(value, "HTTP") != 0) && (strcmp(value, "HTTPS") != 0))
return FAULT_9007;
} else {
@ -183,21 +178,16 @@ static int set_userint_remoteaccesss_protocol(char *refparam, struct dmctx *ctx,
return 0;
case VALUESET:
uci_foreach_sections("firewall", "rule", ss) {
char *rule_name;
dmuci_get_value_by_section_string(ss, "name", &rule_name);
if (strcmp(rule_name, "juci-remote-access") == 0) {
if (strcmp(value, "HTTPS") == 0)
dmuci_set_value_by_section(ss, "owsd", "wan_https");
else
dmuci_set_value_by_section(ss, "owsd", "wan");
dmuci_set_value_by_section(ss, "owsd", (strcmp(value, "HTTPS") == 0) ? "wan_https" : "wan");
return 0;
}
}
if (strcmp(value, "HTTPS") == 0)
name_http = "wan_https";
else
name_http = "wan";
add_default_rule("80", "0", name_http);
add_default_rule("80", "0", (strcmp(value, "HTTPS") == 0) ? "wan_https" : "wan");
return 0;
}
return 0;

View file

@ -15,8 +15,8 @@
/*#Device.Users.User.{i}.!UCI:users/user/dmmap_users*/
static int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst, *max_inst = NULL;
struct dmmap_dup *p;
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("users", "user", "dmmap_users", &dup_list);

View file

@ -444,7 +444,7 @@ char * os__get_radio_frequency_nocache(const struct wifi_radio_args *args)
int os__get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
json_object *res = NULL, *neighboring_wifi_obj = NULL;
char object[32];
@ -465,7 +465,7 @@ int os__get_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struc
int os__get_neighboring_wifi_diagnostics_result_number_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
json_object *res = NULL, *accesspoints = NULL;
size_t entries = 0, result = 0;
char object[32];
@ -602,9 +602,9 @@ int os__get_WiFiRadio_CurrentOperatingChannelBandwidth(char *refparam, struct dm
/*#Device.WiFi.NeighboringWiFiDiagnostic.Result.{i}.!UBUS:wifi.radio.@Name/scanresults//accesspoints*/
int os__browseWifiNeighboringWiFiDiagnosticResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
json_object *res = NULL, *accesspoints = NULL, *arrobj = NULL;
char object[32], *inst, *max_inst = NULL;
char object[32], *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
uci_foreach_sections("wireless", "wifi-device", ss) {
@ -672,10 +672,8 @@ int os__get_access_point_total_associations(char *refparam, struct dmctx *ctx, v
snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_acp_args *)data)->ifname);
dmubus_call(object, "assoclist", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, assoclist, i, 1, "assoclist") {
entries++;
}
dmjson_foreach_obj_in_array(res, arrobj, assoclist, i, 1, "assoclist") {
entries++;
}
dmasprintf(value, "%d", entries);
return 0;
@ -684,17 +682,15 @@ int os__get_access_point_total_associations(char *refparam, struct dmctx *ctx, v
int os__browse_wifi_associated_device(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *stations = NULL, *arrobj = NULL;
char object[32], *inst, *max_inst = NULL;
char object[32], *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
snprintf(object, sizeof(object), "wifi.ap.%s", ((struct wifi_acp_args *)prev_data)->ifname);
dmubus_call(object, "stations", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, stations, i, 1, "stations") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)stations, inst) == DM_STOP)
return 0;
}
dmjson_foreach_obj_in_array(res, arrobj, stations, i, 1, "stations") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)stations, inst) == DM_STOP)
return 0;
}
return 0;
}
@ -711,7 +707,7 @@ char * os__get_default_wpa_key()
***************************************************************************/
static int os__get_WiFiDataElementsNetwork_option(const char *option, char **value)
{
int i;
int i = 0;
json_object *res, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
dmubus_call("wifi.dataelements.collector", "dump", UBUS_ARGS{}, 0, &res);
@ -772,7 +768,7 @@ int os__set_WiFiDataElementsNetwork_ControllerID(char *refparam, struct dmctx *c
/*#Device.WiFi.DataElements.Network.DeviceNumberOfEntries!UBUS:wifi.dataelements.collector/dump//data[@i-1].wfa-dataelements:Network.NumberOfDevices*/
int os__get_WiFiDataElementsNetwork_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int i;
int i = 0;
json_object *res, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
dmubus_call("wifi.dataelements.collector", "dump", UBUS_ARGS{}, 0, &res);
@ -1421,13 +1417,12 @@ int os__get_WiFiDataElementsAssociationEvent_AssociationEventDataNumberOfEntries
int num_assoc_ev = 0, i = 0;
dmubus_call("wifi.dataelements.collector", "event", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:AssociationEvent", &assoc_ev)) {
num_assoc_ev++;
}
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:AssociationEvent", &assoc_ev)) {
num_assoc_ev++;
}
}
dmasprintf(value, "%d", num_assoc_ev);
return 0;
}
@ -1528,11 +1523,9 @@ int os__get_WiFiDataElementsDisassociationEvent_DisassociationEventDataNumberOfE
int num_disassoc_ev = 0, i = 0;
dmubus_call("wifi.dataelements.collector", "event", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:DisassociationEvent", &disassoc_ev)) {
num_disassoc_ev++;
}
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:DisassociationEvent", &disassoc_ev)) {
num_disassoc_ev++;
}
}
dmasprintf(value, "%d", num_disassoc_ev);
@ -1686,20 +1679,18 @@ int os__get_WiFiDataElementsDisassociationEventDisassociationEventData_TimeStamp
**************************************************************/
int os__browseWiFiDataElementsNetworkDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
int i, j, id = 0;
int i = 0, j = 0, id = 0;
char *inst = NULL, *max_inst = NULL;
json_object *res = NULL, *data_arr = NULL, *data_obj = NULL, *net_obj = NULL;
json_object *dev_arr = NULL, *dev_obj = NULL;
dmubus_call("wifi.dataelements.collector", "dump", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, data_arr, data_obj, i, 1, "data") {
json_object_object_get_ex(data_obj, "wfa-dataelements:Network", &net_obj);
dmjson_foreach_obj_in_array(net_obj, dev_arr, dev_obj, j, 1, "DeviceList") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dev_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, data_arr, data_obj, i, 1, "data") {
json_object_object_get_ex(data_obj, "wfa-dataelements:Network", &net_obj);
dmjson_foreach_obj_in_array(net_obj, dev_arr, dev_obj, j, 1, "DeviceList") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dev_obj, inst) == DM_STOP)
break;
}
}
return 0;
@ -1782,12 +1773,10 @@ int os__browseWiFiDataElementsNetworkDeviceRadioCapabilitiesCapableOperatingClas
int id = 0, i = 0;
json_object_object_get_ex((json_object *)prev_data, "Capabilites", &caps_obj);
if (caps_obj) {
dmjson_foreach_obj_in_array(caps_obj, opclass_arr, opclass_obj, i, 1, "OperatingClasses") {
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)opclass_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(caps_obj, opclass_arr, opclass_obj, i, 1, "OperatingClasses") {
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)opclass_obj, inst) == DM_STOP)
break;
}
return 0;
}
@ -1855,13 +1844,11 @@ int os__browseWiFiDataElementsAssociationEventAssociationEventDataInst(struct dm
int id = 0, i = 0;
dmubus_call("wifi.dataelements.collector", "event", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:AssociationEvent", &assoc_ev)) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)notify_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:AssociationEvent", &assoc_ev)) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)notify_obj, inst) == DM_STOP)
break;
}
}
return 0;
@ -1874,13 +1861,11 @@ int os__browseWiFiDataElementsDisassociationEventDisassociationEventDataInst(str
int id = 0, i = 0;
dmubus_call("wifi.dataelements.collector", "event", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:DisassociationEvent", &disassoc_ev)) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)notify_obj, inst) == DM_STOP)
break;
}
dmjson_foreach_obj_in_array(res, notify_arr, notify_obj, i, 1, "notification") {
if (json_object_object_get_ex(notify_obj, "wfa-dataelements:DisassociationEvent", &disassoc_ev)) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)notify_obj, inst) == DM_STOP)
break;
}
}
return 0;

View file

@ -226,21 +226,6 @@ int os__get_access_point_associative_device_statistics_retrans_count(char *refpa
return not_implemented(value);
}
int os__get_access_point_associative_device_statistics_failed_retrans_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}
int os__get_access_point_associative_device_statistics_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}
int os__get_access_point_associative_device_statistics_multiple_retry_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);
}
int os_get_wifi_access_point_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return not_implemented(value);

View file

@ -82,7 +82,7 @@ static inline int init_wifi_enp(struct wifi_enp_args *args, struct uci_section *
/*#Device.WiFi.RadioNumberOfEntries!UCI:wireless/wifi-device/*/
static int get_WiFi_RadioNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int nbre = 0;
uci_foreach_sections("wireless", "wifi-device", s) {
@ -95,7 +95,7 @@ static int get_WiFi_RadioNumberOfEntries(char *refparam, struct dmctx *ctx, void
/*#Device.WiFi.SSIDNumberOfEntries!UCI:wireless/wifi-iface/*/
static int get_WiFi_SSIDNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int nbre = 0;
uci_foreach_sections("wireless", "wifi-iface", s) {
@ -108,7 +108,7 @@ static int get_WiFi_SSIDNumberOfEntries(char *refparam, struct dmctx *ctx, void
/*#Device.WiFi.AccessPointNumberOfEntries!UCI:wireless/wifi-iface/*/
static int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int nbre = 0;
char *mode = NULL;
@ -125,7 +125,7 @@ static int get_WiFi_AccessPointNumberOfEntries(char *refparam, struct dmctx *ctx
/*#Device.WiFi.EndPointNumberOfEntries!UCI:wireless/wifi-iface/*/
static int get_WiFi_EndPointNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s;
struct uci_section *s = NULL;
int nbre = 0;
char *mode = NULL;
@ -444,14 +444,15 @@ static int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx
static int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char buf[6];
char buf[8];
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, -1, SupportedOperatingChannelBandwidth, 6, NULL, 0))
return FAULT_9007;
break;
case VALUESET:
sscanf(value,"%[^M]", buf);
sscanf(value,"%3[^M]", buf);
dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", buf);
break;
}
@ -731,10 +732,9 @@ static int set_WiFiAccessPoint_IsolationEnable(char *refparam, struct dmctx *ctx
/*#Device.WiFi.AccessPoint.{i}.AllowedMACAddress!UCI:wireless/wifi-iface,@i-1/maclist*/
static int get_WiFiAccessPoint_AllowedMACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_list *val = NULL;
dmuci_get_value_by_section_list(((struct wifi_acp_args *)data)->wifi_acp_sec, "maclist", &val);
if (val)
*value = dmuci_list_to_string(val, ",");
*value = dmuci_list_to_string(val, ",");
return 0;
}
@ -822,10 +822,11 @@ static char *get_security_mode(struct uci_section *section)
if (strstr(encryption, "wep")) {
char *key_index = NULL, *key = NULL;
char buf[16];
dmuci_get_value_by_section_string(section, "key", &key_index);
if (key_index && (*key_index) > '0' && (*key_index) < '5' && *(key_index+1) == '\0') {
char buf[16];
snprintf(buf, sizeof(buf), "key%s", key_index);
dmuci_get_value_by_section_string(section, buf, &key);
}
@ -1248,10 +1249,10 @@ static int get_wps_config_methods_enabled(struct uci_section *section, char **va
static void set_wps_config_methods_enabled(struct uci_section *section, char *value)
{
char *wps_list = NULL, *token, *saveptr;
char *token = NULL, *saveptr = NULL;
bool pushbut = false, label = false, pin = false;
wps_list = dmstrdup(value);
char *wps_list = dmstrdup(value);
for (token = strtok_r(wps_list, ",", &saveptr); token; token = strtok_r(NULL, ",", &saveptr)) {
if (strcmp(token, "PushButton") == 0)
@ -2003,7 +2004,7 @@ static int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
{
char *inst = NULL, *max_inst = NULL;
struct wifi_radio_args curr_wifi_radio_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("wireless", "wifi-device", "dmmap_wireless", &dup_list);
@ -2023,9 +2024,9 @@ static int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
/*#Device.WiFi.SSID.{i}.!UCI:wireless/wifi-iface/dmmap_wireless*/
static int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *ifname, *linker;
char *inst = NULL, *max_inst = NULL, *ifname = NULL, *linker;
struct wifi_ssid_args curr_wifi_ssid_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list);
@ -2053,7 +2054,7 @@ static int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, v
{
char *inst = NULL, *ifname, *max_inst = NULL, *mode = NULL;
struct wifi_acp_args curr_wifi_acp_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list);
@ -2079,7 +2080,7 @@ static int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void
{
char *inst = NULL, *ifname, *max_inst = NULL, *mode = NULL;
struct wifi_enp_args curr_wifi_enp_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("wireless", "wifi-iface", "dmmap_wireless", &dup_list);
@ -2104,14 +2105,13 @@ static int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void
static int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *max_inst = NULL, *ep_instance;
char *max_inst = NULL, *ep_instance = NULL;
struct wifi_enp_args *ep_args = (struct wifi_enp_args *)prev_data;
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ep_args->wifi_enp_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "endpointinstance", &ep_instance);
s = is_dmmap_section_exist_eq("dmmap_wireless", "ep_profile", "ep_key", ep_instance);
struct uci_section *s = is_dmmap_section_exist_eq("dmmap_wireless", "ep_profile", "ep_key", ep_instance);
if (!s)
dmuci_add_section_bbfdm("dmmap_wireless", "ep_profile", &s);
dmuci_set_value_by_section_bbfdm(s, "ep_key", ep_instance);
@ -2125,7 +2125,7 @@ static int browseWiFiEndPointProfileInst(struct dmctx *dmctx, DMNODE *parent_nod
int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *ss;
struct uci_section *ss = NULL;
switch (action) {
case VALUECHECK:

View file

@ -15,7 +15,7 @@
int browseXIopsysEuButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("buttons", "button", "dmmap_buttons", &dup_list);
@ -43,13 +43,10 @@ static int get_x_iopsys_eu_button_name(char *refparam, struct dmctx *ctx, void *
static int get_x_iopsys_eu_button_gpio(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_list *val = NULL;
dmuci_get_value_by_section_list((struct uci_section *)data, "button", &val);
if (val)
*value = dmuci_list_to_string(val, " ");
else
*value = "";
*value = dmuci_list_to_string(val, " ");
return 0;
}

View file

@ -15,7 +15,7 @@
int browseXIopsysEuDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dropbear", "dropbear", "dmmap_dropbear", &dup_list);

View file

@ -15,12 +15,11 @@
static void get_mcast_iface_key(char *p_ifname, char *key, size_t key_size)
{
int itf_found = 0;
struct uci_section *n_sec;
struct uci_section *n_sec = NULL;
char *intf_name;
uci_foreach_sections("network", "interface", n_sec) {
itf_found = 0;
bool itf_found = 0;
dmuci_get_value_by_section_string(n_sec, "ifname", &intf_name);
intf_name = dmstrdup(intf_name);
@ -28,7 +27,7 @@ static void get_mcast_iface_key(char *p_ifname, char *key, size_t key_size)
pch = strtok_r(intf_name, " ", &spch);
while (pch != NULL) {
if (strcmp(pch, p_ifname) == 0) {
strncpy(key, section_name(n_sec), key_size - 1);
DM_STRNCPY(key, section_name(n_sec), key_size);
itf_found = 1;
break;
}
@ -44,7 +43,7 @@ static void sync_mcast_dmmap_iface_sec(struct uci_list *proxy_iface, char *s_mod
struct uci_section *s, char *dmmap_package, char *dmmap_sec,
struct list_head *dup_list, char *up_iface)
{
struct uci_element *e;
struct uci_element *e = NULL;
struct uci_section *d_sec;
int found = 0;
char key[1024] = "";
@ -53,7 +52,7 @@ static void sync_mcast_dmmap_iface_sec(struct uci_list *proxy_iface, char *s_mod
uci_foreach_element(proxy_iface, e) {
char *p_ifname = dmstrdup(e->name);
if (strstr(p_ifname, "br-") != NULL)
strncpy(key, p_ifname, sizeof(key) - 1);
DM_STRNCPY(key, p_ifname, sizeof(key));
else
get_mcast_iface_key(p_ifname, key, sizeof(key));
@ -85,7 +84,7 @@ static void sync_mcast_dmmap_iface_sec(struct uci_list *proxy_iface, char *s_mod
static void add_empty_mcast_iface_to_list(char *dmmap_package, char *dmmap_sec,
struct uci_section *s, struct list_head *dup_list)
{
struct uci_section *dmmap_sect;
struct uci_section *dmmap_sect = NULL;
char *f_ifname;
uci_path_foreach_option_eq(bbfdm, dmmap_package, dmmap_sec, "section_name", section_name(s), dmmap_sect) {
@ -100,7 +99,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_iface(char *package,
void *data, char *dmmap_package, char *dmmap_sec, char *proto,
struct list_head *dup_list)
{
struct uci_section *s, *stmp;
struct uci_section *s = NULL, *stmp = NULL;
char *v;
uci_foreach_option_eq(package, section_type, "proto", proto, s) {
@ -143,7 +142,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
void *data, char *dmmap_package, char *dmmap_sec, char *proto,
struct list_head *dup_list)
{
struct uci_section *s, *dmmap_sect, *d_sec, *stmp;
struct uci_section *s = NULL, *dmmap_sect = NULL, *d_sec = NULL, *stmp = NULL;
char *v, *s_name;
uci_foreach_option_eq(package, section_type, "proto", proto, s) {
@ -156,7 +155,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
dmuci_get_value_by_section_list(s, "filter", &l);
if (l != NULL) {
struct uci_element *e;
struct uci_element *e = NULL;
uci_foreach_element(l, e) {
char *ip_addr = dmstrdup(e->name);
int found = 0;
@ -247,7 +246,7 @@ int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname)
struct uci_section *intf_s = NULL;
uci_foreach_sections("network", "interface", intf_s) {
char sec[20] = {0};
strncpy(sec, section_name(intf_s), sizeof(sec) - 1);
DM_STRNCPY(sec, section_name(intf_s), sizeof(sec));
if (strncmp(sec, sec_name, sizeof(sec)) != 0)
continue;
@ -342,7 +341,7 @@ static int browse_igmp_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "igmp", &dup_list);
@ -441,7 +440,7 @@ static int browse_igmp_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, v
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "igmp", &dup_list);
@ -490,12 +489,13 @@ static int get_igmpp_no_of_entries(char *refparam, struct dmctx *ctx, void *data
static int browse_igmp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
//perform ubus call to mcast stats and browse through each igmp group json object
int i = 0, id = 0;
json_object *res = NULL, *jobj = NULL, *arrobj = NULL, *group_obj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
dmubus_call("mcast", "stats", UBUS_ARGS{}, 0, &res);
if (res) {
int i = 0, id = 0;
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "snooping");
dmjson_foreach_obj_in_array(jobj, arrobj, group_obj, i, 1, "groups") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
@ -615,11 +615,13 @@ int get_mcasts_filter_no_of_entries(char *refparam, struct dmctx *ctx, void *dat
static int get_igmp_cgrps_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int i = 0, cnt = 0;
int cnt = 0;
json_object *res = NULL, *jobj = NULL, *arrobj = NULL, *group_obj = NULL;
dmubus_call("mcast", "stats", UBUS_ARGS{}, 0, &res);
if (res) {
int i = 0;
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "snooping");
dmjson_foreach_obj_in_array(jobj, arrobj, group_obj, i, 1, "groups") {
cnt++;
@ -631,7 +633,7 @@ static int get_igmp_cgrps_no_of_entries(char *refparam, struct dmctx *ctx, void
int get_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *f_sec;
struct uci_section *f_sec = NULL;
char *f_inst, *f_enable;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter",
@ -685,7 +687,7 @@ int set_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char
int get_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec;
struct uci_section *d_sec = NULL;
char *f_inst, *ip_addr;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter",
@ -931,7 +933,7 @@ int get_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data,
// section would be wan, so extract wan from br-wan
char *tok, *end;
strncpy(val, val1, sizeof(val) - 1);
DM_STRNCPY(val, val1, sizeof(val));
tok = strtok_r(val, "-", &end);
if ((tok == NULL) || (end == NULL))
return 0;
@ -939,7 +941,7 @@ int get_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data,
if (strcmp(tok, "br") != 0)
return 0;
strncpy(sec_name, end, sizeof(sec_name) - 1);
DM_STRNCPY(sec_name, end, sizeof(sec_name));
// In the dmmap_bridge file, the details related to the instance id etc. associated with this bridge
// is stored, we now switch our focus to it to extract the necessary information.
get_bridge_port_linker(ctx, sec_name, value);
@ -993,15 +995,15 @@ static int add_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data
static void get_igmpp_iface_del_key_val(char *key, size_t key_size, char *if_name)
{
struct uci_section *s;
struct uci_section *s = NULL;
char *ifval;
if (strstr(if_name, "br-") != NULL) {
strncpy(key, if_name, key_size - 1);
DM_STRNCPY(key, if_name, key_size);
} else {
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), if_name) == 0) {
dmuci_get_value_by_section_string(s, "ifname", &ifval);
strncpy(key, ifval, key_size - 1);
DM_STRNCPY(key, ifval, key_size);
break;
}
}
@ -1043,8 +1045,8 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data
char key[1024];
get_igmpp_iface_del_key_val(key, sizeof(key), if_name);
char *pch = NULL, *spch = NULL;
pch = strtok_r(key, " ", &spch);
char *spch = NULL;
char *pch = strtok_r(key, " ", &spch);
while (pch != NULL) {
del_igmpp_iface_val(upstream, data, pch);
pch = strtok_r(NULL, " ", &spch);
@ -1199,8 +1201,9 @@ int get_mcastp_interface_no_of_entries(char *refparam, struct dmctx *ctx, void *
int get_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *f_sec;
struct uci_section *f_sec = NULL;
char *f_inst, *f_enable = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter",
"section_name", section_name((struct uci_section *)data), f_sec) {
dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst);
@ -1250,7 +1253,7 @@ int set_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char
int get_mcastp_filter_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec;
struct uci_section *d_sec = NULL;
char *f_inst;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter",
@ -1299,7 +1302,7 @@ static int browse_igmp_cgrp_assoc_dev_inst(struct dmctx *dmctx, DMNODE *parent_n
int i = 0, id = 0;
json_object *arrobj = NULL, *client_jobj = NULL;
char *inst, *max_inst = NULL;
char *inst = NULL, *max_inst = NULL;
dmjson_foreach_obj_in_array((struct json_object *)prev_data, arrobj, client_jobj, i, 1, "clients") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
@ -1617,17 +1620,16 @@ void update_snooping_mode(struct uci_section *s)
{
// Update snooping mode as per downstream interface
struct uci_list *v = NULL;
struct uci_element *e;
struct uci_section *itf_sec;
char *val, *s_mode, *up;
struct uci_element *e = NULL;
struct uci_section *itf_sec = NULL;
char *val = NULL, *s_mode = NULL, *up = NULL;
bool b;
dmuci_get_value_by_section_list(s, "downstream_interface", &v);
if (v != NULL) {
uci_foreach_element(v, e) {
val = dmstrdup(e->name);
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
"ifname", val, itf_sec) {
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "ifname", val, itf_sec) {
dmuci_get_value_by_section_string(itf_sec, "upstream", &up);
string_to_bool(up, &b);
if (b)
@ -1651,7 +1653,7 @@ static void sync_proxy_interface_sections(struct uci_section *s, char *section,
char *value, bool up_iface)
{
struct uci_list *v = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
char *val;
dmuci_get_value_by_section_list(s, section, &v);
@ -1660,14 +1662,16 @@ static void sync_proxy_interface_sections(struct uci_section *s, char *section,
// update the downstream or upstream interface list.
value = dmstrdup(value);
char *pch = NULL, *spch = NULL;
pch = strtok_r(value, " ", &spch);
char *spch = NULL;
char *pch = strtok_r(value, " ", &spch);
while (pch != NULL) {
int found = 0; // use to avoid duplicate entries
if (v != NULL) {
// For each pch value check if entry already exists
// in the qos uci file in the downstream or upstream list
bool found = 0; // use to avoid duplicate entries
uci_foreach_element(v, e) {
val = dmstrdup(e->name);
if (strcmp(val, pch) == 0) {
@ -1702,7 +1706,7 @@ static void sync_proxy_interface_sections(struct uci_section *s, char *section,
static void set_igmpp_iface_val(void *data, char *instance, char *linker, char *interface_linker, bool is_br)
{
struct uci_section *d_sec;
struct uci_section *d_sec = NULL;
char *up, *f_inst;
bool b;
@ -1732,9 +1736,9 @@ static void set_igmpp_iface_val(void *data, char *instance, char *linker, char *
static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *linker = NULL, *interface_linker = NULL;
char ifname[16];
char *if_type;
struct uci_section *s;
char ifname[16] = {0};
char *if_type = NULL;
struct uci_section *s = NULL;
bool is_br = false;
switch (action) {
@ -1755,7 +1759,7 @@ static int set_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da
continue;
dmuci_get_value_by_section_string(s, "type", &if_type);
if (strcmp(if_type, "bridge") == 0) {
if (if_type && strcmp(if_type, "bridge") == 0) {
dmasprintf(&interface_linker, "br-%s", linker);
is_br = true;
} else {
@ -1798,11 +1802,11 @@ static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da
if (strstr(igmpp_ifname, "br-")) {
// Interface is bridge type, convert to network uci file section name
char val[16] = {0};
strncpy(val, igmpp_ifname, sizeof(val) - 1);
DM_STRNCPY(val, igmpp_ifname, sizeof(val));
char *token, *end;
token = strtok_r(val, "-", &end);
if (strcmp(token, "br") == 0) {
strncpy(sec_name, end, sizeof(sec_name) - 1);
DM_STRNCPY(sec_name, end, sizeof(sec_name));
} else {
goto end;
}
@ -1866,12 +1870,12 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void
char *ifval;
dmuci_get_value_by_section_string(d_sec, "ifname", &ifname);
if (strstr(ifname, "br-") != NULL) {
strncpy(key, ifname, sizeof(key) - 1);
DM_STRNCPY(key, ifname, sizeof(key));
} else {
uci_foreach_sections("network", "interface", s) {
if(strcmp(section_name(s), ifname) == 0) {
dmuci_get_value_by_section_string(s, "ifname", &ifval);
strncpy(key, ifval, sizeof(key) - 1);
DM_STRNCPY(key, ifval, sizeof(key));
break;
}
}
@ -1894,7 +1898,7 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void
int get_mcastp_interface_upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec;
struct uci_section *d_sec = NULL;
char *f_inst, *up = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",
@ -1912,7 +1916,7 @@ int get_mcastp_interface_upstream(char *refparam, struct dmctx *ctx, void *data,
int get_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *d_sec;
struct uci_section *d_sec = NULL;
char *f_inst, *val = NULL;
uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface",

View file

@ -50,7 +50,7 @@ static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "mld", &dup_list);
@ -107,7 +107,7 @@ static int browse_mld_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, vo
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "mld", &dup_list);
@ -483,7 +483,7 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat
char *linker = NULL, *interface_linker = NULL;
char ifname[16];
char *up, *f_inst, *if_type;
struct uci_section *d_sec, *s;
struct uci_section *d_sec = NULL, *s = NULL;
bool b;
switch (action) {
@ -558,11 +558,11 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat
if (strstr(mldp_ifname, "br-")) {
// Interface is bridge type, convert to network uci file section name
char val[16] = {0};
strncpy(val, mldp_ifname, sizeof(val) - 1);
DM_STRNCPY(val, mldp_ifname, sizeof(val));
char *tok, *end;
tok = strtok_r(val, "-", &end);
if (strcmp(tok, "br") == 0) {
strncpy(sec_name, end, sizeof(sec_name) - 1);
DM_STRNCPY(sec_name, end, sizeof(sec_name));
} else {
goto end;
}

View file

@ -16,7 +16,7 @@
static int browseXIopsysEuOWSDVirtualHost(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("owsd", "owsd-listen", "dmmap_owsd", &dup_list);
@ -195,13 +195,10 @@ static int set_x_iopsys_eu_owsd_virtualhost_whitelist_dhcp(char *refparam, struc
static int get_x_iopsys_eu_owsd_virtualhost_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *val;
struct uci_list *val = NULL;
dmuci_get_value_by_section_list((struct uci_section *)data, "origin", &val);
if (val)
*value = dmuci_list_to_string(val, " ");
else
*value = "";
*value = dmuci_list_to_string(val, " ");
return 0;
}

View file

@ -34,8 +34,8 @@ LIB_MAP_OPERATE tRootDynamicOperate[] = {
/*************************************************************/
static int execute_bbk_speedtest()
{
json_object *res;
char *latency, *download, *upload = NULL;
json_object *res = NULL;
char *latency = NULL, *download = NULL, *upload = NULL;
dmubus_call("bbk", "start", UBUS_ARGS{}, 0, &res);
if (res) {
@ -62,10 +62,8 @@ static char *bbk_speedtest_get(char *option, char *default_value)
void bbk_speedtest_set(char *option, char *value)
{
struct uci_section *section = NULL;
check_create_dmmap_package("dmmap_diagnostics");
section = dmuci_walk_section_bbfdm("dmmap_diagnostics", "bbkspeedtest", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
struct uci_section *section = dmuci_walk_section_bbfdm("dmmap_diagnostics", "bbkspeedtest", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION);
if (!section)
dmuci_set_value_bbfdm("dmmap_diagnostics", "bbkspeedtest", "", "bbkspeedtest");

View file

@ -488,7 +488,7 @@ def cprintBrowseObj( fbrowse, name, mappingobj, dmobject ):
############################## UCI ########################################
if type == "uci" :
print(" char *inst = NULL, *max_inst = NULL;", file=fp)
print(" struct dmmap_dup *p;", file=fp)
print(" struct dmmap_dup *p = NULL;", file=fp)
print(" LIST_HEAD(dup_list);", file=fp)
print("", file=fp)
print(" synchronize_specific_config_sections_with_dmmap(\"%s\", \"%s\", \"%s\", &dup_list);" % (res1, res2, res3), file=fp)

View file

@ -297,11 +297,8 @@ static void dm_browse_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *ent
static int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance)
{
DMOBJ *jentryobj;
struct dm_dynamic_obj *next_dyn_array;
int i, j, err = 0;
char *parent_obj = parent_node->current_object;
int err = 0;
if (entryobj) {
for (; entryobj->obj; entryobj++) {
@ -313,11 +310,11 @@ static int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj,
if (parent_node->obj) {
if (parent_node->obj->nextdynamicobj) {
for (i = 0; i < __INDX_DYNAMIC_MAX; i++) {
next_dyn_array = parent_node->obj->nextdynamicobj + i;
for (int i = 0; i < __INDX_DYNAMIC_MAX; i++) {
struct dm_dynamic_obj *next_dyn_array = parent_node->obj->nextdynamicobj + i;
if (next_dyn_array->nextobj) {
for (j = 0; next_dyn_array->nextobj[j]; j++) {
jentryobj = next_dyn_array->nextobj[j];
for (int j = 0; next_dyn_array->nextobj[j]; j++) {
DMOBJ *jentryobj = next_dyn_array->nextobj[j];
for (; (jentryobj && jentryobj->obj); jentryobj++) {
dm_browse_entry(dmctx, parent_node, jentryobj, data, instance, parent_obj, &err);
if (dmctx->stop)
@ -383,10 +380,11 @@ int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char
void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *full_obj, char *obj, DMOBJ **root_entry, int *obj_found)
{
int err = 0;
if (!entryobj)
return;
char *parent_obj = parent_node->current_object;
for (; entryobj->obj; entryobj++) {
DMNODE node = {0};
node.obj = entryobj;
@ -400,7 +398,7 @@ void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entry
return;
}
err = plugin_dynamic_obj_match(dmctx, &node, entryobj->obj, full_obj);
int err = plugin_dynamic_obj_match(dmctx, &node, entryobj->obj, full_obj);
if (err)
continue;
@ -582,20 +580,6 @@ char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst)
return inst;
}
char *get_last_instance_bbfdm_without_update(char *package, char *section, char *opt_inst)
{
struct uci_section *s;
char *inst = NULL, *last_inst = NULL;
uci_path_foreach_sections(bbfdm, package, section, s) {
dmuci_get_value_by_section_string(s, opt_inst, &inst);
if(last_inst)
dmfree(last_inst);
last_inst = dmstrdup(inst);
}
return inst;
}
char *get_last_instance(char *package, char *section, char *opt_inst)
{
struct uci_section *s;
@ -626,7 +610,7 @@ char *get_last_instance_lev2_bbfdm_dmmap_opt(char *dmmap_package, char *section,
browse_args.value = value_check;
uci_path_foreach_option_eq(bbfdm, dmmap_package, section, opt_check, value_check, s) {
instance = update_instance(last_inst, 5, s, opt_inst, NULL, check_browse_section, (void *)&browse_args);
instance = update_instance(last_inst, 5, s, opt_inst, 0, check_browse_section, (void *)&browse_args);
if(last_inst)
dmfree(last_inst);
last_inst = dmstrdup(instance);
@ -653,26 +637,6 @@ char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_pac
return instance;
}
char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char *opt_check, char *value_check)
{
struct uci_section *s;
char *instance = NULL, *last_inst = NULL;
if (strcmp(package, DMMAP) == 0) {
uci_path_foreach_option_cont(bbfdm, package, section, opt_check, value_check, s) {
instance = update_instance(last_inst, 2, s, opt_inst);
if(last_inst)
dmfree(last_inst);
last_inst = dmstrdup(instance);
}
} else {
uci_foreach_option_cont(package, section, opt_check, value_check, s) {
instance = update_instance(instance, 2, s, opt_inst);
}
}
return instance;
}
int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "";
@ -682,7 +646,8 @@ int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, cha
void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *param_notification)
{
struct dm_parameter *dm_parameter;
struct list_head *ilist;
struct list_head *ilist = NULL;
list_for_each(ilist, &ctx->list_parameter) {
dm_parameter = list_entry(ilist, struct dm_parameter, list);
int cmp = strcmp(dm_parameter->name, param_name);
@ -709,7 +674,7 @@ void api_del_list_parameter(struct dm_parameter *dm_parameter)
void free_all_list_parameter(struct dmctx *ctx)
{
struct dm_parameter *dm_parameter;
struct dm_parameter *dm_parameter = NULL;
while (ctx->list_parameter.next != &ctx->list_parameter) {
dm_parameter = list_entry(ctx->list_parameter.next, struct dm_parameter, list);
api_del_list_parameter(dm_parameter);
@ -735,7 +700,7 @@ static void del_set_list_tmp(struct set_tmp *set_tmp)
void free_all_set_list_tmp(struct dmctx *ctx)
{
struct set_tmp *set_tmp;
struct set_tmp *set_tmp = NULL;
while (ctx->set_list_tmp.next != &ctx->set_list_tmp) {
set_tmp = list_entry(ctx->set_list_tmp.next, struct set_tmp, list);
del_set_list_tmp(set_tmp);
@ -762,7 +727,7 @@ void bbf_api_del_list_fault_param(struct param_fault *param_fault)
void free_all_list_fault_param(struct dmctx *ctx)
{
struct param_fault *param_fault;
struct param_fault *param_fault = NULL;
while (ctx->list_fault_param.next != &ctx->list_fault_param) {
param_fault = list_entry(ctx->list_fault_param.next, struct param_fault, list);
bbf_api_del_list_fault_param(param_fault);
@ -840,7 +805,7 @@ static char *get_parameter_notification(struct dmctx *ctx, char *param)
struct uci_list *list_notif;
char *pch, *new_param;
char *notification = "0";
struct uci_element *e;
struct uci_element *e = NULL;
update_param_instance_alias(ctx, param, &new_param);
for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) {
@ -873,8 +838,9 @@ static int remove_parameter_notification(char *param)
{
int i;
struct uci_list *list_notif;
struct uci_element *e, *tmp;
struct uci_element *e = NULL, *tmp = NULL;
char *pch;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) {
if (param[strlen(param)-1] == '.') {
dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif);
@ -924,7 +890,7 @@ static int set_parameter_notification(struct dmctx *ctx, char *param, char *valu
dmuci_add_list_value("cwmp", "@notifications[0]", "passive_active_lw", new_param);
} else if (strcmp(value, "0") == 0) {
struct uci_list *list_notif;
struct uci_element *e;
struct uci_element *e = NULL;
int i, len;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 1; i--) {
dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif);
@ -986,8 +952,7 @@ static char *check_value_by_type(char *value, int type)
char buf[len + 1];
struct tm tm;
strcpy(buf, value);
buf[len] = 0;
snprintf(buf, sizeof(buf), "%s", value);
switch (type) {
case DMT_UNINT:
@ -1074,27 +1039,6 @@ void dmentry_instance_lookup_inparam(struct dmctx *ctx)
/* **********
* get value
* **********/
int dm_entry_get_full_param_value(struct dmctx *dmctx)
{
int err = 0;
unsigned char findparam_check = 0;
DMOBJ *root = dmctx->dm_entryobj;
DMNODE node = {.current_object = ""};
dmctx->inparam_isparam = 1;
dmctx->findparam = 0;
dmctx->stop = 0;
dmctx->checkobj = plugin_obj_match;
dmctx->checkleaf = plugin_leaf_match;
dmctx->method_obj = mobj_get_value_in_param;
dmctx->method_param = mparam_get_value_in_param;
err = dm_browse(dmctx, &node, root, NULL, NULL);
if (findparam_check && dmctx->findparam)
return 0;
else
return err;
}
int dm_entry_get_value(struct dmctx *dmctx)
{
int err = 0;
@ -1368,12 +1312,11 @@ int dm_entry_get_instances(struct dmctx *ctx)
{
DMOBJ *root = ctx->dm_entryobj;
DMNODE node = { .current_object = "" };
char buf[4] = { '.', 0 };
size_t plen;
int err;
if (ctx->in_param[0] == 0)
ctx->in_param = buf;
ctx->in_param = dmstrdup(".");
plen = strlen(ctx->in_param);
if (ctx->in_param[plen - 1] != '.')
@ -1649,17 +1592,17 @@ static int mobj_set_value(DMOBJECT_ARGS)
static int mparam_set_value(DMPARAM_ARGS)
{
char *refparam, *perm;
char *refparam = NULL;
dmastrcat(&refparam, node->current_object, lastname);
if (strcmp(refparam, dmctx->in_param) != 0) {
if (refparam && strcmp(refparam, dmctx->in_param) != 0) {
dmfree(refparam);
return FAULT_9005;
}
dmctx->stop = 1;
if (dmctx->setaction == VALUECHECK) {
perm = permission->val;
char *perm = permission->val;
if (permission->get_permission != NULL)
perm = permission->get_permission(refparam, dmctx, data, instance);

View file

@ -38,6 +38,12 @@
#define FREE(x) do { if(x) {free(x); x = NULL;} } while (0)
#endif
#define DM_STRNCPY(DST, SRC, SIZE) \
do { \
strncpy(DST, SRC, SIZE - 1); \
DST[SIZE-1] = '\0'; \
} while(0)
extern struct dm_permession_s DMREAD;
extern struct dm_permession_s DMWRITE;
extern char *DMT_TYPE[];
@ -407,29 +413,26 @@ void bbf_api_del_list_fault_param(struct param_fault *param_fault);
void free_all_list_fault_param(struct dmctx *ctx);
int string_to_bool(char *v, bool *b);
void dmentry_instance_lookup_inparam(struct dmctx *ctx);
int dm_entry_get_value(struct dmctx *ctx);
int dm_entry_get_value(struct dmctx *dmctx);
int dm_entry_get_name(struct dmctx *ctx);
int dm_entry_get_schema(struct dmctx *ctx);
int dm_entry_get_instances(struct dmctx *dmctx);
int dm_entry_get_notification(struct dmctx *ctx);
int dm_entry_add_object(struct dmctx *ctx);
int dm_entry_delete_object(struct dmctx *ctx);
int dm_entry_set_value(struct dmctx *ctx);
int dm_entry_set_notification(struct dmctx *ctx);
int dm_entry_get_instances(struct dmctx *ctx);
int dm_entry_get_notification(struct dmctx *dmctx);
int dm_entry_add_object(struct dmctx *dmctx);
int dm_entry_delete_object(struct dmctx *dmctx);
int dm_entry_set_value(struct dmctx *dmctx);
int dm_entry_set_notification(struct dmctx *dmctx);
int dm_entry_enabled_notify(struct dmctx *dmctx);
int dm_entry_get_linker(struct dmctx *ctx);
int dm_entry_get_linker_value(struct dmctx *ctx);
int dm_entry_get_linker(struct dmctx *dmctx);
int dm_entry_get_linker_value(struct dmctx *dmctx);
char *get_last_instance(char *package, char *section, char *opt_inst);
char *get_last_instance_bbfdm_without_update(char *package, char *section, char *opt_inst);
char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst);
char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char *opt_check, char *value_check);
char *get_last_instance_lev2_bbfdm_dmmap_opt(char* dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check);
char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check);
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *full_obj, char *obj, DMOBJ **root_entry, int *obj_found);
int free_dm_browse_node_dynamic_object_tree(DMNODE *parent_node, DMOBJ *entryobj);
int dm_entry_get_full_param_value(struct dmctx *dmctx);
char *check_parameter_forced_notification(const char *parameter);
static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)
@ -441,33 +444,25 @@ static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, voi
}
#ifndef TRACE
#define TRACE_TYPE 2
static inline void trace_empty_func()
{
}
#if TRACE_TYPE == 2
#define TRACE(MESSAGE, ...) do { \
fprintf(stderr, "TRACE: %s@%s:%d " MESSAGE, __FUNCTION__,__FILE__,__LINE__, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} while(0)
#endif
#define ENABLE_BBF_DEBUG 0
#if ENABLE_BBF_DEBUG
#define BBF_DEBUG(fmt, ...) do { \
FILE *fp = fopen("/tmp/bbfdm.log", "a"); \
if (fp) { \
fprintf(fp, "%s@%s:%d: " MESSAGE, __func__, __FILE__, __LINE__, ##__VA_ARGS__); \
fprintf(fp, "%s@%s:%d: " fmt, __func__, __FILE__, __LINE__, ##__VA_ARGS__); \
fclose(fp); \
} \
} while(0)
#elif TRACE_TYPE == 1
#define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__)
#else
#define TRACE(MESSAGE, ...) trace_empty_func()
#endif
#define BBF_DEBUG(fmt, ...)
#endif
#ifndef DETECT_CRASH
#define DETECT_CRASH(MESSAGE,args...) { \
const char *A[] = {MESSAGE}; \
printf("DETECT_CRASH: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
sleep(1); \
}
#endif
#endif
#endif //__DMBBF_H__

View file

@ -119,10 +119,9 @@ char *cidr2netmask(int bits)
bool is_strword_in_optionvalue(char *optionvalue, char *str)
{
int len;
char *s = optionvalue;
while ((s = strstr(s, str))) {
len = strlen(str); //should be inside while, optimization reason
int len = strlen(str); //should be inside while, optimization reason
if(s[len] == '\0' || s[len] == ' ')
return true;
s++;
@ -196,10 +195,9 @@ int dmcmd_no_wait(char *cmd, int n, ...)
static char sargv[4][128];
argv[0] = cmd;
va_start(arg,n);
for (i=0; i<n; i++)
{
strcpy(sargv[i], va_arg(arg, char*));
va_start(arg, n);
for (i = 0; i < n; i++) {
DM_STRNCPY(sargv[i], va_arg(arg, char*), sizeof(sargv[i]));
argv[i+1] = sargv[i];
}
va_end(arg);
@ -217,39 +215,6 @@ int dmcmd_no_wait(char *cmd, int n, ...)
return 0;
}
void dmcmd_read_alloc(int pipe, char **value)
{
char buffer[64];
ssize_t rxed;
int t, len = 1;
*value = NULL;
while ((rxed = read(pipe, buffer, sizeof(buffer) - 1)) > 0) {
t = len;
len += rxed;
*value = dmrealloc(*value, len);
memcpy(*value + t - 1, buffer, rxed);
*(*value + len -1) = '\0';
}
if (*value == NULL)
*value = dmstrdup("");
}
int dmcmd_read(int pipe, char *buffer, int size)
{
int rd;
if (size < 2) return -1;
if ((rd = read(pipe, buffer, (size-1))) > 0) {
remove_new_line(buffer);
buffer[rd] = '\0';
return (rd + 1);
} else {
buffer[0] = '\0';
return -1;
}
return -1;
}
void update_section_list(char *config, char *section, char *option, int number, char *filter, char *option1, char *val1, char *option2, char *val2)
{
struct uci_section *s = NULL;
@ -316,24 +281,16 @@ int wan_remove_dev_interface(struct uci_section *interface_setion, char *dev)
void hex_to_ip(char *address, char *ret)
{
int ip[4] = {0};
unsigned int ip[4] = {0};
sscanf(address, "%2x%2x%2x%2x", &(ip[0]), &(ip[1]), &(ip[2]), &(ip[3]));
if (htonl(13) == 13) {
sprintf(ret, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
sprintf(ret, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
} else {
sprintf(ret, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]);
sprintf(ret, "%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]);
}
}
void ip_to_hex(char *address, char *ret)
{
int ip[4] = {0};
sscanf(address, "%d.%d.%d.%d", &(ip[0]), &(ip[1]), &(ip[2]), &(ip[3]));
sprintf(ret, "%02X%02X%02X%02X", ip[0], ip[1], ip[2], ip[3]);
}
/*
* dmmap_config sections list manipulation
*/
@ -355,7 +312,7 @@ static void dmmap_config_dup_delete(struct dmmap_dup *dmmap_config)
void free_dmmap_config_dup_list(struct list_head *dup_list)
{
struct dmmap_dup *dmmap_config;
struct dmmap_dup *dmmap_config = NULL;
while (dup_list->next != dup_list) {
dmmap_config = list_entry(dup_list->next, struct dmmap_dup, list);
dmmap_config_dup_delete(dmmap_config);
@ -549,7 +506,7 @@ int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_packag
* Add system and dmmap sections to the list
*/
if(instance == NULL || strlen(instance) <= 0)
if (instance == NULL || *instance == '\0')
add_sysfs_section_list(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
else
add_sysfs_section_list(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
@ -629,7 +586,7 @@ char *check_create_dmmap_package(const char *dmmap_package)
if (rc == -1)
return NULL;
if (access(path, F_OK)) {
if (!file_exists(path)) {
/*
*File does not exist
**/
@ -804,14 +761,15 @@ char **strsplit_by_str(const char str[], char *delim)
char **tokens = dmcalloc(tokens_alloc, sizeof(char*));
char *strparse = strdup(str);
do {
substr = strstr(strparse, delim);
if (substr == NULL && (strparse == NULL || strparse[0] == '\0'))
if (strparse == NULL || strparse[0] == '\0')
break;
substr = strstr(strparse, delim);
if (substr == NULL) {
substr = strdup(strparse);
tokens[tokens_used] = dmcalloc(strlen(substr)+1, sizeof(char));
strcpy(tokens[tokens_used], strparse);
DM_STRNCPY(tokens[tokens_used], strparse, strlen(substr)+1);
tokens_used++;
FREE(strparse);
break;
@ -836,23 +794,6 @@ char **strsplit_by_str(const char str[], char *delim)
return tokens;
}
char *get_macaddr_from_device(char *device_name)
{
char *mac;
if (device_name[0]) {
char file[128];
char val[32];
snprintf(file, sizeof(file), "/sys/class/net/%s/address", device_name);
dm_read_sysfs_file(file, val, sizeof(val));
mac = dmstrdup(val);
} else {
mac = "";
}
return mac;
}
char *get_macaddr(char *interface_name)
{
char *device = get_device(interface_name);
@ -1015,16 +956,15 @@ int get_shift_time_time(int shift_time, char *local_time, int size)
return 0;
}
int command_exec_output_to_array(char *cmd, char **output, int *length)
int command_exec_output_to_array(const char *cmd, char **output, int *length)
{
FILE *fp;
char out[1035];
char out[2048];
int i = 0;
/* Open the command for reading. */
fp = popen(cmd, "r");
FILE *fp = popen(cmd, "r");
if (fp == NULL)
return 0;
return -1;
/* Read the output line by line and store it in output array. */
while (fgets(out, sizeof(out)-1, fp) != NULL)
@ -1137,8 +1077,7 @@ void convert_hex_to_string(const char *hex, char *str)
char buf[3] = {0};
for (i = 0, j = 0; i < len; i += 2, j++) {
strncpy(buf, &hex[i], 2);
buf[2] = '\0';
DM_STRNCPY(buf, &hex[i], 3);
sprintf((char *)str + j, "%c", (char)strtol(buf, NULL, 16));
}
str[j] = '\0';
@ -1241,7 +1180,7 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_
}
/* check size */
if ((r_args[i].min && ui_val < minval) || (r_args[i].max && ui_val > maxval) || (ui_val < 0) || (ui_val > (unsigned int)UINT_MAX))
if ((r_args[i].min && ui_val < minval) || (r_args[i].max && ui_val > maxval) || (ui_val > (unsigned int)UINT_MAX))
return -1;
}
@ -1295,7 +1234,7 @@ int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args
if ((*value == '-') || (*endval != 0) || (errno != 0)) return -1;
/* check size */
if ((r_args[i].min && ul_val < minval) || (r_args[i].max && ul_val > maxval) || (ul_val < 0) || (ul_val > (unsigned long)ULONG_MAX))
if ((r_args[i].min && ul_val < minval) || (r_args[i].max && ul_val > maxval) || (ul_val > (unsigned long)ULONG_MAX))
return -1;
}
@ -1391,8 +1330,7 @@ int dm_validate_string_list(char *value, int min_item, int max_item, int max_siz
/* copy data in buffer */
char buf[strlen(value)+1];
strncpy(buf, value, sizeof(buf) - 1);
buf[strlen(value)] = '\0';
DM_STRNCPY(buf, value, sizeof(buf));
/* for each value, validate string */
for (pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) {
@ -1419,8 +1357,7 @@ int dm_validate_unsignedInt_list(char *value, int min_item, int max_item, int ma
/* copy data in buffer */
char buf[strlen(value)+1];
strncpy(buf, value, sizeof(buf) - 1);
buf[strlen(value)] = '\0';
DM_STRNCPY(buf, value, sizeof(buf));
/* for each value, validate string */
for (token = strtok_r(buf, ",", &saveptr); token != NULL; token = strtok_r(NULL, ",", &saveptr)) {
@ -1440,7 +1377,7 @@ bool folder_exists(const char *path)
{
struct stat buffer;
return (stat(path, &buffer) == 0 && S_ISDIR(buffer.st_mode));
return stat(path, &buffer) == 0 && S_ISDIR(buffer.st_mode);
}
bool file_exists(const char *path)
@ -1454,7 +1391,7 @@ bool is_regular_file(const char *path)
{
struct stat buffer;
return (stat(path, &buffer) == 0 && S_ISREG(buffer.st_mode));
return stat(path, &buffer) == 0 && S_ISREG(buffer.st_mode);
}
unsigned long file_system_size(const char *path, const enum fs_size_type_enum type)
@ -1503,10 +1440,8 @@ char *decode64(char *enc)
char *stringToHex(char *text, int length)
{
char *hex = NULL;
int i, j;
hex = (char *)dmcalloc(100, sizeof(char));
char *hex = (char *)dmcalloc(100, sizeof(char));
for (i = 0, j = 0; i < length; ++i, j += 3) {
sprintf(hex + j, "%02x", text[i] & 0xff);
@ -1526,6 +1461,36 @@ char *replace_char(char *str, char find, char replace)
return str;
}
char *replace_str(const char *str, const char *substr, const char *replacement)
{
int replacement_len = strlen(replacement);
int substr_len = strlen(substr);
int i, cnt = 0;
for (i = 0; str[i] != '\0'; i++) {
if (strstr(&str[i], substr) == &str[i]) {
cnt++;
i += substr_len - 1;
}
}
size_t new_str_len = i + cnt * (replacement_len - substr_len) + 1;
char *value = (char *)dmmalloc(new_str_len * sizeof(char));
i = 0;
while (*str) {
if (strstr(str, substr) == str) {
i += snprintf(&value[i], new_str_len - i, "%s", replacement);
str += substr_len;
}
else
value[i++] = *str++;
}
value[i] = '\0';
return value;
}
void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, char *value)
{
struct uci_section *d_sec = NULL;
@ -1542,14 +1507,14 @@ void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, ch
void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *value, bool b)
{
struct uci_list *v = NULL;
struct uci_element *e;
char *val;
struct uci_element *e = NULL;
char *val = NULL;
dmuci_get_value_by_section_list(s, section, &v);
if (v != NULL) {
uci_foreach_element(v, e) {
val = dmstrdup(e->name);
if (strcmp(val, value) == 0) {
if (val && strcmp(val, value) == 0) {
if (!b) {
// remove this entry
dmuci_del_list_value_by_section(s, section, value);

View file

@ -224,13 +224,10 @@ char *cidr2netmask(int bits);
bool is_strword_in_optionvalue(char *optionvalue, char *str);
void remove_new_line(char *buf);
int dmcmd(char *cmd, int n, ...);
int dmcmd_read(int pipe, char *buffer, int size);
void dmcmd_read_alloc(int pipe, char **value);
int dmcmd_no_wait(char *cmd, int n, ...);
void update_section_list(char *config, char *section, char *option, int number, char *filter, char *option1, char *val1, char *option2, char *val2);
int wan_remove_dev_interface(struct uci_section *interface_setion, char *dev);
void hex_to_ip(char *address, char *ret);
void ip_to_hex(char *address, char *ret);
void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section, void* additional_attribute);
void free_dmmap_config_dup_list(struct list_head *dup_list);
void synchronize_specific_config_sections_with_dmmap(char *package, char *section_type, char *dmmap_package, struct list_head *dup_list);
@ -251,25 +248,24 @@ unsigned char isdigit_str(char *str);
char *dm_strword(char *src, char *str);
char **strsplit(const char* str, const char* delim, size_t* numtokens);
char **strsplit_by_str(const char str[], char *delim);
char *get_macaddr_from_device(char *device_name);
char *get_macaddr(char *ifname);
char *get_macaddr(char *interface_name);
char *get_device(char *interface_name);
char *get_l3_device(char *interface_name);
bool elt_exits_in_str_list(char *str_list, char *elt);
void add_elt_to_str_list(char **str_list, char *elt);
void remove_elt_from_str_list(char **iface_list, char *ifname);
void remove_elt_from_str_list(char **str_list, char *ifname);
struct uci_section *get_origin_section_from_config(char *package, char *section_type, char *orig_section_name);
struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_type, char *orig_section_name);
struct uci_section *get_dup_section_in_dmmap_opt(char *dmmap_package, char *section_type, char *opt_name, char *opt_value);
struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value);
bool elt_exists_in_array(char **str_array, char *str, int length);
int get_shift_time_time(int shift_time, char *local_time, int size);
int command_exec_output_to_array(char *cmd, char **output, int *length);
int command_exec_output_to_array(const char *cmd, char **output, int *length);
struct uci_section *is_dmmap_section_exist(char* package, char* section);
struct uci_section *is_dmmap_section_exist_eq(char* package, char* section, char* opt, char* value);
int dm_read_sysfs_file(const char *file, char *dst, unsigned len);
int get_net_iface_sysfs(const char *uci_iface, const char *name, char **value);
int get_net_device_sysfs(const char *uci_iface, const char *name, char **value);
int get_net_device_sysfs(const char *device, const char *name, char **value);
char *get_device_from_wifi_iface(const char *wifi_iface, const char *wifi_section);
int dm_time_format(time_t ts, char **dst);
void convert_string_to_hex(const char *str, char *hex);
@ -292,6 +288,7 @@ bool is_regular_file(const char *path);
unsigned long file_system_size(const char *path, const enum fs_size_type_enum type);
char *stringToHex(char *text, int length);
char *replace_char(char *str, char find, char replace);
char *replace_str(const char *str, const char *substr, const char *replacement);
void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *value, bool b);
void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, char *value);
int check_browse_section(struct uci_section *s, void *data);

View file

@ -12,57 +12,6 @@
#include "dmjson.h"
static json_object *dmjson_jobj = NULL;
void dm_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);
}
}
static void inline __dmjson_fprintf(FILE *fp, int argc, struct dmjson_arg dmarg[])
{
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++) {
dm_add_json_obj(json_obj_out, dmarg[i].key, dmarg[i].val);
}
arg = (char *)json_object_to_json_string(json_obj_out);
fprintf(fp, "%s\n", arg);
}
json_object_put(json_obj_out);
}
void dmjson_fprintf(FILE *fp, int argc, struct dmjson_arg dmarg[])
{
__dmjson_fprintf(fp, argc, dmarg);
}
void bbf_api_dmjson_parse_init(char *msg)
{
if (dmjson_jobj) {
json_object_put(dmjson_jobj);
dmjson_jobj = NULL;
}
dmjson_jobj = json_tokener_parse(msg);
}
void bbf_api_dmjson_parse_fini(void)
{
if (dmjson_jobj) {
json_object_put(dmjson_jobj);
dmjson_jobj = NULL;
}
}
static char *dmjson_print_value(json_object *jobj)
{
enum json_type type;
@ -87,13 +36,8 @@ static char *dmjson_print_value(json_object *jobj)
char *____dmjson_get_value_in_obj(json_object *mainjobj, char *argv[])
{
json_object *jobj = NULL;
char *value = "";
jobj = bbf_api_dmjson_select_obj(mainjobj, argv);
value = dmjson_print_value(jobj);
return value;
json_object *jobj = bbf_api_dmjson_select_obj(mainjobj, argv);
return dmjson_print_value(jobj);
}
char *__dmjson_get_value_in_obj(json_object *mainjobj, int argc, ...)
@ -125,10 +69,9 @@ json_object *__dmjson_get_obj(json_object *mainjobj, int argc, ...)
argv[argc] = NULL;
va_end(arg);
return bbf_api_dmjson_select_obj(mainjobj, argv);
//return v;
}
json_object *bbf_api_dmjson_select_obj(json_object * jobj, char *argv[])
json_object *bbf_api_dmjson_select_obj(json_object *jobj, char *argv[])
{
int i;
for (i = 0; argv[i]; i++) {
@ -243,7 +186,7 @@ char *____dmjson_get_value_array_all(json_object *mainjobj, char *delim, char *a
{
json_object *arrobj;
char *v, *ret = "";
int i, dlen;
int i, dlen, rlen;
delim = (delim) ? delim : ",";
dlen = strlen(delim);
@ -255,9 +198,9 @@ char *____dmjson_get_value_array_all(json_object *mainjobj, char *delim, char *a
if (*ret == '\0') {
ret = dmstrdup(v);
} else if (*v) {
ret = dmrealloc(ret, strlen(ret) + dlen + strlen(v) + 1);
strcat(ret, delim);
strcat(ret, v);
rlen = strlen(ret);
ret = dmrealloc(ret, rlen + dlen + strlen(v) + 1);
snprintf(&ret[rlen], dlen + strlen(v) + 1, "%s%s", delim, v);
}
}
return ret;
@ -278,29 +221,3 @@ char *__dmjson_get_value_array_all(json_object *mainjobj, char *delim, int argc,
ret = ____dmjson_get_value_array_all(mainjobj, delim, argv);
return ret;
}
void bbf_api_dmjson_get_var(char *jkey, char **jval)
{
*jval = "";
if (dmjson_jobj == NULL)
return;
json_object_object_foreach(dmjson_jobj, key, val) {
if (strcmp(jkey, key) == 0) {
*jval = dmjson_print_value(val);
return;
}
}
}
void bbf_api_dmjson_get_string(char *jkey, char **jval)
{
*jval = "";
if (dmjson_jobj == NULL)
return;
struct json_object *get_obj;
if (json_object_object_get_ex(dmjson_jobj, jkey, &get_obj))
*jval = (char *)json_object_get_string(get_obj);
}

View file

@ -27,13 +27,6 @@ struct dmjson_arg {
#define DMJSON_ARGS (struct dmjson_arg[])
void dm_add_json_obj(json_object *json_obj_out, char *object, char *string);
void dmjson_printf(int argc, struct dmjson_arg dmarg[]);
void dmjson_fprintf(FILE *fp, int argc, struct dmjson_arg dmarg[]);
void bbf_api_dmjson_parse_init(char *msg);
void bbf_api_dmjson_parse_fini(void);
void bbf_api_dmjson_get_var(char *jkey, char **jval);
void bbf_api_dmjson_get_string(char *jkey, char **jval);
json_object *bbf_api_dmjson_select_obj(json_object * jobj, char *argv[]);
json_object *__dmjson_get_obj(json_object *mainjobj, int argc, ...);
char *____dmjson_get_value_in_obj(json_object *mainjobj, char *argv[]);
@ -58,7 +51,7 @@ char *__dmjson_get_value_array_all(json_object *mainjobj, char *delim, int argc,
__dmjson_select_obj_in_array_idx(MAINJOBJ, NULL, INDEX, ARGC, ##args)
#define dmjson_get_value_array_all(MAINJOBJ,DELIM,ARGC,args...) \
__dmjson_get_value_array_all(MAINJOBJ, DELIM, ARGC, ##args);
__dmjson_get_value_array_all(MAINJOBJ, DELIM, ARGC, ##args)
#define dmjson_foreach_obj_in_array(MAINJOBJ,ARROBJ,OBJ,INDEX,ARGC,args...) \
for (INDEX = 0, ARROBJ = NULL, OBJ = __dmjson_select_obj_in_array_idx(MAINJOBJ, &(ARROBJ), INDEX, ARGC, ##args);\

View file

@ -57,12 +57,12 @@ inline void *__dmrealloc
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
void *old, size_t size
void *n, size_t size
)
{
struct dmmem *m = NULL;
if (old != NULL) {
m = container_of(old, struct dmmem, mem);
if (n != NULL) {
m = container_of(n, struct dmmem, mem);
list_del(&m->list);
}
struct dmmem *new_m = realloc(m, sizeof(struct dmmem) + size);
@ -131,26 +131,22 @@ char **s, const char *format, ...
{
int size;
char *str = NULL;
va_list arg, argcopy;
va_list arg;
va_start(arg,format);
va_copy(argcopy, arg);
size = vsnprintf(NULL, 0, format, argcopy);
if (size < 0)
return -1;
va_end(argcopy);
#ifdef WITH_MEMTRACK
str = (char *)__dmcalloc(file, func, line, sizeof(char), size+1);
#else
str = (char *)__dmcalloc(sizeof(char), size+1);
#endif
vsnprintf(str, size+1, format, arg);
va_start(arg, format);
size = vasprintf(&str, format, arg);
va_end(arg);
if (size < 0 || str == NULL)
return -1;
#ifdef WITH_MEMTRACK
*s = __dmstrdup(file, func, line, str);
#else
*s = __dmstrdup(str);
#endif /*WITH_MEMTRACK*/
free(str);
if (*s == NULL)
return -1;
return 0;

View file

@ -149,7 +149,7 @@ static unsigned dm_ubus_req_hash(const struct dm_ubus_req *req)
static const struct dm_ubus_cache_entry * dm_ubus_cache_lookup(unsigned hash)
{
const struct dm_ubus_cache_entry *entry;
const struct dm_ubus_cache_entry *entry = NULL;
const struct dm_ubus_cache_entry *entry_match = NULL;
list_for_each_entry(entry, &dmubus_cache, list) {
@ -204,8 +204,8 @@ int dmubus_call(char *obj, char *method, struct ubus_arg u_args[], int u_args_si
static void receive_list_result(struct ubus_context *ctx, struct ubus_object_data *obj, void *priv)
{
struct blob_attr *cur;
size_t rem;
struct blob_attr *cur = NULL;
size_t rem = 0;
if (!obj->signature || *ubus_method == '\0')
return;
@ -236,7 +236,7 @@ bool dmubus_object_method_exists(const char *obj)
*delimiter = '\0';
}
strncpy(ubus_method, method, sizeof(ubus_method) - 1);
DM_STRNCPY(ubus_method, method, sizeof(ubus_method));
ubus_method_exists = false;
if (ubus_lookup(ubus_ctx, obj, receive_list_result, NULL))

View file

@ -68,39 +68,28 @@ int bbf_uci_exit(void)
return 0;
}
char *dmuci_list_to_string(struct uci_list *list, char *delimitor)
char *dmuci_list_to_string(struct uci_list *list, const char *delimitor)
{
struct uci_element *e = NULL;
char val[512] = {0};
int del_len = strlen(delimitor);
if (list) {
struct uci_element *e = NULL;
char list_val[512] = {0};
unsigned pos = 0;
list_val[0] = 0;
uci_foreach_element(list, e) {
int len = strlen(val);
if (len != 0) {
memcpy(val + len, delimitor, del_len);
strcpy(val + len + del_len, e->name);
} else
strcpy(val, e->name);
if (e->name)
pos += snprintf(&list_val[pos], sizeof(list_val) - pos, "%s%s", e->name, delimitor);
}
return (dmstrdup(val)); // MEM WILL BE FREED IN DMMEMCLEAN
if (pos)
list_val[pos - 1] = 0;
return dmstrdup(list_val); // MEM WILL BE FREED IN DMMEMCLEAN
} else {
return "";
}
}
void uci_add_list_to_list(struct uci_list *addlist, struct uci_list *list)
{
struct uci_element *e, *elt;
uci_foreach_element(addlist, e) {
elt = dmcalloc(1, sizeof(struct uci_element));
elt->list= e->list;
elt->name= e->name;
uci_list_add(list, &elt->list);
}
}
static inline bool check_section_name(const char *str, bool name)
{
if (!*str)
@ -117,7 +106,8 @@ static inline bool check_section_name(const char *str, bool name)
static void add_list_package_change(struct list_head *clist, char *package)
{
struct package_change *pc;
struct package_change *pc = NULL;
list_for_each_entry(pc, clist, list) {
if (strcmp(pc->package, package) == 0)
return;
@ -223,10 +213,10 @@ char *dmuci_get_option_value_fallback_def(char *package, char *section, char *op
int dmuci_get_option_value_list(char *package, char *section, char *option, struct uci_list **value)
{
struct uci_element *e;
struct uci_element *e = NULL;
struct uci_ptr ptr = {0};
struct uci_list *list;
char *pch = NULL, *spch = NULL, *dup;
char *pch = NULL, *spch = NULL, *dup = NULL;
*value = NULL;
@ -265,7 +255,7 @@ int dmuci_get_option_value_list(char *package, char *section, char *option, stru
static struct uci_option *dmuci_get_option_ptr(char *cfg_path, char *package, char *section, char *option)
{
struct uci_option *o = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
struct uci_ptr ptr = {0};
char *oconfdir;
@ -292,7 +282,7 @@ end:
int dmuci_import(char *package_name, const char *input_path)
{
struct uci_package *package = NULL;
struct uci_element *e;
struct uci_element *e = NULL;
int ret = 0;
FILE *input = fopen(input_path, "r");
@ -532,20 +522,17 @@ int dmuci_del_list_value(char *package, char *section, char *option, char *value
char *dmuci_add_section(char *package, char *stype, struct uci_section **s)
{
struct uci_ptr ptr = {0};
char *fname, *val = "";
char fname[128], *val = "";
*s = NULL;
dmasprintf(&fname, "%s/%s", uci_ctx->confdir, package);
if (access(fname, F_OK ) == -1 ) {
snprintf(fname, sizeof(fname), "%s/%s", uci_ctx->confdir, package);
if (!file_exists(fname)) {
FILE *fptr = fopen(fname, "w");
dmfree(fname);
if (fptr)
fclose(fptr);
else
return val;
} else {
dmfree(fname);
}
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) == 0
@ -618,7 +605,7 @@ lookup:
/**** UCI GET by section pointer*****/
int dmuci_get_value_by_section_string(struct uci_section *s, char *option, char **value)
{
struct uci_element *e;
struct uci_element *e = NULL;
struct uci_option *o;
if (s == NULL || option == NULL)
@ -654,7 +641,7 @@ char *dmuci_get_value_by_section_fallback_def(struct uci_section *s, char *optio
int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value)
{
struct uci_element *e;
struct uci_element *e = NULL;
struct uci_option *o;
struct uci_list *list;
char *pch = NULL, *spch = NULL, *dup;
@ -785,7 +772,7 @@ int dmuci_rename_section_by_section(struct uci_section *s, char *value)
struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk)
{
struct uci_section *s = NULL;
struct uci_element *e, *m;
struct uci_element *e, *m = NULL;
char *value, *dup, *pch, *spch;
struct uci_list *list_value, *list_section;
struct uci_ptr ptr = {0};

View file

@ -314,8 +314,7 @@ int dmuci_init(void);
void dmuci_exit(void);
int bbf_uci_init(void);
int bbf_uci_exit(void);
char *dmuci_list_to_string(struct uci_list *list, char *delimitor);
void uci_add_list_to_list(struct uci_list *addlist, struct uci_list *list);
char *dmuci_list_to_string(struct uci_list *list, const char *delimitor);
void free_all_list_package_change(struct list_head *clist);
int dmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);
int dmuci_import(char *package_name, const char *input_path);