diff options
Diffstat (limited to 'testing/nTox.c')
-rw-r--r-- | testing/nTox.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index 6ac663a6..cbf8d028 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -67,6 +67,55 @@ typedef struct { | |||
67 | Friend_request pending_requests[256]; | 67 | Friend_request pending_requests[256]; |
68 | uint8_t num_requests = 0; | 68 | uint8_t num_requests = 0; |
69 | 69 | ||
70 | #define NUM_FILE_SENDERS 256 | ||
71 | typedef struct { | ||
72 | FILE *file; | ||
73 | uint16_t friendnum; | ||
74 | uint8_t filenumber; | ||
75 | uint8_t nextpiece[1024]; | ||
76 | uint16_t piecelength; | ||
77 | } File_Sender; | ||
78 | File_Sender file_senders[NUM_FILE_SENDERS]; | ||
79 | uint8_t numfilesenders; | ||
80 | |||
81 | void send_filesenders(Tox *m) | ||
82 | { | ||
83 | uint32_t i; | ||
84 | |||
85 | for (i = 0; i < NUM_FILE_SENDERS; ++i) { | ||
86 | if (file_senders[i].file == 0) | ||
87 | continue; | ||
88 | |||
89 | while (1) { | ||
90 | if (!file_data(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece, | ||
91 | file_senders[i].piecelength)) | ||
92 | break; | ||
93 | |||
94 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, 1000, file_senders[i].file); | ||
95 | |||
96 | if (file_senders[i].piecelength == 0) { | ||
97 | fclose(file_senders[i].file); | ||
98 | file_senders[i].file = 0; | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | int add_filesender(Tox *m, uint16_t friendnum, char *filename) | ||
105 | { | ||
106 | file_senders[numfilesenders].file = fopen(filename, "r"); | ||
107 | |||
108 | if (file_senders[numfilesenders].file == 0) | ||
109 | return -1; | ||
110 | |||
111 | file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, 1000, | ||
112 | file_senders[numfilesenders].file); | ||
113 | file_senders[numfilesenders].friendnum = friendnum; | ||
114 | file_senders[numfilesenders].filenumber = numfilesenders; | ||
115 | ++numfilesenders; | ||
116 | return (numfilesenders - 1); | ||
117 | } | ||
118 | |||
70 | /* | 119 | /* |
71 | resolve_addr(): | 120 | resolve_addr(): |
72 | address should represent IPv4 or a hostname with A record | 121 | address should represent IPv4 or a hostname with A record |
@@ -366,6 +415,16 @@ void line_eval(Tox *m, char *line) | |||
366 | tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1)); | 415 | tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1) + 1)); |
367 | new_lines(msg); | 416 | new_lines(msg); |
368 | } | 417 | } |
418 | } else if (inpt_command == 't') { | ||
419 | char msg[512]; | ||
420 | char *posi[1]; | ||
421 | int friendnum = strtoul(line + prompt_offset, posi, 0); | ||
422 | |||
423 | if (**posi != 0) { | ||
424 | sprintf(msg, "[t] Sending file %s to friendnum %u returned %i (-1 means failure)", *posi + 1, friendnum, | ||
425 | add_filesender(m, friendnum, *posi + 1)); | ||
426 | new_lines(msg); | ||
427 | } | ||
369 | } else if (inpt_command == 'q') { //exit | 428 | } else if (inpt_command == 'q') { //exit |
370 | save_data(m); | 429 | save_data(m); |
371 | endwin(); | 430 | endwin(); |
@@ -586,6 +645,15 @@ void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *messag | |||
586 | new_lines(msg); | 645 | new_lines(msg); |
587 | } | 646 | } |
588 | 647 | ||
648 | void write_file(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | ||
649 | { | ||
650 | char filename[256]; | ||
651 | sprintf(filename, "%u.%u.bin", friendnumber, filenumber); | ||
652 | FILE *pFile = fopen(filename, "a"); | ||
653 | fwrite(data, length, 1, pFile); | ||
654 | fclose(pFile); | ||
655 | } | ||
656 | |||
589 | 657 | ||
590 | int main(int argc, char *argv[]) | 658 | int main(int argc, char *argv[]) |
591 | { | 659 | { |
@@ -633,6 +701,7 @@ int main(int argc, char *argv[]) | |||
633 | tox_callback_statusmessage(m, print_statuschange, NULL); | 701 | tox_callback_statusmessage(m, print_statuschange, NULL); |
634 | tox_callback_group_invite(m, print_invite, NULL); | 702 | tox_callback_group_invite(m, print_invite, NULL); |
635 | tox_callback_group_message(m, print_groupmessage, NULL); | 703 | tox_callback_group_message(m, print_groupmessage, NULL); |
704 | callback_file_data(m, write_file, NULL); | ||
636 | 705 | ||
637 | initscr(); | 706 | initscr(); |
638 | noecho(); | 707 | noecho(); |
@@ -668,6 +737,7 @@ int main(int argc, char *argv[]) | |||
668 | } | 737 | } |
669 | 738 | ||
670 | time_t timestamp0 = time(NULL); | 739 | time_t timestamp0 = time(NULL); |
740 | |||
671 | while (1) { | 741 | while (1) { |
672 | if (on == 0) { | 742 | if (on == 0) { |
673 | if (tox_isconnected(m)) { | 743 | if (tox_isconnected(m)) { |
@@ -675,6 +745,7 @@ int main(int argc, char *argv[]) | |||
675 | on = 1; | 745 | on = 1; |
676 | } else { | 746 | } else { |
677 | time_t timestamp1 = time(NULL); | 747 | time_t timestamp1 = time(NULL); |
748 | |||
678 | if (timestamp0 + 10 < timestamp1) { | 749 | if (timestamp0 + 10 < timestamp1) { |
679 | timestamp0 = timestamp1; | 750 | timestamp0 = timestamp1; |
680 | tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string); | 751 | tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string); |
@@ -682,6 +753,7 @@ int main(int argc, char *argv[]) | |||
682 | } | 753 | } |
683 | } | 754 | } |
684 | 755 | ||
756 | send_filesenders(m); | ||
685 | tox_do(m); | 757 | tox_do(m); |
686 | c_sleep(1); | 758 | c_sleep(1); |
687 | do_refresh(); | 759 | do_refresh(); |