Browse Source

feat: load diverter assets

dev
dnomd343 2 years ago
parent
commit
2fdd171562
  1. 1
      include/common/system.h
  2. 8
      src/common/system.c
  3. 2
      src/loader/default.c
  4. 20
      src/loader/loader.c

1
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

8
src/common/system.c

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#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");

2
src/loader/default.c

@ -1,8 +1,8 @@
#include <stdlib.h>
#include "json.h"
#include "logger.h"
#include "system.h"
#include "sundry.h"
#include "system.h"
#define DEFAULT_CONFIG "\
port: 53\n\

20
src/loader/loader.c

@ -1,21 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#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);

Loading…
Cancel
Save