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 /auto_tests | |
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.
Diffstat (limited to 'auto_tests')
-rw-r--r-- | auto_tests/TCP_test.c | 10 | ||||
-rw-r--r-- | auto_tests/assoc_test.c | 2 | ||||
-rw-r--r-- | auto_tests/crypto_test.c | 16 | ||||
-rw-r--r-- | auto_tests/dht_test.c | 66 | ||||
-rw-r--r-- | auto_tests/encryptsave_test.c | 17 | ||||
-rw-r--r-- | auto_tests/messenger_test.c | 48 | ||||
-rw-r--r-- | auto_tests/network_test.c | 4 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 41 | ||||
-rw-r--r-- | auto_tests/skeleton_test.c | 3 | ||||
-rw-r--r-- | auto_tests/tox_test.c | 114 | ||||
-rw-r--r-- | auto_tests/toxav_basic_test.c | 37 | ||||
-rw-r--r-- | auto_tests/toxav_many_test.c | 43 |
12 files changed, 204 insertions, 197 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 | ||