diff --git a/CMakeLists.txt b/CMakeLists.txt index f211207794..b3196267fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,13 +337,15 @@ set(toxcore_SOURCES toxcore/timed_auth.h toxcore/tox_api.c toxcore/tox.c + toxcore/tox.h toxcore/tox_dispatch.c toxcore/tox_dispatch.h toxcore/tox_event.c toxcore/tox_event.h toxcore/tox_events.c toxcore/tox_events.h - toxcore/tox.h + toxcore/tox_log_level.c + toxcore/tox_log_level.h toxcore/tox_private.c toxcore/tox_private.h toxcore/tox_pack.c @@ -363,8 +365,9 @@ endif() set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium) set(toxcore_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox + ${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox ${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox - ${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox) + ${toxcore_SOURCE_DIR}/toxcore/tox_log_level.h^tox) if(EXPERIMENTAL_API) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox) diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 1534d7a674..002579889f 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -4,6 +4,7 @@ load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test") exports_files( srcs = [ "tox.h", + "tox_log_level.h", "tox_private.h", ], visibility = ["//c-toxcore:__subpackages__"], @@ -980,6 +981,13 @@ cc_library( ], ) +cc_library( + name = "tox_log_level", + srcs = ["tox_log_level.c"], + hdrs = ["tox_log_level.h"], + visibility = ["//c-toxcore:__subpackages__"], +) + cc_library( name = "tox", srcs = [ @@ -1010,6 +1018,7 @@ cc_library( ":network", ":onion_client", ":state", + ":tox_log_level", ":util", "//c-toxcore/toxencryptsave:defines", "@pthread", diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index db3e193243..d48d8b24af 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc @@ -96,6 +96,8 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \ ../toxcore/tox_event.c \ ../toxcore/tox_events.h \ ../toxcore/tox_events.c \ + ../toxcore/tox_log_level.c \ + ../toxcore/tox_log_level.h \ ../toxcore/tox_pack.h \ ../toxcore/tox_pack.c \ ../toxcore/tox_unpack.h \ diff --git a/toxcore/tox.h b/toxcore/tox.h index ebeed3b1f5..8e17d7095c 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -95,6 +95,8 @@ #include #include +#include "tox_log_level.h" + #ifdef __cplusplus extern "C" { #endif @@ -438,40 +440,6 @@ typedef enum Tox_Savedata_Type { const char *tox_savedata_type_to_string(Tox_Savedata_Type value); -/** - * @brief Severity level of log messages. - */ -typedef enum Tox_Log_Level { - - /** - * Very detailed traces including all network activity. - */ - TOX_LOG_LEVEL_TRACE, - - /** - * Debug messages such as which port we bind to. - */ - TOX_LOG_LEVEL_DEBUG, - - /** - * Informational log messages such as video call status changes. - */ - TOX_LOG_LEVEL_INFO, - - /** - * Warnings about internal inconsistency or logic errors. - */ - TOX_LOG_LEVEL_WARNING, - - /** - * Severe unexpected errors caused by external or internal inconsistency. - */ - TOX_LOG_LEVEL_ERROR, - -} Tox_Log_Level; - -const char *tox_log_level_to_string(Tox_Log_Level value); - /** * @brief This event is triggered when Tox logs an internal message. * diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 18d861c18e..1ea8690c54 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -378,27 +378,6 @@ const char *tox_savedata_type_to_string(Tox_Savedata_Type value) return ""; } -const char *tox_log_level_to_string(Tox_Log_Level value) -{ - switch (value) { - case TOX_LOG_LEVEL_TRACE: - return "TOX_LOG_LEVEL_TRACE"; - - case TOX_LOG_LEVEL_DEBUG: - return "TOX_LOG_LEVEL_DEBUG"; - - case TOX_LOG_LEVEL_INFO: - return "TOX_LOG_LEVEL_INFO"; - - case TOX_LOG_LEVEL_WARNING: - return "TOX_LOG_LEVEL_WARNING"; - - case TOX_LOG_LEVEL_ERROR: - return "TOX_LOG_LEVEL_ERROR"; - } - - return ""; -} const char *tox_err_options_new_to_string(Tox_Err_Options_New value) { switch (value) { diff --git a/toxcore/tox_log_level.c b/toxcore/tox_log_level.c new file mode 100644 index 0000000000..27291da833 --- /dev/null +++ b/toxcore/tox_log_level.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2016-2024 The TokTok team. + * Copyright © 2013 Tox project. + */ +#include "tox_log_level.h" + +const char *tox_log_level_to_string(Tox_Log_Level value) +{ + switch (value) { + case TOX_LOG_LEVEL_TRACE: + return "TOX_LOG_LEVEL_TRACE"; + + case TOX_LOG_LEVEL_DEBUG: + return "TOX_LOG_LEVEL_DEBUG"; + + case TOX_LOG_LEVEL_INFO: + return "TOX_LOG_LEVEL_INFO"; + + case TOX_LOG_LEVEL_WARNING: + return "TOX_LOG_LEVEL_WARNING"; + + case TOX_LOG_LEVEL_ERROR: + return "TOX_LOG_LEVEL_ERROR"; + } + + return ""; +} diff --git a/toxcore/tox_log_level.h b/toxcore/tox_log_level.h new file mode 100644 index 0000000000..66dfb3e935 --- /dev/null +++ b/toxcore/tox_log_level.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + * Copyright © 2022-2024 The TokTok team. + */ + +#ifndef C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H +#define C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Severity level of log messages. + */ +typedef enum Tox_Log_Level { + /** + * Very detailed traces including all network activity. + */ + TOX_LOG_LEVEL_TRACE, + + /** + * Debug messages such as which port we bind to. + */ + TOX_LOG_LEVEL_DEBUG, + + /** + * Informational log messages such as video call status changes. + */ + TOX_LOG_LEVEL_INFO, + + /** + * Warnings about internal inconsistency or logic errors. + */ + TOX_LOG_LEVEL_WARNING, + + /** + * Severe unexpected errors caused by external or internal inconsistency. + */ + TOX_LOG_LEVEL_ERROR, +} Tox_Log_Level; + +const char *tox_log_level_to_string(Tox_Log_Level value); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* C_TOXCORE_TOXCORE_TOX_LOG_LEVEL_H */