summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-x.travis/cmake-linux10
-rw-r--r--CMakeLists.txt10
-rw-r--r--auto_tests/BUILD.bazel24
-rw-r--r--auto_tests/conference_peer_nick_test.c2
-rw-r--r--auto_tests/conference_test.c2
-rw-r--r--auto_tests/file_transfer_test.c14
-rw-r--r--auto_tests/monolith_test.cc254
-rw-r--r--auto_tests/tox_many_test.c32
-rw-r--r--auto_tests/tox_one_test.c23
-rw-r--r--configure.ac12
-rw-r--r--other/BUILD.bazel12
-rw-r--r--other/analysis/gen-file.sh116
-rwxr-xr-xother/analysis/run-clang22
-rwxr-xr-xother/analysis/run-clang-analyze8
-rwxr-xr-xother/analysis/run-cppcheck4
-rwxr-xr-xother/analysis/run-gcc23
-rwxr-xr-xother/analysis/run-infer4
-rwxr-xr-xother/analysis/run-sparse9
-rw-r--r--other/bootstrap_daemon/src/config.c4
-rw-r--r--other/bootstrap_daemon/src/tox-bootstrapd.c2
-rw-r--r--other/cpufeatures.c2
-rw-r--r--other/fun/cracker.c2
-rw-r--r--other/fun/sign.c15
-rw-r--r--other/fun/strkey.c2
-rw-r--r--other/monolith.h38
-rw-r--r--testing/BUILD.bazel12
-rw-r--r--testing/DHT_test.c2
-rw-r--r--testing/random_testing.cc5
-rw-r--r--toxav/BUILD.bazel27
-rw-r--r--toxav/groupav.h5
-rw-r--r--toxcore/BUILD.bazel35
-rw-r--r--toxcore/logger.c10
-rw-r--r--toxcore/logger.h22
-rw-r--r--toxcore/tox.c4
35 files changed, 234 insertions, 535 deletions
diff --git a/.gitignore b/.gitignore
index b62599ff..cef011b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@ CTestTestfile.cmake
27*.pc 27*.pc
28 28
29# Testing 29# Testing
30/amalgamation.*
30testing/data 31testing/data
31*~ 32*~
32 33
diff --git a/.travis/cmake-linux b/.travis/cmake-linux
index 48b72925..bbfb7a96 100755
--- a/.travis/cmake-linux
+++ b/.travis/cmake-linux
@@ -37,6 +37,13 @@ travis_install() {
37 } 37 }
38} 38}
39 39
40run_static_analysis() {
41 export CPPFLAGS="-isystem $CACHEDIR/include"
42 export LDFLAGS="-L $CACHEDIR/lib"
43 other/analysis/run-clang
44 other/analysis/run-clang-analyze
45}
46
40travis_script() { 47travis_script() {
41 . ".travis/flags-$CC.sh" 48 . ".travis/flags-$CC.sh"
42 49
@@ -50,6 +57,9 @@ travis_script() {
50 57
51 other/astyle/format-source . "$ASTYLE" 58 other/astyle/format-source . "$ASTYLE"
52 59
60 # Use () to run in a separate process so the exports are local.
61 (run_static_analysis)
62
53 cmake -B_build -H. \ 63 cmake -B_build -H. \
54 -DCMAKE_C_FLAGS="$C_FLAGS" \ 64 -DCMAKE_C_FLAGS="$C_FLAGS" \
55 -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \ 65 -DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 181d4155..92c7beb9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -104,7 +104,7 @@ if(TRACE)
104endif() 104endif()
105 105
106if(MIN_LOGGER_LEVEL) 106if(MIN_LOGGER_LEVEL)
107 add_definitions(-DMIN_LOGGER_LEVEL=LOG_${MIN_LOGGER_LEVEL}) 107 add_definitions(-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_${MIN_LOGGER_LEVEL})
108endif() 108endif()
109 109
110option(USE_IPV6 "Use IPv6 in tests" ON) 110option(USE_IPV6 "Use IPv6 in tests" ON)
@@ -403,14 +403,6 @@ function(auto_test target)
403 endif() 403 endif()
404endfunction() 404endfunction()
405 405
406if(BUILD_TOXAV)
407 add_definitions(-D__STDC_LIMIT_MACROS=1)
408 add_executable(auto_monolith_test ${CPUFEATURES}
409 auto_tests/monolith_test.cc)
410 target_link_libraries(auto_monolith_test ${toxcore_LINK_MODULES})
411 add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
412endif()
413
414auto_test(TCP) 406auto_test(TCP)
415auto_test(bootstrap) 407auto_test(bootstrap)
416auto_test(conference) 408auto_test(conference)
diff --git a/auto_tests/BUILD.bazel b/auto_tests/BUILD.bazel
index 21c403ab..a5ef7645 100644
--- a/auto_tests/BUILD.bazel
+++ b/auto_tests/BUILD.bazel
@@ -25,32 +25,10 @@ test_sizes = {
25 deps = [ 25 deps = [
26 ":check_compat", 26 ":check_compat",
27 ":run_auto_test", 27 ":run_auto_test",
28 "//c-toxcore/other:monolith",
29 "//c-toxcore/testing:misc_tools", 28 "//c-toxcore/testing:misc_tools",
30 "//c-toxcore/toxav", 29 "//c-toxcore/toxav",
31 "//c-toxcore/toxcore", 30 "//c-toxcore/toxcore",
31 "//c-toxcore/toxcore:DHT_srcs",
32 "//c-toxcore/toxencryptsave", 32 "//c-toxcore/toxencryptsave",
33 ], 33 ],
34) for src in glob(["*_test.c"])] 34) for src in glob(["*_test.c"])]
35
36cc_library(
37 name = "monolith",
38 hdrs = glob([
39 "*.c",
40 "*.h",
41 ]),
42)
43
44cc_test(
45 name = "monolith_test",
46 size = "small",
47 srcs = ["monolith_test.cc"],
48 copts = ["-Wno-sign-compare"],
49 deps = [
50 ":check_compat",
51 ":monolith",
52 ":run_auto_test",
53 "//c-toxcore/other:monolith",
54 "//c-toxcore/testing:misc_tools",
55 ],
56)
diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c
index 4d54f1fb..e99d3b79 100644
--- a/auto_tests/conference_peer_nick_test.c
+++ b/auto_tests/conference_peer_nick_test.c
@@ -65,7 +65,7 @@ static void rebuild_peer_list(Tox *tox)
65 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, 65 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
66 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err); 66 "failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
67 67
68 uint8_t *const name = malloc(size); 68 uint8_t *const name = (uint8_t *)malloc(size);
69 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err); 69 tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
70 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, 70 ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
71 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err); 71 "failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);
diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c
index 92e805c9..2bdee78f 100644
--- a/auto_tests/conference_test.c
+++ b/auto_tests/conference_test.c
@@ -234,7 +234,7 @@ static void test_many_group(void)
234 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr); 234 uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
235 235
236 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)." 236 ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
237 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n", 237 "\n\t\t\tExpected: %d but tox_instance(%u) only has: %u\n\n",
238 NUM_GROUP_TOX, i, (unsigned)peer_count); 238 NUM_GROUP_TOX, i, (unsigned)peer_count);
239 239
240 uint8_t title[2048]; 240 uint8_t title[2048];
diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c
index a6e45431..94bdb42f 100644
--- a/auto_tests/file_transfer_test.c
+++ b/auto_tests/file_transfer_test.c
@@ -140,20 +140,18 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
140 m_send_reached = 1; 140 m_send_reached = 1;
141 } 141 }
142 142
143 TOX_ERR_FILE_SEND_CHUNK error;
144 VLA(uint8_t, f_data, length); 143 VLA(uint8_t, f_data, length);
145 memset(f_data, sending_num, length); 144 memset(f_data, sending_num, length);
146 145
147 if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) { 146 TOX_ERR_FILE_SEND_CHUNK error;
148 ++sending_num; 147 tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error);
149 sending_pos += length;
150 } else {
151 ck_abort_msg("Could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
152 }
153 148
154 if (error != TOX_ERR_FILE_SEND_CHUNK_OK) { 149 if (error != TOX_ERR_FILE_SEND_CHUNK_OK) {
155 ck_abort_msg("Wrong error code"); 150 ck_abort_msg("Could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
156 } 151 }
152
153 ++sending_num;
154 sending_pos += length;
157} 155}
158 156
159 157
diff --git a/auto_tests/monolith_test.cc b/auto_tests/monolith_test.cc
deleted file mode 100644
index 5b1b910d..00000000
--- a/auto_tests/monolith_test.cc
+++ /dev/null
@@ -1,254 +0,0 @@
1/* Nop-test, just to make sure our code compiles as C++.
2 */
3
4#ifdef __FreeBSD__
5// Include this here, because _XOPEN_SOURCE hides symbols we need.
6//
7// https://lists.freebsd.org/pipermail/freebsd-standards/2004-March/000474.html.
8#include <net/if.h>
9#endif
10
11#ifdef __APPLE__
12#define _DARWIN_C_SOURCE
13#endif
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include "../other/monolith.h"
20#define DHT_C_INCLUDED
21
22#include "../testing/misc_tools.c"
23#include "check_compat.h"
24
25#include <ctype.h>
26
27namespace TCP_test {
28int main(void);
29#include "TCP_test.c"
30} // namespace TCP_test
31namespace bootstrap_test {
32int main(void);
33#include "bootstrap_test.c"
34} // namespace bootstrap_test
35namespace conference_simple_test {
36int main(void);
37#include "conference_simple_test.c"
38} // namespace conference_simple_test
39namespace conference_test {
40int main(void);
41#include "conference_test.c"
42} // namespace conference_test
43namespace crypto_test {
44int main(void);
45#include "crypto_test.c"
46} // namespace crypto_test
47namespace dht_test {
48int main(void);
49#include "dht_test.c"
50} // namespace dht_test
51namespace encryptsave_test {
52int main(void);
53#include "encryptsave_test.c"
54} // namespace encryptsave_test
55namespace file_saving_test {
56int main(void);
57#include "file_saving_test.c"
58} // namespace file_saving_test
59namespace friend_request_test {
60int main(void);
61#include "friend_request_test.c"
62} // namespace friend_request_test
63namespace lan_discovery_test {
64int main(void);
65#include "lan_discovery_test.c"
66} // namespace lan_discovery_test
67namespace lossless_packet_test {
68int main(void);
69#include "lossless_packet_test.c"
70} // namespace lossless_packet_test
71namespace lossy_packet_test {
72int main(void);
73#include "lossy_packet_test.c"
74} // namespace lossy_packet_test
75namespace messenger_test {
76int main(void);
77#include "messenger_test.c"
78} // namespace messenger_test
79namespace network_test {
80int main(void);
81#include "network_test.c"
82} // namespace network_test
83namespace onion_test {
84int main(void);
85#include "onion_test.c"
86} // namespace onion_test
87namespace save_friend_test {
88int main(void);
89#include "save_friend_test.c"
90} // namespace save_friend_test
91namespace save_load_test {
92int main(void);
93#include "save_load_test.c"
94} // namespace save_load_test
95namespace send_message_test {
96int main(void);
97#include "send_message_test.c"
98} // namespace send_message_test
99namespace set_name_test {
100int main(void);
101#include "set_name_test.c"
102} // namespace set_name_test
103namespace set_status_message_test {
104int main(void);
105#include "set_status_message_test.c"
106} // namespace set_status_message_test
107namespace skeleton_test {
108int main(void);
109#include "skeleton_test.c"
110} // namespace skeleton_test
111namespace toxav_basic_test {
112int main(void);
113#include "toxav_basic_test.c"
114} // namespace toxav_basic_test
115namespace toxav_many_test {
116int main(void);
117#include "toxav_many_test.c"
118} // namespace toxav_many_test
119namespace tox_many_tcp_test {
120int main(void);
121#include "tox_many_tcp_test.c"
122} // namespace tox_many_tcp_test
123namespace tox_many_test {
124int main(void);
125#include "tox_many_test.c"
126} // namespace tox_many_test
127namespace tox_one_test {
128int main(void);
129#include "tox_one_test.c"
130} // namespace tox_one_test
131namespace tox_strncasecmp_test {
132int main(void);
133#include "tox_strncasecmp_test.c"
134} // namespace tox_strncasecmp_test
135namespace typing_test {
136int main(void);
137#include "typing_test.c"
138} // namespace typing_test
139namespace version_test {
140int main(void);
141#include "version_test.c"
142} // namespace version_test
143
144#define PRINT_SIZE 0
145
146template <typename T, size_t Expected, size_t Actual = sizeof(T)>
147void check_size(char const *type) {
148#if PRINT_SIZE
149 printf("CHECK_SIZE(%s, %zu);\n", type, Actual);
150#else
151 static_assert(Actual == Expected, "Bad sizeof - see template expansion errors for details");
152#endif
153}
154
155#define CHECK_SIZE(TYPE, SIZE) check_size<TYPE, SIZE>(#TYPE)
156
157/**
158 * The main function static-asserts that we are aware of all the sizes of all
159 * the structs it toxcore. If you find this failing after you make a change,
160 * switch on the PRINT_SIZE above and copy the number into this function.
161 */
162int main(int argc, char *argv[]) {
163 static_assert(sizeof(uint64_t) >= sizeof(size_t),
164 "Assumption violated: size_t is more than 64 bits wide");
165
166#if defined(__x86_64__) && defined(__LP64__)
167 // toxcore/DHT
168 CHECK_SIZE(Client_data, 496);
169 CHECK_SIZE(Cryptopacket_Handler, 16);
170 CHECK_SIZE(DHT, 676528);
171 CHECK_SIZE(DHT_Friend, 5104);
172 CHECK_SIZE(Hardening, 144);
173 CHECK_SIZE(IPPTs, 40);
174 CHECK_SIZE(IPPTsPng, 232);
175 CHECK_SIZE(NAT, 48);
176 CHECK_SIZE(Node_format, 64);
177 CHECK_SIZE(Shared_Key, 80);
178 CHECK_SIZE(Shared_Keys, 81920);
179 // toxcore/friend_connection
180 CHECK_SIZE(Friend_Conn, 1784);
181 CHECK_SIZE(Friend_Connections, 72);
182 // toxcore/friend_requests
183 CHECK_SIZE(Friend_Requests, 1080);
184 // toxcore/group
185 CHECK_SIZE(Group_c, 728);
186 CHECK_SIZE(Group_Chats, 2120);
187 CHECK_SIZE(Group_Peer, 480);
188 // toxcore/list
189 CHECK_SIZE(BS_List, 32);
190 // toxcore/logger
191 CHECK_SIZE(Logger, 24);
192 // toxcore/Messenger
193 CHECK_SIZE(File_Transfers, 72);
194 CHECK_SIZE(Friend, 39264);
195 CHECK_SIZE(Messenger, 2008);
196 CHECK_SIZE(Messenger_Options, 72);
197 CHECK_SIZE(Receipts, 16);
198 // toxcore/net_crypto
199#ifdef __linux__
200 CHECK_SIZE(Crypto_Connection, 525392);
201 CHECK_SIZE(Net_Crypto, 272);
202#endif
203 CHECK_SIZE(New_Connection, 168);
204 CHECK_SIZE(Packet_Data, 1384);
205 CHECK_SIZE(Packets_Array, 262152);
206 // toxcore/network
207 CHECK_SIZE(IP, 24);
208 CHECK_SIZE(IP4, 4);
209#if USE_IPV6
210 CHECK_SIZE(IP6, 16);
211#endif
212 CHECK_SIZE(IP_Port, 32);
213 CHECK_SIZE(Networking_Core, 4112);
214 CHECK_SIZE(Packet_Handler, 16);
215 // toxcore/onion_announce
216 CHECK_SIZE(Cmp_data, 296);
217 CHECK_SIZE(Onion_Announce, 128048);
218 CHECK_SIZE(Onion_Announce_Entry, 288);
219 // toxcore/onion_client
220 CHECK_SIZE(Last_Pinged, 40);
221 CHECK_SIZE(Onion_Client, 15816);
222 CHECK_SIZE(Onion_Client_Cmp_data, 176);
223 CHECK_SIZE(Onion_Client_Paths, 2520);
224 CHECK_SIZE(Onion_Friend, 1936);
225 CHECK_SIZE(Onion_Friend, 1936);
226 CHECK_SIZE(Onion_Node, 168);
227 // toxcore/onion
228 CHECK_SIZE(Onion, 245832);
229 CHECK_SIZE(Onion_Path, 392);
230 // toxcore/ping_array
231 CHECK_SIZE(Ping_Array, 24);
232 CHECK_SIZE(Ping_Array_Entry, 32);
233 // toxcore/ping
234 CHECK_SIZE(Ping, 2072);
235 // toxcore/TCP_client
236 CHECK_SIZE(TCP_Client_Connection, 12064);
237 CHECK_SIZE(TCP_Proxy_Info, 40);
238 // toxcore/TCP_connection
239 CHECK_SIZE(TCP_con, 112);
240 CHECK_SIZE(TCP_Connections, 200);
241 CHECK_SIZE(TCP_Connection_to, 112);
242 // toxcore/TCP_server
243 CHECK_SIZE(TCP_Priority_List, 16);
244 CHECK_SIZE(TCP_Secure_Connection, 11816);
245#ifdef TCP_SERVER_USE_EPOLL
246 CHECK_SIZE(TCP_Server, 6049968); // 6MB!
247#else
248 CHECK_SIZE(TCP_Server, 6049952); // 6MB!
249#endif
250 // toxcore/tox
251 CHECK_SIZE(Tox_Options, 64);
252#endif
253 return 0;
254}
diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c
index ff217e87..49933234 100644
--- a/auto_tests/tox_many_test.c
+++ b/auto_tests/tox_many_test.c
@@ -24,16 +24,16 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
24} 24}
25 25
26 26
27#define NUM_TOXES 90 27#define TCP_TEST_NUM_TOXES 90
28#define NUM_FRIENDS 50 28#define TCP_TEST_NUM_FRIENDS 50
29 29
30static void test_many_clients(void) 30static void test_many_clients(void)
31{ 31{
32 time_t cur_time = time(nullptr); 32 time_t cur_time = time(nullptr);
33 Tox *toxes[NUM_TOXES]; 33 Tox *toxes[TCP_TEST_NUM_TOXES];
34 uint32_t index[NUM_TOXES]; 34 uint32_t index[TCP_TEST_NUM_TOXES];
35 35
36 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 36 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
37 index[i] = i + 1; 37 index[i] = i + 1;
38 toxes[i] = tox_new_log(nullptr, nullptr, &index[i]); 38 toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
39 ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i); 39 ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
@@ -43,22 +43,22 @@ static void test_many_clients(void)
43 struct { 43 struct {
44 uint16_t tox1; 44 uint16_t tox1;
45 uint16_t tox2; 45 uint16_t tox2;
46 } pairs[NUM_FRIENDS]; 46 } pairs[TCP_TEST_NUM_FRIENDS];
47 47
48 uint8_t address[TOX_ADDRESS_SIZE]; 48 uint8_t address[TOX_ADDRESS_SIZE];
49 49
50 uint32_t num_f = 0; 50 uint32_t num_f = 0;
51 51
52 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 52 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
53 num_f += tox_self_get_friend_list_size(toxes[i]); 53 num_f += tox_self_get_friend_list_size(toxes[i]);
54 } 54 }
55 55
56 ck_assert_msg(num_f == 0, "bad num friends: %u", num_f); 56 ck_assert_msg(num_f == 0, "bad num friends: %u", num_f);
57 57
58 for (uint32_t i = 0; i < NUM_FRIENDS; ++i) { 58 for (uint32_t i = 0; i < TCP_TEST_NUM_FRIENDS; ++i) {
59loop_top: 59loop_top:
60 pairs[i].tox1 = random_u32() % NUM_TOXES; 60 pairs[i].tox1 = random_u32() % TCP_TEST_NUM_TOXES;
61 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (NUM_TOXES - 1) + 1) % NUM_TOXES; 61 pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (TCP_TEST_NUM_TOXES - 1) + 1) % TCP_TEST_NUM_TOXES;
62 62
63 for (uint32_t j = 0; j < i; ++j) { 63 for (uint32_t j = 0; j < i; ++j) {
64 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { 64 if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
@@ -84,18 +84,18 @@ loop_top:
84 ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test); 84 ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test);
85 } 85 }
86 86
87 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 87 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
88 num_f += tox_self_get_friend_list_size(toxes[i]); 88 num_f += tox_self_get_friend_list_size(toxes[i]);
89 } 89 }
90 90
91 ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f); 91 ck_assert_msg(num_f == TCP_TEST_NUM_FRIENDS, "bad num friends: %u", num_f);
92 92
93 uint16_t last_count = 0; 93 uint16_t last_count = 0;
94 94
95 while (1) { 95 while (1) {
96 uint16_t counter = 0; 96 uint16_t counter = 0;
97 97
98 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 98 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
99 for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { 99 for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
100 if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) { 100 if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) {
101 ++counter; 101 ++counter;
@@ -108,18 +108,18 @@ loop_top:
108 last_count = counter; 108 last_count = counter;
109 } 109 }
110 110
111 if (counter == NUM_FRIENDS * 2) { 111 if (counter == TCP_TEST_NUM_FRIENDS * 2) {
112 break; 112 break;
113 } 113 }
114 114
115 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 115 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
116 tox_iterate(toxes[i], nullptr); 116 tox_iterate(toxes[i], nullptr);
117 } 117 }
118 118
119 c_sleep(50); 119 c_sleep(50);
120 } 120 }
121 121
122 for (uint32_t i = 0; i < NUM_TOXES; ++i) { 122 for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
123 tox_kill(toxes[i]); 123 tox_kill(toxes[i]);
124 } 124 }
125 125
diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c
index 69ec4461..28f18c29 100644
--- a/auto_tests/tox_one_test.c
+++ b/auto_tests/tox_one_test.c
@@ -28,7 +28,7 @@ static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t
28 } 28 }
29} 29}
30 30
31START_TEST(test_one) 31static void test_one(void)
32{ 32{
33 uint8_t name[TOX_MAX_NAME_LENGTH]; 33 uint8_t name[TOX_MAX_NAME_LENGTH];
34 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH]; 34 uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
@@ -128,30 +128,13 @@ START_TEST(test_one)
128 tox_kill(tox1); 128 tox_kill(tox1);
129 tox_kill(tox2); 129 tox_kill(tox2);
130} 130}
131END_TEST
132 131
133 132
134static Suite *tox_suite(void)
135{
136 Suite *s = suite_create("Tox one");
137
138 DEFTESTCASE(one);
139
140 return s;
141}
142
143int main(void) 133int main(void)
144{ 134{
145 setvbuf(stdout, nullptr, _IONBF, 0); 135 setvbuf(stdout, nullptr, _IONBF, 0);
146 136
147 Suite *tox = tox_suite(); 137 test_one();
148 SRunner *test_runner = srunner_create(tox);
149
150 int number_failed = 0;
151 srunner_run_all(test_runner, CK_NORMAL);
152 number_failed = srunner_ntests_failed(test_runner);
153
154 srunner_free(test_runner);
155 138
156 return number_failed; 139 return 0;
157} 140}
diff --git a/configure.ac b/configure.ac
index 35ddb663..5de53523 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,7 +72,7 @@ AC_ARG_ENABLE([logging],
72 if test "x$enableval" = "xyes"; then 72 if test "x$enableval" = "xyes"; then
73 TOX_LOGGER="yes" 73 TOX_LOGGER="yes"
74 74
75 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_DEBUG], [LOG_LEVEL value]) 75 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_DEBUG], [Logger_Level value])
76 fi 76 fi
77 ] 77 ]
78) 78)
@@ -85,19 +85,19 @@ AC_ARG_WITH(log-level,
85 AC_MSG_WARN([Logging disabled!]) 85 AC_MSG_WARN([Logging disabled!])
86 else 86 else
87 if test "x$withval" = "xTRACE"; then 87 if test "x$withval" = "xTRACE"; then
88 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_TRACE], [LOG_LEVEL value]) 88 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_TRACE], [Logger_Level value])
89 89
90 elif test "x$withval" = "xDEBUG"; then 90 elif test "x$withval" = "xDEBUG"; then
91 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_DEBUG], [LOG_LEVEL value]) 91 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_DEBUG], [Logger_Level value])
92 92
93 elif test "x$withval" = "xINFO"; then 93 elif test "x$withval" = "xINFO"; then
94 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_INFO], [LOG_LEVEL value]) 94 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_INFO], [Logger_Level value])
95 95
96 elif test "x$withval" = "xWARNING"; then 96 elif test "x$withval" = "xWARNING"; then
97 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_WARNING], [LOG_LEVEL value]) 97 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_WARNING], [Logger_Level value])
98 98
99 elif test "x$withval" = "xERROR"; then 99 elif test "x$withval" = "xERROR"; then
100 AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_ERROR], [LOG_LEVEL value]) 100 AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_ERROR], [Logger_Level value])
101 else 101 else
102 AC_MSG_WARN([Invalid logger level: $withval. Using default 'DEBUG']) 102 AC_MSG_WARN([Invalid logger level: $withval. Using default 'DEBUG'])
103 fi 103 fi
diff --git a/other/BUILD.bazel b/other/BUILD.bazel
index 8bcdc4b4..d0fcf850 100644
--- a/other/BUILD.bazel
+++ b/other/BUILD.bazel
@@ -1,18 +1,6 @@
1load("//tools:no_undefined.bzl", "cc_library") 1load("//tools:no_undefined.bzl", "cc_library")
2 2
3cc_library( 3cc_library(
4 name = "monolith",
5 hdrs = ["monolith.h"],
6 visibility = ["//c-toxcore/auto_tests:__pkg__"],
7 deps = [
8 "//c-toxcore/testing:monolith",
9 "//c-toxcore/toxav:monolith",
10 "//c-toxcore/toxcore:monolith",
11 "//c-toxcore/toxencryptsave:monolith",
12 ],
13)
14
15cc_library(
16 name = "bootstrap_node_packets", 4 name = "bootstrap_node_packets",
17 srcs = ["bootstrap_node_packets.c"], 5 srcs = ["bootstrap_node_packets.c"],
18 hdrs = ["bootstrap_node_packets.h"], 6 hdrs = ["bootstrap_node_packets.h"],
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh
index 710e20d7..89144eff 100644
--- a/other/analysis/gen-file.sh
+++ b/other/analysis/gen-file.sh
@@ -1,48 +1,80 @@
1CPPFLAGS="-DMIN_LOGGER_LEVEL=LOG_TRACE -Iauto_tests -Itoxcore -Itoxav -Itoxencryptsave `pkg-config --cflags libsodium opus vpx`" 1#!/bin/sh
2
3CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
4CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus"
5CPPFLAGS="$CPPFLAGS -Iauto_tests"
6CPPFLAGS="$CPPFLAGS -Iother"
7CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src"
8CPPFLAGS="$CPPFLAGS -Iother/fun"
9CPPFLAGS="$CPPFLAGS -Itesting"
10CPPFLAGS="$CPPFLAGS -Itoxcore"
11CPPFLAGS="$CPPFLAGS -Itoxav"
12CPPFLAGS="$CPPFLAGS -Itoxencryptsave"
13
14LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig"
2 15
3put() { 16put() {
4 if [ "$SKIP_LINES" = "" ]; then 17 if [ "$SKIP_LINES" = "" ]; then
5 echo "#line 1 \"$1\"" >> test.c 18 echo "#line 1 \"$1\"" >> amalgamation.cc
19 fi
20 cat $1 >> amalgamation.cc
21}
22
23putmain() {
24 echo "namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc
25 if [ "$SKIP_LINES" = "" ]; then
26 echo "#line 1 \"$1\"" >> amalgamation.cc
6 fi 27 fi
7 cat $1 >> test.c 28 sed -e 's/^int main(/static &/' $1 >> amalgamation.cc
29 echo "} // namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc
30}
31
32callmain() {
33 echo " call($(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc
8} 34}
9 35
10:> test.c 36:> amalgamation.cc
11 37
12put toxcore/tox.c 38echo "#include <algorithm>" >> amalgamation.cc
13 39echo "#include <cstdio>" >> amalgamation.cc
14put toxcore/DHT.c 40echo "#include <memory>" >> amalgamation.cc
15put toxcore/LAN_discovery.c 41echo "#include <random>" >> amalgamation.cc
16put toxcore/Messenger.c 42
17put toxcore/TCP_client.c 43echo "#define TOX_DEFINED" >> amalgamation.cc
18put toxcore/TCP_connection.c 44echo "typedef struct Messenger Tox;" >> amalgamation.cc
19put toxcore/TCP_server.c 45
20put toxcore/crypto_core.c 46put auto_tests/check_compat.h
21put toxcore/crypto_core_mem.c 47
22put toxcore/friend_connection.c 48FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'"
23put toxcore/friend_requests.c 49FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'"
24put toxcore/group.c 50FIND_QUERY="$FIND_QUERY -and -not -wholename './toxav/*.cc'"
25put toxcore/list.c 51FIND_QUERY="$FIND_QUERY -and -not -wholename './toxcore/*.cc'"
26put toxcore/logger.c 52FIND_QUERY="$FIND_QUERY -and -not -wholename './toxencryptsave/*.cc'"
27put toxcore/network.c 53FIND_QUERY="$FIND_QUERY -and -not -name amalgamation.cc"
28put toxcore/net_crypto.c 54FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
29put toxcore/onion.c 55FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
30put toxcore/onion_announce.c 56FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
31put toxcore/onion_client.c 57
32put toxcore/ping.c 58for i in $(eval $FIND_QUERY); do
33put toxcore/ping_array.c 59 if ! grep -q '^int main(' $i; then
34put toxcore/tox_api.c 60 put $i
35put toxcore/util.c 61 fi
36 62done
37# Not included yet, since there are too many issues with this code. 63
38#put toxav/audio.c 64for i in $(eval $FIND_QUERY); do
39#put toxav/bwcontroller.c 65 if grep -q '^int main(' $i; then
40#put toxav/groupav.c 66 putmain $i
41#put toxav/msi.c 67 fi
42#put toxav/ring_buffer.c 68done
43#put toxav/rtp.c 69
44#put toxav/toxav.c 70echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc
45#put toxav/toxav_old.c 71echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc
46#put toxav/video.c 72
47 73echo "int main(int argc, char **argv) {" >> amalgamation.cc
48put toxencryptsave/toxencryptsave.c 74for i in $(eval $FIND_QUERY); do
75 if grep -q '^int main(' $i; then
76 callmain $i
77 fi
78done
79echo " return 0;" >> amalgamation.cc
80echo "}" >> amalgamation.cc
diff --git a/other/analysis/run-clang b/other/analysis/run-clang
index 1c8da7ea..60e59eab 100755
--- a/other/analysis/run-clang
+++ b/other/analysis/run-clang
@@ -2,6 +2,22 @@
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5put auto_tests/lan_discovery_test.c 5echo "Running Clang compiler"
6 6clang++ -o /dev/null amalgamation.cc \
7clang --analyze test.c $CPPFLAGS 7 $CPPFLAGS \
8 $LDFLAGS \
9 -std=c++11 \
10 -Weverything \
11 -Wno-c++98-compat-pedantic \
12 -Wno-c99-extensions \
13 -Wno-cast-align \
14 -Wno-conversion \
15 -Wno-covered-switch-default \
16 -Wno-documentation-deprecated-sync \
17 -Wno-missing-field-initializers \
18 -Wno-old-style-cast \
19 -Wno-padded \
20 -Wno-sign-compare \
21 -Wno-unreachable-code-return \
22 -Wno-unused-parameter \
23 -Wno-used-but-marked-unused \
diff --git a/other/analysis/run-clang-analyze b/other/analysis/run-clang-analyze
new file mode 100755
index 00000000..0e6d9af0
--- /dev/null
+++ b/other/analysis/run-clang-analyze
@@ -0,0 +1,8 @@
1#!/bin/sh
2
3. other/analysis/gen-file.sh
4
5echo "Running Clang static analyzer"
6clang++ --analyze amalgamation.cc \
7 $CPPFLAGS \
8 -std=c++11
diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck
index 9e928c9a..dc369840 100755
--- a/other/analysis/run-cppcheck
+++ b/other/analysis/run-cppcheck
@@ -2,6 +2,4 @@
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5put auto_tests/lan_discovery_test.c 5cppcheck amalgamation.cc $CPPFLAGS
6
7cppcheck test.c $CPPFLAGS
diff --git a/other/analysis/run-gcc b/other/analysis/run-gcc
index ffd42f4e..3ea32782 100755
--- a/other/analysis/run-gcc
+++ b/other/analysis/run-gcc
@@ -2,12 +2,14 @@
2 2
3. other/analysis/gen-file.sh 3. other/analysis/gen-file.sh
4 4
5put auto_tests/lan_discovery_test.c 5echo "Running GCC"
6
7# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector 6# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector
8gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ 7g++ -O3 -o /dev/null amalgamation.cc \
9 -std=c99 \ 8 $CPPFLAGS \
9 $LDFLAGS \
10 -std=c++11 \
10 -pedantic \ 11 -pedantic \
12 -fdiagnostics-color=always \
11 -Wall \ 13 -Wall \
12 -Wextra \ 14 -Wextra \
13 -Wno-aggregate-return \ 15 -Wno-aggregate-return \
@@ -22,18 +24,9 @@ gcc -O3 -c -o /dev/null test.c $CPPFLAGS \
22 -Wno-unused-parameter \ 24 -Wno-unused-parameter \
23 -Wstrict-aliasing=0 \ 25 -Wstrict-aliasing=0 \
24 -Wstrict-overflow=1 \ 26 -Wstrict-overflow=1 \
25 \ 27 \
26 -Wbad-function-cast \
27 -Wmissing-declarations \ 28 -Wmissing-declarations \
28 -Wmissing-parameter-type \
29 -Wmissing-prototypes \
30 -Wnested-externs \
31 -Wold-style-declaration \
32 -Wold-style-definition \
33 -Wstrict-prototypes \
34 -Wbool-compare \ 29 -Wbool-compare \
35 -Wc99-c11-compat \
36 -Wc++-compat \
37 -Wcast-align \ 30 -Wcast-align \
38 -Wcast-qual \ 31 -Wcast-qual \
39 -Wchar-subscripts \ 32 -Wchar-subscripts \
@@ -45,10 +38,8 @@ gcc -O3 -c -o /dev/null test.c $CPPFLAGS \
45 -Wformat=2 \ 38 -Wformat=2 \
46 -Wframe-address \ 39 -Wframe-address \
47 -Wframe-larger-than=133168 \ 40 -Wframe-larger-than=133168 \
48 -Wjump-misses-init \
49 -Wignored-qualifiers \ 41 -Wignored-qualifiers \
50 -Wignored-attributes \ 42 -Wignored-attributes \
51 -Wincompatible-pointer-types \
52 -Winit-self \ 43 -Winit-self \
53 -Winline \ 44 -Winline \
54 -Wlarger-than=133120 \ 45 -Wlarger-than=133120 \
diff --git a/other/analysis/run-infer b/other/analysis/run-infer
index 942d0cfd..2a897227 100755
--- a/other/analysis/run-infer
+++ b/other/analysis/run-infer
@@ -5,6 +5,4 @@ SKIP_LINES=1
5 5
6. other/analysis/gen-file.sh 6. other/analysis/gen-file.sh
7 7
8put auto_tests/lan_discovery_test.c 8infer -- clang++ -fsyntax-only amalgamation.cc $CPPFLAGS
9
10infer -- clang -fsyntax-only test.c $CPPFLAGS
diff --git a/other/analysis/run-sparse b/other/analysis/run-sparse
deleted file mode 100755
index b4d0f736..00000000
--- a/other/analysis/run-sparse
+++ /dev/null
@@ -1,9 +0,0 @@
1#!/bin/sh
2
3. other/analysis/gen-file.sh
4
5put auto_tests/lan_discovery_test.c
6
7sparse test.c $CPPFLAGS \
8 -Wsparse-all \
9 -Wno-declaration-after-statement
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c
index 9fde33b2..0a7f566b 100644
--- a/other/bootstrap_daemon/src/config.c
+++ b/other/bootstrap_daemon/src/config.c
@@ -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 */
306static uint8_t *hex_string_to_bin(const char *hex_string) 306static uint8_t *bootstrap_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 nullptr; 309 return nullptr;
@@ -407,7 +407,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
407 goto next; 407 goto next;
408 } 408 }
409 409
410 bs_public_key_bin = hex_string_to_bin(bs_public_key); 410 bs_public_key_bin = bootstrap_hex_string_to_bin(bs_public_key);
411 address_resolved = dht_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port), 411 address_resolved = dht_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port),
412 bs_public_key_bin); 412 bs_public_key_bin);
413 free(bs_public_key_bin); 413 free(bs_public_key_bin);
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c
index fd05f8a2..b17fc2ba 100644
--- a/other/bootstrap_daemon/src/tox-bootstrapd.c
+++ b/other/bootstrap_daemon/src/tox-bootstrapd.c
@@ -22,7 +22,9 @@
22 * You should have received a copy of the GNU General Public License 22 * You should have received a copy of the GNU General Public License
23 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 23 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
24 */ 24 */
25#ifndef _XOPEN_SOURCE
25#define _XOPEN_SOURCE 600 26#define _XOPEN_SOURCE 600
27#endif
26 28
27// system provided 29// system provided
28#include <sys/stat.h> 30#include <sys/stat.h>
diff --git a/other/cpufeatures.c b/other/cpufeatures.c
index e52a90ff..3da06e58 100644
--- a/other/cpufeatures.c
+++ b/other/cpufeatures.c
@@ -1,5 +1,5 @@
1#define typeof __typeof__
2#ifdef ANDROID_CPU_FEATURES 1#ifdef ANDROID_CPU_FEATURES
2#define typeof __typeof__
3#include ANDROID_CPU_FEATURES 3#include ANDROID_CPU_FEATURES
4#endif 4#endif
5 5
diff --git a/other/fun/cracker.c b/other/fun/cracker.c
index 502a8af0..fd9564f6 100644
--- a/other/fun/cracker.c
+++ b/other/fun/cracker.c
@@ -20,7 +20,7 @@
20#include "../../testing/misc_tools.h" 20#include "../../testing/misc_tools.h"
21#include "../../toxcore/ccompat.h" 21#include "../../toxcore/ccompat.h"
22 22
23void print_key(uint8_t *client_id) 23static void print_key(uint8_t *client_id)
24{ 24{
25 uint32_t j; 25 uint32_t j;
26 26
diff --git a/other/fun/sign.c b/other/fun/sign.c
index 007d19a0..547af311 100644
--- a/other/fun/sign.c
+++ b/other/fun/sign.c
@@ -21,7 +21,7 @@
21#include "../../testing/misc_tools.h" // hex_string_to_bin 21#include "../../testing/misc_tools.h" // hex_string_to_bin
22#include "../../toxcore/ccompat.h" 22#include "../../toxcore/ccompat.h"
23 23
24int load_file(char *filename, char **result) 24static int load_file(char *filename, unsigned char **result)
25{ 25{
26 int size = 0; 26 int size = 0;
27 FILE *f = fopen(filename, "rb"); 27 FILE *f = fopen(filename, "rb");
@@ -34,7 +34,7 @@ int load_file(char *filename, char **result)
34 fseek(f, 0, SEEK_END); 34 fseek(f, 0, SEEK_END);
35 size = ftell(f); 35 size = ftell(f);
36 fseek(f, 0, SEEK_SET); 36 fseek(f, 0, SEEK_SET);
37 *result = (char *)malloc(size + 1); 37 *result = (unsigned char *)malloc(size + 1);
38 38
39 if (size != fread(*result, sizeof(char), size, f)) { 39 if (size != fread(*result, sizeof(char), size, f)) {
40 free(*result); 40 free(*result);
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
72 72
73 if (argc == 5 && argv[1][0] == 's') { 73 if (argc == 5 && argv[1][0] == 's') {
74 unsigned char *secret_key = hex_string_to_bin(argv[2]); 74 unsigned char *secret_key = hex_string_to_bin(argv[2]);
75 char *data; 75 unsigned char *data;
76 int size = load_file(argv[3], &data); 76 int size = load_file(argv[3], &data);
77 77
78 if (size < 0) { 78 if (size < 0) {
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
80 } 80 }
81 81
82 unsigned long long smlen; 82 unsigned long long smlen;
83 char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); 83 unsigned char *sm = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES * 2);
84 crypto_sign_ed25519(sm, &smlen, data, size, secret_key); 84 crypto_sign_ed25519(sm, &smlen, data, size, secret_key);
85 free(secret_key); 85 free(secret_key);
86 86
@@ -106,19 +106,18 @@ int main(int argc, char *argv[])
106 106
107 if (argc == 4 && argv[1][0] == 'c') { 107 if (argc == 4 && argv[1][0] == 'c') {
108 unsigned char *public_key = hex_string_to_bin(argv[2]); 108 unsigned char *public_key = hex_string_to_bin(argv[2]);
109 char *data; 109 unsigned char *data;
110 int size = load_file(argv[3], &data); 110 int size = load_file(argv[3], &data);
111 111
112 if (size < 0) { 112 if (size < 0) {
113 goto fail; 113 goto fail;
114 } 114 }
115 115
116 char *signe = malloc(size + crypto_sign_ed25519_BYTES); 116 unsigned char *signe = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES);
117 memcpy(signe, data + size - crypto_sign_ed25519_BYTES, 117 memcpy(signe, data + size - crypto_sign_ed25519_BYTES,
118 crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file. 118 crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file.
119 memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); 119 memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES);
120 unsigned long long smlen; 120 unsigned char *m = (unsigned char *)malloc(size);
121 char *m = malloc(size);
122 unsigned long long mlen; 121 unsigned long long mlen;
123 122
124 if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { 123 if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) {
diff --git a/other/fun/strkey.c b/other/fun/strkey.c
index ef54a404..d769318a 100644
--- a/other/fun/strkey.c
+++ b/other/fun/strkey.c
@@ -43,7 +43,7 @@
43 43
44#define PRINT_TRIES_COUNT 44#define PRINT_TRIES_COUNT
45 45
46void print_key(unsigned char *key) 46static void print_key(unsigned char *key)
47{ 47{
48 size_t i; 48 size_t i;
49 49
diff --git a/other/monolith.h b/other/monolith.h
deleted file mode 100644
index 356252f2..00000000
--- a/other/monolith.h
+++ /dev/null
@@ -1,38 +0,0 @@
1#include "../toxcore/tox.c"
2
3#include "../toxcore/DHT.c"
4#include "../toxcore/LAN_discovery.c"
5#include "../toxcore/Messenger.c"
6#include "../toxcore/TCP_client.c"
7#include "../toxcore/TCP_connection.c"
8#include "../toxcore/TCP_server.c"
9#include "../toxcore/crypto_core.c"
10#include "../toxcore/crypto_core_mem.c"
11#include "../toxcore/friend_connection.c"
12#include "../toxcore/friend_requests.c"
13#include "../toxcore/group.c"
14#include "../toxcore/list.c"
15#include "../toxcore/logger.c"
16#include "../toxcore/mono_time.c"
17#include "../toxcore/network.c"
18#include "../toxcore/net_crypto.c"
19#include "../toxcore/onion.c"
20#include "../toxcore/onion_announce.c"
21#include "../toxcore/onion_client.c"
22#include "../toxcore/ping.c"
23#include "../toxcore/ping_array.c"
24#include "../toxcore/state.c"
25#include "../toxcore/tox_api.c"
26#include "../toxcore/util.c"
27
28#include "../toxav/audio.c"
29#include "../toxav/bwcontroller.c"
30#include "../toxav/groupav.c"
31#include "../toxav/msi.c"
32#include "../toxav/ring_buffer.c"
33#include "../toxav/rtp.c"
34#include "../toxav/toxav.c"
35#include "../toxav/toxav_old.c"
36#include "../toxav/video.c"
37
38#include "../toxencryptsave/toxencryptsave.c"
diff --git a/testing/BUILD.bazel b/testing/BUILD.bazel
index 4d0674b4..c0d76f7f 100644
--- a/testing/BUILD.bazel
+++ b/testing/BUILD.bazel
@@ -35,7 +35,7 @@ cc_binary(
35 copts = ["-O1"], 35 copts = ["-O1"],
36 deps = [ 36 deps = [
37 "//c-toxcore/toxav", 37 "//c-toxcore/toxav",
38 "//c-toxcore/toxav:monolith", 38 "//c-toxcore/toxav:ring_buffer_srcs",
39 "//c-toxcore/toxcore", 39 "//c-toxcore/toxcore",
40 "@opencv//:core", 40 "@opencv//:core",
41 "@opencv//:highgui", 41 "@opencv//:highgui",
@@ -52,13 +52,3 @@ cc_binary(
52 "//c-toxcore/toxcore", 52 "//c-toxcore/toxcore",
53 ], 53 ],
54) 54)
55
56cc_library(
57 name = "monolith",
58 hdrs = [
59 "misc_tools.c",
60 "misc_tools.h",
61 ],
62 visibility = ["//c-toxcore/other:__pkg__"],
63 deps = ["//c-toxcore/toxcore"],
64)
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index c242953a..78853746 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -28,7 +28,9 @@
28 * You should have received a copy of the GNU General Public License 28 * You should have received a copy of the GNU General Public License
29 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 29 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
30 */ 30 */
31#ifndef _XOPEN_SOURCE
31#define _XOPEN_SOURCE 600 32#define _XOPEN_SOURCE 600
33#endif
32 34
33#include <stdlib.h> 35#include <stdlib.h>
34#include <stdio.h> 36#include <stdio.h>
diff --git a/testing/random_testing.cc b/testing/random_testing.cc
index bcdb8e70..4e64c1b4 100644
--- a/testing/random_testing.cc
+++ b/testing/random_testing.cc
@@ -102,6 +102,7 @@ struct Global_State : std::vector<Local_State> {
102 // Non-copyable; 102 // Non-copyable;
103 Global_State(Global_State const &) = delete; 103 Global_State(Global_State const &) = delete;
104 Global_State(Global_State &&) = default; 104 Global_State(Global_State &&) = default;
105 ~Global_State();
105 explicit Global_State(std::vector<Action> const &actions) 106 explicit Global_State(std::vector<Action> const &actions)
106 : actions_(actions), rnd_(actions), action_counter_(actions.size()) {} 107 : actions_(actions), rnd_(actions), action_counter_(actions.size()) {}
107 108
@@ -115,6 +116,8 @@ struct Global_State : std::vector<Local_State> {
115 std::vector<unsigned> action_counter_; 116 std::vector<unsigned> action_counter_;
116}; 117};
117 118
119Global_State::~Global_State() {}
120
118void handle_friend_connection_status(Tox *tox, uint32_t friend_number, 121void handle_friend_connection_status(Tox *tox, uint32_t friend_number,
119 TOX_CONNECTION connection_status, void *user_data) { 122 TOX_CONNECTION connection_status, void *user_data) {
120 Local_State *state = static_cast<Local_State *>(user_data); 123 Local_State *state = static_cast<Local_State *>(user_data);
@@ -394,4 +397,6 @@ int main() {
394 for (uint32_t i = 0; i < toxes.action_counter().size(); i++) { 397 for (uint32_t i = 0; i < toxes.action_counter().size(); i++) {
395 std::printf("%u x '%s'\n", toxes.action_counter().at(i), actions[i].title); 398 std::printf("%u x '%s'\n", toxes.action_counter().at(i), actions[i].title);
396 } 399 }
400
401 return 0;
397} 402}
diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel
index f6c92b52..ec67d986 100644
--- a/toxav/BUILD.bazel
+++ b/toxav/BUILD.bazel
@@ -28,6 +28,16 @@ cc_test(
28) 28)
29 29
30cc_library( 30cc_library(
31 name = "ring_buffer_srcs",
32 hdrs = [
33 "ring_buffer.c",
34 "ring_buffer.h",
35 ],
36 visibility = ["//c-toxcore/testing:__pkg__"],
37 deps = ["//c-toxcore/toxcore:ccompat"],
38)
39
40cc_library(
31 name = "bwcontroller", 41 name = "bwcontroller",
32 srcs = ["bwcontroller.c"], 42 srcs = ["bwcontroller.c"],
33 hdrs = ["bwcontroller.h"], 43 hdrs = ["bwcontroller.h"],
@@ -117,20 +127,3 @@ cc_library(
117 ":video", 127 ":video",
118 ], 128 ],
119) 129)
120
121cc_library(
122 name = "monolith",
123 hdrs = glob([
124 "*.c",
125 "*.h",
126 ]),
127 visibility = [
128 "//c-toxcore/other:__pkg__",
129 "//c-toxcore/testing:__pkg__",
130 ],
131 deps = [
132 "//c-toxcore/toxcore:group",
133 "@libvpx",
134 "@opus",
135 ],
136)
diff --git a/toxav/groupav.h b/toxav/groupav.h
index ca30a51b..42f2c578 100644
--- a/toxav/groupav.h
+++ b/toxav/groupav.h
@@ -17,6 +17,9 @@
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 18 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
19 */ 19 */
20#ifndef C_TOXCORE_TOXAV_GROUPAV_H
21#define C_TOXCORE_TOXAV_GROUPAV_H
22
20#include "../toxcore/group.h" 23#include "../toxcore/group.h"
21 24
22/* Audio encoding/decoding */ 25/* Audio encoding/decoding */
@@ -50,3 +53,5 @@ int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber
50int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, 53int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
51 uint32_t sample_rate); 54 uint32_t sample_rate);
52 55
56
57#endif // C_TOXCORE_TOXAV_GROUPAV_H
diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel
index 543bb59f..6fbe016e 100644
--- a/toxcore/BUILD.bazel
+++ b/toxcore/BUILD.bazel
@@ -135,6 +135,27 @@ cc_library(
135) 135)
136 136
137cc_library( 137cc_library(
138 name = "DHT_srcs",
139 hdrs = [
140 "DHT.c",
141 "DHT.h",
142 "LAN_discovery.c",
143 "LAN_discovery.h",
144 "ping.c",
145 "ping.h",
146 ],
147 visibility = [
148 "//c-toxcore/auto_tests:__pkg__",
149 "//c-toxcore/other/bootstrap_daemon:__pkg__",
150 ],
151 deps = [
152 ":logger",
153 ":ping_array",
154 ":state",
155 ],
156)
157
158cc_library(
138 name = "onion", 159 name = "onion",
139 srcs = ["onion.c"], 160 srcs = ["onion.c"],
140 hdrs = ["onion.h"], 161 hdrs = ["onion.h"],
@@ -242,17 +263,3 @@ cc_library(
242 "//c-toxcore/toxencryptsave:defines", 263 "//c-toxcore/toxencryptsave:defines",
243 ], 264 ],
244) 265)
245
246cc_library(
247 name = "monolith",
248 hdrs = glob([
249 "*.c",
250 "*.h",
251 ]),
252 linkopts = ["-lpthread"],
253 visibility = ["//c-toxcore/other:__pkg__"],
254 deps = [
255 "//c-toxcore/toxencryptsave:defines",
256 "@libsodium",
257 ],
258)
diff --git a/toxcore/logger.c b/toxcore/logger.c
index ac80b194..5e16233c 100644
--- a/toxcore/logger.c
+++ b/toxcore/logger.c
@@ -44,19 +44,19 @@ struct Logger {
44static const char *logger_level_name(Logger_Level level) 44static const char *logger_level_name(Logger_Level level)
45{ 45{
46 switch (level) { 46 switch (level) {
47 case LOG_TRACE: 47 case LOGGER_LEVEL_TRACE:
48 return "TRACE"; 48 return "TRACE";
49 49
50 case LOG_DEBUG: 50 case LOGGER_LEVEL_DEBUG:
51 return "DEBUG"; 51 return "DEBUG";
52 52
53 case LOG_INFO: 53 case LOGGER_LEVEL_INFO:
54 return "INFO"; 54 return "INFO";
55 55
56 case LOG_WARNING: 56 case LOGGER_LEVEL_WARNING:
57 return "WARNING"; 57 return "WARNING";
58 58
59 case LOG_ERROR: 59 case LOGGER_LEVEL_ERROR:
60 return "ERROR"; 60 return "ERROR";
61 } 61 }
62 62
diff --git a/toxcore/logger.h b/toxcore/logger.h
index 38cc0ac9..dd7edee7 100644
--- a/toxcore/logger.h
+++ b/toxcore/logger.h
@@ -29,15 +29,15 @@
29#include "ccompat.h" 29#include "ccompat.h"
30 30
31#ifndef MIN_LOGGER_LEVEL 31#ifndef MIN_LOGGER_LEVEL
32#define MIN_LOGGER_LEVEL LOG_INFO 32#define MIN_LOGGER_LEVEL LOGGER_LEVEL_INFO
33#endif 33#endif
34 34
35typedef enum Logger_Level { 35typedef enum Logger_Level {
36 LOG_TRACE, 36 LOGGER_LEVEL_TRACE,
37 LOG_DEBUG, 37 LOGGER_LEVEL_DEBUG,
38 LOG_INFO, 38 LOGGER_LEVEL_INFO,
39 LOG_WARNING, 39 LOGGER_LEVEL_WARNING,
40 LOG_ERROR 40 LOGGER_LEVEL_ERROR
41} Logger_Level; 41} Logger_Level;
42 42
43typedef struct Logger Logger; 43typedef struct Logger Logger;
@@ -84,10 +84,10 @@ void logger_write(
84 } while (0) 84 } while (0)
85 85
86/* To log with an logger */ 86/* To log with an logger */
87#define LOGGER_TRACE(log, ...) LOGGER_WRITE(log, LOG_TRACE , __VA_ARGS__) 87#define LOGGER_TRACE(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_TRACE , __VA_ARGS__)
88#define LOGGER_DEBUG(log, ...) LOGGER_WRITE(log, LOG_DEBUG , __VA_ARGS__) 88#define LOGGER_DEBUG(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_DEBUG , __VA_ARGS__)
89#define LOGGER_INFO(log, ...) LOGGER_WRITE(log, LOG_INFO , __VA_ARGS__) 89#define LOGGER_INFO(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_INFO , __VA_ARGS__)
90#define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOG_WARNING, __VA_ARGS__) 90#define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_WARNING, __VA_ARGS__)
91#define LOGGER_ERROR(log, ...) LOGGER_WRITE(log, LOG_ERROR , __VA_ARGS__) 91#define LOGGER_ERROR(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_ERROR , __VA_ARGS__)
92 92
93#endif /* TOXLOGGER_H */ 93#endif /* TOXLOGGER_H */
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 80ff42c3..cdccbe45 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -25,10 +25,14 @@
25#include "config.h" 25#include "config.h"
26#endif 26#endif
27 27
28#ifndef _XOPEN_SOURCE
28#define _XOPEN_SOURCE 600 29#define _XOPEN_SOURCE 600
30#endif
29 31
32#ifndef TOX_DEFINED
30#define TOX_DEFINED 33#define TOX_DEFINED
31typedef struct Messenger Tox; 34typedef struct Messenger Tox;
35#endif
32#include "tox.h" 36#include "tox.h"
33 37
34#include <assert.h> 38#include <assert.h>