mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 04:03:25 +01:00
add option to specify DNSservers path
This commit is contained in:
parent
a318bdb034
commit
35cc815cdb
@ -49,6 +49,7 @@
|
||||
|
||||
extern struct _Winthread Winthread;
|
||||
extern struct _dns3_servers dns3_servers;
|
||||
extern struct arg_opts arg_opts;
|
||||
|
||||
/* Hardcoded backup in case domain list is not loaded */
|
||||
static struct dns3_server_backup {
|
||||
@ -97,9 +98,8 @@ struct _dns3_servers {
|
||||
char keys[MAX_DNS_SERVERS][DNS3_KEY_SIZE];
|
||||
} 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");
|
||||
|
||||
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) {
|
||||
const char *path = arg_opts.dns_path[0] ? arg_opts.dns_path : PACKAGE_DATADIR "/DNSservers";
|
||||
dns3_servers.loaded = true;
|
||||
int ret = load_dns_domainlist();
|
||||
int ret = load_dns_domainlist(path);
|
||||
|
||||
if (ret < 0) {
|
||||
const char *errmsg = "DNS server list failed to load with error code %d. Falling back to hard-coded list.";
|
||||
|
13
src/toxic.c
13
src/toxic.c
@ -470,7 +470,10 @@ static void do_toxic(Tox *m, ToxWindow *prompt)
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
do_connection(m, prompt);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -510,6 +513,7 @@ static void print_usage(void)
|
||||
fprintf(stderr, " -h, --help Show this message and exit\n");
|
||||
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\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");
|
||||
}
|
||||
|
||||
@ -535,9 +539,10 @@ static void parse_args(int argc, char *argv[])
|
||||
{"nodes", required_argument, 0, 'n'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"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;
|
||||
|
||||
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;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
snprintf(arg_opts.dns_path, sizeof(arg_opts.dns_path), "%s", optarg);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
arg_opts.ignore_data_file = 1;
|
||||
break;
|
||||
|
@ -77,6 +77,7 @@ struct arg_opts {
|
||||
int default_locale;
|
||||
int use_custom_data;
|
||||
int no_connect;
|
||||
char dns_path[MAX_STR_SIZE];
|
||||
char config_path[MAX_STR_SIZE];
|
||||
char nodes_path[MAX_STR_SIZE];
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user