mirror of https://github.com/dnomd343/ClearDNS
dnomd343
2 years ago
11 changed files with 154 additions and 7 deletions
@ -0,0 +1,18 @@ |
|||||
|
#ifndef _DNSPROXY_H_ |
||||
|
#define _DNSPROXY_H_ |
||||
|
|
||||
|
typedef struct { |
||||
|
int port; |
||||
|
int verify; // bool value
|
||||
|
int parallel; // bool value
|
||||
|
int optimistic; // bool value
|
||||
|
char **bootstrap; |
||||
|
char **fallback; |
||||
|
char **primary; |
||||
|
char *cache; |
||||
|
} dnsproxy; |
||||
|
|
||||
|
dnsproxy* dnsproxy_init(int port); |
||||
|
void dnsproxy_dump(char *caption, dnsproxy *info); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,11 @@ |
|||||
|
#ifndef _STRLIST_H_ |
||||
|
#define _STRLIST_H_ |
||||
|
|
||||
|
char* string_init(char *str); |
||||
|
|
||||
|
char** string_list_init(); |
||||
|
int string_list_len(char **string_list); |
||||
|
char* string_list_dump(char **string_list); |
||||
|
char** string_list_append(char **string_list, char *string); |
||||
|
|
||||
|
#endif |
@ -0,0 +1,54 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include "dnsproxy.h" |
||||
|
#include "logger.h" |
||||
|
#include "common.h" |
||||
|
#include "strList.h" |
||||
|
|
||||
|
char* show_bool(int value) { |
||||
|
if (value) { |
||||
|
return "true"; |
||||
|
} else { |
||||
|
return "false"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
char** command_init(char *file) { |
||||
|
return string_list_append(string_list_init(), file); |
||||
|
} |
||||
|
|
||||
|
dnsproxy* dnsproxy_init(int port) { |
||||
|
dnsproxy *info = (dnsproxy*)malloc(sizeof(dnsproxy)); |
||||
|
info->port = port; |
||||
|
info->verify = TRUE; |
||||
|
info->parallel = TRUE; |
||||
|
info->optimistic = FALSE; |
||||
|
info->bootstrap = string_list_init(); |
||||
|
info->fallback = string_list_init(); |
||||
|
info->primary = string_list_init(); |
||||
|
info->cache = "4194304"; // 4MiB
|
||||
|
return info; |
||||
|
} |
||||
|
|
||||
|
void dnsproxy_dump(char *caption, dnsproxy *info) { |
||||
|
log_debug("%s listen port -> %d", caption, info->port); |
||||
|
log_debug("%s verify -> %s", caption, show_bool(info->verify)); |
||||
|
log_debug("%s parallel -> %s", caption, show_bool(info->parallel)); |
||||
|
log_debug("%s optimistic -> %s", caption, show_bool(info->optimistic)); |
||||
|
|
||||
|
log_debug("%s bootstrap -> %s", caption, string_list_dump(info->bootstrap)); |
||||
|
log_debug("%s fallback -> %s", caption, string_list_dump(info->fallback)); |
||||
|
log_debug("%s primary -> %s", caption, string_list_dump(info->primary)); |
||||
|
|
||||
|
log_debug("%s cache -> %s", caption, info->cache); |
||||
|
|
||||
|
char **test = string_list_init(); |
||||
|
test = string_list_append(test, "0"); |
||||
|
test = string_list_append(test, "1"); |
||||
|
test = string_list_append(test, "2"); |
||||
|
|
||||
|
// char *test[] = {NULL};
|
||||
|
// char *test[] = {"dnomd343", "2333", NULL};
|
||||
|
log_warn("%s", string_list_dump(test)); |
||||
|
log_warn("%d", string_list_len(test)); |
||||
|
|
||||
|
} |
@ -1,3 +1,3 @@ |
|||||
cmake_minimum_required(VERSION 2.8.12) |
cmake_minimum_required(VERSION 2.8.12) |
||||
|
|
||||
add_library(utils cJSON.c logger.c) |
add_library(utils logger.c strList.c) |
||||
|
@ -0,0 +1,47 @@ |
|||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include "strList.h" |
||||
|
|
||||
|
char* string_init(char *str) { |
||||
|
return strcpy((char*)malloc(strlen(str) + 1), str); |
||||
|
} |
||||
|
|
||||
|
char* string_list_dump(char **string_list) { // ['a', 'b', 'c', ...]
|
||||
|
unsigned long string_len = 0; |
||||
|
for (char **string = string_list; *string != NULL; ++string) { |
||||
|
string_len += strlen(*string) + 4; |
||||
|
} |
||||
|
if (string_len == 0) { // empty string
|
||||
|
string_len = 2; |
||||
|
} |
||||
|
char *string_ret = (char *)malloc(sizeof(char) * (string_len + 1)); |
||||
|
string_ret[0] = '['; |
||||
|
string_ret[1] = 0x00; |
||||
|
for (char **string = string_list; *string != NULL; ++string) { |
||||
|
string_ret = strcat(strcat(string_ret, "'"), *string); |
||||
|
string_ret = strcat(string_ret, "', "); |
||||
|
} |
||||
|
string_ret[string_len - 1] = ']'; |
||||
|
string_ret[string_len] = 0x00; |
||||
|
return string_ret; |
||||
|
} |
||||
|
|
||||
|
int string_list_len(char **string_list) { |
||||
|
int num = 0; |
||||
|
while(string_list[num++] != NULL); // get string list size
|
||||
|
return num - 1; |
||||
|
} |
||||
|
|
||||
|
char** string_list_init() { |
||||
|
char **string_list = (char**)malloc(sizeof(char*)); |
||||
|
*string_list = NULL; |
||||
|
return string_list; |
||||
|
} |
||||
|
|
||||
|
char** string_list_append(char **string_list, char *string) { |
||||
|
int len = string_list_len(string_list); |
||||
|
string_list = (char**)realloc(string_list, sizeof(char**) * (len + 2)); |
||||
|
string_list[len] = string_init(string); |
||||
|
string_list[len + 1] = NULL; // list end sign
|
||||
|
return string_list; |
||||
|
} |
Loading…
Reference in new issue