Browse Source

update: free config struct

dev
dnomd343 2 years ago
parent
commit
6d44039993
  1. 2
      src/loader/CMakeLists.txt
  2. 32
      src/loader/config.c
  3. 5
      src/loader/loader.c

2
src/loader/CMakeLists.txt

@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
add_library(loader config.c parser.c) add_library(loader config.c loader.c parser.c)

32
src/loader/config.c

@ -3,7 +3,7 @@
#include "logger.h" #include "logger.h"
#include "structure.h" #include "structure.h"
cleardns_config* config_init() { cleardns_config* config_init() { // init config struct of cleardns
cleardns_config *config = (cleardns_config *)malloc(sizeof(cleardns_config)); cleardns_config *config = (cleardns_config *)malloc(sizeof(cleardns_config));
config->port = DNS_PORT; config->port = DNS_PORT;
config->cache.size = 0; config->cache.size = 0;
@ -31,8 +31,8 @@ cleardns_config* config_init() {
config->adguard.port = ADGUARD_PORT; config->adguard.port = ADGUARD_PORT;
config->adguard.enable = TRUE; config->adguard.enable = TRUE;
config->adguard.username = ADGUARD_USER; config->adguard.username = string_init(ADGUARD_USER);
config->adguard.password = ADGUARD_PASSWD; config->adguard.password = string_init(ADGUARD_PASSWD);
config->reject = uint32_list_init(); config->reject = uint32_list_init();
config->hosts = string_list_init(); config->hosts = string_list_init();
@ -40,7 +40,7 @@ cleardns_config* config_init() {
return config; return config;
} }
void config_dump(cleardns_config *config) { void config_dump(cleardns_config *config) { // dump config info of cleardns
log_debug("DNS port -> %u", config->port); log_debug("DNS port -> %u", config->port);
log_debug("Cache size -> %u", config->cache.size); log_debug("Cache size -> %u", config->cache.size);
log_debug("Cache enable -> %s", show_bool(config->cache.enable)); log_debug("Cache enable -> %s", show_bool(config->cache.enable));
@ -75,6 +75,27 @@ void config_dump(cleardns_config *config) {
string_list_debug("Hosts", config->hosts); string_list_debug("Hosts", config->hosts);
} }
void config_free(cleardns_config *config) { // free config struct of cleardns
string_list_free(config->domestic.bootstrap);
string_list_free(config->domestic.fallback);
string_list_free(config->domestic.primary);
string_list_free(config->foreign.bootstrap);
string_list_free(config->foreign.fallback);
string_list_free(config->foreign.primary);
string_list_free(config->diverter.gfwlist);
string_list_free(config->diverter.china_ip);
string_list_free(config->diverter.chinalist);
uint32_list_free(config->reject);
string_list_free(config->hosts);
string_list_free(config->ttl);
free(config->adguard.username);
free(config->adguard.password);
free(config);
}
void load_config(const char *config_file) { void load_config(const char *config_file) {
cleardns_config *config = config_init(); cleardns_config *config = config_init();
@ -85,6 +106,5 @@ void load_config(const char *config_file) {
// TODO: load into process // TODO: load into process
// TODO: free config struct config_free(config);
} }

5
src/loader/loader.c

@ -0,0 +1,5 @@
#include "loader.h"
void load_dnsproxy() {
}
Loading…
Cancel
Save