From 24f49fc917c056f70194c675a761799871fa124f Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 21 Dec 2021 17:54:02 +0000 Subject: [PATCH] chore: Fix up a few source code comment and style issues. Tokstyle no longer allows: * Includes inside an `extern "C"` * Comments on function definition and declaration to be different. * Doxygen comments commenting on other doxygen comments. --- .cirrus.yml | 4 +-- toxav/bwcontroller.h | 5 ---- toxav/groupav.h | 2 +- toxav/msi.c | 3 +- toxav/rtp.c | 9 ++++-- toxav/rtp.h | 6 +--- toxcore/logger.c | 3 +- toxcore/tox.h | 49 +++++++++++++++------------------ toxencryptsave/toxencryptsave.c | 37 +++++++++++++------------ toxencryptsave/toxencryptsave.h | 8 +++--- 10 files changed, 61 insertions(+), 65 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index b97a8594..68c04af8 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,7 +1,7 @@ --- cirrus-ci_task: container: - image: toxchat/toktok-stack:0.0.28-third_party + image: toxchat/toktok-stack:0.0.29-third_party cpu: 2 memory: 2G configure_script: @@ -19,7 +19,7 @@ cirrus-ci_task: cimple_task: container: - image: toxchat/toktok-stack:0.0.28-third_party + image: toxchat/toktok-stack:0.0.29-third_party cpu: 2 memory: 4G configure_script: diff --git a/toxav/bwcontroller.h b/toxav/bwcontroller.h index 9470c125..4cd25bd1 100644 --- a/toxav/bwcontroller.h +++ b/toxav/bwcontroller.h @@ -8,11 +8,6 @@ #include "../toxcore/Messenger.h" #include "../toxcore/tox.h" -#ifndef TOX_DEFINED -#define TOX_DEFINED -typedef struct Tox Tox; -#endif /* TOX_DEFINED */ - typedef struct BWController_s BWController; typedef void m_cb(BWController *bwc, uint32_t friend_number, float todo, void *user_data); diff --git a/toxav/groupav.h b/toxav/groupav.h index 32304a2b..f9ba1443 100644 --- a/toxav/groupav.h +++ b/toxav/groupav.h @@ -8,7 +8,7 @@ #include "../toxcore/group.h" #include "../toxcore/tox.h" -/* Audio encoding/decoding */ +// Audio encoding/decoding #include #define GROUP_AUDIO_PACKET_ID 192 diff --git a/toxav/msi.c b/toxav/msi.c index e1d7de74..6901d719 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -74,9 +74,10 @@ static void handle_pop(MSICall *call, const MSIMessage *msg); static void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t length, void *object); -/** +/* * Public functions */ + void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICallbackID id) { if (!session) { diff --git a/toxav/rtp.c b/toxav/rtp.c index f4b411c6..071d1a2a 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -740,8 +740,13 @@ int rtp_stop_receiving(RTPSession *session) } /** - * @param data is raw vpx data. - * @param length is the length of the raw data. + * Send a frame of audio or video data, chunked in \ref RTPMessage instances. + * + * @param session The A/V session to send the data for. + * @param data A byte array of length \p length. + * @param length The number of bytes to send from @p data. + * @param is_keyframe Whether this video frame is a key frame. If it is an + * audio frame, this parameter is ignored. */ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, bool is_keyframe, const Logger *log) diff --git a/toxav/rtp.h b/toxav/rtp.h index be9e63f8..91b48af9 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h @@ -9,6 +9,7 @@ #include "../toxcore/Messenger.h" #include "../toxcore/logger.h" +#include "../toxcore/tox.h" #include @@ -16,11 +17,6 @@ extern "C" { #endif -#ifndef TOX_DEFINED -#define TOX_DEFINED -typedef struct Tox Tox; -#endif /* TOX_DEFINED */ - /** * RTPHeader serialised size in bytes. */ diff --git a/toxcore/logger.c b/toxcore/logger.c index dd4631dd..0ee4d858 100644 --- a/toxcore/logger.c +++ b/toxcore/logger.c @@ -58,9 +58,10 @@ static const Logger logger_stderr = { }; #endif -/** +/* * Public Functions */ + Logger *logger_new(void) { return (Logger *)calloc(1, sizeof(Logger)); diff --git a/toxcore/tox.h b/toxcore/tox.h index 236714fd..e1c7ea06 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -3,29 +3,6 @@ * Copyright © 2013 Tox project. */ -/* - * The Tox public API. - */ -#ifndef C_TOXCORE_TOXCORE_TOX_H -#define C_TOXCORE_TOXCORE_TOX_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/******************************************************************************* - * `tox.h` SHOULD NOT BE EDITED MANUALLY – any changes should be made to - * `tox.api.h`, located in `toxcore/`. For instructions on how to - * generate `tox.h` from `tox.api.h` please refer to `docs/apidsl.md` - ******************************************************************************/ - - - /** * @page core Public core API for Tox clients. * @@ -64,8 +41,7 @@ extern "C" { * * Integer constants and the memory layout of publicly exposed structs are not * part of the ABI. - */ -/** + * * @subsection events Events and callbacks * * Events are handled by callbacks. One callback can be registered per event. @@ -87,8 +63,7 @@ extern "C" { * Old style callbacks that are registered together with a user data pointer * receive that pointer as argument when they are called. They can each have * their own user data pointer of their own type. - */ -/** + * * @subsection threading Threading implications * * It is possible to run multiple concurrent threads with a Tox instance for @@ -122,6 +97,26 @@ extern "C" { * memory, the length may have become invalid, and the call to * tox_self_get_name may cause undefined behaviour. */ +#ifndef C_TOXCORE_TOXCORE_TOX_H +#define C_TOXCORE_TOXCORE_TOX_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/******************************************************************************* + * `tox.h` SHOULD NOT BE EDITED MANUALLY – any changes should be made to + * `tox.api.h`, located in `toxcore/`. For instructions on how to + * generate `tox.h` from `tox.api.h` please refer to `docs/apidsl.md` + ******************************************************************************/ + + + /** * The Tox instance type. All the state associated with a connection is held * within the instance. Multiple instances can exist and operate concurrently. diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index f94ab3fc..d894a69d 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -151,18 +151,21 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp } /** - * Encrypt arbitrary with a key produced by `tox_derive_key_*`. The output - * array must be at least data_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes long. - * key must be TOX_PASS_KEY_LENGTH bytes. - * If you already have a symmetric key from somewhere besides this module, simply - * call encrypt_data_symmetric in toxcore/crypto_core directly. + * Encrypt a plain text with a key produced by tox_pass_key_derive or tox_pass_key_derive_with_salt. * - * returns true on success + * The output array must be at least `plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH` + * bytes long. + * + * @param plaintext A byte array of length `plaintext_len`. + * @param plaintext_len The length of the plain text array. Bigger than 0. + * @param ciphertext The cipher text array to write the encrypted data to. + * + * @return true on success. */ -bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t *data, size_t data_len, uint8_t *out, - Tox_Err_Encryption *error) +bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t *plaintext, size_t plaintext_len, + uint8_t *ciphertext, Tox_Err_Encryption *error) { - if (data_len == 0 || !data || !key || !out) { + if (plaintext_len == 0 || !plaintext || !key || !ciphertext) { SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_NULL); return 0; } @@ -175,21 +178,21 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t *data, size_t d // need them to decrypt the data /* first add the magic number */ - memcpy(out, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH); - out += TOX_ENC_SAVE_MAGIC_LENGTH; + memcpy(ciphertext, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH); + ciphertext += TOX_ENC_SAVE_MAGIC_LENGTH; /* then add the rest prefix */ - memcpy(out, key->salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); - out += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; + memcpy(ciphertext, key->salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES); + ciphertext += crypto_pwhash_scryptsalsa208sha256_SALTBYTES; uint8_t nonce[crypto_box_NONCEBYTES]; random_nonce(nonce); - memcpy(out, nonce, crypto_box_NONCEBYTES); - out += crypto_box_NONCEBYTES; + memcpy(ciphertext, nonce, crypto_box_NONCEBYTES); + ciphertext += crypto_box_NONCEBYTES; /* now encrypt */ - if (encrypt_data_symmetric(key->key, nonce, data, data_len, out) - != data_len + crypto_box_MACBYTES) { + if (encrypt_data_symmetric(key->key, nonce, plaintext, plaintext_len, ciphertext) + != plaintext_len + crypto_box_MACBYTES) { SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTION_FAILED); return 0; } diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index cca8878a..51b6fe4a 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -10,15 +10,15 @@ #ifndef C_TOXCORE_TOXENCRYPTSAVE_TOXENCRYPTSAVE_H #define C_TOXCORE_TOXENCRYPTSAVE_TOXENCRYPTSAVE_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + /******************************************************************************* * * This module is organized into two parts.