From 657d443094683febd6f880136921765e5f4ed9cf Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Mon, 12 Sep 2022 16:01:57 +0800 Subject: [PATCH] fix: variable type --- src/dnsproxy.c | 18 +++++++++--------- src/overture.c | 25 ++++++++++++------------- src/utils/structure.c | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/dnsproxy.c b/src/dnsproxy.c index f5fa043..af6184e 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -6,7 +6,7 @@ #include "common.h" #include "cJSON.h" -char* dnsproxy_gen_config(dnsproxy *info); +char* dnsproxy_config(dnsproxy *info); void dnsproxy_dump(const char *caption, dnsproxy *info); void dnsproxy_add_primary(dnsproxy *info, const char *server) { // add primary dns server @@ -22,7 +22,7 @@ void dnsproxy_add_bootstrap(dnsproxy *info, const char *server) { // add bootstr } dnsproxy* dnsproxy_init(uint16_t port) { // init dnsproxy options - dnsproxy *info = (dnsproxy*)malloc(sizeof(dnsproxy)); + dnsproxy *info = (dnsproxy *)malloc(sizeof(dnsproxy)); info->port = port; info->cache = 0; // disable cache in default info->debug = FALSE; @@ -37,8 +37,8 @@ dnsproxy* dnsproxy_init(uint16_t port) { // init dnsproxy options void dnsproxy_dump(const char *caption, dnsproxy *info) { // show dnsproxy info in debug log char *str_dump; - log_debug("%s port -> %d", caption, info->port); - log_debug("%s cache -> %d", caption, info->cache); + log_debug("%s port -> %u", caption, info->port); + log_debug("%s cache -> %u", caption, info->cache); log_debug("%s debug -> %s", caption, show_bool(info->debug)); log_debug("%s verify -> %s", caption, show_bool(info->verify)); log_debug("%s parallel -> %s", caption, show_bool(info->parallel)); @@ -49,24 +49,24 @@ void dnsproxy_dump(const char *caption, dnsproxy *info) { // show dnsproxy info free(str_dump); str_dump = string_list_dump(info->fallback); - log_debug("%s fallback -> %s", caption, string_list_dump(info->fallback)); + log_debug("%s fallback -> %s", caption, str_dump); free(str_dump); str_dump = string_list_dump(info->primary); - log_debug("%s primary -> %s", caption, string_list_dump(info->primary)); + log_debug("%s primary -> %s", caption, str_dump); free(str_dump); } process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { dnsproxy_dump(caption, info); - char *config = dnsproxy_gen_config(info); // string config (JSON format) + char *config = dnsproxy_config(info); // string config (JSON format) char *config_file = string_join(WORK_DIR, file); save_file(config_file, config); free(config_file); free(config); char *option = string_join("--config-path=", file); - process *p = (process*)malloc(sizeof(process)); + process *p = (process *)malloc(sizeof(process)); p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN); p->cmd = string_list_append(p->cmd, option); if (info->debug) { @@ -78,7 +78,7 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { return p; } -char* dnsproxy_gen_config(dnsproxy *info) { // generate json configure from dnsproxy options +char* dnsproxy_config(dnsproxy *info) { // generate json configure from dnsproxy options cJSON *config = cJSON_CreateObject(); if (!info->verify) { cJSON_AddTrueToObject(config, "insecure"); // insecure --(default)--> `false` diff --git a/src/overture.c b/src/overture.c index 0ab981f..d361ebe 100644 --- a/src/overture.c +++ b/src/overture.c @@ -8,7 +8,7 @@ #include "structure.h" void overture_dump(overture *info); -char* overture_gen_config(overture *info); +char* overture_config(overture *info); overture* overture_init(uint16_t port) { // init overture options overture *info = (overture*)malloc(sizeof(overture)); @@ -29,13 +29,13 @@ overture* overture_init(uint16_t port) { // init overture options void overture_dump(overture *info) { // show overture info in debug log char *reject_type = uint32_list_dump(info->reject_type); - log_debug("Overture port -> %d", info->port); + log_debug("Overture port -> %u", info->port); log_debug("Overture debug -> %s", show_bool(info->debug)); - log_debug("Overture timeout -> %d", info->timeout); + log_debug("Overture timeout -> %u", info->timeout); log_debug("Overture ttl file -> %s", info->ttl_file); log_debug("Overture host file -> %s", info->host_file); - log_debug("Overture foreign port -> %d", info->foreign_port); - log_debug("Overture domestic port -> %d", info->domestic_port); + log_debug("Overture foreign port -> %u", info->foreign_port); + log_debug("Overture domestic port -> %u", info->domestic_port); log_debug("Overture reject type -> %s", reject_type); log_debug("Overture foreign ip file -> %s", info->foreign_ip_file); log_debug("Overture domestic ip file -> %s", info->domestic_ip_file); @@ -46,16 +46,15 @@ void overture_dump(overture *info) { // show overture info in debug log process* overture_load(overture *info, const char *file) { overture_dump(info); - char *config = overture_gen_config(info); // string config (JSON format) + char *config = overture_config(info); // string config (JSON format) char *config_file = string_join(WORK_DIR, file); save_file(config_file, config); free(config_file); free(config); - process *p = (process*)malloc(sizeof(process)); + process *p = (process *)malloc(sizeof(process)); p->cmd = string_list_append(string_list_init(), OVERTURE_BIN); - p->cmd = string_list_append(p->cmd, "-c"); - p->cmd = string_list_append(p->cmd, file); + p->cmd = string_list_append(string_list_append(p->cmd, "-c"), file); if (info->debug) { p->cmd = string_list_append(p->cmd, "-v"); // overture enable debug mode } @@ -64,14 +63,14 @@ process* overture_load(overture *info, const char *file) { return p; } -char* overture_gen_config(overture *info) { // generate json configure from overture options +char* overture_config(overture *info) { // generate json configure from overture options cJSON *config = cJSON_CreateObject(); char port_str[12]; // 32-bits (MAX_LEN -> -2147483648 -> 12-bytes) - sprintf(port_str, "%d", info->port); + sprintf(port_str, "%u", info->port); char *bind_addr = string_join(":", port_str); - sprintf(port_str, "%d", info->foreign_port); + sprintf(port_str, "%u", info->foreign_port); char *foreign_addr = string_join("127.0.0.1:", port_str); - sprintf(port_str, "%d", info->domestic_port); + sprintf(port_str, "%u", info->domestic_port); char *domestic_port = string_join("127.0.0.1:", port_str); cJSON_AddStringToObject(config, "bindAddress", bind_addr); diff --git a/src/utils/structure.c b/src/utils/structure.c index 352c809..8c7d0c6 100644 --- a/src/utils/structure.c +++ b/src/utils/structure.c @@ -94,7 +94,7 @@ char* uint32_list_dump(uint32_t **uint32_list) { // [1, 2, 3, ...] char *string_ret = (char *)malloc(2); strcpy(string_ret, "["); for (uint32_t **number = uint32_list; *number != NULL; ++number) { - sprintf(uint32_str, "%d", **number); + sprintf(uint32_str, "%u", **number); string_ret = (char*)realloc(string_ret, strlen(string_ret) + 15); string_ret = strcat(strcat(string_ret, uint32_str), ", "); }