diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-09-05 16:10:48 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-09-06 11:54:37 +0100 |
commit | ad2656051697899e960694bb68ac104fcc5e92f1 (patch) | |
tree | 7e69fcd03db88b3839ee523f5d1b51ef9a38c372 | |
parent | 4e6c86d1cb228308678f89ff6e4e09b3f46347aa (diff) |
Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
dangerous. All but one instance of this are now correct. The one
instance where we can't keep `const` is one where toxav code actually
writes to a chunk of memory marked as `const`. This code also assumes
4 byte alignment of data packets. I don't know whether that is a valid
assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
parameters to it. Empty parameter lists are old style declarations for
unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
of enumerators in the default case is very large. In this case, it was
2, so we want to list them both explicitly to be warned about missing
one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
into nTox.c. They are not used outside and nTox is not a library.
38 files changed, 416 insertions, 391 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index d7312be8..98edc357 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -130,7 +130,7 @@ struct sec_TCP_con { | |||
130 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; | 130 | uint8_t shared_key[crypto_box_BEFORENMBYTES]; |
131 | }; | 131 | }; |
132 | 132 | ||
133 | struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | 133 | static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) |
134 | { | 134 | { |
135 | struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con)); | 135 | struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con)); |
136 | sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); | 136 | sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); |
@@ -176,13 +176,13 @@ struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) | |||
176 | return sec_c; | 176 | return sec_c; |
177 | } | 177 | } |
178 | 178 | ||
179 | void kill_TCP_con(struct sec_TCP_con *con) | 179 | static void kill_TCP_con(struct sec_TCP_con *con) |
180 | { | 180 | { |
181 | kill_sock(con->sock); | 181 | kill_sock(con->sock); |
182 | free(con); | 182 | free(con); |
183 | } | 183 | } |
184 | 184 | ||
185 | int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) | 185 | static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) |
186 | { | 186 | { |
187 | uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES]; | 187 | uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES]; |
188 | 188 | ||
@@ -200,7 +200,7 @@ int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, u | |||
200 | return 0; | 200 | return 0; |
201 | } | 201 | } |
202 | 202 | ||
203 | int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length) | 203 | static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length) |
204 | { | 204 | { |
205 | int len = recv(con->sock, data, length, 0); | 205 | int len = recv(con->sock, data, length, 0); |
206 | ck_assert_msg(len == length, "wrong len %i\n", len); | 206 | ck_assert_msg(len == length, "wrong len %i\n", len); |
@@ -731,7 +731,7 @@ START_TEST(test_tcp_connection2) | |||
731 | } | 731 | } |
732 | END_TEST | 732 | END_TEST |
733 | 733 | ||
734 | Suite *TCP_suite(void) | 734 | static Suite *TCP_suite(void) |
735 | { | 735 | { |
736 | Suite *s = suite_create("TCP"); | 736 | Suite *s = suite_create("TCP"); |
737 | 737 | ||
diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c index 79a97fd5..887ffc0b 100644 --- a/auto_tests/assoc_test.c +++ b/auto_tests/assoc_test.c | |||
@@ -134,7 +134,7 @@ START_TEST(test_fillup) | |||
134 | } | 134 | } |
135 | END_TEST | 135 | END_TEST |
136 | 136 | ||
137 | Suite *Assoc_suite(void) | 137 | static Suite *Assoc_suite(void) |
138 | { | 138 | { |
139 | Suite *s = suite_create("Assoc"); | 139 | Suite *s = suite_create("Assoc"); |
140 | 140 | ||
diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 30cc2178..ff8ab41d 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c | |||
@@ -12,7 +12,7 @@ | |||
12 | 12 | ||
13 | #include "helpers.h" | 13 | #include "helpers.h" |
14 | 14 | ||
15 | void rand_bytes(uint8_t *b, size_t blen) | 15 | static void rand_bytes(uint8_t *b, size_t blen) |
16 | { | 16 | { |
17 | size_t i; | 17 | size_t i; |
18 | 18 | ||
@@ -23,27 +23,27 @@ void rand_bytes(uint8_t *b, size_t blen) | |||
23 | 23 | ||
24 | // These test vectors are from libsodium's test suite | 24 | // These test vectors are from libsodium's test suite |
25 | 25 | ||
26 | unsigned char alicesk[32] = { | 26 | static const unsigned char alicesk[32] = { |
27 | 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, | 27 | 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, |
28 | 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, | 28 | 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, |
29 | 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, | 29 | 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, |
30 | 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a | 30 | 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a |
31 | }; | 31 | }; |
32 | 32 | ||
33 | unsigned char bobpk[32] = { | 33 | static const unsigned char bobpk[32] = { |
34 | 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, | 34 | 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, |
35 | 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, | 35 | 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, |
36 | 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d, | 36 | 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d, |
37 | 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f | 37 | 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f |
38 | }; | 38 | }; |
39 | 39 | ||
40 | unsigned char nonce[24] = { | 40 | static const unsigned char nonce[24] = { |
41 | 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, | 41 | 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, |
42 | 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6, | 42 | 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6, |
43 | 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 | 43 | 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 |
44 | }; | 44 | }; |
45 | 45 | ||
46 | unsigned char test_m[131] = { | 46 | static const unsigned char test_m[131] = { |
47 | 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, | 47 | 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, |
48 | 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b, | 48 | 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b, |
49 | 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, | 49 | 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, |
@@ -63,7 +63,7 @@ unsigned char test_m[131] = { | |||
63 | 0x5e, 0x07, 0x05 | 63 | 0x5e, 0x07, 0x05 |
64 | }; | 64 | }; |
65 | 65 | ||
66 | unsigned char test_c[147] = { | 66 | static const unsigned char test_c[147] = { |
67 | 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, | 67 | 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, |
68 | 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, | 68 | 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, |
69 | 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, | 69 | 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, |
@@ -271,7 +271,7 @@ START_TEST(test_large_data_symmetric) | |||
271 | } | 271 | } |
272 | END_TEST | 272 | END_TEST |
273 | 273 | ||
274 | void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) | 274 | static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) |
275 | { | 275 | { |
276 | uint32_t num1, num2; | 276 | uint32_t num1, num2; |
277 | memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1)); | 277 | memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1)); |
@@ -323,7 +323,7 @@ START_TEST(test_increment_nonce) | |||
323 | } | 323 | } |
324 | END_TEST | 324 | END_TEST |
325 | 325 | ||
326 | Suite *crypto_suite(void) | 326 | static Suite *crypto_suite(void) |
327 | { | 327 | { |
328 | Suite *s = suite_create("Crypto"); | 328 | Suite *s = suite_create("Crypto"); |
329 | 329 | ||
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 7aab9573..dd68ffbe 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c | |||
@@ -10,6 +10,9 @@ | |||
10 | 10 | ||
11 | #include "helpers.h" | 11 | #include "helpers.h" |
12 | 12 | ||
13 | |||
14 | // These tests currently fail. | ||
15 | #if 0 | ||
13 | #define swap(x,y) do \ | 16 | #define swap(x,y) do \ |
14 | { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ | 17 | { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ |
15 | memcpy(swap_temp,&y,sizeof(x)); \ | 18 | memcpy(swap_temp,&y,sizeof(x)); \ |
@@ -18,7 +21,7 @@ | |||
18 | } while(0) | 21 | } while(0) |
19 | 22 | ||
20 | 23 | ||
21 | void mark_bad(IPPTsPng *ipptp) | 24 | static void mark_bad(IPPTsPng *ipptp) |
22 | { | 25 | { |
23 | ipptp->timestamp = unix_time() - 2 * BAD_NODE_TIMEOUT; | 26 | ipptp->timestamp = unix_time() - 2 * BAD_NODE_TIMEOUT; |
24 | ipptp->hardening.routes_requests_ok = 0; | 27 | ipptp->hardening.routes_requests_ok = 0; |
@@ -26,7 +29,7 @@ void mark_bad(IPPTsPng *ipptp) | |||
26 | ipptp->hardening.testing_requests = 0; | 29 | ipptp->hardening.testing_requests = 0; |
27 | } | 30 | } |
28 | 31 | ||
29 | void mark_possible_bad(IPPTsPng *ipptp) | 32 | static void mark_possible_bad(IPPTsPng *ipptp) |
30 | { | 33 | { |
31 | ipptp->timestamp = unix_time(); | 34 | ipptp->timestamp = unix_time(); |
32 | ipptp->hardening.routes_requests_ok = 0; | 35 | ipptp->hardening.routes_requests_ok = 0; |
@@ -34,7 +37,7 @@ void mark_possible_bad(IPPTsPng *ipptp) | |||
34 | ipptp->hardening.testing_requests = 0; | 37 | ipptp->hardening.testing_requests = 0; |
35 | } | 38 | } |
36 | 39 | ||
37 | void mark_good(IPPTsPng *ipptp) | 40 | static void mark_good(IPPTsPng *ipptp) |
38 | { | 41 | { |
39 | ipptp->timestamp = unix_time(); | 42 | ipptp->timestamp = unix_time(); |
40 | ipptp->hardening.routes_requests_ok = (HARDENING_ALL_OK >> 0) & 1; | 43 | ipptp->hardening.routes_requests_ok = (HARDENING_ALL_OK >> 0) & 1; |
@@ -42,7 +45,7 @@ void mark_good(IPPTsPng *ipptp) | |||
42 | ipptp->hardening.testing_requests = (HARDENING_ALL_OK >> 2) & 1; | 45 | ipptp->hardening.testing_requests = (HARDENING_ALL_OK >> 2) & 1; |
43 | } | 46 | } |
44 | 47 | ||
45 | void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) | 48 | static void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) |
46 | { | 49 | { |
47 | uint32_t i; | 50 | uint32_t i; |
48 | 51 | ||
@@ -57,7 +60,7 @@ void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) | |||
57 | 60 | ||
58 | /* Returns 1 if public_key has a furthest distance to comp_client_id | 61 | /* Returns 1 if public_key has a furthest distance to comp_client_id |
59 | than all public_key's in the list */ | 62 | than all public_key's in the list */ |
60 | uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key) | 63 | static uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key) |
61 | { | 64 | { |
62 | uint32_t i; | 65 | uint32_t i; |
63 | 66 | ||
@@ -70,7 +73,7 @@ uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t l | |||
70 | return 1; | 73 | return 1; |
71 | } | 74 | } |
72 | 75 | ||
73 | int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) | 76 | static int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) |
74 | { | 77 | { |
75 | int i; | 78 | int i; |
76 | 79 | ||
@@ -83,10 +86,10 @@ int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key | |||
83 | return -1; | 86 | return -1; |
84 | } | 87 | } |
85 | 88 | ||
86 | void test_addto_lists_update(DHT *dht, | 89 | static void test_addto_lists_update(DHT *dht, |
87 | Client_data *list, | 90 | Client_data *list, |
88 | uint32_t length, | 91 | uint32_t length, |
89 | IP_Port *ip_port) | 92 | IP_Port *ip_port) |
90 | { | 93 | { |
91 | int used, test, test1, test2, found; | 94 | int used, test, test1, test2, found; |
92 | IP_Port test_ipp; | 95 | IP_Port test_ipp; |
@@ -157,10 +160,10 @@ void test_addto_lists_update(DHT *dht, | |||
157 | "Client IP_Port is incorrect"); | 160 | "Client IP_Port is incorrect"); |
158 | } | 161 | } |
159 | 162 | ||
160 | void test_addto_lists_bad(DHT *dht, | 163 | static void test_addto_lists_bad(DHT *dht, |
161 | Client_data *list, | 164 | Client_data *list, |
162 | uint32_t length, | 165 | uint32_t length, |
163 | IP_Port *ip_port) | 166 | IP_Port *ip_port) |
164 | { | 167 | { |
165 | // check "bad" clients replacement | 168 | // check "bad" clients replacement |
166 | int used, test1, test2, test3; | 169 | int used, test1, test2, test3; |
@@ -200,11 +203,11 @@ void test_addto_lists_bad(DHT *dht, | |||
200 | ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed"); | 203 | ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed"); |
201 | } | 204 | } |
202 | 205 | ||
203 | void test_addto_lists_possible_bad(DHT *dht, | 206 | static void test_addto_lists_possible_bad(DHT *dht, |
204 | Client_data *list, | 207 | Client_data *list, |
205 | uint32_t length, | 208 | uint32_t length, |
206 | IP_Port *ip_port, | 209 | IP_Port *ip_port, |
207 | const uint8_t *comp_client_id) | 210 | const uint8_t *comp_client_id) |
208 | { | 211 | { |
209 | // check "possibly bad" clients replacement | 212 | // check "possibly bad" clients replacement |
210 | int used, test1, test2, test3; | 213 | int used, test1, test2, test3; |
@@ -265,11 +268,11 @@ void test_addto_lists_possible_bad(DHT *dht, | |||
265 | } | 268 | } |
266 | } | 269 | } |
267 | 270 | ||
268 | void test_addto_lists_good(DHT *dht, | 271 | static void test_addto_lists_good(DHT *dht, |
269 | Client_data *list, | 272 | Client_data *list, |
270 | uint32_t length, | 273 | uint32_t length, |
271 | IP_Port *ip_port, | 274 | IP_Port *ip_port, |
272 | const uint8_t *comp_client_id) | 275 | const uint8_t *comp_client_id) |
273 | { | 276 | { |
274 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; | 277 | uint8_t public_key[crypto_box_PUBLICKEYBYTES]; |
275 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; | 278 | uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; |
@@ -295,8 +298,6 @@ void test_addto_lists_good(DHT *dht, | |||
295 | ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); | 298 | ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); |
296 | } | 299 | } |
297 | 300 | ||
298 | // These tests currently fail. | ||
299 | #if 0 | ||
300 | static void test_addto_lists(IP ip) | 301 | static void test_addto_lists(IP ip) |
301 | { | 302 | { |
302 | Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT); | 303 | Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT); |
@@ -382,7 +383,7 @@ END_TEST | |||
382 | 383 | ||
383 | #define DHT_LIST_LENGTH 128 | 384 | #define DHT_LIST_LENGTH 128 |
384 | 385 | ||
385 | void print_pk(uint8_t *public_key) | 386 | static void print_pk(uint8_t *public_key) |
386 | { | 387 | { |
387 | uint32_t j; | 388 | uint32_t j; |
388 | 389 | ||
@@ -393,8 +394,9 @@ void print_pk(uint8_t *public_key) | |||
393 | printf("\n"); | 394 | printf("\n"); |
394 | } | 395 | } |
395 | 396 | ||
396 | void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigned int length, const uint8_t *pk, | 397 | static void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], |
397 | const uint8_t *cmp_pk) | 398 | unsigned int length, const uint8_t *pk, |
399 | const uint8_t *cmp_pk) | ||
398 | { | 400 | { |
399 | uint8_t p_b[crypto_box_PUBLICKEYBYTES]; | 401 | uint8_t p_b[crypto_box_PUBLICKEYBYTES]; |
400 | unsigned int i; | 402 | unsigned int i; |
@@ -423,7 +425,7 @@ void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigne | |||
423 | 425 | ||
424 | #define NUM_DHT 100 | 426 | #define NUM_DHT 100 |
425 | 427 | ||
426 | void test_list_main() | 428 | static void test_list_main(void) |
427 | { | 429 | { |
428 | DHT *dhts[NUM_DHT]; | 430 | DHT *dhts[NUM_DHT]; |
429 | 431 | ||
@@ -555,7 +557,7 @@ START_TEST(test_list) | |||
555 | } | 557 | } |
556 | END_TEST | 558 | END_TEST |
557 | 559 | ||
558 | void ip_callback(void *data, int32_t number, IP_Port ip_port) | 560 | static void ip_callback(void *data, int32_t number, IP_Port ip_port) |
559 | { | 561 | { |
560 | } | 562 | } |
561 | 563 | ||
@@ -646,7 +648,7 @@ loop_top: | |||
646 | } | 648 | } |
647 | END_TEST | 649 | END_TEST |
648 | 650 | ||
649 | Suite *dht_suite(void) | 651 | static Suite *dht_suite(void) |
650 | { | 652 | { |
651 | Suite *s = suite_create("DHT"); | 653 | Suite *s = suite_create("DHT"); |
652 | 654 | ||
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 02a29016..f1e768d6 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -19,16 +19,16 @@ | |||
19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" | 19 | #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" |
20 | #endif | 20 | #endif |
21 | 21 | ||
22 | unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; | 22 | static unsigned char salt[32] = {0xB1, 0xC2, 0x09, 0xEE, 0x50, 0x6C, 0xF0, 0x20, 0xC4, 0xD6, 0xEB, 0xC0, 0x44, 0x51, 0x3B, 0x60, 0x4B, 0x39, 0x4A, 0xCF, 0x09, 0x53, 0x4F, 0xEA, 0x08, 0x41, 0xFA, 0xCA, 0x66, 0xD2, 0x68, 0x7F}; |
23 | unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; | 23 | static unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x65, 0xbb, 0x46, 0x8b, 0xde, 0xa1, 0xac, 0xf, 0xd5, 0x11, 0x81, 0xc8, 0x29, 0x28, 0x17, 0x23, 0xa6, 0xc3, 0x6b, 0x77, 0x2e, 0xd7, 0xd3, 0x10, 0xeb, 0xd2, 0xf7, 0xc8}; |
24 | const char *pw = "hunter2"; | 24 | static const char *pw = "hunter2"; |
25 | unsigned int pwlen = 7; | 25 | static unsigned int pwlen = 7; |
26 | 26 | ||
27 | unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; | 27 | static unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; |
28 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat | 28 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat |
29 | 29 | ||
30 | /* cause I'm shameless */ | 30 | /* cause I'm shameless */ |
31 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 31 | static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
32 | { | 32 | { |
33 | if (*((uint32_t *)userdata) != 974536) { | 33 | if (*((uint32_t *)userdata) != 974536) { |
34 | return; | 34 | return; |
@@ -63,7 +63,7 @@ START_TEST(test_save_friend) | |||
63 | tox_callback_friend_request(tox2, accept_friend_request); | 63 | tox_callback_friend_request(tox2, accept_friend_request); |
64 | uint8_t address[TOX_ADDRESS_SIZE]; | 64 | uint8_t address[TOX_ADDRESS_SIZE]; |
65 | tox_self_get_address(tox2, address); | 65 | tox_self_get_address(tox2, address); |
66 | uint32_t test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0); | 66 | uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)"Gentoo", 7, 0); |
67 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); | 67 | ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); |
68 | 68 | ||
69 | size_t size = tox_get_savedata_size(tox1); | 69 | size_t size = tox_get_savedata_size(tox1); |
@@ -186,7 +186,7 @@ START_TEST(test_keys) | |||
186 | } | 186 | } |
187 | END_TEST | 187 | END_TEST |
188 | 188 | ||
189 | Suite *encryptsave_suite(void) | 189 | static Suite *encryptsave_suite(void) |
190 | { | 190 | { |
191 | Suite *s = suite_create("encryptsave"); | 191 | Suite *s = suite_create("encryptsave"); |
192 | 192 | ||
@@ -212,4 +212,3 @@ int main(int argc, char *argv[]) | |||
212 | 212 | ||
213 | return number_failed; | 213 | return number_failed; |
214 | } | 214 | } |
215 | |||
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 2407574e..f7dc92d5 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -26,34 +26,34 @@ | |||
26 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) | 26 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) |
27 | #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) | 27 | #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) |
28 | 28 | ||
29 | char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; | 29 | static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; |
30 | 30 | ||
31 | /* in case we need more than one ID for a test */ | 31 | /* in case we need more than one ID for a test */ |
32 | char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; | 32 | static const char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; |
33 | char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; | 33 | static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; |
34 | 34 | ||
35 | char *bad_id_str = "9B569D14ff637e69f2"; | 35 | static const char *bad_id_str = "9B569D14ff637e69f2"; |
36 | 36 | ||
37 | unsigned char *friend_id = NULL; | 37 | static unsigned char *friend_id = NULL; |
38 | unsigned char *good_id_a = NULL; | 38 | static unsigned char *good_id_a = NULL; |
39 | unsigned char *good_id_b = NULL; | 39 | static unsigned char *good_id_b = NULL; |
40 | unsigned char *bad_id = NULL; | 40 | static unsigned char *bad_id = NULL; |
41 | 41 | ||
42 | int friend_id_num = 0; | 42 | static int friend_id_num = 0; |
43 | 43 | ||
44 | Messenger *m; | 44 | static Messenger *m; |
45 | 45 | ||
46 | START_TEST(test_m_sendmesage) | 46 | START_TEST(test_m_sendmesage) |
47 | { | 47 | { |
48 | char *message = "h-hi :3"; | 48 | const char *message = "h-hi :3"; |
49 | int good_len = strlen(message); | 49 | int good_len = strlen(message); |
50 | int bad_len = MAX_CRYPTO_PACKET_SIZE; | 50 | int bad_len = MAX_CRYPTO_PACKET_SIZE; |
51 | 51 | ||
52 | 52 | ||
53 | ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); | 53 | ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); |
54 | ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); | 54 | ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); |
55 | ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); | 55 | ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); |
56 | ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (uint8_t *)message, bad_len, 0) == -2); | 56 | ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (const uint8_t *)message, bad_len, 0) == -2); |
57 | } | 57 | } |
58 | END_TEST | 58 | END_TEST |
59 | 59 | ||
@@ -77,15 +77,15 @@ END_TEST | |||
77 | 77 | ||
78 | START_TEST(test_m_set_userstatus) | 78 | START_TEST(test_m_set_userstatus) |
79 | { | 79 | { |
80 | char *status = "online!"; | 80 | const char *status = "online!"; |
81 | uint16_t good_length = strlen(status); | 81 | uint16_t good_length = strlen(status); |
82 | uint16_t bad_length = REALLY_BIG_NUMBER; | 82 | uint16_t bad_length = REALLY_BIG_NUMBER; |
83 | 83 | ||
84 | ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1), | 84 | ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, bad_length) == -1), |
85 | "m_set_userstatus did NOT catch the following length: %d\n", | 85 | "m_set_userstatus did NOT catch the following length: %d\n", |
86 | REALLY_BIG_NUMBER); | 86 | REALLY_BIG_NUMBER); |
87 | 87 | ||
88 | ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0), | 88 | ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, good_length) == 0), |
89 | "m_set_userstatus did NOT return 0 on the following length: %d\n" | 89 | "m_set_userstatus did NOT return 0 on the following length: %d\n" |
90 | "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); | 90 | "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); |
91 | } | 91 | } |
@@ -156,25 +156,25 @@ END_TEST */ | |||
156 | 156 | ||
157 | START_TEST(test_setname) | 157 | START_TEST(test_setname) |
158 | { | 158 | { |
159 | char *good_name = "consensualCorn"; | 159 | const char *good_name = "consensualCorn"; |
160 | int good_length = strlen(good_name); | 160 | int good_length = strlen(good_name); |
161 | int bad_length = REALLY_BIG_NUMBER; | 161 | int bad_length = REALLY_BIG_NUMBER; |
162 | 162 | ||
163 | ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1), | 163 | ck_assert_msg((setname(m, (const uint8_t *)good_name, bad_length) == -1), |
164 | "setname() did NOT error on %d as a length argument!\n", bad_length); | 164 | "setname() did NOT error on %d as a length argument!\n", bad_length); |
165 | 165 | ||
166 | ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0), | 166 | ck_assert_msg((setname(m, (const uint8_t *)good_name, good_length) == 0), |
167 | "setname() did NOT return 0 on good arguments!\n"); | 167 | "setname() did NOT return 0 on good arguments!\n"); |
168 | } | 168 | } |
169 | END_TEST | 169 | END_TEST |
170 | 170 | ||
171 | START_TEST(test_getself_name) | 171 | START_TEST(test_getself_name) |
172 | { | 172 | { |
173 | char *nickname = "testGallop"; | 173 | const char *nickname = "testGallop"; |
174 | int len = strlen(nickname); | 174 | int len = strlen(nickname); |
175 | char nick_check[len]; | 175 | char nick_check[len]; |
176 | 176 | ||
177 | setname(m, (uint8_t *)nickname, len); | 177 | setname(m, (const uint8_t *)nickname, len); |
178 | getself_name(m, (uint8_t *)nick_check); | 178 | getself_name(m, (uint8_t *)nick_check); |
179 | 179 | ||
180 | ck_assert_msg((memcmp(nickname, nick_check, len) == 0), | 180 | ck_assert_msg((memcmp(nickname, nick_check, len) == 0), |
@@ -300,7 +300,7 @@ START_TEST(test_messenger_state_saveloadsave) | |||
300 | } | 300 | } |
301 | END_TEST | 301 | END_TEST |
302 | 302 | ||
303 | Suite *messenger_suite(void) | 303 | static Suite *messenger_suite(void) |
304 | { | 304 | { |
305 | Suite *s = suite_create("Messenger"); | 305 | Suite *s = suite_create("Messenger"); |
306 | 306 | ||
diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index b5d8b33e..783f3f7b 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c | |||
@@ -134,7 +134,7 @@ START_TEST(test_ip_equal) | |||
134 | } | 134 | } |
135 | END_TEST | 135 | END_TEST |
136 | 136 | ||
137 | Suite *network_suite(void) | 137 | static Suite *network_suite(void) |
138 | { | 138 | { |
139 | Suite *s = suite_create("Network"); | 139 | Suite *s = suite_create("Network"); |
140 | 140 | ||
@@ -144,7 +144,7 @@ Suite *network_suite(void) | |||
144 | return s; | 144 | return s; |
145 | } | 145 | } |
146 | 146 | ||
147 | int main() | 147 | int main(void) |
148 | { | 148 | { |
149 | srand((unsigned int) time(NULL)); | 149 | srand((unsigned int) time(NULL)); |
150 | 150 | ||
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 58fde2d6..dd5a1946 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #define c_sleep(x) usleep(1000*x) | 23 | #define c_sleep(x) usleep(1000*x) |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | void do_onion(Onion *onion) | 26 | static void do_onion(Onion *onion) |
27 | { | 27 | { |
28 | networking_poll(onion->net, NULL); | 28 | networking_poll(onion->net, NULL); |
29 | do_DHT(onion->dht); | 29 | do_DHT(onion->dht); |
@@ -38,7 +38,7 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
38 | return 1; | 38 | return 1; |
39 | } | 39 | } |
40 | 40 | ||
41 | if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"), | 41 | if (send_onion_response(onion->net, source, (const uint8_t *)"install gentoo", sizeof("install gentoo"), |
42 | packet + sizeof("Install Gentoo")) == -1) { | 42 | packet + sizeof("Install Gentoo")) == -1) { |
43 | return 1; | 43 | return 1; |
44 | } | 44 | } |
@@ -54,14 +54,14 @@ static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
54 | return 1; | 54 | return 1; |
55 | } | 55 | } |
56 | 56 | ||
57 | if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { | 57 | if (memcmp(packet, (const uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { |
58 | return 1; | 58 | return 1; |
59 | } | 59 | } |
60 | 60 | ||
61 | handled_test_2 = 1; | 61 | handled_test_2 = 1; |
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | /* | 64 | #if 0 |
65 | void print_client_id(uint8_t *client_id, uint32_t length) | 65 | void print_client_id(uint8_t *client_id, uint32_t length) |
66 | { | 66 | { |
67 | uint32_t j; | 67 | uint32_t j; |
@@ -69,13 +69,14 @@ void print_client_id(uint8_t *client_id, uint32_t length) | |||
69 | for (j = 0; j < length; j++) { | 69 | for (j = 0; j < length; j++) { |
70 | printf("%02hhX", client_id[j]); | 70 | printf("%02hhX", client_id[j]); |
71 | } | 71 | } |
72 | |||
72 | printf("\n"); | 73 | printf("\n"); |
73 | } | 74 | } |
74 | */ | 75 | #endif |
75 | uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; | 76 | static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; |
76 | static int handled_test_3; | 77 | static int handled_test_3; |
77 | uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; | 78 | static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; |
78 | uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; | 79 | static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; |
79 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 80 | static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
80 | { | 81 | { |
81 | Onion *onion = object; | 82 | Onion *onion = object; |
@@ -106,7 +107,7 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
106 | return 0; | 107 | return 0; |
107 | } | 108 | } |
108 | 109 | ||
109 | uint8_t nonce[crypto_box_NONCEBYTES]; | 110 | static uint8_t nonce[crypto_box_NONCEBYTES]; |
110 | static int handled_test_4; | 111 | static int handled_test_4; |
111 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 112 | static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
112 | { | 113 | { |
@@ -165,7 +166,7 @@ START_TEST(test_basic) | |||
165 | nodes[3] = n2; | 166 | nodes[3] = n2; |
166 | Onion_Path path; | 167 | Onion_Path path; |
167 | create_onion_path(onion1->dht, &path, nodes); | 168 | create_onion_path(onion1->dht, &path, nodes); |
168 | int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (uint8_t *)"Install Gentoo", | 169 | int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"Install Gentoo", |
169 | sizeof("Install Gentoo")); | 170 | sizeof("Install Gentoo")); |
170 | ck_assert_msg(ret == 0, "Failed to create/send onion packet."); | 171 | ck_assert_msg(ret == 0, "Failed to create/send onion packet."); |
171 | 172 | ||
@@ -227,7 +228,7 @@ START_TEST(test_basic) | |||
227 | new_nonce(nonce); | 228 | new_nonce(nonce); |
228 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, | 229 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, |
229 | onion1->dht->self_public_key, | 230 | onion1->dht->self_public_key, |
230 | nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); | 231 | nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo")); |
231 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); | 232 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); |
232 | handled_test_4 = 0; | 233 | handled_test_4 = 0; |
233 | 234 | ||
@@ -278,7 +279,7 @@ typedef struct { | |||
278 | Onion_Client *onion_c; | 279 | Onion_Client *onion_c; |
279 | } Onions; | 280 | } Onions; |
280 | 281 | ||
281 | Onions *new_onions(uint16_t port) | 282 | static Onions *new_onions(uint16_t port) |
282 | { | 283 | { |
283 | IP ip; | 284 | IP ip; |
284 | ip_init(&ip, 1); | 285 | ip_init(&ip, 1); |
@@ -297,14 +298,14 @@ Onions *new_onions(uint16_t port) | |||
297 | return NULL; | 298 | return NULL; |
298 | } | 299 | } |
299 | 300 | ||
300 | void do_onions(Onions *on) | 301 | static void do_onions(Onions *on) |
301 | { | 302 | { |
302 | networking_poll(on->onion->net, NULL); | 303 | networking_poll(on->onion->net, NULL); |
303 | do_DHT(on->onion->dht); | 304 | do_DHT(on->onion->dht); |
304 | do_onion_client(on->onion_c); | 305 | do_onion_client(on->onion_c); |
305 | } | 306 | } |
306 | 307 | ||
307 | void kill_onions(Onions *on) | 308 | static void kill_onions(Onions *on) |
308 | { | 309 | { |
309 | Networking_Core *net = on->onion->dht->net; | 310 | Networking_Core *net = on->onion->dht->net; |
310 | DHT *dht = on->onion->dht; | 311 | DHT *dht = on->onion->dht; |
@@ -322,8 +323,8 @@ void kill_onions(Onions *on) | |||
322 | #define NUM_FIRST 7 | 323 | #define NUM_FIRST 7 |
323 | #define NUM_LAST 37 | 324 | #define NUM_LAST 37 |
324 | 325 | ||
325 | _Bool first_ip, last_ip; | 326 | static _Bool first_ip, last_ip; |
326 | void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | 327 | static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) |
327 | { | 328 | { |
328 | if (NUM_FIRST == number) { | 329 | if (NUM_FIRST == number) { |
329 | first_ip = 1; | 330 | first_ip = 1; |
@@ -338,9 +339,9 @@ void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) | |||
338 | ck_abort_msg("Error."); | 339 | ck_abort_msg("Error."); |
339 | } | 340 | } |
340 | 341 | ||
341 | _Bool first, last; | 342 | static _Bool first, last; |
342 | uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; | 343 | static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; |
343 | uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; | 344 | static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; |
344 | 345 | ||
345 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) | 346 | static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) |
346 | { | 347 | { |
@@ -460,7 +461,7 @@ START_TEST(test_announce) | |||
460 | } | 461 | } |
461 | END_TEST | 462 | END_TEST |
462 | 463 | ||
463 | Suite *onion_suite(void) | 464 | static Suite *onion_suite(void) |
464 | { | 465 | { |
465 | Suite *s = suite_create("Onion"); | 466 | Suite *s = suite_create("Onion"); |
466 | 467 | ||
diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c index 8d3ec3bb..b8950921 100644 --- a/auto_tests/skeleton_test.c +++ b/auto_tests/skeleton_test.c | |||
@@ -22,7 +22,7 @@ START_TEST(test_creativetestnamegoeshere) | |||
22 | } | 22 | } |
23 | END_TEST | 23 | END_TEST |
24 | 24 | ||
25 | Suite *creativesuitenamegoeshere_suite(void) | 25 | static Suite *creativesuitenamegoeshere_suite(void) |
26 | { | 26 | { |
27 | Suite *s = suite_create("creativesuitedescritptiongoeshere"); | 27 | Suite *s = suite_create("creativesuitedescritptiongoeshere"); |
28 | 28 | ||
@@ -46,4 +46,3 @@ int main(int argc, char *argv[]) | |||
46 | 46 | ||
47 | return number_failed; | 47 | return number_failed; |
48 | } | 48 | } |
49 | |||
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index bc6006e3..7efb5465 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c | |||
@@ -42,7 +42,7 @@ | |||
42 | #define TOX_LOCALHOST "127.0.0.1" | 42 | #define TOX_LOCALHOST "127.0.0.1" |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 45 | static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
46 | { | 46 | { |
47 | if (*((uint32_t *)userdata) != 974536) { | 47 | if (*((uint32_t *)userdata) != 974536) { |
48 | return; | 48 | return; |
@@ -52,10 +52,10 @@ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *dat | |||
52 | tox_friend_add_norequest(m, public_key, 0); | 52 | tox_friend_add_norequest(m, public_key, 0); |
53 | } | 53 | } |
54 | } | 54 | } |
55 | uint32_t messages_received; | 55 | static uint32_t messages_received; |
56 | 56 | ||
57 | void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, | 57 | static void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, |
58 | void *userdata) | 58 | void *userdata) |
59 | { | 59 | { |
60 | if (*((uint32_t *)userdata) != 974536) { | 60 | if (*((uint32_t *)userdata) != 974536) { |
61 | return; | 61 | return; |
@@ -73,9 +73,9 @@ void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const u | |||
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | uint32_t name_changes; | 76 | static uint32_t name_changes; |
77 | 77 | ||
78 | void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) | 78 | static void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) |
79 | { | 79 | { |
80 | if (*((uint32_t *)userdata) != 974536) { | 80 | if (*((uint32_t *)userdata) != 974536) { |
81 | return; | 81 | return; |
@@ -86,8 +86,9 @@ void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | uint32_t status_m_changes; | 89 | static uint32_t status_m_changes; |
90 | void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, void *user_data) | 90 | static void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, |
91 | void *user_data) | ||
91 | { | 92 | { |
92 | if (*((uint32_t *)user_data) != 974536) { | 93 | if (*((uint32_t *)user_data) != 974536) { |
93 | return; | 94 | return; |
@@ -98,9 +99,9 @@ void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *mess | |||
98 | } | 99 | } |
99 | } | 100 | } |
100 | 101 | ||
101 | uint32_t typing_changes; | 102 | static uint32_t typing_changes; |
102 | 103 | ||
103 | void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata) | 104 | static void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata) |
104 | { | 105 | { |
105 | if (*((uint32_t *)userdata) != 974536) { | 106 | if (*((uint32_t *)userdata) != 974536) { |
106 | return; | 107 | return; |
@@ -113,9 +114,9 @@ void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userda | |||
113 | } | 114 | } |
114 | } | 115 | } |
115 | 116 | ||
116 | uint32_t custom_packet; | 117 | static uint32_t custom_packet; |
117 | 118 | ||
118 | void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size_t len, void *object) | 119 | static void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size_t len, void *object) |
119 | { | 120 | { |
120 | uint8_t number = *((uint32_t *)object); | 121 | uint8_t number = *((uint32_t *)object); |
121 | 122 | ||
@@ -135,15 +136,14 @@ void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size | |||
135 | return; | 136 | return; |
136 | } | 137 | } |
137 | 138 | ||
138 | uint64_t size_recv; | 139 | static uint64_t size_recv; |
139 | uint64_t sending_pos; | 140 | static uint64_t sending_pos; |
140 | 141 | ||
141 | uint8_t file_cmp_id[TOX_FILE_ID_LENGTH]; | 142 | static uint8_t file_cmp_id[TOX_FILE_ID_LENGTH]; |
142 | uint8_t filenum; | 143 | static uint32_t file_accepted; |
143 | uint32_t file_accepted; | 144 | static uint64_t file_size; |
144 | uint64_t file_size; | 145 | static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize, |
145 | void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize, | 146 | const uint8_t *filename, size_t filename_length, void *userdata) |
146 | const uint8_t *filename, size_t filename_length, void *userdata) | ||
147 | { | 147 | { |
148 | if (*((uint32_t *)userdata) != 974536) { | 148 | if (*((uint32_t *)userdata) != 974536) { |
149 | return; | 149 | return; |
@@ -208,9 +208,9 @@ void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, ui | |||
208 | ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error"); | 208 | ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error"); |
209 | } | 209 | } |
210 | 210 | ||
211 | uint32_t sendf_ok; | 211 | static uint32_t sendf_ok; |
212 | void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, | 212 | static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, |
213 | void *userdata) | 213 | void *userdata) |
214 | { | 214 | { |
215 | if (*((uint32_t *)userdata) != 974536) { | 215 | if (*((uint32_t *)userdata) != 974536) { |
216 | return; | 216 | return; |
@@ -222,12 +222,13 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | uint64_t max_sending; | 225 | static uint64_t max_sending; |
226 | _Bool m_send_reached; | 226 | static _Bool m_send_reached; |
227 | uint8_t sending_num; | 227 | static uint8_t sending_num; |
228 | _Bool file_sending_done; | 228 | static _Bool file_sending_done; |
229 | void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, | 229 | static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, |
230 | void *user_data) | 230 | size_t length, |
231 | void *user_data) | ||
231 | { | 232 | { |
232 | if (*((uint32_t *)user_data) != 974536) { | 233 | if (*((uint32_t *)user_data) != 974536) { |
233 | return; | 234 | return; |
@@ -277,10 +278,10 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb | |||
277 | } | 278 | } |
278 | 279 | ||
279 | 280 | ||
280 | uint8_t num; | 281 | static uint8_t num; |
281 | _Bool file_recv; | 282 | static _Bool file_recv; |
282 | void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, | 283 | static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, |
283 | size_t length, void *user_data) | 284 | size_t length, void *user_data) |
284 | { | 285 | { |
285 | if (*((uint32_t *)user_data) != 974536) { | 286 | if (*((uint32_t *)user_data) != 974536) { |
286 | return; | 287 | return; |
@@ -307,8 +308,8 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p | |||
307 | } | 308 | } |
308 | } | 309 | } |
309 | 310 | ||
310 | unsigned int connected_t1; | 311 | static unsigned int connected_t1; |
311 | void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) | 312 | static void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) |
312 | { | 313 | { |
313 | if (*((uint32_t *)user_data) != 974536) { | 314 | if (*((uint32_t *)user_data) != 974536) { |
314 | return; | 315 | return; |
@@ -347,7 +348,7 @@ START_TEST(test_one) | |||
347 | uint8_t address[TOX_ADDRESS_SIZE]; | 348 | uint8_t address[TOX_ADDRESS_SIZE]; |
348 | tox_self_get_address(tox1, address); | 349 | tox_self_get_address(tox1, address); |
349 | TOX_ERR_FRIEND_ADD error; | 350 | TOX_ERR_FRIEND_ADD error; |
350 | uint32_t ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error); | 351 | uint32_t ret = tox_friend_add(tox1, address, (const uint8_t *)"m", 1, &error); |
351 | ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked."); | 352 | ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked."); |
352 | 353 | ||
353 | tox_self_get_address(tox2, address); | 354 | tox_self_get_address(tox2, address); |
@@ -361,7 +362,7 @@ START_TEST(test_one) | |||
361 | "TOX_MAX_FRIEND_REQUEST_LENGTH is too big."); | 362 | "TOX_MAX_FRIEND_REQUEST_LENGTH is too big."); |
362 | 363 | ||
363 | address[0]++; | 364 | address[0]++; |
364 | ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error); | 365 | ret = tox_friend_add(tox1, address, (const uint8_t *)"m", 1, &error); |
365 | ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_BAD_CHECKSUM, | 366 | ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_BAD_CHECKSUM, |
366 | "Adding address with bad checksum worked."); | 367 | "Adding address with bad checksum worked."); |
367 | 368 | ||
@@ -465,7 +466,7 @@ START_TEST(test_few_clients) | |||
465 | tox_callback_friend_request(tox2, accept_friend_request); | 466 | tox_callback_friend_request(tox2, accept_friend_request); |
466 | uint8_t address[TOX_ADDRESS_SIZE]; | 467 | uint8_t address[TOX_ADDRESS_SIZE]; |
467 | tox_self_get_address(tox2, address); | 468 | tox_self_get_address(tox2, address); |
468 | uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0); | 469 | uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, 0); |
469 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); | 470 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); |
470 | 471 | ||
471 | uint8_t off = 1; | 472 | uint8_t off = 1; |
@@ -560,7 +561,7 @@ START_TEST(test_few_clients) | |||
560 | printf("tox clients connected took %llu seconds\n", time(NULL) - con_time); | 561 | printf("tox clients connected took %llu seconds\n", time(NULL) - con_time); |
561 | tox_callback_friend_name(tox3, print_nickchange); | 562 | tox_callback_friend_name(tox3, print_nickchange); |
562 | TOX_ERR_SET_INFO err_n; | 563 | TOX_ERR_SET_INFO err_n; |
563 | bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); | 564 | bool succ = tox_self_set_name(tox2, (const uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); |
564 | ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n); | 565 | ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n); |
565 | 566 | ||
566 | while (1) { | 567 | while (1) { |
@@ -582,7 +583,7 @@ START_TEST(test_few_clients) | |||
582 | ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); | 583 | ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); |
583 | 584 | ||
584 | tox_callback_friend_status_message(tox3, print_status_m_change); | 585 | tox_callback_friend_status_message(tox3, print_status_m_change); |
585 | succ = tox_self_set_status_message(tox2, (uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n); | 586 | succ = tox_self_set_status_message(tox2, (const uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n); |
586 | ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n); | 587 | ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n); |
587 | 588 | ||
588 | while (1) { | 589 | while (1) { |
@@ -704,7 +705,7 @@ START_TEST(test_few_clients) | |||
704 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); | 705 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); |
705 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); | 706 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); |
706 | uint64_t totalf_size = 100 * 1024 * 1024; | 707 | uint64_t totalf_size = 100 * 1024 * 1024; |
707 | uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", | 708 | uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", |
708 | sizeof("Gentoo.exe"), 0); | 709 | sizeof("Gentoo.exe"), 0); |
709 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); | 710 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); |
710 | 711 | ||
@@ -751,7 +752,8 @@ START_TEST(test_few_clients) | |||
751 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); | 752 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); |
752 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); | 753 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); |
753 | totalf_size = UINT64_MAX; | 754 | totalf_size = UINT64_MAX; |
754 | fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); | 755 | fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), |
756 | 0); | ||
755 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); | 757 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); |
756 | 758 | ||
757 | ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); | 759 | ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); |
@@ -798,7 +800,8 @@ START_TEST(test_few_clients) | |||
798 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); | 800 | tox_callback_file_recv_control(tox3, file_print_control, &to_compare); |
799 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); | 801 | tox_callback_file_recv(tox3, tox_file_receive, &to_compare); |
800 | totalf_size = 0; | 802 | totalf_size = 0; |
801 | fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); | 803 | fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), |
804 | 0); | ||
802 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); | 805 | ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); |
803 | 806 | ||
804 | ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); | 807 | ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); |
@@ -890,7 +893,7 @@ loop_top: | |||
890 | tox_self_get_address(toxes[pairs[i].tox1], address); | 893 | tox_self_get_address(toxes[pairs[i].tox1], address); |
891 | 894 | ||
892 | TOX_ERR_FRIEND_ADD test; | 895 | TOX_ERR_FRIEND_ADD test; |
893 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); | 896 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); |
894 | 897 | ||
895 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { | 898 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { |
896 | goto loop_top; | 899 | goto loop_top; |
@@ -996,7 +999,7 @@ loop_top: | |||
996 | tox_self_get_address(toxes[pairs[i].tox1], address); | 999 | tox_self_get_address(toxes[pairs[i].tox1], address); |
997 | 1000 | ||
998 | TOX_ERR_FRIEND_ADD test; | 1001 | TOX_ERR_FRIEND_ADD test; |
999 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); | 1002 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); |
1000 | 1003 | ||
1001 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { | 1004 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { |
1002 | goto loop_top; | 1005 | goto loop_top; |
@@ -1095,7 +1098,7 @@ loop_top: | |||
1095 | tox_self_get_address(toxes[pairs[i].tox1], address); | 1098 | tox_self_get_address(toxes[pairs[i].tox1], address); |
1096 | 1099 | ||
1097 | TOX_ERR_FRIEND_ADD test; | 1100 | TOX_ERR_FRIEND_ADD test; |
1098 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); | 1101 | uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); |
1099 | 1102 | ||
1100 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { | 1103 | if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { |
1101 | goto loop_top; | 1104 | goto loop_top; |
@@ -1137,7 +1140,8 @@ END_TEST | |||
1137 | 1140 | ||
1138 | #define NUM_GROUP_TOX 32 | 1141 | #define NUM_GROUP_TOX 32 |
1139 | 1142 | ||
1140 | void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 1143 | static void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
1144 | void *userdata) | ||
1141 | { | 1145 | { |
1142 | if (*((uint32_t *)userdata) != 234212) { | 1146 | if (*((uint32_t *)userdata) != 234212) { |
1143 | return; | 1147 | return; |
@@ -1151,8 +1155,9 @@ void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *d | |||
1151 | static Tox *invite_tox; | 1155 | static Tox *invite_tox; |
1152 | static unsigned int invite_counter; | 1156 | static unsigned int invite_counter; |
1153 | 1157 | ||
1154 | void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, | 1158 | static void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, |
1155 | void *userdata) | 1159 | uint16_t length, |
1160 | void *userdata) | ||
1156 | { | 1161 | { |
1157 | if (*((uint32_t *)userdata) != 234212) { | 1162 | if (*((uint32_t *)userdata) != 234212) { |
1158 | return; | 1163 | return; |
@@ -1178,8 +1183,8 @@ void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, c | |||
1178 | 1183 | ||
1179 | static unsigned int num_recv; | 1184 | static unsigned int num_recv; |
1180 | 1185 | ||
1181 | void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, | 1186 | static void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, |
1182 | void *userdata) | 1187 | void *userdata) |
1183 | { | 1188 | { |
1184 | if (*((uint32_t *)userdata) != 234212) { | 1189 | if (*((uint32_t *)userdata) != 234212) { |
1185 | return; | 1190 | return; |
@@ -1217,7 +1222,7 @@ group_test_restart: | |||
1217 | tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address); | 1222 | tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address); |
1218 | 1223 | ||
1219 | for (i = 0; i < NUM_GROUP_TOX; ++i) { | 1224 | for (i = 0; i < NUM_GROUP_TOX; ++i) { |
1220 | ck_assert_msg(tox_friend_add(toxes[i], address, (uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend"); | 1225 | ck_assert_msg(tox_friend_add(toxes[i], address, (const uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend"); |
1221 | 1226 | ||
1222 | tox_self_get_address(toxes[i], address); | 1227 | tox_self_get_address(toxes[i], address); |
1223 | } | 1228 | } |
@@ -1310,7 +1315,7 @@ group_test_restart: | |||
1310 | tox_callback_group_message(toxes[i], &print_group_message, &to_comp); | 1315 | tox_callback_group_message(toxes[i], &print_group_message, &to_comp); |
1311 | } | 1316 | } |
1312 | 1317 | ||
1313 | ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, (uint8_t *)"Install Gentoo", | 1318 | ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, (const uint8_t *)"Install Gentoo", |
1314 | sizeof("Install Gentoo") - 1) == 0, "Failed to send group message."); | 1319 | sizeof("Install Gentoo") - 1) == 0, "Failed to send group message."); |
1315 | num_recv = 0; | 1320 | num_recv = 0; |
1316 | 1321 | ||
@@ -1358,7 +1363,7 @@ uint8_t timeout_mux = 20; | |||
1358 | uint8_t timeout_mux = 10; | 1363 | uint8_t timeout_mux = 10; |
1359 | #endif | 1364 | #endif |
1360 | 1365 | ||
1361 | Suite *tox_suite(void) | 1366 | static Suite *tox_suite(void) |
1362 | { | 1367 | { |
1363 | Suite *s = suite_create("Tox"); | 1368 | Suite *s = suite_create("Tox"); |
1364 | 1369 | ||
@@ -1398,4 +1403,3 @@ int main(int argc, char *argv[]) | |||
1398 | 1403 | ||
1399 | return number_failed; | 1404 | return number_failed; |
1400 | } | 1405 | } |
1401 | |||
diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index e3c4447e..399eac68 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c | |||
@@ -6,7 +6,7 @@ | |||
6 | # include <assert.h> | 6 | # include <assert.h> |
7 | 7 | ||
8 | # define ck_assert(X) assert(X); | 8 | # define ck_assert(X) assert(X); |
9 | # define START_TEST(NAME) void NAME () | 9 | # define START_TEST(NAME) static void NAME (void) |
10 | # define END_TEST | 10 | # define END_TEST |
11 | #else | 11 | #else |
12 | # include "helpers.h" | 12 | # include "helpers.h" |
@@ -66,7 +66,7 @@ typedef struct { | |||
66 | /** | 66 | /** |
67 | * Callbacks | 67 | * Callbacks |
68 | */ | 68 | */ |
69 | void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 69 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
70 | { | 70 | { |
71 | (void) av; | 71 | (void) av; |
72 | (void) friend_number; | 72 | (void) friend_number; |
@@ -76,7 +76,7 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool | |||
76 | printf("Handling CALL callback\n"); | 76 | printf("Handling CALL callback\n"); |
77 | ((CallControl *)user_data)->incoming = true; | 77 | ((CallControl *)user_data)->incoming = true; |
78 | } | 78 | } |
79 | void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 79 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
80 | { | 80 | { |
81 | (void) av; | 81 | (void) av; |
82 | (void) friend_number; | 82 | (void) friend_number; |
@@ -84,11 +84,11 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo | |||
84 | printf("Handling CALL STATE callback: %d\n", state); | 84 | printf("Handling CALL STATE callback: %d\n", state); |
85 | ((CallControl *)user_data)->state = state; | 85 | ((CallControl *)user_data)->state = state; |
86 | } | 86 | } |
87 | void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 87 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
88 | uint16_t width, uint16_t height, | 88 | uint16_t width, uint16_t height, |
89 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 89 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
90 | int32_t ystride, int32_t ustride, int32_t vstride, | 90 | int32_t ystride, int32_t ustride, int32_t vstride, |
91 | void *user_data) | 91 | void *user_data) |
92 | { | 92 | { |
93 | (void) av; | 93 | (void) av; |
94 | (void) friend_number; | 94 | (void) friend_number; |
@@ -103,12 +103,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | |||
103 | (void) user_data; | 103 | (void) user_data; |
104 | printf("Received video payload\n"); | 104 | printf("Received video payload\n"); |
105 | } | 105 | } |
106 | void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 106 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
107 | int16_t const *pcm, | 107 | int16_t const *pcm, |
108 | size_t sample_count, | 108 | size_t sample_count, |
109 | uint8_t channels, | 109 | uint8_t channels, |
110 | uint32_t sampling_rate, | 110 | uint32_t sampling_rate, |
111 | void *user_data) | 111 | void *user_data) |
112 | { | 112 | { |
113 | (void) av; | 113 | (void) av; |
114 | (void) friend_number; | 114 | (void) friend_number; |
@@ -119,7 +119,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
119 | (void) user_data; | 119 | (void) user_data; |
120 | printf("Received audio payload\n"); | 120 | printf("Received audio payload\n"); |
121 | } | 121 | } |
122 | void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 122 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
123 | void *userdata) | ||
123 | { | 124 | { |
124 | (void) userdata; | 125 | (void) userdata; |
125 | 126 | ||
@@ -132,7 +133,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t | |||
132 | /** | 133 | /** |
133 | * Iterate helper | 134 | * Iterate helper |
134 | */ | 135 | */ |
135 | int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) | 136 | static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) |
136 | { | 137 | { |
137 | c_sleep(100); | 138 | c_sleep(100); |
138 | tox_iterate(bootstrap, NULL); | 139 | tox_iterate(bootstrap, NULL); |
@@ -175,7 +176,7 @@ START_TEST(test_AV_flows) | |||
175 | tox_self_get_address(Alice, address); | 176 | tox_self_get_address(Alice, address); |
176 | 177 | ||
177 | 178 | ||
178 | ck_assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 179 | ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
179 | 180 | ||
180 | uint8_t off = 1; | 181 | uint8_t off = 1; |
181 | 182 | ||
@@ -601,7 +602,7 @@ int main(int argc, char *argv[]) | |||
601 | return 0; | 602 | return 0; |
602 | } | 603 | } |
603 | #else | 604 | #else |
604 | Suite *tox_suite(void) | 605 | static Suite *tox_suite(void) |
605 | { | 606 | { |
606 | Suite *s = suite_create("ToxAV"); | 607 | Suite *s = suite_create("ToxAV"); |
607 | 608 | ||
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 5d889032..e3dd5a42 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c | |||
@@ -6,7 +6,7 @@ | |||
6 | # include <assert.h> | 6 | # include <assert.h> |
7 | 7 | ||
8 | # define ck_assert(X) assert(X); | 8 | # define ck_assert(X) assert(X); |
9 | # define START_TEST(NAME) void NAME () | 9 | # define START_TEST(NAME) static void NAME (void) |
10 | # define END_TEST | 10 | # define END_TEST |
11 | #else | 11 | #else |
12 | # include "helpers.h" | 12 | # include "helpers.h" |
@@ -52,7 +52,7 @@ typedef struct { | |||
52 | /** | 52 | /** |
53 | * Callbacks | 53 | * Callbacks |
54 | */ | 54 | */ |
55 | void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 55 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
56 | { | 56 | { |
57 | (void) av; | 57 | (void) av; |
58 | (void) audio_enabled; | 58 | (void) audio_enabled; |
@@ -61,16 +61,16 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool | |||
61 | printf("Handling CALL callback\n"); | 61 | printf("Handling CALL callback\n"); |
62 | ((CallControl *)user_data)[friend_number].incoming = true; | 62 | ((CallControl *)user_data)[friend_number].incoming = true; |
63 | } | 63 | } |
64 | void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 64 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
65 | { | 65 | { |
66 | printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); | 66 | printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); |
67 | ((CallControl *)user_data)[friend_number].state = state; | 67 | ((CallControl *)user_data)[friend_number].state = state; |
68 | } | 68 | } |
69 | void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 69 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
70 | uint16_t width, uint16_t height, | 70 | uint16_t width, uint16_t height, |
71 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 71 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
72 | int32_t ystride, int32_t ustride, int32_t vstride, | 72 | int32_t ystride, int32_t ustride, int32_t vstride, |
73 | void *user_data) | 73 | void *user_data) |
74 | { | 74 | { |
75 | (void) av; | 75 | (void) av; |
76 | (void) friend_number; | 76 | (void) friend_number; |
@@ -84,12 +84,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | |||
84 | (void) vstride; | 84 | (void) vstride; |
85 | (void) user_data; | 85 | (void) user_data; |
86 | } | 86 | } |
87 | void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 87 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
88 | int16_t const *pcm, | 88 | int16_t const *pcm, |
89 | size_t sample_count, | 89 | size_t sample_count, |
90 | uint8_t channels, | 90 | uint8_t channels, |
91 | uint32_t sampling_rate, | 91 | uint32_t sampling_rate, |
92 | void *user_data) | 92 | void *user_data) |
93 | { | 93 | { |
94 | (void) av; | 94 | (void) av; |
95 | (void) friend_number; | 95 | (void) friend_number; |
@@ -99,7 +99,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
99 | (void) sampling_rate; | 99 | (void) sampling_rate; |
100 | (void) user_data; | 100 | (void) user_data; |
101 | } | 101 | } |
102 | void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 102 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
103 | void *userdata) | ||
103 | { | 104 | { |
104 | (void) userdata; | 105 | (void) userdata; |
105 | 106 | ||
@@ -112,7 +113,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t | |||
112 | /** | 113 | /** |
113 | * Iterate helper | 114 | * Iterate helper |
114 | */ | 115 | */ |
115 | ToxAV *setup_av_instance(Tox *tox, CallControl *CC) | 116 | static ToxAV *setup_av_instance(Tox *tox, CallControl *CC) |
116 | { | 117 | { |
117 | TOXAV_ERR_NEW error; | 118 | TOXAV_ERR_NEW error; |
118 | 119 | ||
@@ -126,7 +127,7 @@ ToxAV *setup_av_instance(Tox *tox, CallControl *CC) | |||
126 | 127 | ||
127 | return av; | 128 | return av; |
128 | } | 129 | } |
129 | void *call_thread(void *pd) | 130 | static void *call_thread(void *pd) |
130 | { | 131 | { |
131 | ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; | 132 | ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; |
132 | ToxAV *BobAV = ((thread_data *) pd)->BobAV; | 133 | ToxAV *BobAV = ((thread_data *) pd)->BobAV; |
@@ -241,9 +242,9 @@ START_TEST(test_AV_three_calls) | |||
241 | tox_self_get_address(Alice, address); | 242 | tox_self_get_address(Alice, address); |
242 | 243 | ||
243 | 244 | ||
244 | ck_assert(tox_friend_add(Bobs[0], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 245 | ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
245 | ck_assert(tox_friend_add(Bobs[1], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 246 | ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
246 | ck_assert(tox_friend_add(Bobs[2], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 247 | ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
247 | 248 | ||
248 | uint8_t off = 1; | 249 | uint8_t off = 1; |
249 | 250 | ||
@@ -351,7 +352,7 @@ int main(int argc, char *argv[]) | |||
351 | return 0; | 352 | return 0; |
352 | } | 353 | } |
353 | #else | 354 | #else |
354 | Suite *tox_suite(void) | 355 | static Suite *tox_suite(void) |
355 | { | 356 | { |
356 | Suite *s = suite_create("ToxAV"); | 357 | Suite *s = suite_create("ToxAV"); |
357 | 358 | ||
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 8ea4c161..2dc24b4e 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -58,7 +58,7 @@ | |||
58 | #define PORT 33445 | 58 | #define PORT 33445 |
59 | 59 | ||
60 | 60 | ||
61 | void manage_keys(DHT *dht) | 61 | static void manage_keys(DHT *dht) |
62 | { | 62 | { |
63 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; | 63 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; |
64 | uint8_t keys[KEYS_SIZE]; | 64 | uint8_t keys[KEYS_SIZE]; |
diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index ecfef1ad..262dd4c8 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c | |||
@@ -35,7 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Prints --help message | 36 | * Prints --help message |
37 | */ | 37 | */ |
38 | void print_help() | 38 | static void print_help(void) |
39 | { | 39 | { |
40 | // 2 space ident | 40 | // 2 space ident |
41 | // make sure all lines fit into 80 columns | 41 | // make sure all lines fit into 80 columns |
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index dc0a251c..a0c6045d 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c | |||
@@ -41,7 +41,7 @@ | |||
41 | * | 41 | * |
42 | * Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports`. | 42 | * Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports`. |
43 | */ | 43 | */ |
44 | void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) | 44 | static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) |
45 | { | 45 | { |
46 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; | 46 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; |
47 | 47 | ||
@@ -303,7 +303,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k | |||
303 | * @return binary on success, | 303 | * @return binary on success, |
304 | * NULL on failure. | 304 | * NULL on failure. |
305 | */ | 305 | */ |
306 | uint8_t *hex_string_to_bin(char *hex_string) | 306 | static uint8_t *hex_string_to_bin(const char *hex_string) |
307 | { | 307 | { |
308 | if (strlen(hex_string) % 2 != 0) { | 308 | if (strlen(hex_string) % 2 != 0) { |
309 | return NULL; | 309 | return NULL; |
@@ -312,7 +312,7 @@ uint8_t *hex_string_to_bin(char *hex_string) | |||
312 | size_t len = strlen(hex_string) / 2; | 312 | size_t len = strlen(hex_string) / 2; |
313 | uint8_t *ret = malloc(len); | 313 | uint8_t *ret = malloc(len); |
314 | 314 | ||
315 | char *pos = hex_string; | 315 | const char *pos = hex_string; |
316 | size_t i; | 316 | size_t i; |
317 | 317 | ||
318 | for (i = 0; i < len; ++i, pos += 2) { | 318 | for (i = 0; i < len; ++i, pos += 2) { |
@@ -403,7 +403,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
403 | goto next; | 403 | goto next; |
404 | } | 404 | } |
405 | 405 | ||
406 | uint8_t *bs_public_key_bin = hex_string_to_bin((char *)bs_public_key); | 406 | uint8_t *bs_public_key_bin = hex_string_to_bin((const char *)bs_public_key); |
407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), | 407 | const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), |
408 | bs_public_key_bin); | 408 | bs_public_key_bin); |
409 | free(bs_public_key_bin); | 409 | free(bs_public_key_bin); |
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index ee3a1421..e0fb3b33 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c | |||
@@ -48,7 +48,7 @@ bool open_log(LOG_BACKEND backend) | |||
48 | return true; | 48 | return true; |
49 | } | 49 | } |
50 | 50 | ||
51 | bool close_log() | 51 | bool close_log(void) |
52 | { | 52 | { |
53 | if (current_backend == -1) { | 53 | if (current_backend == -1) { |
54 | return false; | 54 | return false; |
@@ -63,7 +63,7 @@ bool close_log() | |||
63 | return true; | 63 | return true; |
64 | } | 64 | } |
65 | 65 | ||
66 | int level_syslog(LOG_LEVEL level) | 66 | static int level_syslog(LOG_LEVEL level) |
67 | { | 67 | { |
68 | switch (level) { | 68 | switch (level) { |
69 | case LOG_LEVEL_INFO: | 69 | case LOG_LEVEL_INFO: |
@@ -79,12 +79,12 @@ int level_syslog(LOG_LEVEL level) | |||
79 | return LOG_INFO; | 79 | return LOG_INFO; |
80 | } | 80 | } |
81 | 81 | ||
82 | void log_syslog(LOG_LEVEL level, const char *format, va_list args) | 82 | static void log_syslog(LOG_LEVEL level, const char *format, va_list args) |
83 | { | 83 | { |
84 | vsyslog(level_syslog(level), format, args); | 84 | vsyslog(level_syslog(level), format, args); |
85 | } | 85 | } |
86 | 86 | ||
87 | FILE *level_stdout(LOG_LEVEL level) | 87 | static FILE *level_stdout(LOG_LEVEL level) |
88 | { | 88 | { |
89 | switch (level) { | 89 | switch (level) { |
90 | case LOG_LEVEL_INFO: | 90 | case LOG_LEVEL_INFO: |
@@ -98,7 +98,7 @@ FILE *level_stdout(LOG_LEVEL level) | |||
98 | return stdout; | 98 | return stdout; |
99 | } | 99 | } |
100 | 100 | ||
101 | void log_stdout(LOG_LEVEL level, const char *format, va_list args) | 101 | static void log_stdout(LOG_LEVEL level, const char *format, va_list args) |
102 | { | 102 | { |
103 | vfprintf(level_stdout(level), format, args); | 103 | vfprintf(level_stdout(level), format, args); |
104 | fflush(level_stdout(level)); | 104 | fflush(level_stdout(level)); |
diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h index 61cb2ee3..cb374968 100644 --- a/other/bootstrap_daemon/src/log.h +++ b/other/bootstrap_daemon/src/log.h | |||
@@ -49,7 +49,7 @@ bool open_log(LOG_BACKEND backend); | |||
49 | * Releases all used resources by the logger. | 49 | * Releases all used resources by the logger. |
50 | * @return true on success, flase if log is already closed. | 50 | * @return true on success, flase if log is already closed. |
51 | */ | 51 | */ |
52 | bool close_log(); | 52 | bool close_log(void); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Writes a message to the log. | 55 | * Writes a message to the log. |
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 06ea45aa..fe360b4e 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -53,7 +53,7 @@ | |||
53 | // returns 1 on success | 53 | // returns 1 on success |
54 | // 0 on failure - no keys were read or stored | 54 | // 0 on failure - no keys were read or stored |
55 | 55 | ||
56 | int manage_keys(DHT *dht, char *keys_file_path) | 56 | static int manage_keys(DHT *dht, char *keys_file_path) |
57 | { | 57 | { |
58 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; | 58 | enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; |
59 | uint8_t keys[KEYS_SIZE]; | 59 | uint8_t keys[KEYS_SIZE]; |
@@ -98,7 +98,7 @@ int manage_keys(DHT *dht, char *keys_file_path) | |||
98 | 98 | ||
99 | // Prints public key | 99 | // Prints public key |
100 | 100 | ||
101 | void print_public_key(const uint8_t *public_key) | 101 | static void print_public_key(const uint8_t *public_key) |
102 | { | 102 | { |
103 | char buffer[2 * crypto_box_PUBLICKEYBYTES + 1]; | 103 | char buffer[2 * crypto_box_PUBLICKEYBYTES + 1]; |
104 | int index = 0; | 104 | int index = 0; |
@@ -115,7 +115,7 @@ void print_public_key(const uint8_t *public_key) | |||
115 | // Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend | 115 | // Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend |
116 | // Terminates the application if the daemonization fails. | 116 | // Terminates the application if the daemonization fails. |
117 | 117 | ||
118 | void daemonize(LOG_BACKEND log_backend, char *pid_file_path) | 118 | static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) |
119 | { | 119 | { |
120 | // Check if the PID file exists | 120 | // Check if the PID file exists |
121 | FILE *pid_file; | 121 | FILE *pid_file; |
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index f6a2c4bc..04340b0e 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -54,7 +54,7 @@ | |||
54 | 54 | ||
55 | uint8_t zeroes_cid[crypto_box_PUBLICKEYBYTES]; | 55 | uint8_t zeroes_cid[crypto_box_PUBLICKEYBYTES]; |
56 | 56 | ||
57 | void print_client_id(uint8_t *public_key) | 57 | static void print_client_id(uint8_t *public_key) |
58 | { | 58 | { |
59 | uint32_t j; | 59 | uint32_t j; |
60 | 60 | ||
@@ -63,7 +63,7 @@ void print_client_id(uint8_t *public_key) | |||
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | void print_hardening(Hardening *h) | 66 | static void print_hardening(Hardening *h) |
67 | { | 67 | { |
68 | printf("Hardening:\n"); | 68 | printf("Hardening:\n"); |
69 | printf("routes_requests_ok: %hhu\n", h->routes_requests_ok); | 69 | printf("routes_requests_ok: %hhu\n", h->routes_requests_ok); |
@@ -81,7 +81,7 @@ void print_hardening(Hardening *h) | |||
81 | printf("\n\n"); | 81 | printf("\n\n"); |
82 | } | 82 | } |
83 | 83 | ||
84 | void print_assoc(IPPTsPng *assoc, uint8_t ours) | 84 | static void print_assoc(IPPTsPng *assoc, uint8_t ours) |
85 | { | 85 | { |
86 | IP_Port *ipp = &assoc->ip_port; | 86 | IP_Port *ipp = &assoc->ip_port; |
87 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port)); | 87 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port)); |
@@ -100,7 +100,7 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours) | |||
100 | print_hardening(&assoc->hardening); | 100 | print_hardening(&assoc->hardening); |
101 | } | 101 | } |
102 | 102 | ||
103 | void print_clientlist(DHT *dht) | 103 | static void print_clientlist(DHT *dht) |
104 | { | 104 | { |
105 | uint32_t i; | 105 | uint32_t i; |
106 | printf("___________________CLOSE________________________________\n"); | 106 | printf("___________________CLOSE________________________________\n"); |
@@ -120,7 +120,7 @@ void print_clientlist(DHT *dht) | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | void print_friendlist(DHT *dht) | 123 | static void print_friendlist(DHT *dht) |
124 | { | 124 | { |
125 | uint32_t i, k; | 125 | uint32_t i, k; |
126 | IP_Port p_ip; | 126 | IP_Port p_ip; |
@@ -153,7 +153,8 @@ void print_friendlist(DHT *dht) | |||
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | 156 | #if 0 /* slvrTODO: */ |
157 | static void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | ||
157 | { | 158 | { |
158 | uint32_t i; | 159 | uint32_t i; |
159 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); | 160 | printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); |
@@ -169,6 +170,7 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) | |||
169 | 170 | ||
170 | printf("\n--------------------END-----------------------------\n\n\n"); | 171 | printf("\n--------------------END-----------------------------\n\n\n"); |
171 | } | 172 | } |
173 | #endif | ||
172 | 174 | ||
173 | int main(int argc, char *argv[]) | 175 | int main(int argc, char *argv[]) |
174 | { | 176 | { |
@@ -230,26 +232,27 @@ int main(int argc, char *argv[]) | |||
230 | return 1; | 232 | return 1; |
231 | } | 233 | } |
232 | 234 | ||
233 | /* | 235 | #if 0 /* slvrTODO: */ |
234 | IP_Port ip_port; | 236 | IP_Port ip_port; |
235 | uint8_t data[MAX_UDP_PACKET_SIZE]; | 237 | uint8_t data[MAX_UDP_PACKET_SIZE]; |
236 | uint32_t length; | 238 | uint32_t length; |
237 | */ | 239 | #endif |
238 | 240 | ||
239 | while (1) { | 241 | while (1) { |
240 | |||
241 | do_DHT(dht); | 242 | do_DHT(dht); |
242 | 243 | ||
243 | /* slvrTODO: | 244 | #if 0 /* slvrTODO: */ |
244 | while(receivepacket(&ip_port, data, &length) != -1) { | 245 | |
245 | if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { | 246 | while (receivepacket(&ip_port, data, &length) != -1) { |
246 | //unhandled packet | 247 | if (DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { |
247 | printpacket(data, length, ip_port); | 248 | //unhandled packet |
248 | } else { | 249 | printpacket(data, length, ip_port); |
249 | printf("Received handled packet with length: %u\n", length); | 250 | } else { |
250 | } | 251 | printf("Received handled packet with length: %u\n", length); |
251 | } | 252 | } |
252 | */ | 253 | } |
254 | |||
255 | #endif | ||
253 | networking_poll(dht->net, NULL); | 256 | networking_poll(dht->net, NULL); |
254 | 257 | ||
255 | print_clientlist(dht); | 258 | print_clientlist(dht); |
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 668f046a..84508621 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c | |||
@@ -56,18 +56,18 @@ | |||
56 | 56 | ||
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, | 59 | static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, |
60 | void *userdata) | 60 | void *userdata) |
61 | { | 61 | { |
62 | printf("Message with length %lu received from %u: %s \n", length, friendnumber, string); | 62 | printf("Message with length %lu received from %u: %s \n", length, friendnumber, string); |
63 | m_send_message_generic(m, friendnumber, type, (uint8_t *)"Test1", 6, 0); | 63 | m_send_message_generic(m, friendnumber, type, (const uint8_t *)"Test1", 6, 0); |
64 | } | 64 | } |
65 | 65 | ||
66 | /* FIXME needed as print_request has to match the interface expected by | 66 | /* FIXME needed as print_request has to match the interface expected by |
67 | * networking_requesthandler and so cannot take a Messenger * */ | 67 | * networking_requesthandler and so cannot take a Messenger * */ |
68 | static Messenger *m; | 68 | static Messenger *m; |
69 | 69 | ||
70 | void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 70 | static void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
71 | { | 71 | { |
72 | printf("Friend request received from: \n"); | 72 | printf("Friend request received from: \n"); |
73 | printf("ClientID: "); | 73 | printf("ClientID: "); |
@@ -164,7 +164,7 @@ int main(int argc, char *argv[]) | |||
164 | printf("%hhX", address[i]); | 164 | printf("%hhX", address[i]); |
165 | } | 165 | } |
166 | 166 | ||
167 | setname(m, (uint8_t *)"Anon", 5); | 167 | setname(m, (const uint8_t *)"Anon", 5); |
168 | 168 | ||
169 | char temp_hex_id[128]; | 169 | char temp_hex_id[128]; |
170 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); | 170 | printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); |
@@ -178,7 +178,7 @@ int main(int argc, char *argv[]) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); | 180 | uint8_t *bin_id = hex_string_to_bin(temp_hex_id); |
181 | int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); | 181 | int num = m_addfriend(m, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); |
182 | free(bin_id); | 182 | free(bin_id); |
183 | 183 | ||
184 | perror("Initialization"); | 184 | perror("Initialization"); |
@@ -188,7 +188,7 @@ int main(int argc, char *argv[]) | |||
188 | getname(m, num, name); | 188 | getname(m, num, name); |
189 | printf("%s\n", name); | 189 | printf("%s\n", name); |
190 | 190 | ||
191 | m_send_message_generic(m, num, MESSAGE_NORMAL, (uint8_t *)"Test", 5, 0); | 191 | m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, 0); |
192 | do_messenger(m, NULL); | 192 | do_messenger(m, NULL); |
193 | c_sleep(30); | 193 | c_sleep(30); |
194 | FILE *file = fopen("Save.bak", "wb"); | 194 | FILE *file = fopen("Save.bak", "wb"); |
diff --git a/testing/av_test.c b/testing/av_test.c index 35eb3f60..5dc2643c 100644 --- a/testing/av_test.c +++ b/testing/av_test.c | |||
@@ -84,15 +84,15 @@ struct toxav_thread_data { | |||
84 | int32_t sig; | 84 | int32_t sig; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | const char *vdout = "AV Test"; /* Video output */ | 87 | static const char *vdout = "AV Test"; /* Video output */ |
88 | PaStream *adout = NULL; /* Audio output */ | 88 | static PaStream *adout = NULL; /* Audio output */ |
89 | 89 | ||
90 | typedef struct { | 90 | typedef struct { |
91 | uint16_t size; | 91 | uint16_t size; |
92 | int16_t data[]; | 92 | int16_t data[]; |
93 | } frame; | 93 | } frame; |
94 | 94 | ||
95 | void *pa_write_thread (void *d) | 95 | static void *pa_write_thread (void *d) |
96 | { | 96 | { |
97 | /* The purpose of this thread is to make sure Pa_WriteStream will not block | 97 | /* The purpose of this thread is to make sure Pa_WriteStream will not block |
98 | * toxav_iterate thread | 98 | * toxav_iterate thread |
@@ -119,21 +119,21 @@ void *pa_write_thread (void *d) | |||
119 | /** | 119 | /** |
120 | * Callbacks | 120 | * Callbacks |
121 | */ | 121 | */ |
122 | void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) | 122 | static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) |
123 | { | 123 | { |
124 | printf("Handling CALL callback\n"); | 124 | printf("Handling CALL callback\n"); |
125 | ((CallControl *)user_data)->incoming = true; | 125 | ((CallControl *)user_data)->incoming = true; |
126 | } | 126 | } |
127 | void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) | 127 | static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) |
128 | { | 128 | { |
129 | printf("Handling CALL STATE callback: %d\n", state); | 129 | printf("Handling CALL STATE callback: %d\n", state); |
130 | ((CallControl *)user_data)->state = state; | 130 | ((CallControl *)user_data)->state = state; |
131 | } | 131 | } |
132 | void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | 132 | static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, |
133 | uint16_t width, uint16_t height, | 133 | uint16_t width, uint16_t height, |
134 | uint8_t const *y, uint8_t const *u, uint8_t const *v, | 134 | uint8_t const *y, uint8_t const *u, uint8_t const *v, |
135 | int32_t ystride, int32_t ustride, int32_t vstride, | 135 | int32_t ystride, int32_t ustride, int32_t vstride, |
136 | void *user_data) | 136 | void *user_data) |
137 | { | 137 | { |
138 | ystride = abs(ystride); | 138 | ystride = abs(ystride); |
139 | ustride = abs(ustride); | 139 | ustride = abs(ustride); |
@@ -166,12 +166,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, | |||
166 | cvShowImage(vdout, img); | 166 | cvShowImage(vdout, img); |
167 | free(img_data); | 167 | free(img_data); |
168 | } | 168 | } |
169 | void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | 169 | static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, |
170 | int16_t const *pcm, | 170 | int16_t const *pcm, |
171 | size_t sample_count, | 171 | size_t sample_count, |
172 | uint8_t channels, | 172 | uint8_t channels, |
173 | uint32_t sampling_rate, | 173 | uint32_t sampling_rate, |
174 | void *user_data) | 174 | void *user_data) |
175 | { | 175 | { |
176 | CallControl *cc = user_data; | 176 | CallControl *cc = user_data; |
177 | frame *f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels); | 177 | frame *f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels); |
@@ -182,13 +182,14 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, | |||
182 | free(rb_write(cc->arb, f)); | 182 | free(rb_write(cc->arb, f)); |
183 | pthread_mutex_unlock(cc->arb_mutex); | 183 | pthread_mutex_unlock(cc->arb_mutex); |
184 | } | 184 | } |
185 | void t_toxav_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, | 185 | static void t_toxav_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, |
186 | uint32_t audio_bit_rate, uint32_t video_bit_rate, | 186 | uint32_t audio_bit_rate, uint32_t video_bit_rate, |
187 | void *user_data) | 187 | void *user_data) |
188 | { | 188 | { |
189 | printf ("Suggested bit rates: audio: %d video: %d\n", audio_bit_rate, video_bit_rate); | 189 | printf ("Suggested bit rates: audio: %d video: %d\n", audio_bit_rate, video_bit_rate); |
190 | } | 190 | } |
191 | void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 191 | static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, |
192 | void *userdata) | ||
192 | { | 193 | { |
193 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { | 194 | if (length == 7 && memcmp("gentoo", data, 7) == 0) { |
194 | assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); | 195 | assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); |
@@ -197,7 +198,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t | |||
197 | 198 | ||
198 | /** | 199 | /** |
199 | */ | 200 | */ |
200 | void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxAV **BobAV, CallControl *BobCC) | 201 | static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxAV **BobAV, CallControl *BobCC) |
201 | { | 202 | { |
202 | Tox *Alice; | 203 | Tox *Alice; |
203 | Tox *Bob; | 204 | Tox *Bob; |
@@ -235,7 +236,7 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA | |||
235 | tox_self_get_address(Alice, address); | 236 | tox_self_get_address(Alice, address); |
236 | 237 | ||
237 | 238 | ||
238 | assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); | 239 | assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); |
239 | 240 | ||
240 | uint8_t off = 1; | 241 | uint8_t off = 1; |
241 | 242 | ||
@@ -286,7 +287,7 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA | |||
286 | printf("Created 2 instances of ToxAV\n"); | 287 | printf("Created 2 instances of ToxAV\n"); |
287 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); | 288 | printf("All set after %llu seconds!\n", time(NULL) - cur_time); |
288 | } | 289 | } |
289 | int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) | 290 | static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) |
290 | { | 291 | { |
291 | tox_iterate(bootstrap, userdata); | 292 | tox_iterate(bootstrap, userdata); |
292 | tox_iterate(toxav_get_tox(AliceAV), userdata); | 293 | tox_iterate(toxav_get_tox(AliceAV), userdata); |
@@ -294,7 +295,7 @@ int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) | |||
294 | 295 | ||
295 | return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); | 296 | return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); |
296 | } | 297 | } |
297 | void *iterate_toxav (void *data) | 298 | static void *iterate_toxav (void *data) |
298 | { | 299 | { |
299 | struct toxav_thread_data *data_cast = data; | 300 | struct toxav_thread_data *data_cast = data; |
300 | #if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 | 301 | #if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 |
@@ -330,7 +331,7 @@ void *iterate_toxav (void *data) | |||
330 | pthread_exit(NULL); | 331 | pthread_exit(NULL); |
331 | } | 332 | } |
332 | 333 | ||
333 | int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) | 334 | static int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) |
334 | { | 335 | { |
335 | int32_t strides[3] = { 1280, 640, 640 }; | 336 | int32_t strides[3] = { 1280, 640, 640 }; |
336 | uint8_t *planes[3] = { | 337 | uint8_t *planes[3] = { |
@@ -368,7 +369,7 @@ int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) | |||
368 | free(planes[2]); | 369 | free(planes[2]); |
369 | return rc; | 370 | return rc; |
370 | } | 371 | } |
371 | int print_audio_devices() | 372 | static int print_audio_devices(void) |
372 | { | 373 | { |
373 | int i = 0; | 374 | int i = 0; |
374 | 375 | ||
@@ -382,7 +383,7 @@ int print_audio_devices() | |||
382 | 383 | ||
383 | return 0; | 384 | return 0; |
384 | } | 385 | } |
385 | int print_help (const char *name) | 386 | static int print_help (const char *name) |
386 | { | 387 | { |
387 | printf("Usage: %s -[a:v:o:dh]\n" | 388 | printf("Usage: %s -[a:v:o:dh]\n" |
388 | "-a <path> audio input file\n" | 389 | "-a <path> audio input file\n" |
diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 830ecfd8..3151dd99 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c | |||
@@ -14,7 +14,7 @@ | |||
14 | 14 | ||
15 | #endif | 15 | #endif |
16 | 16 | ||
17 | uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id) | 17 | static uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id) |
18 | { | 18 | { |
19 | memset(packet, 0, str_len + 13 + 16); | 19 | memset(packet, 0, str_len + 13 + 16); |
20 | packet[0] = id; | 20 | packet[0] = id; |
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index 558b3631..874c31f5 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c | |||
@@ -27,12 +27,12 @@ | |||
27 | #define IRC_CHANNEL "#tox-real-ontopic" | 27 | #define IRC_CHANNEL "#tox-real-ontopic" |
28 | 28 | ||
29 | //IRC server ip and port. | 29 | //IRC server ip and port. |
30 | uint8_t ip[4] = {127, 0, 0, 1}; | 30 | static uint8_t ip[4] = {127, 0, 0, 1}; |
31 | uint16_t port = 6667; | 31 | static uint16_t port = 6667; |
32 | 32 | ||
33 | #define SILENT_TIMEOUT 20 | 33 | #define SILENT_TIMEOUT 20 |
34 | 34 | ||
35 | int sock; | 35 | static int sock; |
36 | 36 | ||
37 | #define SERVER_CONNECT "NICK "IRC_NAME"\nUSER "IRC_NAME" 8 * :"IRC_NAME"\n" | 37 | #define SERVER_CONNECT "NICK "IRC_NAME"\nUSER "IRC_NAME" 8 * :"IRC_NAME"\n" |
38 | #define CHANNEL_JOIN "JOIN "IRC_CHANNEL"\n" | 38 | #define CHANNEL_JOIN "JOIN "IRC_CHANNEL"\n" |
@@ -40,12 +40,12 @@ int sock; | |||
40 | /* In toxcore/network.c */ | 40 | /* In toxcore/network.c */ |
41 | uint64_t current_time_monotonic(void); | 41 | uint64_t current_time_monotonic(void); |
42 | 42 | ||
43 | uint64_t get_monotime_sec(void) | 43 | static uint64_t get_monotime_sec(void) |
44 | { | 44 | { |
45 | return current_time_monotonic() / 1000; | 45 | return current_time_monotonic() / 1000; |
46 | } | 46 | } |
47 | 47 | ||
48 | int reconnect(void) | 48 | static int reconnect(void) |
49 | { | 49 | { |
50 | int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 50 | int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
51 | 51 | ||
@@ -81,7 +81,7 @@ int reconnect(void) | |||
81 | #include "../toxcore/tox.h" | 81 | #include "../toxcore/tox.h" |
82 | #include "misc_tools.c" | 82 | #include "misc_tools.c" |
83 | 83 | ||
84 | int current_group = -1; | 84 | static 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 | { |
@@ -90,8 +90,9 @@ static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t | |||
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, | 93 | static void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, |
94 | void *userdata) | 94 | size_t length, |
95 | void *userdata) | ||
95 | { | 96 | { |
96 | if (length == 1 && *message == 'c') { | 97 | if (length == 1 && *message == 'c') { |
97 | if (tox_del_groupchat(tox, current_group) == 0) { | 98 | if (tox_del_groupchat(tox, current_group) == 0) { |
@@ -156,7 +157,7 @@ static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, | |||
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
159 | void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | 160 | static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) |
160 | { | 161 | { |
161 | if (len > 1350 || len == 0 || len == 1) { | 162 | if (len > 1350 || len == 0 || len == 1) { |
162 | return; | 163 | return; |
@@ -218,7 +219,7 @@ void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) | |||
218 | tox_group_message_send(tox, current_group, message, length); | 219 | tox_group_message_send(tox, current_group, message, length); |
219 | } | 220 | } |
220 | 221 | ||
221 | Tox *init_tox(int argc, char *argv[]) | 222 | static Tox *init_tox(int argc, char *argv[]) |
222 | { | 223 | { |
223 | uint8_t ipv6enabled = 1; /* x */ | 224 | uint8_t ipv6enabled = 1; /* x */ |
224 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); | 225 | int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); |
@@ -239,7 +240,7 @@ Tox *init_tox(int argc, char *argv[]) | |||
239 | exit(1); | 240 | exit(1); |
240 | } | 241 | } |
241 | 242 | ||
242 | tox_self_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); | 243 | tox_self_set_name(tox, (const uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); |
243 | tox_callback_friend_message(tox, &callback_friend_message); | 244 | tox_callback_friend_message(tox, &callback_friend_message); |
244 | tox_callback_group_invite(tox, &callback_group_invite, 0); | 245 | tox_callback_group_invite(tox, &callback_group_invite, 0); |
245 | tox_callback_group_message(tox, ©_groupmessage, 0); | 246 | tox_callback_group_message(tox, ©_groupmessage, 0); |
@@ -258,7 +259,7 @@ Tox *init_tox(int argc, char *argv[]) | |||
258 | free(binary_string); | 259 | free(binary_string); |
259 | 260 | ||
260 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 261 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
261 | uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1, 0); | 262 | uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1, 0); |
262 | free(bin_id); | 263 | free(bin_id); |
263 | 264 | ||
264 | if (num == UINT32_MAX) { | 265 | if (num == UINT32_MAX) { |
diff --git a/testing/misc_tools.c b/testing/misc_tools.c index b667f991..8fdc936c 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #endif // TOX_DEBUG | 35 | #endif // TOX_DEBUG |
36 | 36 | ||
37 | // You are responsible for freeing the return value! | 37 | // You are responsible for freeing the return value! |
38 | uint8_t *hex_string_to_bin(char *hex_string) | 38 | uint8_t *hex_string_to_bin(const char *hex_string) |
39 | { | 39 | { |
40 | // byte is represented by exactly 2 hex digits, so lenth of binary string | 40 | // byte is represented by exactly 2 hex digits, so lenth of binary string |
41 | // is half of that of the hex one. only hex string with even length | 41 | // is half of that of the hex one. only hex string with even length |
@@ -44,7 +44,7 @@ uint8_t *hex_string_to_bin(char *hex_string) | |||
44 | // then the last byte just won't be written in 'ret'. | 44 | // then the last byte just won't be written in 'ret'. |
45 | size_t i, len = strlen(hex_string) / 2; | 45 | size_t i, len = strlen(hex_string) / 2; |
46 | uint8_t *ret = malloc(len); | 46 | uint8_t *ret = malloc(len); |
47 | char *pos = hex_string; | 47 | const 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]); |
diff --git a/testing/nTox.c b/testing/nTox.c index fcfbe004..fe62e047 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -52,13 +52,16 @@ | |||
52 | #define c_sleep(x) usleep(1000*x) | 52 | #define c_sleep(x) usleep(1000*x) |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | char lines[HISTORY][STRING_LENGTH]; | 55 | static void new_lines(char const *line); |
56 | uint8_t flag[HISTORY]; | 56 | static void do_refresh(void); |
57 | char input_line[STRING_LENGTH]; | 57 | |
58 | static char lines[HISTORY][STRING_LENGTH]; | ||
59 | static uint8_t flag[HISTORY]; | ||
60 | static char input_line[STRING_LENGTH]; | ||
58 | 61 | ||
59 | /* wrap: continuation mark */ | 62 | /* wrap: continuation mark */ |
60 | enum { wrap_cont_len = 3 }; | 63 | enum { wrap_cont_len = 3 }; |
61 | const char wrap_cont_str[] = "\n+ "; | 64 | static const char wrap_cont_str[] = "\n+ "; |
62 | 65 | ||
63 | #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) | 66 | #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) |
64 | 67 | ||
@@ -66,7 +69,7 @@ const char wrap_cont_str[] = "\n+ "; | |||
66 | /* undocumented: d (tox_do()) */ | 69 | /* undocumented: d (tox_do()) */ |
67 | 70 | ||
68 | /* 251+1 characters */ | 71 | /* 251+1 characters */ |
69 | char *help_main = | 72 | static const char *help_main = |
70 | "[i] Available main commands:\n+ " | 73 | "[i] Available main commands:\n+ " |
71 | "/x (to print one's own id)|" | 74 | "/x (to print one's own id)|" |
72 | "/s status (to change status, e.g. AFK)|" | 75 | "/s status (to change status, e.g. AFK)|" |
@@ -77,7 +80,7 @@ char *help_main = | |||
77 | "/h group (for group related commands)"; | 80 | "/h group (for group related commands)"; |
78 | 81 | ||
79 | /* 190+1 characters */ | 82 | /* 190+1 characters */ |
80 | char *help_friend1 = | 83 | static const char *help_friend1 = |
81 | "[i] Available friend commands (1/2):\n+ " | 84 | "[i] Available friend commands (1/2):\n+ " |
82 | "/l list (to list friends)|" | 85 | "/l list (to list friends)|" |
83 | "/r friend no. (to remove from the friend list)|" | 86 | "/r friend no. (to remove from the friend list)|" |
@@ -85,14 +88,14 @@ char *help_friend1 = | |||
85 | "/a request no. (to accept a friend request)"; | 88 | "/a request no. (to accept a friend request)"; |
86 | 89 | ||
87 | /* 187+1 characters */ | 90 | /* 187+1 characters */ |
88 | char *help_friend2 = | 91 | static const char *help_friend2 = |
89 | "[i] Available friend commands (2/2):\n+ " | 92 | "[i] Available friend commands (2/2):\n+ " |
90 | "/m friend no. message (to send a message)|" | 93 | "/m friend no. message (to send a message)|" |
91 | "/t friend no. filename (to send a file to a friend)|" | 94 | "/t friend no. filename (to send a file to a friend)|" |
92 | "/cf friend no. (to talk to that friend per default)"; | 95 | "/cf friend no. (to talk to that friend per default)"; |
93 | 96 | ||
94 | /* 253+1 characters */ | 97 | /* 253+1 characters */ |
95 | char *help_group = | 98 | static const char *help_group = |
96 | "[i] Available group commands:\n+ " | 99 | "[i] Available group commands:\n+ " |
97 | "/g (to create a group)|" | 100 | "/g (to create a group)|" |
98 | "/i friend no. group no. (to invite a friend to a group)|" | 101 | "/i friend no. group no. (to invite a friend to a group)|" |
@@ -100,17 +103,17 @@ char *help_group = | |||
100 | "/p group no. (to list a group's peers)|" | 103 | "/p group no. (to list a group's peers)|" |
101 | "/cg group no. (to talk to that group per default)"; | 104 | "/cg group no. (to talk to that group per default)"; |
102 | 105 | ||
103 | int x, y; | 106 | static int x, y; |
104 | 107 | ||
105 | int conversation_default = 0; | 108 | static int conversation_default = 0; |
106 | 109 | ||
107 | typedef struct { | 110 | typedef struct { |
108 | uint8_t id[TOX_PUBLIC_KEY_SIZE]; | 111 | uint8_t id[TOX_PUBLIC_KEY_SIZE]; |
109 | uint8_t accepted; | 112 | uint8_t accepted; |
110 | } Friend_request; | 113 | } Friend_request; |
111 | 114 | ||
112 | Friend_request pending_requests[256]; | 115 | static Friend_request pending_requests[256]; |
113 | uint8_t num_requests = 0; | 116 | static uint8_t num_requests = 0; |
114 | 117 | ||
115 | #define NUM_FILE_SENDERS 64 | 118 | #define NUM_FILE_SENDERS 64 |
116 | typedef struct { | 119 | typedef struct { |
@@ -118,11 +121,12 @@ typedef struct { | |||
118 | uint32_t friendnum; | 121 | uint32_t friendnum; |
119 | uint32_t filenumber; | 122 | uint32_t filenumber; |
120 | } File_Sender; | 123 | } File_Sender; |
121 | File_Sender file_senders[NUM_FILE_SENDERS]; | 124 | static File_Sender file_senders[NUM_FILE_SENDERS]; |
122 | uint8_t numfilesenders; | 125 | static uint8_t numfilesenders; |
123 | 126 | ||
124 | void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, | 127 | static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, |
125 | void *user_data) | 128 | size_t length, |
129 | void *user_data) | ||
126 | { | 130 | { |
127 | unsigned int i; | 131 | unsigned int i; |
128 | 132 | ||
@@ -148,7 +152,7 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb | |||
148 | } | 152 | } |
149 | 153 | ||
150 | 154 | ||
151 | uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | 155 | static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) |
152 | { | 156 | { |
153 | FILE *tempfile = fopen(filename, "rb"); | 157 | FILE *tempfile = fopen(filename, "rb"); |
154 | 158 | ||
@@ -206,7 +210,7 @@ static void fraddr_to_str(uint8_t *id_bin, char *id_str) | |||
206 | } | 210 | } |
207 | } | 211 | } |
208 | 212 | ||
209 | void get_id(Tox *m, char *data) | 213 | static void get_id(Tox *m, char *data) |
210 | { | 214 | { |
211 | sprintf(data, "[i] ID: "); | 215 | sprintf(data, "[i] ID: "); |
212 | int offset = strlen(data); | 216 | int offset = strlen(data); |
@@ -215,7 +219,7 @@ void get_id(Tox *m, char *data) | |||
215 | fraddr_to_str(address, data + offset); | 219 | fraddr_to_str(address, data + offset); |
216 | } | 220 | } |
217 | 221 | ||
218 | int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) | 222 | static int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) |
219 | { | 223 | { |
220 | tox_friend_get_name(m, friendnum, (uint8_t *)namebuf, NULL); | 224 | tox_friend_get_name(m, friendnum, (uint8_t *)namebuf, NULL); |
221 | int res = tox_friend_get_name_size(m, friendnum, NULL); | 225 | int res = tox_friend_get_name_size(m, friendnum, NULL); |
@@ -229,7 +233,7 @@ int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) | |||
229 | return res; | 233 | return res; |
230 | } | 234 | } |
231 | 235 | ||
232 | void new_lines_mark(char *line, uint8_t special) | 236 | static void new_lines_mark(char const *line, uint8_t special) |
233 | { | 237 | { |
234 | int i = 0; | 238 | int i = 0; |
235 | 239 | ||
@@ -244,15 +248,15 @@ void new_lines_mark(char *line, uint8_t special) | |||
244 | do_refresh(); | 248 | do_refresh(); |
245 | } | 249 | } |
246 | 250 | ||
247 | void new_lines(char *line) | 251 | static void new_lines(char const *line) |
248 | { | 252 | { |
249 | new_lines_mark(line, 0); | 253 | new_lines_mark(line, 0); |
250 | } | 254 | } |
251 | 255 | ||
252 | 256 | ||
253 | const char ptrn_friend[] = "[i] Friend %i: %s\n+ id: %s"; | 257 | static const char ptrn_friend[] = "[i] Friend %i: %s\n+ id: %s"; |
254 | const int id_str_len = TOX_ADDRESS_SIZE * 2 + 3; | 258 | static const int id_str_len = TOX_ADDRESS_SIZE * 2 + 3; |
255 | void print_friendlist(Tox *m) | 259 | static void print_friendlist(Tox *m) |
256 | { | 260 | { |
257 | new_lines("[i] Friend List:"); | 261 | new_lines("[i] Friend List:"); |
258 | 262 | ||
@@ -328,9 +332,9 @@ static void print_formatted_message(Tox *m, char *message, int friendnum, uint8_ | |||
328 | 332 | ||
329 | /* forward declarations */ | 333 | /* forward declarations */ |
330 | static int save_data(Tox *m); | 334 | static int save_data(Tox *m); |
331 | void print_groupchatpeers(Tox *m, int groupnumber); | 335 | static void print_groupchatpeers(Tox *m, int groupnumber); |
332 | 336 | ||
333 | void line_eval(Tox *m, char *line) | 337 | static void line_eval(Tox *m, char *line) |
334 | { | 338 | { |
335 | if (line[0] == '/') { | 339 | if (line[0] == '/') { |
336 | char inpt_command = line[1]; | 340 | char inpt_command = line[1]; |
@@ -353,7 +357,7 @@ void line_eval(Tox *m, char *line) | |||
353 | 357 | ||
354 | unsigned char *bin_string = hex_string_to_bin(temp_id); | 358 | unsigned char *bin_string = hex_string_to_bin(temp_id); |
355 | TOX_ERR_FRIEND_ADD error; | 359 | TOX_ERR_FRIEND_ADD error; |
356 | uint32_t num = tox_friend_add(m, bin_string, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), &error); | 360 | uint32_t num = tox_friend_add(m, bin_string, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), &error); |
357 | free(bin_string); | 361 | free(bin_string); |
358 | char numstring[100]; | 362 | char numstring[100]; |
359 | 363 | ||
@@ -659,7 +663,7 @@ void line_eval(Tox *m, char *line) | |||
659 | /* basic wrap, ignores embedded '\t', '\n' or '|' | 663 | /* basic wrap, ignores embedded '\t', '\n' or '|' |
660 | * inserts continuation markers if there's enough space left, | 664 | * inserts continuation markers if there's enough space left, |
661 | * otherwise turns spaces into newlines if possible */ | 665 | * otherwise turns spaces into newlines if possible */ |
662 | void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width) | 666 | static void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width) |
663 | { | 667 | { |
664 | size_t i, len = strlen(input); | 668 | size_t i, len = strlen(input); |
665 | 669 | ||
@@ -741,7 +745,7 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin | |||
741 | * marks wrapped lines with "+ " in front, which does expand output | 745 | * marks wrapped lines with "+ " in front, which does expand output |
742 | * does NOT honor '\t': would require a lot more work (and tab width isn't always 8) | 746 | * does NOT honor '\t': would require a lot more work (and tab width isn't always 8) |
743 | */ | 747 | */ |
744 | void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], size_t line_width) | 748 | static void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], size_t line_width) |
745 | { | 749 | { |
746 | size_t len = strlen(input); | 750 | size_t len = strlen(input); |
747 | size_t ipos, opos = 0; | 751 | size_t ipos, opos = 0; |
@@ -840,7 +844,7 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si | |||
840 | output[opos] = 0; | 844 | output[opos] = 0; |
841 | } | 845 | } |
842 | 846 | ||
843 | int count_lines(char *string) | 847 | static int count_lines(char *string) |
844 | { | 848 | { |
845 | size_t i, len = strlen(string); | 849 | size_t i, len = strlen(string); |
846 | int count = 1; | 850 | int count = 1; |
@@ -854,7 +858,7 @@ int count_lines(char *string) | |||
854 | return count; | 858 | return count; |
855 | } | 859 | } |
856 | 860 | ||
857 | char *appender(char *str, const char c) | 861 | static char *appender(char *str, const char c) |
858 | { | 862 | { |
859 | size_t len = strlen(str); | 863 | size_t len = strlen(str); |
860 | 864 | ||
@@ -866,7 +870,7 @@ char *appender(char *str, const char c) | |||
866 | return str; | 870 | return str; |
867 | } | 871 | } |
868 | 872 | ||
869 | void do_refresh() | 873 | static void do_refresh(void) |
870 | { | 874 | { |
871 | int count = 0; | 875 | int count = 0; |
872 | char wrap_output[STRING_LENGTH_WRAPPED]; | 876 | char wrap_output[STRING_LENGTH_WRAPPED]; |
@@ -897,10 +901,10 @@ void do_refresh() | |||
897 | refresh(); | 901 | refresh(); |
898 | } | 902 | } |
899 | 903 | ||
900 | void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) | 904 | static void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) |
901 | { | 905 | { |
902 | new_lines("[i] received friend request with message:"); | 906 | new_lines("[i] received friend request with message:"); |
903 | new_lines((char *)data); | 907 | new_lines((const char *)data); |
904 | char numchar[100]; | 908 | char numchar[100]; |
905 | sprintf(numchar, "[i] accept request with /a %u", num_requests); | 909 | sprintf(numchar, "[i] accept request with /a %u", num_requests); |
906 | new_lines(numchar); | 910 | new_lines(numchar); |
@@ -910,8 +914,8 @@ void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_ | |||
910 | do_refresh(); | 914 | do_refresh(); |
911 | } | 915 | } |
912 | 916 | ||
913 | void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, | 917 | static void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, |
914 | void *userdata) | 918 | void *userdata) |
915 | { | 919 | { |
916 | /* ensure null termination */ | 920 | /* ensure null termination */ |
917 | uint8_t null_string[length + 1]; | 921 | uint8_t null_string[length + 1]; |
@@ -920,7 +924,7 @@ void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const u | |||
920 | print_formatted_message(m, (char *)null_string, friendnumber, 0); | 924 | print_formatted_message(m, (char *)null_string, friendnumber, 0); |
921 | } | 925 | } |
922 | 926 | ||
923 | void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) | 927 | static void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) |
924 | { | 928 | { |
925 | char name[TOX_MAX_NAME_LENGTH + 1]; | 929 | char name[TOX_MAX_NAME_LENGTH + 1]; |
926 | 930 | ||
@@ -937,7 +941,7 @@ void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size | |||
937 | } | 941 | } |
938 | } | 942 | } |
939 | 943 | ||
940 | void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) | 944 | static void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) |
941 | { | 945 | { |
942 | char name[TOX_MAX_NAME_LENGTH + 1]; | 946 | char name[TOX_MAX_NAME_LENGTH + 1]; |
943 | 947 | ||
@@ -954,9 +958,9 @@ void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, si | |||
954 | } | 958 | } |
955 | } | 959 | } |
956 | 960 | ||
957 | static char *data_file_name = NULL; | 961 | static const char *data_file_name = NULL; |
958 | 962 | ||
959 | static Tox *load_data() | 963 | static Tox *load_data(void) |
960 | { | 964 | { |
961 | FILE *data_file = fopen(data_file_name, "r"); | 965 | FILE *data_file = fopen(data_file_name, "r"); |
962 | 966 | ||
@@ -1024,7 +1028,7 @@ static int save_data(Tox *m) | |||
1024 | return res; | 1028 | return res; |
1025 | } | 1029 | } |
1026 | 1030 | ||
1027 | static int save_data_file(Tox *m, char *path) | 1031 | static int save_data_file(Tox *m, const char *path) |
1028 | { | 1032 | { |
1029 | data_file_name = path; | 1033 | data_file_name = path; |
1030 | 1034 | ||
@@ -1035,7 +1039,7 @@ static int save_data_file(Tox *m, char *path) | |||
1035 | return 0; | 1039 | return 0; |
1036 | } | 1040 | } |
1037 | 1041 | ||
1038 | void print_help(char *prog_name) | 1042 | static void print_help(char *prog_name) |
1039 | { | 1043 | { |
1040 | printf("nTox %.1f - Command-line tox-core client\n", 0.1); | 1044 | printf("nTox %.1f - Command-line tox-core client\n", 0.1); |
1041 | printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", prog_name); | 1045 | printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", prog_name); |
@@ -1046,7 +1050,7 @@ void print_help(char *prog_name) | |||
1046 | puts(" -f keyfile [Optional] Specify a keyfile to read from and write to."); | 1050 | puts(" -f keyfile [Optional] Specify a keyfile to read from and write to."); |
1047 | } | 1051 | } |
1048 | 1052 | ||
1049 | void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) | 1053 | static void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) |
1050 | { | 1054 | { |
1051 | char msg[256]; | 1055 | char msg[256]; |
1052 | 1056 | ||
@@ -1060,7 +1064,7 @@ void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, u | |||
1060 | new_lines(msg); | 1064 | new_lines(msg); |
1061 | } | 1065 | } |
1062 | 1066 | ||
1063 | void print_groupchatpeers(Tox *m, int groupnumber) | 1067 | static void print_groupchatpeers(Tox *m, int groupnumber) |
1064 | { | 1068 | { |
1065 | int num = tox_group_number_peers(m, groupnumber); | 1069 | int num = tox_group_number_peers(m, groupnumber); |
1066 | 1070 | ||
@@ -1109,8 +1113,8 @@ void print_groupchatpeers(Tox *m, int groupnumber) | |||
1109 | new_lines_mark(msg, 1); | 1113 | new_lines_mark(msg, 1); |
1110 | } | 1114 | } |
1111 | 1115 | ||
1112 | void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, | 1116 | static void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, |
1113 | void *userdata) | 1117 | void *userdata) |
1114 | { | 1118 | { |
1115 | char msg[256 + length]; | 1119 | char msg[256 + length]; |
1116 | uint8_t name[TOX_MAX_NAME_LENGTH] = {0}; | 1120 | uint8_t name[TOX_MAX_NAME_LENGTH] = {0}; |
@@ -1129,7 +1133,7 @@ void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t * | |||
1129 | 1133 | ||
1130 | new_lines(msg); | 1134 | new_lines(msg); |
1131 | } | 1135 | } |
1132 | void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) | 1136 | static void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) |
1133 | { | 1137 | { |
1134 | char msg[256]; | 1138 | char msg[256]; |
1135 | 1139 | ||
@@ -1175,8 +1179,9 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t | |||
1175 | print_groupchatpeers(m, groupnumber); | 1179 | print_groupchatpeers(m, groupnumber); |
1176 | } | 1180 | } |
1177 | } | 1181 | } |
1178 | void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, uint64_t file_size, | 1182 | static void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, |
1179 | const uint8_t *filename, size_t filename_length, void *user_data) | 1183 | uint64_t file_size, |
1184 | const uint8_t *filename, size_t filename_length, void *user_data) | ||
1180 | { | 1185 | { |
1181 | if (type != TOX_FILE_KIND_DATA) { | 1186 | if (type != TOX_FILE_KIND_DATA) { |
1182 | new_lines("Refused invalid file type."); | 1187 | new_lines("Refused invalid file type."); |
@@ -1196,8 +1201,8 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
1196 | } | 1201 | } |
1197 | } | 1202 | } |
1198 | 1203 | ||
1199 | void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, | 1204 | static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, |
1200 | void *user_data) | 1205 | void *user_data) |
1201 | { | 1206 | { |
1202 | char msg[512] = {0}; | 1207 | char msg[512] = {0}; |
1203 | sprintf(msg, "[t] control %u received", control); | 1208 | sprintf(msg, "[t] control %u received", control); |
@@ -1219,8 +1224,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
1219 | } | 1224 | } |
1220 | } | 1225 | } |
1221 | 1226 | ||
1222 | void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, | 1227 | static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, |
1223 | size_t length, void *user_data) | 1228 | size_t length, void *user_data) |
1224 | { | 1229 | { |
1225 | if (length == 0) { | 1230 | if (length == 0) { |
1226 | char msg[512]; | 1231 | char msg[512]; |
@@ -1246,7 +1251,7 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p | |||
1246 | fclose(pFile); | 1251 | fclose(pFile); |
1247 | } | 1252 | } |
1248 | 1253 | ||
1249 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 1254 | static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) |
1250 | { | 1255 | { |
1251 | if (status) { | 1256 | if (status) { |
1252 | printf("\nOther went online.\n"); | 1257 | printf("\nOther went online.\n"); |
@@ -1263,7 +1268,7 @@ void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void * | |||
1263 | } | 1268 | } |
1264 | } | 1269 | } |
1265 | 1270 | ||
1266 | char timeout_getch(Tox *m) | 1271 | static char timeout_getch(Tox *m) |
1267 | { | 1272 | { |
1268 | char c; | 1273 | char c; |
1269 | int slpval = tox_iteration_interval(m); | 1274 | int slpval = tox_iteration_interval(m); |
@@ -1312,7 +1317,7 @@ int main(int argc, char *argv[]) | |||
1312 | } | 1317 | } |
1313 | 1318 | ||
1314 | int on = 0; | 1319 | int on = 0; |
1315 | char *filename = "data"; | 1320 | const char *filename = "data"; |
1316 | char idstring[200] = {0}; | 1321 | char idstring[200] = {0}; |
1317 | Tox *m; | 1322 | Tox *m; |
1318 | 1323 | ||
diff --git a/testing/nTox.h b/testing/nTox.h index 44def142..61f86a9b 100644 --- a/testing/nTox.h +++ b/testing/nTox.h | |||
@@ -36,7 +36,4 @@ | |||
36 | #define STRING_LENGTH 256 | 36 | #define STRING_LENGTH 256 |
37 | #define HISTORY 50 | 37 | #define HISTORY 50 |
38 | 38 | ||
39 | void new_lines(char *line); | ||
40 | void do_refresh(); | ||
41 | |||
42 | #endif | 39 | #endif |
diff --git a/testing/tox_shell.c b/testing/tox_shell.c index 77047a44..40890453 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c | |||
@@ -45,7 +45,7 @@ | |||
45 | 45 | ||
46 | #define c_sleep(x) usleep(1000*x) | 46 | #define c_sleep(x) usleep(1000*x) |
47 | 47 | ||
48 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 48 | static 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"); |
@@ -54,8 +54,8 @@ void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void * | |||
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, | 57 | static void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, |
58 | void *userdata) | 58 | void *userdata) |
59 | { | 59 | { |
60 | int master = *((int *)userdata); | 60 | int master = *((int *)userdata); |
61 | write(master, string, length); | 61 | write(master, string, length); |
@@ -129,7 +129,7 @@ int main(int argc, char *argv[]) | |||
129 | } | 129 | } |
130 | 130 | ||
131 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 131 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
132 | uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); | 132 | uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); |
133 | free(bin_id); | 133 | free(bin_id); |
134 | 134 | ||
135 | if (num == UINT32_MAX) { | 135 | if (num == UINT32_MAX) { |
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index f30ce059..36b01cf4 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -49,12 +49,13 @@ typedef struct { | |||
49 | uint32_t friendnum; | 49 | uint32_t friendnum; |
50 | uint32_t filenumber; | 50 | uint32_t filenumber; |
51 | } File_t; | 51 | } File_t; |
52 | File_t file_senders[NUM_FILE_SENDERS]; | 52 | static File_t file_senders[NUM_FILE_SENDERS]; |
53 | File_t file_recv[NUM_FILE_SENDERS]; | 53 | static File_t file_recv[NUM_FILE_SENDERS]; |
54 | uint8_t numfilesenders; | 54 | static uint8_t numfilesenders; |
55 | 55 | ||
56 | void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, | 56 | static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, |
57 | void *user_data) | 57 | size_t length, |
58 | void *user_data) | ||
58 | { | 59 | { |
59 | unsigned int i; | 60 | unsigned int i; |
60 | 61 | ||
@@ -78,7 +79,7 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb | |||
78 | } | 79 | } |
79 | 80 | ||
80 | 81 | ||
81 | uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | 82 | static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) |
82 | { | 83 | { |
83 | FILE *tempfile = fopen(filename, "rb"); | 84 | FILE *tempfile = fopen(filename, "rb"); |
84 | 85 | ||
@@ -103,7 +104,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
103 | return filenum; | 104 | return filenum; |
104 | } | 105 | } |
105 | 106 | ||
106 | void kill_filesender(Tox *m, uint32_t filenum) | 107 | static void kill_filesender(Tox *m, uint32_t filenum) |
107 | { | 108 | { |
108 | uint32_t i; | 109 | uint32_t i; |
109 | 110 | ||
@@ -114,7 +115,7 @@ void kill_filesender(Tox *m, uint32_t filenum) | |||
114 | } | 115 | } |
115 | } | 116 | } |
116 | } | 117 | } |
117 | int not_sending() | 118 | static int not_sending(void) |
118 | { | 119 | { |
119 | uint32_t i; | 120 | uint32_t i; |
120 | 121 | ||
@@ -129,8 +130,9 @@ int not_sending() | |||
129 | 130 | ||
130 | static char path[1024]; | 131 | static char path[1024]; |
131 | 132 | ||
132 | void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, uint64_t file_size, | 133 | static void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, |
133 | const uint8_t *filename, size_t filename_length, void *user_data) | 134 | uint64_t file_size, |
135 | const uint8_t *filename, size_t filename_length, void *user_data) | ||
134 | { | 136 | { |
135 | if (type != TOX_FILE_KIND_DATA) { | 137 | if (type != TOX_FILE_KIND_DATA) { |
136 | printf("Refused invalid file type."); | 138 | printf("Refused invalid file type."); |
@@ -142,7 +144,7 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
142 | uint32_t i; | 144 | uint32_t i; |
143 | uint16_t rm = 0; | 145 | uint16_t rm = 0; |
144 | 146 | ||
145 | for (i = 0; i < strlen((char *)filename); ++i) { | 147 | for (i = 0; i < strlen((const char *)filename); ++i) { |
146 | if (filename[i] == '/') { | 148 | if (filename[i] == '/') { |
147 | rm = i; | 149 | rm = i; |
148 | } | 150 | } |
@@ -175,8 +177,8 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
175 | } | 177 | } |
176 | } | 178 | } |
177 | 179 | ||
178 | void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, | 180 | static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, |
179 | void *user_data) | 181 | void *user_data) |
180 | { | 182 | { |
181 | if (file_number < (1 << 15) && (control == TOX_FILE_CONTROL_CANCEL)) { | 183 | if (file_number < (1 << 15) && (control == TOX_FILE_CONTROL_CANCEL)) { |
182 | kill_filesender(tox, file_number); | 184 | kill_filesender(tox, file_number); |
@@ -192,8 +194,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, | |||
192 | } | 194 | } |
193 | } | 195 | } |
194 | 196 | ||
195 | void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, | 197 | static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, |
196 | size_t length, void *user_data) | 198 | size_t length, void *user_data) |
197 | { | 199 | { |
198 | uint8_t file_index = (filenumber >> 16) - 1; | 200 | uint8_t file_index = (filenumber >> 16) - 1; |
199 | 201 | ||
@@ -214,7 +216,7 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p | |||
214 | } | 216 | } |
215 | } | 217 | } |
216 | 218 | ||
217 | void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) | 219 | static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) |
218 | { | 220 | { |
219 | if (status) { | 221 | if (status) { |
220 | printf("\nOther went online.\n"); | 222 | printf("\nOther went online.\n"); |
@@ -284,7 +286,7 @@ int main(int argc, char *argv[]) | |||
284 | } | 286 | } |
285 | 287 | ||
286 | uint8_t *bin_id = hex_string_to_bin(temp_id); | 288 | uint8_t *bin_id = hex_string_to_bin(temp_id); |
287 | uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); | 289 | uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); |
288 | free(bin_id); | 290 | free(bin_id); |
289 | 291 | ||
290 | if (num == UINT32_MAX) { | 292 | if (num == UINT32_MAX) { |
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index a38d71c0..5619c715 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c | |||
@@ -177,7 +177,7 @@ void send_update(BWController *bwc) | |||
177 | bwc->cycle.lsu = current_time_monotonic(); | 177 | bwc->cycle.lsu = current_time_monotonic(); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | int on_update (BWController *bwc, struct BWCMessage *msg) | 180 | static int on_update (BWController *bwc, struct BWCMessage *msg) |
181 | { | 181 | { |
182 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc); | 182 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc); |
183 | 183 | ||
diff --git a/toxav/msi.c b/toxav/msi.c index a62bdb35..76c727a9 100644 --- a/toxav/msi.c +++ b/toxav/msi.c | |||
@@ -682,7 +682,8 @@ void handle_init (MSICall *call, const MSIMessage *msg) | |||
682 | } | 682 | } |
683 | break; | 683 | break; |
684 | 684 | ||
685 | default: { | 685 | case msi_CallRequested: |
686 | case msi_CallRequesting: { | ||
686 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'"); | 687 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'"); |
687 | call->error = msi_EInvalidState; | 688 | call->error = msi_EInvalidState; |
688 | goto FAILURE; | 689 | goto FAILURE; |
diff --git a/toxav/rtp.c b/toxav/rtp.c index 38e64dd7..6e0c22b2 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -191,7 +191,7 @@ int rtp_send_data (RTPSession *session, const uint8_t *data, uint16_t length) | |||
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | bool chloss (const RTPSession *session, const struct RTPHeader *header) | 194 | static bool chloss (const RTPSession *session, const struct RTPHeader *header) |
195 | { | 195 | { |
196 | if (ntohl(header->timestamp) < session->rtimestamp) { | 196 | if (ntohl(header->timestamp) < session->rtimestamp) { |
197 | uint16_t hosq, lost = 0; | 197 | uint16_t hosq, lost = 0; |
@@ -213,7 +213,7 @@ bool chloss (const RTPSession *session, const struct RTPHeader *header) | |||
213 | 213 | ||
214 | return false; | 214 | return false; |
215 | } | 215 | } |
216 | struct RTPMessage *new_message (size_t allocate_len, const uint8_t *data, uint16_t data_length) | 216 | static struct RTPMessage *new_message (size_t allocate_len, const uint8_t *data, uint16_t data_length) |
217 | { | 217 | { |
218 | assert(allocate_len >= data_length); | 218 | assert(allocate_len >= data_length); |
219 | 219 | ||
@@ -246,7 +246,7 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, | |||
246 | return -1; | 246 | return -1; |
247 | } | 247 | } |
248 | 248 | ||
249 | const struct RTPHeader *header = (struct RTPHeader *) data; | 249 | const struct RTPHeader *header = (const struct RTPHeader *) data; |
250 | 250 | ||
251 | if (header->pt != session->payload_type % 128) { | 251 | if (header->pt != session->payload_type % 128) { |
252 | LOGGER_WARNING(m->log, "Invalid payload type with the session"); | 252 | LOGGER_WARNING(m->log, "Invalid payload type with the session"); |
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ac94a36e..2e475d01 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -2136,6 +2136,7 @@ static void do_NAT(DHT *dht) | |||
2136 | #define CHECK_TYPE_TEST_REQ 4 | 2136 | #define CHECK_TYPE_TEST_REQ 4 |
2137 | #define CHECK_TYPE_TEST_RES 5 | 2137 | #define CHECK_TYPE_TEST_RES 5 |
2138 | 2138 | ||
2139 | #if DHT_HARDENING | ||
2139 | static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8_t *contents, uint16_t length) | 2140 | static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8_t *contents, uint16_t length) |
2140 | { | 2141 | { |
2141 | if (length > HARDREQ_DATA_SIZE - 1) { | 2142 | if (length > HARDREQ_DATA_SIZE - 1) { |
@@ -2164,6 +2165,7 @@ static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format * | |||
2164 | memcpy(data + sizeof(Node_format), search_id, crypto_box_PUBLICKEYBYTES); | 2165 | memcpy(data + sizeof(Node_format), search_id, crypto_box_PUBLICKEYBYTES); |
2165 | return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + crypto_box_PUBLICKEYBYTES); | 2166 | return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + crypto_box_PUBLICKEYBYTES); |
2166 | } | 2167 | } |
2168 | #endif | ||
2167 | 2169 | ||
2168 | /* Send a get node hardening response */ | 2170 | /* Send a get node hardening response */ |
2169 | static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id, | 2171 | static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id, |
@@ -2316,10 +2318,11 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ | |||
2316 | return 1; | 2318 | return 1; |
2317 | } | 2319 | } |
2318 | 2320 | ||
2321 | #if DHT_HARDENING | ||
2319 | /* Return a random node from all the nodes we are connected to. | 2322 | /* Return a random node from all the nodes we are connected to. |
2320 | * TODO: improve this function. | 2323 | * TODO: improve this function. |
2321 | */ | 2324 | */ |
2322 | Node_format random_node(DHT *dht, sa_family_t sa_family) | 2325 | static Node_format random_node(DHT *dht, sa_family_t sa_family) |
2323 | { | 2326 | { |
2324 | uint8_t id[crypto_box_PUBLICKEYBYTES]; | 2327 | uint8_t id[crypto_box_PUBLICKEYBYTES]; |
2325 | uint32_t i; | 2328 | uint32_t i; |
@@ -2339,12 +2342,13 @@ Node_format random_node(DHT *dht, sa_family_t sa_family) | |||
2339 | 2342 | ||
2340 | return nodes_list[rand() % num_nodes]; | 2343 | return nodes_list[rand() % num_nodes]; |
2341 | } | 2344 | } |
2345 | #endif | ||
2342 | 2346 | ||
2343 | /* Put up to max_num nodes in nodes from the closelist. | 2347 | /* Put up to max_num nodes in nodes from the closelist. |
2344 | * | 2348 | * |
2345 | * return the number of nodes. | 2349 | * return the number of nodes. |
2346 | */ | 2350 | */ |
2347 | uint16_t list_nodes(Client_data *list, unsigned int length, Node_format *nodes, uint16_t max_num) | 2351 | static uint16_t list_nodes(Client_data *list, unsigned int length, Node_format *nodes, uint16_t max_num) |
2348 | { | 2352 | { |
2349 | if (max_num == 0) { | 2353 | if (max_num == 0) { |
2350 | return 0; | 2354 | return 0; |
@@ -2417,7 +2421,8 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num) | |||
2417 | return list_nodes(dht->close_clientlist, LCLIENT_LIST, nodes, max_num); | 2421 | return list_nodes(dht->close_clientlist, LCLIENT_LIST, nodes, max_num); |
2418 | } | 2422 | } |
2419 | 2423 | ||
2420 | void do_hardening(DHT *dht) | 2424 | #if DHT_HARDENING |
2425 | static void do_hardening(DHT *dht) | ||
2421 | { | 2426 | { |
2422 | uint32_t i; | 2427 | uint32_t i; |
2423 | 2428 | ||
@@ -2469,6 +2474,7 @@ void do_hardening(DHT *dht) | |||
2469 | //TODO: add the 2 other testers. | 2474 | //TODO: add the 2 other testers. |
2470 | } | 2475 | } |
2471 | } | 2476 | } |
2477 | #endif | ||
2472 | 2478 | ||
2473 | /*----------------------------------------------------------------------------------*/ | 2479 | /*----------------------------------------------------------------------------------*/ |
2474 | 2480 | ||
@@ -2589,7 +2595,9 @@ void do_DHT(DHT *dht) | |||
2589 | do_DHT_friends(dht); | 2595 | do_DHT_friends(dht); |
2590 | do_NAT(dht); | 2596 | do_NAT(dht); |
2591 | do_to_ping(dht->ping); | 2597 | do_to_ping(dht->ping); |
2592 | //do_hardening(dht); | 2598 | #if DHT_HARDENING |
2599 | do_hardening(dht); | ||
2600 | #endif | ||
2593 | #ifdef ENABLE_ASSOC_DHT | 2601 | #ifdef ENABLE_ASSOC_DHT |
2594 | 2602 | ||
2595 | if (dht->assoc) | 2603 | if (dht->assoc) |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 472ddd9e..7ec2ad01 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -56,7 +56,7 @@ static uint8_t friend_not_valid(const Messenger *m, int32_t friendnumber) | |||
56 | * | 56 | * |
57 | * return -1 if realloc fails. | 57 | * return -1 if realloc fails. |
58 | */ | 58 | */ |
59 | int realloc_friendlist(Messenger *m, uint32_t num) | 59 | static int realloc_friendlist(Messenger *m, uint32_t num) |
60 | { | 60 | { |
61 | if (num == 0) { | 61 | if (num == 0) { |
62 | free(m->friendlist); | 62 | free(m->friendlist); |
@@ -1191,8 +1191,8 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_ | |||
1191 | return i; | 1191 | return i; |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, | 1194 | static int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, |
1195 | uint8_t control_type, uint8_t *data, uint16_t data_length) | 1195 | uint8_t control_type, uint8_t *data, uint16_t data_length) |
1196 | { | 1196 | { |
1197 | if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) { | 1197 | if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) { |
1198 | return -1; | 1198 | return -1; |
@@ -2845,7 +2845,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 | |||
2845 | switch (type) { | 2845 | switch (type) { |
2846 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: | 2846 | case MESSENGER_STATE_TYPE_NOSPAMKEYS: |
2847 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { | 2847 | if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { |
2848 | set_nospam(&(m->fr), *(uint32_t *)data); | 2848 | set_nospam(&(m->fr), *(const uint32_t *)data); |
2849 | load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES); | 2849 | load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES); |
2850 | 2850 | ||
2851 | if (public_key_cmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key) != 0) { | 2851 | if (public_key_cmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key) != 0) { |
diff --git a/toxcore/group.c b/toxcore/group.c index f1086657..dbfb31cd 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -1188,7 +1188,7 @@ static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, | |||
1188 | uint16_t len); | 1188 | uint16_t len); |
1189 | 1189 | ||
1190 | #define GROUP_MESSAGE_PING_ID 0 | 1190 | #define GROUP_MESSAGE_PING_ID 0 |
1191 | int group_ping_send(const Group_Chats *g_c, int groupnumber) | 1191 | static int group_ping_send(const Group_Chats *g_c, int groupnumber) |
1192 | { | 1192 | { |
1193 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0)) { | 1193 | if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0)) { |
1194 | return 0; | 1194 | return 0; |
@@ -1203,8 +1203,8 @@ int group_ping_send(const Group_Chats *g_c, int groupnumber) | |||
1203 | * return 0 on success | 1203 | * return 0 on success |
1204 | * return -1 on failure | 1204 | * return -1 on failure |
1205 | */ | 1205 | */ |
1206 | int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, | 1206 | static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, |
1207 | uint8_t *temp_pk) | 1207 | uint8_t *temp_pk) |
1208 | { | 1208 | { |
1209 | uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; | 1209 | uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; |
1210 | 1210 | ||
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 0d8fabac..e09d7444 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -458,7 +458,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por | |||
458 | * return IP_Port with family 0 on failure. | 458 | * return IP_Port with family 0 on failure. |
459 | * return IP_Port on success. | 459 | * return IP_Port on success. |
460 | */ | 460 | */ |
461 | IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) | 461 | static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) |
462 | { | 462 | { |
463 | IP_Port empty; | 463 | IP_Port empty; |
464 | empty.ip.family = 0; | 464 | empty.ip.family = 0; |
diff --git a/toxcore/network.c b/toxcore/network.c index 05867adc..2097078a 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -268,11 +268,11 @@ uint64_t current_time_monotonic(void) | |||
268 | 268 | ||
269 | static uint32_t data_0(uint16_t buflen, const uint8_t *buffer) | 269 | static uint32_t data_0(uint16_t buflen, const uint8_t *buffer) |
270 | { | 270 | { |
271 | return buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0; | 271 | return buflen > 4 ? ntohl(*(const uint32_t *)&buffer[1]) : 0; |
272 | } | 272 | } |
273 | static uint32_t data_1(uint16_t buflen, const uint8_t *buffer) | 273 | static uint32_t data_1(uint16_t buflen, const uint8_t *buffer) |
274 | { | 274 | { |
275 | return buflen > 7 ? ntohl(*(uint32_t *)&buffer[5]) : 0; | 275 | return buflen > 7 ? ntohl(*(const uint32_t *)&buffer[5]) : 0; |
276 | } | 276 | } |
277 | 277 | ||
278 | static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, | 278 | static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, |
@@ -359,7 +359,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 | |||
359 | return -1; | 359 | return -1; |
360 | } | 360 | } |
361 | 361 | ||
362 | int res = sendto(net->sock, (char *) data, length, 0, (struct sockaddr *)&addr, addrsize); | 362 | int res = sendto(net->sock, (const char *) data, length, 0, (struct sockaddr *)&addr, addrsize); |
363 | 363 | ||
364 | loglogdata(net->log, "O=>", data, length, ip_port, res); | 364 | loglogdata(net->log, "O=>", data, length, ip_port, res); |
365 | 365 | ||
@@ -874,13 +874,13 @@ const char *ip_ntoa(const IP *ip) | |||
874 | if (ip) { | 874 | if (ip) { |
875 | if (ip->family == AF_INET) { | 875 | if (ip->family == AF_INET) { |
876 | /* returns standard quad-dotted notation */ | 876 | /* returns standard quad-dotted notation */ |
877 | struct in_addr *addr = (struct in_addr *)&ip->ip4; | 877 | const struct in_addr *addr = (const struct in_addr *)&ip->ip4; |
878 | 878 | ||
879 | addresstext[0] = 0; | 879 | addresstext[0] = 0; |
880 | inet_ntop(ip->family, addr, addresstext, sizeof(addresstext)); | 880 | inet_ntop(ip->family, addr, addresstext, sizeof(addresstext)); |
881 | } else if (ip->family == AF_INET6) { | 881 | } else if (ip->family == AF_INET6) { |
882 | /* returns hex-groups enclosed into square brackets */ | 882 | /* returns hex-groups enclosed into square brackets */ |
883 | struct in6_addr *addr = (struct in6_addr *)&ip->ip6; | 883 | const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; |
884 | 884 | ||
885 | addresstext[0] = '['; | 885 | addresstext[0] = '['; |
886 | inet_ntop(ip->family, addr, &addresstext[1], sizeof(addresstext) - 3); | 886 | inet_ntop(ip->family, addr, &addresstext[1], sizeof(addresstext) - 3); |
@@ -921,12 +921,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length) | |||
921 | } | 921 | } |
922 | 922 | ||
923 | if (ip->family == AF_INET) { | 923 | if (ip->family == AF_INET) { |
924 | struct in_addr *addr = (struct in_addr *)&ip->ip4; | 924 | const struct in_addr *addr = (const struct in_addr *)&ip->ip4; |
925 | return inet_ntop(ip->family, addr, address, length) != NULL; | 925 | return inet_ntop(ip->family, addr, address, length) != NULL; |
926 | } | 926 | } |
927 | 927 | ||
928 | if (ip->family == AF_INET6) { | 928 | if (ip->family == AF_INET6) { |
929 | struct in6_addr *addr = (struct in6_addr *)&ip->ip6; | 929 | const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; |
930 | return inet_ntop(ip->family, addr, address, length) != NULL; | 930 | return inet_ntop(ip->family, addr, address, length) != NULL; |
931 | } | 931 | } |
932 | 932 | ||
diff --git a/toxcore/util.c b/toxcore/util.c index 9f1a7e28..92ad4510 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -38,7 +38,7 @@ | |||
38 | static uint64_t unix_time_value; | 38 | static uint64_t unix_time_value; |
39 | static uint64_t unix_base_time_value; | 39 | static uint64_t unix_base_time_value; |
40 | 40 | ||
41 | void unix_time_update() | 41 | void unix_time_update(void) |
42 | { | 42 | { |
43 | if (unix_base_time_value == 0) { | 43 | if (unix_base_time_value == 0) { |
44 | unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); | 44 | unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); |
@@ -47,7 +47,7 @@ void unix_time_update() | |||
47 | unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; | 47 | unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; |
48 | } | 48 | } |
49 | 49 | ||
50 | uint64_t unix_time() | 50 | uint64_t unix_time(void) |
51 | { | 51 | { |
52 | return unix_time_value; | 52 | return unix_time_value; |
53 | } | 53 | } |
diff --git a/toxcore/util.h b/toxcore/util.h index 17b1a27b..840f0a3e 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -32,8 +32,8 @@ | |||
32 | #define MIN(a,b) (((a)<(b))?(a):(b)) | 32 | #define MIN(a,b) (((a)<(b))?(a):(b)) |
33 | #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } | 33 | #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } |
34 | 34 | ||
35 | void unix_time_update(); | 35 | void unix_time_update(void); |
36 | uint64_t unix_time(); | 36 | uint64_t unix_time(void); |
37 | int is_timeout(uint64_t timestamp, uint64_t timeout); | 37 | int is_timeout(uint64_t timestamp, uint64_t timeout); |
38 | 38 | ||
39 | 39 | ||