Browse Source

fix: variable type

dev
dnomd343 2 years ago
parent
commit
657d443094
  1. 18
      src/dnsproxy.c
  2. 25
      src/overture.c
  3. 2
      src/utils/structure.c

18
src/dnsproxy.c

@ -6,7 +6,7 @@
#include "common.h" #include "common.h"
#include "cJSON.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_dump(const char *caption, dnsproxy *info);
void dnsproxy_add_primary(dnsproxy *info, const char *server) { // add primary dns server 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* dnsproxy_init(uint16_t port) { // init dnsproxy options
dnsproxy *info = (dnsproxy*)malloc(sizeof(dnsproxy)); dnsproxy *info = (dnsproxy *)malloc(sizeof(dnsproxy));
info->port = port; info->port = port;
info->cache = 0; // disable cache in default info->cache = 0; // disable cache in default
info->debug = FALSE; 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 void dnsproxy_dump(const char *caption, dnsproxy *info) { // show dnsproxy info in debug log
char *str_dump; char *str_dump;
log_debug("%s port -> %d", caption, info->port); log_debug("%s port -> %u", caption, info->port);
log_debug("%s cache -> %d", caption, info->cache); log_debug("%s cache -> %u", caption, info->cache);
log_debug("%s debug -> %s", caption, show_bool(info->debug)); log_debug("%s debug -> %s", caption, show_bool(info->debug));
log_debug("%s verify -> %s", caption, show_bool(info->verify)); log_debug("%s verify -> %s", caption, show_bool(info->verify));
log_debug("%s parallel -> %s", caption, show_bool(info->parallel)); 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); free(str_dump);
str_dump = string_list_dump(info->fallback); 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); free(str_dump);
str_dump = string_list_dump(info->primary); 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); free(str_dump);
} }
process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) {
dnsproxy_dump(caption, info); 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); char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config); save_file(config_file, config);
free(config_file); free(config_file);
free(config); free(config);
char *option = string_join("--config-path=", file); 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(string_list_init(), DNSPROXY_BIN);
p->cmd = string_list_append(p->cmd, option); p->cmd = string_list_append(p->cmd, option);
if (info->debug) { if (info->debug) {
@ -78,7 +78,7 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) {
return p; 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(); cJSON *config = cJSON_CreateObject();
if (!info->verify) { if (!info->verify) {
cJSON_AddTrueToObject(config, "insecure"); // insecure --(default)--> `false` cJSON_AddTrueToObject(config, "insecure"); // insecure --(default)--> `false`

25
src/overture.c

@ -8,7 +8,7 @@
#include "structure.h" #include "structure.h"
void overture_dump(overture *info); 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* overture_init(uint16_t port) { // init overture options
overture *info = (overture*)malloc(sizeof(overture)); 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 void overture_dump(overture *info) { // show overture info in debug log
char *reject_type = uint32_list_dump(info->reject_type); 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 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 ttl file -> %s", info->ttl_file);
log_debug("Overture host file -> %s", info->host_file); log_debug("Overture host file -> %s", info->host_file);
log_debug("Overture foreign port -> %d", info->foreign_port); log_debug("Overture foreign port -> %u", info->foreign_port);
log_debug("Overture domestic port -> %d", info->domestic_port); log_debug("Overture domestic port -> %u", info->domestic_port);
log_debug("Overture reject type -> %s", reject_type); log_debug("Overture reject type -> %s", reject_type);
log_debug("Overture foreign ip file -> %s", info->foreign_ip_file); log_debug("Overture foreign ip file -> %s", info->foreign_ip_file);
log_debug("Overture domestic ip file -> %s", info->domestic_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) { process* overture_load(overture *info, const char *file) {
overture_dump(info); 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); char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config); save_file(config_file, config);
free(config_file); free(config_file);
free(config); 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(string_list_init(), OVERTURE_BIN);
p->cmd = string_list_append(p->cmd, "-c"); p->cmd = string_list_append(string_list_append(p->cmd, "-c"), file);
p->cmd = string_list_append(p->cmd, file);
if (info->debug) { if (info->debug) {
p->cmd = string_list_append(p->cmd, "-v"); // overture enable debug mode 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; 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(); cJSON *config = cJSON_CreateObject();
char port_str[12]; // 32-bits (MAX_LEN -> -2147483648 -> 12-bytes) 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); 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); 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); char *domestic_port = string_join("127.0.0.1:", port_str);
cJSON_AddStringToObject(config, "bindAddress", bind_addr); cJSON_AddStringToObject(config, "bindAddress", bind_addr);

2
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); char *string_ret = (char *)malloc(2);
strcpy(string_ret, "["); strcpy(string_ret, "[");
for (uint32_t **number = uint32_list; *number != NULL; ++number) { 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 = (char*)realloc(string_ret, strlen(string_ret) + 15);
string_ret = strcat(strcat(string_ret, uint32_str), ", "); string_ret = strcat(strcat(string_ret, uint32_str), ", ");
} }

Loading…
Cancel
Save