diff options
Diffstat (limited to 'testing/Messenger_test.c')
-rw-r--r-- | testing/Messenger_test.c | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 73d44efb..e7a75c8c 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -95,13 +95,44 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len | |||
95 | 95 | ||
96 | int main(int argc, char *argv[]) | 96 | int main(int argc, char *argv[]) |
97 | { | 97 | { |
98 | if (argc < 4 && argc != 2) { | 98 | /* let user override default by cmdline */ |
99 | printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); | 99 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
100 | |||
101 | int argvoffset = 0, argi; | ||
102 | for(argi = 1; argi < argc; argi++) | ||
103 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | ||
104 | if (argv[argi][5] && !argv[argi][6]) { | ||
105 | char c = argv[argi][5]; | ||
106 | if (c == '4') | ||
107 | ipv6enabled = 0; | ||
108 | else if (c == '6') | ||
109 | ipv6enabled = 1; | ||
110 | else { | ||
111 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
112 | exit(1); | ||
113 | } | ||
114 | } | ||
115 | else { | ||
116 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | ||
117 | exit(1); | ||
118 | } | ||
119 | |||
120 | if (argvoffset != argi - 1) { | ||
121 | printf("Argument must come first: %s.\n", argv[argi]); | ||
122 | exit(1); | ||
123 | } | ||
124 | |||
125 | argvoffset++; | ||
126 | } | ||
127 | |||
128 | /* with optional --ipvx, now it can be 1-4 arguments... */ | ||
129 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { | ||
130 | printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]); | ||
131 | printf("or\n"); | ||
132 | printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0], argv[0]); | ||
100 | exit(0); | 133 | exit(0); |
101 | } | 134 | } |
102 | 135 | ||
103 | /* IPv6: maybe allow from cmdline --ipv6? sticking to IPv4 for now */ | ||
104 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | ||
105 | m = initMessenger(ipv6enabled); | 136 | m = initMessenger(ipv6enabled); |
106 | 137 | ||
107 | if ( !m ) { | 138 | if ( !m ) { |
@@ -109,13 +140,19 @@ int main(int argc, char *argv[]) | |||
109 | exit(0); | 140 | exit(0); |
110 | } | 141 | } |
111 | 142 | ||
112 | if (argc > 3) { | 143 | if (argc == argvoffset + 4) { |
113 | uint16_t port = htons(atoi(argv[2])); | 144 | uint16_t port = htons(atoi(argv[argvoffset + 2])); |
114 | DHT_bootstrap_ex(m->dht, argv[1], ipv6enabled, port, hex_string_to_bin(argv[3])); | 145 | uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); |
146 | int res = DHT_bootstrap_ex(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key); | ||
147 | free(bootstrap_key); | ||
148 | if (!res) { | ||
149 | printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); | ||
150 | exit(1); | ||
151 | } | ||
115 | } else { | 152 | } else { |
116 | FILE *file = fopen(argv[1], "rb"); | 153 | FILE *file = fopen(argv[argvoffset + 1], "rb"); |
117 | |||
118 | if ( file == NULL ) { | 154 | if ( file == NULL ) { |
155 | printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]); | ||
119 | return 1; | 156 | return 1; |
120 | } | 157 | } |
121 | 158 | ||