diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-31 19:12:19 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-31 20:04:16 +0100 |
commit | 633da98ae69866efb195e00d9a3a22ace6bada66 (patch) | |
tree | 875535f3d2257c4ea5bb97a553b2f1beab4a1590 /testing | |
parent | 6356eb4e4fe407fa7870f2a685d0d08b5c2ec5bb (diff) |
Add braces to all if statements.
Diffstat (limited to 'testing')
-rw-r--r-- | testing/DHT_test.c | 26 | ||||
-rw-r--r-- | testing/Messenger_test.c | 16 | ||||
-rw-r--r-- | testing/av_test.c | 38 | ||||
-rw-r--r-- | testing/dns3_test.c | 22 | ||||
-rw-r--r-- | testing/irc_syncbot.c | 48 | ||||
-rw-r--r-- | testing/misc_tools.c | 12 | ||||
-rw-r--r-- | testing/nTox.c | 147 | ||||
-rw-r--r-- | testing/tox_shell.c | 11 | ||||
-rw-r--r-- | testing/tox_sync.c | 38 |
9 files changed, 232 insertions, 126 deletions
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 91e556c6..cd3ff5f7 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -90,10 +90,11 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours) | |||
90 | 90 | ||
91 | ipp = &assoc->ret_ip_port; | 91 | ipp = &assoc->ret_ip_port; |
92 | 92 | ||
93 | if (ours) | 93 | if (ours) { |
94 | printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 94 | printf("OUR IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); |
95 | else | 95 | } else { |
96 | printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 96 | printf("RET IP: %s Port: %u\n", ip_ntoa(&ipp->ip), ntohs(ipp->port)); |
97 | } | ||
97 | 98 | ||
98 | printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); | 99 | printf("Timestamp: %llu\n", (long long unsigned int) assoc->ret_timestamp); |
99 | print_hardening(&assoc->hardening); | 100 | print_hardening(&assoc->hardening); |
@@ -108,8 +109,9 @@ void print_clientlist(DHT *dht) | |||
108 | for (i = 0; i < LCLIENT_LIST; i++) { | 109 | for (i = 0; i < LCLIENT_LIST; i++) { |
109 | Client_data *client = &dht->close_clientlist[i]; | 110 | Client_data *client = &dht->close_clientlist[i]; |
110 | 111 | ||
111 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) | 112 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { |
112 | continue; | 113 | continue; |
114 | } | ||
113 | 115 | ||
114 | printf("ClientID: "); | 116 | printf("ClientID: "); |
115 | print_client_id(client->public_key); | 117 | print_client_id(client->public_key); |
@@ -139,8 +141,9 @@ void print_friendlist(DHT *dht) | |||
139 | for (i = 0; i < MAX_FRIEND_CLIENTS; i++) { | 141 | for (i = 0; i < MAX_FRIEND_CLIENTS; i++) { |
140 | Client_data *client = &dht->friends_list[k].client_list[i]; | 142 | Client_data *client = &dht->friends_list[k].client_list[i]; |
141 | 143 | ||
142 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) | 144 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { |
143 | continue; | 145 | continue; |
146 | } | ||
144 | 147 | ||
145 | printf("ClientID: "); | 148 | printf("ClientID: "); |
146 | print_client_id(client->public_key); | 149 | print_client_id(client->public_key); |
@@ -158,8 +161,9 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | |||
158 | printf("--------------------BEGIN-----------------------------\n"); | 161 | printf("--------------------BEGIN-----------------------------\n"); |
159 | 162 | ||
160 | for (i = 0; i < length; i++) { | 163 | for (i = 0; i < length; i++) { |
161 | if (data[i] < 16) | 164 | if (data[i] < 16) { |
162 | printf("0"); | 165 | printf("0"); |
166 | } | ||
163 | 167 | ||
164 | printf("%hhX", data[i]); | 168 | printf("%hhX", data[i]); |
165 | } | 169 | } |
@@ -178,8 +182,9 @@ int main(int argc, char *argv[]) | |||
178 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ | 182 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
179 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 183 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
180 | 184 | ||
181 | if (argvoffset < 0) | 185 | if (argvoffset < 0) { |
182 | exit(1); | 186 | exit(1); |
187 | } | ||
183 | 188 | ||
184 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); | 189 | //memcpy(self_client_id, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq", 32); |
185 | /* initialize networking */ | 190 | /* initialize networking */ |
@@ -192,8 +197,9 @@ int main(int argc, char *argv[]) | |||
192 | uint32_t i; | 197 | uint32_t i; |
193 | 198 | ||
194 | for (i = 0; i < 32; i++) { | 199 | for (i = 0; i < 32; i++) { |
195 | if (dht->self_public_key[i] < 16) | 200 | if (dht->self_public_key[i] < 16) { |
196 | printf("0"); | 201 | printf("0"); |
202 | } | ||
197 | 203 | ||
198 | printf("%hhX", dht->self_public_key[i]); | 204 | printf("%hhX", dht->self_public_key[i]); |
199 | } | 205 | } |
@@ -201,11 +207,13 @@ int main(int argc, char *argv[]) | |||
201 | char temp_id[128]; | 207 | char temp_id[128]; |
202 | printf("\nEnter the public_key of the friend you wish to add (32 bytes HEX format):\n"); | 208 | printf("\nEnter the public_key of the friend you wish to add (32 bytes HEX format):\n"); |
203 | 209 | ||
204 | if (!fgets(temp_id, sizeof(temp_id), stdin)) | 210 | if (!fgets(temp_id, sizeof(temp_id), stdin)) { |
205 | exit(0); | 211 | exit(0); |
212 | } | ||
206 | 213 | ||
207 | if ((strlen(temp_id) > 0) && (temp_id[strlen(temp_id) - 1] == '\n')) | 214 | if ((strlen(temp_id) > 0) && (temp_id[strlen(temp_id) - 1] == '\n')) { |
208 | temp_id[strlen(temp_id) - 1] = '\0'; | 215 | temp_id[strlen(temp_id) - 1] = '\0'; |
216 | } | ||
209 | 217 | ||
210 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 218 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
211 | DHT_addfriend(dht, bin_id, 0, 0, 0, 0); | 219 | DHT_addfriend(dht, bin_id, 0, 0, 0, 0); |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index e39a1182..f31052e3 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -74,8 +74,9 @@ void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, | |||
74 | uint32_t j; | 74 | uint32_t j; |
75 | 75 | ||
76 | for (j = 0; j < 32; j++) { | 76 | for (j = 0; j < 32; j++) { |
77 | if (public_key[j] < 16) | 77 | if (public_key[j] < 16) { |
78 | printf("0"); | 78 | printf("0"); |
79 | } | ||
79 | 80 | ||
80 | printf("%hhX", public_key[j]); | 81 | printf("%hhX", public_key[j]); |
81 | } | 82 | } |
@@ -100,8 +101,9 @@ int main(int argc, char *argv[]) | |||
100 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ | 101 | uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ |
101 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 102 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
102 | 103 | ||
103 | if (argvoffset < 0) | 104 | if (argvoffset < 0) { |
104 | exit(1); | 105 | exit(1); |
106 | } | ||
105 | 107 | ||
106 | /* with optional --ipvx, now it can be 1-4 arguments... */ | 108 | /* with optional --ipvx, now it can be 1-4 arguments... */ |
107 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { | 109 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { |
@@ -156,8 +158,9 @@ int main(int argc, char *argv[]) | |||
156 | getaddress(m, address); | 158 | getaddress(m, address); |
157 | 159 | ||
158 | for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { | 160 | for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { |
159 | if (address[i] < 16) | 161 | if (address[i] < 16) { |
160 | printf("0"); | 162 | printf("0"); |
163 | } | ||
161 | 164 | ||
162 | printf("%hhX", address[i]); | 165 | printf("%hhX", address[i]); |
163 | } | 166 | } |
@@ -167,12 +170,13 @@ int main(int argc, char *argv[]) | |||
167 | char temp_hex_id[128]; | 170 | char temp_hex_id[128]; |
168 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); | 171 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); |
169 | 172 | ||
170 | if (!fgets(temp_hex_id, sizeof(temp_hex_id), stdin)) | 173 | if (!fgets(temp_hex_id, sizeof(temp_hex_id), stdin)) { |
171 | exit(0); | 174 | exit(0); |
175 | } | ||
172 | 176 | ||
173 | if ((strlen(temp_hex_id) > 0) && (temp_hex_id[strlen(temp_hex_id) - 1] == '\n')) | 177 | if ((strlen(temp_hex_id) > 0) && (temp_hex_id[strlen(temp_hex_id) - 1] == '\n')) { |
174 | temp_hex_id[strlen(temp_hex_id) - 1] = '\0'; | 178 | temp_hex_id[strlen(temp_hex_id) - 1] = '\0'; |
175 | 179 | } | |
176 | 180 | ||
177 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); | 181 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); |
178 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 182 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); |
diff --git a/testing/av_test.c b/testing/av_test.c index 7c2922b7..e724bb0e 100644 --- a/testing/av_test.c +++ b/testing/av_test.c | |||
@@ -258,8 +258,9 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA | |||
258 | } | 258 | } |
259 | 259 | ||
260 | if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP && | 260 | if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP && |
261 | tox_friend_get_connection_status(Bob, 0, NULL) == TOX_CONNECTION_UDP) | 261 | tox_friend_get_connection_status(Bob, 0, NULL) == TOX_CONNECTION_UDP) { |
262 | break; | 262 | break; |
263 | } | ||
263 | 264 | ||
264 | c_sleep(20); | 265 | c_sleep(20); |
265 | } | 266 | } |
@@ -316,8 +317,9 @@ void *iterate_toxav (void *data) | |||
316 | 317 | ||
317 | #if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 | 318 | #if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 |
318 | 319 | ||
319 | if (!rc) | 320 | if (!rc) { |
320 | rc = 1; | 321 | rc = 1; |
322 | } | ||
321 | 323 | ||
322 | cvWaitKey(rc); | 324 | cvWaitKey(rc); |
323 | #else | 325 | #else |
@@ -379,8 +381,9 @@ int print_audio_devices() | |||
379 | for (i = 0; i < Pa_GetDeviceCount(); ++i) { | 381 | for (i = 0; i < Pa_GetDeviceCount(); ++i) { |
380 | const PaDeviceInfo *info = Pa_GetDeviceInfo(i); | 382 | const PaDeviceInfo *info = Pa_GetDeviceInfo(i); |
381 | 383 | ||
382 | if (info) | 384 | if (info) { |
383 | printf("%d) %s\n", i, info->name); | 385 | printf("%d) %s\n", i, info->name); |
386 | } | ||
384 | } | 387 | } |
385 | 388 | ||
386 | return 0; | 389 | return 0; |
@@ -498,8 +501,9 @@ CHECK_ARG: | |||
498 | } | 501 | } |
499 | } | 502 | } |
500 | 503 | ||
501 | if (audio_out_dev_idx < 0) | 504 | if (audio_out_dev_idx < 0) { |
502 | audio_out_dev_idx = Pa_GetDefaultOutputDevice(); | 505 | audio_out_dev_idx = Pa_GetDefaultOutputDevice(); |
506 | } | ||
503 | 507 | ||
504 | const PaDeviceInfo *audio_dev = Pa_GetDeviceInfo(audio_out_dev_idx); | 508 | const PaDeviceInfo *audio_dev = Pa_GetDeviceInfo(audio_out_dev_idx); |
505 | 509 | ||
@@ -548,8 +552,9 @@ CHECK_ARG: | |||
548 | } | 552 | } |
549 | } | 553 | } |
550 | 554 | ||
551 | while (!BobCC.incoming) | 555 | while (!BobCC.incoming) { |
552 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 556 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); |
557 | } | ||
553 | 558 | ||
554 | { /* Answer */ | 559 | { /* Answer */ |
555 | TOXAV_ERR_ANSWER rc; | 560 | TOXAV_ERR_ANSWER rc; |
@@ -561,8 +566,9 @@ CHECK_ARG: | |||
561 | } | 566 | } |
562 | } | 567 | } |
563 | 568 | ||
564 | while (AliceCC.state == 0) | 569 | while (AliceCC.state == 0) { |
565 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 570 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); |
571 | } | ||
566 | 572 | ||
567 | /* Open audio file */ | 573 | /* Open audio file */ |
568 | af_handle = sf_open(af_name, SFM_READ, &af_info); | 574 | af_handle = sf_open(af_name, SFM_READ, &af_info); |
@@ -627,7 +633,7 @@ CHECK_ARG: | |||
627 | } | 633 | } |
628 | 634 | ||
629 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 635 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); |
630 | c_sleep(abs(audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1)); | 636 | c_sleep((audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1)); |
631 | } | 637 | } |
632 | 638 | ||
633 | printf("Played file in: %lu; stopping stream...\n", time(NULL) - start_time); | 639 | printf("Played file in: %lu; stopping stream...\n", time(NULL) - start_time); |
@@ -651,19 +657,22 @@ CHECK_ARG: | |||
651 | /* Stop decode thread */ | 657 | /* Stop decode thread */ |
652 | data.sig = -1; | 658 | data.sig = -1; |
653 | 659 | ||
654 | while (data.sig != 1) | 660 | while (data.sig != 1) { |
655 | pthread_yield(); | 661 | pthread_yield(); |
662 | } | ||
656 | 663 | ||
657 | pthread_mutex_destroy(AliceCC.arb_mutex); | 664 | pthread_mutex_destroy(AliceCC.arb_mutex); |
658 | pthread_mutex_destroy(BobCC.arb_mutex); | 665 | pthread_mutex_destroy(BobCC.arb_mutex); |
659 | 666 | ||
660 | void *f = NULL; | 667 | void *f = NULL; |
661 | 668 | ||
662 | while (rb_read(AliceCC.arb, &f)) | 669 | while (rb_read(AliceCC.arb, &f)) { |
663 | free(f); | 670 | free(f); |
671 | } | ||
664 | 672 | ||
665 | while (rb_read(BobCC.arb, &f)) | 673 | while (rb_read(BobCC.arb, &f)) { |
666 | free(f); | 674 | free(f); |
675 | } | ||
667 | 676 | ||
668 | printf("Success!"); | 677 | printf("Success!"); |
669 | } | 678 | } |
@@ -684,8 +693,9 @@ CHECK_ARG: | |||
684 | } | 693 | } |
685 | } | 694 | } |
686 | 695 | ||
687 | while (!BobCC.incoming) | 696 | while (!BobCC.incoming) { |
688 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 697 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); |
698 | } | ||
689 | 699 | ||
690 | { /* Answer */ | 700 | { /* Answer */ |
691 | TOXAV_ERR_ANSWER rc; | 701 | TOXAV_ERR_ANSWER rc; |
@@ -724,8 +734,9 @@ CHECK_ARG: | |||
724 | while (start_time + 90 > time(NULL)) { | 734 | while (start_time + 90 > time(NULL)) { |
725 | IplImage *frame = cvQueryFrame(capture ); | 735 | IplImage *frame = cvQueryFrame(capture ); |
726 | 736 | ||
727 | if (!frame) | 737 | if (!frame) { |
728 | break; | 738 | break; |
739 | } | ||
729 | 740 | ||
730 | send_opencv_img(AliceAV, 0, frame); | 741 | send_opencv_img(AliceAV, 0, frame); |
731 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); | 742 | iterate_tox(bootstrap, AliceAV, BobAV, NULL); |
@@ -751,8 +762,9 @@ CHECK_ARG: | |||
751 | printf("Stopping decode thread\n"); | 762 | printf("Stopping decode thread\n"); |
752 | data.sig = -1; | 763 | data.sig = -1; |
753 | 764 | ||
754 | while (data.sig != 1) | 765 | while (data.sig != 1) { |
755 | pthread_yield(); | 766 | pthread_yield(); |
767 | } | ||
756 | 768 | ||
757 | printf("Success!"); | 769 | printf("Success!"); |
758 | } | 770 | } |
diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 1f6c6a12..975bc17b 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c | |||
@@ -54,11 +54,13 @@ int main(int argc, char *argv[]) | |||
54 | ip.family = AF_INET; | 54 | ip.family = AF_INET; |
55 | sock_t sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP); | 55 | sock_t sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP); |
56 | 56 | ||
57 | if (!sock_valid(sock)) | 57 | if (!sock_valid(sock)) { |
58 | return -1; | 58 | return -1; |
59 | } | ||
59 | 60 | ||
60 | if (!addr_resolve_or_parse_ip(argv[1], &ip, 0)) | 61 | if (!addr_resolve_or_parse_ip(argv[1], &ip, 0)) { |
61 | return -1; | 62 | return -1; |
63 | } | ||
62 | 64 | ||
63 | struct sockaddr_in target; | 65 | struct sockaddr_in target; |
64 | size_t addrsize = sizeof(struct sockaddr_in); | 66 | size_t addrsize = sizeof(struct sockaddr_in); |
@@ -77,8 +79,9 @@ int main(int argc, char *argv[]) | |||
77 | }*/ | 79 | }*/ |
78 | int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); | 80 | int len = tox_generate_dns3_string(d, string + 1, sizeof(string) - 1, &request_id, (uint8_t *)argv[3], strlen(argv[3])); |
79 | 81 | ||
80 | if (len == -1) | 82 | if (len == -1) { |
81 | return -1; | 83 | return -1; |
84 | } | ||
82 | 85 | ||
83 | string[0] = '_'; | 86 | string[0] = '_'; |
84 | memcpy(string + len + 1, "._tox.", sizeof("._tox.")); | 87 | memcpy(string + len + 1, "._tox.", sizeof("._tox.")); |
@@ -87,21 +90,26 @@ int main(int argc, char *argv[]) | |||
87 | uint8_t id = rand(); | 90 | uint8_t id = rand(); |
88 | uint32_t p_len = create_packet(packet, string, strlen((char *)string), id); | 91 | uint32_t p_len = create_packet(packet, string, strlen((char *)string), id); |
89 | 92 | ||
90 | if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) | 93 | if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len) { |
91 | return -1; | 94 | return -1; |
95 | } | ||
92 | 96 | ||
93 | uint8_t buffer[512] = {}; | 97 | uint8_t buffer[512] = {}; |
94 | int r_len = recv(sock, buffer, sizeof(buffer), 0); | 98 | int r_len = recv(sock, buffer, sizeof(buffer), 0); |
95 | 99 | ||
96 | if (r_len < (int)p_len) | 100 | if (r_len < (int)p_len) { |
97 | return -1; | 101 | return -1; |
102 | } | ||
98 | 103 | ||
99 | for (i = r_len - 1; i != 0 && buffer[i] != '='; --i); | 104 | for (i = r_len - 1; i != 0 && buffer[i] != '='; --i) { |
105 | ; | ||
106 | } | ||
100 | 107 | ||
101 | uint8_t tox_id[TOX_ADDRESS_SIZE]; | 108 | uint8_t tox_id[TOX_ADDRESS_SIZE]; |
102 | 109 | ||
103 | if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0) | 110 | if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0) { |
104 | return -1; | 111 | return -1; |
112 | } | ||
105 | 113 | ||
106 | printf("The Tox id for username %s is:\n", argv[3]); | 114 | printf("The Tox id for username %s is:\n", argv[3]); |
107 | 115 | ||
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index 8ee28d80..01e557d5 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c | |||
@@ -85,16 +85,18 @@ int current_group = -1; | |||
85 | 85 | ||
86 | static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) | 86 | static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) |
87 | { | 87 | { |
88 | if (current_group == -1) | 88 | if (current_group == -1) { |
89 | current_group = tox_join_groupchat(tox, fid, data, length); | 89 | current_group = tox_join_groupchat(tox, fid, data, length); |
90 | } | ||
90 | } | 91 | } |
91 | 92 | ||
92 | void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, | 93 | void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, |
93 | void *userdata) | 94 | void *userdata) |
94 | { | 95 | { |
95 | if (length == 1 && *message == 'c') { | 96 | if (length == 1 && *message == 'c') { |
96 | if (tox_del_groupchat(tox, current_group) == 0) | 97 | if (tox_del_groupchat(tox, current_group) == 0) { |
97 | current_group = -1; | 98 | current_group = -1; |
99 | } | ||
98 | } | 100 | } |
99 | 101 | ||
100 | if (length == 1 && *message == 'i') { | 102 | if (length == 1 && *message == 'i') { |
@@ -109,8 +111,9 @@ void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, cons | |||
109 | static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t *message, uint16_t length, | 111 | static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t *message, uint16_t length, |
110 | void *userdata) | 112 | void *userdata) |
111 | { | 113 | { |
112 | if (tox_group_peernumber_is_ours(tox, groupnumber, friendgroupnumber)) | 114 | if (tox_group_peernumber_is_ours(tox, groupnumber, friendgroupnumber)) { |
113 | return; | 115 | return; |
116 | } | ||
114 | 117 | ||
115 | uint8_t name[TOX_MAX_NAME_LENGTH]; | 118 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
116 | int namelen = tox_group_peername(tox, groupnumber, friendgroupnumber, name); | 119 | int namelen = tox_group_peername(tox, groupnumber, friendgroupnumber, name); |
@@ -136,29 +139,34 @@ static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, | |||
136 | unsigned int i; | 139 | unsigned int i; |
137 | 140 | ||
138 | for (i = 0; i < send_len; ++i) { | 141 | for (i = 0; i < send_len; ++i) { |
139 | if (sendbuf[i] == '\n') | 142 | if (sendbuf[i] == '\n') { |
140 | sendbuf[i] = '|'; | 143 | sendbuf[i] = '|'; |
144 | } | ||
141 | 145 | ||
142 | if (sendbuf[i] == 0) | 146 | if (sendbuf[i] == 0) { |
143 | sendbuf[i] = ' '; | 147 | sendbuf[i] = ' '; |
148 | } | ||
144 | } | 149 | } |
145 | 150 | ||
146 | sendbuf[send_len] = '\n'; | 151 | sendbuf[send_len] = '\n'; |
147 | send_len += 1; | 152 | send_len += 1; |
148 | 153 | ||
149 | if (sock >= 0) | 154 | if (sock >= 0) { |
150 | send(sock, sendbuf, send_len, MSG_NOSIGNAL); | 155 | send(sock, sendbuf, send_len, MSG_NOSIGNAL); |
156 | } | ||
151 | } | 157 | } |
152 | 158 | ||
153 | void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | 159 | void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) |
154 | { | 160 | { |
155 | if (len > 1350 || len == 0 || len == 1) | 161 | if (len > 1350 || len == 0 || len == 1) { |
156 | return; | 162 | return; |
163 | } | ||
157 | 164 | ||
158 | --len; | 165 | --len; |
159 | 166 | ||
160 | if (*msg != ':') | 167 | if (*msg != ':') { |
161 | return; | 168 | return; |
169 | } | ||
162 | 170 | ||
163 | uint8_t req[len]; | 171 | uint8_t req[len]; |
164 | unsigned int i; | 172 | unsigned int i; |
@@ -185,8 +193,9 @@ void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | |||
185 | 193 | ||
186 | uint8_t *pmsg = (uint8_t *)strstr((char *)req, " PRIVMSG"); | 194 | uint8_t *pmsg = (uint8_t *)strstr((char *)req, " PRIVMSG"); |
187 | 195 | ||
188 | if (pmsg == NULL) | 196 | if (pmsg == NULL) { |
189 | return; | 197 | return; |
198 | } | ||
190 | 199 | ||
191 | uint8_t *dt; | 200 | uint8_t *dt; |
192 | 201 | ||
@@ -200,8 +209,9 @@ void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | |||
200 | message[length] = ' '; | 209 | message[length] = ' '; |
201 | length += 1; | 210 | length += 1; |
202 | 211 | ||
203 | if ((req_len + 2) >= len) | 212 | if ((req_len + 2) >= len) { |
204 | return; | 213 | return; |
214 | } | ||
205 | 215 | ||
206 | memcpy(message + length, msg + req_len + 2, len - (req_len + 2)); | 216 | memcpy(message + length, msg + req_len + 2, len - (req_len + 2)); |
207 | length += len - (req_len + 2); | 217 | length += len - (req_len + 2); |
@@ -213,8 +223,9 @@ Tox *init_tox(int argc, char *argv[]) | |||
213 | uint8_t ipv6enabled = 1; /* x */ | 223 | uint8_t ipv6enabled = 1; /* x */ |
214 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 224 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
215 | 225 | ||
216 | if (argvoffset < 0) | 226 | if (argvoffset < 0) { |
217 | exit(1); | 227 | exit(1); |
228 | } | ||
218 | 229 | ||
219 | /* with optional --ipvx, now it can be 1-4 arguments... */ | 230 | /* with optional --ipvx, now it can be 1-4 arguments... */ |
220 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { | 231 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { |
@@ -224,8 +235,9 @@ Tox *init_tox(int argc, char *argv[]) | |||
224 | 235 | ||
225 | Tox *tox = tox_new(0, 0); | 236 | Tox *tox = tox_new(0, 0); |
226 | 237 | ||
227 | if (!tox) | 238 | if (!tox) { |
228 | exit(1); | 239 | exit(1); |
240 | } | ||
229 | 241 | ||
230 | tox_self_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); | 242 | tox_self_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); |
231 | tox_callback_friend_message(tox, &callback_friend_message); | 243 | tox_callback_friend_message(tox, &callback_friend_message); |
@@ -263,8 +275,9 @@ int main(int argc, char *argv[]) | |||
263 | 275 | ||
264 | sock = reconnect(); | 276 | sock = reconnect(); |
265 | 277 | ||
266 | if (sock < 0) | 278 | if (sock < 0) { |
267 | return 1; | 279 | return 1; |
280 | } | ||
268 | 281 | ||
269 | uint64_t last_get = get_monotime_sec(); | 282 | uint64_t last_get = get_monotime_sec(); |
270 | int connected = 0, ping_sent = 0; | 283 | int connected = 0, ping_sent = 0; |
@@ -281,8 +294,9 @@ int main(int argc, char *argv[]) | |||
281 | recv(sock, data, count, MSG_NOSIGNAL); | 294 | recv(sock, data, count, MSG_NOSIGNAL); |
282 | printf("%s", data); | 295 | printf("%s", data); |
283 | 296 | ||
284 | if (!connected) | 297 | if (!connected) { |
285 | connected = 1; | 298 | connected = 1; |
299 | } | ||
286 | 300 | ||
287 | if (count > 6 && data[0] == 'P' && data[1] == 'I' && data[2] == 'N' && data[3] == 'G') { | 301 | if (count > 6 && data[0] == 'P' && data[1] == 'I' && data[2] == 'N' && data[3] == 'G') { |
288 | data[1] = 'O'; | 302 | data[1] = 'O'; |
@@ -309,8 +323,9 @@ int main(int argc, char *argv[]) | |||
309 | break; | 323 | break; |
310 | } | 324 | } |
311 | 325 | ||
312 | if (data[i] == ':') | 326 | if (data[i] == ':') { |
313 | break; | 327 | break; |
328 | } | ||
314 | } | 329 | } |
315 | 330 | ||
316 | for (i = 0; i < count; ++i) { | 331 | for (i = 0; i < count; ++i) { |
@@ -329,8 +344,9 @@ int main(int argc, char *argv[]) | |||
329 | if (!ping_sent && last_get + (SILENT_TIMEOUT / 2) < get_monotime_sec()) { | 344 | if (!ping_sent && last_get + (SILENT_TIMEOUT / 2) < get_monotime_sec()) { |
330 | unsigned int p_s = sizeof("PING :test\n") - 1; | 345 | unsigned int p_s = sizeof("PING :test\n") - 1; |
331 | 346 | ||
332 | if (send(sock, "PING :test\n", p_s, MSG_NOSIGNAL) == p_s) | 347 | if (send(sock, "PING :test\n", p_s, MSG_NOSIGNAL) == p_s) { |
333 | ping_sent = 1; | 348 | ping_sent = 1; |
349 | } | ||
334 | } | 350 | } |
335 | 351 | ||
336 | int error = 0; | 352 | int error = 0; |
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 52b739dc..ba49ebc8 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -46,8 +46,9 @@ uint8_t *hex_string_to_bin(char *hex_string) | |||
46 | uint8_t *ret = malloc(len); | 46 | uint8_t *ret = malloc(len); |
47 | char *pos = hex_string; | 47 | char *pos = hex_string; |
48 | 48 | ||
49 | for (i = 0; i < len; ++i, pos += 2) | 49 | for (i = 0; i < len; ++i, pos += 2) { |
50 | sscanf(pos, "%2hhx", &ret[i]); | 50 | sscanf(pos, "%2hhx", &ret[i]); |
51 | } | ||
51 | 52 | ||
52 | return ret; | 53 | return ret; |
53 | } | 54 | } |
@@ -56,16 +57,16 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) | |||
56 | { | 57 | { |
57 | int argvoffset = 0, argi; | 58 | int argvoffset = 0, argi; |
58 | 59 | ||
59 | for (argi = 1; argi < argc; argi++) | 60 | for (argi = 1; argi < argc; argi++) { |
60 | if (!strncasecmp(argv[argi], "--ipv", 5)) { | 61 | if (!strncasecmp(argv[argi], "--ipv", 5)) { |
61 | if (argv[argi][5] && !argv[argi][6]) { | 62 | if (argv[argi][5] && !argv[argi][6]) { |
62 | char c = argv[argi][5]; | 63 | char c = argv[argi][5]; |
63 | 64 | ||
64 | if (c == '4') | 65 | if (c == '4') { |
65 | *ipv6enabled = 0; | 66 | *ipv6enabled = 0; |
66 | else if (c == '6') | 67 | } else if (c == '6') { |
67 | *ipv6enabled = 1; | 68 | *ipv6enabled = 1; |
68 | else { | 69 | } else { |
69 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); | 70 | printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]); |
70 | return -1; | 71 | return -1; |
71 | } | 72 | } |
@@ -81,6 +82,7 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) | |||
81 | 82 | ||
82 | argvoffset++; | 83 | argvoffset++; |
83 | } | 84 | } |
85 | } | ||
84 | 86 | ||
85 | return argvoffset; | 87 | return argvoffset; |
86 | }; | 88 | }; |
diff --git a/testing/nTox.c b/testing/nTox.c index 8cc633bc..3494015c 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -152,8 +152,9 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
152 | { | 152 | { |
153 | FILE *tempfile = fopen(filename, "rb"); | 153 | FILE *tempfile = fopen(filename, "rb"); |
154 | 154 | ||
155 | if (tempfile == 0) | 155 | if (tempfile == 0) { |
156 | return -1; | 156 | return -1; |
157 | } | ||
157 | 158 | ||
158 | fseek(tempfile, 0, SEEK_END); | 159 | fseek(tempfile, 0, SEEK_END); |
159 | uint64_t filesize = ftell(tempfile); | 160 | uint64_t filesize = ftell(tempfile); |
@@ -161,8 +162,9 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
161 | uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, 0, (uint8_t *)filename, | 162 | uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, 0, (uint8_t *)filename, |
162 | strlen(filename), 0); | 163 | strlen(filename), 0); |
163 | 164 | ||
164 | if (filenum == -1) | 165 | if (filenum == -1) { |
165 | return -1; | 166 | return -1; |
167 | } | ||
166 | 168 | ||
167 | file_senders[numfilesenders].file = tempfile; | 169 | file_senders[numfilesenders].file = tempfile; |
168 | file_senders[numfilesenders].friendnum = friendnum; | 170 | file_senders[numfilesenders].friendnum = friendnum; |
@@ -183,11 +185,13 @@ static void fraddr_to_str(uint8_t *id_bin, char *id_str) | |||
183 | for (i = 0; i < TOX_ADDRESS_SIZE; i++) { | 185 | for (i = 0; i < TOX_ADDRESS_SIZE; i++) { |
184 | sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]); | 186 | sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]); |
185 | 187 | ||
186 | if ((i + 1) == TOX_PUBLIC_KEY_SIZE) | 188 | if ((i + 1) == TOX_PUBLIC_KEY_SIZE) { |
187 | pos_extra = 2 * (i + 1) + delta; | 189 | pos_extra = 2 * (i + 1) + delta; |
190 | } | ||
188 | 191 | ||
189 | if (i >= TOX_PUBLIC_KEY_SIZE) | 192 | if (i >= TOX_PUBLIC_KEY_SIZE) { |
190 | sum_extra |= id_bin[i]; | 193 | sum_extra |= id_bin[i]; |
194 | } | ||
191 | 195 | ||
192 | if (!((i + 1) % FRADDR_TOSTR_CHUNK_LEN)) { | 196 | if (!((i + 1) % FRADDR_TOSTR_CHUNK_LEN)) { |
193 | id_str[2 * (i + 1) + delta] = ' '; | 197 | id_str[2 * (i + 1) + delta] = ' '; |
@@ -197,8 +201,9 @@ static void fraddr_to_str(uint8_t *id_bin, char *id_str) | |||
197 | 201 | ||
198 | id_str[2 * i + delta] = 0; | 202 | id_str[2 * i + delta] = 0; |
199 | 203 | ||
200 | if (!sum_extra) | 204 | if (!sum_extra) { |
201 | id_str[pos_extra] = 0; | 205 | id_str[pos_extra] = 0; |
206 | } | ||
202 | } | 207 | } |
203 | 208 | ||
204 | void get_id(Tox *m, char *data) | 209 | void get_id(Tox *m, char *data) |
@@ -215,10 +220,11 @@ int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) | |||
215 | tox_friend_get_name(m, friendnum, (uint8_t *)namebuf, NULL); | 220 | tox_friend_get_name(m, friendnum, (uint8_t *)namebuf, NULL); |
216 | int res = tox_friend_get_name_size(m, friendnum, NULL); | 221 | int res = tox_friend_get_name_size(m, friendnum, NULL); |
217 | 222 | ||
218 | if (res >= 0) | 223 | if (res >= 0) { |
219 | namebuf[res] = 0; | 224 | namebuf[res] = 0; |
220 | else | 225 | } else { |
221 | namebuf[0] = 0; | 226 | namebuf[0] = 0; |
227 | } | ||
222 | 228 | ||
223 | return res; | 229 | return res; |
224 | } | 230 | } |
@@ -260,10 +266,11 @@ void print_friendlist(Tox *m) | |||
260 | uint32_t i = 0; | 266 | uint32_t i = 0; |
261 | 267 | ||
262 | while (getfriendname_terminated(m, i, name) != -1) { | 268 | while (getfriendname_terminated(m, i, name) != -1) { |
263 | if (tox_friend_get_public_key(m, i, fraddr_bin, NULL)) | 269 | if (tox_friend_get_public_key(m, i, fraddr_bin, NULL)) { |
264 | fraddr_to_str(fraddr_bin, fraddr_str); | 270 | fraddr_to_str(fraddr_bin, fraddr_str); |
265 | else | 271 | } else { |
266 | sprintf(fraddr_str, "???"); | 272 | sprintf(fraddr_str, "???"); |
273 | } | ||
267 | 274 | ||
268 | if (strlen(name) <= 0) { | 275 | if (strlen(name) <= 0) { |
269 | sprintf(fstring, ptrn_friend, i, "No name?", fraddr_str); | 276 | sprintf(fstring, ptrn_friend, i, "No name?", fraddr_str); |
@@ -275,8 +282,9 @@ void print_friendlist(Tox *m) | |||
275 | new_lines(fstring); | 282 | new_lines(fstring); |
276 | } | 283 | } |
277 | 284 | ||
278 | if (i == 0) | 285 | if (i == 0) { |
279 | new_lines("+ no friends! D:"); | 286 | new_lines("+ no friends! D:"); |
287 | } | ||
280 | } | 288 | } |
281 | 289 | ||
282 | static int fmtmsg_tm_mday = -1; | 290 | static int fmtmsg_tm_mday = -1; |
@@ -338,8 +346,9 @@ void line_eval(Tox *m, char *line) | |||
338 | for (i = 0; i < 128; i++) { | 346 | for (i = 0; i < 128; i++) { |
339 | temp_id[i - delta] = line[i + prompt_offset]; | 347 | temp_id[i - delta] = line[i + prompt_offset]; |
340 | 348 | ||
341 | if ((temp_id[i - delta] == ' ') || (temp_id[i - delta] == '+')) | 349 | if ((temp_id[i - delta] == ' ') || (temp_id[i - delta] == '+')) { |
342 | delta++; | 350 | delta++; |
351 | } | ||
343 | } | 352 | } |
344 | 353 | ||
345 | unsigned char *bin_string = hex_string_to_bin(temp_id); | 354 | unsigned char *bin_string = hex_string_to_bin(temp_id); |
@@ -402,14 +411,17 @@ void line_eval(Tox *m, char *line) | |||
402 | } else { | 411 | } else { |
403 | print_formatted_message(m, *posi + 1, num, 1); | 412 | print_formatted_message(m, *posi + 1, num, 1); |
404 | } | 413 | } |
405 | } else | 414 | } else { |
406 | new_lines("Error, bad input."); | 415 | new_lines("Error, bad input."); |
416 | } | ||
407 | } else if (inpt_command == 'n') { | 417 | } else if (inpt_command == 'n') { |
408 | uint8_t name[TOX_MAX_NAME_LENGTH]; | 418 | uint8_t name[TOX_MAX_NAME_LENGTH]; |
409 | size_t i, len = strlen(line); | 419 | size_t i, len = strlen(line); |
410 | 420 | ||
411 | for (i = 3; i < len; i++) { | 421 | for (i = 3; i < len; i++) { |
412 | if (line[i] == 0 || line[i] == '\n') break; | 422 | if (line[i] == 0 || line[i] == '\n') { |
423 | break; | ||
424 | } | ||
413 | 425 | ||
414 | name[i - 3] = line[i]; | 426 | name[i - 3] = line[i]; |
415 | } | 427 | } |
@@ -426,7 +438,9 @@ void line_eval(Tox *m, char *line) | |||
426 | size_t i, len = strlen(line); | 438 | size_t i, len = strlen(line); |
427 | 439 | ||
428 | for (i = 3; i < len; i++) { | 440 | for (i = 3; i < len; i++) { |
429 | if (line[i] == 0 || line[i] == '\n') break; | 441 | if (line[i] == 0 || line[i] == '\n') { |
442 | break; | ||
443 | } | ||
430 | 444 | ||
431 | status[i - 3] = line[i]; | 445 | status[i - 3] = line[i]; |
432 | } | 446 | } |
@@ -482,10 +496,11 @@ void line_eval(Tox *m, char *line) | |||
482 | if (c == 'y') { | 496 | if (c == 'y') { |
483 | int res = tox_friend_delete(m, numf, NULL); | 497 | int res = tox_friend_delete(m, numf, NULL); |
484 | 498 | ||
485 | if (res) | 499 | if (res) { |
486 | sprintf(msg, "[i] [%i: %s] is no longer your friend", numf, fname); | 500 | sprintf(msg, "[i] [%i: %s] is no longer your friend", numf, fname); |
487 | else | 501 | } else { |
488 | sprintf(msg, "[i] failed to remove friend"); | 502 | sprintf(msg, "[i] failed to remove friend"); |
503 | } | ||
489 | 504 | ||
490 | new_lines(msg); | 505 | new_lines(msg); |
491 | } | 506 | } |
@@ -555,20 +570,22 @@ void line_eval(Tox *m, char *line) | |||
555 | if (conversation_default != 0) { | 570 | if (conversation_default != 0) { |
556 | conversation_default = 0; | 571 | conversation_default = 0; |
557 | new_lines("[i] default conversation reset"); | 572 | new_lines("[i] default conversation reset"); |
558 | } else | 573 | } else { |
559 | new_lines("[i] default conversation wasn't set, nothing to do"); | 574 | new_lines("[i] default conversation wasn't set, nothing to do"); |
575 | } | ||
560 | } else if (line[3] != ' ') { | 576 | } else if (line[3] != ' ') { |
561 | new_lines("[i] invalid command"); | 577 | new_lines("[i] invalid command"); |
562 | } else { | 578 | } else { |
563 | int num = atoi(line + 4); | 579 | int num = atoi(line + 4); |
564 | 580 | ||
565 | /* zero is also returned for not-a-number */ | 581 | /* zero is also returned for not-a-number */ |
566 | if (!num && strcmp(line + 4, "0")) | 582 | if (!num && strcmp(line + 4, "0")) { |
567 | num = -1; | 583 | num = -1; |
584 | } | ||
568 | 585 | ||
569 | if (num < 0) | 586 | if (num < 0) { |
570 | new_lines("[i] invalid command parameter"); | 587 | new_lines("[i] invalid command parameter"); |
571 | else if (line[2] == 'f') { | 588 | } else if (line[2] == 'f') { |
572 | conversation_default = num + 1; | 589 | conversation_default = num + 1; |
573 | char buffer[128]; | 590 | char buffer[128]; |
574 | sprintf(buffer, "[i] default conversation is now to friend %i", num); | 591 | sprintf(buffer, "[i] default conversation is now to friend %i", num); |
@@ -578,8 +595,9 @@ void line_eval(Tox *m, char *line) | |||
578 | conversation_default = - (num + 1); | 595 | conversation_default = - (num + 1); |
579 | sprintf(buffer, "[i] default conversation is now to group %i", num); | 596 | sprintf(buffer, "[i] default conversation is now to group %i", num); |
580 | new_lines(buffer); | 597 | new_lines(buffer); |
581 | } else | 598 | } else { |
582 | new_lines("[i] invalid command"); | 599 | new_lines("[i] invalid command"); |
600 | } | ||
583 | } | 601 | } |
584 | } else if (inpt_command == 'p') { //list peers | 602 | } else if (inpt_command == 'p') { //list peers |
585 | char *posi = NULL; | 603 | char *posi = NULL; |
@@ -613,8 +631,9 @@ void line_eval(Tox *m, char *line) | |||
613 | char sss[128]; | 631 | char sss[128]; |
614 | sprintf(sss, "[i] could not send message to friend no. %u", friendnumber); | 632 | sprintf(sss, "[i] could not send message to friend no. %u", friendnumber); |
615 | new_lines(sss); | 633 | new_lines(sss); |
616 | } else | 634 | } else { |
617 | print_formatted_message(m, line, friendnumber, 1); | 635 | print_formatted_message(m, line, friendnumber, 1); |
636 | } | ||
618 | } else { | 637 | } else { |
619 | int groupnumber = - conversation_default - 1; | 638 | int groupnumber = - conversation_default - 1; |
620 | int res = tox_group_message_send(m, groupnumber, (uint8_t *)line, strlen(line)); | 639 | int res = tox_group_message_send(m, groupnumber, (uint8_t *)line, strlen(line)); |
@@ -629,8 +648,9 @@ void line_eval(Tox *m, char *line) | |||
629 | new_lines(msg); | 648 | new_lines(msg); |
630 | } | 649 | } |
631 | } | 650 | } |
632 | } else | 651 | } else { |
633 | new_lines("[i] invalid input: neither command nor in conversation"); | 652 | new_lines("[i] invalid input: neither command nor in conversation"); |
653 | } | ||
634 | } | 654 | } |
635 | } | 655 | } |
636 | 656 | ||
@@ -652,8 +672,9 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin | |||
652 | 672 | ||
653 | /* if the line is very very short, don't insert continuation markers, | 673 | /* if the line is very very short, don't insert continuation markers, |
654 | * as they would use up too much of the line */ | 674 | * as they would use up too much of the line */ |
655 | if ((size_t)line_width < 2 * wrap_cont_len) | 675 | if ((size_t)line_width < 2 * wrap_cont_len) { |
656 | delta_remain = 0; | 676 | delta_remain = 0; |
677 | } | ||
657 | 678 | ||
658 | for (i = line_width; i < len; i += line_width) { | 679 | for (i = line_width; i < len; i += line_width) { |
659 | /* look backward for a space to expand/turn into a new line */ | 680 | /* look backward for a space to expand/turn into a new line */ |
@@ -685,8 +706,9 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin | |||
685 | } else { | 706 | } else { |
686 | /* string ends right here: | 707 | /* string ends right here: |
687 | * don't add a continuation marker with nothing following */ | 708 | * don't add a continuation marker with nothing following */ |
688 | if (i == len - 1) | 709 | if (i == len - 1) { |
689 | break; | 710 | break; |
711 | } | ||
690 | 712 | ||
691 | /* nothing found backwards */ | 713 | /* nothing found backwards */ |
692 | if (delta_remain > wrap_cont_len) { | 714 | if (delta_remain > wrap_cont_len) { |
@@ -728,8 +750,9 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si | |||
728 | /* not yet at the limit */ | 750 | /* not yet at the limit */ |
729 | char c = input[ipos]; | 751 | char c = input[ipos]; |
730 | 752 | ||
731 | if (c == ' ') | 753 | if (c == ' ') { |
732 | space_avail = opos; | 754 | space_avail = opos; |
755 | } | ||
733 | 756 | ||
734 | output[opos++] = input[ipos]; | 757 | output[opos++] = input[ipos]; |
735 | 758 | ||
@@ -751,8 +774,9 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si | |||
751 | output[opos++] = ' '; | 774 | output[opos++] = ' '; |
752 | } | 775 | } |
753 | 776 | ||
754 | if (c == '\n') | 777 | if (c == '\n') { |
755 | nl_got = opos; | 778 | nl_got = opos; |
779 | } | ||
756 | 780 | ||
757 | continue; | 781 | continue; |
758 | } else { | 782 | } else { |
@@ -807,8 +831,9 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si | |||
807 | } | 831 | } |
808 | } | 832 | } |
809 | 833 | ||
810 | if (opos >= STRING_LENGTH_WRAPPED) | 834 | if (opos >= STRING_LENGTH_WRAPPED) { |
811 | opos = STRING_LENGTH_WRAPPED - 1; | 835 | opos = STRING_LENGTH_WRAPPED - 1; |
836 | } | ||
812 | 837 | ||
813 | output[opos] = 0; | 838 | output[opos] = 0; |
814 | } | 839 | } |
@@ -819,8 +844,9 @@ int count_lines(char *string) | |||
819 | int count = 1; | 844 | int count = 1; |
820 | 845 | ||
821 | for (i = 0; i < len; i++) { | 846 | for (i = 0; i < len; i++) { |
822 | if (string[i] == '\n') | 847 | if (string[i] == '\n') { |
823 | count++; | 848 | count++; |
849 | } | ||
824 | } | 850 | } |
825 | 851 | ||
826 | return count; | 852 | return count; |
@@ -845,10 +871,11 @@ void do_refresh() | |||
845 | int i; | 871 | int i; |
846 | 872 | ||
847 | for (i = 0; i < HISTORY; i++) { | 873 | for (i = 0; i < HISTORY; i++) { |
848 | if (flag[i]) | 874 | if (flag[i]) { |
849 | wrap_bars(wrap_output, lines[i], x); | 875 | wrap_bars(wrap_output, lines[i], x); |
850 | else | 876 | } else { |
851 | wrap(wrap_output, lines[i], x); | 877 | wrap(wrap_output, lines[i], x); |
878 | } | ||
852 | 879 | ||
853 | int L = count_lines(wrap_output); | 880 | int L = count_lines(wrap_output); |
854 | count = count + L; | 881 | count = count + L; |
@@ -898,10 +925,11 @@ void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size | |||
898 | if (getfriendname_terminated(m, friendnumber, name) != -1) { | 925 | if (getfriendname_terminated(m, friendnumber, name) != -1) { |
899 | char msg[100 + length]; | 926 | char msg[100 + length]; |
900 | 927 | ||
901 | if (name[0] != 0) | 928 | if (name[0] != 0) { |
902 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); | 929 | sprintf(msg, "[i] [%d] %s is now known as %s.", friendnumber, name, string); |
903 | else | 930 | } else { |
904 | sprintf(msg, "[i] [%d] Friend's name is %s.", friendnumber, string); | 931 | sprintf(msg, "[i] [%d] Friend's name is %s.", friendnumber, string); |
932 | } | ||
905 | 933 | ||
906 | new_lines(msg); | 934 | new_lines(msg); |
907 | } | 935 | } |
@@ -914,10 +942,11 @@ void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, si | |||
914 | if (getfriendname_terminated(m, friendnumber, name) != -1) { | 942 | if (getfriendname_terminated(m, friendnumber, name) != -1) { |
915 | char msg[100 + length + strlen(name) + 1]; | 943 | char msg[100 + length + strlen(name) + 1]; |
916 | 944 | ||
917 | if (name[0] != 0) | 945 | if (name[0] != 0) { |
918 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); | 946 | sprintf(msg, "[i] [%d] %s's status changed to %s.", friendnumber, name, string); |
919 | else | 947 | } else { |
920 | sprintf(msg, "[i] [%d] Their status changed to %s.", friendnumber, string); | 948 | sprintf(msg, "[i] [%d] Their status changed to %s.", friendnumber, string); |
949 | } | ||
921 | 950 | ||
922 | new_lines(msg); | 951 | new_lines(msg); |
923 | } | 952 | } |
@@ -997,8 +1026,9 @@ static int save_data_file(Tox *m, char *path) | |||
997 | { | 1026 | { |
998 | data_file_name = path; | 1027 | data_file_name = path; |
999 | 1028 | ||
1000 | if (save_data(m)) | 1029 | if (save_data(m)) { |
1001 | return 1; | 1030 | return 1; |
1031 | } | ||
1002 | 1032 | ||
1003 | return 0; | 1033 | return 0; |
1004 | } | 1034 | } |
@@ -1032,8 +1062,9 @@ void print_groupchatpeers(Tox *m, int groupnumber) | |||
1032 | { | 1062 | { |
1033 | int num = tox_group_number_peers(m, groupnumber); | 1063 | int num = tox_group_number_peers(m, groupnumber); |
1034 | 1064 | ||
1035 | if (num < 0) | 1065 | if (num < 0) { |
1036 | return; | 1066 | return; |
1067 | } | ||
1037 | 1068 | ||
1038 | if (!num) { | 1069 | if (!num) { |
1039 | new_lines("[g]+ no peers left in group."); | 1070 | new_lines("[g]+ no peers left in group."); |
@@ -1084,13 +1115,15 @@ void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t * | |||
1084 | int len = tox_group_peername(m, groupnumber, peernumber, name); | 1115 | int len = tox_group_peername(m, groupnumber, peernumber, name); |
1085 | 1116 | ||
1086 | //print_groupchatpeers(m, groupnumber); | 1117 | //print_groupchatpeers(m, groupnumber); |
1087 | if (len <= 0) | 1118 | if (len <= 0) { |
1088 | name[0] = 0; | 1119 | name[0] = 0; |
1120 | } | ||
1089 | 1121 | ||
1090 | if (name[0] != 0) | 1122 | if (name[0] != 0) { |
1091 | sprintf(msg, "[g] %u: %u <%s>: %s", groupnumber, peernumber, name, message); | 1123 | sprintf(msg, "[g] %u: %u <%s>: %s", groupnumber, peernumber, name, message); |
1092 | else | 1124 | } else { |
1093 | sprintf(msg, "[g] #%u: %u Unknown: %s", groupnumber, peernumber, message); | 1125 | sprintf(msg, "[g] #%u: %u Unknown: %s", groupnumber, peernumber, message); |
1126 | } | ||
1094 | 1127 | ||
1095 | new_lines(msg); | 1128 | new_lines(msg); |
1096 | } | 1129 | } |
@@ -1116,8 +1149,9 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t | |||
1116 | uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; | 1149 | uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; |
1117 | int len = tox_group_peername(m, groupnumber, peernumber, peername); | 1150 | int len = tox_group_peername(m, groupnumber, peernumber, peername); |
1118 | 1151 | ||
1119 | if (len <= 0) | 1152 | if (len <= 0) { |
1120 | peername[0] = 0; | 1153 | peername[0] = 0; |
1154 | } | ||
1121 | 1155 | ||
1122 | sprintf(msg, "[g] #%i: Peer %i left. Former peer [%i: <%s>] is now peer %i.", groupnumber, peernumber, | 1156 | sprintf(msg, "[g] #%i: Peer %i left. Former peer [%i: <%s>] is now peer %i.", groupnumber, peernumber, |
1123 | peers_total, peername, peernumber); | 1157 | peers_total, peername, peernumber); |
@@ -1127,8 +1161,9 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t | |||
1127 | uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; | 1161 | uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; |
1128 | int len = tox_group_peername(m, groupnumber, peernumber, peername); | 1162 | int len = tox_group_peername(m, groupnumber, peernumber, peername); |
1129 | 1163 | ||
1130 | if (len <= 0) | 1164 | if (len <= 0) { |
1131 | peername[0] = 0; | 1165 | peername[0] = 0; |
1166 | } | ||
1132 | 1167 | ||
1133 | sprintf(msg, "[g] #%i: Peer %i's name changed: %s", groupnumber, peernumber, peername); | 1168 | sprintf(msg, "[g] #%i: Peer %i's name changed: %s", groupnumber, peernumber, peername); |
1134 | new_lines(msg); | 1169 | new_lines(msg); |
@@ -1154,8 +1189,9 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
1154 | if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { | 1189 | if (tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, 0)) { |
1155 | sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friend_number, file_number); | 1190 | sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friend_number, file_number); |
1156 | new_lines(msg); | 1191 | new_lines(msg); |
1157 | } else | 1192 | } else { |
1158 | new_lines("Could not accept file transfer."); | 1193 | new_lines("Could not accept file transfer."); |
1194 | } | ||
1159 | } | 1195 | } |
1160 | 1196 | ||
1161 | void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, | 1197 | void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, |
@@ -1195,30 +1231,33 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p | |||
1195 | sprintf(filename, "%u.%u.bin", friendnumber, filenumber); | 1231 | sprintf(filename, "%u.%u.bin", friendnumber, filenumber); |
1196 | FILE *pFile = fopen(filename, "r+b"); | 1232 | FILE *pFile = fopen(filename, "r+b"); |
1197 | 1233 | ||
1198 | if (pFile == NULL) | 1234 | if (pFile == NULL) { |
1199 | pFile = fopen(filename, "wb"); | 1235 | pFile = fopen(filename, "wb"); |
1236 | } | ||
1200 | 1237 | ||
1201 | fseek(pFile, position, SEEK_SET); | 1238 | fseek(pFile, position, SEEK_SET); |
1202 | 1239 | ||
1203 | if (fwrite(data, length, 1, pFile) != 1) | 1240 | if (fwrite(data, length, 1, pFile) != 1) { |
1204 | new_lines("Error writing to file"); | 1241 | new_lines("Error writing to file"); |
1242 | } | ||
1205 | 1243 | ||
1206 | fclose(pFile); | 1244 | fclose(pFile); |
1207 | } | 1245 | } |
1208 | 1246 | ||
1209 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 1247 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) |
1210 | { | 1248 | { |
1211 | if (status) | 1249 | if (status) { |
1212 | printf("\nOther went online.\n"); | 1250 | printf("\nOther went online.\n"); |
1213 | else { | 1251 | } else { |
1214 | printf("\nOther went offline.\n"); | 1252 | printf("\nOther went offline.\n"); |
1215 | unsigned int i; | 1253 | unsigned int i; |
1216 | 1254 | ||
1217 | for (i = 0; i < NUM_FILE_SENDERS; ++i) | 1255 | for (i = 0; i < NUM_FILE_SENDERS; ++i) { |
1218 | if (file_senders[i].file != 0 && file_senders[i].friendnum == friendnumber) { | 1256 | if (file_senders[i].file != 0 && file_senders[i].friendnum == friendnumber) { |
1219 | fclose(file_senders[i].file); | 1257 | fclose(file_senders[i].file); |
1220 | file_senders[i].file = 0; | 1258 | file_senders[i].file = 0; |
1221 | } | 1259 | } |
1260 | } | ||
1222 | } | 1261 | } |
1223 | } | 1262 | } |
1224 | 1263 | ||
@@ -1266,8 +1305,9 @@ int main(int argc, char *argv[]) | |||
1266 | uint8_t ipv6enabled = 1; /* x */ | 1305 | uint8_t ipv6enabled = 1; /* x */ |
1267 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 1306 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
1268 | 1307 | ||
1269 | if (argvoffset < 0) | 1308 | if (argvoffset < 0) { |
1270 | exit(1); | 1309 | exit(1); |
1310 | } | ||
1271 | 1311 | ||
1272 | int on = 0; | 1312 | int on = 0; |
1273 | char *filename = "data"; | 1313 | char *filename = "data"; |
@@ -1276,9 +1316,11 @@ int main(int argc, char *argv[]) | |||
1276 | 1316 | ||
1277 | /* [-f keyfile] MUST be last two arguments, no point in walking over the list | 1317 | /* [-f keyfile] MUST be last two arguments, no point in walking over the list |
1278 | * especially not a good idea to accept it anywhere in the middle */ | 1318 | * especially not a good idea to accept it anywhere in the middle */ |
1279 | if (argc > argvoffset + 3) | 1319 | if (argc > argvoffset + 3) { |
1280 | if (!strcmp(argv[argc - 2], "-f")) | 1320 | if (!strcmp(argv[argc - 2], "-f")) { |
1281 | filename = argv[argc - 1]; | 1321 | filename = argv[argc - 1]; |
1322 | } | ||
1323 | } | ||
1282 | 1324 | ||
1283 | data_file_name = filename; | 1325 | data_file_name = filename; |
1284 | m = load_data(); | 1326 | m = load_data(); |
@@ -1359,8 +1401,9 @@ int main(int argc, char *argv[]) | |||
1359 | 1401 | ||
1360 | int c = timeout_getch(m); | 1402 | int c = timeout_getch(m); |
1361 | 1403 | ||
1362 | if (c == ERR || c == 27) | 1404 | if (c == ERR || c == 27) { |
1363 | continue; | 1405 | continue; |
1406 | } | ||
1364 | 1407 | ||
1365 | getmaxyx(stdscr, y, x); | 1408 | getmaxyx(stdscr, y, x); |
1366 | 1409 | ||
diff --git a/testing/tox_shell.c b/testing/tox_shell.c index 9c71a2d7..f6dae7b9 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c | |||
@@ -47,10 +47,11 @@ | |||
47 | 47 | ||
48 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 48 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) |
49 | { | 49 | { |
50 | if (status) | 50 | if (status) { |
51 | printf("\nOther went online.\n"); | 51 | printf("\nOther went online.\n"); |
52 | else | 52 | } else { |
53 | printf("\nOther went offline.\n"); | 53 | printf("\nOther went offline.\n"); |
54 | } | ||
54 | } | 55 | } |
55 | 56 | ||
56 | void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, | 57 | void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, |
@@ -66,8 +67,9 @@ int main(int argc, char *argv[]) | |||
66 | uint8_t ipv6enabled = 1; /* x */ | 67 | uint8_t ipv6enabled = 1; /* x */ |
67 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 68 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
68 | 69 | ||
69 | if (argvoffset < 0) | 70 | if (argvoffset < 0) { |
70 | exit(1); | 71 | exit(1); |
72 | } | ||
71 | 73 | ||
72 | /* with optional --ipvx, now it can be 1-4 arguments... */ | 74 | /* with optional --ipvx, now it can be 1-4 arguments... */ |
73 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { | 75 | if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { |
@@ -147,8 +149,9 @@ int main(int argc, char *argv[]) | |||
147 | uint8_t buf[TOX_MAX_MESSAGE_LENGTH]; | 149 | uint8_t buf[TOX_MAX_MESSAGE_LENGTH]; |
148 | ret = read(*master, buf, sizeof(buf)); | 150 | ret = read(*master, buf, sizeof(buf)); |
149 | 151 | ||
150 | if (ret <= 0) | 152 | if (ret <= 0) { |
151 | break; | 153 | break; |
154 | } | ||
152 | 155 | ||
153 | tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0); | 156 | tox_friend_send_message(tox, num, TOX_MESSAGE_TYPE_NORMAL, buf, ret, 0); |
154 | } | 157 | } |
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index a90e343e..c80db339 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -82,8 +82,9 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
82 | { | 82 | { |
83 | FILE *tempfile = fopen(filename, "rb"); | 83 | FILE *tempfile = fopen(filename, "rb"); |
84 | 84 | ||
85 | if (tempfile == 0) | 85 | if (tempfile == 0) { |
86 | return -1; | 86 | return -1; |
87 | } | ||
87 | 88 | ||
88 | fseek(tempfile, 0, SEEK_END); | 89 | fseek(tempfile, 0, SEEK_END); |
89 | uint64_t filesize = ftell(tempfile); | 90 | uint64_t filesize = ftell(tempfile); |
@@ -91,8 +92,9 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
91 | uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, 0, (uint8_t *)filename, | 92 | uint32_t filenum = tox_file_send(m, friendnum, TOX_FILE_KIND_DATA, filesize, 0, (uint8_t *)filename, |
92 | strlen(filename), 0); | 93 | strlen(filename), 0); |
93 | 94 | ||
94 | if (filenum == -1) | 95 | if (filenum == -1) { |
95 | return -1; | 96 | return -1; |
97 | } | ||
96 | 98 | ||
97 | file_senders[numfilesenders].file = tempfile; | 99 | file_senders[numfilesenders].file = tempfile; |
98 | file_senders[numfilesenders].friendnum = friendnum; | 100 | file_senders[numfilesenders].friendnum = friendnum; |
@@ -105,19 +107,22 @@ void kill_filesender(Tox *m, uint32_t filenum) | |||
105 | { | 107 | { |
106 | uint32_t i; | 108 | uint32_t i; |
107 | 109 | ||
108 | for (i = 0; i < NUM_FILE_SENDERS; ++i) | 110 | for (i = 0; i < NUM_FILE_SENDERS; ++i) { |
109 | if (file_senders[i].file != 0 && file_senders[i].filenumber == filenum) { | 111 | if (file_senders[i].file != 0 && file_senders[i].filenumber == filenum) { |
110 | fclose(file_senders[i].file); | 112 | fclose(file_senders[i].file); |
111 | file_senders[i].file = 0; | 113 | file_senders[i].file = 0; |
112 | } | 114 | } |
115 | } | ||
113 | } | 116 | } |
114 | int not_sending() | 117 | int not_sending() |
115 | { | 118 | { |
116 | uint32_t i; | 119 | uint32_t i; |
117 | 120 | ||
118 | for (i = 0; i < NUM_FILE_SENDERS; ++i) | 121 | for (i = 0; i < NUM_FILE_SENDERS; ++i) { |
119 | if (file_senders[i].file != 0) | 122 | if (file_senders[i].file != 0) { |
120 | return 0; | 123 | return 0; |
124 | } | ||
125 | } | ||
121 | 126 | ||
122 | return 1; | 127 | return 1; |
123 | } | 128 | } |
@@ -138,14 +143,16 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
138 | uint16_t rm = 0; | 143 | uint16_t rm = 0; |
139 | 144 | ||
140 | for (i = 0; i < strlen((char *)filename); ++i) { | 145 | for (i = 0; i < strlen((char *)filename); ++i) { |
141 | if (filename[i] == '/') | 146 | if (filename[i] == '/') { |
142 | rm = i; | 147 | rm = i; |
148 | } | ||
143 | } | 149 | } |
144 | 150 | ||
145 | if (path[strlen(path) - 1] == '/') | 151 | if (path[strlen(path) - 1] == '/') { |
146 | sprintf(fullpath, "%s%s", path, filename + rm + 1); | 152 | sprintf(fullpath, "%s%s", path, filename + rm + 1); |
147 | else | 153 | } else { |
148 | sprintf(fullpath, "%s/%s", path, filename + rm + 1); | 154 | sprintf(fullpath, "%s/%s", path, filename + rm + 1); |
155 | } | ||
149 | 156 | ||
150 | FILE *tempfile = fopen(fullpath, "rb"); | 157 | FILE *tempfile = fopen(fullpath, "rb"); |
151 | 158 | ||
@@ -202,16 +209,17 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p | |||
202 | if (file_recv[file_index].file != 0) { | 209 | if (file_recv[file_index].file != 0) { |
203 | fseek(file_recv[file_index].file, position, SEEK_SET); | 210 | fseek(file_recv[file_index].file, position, SEEK_SET); |
204 | 211 | ||
205 | if (fwrite(data, length, 1, file_recv[file_index].file) != 1) | 212 | if (fwrite(data, length, 1, file_recv[file_index].file) != 1) { |
206 | printf("Error writing data\n"); | 213 | printf("Error writing data\n"); |
214 | } | ||
207 | } | 215 | } |
208 | } | 216 | } |
209 | 217 | ||
210 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 218 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) |
211 | { | 219 | { |
212 | if (status) | 220 | if (status) { |
213 | printf("\nOther went online.\n"); | 221 | printf("\nOther went online.\n"); |
214 | else { | 222 | } else { |
215 | printf("\nOther went offline.\n"); | 223 | printf("\nOther went offline.\n"); |
216 | unsigned int i; | 224 | unsigned int i; |
217 | 225 | ||
@@ -234,8 +242,9 @@ int main(int argc, char *argv[]) | |||
234 | uint8_t ipv6enabled = 1; /* x */ | 242 | uint8_t ipv6enabled = 1; /* x */ |
235 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 243 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
236 | 244 | ||
237 | if (argvoffset < 0) | 245 | if (argvoffset < 0) { |
238 | exit(1); | 246 | exit(1); |
247 | } | ||
239 | 248 | ||
240 | /* with optional --ipvx, now it can be 1-4 arguments... */ | 249 | /* with optional --ipvx, now it can be 1-4 arguments... */ |
241 | if ((argc != argvoffset + 3) && (argc != argvoffset + 5)) { | 250 | if ((argc != argvoffset + 3) && (argc != argvoffset + 5)) { |
@@ -303,10 +312,11 @@ int main(int argc, char *argv[]) | |||
303 | if (dir->d_type == DT_REG) { | 312 | if (dir->d_type == DT_REG) { |
304 | char fullpath[1024]; | 313 | char fullpath[1024]; |
305 | 314 | ||
306 | if (path[strlen(path) - 1] == '/') | 315 | if (path[strlen(path) - 1] == '/') { |
307 | sprintf(fullpath, "%s%s", path, dir->d_name); | 316 | sprintf(fullpath, "%s%s", path, dir->d_name); |
308 | else | 317 | } else { |
309 | sprintf(fullpath, "%s/%s", path, dir->d_name); | 318 | sprintf(fullpath, "%s/%s", path, dir->d_name); |
319 | } | ||
310 | 320 | ||
311 | add_filesender(tox, num, fullpath); | 321 | add_filesender(tox, num, fullpath); |
312 | } | 322 | } |