diff --git a/dmbbfcommon.c b/dmbbfcommon.c index 12430257..70d282e1 100644 --- a/dmbbfcommon.c +++ b/dmbbfcommon.c @@ -56,27 +56,27 @@ int get_dm_type(char *dm_str) if (dm_str == NULL) return DMT_STRING; - if (strcmp(dm_str, DMT_TYPE[DMT_STRING]) == 0) + if (DM_STRCMP(dm_str, DMT_TYPE[DMT_STRING]) == 0) return DMT_STRING; - else if (strcmp(dm_str, DMT_TYPE[DMT_UNINT]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_UNINT]) == 0) return DMT_UNINT; - else if (strcmp(dm_str, DMT_TYPE[DMT_INT]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_INT]) == 0) return DMT_INT; - else if (strcmp(dm_str, DMT_TYPE[DMT_UNLONG]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_UNLONG]) == 0) return DMT_UNLONG; - else if (strcmp(dm_str, DMT_TYPE[DMT_LONG]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_LONG]) == 0) return DMT_LONG; - else if (strcmp(dm_str, DMT_TYPE[DMT_BOOL]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_BOOL]) == 0) return DMT_BOOL; - else if (strcmp(dm_str, DMT_TYPE[DMT_TIME]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_TIME]) == 0) return DMT_TIME; - else if (strcmp(dm_str, DMT_TYPE[DMT_HEXBIN]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_HEXBIN]) == 0) return DMT_HEXBIN; - else if (strcmp(dm_str, DMT_TYPE[DMT_BASE64]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_BASE64]) == 0) return DMT_BASE64; - else if (strcmp(dm_str, DMT_TYPE[DMT_COMMAND]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_COMMAND]) == 0) return DMT_COMMAND; - else if (strcmp(dm_str, DMT_TYPE[DMT_EVENT]) == 0) + else if (DM_STRCMP(dm_str, DMT_TYPE[DMT_EVENT]) == 0) return DMT_EVENT; else return DMT_STRING; diff --git a/dmdiagnostics.c b/dmdiagnostics.c index e03933a2..cd76033a 100644 --- a/dmdiagnostics.c +++ b/dmdiagnostics.c @@ -65,10 +65,10 @@ void set_diagnostics_interface_option(struct dmctx *ctx, char *sec_name, char *v { char *linker = NULL; - if (!value) + if (!value || *value == 0) return; - if (*value && strncmp(value, "Device.IP.Interface.", 20) != 0) + if (strncmp(value, "Device.IP.Interface.", 20) != 0) return; adm_entry_get_linker_value(ctx, value, &linker); @@ -226,7 +226,7 @@ const bool validate_sha1sum_value(const char *file_path, const char *checksum) for (int i = 0; i < SHA_DIGEST_LENGTH; i++) snprintf(&sha1_res[i * 2], sizeof(sha1_res) - (i * 2), "%02x", hash[i]); - if (strcmp(sha1_res, checksum) == 0) + if (DM_STRCMP(sha1_res, checksum) == 0) res = true; end: @@ -262,7 +262,7 @@ const bool validate_sha224sum_value(const char *file_path, const char *checksum) for (int i = 0; i < SHA224_DIGEST_LENGTH; i++) snprintf(&sha224_res[i * 2], sizeof(sha224_res) - (i * 2), "%02x", hash[i]); - if (strcmp(sha224_res, checksum) == 0) + if (DM_STRCMP(sha224_res, checksum) == 0) res = true; end: @@ -298,7 +298,7 @@ const bool validate_sha256sum_value(const char *file_path, const char *checksum) for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) snprintf(&sha256_res[i * 2], sizeof(sha256_res) - (i * 2), "%02x", hash[i]); - if (strcmp(sha256_res, checksum) == 0) + if (DM_STRCMP(sha256_res, checksum) == 0) res = true; end: @@ -334,7 +334,7 @@ const bool validate_sha384sum_value(const char *file_path, const char *checksum) for (int i = 0; i < SHA384_DIGEST_LENGTH; i++) snprintf(&sha384_res[i * 2], sizeof(sha384_res) - (i * 2), "%02x", hash[i]); - if (strcmp(sha384_res, checksum) == 0) + if (DM_STRCMP(sha384_res, checksum) == 0) res = true; end: @@ -370,7 +370,7 @@ const bool validate_sha512sum_value(const char *file_path, const char *checksum) for (int i = 0; i < SHA512_DIGEST_LENGTH; i++) snprintf(&sha512_res[i * 2], sizeof(sha512_res) - (i * 2), "%02x", hash[i]); - if (strcmp(sha512_res, checksum) == 0) + if (DM_STRCMP(sha512_res, checksum) == 0) res = true; end: @@ -566,7 +566,7 @@ static void activate_fw_images(char *start_time[]) { for (int i = 0; i < MAX_TIME_WINDOW && DM_STRLEN(start_time[i]); i++) { activate_timer[i].cb = launch_activate_iamge_cb; - uloop_timeout_set(&activate_timer[i], atoi(start_time[i]) * 1000); + uloop_timeout_set(&activate_timer[i], DM_STRTOL(start_time[i]) * 1000); } } @@ -680,7 +680,7 @@ static void http_download_per_packet(libtrace_packet_t *packet) diag_stats.test_bytes_received = strlen(nexthdr); val += strlen("Content-Length: "); pch = strtok_r(val, " \r\n\t", &pchr); - diag_stats.test_bytes_received += atoi(pch); + diag_stats.test_bytes_received += DM_STRTOL(pch); diag_stats.first_data = 1; return; } @@ -705,16 +705,16 @@ static void ftp_download_per_packet(libtrace_packet_t *packet) gmtime_r(&(ftp_download_ts.tv_sec), &ftp_download_lt); strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S", &ftp_download_lt); - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0) { + if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_SIZE_RESPONSE) && strncmp(nexthdr, FTP_SIZE_RESPONSE, strlen(FTP_SIZE_RESPONSE)) == 0) { char *val = strstr(nexthdr,"213"); char *pch, *pchr; val += strlen("213 "); pch =strtok_r(val, " \r\n\t", &pchr); - diag_stats.test_bytes_received = atoi(pch); + diag_stats.test_bytes_received = DM_STRTOL(pch); return; } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) { + if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) { diag_stats.ftp_syn = 1; return; } @@ -731,7 +731,7 @@ static void ftp_download_per_packet(libtrace_packet_t *packet) return; } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0) { + if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_RETR_REQUEST) && strncmp(nexthdr, FTP_RETR_REQUEST, strlen(FTP_RETR_REQUEST)) == 0) { snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_download_ts.tv_usec); return; } @@ -835,7 +835,7 @@ static void ftp_upload_per_packet(libtrace_packet_t *packet) if (get_tcp_flag_from_packet(packet, &tcp, tcp_flag, &nexthdr)) return; - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) { + if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_PASV_RESPONSE) && strncmp(nexthdr, FTP_PASV_RESPONSE, strlen(FTP_PASV_RESPONSE)) == 0) { diag_stats.ftp_syn = 1; return; } @@ -856,7 +856,7 @@ static void ftp_upload_per_packet(libtrace_packet_t *packet) return; } - if (strcmp(tcp_flag, "PSH ACK ") == 0 && strlen(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0) { + if (strcmp(tcp_flag, "PSH ACK ") == 0 && DM_STRLEN(nexthdr) > strlen(FTP_STOR_REQUEST) && strncmp(nexthdr, FTP_STOR_REQUEST, strlen(FTP_STOR_REQUEST)) == 0) { snprintf(diag_stats.romtime, sizeof(diag_stats.romtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec); return; } @@ -880,7 +880,7 @@ static void ftp_upload_per_packet(libtrace_packet_t *packet) return; } - if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && strlen(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) { + if ( (strcmp(tcp_flag, "PSH ACK ") == 0 || strcmp(tcp_flag, "FIN PSH ACK ") == 0) && DM_STRLEN(nexthdr) > strlen(FTP_TRANSFERT_COMPLETE) && strncmp(nexthdr, FTP_TRANSFERT_COMPLETE, strlen(FTP_TRANSFERT_COMPLETE)) == 0) { snprintf(diag_stats.eomtime, sizeof(diag_stats.eomtime), "%s.%06ldZ", s_now, (long) ftp_upload_ts.tv_usec); read_next = 0; return; @@ -947,11 +947,10 @@ static int extract_stats(char *dump_file, int proto, int diagnostic_type) static char *get_default_gateway_device(void) { - char *device = ""; - FILE *f = fopen(PROC_ROUTE, "r"); if (f != NULL) { char line[100] = {0}, *p = NULL, *c = NULL, *saveptr = NULL; + char *device = NULL; while(fgets(line, sizeof(line), f)) { p = strtok_r(line, " \t", &saveptr); @@ -962,9 +961,11 @@ static char *get_default_gateway_device(void) } } fclose(f); + + return device ? device : ""; } - return device; + return ""; } int start_upload_download_diagnostic(int diagnostic_type) @@ -980,10 +981,9 @@ int start_upload_download_diagnostic(int diagnostic_type) interface = get_diagnostics_option("upload", "interface"); } - if ((url[0] == '\0') || - (strncmp(url, HTTP_URI, strlen(HTTP_URI)) != 0 && + if (strncmp(url, HTTP_URI, strlen(HTTP_URI)) != 0 && strncmp(url, FTP_URI, strlen(FTP_URI)) != 0 && - strstr(url,"@") != NULL)) + strchr(url,'@') != NULL) return -1; device = (interface && *interface) ? get_device(interface) : get_default_gateway_device(); diff --git a/dmdynamicjson.c b/dmdynamicjson.c index 1f40ec74..096aab7c 100644 --- a/dmdynamicjson.c +++ b/dmdynamicjson.c @@ -196,7 +196,7 @@ static char *generate_path_without_instance(char *full_obj, bool is_obj) char *str = dm_dynamic_strdup(&json_memhead, full_obj); for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { - if (atoi(pch) == 0 && strcmp(pch, "{i}") != 0) { + if (DM_STRTOL(pch) == 0 && strcmp(pch, "{i}") != 0) { pos += snprintf(buf + pos, sizeof(buf) - pos, "%s.", pch); } } @@ -237,9 +237,9 @@ static json_object *get_requested_json_obj(json_object *json_obj, char *instance char *p = strchr(buf, '['); if (strcmp(p+1, "@index") == 0 || strcmp(p+1, "@i-1") == 0) { - idx_pos = instance ? atoi(instance)-1 : 1; + idx_pos = instance ? DM_STRTOL(instance)-1 : 1; } else { - idx_pos = atoi(p+1); + idx_pos = DM_STRTOL(p+1); } *p = 0; @@ -264,7 +264,7 @@ static int get_number_of_instances(char *refparam) DM_STRNCPY(buf_path, refparam, sizeof(buf_path)); for (pch = strtok_r(buf_path, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { - if (atoi(pch) != 0) + if (DM_STRTOL(pch) != 0) nbr_inst++; } @@ -310,10 +310,10 @@ static void resolve_all_symbols(struct dmctx *ctx, void *data, char *instance, c else if (strcmp(pch, "@Value") == 0) pos += snprintf(&new_key[pos], key_len - pos, "%s.", value); else if (strcmp(pch, (json_version == JSON_VERSION_1) ? "@index" : "@i-1") == 0) - pos += snprintf(&new_key[pos], key_len - pos, "%d.", instance ? atoi(instance)-1 : 1); + pos += snprintf(&new_key[pos], key_len - pos, "%ld.", instance ? DM_STRTOL(instance)-1 : 1); else if (strstr(pch, "@index-")) { char *p = strchr(pch, '-'); - int idx_pos = atoi(p + 1); + int idx_pos = DM_STRTOL(p + 1); if (idx_pos != 0 && nbr_instances - idx_pos >= 0) pos += snprintf(&new_key[pos], key_len - pos, "%s.", ctx->inst_buf[nbr_instances - idx_pos] ? ctx->inst_buf[nbr_instances - idx_pos] : ""); @@ -367,7 +367,7 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *obj = generate_path_without_instance(parent_node->current_object, true); list_for_each_entry(pobj, &json_list, list) { - if (strcmp(pobj->name, obj) == 0) { + if (DM_STRCMP(pobj->name, obj) == 0) { mapping_obj = pobj->data; json_version = pobj->json_version; break; @@ -481,7 +481,7 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc char *obj = generate_path_without_instance(refparam, true); list_for_each_entry(pobj, &json_list, list) { - if (strcmp(pobj->name, obj) == 0) { + if (DM_STRCMP(pobj->name, obj) == 0) { mapping_obj = pobj->data; json_version = pobj->json_version; break; @@ -540,7 +540,7 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta char *obj = generate_path_without_instance(refparam, true); list_for_each_entry(pobj, &json_list, list) { - if (strcmp(pobj->name, obj) == 0) { + if (DM_STRCMP(pobj->name, obj) == 0) { mapping_obj = pobj->data; json_version = pobj->json_version; break; @@ -633,7 +633,7 @@ static char *uci_get_value(json_object *mapping_obj, int json_version, char *ref dmasprintf(&value, "%s", section_name((struct uci_section *)data)); } else { char uci_type[32] = {0}; - snprintf(uci_type, sizeof(uci_type), "@%s[%d]", json_object_get_string(type), instance ? atoi(instance)-1 : 0); + snprintf(uci_type, sizeof(uci_type), "@%s[%ld]", json_object_get_string(type), instance ? DM_STRTOL(instance)-1 : 0); value = dmuci_get_value_by_path(json_object_get_string(path), json_object_get_string(file), uci_type, json_object_get_string(option_name)); } } else if (file && section_name && option_name) { @@ -811,7 +811,7 @@ static int getvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i char *obj = generate_path_without_instance(refparam, false); list_for_each_entry(pleaf, &json_list, list) { - if (strcmp(pleaf->name, obj) == 0) { + if (DM_STRCMP(pleaf->name, obj) == 0) { param_obj = pleaf->data; json_version = pleaf->json_version; break; @@ -868,7 +868,7 @@ static int getcommand_param(char *refparam, struct dmctx *ctx, void *data, char char *obj = generate_path_without_instance(refparam, false); list_for_each_entry(leaf, &json_list, list) { - if (strcmp(leaf->name, obj) == 0) { + if (DM_STRCMP(leaf->name, obj) == 0) { found = true; break; } @@ -891,7 +891,7 @@ static int setcommand_param(char *refparam, struct dmctx *ctx, void *data, char char *obj = generate_path_without_instance(refparam, false); list_for_each_entry(leaf_node, &json_list, list) { - if (strcmp(leaf_node->name, obj) == 0) { + if (DM_STRCMP(leaf_node->name, obj) == 0) { p_obj = leaf_node->data; json_version = leaf_node->json_version; break; @@ -926,7 +926,7 @@ static int getevent_param(char *refparam, struct dmctx *ctx, void *data, char *i char *obj = generate_path_without_instance(refparam, false); list_for_each_entry(leaf, &json_list, list) { - if (strcmp(leaf->name, obj) == 0) { + if (DM_STRCMP(leaf->name, obj) == 0) { found = true; break; } @@ -979,8 +979,8 @@ static int fill_string_arguments(struct json_object *json_obj, int *min_length, json_object_object_get_ex(range_obj, "min", &range_min); json_object_object_get_ex(range_obj, "max", &range_max); - *min_length = range_min ? atoi(json_object_get_string(range_min)) : -1; - *max_length = range_max ? atoi(json_object_get_string(range_max)) : -1; + *min_length = range_min ? DM_STRTOL(json_object_get_string(range_min)) : -1; + *max_length = range_max ? DM_STRTOL(json_object_get_string(range_max)) : -1; } json_object_object_get_ex(json_obj, "enumerations", &enum_obj); @@ -1088,7 +1088,7 @@ static int dm_validate_value(json_object *json_obj, char *value) return -1; json_object_object_get_ex(list_obj, "maxsize", &maxsize); - max_size = maxsize ? atoi(json_object_get_string(maxsize)) : -1; + max_size = maxsize ? DM_STRTOL(json_object_get_string(maxsize)) : -1; json_object_object_get_ex(list_obj, "item", &item_obj); if (item_obj) { @@ -1097,8 +1097,8 @@ static int dm_validate_value(json_object *json_obj, char *value) json_object_object_get_ex(item_obj, "min", &item_min); json_object_object_get_ex(item_obj, "max", &item_max); - min_item = item_min ? atoi(json_object_get_string(item_min)) : -1; - max_item = item_max ? atoi(json_object_get_string(item_max)) : -1; + min_item = item_min ? DM_STRTOL(json_object_get_string(item_min)) : -1; + max_item = item_max ? DM_STRTOL(json_object_get_string(item_max)) : -1; } if (strcmp(datatype, "unsignedInt") == 0 || @@ -1169,7 +1169,7 @@ static void uci_set_value(json_object *mapping_obj, int json_version, char *refp if (data && file && type && option_name) { char uci_type[32] = {0}; - snprintf(uci_type, sizeof(uci_type), "@%s[%d]", json_object_get_string(type), instance ? atoi(instance)-1 : 0); + snprintf(uci_type, sizeof(uci_type), "@%s[%ld]", json_object_get_string(type), instance ? DM_STRTOL(instance)-1 : 0); dmuci_set_value_by_path(json_object_get_string(path), json_object_get_string(file), uci_type, json_object_get_string(option_name), value); } else if (file && section_name && option_name) { dmuci_set_value_by_path(json_object_get_string(path), json_object_get_string(file), json_object_get_string(section_name), json_object_get_string(option_name), value); @@ -1265,7 +1265,7 @@ static int setvalue_param(char *refparam, struct dmctx *ctx, void *data, char *i char *obj = generate_path_without_instance(refparam, false); list_for_each_entry(pleaf, &json_list, list) { - if (strcmp(pleaf->name, obj) == 0) { + if (DM_STRCMP(pleaf->name, obj) == 0) { param_obj = pleaf->data; json_version = pleaf->json_version; break; diff --git a/dmdynamiclibrary.c b/dmdynamiclibrary.c index 46f42935..0119368e 100644 --- a/dmdynamiclibrary.c +++ b/dmdynamiclibrary.c @@ -129,7 +129,7 @@ static char *get_path_without_instance(char *path) res_path[0] = 0; for (pch = strtok_r(str, ".", &pchr); pch != NULL; pch = strtok_r(NULL, ".", &pchr)) { - if (atoi(pch) == 0 && strcmp(pch, "{i}") != 0) + if (DM_STRTOL(pch) == 0 && strcmp(pch, "{i}") != 0) pos += snprintf(&res_path[pos], sizeof(res_path) - pos, "%s%s", pch, (pchr != NULL && *pchr != '\0') ? "." : ""); } @@ -145,7 +145,7 @@ static int get_dynamic_operate_args(char *refparam, struct dmctx *ctx, void *dat char *operate_path = get_path_without_instance(refparam); list_for_each_entry(dyn_operate, &dynamic_operate_list, list) { - if (strcmp(dyn_operate->operate_path, operate_path) == 0) { + if (DM_STRCMP(dyn_operate->operate_path, operate_path) == 0) { operate_args = (operation_args *)dyn_operate->operate_args; break; } @@ -162,7 +162,7 @@ static int dynamic_operate_leaf(char *refparam, struct dmctx *ctx, void *data, c char *operate_path = get_path_without_instance(refparam); list_for_each_entry(dyn_operate, &dynamic_operate_list, list) { - if (strcmp(dyn_operate->operate_path, operate_path) == 0) { + if (DM_STRCMP(dyn_operate->operate_path, operate_path) == 0) { operate_func = (operation)dyn_operate->operate; break; } @@ -264,7 +264,7 @@ int load_library_dynamic_arrays(struct dmctx *ctx) dmfree(object_path); char *ret = strrchr(operate_path, '.'); - strncpy(parent_path, operate_path, ret - operate_path +1); + DM_STRNCPY(parent_path, operate_path, ret - operate_path + 2); bool obj_exists = operate_find_root_entry(ctx, parent_path, &dm_entryobj); if (obj_exists == false || !dm_entryobj) diff --git a/dmdynamicvendor.c b/dmdynamicvendor.c index 8ad7b222..9ff8010f 100644 --- a/dmdynamicvendor.c +++ b/dmdynamicvendor.c @@ -52,7 +52,7 @@ static void overwrite_param(DMOBJ *entryobj, DMLEAF *leaf) DMLEAF *entryleaf = entryobj->leaf; for (; (entryleaf && entryleaf->parameter); entryleaf++) { - if (strcmp(entryleaf->parameter, leaf->parameter) == 0) { + if (DM_STRCMP(entryleaf->parameter, leaf->parameter) == 0) { entryleaf->getvalue = leaf->getvalue; entryleaf->setvalue = leaf->setvalue; return; @@ -69,7 +69,7 @@ static void overwrite_obj(DMOBJ *entryobj, DMOBJ *dmobj) DMOBJ *entrynextobj = entryobj->nextobj; for (; (entrynextobj && entrynextobj->obj); entrynextobj++) { - if (strcmp(entrynextobj->obj, dmobj->obj) == 0) { + if (DM_STRCMP(entrynextobj->obj, dmobj->obj) == 0) { entrynextobj->addobj = dmobj->addobj; entrynextobj->delobj = dmobj->delobj; @@ -113,7 +113,7 @@ static void load_vendor_extension_arrays(struct dmctx *ctx) for (int j = 0; vendor_map_obj[j].vendor; j++) { - if (strcmp(vendor_map_obj[j].vendor, tokens[idx]) != 0) + if (DM_STRCMP(vendor_map_obj[j].vendor, tokens[idx]) != 0) continue; DM_MAP_OBJ *vendor_obj = vendor_map_obj[j].vendor_obj; @@ -185,7 +185,7 @@ static void load_vendor_extension_overwrite_arrays(struct dmctx *ctx) for (int j = 0; vendor_map_obj[j].vendor; j++) { - if (strcmp(vendor_map_obj[j].vendor, tokens[idx]) != 0) + if (DM_STRCMP(vendor_map_obj[j].vendor, tokens[idx]) != 0) continue; DM_MAP_OBJ *dynamic_overwrite_obj = vendor_map_obj[j].vendor_obj; @@ -234,8 +234,12 @@ static void exclude_param(struct dmctx *ctx, char *in_param) DMOBJ *entryobj = NULL; char obj_prefix[256] = {'\0'}; + if (in_param == NULL) + return; + char *ret = strrchr(in_param, '.'); - strncpy(obj_prefix, in_param, ret - in_param +1); + if (ret) + DM_STRNCPY(obj_prefix, in_param, ret - in_param + 2); bool obj_exists = find_root_entry(ctx, obj_prefix, &entryobj); @@ -273,14 +277,14 @@ static void load_vendor_extension_exclude_arrays(struct dmctx *ctx) for (int j = 0; vendor_map_exclude_obj[j].vendor; j++) { - if (strcmp(vendor_map_exclude_obj[j].vendor, tokens[idx]) != 0) + if (DM_STRCMP(vendor_map_exclude_obj[j].vendor, tokens[idx]) != 0) continue; char **dynamic_exclude_obj = vendor_map_exclude_obj[j].vendor_obj; for (; *dynamic_exclude_obj; dynamic_exclude_obj++) { - if ((*dynamic_exclude_obj)[strlen(*dynamic_exclude_obj) - 1] == '.') + if ((*dynamic_exclude_obj)[DM_STRLEN(*dynamic_exclude_obj) - 1] == '.') exclude_obj(ctx, *dynamic_exclude_obj); else exclude_param(ctx, *dynamic_exclude_obj); diff --git a/dmentry.c b/dmentry.c index bb82e70a..85d7ba01 100644 --- a/dmentry.c +++ b/dmentry.c @@ -210,11 +210,12 @@ int dm_ctx_clean_sub(struct dmctx *ctx) int dm_get_supported_dm(struct dmctx *ctx, char *path, bool first_level, schema_type_t schema_type) { int fault = 0; + int len = DM_STRLEN(path); // Load dynamic objects and parameters load_dynamic_arrays(ctx); - if (strlen(path) == 0) { + if (len == 0) { path = ""; } else { if (path[strlen(path) - 1] != '.') @@ -263,13 +264,13 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, ctx->stop = false; switch(cmd) { case CMD_GET_VALUE: - if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1) + if (ctx->in_param[0] == '.' && DM_STRLEN(ctx->in_param) == 1) fault = FAULT_9005; else fault = dm_entry_get_value(ctx); break; case CMD_GET_NAME: - if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1) + if (ctx->in_param[0] == '.' && DM_STRLEN(ctx->in_param) == 1) fault = FAULT_9005; else if (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0) fault = dm_entry_get_name(ctx); @@ -386,7 +387,7 @@ int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value) if (!param || param[0] == '\0') return 0; - snprintf(linker, sizeof(linker), "%s%c", param, (param[strlen(param) - 1] != '.') ? '.' : '\0'); + snprintf(linker, sizeof(linker), "%s%c", param, (param[DM_STRLEN(param) - 1] != '.') ? '.' : '\0'); dm_ctx_init_sub(&dmctx, ctx->instance_mode); dmctx.in_param = linker; @@ -408,7 +409,7 @@ int dm_entry_validate_allowed_objects(struct dmctx *ctx, char *value, char *obje for (; *objects; objects++) { - if (strncmp(value, *objects, strlen(*objects)) == 0) { + if (DM_STRNCMP(value, *objects, DM_STRLEN(*objects)) == 0) { char *linker = NULL; adm_entry_get_linker_value(ctx, value, &linker); @@ -541,15 +542,15 @@ static int check_stats_folder(bool json_path) if (json_path) { #ifdef BBFDM_ENABLE_JSON_PLUGIN - if (strcmp(buf, json_hash) != 0) { - strncpy(json_hash, buf, 64); + if (DM_STRCMP(buf, json_hash) != 0) { + DM_STRNCPY(json_hash, buf, sizeof(json_hash)); return 1; } #endif /* BBFDM_ENABLE_JSON_PLUGIN */ } else { #ifdef BBFDM_ENABLE_DOTSO_PLUGIN - if (strcmp(buf, library_hash) != 0) { - strncpy(library_hash, buf, 64); + if (DM_STRCMP(buf, library_hash) != 0) { + DM_STRNCPY(library_hash, buf, sizeof(library_hash)); return 1; } #endif /* BBFDM_ENABLE_DOTSO_PLUGIN */ diff --git a/dmtree/tr104/common.c b/dmtree/tr104/common.c index f2bb017f..7ecdf86e 100644 --- a/dmtree/tr104/common.c +++ b/dmtree/tr104/common.c @@ -22,6 +22,7 @@ struct codec_info supported_codecs[MAX_SUPPORTED_CODECS]; int codecs_num; LIST_HEAD(call_log_list); +static struct stat prev_stat = { 0 }; static int call_log_list_size = 0; int call_log_count = 0; @@ -99,11 +100,11 @@ static void convert_src_dst(char *src_or_dst, size_t buf_size) int inst; // Examples, "TELCHAN/5/2", "SIP/sip0-00000000", - if ((token = strstr(src_or_dst, TEL_LINE_PREFIX))) { - inst = atoi(token + strlen(TEL_LINE_PREFIX)) + 1; + if ((token = DM_STRSTR(src_or_dst, TEL_LINE_PREFIX))) { + inst = DM_STRTOL(token + DM_STRLEN(TEL_LINE_PREFIX)) + 1; snprintf(src_or_dst, buf_size, "Device.Services.VoiceService.1.CallControl.Line.%d", inst); - } else if ((token = strstr(src_or_dst, SIP_ACCOUNT_PREFIX))) { - inst = atoi(token + strlen(SIP_ACCOUNT_PREFIX)) + 1; + } else if ((token = DM_STRSTR(src_or_dst, SIP_ACCOUNT_PREFIX))) { + inst = DM_STRTOL(token + DM_STRLEN(SIP_ACCOUNT_PREFIX)) + 1; snprintf(src_or_dst, buf_size, "Device.Services.VoiceService.1.SIP.Client.%d", inst); } } @@ -120,7 +121,6 @@ int init_call_log(void) cdr.calling_num, cdr.called_num, cdr.start_time, end_time); \ continue; \ } - static struct stat prev_stat = { 0 }; struct stat cur_stat; int res = 0, i = 0, j = 0; struct call_log_entry *entry; @@ -187,284 +187,284 @@ int init_call_log(void) * "1598364701.4","" */ // calling number - token = strstr(line, SEPARATOR); + token = DM_STRSTR(line, SEPARATOR); CHECK_RESULT(token); token += SEPARATOR_SIZE; - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.calling_num, token, end - token); + DM_STRNCPY(cdr.calling_num, token, end - token + 1); // called number token = end + SEPARATOR_SIZE; - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.called_num, token, end - token); + DM_STRNCPY(cdr.called_num, token, end - token + 1); // source token = end + SEPARATOR_SIZE; // sip0 in the last example - token = strstr(token, SEPARATOR); + token = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(token); token += SEPARATOR_SIZE; // ""8001"" <8001> in the last example - token = strstr(token, SEPARATOR); + token = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(token); token += SEPARATOR_SIZE; // TELCHAN/5/1 in the last example - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.source, token, end - token); + DM_STRNCPY(cdr.source, token, end - token + 1); // destination token = end + SEPARATOR_SIZE; // SIP/sip0-00000001 in the last example - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.destination, token, end - token); + DM_STRNCPY(cdr.destination, token, end - token + 1); // start time and end time token = end + SEPARATOR_SIZE; // Dial in the last example - token = strstr(token, SEPARATOR); + token = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(token); token += SEPARATOR_SIZE; // SIP/7001@sip0,,gT in the last example - token = strstr(token, SEPARATOR); + token = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(token); token += SEPARATOR_SIZE; // The first date - end = strstr(token, "\",,\""); + end = DM_STRSTR(token, "\",,\""); if (end) { // Not answered, e.g. "2020-08-27 11:02:40",,"2020-08-27 11:02:40",21,11, - strncpy(cdr.start_time, token, end - token); + DM_STRNCPY(cdr.start_time, token, end - token + 1); token = end + 4; } else { // Answered, e.g. "2020-08-25 16:11:41","2020-08-25 16:11:50","2020-08-25 16:12:02",21,11, - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.start_time, token, end - token); - token = strstr(end + SEPARATOR_SIZE, SEPARATOR); // Skip the middle date and come to the last date + DM_STRNCPY(cdr.start_time, token, end - token + 1); + token = DM_STRSTR(end + SEPARATOR_SIZE, SEPARATOR); // Skip the middle date and come to the last date CHECK_RESULT(token); token += SEPARATOR_SIZE; } - end = strstr(token, "\","); + end = DM_STRSTR(token, "\","); CHECK_RESULT(end); - strncpy(end_time, token, end - token); + DM_STRNCPY(end_time, token, end - token + 1); // termination cause - token = strstr(end + 2, ",\""); // ANSWERED in the last example + token = DM_STRSTR(end + 2, ",\""); // ANSWERED in the last example CHECK_RESULT(token); token += 2; - end = strstr(token, SEPARATOR); + end = DM_STRSTR(token, SEPARATOR); CHECK_RESULT(end); - strncpy(cdr.termination_cause, token, end - token); + DM_STRNCPY(cdr.termination_cause, token, end - token + 1); // session id - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.sessionId, token, end - token); + DM_STRNCPY(cdr.sessionId, token, end - token + 1); // SIP IP Address - token = strstr(token, ",\""); + token = DM_STRSTR(token, ",\""); CHECK_RESULT(token); token += 2; - end = strstr(token, "\","); + end = DM_STRSTR(token, "\","); CHECK_RESULT(end); - strncpy(cdr.sipIpAddress, token, end - token); + DM_STRNCPY(cdr.sipIpAddress, token, end - token + 1); // Far End IP Address - token = strstr(token, ",\""); + token = DM_STRSTR(token, ",\""); CHECK_RESULT(token); token += 2; - end = strstr(token, "\","); + end = DM_STRSTR(token, "\","); CHECK_RESULT(end); - strncpy(cdr.farEndIPAddress, token, end - token); + DM_STRNCPY(cdr.farEndIPAddress, token, end - token + 1); // Sip Response Code - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.sipResponseCode, token, end - token); + DM_STRNCPY(cdr.sipResponseCode, token, end - token + 1); // Codec - token = strstr(token, ",\""); + token = DM_STRSTR(token, ",\""); CHECK_RESULT(token); token += 2; - end = strstr(token, "\","); + end = DM_STRSTR(token, "\","); CHECK_RESULT(end); - strncpy(cdr.codec, token, end - token); + DM_STRNCPY(cdr.codec, token, end - token + 1); // RTP statistic values - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localBurstDensity, token, end - token); + DM_STRNCPY(cdr.localBurstDensity, token, end - token + 1); // for incoming unanswered call cdr does not contain RTP stats if (strcasecmp(cdr.localBurstDensity, "\"DOCUMENTATION\"") == 0) { cdr.localBurstDensity[0] = '\0'; } else { - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteBurstDensity, token, end - token); + DM_STRNCPY(cdr.remoteBurstDensity, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localBurstDuration, token, end - token); + DM_STRNCPY(cdr.localBurstDuration, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteBurstDuration, token, end - token); + DM_STRNCPY(cdr.remoteBurstDuration, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localGapDensity, token, end - token); + DM_STRNCPY(cdr.localGapDensity, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteGapDensity, token, end - token); + DM_STRNCPY(cdr.remoteGapDensity, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localGapDuration, token, end - token); + DM_STRNCPY(cdr.localGapDuration, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteGapDuration, token, end - token); + DM_STRNCPY(cdr.remoteGapDuration, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localJbRate, token, end - token); + DM_STRNCPY(cdr.localJbRate, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteJbRate, token, end - token); + DM_STRNCPY(cdr.remoteJbRate, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localJbMax, token, end - token); + DM_STRNCPY(cdr.localJbMax, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteJbMax, token, end - token); + DM_STRNCPY(cdr.remoteJbMax, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localJbNominal, token, end - token); + DM_STRNCPY(cdr.localJbNominal, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteJbNominal, token, end - token); + DM_STRNCPY(cdr.remoteJbNominal, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.localJbAbsMax, token, end - token); + DM_STRNCPY(cdr.localJbAbsMax, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.remoteJbAbsMax, token, end - token); + DM_STRNCPY(cdr.remoteJbAbsMax, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.jbAvg, token, end - token); + DM_STRNCPY(cdr.jbAvg, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.uLossRate, token, end - token); + DM_STRNCPY(cdr.uLossRate, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.discarded, token, end - token); + DM_STRNCPY(cdr.discarded, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.lost, token, end - token); + DM_STRNCPY(cdr.lost, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.rxpkts, token, end - token); + DM_STRNCPY(cdr.rxpkts, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.txpkts, token, end - token); + DM_STRNCPY(cdr.txpkts, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.jitter, token, end - token); + DM_STRNCPY(cdr.jitter, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.maxJitter, token, end - token); + DM_STRNCPY(cdr.maxJitter, token, end - token + 1); - token = strstr(token, ","); + token = DM_STRSTR(token, ","); CHECK_RESULT(token); token += 1; - end = strstr(token, ","); + end = DM_STRSTR(token, ","); CHECK_RESULT(end); - strncpy(cdr.averageRoundTripDelay, token, end - token); + DM_STRNCPY(cdr.averageRoundTripDelay, token, end - token + 1); } // Skip invalid call logs if (cdr.calling_num[0] == '\0' || cdr.called_num[0] == '\0' || diff --git a/dmtree/tr104/servicesvoiceservicecallcontrol.c b/dmtree/tr104/servicesvoiceservicecallcontrol.c index 727bcf52..06521fb1 100644 --- a/dmtree/tr104/servicesvoiceservicecallcontrol.c +++ b/dmtree/tr104/servicesvoiceservicecallcontrol.c @@ -583,7 +583,7 @@ static int get_ServicesVoiceServiceCallControlLine_CallStatus(char *refparam, st json_object *res = NULL; char line_str[16]; - snprintf(line_str, sizeof(line_str), "%d", instance ? atoi(instance) - 1 : 0); + snprintf(line_str, sizeof(line_str), "%ld", instance ? DM_STRTOL(instance) - 1 : 0); dmubus_call("asterisk", "call_status", UBUS_ARGS{{"line", line_str, Integer}}, 1, &res); if (res) { *value = dmjson_get_value(res, 1, "call_status"); @@ -924,7 +924,7 @@ static int get_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type); dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "provider", &provider_string); - if (strlen(provider_string)) { + if (DM_STRLEN(provider_string)) { unsigned pos = 0; char *ptr = NULL, *spch = NULL; buf[0] = 0; @@ -933,7 +933,7 @@ static int get_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, while (ptr != NULL) { char *linker = NULL; - adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", !strcmp(type, "fxs") ? section_name(((struct dmmap_dup *)data)->config_section) : ptr, &linker); + adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", !DM_STRCMP(type, "fxs") ? section_name(((struct dmmap_dup *)data)->config_section) : ptr, &linker); if (linker && *linker) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s,", linker); @@ -952,8 +952,8 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, { char fxs_extension[64] = "Device.Services.VoiceService.1.POTS.FXS."; char dect_extension[64] = "Device.Services.VoiceService.1.DECT.Portable."; - size_t fxs_len = strlen(fxs_extension); - size_t dect_len = strlen(dect_extension); + size_t fxs_len = DM_STRLEN(fxs_extension); + size_t dect_len = DM_STRLEN(dect_extension); char *pch = NULL, *spch = NULL; char value_buf[512] = {0}; char *type; @@ -975,7 +975,7 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, for (pch = strtok_r(value_buf, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { char *linker = NULL; - if (strncmp(pch, !strcmp(type, "fxs") ? fxs_extension : dect_extension, !strcmp(type, "fxs") ? fxs_len : dect_len) != 0) + if (strncmp(pch, !DM_STRCMP(type, "fxs") ? fxs_extension : dect_extension, !DM_STRCMP(type, "fxs") ? fxs_len : dect_len) != 0) return FAULT_9007; adm_entry_get_linker_value(ctx, pch, &linker); @@ -993,9 +993,9 @@ static int set_ServicesVoiceServiceCallControlExtension_Provider(char *refparam, pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", ","); adm_entry_get_linker_value(ctx, pch, &linker); - if(!strcmp(linker, "extension3")) + if(!DM_STRCMP(linker, "extension3")) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs1"); - else if(!strcmp(linker, "extension4")) + else if(!DM_STRCMP(linker, "extension4")) pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", "fxs2"); else pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s", linker); @@ -1069,7 +1069,7 @@ static int get_ServicesVoiceServiceCallControlExtension_CallStatus(char *refpara json_object *res = NULL; char ext_str[16]; - snprintf(ext_str, sizeof(ext_str), "%d", instance ? atoi(instance) - 1 : 0); + snprintf(ext_str, sizeof(ext_str), "%ld", instance ? DM_STRTOL(instance) - 1 : 0); dmubus_call("asterisk", "call_status", UBUS_ARGS{{"extension", ext_str, Integer}}, 1, &res); if (res) { *value = dmjson_get_value(res, 1, "call_status"); diff --git a/dmtree/tr104/servicesvoiceservicecapabilities.c b/dmtree/tr104/servicesvoiceservicecapabilities.c index c07e92d1..7340dfb3 100644 --- a/dmtree/tr104/servicesvoiceservicecapabilities.c +++ b/dmtree/tr104/servicesvoiceservicecapabilities.c @@ -63,7 +63,7 @@ static int get_ServicesVoiceServiceCapabilities_MaxSessionCount(char *refparam, db_get_value_string("hw", "board", "VoicePorts", &max_line); if (max_line && *max_line) { - int max_session = 2 * atoi(max_line); + int max_session = 2 * DM_STRTOL(max_line); dmasprintf(value, "%d", max_session); } else *value = "-1"; diff --git a/dmtree/tr104/servicesvoiceservicedect.c b/dmtree/tr104/servicesvoiceservicedect.c index 69803ad0..9fa52d4d 100644 --- a/dmtree/tr104/servicesvoiceservicedect.c +++ b/dmtree/tr104/servicesvoiceservicedect.c @@ -58,7 +58,7 @@ static int browseServicesVoiceServiceDECTPortableInst(struct dmctx *dmctx, DMNOD /* Use the id from the UBUS call if it is found */ if (str_id && *str_id) { - id = atoi(str_id); + id = DM_STRTOL(str_id); } else { id++; } diff --git a/dmtree/tr104/servicesvoiceservicesip.c b/dmtree/tr104/servicesvoiceservicesip.c index b3649fd0..bb9ef3b5 100644 --- a/dmtree/tr104/servicesvoiceservicesip.c +++ b/dmtree/tr104/servicesvoiceservicesip.c @@ -288,7 +288,7 @@ static int set_ServicesVoiceServiceSIPClient_RegisterURI(char *refparam, struct return FAULT_9007; break; case VALUESET: - value_domain = strchr(value, '@'); + value_domain = DM_STRCHR(value, '@'); if (value_domain) { value_domain++; value_user = dmstrdup(value); @@ -362,12 +362,12 @@ static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, s dmuci_get_option_value_string(TR104_UCI_PACKAGE, "sip_options", "defaultexpiry", &period_str); if (period_str && *period_str) { - period = atoi(period_str); + period = DM_STRTOL(period_str); dmfree(period_str); } if (period <= 0) { BBF_DEBUG("Use default registration expires\n"); - period = atoi(DEFAULT_SIP_REGISTER_EXPIRY_STR); + period = DM_STRTOL(DEFAULT_SIP_REGISTER_EXPIRY_STR); } time_expires = time_last + period; @@ -445,7 +445,7 @@ static int get_server_address(struct uci_section *section, char *option, char ** { dmuci_get_value_by_section_string(section, option, value); if (*value && **value) { - char *port = strchr(*value, ':'); + char *port = DM_STRCHR(*value, ':'); if (port) { char *server = dmstrdup(*value); if (server) { @@ -464,7 +464,7 @@ static int set_server_address(struct uci_section *section, char *option, char *v char *old_value = NULL; dmuci_get_value_by_section_string(section, option, &old_value); - char *port = (old_value && *old_value) ? strchr(old_value, ':') : NULL; + char *port = (old_value && *old_value) ? DM_STRCHR(old_value, ':') : NULL; if (port) { char new_value[32] = {0}; @@ -487,7 +487,7 @@ static int get_server_port(struct uci_section *section, char *option, char **val dmuci_get_value_by_section_string(section, option, &domain); if (domain && *domain) { - port = strchr(domain, ':'); + port = DM_STRCHR(domain, ':'); if (port) port++; } @@ -505,7 +505,7 @@ static int set_server_port(struct uci_section *section, char *option, char *valu char *old_value = NULL, new_value[32] = {0}; dmuci_get_value_by_section_string(section, option, &old_value); - char *tmp = old_value ? strchr(old_value, ':') : NULL; + char *tmp = old_value ? DM_STRCHR(old_value, ':') : NULL; if (tmp) *tmp = '\0'; @@ -910,7 +910,7 @@ static int set_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("asterisk", "sip_options", "srvlookup", value); - *value = (strcmp(*value, "yes") == 0) ? "1" : "0"; + *value = (DM_STRCMP(*value, "yes") == 0) ? "1" : "0"; return 0; } diff --git a/dmtree/tr143/diagnostics.c b/dmtree/tr143/diagnostics.c index 0e5b3549..9ef0e29e 100644 --- a/dmtree/tr143/diagnostics.c +++ b/dmtree/tr143/diagnostics.c @@ -44,7 +44,7 @@ static int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { IPPING_STOP set_diagnostics_option("ipping", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_IPPING_DIAGNOSTIC); @@ -281,7 +281,7 @@ static int set_IPDiagnosticsTraceRoute_DiagnosticsState(char *refparam, struct d return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { TRACEROUTE_STOP set_diagnostics_option("traceroute", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_TRACEROUTE_DIAGNOSTIC); @@ -528,7 +528,7 @@ static int set_IPDiagnosticsDownloadDiagnostics_DiagnosticsState(char *refparam, return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { DOWNLOAD_DIAGNOSTIC_STOP set_diagnostics_option("download", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_DOWNLOAD_DIAGNOSTIC); @@ -858,7 +858,7 @@ static int set_IPDiagnosticsUploadDiagnostics_DiagnosticsState(char *refparam, s return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { UPLOAD_DIAGNOSTIC_STOP set_diagnostics_option("upload", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_UPLOAD_DIAGNOSTIC); @@ -1205,7 +1205,7 @@ static int set_IPDiagnosticsUDPEchoDiagnostics_DiagnosticsState(char *refparam, return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { UDPECHO_STOP; set_diagnostics_option("udpechodiag", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_UDPECHO_DIAGNOSTIC); @@ -1468,7 +1468,7 @@ static int set_IPDiagnosticsServerSelectionDiagnostics_DiagnosticsState(char *re return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { SERVERSELECTION_STOP set_diagnostics_option("serverselection", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_SERVERSELECTION_DIAGNOSTIC); @@ -2181,7 +2181,7 @@ static int operate_IPDiagnostics_ServerSelectionDiagnostics(char *refparam, stru char *port = dmjson_get_value((json_object *)value, 1, "Port"); char *proto = dmjson_get_value((json_object *)value, 1, "Protocol"); - if (strcmp(proto, "ICMP") && port[0] == '\0') + if (DM_STRCMP(proto, "ICMP") && port[0] == '\0') return CMD_INVALID_ARGUMENTS; char *protocol_version = dmjson_get_value((json_object *)value, 1, "ProtocolVersion"); diff --git a/dmtree/tr181/atm.c b/dmtree/tr181/atm.c index 2e9566e6..b8347a13 100644 --- a/dmtree/tr181/atm.c +++ b/dmtree/tr181/atm.c @@ -51,7 +51,7 @@ void remove_device_from_interface(struct uci_section *interface_s, char *device) new_device[0] = '\0'; for (pch = strtok_r(curr_device, " ", &spch); pch; pch = strtok_r(NULL, " ", &spch)) { - if (strcmp(pch, device) == 0) + if (DM_STRCMP(pch, device) == 0) continue; pos += snprintf(&new_device[pos], sizeof(new_device) - pos, "%s ", pch); @@ -203,7 +203,7 @@ static int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "encapsulation", &encapsulation); - *value = (strcmp(encapsulation, "vcmux") == 0) ? "VCMUX" : "LLC"; + *value = (DM_STRCMP(encapsulation, "vcmux") == 0) ? "VCMUX" : "LLC"; return 0; } @@ -215,7 +215,7 @@ static int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, return FAULT_9007; return 0; case VALUESET: - dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "encapsulation", (strcmp(value, "LLC") == 0) ? "llc" : "vcmux"); + dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "encapsulation", (DM_STRCMP(value, "LLC") == 0) ? "llc" : "vcmux"); return 0; } return 0; @@ -227,13 +227,13 @@ static int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char char *link_type; dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "link_type", &link_type); - if (strcmp(link_type, "eoa") == 0) + if (DM_STRCMP(link_type, "eoa") == 0) *value = "EoA"; - else if (strcmp(link_type, "ipoa") == 0) + else if (DM_STRCMP(link_type, "ipoa") == 0) *value = "IPoA"; - else if (strcmp(link_type, "pppoa") == 0) + else if (DM_STRCMP(link_type, "pppoa") == 0) *value = "PPPoA"; - else if (strcmp(link_type, "cip") == 0) + else if (DM_STRCMP(link_type, "cip") == 0) *value = "CIP"; else *value = "Unconfigured"; @@ -248,13 +248,13 @@ static int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "EoA") == 0) + if (DM_STRCMP(value, "EoA") == 0) dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "eoa"); - else if (strcmp(value, "IPoA") == 0) + else if (DM_STRCMP(value, "IPoA") == 0) dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "ipoa"); - else if (strcmp(value, "PPPoA") == 0) + else if (DM_STRCMP(value, "PPPoA") == 0) dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "pppoa"); - else if (strcmp(value, "CIP") == 0) + else if (DM_STRCMP(value, "CIP") == 0) dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "cip"); else dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", ""); @@ -273,7 +273,7 @@ static int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch if (*value != NULL && (*value)[0] != '\0') return 0; - snprintf(atm_file, sizeof(atm_file), "/sys/class/net/atm%d", atoi(instance) - 1); + snprintf(atm_file, sizeof(atm_file), "/sys/class/net/atm%ld", DM_STRTOL(instance) - 1); if (folder_exists(atm_file)) { *value = "Device.DSL.Channel.1"; dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "atm_ll_link", "dsl_channel_1"); @@ -285,7 +285,7 @@ static int set_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch { switch (action) { case VALUECHECK: - if (strncmp(value, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0) + if (DM_STRNCMP(value, "Device.DSL.Channel.1", DM_STRLEN("Device.DSL.Channel.1")) != 0) return FAULT_9007; break; case VALUESET: diff --git a/dmtree/tr181/bridging.c b/dmtree/tr181/bridging.c index 214b3e94..98b61695 100644 --- a/dmtree/tr181/bridging.c +++ b/dmtree/tr181/bridging.c @@ -183,8 +183,8 @@ void bridging_get_vlan_tvid(char *uci_opt_name, void *data, char **value) void bridging_set_vlan_tvid(char *uci_opt_name, void *data, char *value) { - dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_sec, uci_opt_name, !strcmp(value, "0") ? "" : value); - dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, uci_opt_name, !strcmp(value, "0") ? "" : value); + dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_sec, uci_opt_name, !DM_STRCMP(value, "0") ? "" : value); + dmuci_set_value_by_section(((struct bridge_vlan_args *)data)->bridge_vlan_sec, uci_opt_name, !DM_STRCMP(value, "0") ? "" : value); } static void bridge_remove_related_device_section(struct uci_list *br_ports_list) @@ -213,7 +213,7 @@ static int get_last_inst(char *config, char *section, char *option1, char *optio dmuci_get_value_by_section_string(s, option2, &tmp); if (tmp[0] == '\0') continue; - instance = atoi(tmp); + instance = DM_STRTOL(tmp); if (instance > max) max = instance; } return max; @@ -270,8 +270,8 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi bool found = false; // Get candidate bridge instance - if (value[strlen(value) - 1] == '.') - value[strlen(value) - 1] = 0; + if (value[DM_STRLEN(value) - 1] == '.') + value[DM_STRLEN(value) - 1] = 0; char *br_inst = strrchr(value, '.'); @@ -293,11 +293,11 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi } } - if (strcmp(component, "CVLAN") == 0) { + if (DM_STRCMP(component, "CVLAN") == 0) { // Set svlan_br_inst in dmmap_provider_bridge->provider_bridge section dmuci_add_list_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "cvlan_br_inst", br_inst ? br_inst+1 : ""); - } else if (strcmp(component, "SVLAN") == 0) { + } else if (DM_STRCMP(component, "SVLAN") == 0) { // Set svlan_br_inst in dmmap_provider_bridgei->provider_bridge section dmuci_set_value_by_section(((struct provider_bridge_args *)data)->provider_bridge_sec, "svlan_br_inst", br_inst ? br_inst+1 : ""); @@ -308,7 +308,7 @@ static void set_Provider_bridge_component(char *refparam, struct dmctx *ctx, voi char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) + if (management && DM_STRCMP(management, "1") == 0) dmmap_bridge_section = s;// later used to find network->device(bridge) section name dmuci_set_value_by_section(s, "provider_br_inst", instance); } @@ -418,7 +418,7 @@ static bool is_bridge_section_exist(char *device) continue; uci_foreach_element(ports_list, e) { - if (strcmp(e->name, device) == 0) + if (DM_STRCMP(e->name, device) == 0) return true; } } @@ -434,8 +434,8 @@ static int get_last_instance_bridge(char *package, char *section, char *opt_inst char *opt_val = NULL; dmuci_get_value_by_section_string(s, opt_inst, &opt_val); - if (opt_val && *opt_val != '\0' && atoi(opt_val) > inst) - inst = atoi(opt_val); + if (opt_val && *opt_val != '\0' && DM_STRTOL(opt_val) > inst) + inst = DM_STRTOL(opt_val); } return inst; @@ -496,7 +496,7 @@ static void dmmap_synchronizeBridgingProviderBridge(struct dmctx *dmctx, DMNODE dmuci_get_value_by_section_string(ss, "type", &type); // If type is 8021ad, add to svlan - if (type && strcmp(type,"8021ad") == 0 && !is_bridge_section_exist(e->name)) { + if (type && DM_STRCMP(type,"8021ad") == 0 && !is_bridge_section_exist(e->name)) { // Create device bridge dmmap section char *svlan_br_inst = create_dmmap_bridge_section(e->name); @@ -506,7 +506,7 @@ static void dmmap_synchronizeBridgingProviderBridge(struct dmctx *dmctx, DMNODE } // If type is 8021q, add to cvlan - if (type && strcmp(type,"8021q") == 0 && !is_bridge_section_exist(e->name)) { + if (type && DM_STRCMP(type,"8021q") == 0 && !is_bridge_section_exist(e->name)) { // Create device bridge dmmap section char *cvlan_br_inst = create_dmmap_bridge_section(e->name); @@ -528,7 +528,7 @@ static bool is_bridge_vlan_exist(char *br_inst, char *vid) char *s_vid = NULL; dmuci_get_value_by_section_string(s, "vid", &s_vid); - if (s_vid && strcmp(s_vid, vid) == 0) + if (s_vid && DM_STRCMP(s_vid, vid) == 0) return true; } return false; @@ -548,7 +548,7 @@ static void dmmap_synchronizeBridgingBridgeVLAN(struct dmctx *dmctx, DMNODE *par // 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) + if (s_user && DM_STRCMP(s_user, "1") == 0) continue; // vid is available in ports list ==> skip it @@ -556,7 +556,7 @@ static void dmmap_synchronizeBridgingBridgeVLAN(struct dmctx *dmctx, DMNODE *par bool vid_found = false; dmuci_get_value_by_section_string(s, "vid", &vid); uci_foreach_element(br_args->br_ports_list, e) { - if (vid && strstr(e->name, vid)) { + if (vid && DM_STRSTR(e->name, vid)) { vid_found = true; break; } @@ -577,7 +577,7 @@ static void dmmap_synchronizeBridgingBridgeVLAN(struct dmctx *dmctx, DMNODE *par dmuci_get_value_by_section_string(s, "vid", &vid); if (vid && vid[0] == '\0') { - char *ifname = strchr(e->name, '.'); + char *ifname = DM_STRCHR(e->name, '.'); if (ifname) vid = dmstrdup(ifname+1); } @@ -603,7 +603,7 @@ static bool is_bridge_vlanport_exist(char *br_inst, char *name) char *s_name = NULL; dmuci_get_value_by_section_string(s, "name", &s_name); - if (strcmp(s_name, name) == 0) + if (DM_STRCMP(s_name, name) == 0) return true; } return false; @@ -633,7 +633,7 @@ static void dmmap_synchronizeBridgingBridgeVLANPort(struct dmctx *dmctx, DMNODE // 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) + if (s_user && DM_STRCMP(s_user, "1") == 0) continue; // port device is available in ports list ==> skip it @@ -677,7 +677,7 @@ static int is_bridge_pr_br_member(char *br_inst, char **pr_br_inst) // Check if the passed bridge section is svlan dmuci_get_value_by_section_string(pr_br_sec, "svlan_br_inst", &svlan); - if (svlan && br_inst && strcmp(svlan, br_inst) == 0) { + if (svlan && br_inst && DM_STRCMP(svlan, br_inst) == 0) { // Get provider bridge instance dmuci_get_value_by_section_string(pr_br_sec, "provider_bridge_instance", pr_br_inst); return true; @@ -689,7 +689,7 @@ static int is_bridge_pr_br_member(char *br_inst, char **pr_br_inst) struct uci_element *e = NULL; uci_foreach_element(cvlan_list, e) { - if (br_inst && strcmp(e->name, br_inst) == 0) { + if (br_inst && DM_STRCMP(e->name, br_inst) == 0) { // Get provider bridge instance dmuci_get_value_by_section_string(pr_br_sec, "provider_bridge_instance", pr_br_inst); return true; @@ -708,7 +708,7 @@ static bool is_bridge_port_exist(char *br_inst, char *port, struct uci_section * char *curr_port = NULL; dmuci_get_value_by_section_string(s, "port", &curr_port); - if (curr_port && strcmp(curr_port, port) == 0) { + if (curr_port && DM_STRCMP(curr_port, port) == 0) { *dmmap_br_port = s; return true; } @@ -724,7 +724,7 @@ static bool is_bridge_management_port_exist(char *br_inst) char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) + if (management && DM_STRCMP(management, "1") == 0) return true; } return false; @@ -751,7 +751,7 @@ static bool is_wireless_ifname_exist(char *dev_sec_name, char *ifname) char *curr_ifname = NULL; dmuci_get_value_by_section_string(s, "ifname", &curr_ifname); - if (curr_ifname && strcmp(curr_ifname, ifname) == 0) + if (curr_ifname && DM_STRCMP(curr_ifname, ifname) == 0) return true; } return false; @@ -765,7 +765,7 @@ static void update_bridge_management_port(char *br_inst, char *linker) char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { dmuci_set_value_by_section(s, "port", linker); return; } @@ -809,13 +809,13 @@ static void dmmap_synchronizeBridgingBridgePort(struct dmctx *dmctx, DMNODE *par // section added by user ==> skip it dmuci_get_value_by_section_string(s, "added_by_user", &s_user); - if (s_user && strcmp(s_user, "1") == 0) + if (s_user && DM_STRCMP(s_user, "1") == 0) continue; // section for management ==> skip it char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) + if (management && DM_STRCMP(management, "1") == 0) continue; // port device is available in ports list ==> skip it @@ -835,7 +835,7 @@ static void dmmap_synchronizeBridgingBridgePort(struct dmctx *dmctx, DMNODE *par // section added by user ==> skip it get_dmmap_section_of_config_section("dmmap_bridge", "device", br_args->bridge_sec_name, &s); dmuci_get_value_by_section_string(s, "added_by_user", &s_user); - if (s_user && strcmp(s_user, "1") != 0 && !is_bridge_management_port_exist(br_args->br_inst)) + if (s_user && DM_STRCMP(s_user, "1") != 0 && !is_bridge_management_port_exist(br_args->br_inst)) create_new_bridge_port_section("network", "", br_args->br_inst, dev_name, br_args->bridge_sec_name, "1"); linker_buf[0] = 0; @@ -878,7 +878,7 @@ end: linker_buf[pos - 1] = 0; // Update the device linker for management port if it is not added by user - if (s_user && strcmp(s_user, "1") != 0) + if (s_user && DM_STRCMP(s_user, "1") != 0) update_bridge_management_port(br_args->br_inst, linker_buf); } @@ -951,9 +951,9 @@ static void remove_vlanid_from_ifname_list(struct uci_section *bridge_sec, char return; uci_foreach_element(device_ports, e) { - char *vid = strchr(e->name, '.'); + char *vid = DM_STRCHR(e->name, '.'); - if (vid && strcmp(vid+1, curr_vid) == 0) { + if (vid && DM_STRCMP(vid+1, curr_vid) == 0) { // Update port section if vid != 0 struct uci_section *port_s = NULL; @@ -962,7 +962,7 @@ static void remove_vlanid_from_ifname_list(struct uci_section *bridge_sec, char // Get device from dmmap section dmuci_get_value_by_section_string(port_s, "port", &device); - if (device && strcmp(device, e->name) == 0) { + if (device && DM_STRCMP(device, e->name) == 0) { // Remove vid from device vid[0] = '\0'; // Update device in dmmap @@ -986,7 +986,7 @@ static int set_lowerlayers_management_port(struct dmctx *ctx, void *data, char * snprintf(lower_layer_path, sizeof(lower_layer_path), "Device.Bridging.Bridge.%s.Port.", ((struct bridge_port_args *)data)->br_inst); - if (strncmp(pch, lower_layer_path, strlen(lower_layer_path)) == 0) { + if (DM_STRNCMP(pch, lower_layer_path, DM_STRLEN(lower_layer_path)) == 0) { /* check linker is available */ char *linker = NULL; adm_entry_get_linker_value(ctx, pch, &linker); @@ -1014,7 +1014,7 @@ static void update_device_management_port(char *old_name, char *new_name, char * char *management = NULL, *port = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "0") == 0) + if (management && DM_STRCMP(management, "0") == 0) continue; dmuci_get_value_by_section_string(s, "port", &port); @@ -1024,10 +1024,10 @@ static void update_device_management_port(char *old_name, char *new_name, char * new_port[0] = 0; for (pch = strtok_r(port, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { - if (!strstr(pch, old_name)) { + if (!DM_STRSTR(pch, old_name)) { pos += snprintf(&new_port[pos], sizeof(new_port) - pos, "%s,", pch); } else { - char *sec = strchr(pch, '+'); + char *sec = DM_STRCHR(pch, '+'); if (sec) sec[0] = '\0'; pos += snprintf(&new_port[pos], sizeof(new_port) - pos, "%s+%s,", pch, new_name); } @@ -1052,7 +1052,7 @@ static void remove_device_from_management_port(const struct bridge_port_args *da char *management = NULL, *port_linker = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "0") == 0) + if (management && DM_STRCMP(management, "0") == 0) continue; dmuci_get_value_by_section_string(s, "port", &port_linker); @@ -1063,7 +1063,7 @@ static void remove_device_from_management_port(const struct bridge_port_args *da new_port[0] = 0; for (pch = strtok_r(port_linker, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) { - if (strcmp(pch, curr_linker) == 0) + if (DM_STRCMP(pch, curr_linker) == 0) continue; pos += snprintf(&new_port[pos], sizeof(new_port) - pos, "%s,", pch); @@ -1130,7 +1130,7 @@ static void remove_vlanid_from_device_and_vlanport(char *vid) dmuci_get_value_by_section_string(s, "name", &name); uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlanport", "bridge_vlanport", "name", name, port_s) { - char *curr_vid = strchr(name, '.'); + char *curr_vid = DM_STRCHR(name, '.'); if (curr_vid) curr_vid[0] = '\0'; dmuci_set_value_by_section(port_s, "name", name); } @@ -1163,7 +1163,7 @@ static void remove_vlanport_section(struct uci_section *vlanport_dmmap_sec, stru dmuci_get_value_by_section_string(s, "port", &port); DM_STRNCPY(curr_port, port, sizeof(curr_port)); - char *vid = port ? strchr(port, '.') : NULL; + char *vid = port ? DM_STRCHR(port, '.') : NULL; if (vid) { // network: Remove curr port from ports list of bridge section remove_port_from_bridge_section(bridge_sec, curr_port); @@ -1218,8 +1218,8 @@ static char *fetch_and_configure_inner_vid(char *br_inst, char *type_val, char * } //Check if the bridge instances are same or not, if yes, then get the vid. - if (instance && br_inst && strcmp(br_inst, instance) == 0) { - if (type_val && strcmp(type_val, "8021ad") == 0) + if (instance && br_inst && DM_STRCMP(br_inst, instance) == 0) { + if (type_val && DM_STRCMP(type_val, "8021ad") == 0) dmuci_set_value_by_section(dev_s, "inner_vid", vid); else dmuci_get_value_by_section_string(dev_s, "vid", &cur_vid); @@ -1265,7 +1265,7 @@ static int configure_device_type(const struct bridge_port_args *data, char *type dmuci_set_value_by_section(data->bridge_port_sec, "type", type_value); - if (strncmp(type_value, "8021q", 5) == 0) { + if (DM_STRNCMP(type_value, "8021q", 5) == 0) { //Check if the device has inner-vid if so then delete uci_foreach_sections("network", "device", s) { @@ -1290,7 +1290,7 @@ static int configure_device_type(const struct bridge_port_args *data, char *type if (vid != NULL && vid[0] != '\0') fetch_and_configure_inner_vid(data->br_inst, "8021ad", vid); - } else if (strncmp(type_value, "8021ad", 6) == 0) { + } else if (DM_STRNCMP(type_value, "8021ad", 6) == 0) { char *cur_vid = NULL; cur_vid = fetch_and_configure_inner_vid(data->br_inst, "8021q", ""); @@ -1316,7 +1316,7 @@ static void restore_bridge_config(char *vlan_br_inst) char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { dmmap_br_sec = s; break; } @@ -1439,7 +1439,7 @@ void static get_rem_pr_br_instance(struct uci_section *pr_br_sec, char *bridge_i char *management = NULL; dmuci_get_value_by_section_string(s, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { dmmap_br_port_sec = s; break; } @@ -1467,7 +1467,7 @@ void static get_rem_pr_br_instance(struct uci_section *pr_br_sec, char *bridge_i /* traverse each list value and delete all bridge section */ ptr = new_ifname; uci_foreach_element(ports_list, e) { - if (strstr(ifname, e->name)) + if (DM_STRSTR(ifname, e->name)) continue; dmstrappendstr(ptr, e->name); @@ -1502,7 +1502,7 @@ void remove_bridge_from_provider_bridge(char *bridge_inst) // Check if the passed bridge section is svlan dmuci_get_value_by_section_string(pr_br_sec, "svlan_br_inst", &svlan); - if (svlan && strcmp(svlan, bridge_inst) == 0) { + if (svlan && DM_STRCMP(svlan, bridge_inst) == 0) { restore_bridge_config(svlan); dmuci_set_value_by_section(pr_br_sec, "svlan_br_inst", ""); get_rem_pr_br_instance(pr_br_sec, bridge_inst); @@ -1514,7 +1514,7 @@ void remove_bridge_from_provider_bridge(char *bridge_inst) struct uci_element *e = NULL; uci_foreach_element(cvlan_list, e) { - if (strcmp(e->name, bridge_inst) == 0) { + if (DM_STRCMP(e->name, bridge_inst) == 0) { restore_bridge_config(bridge_inst); dmuci_del_list_value_by_section(pr_br_sec, "cvlan_br_inst", bridge_inst); get_rem_pr_br_instance(pr_br_sec, bridge_inst); @@ -1593,7 +1593,7 @@ static int delObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, c dmuci_get_value_by_section_string(s, "proto", &proto); dmuci_get_value_by_section_string(s, "device", &device); - if (device && strcmp(device, curr_device) == 0) { + if (device && DM_STRCMP(device, curr_device) == 0) { dmuci_delete_by_section(s, (proto && *proto == 0) ? NULL : "device", NULL); break; } @@ -1641,7 +1641,7 @@ static int delObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, c dmuci_get_value_by_section_string(ss, "proto", &proto); dmuci_get_value_by_section_string(ss, "device", &device); - if (device && strcmp(device, curr_device) == 0) { + if (device && DM_STRCMP(device, curr_device) == 0) { dmuci_delete_by_section(ss, (proto && *proto == 0) ? NULL : "device", NULL); break; } @@ -1692,7 +1692,7 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "port", &port); dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); - if ((port && port[0] == '\0') || (management && strcmp(management, "1") == 0)) { + if ((port && port[0] == '\0') || (management && DM_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 if (port && *port) { @@ -1734,7 +1734,7 @@ static int delObjBridgingBridgePort(char *refparam, struct dmctx *ctx, void *dat dmuci_get_value_by_section_string(s, "port", &port); dmuci_get_value_by_section_string(s, "management", &management); - if ((port && port[0] != '\0') && (management && strcmp(management, "0") == 0)) { + if ((port && port[0] != '\0') && (management && DM_STRCMP(management, "0") == 0)) { struct uci_section *ss = NULL; // Remove network option from wireless wifi-iface section @@ -2006,7 +2006,7 @@ static int set_BridgingBridge_Enable(char *refparam, struct dmctx *ctx, void *da static int get_BridgingBridge_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_BridgingBridge_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } @@ -2099,7 +2099,7 @@ static int get_BridgingBridgePort_Enable(char *refparam, struct dmctx *ctx, void char *management = NULL; dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { *value = "1"; } else { char *eth_ports = NULL; @@ -2114,7 +2114,7 @@ static int get_BridgingBridgePort_Enable(char *refparam, struct dmctx *ctx, void // ports config => ethport sections *value = dmuci_get_value_by_section_fallback_def(((struct bridge_port_args *)data)->bridge_port_sec, "enabled", "1"); - } else if (config && !strcmp(config, "wireless")) { + } else if (config && !DM_STRCMP(config, "wireless")) { // wireless config => wifi-iface sections dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_sec, "disabled", value); @@ -2145,7 +2145,7 @@ static int set_BridgingBridgePort_Enable(char *refparam, struct dmctx *ctx, void case VALUESET: string_to_bool(value, &b); dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { break; } else { char *eth_ports = NULL; @@ -2160,7 +2160,7 @@ static int set_BridgingBridgePort_Enable(char *refparam, struct dmctx *ctx, void // ports config => ethport sections dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_sec, "enabled", b ? "1" : "0"); - } else if (config && !strcmp(config, "wireless")) { + } else if (config && !DM_STRCMP(config, "wireless")) { // wireless config => wifi-iface sections dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_sec, "disabled", b ? "0" : "1"); @@ -2174,7 +2174,7 @@ static int set_BridgingBridgePort_Enable(char *refparam, struct dmctx *ctx, void static int get_BridgingBridgePort_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_BridgingBridgePort_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Up" : "Down"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Up" : "Down"; return 0; } @@ -2210,7 +2210,7 @@ static int get_BridgingBridgePort_Name(char *refparam, struct dmctx *ctx, void * char *management = NULL; dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); - if (management && strcmp(management, "1") != 0) + if (management && DM_STRCMP(management, "1") != 0) *value = dmstrdup(((struct bridge_port_args *)data)->br_port_device); return 0; } @@ -2222,7 +2222,7 @@ static int get_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "management", &management); dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "port", &port_device); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { char *pch = NULL, *spch = NULL; char lbuf[1024] = { 0, 0 }; unsigned pos = 0; @@ -2243,8 +2243,8 @@ static int get_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "config", &config); - if (config && strcmp(config, "network") == 0) { - char *tag = port_device ? strchr(port_device, '.') : NULL; + if (config && DM_STRCMP(config, "network") == 0) { + char *tag = port_device ? DM_STRCHR(port_device, '.') : NULL; if (tag) tag[0] = '\0'; } @@ -2276,7 +2276,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, if (dm_validate_string_list(value, -1, -1, 1024, -1, -1, NULL, NULL)) return FAULT_9007; - if (management && strcmp(management, "1") == 0) + if (management && DM_STRCMP(management, "1") == 0) break; if (dm_entry_validate_allowed_objects(ctx, value, allowed_objects)) @@ -2284,7 +2284,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, return 0; case VALUESET: - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { /* Management Port ==> true */ return set_lowerlayers_management_port(ctx, data, value); } else { @@ -2299,7 +2299,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, } // Update config section on dmmap_bridge_port if the linker is wirelss port or network port - if (strncmp(value, "Device.WiFi.SSID.", 17) == 0) { + if (DM_STRNCMP(value, "Device.WiFi.SSID.", 17) == 0) { dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_dmmap_sec, "config", "wireless"); is_wireless_config = true; } else @@ -2327,7 +2327,7 @@ static int set_BridgingBridgePort_LowerLayers(char *refparam, struct dmctx *ctx, update_device_management_port(section_name(((struct bridge_port_args *)data)->bridge_port_dmmap_sec), linker, ((struct bridge_port_args *)data)->br_inst); } else { - char *tag = strchr(port_device, '.'); + char *tag = DM_STRCHR(port_device, '.'); if (tag && !is_wireless_config) { char *cur_vid = dmstrdup(tag+1); char new_name[32] = {0}; @@ -2445,7 +2445,7 @@ static int set_BridgingBridgePort_DefaultUserPriority(char *refparam, struct dmc return 0; case VALUESET: dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_sec, "type", &type); - if (type[0] != '\0' && (strcmp(type, "untagged") == 0 || strcmp(type, "8021q") == 0)) + if (type[0] != '\0' && (DM_STRCMP(type, "untagged") == 0 || DM_STRCMP(type, "8021q") == 0)) dmuci_set_value_by_section(((struct bridge_port_args *)data)->bridge_port_sec, "priority", value); return 0; } @@ -2490,7 +2490,7 @@ static int set_BridgingBridgePort_PVID(char *refparam, struct dmctx *ctx, void * return 0; case VALUESET: dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_sec, "type", &type); - if (type && type[0] != '\0' && (strcmp(type, "untagged") == 0 || strcmp(type, "8021q") == 0)) { + if (type && type[0] != '\0' && (DM_STRCMP(type, "untagged") == 0 || DM_STRCMP(type, "8021q") == 0)) { char new_name[32] = {0}; char *ifname = NULL; @@ -2504,7 +2504,7 @@ static int set_BridgingBridgePort_PVID(char *refparam, struct dmctx *ctx, void * dmuci_get_value_by_section_string(vlanport_s, "name", &vlan_name); dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_sec, "name", &name); - if (vlan_name && name && strcmp(vlan_name, name) == 0) { + if (vlan_name && name && DM_STRCMP(vlan_name, name) == 0) { dmuci_set_value_by_section(vlanport_s, "name", new_name); break; } @@ -2530,9 +2530,9 @@ static int get_BridgingBridgePort_TPID(char *refparam, struct dmctx *ctx, void * char *type = NULL; dmuci_get_value_by_section_string(((struct bridge_port_args *)data)->bridge_port_sec, "type", &type); - if (type && (strcmp(type, "8021q") == 0 || strcmp(type, "untagged") == 0)) + if (type && (DM_STRCMP(type, "8021q") == 0 || DM_STRCMP(type, "untagged") == 0)) *value = "33024"; - else if (type && strcmp(type, "8021ad") == 0) + else if (type && DM_STRCMP(type, "8021ad") == 0) *value = "34984"; else *value = "37120"; @@ -2547,9 +2547,9 @@ static int set_BridgingBridgePort_TPID(char *refparam, struct dmctx *ctx, void * return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "33024") == 0) + if (DM_STRCMP(value, "33024") == 0) configure_device_type((struct bridge_port_args *)data, "8021q"); - else if (strcmp(value, "34984") == 0) + else if (DM_STRCMP(value, "34984") == 0) configure_device_type((struct bridge_port_args *)data, "8021ad"); return 0; } @@ -2704,9 +2704,9 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void return 0; uci_foreach_element_safe(device_ports, tmp, e) { - char *vid = strchr(e->name, '.'); + char *vid = DM_STRCHR(e->name, '.'); - if (vid && curr_vid && strcmp(vid+1, curr_vid) == 0) { + if (vid && curr_vid && DM_STRCMP(vid+1, curr_vid) == 0) { struct uci_section *s = NULL; char new_name[16] = {0}; @@ -2717,7 +2717,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void dmuci_get_value_by_section_string(s, "ifname", &ifname); if (ifname && *ifname == '\0') { dmuci_get_value_by_section_string(s, "name", &ifname); - char *name = strchr(ifname, '.'); + char *name = DM_STRCHR(ifname, '.'); if (name) *name = '\0'; } @@ -2731,7 +2731,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void char *vlan_name = NULL; dmuci_get_value_by_section_string(s, "name", &vlan_name); - if (vlan_name && strcmp(vlan_name, e->name) == 0) { + if (vlan_name && DM_STRCMP(vlan_name, e->name) == 0) { dmuci_set_value_by_section(s, "name", new_name); break; } @@ -2742,7 +2742,7 @@ static int set_BridgingBridgeVLAN_VLANID(char *refparam, struct dmctx *ctx, void char *port = NULL; dmuci_get_value_by_section_string(s, "port", &port); - if (port && strcmp(port, e->name) == 0) { + if (port && DM_STRCMP(port, e->name) == 0) { dmuci_set_value_by_section(s, "port", new_name); update_device_management_port(port, new_name, ((struct bridge_vlan_args *)data)->br_inst); break; @@ -2874,7 +2874,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo char *port = NULL; dmuci_get_value_by_section_string(s, "port", &port); - if (port && strcmp(port, curr_name) == 0) { + if (port && DM_STRCMP(port, curr_name) == 0) { dmuci_set_value_by_section(s, "port", curr_ifname); update_device_management_port(port, curr_ifname, ((struct bridge_vlanport_args *)data)->br_inst); break; @@ -2892,7 +2892,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "vid", ""); } else { - char *br = strstr(linker, ":vlan_"); + char *br = DM_STRSTR(linker, ":vlan_"); if (br) { char *new_vid = dmstrdup(br+6); @@ -2915,7 +2915,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo char *port = NULL; dmuci_get_value_by_section_string(s, "port", &port); - if (port && strcmp(port, curr_name) == 0) { + if (port && DM_STRCMP(port, curr_name) == 0) { dmuci_set_value_by_section(s, "port", new_name); update_device_management_port(port, new_name, ((struct bridge_vlanport_args *)data)->br_inst); break; @@ -2944,7 +2944,7 @@ static int set_BridgingBridgeVLANPort_VLAN(char *refparam, struct dmctx *ctx, vo char *vlan_inst = NULL; dmuci_get_value_by_section_string(vlan_s, "bridge_vlan_instance", &vlan_inst); - if (vlan_inst && strcmp(vlan_inst, instance) == 0) { + if (vlan_inst && DM_STRCMP(vlan_inst, instance) == 0) { char *tvid; dmuci_get_value_by_section_string(vlan_s, "tvid", &tvid); dmuci_set_value_by_section(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "tvid", tvid); @@ -3013,7 +3013,7 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo return 0; DM_STRNCPY(name, curr_name, sizeof(name)); - char *tag = strchr(curr_name, '.'); + char *tag = DM_STRCHR(curr_name, '.'); if (tag) tag[0] = '\0'; /* Update device section */ @@ -3042,11 +3042,11 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo } } } else { - char *br = strchr(linker, ':'); + char *br = DM_STRCHR(linker, ':'); if (br) { char *section_name = dmstrdup(br+1); - char *br_link = strchr(section_name, '+'); + char *br_link = DM_STRCHR(section_name, '+'); if (br_link) { char *curr_vid = NULL; char *port_linker = dmstrdup(br_link+1); @@ -3069,7 +3069,7 @@ static int set_BridgingBridgeVLANPort_Port(char *refparam, struct dmctx *ctx, vo /* Create the new ifname */ if (port_linker[0] != '\0'){ - char *tag = strchr(port_linker, '.'); + char *tag = DM_STRCHR(port_linker, '.'); if (tag) tag[0] = '\0'; snprintf(new_name, sizeof(new_name), "%s.%s", port_linker, curr_vid); } @@ -3114,7 +3114,7 @@ static int get_BridgingBridgeVLANPort_Untagged(char *refparam, struct dmctx *ctx { char *type; dmuci_get_value_by_section_string(((struct bridge_vlanport_args *)data)->bridge_vlanport_sec, "type", &type); - *value = (strcmp(type, "untagged") == 0) ? "1" : "0"; + *value = (DM_STRCMP(type, "untagged") == 0) ? "1" : "0"; return 0; } @@ -3161,7 +3161,7 @@ static int set_BridgingBridgeProviderBridge_Enable(char *refparam, struct dmctx static int get_BridgingBridgeProviderBridge_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct provider_bridge_args *)data)->provider_bridge_sec, "enable", value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } diff --git a/dmtree/tr181/deviceinfo.c b/dmtree/tr181/deviceinfo.c index e2cbb096..4d8a0bbb 100644 --- a/dmtree/tr181/deviceinfo.c +++ b/dmtree/tr181/deviceinfo.c @@ -47,7 +47,7 @@ static bool check_file_dir(char *name) if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { while ((d_file = readdir (dir)) != NULL) { - if (strcmp(name, d_file->d_name) == 0) { + if (DM_STRCMP(name, d_file->d_name) == 0) { closedir(dir); return true; } @@ -62,8 +62,8 @@ static int get_number_of_cpus(void) char val[16]; dm_read_sysfs_file("/sys/devices/system/cpu/present", val, sizeof(val)); - char *max = strchr(val, '-'); - return max ? atoi(max+1)+1 : 0; + char *max = DM_STRCHR(val, '-'); + return max ? DM_STRTOL(max+1)+1 : 0; } static int dmmap_synchronizeVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) @@ -252,7 +252,7 @@ static int get_device_active_fwimage(char *refparam, struct dmctx *ctx, void *da dmubus_call("fwbank", "dump", UBUS_ARGS{0}, 0, &res); dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") { active = dmjson_get_value(bank_obj, 1, "active"); - if (active && strcmp(active, "true") == 0) { + if (active && DM_STRCMP(active, "true") == 0) { id = dmjson_get_value(bank_obj, 1, "id"); break; } @@ -273,7 +273,7 @@ static int get_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data dmubus_call("fwbank", "dump", UBUS_ARGS{0}, 0, &res); dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") { boot = dmjson_get_value(bank_obj, 1, "boot"); - if (boot && strcmp(boot, "true") == 0) { + if (boot && DM_STRCMP(boot, "true") == 0) { id = dmjson_get_value(bank_obj, 1, "id"); break; } @@ -301,13 +301,13 @@ static int set_device_boot_fwimage(char *refparam, struct dmctx *ctx, void *data case VALUESET: adm_entry_get_linker_value(ctx, value, &linker); if (linker && *linker) { - char *bank_id = strchr(linker, ':'); + char *bank_id = DM_STRCHR(linker, ':'); if (bank_id) { json_object *res = NULL; dmubus_call("fwbank", "set_bootbank", UBUS_ARGS{{"bank", bank_id+1, Integer}}, 1, &res); char *success = dmjson_get_value(res, 1, "success"); - if (strcmp(success, "true") != 0) + if (DM_STRCMP(success, "true") != 0) return FAULT_9001; } } @@ -451,7 +451,7 @@ static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *ins 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 (config_name && strcmp(config_name, d_file->d_name) == 0) { + if (config_name && DM_STRCMP(config_name, d_file->d_name) == 0) { char date[sizeof("AAAA-MM-JJTHH:MM:SSZ")], path[280] = {0}; struct stat attr; @@ -535,7 +535,7 @@ static int get_vlf_max_size (char *refparam, struct dmctx *ctx, void *data, char dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log_size", value); // Value defined in system is in KiB in datamodel this is in bytes, convert the value in bytes - size = (*value && **value) ? atoi(*value) * 1000 : 0; + size = (*value && **value) ? DM_STRTOL(*value) * 1000 : 0; dmasprintf(value, "%d", size); return 0; @@ -589,9 +589,9 @@ static int get_DeviceInfoProcessor_Architecture(char *refparam, struct dmctx *ct if (uname(&utsname) < 0) return 0; - if (strstr(utsname.machine, "arm") || strstr(utsname.machine, "aarch64")) { + if (DM_STRSTR(utsname.machine, "arm") || DM_STRSTR(utsname.machine, "aarch64")) { *value = "arm"; - } else if(strstr(utsname.machine, "mips")) { + } else if(DM_STRSTR(utsname.machine, "mips")) { const bool is_big_endian = IS_BIG_ENDIAN; *value = (is_big_endian) ? "mipseb" : "mipsel"; } else @@ -783,7 +783,7 @@ static int get_process_priority(char* refparam, struct dmctx *ctx, void *data, c *value = dmjson_get_value((json_object *)data, 1, "priority"); - priority = (*value && **value) ? atoi(*value) : 0; + priority = (*value && **value) ? DM_STRTOL(*value) : 0; /* Convert Linux priority to a value between 0 and 99 */ priority = round((priority + 100) * 99 / 139); @@ -804,7 +804,7 @@ static int get_process_cpu_time(char* refparam, struct dmctx *ctx, void *data, c static int get_process_state(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *state = dmjson_get_value((json_object *)data, 1, "state"); - *value = (state && strcmp(state, "Unknown") == 0) ? "Idle" : state; + *value = (state && DM_STRCMP(state, "Unknown") == 0) ? "Idle" : state; return 0; } @@ -913,7 +913,7 @@ static int operate_DeviceInfoVendorConfigFile_Restore(char *refparam, struct dmc char restore_command[32] = {'\0'}; char *ret = strrchr(refparam, '.'); - strncpy(restore_path, refparam, ret - refparam +1); + DM_STRNCPY(restore_path, refparam, ret - refparam + 2); DM_STRNCPY(restore_command, ret+1, sizeof(restore_command)); char *url = dmjson_get_value((json_object *)value, 1, "URL"); @@ -957,7 +957,7 @@ static int operate_DeviceInfoFirmwareImage_Download(char *refparam, struct dmctx char command[32] = {'\0'}; char *ret = strrchr(refparam, '.'); - strncpy(obj_path, refparam, ret - refparam +1); + DM_STRNCPY(obj_path, refparam, ret - refparam + 2); DM_STRNCPY(command, ret+1, sizeof(command)); char *url = dmjson_get_value((json_object *)value, 1, "URL"); diff --git a/dmtree/tr181/dhcpv4.c b/dmtree/tr181/dhcpv4.c index 333de7df..0d4a81b8 100644 --- a/dmtree/tr181/dhcpv4.c +++ b/dmtree/tr181/dhcpv4.c @@ -120,7 +120,7 @@ int set_section_order(char *package, char *dmpackage, char *sect_type, struct uc struct uci_section *s, *dm; dmuci_get_value_by_section_string(dmmap_sect, "order", &v); - if (strlen(v) > 0 && strcmp(v, order) == 0) + if (DM_STRLEN(v) > 0 && DM_STRCMP(v, order) == 0) return 0; dmuci_set_value_by_section_bbfdm(dmmap_sect, "order", order); if (conf == NULL) { @@ -129,19 +129,19 @@ int set_section_order(char *package, char *dmpackage, char *sect_type, struct uc } else s = conf; - if (strcmp(order, "1") != 0 && s != NULL) { + if (DM_STRCMP(order, "1") != 0 && s != NULL) { dmuci_set_value_by_section(s, "force", ""); } - if (set_force == 1 && strcmp(order, "1") == 0 && s != NULL) { + if (set_force == 1 && DM_STRCMP(order, "1") == 0 && s != NULL) { dmuci_set_value_by_section(s, "force", "1"); } if ((dm = exist_other_section_same_order(dmmap_sect, dmpackage, sect_type, order)) != NULL) { dmuci_get_value_by_section_string(dm, "section_name", §_name); get_config_section_of_dmmap_section(package, sect_type, sect_name, &s); - dmasprintf(&incrorder, "%d", atoi(order)+1); - if (s != NULL && strcmp(order, "1") == 0) { + dmasprintf(&incrorder, "%ld", DM_STRTOL(order)+1); + if (s != NULL && DM_STRCMP(order, "1") == 0) { dmuci_set_value_by_section(s, "force", ""); } set_section_order(package, dmpackage, sect_type, dm, s, set_force, incrorder); @@ -163,7 +163,7 @@ int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, macarray = strsplit(option_value, ":", &length); for (int i = 0; i < 6; i++) - pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s:", (macarray[i] && strcmp(macarray[i], "*") == 0) ? "00" : type ? "FF" : macarray[i]); + pos += snprintf(&buf[pos], sizeof(buf) - pos, "%s:", (macarray[i] && DM_STRCMP(macarray[i], "*") == 0) ? "00" : type ? "FF" : macarray[i]); if (pos) buf[pos - 1] = 0; @@ -193,7 +193,7 @@ static void dmmap_synchronizeDHCPv4Client(struct dmctx *dmctx, DMNODE *parent_no char *iface_name = NULL; dmuci_get_value_by_section_string(s, "added_by_controller", &added_by_controller); - if (strcmp(added_by_controller, "1") == 0) + if (DM_STRCMP(added_by_controller, "1") == 0) continue; dmuci_get_value_by_section_string(s, "iface_name", &iface_name); @@ -209,7 +209,7 @@ static void dmmap_synchronizeDHCPv4Client(struct dmctx *dmctx, DMNODE *parent_no char *proto = NULL; dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(proto, "dhcp") != 0) + if (DM_STRCMP(proto, "dhcp") != 0) continue; if (is_dhcp_section_exist("dmmap_dhcp_client", section_name(s))) @@ -231,7 +231,7 @@ static void dmmap_synchronizeDHCPv4RelayForwarding(struct dmctx *dmctx, DMNODE * char *iface_name = NULL; dmuci_get_value_by_section_string(s, "added_by_controller", &added_by_controller); - if (strcmp(added_by_controller, "1") == 0) + if (DM_STRCMP(added_by_controller, "1") == 0) continue; dmuci_get_value_by_section_string(s, "iface_name", &iface_name); @@ -247,7 +247,7 @@ static void dmmap_synchronizeDHCPv4RelayForwarding(struct dmctx *dmctx, DMNODE * char *proto = NULL; dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(proto, "relay") != 0) + if (DM_STRCMP(proto, "relay") != 0) continue; if (is_dhcp_section_exist("dmmap_dhcp_relay", section_name(s))) @@ -299,9 +299,9 @@ static int interface_get_ipv4(const char *iface, uint32_t *addr, unsigned *bits) return -1; json_object_object_foreach(jobj, key, val) { - if (!strcmp(key, "address")) + if (!DM_STRCMP(key, "address")) addr_str = json_object_get_string(val); - else if (!strcmp(key, "mask")) + else if (!DM_STRCMP(key, "mask")) addr_cidr = json_object_get_int(val); } } @@ -354,7 +354,7 @@ static bool check_dhcp_host_alias_exists(char *dhcp_interface, char *option, cha dmuci_get_value_by_section_string(s, option, &opt_value); - if (strcmp(opt_value, value) == 0) + if (DM_STRCMP(opt_value, value) == 0) return true; } @@ -370,7 +370,7 @@ static bool check_dhcp_host_option_exists(char *dhcp_interface, char *option, ch dmuci_get_value_by_section_string(s, option, &opt_value); - if (strcmp(opt_value, value) == 0) + if (DM_STRCMP(opt_value, value) == 0) return true; } @@ -391,10 +391,10 @@ static int get_dhcp_iface_range(struct uci_section *dhcp_sec, char *interface, u return -1; *iface_bits = ~((1 << (32 - iface_cidr)) - 1); - *iface_net_start = (ntohl(*iface_addr) & *iface_bits) + atoi(dhcp_start); - *iface_net_end = (ntohl(*iface_addr) & *iface_bits) + atoi(dhcp_start) + atoi(dhcp_limit) - 1; - *start = atoi(dhcp_start); - *limit = atoi(dhcp_limit); + *iface_net_start = (ntohl(*iface_addr) & *iface_bits) + DM_STRTOL(dhcp_start); + *iface_net_end = (ntohl(*iface_addr) & *iface_bits) + DM_STRTOL(dhcp_start) + DM_STRTOL(dhcp_limit) - 1; + *start = DM_STRTOL(dhcp_start); + *limit = DM_STRTOL(dhcp_limit); return 0; } @@ -431,7 +431,7 @@ static char *get_dhcp_network_from_relay_list(char *net_list) dmuci_get_value_by_section_string(s, "proto", &proto); for (int i = 0; i < length; i++) { - if (strcmp(net_list_arr[i], section_name(s)) == 0 && strcmp(proto, "dhcp") == 0) + if (strcmp(net_list_arr[i], section_name(s)) == 0 && DM_STRCMP(proto, "dhcp") == 0) return net_list_arr[i]; } } @@ -446,7 +446,7 @@ static struct uci_section *get_dhcp_classifier(char *classifier_name, char *netw uci_foreach_sections("dhcp", classifier_name, s) { dmuci_get_value_by_section_string(s, "networkid", &networkid); - if (strcmp(networkid, network) == 0) + if (DM_STRCMP(networkid, network) == 0) return s; } @@ -461,7 +461,7 @@ bool tag_option_exists(char *dmmap_package, char *section, char *opt_check, char char *curr_tag = NULL; dmuci_get_value_by_section_string(s, tag_name, &curr_tag); - if (curr_tag && tag_value && strcmp(curr_tag, tag_value) == 0) + if (curr_tag && tag_value && DM_STRCMP(curr_tag, tag_value) == 0) return true; } @@ -497,14 +497,14 @@ static int get_DHCPv4ServerPool_Option_Value(struct uci_section *s, const char * return -1; uci_foreach_element(dhcp_option, e) { - char *pch = strchr(e->name, ','); + char *pch = DM_STRCHR(e->name, ','); if (pch) { char opt_tag[8] = {0}; unsigned int len = pch - e->name + 1; unsigned int opt_size = (len > sizeof(opt_tag)) ? sizeof(opt_tag) : len; DM_STRNCPY(opt_tag, e->name, opt_size); - if (strcmp(opt_tag, option) == 0) { + if (DM_STRCMP(opt_tag, option) == 0) { *value = dmstrdup(pch + 1); return 0; } @@ -523,14 +523,14 @@ static int set_DHCPv4ServerPool_Option_Value(struct uci_section *s, const char * struct uci_element *e = NULL, *tmp = NULL; uci_foreach_element_safe(dhcp_option, tmp, e) { - char *pch = strchr(e->name, ','); + char *pch = DM_STRCHR(e->name, ','); if (pch) { char opt_tag[8] = {0}; unsigned int len = pch - e->name + 1; unsigned int opt_size = (len > sizeof(opt_tag)) ? sizeof(opt_tag) : len; DM_STRNCPY(opt_tag, e->name, opt_size); - if (strcmp(opt_tag, option) == 0) { + if (DM_STRCMP(opt_tag, option) == 0) { dmuci_del_list_value_by_section(s, "dhcp_option", e->name); break; } @@ -578,7 +578,7 @@ static int browseDHCPv4ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, // skip the section if option ignore = '1' dmuci_get_value_by_section_string(p->config_section, "ignore", &ignore); - if (ignore && strcmp(ignore, "1") == 0) + if (ignore && DM_STRCMP(ignore, "1") == 0) continue; dmuci_get_value_by_section_string(p->config_section, "interface", &interface); @@ -589,7 +589,7 @@ static int browseDHCPv4ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, inst = handle_instance(dmctx, parent_node, p->dmmap_section, "dhcp_instance", "dhcp_alias"); dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); - if (v == NULL || strlen(v) == 0) + if (v == NULL || DM_STRLEN(v) == 0) set_section_order("dhcp", "dmmap_dhcp", "dhcp", p->dmmap_section, p->config_section, 0, inst); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_args, inst) == DM_STOP) @@ -613,7 +613,7 @@ static int browseDHCPv4ServerPoolStaticAddressInst(struct dmctx *dmctx, DMNODE * // Skip all reserved hosts char *host_name = NULL; dmuci_get_value_by_section_string(p->config_section, "name", &host_name); - if (host_name && strcmp(host_name, "reserved") == 0) + if (host_name && DM_STRCMP(host_name, "reserved") == 0) continue; dmuci_set_value_by_section(p->dmmap_section, "dhcp", ((struct dhcp_args *)prev_data)->interface); @@ -672,9 +672,9 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p sscanf(line, "%23s vcid=%127s clid=%127s ucid=%127s", macaddr, vcid, clid, ucid); - if (strncmp(macaddr, (char *)args->lease->hwaddr, 24) == 0) { + if (DM_STRNCMP(macaddr, (char *)args->lease->hwaddr, 24) == 0) { - if (strcmp(vcid, "-") != 0) { + if (DM_STRCMP(vcid, "-") != 0) { init_client_options_args(&curr_client_options_args, "60", dmstrdup(vcid)); inst = handle_instance_without_section(dmctx, parent_node, ++id); @@ -683,7 +683,7 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p break; } - if (strcmp(clid, "-") != 0) { + if (DM_STRCMP(clid, "-") != 0) { init_client_options_args(&curr_client_options_args, "61", dmstrdup(clid)); inst = handle_instance_without_section(dmctx, parent_node, ++id); @@ -693,7 +693,7 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p } - if (strcmp(ucid, "-") != 0) { + if (DM_STRCMP(ucid, "-") != 0) { init_client_options_args(&curr_client_options_args, "77", dmstrdup(ucid)); inst = handle_instance_without_section(dmctx, parent_node, ++id); @@ -1071,7 +1071,7 @@ static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha char *device = NULL; dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(((struct dhcp_client_args *)data)->iface_s, NULL, NULL); } else { dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "proto", "none"); @@ -1108,7 +1108,7 @@ static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha char *device = NULL; dmuci_get_value_by_section_string(iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(iface_s, NULL, NULL); } else { dmuci_set_value_by_section(iface_s, "proto", "none"); @@ -1160,9 +1160,9 @@ static int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void switch (del_action) { case DEL_INST: if (((struct dhcp_client_option_args *)data)->client_sect) { - char *option_name = get_dhcp_option_name(atoi(((struct dhcp_client_option_args *)data)->option_tag)); + char *option_name = get_dhcp_option_name(DM_STRTOL(((struct dhcp_client_option_args *)data)->option_tag)); - if (strcmp(option_name, "sendopts") == 0) { + if (DM_STRCMP(option_name, "sendopts") == 0) { char *sendopts = NULL; dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &sendopts); @@ -1337,7 +1337,7 @@ static int delObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void * static int get_DHCPv4ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct dhcp_args *)data)->sections)->config_section, "dhcpv4", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "0" : "1"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "0" : "1"; return 0; } @@ -1362,7 +1362,7 @@ static int set_DHCPv4ServerPool_Enable(char *refparam, struct dmctx *ctx, void * static int get_DHCPv4ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct dhcp_args *)data)->sections)->config_section, "dhcpv4", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "Disabled" : "Enabled"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "Disabled" : "Enabled"; return 0; } @@ -1567,7 +1567,7 @@ static int get_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx * char *host_name = NULL; dmuci_get_value_by_section_string(s, "name", &host_name); - if (host_name && strcmp(host_name, "reserved") != 0) + if (host_name && DM_STRCMP(host_name, "reserved") != 0) continue; char *ip = NULL; @@ -1617,7 +1617,7 @@ static int set_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx * char *host_name = NULL; dmuci_get_value_by_section_string(s, "name", &host_name); - if (host_name && strcmp(host_name, "reserved") != 0) + if (host_name && DM_STRCMP(host_name, "reserved") != 0) continue; char *ip = NULL; @@ -1626,7 +1626,7 @@ static int set_DHCPv4ServerPool_ReservedAddresses(char *refparam, struct dmctx * continue; // Check if ip exists in the list value : yes -> skip it else delete it - if (!strstr(value, ip)) + if (!DM_STRSTR(value, ip)) dmuci_delete_by_section(s, NULL, NULL); } @@ -1760,18 +1760,18 @@ static int get_DHCPv4ServerPool_LeaseTime(char *refparam, struct dmctx *ctx, voi if (ltime == NULL || *ltime == '\0') return 0; - if (strchr(ltime, 'd')) { + if (DM_STRCHR(ltime, 'd')) { pch = strtok_r(ltime, "d", &pchr); - leasetime = atoi(pch) * 24 * 3600; - } else if (strchr(ltime, 'h')) { + leasetime = DM_STRTOL(pch) * 24 * 3600; + } else if (DM_STRCHR(ltime, 'h')) { pch = strtok_r(ltime, "h", &pchr); - leasetime = atoi(pch) * 3600; - } else if (strchr(ltime, 'm')) { + leasetime = DM_STRTOL(pch) * 3600; + } else if (DM_STRCHR(ltime, 'm')) { pch = strtok_r(ltime, "m", &pchr); - leasetime = atoi(pch) * 60; + leasetime = DM_STRTOL(pch) * 60; } else { pch = strtok_r(ltime, "s", &pchr); - leasetime = atoi(pch); + leasetime = DM_STRTOL(pch); } dmasprintf(value, "%d", leasetime); @@ -1789,7 +1789,7 @@ static int set_DHCPv4ServerPool_LeaseTime(char *refparam, struct dmctx *ctx, voi return FAULT_9007; return 0; case VALUESET: - leasetime = atoi(value); + leasetime = DM_STRTOL(value); if (leasetime == -1) buf[0] = '\0'; else @@ -1869,12 +1869,12 @@ static int set_DHCPv4ServerPoolStaticAddress_Alias(char *refparam, struct dmctx // Check if alias is assigned by user dmuci_get_value_by_section_string((((struct dhcp_host_args *)data)->host_sections)->dmmap_section, "dhcp_host_alias_assigned", &alias_assigned); - if (alias_assigned && strcmp(alias_assigned, "1") == 0) + if (alias_assigned && DM_STRCMP(alias_assigned, "1") == 0) return FAULT_9007; // Check if alias exists dmuci_get_value_by_section_string((((struct dhcp_host_args *)data)->host_sections)->dmmap_section, "dhcp_host_alias", &curr_alias); - if (strcmp(curr_alias, value) != 0 && check_dhcp_host_alias_exists(((struct dhcp_host_args *)data)->dhcp_interface, "dhcp_host_alias", value)) + if (DM_STRCMP(curr_alias, value) != 0 && check_dhcp_host_alias_exists(((struct dhcp_host_args *)data)->dhcp_interface, "dhcp_host_alias", value)) return FAULT_9007; return 0; @@ -1905,7 +1905,7 @@ static int set_DHCPv4ServerPoolStaticAddress_Chaddr(char *refparam, struct dmctx // Check if mac exists dmuci_get_value_by_section_string((((struct dhcp_host_args *)data)->host_sections)->config_section, "mac", &curr_mac); - if (strcmp(curr_mac, value) != 0 && check_dhcp_host_option_exists(((struct dhcp_host_args *)data)->dhcp_interface, "mac", value)) + if (DM_STRCMP(curr_mac, value) != 0 && check_dhcp_host_option_exists(((struct dhcp_host_args *)data)->dhcp_interface, "mac", value)) return FAULT_9007; return 0; @@ -1940,7 +1940,7 @@ static int set_DHCPv4ServerPoolStaticAddress_Yiaddr(char *refparam, struct dmctx // Check if ip exists dmuci_get_value_by_section_string((((struct dhcp_host_args *)data)->host_sections)->config_section, "ip", &curr_ip); - if (strcmp(curr_ip, value) != 0 && check_dhcp_host_option_exists(host_args->dhcp_interface, "ip", value)) + if (DM_STRCMP(curr_ip, value) != 0 && check_dhcp_host_option_exists(host_args->dhcp_interface, "ip", value)) return FAULT_9007; return 0; @@ -1960,7 +1960,7 @@ static int get_DHCPv4ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, v uci_path_foreach_sections(bbfdm, "dmmap", "dhcpv4clients", s) { char *macaddr; dmuci_get_value_by_section_string(s, "macaddr", &macaddr); - if (strcmp(hwaddr, macaddr) == 0) { + if (DM_STRCMP(hwaddr, macaddr) == 0) { dmuci_get_value_by_section_string(s, "alias", value); break; } @@ -2127,7 +2127,7 @@ static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d char *device = NULL; dmuci_get_value_by_section_string(dhcpv4_client->iface_s, "device", &device); - iface_name = (device && *device) ? strchr(device, '@') : NULL; + iface_name = (device && *device) ? DM_STRCHR(device, '@') : NULL; adm_entry_get_linker_param(ctx, "Device.IP.Interface.", iface_name ? iface_name + 1 : "", value); } return 0; @@ -2171,7 +2171,7 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d char *device = NULL; dmuci_get_value_by_section_string(dhcpv4_client->iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(dhcpv4_client->iface_s, NULL, NULL); } else { dmuci_set_value_by_section(dhcpv4_client->iface_s, "proto", "none"); @@ -2196,7 +2196,7 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d char *proto = NULL; dmuci_get_value_by_section_string(interface_s, "proto", &proto); - if (strncmp(proto, "dhcp", 4) == 0) { + if (DM_STRNCMP(proto, "dhcp", 4) == 0) { char dev_name[32]; snprintf(iface_name, sizeof(iface_name), "%s_4", linker); @@ -2217,7 +2217,7 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d dmuci_get_value_by_section_string(option_s, "enable", &enable); - if (strcmp(enable, "1") == 0) { + if (DM_STRCMP(enable, "1") == 0) { char *opt_tag = NULL; char *opt_value = NULL; @@ -2238,7 +2238,7 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d char *enable = NULL; dmuci_get_value_by_section_string(option_s, "enable", &enable); - if (strcmp(enable, "1") == 0) { + if (DM_STRCMP(enable, "1") == 0) { char *opt_tag = NULL; dmuci_get_value_by_section_string(option_s, "option_tag", &opt_tag); @@ -2264,7 +2264,7 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d static int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_DHCPv4Client_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } @@ -2351,7 +2351,7 @@ static int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void * if (res) { json_object *jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); mask = dmjson_get_value(jobj, 1, "mask"); - mask = (mask && *mask) ? cidr2netmask(atoi(mask)) : ""; + mask = (mask && *mask) ? cidr2netmask(DM_STRTOL(mask)) : ""; } } } @@ -2455,9 +2455,9 @@ static int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, string_to_bool(value, &b); if (dhcp_client_s->client_sect) { - option_name = get_dhcp_option_name(atoi(dhcp_client_s->option_tag)); + option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); - if (strcmp(option_name, "sendopts") == 0) { + if (DM_STRCMP(option_name, "sendopts") == 0) { char tag_value[128] = {0}; char *sendopts = NULL; @@ -2524,13 +2524,13 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (dhcp_client_s->option_tag && strcmp(dhcp_client_s->option_tag, value) == 0) + if (dhcp_client_s->option_tag && DM_STRCMP(dhcp_client_s->option_tag, value) == 0) break; dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "dhcp_client_key", &dhcp_client_key); - new_option_name = get_dhcp_option_name(atoi(value)); - if (strcmp(new_option_name ,"sendopts") == 0) { + new_option_name = get_dhcp_option_name(DM_STRTOL(value)); + if (DM_STRCMP(new_option_name ,"sendopts") == 0) { if (tag_option_exists("dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, "option_tag", value)) return FAULT_9007; } else { @@ -2546,10 +2546,10 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi break; case VALUESET: if (dhcp_client_s->client_sect) { - old_option_name = get_dhcp_option_name(atoi(dhcp_client_s->option_tag)); - new_option_name = get_dhcp_option_name(atoi(value)); + old_option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); + new_option_name = get_dhcp_option_name(DM_STRTOL(value)); - if (strcmp(old_option_name, "sendopts") == 0) { + if (DM_STRCMP(old_option_name, "sendopts") == 0) { char old_tag_value[128] = {0}; char *sendopts = NULL; @@ -2560,7 +2560,7 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi remove_elt_from_str_list(&sendopts, old_tag_value); dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); - if (strcmp(new_option_name, "sendopts") == 0) { + if (DM_STRCMP(new_option_name, "sendopts") == 0) { char new_tag_value[128] = {0}; snprintf(new_tag_value, sizeof(new_tag_value), "%s:%s", value, dhcp_client_s->value); @@ -2577,7 +2577,7 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi if (option_value && *option_value) { dmuci_set_value_by_section(dhcp_client_s->client_sect, old_option_name, ""); - if (strcmp(new_option_name, "sendopts") == 0) { + if (DM_STRCMP(new_option_name, "sendopts") == 0) { char new_tag_value[128] = {0}; char *sendopts = NULL; @@ -2624,9 +2624,9 @@ static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, v case VALUESET: convert_hex_to_string(value, res, sizeof(res)); if (dhcp_client_s->client_sect) { - option_name = get_dhcp_option_name(atoi(dhcp_client_s->option_tag)); + option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); - if (strcmp(option_name, "sendopts") == 0) { + if (DM_STRCMP(option_name, "sendopts") == 0) { char old_tag_value[128] = {0}; char *sendopts = NULL; @@ -2733,7 +2733,7 @@ static int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (dhcp_client_s->option_tag && strcmp(dhcp_client_s->option_tag, value) == 0) + if (dhcp_client_s->option_tag && DM_STRCMP(dhcp_client_s->option_tag, value) == 0) break; dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "dhcp_client_key", &dhcp_client_key); @@ -2808,7 +2808,7 @@ static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { *value = "1"; return 0; } @@ -2841,7 +2841,7 @@ static int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { option_enabled = true; if (!b) dmuci_del_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", opt_value); @@ -2895,7 +2895,7 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (dhcp_client_s->option_tag && strcmp(dhcp_client_s->option_tag, value) == 0) + if (dhcp_client_s->option_tag && DM_STRCMP(dhcp_client_s->option_tag, value) == 0) break; if (tag_option_exists("dmmap_dhcp", "servpool_option", "section_name", section_name(dhcp_client_s->client_sect), "option_tag", value)) @@ -2911,7 +2911,7 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { option_enabled = true; break; } @@ -2966,7 +2966,7 @@ static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { option_enabled = true; break; } @@ -3069,7 +3069,7 @@ static int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, v static int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_DHCPv4RelayForwarding_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } diff --git a/dmtree/tr181/dhcpv6.c b/dmtree/tr181/dhcpv6.c index cbce88a1..36cc1f75 100644 --- a/dmtree/tr181/dhcpv6.c +++ b/dmtree/tr181/dhcpv6.c @@ -64,7 +64,7 @@ static void dmmap_synchronizeDHCPv6Client(struct dmctx *dmctx, DMNODE *parent_no char *iface_name = NULL; dmuci_get_value_by_section_string(s, "added_by_controller", &added_by_controller); - if (strcmp(added_by_controller, "1") == 0) + if (DM_STRCMP(added_by_controller, "1") == 0) continue; dmuci_get_value_by_section_string(s, "iface_name", &iface_name); @@ -80,7 +80,7 @@ static void dmmap_synchronizeDHCPv6Client(struct dmctx *dmctx, DMNODE *parent_no char *proto = NULL; dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(proto, "dhcpv6") != 0) + if (DM_STRCMP(proto, "dhcpv6") != 0) continue; if (is_dhcpv6_client_section_exist(section_name(s))) @@ -98,7 +98,7 @@ static struct uci_section *get_dhcpv6_classifier(char *classifier_name, const ch uci_foreach_sections("dhcp", classifier_name, s) { dmuci_get_value_by_section_string(s, "networkid", &v); - if (strcmp(v, network) == 0) + if (DM_STRCMP(v, network) == 0) return s; } return NULL; @@ -107,8 +107,8 @@ static struct uci_section *get_dhcpv6_classifier(char *classifier_name, const ch static int get_value_in_date_time_format(json_object *json_obj, char *option_name, char **value) { const char *option_value = dmjson_get_value(json_obj, 1, option_name); - if (option_value && *option_value != '\0' && atoi(option_value) > 0) { - time_t time_value = atoi(option_value); + if (option_value && *option_value != '\0' && DM_STRTOL(option_value) > 0) { + time_t time_value = DM_STRTOL(option_value); char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"]; if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", gmtime(&time_value)) == 0) return -1; @@ -178,7 +178,7 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, // skip the section if option ignore = '1' dmuci_get_value_by_section_string(p->config_section, "ignore", &ignore); - if (ignore && strcmp(ignore, "1") == 0) + if (ignore && DM_STRCMP(ignore, "1") == 0) continue; dmuci_get_value_by_section_string(p->config_section, "interface", &interface); @@ -187,7 +187,7 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, inst = handle_instance(dmctx, parent_node, p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias"); dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); - if (v == NULL || strlen(v) == 0) + if (v == NULL || DM_STRLEN(v) == 0) set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, inst); if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp6_args, inst) == DM_STOP) @@ -346,7 +346,7 @@ static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha char *device = NULL; dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(((struct dhcpv6_client_args *)data)->iface_s, NULL, NULL); } else { dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->iface_s, "proto", "none"); @@ -369,7 +369,7 @@ static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha char *device = NULL; dmuci_get_value_by_section_string(iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(iface_s, NULL, NULL); } else { dmuci_set_value_by_section(iface_s, "proto", "none"); @@ -418,7 +418,7 @@ static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char *dhcpv6 = NULL; dmuci_get_value_by_section_string(s, "dhcpv6", &dhcpv6); - if (strcmp(dhcpv6, "server") == 0) { + if (DM_STRCMP(dhcpv6, "server") == 0) { struct uci_section *dmmap_section = NULL; get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(s), &dmmap_section); @@ -547,7 +547,7 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d char *device = NULL; dmuci_get_value_by_section_string(dhcpv6_client->iface_s, "device", &device); - iface_name = (device && *device) ? strchr(device, '@') : NULL; + iface_name = (device && *device) ? DM_STRCHR(device, '@') : NULL; adm_entry_get_linker_param(ctx, "Device.IP.Interface.", iface_name ? iface_name + 1 : "", value); } return 0; @@ -588,7 +588,7 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d char *device = NULL; dmuci_get_value_by_section_string(dhcpv6_client->iface_s, "device", &device); - if (device && strchr(device, '@')) { + if (device && DM_STRCHR(device, '@')) { dmuci_delete_by_section(dhcpv6_client->iface_s, NULL, NULL); } else { dmuci_set_value_by_section(dhcpv6_client->iface_s, "proto", "none"); @@ -617,7 +617,7 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d char *proto = NULL; dmuci_get_value_by_section_string(interface_s, "proto", &proto); - if (strncmp(proto, "dhcp", 4) == 0) { + if (DM_STRNCMP(proto, "dhcp", 4) == 0) { char dev_name[32]; snprintf(iface_name, sizeof(iface_name), "%s_6", linker); @@ -648,7 +648,7 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_DHCPv6Client_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } @@ -672,7 +672,7 @@ static int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, char *reqaddress = NULL; dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "reqaddress", &reqaddress); - *value = (reqaddress && strcmp(reqaddress, "none") == 0) ? "0" : "1"; + *value = (reqaddress && DM_STRCMP(reqaddress, "none") == 0) ? "0" : "1"; return 0; } @@ -703,7 +703,7 @@ static int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, v char *reqprefix = NULL; dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "reqprefix", &reqprefix); - *value = (reqprefix && strcmp(reqprefix, "auto") == 0) ? "1" : "0"; + *value = (reqprefix && DM_STRCMP(reqprefix, "auto") == 0) ? "1" : "0"; return 0; } @@ -818,7 +818,7 @@ static int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ct static int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "0" : "1"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "0" : "1"; return 0; } @@ -843,7 +843,7 @@ static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void * static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "Disabled" : "Enabled"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "Disabled" : "Enabled"; return 0; } @@ -1067,7 +1067,7 @@ static int get_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, v uci_path_foreach_sections(bbfdm, "dmmap", "dhcpv6clients", s) { char *srcaddr; dmuci_get_value_by_section_string(s, "srcaddr", &srcaddr); - if (strcmp(src_addr, srcaddr) == 0) { + if (DM_STRCMP(src_addr, srcaddr) == 0) { dmuci_get_value_by_section_string(s, "alias", value); break; } @@ -1141,8 +1141,8 @@ static int get_DHCPv6ServerPoolClientIPv6Prefix_PreferredLifetime(char *refparam *value = "0001-01-01T00:00:00Z"; char *preferred = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "preferred-lifetime"); - if (preferred && *preferred != '\0' && atoi(preferred) > 0) { - time_t time_value = atoi(preferred); + if (preferred && *preferred != '\0' && DM_STRTOL(preferred) > 0) { + time_t time_value = DM_STRTOL(preferred); char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"]; if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", gmtime(&time_value)) == 0) return -1; @@ -1157,8 +1157,8 @@ static int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, st *value = "0001-01-01T00:00:00Z"; char *valid = dmjson_get_value(((struct clientv6_args *)data)->clientparam, 1, "valid-lifetime"); - if (valid && *valid != '\0' && atoi(valid) > 0) { - time_t time_value = atoi(valid); + if (valid && *valid != '\0' && DM_STRTOL(valid) > 0) { + time_t time_value = DM_STRTOL(valid); char s_now[sizeof "AAAA-MM-JJTHH:MM:SSZ"]; if (strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%SZ", gmtime(&time_value)) == 0) return -1; @@ -1180,7 +1180,7 @@ static int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { *value = "1"; return 0; } @@ -1213,7 +1213,7 @@ static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { option_enabled = true; if (!b) dmuci_del_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", opt_value); @@ -1268,7 +1268,7 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (dm_validate_unsignedInt(value, RANGE_ARGS{{"0","65535"}}, 1)) return FAULT_9007; - if (dhcpv6_client_s->option_tag && strcmp(dhcpv6_client_s->option_tag, value) == 0) + if (dhcpv6_client_s->option_tag && DM_STRCMP(dhcpv6_client_s->option_tag, value) == 0) break; if (tag_option_exists("dmmap_dhcpv6", "servpool_option", "section_name", section_name(dhcpv6_client_s->client_sect), "option_tag", value)) @@ -1284,7 +1284,7 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { option_enabled = true; break; } @@ -1339,7 +1339,7 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && strcmp(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { option_enabled = true; break; } diff --git a/dmtree/tr181/dns.c b/dmtree/tr181/dns.c index 54560400..0715690f 100644 --- a/dmtree/tr181/dns.c +++ b/dmtree/tr181/dns.c @@ -24,7 +24,7 @@ static unsigned char is_dns_server_in_dmmap(char *chk_ip, char *chk_interface) uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) { dmuci_get_value_by_section_string(s, "ip", &ip); dmuci_get_value_by_section_string(s, "interface", &interface); - if (strcmp(interface, chk_interface) == 0 && strcmp(ip, chk_ip) == 0) { + if (DM_STRCMP(interface, chk_interface) == 0 && DM_STRCMP(ip, chk_ip) == 0) { return 1; } } @@ -48,7 +48,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa bool found = false; dmuci_get_value_by_section_string(s, "added_by_controller", &added_by_controller); - if (strcmp(added_by_controller, "1") == 0) + if (DM_STRCMP(added_by_controller, "1") == 0) continue; dmuci_get_value_by_section_string(s, "ip", &ip); @@ -62,7 +62,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa dmuci_get_value_by_section_list(ss, "dns", &dns_list); if (dns_list != NULL) { uci_foreach_element(dns_list, e) { - if (strcmp(e->name, ip) == 0) { + if (DM_STRCMP(e->name, ip) == 0) { found = true; break; } @@ -75,7 +75,7 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(ss), String}}, 1, &jobj); if (!jobj) break; dmjson_foreach_value_in_array(jobj, arrobj, ipdns, j, 1, "dns-server") { - if (strcmp(ipdns, ip) == 0) { + if (DM_STRCMP(ipdns, ip) == 0) { found = true; break; } @@ -280,7 +280,7 @@ static int get_dns_interface(char *refparam, struct dmctx *ctx, void *data, char dmuci_get_option_value_string("network", linker, "device", &device); if (DM_STRLEN(device)) { - char *sec_name = strchr(device, '@'); + char *sec_name = DM_STRCHR(device, '@'); adm_entry_get_linker_param(ctx, "Device.IP.Interface.", sec_name ? sec_name + 1 : "", value); } } @@ -294,7 +294,7 @@ static int get_dns_type(char *refparam, struct dmctx *ctx, void *data, char *ins dmuci_get_value_by_section_string((struct uci_section *)data, "peerdns", &v); if (*v == '1') { dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &v); - if (strchr(v, ':') == NULL) + if (DM_STRCHR(v, ':') == NULL) *value = "DHCPv4"; else *value = "DHCPv6"; @@ -523,7 +523,7 @@ static int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *i break; case VALUESET: dmuci_get_value_by_section_string((struct uci_section *)data, "ip", &oip); - if (strcmp(oip, value) == 0) + if (DM_STRCMP(oip, value) == 0) return 0; dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface); @@ -576,7 +576,7 @@ static int set_dns_interface(char *refparam, struct dmctx *ctx, void *data, char return 0; } - if (strcmp(interface, linker) == 0) + if (DM_STRCMP(interface, linker) == 0) return 0; if (DM_STRLEN(interface)) { @@ -632,7 +632,7 @@ static int set_nslookupdiagnostics_diagnostics_state(char *refparam, struct dmct return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { NSLOOKUP_STOP set_diagnostics_option("nslookup", "DiagnosticState", value); bbf_set_end_session_flag(ctx, BBF_END_SESSION_NSLOOKUP_DIAGNOSTIC); diff --git a/dmtree/tr181/dsl.c b/dmtree/tr181/dsl.c index 1ef21a18..02d1bb59 100644 --- a/dmtree/tr181/dsl.c +++ b/dmtree/tr181/dsl.c @@ -72,7 +72,7 @@ static struct uci_section *update_create_dmmap_dsl_line(char *curr_id) if (!s) { char instance[16]; - snprintf(instance, sizeof(instance), "%d", atoi(curr_id)); + snprintf(instance, sizeof(instance), "%ld", DM_STRTOL(curr_id)); dmuci_add_section_bbfdm("dmmap", "dsl_line", &s); dmuci_set_value_by_section_bbfdm(s, "id", curr_id); dmuci_set_value_by_section_bbfdm(s, "dsl_line_instance", instance); @@ -90,7 +90,7 @@ static struct uci_section *update_create_dmmap_dsl_channel(char *curr_id) if (!s) { char instance[16]; - snprintf(instance, sizeof(instance), "%d", atoi(curr_id)); + snprintf(instance, sizeof(instance), "%ld", DM_STRTOL(curr_id)); dmuci_add_section_bbfdm("dmmap", "dsl_channel", &s); dmuci_set_value_by_section_bbfdm(s, "id", curr_id); dmuci_set_value_by_section_bbfdm(s, "dsl_channel_instance", instance); @@ -217,17 +217,17 @@ int get_line_linkstatus(char *method, char *id, char **value) { char *link_status = get_dsl_value_without_argument(method, id, "status", "link_status"); - if (strcmp(link_status, "up") == 0) + if (DM_STRCMP(link_status, "up") == 0) *value = "Up"; - else if (strcmp(link_status, "initializing") == 0) + else if (DM_STRCMP(link_status, "initializing") == 0) *value = "Initializing"; - else if (strcmp(link_status, "no_signal") == 0) + else if (DM_STRCMP(link_status, "no_signal") == 0) *value = "NoSignal"; - else if (strcmp(link_status, "disabled") == 0) + else if (DM_STRCMP(link_status, "disabled") == 0) *value = "Disabled"; - else if (strcmp(link_status, "establishing") == 0) + else if (DM_STRCMP(link_status, "establishing") == 0) *value = "EstablishingLink"; - else if (strcmp(link_status, "error") == 0) + else if (DM_STRCMP(link_status, "error") == 0) *value = "Error"; else *value = link_status; @@ -255,7 +255,7 @@ static int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, voi static int get_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "1" : "0"; + *value = (DM_STRCMP(status, "up") == 0) ? "1" : "0"; return 0; } @@ -276,7 +276,7 @@ static int set_DSLLine_Enable(char *refparam, struct dmctx *ctx, void *data, cha static int get_DSLLine_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; + *value = (DM_STRCMP(status, "up") == 0) ? "Up" : "Down"; return 0; } @@ -351,55 +351,55 @@ static char *get_dsl_standard(char *str) { char *dsl_standard; - if(strcmp(str, "gdmt_annexa") == 0) + if(DM_STRCMP(str, "gdmt_annexa") == 0) dsl_standard = "G.992.1_Annex_A"; - else if(strcmp(str, "gdmt_annexb") == 0) + else if(DM_STRCMP(str, "gdmt_annexb") == 0) dsl_standard = "G.992.1_Annex_B"; - else if(strcmp(str, "gdmt_annexc") == 0) + else if(DM_STRCMP(str, "gdmt_annexc") == 0) dsl_standard = "G.992.1_Annex_C"; - else if(strcmp(str, "t1413") == 0) + else if(DM_STRCMP(str, "t1413") == 0) dsl_standard = "T1.413"; - else if(strcmp(str, "t1413_i2") == 0) + else if(DM_STRCMP(str, "t1413_i2") == 0) dsl_standard = "T1.413i2"; - else if(strcmp(str, "glite") == 0) + else if(DM_STRCMP(str, "glite") == 0) dsl_standard = "G.992.2"; - else if(strcmp(str, "etsi_101_388") == 0) + else if(DM_STRCMP(str, "etsi_101_388") == 0) dsl_standard = "ETSI_101_388"; - else if(strcmp(str, "adsl2_annexa") == 0) + else if(DM_STRCMP(str, "adsl2_annexa") == 0) dsl_standard = "G.992.3_Annex_A"; - else if(strcmp(str, "adsl2_annexb") == 0) + else if(DM_STRCMP(str, "adsl2_annexb") == 0) dsl_standard = "G.992.3_Annex_B"; - else if(strcmp(str, "adsl2_annexc") == 0) + else if(DM_STRCMP(str, "adsl2_annexc") == 0) dsl_standard = "G.992.3_Annex_C"; - else if(strcmp(str, "adsl2_annexi") == 0) + else if(DM_STRCMP(str, "adsl2_annexi") == 0) dsl_standard = "G.992.3_Annex_I"; - else if(strcmp(str, "adsl2_annexj") == 0) + else if(DM_STRCMP(str, "adsl2_annexj") == 0) dsl_standard = "G.992.3_Annex_J"; - else if(strcmp(str, "adsl2_annexl") == 0) + else if(DM_STRCMP(str, "adsl2_annexl") == 0) dsl_standard = "G.992.3_Annex_L"; - else if(strcmp(str, "adsl2_annexm") == 0) + else if(DM_STRCMP(str, "adsl2_annexm") == 0) dsl_standard = "G.992.3_Annex_M"; - else if(strcmp(str, "splitterless_adsl2") == 0) + else if(DM_STRCMP(str, "splitterless_adsl2") == 0) dsl_standard = "G.992.4"; - else if(strcmp(str, "adsl2p_annexa") == 0) + else if(DM_STRCMP(str, "adsl2p_annexa") == 0) dsl_standard = "G.992.5_Annex_A"; - else if(strcmp(str, "adsl2p_annexb") == 0) + else if(DM_STRCMP(str, "adsl2p_annexb") == 0) dsl_standard = "G.992.5_Annex_B"; - else if(strcmp(str, "adsl2p_annexc") == 0) + else if(DM_STRCMP(str, "adsl2p_annexc") == 0) dsl_standard = "G.992.5_Annex_C"; - else if(strcmp(str, "adsl2p_annexi") == 0) + else if(DM_STRCMP(str, "adsl2p_annexi") == 0) dsl_standard = "G.992.5_Annex_I"; - else if(strcmp(str, "adsl2p_annexj") == 0) + else if(DM_STRCMP(str, "adsl2p_annexj") == 0) dsl_standard = "G.992.5_Annex_J"; - else if(strcmp(str, "adsl2p_annexm") == 0) + else if(DM_STRCMP(str, "adsl2p_annexm") == 0) dsl_standard = "G.992.5_Annex_M"; - else if(strcmp(str, "vdsl") == 0) + else if(DM_STRCMP(str, "vdsl") == 0) dsl_standard = "G.993.1"; - else if(strcmp(str, "vdsl2_annexa") == 0) + else if(DM_STRCMP(str, "vdsl2_annexa") == 0) dsl_standard = "G.993.2_Annex_A"; - else if(strcmp(str, "vdsl2_annexb") == 0) + else if(DM_STRCMP(str, "vdsl2_annexb") == 0) dsl_standard = "G.993.2_Annex_B"; - else if(strcmp(str, "vdsl2_annexc") == 0) + else if(DM_STRCMP(str, "vdsl2_annexc") == 0) dsl_standard = "G.993.2_Annex_C"; else dsl_standard = str; @@ -489,17 +489,17 @@ static int get_DSLLine_XTSUsed(char *refparam, struct dmctx *ctx, void *data, ch static int get_DSLLine_LineEncoding(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *line_encoding = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "line_encoding"); - if(strcmp(line_encoding, "dmt") == 0) + if(DM_STRCMP(line_encoding, "dmt") == 0) *value = "DMT"; - else if(strcmp(line_encoding, "cap") == 0) + else if(DM_STRCMP(line_encoding, "cap") == 0) *value = "CAP"; - else if(strcmp(line_encoding, "2b1q") == 0) + else if(DM_STRCMP(line_encoding, "2b1q") == 0) *value = "2B1Q"; - else if(strcmp(line_encoding, "43bt") == 0) + else if(DM_STRCMP(line_encoding, "43bt") == 0) *value = "43BT"; - else if(strcmp(line_encoding, "pam") == 0) + else if(DM_STRCMP(line_encoding, "pam") == 0) *value = "PAM"; - else if(strcmp(line_encoding, "qam") == 0) + else if(DM_STRCMP(line_encoding, "qam") == 0) *value = "QAM"; else *value = line_encoding; @@ -517,7 +517,7 @@ static int get_DSLLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void * static int get_DSLLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *current_profile = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "current_profile"); - *value = (current_profile && strcmp(current_profile, "unknown") == 0) ? "" : current_profile; + *value = (current_profile && DM_STRCMP(current_profile, "unknown") == 0) ? "" : current_profile; return 0; } @@ -525,15 +525,15 @@ static int get_DSLLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *d static int get_DSLLine_PowerManagementState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *power_mng_state = get_dsl_value_without_argument("dsl.line", ((struct dsl_line_args*)data)->id, "status", "power_management_state"); - if(strcmp(power_mng_state, "l0") == 0) + if(DM_STRCMP(power_mng_state, "l0") == 0) *value = "L0"; - else if(strcmp(power_mng_state, "l1") == 0) + else if(DM_STRCMP(power_mng_state, "l1") == 0) *value = "L1"; - else if(strcmp(power_mng_state, "l2") == 0) + else if(DM_STRCMP(power_mng_state, "l2") == 0) *value = "L2"; - else if(strcmp(power_mng_state, "l3") == 0) + else if(DM_STRCMP(power_mng_state, "l3") == 0) *value = "L3"; - else if(strcmp(power_mng_state, "l4") == 0) + else if(DM_STRCMP(power_mng_state, "l4") == 0) *value = "L4"; else *value = power_mng_state; @@ -929,7 +929,7 @@ static int get_DSLLineStatsQuarterHour_SeverelyErroredSecs(char *refparam, struc static int get_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "1" : "0"; + *value = (DM_STRCMP(status, "up") == 0) ? "1" : "0"; return 0; } @@ -950,17 +950,17 @@ static int set_DSLChannel_Enable(char *refparam, struct dmctx *ctx, void *data, static int get_DSLChannel_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "status"); - if (strcmp(status, "up") == 0) + if (DM_STRCMP(status, "up") == 0) *value = "Up"; - else if (strcmp(status, "down") == 0) + else if (DM_STRCMP(status, "down") == 0) *value = "Down"; - else if (strcmp(status, "dormant") == 0) + else if (DM_STRCMP(status, "dormant") == 0) *value = "Dormant"; - else if (strcmp(status, "not_present") == 0) + else if (DM_STRCMP(status, "not_present") == 0) *value = "NotPresent"; - else if (strcmp(status, "lower_layer_down") == 0) + else if (DM_STRCMP(status, "lower_layer_down") == 0) *value = "LowerLayerDown"; - else if (strcmp(status, "error") == 0) + else if (DM_STRCMP(status, "error") == 0) *value = "Error"; else *value = "Unknown"; @@ -1008,13 +1008,13 @@ static char *get_dsl_link_encapsulation_standard(char *str) { char *dsl_link_encapsulation_standard = ""; - if(strcmp(str, "adsl2_atm") == 0) + if(DM_STRCMP(str, "adsl2_atm") == 0) dsl_link_encapsulation_standard = "G.992.3_Annex_K_ATM"; - else if(strcmp(str, "adsl2_ptm") == 0) + else if(DM_STRCMP(str, "adsl2_ptm") == 0) dsl_link_encapsulation_standard = "G.992.3_Annex_K_PTM"; - else if(strcmp(str, "vdsl2_atm") == 0) + else if(DM_STRCMP(str, "vdsl2_atm") == 0) dsl_link_encapsulation_standard = "G.993.2_Annex_K_ATM"; - else if(strcmp(str, "vdsl2_ptm") == 0) + else if(DM_STRCMP(str, "vdsl2_ptm") == 0) dsl_link_encapsulation_standard = "G.993.2_Annex_K_PTM"; else dsl_link_encapsulation_standard = "G.994.1"; @@ -1050,7 +1050,7 @@ static int get_DSLChannel_LinkEncapsulationSupported(char *refparam, struct dmct static int get_DSLChannel_LinkEncapsulationUsed(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *link_encapsulation_used = get_dsl_value_without_argument("dsl.channel", ((struct dsl_channel_args*)data)->id, "status", "link_encapsulation_used"); - *value = (strcmp(link_encapsulation_used, "auto") != 0) ? get_dsl_link_encapsulation_standard(link_encapsulation_used) : "G.993.2_Annex_K_PTM"; + *value = (DM_STRCMP(link_encapsulation_used, "auto") != 0) ? get_dsl_link_encapsulation_standard(link_encapsulation_used) : "G.993.2_Annex_K_PTM"; return 0; } diff --git a/dmtree/tr181/dynamicdns.c b/dmtree/tr181/dynamicdns.c index a0fd9be0..4397ab4e 100644 --- a/dmtree/tr181/dynamicdns.c +++ b/dmtree/tr181/dynamicdns.c @@ -62,7 +62,7 @@ static int dmmap_synchronizeDynamicDNSServer(struct dmctx *dmctx, DMNODE *parent found = 0; uci_foreach_sections("ddns", "service", ss) { dmuci_get_value_by_section_string(ss, "service_name", &service_name); - if (strcmp(service_name, dmmap_service_name) == 0) { + if (DM_STRCMP(service_name, dmmap_service_name) == 0) { found = 1; break; } @@ -88,7 +88,7 @@ static int dmmap_synchronizeDynamicDNSServer(struct dmctx *dmctx, DMNODE *parent found = 0; uci_path_foreach_sections(bbfdm, "dmmap_ddns", "ddns_server", ss) { dmuci_get_value_by_section_string(ss, "service_name", &dmmap_service_name); - if (strcmp(service_name, dmmap_service_name) == 0) { + if (DM_STRCMP(service_name, dmmap_service_name) == 0) { found = 1; //Update dmmap with ddns config dmuci_set_value_by_section(ss, "section_name", section_name(s)); @@ -284,9 +284,9 @@ static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, v continue; pch = strtok_r(line, "\t", &spch); - pch = strstr(pch, "\"") + 1; - pch[strchr(pch, '\"')-pch] = 0; - if (strcmp(buf, "") == 0) { + pch = DM_STRSTR(pch, "\"") + 1; + pch[DM_STRCHR(pch, '\"')-pch] = 0; + if (DM_STRCMP(buf, "") == 0) { snprintf(buf, sizeof(buf), "%s", pch); } else { DM_STRNCPY(buf_tmp, buf, sizeof(buf_tmp)); @@ -329,8 +329,8 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void * char status[32] = {0}, *enable, *logdir = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable); - if (*enable == '\0' || strcmp(enable, "0") == 0) { - strcpy(status, "Disabled"); + if (*enable == '\0' || DM_STRCMP(enable, "0") == 0) { + DM_STRNCPY(status, "Disabled", sizeof(status)); } else { char path[64] = {0}; @@ -342,20 +342,20 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void * if (fp != NULL) { char buf[512] = {0}; - strcpy(status, "Connecting"); + DM_STRNCPY(status, "Connecting", sizeof(status)); while (fgets(buf, 512, fp) != NULL) { - if (strstr(buf, "Update successful")) - strcpy(status, "Updated"); - else if (strstr(buf, "ERROR") && strstr(buf, "Please check your configuration")) - strcpy(status, "Error_Misconfigured"); - else if (strstr(buf, "Registered IP")) - strcpy(status, "Connecting"); - else if (strstr(buf, "failed")) - strcpy(status, "Error"); + if (DM_STRSTR(buf, "Update successful")) + DM_STRNCPY(status, "Updated", sizeof(status)); + else if (DM_STRSTR(buf, "ERROR") && DM_STRSTR(buf, "Please check your configuration")) + DM_STRNCPY(status, "Error_Misconfigured", sizeof(status)); + else if (DM_STRSTR(buf, "Registered IP")) + DM_STRNCPY(status, "Connecting", sizeof(status)); + else if (DM_STRSTR(buf, "failed")) + DM_STRNCPY(status, "Error", sizeof(status)); } fclose(fp); } else - strcpy(status, "Error"); + DM_STRNCPY(status, "Error", sizeof(status)); } *value = dmstrdup(status); return 0; @@ -389,8 +389,8 @@ static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, voi char last_err[64] = {0}, *enable = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable); - if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) { - strcpy(last_err, "NO_ERROR"); + if (enable && (*enable == '\0' || DM_STRCMP(enable, "0") == 0)) { + DM_STRNCPY(last_err, "NO_ERROR", sizeof(last_err)); } else { char path[128] = {0}, *logdir = NULL; @@ -401,22 +401,22 @@ static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, voi if (fp != NULL) { char buf[512] = {0}; - strcpy(last_err, "NO_ERROR"); + DM_STRNCPY(last_err, "NO_ERROR", sizeof(last_err)); while (fgets(buf, 512, fp) != NULL) { - if (strstr(buf, "ERROR") && strstr(buf, "Please check your configuration")) - strcpy(last_err, "MISCONFIGURATION_ERROR"); - else if (strstr(buf, "NO valid IP found")) - strcpy(last_err, "DNS_ERROR"); - else if (strstr(buf, "Authentication Failed")) - strcpy(last_err, "AUTHENTICATION_ERROR"); - else if (strstr(buf, "Transfer failed") || (strstr(buf, "WARN") && strstr(buf, "failed"))) - strcpy(last_err, "CONNECTION_ERROR"); - else if (strstr(buf, "Registered IP") || strstr(buf, "Update successful")) - strcpy(last_err, "NO_ERROR"); + if (DM_STRSTR(buf, "ERROR") && DM_STRSTR(buf, "Please check your configuration")) + DM_STRNCPY(last_err, "MISCONFIGURATION_ERROR", sizeof(last_err)); + else if (DM_STRSTR(buf, "NO valid IP found")) + DM_STRNCPY(last_err, "DNS_ERROR", sizeof(last_err)); + else if (DM_STRSTR(buf, "Authentication Failed")) + DM_STRNCPY(last_err, "AUTHENTICATION_ERROR", sizeof(last_err)); + else if (DM_STRSTR(buf, "Transfer failed") || (DM_STRSTR(buf, "WARN") && DM_STRSTR(buf, "failed"))) + DM_STRNCPY(last_err, "CONNECTION_ERROR", sizeof(last_err)); + else if (DM_STRSTR(buf, "Registered IP") || DM_STRSTR(buf, "Update successful")) + DM_STRNCPY(last_err, "NO_ERROR", sizeof(last_err)); } fclose(fp); } else - strcpy(last_err, "MISCONFIGURATION_ERROR"); + DM_STRNCPY(last_err, "MISCONFIGURATION_ERROR", sizeof(last_err)); } *value = dmstrdup(last_err); return 0; @@ -564,8 +564,8 @@ static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx char status[32] = {0}, *enable = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable); - if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) { - strcpy(status, "Disabled"); + if (enable && (*enable == '\0' || DM_STRCMP(enable, "0") == 0)) { + DM_STRNCPY(status, "Disabled", sizeof(status)); } else { char path[128] = {0}, *logdir = NULL; @@ -575,18 +575,18 @@ static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx if (fp != NULL) { char buf[512] = {0}; - strcpy(status, "Registered"); + DM_STRNCPY(status, "Registered", sizeof(status)); while (fgets(buf, 512, fp) != NULL) { - if (strstr(buf, "Registered IP") || strstr(buf, "Update successful")) - strcpy(status, "Registered"); - else if (strstr(buf, "Update needed")) - strcpy(status, "UpdateNeeded"); - else if (strstr(buf, "NO valid IP found")) - strcpy(status, "Error"); + if (DM_STRSTR(buf, "Registered IP") || DM_STRSTR(buf, "Update successful")) + DM_STRNCPY(status, "Registered", sizeof(status)); + else if (DM_STRSTR(buf, "Update needed")) + DM_STRNCPY(status, "UpdateNeeded", sizeof(status)); + else if (DM_STRSTR(buf, "NO valid IP found")) + DM_STRNCPY(status, "Error", sizeof(status)); } fclose(fp); } else - strcpy(status, "Error"); + DM_STRNCPY(status, "Error", sizeof(status)); } *value = dmstrdup(status); return 0; @@ -648,7 +648,7 @@ static int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx } else uptime = "0"; - epoch_time = now - atoi(uptime) + atoi(last_time); + epoch_time = now - DM_STRTOL(uptime) + DM_STRTOL(last_time); if ((ts = gmtime(&epoch_time)) == NULL) return -1; @@ -787,7 +787,7 @@ static int get_DynamicDNSServer_ServerAddress(char *refparam, struct dmctx *ctx, if (*dns_server == '\0') { dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", value); } else { - char *addr = strchr(dns_server, ':'); + char *addr = DM_STRCHR(dns_server, ':'); if (addr) *addr = '\0'; *value = dmstrdup(dns_server); @@ -805,7 +805,7 @@ static void set_server_address(struct uci_section *section, char *value) } else { char new[64] = {0}; - char *addr = dns_server ? strchr(dns_server, ':') : NULL; + char *addr = dns_server ? DM_STRCHR(dns_server, ':') : NULL; if (addr) snprintf(new, sizeof(new), "%s%s", value, addr); else @@ -846,7 +846,7 @@ static int get_DynamicDNSServer_ServerPort(char *refparam, struct dmctx *ctx, vo if (*dns_server == '\0') return 0; - char *port = strchr(dns_server, ':'); + char *port = DM_STRCHR(dns_server, ':'); if (port) *value = dmstrdup(port+1); return 0; @@ -860,7 +860,7 @@ static void set_server_port(struct uci_section *section, char *value) if (*dns_server == '\0') { snprintf(new, sizeof(new), ":%s", value); } else { - char *addr = strchr(dns_server, ':'); + char *addr = DM_STRCHR(dns_server, ':'); if (addr) *addr = '\0'; snprintf(new, sizeof(new), "%s:%s", dns_server, value); } @@ -899,7 +899,7 @@ static int get_DynamicDNSServer_SupportedProtocols(char *refparam, struct dmctx static int get_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "use_https", value); - if (*value[0] == '\0' || strcmp(*value, "0") == 0) + if (*value[0] == '\0' || DM_STRCMP(*value, "0") == 0) *value = "HTTP"; else *value = "HTTPS"; @@ -917,10 +917,10 @@ static int set_DynamicDNSServer_Protocol(char *refparam, struct dmctx *ctx, void return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "use_https", (strcmp(value, "HTTPS") == 0) ? "1" : "0"); + dmuci_set_value_by_section((struct uci_section *)data, "use_https", (DM_STRCMP(value, "HTTPS") == 0) ? "1" : "0"); dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name); uci_foreach_option_eq("ddns", "service", "service_name", service_name, s) { - dmuci_set_value_by_section(s, "use_https", (strcmp(value, "HTTPS") == 0) ? "1" : "0"); + dmuci_set_value_by_section(s, "use_https", (DM_STRCMP(value, "HTTPS") == 0) ? "1" : "0"); } break; } @@ -947,12 +947,12 @@ static int set_DynamicDNSServer_CheckInterval(char *refparam, struct dmctx *ctx, break; case VALUESET: dmuci_get_value_by_section_string((struct uci_section *)data, "check_unit", &check_unit); - if (strcmp(check_unit, "hours") == 0) - check_interval = atoi(value) * 3600; - else if (strcmp(check_unit, "minutes") == 0) - check_interval = atoi(value) * 60; + if (DM_STRCMP(check_unit, "hours") == 0) + check_interval = DM_STRTOL(value) * 3600; + else if (DM_STRCMP(check_unit, "minutes") == 0) + check_interval = DM_STRTOL(value) * 60; else - check_interval = atoi(value); + check_interval = DM_STRTOL(value); snprintf(buf, sizeof(buf), "%d", check_interval); dmuci_set_value_by_section((struct uci_section *)data, "check_interval", buf); @@ -985,12 +985,12 @@ static int set_DynamicDNSServer_RetryInterval(char *refparam, struct dmctx *ctx, break; case VALUESET: dmuci_get_value_by_section_string((struct uci_section *)data, "retry_unit", &retry_unit); - if (strcmp(retry_unit, "hours") == 0) - retry_interval = atoi(value) * 3600; - else if (strcmp(retry_unit, "minutes") == 0) - retry_interval = atoi(value) * 60; + if (DM_STRCMP(retry_unit, "hours") == 0) + retry_interval = DM_STRTOL(value) * 3600; + else if (DM_STRCMP(retry_unit, "minutes") == 0) + retry_interval = DM_STRTOL(value) * 60; else - retry_interval = atoi(value); + retry_interval = DM_STRTOL(value); snprintf(buf, sizeof(buf), "%d", retry_interval); dmuci_set_value_by_section((struct uci_section *)data, "retry_interval", buf); dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name); diff --git a/dmtree/tr181/ethernet.c b/dmtree/tr181/ethernet.c index bc1a6fff..f8188844 100644 --- a/dmtree/tr181/ethernet.c +++ b/dmtree/tr181/ethernet.c @@ -88,7 +88,7 @@ static void get_bridge_port_linker(struct dmctx *ctx, char *device_s_name, char char *management = NULL; dmuci_get_value_by_section_string(bridge_port, "management", &management); - if (management && strcmp(management, "1") == 0) { + if (management && DM_STRCMP(management, "1") == 0) { char linker[512] = {0}; char *port = NULL; @@ -121,7 +121,7 @@ static struct uci_section *is_device_section_exist(char *device) uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { dmuci_get_value_by_section_string(s, "device", &dev); - if (strcmp(dev, device) == 0) + if (DM_STRCMP(dev, device) == 0) return s; } return s; @@ -133,7 +133,7 @@ bool ethernet___check_section_in_curr_section(const char *curr_section, const ch 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) + if (DM_STRCMP(pch, section) == 0) return true; } return false; @@ -167,7 +167,7 @@ static void add_new_dmmap_section(char *macaddr, char*interface, char *section_n dmuci_add_section_bbfdm(DMMAP, "link", &dmmap); dmuci_set_value_by_section(dmmap, "mac", macaddr); dmuci_set_value_by_section(dmmap, "device", interface); - dmuci_set_value_by_section(dmmap, "is_eth", (!strncmp(interface, "atm", 3) || !strncmp(interface, "ptm", 3)) ? "0" : "1"); + dmuci_set_value_by_section(dmmap, "is_eth", (!DM_STRNCMP(interface, "atm", 3) || !DM_STRNCMP(interface, "ptm", 3)) ? "0" : "1"); dmuci_set_value_by_section(dmmap, "section_name", section_name); } @@ -181,7 +181,7 @@ static void create_link(char *sec_name, char *mac_addr) char *dev_sec_name; uci_path_foreach_sections(bbfdm, DMMAP, "link", s) { dmuci_get_value_by_section_string(s, "section_name", &dev_sec_name); - if (strcmp(sec_name, dev_sec_name) == 0) { + if (DM_STRCMP(sec_name, dev_sec_name) == 0) { dmuci_set_value_by_section(s, "mac", macaddr); return; } @@ -194,8 +194,8 @@ 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}; DM_STRNCPY(intf, device, sizeof(intf)); - char *vid = strchr(intf, '.'); - char *macvlan = strchr(intf, '_'); + char *vid = DM_STRCHR(intf, '.'); + char *macvlan = DM_STRCHR(intf, '_'); if (vid != NULL || !macvlan) { if (vid) *vid = '\0'; struct uci_section *dmmap_section = is_device_section_exist(intf); @@ -239,7 +239,7 @@ static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_nod // Skip this interface section if its device option contains '@' or is empty dmuci_get_value_by_section_string(s, "device", &device); - if (*device == 0 || strchr(device, '@')) + if (*device == 0 || DM_STRCHR(device, '@')) continue; dmuci_get_value_by_section_string(s, "macaddr", &macaddr); @@ -304,9 +304,9 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent dmuci_get_value_by_section_string(p->config_section, "type", &type); dmuci_get_value_by_section_string(p->config_section, "name", &name); dmuci_get_value_by_section_string(p->dmmap_section, "is_vlan_ter", &is_vlan); - if (strcmp(type, "bridge") == 0 || - strcmp(type, "untagged") == 0 || - (*name == 0 && strcmp(is_vlan, "1") != 0) || + if (DM_STRCMP(type, "bridge") == 0 || + DM_STRCMP(type, "untagged") == 0 || + (*name == 0 && DM_STRCMP(is_vlan, "1") != 0) || (*name != 0 && !ethernet___check_vlan_termination_section(name))) continue; @@ -473,9 +473,9 @@ static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void dmuci_get_value_by_section_string(s_dev, "type", &type); dmuci_get_value_by_section_string(s_dev, "name", &name); - if (strcmp(type, "bridge") == 0 || - strcmp(type, "untagged") == 0 || - (*name == 0 && strcmp(is_vlan, "1") != 0) || + if (DM_STRCMP(type, "bridge") == 0 || + DM_STRCMP(type, "untagged") == 0 || + (*name == 0 && DM_STRCMP(is_vlan, "1") != 0) || (*name != 0 && !ethernet___check_vlan_termination_section(name))) continue; @@ -603,7 +603,7 @@ static int get_EthernetInterface_LastChange(char *refparam, struct dmctx *ctx, v *value ="0"; uci_foreach_sections("network", "interface", s) { dmuci_get_value_by_section_string(s, "device", &device); - if (0 == strncmp(device, "br-", 3)) { + if (0 == DM_STRNCMP(device, "br-", 3)) { uci_foreach_option_eq("network", "device", "name", device, dev_s) { dmuci_get_value_by_section_list(dev_s, "ports", &uci_list); if (value_exists_in_uci_list(uci_list, ((struct eth_port_args *)data)->ifname)) { @@ -611,7 +611,7 @@ static int get_EthernetInterface_LastChange(char *refparam, struct dmctx *ctx, v } } } else { - if (strstr(device, ((struct eth_port_args *)data)->ifname)) { + if (DM_STRSTR(device, ((struct eth_port_args *)data)->ifname)) { intf_found = 1; } } @@ -675,7 +675,7 @@ static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, v dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "autoneg", &autoneg); - if (autoneg && strcmp(autoneg, "0") == 0) + if (autoneg && DM_STRCMP(autoneg, "0") == 0) dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "speed", value); else *value = "-1"; @@ -691,7 +691,7 @@ static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "-1") == 0) + if (DM_STRCMP(value, "-1") == 0) dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "1"); else { dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "0"); @@ -723,11 +723,11 @@ static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, v dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "autoneg", &autoneg); - if (autoneg && strcmp(autoneg, "0") == 0) { + if (autoneg && DM_STRCMP(autoneg, "0") == 0) { char *duplex = NULL; dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "duplex", &duplex); - *value = (duplex && strcmp(duplex, "full") == 0) ? "Full" : "Half"; + *value = (duplex && DM_STRCMP(duplex, "full") == 0) ? "Full" : "Half"; } else { *value = "Auto"; } @@ -742,7 +742,7 @@ static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Auto") == 0) + if (DM_STRCMP(value, "Auto") == 0) dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "1"); else { dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "0"); @@ -891,7 +891,7 @@ static int get_EthernetLink_Enable(char *refparam, struct dmctx *ctx, void *data dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &int_name); s = get_origin_section_from_config("network", "interface", int_name); dmuci_get_value_by_section_string(s, "disabled", value); - *value = (strcmp(*value, "1") == 0) ? "0" : "1"; + *value = (DM_STRCMP(*value, "1") == 0) ? "0" : "1"; return 0; } @@ -928,7 +928,7 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device); if (DM_STRLEN(device)) { struct uci_section *port_s = NULL; - char *is_bridge = strstr(device, "br-"); + char *is_bridge = DM_STRSTR(device, "br-"); if (is_bridge) { /* Ethernet.Link.{i}. ---> Bridging.Bridge.{i}.Port.{i}. */ @@ -947,7 +947,7 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void DM_STRNCPY(buf, e->name, sizeof(buf)); - char *is_tagged = strchr(buf, '.'); + char *is_tagged = DM_STRCHR(buf, '.'); if (is_tagged) *is_tagged = 0; @@ -955,7 +955,7 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void char *pause = port_s ? dmuci_get_value_by_section_fallback_def(port_s, "pause", "0") : "0"; char *curr_value = dmuci_string_to_boolean(pause) ? "1" : "0"; - if (strcmp(curr_value, default_value) != 0) { + if (DM_STRCMP(curr_value, default_value) != 0) { *value = "1"; return 0; } @@ -968,11 +968,11 @@ static int get_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void } else { /* Ethernet.Link.{i}. ---> Ethernet.Interface.{i}. */ - char *is_mac_vlan = strchr(device, '_'); + char *is_mac_vlan = DM_STRCHR(device, '_'); if (is_mac_vlan) *is_mac_vlan = 0; - char *is_tagged = strchr(device, '.'); + char *is_tagged = DM_STRCHR(device, '.'); if (is_tagged) *is_tagged = 0; @@ -1009,7 +1009,7 @@ static int set_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void dmuci_get_value_by_section_string((struct uci_section *)data, "device", &device); if (DM_STRLEN(device)) { struct uci_section *port_s = NULL; - char *is_bridge = strstr(device, "br-"); + char *is_bridge = DM_STRSTR(device, "br-"); if (is_bridge) { /* Ethernet.Link.{i}. ---> Bridging.Bridge.{i}.Port.{i}. */ @@ -1027,7 +1027,7 @@ static int set_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void DM_STRNCPY(buf, e->name, sizeof(buf)); - char *is_tagged = strchr(buf, '.'); + char *is_tagged = DM_STRCHR(buf, '.'); if (is_tagged) *is_tagged = 0; @@ -1040,11 +1040,11 @@ static int set_EthernetLink_FlowControl(char *refparam, struct dmctx *ctx, void } else { /* Ethernet.Link.{i}. ---> Ethernet.Interface.{i}. */ - char *is_mac_vlan = strchr(device, '_'); + char *is_mac_vlan = DM_STRCHR(device, '_'); if (is_mac_vlan) *is_mac_vlan = 0; - char *is_tagged = strchr(device, '.'); + char *is_tagged = DM_STRCHR(device, '.'); if (is_tagged) *is_tagged = 0; @@ -1138,12 +1138,12 @@ static int get_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void if (br_device_s) dmuci_get_value_by_section_string(br_device_s, "type", &device_s_type); - if (br_device_s && strcmp(device_s_type, "bridge") == 0) { + if (br_device_s && DM_STRCMP(device_s_type, "bridge") == 0) { get_bridge_port_linker(ctx, section_name(br_device_s), value); } else { - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; - char *macvlan = strchr(linker, '_'); + char *macvlan = DM_STRCHR(linker, '_'); if (macvlan) *macvlan = '\0'; adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); } @@ -1186,14 +1186,14 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void if (!link_linker || link_linker[0] == 0) { dmuci_set_value_by_section((struct uci_section *)data, "device", ""); - } else if (strncmp(value, eth_interface, strlen(eth_interface)) == 0 || - strncmp(value, atm_link, strlen(atm_link)) == 0 || - strncmp(value, ptm_link, strlen(ptm_link)) == 0) { + } else if (DM_STRNCMP(value, eth_interface, DM_STRLEN(eth_interface)) == 0 || + DM_STRNCMP(value, atm_link, DM_STRLEN(atm_link)) == 0 || + DM_STRNCMP(value, ptm_link, DM_STRLEN(ptm_link)) == 0) { char *iface_name = NULL; dmuci_set_value_by_section((struct uci_section *)data, "device", link_linker); - dmuci_set_value_by_section((struct uci_section *)data, "is_eth", !strncmp(value, eth_interface, strlen(eth_interface)) ? "1" : "0"); + dmuci_set_value_by_section((struct uci_section *)data, "is_eth", !DM_STRNCMP(value, eth_interface, DM_STRLEN(eth_interface)) ? "1" : "0"); // Check if there is a IP.Interface linked to this Ethernet.Link dmuci_get_value_by_section_string((struct uci_section *)data, "section_name", &iface_name); @@ -1220,12 +1220,12 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void dmuci_set_value_by_section(ppp_s, "device", link_linker); } - } else if (strncmp(value, bridge_port, strlen(bridge_port)) == 0) { + } else if (DM_STRNCMP(value, bridge_port, DM_STRLEN(bridge_port)) == 0) { char br_linker[250] = {0}; DM_STRNCPY(br_linker, link_linker, sizeof(br_linker)); - char *bridge = strchr(br_linker, ':'); + char *bridge = DM_STRCHR(br_linker, ':'); if (bridge) { struct uci_section *s = NULL; char *device_name = NULL; @@ -1250,7 +1250,7 @@ static int set_EthernetLink_LowerLayers(char *refparam, struct dmctx *ctx, void char *device = NULL; dmuci_get_value_by_section_string(s, "device", &device); - if (device && strcmp(device, old_device) == 0) { + if (device && DM_STRCMP(device, old_device) == 0) { dmuci_delete_by_section(s, NULL, NULL); break; } @@ -1486,7 +1486,7 @@ static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type); dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ifname", &ifname); - if (strncmp(type, "8021ad", 6) == 0) { + if (DM_STRNCMP(type, "8021ad", 6) == 0) { // 8021ad device, will have a vlan termination object as its lowerlayer char *inner_vid, *dev_name; @@ -1531,7 +1531,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx // Set ifname and name options of device section to empty value dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", ""); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", ""); - } else if (strncmp(value, eth_link, strlen(eth_link)) == 0) { + } else if (DM_STRNCMP(value, eth_link, DM_STRLEN(eth_link)) == 0) { char new_name[16] = {0}, *type; char *iface_name = NULL; char *old_name = NULL; @@ -1542,7 +1542,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &old_name); dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid", &vid); - if ((strcmp(type, "macvlan") == 0)) { + if ((DM_STRCMP(type, "macvlan") == 0)) { /* type == macvlan */ struct uci_section *s = NULL, *dmmap_s = NULL; @@ -1619,7 +1619,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", vlan_linker); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", new_name); - } else if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) { + } else if (DM_STRNCMP(value, eth_vlan_term, DM_STRLEN(eth_vlan_term)) == 0) { struct uci_section *ss = NULL; char *dev_name, *inner_vid, *vid, new_name[16] = {0}; @@ -1663,7 +1663,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, // Get type option from device section dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type); - if (strcmp(type, "macvlan") != 0) { + if (DM_STRCMP(type, "macvlan") != 0) { /* only when type != macvlan */ char *ifname = NULL; @@ -1678,7 +1678,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid", &old_vid); - if (strcmp(type, "8021ad") == 0) { + if (DM_STRCMP(type, "8021ad") == 0) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "inner_vid", &inner_vid); snprintf(old_name, sizeof(old_name), "%s.%s.%s", ifname, inner_vid, old_vid); snprintf(new_name, sizeof(new_name), "%s.%s.%s", ifname, inner_vid, value); @@ -1696,7 +1696,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(uci_s, "inner_vid", &inner_vid); dmuci_get_value_by_section_string(uci_s, "ifname", &curr_ifname); - if (strcmp(inner_vid, old_vid) == 0 && strcmp(curr_ifname, ifname) == 0) { + if (DM_STRCMP(inner_vid, old_vid) == 0 && DM_STRCMP(curr_ifname, ifname) == 0) { struct uci_section *__s = NULL; char __new_name[32] = {0}; char *curr_name = NULL; @@ -1730,10 +1730,10 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(uci_s, "device", &link_device); dmuci_get_value_by_section_string(uci_s, "mac", &link_macaddr); - if (interface_macaddr && *interface_macaddr && strcmp(link_macaddr, interface_macaddr) != 0) + if (interface_macaddr && *interface_macaddr && DM_STRCMP(link_macaddr, interface_macaddr) != 0) continue; - if (strcmp(link_device, old_name) == 0) { + if (DM_STRCMP(link_device, old_name) == 0) { dmuci_set_value_by_section(uci_s, "device", new_name); break; } @@ -1755,9 +1755,9 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, static int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", value); - if (strcmp(*value, "8021q") == 0) + if (DM_STRCMP(*value, "8021q") == 0) *value = "33024"; - else if (strcmp(*value, "8021ad") == 0) + else if (DM_STRCMP(*value, "8021ad") == 0) *value = "34984"; else *value = "37120"; @@ -1772,9 +1772,9 @@ static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, v return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "33024") == 0) + if (DM_STRCMP(value, "33024") == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", "8021q"); - else if (strcmp(value, "34984") == 0) + else if (DM_STRCMP(value, "34984") == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", "8021ad"); return 0; } @@ -1862,7 +1862,7 @@ static int set_EthernetRMONStats_Enable(char *refparam, struct dmctx *ctx, void static int get_EthernetRMONStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_EthernetRMONStats_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } diff --git a/dmtree/tr181/fast.c b/dmtree/tr181/fast.c index 5b0715ab..55949671 100644 --- a/dmtree/tr181/fast.c +++ b/dmtree/tr181/fast.c @@ -52,7 +52,7 @@ static struct uci_section *update_create_dmmap_fast_line(char *curr_id) if (!s) { char instance[16]; - snprintf(instance, sizeof(instance), "%d", atoi(curr_id)); + snprintf(instance, sizeof(instance), "%ld", DM_STRTOL(curr_id)); dmuci_add_section_bbfdm("dmmap", "fast_line", &s); dmuci_set_value_by_section_bbfdm(s, "id", curr_id); dmuci_set_value_by_section_bbfdm(s, "fast_line_instance", instance); @@ -144,7 +144,7 @@ static int get_FAST_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void static int get_FASTLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_fast_value_without_argument("fast.line", ((struct fast_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "1" : "0"; + *value = (DM_STRCMP(status, "up") == 0) ? "1" : "0"; return 0; } @@ -165,7 +165,7 @@ static int set_FASTLine_Enable(char *refparam, struct dmctx *ctx, void *data, ch static int get_FASTLine_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = get_fast_value_without_argument("fast.line", ((struct fast_line_args*)data)->id, "status", "status"); - *value = (strcmp(status, "up") == 0) ? "Up" : "Down"; + *value = (DM_STRCMP(status, "up") == 0) ? "Up" : "Down"; return 0; } @@ -249,7 +249,7 @@ static int get_FASTLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void list_profile[0] = 0; dmjson_foreach_value_in_array(res, allowed_profiles, profile, idx, 1, "allowed_profiles") { - if (profile && (strcmp(profile, "106a") == 0 || strcmp(profile, "212a") == 0)) + if (profile && (DM_STRCMP(profile, "106a") == 0 || DM_STRCMP(profile, "212a") == 0)) pos += snprintf(&list_profile[pos], sizeof(list_profile) - pos, "%s,", profile); } @@ -265,7 +265,7 @@ static int get_FASTLine_AllowedProfiles(char *refparam, struct dmctx *ctx, void static int get_FASTLine_CurrentProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *current_profile = get_fast_value_without_argument("fast.line", ((struct fast_line_args*)data)->id, "status", "current_profile"); - *value = (current_profile && strcmp(current_profile, "unknown") == 0) ? "" : current_profile; + *value = (current_profile && DM_STRCMP(current_profile, "unknown") == 0) ? "" : current_profile; return 0; } @@ -273,13 +273,13 @@ static int get_FASTLine_CurrentProfile(char *refparam, struct dmctx *ctx, void * static int get_FASTLine_PowerManagementState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *power_mng_state = get_fast_value_without_argument("fast.line", ((struct fast_line_args*)data)->id, "status", "power_management_state"); - if(strcmp(power_mng_state, "l0") == 0) + if(DM_STRCMP(power_mng_state, "l0") == 0) *value = "L0"; - else if(strcmp(power_mng_state, "l1") == 0) + else if(DM_STRCMP(power_mng_state, "l1") == 0) *value = "L2.1"; - else if(strcmp(power_mng_state, "l2") == 0) + else if(DM_STRCMP(power_mng_state, "l2") == 0) *value = "L2.2"; - else if(strcmp(power_mng_state, "l3") == 0) + else if(DM_STRCMP(power_mng_state, "l3") == 0) *value = "L3"; else *value = power_mng_state; diff --git a/dmtree/tr181/firewall.c b/dmtree/tr181/firewall.c index 1f6732b5..b7c3f9de 100644 --- a/dmtree/tr181/firewall.c +++ b/dmtree/tr181/firewall.c @@ -370,9 +370,9 @@ static int get_FirewallChainRule_ExpiryDate(char *refparam, struct dmctx *ctx, v char *expiry_date = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "expiry", &expiry_date); - if (expiry_date && *expiry_date != '\0' && atoi(expiry_date) > 0) { + if (expiry_date && *expiry_date != '\0' && DM_STRTOL(expiry_date) > 0) { char expiry[sizeof "AAAA-MM-JJTHH:MM:SSZ"]; - time_t time_value = atoi(expiry_date); + time_t time_value = DM_STRTOL(expiry_date); strftime(expiry, sizeof expiry, "%Y-%m-%dT%H:%M:%SZ", gmtime(&time_value)); *value = dmstrdup(expiry); @@ -410,7 +410,7 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da if (src == NULL || *src == '\0') return 0; - if (strcmp(src, "*") == 0) { + if (DM_STRCMP(src, "*") == 0) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "src", &src); } else { struct uci_section *s = NULL; @@ -418,7 +418,7 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "name", &zone_name); - if (zone_name && strcmp(zone_name, src) == 0) { + if (zone_name && DM_STRCMP(zone_name, src) == 0) { dmuci_get_value_by_section_list(s, "network", &net_list); break; } @@ -465,7 +465,7 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data if (dest == NULL || *dest == '\0') return 0; - if (strcmp(dest, "*") == 0) { + if (DM_STRCMP(dest, "*") == 0) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "dest", &dest); } else { struct uci_section *s = NULL; @@ -473,7 +473,7 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "name", &zone_name); - if (zone_name && strcmp(zone_name, dest) == 0) { + if (zone_name && DM_STRCMP(zone_name, dest) == 0) { dmuci_get_value_by_section_list(s, "network", &net_list); break; } @@ -534,7 +534,7 @@ static int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip); DM_STRNCPY(buf, destip, sizeof(buf)); - pch = strchr(buf, '/'); + pch = DM_STRCHR(buf, '/'); if (pch) *pch = '\0'; *value = dmstrdup(buf); return 0; @@ -549,14 +549,14 @@ static int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha if (*destip == '\0') return 0; - pch = strchr(destip, '/'); + pch = DM_STRCHR(destip, '/'); if (pch) { *value = destip; } else { char *family; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "family", &family); - dmasprintf(value, "%s/%s", destip, strcmp(family, "ipv6") == 0 ? "128" : "32"); + dmasprintf(value, "%s/%s", destip, DM_STRCMP(family, "ipv6") == 0 ? "128" : "32"); } return 0; } @@ -568,7 +568,7 @@ static int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip); DM_STRNCPY(buf, srcip, sizeof(buf)); - pch = strchr(buf, '/'); + pch = DM_STRCHR(buf, '/'); if (pch) *pch = '\0'; *value = dmstrdup(buf); @@ -584,14 +584,14 @@ static int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c if (*srcip == '\0') return 0; - pch = strchr(srcip, '/'); + pch = DM_STRCHR(srcip, '/'); if (pch) { *value = srcip; } else { char *family; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "family", &family); - dmasprintf(value, "%s/%s", srcip, strcmp(family, "ipv6") == 0 ? "128" : "32"); + dmasprintf(value, "%s/%s", srcip, DM_STRCMP(family, "ipv6") == 0 ? "128" : "32"); } return 0; } @@ -616,7 +616,7 @@ static int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char return 0; while (fgets (buf , 256 , fp) != NULL) { sscanf(buf, "%31s %15s", protocol, protocol_nbr); - if (strcmp(protocol, v) == 0) { + if (DM_STRCMP(protocol, v) == 0) { *value = dmstrdup(protocol_nbr); fclose(fp); return 0; @@ -633,9 +633,9 @@ static int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, cha dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v); v = dmstrdup(v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); if (tmp) *tmp = '\0'; if (*v == '\0') { @@ -652,9 +652,9 @@ static int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void char *tmp, *v; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); *value = (tmp) ? tmp+1 : "-1"; return 0; } @@ -666,9 +666,9 @@ static int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, c dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v); v = dmstrdup(v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); if (tmp) *tmp = '\0'; if (*v == '\0') { @@ -685,9 +685,9 @@ static int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi char *tmp, *v; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); *value = (tmp) ? tmp+1 : "-1"; return 0; } @@ -819,10 +819,10 @@ static int set_level_default_policy(char *refparam, struct dmctx *ctx, void *dat return FAULT_9007; break; case VALUESET: - if (strcmp(value, "Drop") == 0) { + if (DM_STRCMP(value, "Drop") == 0) { dmuci_set_value("firewall", "@defaults[0]", "input", "DROP"); dmuci_set_value("firewall", "@defaults[0]", "output", "DROP"); - } else if (strcmp(value, "Accept") == 0) { + } else if (DM_STRCMP(value, "Accept") == 0) { dmuci_set_value("firewall", "@defaults[0]", "input", "ACCEPT"); dmuci_set_value("firewall", "@defaults[0]", "output", "ACCEPT"); } else { @@ -1015,7 +1015,7 @@ static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *v dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, type, &option); if (*value == '\0') { - dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, ""); + dmuci_set_value_by_section((option && DM_STRCMP(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, ""); } else { adm_entry_get_linker_value(ctx, value, &iface); if (iface && iface[0] != '\0') { @@ -1028,7 +1028,7 @@ static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *v char *zone_name; dmuci_get_value_by_section_string(s, "name", &zone_name); - dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, zone_name); + dmuci_set_value_by_section((option && DM_STRCMP(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, zone_name); break; } } @@ -1124,11 +1124,11 @@ static int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, c return FAULT_9007; break; case VALUESET: - if (strcmp(value, "4") == 0) + if (DM_STRCMP(value, "4") == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", "ipv4"); - else if (strcmp(value, "6") == 0) + else if (DM_STRCMP(value, "6") == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", "ipv6"); - else if (strcmp(value, "-1") == 0) + else if (DM_STRCMP(value, "-1") == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", ""); break; } @@ -1147,7 +1147,7 @@ static int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip); DM_STRNCPY(buf, destip, sizeof(buf)); - pch = strchr(buf, '/'); + pch = DM_STRCHR(buf, '/'); if (pch) snprintf(new, sizeof(new), "%s%s", value, pch); else @@ -1169,11 +1169,11 @@ static int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha break; case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip); - pch = strchr(destip, '/'); + pch = DM_STRCHR(destip, '/'); if (pch) *pch = '\0'; - pch = strchr(value, '/'); + pch = DM_STRCHR(value, '/'); snprintf(new, sizeof(new), "%s%s", destip, pch); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_ip", new); @@ -1194,7 +1194,7 @@ static int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip); DM_STRNCPY(buf, srcip, sizeof(buf)); - pch = strchr(buf, '/'); + pch = DM_STRCHR(buf, '/'); if (pch) snprintf(new, sizeof(new), "%s%s", value, pch); else @@ -1216,11 +1216,11 @@ static int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c break; case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip); - pch = strchr(srcip, '/'); + pch = DM_STRCHR(srcip, '/'); if (pch) *pch = '\0'; - pch = strchr(value, '/'); + pch = DM_STRCHR(value, '/'); snprintf(new, sizeof(new), "%s%s", srcip, pch); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_ip", new); @@ -1256,9 +1256,9 @@ static int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, cha if (*value == '-') value = ""; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); if (tmp == NULL) snprintf(buffer, sizeof(buffer), "%s", value); else @@ -1282,9 +1282,9 @@ static int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v); buf = dmstrdup(v); v = buf; - tmp = strchr(buf, ':'); + tmp = DM_STRCHR(buf, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); if (tmp) *tmp = '\0'; if (*value == '-') @@ -1311,9 +1311,9 @@ static int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, c if (*value == '-') value = ""; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v); - tmp = strchr(v, ':'); + tmp = DM_STRCHR(v, ':'); if (tmp == NULL) - tmp = strchr(v, '-'); + tmp = DM_STRCHR(v, '-'); if (tmp == NULL) snprintf(buffer, sizeof(buffer), "%s", value); else @@ -1337,9 +1337,9 @@ static int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v); buf = dmstrdup(v); v = buf; - tmp = strchr(buf, ':'); + tmp = DM_STRCHR(buf, ':'); if (tmp == NULL) - tmp = strchr(buf, '-'); + tmp = DM_STRCHR(buf, '-'); if (tmp) *tmp = '\0'; if (*value == '-') diff --git a/dmtree/tr181/gre.c b/dmtree/tr181/gre.c index ce5d18f6..7c434416 100644 --- a/dmtree/tr181/gre.c +++ b/dmtree/tr181/gre.c @@ -147,7 +147,7 @@ static int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *dat dmuci_get_value_by_section_string(s, "device", &device); snprintf(device_buf, sizeof(device_buf), "@%s", section_name(((struct dmmap_dup *)data)->config_section)); - if (!device || strcmp(device, device_buf) != 0) + if (!device || DM_STRCMP(device, device_buf) != 0) continue; get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section); diff --git a/dmtree/tr181/hosts.c b/dmtree/tr181/hosts.c index 890079ca..1a545b62 100644 --- a/dmtree/tr181/hosts.c +++ b/dmtree/tr181/hosts.c @@ -112,7 +112,7 @@ static int get_HostsHost_Layer1Interface(char *refparam, struct dmctx *ctx, void { char *linker = dmjson_get_value((json_object *)data, 1, "device"); char *type = dmjson_get_value((json_object *)data, 1, "interface_type"); - if (strcmp(type, "Wi-Fi") == 0) + if (DM_STRCMP(type, "Wi-Fi") == 0) adm_entry_get_linker_param(ctx, "Device.WiFi.Radio.", linker, value); else adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value); diff --git a/dmtree/tr181/ieee1905.c b/dmtree/tr181/ieee1905.c index f5eeb3dd..47c2ceb3 100644 --- a/dmtree/tr181/ieee1905.c +++ b/dmtree/tr181/ieee1905.c @@ -318,35 +318,35 @@ static int ubus_ieee1905_info_options(const char *option1, const char *option2, static char *get_datamodel_media_type(const char *media) { - if (!strcmp(media, "IEEE 802_3U_FAST_ETHERNET")) + if (!DM_STRCMP(media, "IEEE 802_3U_FAST_ETHERNET")) return "IEEE 802.3u"; - else if (!strcmp(media, "IEEE 802_3AB_GIGABIT_ETHERNET")) + else if (!DM_STRCMP(media, "IEEE 802_3AB_GIGABIT_ETHERNET")) return "IEEE 802.3ab"; - else if (!strcmp(media, "IEEE 802_11B_2_4_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11B_2_4_GHZ")) return "IEEE 802.11b"; - else if (!strcmp(media, "IEEE 802_11G_2_4_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11G_2_4_GHZ")) return "IEEE 802.11g"; - else if (!strcmp(media, "IEEE 802_11A_5_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11A_5_GHZ")) return "IEEE 802.11a"; - else if (!strcmp(media, "IEEE 802_11N_2_4_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11N_2_4_GHZ")) return "IEEE 802.11n 2.4"; - else if (!strcmp(media, "IEEE 802_11N_5_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11N_5_GHZ")) return "IEEE 802.11n 5.0"; - else if (!strcmp(media, "IEEE 802_11AC_5_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11AC_5_GHZ")) return "IEEE 802.11ac"; - else if (!strcmp(media, "IEEE 802_11AX_2_4_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11AX_2_4_GHZ")) return "IEEE 802.11ax 2.4"; - else if (!strcmp(media, "IEEE 802_11AX_5_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11AX_5_GHZ")) return "IEEE 802.11ax 5.0"; - else if (!strcmp(media, "IEEE 802_11AD_60_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11AD_60_GHZ")) return "IEEE 802.11ad"; - else if (!strcmp(media, "IEEE 802_11AF_GHZ")) + else if (!DM_STRCMP(media, "IEEE 802_11AF_GHZ")) return "IEEE 802.11af"; - else if (!strcmp(media, "IEEE 1901_WAVELET")) + else if (!DM_STRCMP(media, "IEEE 1901_WAVELET")) return "IEEE 1901 Wavelet"; - else if (!strcmp(media, "IEEE 1901_FFT")) + else if (!DM_STRCMP(media, "IEEE 1901_FFT")) return "IEEE 1901 FFT"; - else if (!strcmp(media, "IEEE MOCA_V1_1")) + else if (!DM_STRCMP(media, "IEEE MOCA_V1_1")) return "MoCAv1.1"; else return (char *)media; @@ -1288,15 +1288,15 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceInterface_Role(char *refpa { char *role = dmjson_get_value((json_object *)data, 1, "role"); - if (!strcmp(role, "ap")) + if (!DM_STRCMP(role, "ap")) *value = "AP"; - else if (!strcmp(role, "sta")) + else if (!DM_STRCMP(role, "sta")) *value = "non-AP/non-PCP STA"; - else if (!strcmp(role, "p2p_client")) + else if (!DM_STRCMP(role, "p2p_client")) *value = "Wi-Fi P2P Client"; - else if (!strcmp(role, "p2p_go")) + else if (!DM_STRCMP(role, "p2p_go")) *value = "Wi-Fi P2P Group Owner"; - else if (!strcmp(role, "pcp")) + else if (!DM_STRCMP(role, "pcp")) *value = "802.11adPCP"; else *value = role; @@ -1308,7 +1308,7 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceInterface_Role(char *refpa static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceInterface_APChannelBand(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val = dmjson_get_value((json_object *)data, 1, "bandwidth"); - int bw = atoi(val); + int bw = DM_STRTOL(val); switch (bw) { case 20: @@ -1338,7 +1338,7 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceInterface_FrequencyIndex1( { char *val = dmjson_get_value((json_object *)data, 1, "freq_seg0_idx"); char freq_str[3] = {0}; - int freq = atoi(val); + int freq = DM_STRTOL(val); snprintf(freq_str, 3, "%02x", freq); @@ -1352,7 +1352,7 @@ static int get_IEEE1905ALNetworkTopologyIEEE1905DeviceInterface_FrequencyIndex2( { char *val = dmjson_get_value((json_object *)data, 1, "freq_seg1_idx"); char freq_str[3] = {0}; - int freq = atoi(val); + int freq = DM_STRTOL(val); snprintf(freq_str, 3, "%02x", freq); *value = dmstrdup(freq_str); diff --git a/dmtree/tr181/interfacestack.c b/dmtree/tr181/interfacestack.c index 85bec937..c90a251f 100644 --- a/dmtree/tr181/interfacestack.c +++ b/dmtree/tr181/interfacestack.c @@ -131,7 +131,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre if (strcmp(section_name(s), "loopback") == 0 || *proto == '\0' || - strchr(device_s, '@')) + DM_STRCHR(device_s, '@')) continue; // The higher layer is Device.IP.Interface.{i}. @@ -143,7 +143,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre higheralias = get_alias_by_section("dmmap_network", "interface", s, "ip_int_alias"); snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : ""); - if (strstr(proto, "ppp")) { + if (DM_STRSTR(proto, "ppp")) { // The lower layer is Device.PPP.Interface.{i}. layer_inst = get_instance_by_section(dmctx->instance_mode, "dmmap_network", "interface", "section_name", section_name(s), "ppp_int_instance", "ppp_int_alias"); if (*layer_inst == '\0') @@ -179,7 +179,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre if (device[0] != '\0') { DM_STRNCPY(linker, device, sizeof(linker)); - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; } else { struct uci_section *ss = NULL; @@ -208,7 +208,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre uci_foreach_sections("network", "interface", s) { char *proto; dmuci_get_value_by_section_string(s, "proto", &proto); - if (!strstr(proto, "ppp")) + if (!DM_STRSTR(proto, "ppp")) continue; // The higher layer is Device.PPP.Interface.{i}. @@ -245,7 +245,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre // The lower layer is Device.Ethernet.Link.{i}. char linker[32] = {0}; DM_STRNCPY(linker, ppp_device, sizeof(linker)); - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; adm_entry_get_linker_param(dmctx, "Device.Ethernet.Link.", linker, &value); loweralias = get_alias_by_section("dmmap", "link", s, "link_alias"); @@ -272,9 +272,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre dmuci_get_value_by_section_string(s, "type", &type); dmuci_get_value_by_section_string(s, "name", &name); dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (strcmp(type, "bridge") == 0 || - strcmp(type, "untagged") == 0 || - (*name == 0 && strcmp(is_vlan, "1") != 0) || + if (DM_STRCMP(type, "bridge") == 0 || + DM_STRCMP(type, "untagged") == 0 || + (*name == 0 && DM_STRCMP(is_vlan, "1") != 0) || (*name != 0 && !ethernet___check_vlan_termination_section(name))) continue; @@ -289,7 +289,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *higheralias ? higheralias : *layer_inst ? "cpe-" : "", (*higheralias == '\0' && *layer_inst) ? layer_inst : ""); // The lower layer can be Device.Ethernet.VLANTermination.{i}. or Device.Ethernet.Link.{i}. - if (strncmp(type, "8021ad", 6) == 0) { + if (DM_STRNCMP(type, "8021ad", 6) == 0) { // The lower layer is Device.Ethernet.VLANTermination.{i}. struct uci_section *vlan_sect = NULL; char *inner_vid = NULL; @@ -347,7 +347,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre struct uci_section *br_device_s = ethernet___get_device_section(linker); if (br_device_s) dmuci_get_value_by_section_string(br_device_s, "type", &device_s_type); - if (br_device_s && strcmp(device_s_type, "bridge") == 0) { + if (br_device_s && DM_STRCMP(device_s_type, "bridge") == 0) { // The lower layer is Device.Bridging.Bridge.{i}.Port.{i}. struct uci_section *dmmap_section, *port = NULL; @@ -359,7 +359,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre dmuci_get_value_by_section_string(dmmap_section, "bridge_instance", &br_inst); 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) { + if (mg && DM_STRCMP(mg, "1") == 0) { char *device, linker_buf[512] = {0}; dmuci_get_value_by_section_string(port, "port", &device); @@ -373,9 +373,9 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre } } else { // The lower layer is Device.Ethernet.Interface.{i}. - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; - char *macvlan = strchr(linker, '_'); + char *macvlan = DM_STRCHR(linker, '_'); if (macvlan) *macvlan = '\0'; struct uci_section *eth_port_sect = NULL, *eth_port_dmms = NULL; @@ -419,7 +419,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre char *mg = NULL; dmuci_get_value_by_section_string(port, "management", &mg); - if (mg && strcmp(mg, "1") == 0) { + if (mg && DM_STRCMP(mg, "1") == 0) { char *device, linker[512] = {0}; dmuci_get_value_by_section_string(port, "port", &device); @@ -440,7 +440,7 @@ 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, sd) { char *mg = NULL; dmuci_get_value_by_section_string(sd, "management", &mg); - if (mg && strcmp(mg, "1") == 0) + if (mg && DM_STRCMP(mg, "1") == 0) continue; char *vb = NULL, *device, linker[512] = {0}; @@ -495,7 +495,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre // The lower layer is Device.ATM.Link.{i}. if (!found && value == NULL) { - char *tag = strchr(device, '.'); + char *tag = DM_STRCHR(device, '.'); if (tag) *tag = '\0'; adm_entry_get_linker_param(dmctx, "Device.ATM.Link.", device, &value); } @@ -513,7 +513,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre // The lower layer is Device.PTM.Link.{i}. if (!found && value == NULL) { - char *tag = strchr(device, '.'); + char *tag = DM_STRCHR(device, '.'); if (tag) *tag = '\0'; adm_entry_get_linker_param(dmctx, "Device.PTM.Link.", device, &value); } @@ -531,7 +531,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre // The lower layer is Device.Ethernet.Interface.{i}. if (!found && value == NULL) { - char *tag = strchr(device, '.'); + char *tag = DM_STRCHR(device, '.'); if (tag) *tag = '\0'; adm_entry_get_linker_param(dmctx, "Device.Ethernet.Interface.", device, &value); } @@ -555,7 +555,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre goto end; // The lower layer is Device.WiFi.Radio.{i}. - if(strcmp(package, "wireless") == 0) { + if(DM_STRCMP(package, "wireless") == 0) { snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : ""); @@ -588,7 +588,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre } // The lower layer is Device.DSL.Channel.{i}. - if(strcmp(package, "dsl:atm") == 0) { + if(DM_STRCMP(package, "dsl:atm") == 0) { snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : ""); @@ -610,7 +610,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre } // The lower layer is Device.DSL.Line.{i}. - if(strcmp(package, "dsl:ptm") == 0) { + if(DM_STRCMP(package, "dsl:ptm") == 0) { snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : ""); diff --git a/dmtree/tr181/ip.c b/dmtree/tr181/ip.c index ceacfa70..f39cd36c 100644 --- a/dmtree/tr181/ip.c +++ b/dmtree/tr181/ip.c @@ -49,7 +49,7 @@ static int get_linker_ipv6_prefix(char *refparam, struct dmctx *dmctx, void *dat char *assign = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "0") == 0) { + if (assign && DM_STRCMP(assign, "0") == 0) { char *address = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "address"); char *mask = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "mask"); dmasprintf(linker, "%s/%s", address, mask); @@ -112,7 +112,7 @@ static void remove_unused_firewall_zone_sections(void) get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(s), &dmmap_section); dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &zone_added); - if (zone_added && strcmp(zone_added, "1") == 0) + if (zone_added && DM_STRCMP(zone_added, "1") == 0) continue; dmuci_get_value_by_section_string(s, "name", &name); @@ -141,8 +141,8 @@ static bool proc_intf6_line_exists(char *parent_section, char *address) dmuci_get_value_by_section_string(s, "parent_section", &parent_s); dmuci_get_value_by_section_string(s, "address", &addr); - if (parent_s && strcmp(parent_s, parent_section) == 0 && - addr && strcmp(addr, address) == 0) + if (parent_s && DM_STRCMP(parent_s, parent_section) == 0 && + addr && DM_STRCMP(addr, address) == 0) return true; } return false; @@ -162,8 +162,8 @@ static void dmmap_synchronize_ipv6_address_link_local(char *parent_section) dmuci_get_value_by_section_string(s, "parent_section", &parent_s); dmuci_get_value_by_section_string(s, "link_local", &link_local); - if ((parent_s && strcmp(parent_s, parent_section) != 0) || - (link_local && strcmp(link_local, "1") != 0)) + if ((parent_s && DM_STRCMP(parent_s, parent_section) != 0) || + (link_local && DM_STRCMP(link_local, "1") != 0)) continue; dmuci_get_value_by_section_string(s, "address", &address); @@ -178,7 +178,7 @@ static void dmmap_synchronize_ipv6_address_link_local(char *parent_section) if (parse_proc_intf6_line(buf, device, ipstr, sizeof(ipstr))) continue; - if (address && strcmp(address, ipstr) == 0) { + if (address && DM_STRCMP(address, ipstr) == 0) { found = true; break; } @@ -217,7 +217,7 @@ static struct uci_section *check_dmmap_network_interface_ipv4(char *dmmap_file_n uci_path_foreach_option_eq(bbfdm, dmmap_file_name, dmmap_sec_name, "parent_section", parent_section, dmmap_section) { dmuci_get_value_by_section_string(dmmap_section, "section_name", &sec_name); - if (strcmp(sec_name, section_name) == 0) + if (DM_STRCMP(sec_name, section_name) == 0) return dmmap_section; } @@ -243,7 +243,7 @@ static struct uci_section *update_dmmap_network_interface(char *dmmap_file_name, uci_path_foreach_option_eq(bbfdm, dmmap_file_name, dmmap_sec_name, "parent_section", parent_section, dmmap_section) { dmuci_get_value_by_section_string(dmmap_section, "section_name", &sec_name); dmuci_get_value_by_section_string(dmmap_section, option, &opt_value); - if (strcmp(sec_name, section_name) == 0 && strcmp(opt_value, value) == 0) + if (DM_STRCMP(sec_name, section_name) == 0 && DM_STRCMP(opt_value, value) == 0) return dmmap_section; } @@ -268,7 +268,7 @@ static void synchronize_intf_ipv6_sections_with_dmmap(void) uci_path_foreach_sections_safe(bbfdm, "dmmap_network_ipv6", "intf_ipv6", stmp, s) { dmuci_get_value_by_section_string(s, "link_local", &link_local); - if (link_local && *link_local != '\0' && strcmp(link_local, "1") == 0) + if (link_local && *link_local != '\0' && DM_STRCMP(link_local, "1") == 0) continue; dmuci_get_value_by_section_string(s, "section_name", &dmmap_intf_s); @@ -278,7 +278,7 @@ static void synchronize_intf_ipv6_sections_with_dmmap(void) ss = get_origin_section_from_config("network", "interface", dmmap_intf_s); dmuci_get_value_by_section_string(ss, "ip6addr", &ip6addr); - if (ip6addr && *ip6addr != '\0' && strcmp(ip6addr, dmmap_address) == 0) + if (ip6addr && *ip6addr != '\0' && DM_STRCMP(ip6addr, dmmap_address) == 0) continue; dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dmmap_intf_s, String}}, 1, &res); @@ -286,7 +286,7 @@ static void synchronize_intf_ipv6_sections_with_dmmap(void) dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-address") { char *address = dmjson_get_value(ipv6_obj, 1, "address"); - if (address && *address && strcmp(address, dmmap_address) == 0) { + if (address && *address && DM_STRCMP(address, dmmap_address) == 0) { found = true; break; } @@ -299,7 +299,7 @@ static void synchronize_intf_ipv6_sections_with_dmmap(void) dmjson_foreach_obj_in_array(res, arrobj, ipv6_obj, i, 1, "ipv6-prefix-assignment") { char *address = dmjson_get_value(ipv6_obj, 2, "local-address", "address"); - if (address && *address && strcmp(address, dmmap_address) == 0) { + if (address && *address && DM_STRCMP(address, dmmap_address) == 0) { found = true; break; } @@ -326,7 +326,7 @@ static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void) ss = get_origin_section_from_config("network", "interface", dmmap_intf_s); dmuci_get_value_by_section_string(ss, "ip6prefix", &ip6prefix); - if (ip6prefix && *ip6prefix != '\0' && strcmp(ip6prefix, dmmap_address) == 0) + if (ip6prefix && *ip6prefix != '\0' && DM_STRCMP(ip6prefix, dmmap_address) == 0) continue; dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dmmap_intf_s, String}}, 1, &res); @@ -339,7 +339,7 @@ static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void) continue; snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); - if (strcmp(ipv6_prefix, dmmap_address) == 0) { + if (DM_STRCMP(ipv6_prefix, dmmap_address) == 0) { found = true; break; } @@ -357,7 +357,7 @@ static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void) continue; snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask); - if (strcmp(ipv6_prefix, dmmap_address) == 0) { + if (DM_STRCMP(ipv6_prefix, dmmap_address) == 0) { found = true; break; } @@ -383,19 +383,19 @@ static int delete_ip_intertace_instance(struct uci_section *s) char *proto = NULL; dmuci_get_value_by_section_string(int_ss, "device", &int_device); - if (strcmp(section_name(int_ss), int_sec_name) != 0 && strcmp(int_device, buf) != 0) + if (strcmp(section_name(int_ss), int_sec_name) != 0 && DM_STRCMP(int_device, buf) != 0) continue; char *device = get_device( section_name(int_ss)); /* Remove the device section corresponding to this interface if exists and no interface used it And it doesn't link to Device.Bridging.Bridge. Object */ - if (device && *device && strncmp(device, "br-", 3) != 0) { + if (device && *device && DM_STRNCMP(device, "br-", 3) != 0) { bool device_found = false; uci_foreach_sections("network", "interface", ss) { dmuci_get_value_by_section_string(ss, "device", &int_device); - if (strcmp(section_name(ss), section_name(int_ss)) != 0 && strcmp(int_device, buf) != 0 && strstr(int_device, device)) { + if (strcmp(section_name(ss), section_name(int_ss)) != 0 && DM_STRCMP(int_device, buf) != 0 && DM_STRSTR(int_device, device)) { device_found = true; break; } @@ -405,7 +405,7 @@ static int delete_ip_intertace_instance(struct uci_section *s) uci_foreach_option_eq_safe("network", "device", "name", device, stmp, ss) { char *device_type; dmuci_get_value_by_section_string(ss, "type", &device_type); - if (strcmp(device_type, "untagged") == 0) dmuci_delete_by_section(ss, NULL, NULL); + if (DM_STRCMP(device_type, "untagged") == 0) dmuci_delete_by_section(ss, NULL, NULL); break; } } @@ -432,7 +432,7 @@ static int delete_ip_intertace_instance(struct uci_section *s) dmuci_get_value_by_section_string(int_ss, "proto", &proto); - if (strcmp(proto, "dhcp") == 0) { + if (DM_STRCMP(proto, "dhcp") == 0) { struct uci_section *dhcpv4_client_s = get_dup_section_in_dmmap_opt("dmmap_dhcp_client", "interface", "iface_name", section_name(int_ss)); if (dhcpv4_client_s) { @@ -455,7 +455,7 @@ static int delete_ip_intertace_instance(struct uci_section *s) } } - if (strcmp(proto, "dhcpv6") == 0) { + if (DM_STRCMP(proto, "dhcpv6") == 0) { struct uci_section *dhcpv6_client_s = get_dup_section_in_dmmap_opt("dmmap_dhcpv6", "interface", "iface_name", section_name(int_ss)); if (dhcpv6_client_s) { @@ -465,7 +465,7 @@ static int delete_ip_intertace_instance(struct uci_section *s) } } - if (strncmp(proto, "ppp", 3) == 0) { + if (DM_STRNCMP(proto, "ppp", 3) == 0) { struct uci_section *ppp_s = get_dup_section_in_dmmap_opt("dmmap_ppp", "interface", "iface_name", section_name(int_ss)); if (ppp_s) { @@ -497,10 +497,10 @@ static bool interface_section_with_dhcpv6_exists(const char *sec_name) char *device; dmuci_get_value_by_section_string(s, "device", &device); - if (strcmp(device, buf) == 0) { + if (DM_STRCMP(device, buf) == 0) { char *proto; dmuci_get_value_by_section_string(s, "proto", &proto); - if (strcmp(proto, "dhcpv6") == 0) + if (DM_STRCMP(proto, "dhcpv6") == 0) return true; } } @@ -552,11 +552,11 @@ 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 || interface_section_with_dhcpv6_exists(section_name(((struct intf_ip_args *)data)->interface_sec))) + if (DM_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, "device", &device); - if (strchr(device, '@')) { + if (DM_STRCHR(device, '@')) { dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL); } else { dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, option_name, ""); @@ -566,7 +566,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 || interface_section_with_dhcpv6_exists(section_name((struct uci_section *)data))) + if (DM_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)); @@ -580,7 +580,7 @@ static int delObjIPInterfaceIPv6(void *data, unsigned char del_action, char *dmm get_dmmap_section_of_config_section(dmmap_file_name, section_type, section_name(s), &dmmap_s); dmuci_delete_by_section(dmmap_s, NULL, NULL); - } else if (strcmp(device, buf) == 0) { + } else if (DM_STRCMP(device, buf) == 0) { get_dmmap_section_of_config_section(dmmap_file_name, section_type, section_name(s), &dmmap_s); dmuci_delete_by_section(dmmap_s, NULL, NULL); @@ -613,7 +613,7 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void if (strcmp(section_name(p->config_section), "loopback") == 0 || *proto == '\0' || - strchr(device, '@')) + DM_STRCHR(device, '@')) continue; // check if firewall zone exists @@ -642,7 +642,7 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_ uci_foreach_sections("network", "interface", intf_s) { dmuci_get_value_by_section_string(intf_s, "device", &device); - if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(device, buf) != 0) + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && DM_STRCMP(device, buf) != 0) continue; dmmap_s = check_dmmap_network_interface_ipv4("dmmap_network_ipv4", "intf_ipv4", section_name(parent_sec), section_name(intf_s)); @@ -655,7 +655,7 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_ ipaddr = dmjson_get_value(ipv4_obj, 1, "address"); } - if (*ipaddr == '\0' && added_by_controller && strcmp(added_by_controller, "1") != 0) + if (*ipaddr == '\0' && added_by_controller && DM_STRCMP(added_by_controller, "1") != 0) continue; if (dmmap_s == NULL) @@ -685,7 +685,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_ uci_foreach_sections("network", "interface", intf_s) { dmuci_get_value_by_section_string(intf_s, "device", &device); - if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(device, buf) != 0) + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && DM_STRCMP(device, buf) != 0) continue; dmuci_get_value_by_section_string(intf_s, "ip6addr", &ip6addr); @@ -740,7 +740,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_ } // Get ipv6 LinkLocal address - if (!strchr(device, '@')) { + if (!DM_STRCHR(device, '@')) { dmmap_synchronize_ipv6_address_link_local(section_name(parent_sec)); @@ -748,7 +748,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_ char *link_local = NULL; dmuci_get_value_by_section_string(dmmap_s, "link_local", &link_local); - if (link_local && strcmp(link_local, "1") != 0) + if (link_local && DM_STRCMP(link_local, "1") != 0) continue; init_interface_ip_args(&curr_intf_ip_args, NULL, dmmap_s, NULL); @@ -779,7 +779,7 @@ static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_n uci_foreach_sections("network", "interface", intf_s) { dmuci_get_value_by_section_string(intf_s, "device", &device); - if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && strcmp(device, buf) != 0) + if (strcmp(section_name(intf_s), section_name(parent_sec)) != 0 && DM_STRCMP(device, buf) != 0) continue; dmuci_get_value_by_section_string(intf_s, "ip6prefix", &ip6prefix); @@ -882,7 +882,7 @@ static int delObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char if (strcmp(section_name(s), "loopback") == 0 || *proto == '\0' || - strchr(device, '@')) + DM_STRCHR(device, '@')) continue; delete_ip_intertace_instance(s); @@ -900,7 +900,7 @@ static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void 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); - if (strcmp(*instance, "1") != 0) { + if (DM_STRCMP(*instance, "1") != 0) { char device_buf[32] = {0}; snprintf(ipv4_name, sizeof(ipv4_name), "iface%s_ipv4_%s", ip_inst, *instance); @@ -918,7 +918,7 @@ static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void dmuci_add_section_bbfdm("dmmap_network_ipv4", "intf_ipv4", &dmmap_ip_interface_ipv4); dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "parent_section", section_name((struct uci_section *)data)); - dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "section_name", (strcmp(*instance, "1") != 0) ? ipv4_name : section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "section_name", (DM_STRCMP(*instance, "1") != 0) ? ipv4_name : section_name((struct uci_section *)data)); dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "added_by_controller", "1"); dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "ipv4_instance", *instance); return 0; @@ -932,11 +932,11 @@ static int delObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void 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) + if (DM_STRCMP(proto, "static") != 0) return FAULT_9001; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "device", &device); - if (strchr(device, '@')) { + if (DM_STRCHR(device, '@')) { dmuci_delete_by_section(((struct intf_ip_args *)data)->interface_sec, NULL, NULL); } else { dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipaddr", ""); @@ -947,7 +947,7 @@ static int delObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void break; case DEL_ALL: dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - if (strcmp(proto, "static") != 0) + if (DM_STRCMP(proto, "static") != 0) return FAULT_9001; snprintf(buf, sizeof(buf), "@%s", section_name((struct uci_section *)data)); @@ -962,7 +962,7 @@ static int delObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void get_dmmap_section_of_config_section("dmmap_network_ipv4", "intf_ipv4", section_name(s), &dmmap_s); dmuci_delete_by_section(dmmap_s, NULL, NULL); - } else if (strcmp(device, buf) == 0) { + } else if (DM_STRCMP(device, buf) == 0) { get_dmmap_section_of_config_section("dmmap_network_ipv4", "intf_ipv4", section_name(s), &dmmap_s); dmuci_delete_by_section(dmmap_s, NULL, NULL); @@ -1085,7 +1085,7 @@ static int get_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char char buf[16] = {0}; dm_read_sysfs_file("/proc/sys/net/ipv6/conf/all/disable_ipv6", buf, sizeof(buf)); - *value = (strcmp(buf, "1") == 0) ? "0" : "1"; + *value = (DM_STRCMP(buf, "1") == 0) ? "0" : "1"; return 0; } @@ -1122,11 +1122,11 @@ static int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char break; } - char *ptr = strstr(buffer, "net.ipv6.conf.all.disable_ipv6"); + char *ptr = DM_STRSTR(buffer, "net.ipv6.conf.all.disable_ipv6"); if (ptr) { *(ptr+31) = (b) ? '0' : '1'; fseek(fp, 0, SEEK_SET); - fwrite(buffer, sizeof(char), strlen(buffer), fp); + fwrite(buffer, sizeof(char), DM_STRLEN(buffer), fp); } else { fputs(buf, fp); } @@ -1142,7 +1142,7 @@ static int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char static int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_IP_IPv6Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } @@ -1282,7 +1282,7 @@ static int get_IPInterface_Status(char *refparam, struct dmctx *ctx, void *data, dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res); DM_ASSERT(res, *value = "Down"); char *up = dmjson_get_value(res, 1, "up"); - *value = (strcmp(up, "true") == 0) ? "Up" : "Down"; + *value = (DM_STRCMP(up, "true") == 0) ? "Up" : "Down"; return 0; } @@ -1343,7 +1343,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * char *proto; dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto); - if (strncmp(proto, "ppp", 3) == 0) { + if (DM_STRNCMP(proto, "ppp", 3) == 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 && (*value)[0] != 0) @@ -1364,7 +1364,7 @@ static int get_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * if (device[0] != '\0') { DM_STRNCPY(linker, device, sizeof(linker)); - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; } else { struct uci_section *s = NULL; @@ -1422,7 +1422,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * dmuci_set_value_by_section((struct uci_section *)data, "device", ""); dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &curr_proto); - if (strncmp(curr_proto, "ppp", 3) == 0) { + if (DM_STRNCMP(curr_proto, "ppp", 3) == 0) { struct uci_section *ppp_s = NULL; ppp_s = get_dup_section_in_dmmap_opt("dmmap_ppp", "interface", "iface_name", section_name((struct uci_section *)data)); @@ -1436,7 +1436,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * DM_STRNCPY(linker_buf, ip_linker, sizeof(linker_buf)); - if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) { + if (DM_STRNCMP(value, eth_vlan_term, DM_STRLEN(eth_vlan_term)) == 0) { struct uci_section *s = NULL, *stmp = NULL; // Check linker value @@ -1452,11 +1452,11 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * uci_foreach_option_eq_safe("network", "device", "name", device, stmp, s) { char *type; dmuci_get_value_by_section_string(s, "type", &type); - if (strcmp(type, "untagged") == 0) dmuci_delete_by_section(s, NULL, NULL); + if (DM_STRCMP(type, "untagged") == 0) dmuci_delete_by_section(s, NULL, NULL); break; } - char *mac_vlan = strchr(linker_buf, '_'); + char *mac_vlan = DM_STRCHR(linker_buf, '_'); if (mac_vlan) { // Check if there is an interface that has the same ifname ==> if yes, remove it uci_foreach_option_eq_safe("network", "interface", "device", linker_buf, stmp, s) { @@ -1471,7 +1471,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * // Check if there is an interface that has the same name of device ==> if yes, remove it char dev_buf[32] = {0}; DM_STRNCPY(dev_buf, linker_buf, sizeof(dev_buf)); - char *vid = strchr(dev_buf, '.'); + char *vid = DM_STRCHR(dev_buf, '.'); if (vid) { *vid = '\0'; uci_foreach_option_eq_safe("network", "interface", "device", dev_buf, stmp, s) { @@ -1483,7 +1483,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * // Update device option dmuci_set_value_by_section((struct uci_section *)data, "device", linker_buf); - } else if (strncmp(value, eth_link, strlen(eth_link)) == 0) { + } else if (DM_STRNCMP(value, eth_link, DM_STRLEN(eth_link)) == 0) { // Get interface name from Ethernet.Link. object struct uci_section *eth_link_s = NULL; @@ -1500,7 +1500,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * dmuci_set_value_by_section(eth_link_s, "section_name", section_name((struct uci_section *)data)); if (!eth_link_without_dev) { - bool is_br_sec = (strncmp(linker_buf, "br-", 3) == 0) ? true : false; + bool is_br_sec = (DM_STRNCMP(linker_buf, "br-", 3) == 0) ? true : false; // Check if the Ethernet.Link. maps to bridge, if yes then check the device name if (is_br_sec) { @@ -1508,7 +1508,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * snprintf(device, sizeof(device), "br-%s", section_name((struct uci_section *)data)); - if (strcmp(device, linker_buf) != 0) { + if (DM_STRCMP(device, linker_buf) != 0) { struct uci_section *s = NULL; // Remove unused Interface section created by Bridge Object if it exists @@ -1516,7 +1516,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * char *br_device = NULL; dmuci_get_value_by_section_string(s, "device", &br_device); - if (br_device && strcmp(br_device, linker_buf) == 0) { + if (br_device && DM_STRCMP(br_device, linker_buf) == 0) { dmuci_delete_by_section(s, NULL, NULL); break; } @@ -1540,7 +1540,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * } // Check if the Ethernet.Link. maps to macvlan, if yes then keep only device name - char *mac_vlan = strchr(linker_buf, '_'); + char *mac_vlan = DM_STRCHR(linker_buf, '_'); if (!is_br_sec && mac_vlan) { *mac_vlan = 0; dmuci_set_value_by_section(eth_link_s, "device", linker_buf); @@ -1548,7 +1548,7 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void * set_ip_interface_device_option((struct uci_section *)data, linker_buf, instance, is_br_sec); } - } else if (strncmp(value, ppp_iface, strlen(ppp_iface)) == 0) { + } else if (DM_STRNCMP(value, ppp_iface, DM_STRLEN(ppp_iface)) == 0) { struct uci_section *ppp_s = get_dup_section_in_dmmap_opt("dmmap_ppp", "interface", "name", linker_buf); if (ppp_s == NULL) ppp_s = get_dup_section_in_dmmap_opt("dmmap_ppp", "interface", "iface_name", linker_buf); @@ -1689,7 +1689,7 @@ static int get_IPInterfaceIPv4Address_Enable(char *refparam, struct dmctx *ctx, char *proto = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (strcmp(proto, "none") != 0) { + if (DM_STRCMP(proto, "none") != 0) { char *disabled = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "disabled", &disabled); @@ -1713,7 +1713,7 @@ static int set_IPInterfaceIPv4Address_Enable(char *refparam, struct dmctx *ctx, case VALUESET: string_to_bool(value, &b); dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (strcmp(proto, "none") == 0) { + if (DM_STRCMP(proto, "none") == 0) { char *ip_addr; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "ipaddr", &ip_addr); @@ -1754,7 +1754,7 @@ static int set_IPInterfaceIPv4Address_Alias(char *refparam, struct dmctx *ctx, v break; case VALUESET: dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (proto && strcmp(proto, "static") == 0) + if (proto && DM_STRCMP(proto, "static") == 0) dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "ipv4_alias", value); break; } @@ -1788,7 +1788,7 @@ static int set_IPInterfaceIPv4Address_IPAddress(char *refparam, struct dmctx *ct break; case VALUESET: dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto_intf); - if (proto_intf && strcmp(proto_intf, "static") == 0) + if (proto_intf && DM_STRCMP(proto_intf, "static") == 0) dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipaddr", value); break; } @@ -1805,7 +1805,7 @@ static int get_IPInterfaceIPv4Address_SubnetMask(char *refparam, struct dmctx *c if (mask && mask[0] == '\0') { json_object *ipv4_obj = dmjson_select_obj_in_array_idx(((struct intf_ip_args *)data)->interface_obj, 0, 1, "ipv4-address"); mask = dmjson_get_value(ipv4_obj, 1, "mask"); - mask = (mask && *mask) ? dmstrdup(cidr2netmask(atoi(mask))) : ""; + mask = (mask && *mask) ? dmstrdup(cidr2netmask(DM_STRTOL(mask))) : ""; } *value = (mask && *mask) ? mask : ""; @@ -1823,7 +1823,7 @@ static int set_IPInterfaceIPv4Address_SubnetMask(char *refparam, struct dmctx *c break; case VALUESET: dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (proto && strcmp(proto, "static") == 0) + if (proto && DM_STRCMP(proto, "static") == 0) dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "netmask", value); break; } @@ -1836,9 +1836,9 @@ static int get_IPInterfaceIPv4Address_AddressingType(char *refparam, struct dmct char *proto = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (proto && strcmp(proto, "static") == 0) + if (proto && DM_STRCMP(proto, "static") == 0) *value = "Static"; - else if (proto && strncmp(proto, "ppp", 3) == 0) + else if (proto && DM_STRNCMP(proto, "ppp", 3) == 0) *value = "IPCP"; else *value = "DHCP"; @@ -1851,7 +1851,7 @@ static int get_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, char *link_local = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "link_local", &link_local); - if (link_local && strcmp(link_local, "1") == 0) { + if (link_local && DM_STRCMP(link_local, "1") == 0) { *value = "1"; } else { *value = dmuci_get_value_by_section_fallback_def(((struct intf_ip_args *)data)->interface_sec, "ipv6", "1"); @@ -1873,7 +1873,7 @@ static int set_IPInterfaceIPv6Address_Enable(char *refparam, struct dmctx *ctx, case VALUESET: string_to_bool(value, &b); dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "link_local", &link_local); - if (link_local && strcmp(link_local, "1") != 0) + if (link_local && DM_STRCMP(link_local, "1") != 0) dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ipv6", b ? "1" : "0"); break; } @@ -1893,7 +1893,7 @@ static int get_IPInterfaceIPv6Address_IPAddressStatus(char *refparam, struct dmc char *assign = NULL, *preferred = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "1") == 0) + if (assign && DM_STRCMP(assign, "1") == 0) preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred"); else preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); @@ -1929,7 +1929,7 @@ static int set_IPInterfaceIPv6Address_Alias(char *refparam, struct dmctx *ctx, v static int get_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "address", value); - char *mask = strchr(*value, '/'); + char *mask = DM_STRCHR(*value, '/'); if (mask) *mask = '\0'; return 0; } @@ -1946,7 +1946,7 @@ static int set_IPInterfaceIPv6Address_IPAddress(char *refparam, struct dmctx *ct case VALUESET: dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "link_local", &link_local); - if (proto && strcmp(proto, "static") == 0 && link_local && strcmp(link_local, "1") != 0) { + if (proto && DM_STRCMP(proto, "static") == 0 && link_local && DM_STRCMP(link_local, "1") != 0) { dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6addr", value); dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value); } @@ -1962,12 +1962,12 @@ static int get_IPInterfaceIPv6Address_Origin(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "link_local", &link_local); - if ((assign && strcmp(assign, "1") == 0) || (link_local && strcmp(link_local, "1") == 0)) { + if ((assign && DM_STRCMP(assign, "1") == 0) || (link_local && DM_STRCMP(link_local, "1") == 0)) { *value = "AutoConfigured"; } else { char *proto; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - *value = (strcmp(proto, "dhcpv6") == 0) ? "DHCPv6" : "Static"; + *value = (DM_STRCMP(proto, "dhcpv6") == 0) ? "DHCPv6" : "Static"; } return 0; } @@ -1977,7 +1977,7 @@ static int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, char *assign = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "1") == 0) { + if (assign && DM_STRCMP(assign, "1") == 0) { struct uci_section *dmmap_section = NULL; char *ip_inst = NULL, *ipv6_prefix_inst = NULL, *parent_section, *section_name; char curr_address[64] = {0}, *address = NULL; @@ -1992,7 +1992,7 @@ static int get_IPInterfaceIPv6Address_Prefix(char *refparam, struct dmctx *ctx, dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "section_name", §ion_name); uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "section_name", section_name, dmmap_section) { dmuci_get_value_by_section_string(dmmap_section, "address", &address); - if (address && strcmp(address, curr_address) == 0) { + if (address && DM_STRCMP(address, curr_address) == 0) { dmuci_get_value_by_section_string(dmmap_section, "ipv6_prefix_instance", &ipv6_prefix_inst); break; } @@ -2022,12 +2022,12 @@ static int get_IPInterfaceIPv6Address_PreferredLifetime(char *refparam, struct d char *assign = NULL, *preferred = NULL, local_time[32] = {0}; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "1") == 0) + if (assign && DM_STRCMP(assign, "1") == 0) preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "preferred"); else preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); - if (preferred && *preferred && get_shift_utc_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + if (preferred && *preferred && get_shift_utc_time(DM_STRTOL(preferred), local_time, sizeof(local_time)) == -1) return 0; *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; @@ -2052,12 +2052,12 @@ static int get_IPInterfaceIPv6Address_ValidLifetime(char *refparam, struct dmctx char *assign = NULL, *preferred = NULL, local_time[32] = {0}; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "1") == 0) + if (assign && DM_STRCMP(assign, "1") == 0) preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 2, "local-address", "valid"); else preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "valid"); - if (preferred && *preferred && get_shift_utc_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + if (preferred && *preferred && get_shift_utc_time(DM_STRTOL(preferred), local_time, sizeof(local_time)) == -1) return 0; *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; @@ -2159,7 +2159,7 @@ static int set_IPInterfaceIPv6Prefix_Prefix(char *refparam, struct dmctx *ctx, v break; case VALUESET: dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - if (proto && strcmp(proto, "static") == 0) { + if (proto && DM_STRCMP(proto, "static") == 0) { dmuci_set_value_by_section(((struct intf_ip_args *)data)->interface_sec, "ip6prefix", value); dmuci_set_value_by_section(((struct intf_ip_args *)data)->dmmap_sec, "address", value); } @@ -2173,12 +2173,12 @@ static int get_IPInterfaceIPv6Prefix_Origin(char *refparam, struct dmctx *ctx, v char *assign = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "1") == 0) { + if (assign && DM_STRCMP(assign, "1") == 0) { *value = "AutoConfigured"; } else { char *proto = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->interface_sec, "proto", &proto); - *value = (proto && strcmp(proto, "dhcpv6") == 0) ? "PrefixDelegation" : "Static"; + *value = (proto && DM_STRCMP(proto, "dhcpv6") == 0) ? "PrefixDelegation" : "Static"; } return 0; } @@ -2210,7 +2210,7 @@ static int get_IPInterfaceIPv6Prefix_ChildPrefixBits(char *refparam, struct dmct char *assign = NULL; dmuci_get_value_by_section_string(((struct intf_ip_args *)data)->dmmap_sec, "assign", &assign); - if (assign && strcmp(assign, "0") == 0) { + if (assign && DM_STRCMP(assign, "0") == 0) { char *address = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "address"); char *mask = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 3, "assigned", "lan", "mask"); if (address && *address && mask && *mask) @@ -2237,7 +2237,7 @@ static int get_IPInterfaceIPv6Prefix_PreferredLifetime(char *refparam, struct dm char local_time[32] = {0}; char *preferred = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "preferred"); - if (preferred && *preferred && get_shift_utc_time(atoi(preferred), local_time, sizeof(local_time)) == -1) + if (preferred && *preferred && get_shift_utc_time(DM_STRTOL(preferred), local_time, sizeof(local_time)) == -1) return 0; *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; @@ -2262,7 +2262,7 @@ static int get_IPInterfaceIPv6Prefix_ValidLifetime(char *refparam, struct dmctx char local_time[32] = {0}; char *valid = dmjson_get_value(((struct intf_ip_args *)data)->interface_obj, 1, "valid"); - if (valid && *valid && get_shift_time_time(atoi(valid), local_time, sizeof(local_time)) == -1) + if (valid && *valid && get_shift_time_time(DM_STRTOL(valid), local_time, sizeof(local_time)) == -1) return 0; *value = (*local_time) ? dmstrdup(local_time) : "9999-12-31T23:59:59Z"; diff --git a/dmtree/tr181/managementserver.c b/dmtree/tr181/managementserver.c index cbe10216..64c1c164 100644 --- a/dmtree/tr181/managementserver.c +++ b/dmtree/tr181/managementserver.c @@ -341,7 +341,7 @@ static int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, return FAULT_9007; return 0; case VALUESET: - if (strcmp(value,"UDP") == 0) + if (DM_STRCMP(value,"UDP") == 0) dmuci_set_value("cwmp", "lwn", "enable", "1"); else dmuci_set_value("cwmp", "lwn", "enable", "0"); @@ -473,7 +473,7 @@ static int set_management_server_retry_interval_multiplier(char *refparam, struc static int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *res = dmuci_get_option_value_fallback_def("cwmp", "cpe", "amd_version", "5"); - *value = (atoi(res) <= AMD_4) ? "false" : "true"; + *value = (DM_STRTOL(res) <= AMD_4) ? "false" : "true"; return 0; } @@ -567,12 +567,12 @@ static int set_management_server_conn_req_xmpp_connection(char *refparam, struct return FAULT_9007; return 0; case VALUESET: - if ((str = strstr(value, "Device.XMPP.Connection."))) { + if ((str = DM_STRSTR(value, "Device.XMPP.Connection."))) { value = dmstrdup(str + sizeof("Device.XMPP.Connection.") - 1); //MEM WILL BE FREED IN DMMEMCLEAN } uci_foreach_sections("xmpp", "connection", s) { dmuci_get_value_by_section_string(s, "xmpp_id", &xmpp_id); - if(strcmp(value, xmpp_id) == 0) { + if(DM_STRCMP(value, xmpp_id) == 0) { dmuci_set_value("xmpp", "xmpp", "id", value); break; } diff --git a/dmtree/tr181/nat.c b/dmtree/tr181/nat.c index 9c65db0a..d2a268fd 100644 --- a/dmtree/tr181/nat.c +++ b/dmtree/tr181/nat.c @@ -45,7 +45,7 @@ static int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list); list_for_each_entry(p, &dup_list, list) { dmuci_get_value_by_section_string(p->config_section, "target", &target); - if (*target != '\0' && strcmp(target, "DNAT") != 0) + if (*target != '\0' && DM_STRCMP(target, "DNAT") != 0) continue; inst = handle_instance(dmctx, parent_node, p->dmmap_section, "port_mapping_instance", "port_mapping_alias"); @@ -304,7 +304,7 @@ static int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void * char *zone_name = NULL; dmuci_get_value_by_section_string(s, "name", &zone_name); - if (intf && zone_name && !strcmp(intf, zone_name)) { + if (intf && zone_name && !DM_STRCMP(intf, zone_name)) { char *masq = NULL; dmuci_get_value_by_section_string(s, "masq", &masq); @@ -324,7 +324,7 @@ static int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void * static int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_nat_port_mapping_enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } @@ -359,14 +359,14 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi unsigned pos = 0; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dip", &src_dip); - if (src_dip && strcmp(src_dip, "*") == 0) + if (src_dip && DM_STRCMP(src_dip, "*") == 0) return 0; buf[0] = 0; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &zone_name); uci_foreach_sections("firewall", "zone", s) { dmuci_get_value_by_section_string(s, "name", &name); - if (zone_name && name && strcmp(zone_name, name) == 0) { + if (zone_name && name && DM_STRCMP(zone_name, name) == 0) { dmuci_get_value_by_section_list(s, "network", &v); break; } @@ -481,8 +481,8 @@ static int get_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx char *expiry_date = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "expiry", &expiry_date); - if (expiry_date && *expiry_date != '\0' && atoi(expiry_date) > 0) { - dmasprintf(value, "%lld", (long long)(atoi(expiry_date) - time(NULL))); + if (expiry_date && *expiry_date != '\0' && DM_STRTOL(expiry_date) > 0) { + dmasprintf(value, "%lld", (long long)(DM_STRTOL(expiry_date) - time(NULL))); } else { *value = "0"; } @@ -499,10 +499,10 @@ 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 || DM_STRTOL(value) == 0) break; - snprintf(expiry_date, sizeof(expiry_date), "%lld", (long long)(atoi(value) + time(NULL))); + snprintf(expiry_date, sizeof(expiry_date), "%lld", (long long)(DM_STRTOL(value) + time(NULL))); dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "expiry", expiry_date); break; } @@ -540,7 +540,7 @@ static int get_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, return 0; } - char *tmp = src_dport ? strchr(src_dport, ':') : NULL; + char *tmp = src_dport ? DM_STRCHR(src_dport, ':') : NULL; if (tmp) *tmp = '\0'; *value = src_dport; @@ -558,7 +558,7 @@ static int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, return 0; case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport); - src_dport = src_dport ? strchr(src_dport, ':') : NULL; + src_dport = src_dport ? DM_STRCHR(src_dport, ':') : NULL; if (src_dport == NULL) snprintf(buffer, sizeof(buffer), "%s", value); else @@ -574,7 +574,7 @@ static int get_nat_port_mapping_external_port_end_range(char *refparam, struct d { char *src_dport = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport); - char *tmp = src_dport ? strchr(src_dport, ':') : NULL; + char *tmp = src_dport ? DM_STRCHR(src_dport, ':') : NULL; *value = tmp ? tmp + 1 : "0"; return 0; } @@ -590,7 +590,7 @@ static int set_nat_port_mapping_external_port_end_range(char *refparam, struct d return 0; case VALUESET: dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport); - tmp = src_dport ? strchr(src_dport, ':') : NULL; + tmp = src_dport ? DM_STRCHR(src_dport, ':') : NULL; if (tmp) *tmp = '\0'; @@ -631,7 +631,7 @@ static int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void { char *proto = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto); - *value = (proto && strcmp(proto, "udp") == 0) ? "UDP" : "TCP"; + *value = (proto && DM_STRCMP(proto, "udp") == 0) ? "UDP" : "TCP"; return 0; } @@ -643,7 +643,7 @@ static int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void return FAULT_9007; return 0; case VALUESET: - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "proto", (strcmp("UDP", value) == 0) ? "udp" : "tcp"); + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "proto", (DM_STRCMP("UDP", value) == 0) ? "udp" : "tcp"); return 0; } return 0; diff --git a/dmtree/tr181/ppp.c b/dmtree/tr181/ppp.c index 3156aa10..da4228ce 100644 --- a/dmtree/tr181/ppp.c +++ b/dmtree/tr181/ppp.c @@ -79,7 +79,7 @@ static void dmmap_synchronizePPPInterface(struct dmctx *dmctx, DMNODE *parent_no char *iface_name = NULL; dmuci_get_value_by_section_string(s, "added_by_controller", &added_by_controller); - if (strcmp(added_by_controller, "1") == 0) + if (DM_STRCMP(added_by_controller, "1") == 0) continue; dmuci_get_value_by_section_string(s, "iface_name", &iface_name); @@ -95,7 +95,7 @@ static void dmmap_synchronizePPPInterface(struct dmctx *dmctx, DMNODE *parent_no char *proto = NULL; dmuci_get_value_by_section_string(s, "proto", &proto); - if (strncmp(proto, "ppp", 3) != 0) + if (DM_STRNCMP(proto, "ppp", 3) != 0) continue; if (is_ppp_section_exist(section_name(s))) @@ -225,7 +225,7 @@ static int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *i static int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_ppp_enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Up" : "Down"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Up" : "Down"; return 0; } @@ -328,7 +328,7 @@ static int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *i string_to_bool(pending, &bpend); } } - if (uptime && atoi(uptime) > 0) + if (uptime && DM_STRTOL(uptime) > 0) *value = "Connected"; else if (pending && bpend) *value = "Pending Disconnect"; @@ -351,7 +351,7 @@ static int get_PPPInterface_LastConnectionError(char *refparam, struct dmctx *ct DM_ASSERT(res, *value = "ERROR_NONE"); char *status = dmjson_get_value(res, 2, "data", "lastconnectionerror"); - switch (atoi(status)) { + switch (DM_STRTOL(status)) { case 0: *value = "ERROR_NONE"; break; @@ -446,7 +446,7 @@ static int get_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void * char *token = NULL , *end = NULL; token = strtok_r(pppd_opt, " ", &end); while (NULL != token) { - if (0 == strcmp(token, "mru")) { + if (0 == DM_STRCMP(token, "mru")) { char mru_val[1024] = {0}, mru_str[1024] = {0}; DM_STRNCPY(mru_val, end, sizeof(mru_val)); sscanf(mru_val, "%1023s", mru_str); @@ -475,7 +475,7 @@ static int configure_pppd_mru(char *pppd_opt, char *mru_str, struct uci_section list_options[0] = 0; token = strtok_r(pppd_opt, " ", &end); while (NULL != token) { - if (0 == strcmp(token, "mru")) { + if (0 == DM_STRCMP(token, "mru")) { found = true; pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s %s", token, value); DM_STRNCPY(mru_opt, end, sizeof(mru_opt)); @@ -576,7 +576,7 @@ static int get_PPPInterface_LCPEchoRetry(char *refparam, struct dmctx *ctx, void if (!lcp_retry || *lcp_retry == '\0') { *value = "5"; } else { - token = strchr(lcp_retry , ' '); + token = DM_STRCHR(lcp_retry , ' '); if (NULL != token) { char lcp_interval[50] = {0}; @@ -594,7 +594,7 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value, char list_options[1024] = {0}; dmuci_get_value_by_section_string(ss, "proto", &proto); - if (0 == strcmp(proto, "pppoe")) { + if (0 == DM_STRCMP(proto, "pppoe")) { dmuci_get_value_by_section_string(ss, "pppd_options", &pppd_opt); } @@ -608,9 +608,9 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value, while (NULL != token) { char ncp_opt[1024] = {0}; DM_STRNCPY(ncp_opt, token, sizeof(ncp_opt)); - if (0 == strncmp(ncp_opt, option, sizeof(ncp_opt))) { + if (0 == DM_STRNCMP(ncp_opt, option, sizeof(ncp_opt))) { found = true; - if (0 == strcmp(value, "1") && NULL != end) { + if (0 == DM_STRCMP(value, "1") && NULL != end) { if (pos != 0) pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%c", ' '); @@ -626,7 +626,7 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value, token = strtok_r(NULL, " ", &end); } - if ((0 == strcmp(value, "0")) && found == false) { + if ((0 == DM_STRCMP(value, "0")) && found == false) { if (pos != 0) pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%c", ' '); @@ -635,7 +635,7 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value, dmuci_set_value_by_section(ss, "pppd_options", list_options); } else { - if (0 == strcmp(value, "0")) { + if (0 == DM_STRCMP(value, "0")) { dmuci_set_value_by_section(ss, "pppd_options", option); } } @@ -653,11 +653,11 @@ static int parse_pppd_options(char *pppd_opt, int option) char value[50] = {0}; DM_STRNCPY(value, token, sizeof(value)); - if ((4 == strlen(value)) && 0 == strcmp(value, "noip")) { + if ((4 == DM_STRLEN(value)) && 0 == DM_STRCMP(value, "noip")) { noip = 1; } - if (0 == strncmp(value, "noipv6", 6)) { + if (0 == DM_STRNCMP(value, "noipv6", 6)) { noipv6 = 1; } @@ -676,7 +676,7 @@ static int handle_supported_ncp_options(struct uci_section *s, char *instance, i char *pppd_opt = NULL, *proto = NULL; dmuci_get_value_by_section_string(s, "proto", &proto); - if (proto && strcmp(proto, "pppoe") == 0) + if (proto && DM_STRCMP(proto, "pppoe") == 0) dmuci_get_value_by_section_string(s, "pppd_options", &pppd_opt); return pppd_opt ? parse_pppd_options(pppd_opt, option) : 0; @@ -852,7 +852,7 @@ static int ppp_read_sysfs(void *data, const char *name, char **value) char *proto; dmuci_get_value_by_section_string(ppp_s, "proto", &proto); - if (!strcmp(proto, "pppoe")) { + if (!DM_STRCMP(proto, "pppoe")) { char *l3_device = get_l3_device(section_name(ppp_s)); get_net_device_sysfs(l3_device, name, value); } @@ -946,7 +946,7 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch char linker[64] = {0}; DM_STRNCPY(linker, device, sizeof(linker)); - char *vid = strchr(linker, '.'); + char *vid = DM_STRCHR(linker, '.'); if (vid) *vid = '\0'; adm_entry_get_linker_param(ctx, "Device.Ethernet.Link.", linker, value); @@ -994,7 +994,7 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch dmuci_set_value_by_section(ppp->dmmap_s, "device", ""); if (ppp->iface_s) dmuci_set_value_by_section(ppp->iface_s, "device", ""); - } else if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) { + } else if (DM_STRNCMP(value, eth_vlan_term, DM_STRLEN(eth_vlan_term)) == 0) { // Check VLANTremination linker and required options struct uci_section *vlan_ter_s = get_dup_section_in_config_opt("network", "device", "name", ppp_linker); @@ -1010,7 +1010,7 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch dmuci_set_value_by_section(ppp->dmmap_s, "proto", "pppoe"); if (ppp->iface_s) dmuci_set_value_by_section(ppp->iface_s, "proto", "pppoe"); - } else if (strncmp(value, eth_link, strlen(eth_link)) == 0) { + } else if (DM_STRNCMP(value, eth_link, DM_STRLEN(eth_link)) == 0) { struct uci_section *eth_link_s = NULL; // Check Ethernet.Link linker and required options @@ -1030,9 +1030,9 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch dmuci_get_value_by_section_string(eth_link_s, "is_eth", &is_eth); // Update proto option - dmuci_set_value_by_section(ppp->dmmap_s, "proto", !strcmp(is_eth, "1") ? "pppoe" : "pppoa"); + dmuci_set_value_by_section(ppp->dmmap_s, "proto", !DM_STRCMP(is_eth, "1") ? "pppoe" : "pppoa"); if (ppp->iface_s) - dmuci_set_value_by_section(ppp->iface_s, "proto", !strcmp(is_eth, "1") ? "pppoe" : "pppoa"); + dmuci_set_value_by_section(ppp->iface_s, "proto", !DM_STRCMP(is_eth, "1") ? "pppoe" : "pppoa"); } } return 0; @@ -1060,7 +1060,7 @@ static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void char *proto; dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); - if (strcmp(proto, "pppoe") == 0) { + if (DM_STRCMP(proto, "pppoe") == 0) { dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "ac", value); return 0; } @@ -1078,7 +1078,7 @@ static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void return FAULT_9007; dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto_intf); - if (strcmp(proto_intf, "pppoe") != 0) + if (DM_STRCMP(proto_intf, "pppoe") != 0) return FAULT_9001; break; case VALUESET: @@ -1097,7 +1097,7 @@ static int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, char *proto; dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); - if (strcmp(proto, "pppoe") == 0) { + if (DM_STRCMP(proto, "pppoe") == 0) { dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "service", value); return 0; } @@ -1115,7 +1115,7 @@ static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, return FAULT_9007; dmuci_get_value_by_section_string(ppp->iface_s ? ppp->iface_s : ppp->dmmap_s, "proto", &proto); - if (strcmp(proto, "pppoe") != 0) + if (DM_STRCMP(proto, "pppoe") != 0) return FAULT_9001; break; case VALUESET: diff --git a/dmtree/tr181/ptm.c b/dmtree/tr181/ptm.c index 985a9070..e94c4bbd 100644 --- a/dmtree/tr181/ptm.c +++ b/dmtree/tr181/ptm.c @@ -201,7 +201,7 @@ static int get_ptm_dsl_channel(struct dmctx *ctx, void *data, char *instance, ch { char *ptm_file = NULL; - dmasprintf(&ptm_file, "/sys/class/net/ptm%d", atoi(instance) - 1); + dmasprintf(&ptm_file, "/sys/class/net/ptm%ld", DM_STRTOL(instance) - 1); if (folder_exists(ptm_file)) { *value = "Device.DSL.Channel.1"; dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1"); @@ -220,7 +220,7 @@ static int get_ptm_fast_line(struct dmctx *ctx, void *data, char *instance, char line_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "line"); if (!line_obj) return 0; - if ( strcmp(dmjson_get_value(line_obj, 1, "status"), "up") == 0) { + if ( DM_STRCMP(dmjson_get_value(line_obj, 1, "status"), "up") == 0) { *value = "Device.FAST.Line.1"; dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1"); } @@ -243,11 +243,11 @@ static int set_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch { switch (action) { case VALUECHECK: - if (strncmp(value, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0 && strncmp(value, "Device.FAST.Line.1", strlen("Device.FAST.Line.1")) != 0) + if (DM_STRNCMP(value, "Device.DSL.Channel.1", DM_STRLEN("Device.DSL.Channel.1")) != 0 && DM_STRNCMP(value, "Device.FAST.Line.1", DM_STRLEN("Device.FAST.Line.1")) != 0) return FAULT_9007; break; case VALUESET: - if (strcmp(value, "Device.DSL.Channel.1") == 0) + if (DM_STRCMP(value, "Device.DSL.Channel.1") == 0) dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "dsl_channel_1"); else dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1"); diff --git a/dmtree/tr181/qos.c b/dmtree/tr181/qos.c index 011e81b5..aa7da2ff 100644 --- a/dmtree/tr181/qos.c +++ b/dmtree/tr181/qos.c @@ -34,7 +34,7 @@ static int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, //synchronizing option src_ip of uci classify section to src_mask/src_ip of dmmap's classify section dmuci_get_value_by_section_string(p->config_section, "src_ip", &value); //checking if src_ip is an ip-prefix or ip address and synchronizing accordingly - ret = strstr(value, "/"); + ret = DM_STRSTR(value, "/"); if (ret) dmuci_set_value_by_section_bbfdm(p->dmmap_section, "src_mask", value); else @@ -43,7 +43,7 @@ static int browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, //synchronizing option dest_ip of uci classify section to dest_mask/dest_ip of dmmap's classify section dmuci_get_value_by_section_string(p->config_section, "dest_ip", &value); //checking if src_ip is an ip-prefix or ip address and synchronizing accordingly - ret = strstr(value, "/"); + ret = DM_STRSTR(value, "/"); if (ret) dmuci_set_value_by_section_bbfdm(p->dmmap_section, "dest_mask", value); else @@ -1100,7 +1100,7 @@ static int set_QoSClassification_Policer(char *refparam, struct dmctx *ctx, void return FAULT_9007; break; case VALUESET: - if (strncmp(value, "Device.QoS.Policer.", 19) != 0) + if (DM_STRNCMP(value, "Device.QoS.Policer.", 19) != 0) return 0; snprintf(link_inst, sizeof(link_inst), "%c", value[19]); @@ -1266,9 +1266,9 @@ static int set_QoSPolicer_PeakBurstSize(char *refparam, struct dmctx *ctx, void static int get_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "meter_type", value); - if (strncmp(*value, "1", 1) == 0) + if (DM_STRNCMP(*value, "1", 1) == 0) *value = "SingleRateThreeColor"; - else if (strncmp(*value, "2", 1) == 0) + else if (DM_STRNCMP(*value, "2", 1) == 0) *value = "TwoRateThreeColor"; else *value = "SimpleTokenBucket"; @@ -1280,15 +1280,15 @@ static int set_QoSPolicer_MeterType(char *refparam, struct dmctx *ctx, void *dat { switch (action) { case VALUECHECK: - if ((strcmp("SimpleTokenBucket", value) != 0) && (strcmp("SingleRateThreeColor", value) != 0) && (strcmp("TwoRateThreeColor", value) != 0)) + if ((DM_STRCMP("SimpleTokenBucket", value) != 0) && (DM_STRCMP("SingleRateThreeColor", value) != 0) && (DM_STRCMP("TwoRateThreeColor", value) != 0)) return FAULT_9007; break; case VALUESET: - if (strcmp("SimpleTokenBucket", value) == 0) + if (DM_STRCMP("SimpleTokenBucket", value) == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "meter_type", "0"); - else if (strcmp("SingleRateThreeColor", value) == 0) + else if (DM_STRCMP("SingleRateThreeColor", value) == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "meter_type", "1"); - else if (strcmp("TwoRateThreeColor", value) == 0) + else if (DM_STRCMP("TwoRateThreeColor", value) == 0) dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "meter_type", "2"); break; } @@ -1509,7 +1509,7 @@ static int set_QoSQueueStats_Enable(char *refparam, struct dmctx *ctx, void *dat static int get_QoSQueueStats_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { get_QoSQueueStats_Enable(refparam, ctx, data, instance, value); - *value = (strcmp(*value, "1") == 0) ? "Enabled" : "Disabled"; + *value = (DM_STRCMP(*value, "1") == 0) ? "Enabled" : "Disabled"; return 0; } diff --git a/dmtree/tr181/routeradvertisement.c b/dmtree/tr181/routeradvertisement.c index 72b2ac33..0265972d 100644 --- a/dmtree/tr181/routeradvertisement.c +++ b/dmtree/tr181/routeradvertisement.c @@ -59,7 +59,7 @@ static int browseRouterAdvertisementInterfaceSettingInst(struct dmctx *dmctx, DM // skip the section if option ignore = '1' dmuci_get_value_by_section_string(p->config_section, "ignore", &ignore); - if (ignore && strcmp(ignore, "1") == 0) + if (ignore && DM_STRCMP(ignore, "1") == 0) continue; inst = handle_instance(dmctx, parent_node, p->dmmap_section, "radv_intf_instance", "radv_intf_alias"); @@ -225,7 +225,7 @@ static int get_RouterAdvertisement_InterfaceSettingNumberOfEntries(char *refpara static int get_RouterAdvertisementInterfaceSetting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ra", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "0" : "1"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "0" : "1"; return 0; } @@ -250,7 +250,7 @@ static int set_RouterAdvertisementInterfaceSetting_Enable(char *refparam, struct static int get_RouterAdvertisementInterfaceSetting_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ra", value); - *value = (*value && strcmp(*value, "disabled") == 0) ? "Disabled" : "Enabled"; + *value = (*value && DM_STRCMP(*value, "disabled") == 0) ? "Disabled" : "Enabled"; return 0; } @@ -329,7 +329,7 @@ static int get_RouterAdvertisementInterfaceSetting_Prefixes(char *refparam, stru uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "section_name", interface, dmmap_s) { dmuci_get_value_by_section_string(dmmap_s, "address", &address); - if (address && strcmp(address, ipv6_prefix) == 0) { + if (address && DM_STRCMP(address, ipv6_prefix) == 0) { dmuci_get_value_by_section_string(dmmap_s, "ipv6_prefix_instance", &ipv6_prefix_inst); break; } diff --git a/dmtree/tr181/routing.c b/dmtree/tr181/routing.c index a7534ab2..e93f2165 100644 --- a/dmtree/tr181/routing.c +++ b/dmtree/tr181/routing.c @@ -70,7 +70,7 @@ static bool is_proc_route_in_config(struct proc_routing *proute) char *mask; dmuci_get_value_by_section_string(s, "netmask", &mask); - if (mask[0] == '\0' || strcmp(proute->mask, mask) == 0) + if (mask[0] == '\0' || DM_STRCMP(proute->mask, mask) == 0) return true; } @@ -78,7 +78,7 @@ static bool is_proc_route_in_config(struct proc_routing *proute) char *mask; dmuci_get_value_by_section_string(s, "netmask", &mask); - if (mask[0] == '\0' || strcmp(proute->mask, mask) == 0) + if (mask[0] == '\0' || DM_STRCMP(proute->mask, mask) == 0) return true; } @@ -88,7 +88,7 @@ static bool is_proc_route_in_config(struct proc_routing *proute) dmuci_get_value_by_section_string(s, "target", &target); dmuci_get_value_by_section_string(s, "gateway", &gateway); dmuci_get_value_by_section_string(s, "device", &device); - if (strcmp(target, proute->destination) == 0 && strcmp(gateway, proute->gateway) == 0 && strcmp(device, proute->iface) == 0) + if (DM_STRCMP(target, proute->destination) == 0 && DM_STRCMP(gateway, proute->gateway) == 0 && DM_STRCMP(device, proute->iface) == 0) return true; } @@ -108,7 +108,7 @@ static bool is_proc_route6_in_config(char *cdev, char *cip, char *cgw) dmuci_get_value_by_section_string(s, "interface", &intf_r); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", intf_r, String}}, 1, &jobj); char *dev_r = (jobj) ? dmjson_get_value(jobj, 1, "device") : ""; - if (strcmp(cdev, dev_r) == 0 && strcmp(cgw, gw_r) == 0 && strcmp(cip, ip_r) == 0) + if (DM_STRCMP(cdev, dev_r) == 0 && DM_STRCMP(cgw, gw_r) == 0 && DM_STRCMP(cip, ip_r) == 0) return true; } @@ -121,7 +121,7 @@ static bool is_proc_route6_in_config(char *cdev, char *cip, char *cgw) dmuci_get_value_by_section_string(s, "interface", &intf_r6); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", intf_r6, String}}, 1, &jobj); char *dev_r6 = (jobj) ? dmjson_get_value(jobj, 1, "device") : ""; - if (strcmp(cdev, dev_r6) == 0 && strcmp(cgw, gw_r6) == 0 && strcmp(cip, ip_r6) == 0) + if (DM_STRCMP(cdev, dev_r6) == 0 && DM_STRCMP(cgw, gw_r6) == 0 && DM_STRCMP(cip, ip_r6) == 0) return true; } @@ -131,7 +131,7 @@ static bool is_proc_route6_in_config(char *cdev, char *cip, char *cgw) dmuci_get_value_by_section_string(s, "target", &ip_r6d); dmuci_get_value_by_section_string(s, "gateway", &gw_r6d); dmuci_get_value_by_section_string(s, "device", &dev_r6d); - if (strcmp(cdev, dev_r6d) == 0 && strcmp(cgw, gw_r6d) == 0 && strcmp(cip, ip_r6d) == 0) + if (DM_STRCMP(cdev, dev_r6d) == 0 && DM_STRCMP(cgw, gw_r6d) == 0 && DM_STRCMP(cip, ip_r6d) == 0) return true; } @@ -144,15 +144,15 @@ static void parse_proc_route_line(char *line, struct proc_routing *proute) proute->iface = strtok_r(line, " \t", &spch); pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->destination); + hex_to_ip(pch, proute->destination, sizeof(proute->destination)); pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->gateway); + hex_to_ip(pch, proute->gateway, sizeof(proute->gateway)); proute->flags = strtok_r(NULL, " \t", &spch); proute->refcnt = strtok_r(NULL, " \t", &spch); proute->use = strtok_r(NULL, " \t", &spch); proute->metric = strtok_r(NULL, " \t", &spch); pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->mask); + hex_to_ip(pch, proute->mask, sizeof(proute->mask)); proute->mtu = strtok_r(NULL, " \t", &spch); proute->window = strtok_r(NULL, " \t", &spch); proute->irtt = strtok_r(NULL, " \t\n\r", &spch); @@ -171,7 +171,7 @@ static int parse_proc_route6_line(const char *line, char *ipstr, char *gwstr, ch &gw[0], &gw[1], &gw[2], &gw[3], metric, &refcnt, &use, &flags, dev); - if (strcmp(dev, "lo") == 0) + if (DM_STRCMP(dev, "lo") == 0) return -1; ip[0] = htonl(ip[0]); @@ -212,7 +212,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN continue; } parse_proc_route_line(line, &proute); - if ((strcmp(iface, proute.iface) == 0) && strcmp(target, proute.destination) == 0) { + if ((DM_STRCMP(iface, proute.iface) == 0) && DM_STRCMP(target, proute.destination) == 0) { found = true; break; } @@ -242,7 +242,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN return 0; } str = dmjson_get_value(jobj, 1, "l3_device"); - if (strcmp(str, proute.iface) == 0) { + if (DM_STRCMP(str, proute.iface) == 0) { iface = section_name(s); break; } @@ -283,7 +283,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN if (parse_proc_route6_line(buf, ipstr, gwstr, dev, &metric)) continue; - if (strcmp(iface, dev) == 0 && strcmp(ipstr, target) == 0) { + if (DM_STRCMP(iface, dev) == 0 && DM_STRCMP(ipstr, target) == 0) { found = 1; break; } @@ -316,7 +316,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN return 0; } char *str = dmjson_get_value(jobj, 1, "device"); - if (strcmp(str, dev) == 0) { + if (DM_STRCMP(str, dev) == 0) { iface = section_name(s); break; } @@ -459,7 +459,7 @@ static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx dmuci_get_value_by_section_string(s, "proto", &proto); dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr); - if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) { + if ((proto && DM_STRCMP(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) { json_object *res = NULL, *route_obj = NULL, *arrobj = NULL; dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); @@ -643,7 +643,7 @@ static int get_router_ipv4forwarding_origin(char *refparam, struct dmctx *ctx, v dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res); DM_ASSERT(res, *value = "DHCPv4"); char *proto = dmjson_get_value(res, 1, "proto"); - *value = (proto && strncmp(proto, "ppp", 3) == 0) ? "IPCP" : "DHCPv4"; + *value = (proto && DM_STRNCMP(proto, "ppp", 3) == 0) ? "IPCP" : "DHCPv4"; } return 0; } @@ -885,7 +885,7 @@ static int get_RoutingRouteInformation_InterfaceSettingNumberOfEntries(char *ref dmuci_get_value_by_section_string(s, "proto", &proto); dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr); - if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) { + if ((proto && DM_STRCMP(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) { json_object *res = NULL, *routes = NULL; dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res); @@ -911,7 +911,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Status(char *refparam, st uci_foreach_sections("network", "route6", s) { dmuci_get_value_by_section_string(s, "target", &ip_target); dmuci_get_value_by_section_string(s, "gateway", &gateway); - if(strcmp(ip_target, buf) == 0 && strcmp(nexthop, gateway) == 0) { + if(DM_STRCMP(ip_target, buf) == 0 && DM_STRCMP(nexthop, gateway) == 0) { *value = "ForwardingEntryCreated"; return 0; } @@ -938,7 +938,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, if (parse_proc_route6_line(buf, ipstr, gwstr, dev, &metric)) continue; - if((strcmp(source, ipstr) == 0) && (strcmp(nexthop, gwstr) == 0)) + if((DM_STRCMP(source, ipstr) == 0) && (DM_STRCMP(nexthop, gwstr) == 0)) break; } fclose(fp); @@ -949,7 +949,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam, dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &jobj); if (!jobj) return 0; char *str = dmjson_get_value(jobj, 1, "device"); - if (strcmp(str, dev) == 0) { + if (DM_STRCMP(str, dev) == 0) { iface = section_name(s); break; } @@ -972,10 +972,10 @@ static int get_RoutingRouteInformationInterfaceSetting_RouteLifetime(char *refpa *value = "0001-01-01T00:00:00Z"; char *valid = dmjson_get_value((struct json_object *)data, 1, "valid"); - if (valid && *valid != '\0' && atoi(valid) > 0) { + if (valid && *valid != '\0' && DM_STRTOL(valid) > 0) { char local_time[32] = {0}; - if (get_shift_utc_time(atoi(valid), local_time, sizeof(local_time)) == -1) + if (get_shift_utc_time(DM_STRTOL(valid), local_time, sizeof(local_time)) == -1) return 0; *value = dmstrdup(local_time); } diff --git a/dmtree/tr181/security.c b/dmtree/tr181/security.c index 01267826..b2e52ed6 100644 --- a/dmtree/tr181/security.c +++ b/dmtree/tr181/security.c @@ -95,14 +95,16 @@ static char *get_certificate_sig_alg(int sig_nid) static char *generate_serial_number(char *text, int length) { - int i, j; char *hex = (char *)dmcalloc(100, sizeof(char)); + unsigned pos = 0; - for (i = 0, j = 0; i < length; ++i, j += 3) { - sprintf(hex + j, "%02x", text[i] & 0xff); - if (i < length-1) - sprintf(hex + j + 2, "%c", ':'); + for (int i = 0; i < length; i++) { + pos += snprintf(&hex[pos], 100 - pos, "%02x:", text[i] & 0xff); } + + if (pos) + hex[pos - 1] = 0; + return hex; } @@ -168,7 +170,7 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod get_certificate_paths(); int i; for (i = 0; i < MAX_CERT; i++) { - if(!strlen(certifcates_paths[i])) + if(!DM_STRLEN(certifcates_paths[i])) break; FILE *fp = fopen(certifcates_paths[i], "r"); if (fp == NULL) diff --git a/dmtree/tr181/times.c b/dmtree/tr181/times.c index feae3a00..fb2409af 100644 --- a/dmtree/tr181/times.c +++ b/dmtree/tr181/times.c @@ -110,7 +110,7 @@ static int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, i *value = ""; return 0; } - if (strcmp(*value, "none") == 0) { + if (DM_STRCMP(*value, "none") == 0) { *value = ""; } return 0; diff --git a/dmtree/tr181/upnp.c b/dmtree/tr181/upnp.c index 25537f88..ef2f7335 100644 --- a/dmtree/tr181/upnp.c +++ b/dmtree/tr181/upnp.c @@ -115,7 +115,7 @@ static int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent 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"); - if(strcmp(is_root_device, "0") == 0) + if(DM_STRCMP(is_root_device, "0") == 0) continue; descurl = dmjson_get_value(device, 1, "descurl"); diff --git a/dmtree/tr181/usb.c b/dmtree/tr181/usb.c index b2ec2737..c9b3fc83 100644 --- a/dmtree/tr181/usb.c +++ b/dmtree/tr181/usb.c @@ -146,7 +146,7 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void snprintf(port_link, sizeof(port_link), "%s", foldersplit[0]); } sysfs_foreach_file(netfolderpath, dir, ent) { - if(strcmp(ent->d_name, ".")==0 || strcmp(ent->d_name, "..")==0) + if(DM_STRCMP(ent->d_name, ".")==0 || DM_STRCMP(ent->d_name, "..")==0) continue; snprintf(iface_name, sizeof(iface_name), "%s", ent->d_name); @@ -188,7 +188,7 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre if (regexec(®ex1, p->sysfs_folder_name, 0, NULL, 0) != 0 && regexec(®ex2, p->sysfs_folder_name, 0, NULL, 0) !=0 && - strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) + DM_STRSTR(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) continue; init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port); @@ -215,7 +215,7 @@ static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, v list_for_each_entry(p, &dup_list, list) { - if(!strstr(p->sysfs_folder_name, "usb")) + if(!DM_STRSTR(p->sysfs_folder_name, "usb")) continue; init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port); @@ -245,7 +245,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch LIST_HEAD(dup_list_no_inst); sysfs_foreach_file(sysfsrep, dir, ent) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) + if (DM_STRCMP(ent->d_name, ".") == 0 || DM_STRCMP(ent->d_name, "..") == 0) continue; if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) { @@ -255,7 +255,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", sysfsrep, ent->d_name); dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass)); - if (strncmp(deviceClass, "09", 2) == 0) { + if (DM_STRNCMP(deviceClass, "09", 2) == 0) { char hubpath[270]; snprintf(hubpath, sizeof(hubpath), "%s/%s", sysfsrep, ent->d_name); @@ -375,7 +375,7 @@ static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *d sysfs_foreach_file(usb_dev->folder_path, dir, ent) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) + if (DM_STRCMP(ent->d_name, ".") == 0 || DM_STRCMP(ent->d_name, "..") == 0) continue; if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) == 0) { @@ -610,9 +610,9 @@ static int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char __read_sysfs_usb_port(port, "bDeviceClass", deviceclass, sizeof(deviceclass)); - if(strstr(port->folder_name, "usb") == port->folder_name) + if(DM_STRSTR(port->folder_name, "usb") == port->folder_name) *value= "Host"; - else if (strcmp(deviceclass, "09") == 0) + else if (DM_STRCMP(deviceclass, "09") == 0) *value= "Hub"; else *value= "Device"; @@ -625,11 +625,11 @@ static int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char __read_sysfs_usb_port(data, "speed", speed, sizeof(speed)); - if(strcmp(speed, "1.5") == 0) + if(DM_STRCMP(speed, "1.5") == 0) *value= "Low"; - else if(strcmp(speed, "12") == 0) + else if(DM_STRCMP(speed, "12") == 0) *value= "Full"; - else if(strcmp(speed, "480") == 0) + else if(DM_STRCMP(speed, "480") == 0) *value= "High"; else *value= "Super"; @@ -644,7 +644,7 @@ static int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char if (pwrctl[0] == 0) *value = "Unknown"; - else if (!strcmp(pwrctl, "auto")) + else if (!DM_STRCMP(pwrctl, "auto")) *value ="Self"; else *value ="Bus"; @@ -688,7 +688,7 @@ static int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *d char up[32]; __read_sysfs_usb_port(data, "power/wakeup", up, sizeof(up)); - *value = strcmp(up, "enabled") == 0 ? "1" : "0"; + *value = DM_STRCMP(up, "enabled") == 0 ? "1" : "0"; return 0; } @@ -745,7 +745,7 @@ static int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmct __read_sysfs_usb_port(data, "power/level", power, sizeof(power)); - if(power[0] == 0 || strcmp(power, "suspend") == 0) + if(power[0] == 0 || DM_STRCMP(power, "suspend") == 0) *value= "false"; else *value= "true"; @@ -936,7 +936,7 @@ static int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *c char status[16] = {0}; __read_sysfs_usb_port(data, "power/runtime_status", status, sizeof(status)); - if(strncmp(status, "suspended", 9) == 0) + if(DM_STRNCMP(status, "suspended", 9) == 0) *value= "1"; else *value = "0"; diff --git a/dmtree/tr181/wifi.c b/dmtree/tr181/wifi.c index 645f2e84..8a2370db 100644 --- a/dmtree/tr181/wifi.c +++ b/dmtree/tr181/wifi.c @@ -127,27 +127,27 @@ static char *get_radio_option_nocache(const char *device_name, char *option) static char *get_data_model_mode(const char *ubus_mode) { - if (strcmp(ubus_mode, "WEP64") == 0) + if (DM_STRCMP(ubus_mode, "WEP64") == 0) return "WEP-64"; - else if (strcmp(ubus_mode, "WEP128") == 0) + else if (DM_STRCMP(ubus_mode, "WEP128") == 0) return "WEP-128"; - else if (strcmp(ubus_mode, "WPAPSK") == 0) + else if (DM_STRCMP(ubus_mode, "WPAPSK") == 0) return "WPA-Personal"; - else if (strcmp(ubus_mode, "WPA2PSK") == 0) + else if (DM_STRCMP(ubus_mode, "WPA2PSK") == 0) return "WPA2-Personal"; - else if (strcmp(ubus_mode, "WPA3PSK") == 0) + else if (DM_STRCMP(ubus_mode, "WPA3PSK") == 0) return "WPA3-Personal"; - else if (strcmp(ubus_mode, "WPAPSK+WPA2PSK") == 0) + else if (DM_STRCMP(ubus_mode, "WPAPSK+WPA2PSK") == 0) return "WPA-WPA2-Personal"; - else if (strcmp(ubus_mode, "WPA2PSK+WPA3PSK") == 0) + else if (DM_STRCMP(ubus_mode, "WPA2PSK+WPA3PSK") == 0) return "WPA3-Personal-Transition"; - else if (strcmp(ubus_mode, "WPA") == 0) + else if (DM_STRCMP(ubus_mode, "WPA") == 0) return "WPA-Enterprise"; - else if (strcmp(ubus_mode, "WPA2") == 0) + else if (DM_STRCMP(ubus_mode, "WPA2") == 0) return "WPA2-Enterprise"; - else if (strcmp(ubus_mode, "WPA3") == 0) + else if (DM_STRCMP(ubus_mode, "WPA3") == 0) return "WPA3-Enterprise"; - else if (strcmp(ubus_mode, "WPA+WPA2") == 0) + else if (DM_STRCMP(ubus_mode, "WPA+WPA2") == 0) return "WPA-WPA2-Enterprise"; else return "None"; @@ -167,7 +167,7 @@ static int get_supported_modes(const char *ubus_method, const char *ifname, char list_modes[0] = 0; dmjson_foreach_value_in_array(res, supported_modes, mode, idx, 1, "supp_security") { - if (!strstr(dm_wifi_driver_modes_supported, mode)) + if (!DM_STRSTR(dm_wifi_driver_modes_supported, mode)) continue; pos += snprintf(&list_modes[pos], sizeof(list_modes) - pos, "%s,", get_data_model_mode(mode)); @@ -192,11 +192,11 @@ static char *get_security_mode(struct uci_section *section) return "None"; /*Here the encryption type and the cipher are seperated*/ - ptrch = strchr(encryption, '+'); + ptrch = DM_STRCHR(encryption, '+'); if (ptrch) *ptrch = '\0'; - if (strstr(encryption, "wep")) { + if (DM_STRSTR(encryption, "wep")) { char *key_index = NULL, *key = NULL; dmuci_get_value_by_section_string(section, "key", &key_index); @@ -206,25 +206,25 @@ static char *get_security_mode(struct uci_section *section) snprintf(buf, sizeof(buf), "key%s", key_index); dmuci_get_value_by_section_string(section, buf, &key); } - return (key && strlen(key) == 10) ? "WEP-64" : "WEP-128"; + return (key && DM_STRLEN(key) == 10) ? "WEP-64" : "WEP-128"; } - else if (strncmp(encryption, "psk-mixed", 9) == 0) + else if (DM_STRNCMP(encryption, "psk-mixed", 9) == 0) return "WPA-WPA2-Personal"; - else if (strncmp(encryption, "psk2", 4) == 0) + else if (DM_STRNCMP(encryption, "psk2", 4) == 0) return "WPA2-Personal"; - else if (strncmp(encryption, "psk", 3) == 0) + else if (DM_STRNCMP(encryption, "psk", 3) == 0) return "WPA-Personal"; - else if (strcmp(encryption, "sae") == 0) + else if (DM_STRCMP(encryption, "sae") == 0) return "WPA3-Personal"; - else if (strcmp(encryption, "sae-mixed") == 0) + else if (DM_STRCMP(encryption, "sae-mixed") == 0) return "WPA3-Personal-Transition"; - else if (strncmp(encryption, "wpa-mixed", 9) == 0) + else if (DM_STRNCMP(encryption, "wpa-mixed", 9) == 0) return "WPA-WPA2-Enterprise"; - else if (strncmp(encryption, "wpa2", 4) == 0) + else if (DM_STRNCMP(encryption, "wpa2", 4) == 0) return "WPA2-Enterprise"; - else if (strncmp(encryption, "wpa3", 4) == 0) + else if (DM_STRNCMP(encryption, "wpa3", 4) == 0) return "WPA3-Enterprise"; - else if (strncmp(encryption, "wpa", 3) == 0) + else if (DM_STRNCMP(encryption, "wpa", 3) == 0) return "WPA-Enterprise"; else return "None"; @@ -281,7 +281,7 @@ struct uci_section *find_mapcontroller_ssid_section(struct uci_section *wireless return NULL; dmuci_get_value_by_section_string(wireless_ssid_s, "multi_ap", &multi_ap); - if (strcmp(multi_ap, "2") != 0) + if (DM_STRCMP(multi_ap, "2") != 0) return NULL; dmuci_get_value_by_section_string(wireless_ssid_s, "network", &network); @@ -298,8 +298,8 @@ struct uci_section *find_mapcontroller_ssid_section(struct uci_section *wireless dmuci_get_value_by_section_string(s, "band", &curr_band); dmuci_get_value_by_section_string(s, "network", &curr_network); - if (strcmp(network, curr_network) == 0 && - strcmp(curr_ssid, ssid) == 0 && + if (DM_STRCMP(network, curr_network) == 0 && + DM_STRCMP(curr_ssid, ssid) == 0 && curr_band[0] == band[0]) { return s; } @@ -350,7 +350,7 @@ static int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ssid_s), &dmmap_section); dmuci_get_value_by_section_string(dmmap_section, "ap_added_by_user", &added_by_user); - if (strcmp(added_by_user, "1") == 0) + if (DM_STRCMP(added_by_user, "1") == 0) continue; dmuci_delete_by_section(dmmap_section, NULL, NULL); @@ -400,7 +400,7 @@ static int delete_wifi_accesspoint(char *refparam, struct dmctx *ctx, void *data get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(ap_s), &dmmap_section); dmuci_get_value_by_section_string(dmmap_section, "ssid_added_by_user", &added_by_user); - if (strcmp(added_by_user, "1") == 0) + if (DM_STRCMP(added_by_user, "1") == 0) continue; dmuci_delete_by_section(dmmap_section, NULL, NULL); @@ -443,7 +443,7 @@ static int delObjWiFiEndPoint(char *refparam, struct dmctx *ctx, void *data, cha char *mode; dmuci_get_value_by_section_string(s, "mode", &mode); - if (strcmp(mode, "sta") != 0) + if (DM_STRCMP(mode, "sta") != 0) continue; dmuci_set_value_by_section(s, "mode", ""); @@ -509,7 +509,7 @@ static int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr char *added_by_user; dmuci_get_value_by_section_string(p->dmmap_section, "ap_added_by_user", &added_by_user); - if (strcmp(added_by_user, "1") == 0) + if (DM_STRCMP(added_by_user, "1") == 0) continue; dmuci_get_value_by_section_string(p->dmmap_section, "ifname", &ifname); @@ -539,11 +539,11 @@ static int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, v char *mode, *ifname, *added_by_user; dmuci_get_value_by_section_string(p->config_section, "mode", &mode); - if (strcmp(mode, "ap") != 0) + if (DM_STRCMP(mode, "ap") != 0) continue; dmuci_get_value_by_section_string(p->dmmap_section, "ssid_added_by_user", &added_by_user); - if (strcmp(added_by_user, "1") == 0) + if (DM_STRCMP(added_by_user, "1") == 0) continue; dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); @@ -573,7 +573,7 @@ static int browseWiFiEndPointInst(struct dmctx *dmctx, DMNODE *parent_node, void list_for_each_entry(p, &dup_list, list) { dmuci_get_value_by_section_string(p->config_section, "mode", &mode); - if (strcmp(mode, "sta") != 0) + if (DM_STRCMP(mode, "sta") != 0) continue; dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname); @@ -650,7 +650,7 @@ static int browseWiFiDataElementsNetworkSSIDInst(struct dmctx *dmctx, DMNODE *pa char *type = NULL; dmuci_get_value_by_section_string(p->config_section, "type", &type); - if (strcmp(type, "fronthaul") != 0) + if (DM_STRCMP(type, "fronthaul") != 0) continue; inst = handle_instance(dmctx, parent_node, p->dmmap_section, "wifi_da_ssid_instance", "wifi_da_ssid_alias"); @@ -678,7 +678,7 @@ static json_object *dump_find_device_object(const char *unique_key) dmjson_foreach_obj_in_array(data_obj, dev_arr, dev_obj, j, 2, "wfa-dataelements:Network", "DeviceList") { char *id = dmjson_get_value(dev_obj, 1, "ID"); - if (strcmp(unique_key, id) == 0) + if (DM_STRCMP(unique_key, id) == 0) return dev_obj; } } @@ -697,7 +697,7 @@ static json_object *dump2_find_device_object(const char *unique_key) dmjson_foreach_obj_in_array(res, device_arr, device_obj, i, 1, "APDeviceList") { char *macaddr = dmjson_get_value(device_obj, 1, "macaddr"); - if (strcmp(unique_key, macaddr) == 0) + if (DM_STRCMP(unique_key, macaddr) == 0) return device_obj; } @@ -715,8 +715,8 @@ static json_object *dump_find_radio_object(json_object *device_obj, const char * char mac[32] = {0}; char *id = dmjson_get_value(radio_obj, 1, "ID"); char *str = base64_decode(id); - string_to_mac(str, strlen(str), mac, sizeof(mac)); - if (strcmp(unique_key, mac) == 0) + string_to_mac(str, DM_STRLEN(str), mac, sizeof(mac)); + if (DM_STRCMP(unique_key, mac) == 0) return radio_obj; } @@ -732,7 +732,7 @@ static json_object *dump2_find_radio_object(json_object *device_obj, const char dmjson_foreach_obj_in_array(device_obj, radio_arr, radio_obj, i, 1, "RadioList") { char *mac = dmjson_get_value(radio_obj, 1, "macaddr"); - if (strcmp(unique_key, mac) == 0) + if (DM_STRCMP(unique_key, mac) == 0) return radio_obj; } @@ -1317,7 +1317,7 @@ static int set_WiFiRadio_DTIMPeriod(char *refparam, struct dmctx *ctx, void *dat dmuci_get_value_by_section_string(s, "mode", &mode); - if (strcmp(mode, "ap") != 0) + if (DM_STRCMP(mode, "ap") != 0) continue; dmuci_set_value_by_section(s, "dtim_period", value); @@ -1340,7 +1340,7 @@ static int get_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx int freq; sscanf(htmode, "%*[A-Z]%d", &freq); - dmasprintf(value, "%dMHz", !strcmp(htmode, "NOHT") ? 20 : freq); + dmasprintf(value, "%dMHz", !DM_STRCMP(htmode, "NOHT") ? 20 : freq); } else { *value = "Auto"; } @@ -1362,8 +1362,8 @@ static int get_WiFiRadio_SupportedOperatingChannelBandwidths(char *refparam, str bandwidth_list[0] = 0; dmjson_foreach_obj_in_array(res, arrobj, supp_channels, i, 1, "supp_channels") { char *bandwidth = dmjson_get_value(supp_channels, 1, "bandwidth"); - if (bandwidth && !strstr(bandwidth_list, !strcmp(bandwidth, "8080") ? "80+80" : !strcmp(bandwidth, "80") ? ",80MHz" : bandwidth)) { - pos += snprintf(&bandwidth_list[pos], sizeof(bandwidth_list) - pos, "%sMHz,", !strcmp(bandwidth, "8080") ? "80+80" : bandwidth); + if (bandwidth && !strstr(bandwidth_list, !DM_STRCMP(bandwidth, "8080") ? "80+80" : !DM_STRCMP(bandwidth, "80") ? ",80MHz" : bandwidth)) { + pos += snprintf(&bandwidth_list[pos], sizeof(bandwidth_list) - pos, "%sMHz,", !DM_STRCMP(bandwidth, "8080") ? "80+80" : bandwidth); } } @@ -1399,9 +1399,9 @@ static int set_WiFiRadio_OperatingChannelBandwidth(char *refparam, struct dmctx dmuci_get_value_by_section_string((((struct wifi_radio_args *)data)->sections)->config_section, "htmode", &curr_htmode); - if (strncmp(curr_htmode, "VHT", 3) == 0) + if (DM_STRNCMP(curr_htmode, "VHT", 3) == 0) snprintf(htmode, sizeof(htmode), "VHT%d", freq); - else if (strncmp(curr_htmode, "HT", 2) == 0 && (freq == 20 || freq == 40)) + else if (DM_STRNCMP(curr_htmode, "HT", 2) == 0 && (freq == 20 || freq == 40)) snprintf(htmode, sizeof(htmode), "HT%d", freq); else snprintf(htmode, sizeof(htmode), "HE%d", freq); @@ -1428,7 +1428,7 @@ static int set_WiFiRadio_PreambleType(char *refparam, struct dmctx *ctx, void *d return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((((struct wifi_radio_args *)data)->sections)->config_section, "short_preamble", (strcmp(value, "short") == 0) ? "1" : "0"); + dmuci_set_value_by_section((((struct wifi_radio_args *)data)->sections)->config_section, "short_preamble", (DM_STRCMP(value, "short") == 0) ? "1" : "0"); break; } return 0; @@ -1530,7 +1530,7 @@ static int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char static int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((((struct wifi_radio_args *)data)->sections)->config_section, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') + if (DM_STRCMP(*value, "auto") == 0 || (*value)[0] == '\0') *value = "1"; else *value = "0"; @@ -1615,7 +1615,7 @@ static int get_access_point_control_enable(char *refparam, struct dmctx *ctx, vo char *macfilter; dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "macfilter", &macfilter); - if (macfilter[0] == 0 || strcmp(macfilter, "deny") == 0 || strcmp(macfilter, "disable") == 0) + if (macfilter[0] == 0 || DM_STRCMP(macfilter, "deny") == 0 || DM_STRCMP(macfilter, "disable") == 0) *value = "false"; else *value = "true"; @@ -1764,11 +1764,11 @@ static bool is_different_group(const char *mode1, const char *mode2) "WPA-Enterprise, WPA2-Enterprise, WPA3-Enterprise, WPA-WPA2-Enterprise"}; for (i = 0; i < 3; i++) { - if (strstr(security_modes[i], mode1)) { + if (DM_STRSTR(security_modes[i], mode1)) { g1 = i; } - if (strstr(security_modes[i], mode2)) { + if (DM_STRSTR(security_modes[i], mode2)) { g2 = i; } } @@ -1789,20 +1789,20 @@ static void set_security_mode(struct uci_section *section, char *value, bool is_ // Use default key only in case the key is not set dmuci_get_value_by_section_string(section, "key", &wpa_key); - if (strlen(wpa_key) == 0) + if (DM_STRLEN(wpa_key) == 0) wpa_key = get_default_wpa_key(); - if (mode && strcmp(value, mode) != 0) { + if (mode && DM_STRCMP(value, mode) != 0) { // Only reset the wlan key section if its belongs to different group if (is_different_group(value, mode)) reset_wlan(section); dmuci_set_value_by_section(section, "ieee80211w", "0"); - if (strcmp(value, "None") == 0) { + if (DM_STRCMP(value, "None") == 0) { dmuci_set_value_by_section(section, "encryption", "none"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "none"); - } else if (strcmp(value, "WEP-64") == 0) { + } else if (DM_STRCMP(value, "WEP-64") == 0) { char key[16], buf[11]; int i; @@ -1815,7 +1815,7 @@ static void set_security_mode(struct uci_section *section, char *value, bool is_ dmuci_set_value_by_section(section, "key", "1"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "none"); - } else if (strcmp(value, "WEP-128") == 0) { + } else if (DM_STRCMP(value, "WEP-128") == 0) { char key[16], buf[27]; int i; @@ -1828,19 +1828,19 @@ static void set_security_mode(struct uci_section *section, char *value, bool is_ dmuci_set_value_by_section(section, "key", "1"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "none"); - } else if (strcmp(value, "WPA-Personal") == 0) { + } else if (DM_STRCMP(value, "WPA-Personal") == 0) { dmuci_set_value_by_section(section, "encryption", "psk"); dmuci_set_value_by_section(section, "key", wpa_key); dmuci_set_value_by_section(section, "wpa_group_rekey", "3600"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "psk"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "key", wpa_key); - } else if (strcmp(value, "WPA-Enterprise") == 0) { + } else if (DM_STRCMP(value, "WPA-Enterprise") == 0) { dmuci_set_value_by_section(section, "encryption", "wpa"); dmuci_set_value_by_section(section, "auth_port", "1812"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "wpa"); - } else if (strcmp(value, "WPA2-Personal") == 0) { + } else if (DM_STRCMP(value, "WPA2-Personal") == 0) { dmuci_set_value_by_section(section, "encryption", "psk2"); dmuci_set_value_by_section(section, "key", wpa_key); dmuci_set_value_by_section(section, "wpa_group_rekey", "3600"); @@ -1849,13 +1849,13 @@ static void set_security_mode(struct uci_section *section, char *value, bool is_ if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "psk2"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "key", wpa_key); - } else if (strcmp(value, "WPA2-Enterprise") == 0) { + } else if (DM_STRCMP(value, "WPA2-Enterprise") == 0) { dmuci_set_value_by_section(section, "encryption", "wpa2"); dmuci_set_value_by_section(section, "auth_port", "1812"); dmuci_set_value_by_section(section, "ieee80211w", "1"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "wpa2"); - } else if (strcmp(value, "WPA-WPA2-Personal") == 0) { + } else if (DM_STRCMP(value, "WPA-WPA2-Personal") == 0) { dmuci_set_value_by_section(section, "encryption", "psk-mixed"); dmuci_set_value_by_section(section, "key", wpa_key); dmuci_set_value_by_section(section, "wpa_group_rekey", "3600"); @@ -1863,24 +1863,24 @@ static void set_security_mode(struct uci_section *section, char *value, bool is_ if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "psk-mixed"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "key", wpa_key); - } else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { + } else if (DM_STRCMP(value, "WPA-WPA2-Enterprise") == 0) { dmuci_set_value_by_section(section, "encryption", "wpa-mixed"); dmuci_set_value_by_section(section, "auth_port", "1812"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "wpa-mixed"); - } else if (strcmp(value, "WPA3-Personal") == 0) { + } else if (DM_STRCMP(value, "WPA3-Personal") == 0) { dmuci_set_value_by_section(section, "encryption", "sae"); dmuci_set_value_by_section(section, "key", wpa_key); dmuci_set_value_by_section(section, "ieee80211w", "2"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "sae"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "key", wpa_key); - } else if (strcmp(value, "WPA3-Enterprise") == 0) { + } else if (DM_STRCMP(value, "WPA3-Enterprise") == 0) { dmuci_set_value_by_section(section, "encryption", "wpa3"); dmuci_set_value_by_section(section, "auth_port", "1812"); if (map_ssid_s) dmuci_set_value_by_section(map_ssid_s, "encryption", "wpa"); - } else if (strcmp(value, "WPA3-Personal-Transition") == 0) { + } else if (DM_STRCMP(value, "WPA3-Personal-Transition") == 0) { dmuci_set_value_by_section(section, "encryption", "sae-mixed"); dmuci_set_value_by_section(section, "key", wpa_key); dmuci_set_value_by_section(section, "ieee80211w", "1"); @@ -1933,7 +1933,7 @@ static int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, v return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "wep")) { + if (DM_STRSTR(encryption, "wep")) { char *key_index = NULL, buf[16]; dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "key", &key_index); @@ -1957,7 +1957,7 @@ static int set_access_point_security_shared_key(char *refparam, struct dmctx *ct return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "psk")) { + if (DM_STRSTR(encryption, "psk")) { dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "key", value); // mapcontroller config: Update the corresponding fronthaul ssid section if exist @@ -1981,7 +1981,7 @@ static int set_access_point_security_passphrase(char *refparam, struct dmctx *ct return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "psk")) + if (DM_STRSTR(encryption, "psk")) set_access_point_security_shared_key(refparam, ctx, data, instance, value, action); return 0; } @@ -2006,7 +2006,7 @@ static int set_access_point_security_rekey_interval(char *refparam, struct dmctx return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (!strstr(encryption, "wep") && strcmp(encryption, "none") != 0) + if (!DM_STRSTR(encryption, "wep") && DM_STRCMP(encryption, "none") != 0) dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "wpa_group_rekey", value); return 0; } @@ -2026,7 +2026,7 @@ static int set_WiFiAccessPointSecurity_SAEPassphrase(char *refparam, struct dmct break; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "sae")) { + if (DM_STRSTR(encryption, "sae")) { dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "key", value); // mapcontroller config: Update the corresponding fronthaul ssid section if exist @@ -2056,7 +2056,7 @@ static int set_access_point_security_radius_ip_address(char *refparam, struct dm return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "wpa")) + if (DM_STRSTR(encryption, "wpa")) dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "auth_server", value); return 0; } @@ -2081,7 +2081,7 @@ static int set_access_point_security_radius_server_port(char *refparam, struct d return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "wpa")) + if (DM_STRSTR(encryption, "wpa")) dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "auth_port", value); return 0; } @@ -2099,7 +2099,7 @@ static int set_access_point_security_radius_secret(char *refparam, struct dmctx return 0; case VALUESET: dmuci_get_value_by_section_string((((struct wifi_acp_args *)data)->sections)->config_section, "encryption", &encryption); - if (strstr(encryption, "wpa")) + if (DM_STRSTR(encryption, "wpa")) dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "auth_secret", value); return 0; } @@ -2126,13 +2126,13 @@ static void get_cipher(char *encryption, bool *aes, bool *sae, bool *tkip) for (token = strtok_r(encryption, "+", &saveptr); token; token = strtok_r(NULL, "+", &saveptr)) { - if (strcmp(token, "aes") == 0) + if (DM_STRCMP(token, "aes") == 0) *aes = true; - if (strcmp(token, "sae") == 0) + if (DM_STRCMP(token, "sae") == 0) *sae = true; - if (strcmp(token, "tkip") == 0) + if (DM_STRCMP(token, "tkip") == 0) *tkip = true; } } @@ -2159,23 +2159,23 @@ static int validate_mfp_config(struct uci_section *section, const char *value) /*Here we get which cipher is true*/ get_cipher(encryption, &aes, &sae, &tkip); - if ((strcmp(mode, "WPA3-Personal")) == 0) { - if ((sae == true || aes == true) && (tkip == false) && (strcmp(value, "Required") == 0)) + if ((DM_STRCMP(mode, "WPA3-Personal")) == 0) { + if ((sae == true || aes == true) && (tkip == false) && (DM_STRCMP(value, "Required") == 0)) return 0; else return -1; - } else if (strcmp(mode, "WPA2-Personal") == 0) { - if ((aes == true) && (tkip == false) && (strcmp(value, "Optional") == 0)) + } else if (DM_STRCMP(mode, "WPA2-Personal") == 0) { + if ((aes == true) && (tkip == false) && (DM_STRCMP(value, "Optional") == 0)) return 0; else return -1; - } else if (strcmp(mode, "WPA3-Personal-Transition") == 0) { - if ((sae == true || aes == true) && (tkip == false) && (strcmp(value, "Optional") == 0)) + } else if (DM_STRCMP(mode, "WPA3-Personal-Transition") == 0) { + if ((sae == true || aes == true) && (tkip == false) && (DM_STRCMP(value, "Optional") == 0)) return 0; else return -1; - } else if (strcmp(value, "Disabled") == 0) + } else if (DM_STRCMP(value, "Disabled") == 0) return 0; else return -1; @@ -2196,11 +2196,11 @@ static int set_WiFiAccessPointSecurity_MFPConfig(char *refparam, struct dmctx *c break; case VALUESET: - if (strcmp(value, "Disabled") == 0) + if (DM_STRCMP(value, "Disabled") == 0) buf[0] = '0'; - else if (strcmp(value, "Optional") == 0) + else if (DM_STRCMP(value, "Optional") == 0) buf[0] = '1'; - else if (strcmp(value, "Required") == 0) + else if (DM_STRCMP(value, "Required") == 0) buf[0] = '2'; buf[1] = 0; dmuci_set_value_by_section((((struct wifi_acp_args *)data)->sections)->config_section, "ieee80211w", buf); @@ -2248,17 +2248,17 @@ static int get_wps_config_methods_enabled(struct uci_section *section, char **va dmuci_get_value_by_section_string(section, "wps_label", &label); dmuci_get_value_by_section_string(section, "wps_pin", &pin); - if (*pushbut && strcmp(pushbut, "1") == 0) - strcpy(buf, "PushButton"); + if (*pushbut && DM_STRCMP(pushbut, "1") == 0) + DM_STRNCPY(buf, "PushButton", sizeof(buf)); - if (*label && strcmp(label, "1") == 0) { + if (*label && DM_STRCMP(label, "1") == 0) { if (*buf) strcat(buf, ","); strcat(buf, "Label"); } - if (*pin && strcmp(pin, "1") == 0) { + if (*pin && DM_STRCMP(pin, "1") == 0) { if (*buf) strcat(buf, ","); @@ -2277,13 +2277,13 @@ static void set_wps_config_methods_enabled(struct uci_section *section, char *va char *wps_list = dmstrdup(value); for (token = strtok_r(wps_list, ",", &saveptr); token; token = strtok_r(NULL, ",", &saveptr)) { - if (strcmp(token, "PushButton") == 0) + if (DM_STRCMP(token, "PushButton") == 0) pushbut = true; - if (strcmp(token, "Label") == 0) + if (DM_STRCMP(token, "Label") == 0) label = true; - if (strcmp(token, "PIN") == 0) + if (DM_STRCMP(token, "PIN") == 0) pin = true; } dmfree(wps_list); @@ -2600,7 +2600,7 @@ static int set_WiFiEndPointProfileSecurity_WEPKey(char *refparam, struct dmctx * return 0; case VALUESET: dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strstr(encryption, "wep")) { + if (DM_STRSTR(encryption, "wep")) { char *key_index = NULL, buf[16]; dmuci_get_value_by_section_string((struct uci_section*)data, "key", &key_index); @@ -2623,7 +2623,7 @@ static int set_WiFiEndPointProfileSecurity_PreSharedKey(char *refparam, struct d return 0; case VALUESET: dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strstr(encryption, "psk")) + if (DM_STRSTR(encryption, "psk")) dmuci_set_value_by_section((struct uci_section*)data, "key", value); return 0; } @@ -2641,7 +2641,7 @@ static int set_WiFiEndPointProfileSecurity_KeyPassphrase(char *refparam, struct return 0; case VALUESET: dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strstr(encryption, "psk")) + if (DM_STRSTR(encryption, "psk")) set_WiFiEndPointProfileSecurity_PreSharedKey(refparam, ctx, data, instance, value, action); return 0; } @@ -2660,7 +2660,7 @@ static int set_WiFiEndPointProfileSecurity_SAEPassphrase(char *refparam, struct break; case VALUESET: dmuci_get_value_by_section_string((struct uci_section*)data, "encryption", &encryption); - if (strstr(encryption, "sae")) + if (DM_STRSTR(encryption, "sae")) dmuci_set_value_by_section((struct uci_section*)data, "key", value); break; } @@ -2673,9 +2673,9 @@ static int get_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmct dmuci_get_value_by_section_string((struct uci_section*)data, "ieee80211w", value); if(*value[0] == 0 || *value[0] == '0') *value = "Disabled"; - else if (strcmp(*value, "1") == 0) + else if (DM_STRCMP(*value, "1") == 0) *value = "Optional"; - else if (strcmp(*value, "2") == 0) + else if (DM_STRCMP(*value, "2") == 0) *value = "Required"; return 0; } @@ -2688,11 +2688,11 @@ static int set_WiFiEndPointProfileSecurity_MFPConfig(char *refparam, struct dmct return FAULT_9007; break; case VALUESET: - if (strcmp(value, "Disabled") == 0) + if (DM_STRCMP(value, "Disabled") == 0) dmuci_set_value_by_section((struct uci_section*)data, "ieee80211w", "0"); - else if (strcmp(value, "Optional") == 0) + else if (DM_STRCMP(value, "Optional") == 0) dmuci_set_value_by_section((struct uci_section*)data, "ieee80211w", "1"); - else if (strcmp(value, "Required") == 0) + else if (DM_STRCMP(value, "Required") == 0) dmuci_set_value_by_section((struct uci_section*)data, "ieee80211w", "2"); break; } @@ -2911,13 +2911,13 @@ static int set_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char * get_dmmap_section_of_config_section("dmmap_wireless", "wifi-iface", section_name(s), &dmmap_section); dmuci_get_value_by_section_string(s, "ifname", &ifname); - if (strcmp(ifname, linker) == 0) { + if (DM_STRCMP(ifname, linker) == 0) { ssid_dmmap_s = dmmap_section; break; } dmuci_get_value_by_section_string(dmmap_section, "ifname", &ifname); - if (strcmp(ifname, linker) == 0) { + if (DM_STRCMP(ifname, linker) == 0) { ssid_dmmap_s = dmmap_section; break; } @@ -2945,7 +2945,7 @@ static int set_neighboring_wifi_diagnostics_diagnostics_state(char *refparam, st return FAULT_9007; return 0; case VALUESET: - if (strcmp(value, "Requested") == 0) { + if (DM_STRCMP(value, "Requested") == 0) { uci_foreach_sections("wireless", "wifi-device", ss) wifi_start_scan(section_name(ss)); @@ -3226,8 +3226,8 @@ static int get_WiFiAccessPointAssociatedDevice_AssociationTime(char *refparam, s *value = "0001-01-01T00:00:00Z"; char *in_network = dmjson_get_value((json_object *)data, 1, "in_network"); - if (in_network && *in_network != '\0' && atoi(in_network) > 0) { - time_t t_time = time(NULL) - atoi(in_network); + if (in_network && *in_network != '\0' && DM_STRTOL(in_network) > 0) { + time_t t_time = time(NULL) - DM_STRTOL(in_network); if (gmtime(&t_time) == NULL) return -1; @@ -3296,7 +3296,7 @@ static int get_wifi_access_point_status(char *refparam, struct dmctx *ctx, void DM_ASSERT(res, status = "Error_Misconfigured"); status = dmjson_get_value(res, 1, "status"); - if (strcmp(status, "running") == 0 || strcmp(status, "up") == 0) + if (DM_STRCMP(status, "running") == 0 || DM_STRCMP(status, "up") == 0) *value = "Enabled"; else *value = "Disabled"; @@ -3360,7 +3360,7 @@ static int set_radio_frequency(char *refparam, struct dmctx *ctx, void *data, ch break; case VALUESET: - dmuci_set_value_by_section((((struct wifi_radio_args *)data)->sections)->config_section, "hwmode", (!strcmp(value, "5GHz") ? "11a" :"11g")); + dmuci_set_value_by_section((((struct wifi_radio_args *)data)->sections)->config_section, "hwmode", (!DM_STRCMP(value, "5GHz") ? "11a" :"11g")); break; } return 0; @@ -3463,7 +3463,7 @@ static int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void * cur_opclass = dmjson_get_value(res, 1, "opclass"); dmjson_foreach_obj_in_array(res, arrobj, supp_channels, i, 1, "supp_channels") { char *opclass = dmjson_get_value(supp_channels, 1, "opclass"); - if (opclass && strcmp(opclass, cur_opclass) != 0) + if (opclass && DM_STRCMP(opclass, cur_opclass) != 0) continue; *value = dmjson_get_value_array_all(supp_channels, ",", 1, "channels"); @@ -3504,8 +3504,8 @@ static int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void dmubus_call(object, "status", UBUS_ARGS{0}, 0, &res); DM_ASSERT(res, *value = "n,ax"); char *standard = dmjson_get_value(res, 1, "standard"); - if (strstr(standard, "802.11")) { - DM_STRNCPY(standard_list, standard + strlen("802.11"), sizeof(standard_list)); + if (DM_STRSTR(standard, "802.11")) { + DM_STRNCPY(standard_list, standard + DM_STRLEN("802.11"), sizeof(standard_list)); replace_char(standard_list, '/', ','); } @@ -3542,30 +3542,30 @@ static int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void if (curr_htmode && *curr_htmode) { sscanf(curr_htmode, "%*[A-Z]%d", &freq); - freq = !strcmp(curr_htmode, "NOHT") ? 20 : freq; + freq = !DM_STRCMP(curr_htmode, "NOHT") ? 20 : freq; } band = get_radio_option_nocache(section_name((((struct wifi_radio_args *)data)->sections)->config_section), "band"); - if (strcmp(band, "5GHz") == 0) { - if (strstr(value, "ax")) + if (DM_STRCMP(band, "5GHz") == 0) { + if (DM_STRSTR(value, "ax")) snprintf(htmode, sizeof(htmode), "HE%d", freq); - else if (strstr(value, "ac")) + else if (DM_STRSTR(value, "ac")) snprintf(htmode, sizeof(htmode), "VHT%d", freq); - else if (strstr(value, "n")) + else if (DM_STRSTR(value, "n")) snprintf(htmode, sizeof(htmode), "HT%d", (freq != 20 && freq != 40) ? 20 : freq); else snprintf(htmode, sizeof(htmode), "NOHT"); snprintf(hwmode, sizeof(hwmode), "11a"); } else { - if (strstr(value, "ax")) { + if (DM_STRSTR(value, "ax")) { snprintf(htmode, sizeof(htmode), "HE%d", freq); snprintf(hwmode, sizeof(hwmode), "11g"); - } else if (strstr(value, "n")) { + } else if (DM_STRSTR(value, "n")) { snprintf(htmode, sizeof(htmode), "HT%d", (freq != 20 && freq != 40) ? 20 : freq); snprintf(hwmode, sizeof(hwmode), "11g"); - } else if (strstr(value, "g")) { + } else if (DM_STRSTR(value, "g")) { snprintf(htmode, sizeof(htmode), "NOHT"); snprintf(hwmode, sizeof(hwmode), "11g"); } else { @@ -3653,7 +3653,7 @@ static int get_WiFiDataElementsNetworkSSID_Band(char *refparam, struct dmctx *ct char *band = NULL; dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "band", &band); - *value = (!strcmp(band, "2")) ? "2.4" : "5"; + *value = (!DM_STRCMP(band, "2")) ? "2.4" : "5"; return 0; } @@ -4213,7 +4213,7 @@ static int get_WiFiDataElementsNetworkDeviceRadioCapabilities_VHTCapabilities(ch json_object_object_get_ex(((struct wifi_data_element_args *)data)->dump_obj, "Capabilites", &caps_obj); cap = (caps_obj) ? dmjson_get_value(caps_obj, 1, "VHTCapabilities") : ""; - if (strlen(cap)) { + if (DM_STRLEN(cap)) { *value = cap; } else { *value = "AAA="; @@ -4230,7 +4230,7 @@ static int get_WiFiDataElementsNetworkDeviceRadioCapabilities_HECapabilities(cha json_object_object_get_ex(((struct wifi_data_element_args *)data)->dump_obj, "Capabilites", &caps_obj); cap = (caps_obj) ? dmjson_get_value(caps_obj, 1, "HECapabilities") : ""; - if (strlen(cap)) { + if (DM_STRLEN(cap)) { *value = cap; } else { *value = "AAAAAA=="; @@ -5563,7 +5563,7 @@ static int operate_WiFiDataElementsNetwork_SetSSID(char *refparam, struct dmctx uci_foreach_option_eq("mapcontroller", "ap", "type", "fronthaul", s) { dmuci_get_value_by_section_string(s, "ssid", &curr_ssid); dmuci_get_value_by_section_string(s, "band", &curr_band); - if (strcmp(curr_ssid, ssid) == 0 && strncmp(curr_band, band, 1) == 0) { + if (DM_STRCMP(curr_ssid, ssid) == 0 && DM_STRNCMP(curr_band, band, 1) == 0) { if (*key) dmuci_set_value_by_section(s, "key", key); ssid_exist = true; break; @@ -5584,7 +5584,7 @@ static int operate_WiFiDataElementsNetwork_SetSSID(char *refparam, struct dmctx uci_foreach_option_eq_safe("mapcontroller", "ap", "type", "fronthaul", stmp, s) { dmuci_get_value_by_section_string(s, "ssid", &curr_ssid); dmuci_get_value_by_section_string(s, "band", &curr_band); - if (strcmp(curr_ssid, ssid) == 0 && strncmp(curr_band, band, 1) == 0) { + if (DM_STRCMP(curr_ssid, ssid) == 0 && DM_STRNCMP(curr_band, band, 1) == 0) { dmuci_delete_by_section(s, NULL, NULL); ssid_exist = true; break; diff --git a/dmtree/vendor/iopsys/tr104/servicesvoiceservicedect.c b/dmtree/vendor/iopsys/tr104/servicesvoiceservicedect.c index cb500920..4e293b57 100644 --- a/dmtree/vendor/iopsys/tr104/servicesvoiceservicedect.c +++ b/dmtree/vendor/iopsys/tr104/servicesvoiceservicedect.c @@ -20,7 +20,7 @@ static int get_ServicesVoiceServiceDECTPortable_Name(char *refparam, struct dmct dmuci_get_option_value_string("dect", ipui, "name", value); if ((*value)[0] == '\0') { - if (strlen(id)) + if (DM_STRLEN(id)) dmasprintf(value, "DECT%s", id); else dmasprintf(value, "DECT%s", instance); diff --git a/dmtree/vendor/iopsys/tr181/ethernet.c b/dmtree/vendor/iopsys/tr181/ethernet.c index 0065a3dc..44c72d5a 100644 --- a/dmtree/vendor/iopsys/tr181/ethernet.c +++ b/dmtree/vendor/iopsys/tr181/ethernet.c @@ -15,7 +15,7 @@ static int get_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", value); - *value = (strcmp(*value, "macvlan") == 0) ? "1" : "0"; + *value = (DM_STRCMP(*value, "macvlan") == 0) ? "1" : "0"; return 0; } diff --git a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c index 3ccc0ffd..95dd29cf 100644 --- a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c +++ b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_igmp.c @@ -23,7 +23,7 @@ static void get_mcast_iface_key(char *p_ifname, char *key, size_t key_size) pch = strtok_r(intf_device, " ", &spch); while (pch != NULL) { - if (strcmp(pch, p_ifname) == 0) { + if (DM_STRCMP(pch, p_ifname) == 0) { DM_STRNCPY(key, section_name(s), key_size); return; } @@ -44,7 +44,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) + if (DM_STRSTR(p_ifname, "br-") != NULL) DM_STRNCPY(key, p_ifname, sizeof(key)); else get_mcast_iface_key(p_ifname, key, sizeof(key)); @@ -103,7 +103,7 @@ void get_mcast_bridge_port_linker(struct dmctx *ctx, char *device_name, char **v char *mg = NULL; dmuci_get_value_by_section_string(bridge_port_s, "management", &mg); - if (mg && strcmp(mg, "1") == 0) { + if (mg && DM_STRCMP(mg, "1") == 0) { char *device, linker[512] = ""; dmuci_get_value_by_section_string(bridge_port_s, "port", &device); @@ -206,7 +206,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package, dmuci_get_value_by_section_string(dmmap_sect, "ipaddr", &f_ip); dmuci_get_value_by_section_string(dmmap_sect, "enable", &f_enable); - if ((f_ip[0] == '\0') || (strcmp(f_enable, "0") == 0)) + if ((f_ip[0] == '\0') || (DM_STRCMP(f_enable, "0") == 0)) add_dmmap_config_dup_list(dup_list, s, dmmap_sect); } } @@ -223,20 +223,20 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package, static int get_br_key_from_lower_layer(char *lower_layer, char *key, size_t s_key) { - char *p = strstr(lower_layer, "Port"); + char *p = DM_STRSTR(lower_layer, "Port"); if (!p) return -1; /* Get the bridge_key. */ - int len = strlen(p); + int len = DM_STRLEN(p); char new_if[250] = {0}; int i; - for (i = 0; i < strlen(lower_layer) - len; i++) { + for (i = 0; i < DM_STRLEN(lower_layer) - len; i++) { new_if[i] = lower_layer[i]; } - char br_key = new_if[strlen(new_if) - 2]; + char br_key = new_if[DM_STRLEN(new_if) - 2]; snprintf(key, s_key, "%c", br_key); @@ -246,7 +246,7 @@ static int get_br_key_from_lower_layer(char *lower_layer, char *key, size_t s_ke int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname) { /* Check if the value is valid or not. */ - if (strncmp(value, "Device.Bridging.Bridge.", 23) != 0) + if (DM_STRNCMP(value, "Device.Bridging.Bridge.", 23) != 0) return -1; char key[10] = {0}; @@ -275,7 +275,7 @@ int get_mcast_snooping_interface_val(char *value, char *ifname, size_t s_ifname) char *type, *name; dmuci_get_value_by_section_string(device_s, "type", &type); - if (*type == '\0' || strcmp(type, "bridge") != 0) + if (*type == '\0' || DM_STRCMP(type, "bridge") != 0) continue; dmuci_get_value_by_section_string(device_s, "name", &name); @@ -294,7 +294,7 @@ void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, ch uci_path_foreach_sections_safe(bbfdm, dmmap_file, section, stmp, d_sec) { dmuci_get_value_by_section_string(d_sec, option, &opt_val); - if (strcmp(opt_val, value) == 0) + if (DM_STRCMP(opt_val, value) == 0) dmuci_delete_by_section(d_sec, NULL, NULL); } } @@ -309,7 +309,7 @@ void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *val if (v != NULL) { uci_foreach_element(v, e) { val = dmstrdup(e->name); - if (val && strcmp(val, value) == 0) { + if (val && DM_STRCMP(val, value) == 0) { if (!b) { // remove this entry dmuci_del_list_value_by_section(s, section, value); @@ -576,7 +576,7 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); dmuci_delete_by_section(d_sec, NULL, NULL); found = 1; @@ -671,13 +671,13 @@ int get_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "enable", &f_enable); break; } } - if (strcmp(f_enable, "1") == 0) { + if (DM_STRCMP(f_enable, "1") == 0) { *value = "true"; } else { *value = "false"; @@ -701,7 +701,7 @@ int set_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "ipaddr", &ip_addr); dmuci_set_value_by_section(f_sec, "enable", (b) ? "1" : "0"); if (ip_addr[0] != '\0') { @@ -725,7 +725,7 @@ int get_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, cha uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); break; } @@ -756,7 +756,7 @@ int set_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, cha uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data), s) { dmuci_get_value_by_section_string(s, "filter_instance", &s_inst); - if (strcmp(s_inst, instance) == 0) { + if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(s, "ipaddr", value); dmuci_get_value_by_section_string(s, "enable", &up); string_to_bool(up, &b); @@ -800,7 +800,7 @@ static int get_igmp_version(char *refparam, struct dmctx *ctx, void *data, char { char *val; dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val); - *value = (strcmp(val, "2") == 0) ? "V2" : "V3"; + *value = (DM_STRCMP(val, "2") == 0) ? "V2" : "V3"; return 0; } @@ -808,11 +808,11 @@ static int set_igmp_version(char *refparam, struct dmctx *ctx, void *data, char { switch (action) { case VALUECHECK: - if ((strcmp("V2", value) != 0) && (strcmp("V3", value) != 0)) + if ((DM_STRCMP("V2", value) != 0) && (DM_STRCMP("V3", value) != 0)) return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "version", (strcmp(value, "V2") == 0) ? "2" : "3"); + dmuci_set_value_by_section((struct uci_section *)data, "version", (DM_STRCMP(value, "V2") == 0) ? "2" : "3"); break; } @@ -824,9 +824,9 @@ int get_mcast_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char char *val; dmuci_get_value_by_section_string((struct uci_section *)data, "snooping_mode", &val); - if (strcmp(val, "1") == 0) + if (DM_STRCMP(val, "1") == 0) *value = "Standard"; - else if (strcmp(val, "2") == 0) + else if (DM_STRCMP(val, "2") == 0) *value = "Blocking"; else *value = "Disabled"; @@ -840,18 +840,18 @@ int set_mcast_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char switch (action) { case VALUECHECK: - if ((strcmp("Standard", value) != 0) - && (strcmp("Blocking", value) != 0) - && (strcmp("Disabled", value) != 0)) + if ((DM_STRCMP("Standard", value) != 0) + && (DM_STRCMP("Blocking", value) != 0) + && (DM_STRCMP("Disabled", value) != 0)) return FAULT_9007; break; case VALUESET: - if (strcmp(value, "Standard") == 0) - strcpy(val, "1"); - else if (strcmp(value, "Blocking") == 0) - strcpy(val, "2"); + if (DM_STRCMP(value, "Standard") == 0) + DM_STRNCPY(val, "1", sizeof(val)); + else if (DM_STRCMP(value, "Blocking") == 0) + DM_STRNCPY(val, "2", sizeof(val)); else - strcpy(val, "0"); + DM_STRNCPY(val, "0", sizeof(val)); dmuci_set_value_by_section((struct uci_section *)data, "snooping_mode", val); break; @@ -886,7 +886,7 @@ int get_mcasts_fast_leave(char *refparam, struct dmctx *ctx, void *data, char *i char *val = NULL; dmuci_get_value_by_section_string((struct uci_section *)data, "fast_leave", &val); - *value = (val && strcmp(val, "1") == 0) ? "true" : "false"; + *value = (val && DM_STRCMP(val, "1") == 0) ? "true" : "false"; return 0; } @@ -970,7 +970,7 @@ int get_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data, if ((tok == NULL) || (end == NULL)) return 0; - if (strcmp(tok, "br") != 0) + if (DM_STRCMP(tok, "br") != 0) return 0; DM_STRNCPY(sec_name, end, sizeof(sec_name)); @@ -1019,7 +1019,7 @@ static void get_igmpp_iface_del_key_val(char *key, size_t key_size, char *if_nam { struct uci_section *s = NULL; char *ifval; - if (strstr(if_name, "br-") != NULL) { + if (DM_STRSTR(if_name, "br-") != NULL) { DM_STRNCPY(key, if_name, key_size); } else { uci_foreach_sections("network", "interface", s) { @@ -1033,7 +1033,7 @@ static void get_igmpp_iface_del_key_val(char *key, size_t key_size, char *if_nam } static void del_igmpp_iface_val(char *upstream, void *data, char *pch) { - if (strcmp(upstream, "1") == 0) { + if (DM_STRCMP(upstream, "1") == 0) { dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", pch); } else { @@ -1054,7 +1054,7 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data dmuci_get_value_by_section_string(igmpp_s, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(igmpp_s, "ifname", &if_name); dmuci_get_value_by_section_string(igmpp_s, "upstream", &upstream); dmuci_delete_by_section(igmpp_s, NULL, NULL); @@ -1154,7 +1154,7 @@ int del_mcastp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); dmuci_delete_by_section(d_sec, NULL, NULL); found = 1; @@ -1213,13 +1213,13 @@ int get_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char 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); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "enable", &f_enable); break; } } - if (f_enable && strcmp(f_enable, "1") == 0) { + if (f_enable && DM_STRCMP(f_enable, "1") == 0) { *value = "true"; } else { *value = "false"; @@ -1243,7 +1243,7 @@ int set_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char 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); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "ipaddr", &ip_addr); dmuci_set_value_by_section(f_sec, "enable", (b) ? "1" : "0"); sync_dmmap_bool_to_uci_list((struct uci_section *)data, @@ -1265,7 +1265,7 @@ int get_mcastp_filter_address(char *refparam, struct dmctx *ctx, void *data, cha uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", value); break; } @@ -1288,7 +1288,7 @@ static int set_igmpp_filter_address(char *refparam, struct dmctx *ctx, void *dat case VALUESET: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data), igmp_s) { dmuci_get_value_by_section_string(igmp_s, "filter_instance", &s_inst); - if (strcmp(s_inst, instance) == 0) { + if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(igmp_s, "ipaddr", value); dmuci_get_value_by_section_string(igmp_s, "enable", &up); string_to_bool(up, &b); @@ -1674,7 +1674,7 @@ static void sync_proxy_interface_sections(struct uci_section *s, char *section, uci_foreach_element(v, e) { val = dmstrdup(e->name); - if (strcmp(val, pch) == 0) { + if (DM_STRCMP(val, pch) == 0) { found = 1; if (!up_iface) { // if entry is found and upstream was set to @@ -1713,7 +1713,7 @@ static void set_igmpp_iface_val(void *data, char *instance, char *linker, char * uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_set_value_by_section(d_sec, "ifname", is_br ? interface_linker : linker); dmuci_get_value_by_section_string(d_sec, "upstream", &up); string_to_bool(up, &b); @@ -1761,7 +1761,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 (if_type && strcmp(if_type, "bridge") == 0) { + if (if_type && DM_STRCMP(if_type, "bridge") == 0) { dmasprintf(&interface_linker, "br-%s", linker); is_br = true; } else { @@ -1790,7 +1790,7 @@ static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) { dmuci_get_value_by_section_string(igmpp_s, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(igmpp_s, "ifname", &igmpp_ifname); found = 1; break; @@ -1803,13 +1803,13 @@ static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da } // Check if this is bridge type interface - if (strstr(igmpp_ifname, "br-")) { + if (DM_STRSTR(igmpp_ifname, "br-")) { // Interface is bridge type, convert to network uci file section name char val[16] = {0}; DM_STRNCPY(val, igmpp_ifname, sizeof(val)); char *token, *end; token = strtok_r(val, "-", &end); - if (strcmp(token, "br") == 0) { + if (DM_STRCMP(token, "br") == 0) { DM_STRNCPY(sec_name, end, sizeof(sec_name)); } else { goto end; @@ -1858,7 +1858,7 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { // The interface is a part of downstream or upstream list in the // uci file based on the value of upstream parameter, hence, when // this parameter is updated, need arises to update the lists as well. @@ -1868,7 +1868,7 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void char key[1024]; char *ifval; dmuci_get_value_by_section_string(d_sec, "ifname", &ifname); - if (strstr(ifname, "br-") != NULL) { + if (DM_STRSTR(ifname, "br-") != NULL) { DM_STRNCPY(key, ifname, sizeof(key)); } else { uci_foreach_sections("network", "interface", s) { @@ -1903,13 +1903,13 @@ int get_mcastp_interface_upstream(char *refparam, struct dmctx *ctx, void *data, uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "upstream", &up); break; } } - *value = (up && strcmp(up, "1") == 0) ? "true" : "false"; + *value = (up && DM_STRCMP(up, "1") == 0) ? "true" : "false"; return 0; } @@ -1921,15 +1921,15 @@ int get_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "snooping_mode", &val); break; } } - if (val && strcmp(val, "1") == 0) + if (val && DM_STRCMP(val, "1") == 0) *value = "Standard"; - else if (val && strcmp(val, "2") == 0) + else if (val && DM_STRCMP(val, "2") == 0) *value = "Blocking"; else *value = "Disabled"; @@ -1946,15 +1946,15 @@ int set_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c switch (action) { case VALUECHECK: - if ((strcmp("Standard", value) != 0) - && (strcmp("Blocking", value) != 0) - && (strcmp("Disabled", value) != 0)) + if ((DM_STRCMP("Standard", value) != 0) + && (DM_STRCMP("Blocking", value) != 0) + && (DM_STRCMP("Disabled", value) != 0)) return FAULT_9007; break; case VALUESET: - if (strcmp(value, "Standard") == 0) + if (DM_STRCMP(value, "Standard") == 0) strcpy(val, "1"); - else if (strcmp(value, "Blocking") == 0) + else if (DM_STRCMP(value, "Blocking") == 0) strcpy(val, "2"); else strcpy(val, "0"); @@ -1962,7 +1962,7 @@ int set_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "upstream", &up); dmuci_set_value_by_section(d_sec, "snooping_mode", val); diff --git a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c index 42b135ff..60d52923 100644 --- a/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c +++ b/dmtree/vendor/iopsys/tr181/x_iopsys_eu_mld.c @@ -169,7 +169,7 @@ static int get_mld_version(char *refparam, struct dmctx *ctx, void *data, char * { char *val; dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val); - *value = (strcmp(val, "2") == 0) ? "V2" : "V1"; + *value = (DM_STRCMP(val, "2") == 0) ? "V2" : "V1"; return 0; } @@ -177,11 +177,11 @@ static int set_mld_version(char *refparam, struct dmctx *ctx, void *data, char * { switch (action) { case VALUECHECK: - if ((strcmp("V2", value) != 0) && (strcmp("V1", value) != 0)) + if ((DM_STRCMP("V2", value) != 0) && (DM_STRCMP("V1", value) != 0)) return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "version", (strcmp(value, "V2") == 0) ? "2" : "1"); + dmuci_set_value_by_section((struct uci_section *)data, "version", (DM_STRCMP(value, "V2") == 0) ? "2" : "1"); break; } @@ -212,7 +212,7 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, dmuci_get_value_by_section_string(mldp_s, "iface_instance", &f_inst); - if (f_inst && strcmp(instance, f_inst) == 0) { + if (f_inst && DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(mldp_s, "ifname", &if_name); dmuci_get_value_by_section_string(mldp_s, "upstream", &upstream); dmuci_delete_by_section(mldp_s, NULL, NULL); @@ -220,7 +220,7 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, } if (found) { - if (upstream && strcmp(upstream, "1") == 0) + if (upstream && DM_STRCMP(upstream, "1") == 0) dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name); else dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name); @@ -237,7 +237,7 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, dmuci_get_value_by_section_string(mldp_s, "upstream", &upstream); if (if_name[0] != '\0') { - if (strcmp(upstream, "1") == 0) + if (DM_STRCMP(upstream, "1") == 0) dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name); else dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name); @@ -287,7 +287,7 @@ static int set_mldp_filter_address(char *refparam, struct dmctx *ctx, void *data uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data), s) { dmuci_get_value_by_section_string(s, "filter_instance", &s_inst); - if (strcmp(s_inst, instance) == 0) { + if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(s, "ipaddr", value); dmuci_get_value_by_section_string(s, "enable", &up); string_to_bool(up, &b); @@ -464,7 +464,7 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat continue; } dmuci_get_value_by_section_string(s, "type", &if_type); - if (strcmp(if_type, "bridge") == 0) + if (DM_STRCMP(if_type, "bridge") == 0) dmasprintf(&interface_linker, "br-%s", linker); else dmuci_get_value_by_section_string(s, "device", &interface_linker); @@ -478,7 +478,7 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_set_value_by_section(d_sec, "ifname", interface_linker); dmuci_get_value_by_section_string(d_sec, "upstream", &up); string_to_bool(up, &b); @@ -506,7 +506,7 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) { dmuci_get_value_by_section_string(mldp_s, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(mldp_s, "ifname", &mldp_ifname); found = 1; break; @@ -519,13 +519,13 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat } // Check if this is bridge type interface - if (strstr(mldp_ifname, "br-")) { + if (DM_STRSTR(mldp_ifname, "br-")) { // Interface is bridge type, convert to network uci file section name char val[16] = {0}; DM_STRNCPY(val, mldp_ifname, sizeof(val)); char *tok, *end; tok = strtok_r(val, "-", &end); - if (strcmp(tok, "br") == 0) { + if (DM_STRCMP(tok, "br") == 0) { DM_STRNCPY(sec_name, end, sizeof(sec_name)); } else { goto end; @@ -553,7 +553,7 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat struct uci_section *intf_s = NULL; uci_foreach_sections("network", "interface", intf_s) { dmuci_get_value_by_section_string(intf_s, "device", &device_name); - if (strcmp(device_name, mldp_ifname) == 0) { + if (DM_STRCMP(device_name, mldp_ifname) == 0) { tmp_linker = dmstrdup(section_name(intf_s)); break; } @@ -582,7 +582,7 @@ static int set_mldp_interface_upstream(char *refparam, struct dmctx *ctx, void * uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); - if (strcmp(instance, f_inst) == 0) { + if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ifname", &ifname); dmuci_set_value_by_section(d_sec, "upstream", (b) ? "1" : "0"); diff --git a/dmtree/vendor/openwrt/tr181/qos.c b/dmtree/vendor/openwrt/tr181/qos.c index d1d0d2c9..5e04af29 100644 --- a/dmtree/vendor/openwrt/tr181/qos.c +++ b/dmtree/vendor/openwrt/tr181/qos.c @@ -93,7 +93,7 @@ static int openwrt__browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_ { struct uci_section *dmmap_sect; char *questatsout[256], *inst = NULL, *max_inst = NULL, *lastinstancestore = NULL, dev[50] = "", user[50] = ""; - static int length = 0, i, ret = 0; + int length = 0; struct queuestats queuests = {0}, emptyquestats = {0}; regex_t regex1 = {}, regex2 = {}; @@ -102,40 +102,43 @@ static int openwrt__browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_ command_exec_output_to_array("tc -s qdisc", questatsout, &length); - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { switch (i%3) { - case 0: ret = regexec(®ex1, questatsout[i], 0, NULL, 0); - if (ret == 0) - sscanf(questatsout[i], "qdisc noqueue %d: dev %49s %49s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt); - else { - ret= regexec(®ex2, questatsout[i], 0, NULL, 0); - if (ret == 0) - sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %49s %49s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt); - } - DM_STRNCPY(queuests.dev, dev, sizeof(queuests.dev)); - break; - case 1: sscanf(questatsout[i], " Sent %d bytes %d pkt (dropped %d, overlimits %d requeues %d)\n", &queuests.bytes_sent, &queuests.pkt_sent, &queuests.pkt_dropped, &queuests.pkt_overlimits, &queuests.pkt_requeues); - break; - case 2: sscanf(questatsout[i], " backlog %db %dp requeues %d\n", &queuests.backlog_b, &queuests.backlog_p, &queuests.backlog_requeues); - if ((dmmap_sect = get_dup_qstats_section_in_dmmap("dmmap_qos", "qqueue_stats", queuests.dev)) == NULL) { - dmuci_add_section_bbfdm("dmmap_qos", "qqueue_stats", &dmmap_sect); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "dev_link", queuests.dev); - } + case 0: + int ret = regexec(®ex1, questatsout[i], 0, NULL, 0); + if (ret == 0) + sscanf(questatsout[i], "qdisc noqueue %d: dev %49s %49s refcnt %d\n", &queuests.noqueue, dev, user, &queuests.refcnt); + else { + ret= regexec(®ex2, questatsout[i], 0, NULL, 0); + if (ret == 0) + sscanf(questatsout[i], "qdisc pfifo_fast %d: dev %49s %49s refcnt %d\n", &queuests.pfifo_fast, dev, user, &queuests.refcnt); + } + DM_STRNCPY(queuests.dev, dev, sizeof(queuests.dev)); + break; + case 1: + sscanf(questatsout[i], " Sent %d bytes %d pkt (dropped %d, overlimits %d requeues %d)\n", &queuests.bytes_sent, &queuests.pkt_sent, &queuests.pkt_dropped, &queuests.pkt_overlimits, &queuests.pkt_requeues); + break; + case 2: + sscanf(questatsout[i], " backlog %db %dp requeues %d\n", &queuests.backlog_b, &queuests.backlog_p, &queuests.backlog_requeues); + if ((dmmap_sect = get_dup_qstats_section_in_dmmap("dmmap_qos", "qqueue_stats", queuests.dev)) == NULL) { + dmuci_add_section_bbfdm("dmmap_qos", "qqueue_stats", &dmmap_sect); + dmuci_set_value_by_section_bbfdm(dmmap_sect, "dev_link", queuests.dev); + } - queuests.dmsect= dmmap_sect; + queuests.dmsect= dmmap_sect; - if (lastinstancestore != NULL && max_inst != NULL) - max_inst = dmstrdup(lastinstancestore); + if (lastinstancestore != NULL && max_inst != NULL) + max_inst = dmstrdup(lastinstancestore); - inst = handle_instance(dmctx, parent_node, dmmap_sect, "queuestatsinstance", "queuestatsalias"); + inst = handle_instance(dmctx, parent_node, dmmap_sect, "queuestatsinstance", "queuestatsalias"); - lastinstancestore = dmstrdup(max_inst); + lastinstancestore = dmstrdup(max_inst); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&queuests, inst) == DM_STOP) - goto end; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&queuests, inst) == DM_STOP) + goto end; - queuests = emptyquestats; - break; + queuests = emptyquestats; + break; } } @@ -260,7 +263,7 @@ static int openwrt__get_QoSClassification_Interface(char *refparam, struct dmctx return 0; uci_foreach_sections("qos", "interface", s) { dmuci_get_value_by_section_string(s, "classgroup", &ifaceclassgrp); - if (ifaceclassgrp != NULL && strcmp(ifaceclassgrp, classgroup) == 0) { + if (ifaceclassgrp != NULL && DM_STRCMP(ifaceclassgrp, classgroup) == 0) { adm_entry_get_linker_param(ctx, "Device.IP.Interface.", section_name(s), value); if (!(*value) || (*value)[0] == 0) adm_entry_get_linker_param(ctx, "Device.PPP.Interface.", section_name(s), value); diff --git a/dmtree/vendor/test/tr181/firewall.c b/dmtree/vendor/test/tr181/firewall.c index 877b7bbb..6f2fe9d2 100644 --- a/dmtree/vendor/test/tr181/firewall.c +++ b/dmtree/vendor/test/tr181/firewall.c @@ -24,7 +24,7 @@ static int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, cha ptr = dmstrdup(*value); dmfree(*value); - if (strlen(ptr) == 0) + if (DM_STRLEN(ptr) == 0) dmasprintf(value, "%s", e->name); else { dmasprintf(value, "%s %s", ptr, e->name); diff --git a/dmtree/vendor/test/tr181/x_test_com_dropbear.c b/dmtree/vendor/test/tr181/x_test_com_dropbear.c index 1049ae68..78e4607f 100644 --- a/dmtree/vendor/test/tr181/x_test_com_dropbear.c +++ b/dmtree/vendor/test/tr181/x_test_com_dropbear.c @@ -103,7 +103,7 @@ static int set_x_test_com_dropbear_alias(char *refparam, struct dmctx *ctx, void static int get_x_test_com_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *res = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "PasswordAuth", "1"); - *value = ((strcmp(res, "on") == 0) || *res == '1') ? "1" : "0"; + *value = ((DM_STRCMP(res, "on") == 0) || *res == '1') ? "1" : "0"; return 0; } @@ -127,7 +127,7 @@ static int set_x_test_com_dropbear_password_auth(char *refparam, struct dmctx *c static int get_x_test_com_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *res = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "RootPasswordAuth", "1"); - *value = ((strcmp(res, "on") == 0) || *res == '1') ? "1" : "0"; + *value = ((DM_STRCMP(res, "on") == 0) || *res == '1') ? "1" : "0"; return 0; } @@ -306,7 +306,7 @@ static int set_x_test_com_dropbear_ssh_keepalive(char *refparam, struct dmctx *c case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "SSHKeepAlive", (strcmp(value, "300") == 0) ? "" : value); + dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "SSHKeepAlive", (DM_STRCMP(value, "300") == 0) ? "" : value); return 0; } diff --git a/libbbf_api/dmapi.h b/libbbf_api/dmapi.h index 1eb14ff3..924f932b 100644 --- a/libbbf_api/dmapi.h +++ b/libbbf_api/dmapi.h @@ -57,6 +57,11 @@ do { \ } while(0) #define DM_STRLEN(SRC) ((SRC != NULL) ? strlen(SRC) : 0) +#define DM_STRSTR(STR, MATCH) ((STR != NULL && MATCH != NULL) ? strstr(STR, MATCH) : NULL) +#define DM_STRCHR(STR, CHR) ((STR != NULL) ? strchr(STR, CHR) : NULL) +#define DM_STRTOL(SRC) ((SRC != NULL) ? strtol(SRC, NULL, 10) : 0) +#define DM_STRCMP(S1, S2) ((S1 != NULL && S2 != NULL) ? strcmp(S1, S2) : -1) +#define DM_STRNCMP(S1, S2, LEN) ((S1 != NULL && S2 != NULL && LEN > 0) ? strncmp(S1, S2, LEN) : -1) #define UBUS_ARGS (struct ubus_arg[]) #define RANGE_ARGS (struct range_args[]) diff --git a/libbbf_api/dmbbf.c b/libbbf_api/dmbbf.c index 8e86957f..83019248 100644 --- a/libbbf_api/dmbbf.c +++ b/libbbf_api/dmbbf.c @@ -74,12 +74,12 @@ static int plugin_obj_match(DMOBJECT_ARGS) { if (node->matched) return 0; - if (!dmctx->inparam_isparam && strstr(node->current_object, dmctx->in_param) == node->current_object) { + if (!dmctx->inparam_isparam && DM_STRSTR(node->current_object, dmctx->in_param) == node->current_object) { node->matched++; dmctx->findparam = 1; return 0; } - if (strstr(dmctx->in_param, node->current_object) == dmctx->in_param) { + if (DM_STRSTR(dmctx->in_param, node->current_object) == dmctx->in_param) { return 0; } return FAULT_9005; @@ -89,7 +89,7 @@ static int obj_match_supported_dm(DMOBJECT_ARGS) { if(node->matched) return 0; - if(!dmctx->inparam_isparam && strstr(node->current_object,dmctx->in_param) == node->current_object) { + if(!dmctx->inparam_isparam && DM_STRSTR(node->current_object,dmctx->in_param) == node->current_object) { node->matched ++; dmctx->findparam = 1; return 0; @@ -104,8 +104,8 @@ static int plugin_leaf_match(DMOBJECT_ARGS) return 0; if (!dmctx->inparam_isparam) return FAULT_9005; - str = dmctx->in_param + strlen(node->current_object); - if (!strchr(str, '.')) + str = dmctx->in_param + DM_STRLEN(node->current_object); + if (!DM_STRCHR(str, '.')) return 0; return FAULT_9005; } @@ -123,12 +123,12 @@ static int plugin_obj_nextlevel_match(DMOBJECT_ARGS) node->matched++; return 0; } - if (!dmctx->inparam_isparam && strstr(node->current_object, dmctx->in_param) == node->current_object) { + if (!dmctx->inparam_isparam && DM_STRSTR(node->current_object, dmctx->in_param) == node->current_object) { node->matched++; dmctx->findparam = 1; return 0; } - if (strstr(dmctx->in_param, node->current_object) == dmctx->in_param) { + if (DM_STRSTR(dmctx->in_param, node->current_object) == dmctx->in_param) { return 0; } return FAULT_9005; @@ -143,8 +143,8 @@ static int plugin_leaf_nextlevel_match(DMOBJECT_ARGS) return 0; if (!dmctx->inparam_isparam) return FAULT_9005; - str = dmctx->in_param + strlen(node->current_object); - if (!strchr(str, '.')) + str = dmctx->in_param + DM_STRLEN(node->current_object); + if (!DM_STRCHR(str, '.')) return 0; return FAULT_9005; } @@ -154,13 +154,13 @@ static int plugin_dynamic_obj_match(struct dmctx *dmctx, struct dmnode *node, ch if (node->matched) return 0; - if (!dmctx->inparam_isparam && strstr(node->current_object, full_obj) == node->current_object) { + if (!dmctx->inparam_isparam && DM_STRSTR(node->current_object, full_obj) == node->current_object) { node->matched++; dmctx->findparam = 1; return 0; } - if (strstr(full_obj, node->current_object) == full_obj) + if (DM_STRSTR(full_obj, node->current_object) == full_obj) return 0; return FAULT_9005; @@ -181,17 +181,17 @@ static bool check_version(const char *obj_version, struct dmctx *ctx) return true; if (*config_version) { - config_major = atoi(config_version); - char *temp = strchr(config_version, '.'); + config_major = DM_STRTOL(config_version); + char *temp = DM_STRCHR(config_version, '.'); if (temp) - config_minor = atoi(temp + 1); + config_minor = DM_STRTOL(temp + 1); } if (*obj_version) { - obj_major = atoi(obj_version); - char *temp = strchr(obj_version, '.'); + obj_major = DM_STRTOL(obj_version); + char *temp = DM_STRCHR(obj_version, '.'); if (temp) - obj_minor = atoi(temp + 1); + obj_minor = DM_STRTOL(temp + 1); } if (obj_major > config_major || obj_minor > config_minor) @@ -217,7 +217,7 @@ static bool check_dependency(const char *conf_obj) DM_STRNCPY(conf_list, conf_obj, sizeof(conf_list)); for (pch = strtok_r(conf_list, ";", &spch); pch != NULL; pch = strtok_r(NULL, ";", &spch)) { - char *conf_type = strchr(pch, ':'); + char *conf_type = DM_STRCHR(pch, ':'); if (!conf_type) return false; @@ -407,7 +407,7 @@ int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char DMNODE node = {0}; if (parent_node->browse_type == BROWSE_FIND_MAX_INST) { - int curr_inst = (instance && *instance != '\0') ? atoi(instance) : 0; + int curr_inst = (instance && *instance != '\0') ? DM_STRTOL(instance) : 0; if (curr_inst > parent_node->max_instance) parent_node->max_instance = curr_inst; return 0; @@ -474,7 +474,7 @@ void dm_exclude_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, c node.matched = parent_node->matched; dmasprintf(&(node.current_object), "%s%s.", parent_obj, entryobj->obj); - if (strcmp(node.current_object, data) == 0) { + if (DM_STRCMP(node.current_object, data) == 0) { entryobj->bbfdm_type = BBFDM_NONE; return; } @@ -497,7 +497,7 @@ static void dm_check_dynamic_obj_entry(struct dmctx *dmctx, DMNODE *parent_node, node.matched = parent_node->matched; dmasprintf(&(node.current_object), "%s%s.", parent_obj, entryobj->obj); - if (strcmp(node.current_object, obj) == 0) { + if (DM_STRCMP(node.current_object, obj) == 0) { *root_entry = entryobj; *obj_found = 1; return; @@ -606,7 +606,7 @@ static int rootcmp(char *inparam, char *rootobj) { char buf[32]; snprintf(buf, sizeof(buf), "%s.", rootobj); - return strcmp(inparam, buf); + return DM_STRCMP(inparam, buf); } /*************************** @@ -763,10 +763,12 @@ static int get_max_instance(char *dmmap_package, char *section_type, char *inst_ continue; dmuci_get_value_by_section_string(s, inst_opt, &inst); - if (inst[0] == '\0') + if (DM_STRLEN(inst) == 0) continue; - max = max > atoi(inst) ? max : atoi(inst); + int instance = DM_STRTOL(inst); + + max = max > instance ? max : instance; } return max; @@ -787,7 +789,7 @@ char *update_instance_alias(int action, char **last_inst, char **max_inst, void if (*max_inst == NULL) max_instance = get_max_instance(section_config(s), section_type(s), inst_opt, check_browse, data); else - max_instance = atoi(*max_inst); + max_instance = DM_STRTOL(*max_inst); dmuci_get_value_by_section_string(s, inst_opt, &instance); if (instance[0] == '\0') { @@ -914,7 +916,7 @@ void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, c list_for_each(ilist, &ctx->list_parameter) { dm_parameter = list_entry(ilist, struct dm_parameter, list); - int cmp = strcmp(dm_parameter->name, param_name); + int cmp = DM_STRCMP(dm_parameter->name, param_name); if (cmp == 0) { return; } else if (cmp > 0) { @@ -1032,7 +1034,7 @@ static int is64digit(char c) static char *check_value_by_type(char *value, int type) { - int i = 0, len = strlen(value); + int i = 0, len = DM_STRLEN(value); char buf[len + 1]; struct tm tm; @@ -1140,7 +1142,7 @@ int dm_entry_get_value(struct dmctx *dmctx) dmctx->findparam = 1; dmctx->stop = 0; findparam_check = 1; - } else if (dmctx->in_param[strlen(dmctx->in_param) - 1] == '.') { + } else if (dmctx->in_param[DM_STRLEN(dmctx->in_param) - 1] == '.') { dmctx->inparam_isparam = 0; dmctx->findparam = 0; dmctx->stop = 0; @@ -1194,7 +1196,7 @@ static int mparam_get_value_in_param(DMPARAM_ARGS) char *value = ""; dmastrcat(&full_param, node->current_object, lastname); - if (strcmp(dmctx->in_param, full_param) != 0) { + if (DM_STRCMP(dmctx->in_param, full_param) != 0) { dmfree(full_param); return FAULT_9005; } @@ -1236,7 +1238,7 @@ int dm_entry_get_name(struct dmctx *ctx) ctx->in_param = root->obj; node.matched = 1; findparam_check = 1; - } else if (*(ctx->in_param + strlen(ctx->in_param) - 1) == '.') { + } else if (*(ctx->in_param + DM_STRLEN(ctx->in_param) - 1) == '.') { ctx->inparam_isparam = 0; ctx->findparam = 0; ctx->stop = 0; @@ -1292,7 +1294,7 @@ static int mparam_get_name_in_param(DMPARAM_ARGS) char *perm = permission->val; dmastrcat(&refparam, node->current_object, lastname); - if (strcmp(refparam, dmctx->in_param) != 0) { + if (DM_STRCMP(refparam, dmctx->in_param) != 0) { dmfree(refparam); return FAULT_9005; } @@ -1338,7 +1340,7 @@ static int mobj_get_name_in_obj(DMOBJECT_ARGS) if (!node->matched) return FAULT_9005; - if (dmctx->nextlevel && strcmp(node->current_object, dmctx->in_param) == 0) + if (dmctx->nextlevel && DM_STRCMP(node->current_object, dmctx->in_param) == 0) return 0; if (permission->get_permission != NULL) @@ -1476,7 +1478,7 @@ int dm_entry_get_instances(struct dmctx *ctx) if (ctx->in_param[0] == 0) ctx->in_param = dmstrdup("."); - plen = strlen(ctx->in_param); + plen = DM_STRLEN(ctx->in_param); if (ctx->in_param[plen - 1] != '.') return FAULT_9005; @@ -1501,7 +1503,7 @@ static int mobj_get_instances_in_obj(DMOBJECT_ARGS) char *name = dmstrdup(node->current_object); if (name) { - name[strlen(name) - 1] = 0; + name[DM_STRLEN(name) - 1] = 0; add_list_parameter(dmctx, name, NULL, "xsd:object", NULL); } } @@ -1524,7 +1526,7 @@ int dm_entry_add_object(struct dmctx *dmctx) int err; if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' - || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != '.')) + || (*(dmctx->in_param + DM_STRLEN(dmctx->in_param) - 1) != '.')) return FAULT_9005; dmctx->inparam_isparam = 0; @@ -1552,7 +1554,7 @@ static int mobj_add_object(DMOBJECT_ARGS) char *new_instance = NULL; int fault = 0; - if (strcmp(refparam, dmctx->in_param) != 0) + if (DM_STRCMP(refparam, dmctx->in_param) != 0) return FAULT_9005; if (node->is_instanceobj) @@ -1589,7 +1591,7 @@ int dm_entry_delete_object(struct dmctx *dmctx) int err; if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' - || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != '.')) + || (*(dmctx->in_param + DM_STRLEN(dmctx->in_param) - 1) != '.')) return FAULT_9005; dmctx->inparam_isparam = 0; @@ -1611,7 +1613,7 @@ static int delete_object_obj(DMOBJECT_ARGS) char *perm = permission->val; unsigned char del_action = DEL_INST; - if (strcmp(refparam, dmctx->in_param) != 0) + if (DM_STRCMP(refparam, dmctx->in_param) != 0) return FAULT_9005; dmctx->stop = 1; @@ -1643,7 +1645,7 @@ int dm_entry_set_value(struct dmctx *dmctx) int err; if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' - || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == '.')) + || (*(dmctx->in_param + DM_STRLEN(dmctx->in_param) - 1) == '.')) return FAULT_9005; dmctx->inparam_isparam = 1; @@ -1669,7 +1671,7 @@ static int mparam_set_value(DMPARAM_ARGS) char refparam[MAX_DM_PATH]; snprintf(refparam, MAX_DM_PATH, "%s%s", node->current_object, lastname); - if (strcmp(refparam, dmctx->in_param) != 0) + if (DM_STRCMP(refparam, dmctx->in_param) != 0) return FAULT_9005; dmctx->stop = 1; @@ -1730,9 +1732,9 @@ static int get_linker_check_obj(DMOBJECT_ARGS) if (dmctx->linker[0] == '\0') return FAULT_9005; - if (link_val && link_val[0] != '\0' && strcmp(link_val, dmctx->linker) == 0) { - if (node->current_object[strlen(node->current_object) - 1] == '.') - node->current_object[strlen(node->current_object) - 1] = 0; + if (link_val && link_val[0] != '\0' && DM_STRCMP(link_val, dmctx->linker) == 0) { + if (node->current_object[DM_STRLEN(node->current_object) - 1] == '.') + node->current_object[DM_STRLEN(node->current_object) - 1] = 0; dmctx->linker_param = dmstrdup(node->current_object); dmctx->stop = true; return 0; @@ -1772,7 +1774,7 @@ static int get_linker_value_check_obj(DMOBJECT_ARGS) if (!get_linker) return FAULT_9005; - if (strcmp(node->current_object, dmctx->in_param) == 0) { + if (DM_STRCMP(node->current_object, dmctx->in_param) == 0) { char *link_val = NULL; if (!data || !instance) @@ -1844,7 +1846,7 @@ static int mparam_operate(DMPARAM_ARGS) char full_param[MAX_DM_PATH]; snprintf(full_param, MAX_DM_PATH, "%s%s", node->current_object, lastname); - if (strcmp(full_param, dmctx->in_param) != 0) + if (DM_STRCMP(full_param, dmctx->in_param) != 0) return CMD_NOT_FOUND; dmctx->stop = 1; @@ -1864,7 +1866,7 @@ int dm_entry_operate(struct dmctx *dmctx) DMNODE node = { .current_object = "" }; int err; - if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != ')')) + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' || (*(dmctx->in_param + DM_STRLEN(dmctx->in_param) - 1) != ')')) return CMD_NOT_FOUND; dmctx->iscommand = 1; diff --git a/libbbf_api/dmcommon.c b/libbbf_api/dmcommon.c index 02bad2f1..d305b796 100644 --- a/libbbf_api/dmcommon.c +++ b/libbbf_api/dmcommon.c @@ -84,7 +84,7 @@ pid_t get_pid(const char *pname) if (fp) { if (fgets(buf, sizeof(buf), fp) != NULL) { char* first = strtok(buf, " "); - if (strstr(first, pname)) { + if (DM_STRSTR(first, pname)) { fclose(fp); closedir(dir); return (pid_t)lpid; @@ -122,8 +122,8 @@ char *cidr2netmask(int bits) bool is_strword_in_optionvalue(char *optionvalue, char *str) { char *s = optionvalue; - while ((s = strstr(s, str))) { - int len = strlen(str); //should be inside while, optimization reason + while ((s = DM_STRSTR(s, str))) { + int len = DM_STRLEN(str); //should be inside while, optimization reason if(s[len] == '\0' || s[len] == ' ') return true; s++; @@ -134,7 +134,7 @@ bool is_strword_in_optionvalue(char *optionvalue, char *str) void remove_new_line(char *buf) { int len; - len = strlen(buf) - 1; + len = DM_STRLEN(buf) - 1; if (buf[len] == '\n') buf[len] = 0; } @@ -143,7 +143,7 @@ int dmcmd(char *cmd, int n, ...) { va_list arg; int i, pid; - static int dmcmd_pfds[2]; + int dmcmd_pfds[2]; char *argv[n+2]; argv[0] = cmd; @@ -194,7 +194,7 @@ int dmcmd_no_wait(char *cmd, int n, ...) va_list arg; int i, pid; char *argv[n+2]; - static char sargv[4][128]; + char sargv[4][128]; argv[0] = cmd; va_start(arg, n); @@ -217,15 +217,15 @@ int dmcmd_no_wait(char *cmd, int n, ...) return 0; } -void hex_to_ip(char *address, char *ret) +void hex_to_ip(char *address, char *ret, size_t size) { 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, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); + snprintf(ret, size, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); } else { - sprintf(ret, "%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]); + snprintf(ret, size, "%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]); } } @@ -286,7 +286,7 @@ struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_ dmuci_get_value_by_section_string(s, "section_name", &dmmap_sec_name); dmuci_replace_invalid_characters_from_section_name(dmmap_sec_name, sec_name, sizeof(sec_name)); - if (strcmp(sec_name, orig_section_name) == 0) + if (DM_STRCMP(sec_name, orig_section_name) == 0) return s; } @@ -322,7 +322,7 @@ struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* secti uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, "section_name", sect_name, s) { dmuci_get_value_by_section_string(s, opt_name, &v); - if (opt_value && strcmp(v, opt_value) == 0) + if (opt_value && DM_STRCMP(v, opt_value) == 0) return s; } return NULL; @@ -336,7 +336,7 @@ struct uci_section *get_section_in_dmmap_with_options_eq(char *dmmap_package, ch char *value = NULL; dmuci_get_value_by_section_string(s, opt2_name, &value); - if (opt2_value && value && strcmp(value, opt2_value) == 0) + if (opt2_value && value && DM_STRCMP(value, opt2_value) == 0) return s; } @@ -555,14 +555,20 @@ __attribute__ ((deprecated)) int is_section_unnamed(char *section_name) { int i; + if (section_name == NULL) + return 0; + if (strlen(section_name) != 9) return 0; + if(strstr(section_name, "cfg") != section_name) return 0; + for (i = 3; i < 9; i++) { if (!isxdigit(section_name[i])) return 0; } + return 1; } @@ -586,7 +592,7 @@ __attribute__ ((deprecated)) void delete_sections_save_next_sections(char* dmmap uci_path_foreach_sections(bbfdm, dmmap_package, section_type, s) { dmuci_get_value_by_section_string(s, instancename, &v); - inst = atoi(v); + inst = DM_STRTOL(v); if (inst > instance){ dmuci_get_value_by_section_string(s, "section_name", &tmp); add_dmmap_list_section(dup_list, lsectname, v); @@ -602,7 +608,7 @@ __attribute__ ((deprecated)) void delete_sections_save_next_sections(char* dmmap uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, s) { dmuci_get_value_by_section_string(s, instancename, &v); - inst = atoi(v); + inst = DM_STRTOL(v); if (inst >= instance) dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL); } @@ -663,12 +669,12 @@ static inline int isword_delim(char c) char *dm_strword(char *src, char *str) { - char *ret = src; - - if (src[0] == 0 || str[0] == 0) + if (!src || src[0] == 0 || !str || str[0] == 0) return NULL; int len = strlen(str); + char *ret = src; + while ((ret = strstr(ret, str)) != NULL) { if ((ret == src && isword_delim(ret[len])) || (ret != src && isword_delim(ret[len]) && isword_delim(*(ret - 1)))) @@ -718,12 +724,12 @@ char **strsplit_by_str(const char str[], char *delim) if (strparse == NULL || strparse[0] == '\0') break; - substr = strstr(strparse, delim); + substr = DM_STRSTR(strparse, delim); if (substr == NULL) { substr = strdup(strparse); - tokens[tokens_used] = dmcalloc(strlen(substr)+1, sizeof(char)); - DM_STRNCPY(tokens[tokens_used], strparse, strlen(substr)+1); + tokens[tokens_used] = dmcalloc(DM_STRLEN(substr)+1, sizeof(char)); + DM_STRNCPY(tokens[tokens_used], strparse, DM_STRLEN(substr)+1); tokens_used++; FREE(strparse); break; @@ -738,10 +744,10 @@ char **strsplit_by_str(const char str[], char *delim) } tokens[tokens_used] = dmcalloc(substr-strparse+1, sizeof(char)); - strncpy(tokens[tokens_used], strparse, substr-strparse); + DM_STRNCPY(tokens[tokens_used], strparse, substr - strparse + 1); tokens_used++; FREE(strparse); - strparse = strdup(substr+strlen(delim)); + strparse = strdup(substr+DM_STRLEN(delim)); } while (substr != NULL); FREE(strparse); tokens[tokens_used] = NULL; @@ -789,7 +795,7 @@ char *get_device_from_wifi_iface(const char *wifi_iface, const char *wifi_sectio unsigned n = 0, i; const char *ifname = ""; - if (wifi_iface[0] == 0 || wifi_section[0] == 0) + if (!wifi_iface || wifi_iface[0] == 0 || !wifi_section || wifi_section[0] == 0) return ""; dmubus_call("network.wireless", "status", UBUS_ARGS{{}}, 0, &jobj); @@ -824,7 +830,7 @@ bool value_exists_in_uci_list(struct uci_list *list, const char *value) return false; uci_foreach_element(list, e) { - if (!strcmp(e->name, value)) + if (!DM_STRCMP(e->name, value)) return true; } @@ -840,7 +846,7 @@ bool value_exits_in_str_list(char *str_list, const char *delimitor, const char * char *list = dmstrdup(str_list); for (pch = strtok_r(list, delimitor, &spch); pch != NULL; pch = strtok_r(NULL, delimitor, &spch)) { - if (strcmp(pch, value) == 0) + if (DM_STRCMP(pch, value) == 0) return true; } return false; @@ -848,7 +854,7 @@ bool value_exits_in_str_list(char *str_list, const char *delimitor, const char * void add_elt_to_str_list(char **str_list, char *elt) { - if (*str_list == NULL || strlen(*str_list) == 0) { + if (*str_list == NULL || DM_STRLEN(*str_list) == 0) { dmasprintf(str_list, "%s", elt); return; } @@ -863,7 +869,7 @@ void remove_elt_from_str_list(char **str_list, char *ifname) { char *list = NULL, *tmp = NULL, *pch = NULL, *spch = NULL; - if (*str_list == NULL || strlen(*str_list) == 0) + if (*str_list == NULL || DM_STRLEN(*str_list) == 0) return; list = dmstrdup(*str_list); @@ -871,7 +877,7 @@ void remove_elt_from_str_list(char **str_list, char *ifname) *str_list = NULL; for (pch = strtok_r(list, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - if (strcmp(pch, ifname) == 0) + if (DM_STRCMP(pch, ifname) == 0) continue; if (tmp == NULL) @@ -899,7 +905,7 @@ bool elt_exists_in_array(char **str_array, char *str, int length) int i; for (i = 0; i < length; i++) { - if (strcmp(str_array[i], str) == 0) + if (DM_STRCMP(str_array[i], str) == 0) return true; } return false; @@ -1079,24 +1085,28 @@ int dm_time_format(time_t ts, char **dst) void convert_string_to_hex(const char *str, char *hex, size_t size) { - int i, j, len = strlen(str); + int i, len = DM_STRLEN(str); + unsigned pos = 0; - for (i = 0, j = 0; i < len && j < size - 2; i++, j += 2) { - sprintf((char *)hex + j, "%02X", str[i]); + for (i = 0; i < len && pos < size - 2; i++) { + pos += snprintf((char *)hex + pos, size - pos, "%02X", str[i]); } - hex[j] = '\0'; + + hex[pos] = '\0'; } void convert_hex_to_string(const char *hex, char *str, size_t size) { - int i, j, len = strlen(hex); + int i, len = DM_STRLEN(hex); + unsigned pos = 0; char buf[3] = {0}; - for (i = 0, j = 0; i < len && j < size - 1; i += 2, j++) { + for (i = 0; i < len && pos < size - 1; i += 2) { DM_STRNCPY(buf, &hex[i], 3); - sprintf((char *)str + j, "%c", (char)strtol(buf, NULL, 16)); + pos += snprintf((char *)str + pos, size - pos, "%c", (char)strtol(buf, NULL, 16)); } - str[j] = '\0'; + + str[pos] = '\0'; } bool match(const char *string, const char *pattern) @@ -1111,7 +1121,7 @@ bool match(const char *string, const char *pattern) static int dm_validate_string_length(char *value, int min_length, int max_length) { - if (((min_length > 0) && (strlen(value) < min_length)) || ((max_length > 0) && (strlen(value) > max_length))) + if (((min_length > 0) && (DM_STRLEN(value) < min_length)) || ((max_length > 0) && (DM_STRLEN(value) > max_length))) return -1; return 0; } @@ -1119,7 +1129,7 @@ static int dm_validate_string_length(char *value, int min_length, int max_length static int dm_validate_string_enumeration(char *value, char *enumeration[]) { for (; *enumeration; enumeration++) { - if (strcmp(*enumeration, value) == 0) + if (DM_STRCMP(*enumeration, value) == 0) return 0; } return -1; @@ -1165,10 +1175,11 @@ int dm_validate_boolean(char *value) int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_size) { - int i; + if (!value || value[0] == 0) + return -1; /* check size for each range */ - for (i = 0; i < r_args_size; i++) { + for (int i = 0; i < r_args_size; i++) { unsigned long ui_val = 0, minval = 0, maxval = 0; char *endval = NULL, *endmin = NULL, *endmax = NULL; @@ -1208,10 +1219,11 @@ int dm_validate_unsignedInt(char *value, struct range_args r_args[], int r_args_ int dm_validate_int(char *value, struct range_args r_args[], int r_args_size) { - int i; + if (!value || value[0] == 0) + return -1; /* check size for each range */ - for (i = 0; i < r_args_size; i++) { + for (int i = 0; i < r_args_size; i++) { long i_val = 0, minval = 0, maxval = 0; char *endval = NULL, *endmin = NULL, *endmax = NULL; @@ -1246,10 +1258,11 @@ int dm_validate_int(char *value, struct range_args r_args[], int r_args_size) int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args_size) { - int i; + if (!value || value[0] == 0) + return -1; /* check size for each range */ - for (i = 0; i < r_args_size; i++) { + for (int i = 0; i < r_args_size; i++) { unsigned long ul_val = 0, minval = 0, maxval = 0; char *endval = NULL, *endmin = NULL, *endmax = NULL; @@ -1284,10 +1297,11 @@ int dm_validate_unsignedLong(char *value, struct range_args r_args[], int r_args int dm_validate_long(char *value, struct range_args r_args[], int r_args_size) { - int i; + if (!value || value[0] == 0) + return -1; /* check size for each range */ - for (i = 0; i < r_args_size; i++) { + for (int i = 0; i < r_args_size; i++) { long u_val = 0, minval = 0, maxval = 0; char *endval = NULL, *endmin = NULL, *endmax = NULL; @@ -1338,11 +1352,11 @@ int dm_validate_dateTime(char *value) return 0; p = strptime(value, "%Y-%m-%dT%H:%M:%S.", &tm); - if (!p || *p == '\0' || value[strlen(value) - 1] != 'Z') + if (!p || *p == '\0' || value[DM_STRLEN(value) - 1] != 'Z') return -1; int num_parsed = sscanf(p, "%dZ", &m); - if (num_parsed != 1 || (strlen(p) != 7 && strlen(p) != 4)) + if (num_parsed != 1 || (DM_STRLEN(p) != 7 && DM_STRLEN(p) != 4)) return -1; return 0; @@ -1353,7 +1367,7 @@ int dm_validate_hexBinary(char *value, struct range_args r_args[], int r_args_si int i; /* check format */ - for (i = 0; i < strlen(value); i++) { + for (i = 0; i < DM_STRLEN(value); i++) { if (!isxdigit(value[i])) return -1; } @@ -1361,9 +1375,9 @@ int dm_validate_hexBinary(char *value, struct range_args r_args[], int r_args_si /* check size */ for (i = 0; i < r_args_size; i++) { - if (r_args[i].min && r_args[i].max && (atoi(r_args[i].min) == atoi(r_args[i].max))) { + if (r_args[i].min && r_args[i].max && (DM_STRTOL(r_args[i].min) == DM_STRTOL(r_args[i].max))) { - if (strlen(value) == 2 * atoi(r_args[i].max)) + if (DM_STRLEN(value) == 2 * DM_STRTOL(r_args[i].max)) break; if (i == r_args_size - 1) @@ -1372,8 +1386,8 @@ int dm_validate_hexBinary(char *value, struct range_args r_args[], int r_args_si continue; } - if ((r_args[i].min && (strlen(value) < atoi(r_args[i].min))) || - (r_args[i].max && (strlen(value) > atoi(r_args[i].max)))) { + if ((r_args[i].min && (DM_STRLEN(value) < DM_STRTOL(r_args[i].min))) || + (r_args[i].max && (DM_STRLEN(value) > DM_STRTOL(r_args[i].max)))) { return -1; } } @@ -1398,6 +1412,9 @@ int dm_validate_string_list(char *value, int min_item, int max_item, int max_siz char *pch, *pchr; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1425,6 +1442,9 @@ int dm_validate_unsignedInt_list(char *value, int min_item, int max_item, int ma char *tmp, *saveptr; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1452,6 +1472,9 @@ int dm_validate_int_list(char *value, int min_item, int max_item, int max_size, char *token, *pchr; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1479,6 +1502,9 @@ int dm_validate_unsignedLong_list(char *value, int min_item, int max_item, int m char *token, *tmp; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1506,6 +1532,9 @@ int dm_validate_long_list(char *value, int min_item, int max_item, int max_size, char *pch, *saveptr; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1533,6 +1562,9 @@ int dm_validate_hexBinary_list(char *value, int min_item, int max_item, int max_ char *pch, *spch; int nbr_item = 0; + if (!value) + return -1; + /* check length of list */ if ((max_size > 0) && (strlen(value) > max_size)) return -1; @@ -1612,10 +1644,10 @@ char *base64_decode(const char *src) if (!src || *src == '\0') return ""; - size_t decsize = strlen(src)*6/8; + size_t decsize = DM_STRLEN(src)*6/8; char *out = (char *)dmmalloc((decsize +1) * sizeof(char)); - for (i = 0; i < strlen(src)-1; i++) { + for (i = 0; i < DM_STRLEN(src)-1; i++) { out[j] = (get_base64_char(src[i]) << (j%3==0?2:(j%3==1?4:6))) + (get_base64_char(src[i+1]) >> (j%3==0?4:(j%3==1? 2:0))); if (j%3 == 2) i++; @@ -1643,22 +1675,22 @@ void string_to_mac(const char *str, size_t str_len, char *out, size_t out_len) char *replace_char(char *str, char find, char replace) { - char *current_pos = strchr(str, find); + char *current_pos = DM_STRCHR(str, find); while (current_pos) { *current_pos = replace; - current_pos = strchr(current_pos, find); + current_pos = DM_STRCHR(current_pos, find); } 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 replacement_len = DM_STRLEN(replacement); + int substr_len = DM_STRLEN(substr); int i, cnt = 0; for (i = 0; str[i] != '\0'; i++) { - if (strstr(&str[i], substr) == &str[i]) { + if (DM_STRSTR(&str[i], substr) == &str[i]) { cnt++; i += substr_len - 1; } @@ -1687,7 +1719,7 @@ int check_browse_section(struct uci_section *s, void *data) char *opt_val; dmuci_get_value_by_section_string(s, browse_args->option, &opt_val); - if (strcmp(opt_val, browse_args->value) == 0) + if (DM_STRCMP(opt_val, browse_args->value) == 0) return 0; return -1; } @@ -1701,7 +1733,7 @@ int parse_proc_intf6_line(const char *line, const char *device, char *ipstr, siz &ip[0], &ip[1], &ip[2], &ip[3], &prefix, dev); - if (strcmp(dev, device) != 0) + if (DM_STRCMP(dev, device) != 0) return -1; ip[0] = htonl(ip[0]); @@ -1760,8 +1792,8 @@ char *get_ipv6(char *interface_name) ipstr[0] = '\0'; if (parse_proc_intf6_line(buf, interface_name, ipstr, sizeof(ipstr)) == 0) { - if (strlen(ipstr) != 0) { - char *slash = strchr(ipstr, '/'); + if (DM_STRLEN(ipstr) != 0) { + char *slash = DM_STRCHR(ipstr, '/'); if (slash) *slash = '\0'; } @@ -1791,7 +1823,7 @@ static bool validate_blob_dataval(struct blob_attr *src_attr, struct blob_attr * if (src_val == NULL && dst_val == NULL) return true; - if (src_val && dst_val && strcmp((char *)src_val, (char*)dst_val) == 0) + if (src_val && dst_val && DM_STRCMP((char *)src_val, (char*)dst_val) == 0) return true; break; default: @@ -1837,7 +1869,7 @@ bool validate_blob_message(struct blob_attr *src, struct blob_attr *dst) __blob_for_each_attr(src_attr, blobmsg_data(src), src_len) { bool matched = false; __blob_for_each_attr(dst_attr, blobmsg_data(dst), dst_len) { - if (strcmp(blobmsg_name(src_attr), blobmsg_name(dst_attr)) != 0) { + if (DM_STRCMP(blobmsg_name(src_attr), blobmsg_name(dst_attr)) != 0) { continue; } diff --git a/libbbf_api/dmcommon.h b/libbbf_api/dmcommon.h index 54c9bfe9..b636c272 100644 --- a/libbbf_api/dmcommon.h +++ b/libbbf_api/dmcommon.h @@ -138,7 +138,7 @@ do { \ #define dmstrappendstr(dest, src) \ do { \ - int len = strlen(src); \ + int len = DM_STRLEN(src); \ memcpy(dest, src, len); \ dest += len; \ } while(0) @@ -213,7 +213,7 @@ bool is_strword_in_optionvalue(char *optionvalue, char *str); void remove_new_line(char *buf); int dmcmd(char *cmd, int n, ...); int dmcmd_no_wait(char *cmd, int n, ...); -void hex_to_ip(char *address, char *ret); +void hex_to_ip(char *address, char *ret, size_t size); void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section); 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); diff --git a/libbbf_api/dmjson.c b/libbbf_api/dmjson.c index 1e5828b0..baf1da20 100644 --- a/libbbf_api/dmjson.c +++ b/libbbf_api/dmjson.c @@ -178,7 +178,7 @@ static char *____dmjson_get_value_array_all(json_object *mainjobj, char *delim, int i, dlen, rlen; delim = (delim) ? delim : ","; - dlen = (delim) ? strlen(delim) : 1; + dlen = (delim) ? DM_STRLEN(delim) : 1; for (i = 0, arrobj = NULL, v = ____dmjson_get_value_in_array_idx(mainjobj, &arrobj, i, argv); v; diff --git a/libbbf_api/dmubus.c b/libbbf_api/dmubus.c index 2ba4d71c..3f0b43d6 100644 --- a/libbbf_api/dmubus.c +++ b/libbbf_api/dmubus.c @@ -71,7 +71,7 @@ static void prepare_blob_message(struct blob_buf *b, const struct ubus_arg u_arg blob_buf_init(b, 0); for (int i = 0; i < u_args_size; i++) { if (u_args[i].type == Integer) { - blobmsg_add_u32(b, u_args[i].key, atoi(u_args[i].val)); + blobmsg_add_u32(b, u_args[i].key, DM_STRTOL(u_args[i].val)); } else if (u_args[i].type == Boolean) { bool val = false; string_to_bool((char *)u_args[i].val, &val); @@ -389,15 +389,15 @@ static unsigned dm_ubus_req_hash_from_blob(const struct dm_ubus_hash_req *req) return hash; } - hash = djbhash(hash, req->obj, strlen(req->obj)); - hash = djbhash(hash, req->method, strlen(req->method)); + hash = djbhash(hash, req->obj, DM_STRLEN(req->obj)); + hash = djbhash(hash, req->method, DM_STRLEN(req->method)); char *jmsg = blobmsg_format_json(req->attr, true); if (!jmsg) { return hash; } - hash = djbhash(hash, jmsg, strlen(jmsg)); + hash = djbhash(hash, jmsg, DM_STRLEN(jmsg)); free(jmsg); return hash; } @@ -520,7 +520,7 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat blob_for_each_attr(cur, obj->signature, rem) { const char *method_name = blobmsg_name(cur); - if (!strcmp(ubus_method, method_name)) { + if (!DM_STRCMP(ubus_method, method_name)) { ubus_method_exists = true; return; } @@ -529,6 +529,9 @@ static void receive_list_result(struct ubus_context *ctx, struct ubus_object_dat bool dmubus_object_method_exists(const char *obj) { + if (obj == NULL) + return false; + if (ubus_ctx == NULL) { ubus_ctx = dm_libubus_init(); if (ubus_ctx == NULL) { diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index 6c0ae27b..cd97b91a 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -105,7 +105,7 @@ static void add_list_package_change(struct list_head *clist, char *package) struct package_change *pc = NULL; list_for_each_entry(pc, clist, list) { - if (strcmp(pc->package, package) == 0) + if (DM_STRCMP(pc->package, package) == 0) return; } pc = calloc(1, sizeof(struct package_change));//TODO !!!!! Do not use dmcalloc here @@ -611,7 +611,7 @@ int dmuci_get_value_by_section_string(struct uci_section *s, char *option, char uci_foreach_element(&s->options, e) { o = (uci_to_option(e)); - if (!strcmp(o->e.name, option)) { + if (!DM_STRCMP(o->e.name, option)) { if (o->type == UCI_TYPE_LIST) { *value = dmuci_list_to_string(&o->v.list, " "); } else { @@ -651,7 +651,7 @@ int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_foreach_element(&s->options, e) { o = (uci_to_option(e)); - if (strcmp(o->e.name, option) == 0) { + if (DM_STRCMP(o->e.name, option) == 0) { switch(o->type) { case UCI_TYPE_LIST: *value = &o->v.list; @@ -788,18 +788,18 @@ struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, while(&e->list != list_section) { s = uci_to_section(e); - if (strcmp(s->type, stype) == 0) { + if (DM_STRCMP(s->type, stype) == 0) { switch(cmp) { case CMP_SECTION: goto end; case CMP_OPTION_EQUAL: dmuci_get_value_by_section_string(s, (char *)arg1, &value); - if (strcmp(value, (char *)arg2) == 0) + if (DM_STRCMP(value, (char *)arg2) == 0) goto end; break; case CMP_OPTION_CONTAINING: dmuci_get_value_by_section_string(s, (char *)arg1, &value); - if (strstr(value, (char *)arg2)) + if (DM_STRSTR(value, (char *)arg2)) goto end; break; case CMP_OPTION_CONT_WORD: @@ -807,7 +807,7 @@ struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, dup = dmstrdup(value); pch = strtok_r(dup, " ", &spch); while (pch != NULL) { - if (strcmp((char *)arg2, pch) == 0) { + if (DM_STRCMP((char *)arg2, pch) == 0) { dmfree(dup); goto end; } @@ -819,7 +819,7 @@ struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, dmuci_get_value_by_section_list(s, (char *)arg1, &list_value); if (list_value != NULL) { uci_foreach_element(list_value, m) { - if (strcmp(m->name, (char *)arg2) == 0) + if (DM_STRCMP(m->name, (char *)arg2) == 0) goto end; } } @@ -939,7 +939,7 @@ void dmuci_replace_invalid_characters_from_section_name(char *old_sec_name, char DM_STRNCPY(new_sec_name, old_sec_name, len); - for (int i = 0; i < strlen(new_sec_name); i++) { + for (int i = 0; i < DM_STRLEN(new_sec_name); i++) { // Replace all {'.' or '-'} with '_' if (new_sec_name[i] == '.' || new_sec_name[i] == '-') diff --git a/libbbf_ubus/libbbf_ubus.c b/libbbf_ubus/libbbf_ubus.c index 2a029306..6f2c24b7 100644 --- a/libbbf_ubus/libbbf_ubus.c +++ b/libbbf_ubus/libbbf_ubus.c @@ -139,9 +139,9 @@ static int get_protocol(const char *val) { int type; - if (strcmp("cwmp", val) == 0) + if (DM_STRCMP("cwmp", val) == 0) type = BBFDM_CWMP; - else if (strcmp("usp", val) == 0) + else if (DM_STRCMP("usp", val) == 0) type = BBFDM_USP; else type = BBFDM_BOTH; @@ -177,7 +177,7 @@ static struct obj_node* find_obj_node(const char *ubus_name) if (temp == NULL) return NULL; - while (strcmp(ubus_name, temp->obj_name) != 0) { + while (DM_STRCMP(ubus_name, temp->obj_name) != 0) { if (temp->next == NULL) { return NULL; } else { @@ -306,7 +306,7 @@ static int handle_add_del_req(struct ubus_context *ctx, const char *ubus_name, s set_bbfdatamodel_type(proto); dm_ctx_init_entry(&bbf_ctx, tEntryObj, 0); - if (strcmp(method, "add_object") == 0) { + if (DM_STRCMP(method, "add_object") == 0) { fault = dm_entry_param_method(&bbf_ctx, CMD_ADD_OBJECT, path, pkey, NULL); } else { fault = dm_entry_param_method(&bbf_ctx, CMD_DEL_OBJECT, path, pkey, NULL); @@ -320,7 +320,7 @@ static int handle_add_del_req(struct ubus_context *ctx, const char *ubus_name, s blobmsg_add_u32(&bb, "fault", fault); blobmsg_add_u8(&bb, "status", 0); } else { - if (strcmp(method, "add_object") == 0) { + if (DM_STRCMP(method, "add_object") == 0) { if (bbf_ctx.addobj_instance) { blobmsg_add_u8(&bb, "status", 1); bb_add_string(&bb, "instance", bbf_ctx.addobj_instance); @@ -537,7 +537,7 @@ static int libbbf_ubus_operate(struct ubus_context *ctx, struct ubus_object *obj snprintf(path, PATH_MAX, "%s", (char *)blobmsg_data(tb[LIBBBF_UBUS_OPERATE_PATH])); - len = strlen(path); + len = DM_STRLEN(path); if (path[len - 1] == '.') { printf("path can't end with (.)\n\r"); if (input) @@ -627,7 +627,7 @@ static int libbbf_ubus_add_del_handler(struct ubus_context *ctx, struct ubus_obj snprintf(path, PATH_MAX, "%s", (char *)blobmsg_data(tb[LIBBBF_UBUS_ADD_DEL_PATH])); - plen = strlen(path); + plen = DM_STRLEN(path); if (path[plen - 1] != '.') { if (plen > PATH_MAX - 2) { printf("path too long(%d) can't append (.)\n\r", plen); @@ -672,7 +672,7 @@ static int libbbf_ubus_set_handler(struct ubus_context *ctx, struct ubus_object snprintf(path, PATH_MAX, "%s", (char *)blobmsg_data(tb[LIBBBF_UBUS_SET_PATH])); snprintf(value, PATH_MAX, "%s", (char *)blobmsg_data(tb[LIBBBF_UBUS_SET_VALUE])); - int plen = strlen(path); + int plen = DM_STRLEN(path); if (path[plen - 1] == '.') { printf("path can't end with (.)\n\r"); return UBUS_STATUS_INVALID_ARGUMENT; @@ -763,7 +763,7 @@ static int libbbf_ubus_transaction_handler(struct ubus_context *ctx, struct ubus memset(&bb, 0, sizeof(struct blob_buf)); blob_buf_init(&bb, 0); - if (strcmp(method, "transaction_start") == 0) { + if (DM_STRCMP(method, "transaction_start") == 0) { if (!g_dynamicdm_transaction_start) { g_dynamicdm_transaction_start = true; blobmsg_add_u8(&bb, "status", true); @@ -771,7 +771,7 @@ static int libbbf_ubus_transaction_handler(struct ubus_context *ctx, struct ubus printf("Transaction already in process\n"); blobmsg_add_u8(&bb, "status", false); } - } else if(strcmp(method, "transaction_abort") == 0) { + } else if(DM_STRCMP(method, "transaction_abort") == 0) { if (g_dynamicdm_transaction_start) { g_dynamicdm_transaction_start = false; dm_ctx_init_entry(&bbf_ctx, tEntryObj, 0); @@ -782,7 +782,7 @@ static int libbbf_ubus_transaction_handler(struct ubus_context *ctx, struct ubus printf("Transaction still not started\n\r"); blobmsg_add_u8(&bb, "status", false); } - } else if (strcmp(method, "transaction_commit") == 0) { + } else if (DM_STRCMP(method, "transaction_commit") == 0) { if (g_dynamicdm_transaction_start) { g_dynamicdm_transaction_start = false; dm_ctx_init_entry(&bbf_ctx, tEntryObj, 0); @@ -907,7 +907,7 @@ void dynamicdm_free(struct ubus_context *ctx, const char *ubus_name) if (curr == NULL) return; - while (strcmp(ubus_name, curr->obj_name) != 0) { + while (DM_STRCMP(ubus_name, curr->obj_name) != 0) { if (curr->next == NULL) { return; } else { diff --git a/scripts/bbf_uci_api b/scripts/bbf_uci_api index 3bffbda0..b30974bb 100755 --- a/scripts/bbf_uci_api +++ b/scripts/bbf_uci_api @@ -15,11 +15,11 @@ UCI_COMMIT_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap commit" UCI_SHOW_BBF_DMMAP="uci -q -c /etc/bbfdm/dmmap show" uci_get() { - local val=`$UCI_GET $1` + val=$($UCI_GET $1) echo ${val:-$2} } uci_get_bbf_dmmap() { - local val=`$UCI_GET_BBF_DMMAP $1` + val=$($UCI_GET_BBF_DMMAP $1) echo ${val:-$2} } diff --git a/scripts/download_launch b/scripts/download_launch index 27ed5d4a..a9a0c48e 100755 --- a/scripts/download_launch +++ b/scripts/download_launch @@ -1,55 +1,54 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: IMEN Bhiri # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api CAPTURE_FILE="/tmp/download_dump" DOWNLOAD_DIAGNOSTIC_FILE="/tmp/bbfdm_download_diagnostic" CONNECTION_TIMEOUT=60 download_launch() { - local proto tx_bytes_before rx_bytes_before time1 tx_bytes_after rx_bytes_after time2 periodtime error_code - local url=$1 - local device=$2 + url=$1 + device=$2 [ "$url" = "" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; return; } - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.download.ProtocolVersion Any` - if [ "$protocol" == "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" == "IPv6" ]; then proto="--ipv6"; else proto=""; fi + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.download.ProtocolVersion Any) + if [ "$protocol" = "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" = "IPv6" ]; then proto="--ipv6"; else proto=""; fi # Disable acceleration on Broadcom devices to capture all packets with tcpdump [ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; } - tcpdump -i $device tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & + tcpdump -i "$device" tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & PID=$! sleep 1 if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then - tx_bytes_before=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes` - rx_bytes_before=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes` - time1=`date +%s` - curl $proto --fail --silent --connect-timeout ${CONNECTION_TIMEOUT} -o ${DOWNLOAD_DIAGNOSTIC_FILE} $url + tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes) + rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes) + time1=$(date +%s) + curl $proto --fail --silent --connect-timeout ${CONNECTION_TIMEOUT} -o ${DOWNLOAD_DIAGNOSTIC_FILE} "$url" error_code="$?" - time2=`date +%s` - tx_bytes_after=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes` - rx_bytes_after=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes` + time2=$(date +%s) + tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes) + rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes) - [ "$error_code" == "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } - [ "$error_code" == "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } - [ "$error_code" == "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } - [ "$error_code" == "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } - [ "$error_code" == "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } [ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } fi tx_bytes=$((tx_bytes_after-tx_bytes_before)) rx_bytes=$((rx_bytes_after-rx_bytes_before)) periodtime=$(($((time2-time1))*1000000)) - + $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=Complete $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesReceived=$rx_bytes $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.TotalBytesSent=$tx_bytes $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.PeriodOfFullLoading=$periodtime - local perconnection=`$UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection` - if ([ "$perconnection" == "true" ] || [ "$perconnection" == "1" ]); then + perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.download.EnablePerConnection) + if [ "$perconnection" = "true" ] || [ "$perconnection" = "1" ]; then $UCI_ADD_BBF_DMMAP dmmap_diagnostics DownloadPerConnection $UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesReceived=$rx_bytes $UCI_SET_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0].TotalBytesSent=$tx_bytes @@ -59,34 +58,33 @@ download_launch() { $UCI_COMMIT_BBF_DMMAP rm ${DOWNLOAD_DIAGNOSTIC_FILE} 2>/dev/null sleep 1 - local pids=`ps | grep $PID` - kill $PID &>/dev/null + kill $PID >/dev/null 2>&1 # Enable acceleration on Broadcom devices after killing the tcpdump pid [ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; } } download_stop_diagnostic() { $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@DownloadPerConnection[0] - local pids=`ps | grep download_launch.*run | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f download_launch.*run) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=None fi - local pids=`ps | grep download_launch.*run | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f download_launch.*run) if [ -n "$pids" ]; then kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*") for kid in $kids; do - kill -9 $kid &>/dev/null + kill -9 "$kid" >/dev/null 2>&1 done - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.download.DiagnosticState=None fi $UCI_COMMIT_BBF_DMMAP } -if [ "$1" == "run" ] ; then - download_launch $2 $3 -elif [ "$1" == "stop" ]; then +if [ "$1" = "run" ] ; then + download_launch "$2" "$3" +elif [ "$1" = "stop" ]; then download_stop_diagnostic else return diff --git a/scripts/ipping_launch b/scripts/ipping_launch index 73b983a2..115d5ec1 100755 --- a/scripts/ipping_launch +++ b/scripts/ipping_launch @@ -1,15 +1,15 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: MOHAMED Kallel # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api ipping_error() { - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3` + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3) $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=0 - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount=$cnt + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$cnt" $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=0 $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=9999 $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=0 @@ -20,15 +20,14 @@ ipping_error() } ipping_launch() { - local i proto device res ba stc times sc1 success_count failure_count min_time avg_time max_time avg_time_sum min max micros avg_time_det min_time_det max_time_det avg_time_sum_det min_det max_det - local host=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.Host` - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3` - local dsize=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.DataBlockSize 64` - local timeout=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.Timeout 1000` - local interface=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.interface` - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.ipping.ProtocolVersion Any` - [ ! -z "$interface" ] && device=`ifstatus $interface | jsonfilter -e @.device` && device="-I $device" || device="" - if [ "$protocol" == "IPv4" ]; then proto="-4"; elif [ "$protocol" == "IPv6" ]; then proto="-6"; else proto=""; fi + host=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.Host) + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.NumberOfRepetitions 3) + dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.DataBlockSize 64) + timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.Timeout 1000) + interface=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.interface) + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.ipping.ProtocolVersion Any) + [ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-I $device" || device="" + if [ "$protocol" = "IPv4" ]; then proto="-4"; elif [ "$protocol" = "IPv6" ]; then proto="-6"; else proto=""; fi [ "$host" = "" ] && return timeout=$((timeout/1000)) [ "$timeout" = "0" ] && timeout="1" @@ -42,38 +41,38 @@ ipping_launch() { max_det=0 i=0 - while [ $i -lt $cnt ]; do - let i++ + while [ $i -lt "$cnt" ]; do + i=$((i+1)) res=$(ping -q $proto -c 1 -s $dsize -W $timeout $device $host 2>&1) - ba=`echo "$res" | grep "bad address"` + ba=$(echo "$res" | grep "bad address") [ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_CannotResolveHostName; ipping_error; return; } - ba=`echo "$res" | grep "unknown host"` + ba=$(echo "$res" | grep "unknown host") [ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_CannotResolveHostName; ipping_error; return; } - stc=`echo "$res" | grep "received"` + stc=$(echo "$res" | grep "received") [ -z "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Error_Other; ipping_error; return; } - times=`echo "$res" | grep "min/avg/max"` + times=$(echo "$res" | grep "min/avg/max") [ -z "$times" ] && continue - sc1=`echo $stc | awk '{print $4}'` + sc1=$(echo "$stc" | awk '{print $4}') sc1=${sc1:-0} success_count=$((success_count+sc1)) - times=`echo $times | awk -F'=' '{ print $2 }'` - min_time=`echo $times | awk -F'[=/ ]' '{ print $1 }'` - avg_time=`echo $times | awk -F'[=/ ]' '{ print $2 }'` - max_time=`echo $times | awk -F'[=/ ]' '{ print $3 }'` + times=$(echo "$times" | awk -F'=' '{ print $2 }') + min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }') + avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }') + max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }') min_time=${min_time:-0} avg_time=${avg_time:-0} max_time=${max_time:-0} - min_time_det=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') - avg_time_det=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') - max_time_det=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') + min_time_det=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + avg_time_det=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + max_time_det=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') min_time=$(awk "BEGIN{print $min_time * 1000}") avg_time=$(awk "BEGIN{print $avg_time * 1000}") max_time=$(awk "BEGIN{print $max_time * 1000}") - [ $min_time -lt $min ] && min=$min_time - [ $max_time -gt $max ] && max=$max_time + [ "$min_time" -lt $min ] && min=$min_time + [ "$max_time" -gt $max ] && max=$max_time avg_time_sum=$((avg_time_sum+avg_time)) - [ $min_time_det -lt $min_det ] && min_det=$min_time_det - [ $max_time_det -gt $max_det ] && max_det=$max_time_det + [ "$min_time_det" -lt $min_det ] && min_det=$min_time_det + [ "$max_time_det" -gt $max_det ] && max_det=$max_time_det avg_time_sum_det=$((avg_time_sum_det+avg_time_det)) done failure_count=$((cnt-success_count)) @@ -84,30 +83,30 @@ ipping_launch() { max_time=$(awk "BEGIN{print int($max / 1000)}") min_time_det=$min_det max_time_det=$max_det - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=Complete - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount=$success_count - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount=$failure_count - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime=$avg_time - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime=$min_time - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime=$max_time - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed=$avg_time_det - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed=$min_time_det - $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed=$max_time_det + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState="Complete" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.SuccessCount="$success_count" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.FailureCount="$failure_count" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTime="$avg_time" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTime="$min_time" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTime="$max_time" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.AverageResponseTimeDetailed="$avg_time_det" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MinimumResponseTimeDetailed="$min_time_det" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.MaximumResponseTimeDetailed="$max_time_det" $UCI_COMMIT_BBF_DMMAP } ipping_stop_diagnostic() { - local pids=`ps | grep ipping_launch | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f ipping_launch) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.ipping.DiagnosticState=None $UCI_COMMIT_BBF_DMMAP fi } -if [ "$1" == "run" ]; then +if [ "$1" = "run" ]; then ipping_launch -elif [ "$1" == "stop" ]; then +elif [ "$1" = "stop" ]; then ipping_stop_diagnostic else return diff --git a/scripts/nslookup_launch b/scripts/nslookup_launch index 2c977b2d..d31f34d3 100755 --- a/scripts/nslookup_launch +++ b/scripts/nslookup_launch @@ -1,32 +1,31 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api LOG_FILE="/tmp/nslookup.log" nslookup_launch() { - local i j time1 time2 timeresponse status AnswerType HostNameReturned address dns_server_ip ResponseTime success_count - local address="" - local hostname=`uci_get_bbf_dmmap dmmap_diagnostics.nslookup.HostName` - local dnsserver=`uci_get_bbf_dmmap dmmap_diagnostics.nslookup.DNSServer` - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.nslookup.NumberOfRepetitions 1` + address="" + hostname=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.HostName) + dnsserver=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.DNSServer) + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.nslookup.NumberOfRepetitions 1) [ "$hostname" = "" ] && return i=0 j=0 success_count=0 [ -e "${LOG_FILE}" ] && rm ${LOG_FILE} delete_all_results - while [ $i -lt $cnt ]; do - let i++ - time1=`date +%s` + while [ $i -lt "$cnt" ]; do + i=$((i+1)) + time1=$(date +%s) if [ -z "$dnsserver" ]; then - nslookup $hostname >>${LOG_FILE} 2>&1 + nslookup "$hostname" >>${LOG_FILE} 2>&1 else - nslookup $hostname $dnsserver >>${LOG_FILE} 2>&1 + nslookup "$hostname" "$dnsserver" >>${LOG_FILE} 2>&1 fi - time2=`date +%s` + time2=$(date +%s) timeresponse=$(($(($time2-$time1))*1000)) echo "ResponseTime: $timeresponse" >>${LOG_FILE} echo "++++++++++++++++++++++++++++++" >>${LOG_FILE} @@ -34,9 +33,9 @@ nslookup_launch() { while IFS= read line; do [ -z "$line" ] && continue; - local server=`echo "$line" | tr -d '\t' | tr -d ' ' | grep "Server:" | awk -F':' '{print $2}'` + server=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Server:" | awk -F':' '{print $2}') - if [[ -n "$server" && "$server" == "0.0.0.0" ]]; then + if [ -n "$server" ] && [ "$server" = "0.0.0.0" ]; then status="Error_DNSServerNotAvailable" continue elif [ -n "$server" ]; then @@ -44,28 +43,28 @@ nslookup_launch() { continue fi - var=`echo "$line" | tr -d '\t' | tr -d ' ' | grep "Name:" | awk -F':' '{print $2}'` - [ -n "$var" ] && { HostNameReturned=$var; status="Success"; AnswerType="Authoritative"; let success_count++; continue; } + var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "Name:" | awk -F':' '{print $2}') + [ -n "$var" ] && { HostNameReturned=$var; status="Success"; AnswerType="Authoritative"; success_count=$((success_count+1)); continue; } - var=`echo "$line" | grep "Address " | awk -F':' '{print substr($0, index($0,$2))}' | tr -d '\t' | tr -d ' '` + var=$(echo "$line" | grep "Address " | awk -F':' '{print substr($0, index($0,$2))}' | tr -d '\t' | tr -d ' ') [ -n "$var" ] && { [ -z "$address" ] && address="$var" || address="$address,$var"; continue; } - var=`echo "$line" | tr -d '\t' | tr -d ' ' | grep "ResponseTime:" | awk -F':' '{print $2}'` + var=$(echo "$line" | tr -d '\t' | tr -d ' ' | grep "ResponseTime:" | awk -F':' '{print $2}') [ -n "$var" ] && { ResponseTime=$var; continue; } - echo $line | grep 'Can' >/dev/null 2>&1 && { continue; } - echo $line | grep 'connection timed out' >/dev/null 2>&1 && { AnswerType="None"; status="Error_Timeout"; continue; } - echo $line | grep 'Non-authoritative' >/dev/null 2>&1 && { AnswerType="NonAuthoritative"; continue; } + echo "$line" | grep 'Can' >/dev/null 2>&1 && { continue; } + echo "$line" | grep 'connection timed out' >/dev/null 2>&1 && { AnswerType="None"; status="Error_Timeout"; continue; } + echo "$line" | grep 'Non-authoritative' >/dev/null 2>&1 && { AnswerType="NonAuthoritative"; continue; } - if echo $line | grep '++++++++++++++++++++++' >/dev/null 2>&1; then + if echo "$line" | grep '++++++++++++++++++++++' >/dev/null 2>&1; then $UCI_ADD_BBF_DMMAP dmmap_diagnostics NSLookupResult - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].Status=$status - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].AnswerType=$AnswerType - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].HostNameReturned=$HostNameReturned - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].IPAddresses=$address - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].DNSServerIP=$dns_server_ip - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].ResponseTime=$ResponseTime - let j++ + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].Status="$status" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].AnswerType="$AnswerType" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].HostNameReturned="$HostNameReturned" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].IPAddresses="$address" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].DNSServerIP="$dns_server_ip" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[$j].ResponseTime="$ResponseTime" + j=$((j+1)) address="" fi done <${LOG_FILE} @@ -76,7 +75,6 @@ nslookup_launch() { } delete_all_results() { - local j for j in $($UCI_SHOW_BBF_DMMAP dmmap_diagnostics | grep "dmmap_diagnostics.@NSLookupResult.*=NSLookupResult"); do $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@NSLookupResult[-1] done @@ -85,17 +83,17 @@ delete_all_results() { nslookup_stop_diagnostic() { delete_all_results - local pids=`ps | grep nslookup_launch | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f nslookup_launch) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.nslookup.DiagnosticState=None $UCI_COMMIT_BBF_DMMAP fi } -if [ "$1" == "run" ]; then +if [ "$1" = "run" ]; then nslookup_launch -elif [ "$1" == "stop" ]; then +elif [ "$1" = "stop" ]; then nslookup_stop_diagnostic else return diff --git a/scripts/serverselection_launch b/scripts/serverselection_launch index 01e8f18b..fd03393c 100755 --- a/scripts/serverselection_launch +++ b/scripts/serverselection_launch @@ -1,20 +1,18 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api serverselection_launch() { - local i proto device res ba stc times sc1 success_count min_time avg_time max_time avg_time_sum min max micros - local fasthost avg_time_host min_time_host max_time_host - local hostlist=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.HostList` - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.NumberOfRepetitions 3` - local timeout=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Timeout 1000` - local port=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.port` - local interface=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.interface` - local protoversion=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.ProtocolVersion Any` - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Protocol ICMP` - if [ "$protoversion" == "IPv4" ]; then proto="-4"; elif [ "$protoversion" == "IPv6" ]; then proto="-6"; else proto=""; fi + hostlist=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.HostList) + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.NumberOfRepetitions 3) + timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Timeout 1000) + port=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.port) + interface=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.interface) + protoversion=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.ProtocolVersion Any) + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.serverselection.Protocol ICMP) + if [ "$protoversion" = "IPv4" ]; then proto="-4"; elif [ "$protoversion" = "IPv6" ]; then proto="-6"; else proto=""; fi [ "$hostlist" = "" ] && return timeout=$((timeout/1000)) [ "$timeout" = "0" ] && timeout="1" @@ -26,68 +24,68 @@ serverselection_launch() { max=0 i=0 - for host in $(echo $hostlist | tr "," "\n"); do - if [ "$protocol" == "ICMP" ]; then - [ ! -z "$interface" ] && device=`ifstatus $interface | jsonfilter -e @.device` && device="-I $device" || device="" - while [ $i -lt $cnt ]; do - let i++ + for host in $(echo "$hostlist" | tr "," "\n"); do + if [ "$protocol" = "ICMP" ]; then + [ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-I $device" || device="" + while [ $i -lt "$cnt" ]; do + i=$((i+1)) res=$(ping -q $proto -c 1 -W $timeout $device $host 2>&1) - ba=`echo "$res" | grep "bad address"` + ba=$(echo "$res" | grep "bad address") [ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; break; } - ba=`echo "$res" | grep "unknown host"` + ba=$(echo "$res" | grep "unknown host") [ -n "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; break; } - stc=`echo "$res" | grep "received"` + stc=$(echo "$res" | grep "received") [ -z "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; break; } - times=`echo "$res" | grep "min/avg/max"` + times=$(echo "$res" | grep "min/avg/max") [ -z "$times" ] && break - sc1=`echo $stc | awk '{print $4}'` + sc1=$(echo "$stc" | awk '{print $4}') sc1=${sc1:-0} success_count=$((success_count+sc1)) - times=`echo $times | awk -F'=' '{ print $2 }'` - min_time=`echo $times | awk -F'[=/ ]' '{ print $1 }'` - avg_time=`echo $times | awk -F'[=/ ]' '{ print $2 }'` - max_time=`echo $times | awk -F'[=/ ]' '{ print $3 }'` + times=$(echo "$times" | awk -F'=' '{ print $2 }') + min_time=$(echo "$times" | awk -F'[=/ ]' '{ print $2 }') + avg_time=$(echo "$times" | awk -F'[=/ ]' '{ print $3 }') + max_time=$(echo "$times" | awk -F'[=/ ]' '{ print $4 }') min_time=${min_time:-0} avg_time=${avg_time:-0} max_time=${max_time:-0} - min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') - avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') - max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') - [ $min_time -lt $min ] && min=$min_time - [ $max_time -gt $max ] && max=$max_time + min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + [ "$min_time" -lt "$min" ] && min="$min_time" + [ "$max_time" -gt "$max" ] && max="$max_time" avg_time_sum=$((avg_time_sum+avg_time)) done else [ "$port" = "" ] && return - [ ! -z "$interface" ] && device=`ifstatus $interface | jsonfilter -e @.device` && device="-e $device" || device="" - while [ $i -lt $cnt ]; do - let i++ - res=$(nping $proto -c 1 --udp --dest-port $port --data-length 24 $device $host 2>&1) - ba=`echo "$res" | grep "RCVD"` + [ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-e $device" || device="" + while [ $i -lt "$cnt" ]; do + i=$((i+1)) + res=$(nping $proto -c 1 --udp --dest-port "$port" --data-length 24 "$device" "$host" 2>&1) + ba=$(echo "$res" | grep "RCVD") [ -z "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; } - stc=`echo "$res" | grep "RCVD" | grep "unreachable"` + stc=$(echo "$res" | grep "RCVD" | grep "unreachable") [ -n "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; return; } - times=`echo "$res" | grep "rtt"` + times=$(echo "$res" | grep "rtt") [ -z "$times" ] && continue - sc1=`echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }'` + sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }') sc1=${sc1:-0} success_count=$((success_count+sc1)) - max_time=`echo $times | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }'` - min_time=`echo $times | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }'` - avg_time=`echo $times | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }'` + max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }') + min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }') + avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }') min_time=${min_time:-0} avg_time=${avg_time:-0} max_time=${max_time:-0} - min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') - avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') - max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') - [ $min_time -lt $min ] && min=$min_time - [ $max_time -gt $max ] && max=$max_time + min_time=$(echo "$min_time" $micros | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo "$avg_time" $micros | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo "$max_time" $micros | awk '{printf "%3.0f\n",$1*$2}') + [ "$min_time" -lt "$min" ] && min="$min_time" + [ "$max_time" -gt "$max" ] && max="$max_time" avg_time_sum=$((avg_time_sum+avg_time)) done fi [ $success_count -gt 0 ] && avg_time=$((avg_time_sum/success_count)) || avg_time=0 - [[ "$avg_time" != "0" && $avg_time -lt $avg_time_host ]] && avg_time_host=$avg_time && min_time_host=$min && max_time_host=$max && fasthost=$host + [ "$avg_time" != "0" ] && [ $avg_time -lt $avg_time_host ] && avg_time_host="$avg_time" && min_time_host="$min" && max_time_host="$max" && fasthost="$host" success_count=0 avg_time_sum=0 min=9999999 @@ -95,25 +93,25 @@ serverselection_launch() { i=0 done $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=Complete - $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost=$fasthost - $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime=$avg_time_host - $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime=$min_time_host - $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime=$max_time_host + $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.FastestHost="$fasthost" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.AverageResponseTime="$avg_time_host" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MinimumResponseTime="$min_time_host" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.MaximumResponseTime="$max_time_host" $UCI_COMMIT_BBF_DMMAP } serverselection_stop_diagnostic() { - local pids=`ps | grep serverselection_launch | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f serverselection_launch) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.serverselection.DiagnosticState=None $UCI_COMMIT_BBF_DMMAP fi } -if [ "$1" == "run" ]; then +if [ "$1" = "run" ]; then serverselection_launch -elif [ "$1" == "stop" ]; then +elif [ "$1" = "stop" ]; then serverselection_stop_diagnostic else return diff --git a/scripts/traceroute_launch b/scripts/traceroute_launch index 6de3d429..c649d2fb 100755 --- a/scripts/traceroute_launch +++ b/scripts/traceroute_launch @@ -1,49 +1,47 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api traceroute_launch() { - local i proto device res host ip time=0 - local host=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Host` - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.NumberOfTries 3` - local dsize=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.DataBlockSize 38` - local timeout=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Timeout 5000` - local maxhop=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.MaxHops 30` - local interface=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.interface` - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.traceroute.ProtocolVersion Any` - [ ! -z "$interface" ] && device=`ifstatus $interface | jsonfilter -e @.device` && device="-i $device" || device="" - if [ "$protocol" == "IPv4" ]; then proto="-4"; elif [ "$protocol" == "IPv6" ]; then proto="-6"; else proto=""; fi + host=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Host) + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.NumberOfTries 3) + dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.DataBlockSize 38) + timeout=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.Timeout 5000) + maxhop=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.MaxHops 30) + interface=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.interface) + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.traceroute.ProtocolVersion Any) + [ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-i $device" || device="" + if [ "$protocol" = "IPv4" ]; then proto="-4"; elif [ "$protocol" = "IPv6" ]; then proto="-6"; else proto=""; fi [ "$host" = "" ] && return timeout=$((timeout/1000)) - [ "$timeout" = "0" ] && timeout = "1" + [ "$timeout" = "0" ] && timeout="1" i=-2 delete_all_route_hops rm -f /tmp/traceres traceroute -m $maxhop -w $timeout -q $cnt $proto $device $host $dsize 2>&1 >/tmp/traceres while read _ host ip time _; do - [ "$host" = "*" -a "$ip" = "*" ] && continue - let i++ + [ "$host" = "*" ] && [ "$ip" = "*" ] && continue + i=$((i+1)) [ "$i" = "-1" ] && continue; ip=${ip#(}; ip=${ip%)} time=${time%.*} $UCI_ADD_BBF_DMMAP dmmap_diagnostics RouteHops - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].host=$host - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].ip=$ip - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].time=$time + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].host="$host" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].ip="$ip" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@RouteHops[$i].time="$time" done < /tmp/traceres rm -f /tmp/traceres - let i++ + i=$((i+1)) $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=Complete $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.NumberOfHops=$i - $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.@RouteHops[-1].time) + $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.ResponseTime="$($UCI_GET_BBF_DMMAP dmmap_diagnostics.@RouteHops[-1].time)" $UCI_COMMIT_BBF_DMMAP } delete_all_route_hops() { - local j for j in $($UCI_SHOW_BBF_DMMAP dmmap_diagnostics | grep "dmmap_diagnostics.@RouteHops.*=RouteHops"); do $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@RouteHops[-1] $UCI_COMMIT_BBF_DMMAP @@ -52,19 +50,18 @@ delete_all_route_hops() { traceroute_stop() { delete_all_route_hops - local pids=`ps aux | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'` - [ -z "$pids" ] && pids=`ps | grep traceroute_launch | grep -v grep | grep -v stop | awk '{print $2}'` + pids=$(pgrep -f traceroute_launch) if [ -n "$pids" ]; then - kill -9 $pids 2>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.traceroute.DiagnosticState=None $UCI_COMMIT_BBF_DMMAP fi } -if [ "$1" == "run" ]; then - traceroute_launch 2>/dev/null -elif [ "$1" == "stop" ]; then - traceroute_stop 2>/dev/null +if [ "$1" = "run" ]; then + traceroute_launch +elif [ "$1" = "stop" ]; then + traceroute_stop else return fi diff --git a/scripts/udpecho_launch b/scripts/udpecho_launch index 784e012a..393d4941 100755 --- a/scripts/udpecho_launch +++ b/scripts/udpecho_launch @@ -1,22 +1,21 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api udpecho_launch() { - local i proto device res ba stc times sc1 success_count failure_count min_time avg_time max_time avg_time_sum min max micros - local host=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.Host` - local port=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.port` - local cnt=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.NumberOfRepetitions 1` - local dsize=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DataBlockSize 24` - local dscp=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DSCP 0` - local interface=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.interface` - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.ProtocolVersion Any` - local inter_time=`uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.InterTransmissionTime 1000` - [ ! -z "$interface" ] && device=`ifstatus $interface | jsonfilter -e @.device` && device="-e $device" || device="" - if [ "$protocol" == "IPv4" ]; then proto="-4"; elif [ "$protocol" == "IPv6" ]; then proto="-6"; else proto=""; fi - local tos=$((dscp<<2)) + host=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.Host) + port=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.port) + cnt=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.NumberOfRepetitions 1) + dsize=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DataBlockSize 24) + dscp=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.DSCP 0) + interface=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.interface) + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.ProtocolVersion Any) + inter_time=$(uci_get_bbf_dmmap dmmap_diagnostics.udpechodiag.InterTransmissionTime 1000) + [ -n "$interface" ] && device=$(ifstatus "$interface" | jsonfilter -e @.device) && device="-e $device" || device="" + if [ "$protocol" = "IPv4" ]; then proto="-4"; elif [ "$protocol" = "IPv6" ]; then proto="-6"; else proto=""; fi + tos=$((dscp<<2)) inter_time=$((inter_time/1000)) [ "$inter_time" = "0" ] && inter_time="1" [ "$host" = "" ] && return @@ -28,29 +27,29 @@ udpecho_launch() { max=0 i=0 - while [ $i -lt $cnt ]; do - let i++ - res=$(nping $proto -c 1 --tos $tos --udp --dest-port $port --data-length $dsize $device $host 2>&1) - ba=`echo "$res" | grep "RCVD"` + while [ $i -lt "$cnt" ]; do + i=$((i+1)) + res=$(nping "$proto" -c 1 --tos $tos --udp --dest-port "$port" --data-length "$dsize" "$device" "$host" 2>&1) + ba=$(echo "$res" | grep "RCVD") [ -z "$ba" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; return; } - stc=`echo "$res" | grep "RCVD" | grep "unreachable"` + stc=$(echo "$res" | grep "RCVD" | grep "unreachable") [ -n "$stc" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; return; } - times=`echo "$res" | grep "rtt"` + times=$(echo "$res" | grep "rtt") [ -z "$times" ] && continue - sc1=`echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }'` - [ $sc1 != 0 ] && sc1=1 || sc1=0 + sc1=$(echo "$res" | grep "Rcvd" | awk -F': ' '{print $3}' | awk -F'(' '{ print $1 }') + [ "$sc1" != 0 ] && sc1=1 || sc1=0 success_count=$((success_count+sc1)) - max_time=`echo $times | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }'` - min_time=`echo $times | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }'` - avg_time=`echo $times | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }'` + max_time=$(echo "$times" | awk -F': ' '{ print $2 }' | awk -F'ms' '{ print $1 }') + min_time=$(echo "$times" | awk -F': ' '{ print $3 }' | awk -F'ms' '{ print $1 }') + avg_time=$(echo "$times" | awk -F': ' '{ print $4 }' | awk -F'ms' '{ print $1 }') min_time=${min_time:-0} avg_time=${avg_time:-0} max_time=${max_time:-0} - min_time=$(echo $min_time $micros | awk '{printf "%3.0f\n",$1*$2}') - avg_time=$(echo $avg_time $micros | awk '{printf "%3.0f\n",$1*$2}') - max_time=$(echo $max_time $micros | awk '{printf "%3.0f\n",$1*$2}') - [ $min_time -lt $min ] && min=$min_time - [ $max_time -gt $max ] && max=$max_time + min_time=$(echo "$min_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + avg_time=$(echo "$avg_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + max_time=$(echo "$max_time" "$micros" | awk '{printf "%3.0f\n",$1*$2}') + [ "$min_time" -lt "$min" ] && min="$min_time" + [ "$max_time" -gt "$max" ] && max="$max_time" avg_time_sum=$((avg_time_sum+avg_time)) sleep $inter_time done @@ -59,26 +58,26 @@ udpecho_launch() { min_time=$min max_time=$max $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=Complete - $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount=$success_count - $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount=$failure_count - $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime=$avg_time - $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime=$min_time - $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime=$max_time + $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.SuccessCount="$success_count" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.FailureCount="$failure_count" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.AverageResponseTime="$avg_time" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MinimumResponseTime="$min_time" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.MaximumResponseTime="$max_time" $UCI_COMMIT_BBF_DMMAP } udpecho_stop_diagnostic() { - local pids=`ps | grep udpecho_launch | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f udpecho_launch) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.udpechodiag.DiagnosticState=None $UCI_COMMIT_BBF_DMMAP fi } -if [ "$1" == "run" ]; then +if [ "$1" = "run" ]; then udpecho_launch -elif [ "$1" == "stop" ]; then +elif [ "$1" = "stop" ]; then udpecho_stop_diagnostic else return diff --git a/scripts/upload_launch b/scripts/upload_launch index 0d2adb3f..7a5eae7a 100755 --- a/scripts/upload_launch +++ b/scripts/upload_launch @@ -1,96 +1,94 @@ #!/bin/sh -# Copyright (C) 2019 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # Author: IMEN Bhiri # Author: AMIN Ben Ramdhane -source /usr/share/bbfdm/bbf_uci_api +. /usr/share/bbfdm/bbf_uci_api CAPTURE_FILE="/tmp/upload_dump" UPLOAD_DIAGNOSTIC_FILE="/tmp/bbfdm_upload_diagnostic.bin" CONNECTION_TIMEOUT=60 upload_launch() { - local proto tx_bytes_before rx_bytes_before time1 tx_bytes_after rx_bytes_after time2 res ba stc periodtime - local url=$1 - local device=$2 - local size=$3 + url=$1 + device=$2 + size=$3 [ "$url" = "" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; return; } - local protocol=`uci_get_bbf_dmmap dmmap_diagnostics.upload.ProtocolVersion Any` - if [ "$protocol" == "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" == "IPv6" ]; then proto="--ipv6"; else proto=""; fi + protocol=$(uci_get_bbf_dmmap dmmap_diagnostics.upload.ProtocolVersion Any) + if [ "$protocol" = "IPv4" ]; then proto="--ipv4"; elif [ "$protocol" = "IPv6" ]; then proto="--ipv6"; else proto=""; fi # Disable acceleration on Broadcom devices to capture all packets with tcpdump [ -e /usr/sbin/fcctl ] && { fcctl disable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; } - tcpdump -i $device tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & + tcpdump -i "$device" tcp -w ${CAPTURE_FILE} > /dev/null 2>&1 & PID=$! sleep 1 - dd if=/dev/zero of=${UPLOAD_DIAGNOSTIC_FILE} bs=${size} count=1 2>/dev/null + dd if=/dev/zero of=${UPLOAD_DIAGNOSTIC_FILE} bs="$size" count=1 2>/dev/null if [ ${url:0:7} = http:// -o ${url:0:6} = ftp:// ]; then - tx_bytes_before=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes` - rx_bytes_before=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes` - time1=`date +%s` - curl $proto --fail --silent --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} $url + tx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes) + rx_bytes_before=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes) + time1=$(date +%s) + curl $proto --fail --silent --connect-timeout ${CONNECTION_TIMEOUT} -T ${UPLOAD_DIAGNOSTIC_FILE} "$url" error_code="$?" - time2=`date +%s` - tx_bytes_after=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes` - rx_bytes_after=`ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes` + time2=$(date +%s) + tx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.tx_bytes) + rx_bytes_after=$(ubus call network.device status "{'name':'$device'}" | jsonfilter -e @.statistics.rx_bytes) - [ "$error_code" == "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } - [ "$error_code" == "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } - [ "$error_code" == "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } - [ "$error_code" == "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } - [ "$error_code" == "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } - [ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; kill $PID &> /dev/null; return; } + [ "$error_code" = "6" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_CannotResolveHostName; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "7" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_InitConnectionFailed; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "22" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_NoResponse; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "27" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_IncorrectSize; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" = "28" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Timeout; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } + [ "$error_code" != "0" ] && { $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Error_Other; $UCI_COMMIT_BBF_DMMAP; kill $PID 2> /dev/null; return; } fi tx_bytes=$((tx_bytes_after-tx_bytes_before)) rx_bytes=$((rx_bytes_after-rx_bytes_before)) periodtime=$(($((time2-time1))*1000000)) $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=Complete - $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent=$size - $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived=$rx_bytes - $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent=$tx_bytes - $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading=$periodtime - local perconnection=`$UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection` - if ([ "$perconnection" == "true" ] || [ "$perconnection" == "1" ]); then + $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TestBytesSent="$size" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesReceived="$rx_bytes" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.TotalBytesSent="$tx_bytes" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.PeriodOfFullLoading="$periodtime" + perconnection=$($UCI_GET_BBF_DMMAP dmmap_diagnostics.upload.EnablePerConnection) + if [ "$perconnection" = "true" ] || [ "$perconnection" = "1" ]; then $UCI_ADD_BBF_DMMAP dmmap_diagnostics UploadPerConnection - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent=$size - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived=$rx_bytes - $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent=$tx_bytes + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TestBytesSent="$size" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesReceived="$rx_bytes" + $UCI_SET_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0].TotalBytesSent="$tx_bytes" else $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0] fi $UCI_COMMIT_BBF_DMMAP - rm ${UPLOAD_DIAGNOSTIC_FILE} &>/dev/null + rm ${UPLOAD_DIAGNOSTIC_FILE} >/dev/null 2>&1 sleep 3 - local pids=`ps | grep $PID` - kill $PID &>/dev/null + kill $PID >/dev/null 2>&1 # Enable acceleration on Broadcom devices after killing the tcpdump pid [ -e /usr/sbin/fcctl ] && { fcctl enable >/dev/null 2>&1; fcctl flush >/dev/null 2>&1; } } upload_stop_diagnostic() { $UCI_DELETE_BBF_DMMAP dmmap_diagnostics.@UploadPerConnection[0] - local pids=`ps | grep upload_launch.*run | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f upload_launch.*run) if [ -n "$pids" ]; then - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=None fi - local pids=`ps | grep upload_launch.*run | grep -v grep | awk '{print $1}'` + pids=$(pgrep -f upload_launch.*run) if [ -n "$pids" ]; then - kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*") - for kid in $kids; do - kill -9 $kid &>/dev/null + kids=$(grep -l "PPid.*$pids" /proc/*/task/*/status | grep -o "[0-9]*") + for kid in $kids; do + kill -9 "$kid" >/dev/null 2>&1 done - kill -9 $pids &>/dev/null + kill -9 "$pids" >/dev/null 2>&1 $UCI_SET_BBF_DMMAP dmmap_diagnostics.upload.DiagnosticState=None fi $UCI_COMMIT_BBF_DMMAP } -if [ "$1" == "run" ] ; then - upload_launch $2 $3 $4 -elif [ "$1" == "stop" ]; then +if [ "$1" = "run" ] ; then + upload_launch "$2" "$3" "$4" +elif [ "$1" = "stop" ]; then upload_stop_diagnostic else return diff --git a/test/bbf_test/bbf_dm.c b/test/bbf_test/bbf_dm.c index 81f428fd..1eaab174 100644 --- a/test/bbf_test/bbf_dm.c +++ b/test/bbf_test/bbf_dm.c @@ -7,6 +7,7 @@ #ifndef CMD_GET_INFO #define CMD_GET_INFO (CMD_EXTERNAL_COMMAND + 1) #endif +static struct ubus_context *ubus_ctx = NULL; static int g_proto = BBFDM_USP; typedef struct { @@ -34,7 +35,7 @@ int get_cmd_from_str(char *str) int i, cmd = CMD_GET_VALUE; for (i = 0; i < ARRAY_SIZE(CMD); i++) { - if (strcmp(CMD[i].str, str) == 0) { + if (DM_STRCMP(CMD[i].str, str) == 0) { cmd = CMD[i].id; break; } @@ -68,8 +69,8 @@ int usp_dm_exec(int cmd, char *path, char *arg1, char *arg2) 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)); + if (cmd == CMD_GET_INFO) { + fault = dm_get_supported_dm(&bbf_ctx, path, false, DM_STRTOL(arg1)); } else { fault = dm_entry_param_method(&bbf_ctx, cmd, path, arg1, arg2); } @@ -90,7 +91,6 @@ 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 = "", *value = "", *version = ""; int cmd; @@ -106,18 +106,18 @@ int main(int argc, char *argv[]) dm_config_ubus(ubus_ctx); - if (strcmp(argv[1], "-c") == 0) + if (DM_STRCMP(argv[1], "-c") == 0) g_proto = BBFDM_CWMP; cmd = get_cmd_from_str(argv[2]); - if (argc > 3 && strlen(argv[3])) + if (argc > 3 && DM_STRLEN(argv[3])) param = argv[3]; - if (argc > 4 && strlen(argv[4])) + if (argc > 4 && DM_STRLEN(argv[4])) value = argv[4]; - if (argc > 5 && strlen(argv[5])) + if (argc > 5 && DM_STRLEN(argv[5])) version = argv[5]; usp_dm_exec(cmd, param, value, version); diff --git a/test/bbf_test/libbbf_test.c b/test/bbf_test/libbbf_test.c index a93a7ca0..331fccd2 100644 --- a/test/bbf_test/libbbf_test.c +++ b/test/bbf_test/libbbf_test.c @@ -296,7 +296,7 @@ static int operate_DeviceXIOPSYSEUPingTEST_Run(char *refparam, struct dmctx *ctx char line[512] = {0}; while (fgets(line, sizeof(line), log) != NULL) { - if (strstr(line, "rtt")) { + if (DM_STRSTR(line, "rtt")) { strtok_r(line, "=", &min); strtok_r(min ? min+1 : "", "/", &avg); add_list_parameter(ctx, dmstrdup("MinimumResponseTime"), dmstrdup(min ? min+1 : ""), "xsd:unsignedInt", NULL); diff --git a/test/cmocka/functional_api_test_bbfd.c b/test/cmocka/functional_api_test_bbfd.c index da5d6d55..7545ae4c 100644 --- a/test/cmocka/functional_api_test_bbfd.c +++ b/test/cmocka/functional_api_test_bbfd.c @@ -1016,7 +1016,7 @@ static void test_bbf_api_common(void **state) */ // hex_to_ip: test - hex_to_ip("0000FEA9", buf); + hex_to_ip("0000FEA9", buf, sizeof(buf)); assert_string_equal(buf, "169.254.0.0"); } diff --git a/test/cmocka/functional_test_bbfd.c b/test/cmocka/functional_test_bbfd.c index 0b779240..9c459e71 100644 --- a/test/cmocka/functional_test_bbfd.c +++ b/test/cmocka/functional_test_bbfd.c @@ -1176,9 +1176,9 @@ static void test_api_bbfdm_valid_standard_operate(void **state) assert_int_equal(fault, CMD_SUCCESS); list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "SuccessCount") == 0) { + if (DM_STRCMP(n->name, "SuccessCount") == 0) { assert_string_equal(n->data, "1"); - } else if (strcmp(n->name, "FailureCount") == 0) { + } else if (DM_STRCMP(n->name, "FailureCount") == 0) { assert_string_equal(n->data, "0"); } else { assert_string_not_equal(n->data, "0"); @@ -1198,13 +1198,13 @@ static void test_api_bbfdm_valid_standard_list_operate(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.FactoryReset()") == 0) { + if (DM_STRCMP(n->name, "Device.FactoryReset()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "sync"); assert_null(n->data); } - if (strcmp(n->name, "Device.DeviceInfo.VendorLogFile.{i}.Upload()") == 0) { + if (DM_STRCMP(n->name, "Device.DeviceInfo.VendorLogFile.{i}.Upload()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "async"); operation_args *args = (operation_args *)n->data; @@ -1230,7 +1230,7 @@ static void test_api_bbfdm_valid_standard_list_operate(void **state) assert_int_equal(i, 3); } - if (strcmp(n->name, "Device.WiFi.NeighboringWiFiDiagnostic()") == 0) { + if (DM_STRCMP(n->name, "Device.WiFi.NeighboringWiFiDiagnostic()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "async"); operation_args *args = (operation_args *)n->data; @@ -1284,13 +1284,13 @@ static void test_api_bbfdm_valid_library_list_operate(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.X_IOPSYS_EU_Reboot()") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Reboot()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "sync"); assert_null(n->data); } - if (strcmp(n->name, "Device.X_IOPSYS_EU_PingTEST.Run()") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_PingTEST.Run()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "async"); operation_args *args = (operation_args *)n->data; @@ -1354,7 +1354,7 @@ static void test_api_bbfdm_valid_json_list_operate(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Status()") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Status()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "async"); operation_args *args = (operation_args *)n->data; @@ -1412,7 +1412,7 @@ static void test_api_bbfdm_valid_json_v1_list_operate(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Status()") == 0) { + if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Status()") == 0) { assert_string_equal(n->type, "xsd:command"); assert_string_equal(n->additional_data, "async"); operation_args *args = (operation_args *)n->data; @@ -1460,12 +1460,12 @@ static void test_api_bbfdm_valid_library_event(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.X_IOPSYS_EU_WakeUp!") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_WakeUp!") == 0) { assert_string_equal(n->type, "xsd:event"); assert_null(n->data); } - if (strcmp(n->name, "Device.X_IOPSYS_EU_Boot!") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_Boot!") == 0) { assert_string_equal(n->type, "xsd:event"); event_args *args = (event_args *)n->data; assert_non_null(args); @@ -1506,12 +1506,12 @@ static void test_api_bbfdm_valid_json_event(void **state) list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Periodic!") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Periodic!") == 0) { assert_string_equal(n->type, "xsd:event"); assert_null(n->data); } - if (strcmp(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Push!") == 0) { + if (DM_STRCMP(n->name, "Device.X_IOPSYS_EU_TEST.{i}.Push!") == 0) { assert_string_equal(n->type, "xsd:event"); event_args *args = (event_args *)n->data; assert_non_null(args); @@ -1545,12 +1545,12 @@ static void test_api_bbfdm_valid_json_v1_event(void **state) assert_int_equal(fault, 0); list_for_each_entry(n, &ctx->list_parameter, list) { - if (strcmp(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Periodic!") == 0) { + if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Periodic!") == 0) { assert_string_equal(n->type, "xsd:event"); assert_null(n->data); } - if (strcmp(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Push!") == 0) { + if (DM_STRCMP(n->name, "Device.UBUS_TEST_V1.Interface.{i}.Push!") == 0) { assert_string_equal(n->type, "xsd:event"); event_args *args = (event_args *)n->data; assert_non_null(args); diff --git a/test/files/usr/libexec/rpcd/ethernet b/test/files/usr/libexec/rpcd/ethernet index 68f0bcbf..bf78d405 100755 --- a/test/files/usr/libexec/rpcd/ethernet +++ b/test/files/usr/libexec/rpcd/ethernet @@ -12,13 +12,13 @@ case "$1" in read input; json_load "$input" json_get_var ifname ifname - if [ "$ifname" == "eth1" ]; then + if [ "$ifname" = "eth1" ]; then cat /tmp/rmonstats_eth1.data 2>/dev/null - elif [ "$ifname" == "eth2" ]; then + elif [ "$ifname" = "eth2" ]; then cat /tmp/rmonstats_eth2.data 2>/dev/null - elif [ "$ifname" == "eth3" ]; then + elif [ "$ifname" = "eth3" ]; then cat /tmp/rmonstats_eth3.data 2>/dev/null - elif [ "$ifname" == "eth4" ]; then + elif [ "$ifname" = "eth4" ]; then cat /tmp/rmonstats_eth4.data 2>/dev/null else cat /tmp/rmonstats_eth0.data 2>/dev/null diff --git a/test/files/usr/libexec/rpcd/network.interface b/test/files/usr/libexec/rpcd/network.interface index 1e9dc6db..725f68b2 100755 --- a/test/files/usr/libexec/rpcd/network.interface +++ b/test/files/usr/libexec/rpcd/network.interface @@ -12,11 +12,11 @@ case "$1" in read input; json_load "$input" json_get_var interface interface - if [ "$interface" == "lan" ]; then + if [ "$interface" = "lan" ]; then cat /tmp/interface_lan.data 2>/dev/null - elif [ "$interface" == "wan" ]; then + elif [ "$interface" = "wan" ]; then cat /tmp/interface_wan.data 2>/dev/null - elif [ "$interface" == "wan6" ]; then + elif [ "$interface" = "wan6" ]; then cat /tmp/interface_wan6.data 2>/dev/null else cat /tmp/interface_lan.data 2>/dev/null diff --git a/test/files/usr/libexec/rpcd/proxd b/test/files/usr/libexec/rpcd/proxd index c0aa8aa2..a84532fc 100755 --- a/test/files/usr/libexec/rpcd/proxd +++ b/test/files/usr/libexec/rpcd/proxd @@ -12,13 +12,13 @@ case "$1" in cat /tmp/proxd.data 2>/dev/null ;; get) - read input; - json_load "$input" - json_get_var path path - json_init - json_add_string "Description" "$path" - json_dump >/dev/console - json_dump + read input; + json_load "$input" + json_get_var path path + json_init + json_add_string "Description" "$path" + json_dump >/dev/console + json_dump ;; esac ;;