diff --git a/include/common/system.h b/include/common/system.h index 0404664..e3b923a 100644 --- a/include/common/system.h +++ b/include/common/system.h @@ -10,5 +10,6 @@ void create_folder(const char *folder); uint8_t is_file_exist(const char *file); void save_file(const char *file, const char *content); void save_string_list(const char *file, char **string_list); +void file_append(const char *base_file, const char *append_file); #endif diff --git a/src/common/system.c b/src/common/system.c index aa318ef..8799993 100644 --- a/src/common/system.c +++ b/src/common/system.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "logger.h" #include "sundry.h" #include "constant.h" @@ -58,6 +59,13 @@ void save_file(const char *file, const char *content) { // save content into fil log_debug("Save `%s` success", file); } +void file_append(const char *base_file, const char *append_file) { // append_file >> base_file + char *append_cmd = (char *)malloc(strlen(base_file) + strlen(append_file) + 9); + sprintf(append_cmd, "cat %s >> %s", append_file, base_file); + run_command(append_cmd); + free(append_cmd); +} + char* read_file(const char *file) { // read file content log_debug("Read file -> %s", file); FILE *fp = fopen(file, "rb"); diff --git a/src/loader/default.c b/src/loader/default.c index 2815373..8f407f3 100644 --- a/src/loader/default.c +++ b/src/loader/default.c @@ -1,8 +1,8 @@ #include #include "json.h" #include "logger.h" -#include "system.h" #include "sundry.h" +#include "system.h" #define DEFAULT_CONFIG "\ port: 53\n\ diff --git a/src/loader/loader.c b/src/loader/loader.c index 49b45c5..6d5c0e2 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -1,21 +1,29 @@ +#include #include #include "config.h" #include "loader.h" #include "parser.h" #include "sundry.h" #include "system.h" +#include "default.h" #include "dnsproxy.h" #include "constant.h" #include "structure.h" -#include "default.h" -#include "logger.h" struct cleardns loader; +void load_diverter_asset(const char *file) { + char *src_file = string_join(ASSETS_DIR, file); + char *dst_file = string_join(WORK_DIR, file); + file_append(dst_file, src_file); + free(dst_file); + free(src_file); +} + void load_diverter_assets() { - // ${ASSETS_DIR}${ASSET_GFW_LIST} >> ${WORK_DIR}${ASSET_GFW_LIST} - // ${ASSETS_DIR}${ASSET_CHINA_IP} >> ${WORK_DIR}${ASSET_CHINA_IP} - // ${ASSETS_DIR}${ASSET_CHINA_LIST} >> ${WORK_DIR}${ASSET_CHINA_LIST} + load_diverter_asset(ASSET_CHINA_IP); + load_diverter_asset(ASSET_GFW_LIST); + load_diverter_asset(ASSET_CHINA_LIST); } dnsproxy* load_domestic(cleardns_config *config) { @@ -106,9 +114,7 @@ adguard* load_filter(cleardns_config *config) { void load_config(const char *config_file) { cleardns_config *config = config_init(); - load_default_config(config_file); - config_parser(config, config_file); config_dump(config);