From a318bdb0349891a6b2ce219cc8cb859341517727 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 12 Aug 2014 18:59:27 -0400 Subject: [PATCH] add option to not connect to the DHT network --- src/toxic.c | 48 +++++++++++++++++++++++++++++------------------- src/windows.h | 1 + 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/toxic.c b/src/toxic.c index b607f87..f91b6ce 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -339,6 +339,9 @@ int init_connection(Tox *m) static void do_connection(Tox *m, ToxWindow *prompt) { + if (arg_opts.no_connect == 1) + return; + char msg[MAX_STR_SIZE] = {0}; static int conn_err = 0; @@ -500,13 +503,14 @@ void *thread_winref(void *data) static void print_usage(void) { fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n"); - fprintf(stderr, " -f, --file Use specified data file\n"); - fprintf(stderr, " -x, --nodata Ignore data file\n"); fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n"); - fprintf(stderr, " -d, --default_locale Use default locale\n"); fprintf(stderr, " -c, --config Use specified config file\n"); - fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n"); + fprintf(stderr, " -d, --default_locale Use default locale\n"); + fprintf(stderr, " -f, --file Use specified data file\n"); 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, " -x, --nodata Ignore data file\n"); } static void set_default_opts(void) @@ -515,6 +519,7 @@ static void set_default_opts(void) arg_opts.ignore_data_file = 0; arg_opts.default_locale = 0; arg_opts.use_custom_data = 0; + arg_opts.no_connect = 0; } static void parse_args(int argc, char *argv[]) @@ -529,13 +534,26 @@ static void parse_args(int argc, char *argv[]) {"config", required_argument, 0, 'c'}, {"nodes", required_argument, 0, 'n'}, {"help", no_argument, 0, 'h'}, + {"noconnect", no_argument, 0, 'o'}, }; - const char *opts_str = "4xdf:c:n:h"; + const char *opts_str = "o4xdf:c:n:h"; int opt, indexptr; while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) { switch (opt) { + case '4': + arg_opts.use_ipv4 = 1; + break; + + case 'c': + snprintf(arg_opts.config_path, sizeof(arg_opts.config_path), "%s", optarg); + break; + + case 'd': + arg_opts.default_locale = 1; + break; + case 'f': arg_opts.use_custom_data = 1; DATA_FILE = strdup(optarg); @@ -548,24 +566,16 @@ static void parse_args(int argc, char *argv[]) strcat(BLOCK_FILE, "-blocklist"); break; - case 'x': - arg_opts.ignore_data_file = 1; - break; - - case '4': - arg_opts.use_ipv4 = 1; - break; - - case 'c': - snprintf(arg_opts.config_path, sizeof(arg_opts.config_path), "%s", optarg); - break; - case 'n': snprintf(arg_opts.nodes_path, sizeof(arg_opts.nodes_path), "%s", optarg); break; - case 'd': - arg_opts.default_locale = 1; + case 'o': + arg_opts.no_connect = 1; + break; + + case 'x': + arg_opts.ignore_data_file = 1; break; case 'h': diff --git a/src/windows.h b/src/windows.h index a06a37c..1db5e10 100644 --- a/src/windows.h +++ b/src/windows.h @@ -76,6 +76,7 @@ struct arg_opts { int use_ipv4; int default_locale; int use_custom_data; + int no_connect; char config_path[MAX_STR_SIZE]; char nodes_path[MAX_STR_SIZE]; };