Browse Source

fix: header file prefix

dev
dnomd343 2 years ago
parent
commit
6a4f792ccb
  1. 4
      include/applet/adguard.h
  2. 4
      include/applet/dnsproxy.h
  3. 4
      include/applet/overture.h
  4. 4
      include/common/constant.h
  5. 4
      include/common/json.h
  6. 4
      include/common/structure.h
  7. 4
      include/common/sundry.h
  8. 6
      include/common/system.h
  9. 18
      include/flag.h
  10. 4
      include/loader/config.h
  11. 4
      include/loader/loader.h
  12. 4
      include/loader/parser.h
  13. 4
      include/utils/logger.h
  14. 4
      include/utils/process.h
  15. 7
      src/applet/adguard.c
  16. 9
      src/cleardns.c
  17. 13
      src/common/json.c
  18. 6
      src/common/system.c
  19. 2
      src/common_legacy.c
  20. 4
      src/loader/loader.c
  21. 2
      src/process_legacy.c

4
include/applet/adguard.h

@ -1,5 +1,5 @@
#ifndef _ADGUARD_H_ #ifndef ADGUARD_H_
#define _ADGUARD_H_ #define ADGUARD_H_
#include <stdint.h> #include <stdint.h>
#include "process.h" #include "process.h"

4
include/applet/dnsproxy.h

@ -1,5 +1,5 @@
#ifndef _DNSPROXY_H_ #ifndef DNSPROXY_H_
#define _DNSPROXY_H_ #define DNSPROXY_H_
#include <stdint.h> #include <stdint.h>
#include "process.h" #include "process.h"

4
include/applet/overture.h

@ -1,5 +1,5 @@
#ifndef _OVERTURE_H_ #ifndef OVERTURE_H_
#define _OVERTURE_H_ #define OVERTURE_H_
#include <stdint.h> #include <stdint.h>
#include "process.h" #include "process.h"

4
include/common/constant.h

@ -1,5 +1,5 @@
#ifndef _CONSTANT_H_ #ifndef CONSTANT_H_
#define _CONSTANT_H_ #define CONSTANT_H_
#define VERSION "1.3.0-dev" #define VERSION "1.3.0-dev"

4
include/common/json.h

@ -1,5 +1,5 @@
#ifndef _JSON_H_ #ifndef JSON_H_
#define _JSON_H_ #define JSON_H_
#include <stdint.h> #include <stdint.h>
#include "cJSON.h" #include "cJSON.h"

4
include/common/structure.h

@ -1,5 +1,5 @@
#ifndef _STRUCTURE_H_ #ifndef STRUCTURE_H_
#define _STRUCTURE_H_ #define STRUCTURE_H_
#include <stdint.h> #include <stdint.h>

4
include/common/sundry.h

@ -1,5 +1,5 @@
#ifndef _SUNDRY_H_ #ifndef SUNDRY_H_
#define _SUNDRY_H_ #define SUNDRY_H_
#include <stdint.h> #include <stdint.h>

6
include/common/system.h

@ -1,14 +1,14 @@
#ifndef _SYSTEM_H_ #ifndef SYSTEM_H_
#define _SYSTEM_H_ #define SYSTEM_H_
#include <stdint.h> #include <stdint.h>
char* read_file(const char *file); char* read_file(const char *file);
void remove_file(const char *file);
int run_command(const char *command); int run_command(const char *command);
void create_folder(const char *folder); void create_folder(const char *folder);
uint8_t is_file_exist(const char *file); uint8_t is_file_exist(const char *file);
void save_file(const char *file, const char *content); void save_file(const char *file, const char *content);
void save_string_list(const char *file, char **string_list); void save_string_list(const char *file, char **string_list);
#endif #endif

18
include/flag.h

@ -1,18 +0,0 @@
#ifndef _EXIT_CODE_H_
#define _EXIT_CODE_H_
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define EXIT_NORMAL 0
#define EXIT_FILE_ERROR 1
#define EXIT_FORK_ERROR 2
#define EXIT_EXEC_ERROR 3
#define EXIT_WAIT_ERROR 4
#endif

4
include/loader/config.h

@ -1,5 +1,5 @@
#ifndef _CONFIG_H_ #ifndef CONFIG_H_
#define _CONFIG_H_ #define CONFIG_H_
#include <stdint.h> #include <stdint.h>

4
include/loader/loader.h

@ -1,5 +1,5 @@
#ifndef _LOADER_H_ #ifndef LOADER_H_
#define _LOADER_H_ #define LOADER_H_
#include "adguard.h" #include "adguard.h"
#include "dnsproxy.h" #include "dnsproxy.h"

4
include/loader/parser.h

@ -1,5 +1,5 @@
#ifndef _PARSER_H_ #ifndef PARSER_H_
#define _PARSER_H_ #define PARSER_H_
#include "config.h" #include "config.h"

4
include/utils/logger.h

@ -1,5 +1,5 @@
#ifndef _LOGGER_H_ #ifndef LOGGER_H_
#define _LOGGER_H_ #define LOGGER_H_
#define LOG_PREFIX "ClearDNS" #define LOG_PREFIX "ClearDNS"

4
include/utils/process.h

@ -1,5 +1,5 @@
#ifndef _PROCESS_H_ #ifndef PROCESS_H_
#define _PROCESS_H_ #define PROCESS_H_
typedef struct { typedef struct {
char *name; char *name;

7
src/applet/adguard.c

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "json.h" #include "json.h"
#include "bcrypt.h" #include "bcrypt.h"
#include "logger.h" #include "logger.h"
@ -76,6 +77,12 @@ process* adguard_load(adguard *info, const char *dir) { // load adguard options
if (!check_port(info->web_port)) { // invalid web port if (!check_port(info->web_port)) { // invalid web port
log_fatal("Invalid web port `%u`", info->web_port); log_fatal("Invalid web port `%u`", info->web_port);
} }
if (!strcmp(info->username, "")) { // invalid username
log_fatal("Invalid AdGuardHome username");
}
if (!strcmp(info->password, "")) { // invalid password
log_fatal("Invalid AdGuardHome password");
}
create_folder(dir); // ensure adguard work dir exist create_folder(dir); // ensure adguard work dir exist
char *adguard_config_ret; char *adguard_config_ret;

9
src/cleardns.c

@ -42,15 +42,6 @@ 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);
// if (is_file_exist("/tmp/test")) {
// log_info("File exist");
// }
// create_folder("/tmp/test");
// run_command("exit 3");
run_command("exit");
return 0;
// char **temp = string_list_init(); // char **temp = string_list_init();
// //

13
src/common/json.c

@ -26,20 +26,17 @@ char* to_json(const char *file) { // convert JSON / TOML / YAML to json format (
} }
flag[8] = '\0'; flag[8] = '\0';
char *output_file = string_join("/tmp/tojson-", flag); char *output_file = string_join("/tmp/to-json-", flag);
char *to_json_cmd = (char *)malloc(strlen(file) + strlen(output_file) + 11); char *to_json_cmd = (char *)malloc(strlen(file) + strlen(output_file) + 11);
sprintf(to_json_cmd, "toJSON %s > %s", file, output_file); sprintf(to_json_cmd, "toJSON %s > %s", file, output_file);
int to_json_ret = run_command(to_json_cmd); int to_json_ret = run_command(to_json_cmd);
free(to_json_cmd); free(to_json_cmd);
char *remove_cmd = string_join("rm -f ", output_file); char *json_content = NULL;
run_command(remove_cmd); if (!to_json_ret) { // toJSON return zero code (convert fine)
free(remove_cmd); json_content = read_file(output_file);
if (to_json_ret) { // toJSON return non-zero code
free(output_file);
return NULL; // convert failed
} }
char *json_content = read_file(output_file); remove_file(output_file);
free(output_file); free(output_file);
return json_content; return json_content;
} }

6
src/common/system.c

@ -15,6 +15,12 @@ int run_command(const char *command) { // running command with system shell
return ret; return ret;
} }
void remove_file(const char *file) {
char *remove_cmd = string_join("rm -f ", file);
run_command(remove_cmd);
free(remove_cmd);
}
void create_folder(const char *folder) { // create folder void create_folder(const char *folder) { // create folder
if (!access(folder, 0)) { // target is file or folder if (!access(folder, 0)) { // target is file or folder
struct stat buf; struct stat buf;

2
src/common_legacy.c

@ -2,7 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <strList.bak> #include <strList.bak>
#include "cJSON.h" #include "cJSON.h"
#include "flag.h" #include "flag_legacy.h"
char **adguard_command = NULL; char **adguard_command = NULL;
char **overture_command = NULL; char **overture_command = NULL;

4
src/loader/loader.c

@ -94,8 +94,8 @@ adguard* load_filter(cleardns_config *config) {
adguard *filter = adguard_init(); adguard *filter = adguard_init();
filter->dns_port = config->port; filter->dns_port = config->port;
filter->web_port = config->adguard.port; filter->web_port = config->adguard.port;
filter->username = config->adguard.username; filter->username = string_init(config->adguard.username);
filter->password = config->adguard.password; filter->password = string_init(config->adguard.password);
char *diverter_port = uint32_to_string(config->diverter.port); char *diverter_port = uint32_to_string(config->diverter.port);
filter->upstream = string_join("127.0.0.1:", diverter_port); filter->upstream = string_join("127.0.0.1:", diverter_port);
free(diverter_port); free(diverter_port);

2
src/process_legacy.c

@ -7,7 +7,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include "constant.h" #include "constant.h"
#include "flag.h" #include "flag_legacy.h"
int exiting = 0; int exiting = 0;

Loading…
Cancel
Save