Browse Source

update: interface of uint32 list

dev
Dnomd343 2 years ago
parent
commit
051206acec
  1. 6
      include/common/structure.h
  2. 51
      src/cleardns.c
  3. 4
      src/common/json.c
  4. 20
      src/common/structure.c
  5. 2
      src/loader/loader.c

6
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

51
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");

4
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

20
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

2
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;
}

Loading…
Cancel
Save