Browse Source

feat: overture interface

dev
dnomd343 2 years ago
parent
commit
af97ee8d31
  1. 5
      include/overture.h
  2. 8
      src/cleardns.c
  3. 21
      src/overture.c

5
include/overture.h

@ -1,6 +1,8 @@
#ifndef _OVERTURE_H_
#define _OVERTURE_H_
#include "process.h"
typedef struct {
int port;
int timeout;
@ -13,7 +15,6 @@ typedef struct {
} overture;
overture* overture_init(int port);
void overture_dump(overture *info);
char* overture_gen_config(overture *info);
process* overture_load(overture *info, const char *file);
#endif

8
src/cleardns.c

@ -62,10 +62,10 @@ int main(int argc, char *argv[]) { // ClearDNS server
diverter->domestic_domain_file = "chinalist.txt";
diverter->foreign_domain_file = "gfwlist.txt";
overture_dump(diverter);
char *config = overture_gen_config(diverter);
log_info("\n%s", config);
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;
// fprintf(stderr, "[ClearDNS] Server start.\n");

21
src/overture.c

@ -1,11 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include "overture.h"
#include "process.h"
#include "common.h"
#include "logger.h"
#include "cJSON.h"
#include "str.h"
void overture_dump(overture *info);
char* overture_gen_config(overture *info);
overture* overture_init(int port) { // init overture options
overture *info = (overture*)malloc(sizeof(overture));
info->port = port;
@ -30,6 +34,23 @@ void overture_dump(overture *info) { // show overture info in debug log
log_debug("Overture domestic domain file -> %s", info->domestic_domain_file);
}
process* overture_load(overture *info, const char *file) {
overture_dump(info);
char *config = overture_gen_config(info); // string config (JSON format)
char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config);
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(p->cmd, "-c");
p->cmd = string_list_append(p->cmd, file);
p->env = string_list_init();
p->cwd = WORK_DIR;
return p;
}
char* overture_gen_config(overture *info) { // generate json configure from overture options
cJSON *config = cJSON_CreateObject();
char port_str[12]; // 32-bits (MAX_LEN -> -2147483648 -> 12-bytes)

Loading…
Cancel
Save