1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:03:27 +01:00

add option to specify DNSservers path

This commit is contained in:
Jfreegman 2014-08-12 19:13:57 -04:00
parent a318bdb034
commit 35cc815cdb
3 changed files with 16 additions and 5 deletions

View File

@ -49,6 +49,7 @@
extern struct _Winthread Winthread; extern struct _Winthread Winthread;
extern struct _dns3_servers dns3_servers; extern struct _dns3_servers dns3_servers;
extern struct arg_opts arg_opts;
/* Hardcoded backup in case domain list is not loaded */ /* Hardcoded backup in case domain list is not loaded */
static struct dns3_server_backup { static struct dns3_server_backup {
@ -97,9 +98,8 @@ struct _dns3_servers {
char keys[MAX_DNS_SERVERS][DNS3_KEY_SIZE]; char keys[MAX_DNS_SERVERS][DNS3_KEY_SIZE];
} dns3_servers; } dns3_servers;
static int load_dns_domainlist(void) static int load_dns_domainlist(const char *path)
{ {
const char *path = PACKAGE_DATADIR "/DNSservers";
FILE *fp = fopen(path, "r"); FILE *fp = fopen(path, "r");
if (fp == NULL) if (fp == NULL)
@ -384,8 +384,9 @@ void dns3_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr,
} }
if (!dns3_servers.loaded) { if (!dns3_servers.loaded) {
const char *path = arg_opts.dns_path[0] ? arg_opts.dns_path : PACKAGE_DATADIR "/DNSservers";
dns3_servers.loaded = true; dns3_servers.loaded = true;
int ret = load_dns_domainlist(); int ret = load_dns_domainlist(path);
if (ret < 0) { if (ret < 0) {
const char *errmsg = "DNS server list failed to load with error code %d. Falling back to hard-coded list."; const char *errmsg = "DNS server list failed to load with error code %d. Falling back to hard-coded list.";

View File

@ -470,7 +470,10 @@ static void do_toxic(Tox *m, ToxWindow *prompt)
pthread_mutex_lock(&Winthread.lock); pthread_mutex_lock(&Winthread.lock);
do_connection(m, prompt); do_connection(m, prompt);
do_file_senders(m); do_file_senders(m);
tox_do(m); /* main tox-core loop */
if (arg_opts.no_connect == 0)
tox_do(m); /* main tox-core loop */
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
} }
@ -510,6 +513,7 @@ static void print_usage(void)
fprintf(stderr, " -h, --help Show this message and exit\n"); fprintf(stderr, " -h, --help Show this message and exit\n");
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n"); fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n"); fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
fprintf(stderr, " -x, --nodata Ignore data file\n"); fprintf(stderr, " -x, --nodata Ignore data file\n");
} }
@ -535,9 +539,10 @@ static void parse_args(int argc, char *argv[])
{"nodes", required_argument, 0, 'n'}, {"nodes", required_argument, 0, 'n'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"noconnect", no_argument, 0, 'o'}, {"noconnect", no_argument, 0, 'o'},
{"dnslist", required_argument, 0, 'r'},
}; };
const char *opts_str = "o4xdf:c:n:h"; const char *opts_str = "4dhoxc:f:n:r:";
int opt, indexptr; int opt, indexptr;
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) { while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
@ -574,6 +579,10 @@ static void parse_args(int argc, char *argv[])
arg_opts.no_connect = 1; arg_opts.no_connect = 1;
break; break;
case 'r':
snprintf(arg_opts.dns_path, sizeof(arg_opts.dns_path), "%s", optarg);
break;
case 'x': case 'x':
arg_opts.ignore_data_file = 1; arg_opts.ignore_data_file = 1;
break; break;

View File

@ -77,6 +77,7 @@ struct arg_opts {
int default_locale; int default_locale;
int use_custom_data; int use_custom_data;
int no_connect; int no_connect;
char dns_path[MAX_STR_SIZE];
char config_path[MAX_STR_SIZE]; char config_path[MAX_STR_SIZE];
char nodes_path[MAX_STR_SIZE]; char nodes_path[MAX_STR_SIZE];
}; };