diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index d7312be85a..98edc357cd 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -130,7 +130,7 @@ struct sec_TCP_con { uint8_t shared_key[crypto_box_BEFORENMBYTES]; }; -struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) +static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) { struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con)); 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) return sec_c; } -void kill_TCP_con(struct sec_TCP_con *con) +static void kill_TCP_con(struct sec_TCP_con *con) { kill_sock(con->sock); free(con); } -int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) +static int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, uint16_t length) { uint8_t packet[sizeof(uint16_t) + length + crypto_box_MACBYTES]; @@ -200,7 +200,7 @@ int write_packet_TCP_secure_connection(struct sec_TCP_con *con, uint8_t *data, u return 0; } -int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length) +static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t length) { int len = recv(con->sock, data, length, 0); ck_assert_msg(len == length, "wrong len %i\n", len); @@ -731,7 +731,7 @@ START_TEST(test_tcp_connection2) } END_TEST -Suite *TCP_suite(void) +static Suite *TCP_suite(void) { Suite *s = suite_create("TCP"); diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c index 79a97fd5bf..887ffc0bd4 100644 --- a/auto_tests/assoc_test.c +++ b/auto_tests/assoc_test.c @@ -134,7 +134,7 @@ START_TEST(test_fillup) } END_TEST -Suite *Assoc_suite(void) +static Suite *Assoc_suite(void) { Suite *s = suite_create("Assoc"); diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index 30cc2178b6..ff8ab41d57 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -12,7 +12,7 @@ #include "helpers.h" -void rand_bytes(uint8_t *b, size_t blen) +static void rand_bytes(uint8_t *b, size_t blen) { size_t i; @@ -23,27 +23,27 @@ void rand_bytes(uint8_t *b, size_t blen) // These test vectors are from libsodium's test suite -unsigned char alicesk[32] = { +static const unsigned char alicesk[32] = { 0x77, 0x07, 0x6d, 0x0a, 0x73, 0x18, 0xa5, 0x7d, 0x3c, 0x16, 0xc1, 0x72, 0x51, 0xb2, 0x66, 0x45, 0xdf, 0x4c, 0x2f, 0x87, 0xeb, 0xc0, 0x99, 0x2a, 0xb1, 0x77, 0xfb, 0xa5, 0x1d, 0xb9, 0x2c, 0x2a }; -unsigned char bobpk[32] = { +static const unsigned char bobpk[32] = { 0xde, 0x9e, 0xdb, 0x7d, 0x7b, 0x7d, 0xc1, 0xb4, 0xd3, 0x5b, 0x61, 0xc2, 0xec, 0xe4, 0x35, 0x37, 0x3f, 0x83, 0x43, 0xc8, 0x5b, 0x78, 0x67, 0x4d, 0xad, 0xfc, 0x7e, 0x14, 0x6f, 0x88, 0x2b, 0x4f }; -unsigned char nonce[24] = { +static const unsigned char nonce[24] = { 0x69, 0x69, 0x6e, 0xe9, 0x55, 0xb6, 0x2b, 0x73, 0xcd, 0x62, 0xbd, 0xa8, 0x75, 0xfc, 0x73, 0xd6, 0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37 }; -unsigned char test_m[131] = { +static const unsigned char test_m[131] = { 0xbe, 0x07, 0x5f, 0xc5, 0x3c, 0x81, 0xf2, 0xd5, 0xcf, 0x14, 0x13, 0x16, 0xeb, 0xeb, 0x0c, 0x7b, 0x52, 0x28, 0xc5, 0x2a, 0x4c, 0x62, 0xcb, 0xd4, @@ -63,7 +63,7 @@ unsigned char test_m[131] = { 0x5e, 0x07, 0x05 }; -unsigned char test_c[147] = { +static const unsigned char test_c[147] = { 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9, 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, @@ -271,7 +271,7 @@ START_TEST(test_large_data_symmetric) } END_TEST -void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) +static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) { uint32_t num1, num2; memcpy(&num1, nonce + (crypto_box_NONCEBYTES - sizeof(num1)), sizeof(num1)); @@ -323,7 +323,7 @@ START_TEST(test_increment_nonce) } END_TEST -Suite *crypto_suite(void) +static Suite *crypto_suite(void) { Suite *s = suite_create("Crypto"); diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 7aab9573f5..dd68ffbe00 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -10,6 +10,9 @@ #include "helpers.h" + +// These tests currently fail. +#if 0 #define swap(x,y) do \ { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ memcpy(swap_temp,&y,sizeof(x)); \ @@ -18,7 +21,7 @@ } while(0) -void mark_bad(IPPTsPng *ipptp) +static void mark_bad(IPPTsPng *ipptp) { ipptp->timestamp = unix_time() - 2 * BAD_NODE_TIMEOUT; ipptp->hardening.routes_requests_ok = 0; @@ -26,7 +29,7 @@ void mark_bad(IPPTsPng *ipptp) ipptp->hardening.testing_requests = 0; } -void mark_possible_bad(IPPTsPng *ipptp) +static void mark_possible_bad(IPPTsPng *ipptp) { ipptp->timestamp = unix_time(); ipptp->hardening.routes_requests_ok = 0; @@ -34,7 +37,7 @@ void mark_possible_bad(IPPTsPng *ipptp) ipptp->hardening.testing_requests = 0; } -void mark_good(IPPTsPng *ipptp) +static void mark_good(IPPTsPng *ipptp) { ipptp->timestamp = unix_time(); ipptp->hardening.routes_requests_ok = (HARDENING_ALL_OK >> 0) & 1; @@ -42,7 +45,7 @@ void mark_good(IPPTsPng *ipptp) ipptp->hardening.testing_requests = (HARDENING_ALL_OK >> 2) & 1; } -void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) +static void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) { uint32_t i; @@ -57,7 +60,7 @@ void mark_all_good(Client_data *list, uint32_t length, uint8_t ipv6) /* Returns 1 if public_key has a furthest distance to comp_client_id than all public_key's in the list */ -uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key) +static uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t length, const uint8_t *public_key) { uint32_t i; @@ -70,7 +73,7 @@ uint8_t is_furthest(const uint8_t *comp_client_id, Client_data *list, uint32_t l return 1; } -int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) +static int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key) { int i; @@ -83,10 +86,10 @@ int client_in_list(Client_data *list, uint32_t length, const uint8_t *public_key return -1; } -void test_addto_lists_update(DHT *dht, - Client_data *list, - uint32_t length, - IP_Port *ip_port) +static void test_addto_lists_update(DHT *dht, + Client_data *list, + uint32_t length, + IP_Port *ip_port) { int used, test, test1, test2, found; IP_Port test_ipp; @@ -157,10 +160,10 @@ void test_addto_lists_update(DHT *dht, "Client IP_Port is incorrect"); } -void test_addto_lists_bad(DHT *dht, - Client_data *list, - uint32_t length, - IP_Port *ip_port) +static void test_addto_lists_bad(DHT *dht, + Client_data *list, + uint32_t length, + IP_Port *ip_port) { // check "bad" clients replacement int used, test1, test2, test3; @@ -200,11 +203,11 @@ void test_addto_lists_bad(DHT *dht, ck_assert_msg(client_in_list(list, length, test_id3) >= 0, "Wrong bad client removed"); } -void test_addto_lists_possible_bad(DHT *dht, - Client_data *list, - uint32_t length, - IP_Port *ip_port, - const uint8_t *comp_client_id) +static void test_addto_lists_possible_bad(DHT *dht, + Client_data *list, + uint32_t length, + IP_Port *ip_port, + const uint8_t *comp_client_id) { // check "possibly bad" clients replacement int used, test1, test2, test3; @@ -265,11 +268,11 @@ void test_addto_lists_possible_bad(DHT *dht, } } -void test_addto_lists_good(DHT *dht, - Client_data *list, - uint32_t length, - IP_Port *ip_port, - const uint8_t *comp_client_id) +static void test_addto_lists_good(DHT *dht, + Client_data *list, + uint32_t length, + IP_Port *ip_port, + const uint8_t *comp_client_id) { uint8_t public_key[crypto_box_PUBLICKEYBYTES]; uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0; @@ -295,8 +298,6 @@ void test_addto_lists_good(DHT *dht, ck_assert_msg(client_in_list(list, length, public_key) == -1, "Good client id is in the list"); } -// These tests currently fail. -#if 0 static void test_addto_lists(IP ip) { Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT); @@ -382,7 +383,7 @@ END_TEST #define DHT_LIST_LENGTH 128 -void print_pk(uint8_t *public_key) +static void print_pk(uint8_t *public_key) { uint32_t j; @@ -393,8 +394,9 @@ void print_pk(uint8_t *public_key) printf("\n"); } -void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigned int length, const uint8_t *pk, - const uint8_t *cmp_pk) +static void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], + unsigned int length, const uint8_t *pk, + const uint8_t *cmp_pk) { uint8_t p_b[crypto_box_PUBLICKEYBYTES]; unsigned int i; @@ -423,7 +425,7 @@ void test_add_to_list(uint8_t cmp_list[][crypto_box_PUBLICKEYBYTES + 1], unsigne #define NUM_DHT 100 -void test_list_main() +static void test_list_main(void) { DHT *dhts[NUM_DHT]; @@ -555,7 +557,7 @@ START_TEST(test_list) } END_TEST -void ip_callback(void *data, int32_t number, IP_Port ip_port) +static void ip_callback(void *data, int32_t number, IP_Port ip_port) { } @@ -646,7 +648,7 @@ START_TEST(test_DHT_test) } END_TEST -Suite *dht_suite(void) +static Suite *dht_suite(void) { Suite *s = suite_create("DHT"); diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 02a2901663..f1e768d6cc 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -19,16 +19,16 @@ #include "../toxencryptsave/crypto_pwhash_scryptsalsa208sha256/crypto_pwhash_scryptsalsa208sha256.h" #endif -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}; -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}; -const char *pw = "hunter2"; -unsigned int pwlen = 7; +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}; +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}; +static const char *pw = "hunter2"; +static unsigned int pwlen = 7; -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}; +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}; // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat /* cause I'm shameless */ -void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -63,7 +63,7 @@ START_TEST(test_save_friend) tox_callback_friend_request(tox2, accept_friend_request); uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox2, address); - uint32_t test = tox_friend_add(tox1, address, (uint8_t *)"Gentoo", 7, 0); + uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)"Gentoo", 7, 0); ck_assert_msg(test != UINT32_MAX, "Failed to add friend"); size_t size = tox_get_savedata_size(tox1); @@ -186,7 +186,7 @@ START_TEST(test_keys) } END_TEST -Suite *encryptsave_suite(void) +static Suite *encryptsave_suite(void) { Suite *s = suite_create("encryptsave"); @@ -212,4 +212,3 @@ int main(int argc, char *argv[]) return number_failed; } - diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 2407574ed9..f7dc92d5ea 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -26,34 +26,34 @@ #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) -char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; +static const char *friend_id_str = "e4b3d5030bc99494605aecc33ceec8875640c1d74aa32790e821b17e98771c4a00000000f1db"; /* in case we need more than one ID for a test */ -char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; -char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; +static const char *good_id_a_str = "DB9B569D14850ED8364C3744CAC2C8FF78985D213E980C7C508D0E91E8E45441"; +static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc29744785291fa4ef4d64"; -char *bad_id_str = "9B569D14ff637e69f2"; +static const char *bad_id_str = "9B569D14ff637e69f2"; -unsigned char *friend_id = NULL; -unsigned char *good_id_a = NULL; -unsigned char *good_id_b = NULL; -unsigned char *bad_id = NULL; +static unsigned char *friend_id = NULL; +static unsigned char *good_id_a = NULL; +static unsigned char *good_id_b = NULL; +static unsigned char *bad_id = NULL; -int friend_id_num = 0; +static int friend_id_num = 0; -Messenger *m; +static Messenger *m; START_TEST(test_m_sendmesage) { - char *message = "h-hi :3"; + const char *message = "h-hi :3"; int good_len = strlen(message); int bad_len = MAX_CRYPTO_PACKET_SIZE; - ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); - ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); - ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (uint8_t *)message, good_len, 0) == -1); - ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (uint8_t *)message, bad_len, 0) == -2); + ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); + ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); + ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1); + ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (const uint8_t *)message, bad_len, 0) == -2); } END_TEST @@ -77,15 +77,15 @@ END_TEST START_TEST(test_m_set_userstatus) { - char *status = "online!"; + const char *status = "online!"; uint16_t good_length = strlen(status); uint16_t bad_length = REALLY_BIG_NUMBER; - ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, bad_length) == -1), + ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, bad_length) == -1), "m_set_userstatus did NOT catch the following length: %d\n", REALLY_BIG_NUMBER); - ck_assert_msg((m_set_statusmessage(m, (uint8_t *)status, good_length) == 0), + ck_assert_msg((m_set_statusmessage(m, (const uint8_t *)status, good_length) == 0), "m_set_userstatus did NOT return 0 on the following length: %d\n" "MAX_STATUSMESSAGE_LENGTH: %d\n", good_length, MAX_STATUSMESSAGE_LENGTH); } @@ -156,25 +156,25 @@ END_TEST */ START_TEST(test_setname) { - char *good_name = "consensualCorn"; + const char *good_name = "consensualCorn"; int good_length = strlen(good_name); int bad_length = REALLY_BIG_NUMBER; - ck_assert_msg((setname(m, (uint8_t *)good_name, bad_length) == -1), + ck_assert_msg((setname(m, (const uint8_t *)good_name, bad_length) == -1), "setname() did NOT error on %d as a length argument!\n", bad_length); - ck_assert_msg((setname(m, (uint8_t *)good_name, good_length) == 0), + ck_assert_msg((setname(m, (const uint8_t *)good_name, good_length) == 0), "setname() did NOT return 0 on good arguments!\n"); } END_TEST START_TEST(test_getself_name) { - char *nickname = "testGallop"; + const char *nickname = "testGallop"; int len = strlen(nickname); char nick_check[len]; - setname(m, (uint8_t *)nickname, len); + setname(m, (const uint8_t *)nickname, len); getself_name(m, (uint8_t *)nick_check); ck_assert_msg((memcmp(nickname, nick_check, len) == 0), @@ -300,7 +300,7 @@ START_TEST(test_messenger_state_saveloadsave) } END_TEST -Suite *messenger_suite(void) +static Suite *messenger_suite(void) { Suite *s = suite_create("Messenger"); diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index b5d8b33e1c..783f3f7b7a 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -134,7 +134,7 @@ START_TEST(test_ip_equal) } END_TEST -Suite *network_suite(void) +static Suite *network_suite(void) { Suite *s = suite_create("Network"); @@ -144,7 +144,7 @@ Suite *network_suite(void) return s; } -int main() +int main(void) { srand((unsigned int) time(NULL)); diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 58fde2d606..dd5a19460d 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -23,7 +23,7 @@ #define c_sleep(x) usleep(1000*x) #endif -void do_onion(Onion *onion) +static void do_onion(Onion *onion) { networking_poll(onion->net, NULL); do_DHT(onion->dht); @@ -38,7 +38,7 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui return 1; } - if (send_onion_response(onion->net, source, (uint8_t *)"install gentoo", sizeof("install gentoo"), + if (send_onion_response(onion->net, source, (const uint8_t *)"install gentoo", sizeof("install gentoo"), packet + sizeof("Install Gentoo")) == -1) { return 1; } @@ -54,14 +54,14 @@ static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, ui return 1; } - if (memcmp(packet, (uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { + if (memcmp(packet, (const uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) { return 1; } handled_test_2 = 1; return 0; } -/* +#if 0 void print_client_id(uint8_t *client_id, uint32_t length) { uint32_t j; @@ -69,13 +69,14 @@ void print_client_id(uint8_t *client_id, uint32_t length) for (j = 0; j < length; j++) { printf("%02hhX", client_id[j]); } + printf("\n"); } -*/ -uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; +#endif +static uint8_t sb_data[ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; static int handled_test_3; -uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; -uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; +static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES]; +static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) { Onion *onion = object; @@ -106,7 +107,7 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui return 0; } -uint8_t nonce[crypto_box_NONCEBYTES]; +static uint8_t nonce[crypto_box_NONCEBYTES]; static int handled_test_4; static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) { @@ -165,7 +166,7 @@ START_TEST(test_basic) nodes[3] = n2; Onion_Path path; create_onion_path(onion1->dht, &path, nodes); - int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (uint8_t *)"Install Gentoo", + int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); ck_assert_msg(ret == 0, "Failed to create/send onion packet."); @@ -227,7 +228,7 @@ START_TEST(test_basic) new_nonce(nonce); ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, onion1->dht->self_public_key, - nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); + nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo")); ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); handled_test_4 = 0; @@ -278,7 +279,7 @@ typedef struct { Onion_Client *onion_c; } Onions; -Onions *new_onions(uint16_t port) +static Onions *new_onions(uint16_t port) { IP ip; ip_init(&ip, 1); @@ -297,14 +298,14 @@ Onions *new_onions(uint16_t port) return NULL; } -void do_onions(Onions *on) +static void do_onions(Onions *on) { networking_poll(on->onion->net, NULL); do_DHT(on->onion->dht); do_onion_client(on->onion_c); } -void kill_onions(Onions *on) +static void kill_onions(Onions *on) { Networking_Core *net = on->onion->dht->net; DHT *dht = on->onion->dht; @@ -322,8 +323,8 @@ void kill_onions(Onions *on) #define NUM_FIRST 7 #define NUM_LAST 37 -_Bool first_ip, last_ip; -void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) +static _Bool first_ip, last_ip; +static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) { if (NUM_FIRST == number) { first_ip = 1; @@ -338,9 +339,9 @@ void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) ck_abort_msg("Error."); } -_Bool first, last; -uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; -uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; +static _Bool first, last; +static uint8_t first_dht_pk[crypto_box_PUBLICKEYBYTES]; +static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES]; static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) { @@ -460,7 +461,7 @@ START_TEST(test_announce) } END_TEST -Suite *onion_suite(void) +static Suite *onion_suite(void) { Suite *s = suite_create("Onion"); diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c index 8d3ec3bb00..b895092142 100644 --- a/auto_tests/skeleton_test.c +++ b/auto_tests/skeleton_test.c @@ -22,7 +22,7 @@ START_TEST(test_creativetestnamegoeshere) } END_TEST -Suite *creativesuitenamegoeshere_suite(void) +static Suite *creativesuitenamegoeshere_suite(void) { Suite *s = suite_create("creativesuitedescritptiongoeshere"); @@ -46,4 +46,3 @@ int main(int argc, char *argv[]) return number_failed; } - diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index bc6006e388..7efb546588 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -42,7 +42,7 @@ #define TOX_LOCALHOST "127.0.0.1" #endif -void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -52,10 +52,10 @@ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *dat tox_friend_add_norequest(m, public_key, 0); } } -uint32_t messages_received; +static uint32_t messages_received; -void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, - void *userdata) +static void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, + void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -73,9 +73,9 @@ void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const u } } -uint32_t name_changes; +static uint32_t name_changes; -void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) +static void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -86,8 +86,9 @@ void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size } } -uint32_t status_m_changes; -void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, void *user_data) +static uint32_t status_m_changes; +static void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, + void *user_data) { if (*((uint32_t *)user_data) != 974536) { return; @@ -98,9 +99,9 @@ void print_status_m_change(Tox *tox, uint32_t friend_number, const uint8_t *mess } } -uint32_t typing_changes; +static uint32_t typing_changes; -void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata) +static void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -113,9 +114,9 @@ void print_typingchange(Tox *m, uint32_t friendnumber, bool typing, void *userda } } -uint32_t custom_packet; +static uint32_t custom_packet; -void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size_t len, void *object) +static void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size_t len, void *object) { uint8_t number = *((uint32_t *)object); @@ -135,15 +136,14 @@ void handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data, size return; } -uint64_t size_recv; -uint64_t sending_pos; +static uint64_t size_recv; +static uint64_t sending_pos; -uint8_t file_cmp_id[TOX_FILE_ID_LENGTH]; -uint8_t filenum; -uint32_t file_accepted; -uint64_t file_size; -void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize, - const uint8_t *filename, size_t filename_length, void *userdata) +static uint8_t file_cmp_id[TOX_FILE_ID_LENGTH]; +static uint32_t file_accepted; +static uint64_t file_size; +static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t kind, uint64_t filesize, + const uint8_t *filename, size_t filename_length, void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -208,9 +208,9 @@ void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_number, ui ck_assert_msg(err_s == TOX_ERR_FILE_SEEK_DENIED, "tox_file_seek wrong error"); } -uint32_t sendf_ok; -void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, - void *userdata) +static uint32_t sendf_ok; +static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, + void *userdata) { if (*((uint32_t *)userdata) != 974536) { return; @@ -222,12 +222,13 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, } } -uint64_t max_sending; -_Bool m_send_reached; -uint8_t sending_num; -_Bool file_sending_done; -void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, - void *user_data) +static uint64_t max_sending; +static _Bool m_send_reached; +static uint8_t sending_num; +static _Bool file_sending_done; +static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, + size_t length, + void *user_data) { if (*((uint32_t *)user_data) != 974536) { return; @@ -277,10 +278,10 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb } -uint8_t num; -_Bool file_recv; -void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, - size_t length, void *user_data) +static uint8_t num; +static _Bool file_recv; +static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, + size_t length, void *user_data) { if (*((uint32_t *)user_data) != 974536) { return; @@ -307,8 +308,8 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p } } -unsigned int connected_t1; -void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) +static unsigned int connected_t1; +static void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, void *user_data) { if (*((uint32_t *)user_data) != 974536) { return; @@ -347,7 +348,7 @@ START_TEST(test_one) uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox1, address); TOX_ERR_FRIEND_ADD error; - uint32_t ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error); + uint32_t ret = tox_friend_add(tox1, address, (const uint8_t *)"m", 1, &error); ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_OWN_KEY, "Adding own address worked."); tox_self_get_address(tox2, address); @@ -361,7 +362,7 @@ START_TEST(test_one) "TOX_MAX_FRIEND_REQUEST_LENGTH is too big."); address[0]++; - ret = tox_friend_add(tox1, address, (uint8_t *)"m", 1, &error); + ret = tox_friend_add(tox1, address, (const uint8_t *)"m", 1, &error); ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_BAD_CHECKSUM, "Adding address with bad checksum worked."); @@ -465,7 +466,7 @@ START_TEST(test_few_clients) tox_callback_friend_request(tox2, accept_friend_request); uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox2, address); - uint32_t test = tox_friend_add(tox3, address, (uint8_t *)"Gentoo", 7, 0); + uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, 0); ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); uint8_t off = 1; @@ -560,7 +561,7 @@ START_TEST(test_few_clients) printf("tox clients connected took %llu seconds\n", time(NULL) - con_time); tox_callback_friend_name(tox3, print_nickchange); TOX_ERR_SET_INFO err_n; - bool succ = tox_self_set_name(tox2, (uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); + bool succ = tox_self_set_name(tox2, (const uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n); ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %u\n", err_n); while (1) { @@ -582,7 +583,7 @@ START_TEST(test_few_clients) ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct"); tox_callback_friend_status_message(tox3, print_status_m_change); - succ = tox_self_set_status_message(tox2, (uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n); + succ = tox_self_set_status_message(tox2, (const uint8_t *)"Installing Gentoo", sizeof("Installing Gentoo"), &err_n); ck_assert_msg(succ && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n); while (1) { @@ -704,7 +705,7 @@ START_TEST(test_few_clients) tox_callback_file_recv_control(tox3, file_print_control, &to_compare); tox_callback_file_recv(tox3, tox_file_receive, &to_compare); uint64_t totalf_size = 100 * 1024 * 1024; - uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", + uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); @@ -751,7 +752,8 @@ START_TEST(test_few_clients) tox_callback_file_recv_control(tox3, file_print_control, &to_compare); tox_callback_file_recv(tox3, tox_file_receive, &to_compare); totalf_size = UINT64_MAX; - fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); + fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), + 0); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); 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) tox_callback_file_recv_control(tox3, file_print_control, &to_compare); tox_callback_file_recv(tox3, tox_file_receive, &to_compare); totalf_size = 0; - fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), 0); + fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), + 0); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); 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 @@ START_TEST(test_many_clients) tox_self_get_address(toxes[pairs[i].tox1], address); TOX_ERR_FRIEND_ADD test; - uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); + uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { goto loop_top; @@ -996,7 +999,7 @@ START_TEST(test_many_clients_tcp) tox_self_get_address(toxes[pairs[i].tox1], address); TOX_ERR_FRIEND_ADD test; - uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); + uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { goto loop_top; @@ -1095,7 +1098,7 @@ START_TEST(test_many_clients_tcp_b) tox_self_get_address(toxes[pairs[i].tox1], address); TOX_ERR_FRIEND_ADD test; - uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7, &test); + uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { goto loop_top; @@ -1137,7 +1140,8 @@ END_TEST #define NUM_GROUP_TOX 32 -void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, + void *userdata) { if (*((uint32_t *)userdata) != 234212) { return; @@ -1151,8 +1155,9 @@ void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *d static Tox *invite_tox; static unsigned int invite_counter; -void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, - void *userdata) +static void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, + uint16_t length, + void *userdata) { if (*((uint32_t *)userdata) != 234212) { return; @@ -1178,8 +1183,8 @@ void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, c static unsigned int num_recv; -void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, - void *userdata) +static void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, + void *userdata) { if (*((uint32_t *)userdata) != 234212) { return; @@ -1217,7 +1222,7 @@ START_TEST(test_many_group) tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address); for (i = 0; i < NUM_GROUP_TOX; ++i) { - ck_assert_msg(tox_friend_add(toxes[i], address, (uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend"); + ck_assert_msg(tox_friend_add(toxes[i], address, (const uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend"); tox_self_get_address(toxes[i], address); } @@ -1310,7 +1315,7 @@ START_TEST(test_many_group) tox_callback_group_message(toxes[i], &print_group_message, &to_comp); } - ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, (uint8_t *)"Install Gentoo", + ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1) == 0, "Failed to send group message."); num_recv = 0; @@ -1358,7 +1363,7 @@ uint8_t timeout_mux = 20; uint8_t timeout_mux = 10; #endif -Suite *tox_suite(void) +static Suite *tox_suite(void) { Suite *s = suite_create("Tox"); @@ -1398,4 +1403,3 @@ int main(int argc, char *argv[]) return number_failed; } - diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index e3c4447e3d..399eac6865 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -6,7 +6,7 @@ # include # define ck_assert(X) assert(X); -# define START_TEST(NAME) void NAME () +# define START_TEST(NAME) static void NAME (void) # define END_TEST #else # include "helpers.h" @@ -66,7 +66,7 @@ typedef struct { /** * Callbacks */ -void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) +static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) { (void) av; (void) friend_number; @@ -76,7 +76,7 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool printf("Handling CALL callback\n"); ((CallControl *)user_data)->incoming = true; } -void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) +static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) { (void) av; (void) friend_number; @@ -84,11 +84,11 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo printf("Handling CALL STATE callback: %d\n", state); ((CallControl *)user_data)->state = state; } -void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, - uint16_t width, uint16_t height, - uint8_t const *y, uint8_t const *u, uint8_t const *v, - int32_t ystride, int32_t ustride, int32_t vstride, - void *user_data) +static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + uint8_t const *y, uint8_t const *u, uint8_t const *v, + int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data) { (void) av; (void) friend_number; @@ -103,12 +103,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, (void) user_data; printf("Received video payload\n"); } -void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, - int16_t const *pcm, - size_t sample_count, - uint8_t channels, - uint32_t sampling_rate, - void *user_data) +static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, + int16_t const *pcm, + size_t sample_count, + uint8_t channels, + uint32_t sampling_rate, + void *user_data) { (void) av; (void) friend_number; @@ -119,7 +119,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, (void) user_data; printf("Received audio payload\n"); } -void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, + void *userdata) { (void) userdata; @@ -132,7 +133,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t /** * Iterate helper */ -int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) +static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob) { c_sleep(100); tox_iterate(bootstrap, NULL); @@ -175,7 +176,7 @@ START_TEST(test_AV_flows) tox_self_get_address(Alice, address); - ck_assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); uint8_t off = 1; @@ -601,7 +602,7 @@ int main(int argc, char *argv[]) return 0; } #else -Suite *tox_suite(void) +static Suite *tox_suite(void) { Suite *s = suite_create("ToxAV"); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 5d8890321b..e3dd5a4215 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -6,7 +6,7 @@ # include # define ck_assert(X) assert(X); -# define START_TEST(NAME) void NAME () +# define START_TEST(NAME) static void NAME (void) # define END_TEST #else # include "helpers.h" @@ -52,7 +52,7 @@ typedef struct { /** * Callbacks */ -void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) +static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) { (void) av; (void) audio_enabled; @@ -61,16 +61,16 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool printf("Handling CALL callback\n"); ((CallControl *)user_data)[friend_number].incoming = true; } -void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) +static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) { printf("Handling CALL STATE callback: %d %p\n", state, (void *)av); ((CallControl *)user_data)[friend_number].state = state; } -void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, - uint16_t width, uint16_t height, - uint8_t const *y, uint8_t const *u, uint8_t const *v, - int32_t ystride, int32_t ustride, int32_t vstride, - void *user_data) +static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + uint8_t const *y, uint8_t const *u, uint8_t const *v, + int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data) { (void) av; (void) friend_number; @@ -84,12 +84,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, (void) vstride; (void) user_data; } -void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, - int16_t const *pcm, - size_t sample_count, - uint8_t channels, - uint32_t sampling_rate, - void *user_data) +static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, + int16_t const *pcm, + size_t sample_count, + uint8_t channels, + uint32_t sampling_rate, + void *user_data) { (void) av; (void) friend_number; @@ -99,7 +99,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, (void) sampling_rate; (void) user_data; } -void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, + void *userdata) { (void) userdata; @@ -112,7 +113,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t /** * Iterate helper */ -ToxAV *setup_av_instance(Tox *tox, CallControl *CC) +static ToxAV *setup_av_instance(Tox *tox, CallControl *CC) { TOXAV_ERR_NEW error; @@ -126,7 +127,7 @@ ToxAV *setup_av_instance(Tox *tox, CallControl *CC) return av; } -void *call_thread(void *pd) +static void *call_thread(void *pd) { ToxAV *AliceAV = ((thread_data *) pd)->AliceAV; ToxAV *BobAV = ((thread_data *) pd)->BobAV; @@ -241,9 +242,9 @@ START_TEST(test_AV_three_calls) tox_self_get_address(Alice, address); - ck_assert(tox_friend_add(Bobs[0], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); - ck_assert(tox_friend_add(Bobs[1], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); - ck_assert(tox_friend_add(Bobs[2], address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); uint8_t off = 1; @@ -351,7 +352,7 @@ int main(int argc, char *argv[]) return 0; } #else -Suite *tox_suite(void) +static Suite *tox_suite(void) { Suite *s = suite_create("ToxAV"); diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 8ea4c16152..2dc24b4eb5 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -58,7 +58,7 @@ #define PORT 33445 -void manage_keys(DHT *dht) +static void manage_keys(DHT *dht) { enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; uint8_t keys[KEYS_SIZE]; diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index ecfef1ad27..262dd4c821 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c @@ -35,7 +35,7 @@ /** * Prints --help message */ -void print_help() +static void print_help(void) { // 2 space ident // make sure all lines fit into 80 columns diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index dc0a251c83..a0c6045d32 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -41,7 +41,7 @@ * * Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports`. */ -void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) +static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) { const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; @@ -303,7 +303,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k * @return binary on success, * NULL on failure. */ -uint8_t *hex_string_to_bin(char *hex_string) +static uint8_t *hex_string_to_bin(const char *hex_string) { if (strlen(hex_string) % 2 != 0) { return NULL; @@ -312,7 +312,7 @@ uint8_t *hex_string_to_bin(char *hex_string) size_t len = strlen(hex_string) / 2; uint8_t *ret = malloc(len); - char *pos = hex_string; + const char *pos = hex_string; size_t i; for (i = 0; i < len; ++i, pos += 2) { @@ -403,7 +403,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } - uint8_t *bs_public_key_bin = hex_string_to_bin((char *)bs_public_key); + uint8_t *bs_public_key_bin = hex_string_to_bin((const char *)bs_public_key); const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), bs_public_key_bin); free(bs_public_key_bin); diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index ee3a142103..e0fb3b33d1 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c @@ -48,7 +48,7 @@ bool open_log(LOG_BACKEND backend) return true; } -bool close_log() +bool close_log(void) { if (current_backend == -1) { return false; @@ -63,7 +63,7 @@ bool close_log() return true; } -int level_syslog(LOG_LEVEL level) +static int level_syslog(LOG_LEVEL level) { switch (level) { case LOG_LEVEL_INFO: @@ -79,12 +79,12 @@ int level_syslog(LOG_LEVEL level) return LOG_INFO; } -void log_syslog(LOG_LEVEL level, const char *format, va_list args) +static void log_syslog(LOG_LEVEL level, const char *format, va_list args) { vsyslog(level_syslog(level), format, args); } -FILE *level_stdout(LOG_LEVEL level) +static FILE *level_stdout(LOG_LEVEL level) { switch (level) { case LOG_LEVEL_INFO: @@ -98,7 +98,7 @@ FILE *level_stdout(LOG_LEVEL level) return stdout; } -void log_stdout(LOG_LEVEL level, const char *format, va_list args) +static void log_stdout(LOG_LEVEL level, const char *format, va_list args) { vfprintf(level_stdout(level), format, args); fflush(level_stdout(level)); diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h index 61cb2ee3b1..cb374968a6 100644 --- a/other/bootstrap_daemon/src/log.h +++ b/other/bootstrap_daemon/src/log.h @@ -49,7 +49,7 @@ bool open_log(LOG_BACKEND backend); * Releases all used resources by the logger. * @return true on success, flase if log is already closed. */ -bool close_log(); +bool close_log(void); /** * Writes a message to the log. diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 06ea45aa7f..fe360b4e9c 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -53,7 +53,7 @@ // returns 1 on success // 0 on failure - no keys were read or stored -int manage_keys(DHT *dht, char *keys_file_path) +static int manage_keys(DHT *dht, char *keys_file_path) { enum { KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES }; uint8_t keys[KEYS_SIZE]; @@ -98,7 +98,7 @@ int manage_keys(DHT *dht, char *keys_file_path) // Prints public key -void print_public_key(const uint8_t *public_key) +static void print_public_key(const uint8_t *public_key) { char buffer[2 * crypto_box_PUBLICKEYBYTES + 1]; int index = 0; @@ -115,7 +115,7 @@ void print_public_key(const uint8_t *public_key) // Demonizes the process, appending PID to the PID file and closing file descriptors based on log backend // Terminates the application if the daemonization fails. -void daemonize(LOG_BACKEND log_backend, char *pid_file_path) +static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) { // Check if the PID file exists FILE *pid_file; diff --git a/testing/DHT_test.c b/testing/DHT_test.c index f6a2c4bc1b..04340b0e76 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -54,7 +54,7 @@ uint8_t zeroes_cid[crypto_box_PUBLICKEYBYTES]; -void print_client_id(uint8_t *public_key) +static void print_client_id(uint8_t *public_key) { uint32_t j; @@ -63,7 +63,7 @@ void print_client_id(uint8_t *public_key) } } -void print_hardening(Hardening *h) +static void print_hardening(Hardening *h) { printf("Hardening:\n"); printf("routes_requests_ok: %hhu\n", h->routes_requests_ok); @@ -81,7 +81,7 @@ void print_hardening(Hardening *h) printf("\n\n"); } -void print_assoc(IPPTsPng *assoc, uint8_t ours) +static void print_assoc(IPPTsPng *assoc, uint8_t ours) { IP_Port *ipp = &assoc->ip_port; printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip), ntohs(ipp->port)); @@ -100,7 +100,7 @@ void print_assoc(IPPTsPng *assoc, uint8_t ours) print_hardening(&assoc->hardening); } -void print_clientlist(DHT *dht) +static void print_clientlist(DHT *dht) { uint32_t i; printf("___________________CLOSE________________________________\n"); @@ -120,7 +120,7 @@ void print_clientlist(DHT *dht) } } -void print_friendlist(DHT *dht) +static void print_friendlist(DHT *dht) { uint32_t i, k; IP_Port p_ip; @@ -153,7 +153,8 @@ void print_friendlist(DHT *dht) } } -void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) +#if 0 /* slvrTODO: */ +static void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) { uint32_t i; printf("UNHANDLED PACKET RECEIVED\nLENGTH:%u\nCONTENTS:\n", length); @@ -169,6 +170,7 @@ void printpacket(uint8_t *data, uint32_t length, IP_Port ip_port) printf("\n--------------------END-----------------------------\n\n\n"); } +#endif int main(int argc, char *argv[]) { @@ -230,26 +232,27 @@ int main(int argc, char *argv[]) return 1; } - /* - IP_Port ip_port; - uint8_t data[MAX_UDP_PACKET_SIZE]; - uint32_t length; - */ +#if 0 /* slvrTODO: */ + IP_Port ip_port; + uint8_t data[MAX_UDP_PACKET_SIZE]; + uint32_t length; +#endif while (1) { - do_DHT(dht); - /* slvrTODO: - while(receivepacket(&ip_port, data, &length) != -1) { - if(DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { - //unhandled packet - printpacket(data, length, ip_port); - } else { - printf("Received handled packet with length: %u\n", length); - } - } - */ +#if 0 /* slvrTODO: */ + + while (receivepacket(&ip_port, data, &length) != -1) { + if (DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { + //unhandled packet + printpacket(data, length, ip_port); + } else { + printf("Received handled packet with length: %u\n", length); + } + } + +#endif networking_poll(dht->net, NULL); print_clientlist(dht); diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 668f046acf..8450862142 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -56,18 +56,18 @@ #endif -void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, - void *userdata) +static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type, const uint8_t *string, size_t length, + void *userdata) { printf("Message with length %lu received from %u: %s \n", length, friendnumber, string); - m_send_message_generic(m, friendnumber, type, (uint8_t *)"Test1", 6, 0); + m_send_message_generic(m, friendnumber, type, (const uint8_t *)"Test1", 6, 0); } /* FIXME needed as print_request has to match the interface expected by * networking_requesthandler and so cannot take a Messenger * */ static Messenger *m; -void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void print_request(Messenger *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { printf("Friend request received from: \n"); printf("ClientID: "); @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) printf("%hhX", address[i]); } - setname(m, (uint8_t *)"Anon", 5); + setname(m, (const uint8_t *)"Anon", 5); char temp_hex_id[128]; printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) } uint8_t *bin_id = hex_string_to_bin(temp_hex_id); - int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); + int num = m_addfriend(m, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); free(bin_id); perror("Initialization"); @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) getname(m, num, name); printf("%s\n", name); - m_send_message_generic(m, num, MESSAGE_NORMAL, (uint8_t *)"Test", 5, 0); + m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, 0); do_messenger(m, NULL); c_sleep(30); FILE *file = fopen("Save.bak", "wb"); diff --git a/testing/av_test.c b/testing/av_test.c index 35eb3f6082..5dc2643c7b 100644 --- a/testing/av_test.c +++ b/testing/av_test.c @@ -84,15 +84,15 @@ struct toxav_thread_data { int32_t sig; }; -const char *vdout = "AV Test"; /* Video output */ -PaStream *adout = NULL; /* Audio output */ +static const char *vdout = "AV Test"; /* Video output */ +static PaStream *adout = NULL; /* Audio output */ typedef struct { uint16_t size; int16_t data[]; } frame; -void *pa_write_thread (void *d) +static void *pa_write_thread (void *d) { /* The purpose of this thread is to make sure Pa_WriteStream will not block * toxav_iterate thread @@ -119,21 +119,21 @@ void *pa_write_thread (void *d) /** * Callbacks */ -void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) +static void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data) { printf("Handling CALL callback\n"); ((CallControl *)user_data)->incoming = true; } -void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) +static void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data) { printf("Handling CALL STATE callback: %d\n", state); ((CallControl *)user_data)->state = state; } -void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, - uint16_t width, uint16_t height, - uint8_t const *y, uint8_t const *u, uint8_t const *v, - int32_t ystride, int32_t ustride, int32_t vstride, - void *user_data) +static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + uint8_t const *y, uint8_t const *u, uint8_t const *v, + int32_t ystride, int32_t ustride, int32_t vstride, + void *user_data) { ystride = abs(ystride); ustride = abs(ustride); @@ -166,12 +166,12 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, cvShowImage(vdout, img); free(img_data); } -void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, - int16_t const *pcm, - size_t sample_count, - uint8_t channels, - uint32_t sampling_rate, - void *user_data) +static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, + int16_t const *pcm, + size_t sample_count, + uint8_t channels, + uint32_t sampling_rate, + void *user_data) { CallControl *cc = user_data; frame *f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels); @@ -182,13 +182,14 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number, free(rb_write(cc->arb, f)); pthread_mutex_unlock(cc->arb_mutex); } -void t_toxav_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, - uint32_t audio_bit_rate, uint32_t video_bit_rate, - void *user_data) +static void t_toxav_bit_rate_status_cb(ToxAV *av, uint32_t friend_number, + uint32_t audio_bit_rate, uint32_t video_bit_rate, + void *user_data) { printf ("Suggested bit rates: audio: %d video: %d\n", audio_bit_rate, video_bit_rate); } -void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, + void *userdata) { if (length == 7 && memcmp("gentoo", data, 7) == 0) { assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); @@ -197,7 +198,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t /** */ -void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxAV **BobAV, CallControl *BobCC) +static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxAV **BobAV, CallControl *BobCC) { Tox *Alice; Tox *Bob; @@ -235,7 +236,7 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA tox_self_get_address(Alice, address); - assert(tox_friend_add(Bob, address, (uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); + assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0); uint8_t off = 1; @@ -286,7 +287,7 @@ void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxA printf("Created 2 instances of ToxAV\n"); printf("All set after %llu seconds!\n", time(NULL) - cur_time); } -int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) +static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) { tox_iterate(bootstrap, userdata); tox_iterate(toxav_get_tox(AliceAV), userdata); @@ -294,7 +295,7 @@ int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata) return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); } -void *iterate_toxav (void *data) +static void *iterate_toxav (void *data) { struct toxav_thread_data *data_cast = data; #if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 @@ -330,7 +331,7 @@ void *iterate_toxav (void *data) pthread_exit(NULL); } -int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) +static int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) { int32_t strides[3] = { 1280, 640, 640 }; uint8_t *planes[3] = { @@ -368,7 +369,7 @@ int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img) free(planes[2]); return rc; } -int print_audio_devices() +static int print_audio_devices(void) { int i = 0; @@ -382,7 +383,7 @@ int print_audio_devices() return 0; } -int print_help (const char *name) +static int print_help (const char *name) { printf("Usage: %s -[a:v:o:dh]\n" "-a audio input file\n" diff --git a/testing/dns3_test.c b/testing/dns3_test.c index 830ecfd8e7..3151dd9959 100644 --- a/testing/dns3_test.c +++ b/testing/dns3_test.c @@ -14,7 +14,7 @@ #endif -uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id) +static uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id) { memset(packet, 0, str_len + 13 + 16); packet[0] = id; diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c index 558b3631f7..874c31f52f 100644 --- a/testing/irc_syncbot.c +++ b/testing/irc_syncbot.c @@ -27,12 +27,12 @@ #define IRC_CHANNEL "#tox-real-ontopic" //IRC server ip and port. -uint8_t ip[4] = {127, 0, 0, 1}; -uint16_t port = 6667; +static uint8_t ip[4] = {127, 0, 0, 1}; +static uint16_t port = 6667; #define SILENT_TIMEOUT 20 -int sock; +static int sock; #define SERVER_CONNECT "NICK "IRC_NAME"\nUSER "IRC_NAME" 8 * :"IRC_NAME"\n" #define CHANNEL_JOIN "JOIN "IRC_CHANNEL"\n" @@ -40,12 +40,12 @@ int sock; /* In toxcore/network.c */ uint64_t current_time_monotonic(void); -uint64_t get_monotime_sec(void) +static uint64_t get_monotime_sec(void) { return current_time_monotonic() / 1000; } -int reconnect(void) +static int reconnect(void) { int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); @@ -81,7 +81,7 @@ int reconnect(void) #include "../toxcore/tox.h" #include "misc_tools.c" -int current_group = -1; +static int current_group = -1; static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) { @@ -90,8 +90,9 @@ static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t } } -void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, - void *userdata) +static void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE type, const uint8_t *message, + size_t length, + void *userdata) { if (length == 1 && *message == 'c') { if (tox_del_groupchat(tox, current_group) == 0) { @@ -156,7 +157,7 @@ static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, } } -void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) +static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) { if (len > 1350 || len == 0 || len == 1) { return; @@ -218,7 +219,7 @@ void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len) tox_group_message_send(tox, current_group, message, length); } -Tox *init_tox(int argc, char *argv[]) +static Tox *init_tox(int argc, char *argv[]) { uint8_t ipv6enabled = 1; /* x */ int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); @@ -239,7 +240,7 @@ Tox *init_tox(int argc, char *argv[]) exit(1); } - tox_self_set_name(tox, (uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); + tox_self_set_name(tox, (const uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); tox_callback_friend_message(tox, &callback_friend_message); tox_callback_group_invite(tox, &callback_group_invite, 0); tox_callback_group_message(tox, ©_groupmessage, 0); @@ -258,7 +259,7 @@ Tox *init_tox(int argc, char *argv[]) free(binary_string); uint8_t *bin_id = hex_string_to_bin(temp_id); - uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1, 0); + uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo") - 1, 0); free(bin_id); if (num == UINT32_MAX) { diff --git a/testing/misc_tools.c b/testing/misc_tools.c index b667f9912d..8fdc936c5a 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -35,7 +35,7 @@ #endif // TOX_DEBUG // You are responsible for freeing the return value! -uint8_t *hex_string_to_bin(char *hex_string) +uint8_t *hex_string_to_bin(const char *hex_string) { // byte is represented by exactly 2 hex digits, so lenth of binary string // is half of that of the hex one. only hex string with even length @@ -44,7 +44,7 @@ uint8_t *hex_string_to_bin(char *hex_string) // then the last byte just won't be written in 'ret'. size_t i, len = strlen(hex_string) / 2; uint8_t *ret = malloc(len); - char *pos = hex_string; + const char *pos = hex_string; for (i = 0; i < len; ++i, pos += 2) { sscanf(pos, "%2hhx", &ret[i]); diff --git a/testing/nTox.c b/testing/nTox.c index fcfbe004c2..fe62e047f9 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -52,13 +52,16 @@ #define c_sleep(x) usleep(1000*x) #endif -char lines[HISTORY][STRING_LENGTH]; -uint8_t flag[HISTORY]; -char input_line[STRING_LENGTH]; +static void new_lines(char const *line); +static void do_refresh(void); + +static char lines[HISTORY][STRING_LENGTH]; +static uint8_t flag[HISTORY]; +static char input_line[STRING_LENGTH]; /* wrap: continuation mark */ enum { wrap_cont_len = 3 }; -const char wrap_cont_str[] = "\n+ "; +static const char wrap_cont_str[] = "\n+ "; #define STRING_LENGTH_WRAPPED (STRING_LENGTH + 16 * (wrap_cont_len + 1)) @@ -66,7 +69,7 @@ const char wrap_cont_str[] = "\n+ "; /* undocumented: d (tox_do()) */ /* 251+1 characters */ -char *help_main = +static const char *help_main = "[i] Available main commands:\n+ " "/x (to print one's own id)|" "/s status (to change status, e.g. AFK)|" @@ -77,7 +80,7 @@ char *help_main = "/h group (for group related commands)"; /* 190+1 characters */ -char *help_friend1 = +static const char *help_friend1 = "[i] Available friend commands (1/2):\n+ " "/l list (to list friends)|" "/r friend no. (to remove from the friend list)|" @@ -85,14 +88,14 @@ char *help_friend1 = "/a request no. (to accept a friend request)"; /* 187+1 characters */ -char *help_friend2 = +static const char *help_friend2 = "[i] Available friend commands (2/2):\n+ " "/m friend no. message (to send a message)|" "/t friend no. filename (to send a file to a friend)|" "/cf friend no. (to talk to that friend per default)"; /* 253+1 characters */ -char *help_group = +static const char *help_group = "[i] Available group commands:\n+ " "/g (to create a group)|" "/i friend no. group no. (to invite a friend to a group)|" @@ -100,17 +103,17 @@ char *help_group = "/p group no. (to list a group's peers)|" "/cg group no. (to talk to that group per default)"; -int x, y; +static int x, y; -int conversation_default = 0; +static int conversation_default = 0; typedef struct { uint8_t id[TOX_PUBLIC_KEY_SIZE]; uint8_t accepted; } Friend_request; -Friend_request pending_requests[256]; -uint8_t num_requests = 0; +static Friend_request pending_requests[256]; +static uint8_t num_requests = 0; #define NUM_FILE_SENDERS 64 typedef struct { @@ -118,11 +121,12 @@ typedef struct { uint32_t friendnum; uint32_t filenumber; } File_Sender; -File_Sender file_senders[NUM_FILE_SENDERS]; -uint8_t numfilesenders; +static File_Sender file_senders[NUM_FILE_SENDERS]; +static uint8_t numfilesenders; -void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, - void *user_data) +static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, + size_t length, + void *user_data) { unsigned int i; @@ -148,7 +152,7 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb } -uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) +static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) { FILE *tempfile = fopen(filename, "rb"); @@ -206,7 +210,7 @@ static void fraddr_to_str(uint8_t *id_bin, char *id_str) } } -void get_id(Tox *m, char *data) +static void get_id(Tox *m, char *data) { sprintf(data, "[i] ID: "); int offset = strlen(data); @@ -215,7 +219,7 @@ void get_id(Tox *m, char *data) fraddr_to_str(address, data + offset); } -int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) +static int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) { tox_friend_get_name(m, friendnum, (uint8_t *)namebuf, NULL); int res = tox_friend_get_name_size(m, friendnum, NULL); @@ -229,7 +233,7 @@ int getfriendname_terminated(Tox *m, int friendnum, char *namebuf) return res; } -void new_lines_mark(char *line, uint8_t special) +static void new_lines_mark(char const *line, uint8_t special) { int i = 0; @@ -244,15 +248,15 @@ void new_lines_mark(char *line, uint8_t special) do_refresh(); } -void new_lines(char *line) +static void new_lines(char const *line) { new_lines_mark(line, 0); } -const char ptrn_friend[] = "[i] Friend %i: %s\n+ id: %s"; -const int id_str_len = TOX_ADDRESS_SIZE * 2 + 3; -void print_friendlist(Tox *m) +static const char ptrn_friend[] = "[i] Friend %i: %s\n+ id: %s"; +static const int id_str_len = TOX_ADDRESS_SIZE * 2 + 3; +static void print_friendlist(Tox *m) { new_lines("[i] Friend List:"); @@ -328,9 +332,9 @@ static void print_formatted_message(Tox *m, char *message, int friendnum, uint8_ /* forward declarations */ static int save_data(Tox *m); -void print_groupchatpeers(Tox *m, int groupnumber); +static void print_groupchatpeers(Tox *m, int groupnumber); -void line_eval(Tox *m, char *line) +static void line_eval(Tox *m, char *line) { if (line[0] == '/') { char inpt_command = line[1]; @@ -353,7 +357,7 @@ void line_eval(Tox *m, char *line) unsigned char *bin_string = hex_string_to_bin(temp_id); TOX_ERR_FRIEND_ADD error; - uint32_t num = tox_friend_add(m, bin_string, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), &error); + uint32_t num = tox_friend_add(m, bin_string, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), &error); free(bin_string); char numstring[100]; @@ -659,7 +663,7 @@ void line_eval(Tox *m, char *line) /* basic wrap, ignores embedded '\t', '\n' or '|' * inserts continuation markers if there's enough space left, * otherwise turns spaces into newlines if possible */ -void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width) +static void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int line_width) { size_t i, len = strlen(input); @@ -741,7 +745,7 @@ void wrap(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], int lin * marks wrapped lines with "+ " in front, which does expand output * does NOT honor '\t': would require a lot more work (and tab width isn't always 8) */ -void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], size_t line_width) +static void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], size_t line_width) { size_t len = strlen(input); size_t ipos, opos = 0; @@ -840,7 +844,7 @@ void wrap_bars(char output[STRING_LENGTH_WRAPPED], char input[STRING_LENGTH], si output[opos] = 0; } -int count_lines(char *string) +static int count_lines(char *string) { size_t i, len = strlen(string); int count = 1; @@ -854,7 +858,7 @@ int count_lines(char *string) return count; } -char *appender(char *str, const char c) +static char *appender(char *str, const char c) { size_t len = strlen(str); @@ -866,7 +870,7 @@ char *appender(char *str, const char c) return str; } -void do_refresh() +static void do_refresh(void) { int count = 0; char wrap_output[STRING_LENGTH_WRAPPED]; @@ -897,10 +901,10 @@ void do_refresh() refresh(); } -void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) +static void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { new_lines("[i] received friend request with message:"); - new_lines((char *)data); + new_lines((const char *)data); char numchar[100]; sprintf(numchar, "[i] accept request with /a %u", num_requests); new_lines(numchar); @@ -910,8 +914,8 @@ void print_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_ do_refresh(); } -void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, - void *userdata) +static void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, + void *userdata) { /* ensure null termination */ uint8_t null_string[length + 1]; @@ -920,7 +924,7 @@ void print_message(Tox *m, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const u print_formatted_message(m, (char *)null_string, friendnumber, 0); } -void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) +static void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) { char name[TOX_MAX_NAME_LENGTH + 1]; @@ -937,7 +941,7 @@ void print_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size } } -void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) +static void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata) { char name[TOX_MAX_NAME_LENGTH + 1]; @@ -954,9 +958,9 @@ void print_statuschange(Tox *m, uint32_t friendnumber, const uint8_t *string, si } } -static char *data_file_name = NULL; +static const char *data_file_name = NULL; -static Tox *load_data() +static Tox *load_data(void) { FILE *data_file = fopen(data_file_name, "r"); @@ -1024,7 +1028,7 @@ static int save_data(Tox *m) return res; } -static int save_data_file(Tox *m, char *path) +static int save_data_file(Tox *m, const char *path) { data_file_name = path; @@ -1035,7 +1039,7 @@ static int save_data_file(Tox *m, char *path) return 0; } -void print_help(char *prog_name) +static void print_help(char *prog_name) { printf("nTox %.1f - Command-line tox-core client\n", 0.1); printf("Usage: %s [--ipv4|--ipv6] IP PORT KEY [-f keyfile]\n", prog_name); @@ -1046,7 +1050,7 @@ void print_help(char *prog_name) puts(" -f keyfile [Optional] Specify a keyfile to read from and write to."); } -void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) +static void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) { char msg[256]; @@ -1060,7 +1064,7 @@ void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, u new_lines(msg); } -void print_groupchatpeers(Tox *m, int groupnumber) +static void print_groupchatpeers(Tox *m, int groupnumber) { int num = tox_group_number_peers(m, groupnumber); @@ -1109,8 +1113,8 @@ void print_groupchatpeers(Tox *m, int groupnumber) new_lines_mark(msg, 1); } -void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, - void *userdata) +static void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, + void *userdata) { char msg[256 + length]; uint8_t name[TOX_MAX_NAME_LENGTH] = {0}; @@ -1129,7 +1133,7 @@ void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t * new_lines(msg); } -void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) +static void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) { char msg[256]; @@ -1175,8 +1179,9 @@ void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t print_groupchatpeers(m, groupnumber); } } -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, uint64_t file_size, - const uint8_t *filename, size_t filename_length, void *user_data) +static void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, + uint64_t file_size, + const uint8_t *filename, size_t filename_length, void *user_data) { if (type != TOX_FILE_KIND_DATA) { new_lines("Refused invalid file type."); @@ -1196,8 +1201,8 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, } } -void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, - void *user_data) +static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, + void *user_data) { char msg[512] = {0}; sprintf(msg, "[t] control %u received", control); @@ -1219,8 +1224,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, } } -void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, - size_t length, void *user_data) +static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, + size_t length, void *user_data) { if (length == 0) { char msg[512]; @@ -1246,7 +1251,7 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p fclose(pFile); } -void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) +static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) { if (status) { printf("\nOther went online.\n"); @@ -1263,7 +1268,7 @@ void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void * } } -char timeout_getch(Tox *m) +static char timeout_getch(Tox *m) { char c; int slpval = tox_iteration_interval(m); @@ -1312,7 +1317,7 @@ int main(int argc, char *argv[]) } int on = 0; - char *filename = "data"; + const char *filename = "data"; char idstring[200] = {0}; Tox *m; diff --git a/testing/nTox.h b/testing/nTox.h index 44def1420e..61f86a9b89 100644 --- a/testing/nTox.h +++ b/testing/nTox.h @@ -36,7 +36,4 @@ #define STRING_LENGTH 256 #define HISTORY 50 -void new_lines(char *line); -void do_refresh(); - #endif diff --git a/testing/tox_shell.c b/testing/tox_shell.c index 77047a4447..4089045389 100644 --- a/testing/tox_shell.c +++ b/testing/tox_shell.c @@ -45,7 +45,7 @@ #define c_sleep(x) usleep(1000*x) -void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) +static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) { if (status) { printf("\nOther went online.\n"); @@ -54,8 +54,8 @@ void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void * } } -void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, - void *userdata) +static void print_message(Tox *tox, uint32_t friendnumber, TOX_MESSAGE_TYPE type, const uint8_t *string, size_t length, + void *userdata) { int master = *((int *)userdata); write(master, string, length); @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) } uint8_t *bin_id = hex_string_to_bin(temp_id); - uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); + uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); free(bin_id); if (num == UINT32_MAX) { diff --git a/testing/tox_sync.c b/testing/tox_sync.c index f30ce05927..36b01cf430 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c @@ -49,12 +49,13 @@ typedef struct { uint32_t friendnum; uint32_t filenumber; } File_t; -File_t file_senders[NUM_FILE_SENDERS]; -File_t file_recv[NUM_FILE_SENDERS]; -uint8_t numfilesenders; +static File_t file_senders[NUM_FILE_SENDERS]; +static File_t file_recv[NUM_FILE_SENDERS]; +static uint8_t numfilesenders; -void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, - void *user_data) +static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, + size_t length, + void *user_data) { unsigned int i; @@ -78,7 +79,7 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb } -uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) +static uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) { FILE *tempfile = fopen(filename, "rb"); @@ -103,7 +104,7 @@ uint32_t add_filesender(Tox *m, uint16_t friendnum, char *filename) return filenum; } -void kill_filesender(Tox *m, uint32_t filenum) +static void kill_filesender(Tox *m, uint32_t filenum) { uint32_t i; @@ -114,7 +115,7 @@ void kill_filesender(Tox *m, uint32_t filenum) } } } -int not_sending() +static int not_sending(void) { uint32_t i; @@ -129,8 +130,9 @@ int not_sending() static char path[1024]; -void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, uint64_t file_size, - const uint8_t *filename, size_t filename_length, void *user_data) +static void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t type, + uint64_t file_size, + const uint8_t *filename, size_t filename_length, void *user_data) { if (type != TOX_FILE_KIND_DATA) { printf("Refused invalid file type."); @@ -142,7 +144,7 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, uint32_t i; uint16_t rm = 0; - for (i = 0; i < strlen((char *)filename); ++i) { + for (i = 0; i < strlen((const char *)filename); ++i) { if (filename[i] == '/') { rm = i; } @@ -175,8 +177,8 @@ void file_request_accept(Tox *tox, uint32_t friend_number, uint32_t file_number, } } -void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, - void *user_data) +static void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, + void *user_data) { if (file_number < (1 << 15) && (control == TOX_FILE_CONTROL_CANCEL)) { kill_filesender(tox, file_number); @@ -192,8 +194,8 @@ void file_print_control(Tox *tox, uint32_t friend_number, uint32_t file_number, } } -void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, - size_t length, void *user_data) +static void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data, + size_t length, void *user_data) { uint8_t file_index = (filenumber >> 16) - 1; @@ -214,7 +216,7 @@ void write_file(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t p } } -void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) +static void print_online(Tox *tox, uint32_t friendnumber, TOX_CONNECTION status, void *userdata) { if (status) { printf("\nOther went online.\n"); @@ -284,7 +286,7 @@ int main(int argc, char *argv[]) } uint8_t *bin_id = hex_string_to_bin(temp_id); - uint32_t num = tox_friend_add(tox, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); + uint32_t num = tox_friend_add(tox, bin_id, (const uint8_t *)"Install Gentoo", sizeof("Install Gentoo"), 0); free(bin_id); if (num == UINT32_MAX) { diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index a38d71c0bf..5619c7153c 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -177,7 +177,7 @@ void send_update(BWController *bwc) bwc->cycle.lsu = current_time_monotonic(); } } -int on_update (BWController *bwc, struct BWCMessage *msg) +static int on_update (BWController *bwc, struct BWCMessage *msg) { LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc); diff --git a/toxav/msi.c b/toxav/msi.c index a62bdb35aa..76c727a944 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -682,7 +682,8 @@ void handle_init (MSICall *call, const MSIMessage *msg) } break; - default: { + case msi_CallRequested: + case msi_CallRequesting: { LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'"); call->error = msi_EInvalidState; goto FAILURE; diff --git a/toxav/rtp.c b/toxav/rtp.c index 38e64dd750..6e0c22b263 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -191,7 +191,7 @@ int rtp_send_data (RTPSession *session, const uint8_t *data, uint16_t length) } -bool chloss (const RTPSession *session, const struct RTPHeader *header) +static bool chloss (const RTPSession *session, const struct RTPHeader *header) { if (ntohl(header->timestamp) < session->rtimestamp) { uint16_t hosq, lost = 0; @@ -213,7 +213,7 @@ bool chloss (const RTPSession *session, const struct RTPHeader *header) return false; } -struct RTPMessage *new_message (size_t allocate_len, const uint8_t *data, uint16_t data_length) +static struct RTPMessage *new_message (size_t allocate_len, const uint8_t *data, uint16_t data_length) { assert(allocate_len >= data_length); @@ -246,7 +246,7 @@ int handle_rtp_packet (Messenger *m, uint32_t friendnumber, const uint8_t *data, return -1; } - const struct RTPHeader *header = (struct RTPHeader *) data; + const struct RTPHeader *header = (const struct RTPHeader *) data; if (header->pt != session->payload_type % 128) { LOGGER_WARNING(m->log, "Invalid payload type with the session"); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ac94a36ef7..2e475d01be 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2136,6 +2136,7 @@ static void do_NAT(DHT *dht) #define CHECK_TYPE_TEST_REQ 4 #define CHECK_TYPE_TEST_RES 5 +#if DHT_HARDENING static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8_t *contents, uint16_t length) { if (length > HARDREQ_DATA_SIZE - 1) { @@ -2164,6 +2165,7 @@ static int send_hardening_getnode_req(DHT *dht, Node_format *dest, Node_format * memcpy(data + sizeof(Node_format), search_id, crypto_box_PUBLICKEYBYTES); return send_hardening_req(dht, dest, CHECK_TYPE_GETNODE_REQ, data, sizeof(Node_format) + crypto_box_PUBLICKEYBYTES); } +#endif /* Send a get node hardening response */ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, const uint8_t *queried_client_id, @@ -2316,10 +2318,11 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ return 1; } +#if DHT_HARDENING /* Return a random node from all the nodes we are connected to. * TODO: improve this function. */ -Node_format random_node(DHT *dht, sa_family_t sa_family) +static Node_format random_node(DHT *dht, sa_family_t sa_family) { uint8_t id[crypto_box_PUBLICKEYBYTES]; uint32_t i; @@ -2339,12 +2342,13 @@ Node_format random_node(DHT *dht, sa_family_t sa_family) return nodes_list[rand() % num_nodes]; } +#endif /* Put up to max_num nodes in nodes from the closelist. * * return the number of nodes. */ -uint16_t list_nodes(Client_data *list, unsigned int length, Node_format *nodes, uint16_t max_num) +static uint16_t list_nodes(Client_data *list, unsigned int length, Node_format *nodes, uint16_t max_num) { if (max_num == 0) { return 0; @@ -2417,7 +2421,8 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num) return list_nodes(dht->close_clientlist, LCLIENT_LIST, nodes, max_num); } -void do_hardening(DHT *dht) +#if DHT_HARDENING +static void do_hardening(DHT *dht) { uint32_t i; @@ -2469,6 +2474,7 @@ void do_hardening(DHT *dht) //TODO: add the 2 other testers. } } +#endif /*----------------------------------------------------------------------------------*/ @@ -2589,7 +2595,9 @@ void do_DHT(DHT *dht) do_DHT_friends(dht); do_NAT(dht); do_to_ping(dht->ping); - //do_hardening(dht); +#if DHT_HARDENING + do_hardening(dht); +#endif #ifdef ENABLE_ASSOC_DHT if (dht->assoc) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 472ddd9e98..7ec2ad01d5 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -56,7 +56,7 @@ static uint8_t friend_not_valid(const Messenger *m, int32_t friendnumber) * * return -1 if realloc fails. */ -int realloc_friendlist(Messenger *m, uint32_t num) +static int realloc_friendlist(Messenger *m, uint32_t num) { if (num == 0) { free(m->friendlist); @@ -1191,8 +1191,8 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_ return i; } -int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, - uint8_t control_type, uint8_t *data, uint16_t data_length) +static int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, + uint8_t control_type, uint8_t *data, uint16_t data_length) { if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) { return -1; @@ -2845,7 +2845,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 switch (type) { case MESSENGER_STATE_TYPE_NOSPAMKEYS: if (length == crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES + sizeof(uint32_t)) { - set_nospam(&(m->fr), *(uint32_t *)data); + set_nospam(&(m->fr), *(const uint32_t *)data); load_secret_key(m->net_crypto, (&data[sizeof(uint32_t)]) + crypto_box_PUBLICKEYBYTES); if (public_key_cmp((&data[sizeof(uint32_t)]), m->net_crypto->self_public_key) != 0) { diff --git a/toxcore/group.c b/toxcore/group.c index f10866570c..dbfb31cdca 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1188,7 +1188,7 @@ static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint16_t len); #define GROUP_MESSAGE_PING_ID 0 -int group_ping_send(const Group_Chats *g_c, int groupnumber) +static int group_ping_send(const Group_Chats *g_c, int groupnumber) { if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0)) { return 0; @@ -1203,8 +1203,8 @@ int group_ping_send(const Group_Chats *g_c, int groupnumber) * return 0 on success * return -1 on failure */ -int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, - uint8_t *temp_pk) +static int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num, const uint8_t *real_pk, + uint8_t *temp_pk) { uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH]; diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 0d8fabacb2..e09d7444e7 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -458,7 +458,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por * return IP_Port with family 0 on failure. * return IP_Port on success. */ -IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) +static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) { IP_Port empty; empty.ip.family = 0; diff --git a/toxcore/network.c b/toxcore/network.c index 05867adcfc..2097078a50 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -268,11 +268,11 @@ uint64_t current_time_monotonic(void) static uint32_t data_0(uint16_t buflen, const uint8_t *buffer) { - return buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0; + return buflen > 4 ? ntohl(*(const uint32_t *)&buffer[1]) : 0; } static uint32_t data_1(uint16_t buflen, const uint8_t *buffer) { - return buflen > 7 ? ntohl(*(uint32_t *)&buffer[5]) : 0; + return buflen > 7 ? ntohl(*(const uint32_t *)&buffer[5]) : 0; } static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, @@ -359,7 +359,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, const uint8_t *data, uint1 return -1; } - int res = sendto(net->sock, (char *) data, length, 0, (struct sockaddr *)&addr, addrsize); + int res = sendto(net->sock, (const char *) data, length, 0, (struct sockaddr *)&addr, addrsize); loglogdata(net->log, "O=>", data, length, ip_port, res); @@ -874,13 +874,13 @@ const char *ip_ntoa(const IP *ip) if (ip) { if (ip->family == AF_INET) { /* returns standard quad-dotted notation */ - struct in_addr *addr = (struct in_addr *)&ip->ip4; + const struct in_addr *addr = (const struct in_addr *)&ip->ip4; addresstext[0] = 0; inet_ntop(ip->family, addr, addresstext, sizeof(addresstext)); } else if (ip->family == AF_INET6) { /* returns hex-groups enclosed into square brackets */ - struct in6_addr *addr = (struct in6_addr *)&ip->ip6; + const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; addresstext[0] = '['; inet_ntop(ip->family, addr, &addresstext[1], sizeof(addresstext) - 3); @@ -921,12 +921,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length) } if (ip->family == AF_INET) { - struct in_addr *addr = (struct in_addr *)&ip->ip4; + const struct in_addr *addr = (const struct in_addr *)&ip->ip4; return inet_ntop(ip->family, addr, address, length) != NULL; } if (ip->family == AF_INET6) { - struct in6_addr *addr = (struct in6_addr *)&ip->ip6; + const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; return inet_ntop(ip->family, addr, address, length) != NULL; } diff --git a/toxcore/util.c b/toxcore/util.c index 9f1a7e28ca..92ad451003 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -38,7 +38,7 @@ static uint64_t unix_time_value; static uint64_t unix_base_time_value; -void unix_time_update() +void unix_time_update(void) { if (unix_base_time_value == 0) { unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); @@ -47,7 +47,7 @@ void unix_time_update() unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; } -uint64_t unix_time() +uint64_t unix_time(void) { return unix_time_value; } diff --git a/toxcore/util.h b/toxcore/util.h index 17b1a27b9f..840f0a3ebc 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -32,8 +32,8 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } -void unix_time_update(); -uint64_t unix_time(); +void unix_time_update(void); +uint64_t unix_time(void); int is_timeout(uint64_t timestamp, uint64_t timeout);