Browse Source

update: enhance process struct interface

dev
dnomd343 2 years ago
parent
commit
c39ced99f9
  1. 4
      include/utils/process.h
  2. 56
      src/cleardns.c
  3. 11
      src/dnsproxy.c
  4. 12
      src/overture.c
  5. 2
      src/utils/CMakeLists.txt
  6. 16
      src/utils/process.c

4
include/process.h → include/utils/process.h

@ -5,9 +5,13 @@
//void init_server(char *init_script, char *custom_script);
typedef struct {
char *name;
char **cmd;
char **env;
char *cwd;
} process;
void process_add_arg(process *proc, const char *arg);
process* process_init(const char *caption, const char *bin);
#endif

56
src/cleardns.c

@ -46,15 +46,16 @@ int main(int argc, char *argv[]) { // ClearDNS server
// free(str);
// string_list_free(temp);
uint32_t **temp = uint32_list_init();
temp = uint32_list_append(temp, 123);
temp = uint32_list_append(temp, 456);
temp = uint32_list_append(temp, 789);
// uint32_t **temp = uint32_list_init();
// temp = uint32_list_append(temp, 123);
// temp = uint32_list_append(temp, 456);
// temp = uint32_list_append(temp, 789);
//
// char *str = uint32_list_dump(temp);
// log_info("`%s`\n", str);
// free(str);
// uint32_list_free(temp);
char *str = uint32_list_dump(temp);
log_info("`%s`\n", str);
free(str);
uint32_list_free(temp);
// dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT);
//
@ -66,35 +67,36 @@ int main(int argc, char *argv[]) { // ClearDNS server
//
// dnsproxy_add_fallback(domestic, "tls://223.6.6.6");
// dnsproxy_add_fallback(domestic, "tls://120.53.53.53");
//
// domestic->verify = FALSE;
// domestic->parallel = FALSE;
// domestic->optimistic = TRUE;
// domestic->debug = TRUE;
// domestic->cache = 0;
// domestic->cache = 4194304; // 4MiB
//
// process *p = dnsproxy_load("Domestic", domestic, "domestic.json");
// log_info("cmd -> %s", string_list_dump(p->cmd));
// log_info("env -> %s", string_list_dump(p->env));
// log_info("cwd -> %s", p->cwd);
// overture *diverter = overture_init(DIVERTER_PORT);
//
// diverter->timeout = 8;
// diverter->domestic_ip_file = "china-ip.txt";
// diverter->domestic_domain_file = "chinalist.txt";
// diverter->foreign_domain_file = "gfwlist.txt";
//
// diverter->debug = TRUE;
// diverter->ttl_file = "domain_ttl.txt";
// diverter->host_file = "hosts.txt";
// diverter->reject_type = int_list_append(diverter->reject_type, 255);
//
// process *p = overture_load(diverter, "overture.json");
// log_info("cmd -> %s", string_list_dump(p->cmd));
// log_info("env -> %s", string_list_dump(p->env));
// log_info("cwd -> %s", p->cwd);
overture *diverter = overture_init(DIVERTER_PORT);
diverter->timeout = 8;
diverter->domestic_ip_file = "china-ip.txt";
diverter->domestic_domain_file = "chinalist.txt";
diverter->foreign_domain_file = "gfwlist.txt";
diverter->debug = TRUE;
diverter->ttl_file = "domain_ttl.txt";
diverter->host_file = "hosts.txt";
diverter->reject_type = uint32_list_append(diverter->reject_type, 255);
diverter->reject_type = uint32_list_append(diverter->reject_type, 254);
process *p = overture_load(diverter, "overture.json");
log_info("cmd -> %s", string_list_dump(p->cmd));
log_info("env -> %s", string_list_dump(p->env));
log_info("cwd -> %s", p->cwd);
// int debug_mode = 0;

11
src/dnsproxy.c

@ -66,16 +66,13 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) {
free(config);
char *option = string_join("--config-path=", file);
process *p = (process *)malloc(sizeof(process));
p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN);
p->cmd = string_list_append(p->cmd, option);
process *proc = process_init(caption, DNSPROXY_BIN);
process_add_arg(proc, option);
if (info->debug) {
p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy enable debug mode
process_add_arg(proc, "--verbose"); // dnsproxy enable debug mode
}
p->env = string_list_init();
p->cwd = WORK_DIR;
free(option);
return p;
return proc;
}
char* dnsproxy_config(dnsproxy *info) { // generate json configure from dnsproxy options

12
src/overture.c

@ -52,15 +52,13 @@ process* overture_load(overture *info, const char *file) {
free(config_file);
free(config);
process *p = (process *)malloc(sizeof(process));
p->cmd = string_list_append(string_list_init(), OVERTURE_BIN);
p->cmd = string_list_append(string_list_append(p->cmd, "-c"), file);
process *proc = process_init("Overture", OVERTURE_BIN);
process_add_arg(proc, "-c");
process_add_arg(proc, file);
if (info->debug) {
p->cmd = string_list_append(p->cmd, "-v"); // overture enable debug mode
process_add_arg(proc, "-v"); // overture enable debug mode
}
p->env = string_list_init();
p->cwd = WORK_DIR;
return p;
return proc;
}
char* overture_config(overture *info) { // generate json configure from overture options

2
src/utils/CMakeLists.txt

@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 2.8.12)
add_library(utils logger.c structure.c cJSON.c)
add_library(utils cJSON.c logger.c process.c structure.c)

16
src/utils/process.c

@ -0,0 +1,16 @@
#include "common.h"
#include "process.h"
#include "structure.h"
process* process_init(const char *caption, const char *bin) { // init process struct
process *proc = (process *)malloc(sizeof(process));
proc->name = string_init(caption); // process caption
proc->cmd = string_list_append(string_list_init(), bin); // argv[0] normally be process file name
proc->env = string_list_init(); // empty environment variable
proc->cwd = WORK_DIR; // current working directory
return proc;
}
void process_add_arg(process *proc, const char *arg) { // add argument for process
proc->cmd = string_list_append(proc->cmd, arg);
}
Loading…
Cancel
Save