mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-01-28 01:47:18 +01:00
Ticket refs #6623: remove static code analysis warnings
This commit is contained in:
parent
d42bd920d3
commit
35633a3bc8
20 changed files with 84 additions and 88 deletions
|
|
@ -12,6 +12,7 @@ stages:
|
|||
variables:
|
||||
DEBUG: 'TRUE'
|
||||
SOURCE_FOLDER: "."
|
||||
RUN_CPPCHECK: "cppcheck --enable=all --error-exitcode=1 --suppress=unusedFunction --suppress=unreadVariable --suppress=knownConditionTrueFalse --suppress=duplicateCondition ."
|
||||
|
||||
run_unit_test:
|
||||
stage: unit_test
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ static json_object *get_requested_json_obj(json_object *json_obj, char *instance
|
|||
}
|
||||
*p = 0;
|
||||
|
||||
res = (idx_pos >= 0) ? dmjson_select_obj_in_array_idx(res, idx_pos, 1, buf) : res;
|
||||
res = dmjson_select_obj_in_array_idx(res, idx_pos, 1, buf);
|
||||
|
||||
} else if (pchr && *pchr) {
|
||||
res = dmjson_get_obj(res, 1, pch);
|
||||
|
|
@ -513,13 +513,13 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc
|
|||
}
|
||||
|
||||
if (file && section_type && dmmap_file) {
|
||||
struct uci_section *section = NULL, *dmmap = NULL;
|
||||
struct uci_section *s = NULL, *dmmap_s = NULL;
|
||||
|
||||
dmuci_add_section(json_object_get_string(file), json_object_get_string(section_type), §ion);
|
||||
dmuci_add_section(json_object_get_string(file), json_object_get_string(section_type), &s);
|
||||
|
||||
dmuci_add_section_bbfdm(json_object_get_string(dmmap_file), json_object_get_string(section_type), &dmmap);
|
||||
dmuci_set_value_by_section(dmmap, "section_name", section_name(section));
|
||||
dmuci_set_value_by_section(dmmap, buf_instance, *instance);
|
||||
dmuci_add_section_bbfdm(json_object_get_string(dmmap_file), json_object_get_string(section_type), &dmmap_s);
|
||||
dmuci_set_value_by_section(dmmap_s, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(dmmap_s, buf_instance, *instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,10 +137,10 @@ static void load_vendor_extension_arrays(struct dmctx *ctx)
|
|||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj = calloc(2, sizeof(DMOBJ *));
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj[0] = vendor_obj[i].root_obj;
|
||||
} else {
|
||||
int idx = get_obj_idx_dynamic_array(dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj);
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj = realloc(dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj, (idx + 2) * sizeof(DMOBJ *));
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj[idx] = vendor_obj[i].root_obj;
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj[idx+1] = NULL;
|
||||
int obj_idx = get_obj_idx_dynamic_array(dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj);
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj = realloc(dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj, (obj_idx + 2) * sizeof(DMOBJ *));
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj[obj_idx] = vendor_obj[i].root_obj;
|
||||
dm_entryobj->nextdynamicobj[INDX_VENDOR_MOUNT].nextobj[obj_idx+1] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,10 +156,10 @@ static void load_vendor_extension_arrays(struct dmctx *ctx)
|
|||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf = calloc(2, sizeof(DMLEAF *));
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf[0] = vendor_obj[i].root_leaf;
|
||||
} else {
|
||||
int idx = get_leaf_idx_dynamic_array(dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf);
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf = realloc(dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf, (idx + 2) * sizeof(DMLEAF *));
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf[idx] = vendor_obj[i].root_leaf;
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf[idx+1] = NULL;
|
||||
int leaf_idx = get_leaf_idx_dynamic_array(dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf);
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf = realloc(dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf, (leaf_idx + 2) * sizeof(DMLEAF *));
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf[leaf_idx] = vendor_obj[i].root_leaf;
|
||||
dm_entryobj->dynamicleaf[INDX_VENDOR_MOUNT].nextleaf[leaf_idx+1] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1,
|
|||
fault = dm_entry_get_schema(ctx);
|
||||
break;
|
||||
case CMD_GET_INSTANCES:
|
||||
if (!arg1 || (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0))
|
||||
if (!arg1 || string_to_bool(arg1, &ctx->nextlevel) == 0)
|
||||
fault = dm_entry_get_instances(ctx);
|
||||
else
|
||||
fault = FAULT_9003;
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ static int browseServicesVoiceServiceDECTBaseInst(struct dmctx *dmctx, DMNODE *p
|
|||
{
|
||||
json_object *res = NULL, *obj = NULL, *arrobj = NULL;
|
||||
char *inst = NULL;
|
||||
int id = 0, i = 0;
|
||||
|
||||
dmubus_call("dect", "status", UBUS_ARGS{0}, 0, &res);
|
||||
if (res) {
|
||||
int id = 0, i = 0;
|
||||
|
||||
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "base") {
|
||||
|
||||
inst = handle_instance_without_section(dmctx, parent_node, ++id);
|
||||
|
|
@ -38,10 +39,11 @@ static int browseServicesVoiceServiceDECTPortableInst(struct dmctx *dmctx, DMNOD
|
|||
{
|
||||
json_object *res = NULL, *obj = NULL, *arrobj = NULL;
|
||||
char *inst = NULL;
|
||||
int id = 0, i = 0;
|
||||
|
||||
dmubus_call("dect", "status", UBUS_ARGS{0}, 0, &res);
|
||||
if (res) {
|
||||
int id = 0, i = 0;
|
||||
|
||||
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "handsets") {
|
||||
|
||||
inst = handle_instance_without_section(dmctx, parent_node, ++id);
|
||||
|
|
@ -310,11 +312,12 @@ static int get_ServicesVoiceServiceDECTPortable_IPUI(char *refparam, struct dmct
|
|||
static int get_ServicesVoiceServiceDECTPortable_IPEI(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *ipui = dmjson_get_value((json_object *)data, 1, "ipui");
|
||||
char buff[14] = {0};
|
||||
|
||||
*value = "";
|
||||
// Check for N type PUT
|
||||
if (ipui[0] == '0') {
|
||||
char buff[14] = {0};
|
||||
|
||||
DM_STRNCPY(buff, &ipui[1], sizeof(buff));
|
||||
dmasprintf(value, "%s0", buff);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -781,7 +781,6 @@ static void dmmap_synchronizeBridgingBridgePort(struct dmctx *dmctx, DMNODE *par
|
|||
uci_path_foreach_option_eq_safe(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_args->br_inst, stmp, s) {
|
||||
|
||||
// section added by user ==> skip it
|
||||
char *s_user = NULL;
|
||||
dmuci_get_value_by_section_string(s, "added_by_user", &s_user);
|
||||
if (s_user && strcmp(s_user, "1") == 0)
|
||||
continue;
|
||||
|
|
@ -1068,16 +1067,16 @@ static void update_vlanport_and_device_section(void *data, char *linker, char **
|
|||
if (device_name && strcmp(section_name(s), device_name) == 0) {
|
||||
char *vid = NULL;
|
||||
dmuci_get_value_by_section_string(s, "vid", &vid);
|
||||
if (vid && vid [0] == '\0') {
|
||||
dmuci_set_value_by_section(s, "ifname", linker);
|
||||
dmuci_set_value_by_section(s, "name", linker);
|
||||
} else {
|
||||
if (vid && *vid) {
|
||||
char new_name[32] = {0};
|
||||
|
||||
snprintf(new_name, sizeof(new_name), "%s.%s", linker, vid);
|
||||
dmuci_set_value_by_section(s, "ifname", linker);
|
||||
dmuci_set_value_by_section(s, "name", new_name);
|
||||
*new_linker = dmstrdup(new_name);
|
||||
} else {
|
||||
dmuci_set_value_by_section(s, "ifname", linker);
|
||||
dmuci_set_value_by_section(s, "name", linker);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1602,7 +1601,7 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat
|
|||
if ((port && port[0] == '\0') || (management && strcmp(management, "1") == 0)) {
|
||||
// Remove only dmmap section
|
||||
dmuci_delete_by_section_bbfdm(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, NULL, NULL);
|
||||
} else {
|
||||
} else if (port && *port) {
|
||||
// Remove device from management port section
|
||||
remove_device_from_management_port((struct bridge_port_args *)data, port);
|
||||
|
||||
|
|
@ -2869,7 +2868,7 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo
|
|||
/* Update dmmap vlanport section */
|
||||
dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_dmmap_sec, "name", port_linker);
|
||||
dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_dmmap_sec, "port_name", section_name);
|
||||
} else {
|
||||
} else if (vid && *vid) {
|
||||
struct uci_section *s = NULL;
|
||||
char new_name[32] = {0};
|
||||
|
||||
|
|
|
|||
|
|
@ -136,9 +136,10 @@ static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_da
|
|||
static int browseDeviceInfoProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
char *inst = NULL;
|
||||
int nbr_cpus = get_number_of_cpus();
|
||||
int i;
|
||||
|
||||
for (i = 0; i < get_number_of_cpus(); i++) {
|
||||
for (i = 0; i < nbr_cpus; i++) {
|
||||
inst = handle_instance_without_section(dmctx, parent_node, i+1);
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, NULL, inst) == DM_STOP)
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -919,7 +919,7 @@ static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void
|
|||
char *device_s_type = NULL;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "device", &linker);
|
||||
if (linker && *linker == '\0')
|
||||
if (!linker || *linker == '\0')
|
||||
return 0;
|
||||
|
||||
// get device section mapped to this device name
|
||||
|
|
@ -988,7 +988,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void
|
|||
dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name);
|
||||
|
||||
//Generate the device name for bridge as br-<NETWORK>
|
||||
snprintf(device, sizeof(device), "br-%s", int_name);
|
||||
snprintf(device, sizeof(device), "br-%s", int_name ? int_name : "");
|
||||
|
||||
uci_foreach_sections("network", "interface", s) {
|
||||
if (int_name && strcmp(section_name(s), int_name) == 0) {
|
||||
|
|
|
|||
|
|
@ -124,14 +124,14 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
|
|||
|
||||
/* Higher layers are Device.IP.Interface.{i}. */
|
||||
uci_foreach_sections("network", "interface", s) {
|
||||
char *proto, *device;
|
||||
char *proto, *device_s;
|
||||
|
||||
dmuci_get_value_by_section_string(s, "proto", &proto);
|
||||
dmuci_get_value_by_section_string(s, "device", &device);
|
||||
dmuci_get_value_by_section_string(s, "device", &device_s);
|
||||
|
||||
if (strcmp(section_name(s), "loopback") == 0 ||
|
||||
*proto == '\0' ||
|
||||
strchr(device, '@'))
|
||||
strchr(device_s, '@'))
|
||||
continue;
|
||||
|
||||
// The higher layer is Device.IP.Interface.{i}.
|
||||
|
|
@ -320,11 +320,11 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
|
|||
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_inst, port) {
|
||||
dmuci_get_value_by_section_string(port, "management", &mg);
|
||||
if (mg && strcmp(mg, "1") == 0) {
|
||||
char *device, linker[512] = {0};
|
||||
char *device, linker_buf[512] = {0};
|
||||
|
||||
dmuci_get_value_by_section_string(port, "port", &device);
|
||||
snprintf(linker, sizeof(linker), "br_%s:%s+%s", br_inst, section_name(port), device);
|
||||
adm_entry_get_linker_param(dmctx, "Device.Bridging.Bridge.", linker, &value);
|
||||
snprintf(linker_buf, sizeof(linker_buf), "br_%s:%s+%s", br_inst, section_name(port), device);
|
||||
adm_entry_get_linker_param(dmctx, "Device.Bridging.Bridge.", linker_buf, &value);
|
||||
dmuci_get_value_by_section_string(port, "bridge_port_alias", &loweralias);
|
||||
dmuci_get_value_by_section_string(port, "bridge_port_instance", &layer_inst);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1263,12 +1263,11 @@ static int get_IPInterface_LastChange(char *refparam, struct dmctx *ctx, void *d
|
|||
|
||||
static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char linker[32] = {0};
|
||||
char linker[64] = {0};
|
||||
char *proto;
|
||||
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
|
||||
if (strstr(proto, "ppp")) {
|
||||
char linker[64] = {0};
|
||||
snprintf(linker, sizeof(linker), "%s", section_name((struct uci_section *)data));
|
||||
adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", linker, value);
|
||||
if (*value != NULL)
|
||||
|
|
@ -1278,7 +1277,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
|
|||
char *device = get_device(section_name((struct uci_section *)data));
|
||||
|
||||
/* If the device value is empty, then get its value directly from device option */
|
||||
if (device && *device == '\0')
|
||||
if (*device == '\0')
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device);
|
||||
|
||||
if (device[0] != '\0') {
|
||||
|
|
@ -1352,12 +1351,12 @@ 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};
|
||||
DM_STRNCPY(device, ip_linker, sizeof(device));
|
||||
char *vid = strchr(device, '.');
|
||||
char dev_buf[32] = {0};
|
||||
DM_STRNCPY(dev_buf, ip_linker, sizeof(dev_buf));
|
||||
char *vid = strchr(dev_buf, '.');
|
||||
if (vid) {
|
||||
*vid = '\0';
|
||||
uci_foreach_option_eq_safe("network", "interface", "device", device, stmp, s) {
|
||||
uci_foreach_option_eq_safe("network", "interface", "device", dev_buf, stmp, s) {
|
||||
dmuci_delete_by_section(s, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ static int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx
|
|||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
if (value && atoi(value) == 0)
|
||||
if (!value || atoi(value) == 0)
|
||||
break;
|
||||
|
||||
snprintf(expiry_date, sizeof(expiry_date), "%lld", (long long)(atoi(value) + time(NULL)));
|
||||
|
|
|
|||
|
|
@ -410,7 +410,6 @@ static int get_PPPInterface_CurrentMRUSize(char *refparam, struct dmctx *ctx, vo
|
|||
static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *lcp_echo = NULL, *token = NULL;
|
||||
char echo_val[50] = {0};
|
||||
|
||||
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", &lcp_echo);
|
||||
if (lcp_echo && *lcp_echo == '\0') {
|
||||
|
|
@ -420,6 +419,8 @@ static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *dat
|
|||
|
||||
token = strtok(lcp_echo , " ");
|
||||
if (NULL != token) {
|
||||
char echo_val[50] = {0};
|
||||
|
||||
DM_STRNCPY(echo_val, token, sizeof(echo_val));
|
||||
*value = dmstrdup(echo_val);
|
||||
}
|
||||
|
|
@ -430,13 +431,15 @@ static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *dat
|
|||
static int get_PPPInterface_LCPEchoRetry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char *lcp_retry = NULL, *token = NULL;
|
||||
char lcp_interval[50] = {0};
|
||||
|
||||
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", &lcp_retry);
|
||||
if (lcp_retry && *lcp_retry == '\0') {
|
||||
if (!lcp_retry || *lcp_retry == '\0') {
|
||||
*value = "5";
|
||||
} else {
|
||||
token = strchr(lcp_retry , ' ');
|
||||
if (NULL != token) {
|
||||
char lcp_interval[50] = {0};
|
||||
|
||||
DM_STRNCPY(lcp_interval, token + 1, sizeof(lcp_interval));
|
||||
*value = dmstrdup(lcp_interval);
|
||||
}
|
||||
|
|
@ -449,7 +452,6 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value,
|
|||
{
|
||||
char *proto, *pppd_opt = NULL;
|
||||
char list_options[1024] = {0};
|
||||
unsigned pos = 0;
|
||||
|
||||
dmuci_get_value_by_section_string(ss, "proto", &proto);
|
||||
if (0 == strcmp(proto, "pppoe")) {
|
||||
|
|
@ -459,6 +461,7 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value,
|
|||
if (pppd_opt && *pppd_opt != '\0') {
|
||||
char *token = NULL, *end = NULL;
|
||||
bool found = false;
|
||||
unsigned pos = 0;
|
||||
|
||||
list_options[0] = 0;
|
||||
token = strtok_r(pppd_opt, " ", &end);
|
||||
|
|
@ -583,15 +586,14 @@ static int set_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void
|
|||
|
||||
static int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
char path[1024] = {0};
|
||||
char session_id[20] = {0};
|
||||
FILE *fp;
|
||||
int i = 0;
|
||||
|
||||
fp = fopen("/proc/net/pppoe" ,"r");
|
||||
FILE *fp = fopen("/proc/net/pppoe" ,"r");
|
||||
if (NULL == fp) {
|
||||
*value = "1";
|
||||
} else {
|
||||
char session_id[20] = {0};
|
||||
char path[1024] = {0};
|
||||
int i = 0;
|
||||
|
||||
while (fgets(path, sizeof(path), fp) != NULL) {
|
||||
i++;
|
||||
if (2 == i) {
|
||||
|
|
@ -749,7 +751,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
|
|||
dev = get_device(section_name(((struct dmmap_dup *)data)->config_section));
|
||||
|
||||
// Check if interface name is same as dev value.
|
||||
char *token, *end = linker;
|
||||
char *token = NULL, *end = linker;
|
||||
while ((token = strtok_r(end, " ", &end))) {
|
||||
if (0 == strcmp(dev, token)) {
|
||||
ret = 1;
|
||||
|
|
@ -757,7 +759,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
|
|||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
if (ret == 0 || !token) {
|
||||
*value = "";
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
2
dmtree/vendor/openwrt/tr181/qos.c
vendored
2
dmtree/vendor/openwrt/tr181/qos.c
vendored
|
|
@ -40,7 +40,7 @@ int command_exec_output_to_array(const char *cmd, char **output, int *length)
|
|||
int i = 0;
|
||||
|
||||
/* Open the command for reading. */
|
||||
FILE *fp = popen(cmd, "r");
|
||||
FILE *fp = popen(cmd, "r"); /* Flawfinder: ignore */
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
|
|
@ -180,14 +180,14 @@ static bool check_version(const char *obj_version, struct dmctx *ctx)
|
|||
if (!config_version || !obj_version)
|
||||
return true;
|
||||
|
||||
if (config_version) {
|
||||
if (*config_version) {
|
||||
config_major = atoi(config_version);
|
||||
char *temp = strchr(config_version, '.');
|
||||
if (temp)
|
||||
config_minor = atoi(temp + 1);
|
||||
}
|
||||
|
||||
if (obj_version) {
|
||||
if (*obj_version) {
|
||||
obj_major = atoi(obj_version);
|
||||
char *temp = strchr(obj_version, '.');
|
||||
if (temp)
|
||||
|
|
|
|||
|
|
@ -477,7 +477,7 @@ static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, voi
|
|||
|
||||
#ifndef TRACE
|
||||
#define TRACE(MESSAGE, ...) do { \
|
||||
fprintf(stderr, "TRACE: %s@%s:%d " MESSAGE, __FUNCTION__,__FILE__,__LINE__, ##__VA_ARGS__); \
|
||||
fprintf(stderr, "TRACE: %s@%s:%d " MESSAGE, __FUNCTION__,__FILE__,__LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||
fprintf(stderr, "\n"); \
|
||||
fflush(stderr); \
|
||||
} while(0)
|
||||
|
|
@ -489,7 +489,7 @@ static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, voi
|
|||
#define BBF_DEBUG(fmt, ...) do { \
|
||||
FILE *fp = fopen("/tmp/bbfdm.log", "a"); \
|
||||
if (fp) { \
|
||||
fprintf(fp, "%s@%s:%d: " fmt, __func__, __FILE__, __LINE__, ##__VA_ARGS__); \
|
||||
fprintf(fp, "%s@%s:%d: " fmt, __func__, __FILE__, __LINE__, ##__VA_ARGS__); /* Flawfinder: ignore */ \
|
||||
fclose(fp); \
|
||||
} \
|
||||
} while(0)
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ int dmcmd(char *cmd, int n, ...)
|
|||
dup2(dmcmd_pfds[1], 1);
|
||||
close(dmcmd_pfds[1]);
|
||||
|
||||
execvp(argv[0], (char **) argv);
|
||||
execvp(argv[0], (char **) argv); /* Flawfinder: ignore */
|
||||
exit(ESRCH);
|
||||
} else if (pid < 0)
|
||||
return -1;
|
||||
|
|
@ -210,7 +210,7 @@ int dmcmd_no_wait(char *cmd, int n, ...)
|
|||
return -1;
|
||||
|
||||
if (pid == 0) {
|
||||
execvp(argv[0], (char **) argv);
|
||||
execvp(argv[0], (char **) argv); /* Flawfinder: ignore */
|
||||
exit(ESRCH);
|
||||
} else if (pid < 0)
|
||||
return -1;
|
||||
|
|
@ -907,13 +907,12 @@ static inline int char_is_valid(char c)
|
|||
|
||||
int dm_read_sysfs_file(const char *file, char *dst, unsigned len)
|
||||
{
|
||||
char *content;
|
||||
char content[len];
|
||||
int fd;
|
||||
int rlen;
|
||||
int i, n;
|
||||
int rc = 0;
|
||||
|
||||
content = alloca(len);
|
||||
dst[0] = 0;
|
||||
|
||||
fd = open(file, O_RDONLY);
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ static char *____dmjson_get_value_array_all(json_object *mainjobj, char *delim,
|
|||
int i, dlen, rlen;
|
||||
|
||||
delim = (delim) ? delim : ",";
|
||||
dlen = strlen(delim);
|
||||
dlen = (delim) ? strlen(delim) : 1;
|
||||
|
||||
for (i = 0, arrobj = NULL, v = ____dmjson_get_value_in_array_idx(mainjobj, &arrobj, i, argv);
|
||||
v;
|
||||
|
|
|
|||
|
|
@ -32,13 +32,6 @@ struct dm_ubus_cache_entry {
|
|||
struct blob_attr *breq;
|
||||
};
|
||||
|
||||
struct dm_ubus_req {
|
||||
const char *obj;
|
||||
const char *method;
|
||||
struct ubus_arg *args;
|
||||
unsigned n_args;
|
||||
};
|
||||
|
||||
struct dm_ubus_hash_req {
|
||||
const char *obj;
|
||||
const char *method;
|
||||
|
|
@ -112,7 +105,6 @@ static void receive_call_result_data(struct ubus_request *req, int type, struct
|
|||
|
||||
static void __async_result_callback(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||
{
|
||||
const char *str;
|
||||
time_t resp_time = time(NULL);
|
||||
|
||||
const unsigned *hash = (unsigned *)req->priv;
|
||||
|
|
@ -149,7 +141,7 @@ static void __async_result_callback(struct ubus_request *req, int type, struct b
|
|||
return;
|
||||
}
|
||||
|
||||
str = blobmsg_format_json_indent(msg, true, -1);
|
||||
const char *str = blobmsg_format_json_indent(msg, true, -1);
|
||||
if (!str) {
|
||||
entry->data = NULL;
|
||||
return;
|
||||
|
|
@ -223,8 +215,6 @@ static inline json_object *ubus_call_req(char *obj, char *method, struct blob_at
|
|||
static int ubus_call_req_async(const char *obj, const char *method, const unsigned hash, struct blob_attr *attr)
|
||||
{
|
||||
uint32_t id;
|
||||
int rc = 0;
|
||||
struct ubus_request *req;
|
||||
|
||||
if (ubus_ctx == NULL) {
|
||||
ubus_ctx = dm_libubus_init();
|
||||
|
|
@ -235,7 +225,7 @@ static int ubus_call_req_async(const char *obj, const char *method, const unsign
|
|||
}
|
||||
|
||||
if (!ubus_lookup_id(ubus_ctx, obj, &id)) {
|
||||
req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
|
||||
struct ubus_request *req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
|
||||
if (req == NULL) {
|
||||
printf("Out of memory!\n\r");
|
||||
return -1;
|
||||
|
|
@ -243,7 +233,7 @@ static int ubus_call_req_async(const char *obj, const char *method, const unsign
|
|||
|
||||
memset(req, 0, sizeof(struct ubus_request));
|
||||
|
||||
rc = ubus_invoke_async(ubus_ctx, id, method, attr, req);
|
||||
int rc = ubus_invoke_async(ubus_ctx, id, method, attr, req);
|
||||
if (rc) {
|
||||
printf("Ubus async invoke failed (%s)\n\r", ubus_strerror(rc));
|
||||
free(req);
|
||||
|
|
@ -401,7 +391,7 @@ int dmubus_call(char *obj, char *method, struct ubus_arg u_args[], int u_args_si
|
|||
|
||||
const unsigned hash = dm_ubus_req_hash_from_blob(&hash_req);
|
||||
const struct dm_ubus_cache_entry *entry = dm_ubus_cache_lookup(hash);
|
||||
json_object *res;
|
||||
json_object *res = NULL;
|
||||
|
||||
if (entry) {
|
||||
res = entry->data;
|
||||
|
|
@ -470,8 +460,7 @@ bool dmubus_object_method_exists(const char *obj)
|
|||
if (ubus_ctx == NULL) {
|
||||
ubus_ctx = dm_libubus_init();
|
||||
if (ubus_ctx == NULL) {
|
||||
printf("UBUS context is null\n\r");
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ int usp_dm_exec(int cmd, char *path, char *arg1, char *arg2)
|
|||
{
|
||||
int fault = 0;
|
||||
struct dmctx bbf_ctx;
|
||||
struct dm_parameter *n;
|
||||
|
||||
memset(&bbf_ctx, 0, sizeof(struct dmctx));
|
||||
|
||||
|
|
@ -64,10 +63,10 @@ int usp_dm_exec(int cmd, char *path, char *arg1, char *arg2)
|
|||
|
||||
dm_ctx_init(&bbf_ctx, 0);
|
||||
|
||||
if (arg2)
|
||||
if (arg2 && *arg2) {
|
||||
bbf_ctx.dm_version = arg2;
|
||||
|
||||
printf("config version %s\n", bbf_ctx.dm_version);
|
||||
printf("config version %s\n", bbf_ctx.dm_version);
|
||||
}
|
||||
|
||||
if (cmd == CMD_GET_INFO){
|
||||
fault = dm_get_supported_dm(&bbf_ctx, path, false, atoi(arg1));
|
||||
|
|
@ -76,6 +75,8 @@ int usp_dm_exec(int cmd, char *path, char *arg1, char *arg2)
|
|||
}
|
||||
|
||||
if (!fault) {
|
||||
struct dm_parameter *n;
|
||||
|
||||
list_for_each_entry(n, &bbf_ctx.list_parameter, list) {
|
||||
printf(" %s::%s::%s\n", n->name, n->data, n->type);
|
||||
}
|
||||
|
|
@ -90,7 +91,7 @@ int usp_dm_exec(int cmd, char *path, char *arg1, char *arg2)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
static struct ubus_context *ubus_ctx = NULL;
|
||||
char *param = NULL, *value = NULL, *version = NULL;
|
||||
char *param = "", *value = "", *version = "";
|
||||
int cmd;
|
||||
|
||||
if (argc < 3) {
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ static int get_operate_args_XIOPSYSEUPingTEST_Run(char *refparam, struct dmctx *
|
|||
|
||||
static int operate_DeviceXIOPSYSEUPingTEST_Run(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
char *p, *min = NULL, *avg = NULL, *max = NULL, line[512], command[512];
|
||||
char *p, *min = NULL, *avg = NULL, *max = NULL, command[512];
|
||||
FILE *log = NULL;
|
||||
|
||||
char *host = dmjson_get_value((json_object *)value, 1, "Host");
|
||||
|
|
@ -292,11 +292,13 @@ static int operate_DeviceXIOPSYSEUPingTEST_Run(char *refparam, struct dmctx *ctx
|
|||
|
||||
snprintf(command, sizeof(command), "ping -c 1 -W 1 %s", host);
|
||||
|
||||
if ((log = popen(command, "r"))) {
|
||||
if ((log = popen(command, "r"))) { /* Flawfinder: ignore */
|
||||
char line[512] = {0};
|
||||
|
||||
while (fgets(line, sizeof(line), log) != NULL) {
|
||||
if (strstr(line, "rtt")) {
|
||||
strtok_r(line, "=", &min);
|
||||
strtok_r(min+1, "/", &avg);
|
||||
strtok_r(min ? min+1 : "", "/", &avg);
|
||||
add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), dmstrdup(min ? min+1 : ""), "xsd:unsignedInt", NULL);
|
||||
strtok_r(avg, "/", &max);
|
||||
add_list_parameter(ctx, dmstrdup("AverageResponseTime"), dmstrdup(avg ? avg : ""), "xsd:unsignedInt", NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue