diff --git a/include/common/structure.h b/include/common/structure.h index 1268381..b74add1 100644 --- a/include/common/structure.h +++ b/include/common/structure.h @@ -16,7 +16,9 @@ uint32_t** uint32_list_init(); char* uint32_list_dump(uint32_t **int_list); void uint32_list_free(uint32_t **uint32_list); uint32_t uint32_list_len(uint32_t **int_list); -uint32_t** uint32_list_append(uint32_t **int_list, uint32_t number); -uint32_t** uint32_list_update(uint32_t **base_list, uint32_t **update_list); +void uint32_list_append(uint32_t ***uint32_list, uint32_t number); +//uint32_t** uint32_list_append(uint32_t **int_list, uint32_t number); +void uint32_list_update(uint32_t ***base_list, uint32_t **update_list); +//uint32_t** uint32_list_update(uint32_t **base_list, uint32_t **update_list); #endif diff --git a/src/cleardns.c b/src/cleardns.c index 772baec..271e6c1 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -46,27 +46,50 @@ int main(int argc, char *argv[]) { // ClearDNS service LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); - char **test = string_list_init(); - log_info("len -> %u", string_list_len(test)); - string_list_append(&test, "test1"); - string_list_append(&test, "test2"); - string_list_append(&test, "test3"); - log_info("len -> %u", string_list_len(test)); - - char *temp = string_list_dump(test); +// char **test = string_list_init(); +// log_info("len -> %u", string_list_len(test)); +// string_list_append(&test, "test1"); +// string_list_append(&test, "test2"); +// string_list_append(&test, "test3"); +// log_info("len -> %u", string_list_len(test)); +// +// char *temp = string_list_dump(test); +// log_info("content -> %s", temp); +// free(temp); +// +// char **add = string_list_init(); +// string_list_append(&add, "test4"); +// string_list_append(&add, "test5"); +// +// string_list_update(&test, add); +// log_info("len -> %d", string_list_len(test)); +// temp = string_list_dump(test); +// log_info("content -> %s", temp); +// free(temp); + + + uint32_t **test = uint32_list_init(); + log_info("len -> %u", uint32_list_len(test)); + uint32_list_append(&test, 1); + uint32_list_append(&test, 2); + uint32_list_append(&test, 3); + log_info("len -> %u", uint32_list_len(test)); + + char *temp = uint32_list_dump(test); log_info("content -> %s", temp); free(temp); - char **add = string_list_init(); - string_list_append(&add, "test4"); - string_list_append(&add, "test5"); + uint32_t **add = uint32_list_init(); + uint32_list_append(&add, 4); + uint32_list_append(&add, 5); - string_list_update(&test, add); - log_info("len -> %d", string_list_len(test)); - temp = string_list_dump(test); + uint32_list_update(&test, add); + log_info("len -> %d", uint32_list_len(test)); + temp = uint32_list_dump(test); log_info("content -> %s", temp); free(temp); + // process *test = process_init("TEST", "lls"); // process *test = process_init("TEST", "ls"); // process_add_arg(test, "-al"); diff --git a/src/common/json.c b/src/common/json.c index faccd76..56742c2 100644 --- a/src/common/json.c +++ b/src/common/json.c @@ -110,14 +110,14 @@ char** json_string_list_value(char *key, cJSON *json, char **string_list) { // j uint32_t** json_uint32_list_value(char *key, cJSON *json, uint32_t **uint32_list) { // json uint32 array -> uint32 list if (cJSON_IsNumber(json)) { - uint32_list = uint32_list_append(uint32_list, json->valueint); + uint32_list_append(&uint32_list, json->valueint); } else if (cJSON_IsArray(json)) { json = json->child; while (json != NULL) { if (!cJSON_IsNumber(json)) { log_fatal("`%s` must be number array", key); } - uint32_list = uint32_list_append(uint32_list, json->valueint); + uint32_list_append(&uint32_list, json->valueint); json = json->next; // next key } } else if (!cJSON_IsNull(json)) { // allow null -> empty uint32 list diff --git a/src/common/structure.c b/src/common/structure.c index d0bf9b2..1251091 100644 --- a/src/common/structure.c +++ b/src/common/structure.c @@ -84,20 +84,20 @@ uint32_t uint32_list_len(uint32_t **uint32_list) { // get len of uint32 list return num - 1; } -uint32_t** uint32_list_append(uint32_t **uint32_list, uint32_t number) { // add new uint32 at the end of list - uint32_t len = uint32_list_len(uint32_list); - uint32_list = (uint32_t **)realloc(uint32_list, sizeof(uint32_t *) * (len + 2)); - uint32_list[len] = (uint32_t *)malloc(sizeof(uint32_t)); - *uint32_list[len] = number; - uint32_list[len + 1] = NULL; // list end sign - return uint32_list; +void uint32_list_append(uint32_t ***uint32_list, uint32_t number) { // add new uint32 at the end of list + uint32_t len = uint32_list_len(*uint32_list); + *uint32_list = (uint32_t **)realloc(*uint32_list, sizeof(uint32_t *) * (len + 2)); + (*uint32_list)[len] = (uint32_t *)malloc(sizeof(uint32_t)); + *(*uint32_list)[len] = number; + (*uint32_list)[len + 1] = NULL; // list end sign +// return uint32_list; } -uint32_t** uint32_list_update(uint32_t **base_list, uint32_t **update_list) { // combine two uint32 list +void uint32_list_update(uint32_t ***base_list, uint32_t **update_list) { // combine two uint32 list for (uint32_t **number = update_list; *number != NULL; ++number) { - base_list = uint32_list_append(base_list, **number); + uint32_list_append(base_list, **number); } - return base_list; +// return base_list; } void uint32_list_free(uint32_t **uint32_list) { // free uint32 list diff --git a/src/loader/loader.c b/src/loader/loader.c index 1c3ae82..64b5313 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -93,7 +93,7 @@ overture* load_diverter(cleardns_config *config) { free(china_ip); free(gfwlist); - diverter->reject_type = uint32_list_update(diverter->reject_type, config->reject); + uint32_list_update(&diverter->reject_type, config->reject); load_diverter_assets(); return diverter; }