summaryrefslogtreecommitdiff
path: root/testing/nTox.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/nTox.c')
-rw-r--r--testing/nTox.c73
1 files changed, 50 insertions, 23 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index 6084aeda..6eeec5d3 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -537,8 +537,40 @@ void print_help(void)
537 537
538int main(int argc, char *argv[]) 538int main(int argc, char *argv[])
539{ 539{
540 /* let use decide by cmdline: TODO */ 540 if (argc < 4) {
541 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 541 printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", argv[0]);
542 exit(0);
543 }
544
545 /* let user override default by cmdline */
546 uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */
547
548 int argvoffset = 0, argi;
549 for(argi = 1; argi < argc; argi++)
550 if (!strncasecmp(argv[argi], "--ipv", 5)) {
551 if (argv[argi][5] && !argv[argi][6]) {
552 char c = argv[argi][5];
553 if (c == '4')
554 ipv6enabled = 0;
555 else if (c == '6')
556 ipv6enabled = 1;
557 else {
558 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
559 exit(1);
560 }
561 }
562 else {
563 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
564 exit(1);
565 }
566
567 if (argvoffset != argi - 1) {
568 printf("Argument must come first: %s.\n", argv[argi]);
569 exit(1);
570 }
571
572 argvoffset++;
573 }
542 574
543 int on = 0; 575 int on = 0;
544 int c = 0; 576 int c = 0;
@@ -547,27 +579,16 @@ int main(int argc, char *argv[])
547 char idstring[200] = {0}; 579 char idstring[200] = {0};
548 Tox *m; 580 Tox *m;
549 581
550 if (argc < 4) { 582 if ((argc == 2) && !strcmp(argv[1], "-h")) {
551 printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); 583 print_help();
552 exit(0); 584 exit(0);
553 } 585 }
554 586
555 for (i = 0; i < argc; i++) { 587 /* [-f keyfile] MUST be last two arguments, no point in walking over the list
556 if (argv[i] == NULL) { 588 * especially not a good idea to accept it anywhere in the middle */
557 break; 589 if (argc > argvoffset + 3)
558 } else if (argv[i][0] == '-') { 590 if (!strcmp(argv[argc - 2], "-f"))
559 if (argv[i][1] == 'h') { 591 filename = argv[argc - 1];
560 print_help();
561 exit(0);
562 } else if (argv[i][1] == 'f') {
563 if (argv[i + 1] != NULL)
564 filename = argv[i + 1];
565 else {
566 fputs("[!] you passed '-f' without giving an argument!\n", stderr);
567 }
568 }
569 }
570 }
571 592
572 m = tox_new_ex(ipv6enabled); 593 m = tox_new_ex(ipv6enabled);
573 594
@@ -593,11 +614,17 @@ int main(int argc, char *argv[])
593 new_lines(idstring); 614 new_lines(idstring);
594 strcpy(line, ""); 615 strcpy(line, "");
595 616
596 uint16_t port = htons(atoi(argv[2])); 617 uint16_t port = htons(atoi(argv[argvoffset + 2]));
597 unsigned char *binary_string = hex_string_to_bin(argv[3]); 618 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
598 tox_bootstrap_ex(m, argv[1], ipv6enabled, port, binary_string); 619 int res = tox_bootstrap_ex(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
599 free(binary_string); 620 free(binary_string);
600 621
622 if (!res) {
623 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
624 endwin();
625 exit(1);
626 }
627
601 nodelay(stdscr, TRUE); 628 nodelay(stdscr, TRUE);
602 while (1) { 629 while (1) {
603 if (on == 0 && tox_isconnected(m)) { 630 if (on == 0 && tox_isconnected(m)) {