diff --git a/include/utils/assets.h b/include/utils/assets.h index d1814d7..5690bba 100644 --- a/include/utils/assets.h +++ b/include/utils/assets.h @@ -1,6 +1,6 @@ #ifndef ASSETS_H_ #define ASSETS_H_ -void load_assets(); +void extract_assets(); #endif diff --git a/src/applet/adguard.c b/src/applet/adguard.c index 3b7aeb6..4fc1433 100644 --- a/src/applet/adguard.c +++ b/src/applet/adguard.c @@ -87,6 +87,9 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options create_folder(dir); // ensure adguard work dir exist char *adguard_config_ret; char *adguard_config_file = string_join(dir, "AdGuardHome.yaml"); + + // TODO: skip to-json if AdGuardHome configure not exist + char *adguard_config_raw = to_json(adguard_config_file); if (adguard_config_raw == NULL) { // configure not exist log_info("Create AdGuardHome configure"); diff --git a/src/cleardns.c b/src/cleardns.c index b07818b..74d9c15 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -11,6 +11,7 @@ #include "system.h" #include "sundry.h" #include "structure.h" +#include "assets.h" char* init(int argc, char *argv[]) { // return config file char *config = string_init(CONFIG_FILE); @@ -61,18 +62,29 @@ int main(int argc, char *argv[]) { // ClearDNS service create_folder(WORK_DIR); // TODO: load assets first + extract_assets(); load_config(config_file); free(config_file); -// process_list_init(); -// process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json")); -// process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json")); -// process_list_append(overture_load(loader.diverter, "overture.json")); -// if (loader.filter != NULL) { -// process_list_append(adguard_load(loader.filter, ADGUARD_DIR)); -// } + if (LOG_LEVEL == LOG_DEBUG) { // debug mode enabled + loader.filter->debug = TRUE; + loader.diverter->debug = TRUE; + loader.domestic->debug = TRUE; + loader.foreign->debug = TRUE; + } + process_list_init(); + // TODO: crontab of assets + process_list_append(dnsproxy_load("Domestic", loader.domestic, "domestic.json")); + process_list_append(dnsproxy_load("Foreign", loader.foreign, "foreign.json")); + process_list_append(overture_load(loader.diverter, "overture.json")); + if (loader.filter != NULL) { + process_list_append(adguard_load(loader.filter, ADGUARD_DIR)); + } // TODO: running custom script + for (char **script = loader.script; *script != NULL; ++script) { + log_info("Run custom script -> `%s`", *script); + } // process_list_run(); diff --git a/src/loader/loader.c b/src/loader/loader.c index 0363e7c..2d826b3 100644 --- a/src/loader/loader.c +++ b/src/loader/loader.c @@ -2,6 +2,7 @@ #include #include "config.h" #include "loader.h" +#include "logger.h" #include "parser.h" #include "sundry.h" #include "system.h" @@ -9,7 +10,6 @@ #include "dnsproxy.h" #include "constant.h" #include "structure.h" -#include "logger.h" struct cleardns loader; @@ -114,8 +114,13 @@ adguard* load_filter(cleardns_config *config) { } assets_config* load_assets(cleardns_config *config) { - // TODO: load assets - return NULL; + assets_config *assets = (assets_config *)malloc(sizeof(assets_config)); + assets->update_url = string_list_init(); + assets->update_file = string_list_init(); + assets->cron = string_init(config->assets.cron); + string_list_update(&assets->update_url, config->assets.update_url); + string_list_update(&assets->update_file, config->assets.update_file); + return assets; } void load_config(const char *config_file) { // parser and load cleardns configure diff --git a/src/utils/assets.c b/src/utils/assets.c index 01eafe6..111e33d 100644 --- a/src/utils/assets.c +++ b/src/utils/assets.c @@ -6,20 +6,20 @@ #include "system.h" #include "constant.h" -void load_asset(const char *file); +void extract_asset(const char *file); // TODO: assets update -> crontab task -void load_assets() { +void extract_assets() { log_info("Start loading assets"); create_folder(ASSETS_DIR); - load_asset(ASSET_GFW_LIST); - load_asset(ASSET_CHINA_IP); - load_asset(ASSET_CHINA_LIST); + extract_asset(ASSET_GFW_LIST); + extract_asset(ASSET_CHINA_IP); + extract_asset(ASSET_CHINA_LIST); log_info("Assets loaded complete"); } -void load_asset(const char *file) { +void extract_asset(const char *file) { log_debug("Start extract `%s`", file); char *output_file = string_join(ASSETS_DIR, file); if (is_file_exist(output_file)) {