Browse Source

update: cmake build

dev
dnomd343 2 years ago
parent
commit
32d6ddf522
  1. 3
      include/applet/adguard.h
  2. 2
      include/applet/dnsproxy.h
  3. 2
      include/applet/overture.h
  4. 14
      include/common.h
  5. 3
      include/utils/process.h
  6. 6
      include/utils/structure.h
  7. 1
      src/applet/CMakeLists.txt
  8. 2
      src/applet/adguard.c
  9. 18
      src/applet/dnsproxy.c
  10. 8
      src/applet/overture.c
  11. 50
      src/cleardns.c
  12. 7
      src/common.c
  13. 1
      src/loader/config.c
  14. 1
      src/loader/loader.c
  15. 3
      src/utils/process.c
  16. 4
      src/utils/structure.c

3
include/applet/adguard.h

@ -1,8 +1,7 @@
#ifndef _ADGUARD_H_ #ifndef _ADGUARD_H_
#define _ADGUARD_H_ #define _ADGUARD_H_
#include "common.h" #include <stdint.h>
#include "process.h"
typedef struct { typedef struct {
uint8_t debug; // bool value uint8_t debug; // bool value

2
include/applet/dnsproxy.h

@ -1,7 +1,7 @@
#ifndef _DNSPROXY_H_ #ifndef _DNSPROXY_H_
#define _DNSPROXY_H_ #define _DNSPROXY_H_
#include "common.h" #include <stdint.h>
#include "process.h" #include "process.h"
typedef struct { typedef struct {

2
include/applet/overture.h

@ -1,7 +1,7 @@
#ifndef _OVERTURE_H_ #ifndef _OVERTURE_H_
#define _OVERTURE_H_ #define _OVERTURE_H_
#include "common.h" #include <stdint.h>
#include "process.h" #include "process.h"
typedef struct { typedef struct {

14
include/common.h

@ -1,12 +1,14 @@
#ifndef _COMMON_H_ #ifndef _COMMON_H_
#define _COMMON_H_ #define _COMMON_H_
#include <stdlib.h> //#include <stdlib.h>
//
//typedef u_int8_t uint8_t;
//typedef u_int16_t uint16_t;
//typedef u_int32_t uint32_t;
//typedef u_int64_t uint64_t;
typedef u_int8_t uint8_t; #include <stdint.h>
typedef u_int16_t uint16_t;
typedef u_int32_t uint32_t;
typedef u_int64_t uint64_t;
#define VERSION "1.3.0-dev" #define VERSION "1.3.0-dev"
@ -41,6 +43,8 @@ void save_file(const char *file, const char *content);
void string_list_debug(char *describe, char **string_list); void string_list_debug(char *describe, char **string_list);
void uint32_list_debug(char *describe, uint32_t **uint32_list); void uint32_list_debug(char *describe, uint32_t **uint32_list);
uint8_t check_port(uint16_t port);
char* string_init(const char *str); char* string_init(const char *str);
char* string_join(const char *base, const char *add); char* string_join(const char *base, const char *add);

3
include/utils/process.h

@ -1,9 +1,6 @@
#ifndef _PROCESS_H_ #ifndef _PROCESS_H_
#define _PROCESS_H_ #define _PROCESS_H_
//void server_daemon();
//void init_server(char *init_script, char *custom_script);
typedef struct { typedef struct {
char *name; char *name;
char **cmd; char **cmd;

6
include/utils/structure.h

@ -1,7 +1,7 @@
#ifndef _STR_H_ #ifndef _STRUCTURE_H_
#define _STR_H_ #define _STRUCTURE_H_
#include "common.h" #include <stdint.h>
uint32_t** uint32_list_init(); uint32_t** uint32_list_init();
char* uint32_list_dump(uint32_t **int_list); char* uint32_list_dump(uint32_t **int_list);

1
src/applet/CMakeLists.txt

@ -1,3 +1,4 @@
cmake_minimum_required(VERSION 2.8.12) cmake_minimum_required(VERSION 2.8.12)
add_library(applet adguard.c dnsproxy.c overture.c) add_library(applet adguard.c dnsproxy.c overture.c)
target_link_libraries(applet utils)

2
src/applet/adguard.c

@ -1,3 +1,5 @@
#include <stdlib.h>
#include "common.h"
#include "adguard.h" #include "adguard.h"
adguard* adguard_init() { adguard* adguard_init() {

18
src/applet/dnsproxy.c

@ -1,10 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "cJSON.h"
#include "common.h"
#include "logger.h"
#include "dnsproxy.h" #include "dnsproxy.h"
#include "structure.h" #include "structure.h"
#include "process.h"
#include "logger.h"
#include "common.h"
#include "cJSON.h"
char* dnsproxy_config(dnsproxy *info); char* dnsproxy_config(dnsproxy *info);
void dnsproxy_dump(const char *caption, dnsproxy *info); void dnsproxy_dump(const char *caption, dnsproxy *info);
@ -58,11 +57,14 @@ void dnsproxy_dump(const char *caption, dnsproxy *info) { // show dnsproxy info
} }
process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) {
// TODO: check primary server number (non-zero)
// TODO: check port (1 ~ 65535)
dnsproxy_dump(caption, info); dnsproxy_dump(caption, info);
if (!check_port(info->port)) { // invalid server port
log_fatal("Invalid port `%u`", info->port);
}
if (string_list_len(info->primary) == 0) { // without primary dns server
log_fatal("%s without primary dns server", caption);
}
char *config = dnsproxy_config(info); // string config (JSON format) char *config = dnsproxy_config(info); // string config (JSON format)
char *config_file = string_join(WORK_DIR, file); char *config_file = string_join(WORK_DIR, file);
save_file(config_file, config); save_file(config_file, config);

8
src/applet/overture.c

@ -1,12 +1,12 @@
#include <stdio.h> #include <stdio.h> // TODO: use int to string instead of sprintf
#include <stdlib.h> #include <stdlib.h>
#include "overture.h" #include "cJSON.h"
#include "process.h"
#include "common.h" #include "common.h"
#include "logger.h" #include "logger.h"
#include "cJSON.h" #include "overture.h"
#include "structure.h" #include "structure.h"
void overture_dump(overture *info); void overture_dump(overture *info);
char* overture_config(overture *info); char* overture_config(overture *info);

50
src/cleardns.c

@ -36,10 +36,10 @@ int main(int argc, char *argv[]) { // ClearDNS server
LOG_LEVEL = LOG_DEBUG; LOG_LEVEL = LOG_DEBUG;
log_info("ClearDNS server start (%s)", VERSION); log_info("ClearDNS server start (%s)", VERSION);
load_config("test.json"); // load_config("test.json");
//
dnsproxy_load("Domestic", loader.domestic, "domestic.json"); // dnsproxy_load("Domestic", loader.domestic, "domestic.json");
dnsproxy_load("Foreign", loader.foreign, "foreign.json"); // dnsproxy_load("Foreign", loader.foreign, "foreign.json");
// char **temp = string_list_init(); // char **temp = string_list_init();
// temp = string_list_append(temp, "123"); // temp = string_list_append(temp, "123");
@ -62,27 +62,27 @@ int main(int argc, char *argv[]) { // ClearDNS server
// uint32_list_free(temp); // uint32_list_free(temp);
// dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT);
//
// dnsproxy_add_bootstrap(domestic, "1.1.1.1"); dnsproxy_add_bootstrap(domestic, "1.1.1.1");
// dnsproxy_add_bootstrap(domestic, "8.8.8.8"); dnsproxy_add_bootstrap(domestic, "8.8.8.8");
//
// dnsproxy_add_primary(domestic, "223.5.5.5"); dnsproxy_add_primary(domestic, "223.5.5.5");
// dnsproxy_add_primary(domestic, "tls://dns.pub"); dnsproxy_add_primary(domestic, "tls://dns.pub");
//
// dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); dnsproxy_add_fallback(domestic, "tls://223.6.6.6");
// dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); dnsproxy_add_fallback(domestic, "tls://120.53.53.53");
//
// domestic->verify = FALSE; domestic->verify = FALSE;
// domestic->parallel = FALSE; domestic->parallel = FALSE;
// domestic->optimistic = TRUE; domestic->optimistic = TRUE;
// domestic->debug = TRUE; domestic->debug = TRUE;
// domestic->cache = 4194304; // 4MiB domestic->cache = 4194304; // 4MiB
//
// process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); process *p = dnsproxy_load("Domestic", domestic, "domestic.json");
// log_info("cmd -> %s", string_list_dump(p->cmd)); log_info("cmd -> %s", string_list_dump(p->cmd));
// log_info("env -> %s", string_list_dump(p->env)); log_info("env -> %s", string_list_dump(p->env));
// log_info("cwd -> %s", p->cwd); log_info("cwd -> %s", p->cwd);
// overture *diverter = overture_init(DIVERTER_PORT); // overture *diverter = overture_init(DIVERTER_PORT);

7
src/common.c

@ -34,6 +34,13 @@ void uint32_list_debug(char *describe, uint32_t **uint32_list) {
free(string_ret); free(string_ret);
} }
uint8_t check_port(uint16_t port) {
if (port > 0 && port <= 65535) { // 1 ~ 65535
return TRUE;
}
return FALSE;
}
void save_file(const char *file, const char *content) { // save into file void save_file(const char *file, const char *content) { // save into file
log_debug("Write into `%s` -> \n%s", file, content); log_debug("Write into `%s` -> \n%s", file, content);
FILE* fp = fopen(file , "w"); FILE* fp = fopen(file , "w");

1
src/loader/config.c

@ -1,3 +1,4 @@
#include <stdlib.h>
#include "common.h" #include "common.h"
#include "config.h" #include "config.h"
#include "logger.h" #include "logger.h"

1
src/loader/loader.c

@ -1,3 +1,4 @@
#include <stdlib.h>
#include "loader.h" #include "loader.h"
#include "config.h" #include "config.h"
#include "parser.h" #include "parser.h"

3
src/utils/process.c

@ -1,6 +1,7 @@
#include "common.h" #include <stdlib.h>
#include "process.h" #include "process.h"
#include "structure.h" #include "structure.h"
#include "common.h"
process* process_init(const char *caption, const char *bin) { // init process struct process* process_init(const char *caption, const char *bin) { // init process struct
process *proc = (process *)malloc(sizeof(process)); process *proc = (process *)malloc(sizeof(process));

4
src/utils/structure.c

@ -1,7 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "structure.h" #include "structure.h"
#include "common.h"
uint32_t* uint32_init(uint32_t number) { // new uint32 (by malloc) uint32_t* uint32_init(uint32_t number) { // new uint32 (by malloc)
uint32_t *data = (uint32_t *)malloc(sizeof(uint32_t)); uint32_t *data = (uint32_t *)malloc(sizeof(uint32_t));

Loading…
Cancel
Save