diff --git a/CMakeLists.txt b/CMakeLists.txt index 60d63098..bd70ab38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,6 @@ endif() option(DEBUG "Enable assertions and other debugging facilities" OFF) if(DEBUG) set(MIN_LOGGER_LEVEL DEBUG) - add_definitions(-DTOX_DEBUG=1) add_cflag("-g3") endif() diff --git a/configure.ac b/configure.ac index 8d59882c..eb16c0e0 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,6 @@ BUILD_AV="yes" BUILD_TESTING="yes" TOX_LOGGER="no" -TOX_DEBUG="no" NCURSES_FOUND="no" LIBCONFIG_FOUND="no" @@ -93,17 +92,6 @@ AC_ARG_ENABLE([logging], ] ) -AC_ARG_ENABLE([debug], - [AC_HELP_STRING([--enable-debug], [enable debugging (default: disabled)]) ], - [ - if test "x$enableval" = "xyes"; then - TOX_DEBUG="yes" - - AC_DEFINE([TOX_DEBUG], [], [If debugging enabled]) - fi - ] -) - AC_ARG_WITH(log-level, AC_HELP_STRING([--with-log-level=LEVEL], [Logger levels: TRACE; DEBUG; INFO; WARNING; ERROR ]), diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 30c813ca..8798c6dd 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -31,10 +31,6 @@ #include #include -#ifdef TOX_DEBUG -#include -#endif // TOX_DEBUG - // You are responsible for freeing the return value! uint8_t *hex_string_to_bin(const char *hex_string) { diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 94bbbe01..611cb0f8 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -2813,13 +2813,10 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le break; -#ifdef TOX_DEBUG - default: - fprintf(stderr, "Load state (DHT): contains unrecognized part (len %u, type %u)\n", - length, type); + LOGGER_ERROR(dht->log, "Load state (DHT): contains unrecognized part (len %u, type %u)\n", + length, type); break; -#endif } return 0; @@ -2839,7 +2836,7 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length) lendian_to_host32(&data32, data); if (data32 == DHT_STATE_COOKIE_GLOBAL) { - return load_state(dht_load_state_callback, dht, data + cookie_len, + return load_state(dht_load_state_callback, dht->log, dht, data + cookie_len, length - cookie_len, DHT_STATE_COOKIE_TYPE); } } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index cd4c8380..05a7c09e 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -31,9 +31,7 @@ #include "network.h" #include "util.h" -#ifdef TOX_DEBUG #include -#endif static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata); @@ -1339,9 +1337,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin return -3; } -#ifdef TOX_DEBUG assert(temp_filenum <= UINT8_MAX); -#endif uint8_t file_number = temp_filenum; // We're always receiving at this point. @@ -2785,20 +2781,16 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data) } uint8_t *next_data = friend_save(&temp, cur_data); -#ifdef TOX_DEBUG assert(next_data - cur_data == friend_size()); #ifdef __LP64__ assert(memcmp(cur_data, &temp, friend_size()) == 0); -#endif #endif cur_data = next_data; num++; } } -#ifdef TOX_DEBUG assert(cur_data - data == num * friend_size()); -#endif return cur_data - data; } @@ -2847,11 +2839,9 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length) for (i = 0; i < num; ++i) { struct SAVED_FRIEND temp = { 0 }; const uint8_t *next_data = friend_load(&temp, cur_data); -#ifdef TOX_DEBUG assert(next_data - cur_data == friend_size()); #ifdef __LP64__ assert(memcmp(&temp, cur_data, friend_size()) == 0); -#endif #endif cur_data = next_data; @@ -2922,9 +2912,7 @@ void messenger_save(const Messenger *m, uint8_t *data) host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL); data += size32; -#ifdef TOX_DEBUG - assert(sizeof(get_nospam(&(m->fr))) == sizeof(uint32_t)); -#endif + assert(sizeof(get_nospam(&m->fr)) == sizeof(uint32_t)); len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE; type = MESSENGER_STATE_TYPE_NOSPAMKEYS; data = z_state_save_subheader(data, len, type); @@ -3075,13 +3063,10 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 return -2; } -#ifdef TOX_DEBUG - default: - fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", - length, type); + LOGGER_ERROR(m->log, "Load state: contains unrecognized part (len %u, type %u)\n", + length, type); break; -#endif } return 0; @@ -3101,7 +3086,7 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length) lendian_to_host32(data32 + 1, data + sizeof(uint32_t)); if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) { - return load_state(messenger_load_state_callback, m, data + cookie_len, + return load_state(messenger_load_state_callback, m->log, m, data + cookie_len, length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); } diff --git a/toxcore/network.c b/toxcore/network.c index f58cde77..253c0611 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -550,9 +550,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ if (ip.family != AF_INET && ip.family != AF_INET6) { -#ifdef TOX_DEBUG - fprintf(stderr, "Invalid address family: %u\n", ip.family); -#endif + LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family); return NULL; } @@ -576,9 +574,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 /* Check for socket error. */ if (!sock_valid(temp->sock)) { -#ifdef TOX_DEBUG - fprintf(stderr, "Failed to get a socket?! %u, %s\n", errno, strerror(errno)); -#endif + LOGGER_ERROR(log, "Failed to get a socket?! %u, %s\n", errno, strerror(errno)); free(temp); if (error) { diff --git a/toxcore/util.c b/toxcore/util.c index 1d2a85dc..b390b169 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -116,13 +116,11 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) } /* state load/save */ -int load_state(load_state_callback_func load_state_callback, void *outer, +int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, const uint8_t *data, uint32_t length, uint16_t cookie_inner) { if (!load_state_callback || !data) { -#ifdef TOX_DEBUG - fprintf(stderr, "load_state() called with invalid args.\n"); -#endif + LOGGER_ERROR(log, "load_state() called with invalid args.\n"); return -1; } @@ -139,17 +137,13 @@ int load_state(load_state_callback_func load_state_callback, void *outer, if (length < length_sub) { /* file truncated */ -#ifdef TOX_DEBUG - fprintf(stderr, "state file too short: %u < %u\n", length, length_sub); -#endif + LOGGER_ERROR(log, "state file too short: %u < %u\n", length, length_sub); return -1; } if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) { /* something is not matching up in a bad way, give up */ -#ifdef DEBUG - fprintf(stderr, "state file garbled: %04x != %04x\n", (cookie_type >> 16), cookie_inner); -#endif + LOGGER_ERROR(log, "state file garbled: %04x != %04x\n", (cookie_type >> 16), cookie_inner); return -1; } diff --git a/toxcore/util.h b/toxcore/util.h index c435813b..daa5a26d 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -29,6 +29,8 @@ #include #include +#include "logger.h" + #define MIN(a,b) (((a)<(b))?(a):(b)) #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } @@ -52,7 +54,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian); /* state load/save */ typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); -int load_state(load_state_callback_func load_state_callback, void *outer, +int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer, const uint8_t *data, uint32_t length, uint16_t cookie_inner); /* Returns -1 if failed or 0 if success */