Squashed 'external/toxcore/c-toxcore/' changes from 1701691d5..640e6cace

640e6cace fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.
6f7f51554 chore(toxav): use realtime deadline for vp8 encoder Technically all this does is choose a quality based on frame duration, which we always set to 1, and as such is always realtime. (In same timebase as pts, which we use as a frame counter...)
5047ae5a2 chore: make the source tarball exhibit the old behavior
14804a4b8 chore: Fix sonar-scan CI action.
e2db7d946 cleanup: Exclude lan_discovery test from running on macos, instead of excluding it from the project.
3accade67 chore: Fix CI, disabling some tests that no longer run on CI.
ef8d767e6 cleanup: Fix comment formatting errors.
34ec822da cleanup: Fix some clang-19 format warnings.
40b3f0b46 refactor: Use clang's nullability qualifiers instead of attributes.
f81e30679 refactor: Use per-parameter nullability annotations.
REVERT: 1701691d5 chore(toxav): use realtime deadline for vp8 encoder Technically all this does is choose a quality based on frame duration, which we always set to 1, and as such is always realtime. (In same timebase as pts, which we use as a frame counter...)
REVERT: a87505867 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 640e6cace81b4412c45977b94eb9c41e53c54035
This commit is contained in:
Green Sky
2025-10-08 12:03:02 +02:00
parent ab12fbe820
commit 54c0a3c874
195 changed files with 3148 additions and 5495 deletions

View File

@@ -194,8 +194,7 @@ const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num)
return dht->friends_list[friend_num].public_key;
}
non_null()
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *_Nonnull assoc)
{
return (assoc->timestamp + BAD_NODE_TIMEOUT) <= cur_time;
}
@@ -204,8 +203,7 @@ static bool assoc_timeout(uint64_t cur_time, const IPPTsPng *assoc)
*
* If the ip_port is already IPv4 this function returns a copy of the original ip_port.
*/
non_null()
static IP_Port ip_port_normalize(const IP_Port *ip_port)
static IP_Port ip_port_normalize(const IP_Port *_Nonnull ip_port)
{
IP_Port res = *ip_port;
@@ -404,8 +402,7 @@ int dht_create_packet(const Memory *mem, const Random *rng,
*
* @retval true on success.
*/
non_null()
static bool bin_pack_node_handler(const void *arr, uint32_t index, const Logger *logger, Bin_Pack *bp)
static bool bin_pack_node_handler(const void *_Nonnull arr, uint32_t index, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
{
const Node_format *nodes = (const Node_format *)arr;
return bin_pack_ip_port(bp, logger, &nodes[index].ip_port)
@@ -465,11 +462,9 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
*
* @return index or UINT32_MAX if not found.
*/
non_null(3) nullable(1)
static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, const uint8_t *pk)
static uint32_t index_of_client_pk(const Client_data *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
{
assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) {
return i;
@@ -479,11 +474,9 @@ static uint32_t index_of_client_pk(const Client_data *array, uint32_t size, cons
return UINT32_MAX;
}
non_null(3) nullable(1)
static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const uint8_t *pk)
static uint32_t index_of_friend_pk(const DHT_Friend *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
{
assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) {
return i;
@@ -493,11 +486,9 @@ static uint32_t index_of_friend_pk(const DHT_Friend *array, uint32_t size, const
return UINT32_MAX;
}
non_null(3) nullable(1)
static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const uint8_t *pk)
static uint32_t index_of_node_pk(const Node_format *_Nullable array, uint32_t size, const uint8_t *_Nonnull pk)
{
assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) {
if (pk_equal(array[i].public_key, pk)) {
return i;
@@ -511,11 +502,9 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const
*
* @return index or UINT32_MAX if not found.
*/
non_null(3) nullable(1)
static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port)
static uint32_t index_of_client_ip_port(const Client_data *_Nullable array, uint32_t size, const IP_Port *_Nonnull ip_port)
{
assert(size == 0 || array != nullptr);
for (uint32_t i = 0; i < size; ++i) {
if ((net_family_is_ipv4(ip_port->ip.family) && ipport_equal(&array[i].assoc4.ip_port, ip_port)) ||
(net_family_is_ipv6(ip_port->ip.family) && ipport_equal(&array[i].assoc6.ip_port, ip_port))) {
@@ -527,9 +516,7 @@ static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size,
}
/** Update ip_port of client if it's needed. */
non_null()
static void update_client(const Logger *log, const Mono_Time *mono_time, int index, Client_data *client,
const IP_Port *ip_port)
static void update_client(const Logger *_Nonnull log, const Mono_Time *_Nonnull mono_time, int index, Client_data *_Nonnull client, const IP_Port *_Nonnull ip_port)
{
IPPTsPng *assoc;
int ip_version;
@@ -548,7 +535,7 @@ static void update_client(const Logger *log, const Mono_Time *mono_time, int ind
Ip_Ntoa ip_str_from;
Ip_Ntoa ip_str_to;
LOGGER_TRACE(log, "coipil[%u]: switching ipv%d from %s:%u to %s:%u",
index, ip_version,
(unsigned int)index, ip_version,
net_ip_ntoa(&assoc->ip_port.ip, &ip_str_from),
net_ntohs(assoc->ip_port.port),
net_ip_ntoa(&ip_port->ip, &ip_str_to),
@@ -569,9 +556,8 @@ static void update_client(const Logger *log, const Mono_Time *mono_time, int ind
* If the id is already in the list with a different ip_port, update it.
* TODO(irungentoo): Maybe optimize this.
*/
non_null()
static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_time, Client_data *list, uint16_t length,
const uint8_t *public_key, const IP_Port *ip_port)
static bool client_or_ip_port_in_list(const Logger *_Nonnull log, const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull list, uint16_t length, const uint8_t *_Nonnull public_key,
const IP_Port *_Nonnull ip_port)
{
const uint64_t temp_time = mono_time_get(mono_time);
uint32_t index = index_of_client_pk(list, length, public_key);
@@ -646,12 +632,8 @@ bool add_to_list(
/**
* helper for `get_close_nodes()`. argument list is a monster :D
*/
non_null()
static void get_close_nodes_inner(
uint64_t cur_time, const uint8_t *public_key,
Node_format *nodes_list, uint32_t *num_nodes_ptr,
Family sa_family, const Client_data *client_list, uint32_t client_list_length,
bool is_lan, bool want_announce)
static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *_Nonnull public_key, Node_format *_Nonnull nodes_list, uint32_t *_Nonnull num_nodes_ptr, Family sa_family,
const Client_data *_Nonnull client_list, uint32_t client_list_length, bool is_lan, bool want_announce)
{
if (!net_family_is_ipv4(sa_family) && !net_family_is_ipv6(sa_family) && !net_family_is_unspec(sa_family)) {
return;
@@ -717,12 +699,8 @@ static void get_close_nodes_inner(
*
* want_announce: return only nodes which implement the dht announcements protocol.
*/
non_null()
static int get_somewhat_close_nodes(
uint64_t cur_time, const uint8_t *public_key, Node_format nodes_list[MAX_SENT_NODES],
Family sa_family, const Client_data *close_clientlist,
const DHT_Friend *friends_list, uint16_t friends_list_size,
bool is_lan, bool want_announce)
static int get_somewhat_close_nodes(uint64_t cur_time, const uint8_t *_Nonnull public_key, Node_format nodes_list[_Nonnull MAX_SENT_NODES], Family sa_family,
const Client_data *_Nonnull close_clientlist, const DHT_Friend *_Nonnull friends_list, uint16_t friends_list_size, bool is_lan, bool want_announce)
{
for (uint16_t i = 0; i < MAX_SENT_NODES; ++i) {
nodes_list[i] = empty_node_format;
@@ -761,8 +739,7 @@ int get_close_nodes(
}
#ifdef CHECK_ANNOUNCE_NODE
non_null()
static void set_announce_node_in_list(Client_data *list, uint32_t list_len, const uint8_t *public_key)
static void set_announce_node_in_list(Client_data *_Nonnull list, uint32_t list_len, const uint8_t *_Nonnull public_key)
{
const uint32_t index = index_of_client_pk(list, list_len, public_key);
@@ -787,8 +764,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key)
}
/** @brief Send data search request, searching for a random key. */
non_null()
static bool send_announce_ping(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
static bool send_announce_ping(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
{
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t)];
@@ -815,13 +791,11 @@ static bool send_announce_ping(DHT *dht, const uint8_t *public_key, const IP_Por
}
/** @brief If the response is valid, set the sender as an announce node. */
non_null(1, 2, 3) nullable(5)
static int handle_data_search_response(void *object, const IP_Port *source,
const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_data_search_response(void *_Nonnull object, const IP_Port *_Nonnull source,
const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
DHT *dht = (DHT *) object;
const int32_t plain_len = (int32_t)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
if (plain_len < (int32_t)(CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))) {
@@ -867,9 +841,7 @@ static int handle_data_search_response(void *object, const IP_Port *source,
* return false if node can't be stored.
* return true if it can.
*/
non_null()
static bool store_node_ok(const Client_data *client, uint64_t cur_time, const uint8_t *public_key,
const uint8_t *comp_public_key)
static bool store_node_ok(const Client_data *_Nonnull client, uint64_t cur_time, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull comp_public_key)
{
return (assoc_timeout(cur_time, &client->assoc4)
&& assoc_timeout(cur_time, &client->assoc6))
@@ -882,8 +854,7 @@ typedef struct Client_data_Cmp {
const uint8_t *comp_public_key;
} Client_data_Cmp;
non_null()
static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1, const Client_data *entry2)
static int client_data_cmp(const Client_data_Cmp *_Nonnull cmp, const Client_data *_Nonnull entry1, const Client_data *_Nonnull entry2)
{
const bool t1 = assoc_timeout(cmp->cur_time, &entry1->assoc4) && assoc_timeout(cmp->cur_time, &entry1->assoc6);
const bool t2 = assoc_timeout(cmp->cur_time, &entry2->assoc4) && assoc_timeout(cmp->cur_time, &entry2->assoc6);
@@ -913,8 +884,7 @@ static int client_data_cmp(const Client_data_Cmp *cmp, const Client_data *entry1
return 0;
}
non_null()
static bool client_data_less_handler(const void *object, const void *a, const void *b)
static bool client_data_less_handler(const void *_Nonnull object, const void *_Nonnull a, const void *_Nonnull b)
{
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
const Client_data *entry1 = (const Client_data *)a;
@@ -923,30 +893,26 @@ static bool client_data_less_handler(const void *object, const void *a, const vo
return client_data_cmp(cmp, entry1, entry2) < 0;
}
non_null()
static const void *client_data_get_handler(const void *arr, uint32_t index)
static const void *client_data_get_handler(const void *_Nonnull arr, uint32_t index)
{
const Client_data *entries = (const Client_data *)arr;
return &entries[index];
}
non_null()
static void client_data_set_handler(void *arr, uint32_t index, const void *val)
static void client_data_set_handler(void *_Nonnull arr, uint32_t index, const void *_Nonnull val)
{
Client_data *entries = (Client_data *)arr;
const Client_data *entry = (const Client_data *)val;
entries[index] = *entry;
}
non_null()
static void *client_data_subarr_handler(void *arr, uint32_t index, uint32_t size)
static void *client_data_subarr_handler(void *_Nonnull arr, uint32_t index, uint32_t size)
{
Client_data *entries = (Client_data *)arr;
return &entries[index];
}
non_null()
static void *client_data_alloc_handler(const void *object, uint32_t size)
static void *client_data_alloc_handler(const void *_Nonnull object, uint32_t size)
{
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
Client_data *tmp = (Client_data *)mem_valloc(cmp->mem, size, sizeof(Client_data));
@@ -958,8 +924,7 @@ static void *client_data_alloc_handler(const void *object, uint32_t size)
return tmp;
}
non_null()
static void client_data_delete_handler(const void *object, void *arr, uint32_t size)
static void client_data_delete_handler(const void *_Nonnull object, void *_Nonnull arr, uint32_t size)
{
const Client_data_Cmp *cmp = (const Client_data_Cmp *)object;
mem_delete(cmp->mem, arr);
@@ -974,9 +939,7 @@ static const Sort_Funcs client_data_cmp_funcs = {
client_data_delete_handler,
};
non_null()
static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_time, unsigned int length,
const uint8_t *comp_public_key)
static void sort_client_list(const Memory *_Nonnull mem, Client_data *_Nonnull list, uint64_t cur_time, unsigned int length, const uint8_t *_Nonnull comp_public_key)
{
// Pass comp_public_key to merge_sort with each Client_data entry, so the
// comparison function can use it as the base of comparison.
@@ -989,8 +952,7 @@ static void sort_client_list(const Memory *mem, Client_data *list, uint64_t cur_
merge_sort(list, length, &cmp, &client_data_cmp_funcs);
}
non_null()
static void update_client_with_reset(const Mono_Time *mono_time, Client_data *client, const IP_Port *ip_port)
static void update_client_with_reset(const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull client, const IP_Port *_Nonnull ip_port)
{
IPPTsPng *ipptp_write = nullptr;
IPPTsPng *ipptp_clear = nullptr;
@@ -1031,13 +993,8 @@ static void update_client_with_reset(const Mono_Time *mono_time, Client_data *cl
*
* @return true when the item was stored, false otherwise
*/
non_null()
static bool replace_all(const DHT *dht,
Client_data *list,
uint16_t length,
const uint8_t *public_key,
const IP_Port *ip_port,
const uint8_t *comp_public_key)
static bool replace_all(const DHT *_Nonnull dht, Client_data *_Nonnull list, uint16_t length, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port,
const uint8_t *_Nonnull comp_public_key)
{
if (!net_family_is_ipv4(ip_port->ip.family) && !net_family_is_ipv6(ip_port->ip.family)) {
return false;
@@ -1064,8 +1021,7 @@ static bool replace_all(const DHT *dht,
* return false on failure.
* return true on success.
*/
non_null()
static bool add_to_close(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port, bool simulate)
static bool add_to_close(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port, bool simulate)
{
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@@ -1105,9 +1061,7 @@ bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Po
return add_to_close(dht, public_key, ip_port, true);
}
non_null()
static bool is_pk_in_client_list(const Client_data *list, unsigned int client_list_length, uint64_t cur_time,
const uint8_t *public_key, const IP_Port *ip_port)
static bool is_pk_in_client_list(const Client_data *_Nonnull list, unsigned int client_list_length, uint64_t cur_time, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
{
const uint32_t index = index_of_client_pk(list, client_list_length, public_key);
@@ -1122,8 +1076,7 @@ static bool is_pk_in_client_list(const Client_data *list, unsigned int client_li
return !assoc_timeout(cur_time, assoc);
}
non_null()
static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
static bool is_pk_in_close_list(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
{
unsigned int index = bit_by_bit_cmp(public_key, dht->self_public_key);
@@ -1142,8 +1095,7 @@ static bool is_pk_in_close_list(const DHT *dht, const uint8_t *public_key, const
* return false if the node should not be pinged.
* return true if it should.
*/
non_null()
static bool ping_node_from_nodes_response_ok(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port)
static bool ping_node_from_nodes_response_ok(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port)
{
bool ret = false;
@@ -1260,9 +1212,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
return used;
}
non_null()
static bool update_client_data(const Mono_Time *mono_time, Client_data *array, size_t size, const IP_Port *ip_port,
const uint8_t *pk, bool node_is_self)
static bool update_client_data(const Mono_Time *_Nonnull mono_time, Client_data *_Nonnull array, size_t size, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull pk, bool node_is_self)
{
const uint64_t temp_time = mono_time_get(mono_time);
const uint32_t index = index_of_client_pk(array, size, pk);
@@ -1293,8 +1243,7 @@ static bool update_client_data(const Mono_Time *mono_time, Client_data *array, s
* If public_key is a friend or us, update ret_ip_port
* nodepublic_key is the id of the node that sent us this info.
*/
non_null()
static void returnedip_ports(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
static void returnedip_ports(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull nodepublic_key)
{
const IP_Port ipp_copy = ip_port_normalize(ip_port);
@@ -1361,9 +1310,8 @@ bool dht_send_nodes_request(DHT *dht, const IP_Port *ip_port, const uint8_t *pub
}
/** Send a nodes response */
non_null()
static int send_nodes_response(const DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id,
const uint8_t *sendback_data, uint16_t length, const uint8_t *shared_encryption_key)
static int send_nodes_response(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull client_id,
const uint8_t *_Nonnull sendback_data, uint16_t length, const uint8_t *_Nonnull shared_encryption_key)
{
/* Check if packet is going to be sent to ourself. */
if (pk_equal(public_key, dht->self_public_key)) {
@@ -1412,8 +1360,7 @@ static int send_nodes_response(const DHT *dht, const IP_Port *ip_port, const uin
#define CRYPTO_NODE_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint64_t))
non_null()
static int handle_nodes_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
static int handle_nodes_request(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
{
DHT *const dht = (DHT *)object;
@@ -1448,8 +1395,7 @@ static int handle_nodes_request(void *object, const IP_Port *source, const uint8
}
/** Return true if we sent a nodes request packet to the peer associated with the supplied info. */
non_null()
static bool sent_nodes_request_to_node(DHT *dht, const uint8_t *public_key, const IP_Port *node_ip_port, uint64_t ping_id)
static bool sent_nodes_request_to_node(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull node_ip_port, uint64_t ping_id)
{
uint8_t data[sizeof(Node_format) * 2];
@@ -1466,9 +1412,8 @@ static bool sent_nodes_request_to_node(DHT *dht, const uint8_t *public_key, cons
return ipport_equal(&test.ip_port, node_ip_port) && pk_equal(test.public_key, public_key);
}
non_null()
static bool handle_nodes_response_core(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
static bool handle_nodes_response_core(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, Node_format *_Nonnull plain_nodes,
uint16_t size_plain_nodes, uint32_t *_Nonnull num_nodes_out)
{
DHT *const dht = (DHT *)object;
const uint32_t cid_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + 1 + sizeof(uint64_t) + CRYPTO_MAC_SIZE;
@@ -1536,9 +1481,7 @@ static bool handle_nodes_response_core(void *object, const IP_Port *source, cons
return true;
}
non_null()
static int handle_nodes_response(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_nodes_response(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
{
DHT *const dht = (DHT *)object;
Node_format plain_nodes[MAX_SENT_NODES];
@@ -1569,9 +1512,8 @@ static int handle_nodes_response(void *object, const IP_Port *source, const uint
/*----------------------------------------------------------------------------------*/
/*------------------------END of packet handling functions--------------------------*/
non_null(1) nullable(2, 3)
static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_callback,
void *data, int32_t number)
static uint32_t dht_friend_lock(DHT_Friend *_Nonnull dht_friend, dht_ip_cb *_Nullable ip_callback,
void *_Nullable data, int32_t number)
{
// find first free slot
uint8_t lock_num;
@@ -1598,8 +1540,7 @@ static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_call
return lock_token;
}
non_null()
static void dht_friend_unlock(DHT_Friend *const dht_friend, uint32_t lock_token)
static void dht_friend_unlock(DHT_Friend *_Nonnull dht_friend, uint32_t lock_token)
{
// If this triggers, there was a double free
assert((lock_token & dht_friend->lock_flags) > 0);
@@ -1736,9 +1677,8 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
}
/** returns number of nodes not in kill-timeout */
non_null()
static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, const uint8_t *public_key,
Client_data *list, uint32_t list_count, uint32_t *bootstrap_times, bool sortable)
static uint8_t do_ping_and_sendnode_requests(DHT *_Nonnull dht, uint64_t *_Nonnull lastgetnode, const uint8_t *_Nonnull public_key, Client_data *_Nonnull list, uint32_t list_count,
uint32_t *_Nonnull bootstrap_times, bool sortable)
{
uint8_t not_kill = 0;
const uint64_t temp_time = mono_time_get(dht->mono_time);
@@ -1822,8 +1762,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
* Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good
* node for each "friend" in our "friends" list.
*/
non_null()
static void do_dht_friends(DHT *dht)
static void do_dht_friends(DHT *_Nonnull dht)
{
for (size_t i = 0; i < dht->num_friends; ++i) {
DHT_Friend *const dht_friend = &dht->friends_list[i];
@@ -1843,8 +1782,7 @@ static void do_dht_friends(DHT *dht)
*
* Send a nodes request every NODES_REQUEST_INTERVAL seconds to a random good node in the list.
*/
non_null()
static void do_close(DHT *dht)
static void do_close(DHT *_Nonnull dht)
{
for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
dht_send_nodes_request(dht, &dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key);
@@ -1950,8 +1888,7 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* @retval 0 if we are connected to friend or if no ips were found.
* @retval -1 if no such friend.
*/
non_null()
static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
static int friend_iplist(const DHT *_Nonnull dht, IP_Port *_Nonnull ip_portlist, uint16_t friend_num)
{
if (friend_num >= dht->num_friends) {
return -1;
@@ -2031,7 +1968,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
* @param n A pointer to the number that will be returned from `foreach_ip_port`.
* @param userdata The `userdata` pointer passed to `foreach_ip_port`.
*/
typedef bool foreach_ip_port_cb(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata);
typedef bool foreach_ip_port_cb(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata);
/**
* Runs a callback on every active connection for a given DHT friend.
@@ -2044,9 +1981,7 @@ typedef bool foreach_ip_port_cb(const DHT *dht, const IP_Port *ip_port, uint32_t
* @param callback The callback to invoke for each IP/port.
* @param userdata Extra pointer passed to the callback.
*/
non_null()
static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
foreach_ip_port_cb *callback, void *userdata)
static uint32_t foreach_ip_port(const DHT *_Nonnull dht, const DHT_Friend *_Nonnull dht_friend, foreach_ip_port_cb *_Nonnull callback, void *_Nonnull userdata)
{
uint32_t n = 0;
@@ -2076,8 +2011,7 @@ static uint32_t foreach_ip_port(const DHT *dht, const DHT_Friend *dht_friend,
return n;
}
non_null()
static bool send_packet_to_friend(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
static bool send_packet_to_friend(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
{
const Packet *packet = (const Packet *)userdata;
const int retval = send_packet(dht->net, ip_port, *packet);
@@ -2118,8 +2052,7 @@ uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet
return foreach_ip_port(dht, dht_friend, send_packet_to_friend, &packet_userdata);
}
non_null()
static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, void *userdata)
static bool get_ip_port(const DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull n, void *_Nonnull userdata)
{
IP_Port *ip_list = (IP_Port *)userdata;
ip_list[*n] = *ip_port;
@@ -2131,8 +2064,7 @@ static bool get_ip_port(const DHT *dht, const IP_Port *ip_port, uint32_t *n, voi
*
* @return number of nodes the packet was sent to.
*/
non_null()
static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet)
static uint32_t routeone_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet)
{
const uint32_t num = index_of_friend_pk(dht->friends_list, dht->num_friends, friend_id);
@@ -2163,8 +2095,7 @@ static uint32_t routeone_to_friend(const DHT *dht, const uint8_t *friend_id, con
/*----------------------------------------------------------------------------------*/
/*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/
non_null()
static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t ping_id, uint8_t type)
static int send_nat_ping(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint64_t ping_id, uint8_t type)
{
uint8_t data[sizeof(uint64_t) + 1];
uint8_t packet_data[MAX_CRYPTO_REQUEST_SIZE];
@@ -2198,9 +2129,8 @@ static int send_nat_ping(const DHT *dht, const uint8_t *public_key, uint64_t pin
}
/** Handle a received ping request for. */
non_null()
static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *source_pubkey, const uint8_t *packet,
uint16_t length, void *userdata)
static int handle_nat_ping(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nonnull userdata)
{
DHT *const dht = (DHT *)object;
@@ -2243,8 +2173,7 @@ static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *s
*
* @return ip of 0 if failure.
*/
non_null()
static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
static IP nat_commonip(const IP_Port *_Nonnull ip_portlist, uint16_t len, uint16_t min_num)
{
IP zero;
ip_reset(&zero);
@@ -2276,8 +2205,7 @@ static IP nat_commonip(const IP_Port *ip_portlist, uint16_t len, uint16_t min_nu
*
* @return number of ports and puts the list of ports in portlist.
*/
non_null()
static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uint16_t len, const IP *ip)
static uint16_t nat_getports(uint16_t *_Nonnull portlist, const IP_Port *_Nonnull ip_portlist, uint16_t len, const IP *_Nonnull ip)
{
uint16_t num = 0;
@@ -2291,8 +2219,7 @@ static uint16_t nat_getports(uint16_t *portlist, const IP_Port *ip_portlist, uin
return num;
}
non_null()
static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint16_t numports, uint16_t friend_num)
static void punch_holes(DHT *_Nonnull dht, const IP *_Nonnull ip, const uint16_t *_Nonnull port_list, uint16_t numports, uint16_t friend_num)
{
if (!dht->hole_punching_enabled) {
return;
@@ -2352,8 +2279,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1
++dht->friends_list[friend_num].nat.tries;
}
non_null()
static void do_nat(DHT *dht)
static void do_nat(DHT *_Nonnull dht)
{
const uint64_t temp_time = mono_time_get(dht->mono_time);
@@ -2404,9 +2330,7 @@ static void do_nat(DHT *dht)
*
* @return the number of nodes.
*/
non_null()
static uint16_t list_nodes(const Random *rng, const Client_data *list, size_t length,
uint64_t cur_time, Node_format *nodes, uint16_t max_num)
static uint16_t list_nodes(const Random *_Nonnull rng, const Client_data *_Nonnull list, size_t length, uint64_t cur_time, Node_format *_Nonnull nodes, uint16_t max_num)
{
if (max_num == 0) {
return 0;
@@ -2490,9 +2414,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
dht->cryptopackethandlers[byte].object = object;
}
non_null()
static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int cryptopacket_handle(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nonnull userdata)
{
DHT *const dht = (DHT *)object;
@@ -2539,12 +2461,10 @@ void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function)
dht->nodes_response_callback = function;
}
non_null(1, 2, 3) nullable(5)
static int handle_lan_discovery(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_lan_discovery(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
DHT *dht = (DHT *)object;
if (!dht->lan_discovery_enabled) {
return 1;
}
@@ -2574,7 +2494,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw
DHT *const dht = (DHT *)mem_alloc(mem, sizeof(DHT));
if (dht == nullptr) {
LOGGER_ERROR(log, "failed to allocate DHT struct (%ld bytes)", (unsigned long)sizeof(DHT));
LOGGER_ERROR(log, "failed to allocate DHT struct (%lu bytes)", (unsigned long)sizeof(DHT));
return nullptr;
}
@@ -2746,7 +2666,7 @@ void dht_save(const DHT *dht, uint8_t *data)
Node_format *clients = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
if (clients == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
LOGGER_ERROR(dht->log, "could not allocate %u nodes", (unsigned int)MAX_SAVED_DHT_NODES);
return;
}
@@ -2826,8 +2746,7 @@ int dht_connect_after_load(DHT *dht)
return 0;
}
non_null()
static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
static State_Load_Status dht_load_state_callback(void *_Nonnull outer, const uint8_t *_Nonnull data, uint32_t length, uint16_t type)
{
DHT *dht = (DHT *)outer;
@@ -2843,7 +2762,7 @@ static State_Load_Status dht_load_state_callback(void *outer, const uint8_t *dat
Node_format *nodes = (Node_format *)mem_valloc(dht->mem, MAX_SAVED_DHT_NODES, sizeof(Node_format));
if (nodes == nullptr) {
LOGGER_ERROR(dht->log, "could not allocate %u nodes", MAX_SAVED_DHT_NODES);
LOGGER_ERROR(dht->log, "could not allocate %u nodes", (unsigned int)MAX_SAVED_DHT_NODES);
dht->loaded_num_nodes = 0;
break;
}

View File

@@ -98,10 +98,8 @@ extern "C" {
* @retval -1 on failure.
* @return the length of the created packet on success.
*/
non_null()
int create_request(const Memory *mem, const Random *rng, const uint8_t *send_public_key, const uint8_t *send_secret_key,
uint8_t *packet, const uint8_t *recv_public_key,
const uint8_t *data, uint32_t data_length, uint8_t request_id);
int create_request(const Memory *_Nonnull mem, const Random *_Nonnull rng, const uint8_t *_Nonnull send_public_key, const uint8_t *_Nonnull send_secret_key, uint8_t *_Nonnull packet,
const uint8_t *_Nonnull recv_public_key, const uint8_t *_Nonnull data, uint32_t data_length, uint8_t request_id);
/**
* @brief Decrypts and unpacks a DHT request packet.
@@ -125,10 +123,8 @@ int create_request(const Memory *mem, const Random *rng, const uint8_t *send_pub
* @retval -1 if not valid request.
* @return the length of the unpacked data.
*/
non_null()
int handle_request(
const Memory *mem, const uint8_t *self_public_key, const uint8_t *self_secret_key, uint8_t *public_key, uint8_t *data,
uint8_t *request_id, const uint8_t *packet, uint16_t packet_length);
int handle_request(const Memory *_Nonnull mem, const uint8_t *_Nonnull self_public_key, const uint8_t *_Nonnull self_secret_key, uint8_t *_Nonnull public_key, uint8_t *_Nonnull data,
uint8_t *_Nonnull request_id, const uint8_t *_Nonnull packet, uint16_t packet_length);
typedef struct IPPTs {
IP_Port ip_port;
@@ -182,8 +178,8 @@ extern const Node_format empty_node_format;
typedef struct DHT_Friend DHT_Friend;
non_null() const uint8_t *dht_friend_public_key(const DHT_Friend *dht_friend);
non_null() const Client_data *dht_friend_client(const DHT_Friend *dht_friend, size_t index);
const uint8_t *_Nonnull dht_friend_public_key(const DHT_Friend *_Nonnull dht_friend);
const Client_data *_Nonnull dht_friend_client(const DHT_Friend *_Nonnull dht_friend, size_t index);
/** @return packet size of packed node with ip_family on success.
* @retval -1 on failure.
@@ -195,20 +191,15 @@ int packed_node_size(Family ip_family);
* @return size of packet on success.
* @retval -1 on failure.
*/
non_null()
int dht_create_packet(const Memory *mem, const Random *rng,
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, uint8_t type,
const uint8_t *plain, size_t plain_length,
uint8_t *packet, size_t length);
int dht_create_packet(const Memory *_Nonnull mem, const Random *_Nonnull rng, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t *_Nonnull shared_key, uint8_t type,
const uint8_t *_Nonnull plain, size_t plain_length, uint8_t *_Nonnull packet, size_t length);
/** @brief Pack number of nodes into data of maxlength length.
*
* @return length of packed nodes on success.
* @retval -1 on failure.
*/
non_null()
int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_format *nodes, uint16_t number);
int pack_nodes(const Logger *_Nonnull logger, uint8_t *_Nonnull data, uint16_t length, const Node_format *_Nonnull nodes, uint16_t number);
/** @brief Unpack data of length into nodes of size max_num_nodes.
* Put the length of the data processed in processed_data_len.
@@ -217,30 +208,28 @@ int pack_nodes(const Logger *logger, uint8_t *data, uint16_t length, const Node_
* @return number of unpacked nodes on success.
* @retval -1 on failure.
*/
non_null(1, 4) nullable(3)
int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data,
int unpack_nodes(Node_format *_Nonnull nodes, uint16_t max_num_nodes, uint16_t *_Nullable processed_data_len, const uint8_t *_Nonnull data,
uint16_t length, bool tcp_enabled);
/*----------------------------------------------------------------------------------*/
typedef int cryptopacket_handler_cb(void *object, const IP_Port *source, const uint8_t *source_pubkey,
const uint8_t *packet, uint16_t length, void *userdata);
typedef int cryptopacket_handler_cb(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull source_pubkey,
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
typedef struct DHT DHT;
non_null() const uint8_t *dht_get_self_public_key(const DHT *dht);
non_null() const uint8_t *dht_get_self_secret_key(const DHT *dht);
non_null() void dht_set_self_public_key(DHT *dht, const uint8_t *key);
non_null() void dht_set_self_secret_key(DHT *dht, const uint8_t *key);
const uint8_t *_Nonnull dht_get_self_public_key(const DHT *_Nonnull dht);
const uint8_t *_Nonnull dht_get_self_secret_key(const DHT *_Nonnull dht);
void dht_set_self_public_key(DHT *_Nonnull dht, const uint8_t *_Nonnull key);
void dht_set_self_secret_key(DHT *_Nonnull dht, const uint8_t *_Nonnull key);
non_null() Networking_Core *dht_get_net(const DHT *dht);
non_null() struct Ping *dht_get_ping(const DHT *dht);
non_null() const Client_data *dht_get_close_clientlist(const DHT *dht);
non_null() const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num);
non_null() uint16_t dht_get_num_friends(const DHT *dht);
Networking_Core *_Nonnull dht_get_net(const DHT *_Nonnull dht);
struct Ping *_Nonnull dht_get_ping(const DHT *_Nonnull dht);
const Client_data *_Nonnull dht_get_close_clientlist(const DHT *_Nonnull dht);
const Client_data *_Nonnull dht_get_close_client(const DHT *_Nonnull dht, uint32_t client_num);
uint16_t dht_get_num_friends(const DHT *_Nonnull dht);
non_null() DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num);
non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num);
DHT_Friend *_Nonnull dht_get_friend(DHT *_Nonnull dht, uint32_t friend_num);
const uint8_t *_Nonnull dht_get_friend_public_key(const DHT *_Nonnull dht, uint32_t friend_num);
/*----------------------------------------------------------------------------------*/
@@ -248,15 +237,13 @@ non_null() const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t fri
* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive.
*/
non_null()
const uint8_t *dht_get_shared_key_recv(DHT *dht, const uint8_t *public_key);
const uint8_t *_Nullable dht_get_shared_key_recv(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
/**
* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send.
*/
non_null()
const uint8_t *dht_get_shared_key_sent(DHT *dht, const uint8_t *public_key);
const uint8_t *_Nullable dht_get_shared_key_sent(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
/**
* Sends a nodes request to `ip_port` with the public key `public_key` for nodes
@@ -264,17 +251,14 @@ const uint8_t *dht_get_shared_key_sent(DHT *dht, const uint8_t *public_key);
*
* @retval true on success.
*/
non_null()
bool dht_send_nodes_request(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *client_id);
bool dht_send_nodes_request(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull client_id);
typedef void dht_ip_cb(void *object, int32_t number, const IP_Port *ip_port);
typedef void dht_ip_cb(void *_Nullable object, int32_t number, const IP_Port *_Nonnull ip_port);
typedef void dht_nodes_response_cb(const DHT *dht, const Node_format *node, void *user_data);
typedef void dht_nodes_response_cb(const DHT *_Nonnull dht, const Node_format *_Nonnull node, void *_Nullable user_data);
/** Sets the callback to be triggered on a nodes response. */
non_null(1) nullable(2)
void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function);
void dht_callback_nodes_response(DHT *_Nonnull dht, dht_nodes_response_cb *_Nullable function);
/** @brief Add a new friend to the friends list.
* @param public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
*
@@ -289,10 +273,8 @@ void dht_callback_nodes_response(DHT *dht, dht_nodes_response_cb *function);
* @retval 0 if success.
* @retval -1 if failure (friends list is full).
*/
non_null(1, 2, 6) nullable(3, 4)
int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
void *data, int32_t number, uint32_t *lock_token);
int dht_addfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, dht_ip_cb *_Nullable ip_callback,
void *_Nullable data, int32_t number, uint32_t *_Nonnull lock_token);
/** @brief Delete a friend from the friends list.
* public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
* @param dht The DHT object
@@ -302,8 +284,7 @@ int dht_addfriend(DHT *dht, const uint8_t *public_key, dht_ip_cb *ip_callback,
* @retval 0 if success.
* @retval -1 if failure (public_key not in friends list).
*/
non_null()
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token);
int dht_delfriend(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, uint32_t lock_token);
/** @brief Get ip of friend.
*
@@ -313,8 +294,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint32_t lock_token);
* @retval 0 if public_key refers to a friend and we failed to find the friend (yet)
* @retval 1 if public_key refers to a friend and we found him
*/
non_null()
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
int dht_getfriendip(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, IP_Port *_Nonnull ip_port);
/** @brief Compares pk1 and pk2 with pk.
*
@@ -322,31 +302,25 @@ int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
* @retval 1 if pk1 is closer.
* @retval 2 if pk2 is closer.
*/
non_null()
int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2);
int id_closest(const uint8_t *_Nonnull pk, const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2);
/** Return index of first unequal bit number between public keys pk1 and pk2. */
non_null()
unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2);
unsigned int bit_by_bit_cmp(const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2);
/**
* Add node to the node list making sure only the nodes closest to cmp_pk are in the list.
*
* @return true iff the node was added to the list.
*/
non_null()
bool add_to_list(
Node_format *nodes_list, uint32_t length, const uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE],
const IP_Port *ip_port, const uint8_t cmp_pk[CRYPTO_PUBLIC_KEY_SIZE]);
bool add_to_list(Node_format *_Nonnull nodes_list, uint32_t length, const uint8_t pk[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const IP_Port *_Nonnull ip_port,
const uint8_t cmp_pk[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
/** Return 1 if node can be added to close list, 0 if it can't. */
non_null()
bool node_addable_to_close_list(DHT *dht, const uint8_t *public_key, const IP_Port *ip_port);
bool node_addable_to_close_list(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const IP_Port *_Nonnull ip_port);
#ifdef CHECK_ANNOUNCE_NODE
/** Set node as announce node. */
non_null()
void set_announce_node(DHT *dht, const uint8_t *public_key);
void set_announce_node(DHT *_Nonnull dht, const uint8_t *_Nonnull public_key);
#endif /* CHECK_ANNOUNCE_NODE */
/**
@@ -359,11 +333,7 @@ void set_announce_node(DHT *dht, const uint8_t *public_key);
*
* @return the number of nodes returned.
*/
non_null()
int get_close_nodes(
const DHT *dht, const uint8_t *public_key,
Node_format nodes_list[MAX_SENT_NODES], Family sa_family,
bool is_lan, bool want_announce);
int get_close_nodes(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, Node_format nodes_list[_Nonnull MAX_SENT_NODES], Family sa_family, bool is_lan, bool want_announce);
/** @brief Put up to max_num nodes in nodes from the random friends.
*
@@ -372,19 +342,16 @@ int get_close_nodes(
*
* @return the number of nodes.
*/
non_null()
uint16_t randfriends_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t randfriends_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
/** @brief Put up to max_num nodes in nodes from the closelist.
*
* @return the number of nodes.
*/
non_null()
uint16_t closelist_nodes(const DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t closelist_nodes(const DHT *_Nonnull dht, Node_format *_Nonnull nodes, uint16_t max_num);
/** Run this function at least a couple times per second (It's the main loop). */
non_null()
void do_dht(DHT *dht);
void do_dht(DHT *_Nonnull dht);
/*
* Use these two functions to bootstrap the client.
@@ -393,8 +360,7 @@ void do_dht(DHT *dht);
* @brief Sends a "nodes request" to the given node with ip, port and public_key
* to setup connections
*/
non_null()
bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
bool dht_bootstrap(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
/** @brief Resolves address into an IP address.
*
@@ -409,17 +375,14 @@ bool dht_bootstrap(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
* @retval true if the address could be converted into an IP address
* @retval false otherwise
*/
non_null()
bool dht_bootstrap_from_address(DHT *dht, const char *address, bool ipv6enabled, bool dns_enabled,
uint16_t port, const uint8_t *public_key);
bool dht_bootstrap_from_address(DHT *_Nonnull dht, const char *_Nonnull address, bool ipv6enabled, bool dns_enabled, uint16_t port, const uint8_t *_Nonnull public_key);
/** @brief Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
*
* @retval 0 if successful
* @retval -1 otherwise
*/
non_null()
int dht_connect_after_load(DHT *dht);
int dht_connect_after_load(DHT *_Nonnull dht);
/* ROUTING FUNCTIONS */
@@ -428,8 +391,7 @@ int dht_connect_after_load(DHT *dht);
* @return number of bytes sent.
* @retval -1 if failure.
*/
non_null()
int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packet, uint16_t length);
int route_packet(const DHT *_Nonnull dht, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet, uint16_t length);
/**
* Send the following packet to everyone who tells us they are connected to friend_id.
@@ -437,52 +399,41 @@ int route_packet(const DHT *dht, const uint8_t *public_key, const uint8_t *packe
* @return ip for friend.
* @return number of nodes the packet was sent to. (Only works if more than (MAX_FRIEND_CLIENTS / 4).
*/
non_null()
uint32_t route_to_friend(const DHT *dht, const uint8_t *friend_id, const Packet *packet);
uint32_t route_to_friend(const DHT *_Nonnull dht, const uint8_t *_Nonnull friend_id, const Packet *_Nonnull packet);
/** Function to handle crypto packets. */
non_null(1) nullable(3, 4)
void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_cb *cb, void *object);
void cryptopacket_registerhandler(DHT *_Nonnull dht, uint8_t byte, cryptopacket_handler_cb *_Nullable cb, void *_Nullable object);
/* SAVE/LOAD functions */
/** Get the size of the DHT (for saving). */
non_null()
uint32_t dht_size(const DHT *dht);
uint32_t dht_size(const DHT *_Nonnull dht);
/** Save the DHT in data where data is an array of size `dht_size()`. */
non_null()
void dht_save(const DHT *dht, uint8_t *data);
void dht_save(const DHT *_Nonnull dht, uint8_t *_Nonnull data);
/** @brief Load the DHT from data of size size.
*
* @retval -1 if failure.
* @retval 0 if success.
*/
non_null()
int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
int dht_load(DHT *_Nonnull dht, const uint8_t *_Nonnull data, uint32_t length);
/** Initialize DHT. */
non_null()
DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Network *ns,
Mono_Time *mono_time, Networking_Core *net, bool hole_punching_enabled, bool lan_discovery_enabled);
nullable(1)
void kill_dht(DHT *dht);
DHT *_Nullable new_dht(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time, Networking_Core *_Nonnull net,
bool hole_punching_enabled, bool lan_discovery_enabled);
void kill_dht(DHT *_Nullable dht);
/**
* @retval false if we are not connected to the DHT.
* @retval true if we are.
*/
non_null()
bool dht_isconnected(const DHT *dht);
bool dht_isconnected(const DHT *_Nonnull dht);
/**
* @retval false if we are not connected or only connected to lan peers with the DHT.
* @retval true if we are.
*/
non_null()
bool dht_non_lan_connected(const DHT *dht);
bool dht_non_lan_connected(const DHT *_Nonnull dht);
/**
* This function returns the ratio of close dht nodes that are known to support announce/store.
@@ -490,8 +441,7 @@ bool dht_non_lan_connected(const DHT *dht);
*
* @return number
*/
non_null()
uint16_t dht_get_num_closelist(const DHT *dht);
uint16_t dht_get_num_closelist(const DHT *_Nonnull dht);
/**
* This function returns the number of DHT nodes in the closelist,
@@ -499,16 +449,14 @@ uint16_t dht_get_num_closelist(const DHT *dht);
*
* @return number
*/
non_null()
uint16_t dht_get_num_closelist_announce_capable(const DHT *dht);
uint16_t dht_get_num_closelist_announce_capable(const DHT *_Nonnull dht);
/** @brief Attempt to add client with ip_port and public_key to the friends client list
* and close_clientlist.
*
* @return 1+ if the item is used in any list, 0 else
*/
non_null()
uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key);
uint32_t addto_lists(DHT *_Nonnull dht, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
/** @brief Copies our own ip_port structure to `dest`.
*
@@ -520,8 +468,7 @@ uint32_t addto_lists(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key
* @retval 1 if IP is a WAN address.
* @retval 2 if IP is a LAN address.
*/
non_null()
unsigned int ipport_self_copy(const DHT *dht, IP_Port *dest);
unsigned int ipport_self_copy(const DHT *_Nonnull dht, IP_Port *_Nonnull dest);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -53,8 +53,7 @@ struct Broadcast_Info {
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
non_null()
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
{
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -124,11 +123,9 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
#elif !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) && (defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__))
non_null()
static bool ip4_is_local(const IP4 *ip4);
static bool ip4_is_local(const IP4 *_Nonnull ip4);
non_null()
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
{
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -222,8 +219,7 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
#else // TODO(irungentoo): Other platforms?
non_null()
static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns)
static Broadcast_Info *fetch_broadcast_info(const Memory *_Nonnull mem, const Network *_Nonnull ns)
{
Broadcast_Info *broadcast = (Broadcast_Info *)mem_alloc(mem, sizeof(Broadcast_Info));
@@ -243,9 +239,7 @@ static Broadcast_Info *fetch_broadcast_info(const Memory *mem, const Network *ns
* @retval true if sent to at least one broadcast target.
* @retval false on failure to find any valid broadcast target.
*/
non_null()
static bool send_broadcasts(const Networking_Core *net, const Broadcast_Info *broadcast, uint16_t port,
const uint8_t *data, uint16_t length)
static bool send_broadcasts(const Networking_Core *_Nonnull net, const Broadcast_Info *_Nonnull broadcast, uint16_t port, const uint8_t *_Nonnull data, uint16_t length)
{
if (broadcast->count == 0) {
return false;
@@ -288,8 +282,7 @@ static IP broadcast_ip(Family family_socket, Family family_broadcast)
return ip;
}
non_null()
static bool ip4_is_local(const IP4 *ip4)
static bool ip4_is_local(const IP4 *_Nonnull ip4)
{
/* Loopback. */
return ip4->uint8[0] == 127;
@@ -315,8 +308,7 @@ bool ip_is_local(const IP *ip)
return ip->ip.v6.uint64[0] == 0 && ip->ip.v6.uint32[2] == 0 && ip->ip.v6.uint32[3] == net_htonl(1);
}
non_null()
static bool ip4_is_lan(const IP4 *ip4)
static bool ip4_is_lan(const IP4 *_Nonnull ip4)
{
/* 10.0.0.0 to 10.255.255.255 range. */
if (ip4->uint8[0] == 10) {

View File

@@ -25,34 +25,27 @@ typedef struct Broadcast_Info Broadcast_Info;
*
* @return true on success, false on failure.
*/
non_null()
bool lan_discovery_send(const Networking_Core *net, const Broadcast_Info *broadcast, const uint8_t *dht_pk,
uint16_t port);
bool lan_discovery_send(const Networking_Core *_Nonnull net, const Broadcast_Info *_Nonnull broadcast, const uint8_t *_Nonnull dht_pk, uint16_t port);
/**
* Discovers broadcast devices and IP addresses.
*/
non_null()
Broadcast_Info *lan_discovery_init(const Memory *mem, const Network *ns);
Broadcast_Info *_Nullable lan_discovery_init(const Memory *_Nonnull mem, const Network *_Nonnull ns);
/**
* Free all resources associated with the broadcast info.
*/
nullable(1)
void lan_discovery_kill(Broadcast_Info *broadcast);
void lan_discovery_kill(Broadcast_Info *_Nullable broadcast);
/**
* Is IP a local ip or not.
*/
non_null()
bool ip_is_local(const IP *ip);
bool ip_is_local(const IP *_Nonnull ip);
/**
* Checks if a given IP isn't routable.
*
* @return true if ip is a LAN ip, false if it is not.
*/
non_null()
bool ip_is_lan(const IP *ip);
bool ip_is_lan(const IP *_Nonnull ip);
#endif /* C_TOXCORE_TOXCORE_LAN_DISCOVERY_H */

View File

@@ -61,8 +61,7 @@ bool friend_is_valid(const Messenger *m, int32_t friendnumber)
*
* @retval -1 if mem_vrealloc fails.
*/
non_null()
static int realloc_friendlist(Messenger *m, uint32_t num)
static int realloc_friendlist(Messenger *_Nonnull m, uint32_t num)
{
if (num == 0) {
mem_delete(m->mem, m->friendlist);
@@ -137,32 +136,25 @@ void getaddress(const Messenger *m, uint8_t *address)
memcpy(address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(nospam), &checksum, sizeof(checksum));
}
non_null()
static bool send_online_packet(const Messenger *m, int friendcon_id)
static bool send_online_packet(const Messenger *_Nonnull m, int friendcon_id)
{
const uint8_t packet[1] = {PACKET_ID_ONLINE};
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
sizeof(packet), false) != -1;
}
non_null()
static bool send_offline_packet(const Messenger *m, int friendcon_id)
static bool send_offline_packet(const Messenger *_Nonnull m, int friendcon_id)
{
const uint8_t packet[1] = {PACKET_ID_OFFLINE};
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, friendcon_id), packet,
sizeof(packet), false) != -1;
}
non_null(1) nullable(4)
static int m_handle_status(void *object, int friendcon_id, bool status, void *userdata);
non_null(1, 3) nullable(5)
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
non_null(1, 3) nullable(5)
static int m_handle_lossy_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length,
void *userdata);
non_null()
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata);
static int m_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
static int m_handle_lossy_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length,
void *_Nullable userdata);
static int32_t init_new_friend(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk, uint8_t status)
{
if (m->numfriends == UINT32_MAX) {
LOGGER_ERROR(m->log, "Friend list full: we have more than 4 billion friends");
@@ -211,8 +203,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta
return FAERR_NOMEM;
}
non_null()
static int32_t m_add_friend_contact_norequest(Messenger *m, const uint8_t *real_pk)
static int32_t m_add_friend_contact_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk)
{
if (getfriend_id(m, real_pk) != -1) {
return FAERR_ALREADYSENT;
@@ -320,8 +311,7 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk)
return m_add_friend_contact_norequest(m, real_pk);
}
non_null()
static int clear_receipts(Messenger *m, int32_t friendnumber)
static int clear_receipts(Messenger *_Nonnull m, int32_t friendnumber)
{
if (!m_friend_exists(m, friendnumber)) {
return -1;
@@ -340,8 +330,7 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
return 0;
}
non_null()
static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
static int add_receipt(Messenger *_Nonnull m, int32_t friendnumber, uint32_t packet_num, uint32_t msg_id)
{
if (!m_friend_exists(m, friendnumber)) {
return -1;
@@ -370,8 +359,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
* return -1 on failure.
* return 0 if packet was received.
*/
non_null()
static int friend_received_packet(const Messenger *m, int32_t friendnumber, uint32_t number)
static int friend_received_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t number)
{
if (!m_friend_exists(m, friendnumber)) {
return -1;
@@ -428,8 +416,7 @@ void m_kill_group_connection(Messenger *m, const GC_Chat *chat)
kill_friend_connection(m->fr_c, chat->friend_connection_id);
}
non_null(1) nullable(3)
static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
static int do_receipts(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
{
if (!m_friend_exists(m, friendnumber)) {
return -1;
@@ -606,9 +593,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
return 0;
}
non_null()
static bool write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length, bool congestion_control)
static bool write_cryptpacket_id(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t packet_id, const uint8_t *_Nonnull data, uint32_t length, bool congestion_control)
{
if (!m_friend_exists(m, friendnumber)) {
return false;
@@ -631,8 +616,7 @@ static bool write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8
/** @brief Send a name packet to friendnumber.
* length is the length with the NULL terminator.
*/
non_null()
static bool m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
static bool m_sendname(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length)
{
if (length > MAX_NAME_LENGTH) {
return false;
@@ -771,8 +755,7 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
return 0;
}
non_null()
static bool userstatus_from_int(uint8_t status, Userstatus *out_enum)
static bool userstatus_from_int(uint8_t status, Userstatus *_Nonnull out_enum)
{
switch (status) {
case USERSTATUS_NONE: {
@@ -927,27 +910,23 @@ int m_get_istyping(const Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].is_typing ? 1 : 0;
}
non_null()
static bool send_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
static bool send_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length, false);
}
non_null()
static bool send_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
static bool send_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status), false);
}
non_null()
static bool send_user_istyping(const Messenger *m, int32_t friendnumber, bool is_typing)
static bool send_user_istyping(const Messenger *_Nonnull m, int32_t friendnumber, bool is_typing)
{
const uint8_t typing = is_typing ? 1 : 0;
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing), false);
}
non_null()
static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
static int set_friend_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull status, uint16_t length)
{
if (!m_friend_exists(m, friendnumber)) {
return -1;
@@ -965,14 +944,12 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
return 0;
}
non_null()
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
static void set_friend_userstatus(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t status)
{
userstatus_from_int(status, &m->friendlist[friendnumber].userstatus);
}
non_null()
static void set_friend_typing(const Messenger *m, int32_t friendnumber, bool is_typing)
static void set_friend_typing(const Messenger *_Nonnull m, int32_t friendnumber, bool is_typing)
{
m->friendlist[friendnumber].is_typing = is_typing;
}
@@ -1024,11 +1001,9 @@ void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *funct
m->core_connection_change = function;
}
non_null(1) nullable(3)
static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userdata)
static void check_friend_tcp_udp(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
{
const int last_connection_udp_tcp = m->friendlist[friendnumber].last_connection_udp_tcp;
const int ret = m_get_friend_connectionstatus(m, friendnumber);
if (ret == -1) {
@@ -1044,11 +1019,9 @@ static void check_friend_tcp_udp(Messenger *m, int32_t friendnumber, void *userd
m->friendlist[friendnumber].last_connection_udp_tcp = (Connection_Status)ret;
}
non_null()
static void break_files(const Messenger *m, int32_t friendnumber);
static void break_files(const Messenger *_Nonnull m, int32_t friendnumber);
non_null(1) nullable(4)
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
static void check_friend_connectionstatus(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
{
if (status == NOFRIEND) {
return;
@@ -1074,8 +1047,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui
}
}
non_null(1) nullable(4)
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata)
static void set_friend_status(Messenger *_Nonnull m, int32_t friendnumber, uint8_t status, void *_Nullable userdata)
{
check_friend_connectionstatus(m, friendnumber, status, userdata);
m->friendlist[friendnumber].status = status;
@@ -1193,9 +1165,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* @retval 1 on success
* @retval 0 on failure
*/
non_null()
static bool file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type,
uint64_t filesize, const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
static bool file_sendrequest(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, uint64_t filesize, const uint8_t *_Nonnull file_id,
const uint8_t *_Nonnull filename, uint16_t filename_length)
{
if (!m_friend_exists(m, friendnumber)) {
return false;
@@ -1274,12 +1245,10 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
return i;
}
non_null(1) nullable(6)
static bool send_file_control_packet(const Messenger *m, int32_t friendnumber, bool inbound, uint8_t filenumber,
uint8_t control_type, const uint8_t *data, uint16_t data_length)
static bool send_file_control_packet(const Messenger *_Nonnull m, int32_t friendnumber, bool inbound, uint8_t filenumber,
uint8_t control_type, const uint8_t *_Nullable data, uint16_t data_length)
{
assert(data_length == 0 || data != nullptr);
if ((unsigned int)(1 + 3 + data_length) > MAX_CRYPTO_DATA_SIZE) {
return false;
}
@@ -1475,12 +1444,10 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
/** @return packet number on success.
* @retval -1 on failure.
*/
non_null(1) nullable(4)
static int64_t send_file_data_packet(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data,
static int64_t send_file_data_packet(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t filenumber, const uint8_t *_Nullable data,
uint16_t length)
{
assert(length == 0 || data != nullptr);
if (!m_friend_exists(m, friendnumber)) {
return -1;
}
@@ -1588,8 +1555,7 @@ int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber
* @return true if there's still work to do, false otherwise.
*
*/
non_null()
static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userdata, uint32_t *free_slots)
static bool do_all_filetransfers(Messenger *_Nonnull m, int32_t friendnumber, void *_Nonnull userdata, uint32_t *_Nonnull free_slots)
{
Friend *const friendcon = &m->friendlist[friendnumber];
@@ -1656,8 +1622,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
return true;
}
non_null(1) nullable(3)
static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdata)
static void do_reqchunk_filecb(Messenger *_Nonnull m, int32_t friendnumber, void *_Nullable userdata)
{
// We're not currently doing any file transfers.
if (m->friendlist[friendnumber].num_sending_files == 0) {
@@ -1711,9 +1676,7 @@ static void break_files(const Messenger *m, int32_t friendnumber)
}
}
non_null()
static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber,
uint32_t *real_filenumber, Friend *sender)
static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber, uint32_t *_Nonnull real_filenumber, Friend *_Nonnull sender)
{
struct File_Transfers *ft;
@@ -1735,9 +1698,8 @@ static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumbe
/** @retval -1 on failure
* @retval 0 on success.
*/
non_null(1, 6) nullable(8)
static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, uint8_t filenumber,
uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata)
static int handle_filecontrol(Messenger *_Nonnull m, int32_t friendnumber, bool outbound, uint8_t filenumber,
uint8_t control_type, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
{
uint32_t real_filenumber;
struct File_Transfers *ft = get_file_transfer(outbound, filenumber, &real_filenumber, &m->friendlist[friendnumber]);
@@ -1805,8 +1767,8 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
uint64_t position;
if (length != sizeof(position)) {
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %d, but got %d",
friendnumber, filenumber, (uint32_t)sizeof(position), length);
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %u, but got %d",
friendnumber, filenumber, (unsigned int)sizeof(position), length);
return -1;
}
@@ -1822,7 +1784,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound,
if (position >= ft->size) {
LOGGER_DEBUG(m->log,
"file control (friend %d, file %d): seek position %ld exceeds file size %ld",
"file control (friend %d, file %d): seek position %lu exceeds file size %lu",
friendnumber, filenumber, (unsigned long)position, (unsigned long)ft->size);
return -1;
}
@@ -1887,12 +1849,10 @@ int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const u
return 0;
}
non_null(1, 3) nullable(5)
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_custom_lossless_packet(void *_Nonnull object, int friend_num, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
Messenger *m = (Messenger *)object;
if (!m_friend_exists(m, friend_num)) {
return -1;
}
@@ -1944,8 +1904,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
}
/** Function to filter out some friend requests*/
non_null()
static int friend_already_added(void *object, const uint8_t *public_key)
static int friend_already_added(void *_Nonnull object, const uint8_t *_Nonnull public_key)
{
const Messenger *m = (const Messenger *)object;
@@ -1962,11 +1921,9 @@ static int friend_already_added(void *object, const uint8_t *public_key)
* @param friendcon_id friendlist index of the timed-out friend
* @param t time
*/
non_null(1) nullable(4)
static void check_friend_request_timed_out(Messenger *m, uint32_t friendcon_id, uint64_t t, void *userdata)
static void check_friend_request_timed_out(Messenger *_Nonnull m, uint32_t friendcon_id, uint64_t t, void *_Nullable userdata)
{
Friend *f = &m->friendlist[friendcon_id];
if (f->friendrequest_lastsent + f->friendrequest_timeout < t) {
set_friend_status(m, friendcon_id, FRIEND_ADDED, userdata);
/* Double the default timeout every time if friendrequest is assumed
@@ -1976,11 +1933,9 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t friendcon_id,
}
}
non_null(1) nullable(4)
static int m_handle_status(void *object, int friendcon_id, bool status, void *userdata)
static int m_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata)
{
Messenger *m = (Messenger *)object;
if (status) { /* Went online. */
send_online_packet(m, m->friendlist[friendcon_id].friendcon_id);
} else { /* Went offline. */
@@ -1992,8 +1947,7 @@ static int m_handle_status(void *object, int friendcon_id, bool status, void *us
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_offline(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_offline(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length == 0) {
set_friend_status(m, friendcon_id, FRIEND_CONFIRMED, userdata);
@@ -2002,8 +1956,7 @@ static int m_handle_packet_offline(Messenger *m, const int friendcon_id, const u
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_nickname(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length > MAX_NAME_LENGTH) {
return 0;
@@ -2025,8 +1978,7 @@ static int m_handle_packet_nickname(Messenger *m, const int friendcon_id, const
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_statusmessage(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length > MAX_STATUSMESSAGE_LENGTH) {
return 0;
@@ -2046,8 +1998,7 @@ static int m_handle_packet_statusmessage(Messenger *m, const int friendcon_id, c
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_userstatus(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length != 1) {
return 0;
@@ -2067,8 +2018,7 @@ static int m_handle_packet_userstatus(Messenger *m, const int friendcon_id, cons
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_typing(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length != 1) {
return 0;
@@ -2085,8 +2035,8 @@ static int m_handle_packet_typing(Messenger *m, const int friendcon_id, const ui
return 0;
}
non_null(1, 3) nullable(6)
static int m_handle_packet_message(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, const Message_Type message_type, void *userdata)
static int m_handle_packet_message(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, const Message_Type message_type,
void *_Nullable userdata)
{
if (data_length == 0) {
return 0;
@@ -2107,8 +2057,7 @@ static int m_handle_packet_message(Messenger *m, const int friendcon_id, const u
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_invite_conference(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length == 0) {
return 0;
@@ -2121,11 +2070,9 @@ static int m_handle_packet_invite_conference(Messenger *m, const int friendcon_i
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_file_sendrequest(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
const unsigned int head_length = 1 + sizeof(uint32_t) + sizeof(uint64_t) + FILE_ID_LENGTH;
if (data_length < head_length) {
return 0;
}
@@ -2186,8 +2133,7 @@ static int m_handle_packet_file_sendrequest(Messenger *m, const int friendcon_id
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_file_control(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length < 3) {
return 0;
@@ -2217,8 +2163,7 @@ static int m_handle_packet_file_control(Messenger *m, const int friendcon_id, co
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_file_data(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
if (data_length < 1) {
return 0;
@@ -2283,8 +2228,7 @@ static int m_handle_packet_file_data(Messenger *m, const int friendcon_id, const
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id, const uint8_t *data, const uint16_t data_length, void *userdata)
static int m_handle_packet_invite_groupchat(Messenger *_Nonnull m, const int friendcon_id, const uint8_t *_Nonnull data, const uint16_t data_length, void *_Nullable userdata)
{
// first two bytes are messenger packet type and group invite type
if (data_length < 2 + GC_JOIN_DATA_LENGTH) {
@@ -2309,11 +2253,9 @@ static int m_handle_packet_invite_groupchat(Messenger *m, const int friendcon_id
return 0;
}
non_null(1, 3) nullable(5)
static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
static int m_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
{
Messenger *m = (Messenger *)object;
if (length == 0) {
return -1;
}
@@ -2364,11 +2306,9 @@ static int m_handle_packet(void *object, int friendcon_id, const uint8_t *data,
return handle_custom_lossless_packet(object, friendcon_id, data, length, userdata);
}
non_null(1) nullable(2)
static void do_friends(Messenger *m, void *userdata)
static void do_friends(Messenger *_Nonnull m, void *_Nullable userdata)
{
const uint64_t temp_time = mono_time_get(m->mono_time);
for (uint32_t i = 0; i < m->numfriends; ++i) {
if (m->friendlist[i].status == FRIEND_ADDED) {
const int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam,
@@ -2423,11 +2363,9 @@ static void do_friends(Messenger *m, void *userdata)
}
}
non_null(1) nullable(2)
static void m_connection_status_callback(Messenger *m, void *userdata)
static void m_connection_status_callback(Messenger *_Nonnull m, void *_Nullable userdata)
{
const Onion_Connection_Status conn_status = onion_connection_status(m->onion_c);
if (conn_status != m->last_connection_status) {
if (m->core_connection_change != nullptr) {
m->core_connection_change(m, conn_status, userdata);
@@ -2441,8 +2379,7 @@ static void m_connection_status_callback(Messenger *m, void *userdata)
#define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1)
/** id_str should be of length at least IDSTRING_LEN */
non_null()
static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
static char *id_to_string(const uint8_t *_Nonnull pk, char *_Nonnull id_str, size_t length)
{
if (length < IDSTRING_LEN) {
snprintf(id_str, length, "Bad buf length");
@@ -2484,8 +2421,7 @@ uint32_t messenger_run_interval(const Messenger *m)
*
* @retval true if success.
*/
non_null()
static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend)
static bool self_announce_group(const Messenger *_Nonnull m, GC_Chat *_Nonnull chat, Onion_Friend *_Nonnull onion_friend)
{
GC_Public_Announce announce = {{{{{0}}}}};
@@ -2531,13 +2467,12 @@ static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend
memzero(chat->announced_tcp_relay_pk, sizeof(chat->announced_tcp_relay_pk));
}
LOGGER_DEBUG(chat->log, "Published group announce. TCP relays: %d, UDP status: %d", tcp_num,
LOGGER_DEBUG(chat->log, "Published group announce. TCP relays: %d, UDP status: %u", tcp_num,
chat->self_udp_status);
return true;
}
non_null()
static void do_gc_onion_friends(const Messenger *m)
static void do_gc_onion_friends(const Messenger *_Nonnull m)
{
const uint16_t num_friends = onion_get_friend_count(m->onion_c);
@@ -2668,7 +2603,7 @@ void do_messenger(Messenger *m, void *userdata)
if (msgfptr != nullptr) {
char id_str[IDSTRING_LEN];
LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s",
LOGGER_TRACE(m->log, "F[%2d:%2u] <%s> %s",
dht2m[friend_idx], friend_idx, msgfptr->name,
id_to_string(msgfptr->real_pk, id_str, sizeof(id_str)));
} else {
@@ -2759,8 +2694,7 @@ static uint32_t friend_size(void)
return data;
}
non_null()
static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
static uint8_t *friend_save(const struct Saved_Friend *_Nonnull temp, uint8_t *_Nonnull data)
{
#define VALUE_MEMBER(data, name) \
do { \
@@ -2796,8 +2730,7 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
return data;
}
non_null()
static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
static const uint8_t *friend_load(struct Saved_Friend *_Nonnull temp, const uint8_t *_Nonnull data)
{
#define VALUE_MEMBER(data, name) \
do { \
@@ -2833,8 +2766,7 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data
return data;
}
non_null()
static uint32_t m_state_plugins_size(const Messenger *m)
static uint32_t m_state_plugins_size(const Messenger *_Nonnull m)
{
const uint32_t size32 = sizeof(uint32_t);
const uint32_t sizesubhead = size32 * 2;
@@ -2879,8 +2811,7 @@ bool m_register_state_plugin(Messenger *m, State_Type type, m_state_size_cb *siz
return true;
}
non_null()
static uint32_t m_plugin_size(const Messenger *m, State_Type type)
static uint32_t m_plugin_size(const Messenger *_Nonnull m, State_Type type)
{
for (uint8_t i = 0; i < m->options.state_plugins_length; ++i) {
const Messenger_State_Plugin plugin = m->options.state_plugins[i];
@@ -2913,14 +2844,12 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data)
}
// nospam state plugin
non_null()
static uint32_t nospam_keys_size(const Messenger *m)
static uint32_t nospam_keys_size(const Messenger *_Nonnull m)
{
return sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
}
non_null()
static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_nospam_keys(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length != m_plugin_size(m, STATE_TYPE_NOSPAMKEYS)) {
return STATE_LOAD_STATUS_ERROR;
@@ -2939,8 +2868,7 @@ static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uin
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
static uint8_t *save_nospam_keys(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_NOSPAMKEYS);
static_assert(sizeof(get_nospam(m->fr)) == sizeof(uint32_t), "nospam doesn't fit in a 32 bit int");
@@ -2953,14 +2881,12 @@ static uint8_t *save_nospam_keys(const Messenger *m, uint8_t *data)
}
// DHT state plugin
non_null()
static uint32_t m_dht_size(const Messenger *m)
static uint32_t m_dht_size(const Messenger *_Nonnull m)
{
return dht_size(m->dht);
}
non_null()
static uint8_t *save_dht(const Messenger *m, uint8_t *data)
static uint8_t *save_dht(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_DHT);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_DHT);
@@ -2969,22 +2895,19 @@ static uint8_t *save_dht(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status m_dht_load(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status m_dht_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
dht_load(m->dht, data, length); // TODO(endoffile78): Should we throw an error if dht_load fails?
return STATE_LOAD_STATUS_CONTINUE;
}
// friendlist state plugin
non_null()
static uint32_t saved_friendslist_size(const Messenger *m)
static uint32_t saved_friendslist_size(const Messenger *_Nonnull m)
{
return count_friendlist(m) * friend_size();
}
non_null()
static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
static uint8_t *friends_list_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_FRIENDS);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_FRIENDS);
@@ -3034,8 +2957,7 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status friends_list_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
const uint32_t l_friend_size = friend_size();
@@ -3078,8 +3000,7 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
static void pack_groupchats(const GC_Session *_Nonnull c, Bin_Pack *_Nonnull bp)
{
assert(bp != nullptr && c != nullptr);
bin_pack_array(bp, gc_count_groups(c));
@@ -3095,23 +3016,20 @@ static void pack_groupchats(const GC_Session *c, Bin_Pack *bp)
}
}
non_null()
static bool pack_groupchats_handler(const void *obj, const Logger *logger, Bin_Pack *bp)
static bool pack_groupchats_handler(const void *_Nonnull obj, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
{
const GC_Session *session = (const GC_Session *)obj;
pack_groupchats(session, bp);
return true; // TODO(iphydf): Return bool from pack functions.
}
non_null()
static uint32_t saved_groups_size(const Messenger *m)
static uint32_t saved_groups_size(const Messenger *_Nonnull m)
{
const GC_Session *session = m->group_handler;
return bin_pack_obj_size(pack_groupchats_handler, session, m->log);
}
non_null()
static uint8_t *groups_save(const Messenger *m, uint8_t *data)
static uint8_t *groups_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const GC_Session *c = m->group_handler;
@@ -3141,8 +3059,7 @@ static uint8_t *groups_save(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static bool handle_groups_load(void *obj, Bin_Unpack *bu)
static bool handle_groups_load(void *_Nonnull obj, Bin_Unpack *_Nonnull bu)
{
Messenger *m = (Messenger *)obj;
@@ -3169,8 +3086,7 @@ static bool handle_groups_load(void *obj, Bin_Unpack *bu)
return true;
}
non_null()
static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status groups_load(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (!bin_unpack_obj(m->mem, handle_groups_load, m, data, length)) {
LOGGER_ERROR(m->log, "msgpack failed to unpack groupchats array");
@@ -3181,14 +3097,12 @@ static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t
}
// name state plugin
non_null()
static uint32_t name_size(const Messenger *m)
static uint32_t name_size(const Messenger *_Nonnull m)
{
return m->name_length;
}
non_null()
static uint8_t *save_name(const Messenger *m, uint8_t *data)
static uint8_t *save_name(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_NAME);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_NAME);
@@ -3197,8 +3111,7 @@ static uint8_t *save_name(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_name(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length > 0 && length <= MAX_NAME_LENGTH) {
setname(m, data, length);
@@ -3208,14 +3121,12 @@ static State_Load_Status load_name(Messenger *m, const uint8_t *data, uint32_t l
}
// status message state plugin
non_null()
static uint32_t status_message_size(const Messenger *m)
static uint32_t status_message_size(const Messenger *_Nonnull m)
{
return m->statusmessage_length;
}
non_null()
static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
static uint8_t *save_status_message(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUSMESSAGE);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUSMESSAGE);
@@ -3224,8 +3135,7 @@ static uint8_t *save_status_message(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_status_message(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_status_message(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length > 0 && length <= MAX_STATUSMESSAGE_LENGTH) {
m_set_statusmessage(m, data, length);
@@ -3235,14 +3145,12 @@ static State_Load_Status load_status_message(Messenger *m, const uint8_t *data,
}
// status state plugin
non_null()
static uint32_t status_size(const Messenger *m)
static uint32_t status_size(const Messenger *_Nonnull m)
{
return 1;
}
non_null()
static uint8_t *save_status(const Messenger *m, uint8_t *data)
static uint8_t *save_status(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
const uint32_t len = m_plugin_size(m, STATE_TYPE_STATUS);
data = state_write_section_header(data, STATE_COOKIE_TYPE, len, STATE_TYPE_STATUS);
@@ -3251,8 +3159,7 @@ static uint8_t *save_status(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_status(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length == 1) {
m_set_userstatus(m, *data);
@@ -3262,14 +3169,12 @@ static State_Load_Status load_status(Messenger *m, const uint8_t *data, uint32_t
}
// TCP Relay state plugin
non_null()
static uint32_t tcp_relay_size(const Messenger *m)
static uint32_t tcp_relay_size(const Messenger *_Nonnull m)
{
return NUM_SAVED_TCP_RELAYS * packed_node_size(net_family_tcp_ipv6());
}
non_null()
static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
static uint8_t *save_tcp_relays(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
Node_format relays[NUM_SAVED_TCP_RELAYS] = {{{0}}};
uint8_t *temp_data = data;
@@ -3293,8 +3198,7 @@ static uint8_t *save_tcp_relays(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_tcp_relays(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length > 0) {
const int num = unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, true);
@@ -3312,14 +3216,12 @@ static State_Load_Status load_tcp_relays(Messenger *m, const uint8_t *data, uint
}
// path node state plugin
non_null()
static uint32_t path_node_size(const Messenger *m)
static uint32_t path_node_size(const Messenger *_Nonnull m)
{
return NUM_SAVED_PATH_NODES * packed_node_size(net_family_tcp_ipv6());
}
non_null()
static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
static uint8_t *save_path_nodes(const Messenger *_Nonnull m, uint8_t *_Nonnull data)
{
Node_format nodes[NUM_SAVED_PATH_NODES] = {{{0}}};
uint8_t *temp_data = data;
@@ -3336,8 +3238,7 @@ static uint8_t *save_path_nodes(const Messenger *m, uint8_t *data)
return data;
}
non_null()
static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint32_t length)
static State_Load_Status load_path_nodes(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length)
{
if (length > 0) {
Node_format nodes[NUM_SAVED_PATH_NODES];
@@ -3355,8 +3256,7 @@ static State_Load_Status load_path_nodes(Messenger *m, const uint8_t *data, uint
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static void m_register_default_plugins(Messenger *m)
static void m_register_default_plugins(Messenger *_Nonnull m)
{
m_register_state_plugin(m, STATE_TYPE_NOSPAMKEYS, nospam_keys_size, load_nospam_keys, save_nospam_keys);
m_register_state_plugin(m, STATE_TYPE_DHT, m_dht_size, m_dht_load, save_dht);
@@ -3411,7 +3311,7 @@ uint32_t count_friendlist(const Messenger *m)
* If the array was too small, the contents
* of out_list will be truncated to list_size.
*/
uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_size)
uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size)
{
if (out_list == nullptr) {
return 0;
@@ -3438,9 +3338,8 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s
}
static fr_friend_request_cb m_handle_friend_request;
non_null(1, 2, 3) nullable(5)
static void m_handle_friend_request(
void *object, const uint8_t *public_key, const uint8_t *message, size_t length, void *user_data)
void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data)
{
Messenger *m = (Messenger *)object;
assert(m != nullptr);

View File

@@ -54,19 +54,19 @@ typedef struct Messenger Messenger;
#endif /* MESSENGER_DEFINED */
// Returns the size of the data
typedef uint32_t m_state_size_cb(const Messenger *m);
typedef uint32_t m_state_size_cb(const Messenger *_Nonnull m);
// Returns the new pointer to data
typedef uint8_t *m_state_save_cb(const Messenger *m, uint8_t *data);
typedef uint8_t *m_state_save_cb(const Messenger *_Nonnull m, uint8_t *_Nonnull data);
// Returns if there were any erros during loading
typedef State_Load_Status m_state_load_cb(Messenger *m, const uint8_t *data, uint32_t length);
typedef State_Load_Status m_state_load_cb(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length);
typedef struct Messenger_State_Plugin {
State_Type type;
m_state_size_cb *size;
m_state_save_cb *save;
m_state_load_cb *load;
m_state_size_cb *_Nullable size;
m_state_save_cb *_Nullable save;
m_state_load_cb *_Nullable load;
} Messenger_State_Plugin;
typedef struct Messenger_Options {
@@ -81,11 +81,11 @@ typedef struct Messenger_Options {
bool dht_announcements_enabled;
bool groups_persistence_enabled;
logger_cb *log_callback;
void *log_context;
void *log_user_data;
logger_cb *_Nullable log_callback;
void *_Nullable log_context;
void *_Nullable log_user_data;
Messenger_State_Plugin *state_plugins;
Messenger_State_Plugin *_Nullable state_plugins;
uint8_t state_plugins_length;
bool dns_enabled;
@@ -94,7 +94,7 @@ typedef struct Messenger_Options {
struct Receipts {
uint32_t packet_num;
uint32_t msg_id;
struct Receipts *next;
struct Receipts *_Nullable next;
};
/** Status definitions. */
@@ -177,36 +177,36 @@ typedef enum Filekind {
FILEKIND_AVATAR,
} Filekind;
typedef void m_self_connection_status_cb(Messenger *m, Onion_Connection_Status connection_status, void *user_data);
typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data);
typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status,
void *user_data);
typedef void m_friend_message_cb(Messenger *m, uint32_t friend_number, unsigned int message_type,
const uint8_t *message, size_t length, void *user_data);
typedef void m_file_recv_control_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, unsigned int control,
void *user_data);
typedef void m_friend_request_cb(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length,
void *user_data);
typedef void m_friend_name_cb(Messenger *m, uint32_t friend_number, const uint8_t *name, size_t length,
void *user_data);
typedef void m_friend_status_message_cb(Messenger *m, uint32_t friend_number, const uint8_t *message, size_t length,
void *user_data);
typedef void m_friend_typing_cb(Messenger *m, uint32_t friend_number, bool is_typing, void *user_data);
typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t friend_number, uint32_t message_id, void *user_data);
typedef void m_file_recv_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint32_t kind,
uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data);
typedef void m_file_chunk_request_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
size_t length, void *user_data);
typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, uint64_t position,
const uint8_t *data, size_t length, void *user_data);
typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
size_t length, void *user_data);
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data,
size_t length, void *user_data);
typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
void *user_data);
typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length,
const uint8_t *group_name, size_t group_name_length, void *user_data);
typedef void m_self_connection_status_cb(Messenger *_Nonnull m, Onion_Connection_Status connection_status, void *_Nullable user_data);
typedef void m_friend_status_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int status, void *_Nullable user_data);
typedef void m_friend_connection_status_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int connection_status,
void *_Nullable user_data);
typedef void m_friend_message_cb(Messenger *_Nonnull m, uint32_t friend_number, unsigned int message_type,
const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data);
typedef void m_file_recv_control_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, unsigned int control,
void *_Nullable user_data);
typedef void m_friend_request_cb(Messenger *_Nonnull m, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length,
void *_Nullable user_data);
typedef void m_friend_name_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull name, size_t length,
void *_Nullable user_data);
typedef void m_friend_status_message_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull message, size_t length,
void *_Nullable user_data);
typedef void m_friend_typing_cb(Messenger *_Nonnull m, uint32_t friend_number, bool is_typing, void *_Nullable user_data);
typedef void m_friend_read_receipt_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t message_id, void *_Nullable user_data);
typedef void m_file_recv_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint32_t kind,
uint64_t file_size, const uint8_t *_Nonnull filename, size_t filename_length, void *_Nullable user_data);
typedef void m_file_chunk_request_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint64_t position,
size_t length, void *_Nullable user_data);
typedef void m_file_recv_chunk_cb(Messenger *_Nonnull m, uint32_t friend_number, uint32_t file_number, uint64_t position,
const uint8_t *_Nullable data, size_t length, void *_Nullable user_data);
typedef void m_friend_lossy_packet_cb(Messenger *_Nonnull m, uint32_t friend_number, uint8_t packet_id, const uint8_t *_Nonnull data,
size_t length, void *_Nullable user_data);
typedef void m_friend_lossless_packet_cb(Messenger *_Nonnull m, uint32_t friend_number, uint8_t packet_id, const uint8_t *_Nonnull data,
size_t length, void *_Nullable user_data);
typedef void m_conference_invite_cb(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull cookie, uint16_t length,
void *_Nullable user_data);
typedef void m_group_invite_cb(const Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull invite_data, size_t length,
const uint8_t *_Nullable group_name, size_t group_name_length, void *_Nullable user_data);
typedef struct Friend {
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
@@ -236,33 +236,33 @@ typedef struct Friend {
uint32_t num_sending_files;
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
struct Receipts *receipts_start;
struct Receipts *receipts_end;
struct Receipts *_Nullable receipts_start;
struct Receipts *_Nullable receipts_end;
} Friend;
struct Messenger {
Logger *log;
Mono_Time *mono_time;
const Memory *mem;
const Random *rng;
const Network *ns;
Logger *_Nullable log;
Mono_Time *_Nullable mono_time;
const Memory *_Nullable mem;
const Random *_Nullable rng;
const Network *_Nullable ns;
Networking_Core *net;
Net_Crypto *net_crypto;
Net_Profile *tcp_np;
DHT *dht;
Networking_Core *_Nonnull net;
Net_Crypto *_Nonnull net_crypto;
Net_Profile *_Nullable tcp_np;
DHT *_Nonnull dht;
Forwarding *forwarding;
Announcements *announce;
Forwarding *_Nullable forwarding;
Announcements *_Nullable announce;
Onion *onion;
Onion_Announce *onion_a;
Onion_Client *onion_c;
Onion *_Nullable onion;
Onion_Announce *_Nullable onion_a;
Onion_Client *_Nullable onion_c;
Friend_Connections *fr_c;
Friend_Connections *_Nullable fr_c;
TCP_Server *tcp_server;
Friend_Requests *fr;
TCP_Server *_Nullable tcp_server;
Friend_Requests *_Nullable fr;
uint8_t name[MAX_NAME_LENGTH];
uint16_t name_length;
@@ -271,43 +271,43 @@ struct Messenger {
Userstatus userstatus;
Friend *friendlist;
Friend *_Nullable friendlist;
uint32_t numfriends;
uint64_t lastdump;
uint8_t is_receiving_file;
GC_Session *group_handler;
GC_Announces_List *group_announce;
GC_Session *_Nonnull group_handler;
GC_Announces_List *_Nonnull group_announce;
bool has_added_relays; // If the first connection has occurred in do_messenger
uint16_t num_loaded_relays;
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
m_friend_request_cb *friend_request;
m_friend_message_cb *friend_message;
m_friend_name_cb *friend_namechange;
m_friend_status_message_cb *friend_statusmessagechange;
m_friend_status_cb *friend_userstatuschange;
m_friend_typing_cb *friend_typingchange;
m_friend_read_receipt_cb *read_receipt;
m_friend_connection_status_cb *friend_connectionstatuschange;
m_friend_request_cb *_Nullable friend_request;
m_friend_message_cb *_Nullable friend_message;
m_friend_name_cb *_Nullable friend_namechange;
m_friend_status_message_cb *_Nullable friend_statusmessagechange;
m_friend_status_cb *_Nullable friend_userstatuschange;
m_friend_typing_cb *_Nullable friend_typingchange;
m_friend_read_receipt_cb *_Nullable read_receipt;
m_friend_connection_status_cb *_Nullable friend_connectionstatuschange;
struct Group_Chats *conferences_object;
m_conference_invite_cb *conference_invite;
struct Group_Chats *_Nullable conferences_object;
m_conference_invite_cb *_Nullable conference_invite;
m_group_invite_cb *group_invite;
m_group_invite_cb *_Nullable group_invite;
m_file_recv_cb *file_sendrequest;
m_file_recv_control_cb *file_filecontrol;
m_file_recv_chunk_cb *file_filedata;
m_file_chunk_request_cb *file_reqchunk;
m_file_recv_cb *_Nullable file_sendrequest;
m_file_recv_control_cb *_Nullable file_filecontrol;
m_file_recv_chunk_cb *_Nullable file_filedata;
m_file_chunk_request_cb *_Nullable file_reqchunk;
m_friend_lossy_packet_cb *lossy_packethandler;
m_friend_lossless_packet_cb *lossless_packethandler;
m_friend_lossy_packet_cb *_Nullable lossy_packethandler;
m_friend_lossless_packet_cb *_Nullable lossless_packethandler;
m_self_connection_status_cb *core_connection_change;
m_self_connection_status_cb *_Nullable core_connection_change;
Onion_Connection_Status last_connection_status;
Messenger_Options options;
@@ -318,16 +318,14 @@ struct Messenger {
*
* @param friendnumber The index in the friend list.
*/
non_null()
bool friend_is_valid(const Messenger *m, int32_t friendnumber);
bool friend_is_valid(const Messenger *_Nonnull m, int32_t friendnumber);
/**
* Format: `[real_pk (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]`
*
* @param[out] address FRIEND_ADDRESS_SIZE byte address to give to others.
*/
non_null()
void getaddress(const Messenger *m, uint8_t *address);
void getaddress(const Messenger *_Nonnull m, uint8_t *_Nonnull address);
/**
* Add a friend.
@@ -350,8 +348,7 @@ void getaddress(const Messenger *m, uint8_t *address);
* (the nospam for that friend was set to the new one).
* @retval FAERR_NOMEM if increasing the friend list size fails.
*/
non_null()
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
int32_t m_addfriend(Messenger *_Nonnull m, const uint8_t *_Nonnull address, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Add a friend without sending a friendrequest.
* @return the friend number if success.
@@ -360,27 +357,23 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u
* @retval -6 if bad checksum in address.
* @retval -8 if increasing the friend list size fails.
*/
non_null()
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *real_pk);
int32_t m_addfriend_norequest(Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
/** @brief Initializes the friend connection and onion connection for a groupchat.
*
* @retval true on success.
*/
non_null()
bool m_create_group_connection(Messenger *m, GC_Chat *chat);
bool m_create_group_connection(Messenger *_Nonnull m, GC_Chat *_Nonnull chat);
/*
* Kills the friend connection for a groupchat.
*/
non_null()
void m_kill_group_connection(Messenger *m, const GC_Chat *chat);
void m_kill_group_connection(Messenger *_Nonnull m, const GC_Chat *_Nonnull chat);
/** @return the friend number associated to that public key.
* @retval -1 if no such friend.
*/
non_null()
int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
int32_t getfriend_id(const Messenger *_Nonnull m, const uint8_t *_Nonnull real_pk);
/** @brief Copies the public key associated to that friend id into real_pk buffer.
*
@@ -389,22 +382,19 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk);
* @retval 0 if success.
* @retval -1 if failure.
*/
non_null()
int get_real_pk(const Messenger *m, int32_t friendnumber, uint8_t *real_pk);
int get_real_pk(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull real_pk);
/** @return friend connection id on success.
* @retval -1 if failure.
*/
non_null()
int getfriendcon_id(const Messenger *m, int32_t friendnumber);
int getfriendcon_id(const Messenger *_Nonnull m, int32_t friendnumber);
/** @brief Remove a friend.
*
* @retval 0 if success.
* @retval -1 if failure.
*/
non_null()
int m_delfriend(Messenger *m, int32_t friendnumber);
int m_delfriend(Messenger *_Nonnull m, int32_t friendnumber);
/** @brief Checks friend's connection status.
*
@@ -413,8 +403,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber);
* @retval CONNECTION_NONE (0) if friend is not connected to us (Offline).
* @retval -1 on failure.
*/
non_null()
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
int m_get_friend_connectionstatus(const Messenger *_Nonnull m, int32_t friendnumber);
/**
* Checks if there exists a friend with given friendnumber.
@@ -424,8 +413,7 @@ int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
* @retval true if friend exists.
* @retval false if friend doesn't exist.
*/
non_null()
bool m_friend_exists(const Messenger *m, int32_t friendnumber);
bool m_friend_exists(const Messenger *_Nonnull m, int32_t friendnumber);
/** @brief Send a message of type to an online friend.
*
@@ -438,10 +426,8 @@ bool m_friend_exists(const Messenger *m, int32_t friendnumber);
*
* The value in message_id will be passed to your read_receipt callback when the other receives the message.
*/
non_null(1, 4) nullable(6)
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length,
uint32_t *message_id);
int m_send_message_generic(Messenger *_Nonnull m, int32_t friendnumber, uint8_t type, const uint8_t *_Nonnull message, uint32_t length,
uint32_t *_Nullable message_id);
/** @brief Set the name and name_length of a friend.
*
* name must be a string of maximum MAX_NAME_LENGTH length.
@@ -451,8 +437,7 @@ int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, con
* @retval 0 if success.
* @retval -1 if failure.
*/
non_null()
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
int setfriendname(Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull name, uint16_t length);
/** @brief Set our nickname.
*
@@ -463,8 +448,7 @@ int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint1
* @retval 0 if success.
* @retval -1 if failure.
*/
non_null()
int setname(Messenger *m, const uint8_t *name, uint16_t length);
int setname(Messenger *_Nonnull m, const uint8_t *_Nonnull name, uint16_t length);
/**
* @brief Get your nickname.
@@ -475,8 +459,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length);
* @return length of the name.
* @retval 0 on error.
*/
non_null()
uint16_t getself_name(const Messenger *m, uint8_t *name);
uint16_t getself_name(const Messenger *_Nonnull m, uint8_t *_Nonnull name);
/** @brief Get name of friendnumber and put it in name.
*
@@ -485,23 +468,22 @@ uint16_t getself_name(const Messenger *m, uint8_t *name);
* @return length of name if success.
* @retval -1 if failure.
*/
non_null()
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name);
int getname(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull name);
/** @return the length of name, including null on success.
* @retval -1 on failure.
*/
non_null() int m_get_name_size(const Messenger *m, int32_t friendnumber);
non_null() int m_get_self_name_size(const Messenger *m);
int m_get_name_size(const Messenger *_Nonnull m, int32_t friendnumber);
int m_get_self_name_size(const Messenger *_Nonnull m);
/** @brief Set our user status.
* You are responsible for freeing status after.
*
* @retval 0 on success.
* @retval -1 on failure.
* @retval 0 if success.
* @retval -1 if failure.
*/
non_null() int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
non_null() int m_set_userstatus(Messenger *m, uint8_t status);
int m_set_statusmessage(Messenger *_Nonnull m, const uint8_t *_Nonnull status, uint16_t length);
int m_set_userstatus(Messenger *_Nonnull m, uint8_t status);
/**
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
@@ -509,8 +491,8 @@ non_null() int m_set_userstatus(Messenger *m, uint8_t status);
* @return the length of friendnumber's status message, including null on success.
* @retval -1 on failure.
*/
non_null() int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
non_null() int m_get_self_statusmessage_size(const Messenger *m);
int m_get_statusmessage_size(const Messenger *_Nonnull m, int32_t friendnumber);
int m_get_self_statusmessage_size(const Messenger *_Nonnull m);
/** @brief Copy friendnumber's status message into buf, truncating if size is over maxlen.
*
@@ -520,8 +502,8 @@ non_null() int m_get_self_statusmessage_size(const Messenger *m);
* @return the length of the copied data on success
* @retval -1 on failure.
*/
non_null() int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
int m_copy_statusmessage(const Messenger *_Nonnull m, int32_t friendnumber, uint8_t *_Nonnull buf, uint32_t maxlen);
int m_copy_self_statusmessage(const Messenger *_Nonnull m, uint8_t *_Nonnull buf);
/** @brief return one of Userstatus values.
*
@@ -529,13 +511,13 @@ non_null() int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
* As above, the self variant will return our own Userstatus.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
non_null() uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
non_null() uint8_t m_get_self_userstatus(const Messenger *m);
uint8_t m_get_userstatus(const Messenger *_Nonnull m, int32_t friendnumber);
uint8_t m_get_self_userstatus(const Messenger *_Nonnull m);
/** @brief returns timestamp of last time friendnumber was seen online or 0 if never seen.
* if friendnumber is invalid this function will return UINT64_MAX.
*/
non_null() uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
uint64_t m_get_last_online(const Messenger *_Nonnull m, int32_t friendnumber);
/** @brief Set our typing status for a friend.
* You are responsible for turning it on or off.
@@ -543,8 +525,7 @@ non_null() uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null()
int m_set_usertyping(Messenger *m, int32_t friendnumber, bool is_typing);
int m_set_usertyping(Messenger *_Nonnull m, int32_t friendnumber, bool is_typing);
/** @brief Get the typing status of a friend.
*
@@ -552,32 +533,29 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, bool is_typing);
* @retval 0 if friend is not typing.
* @retval 1 if friend is typing.
*/
non_null()
int m_get_istyping(const Messenger *m, int32_t friendnumber);
int m_get_istyping(const Messenger *_Nonnull m, int32_t friendnumber);
/** Set the function that will be executed when a friend request is received. */
non_null(1) nullable(2)
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function);
void m_callback_friendrequest(Messenger *_Nonnull m, m_friend_request_cb *_Nullable function);
/** Set the function that will be executed when a message from a friend is received. */
non_null() void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function);
void m_callback_friendmessage(Messenger *_Nonnull m, m_friend_message_cb *_Nonnull function);
/** @brief Set the callback for name changes.
* You are not responsible for freeing newname.
*/
non_null() void m_callback_namechange(Messenger *m, m_friend_name_cb *function);
void m_callback_namechange(Messenger *_Nonnull m, m_friend_name_cb *_Nonnull function);
/** @brief Set the callback for status message changes.
*
* You are not responsible for freeing newstatus
*/
non_null() void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function);
void m_callback_statusmessage(Messenger *_Nonnull m, m_friend_status_message_cb *_Nonnull function);
/** @brief Set the callback for status type changes. */
non_null() void m_callback_userstatus(Messenger *m, m_friend_status_cb *function);
void m_callback_userstatus(Messenger *_Nonnull m, m_friend_status_cb *_Nonnull function);
/** @brief Set the callback for typing changes. */
non_null() void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function);
void m_callback_typingchange(Messenger *_Nonnull m, m_friend_typing_cb *_Nonnull function);
/** @brief Set the callback for read receipts.
*
@@ -587,7 +565,7 @@ non_null() void m_callback_typingchange(Messenger *m, m_friend_typing_cb *functi
* Since core doesn't track ids for you, receipt may not correspond to any message.
* In that case, you should discard it.
*/
non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function);
void m_callback_read_receipt(Messenger *_Nonnull m, m_friend_read_receipt_cb *_Nonnull function);
/** @brief Set the callback for connection status changes.
*
@@ -599,29 +577,24 @@ non_null() void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *
* "after being previously online" part.
* It's assumed that when adding friends, their connection status is offline.
*/
non_null() void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function);
void m_callback_connectionstatus(Messenger *_Nonnull m, m_friend_connection_status_cb *_Nonnull function);
/** @brief Set the callback for typing changes. */
non_null() void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function);
void m_callback_core_connection(Messenger *_Nonnull m, m_self_connection_status_cb *_Nonnull function);
/*** CONFERENCES */
/** @brief Set the callback for conference invites. */
non_null(1) nullable(2)
void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function);
void m_callback_conference_invite(Messenger *_Nonnull m, m_conference_invite_cb *_Nullable function);
/* Set the callback for group invites.
*/
non_null(1) nullable(2)
void m_callback_group_invite(Messenger *m, m_group_invite_cb *function);
void m_callback_group_invite(Messenger *_Nonnull m, m_group_invite_cb *_Nullable function);
/** @brief Send a conference invite packet.
*
* return true on success
* return false on failure
*/
non_null()
bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
bool send_conference_invite_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint16_t length);
/* Send a group invite packet.
*
@@ -630,22 +603,21 @@ bool send_conference_invite_packet(const Messenger *m, int32_t friendnumber, con
*
* return true on success
*/
non_null()
bool send_group_invite_packet(const Messenger *m, uint32_t friendnumber, const uint8_t *packet, uint16_t length);
bool send_group_invite_packet(const Messenger *_Nonnull m, uint32_t friendnumber, const uint8_t *_Nonnull packet, uint16_t length);
/*** FILE SENDING */
/** @brief Set the callback for file send requests. */
non_null() void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function);
void callback_file_sendrequest(Messenger *_Nonnull m, m_file_recv_cb *_Nonnull function);
/** @brief Set the callback for file control requests. */
non_null() void callback_file_control(Messenger *m, m_file_recv_control_cb *function);
void callback_file_control(Messenger *_Nonnull m, m_file_recv_control_cb *_Nonnull function);
/** @brief Set the callback for file data. */
non_null() void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function);
void callback_file_data(Messenger *_Nonnull m, m_file_recv_chunk_cb *_Nonnull function);
/** @brief Set the callback for file request chunk. */
non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function);
void callback_file_reqchunk(Messenger *_Nonnull m, m_file_chunk_request_cb *_Nonnull function);
/** @brief Copy the file transfer file id to file_id
*
@@ -653,8 +625,7 @@ non_null() void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *fu
* @retval -1 if friend not valid.
* @retval -2 if filenumber not valid
*/
non_null()
int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint8_t *file_id);
int file_get_id(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint8_t *_Nonnull file_id);
/** @brief Send a file send request.
*
@@ -666,9 +637,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
* @retval -3 if no more file sending slots left.
* @retval -4 if could not send packet (friend offline).
*/
non_null()
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
long int new_filesender(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, const uint8_t *_Nonnull file_id, const uint8_t *_Nonnull filename,
uint16_t filename_length);
/** @brief Send a file control request.
*
@@ -682,8 +652,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
* @retval -7 if resume file failed because it wasn't paused.
* @retval -8 if packet failed to send.
*/
non_null()
int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
int file_control(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, unsigned int control);
/** @brief Send a seek file control request.
*
@@ -696,8 +665,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
* @retval -6 if position bad.
* @retval -8 if packet failed to send.
*/
non_null()
int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
int file_seek(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position);
/** @brief Send file data.
*
@@ -710,14 +678,12 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
* @retval -6 if packet queue full.
* @retval -7 if wrong position.
*/
non_null(1) nullable(5)
int send_file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
const uint8_t *data, uint16_t length);
int send_file_data(const Messenger *_Nonnull m, int32_t friendnumber, uint32_t filenumber, uint64_t position,
const uint8_t *_Nullable data, uint16_t length);
/*** CUSTOM PACKETS */
/** @brief Set handlers for custom lossy packets. */
non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler);
void custom_lossy_packet_registerhandler(Messenger *_Nonnull m, m_friend_lossy_packet_cb *_Nonnull lossy_packethandler);
/** @brief High level function to send custom lossy packets.
*
@@ -728,12 +694,10 @@ non_null() void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy
* @retval -5 if packet failed to send because of other error.
* @retval 0 on success.
*/
non_null()
int m_send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
int m_send_custom_lossy_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
/** @brief Set handlers for custom lossless packets. */
non_null()
void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler);
void custom_lossless_packet_registerhandler(Messenger *_Nonnull m, m_friend_lossless_packet_cb *_Nonnull lossless_packethandler);
/** @brief High level function to send custom lossless packets.
*
@@ -744,8 +708,7 @@ void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_pack
* @retval -5 if packet failed to send because of other error.
* @retval 0 on success.
*/
non_null()
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
int send_custom_lossless_packet(const Messenger *_Nonnull m, int32_t friendnumber, const uint8_t *_Nonnull data, uint32_t length);
/*** Messenger constructor/destructor/operations. */
@@ -763,29 +726,23 @@ typedef enum Messenger_Error {
*
* if error is not NULL it will be set to one of the values in the enum above.
*/
non_null()
Messenger *new_messenger(Mono_Time *mono_time, const Memory *mem, const Random *rng, const Network *ns,
Messenger_Options *options, Messenger_Error *error);
Messenger *_Nullable new_messenger(Mono_Time *_Nonnull mono_time, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Messenger_Options *_Nonnull options,
Messenger_Error *_Nonnull error);
/** @brief Run this before closing shop.
*
* Free all datastructures.
*/
nullable(1)
void kill_messenger(Messenger *m);
void kill_messenger(Messenger *_Nullable m);
/** @brief The main loop that needs to be run at least 20 times per second. */
non_null(1) nullable(2)
void do_messenger(Messenger *m, void *userdata);
void do_messenger(Messenger *_Nonnull m, void *_Nullable userdata);
/**
* @brief Return the time in milliseconds before `do_messenger()` should be called again
* for optimal performance.
*
* @return time (in ms) before the next `do_messenger()` needs to be run on success.
*/
non_null()
uint32_t messenger_run_interval(const Messenger *m);
uint32_t messenger_run_interval(const Messenger *_Nonnull m);
/* SAVING AND LOADING FUNCTIONS: */
@@ -794,19 +751,13 @@ uint32_t messenger_run_interval(const Messenger *m);
* @retval true on success
* @retval false on error
*/
non_null()
bool m_register_state_plugin(Messenger *m, State_Type type,
m_state_size_cb *size_callback,
m_state_load_cb *load_callback,
m_state_save_cb *save_callback);
bool m_register_state_plugin(Messenger *_Nonnull m, State_Type type, m_state_size_cb *_Nonnull size_callback, m_state_load_cb *_Nonnull load_callback, m_state_save_cb *_Nonnull save_callback);
/** return size of the messenger data (for saving). */
non_null()
uint32_t messenger_size(const Messenger *m);
uint32_t messenger_size(const Messenger *_Nonnull m);
/** Save the messenger in data (must be allocated memory of size at least `Messenger_size()`) */
non_null()
uint8_t *messenger_save(const Messenger *m, uint8_t *data);
uint8_t *_Nonnull messenger_save(const Messenger *_Nonnull m, uint8_t *_Nonnull data);
/** @brief Load a state section.
*
@@ -816,17 +767,14 @@ uint8_t *messenger_save(const Messenger *m, uint8_t *data);
* @param status Result of loading section is stored here if the section is handled.
* @return true iff section handled.
*/
non_null()
bool messenger_load_state_section(Messenger *m, const uint8_t *data, uint32_t length, uint16_t type,
State_Load_Status *status);
bool messenger_load_state_section(Messenger *_Nonnull m, const uint8_t *_Nonnull data, uint32_t length, uint16_t type, State_Load_Status *_Nonnull status);
/** @brief Return the number of friends in the instance m.
*
* You should use this to determine how much memory to allocate
* for copy_friendlist.
*/
non_null()
uint32_t count_friendlist(const Messenger *m);
uint32_t count_friendlist(const Messenger *_Nonnull m);
/** @brief Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
@@ -834,10 +782,8 @@ uint32_t count_friendlist(const Messenger *m);
* If the array was too small, the contents
* of out_list will be truncated to list_size.
*/
non_null()
uint32_t copy_friendlist(const Messenger *m, uint32_t *out_list, uint32_t list_size);
uint32_t copy_friendlist(const Messenger *_Nonnull m, uint32_t *_Nonnull out_list, uint32_t list_size);
non_null()
bool m_is_receiving_file(Messenger *m);
bool m_is_receiving_file(Messenger *_Nonnull m);
#endif /* C_TOXCORE_TOXCORE_MESSENGER_H */

View File

@@ -107,8 +107,8 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
* @retval true on success
* @retval false on failure
*/
non_null()
static bool connect_sock_to(const Network *ns, const Logger *logger, const Memory *mem, Socket sock, const IP_Port *ip_port, const TCP_Proxy_Info *proxy_info)
static bool connect_sock_to(const Network *_Nonnull ns, const Logger *_Nonnull logger, const Memory *_Nonnull mem, Socket sock, const IP_Port *_Nonnull ip_port,
const TCP_Proxy_Info *_Nonnull proxy_info)
{
Net_Err_Connect err;
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
@@ -133,8 +133,7 @@ static bool connect_sock_to(const Network *ns, const Logger *logger, const Memor
* @retval 1 on success.
* @retval 0 on failure.
*/
non_null()
static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_conn)
static int proxy_http_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
{
const char one[] = "CONNECT ";
const char two[] = " HTTP/1.1\nHost: ";
@@ -164,8 +163,7 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con
* @retval 0 if no data received.
* @retval -1 on failure (connection refused).
*/
non_null()
static int proxy_http_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
static int proxy_http_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
{
const char success[] = "200";
uint8_t data[16]; // draining works the best if the length is a power of 2
@@ -214,8 +212,7 @@ enum Tcp_Socks5_Proxy_Hs {
TCP_SOCKS5_PROXY_HS_ADDR_TYPE_IPV6 = 0x04,
};
non_null()
static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
static void proxy_socks5_generate_greetings(TCP_Client_Connection *_Nonnull tcp_conn)
{
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_AUTH_METHODS_SUPPORTED;
@@ -230,8 +227,7 @@ static void proxy_socks5_generate_greetings(TCP_Client_Connection *tcp_conn)
* @retval 0 if no data received.
* @retval -1 on failure (connection refused).
*/
non_null()
static int socks5_read_handshake_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
static int socks5_read_handshake_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
{
uint8_t data[2];
const TCP_Connection *con = &tcp_conn->con;
@@ -248,8 +244,7 @@ static int socks5_read_handshake_response(const Logger *logger, const TCP_Client
return -1;
}
non_null()
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_conn)
static void proxy_socks5_generate_connection_request(TCP_Client_Connection *_Nonnull tcp_conn)
{
tcp_conn->con.last_packet[0] = TCP_SOCKS5_PROXY_HS_VERSION_SOCKS5;
tcp_conn->con.last_packet[1] = TCP_SOCKS5_PROXY_HS_COMM_ESTABLISH_REQUEST;
@@ -280,8 +275,7 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_
* @retval 0 if no data received.
* @retval -1 on failure (connection refused).
*/
non_null()
static int proxy_socks5_read_connection_response(const Logger *logger, const TCP_Client_Connection *tcp_conn)
static int proxy_socks5_read_connection_response(const Logger *_Nonnull logger, const TCP_Client_Connection *_Nonnull tcp_conn)
{
if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) {
uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)];
@@ -316,8 +310,7 @@ static int proxy_socks5_read_connection_response(const Logger *logger, const TCP
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null()
static int generate_handshake(TCP_Client_Connection *tcp_conn)
static int generate_handshake(TCP_Client_Connection *_Nonnull tcp_conn)
{
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
crypto_new_keypair(tcp_conn->con.rng, plain, tcp_conn->temp_secret_key);
@@ -343,8 +336,7 @@ static int generate_handshake(TCP_Client_Connection *tcp_conn)
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null()
static int handle_handshake(TCP_Client_Connection *tcp_conn, const uint8_t *data)
static int handle_handshake(TCP_Client_Connection *_Nonnull tcp_conn, const uint8_t *_Nonnull data)
{
uint8_t plain[CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE];
const int len = decrypt_data_symmetric(tcp_conn->con.mem, tcp_conn->con.shared_key, data, data + CRYPTO_NONCE_SIZE,
@@ -385,8 +377,8 @@ void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *s
con->status_callback_object = object;
}
non_null() static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con);
non_null() static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con);
static int tcp_send_ping_response(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
static int tcp_send_ping_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con);
/**
* @retval 1 on success.
@@ -472,8 +464,7 @@ void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_call
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int client_send_disconnect_notification(const Logger *logger, TCP_Client_Connection *con, uint8_t id)
static int client_send_disconnect_notification(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t id)
{
uint8_t packet[1 + 1];
packet[0] = TCP_PACKET_DISCONNECT_NOTIFICATION;
@@ -486,7 +477,7 @@ static int client_send_disconnect_notification(const Logger *logger, TCP_Client_
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con)
static int tcp_send_ping_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con)
{
if (con->ping_request_id == 0) {
return 1;
@@ -509,7 +500,7 @@ static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *co
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con)
static int tcp_send_ping_response(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con)
{
if (con->ping_response_id == 0) {
return 1;
@@ -595,7 +586,7 @@ void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwa
TCP_Client_Connection *new_tcp_connection(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile)
const TCP_Proxy_Info *proxy_info, Net_Profile *_Nullable net_profile)
{
assert(logger != nullptr);
assert(mem != nullptr);
@@ -699,8 +690,7 @@ TCP_Client_Connection *new_tcp_connection(
return temp;
}
non_null()
static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_routing_response(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1;
@@ -727,8 +717,7 @@ static int handle_tcp_client_routing_response(TCP_Client_Connection *conn, const
return 0;
}
non_null()
static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_connection_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != 1 + 1) {
return -1;
@@ -754,8 +743,7 @@ static int handle_tcp_client_connection_notification(TCP_Client_Connection *conn
return 0;
}
non_null()
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != 1 + 1) {
return -1;
@@ -785,8 +773,7 @@ static int handle_tcp_client_disconnect_notification(TCP_Client_Connection *conn
return 0;
}
non_null()
static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_ping(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != 1 + sizeof(uint64_t)) {
return -1;
@@ -799,8 +786,7 @@ static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *c
return 0;
}
non_null()
static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
static int handle_tcp_client_pong(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != 1 + sizeof(uint64_t)) {
return -1;
@@ -820,8 +806,7 @@ static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *da
return -1;
}
non_null(1, 2) nullable(4)
static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length, void *userdata)
static int handle_tcp_client_oob_recv(TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
{
if (length <= 1 + CRYPTO_PUBLIC_KEY_SIZE) {
return -1;
@@ -839,9 +824,8 @@ static int handle_tcp_client_oob_recv(TCP_Client_Connection *conn, const uint8_t
* @retval 0 on success
* @retval -1 on failure
*/
non_null(1, 2, 3) nullable(5)
static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection *conn, const uint8_t *data,
uint16_t length, void *userdata)
static int handle_tcp_client_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const uint8_t *_Nonnull data,
uint16_t length, void *_Nullable userdata)
{
if (length <= 1) {
return -1;
@@ -899,8 +883,7 @@ static int handle_tcp_client_packet(const Logger *logger, TCP_Client_Connection
return 0;
}
non_null(1, 2) nullable(3)
static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata)
static bool tcp_process_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, void *_Nullable userdata)
{
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet, sizeof(packet),
@@ -923,9 +906,8 @@ static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn
return true;
}
non_null(1, 2, 3) nullable(4)
static int do_confirmed_tcp(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time,
void *userdata)
static int do_confirmed_tcp(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull conn, const Mono_Time *_Nonnull mono_time,
void *_Nullable userdata)
{
send_pending_data(logger, &conn->con);
tcp_send_ping_response(logger, conn);

View File

@@ -44,78 +44,56 @@ typedef enum TCP_Client_Status {
typedef struct TCP_Client_Connection TCP_Client_Connection;
non_null()
const uint8_t *tcp_con_public_key(const TCP_Client_Connection *con);
non_null()
IP_Port tcp_con_ip_port(const TCP_Client_Connection *con);
non_null()
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *con);
const uint8_t *_Nonnull tcp_con_public_key(const TCP_Client_Connection *_Nonnull con);
IP_Port tcp_con_ip_port(const TCP_Client_Connection *_Nonnull con);
TCP_Client_Status tcp_con_status(const TCP_Client_Connection *_Nonnull con);
non_null()
void *tcp_con_custom_object(const TCP_Client_Connection *con);
non_null()
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *con);
non_null()
void tcp_con_set_custom_object(TCP_Client_Connection *con, void *object);
non_null()
void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
void *_Nullable tcp_con_custom_object(const TCP_Client_Connection *_Nonnull con);
uint32_t tcp_con_custom_uint(const TCP_Client_Connection *_Nonnull con);
void tcp_con_set_custom_object(TCP_Client_Connection *_Nonnull con, void *_Nonnull object);
void tcp_con_set_custom_uint(TCP_Client_Connection *_Nonnull con, uint32_t value);
/** Create new TCP connection to ip_port/public_key */
non_null(1, 2, 3, 4, 5, 6, 7, 8, 9) nullable(10, 11)
TCP_Client_Connection *new_tcp_connection(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Random *rng, const Network *ns,
const IP_Port *ip_port, const uint8_t *public_key, const uint8_t *self_public_key, const uint8_t *self_secret_key,
const TCP_Proxy_Info *proxy_info, Net_Profile *net_profile);
TCP_Client_Connection *_Nullable new_tcp_connection(
const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, const Random *_Nonnull rng, const Network *_Nonnull ns,
const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull self_public_key, const uint8_t *_Nonnull self_secret_key,
const TCP_Proxy_Info *_Nullable proxy_info, Net_Profile *_Nullable net_profile);
/** Run the TCP connection */
non_null(1, 2, 3) nullable(4)
void do_tcp_connection(const Logger *logger, const Mono_Time *mono_time,
TCP_Client_Connection *tcp_connection, void *userdata);
void do_tcp_connection(const Logger *_Nonnull logger, const Mono_Time *_Nonnull mono_time,
TCP_Client_Connection *_Nonnull tcp_connection, void *_Nullable userdata);
/** Kill the TCP connection */
nullable(1)
void kill_tcp_connection(TCP_Client_Connection *tcp_connection);
typedef int tcp_onion_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
void kill_tcp_connection(TCP_Client_Connection *_Nullable tcp_connection);
typedef int tcp_onion_response_cb(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
int send_onion_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *data, uint16_t length);
non_null()
void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *onion_callback, void *object);
int send_onion_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length);
void onion_response_handler(TCP_Client_Connection *_Nonnull con, tcp_onion_response_cb *_Nonnull onion_callback, void *_Nonnull object);
non_null()
int send_forward_request_tcp(const Logger *logger, TCP_Client_Connection *con, const IP_Port *dest, const uint8_t *data,
uint16_t length);
non_null()
void forwarding_handler(TCP_Client_Connection *con, forwarded_response_cb *forwarded_response_callback, void *object);
int send_forward_request_tcp(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const IP_Port *_Nonnull dest, const uint8_t *_Nonnull data, uint16_t length);
void forwarding_handler(TCP_Client_Connection *_Nonnull con, forwarded_response_cb *_Nonnull forwarded_response_callback, void *_Nonnull object);
typedef int tcp_routing_response_cb(void *object, uint8_t connection_id, const uint8_t *public_key);
typedef int tcp_routing_status_cb(void *object, uint32_t number, uint8_t connection_id, uint8_t status);
typedef int tcp_routing_response_cb(void *_Nonnull object, uint8_t connection_id, const uint8_t *_Nonnull public_key);
typedef int tcp_routing_status_cb(void *_Nonnull object, uint32_t number, uint8_t connection_id, uint8_t status);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
int send_routing_request(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key);
non_null()
void routing_response_handler(TCP_Client_Connection *con, tcp_routing_response_cb *response_callback, void *object);
non_null()
void routing_status_handler(TCP_Client_Connection *con, tcp_routing_status_cb *status_callback, void *object);
int send_routing_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull public_key);
void routing_response_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_response_cb *_Nonnull response_callback, void *_Nonnull object);
void routing_status_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_status_cb *_Nonnull status_callback, void *_Nonnull object);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id);
int send_disconnect_request(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t con_id);
/** @brief Set the number that will be used as an argument in the callbacks related to con_id.
*
@@ -124,34 +102,28 @@ int send_disconnect_request(const Logger *logger, TCP_Client_Connection *con, ui
* return 0 on success.
* return -1 on failure.
*/
non_null()
int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32_t number);
int set_tcp_connection_number(TCP_Client_Connection *_Nonnull con, uint8_t con_id, uint32_t number);
typedef int tcp_routing_data_cb(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
uint16_t length, void *userdata);
typedef int tcp_routing_data_cb(void *_Nonnull object, uint32_t number, uint8_t connection_id, const uint8_t *_Nonnull data,
uint16_t length, void *_Nullable userdata);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure.
*/
non_null()
int send_data(const Logger *logger, TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length);
non_null()
void routing_data_handler(TCP_Client_Connection *con, tcp_routing_data_cb *data_callback, void *object);
int send_data(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, uint8_t con_id, const uint8_t *_Nonnull data, uint16_t length);
void routing_data_handler(TCP_Client_Connection *_Nonnull con, tcp_routing_data_cb *_Nonnull data_callback, void *_Nonnull object);
typedef int tcp_oob_data_cb(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata);
typedef int tcp_oob_data_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length,
void *_Nullable userdata);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure.
*/
non_null()
int send_oob_packet(const Logger *logger, TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data,
uint16_t length);
non_null()
void oob_data_handler(TCP_Client_Connection *con, tcp_oob_data_cb *oob_data_callback, void *object);
int send_oob_packet(const Logger *_Nonnull logger, TCP_Client_Connection *_Nonnull con, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length);
void oob_data_handler(TCP_Client_Connection *_Nonnull con, tcp_oob_data_cb *_Nonnull oob_data_callback, void *_Nonnull object);
#endif /* C_TOXCORE_TOXCORE_TCP_CLIENT_H */

View File

@@ -97,8 +97,7 @@ int send_pending_data(const Logger *logger, TCP_Connection *con)
* @retval false on failure (only if mem_alloc fails)
* @retval true on success
*/
non_null()
static bool add_priority(TCP_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
static bool add_priority(TCP_Connection *_Nonnull con, const uint8_t *_Nonnull packet, uint16_t size, uint16_t sent)
{
TCP_Priority_List *p = con->priority_queue_end;
TCP_Priority_List *new_list = (TCP_Priority_List *)mem_alloc(con->mem, sizeof(TCP_Priority_List));
@@ -235,8 +234,7 @@ int read_tcp_packet(
* return 0 if nothing has been read from socket.
* return -1 on failure.
*/
non_null()
static uint16_t read_tcp_length(const Logger *logger, const Network *ns, Socket sock, const IP_Port *ip_port)
static uint16_t read_tcp_length(const Logger *_Nonnull logger, const Network *_Nonnull ns, Socket sock, const IP_Port *_Nonnull ip_port)
{
const uint16_t count = net_socket_data_recv_buffer(ns, sock);

View File

@@ -15,15 +15,13 @@
typedef struct TCP_Priority_List TCP_Priority_List;
struct TCP_Priority_List {
TCP_Priority_List *next;
TCP_Priority_List *_Nullable next;
uint16_t size;
uint16_t sent;
uint8_t *data;
uint8_t *_Nonnull data;
};
non_null(1) nullable(2)
void wipe_priority_list(const Memory *mem, TCP_Priority_List *p);
void wipe_priority_list(const Memory *_Nonnull mem, TCP_Priority_List *_Nullable p);
#define NUM_RESERVED_PORTS 16
#define NUM_CLIENT_CONNECTIONS (256 - NUM_RESERVED_PORTS)
@@ -54,9 +52,9 @@ typedef enum Tcp_Packet {
#define MAX_PACKET_SIZE 2048
typedef struct TCP_Connection {
const Memory *mem;
const Random *rng;
const Network *ns;
const Memory *_Nonnull mem;
const Random *_Nonnull rng;
const Network *_Nonnull ns;
Socket sock;
IP_Port ip_port; // for debugging.
uint8_t sent_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of sent packets. */
@@ -65,57 +63,47 @@ typedef struct TCP_Connection {
uint16_t last_packet_length;
uint16_t last_packet_sent;
TCP_Priority_List *priority_queue_start;
TCP_Priority_List *priority_queue_end;
TCP_Priority_List *_Nullable priority_queue_start;
TCP_Priority_List *_Nullable priority_queue_end;
// This is a shared pointer to the parent's respective Net_Profile object
// (either TCP_Server for TCP server packets or TCP_Connections for TCP client packets).
Net_Profile *net_profile;
Net_Profile *_Nullable net_profile;
} TCP_Connection;
/**
* @retval 0 if pending data was sent completely
* @retval -1 if it wasn't
*/
non_null()
int send_pending_data_nonpriority(const Logger *logger, TCP_Connection *con);
int send_pending_data_nonpriority(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
/**
* @retval 0 if pending data was sent completely
* @retval -1 if it wasn't
*/
non_null()
int send_pending_data(const Logger *logger, TCP_Connection *con);
int send_pending_data(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con);
/**
* @retval 1 on success.
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
int write_packet_tcp_secure_connection(
const Logger *logger, TCP_Connection *con, const uint8_t *data, uint16_t length,
bool priority);
int write_packet_tcp_secure_connection(const Logger *_Nonnull logger, TCP_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length, bool priority);
/** @brief Read length bytes from socket.
*
* return length on success
* return -1 on failure/no data in buffer.
*/
non_null()
int read_tcp_packet(
const Logger *logger, const Memory *mem, const Network *ns, Socket sock, uint8_t *data, uint16_t length, const IP_Port *ip_port);
int read_tcp_packet(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Socket sock, uint8_t *_Nonnull data, uint16_t length,
const IP_Port *_Nonnull ip_port);
/**
* @return length of received packet on success.
* @retval 0 if could not read any packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
int read_packet_tcp_secure_connection(
const Logger *logger, const Memory *mem, const Network *ns,
Socket sock, uint16_t *next_packet_length,
const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data,
uint16_t max_len, const IP_Port *ip_port);
int read_packet_tcp_secure_connection(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Socket sock, uint16_t *_Nonnull next_packet_length,
const uint8_t *_Nonnull shared_key, uint8_t *_Nonnull recv_nonce, uint8_t *_Nonnull data, uint16_t max_len, const IP_Port *_Nonnull ip_port);
#endif /* C_TOXCORE_TOXCORE_TCP_COMMON_H */

View File

@@ -80,8 +80,7 @@ uint32_t tcp_connections_count(const TCP_Connections *tcp_c)
* @retval -1 if mem_vrealloc fails.
* @retval 0 if it succeeds.
*/
non_null()
static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **array, size_t num)
static int realloc_tcp_connection_to(const Memory *_Nonnull mem, TCP_Connection_to *_Nullable *_Nonnull array, size_t num)
{
if (num == 0) {
mem_delete(mem, *array);
@@ -101,8 +100,7 @@ static int realloc_tcp_connection_to(const Memory *mem, TCP_Connection_to **arra
return 0;
}
non_null()
static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
static int realloc_tcp_con(const Memory *_Nonnull mem, TCP_con *_Nullable *_Nonnull array, size_t num)
{
if (num == 0) {
mem_delete(mem, *array);
@@ -124,8 +122,7 @@ static int realloc_tcp_con(const Memory *mem, TCP_con **array, size_t num)
/**
* Return true if the connections_number is valid.
*/
non_null()
static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connections_number)
static bool connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int connections_number)
{
if ((unsigned int)connections_number >= tcp_c->connections_length) {
return false;
@@ -141,8 +138,7 @@ static bool connections_number_is_valid(const TCP_Connections *tcp_c, int connec
/**
* Return true if the tcp_connections_number is valid.
*/
non_null()
static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tcp_connections_number)
static bool tcp_connections_number_is_valid(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
if ((uint32_t)tcp_connections_number >= tcp_c->tcp_connections_length) {
return false;
@@ -160,8 +156,7 @@ static bool tcp_connections_number_is_valid(const TCP_Connections *tcp_c, int tc
* return -1 on failure.
* return connections_number on success.
*/
non_null()
static int create_connection(TCP_Connections *tcp_c)
static int create_connection(TCP_Connections *_Nonnull tcp_c)
{
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
if (tcp_c->connections[i].status == TCP_CONN_NONE) {
@@ -185,8 +180,7 @@ static int create_connection(TCP_Connections *tcp_c)
* return -1 on failure.
* return tcp_connections_number on success.
*/
non_null()
static int create_tcp_connection(TCP_Connections *tcp_c)
static int create_tcp_connection(TCP_Connections *_Nonnull tcp_c)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
if (tcp_c->tcp_connections[i].status == TCP_CONN_NONE) {
@@ -210,8 +204,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
static int wipe_connection(TCP_Connections *_Nonnull tcp_c, int connections_number)
{
if (!connections_number_is_valid(tcp_c, connections_number)) {
return -1;
@@ -241,8 +234,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
* return -1 on failure.
* return 0 on success.
*/
non_null()
static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_number)
static int wipe_tcp_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
return -1;
@@ -268,8 +260,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0;
}
non_null()
static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
static TCP_Connection_to *get_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number)
{
if (!connections_number_is_valid(tcp_c, connections_number)) {
return nullptr;
@@ -278,8 +269,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
return &tcp_c->connections[connections_number];
}
non_null()
static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
static TCP_con *get_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
if (!tcp_connections_number_is_valid(tcp_c, tcp_connections_number)) {
return nullptr;
@@ -413,8 +403,7 @@ int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c)
* return TCP connection number on success.
* return -1 on failure.
*/
non_null()
static int get_conn_number_by_ip_port(const TCP_Connections *tcp_c, const IP_Port *ip_port)
static int get_conn_number_by_ip_port(const TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
const IP_Port conn_ip_port = tcp_con_ip_port(tcp_c->tcp_connections[i].connection);
@@ -526,8 +515,7 @@ int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connectio
return -1;
}
non_null()
static int find_tcp_connection_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk);
static int find_tcp_connection_relay(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk);
/** @brief Send an oob packet via the TCP relay corresponding to relay_pk.
*
@@ -604,8 +592,7 @@ bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp
* return connections_number on success.
* return -1 on failure.
*/
non_null()
static int find_tcp_connection_to(const TCP_Connections *tcp_c, const uint8_t *public_key)
static int find_tcp_connection_to(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key)
{
for (uint32_t i = 0; i < tcp_c->connections_length; ++i) {
const TCP_Connection_to *con_to = get_connection(tcp_c, i);
@@ -786,8 +773,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n
return 0;
}
non_null()
static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int tcp_connections_number)
static bool tcp_connection_in_conn(const TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
{
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -802,8 +788,7 @@ static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int
* @return index on success.
* @retval -1 on failure.
*/
non_null()
static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
static int add_tcp_connection_to_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
{
if (tcp_connection_in_conn(con_to, tcp_connections_number)) {
return -1;
@@ -825,8 +810,7 @@ static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tc
* @return index on success.
* @retval -1 on failure.
*/
non_null()
static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number)
static int rm_tcp_connection_from_conn(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number)
{
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -844,8 +828,7 @@ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int t
* @return number of online connections on success.
* @retval -1 on failure.
*/
non_null()
static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *_Nonnull con_to)
{
uint32_t count = 0;
@@ -864,10 +847,7 @@ static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to)
* @return index on success.
* @retval -1 on failure.
*/
non_null()
static int set_tcp_connection_status(TCP_Connection_to *con_to, unsigned int tcp_connections_number,
uint8_t status,
uint8_t connection_id)
static int set_tcp_connection_status(TCP_Connection_to *_Nonnull con_to, unsigned int tcp_connections_number, uint8_t status, uint8_t connection_id)
{
for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
@@ -915,8 +895,7 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number
return wipe_tcp_connection(tcp_c, tcp_connections_number);
}
non_null()
static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
static int reconnect_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -962,8 +941,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec
return 0;
}
non_null()
static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
static int sleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1007,8 +985,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
return 0;
}
non_null()
static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number)
static int unsleep_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1043,9 +1020,7 @@ static int unsleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connecti
* return 0 on success.
* return -1 on failure.
*/
non_null()
static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_connections_number,
const uint8_t *public_key)
static int send_tcp_relay_routing_request(const TCP_Connections *_Nonnull tcp_c, int tcp_connections_number, const uint8_t *_Nonnull public_key)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1064,8 +1039,7 @@ static int send_tcp_relay_routing_request(const TCP_Connections *tcp_c, int tcp_
return 0;
}
non_null()
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
static int tcp_response_callback(void *_Nonnull object, uint8_t connection_id, const uint8_t *_Nonnull public_key)
{
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);
@@ -1098,8 +1072,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
return 0;
}
non_null()
static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
static int tcp_status_callback(void *_Nonnull object, uint32_t number, uint8_t connection_id, uint8_t status)
{
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
const TCP_Connections *tcp_c = (const TCP_Connections *)tcp_con_custom_object(tcp_client_con);
@@ -1137,12 +1110,10 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
return 0;
}
non_null(1, 4) nullable(6)
static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data,
uint16_t length, void *userdata)
static int tcp_conn_data_callback(void *_Nonnull object, uint32_t number, uint8_t connection_id, const uint8_t *_Nonnull data,
uint16_t length, void *_Nullable userdata)
{
const TCP_Client_Connection *tcp_client_con = (TCP_Client_Connection *)object;
if (length == 0) {
return -1;
}
@@ -1169,9 +1140,7 @@ static int tcp_conn_data_callback(void *object, uint32_t number, uint8_t connect
return 0;
}
non_null()
static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length,
void *userdata)
static int tcp_conn_oob_callback(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
const TCP_Client_Connection *tcp_client_con = (const TCP_Client_Connection *)object;
@@ -1204,8 +1173,7 @@ static int tcp_conn_oob_callback(void *object, const uint8_t *public_key, const
return 0;
}
non_null()
static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
static int tcp_onion_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
TCP_Connections *tcp_c = (TCP_Connections *)object;
@@ -1216,8 +1184,7 @@ static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length
return 0;
}
non_null()
static void tcp_forwarding_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
static void tcp_forwarding_callback(void *_Nonnull object, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
TCP_Connections *tcp_c = (TCP_Connections *)object;
@@ -1231,8 +1198,7 @@ static void tcp_forwarding_callback(void *object, const uint8_t *data, uint16_t
* return 0 on success.
* return -1 on failure.
*/
non_null()
static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_number)
static int tcp_relay_set_callbacks(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1254,8 +1220,7 @@ static int tcp_relay_set_callbacks(TCP_Connections *tcp_c, int tcp_connections_n
return 0;
}
non_null()
static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_number)
static int tcp_relay_on_online(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number)
{
TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1295,8 +1260,7 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe
return 0;
}
non_null()
static int add_tcp_relay_instance(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk)
static int add_tcp_relay_instance(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk)
{
IP_Port ipp_copy = *ip_port;
@@ -1451,8 +1415,7 @@ uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int c
* Returns true if the relay was successfully copied.
* Returns false if the connection index is invalid, or if the relay is not connected.
*/
non_null()
static bool copy_tcp_relay_conn(const TCP_Connections *tcp_c, Node_format *tcp_relay, uint16_t idx)
static bool copy_tcp_relay_conn(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relay, uint16_t idx)
{
const TCP_con *tcp_con = get_tcp_connection(tcp_c, idx);
@@ -1628,12 +1591,10 @@ TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, co
return temp;
}
non_null(1, 2) nullable(3)
static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *userdata)
static void do_tcp_conns(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, void *_Nullable userdata)
{
for (uint32_t i = 0; i < tcp_c->tcp_connections_length; ++i) {
TCP_con *tcp_con = get_tcp_connection(tcp_c, i);
if (tcp_con == nullptr) {
continue;
}
@@ -1675,9 +1636,12 @@ static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *use
}
}
non_null()
static void kill_nonused_tcp(TCP_Connections *tcp_c)
static void kill_nonused_tcp(TCP_Connections *_Nullable tcp_c)
{
if (tcp_c == nullptr) {
return;
}
if (tcp_c->tcp_connections_length <= RECOMMENDED_FRIEND_TCP_CONNECTIONS) {
return;
}

View File

@@ -67,7 +67,7 @@ typedef struct TCP_Connection_to {
typedef struct TCP_con {
uint8_t status;
TCP_Client_Connection *connection;
TCP_Client_Connection *_Nullable connection;
uint64_t connected_time;
uint32_t lock_count;
uint32_t sleep_count;
@@ -81,28 +81,22 @@ typedef struct TCP_con {
typedef struct TCP_Connections TCP_Connections;
non_null()
const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c);
const uint8_t *_Nonnull tcp_connections_public_key(const TCP_Connections *_Nonnull tcp_c);
non_null()
uint32_t tcp_connections_count(const TCP_Connections *tcp_c);
uint32_t tcp_connections_count(const TCP_Connections *_Nonnull tcp_c);
/** @brief Returns the number of connected TCP relays. */
non_null()
uint32_t tcp_connected_relays_count(const TCP_Connections *tcp_c);
uint32_t tcp_connected_relays_count(const TCP_Connections *_Nonnull tcp_c);
/** @brief Returns true if we know of a valid TCP relay with the passed public key. */
non_null()
bool tcp_relay_is_valid(const TCP_Connections *tcp_c, const uint8_t *relay_pk);
bool tcp_relay_is_valid(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk);
/** @brief Send a packet to the TCP connection.
*
* return -1 on failure.
* return 0 on success.
*/
non_null()
int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_number, const uint8_t *packet,
uint16_t length);
int send_packet_tcp_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, const uint8_t *_Nonnull packet, uint16_t length);
/** @brief Return a TCP connection number for use in send_tcp_onion_request.
*
@@ -112,25 +106,21 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num
* return TCP connection number on success.
* return -1 on failure.
*/
non_null()
int get_random_tcp_onion_conn_number(const TCP_Connections *tcp_c);
int get_random_tcp_onion_conn_number(const TCP_Connections *_Nonnull tcp_c);
/** @brief Put IP_Port of a random onion TCP connection in ip_port.
*
* return true on success.
* return false on failure.
*/
non_null()
bool tcp_get_random_conn_ip_port(const TCP_Connections *tcp_c, IP_Port *ip_port);
bool tcp_get_random_conn_ip_port(const TCP_Connections *_Nonnull tcp_c, IP_Port *_Nonnull ip_port);
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
*
* return 0 on success.
* return -1 on failure.
*/
non_null()
int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_number, const uint8_t *data,
uint16_t length);
int tcp_send_onion_request(TCP_Connections *_Nonnull tcp_c, uint32_t tcp_connections_number, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Set if we want TCP_connection to allocate some connection for onion use.
*
@@ -139,8 +129,7 @@ int tcp_send_onion_request(TCP_Connections *tcp_c, uint32_t tcp_connections_numb
* return 0 on success.
* return -1 on failure.
*/
non_null()
int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
int set_tcp_onion_status(TCP_Connections *_Nonnull tcp_c, bool status);
/**
* Send a forward request to the TCP relay with IP_Port tcp_forwarder,
@@ -150,49 +139,37 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status);
* return 0 on success.
* return -1 on failure.
*/
non_null()
int tcp_send_forward_request(const Logger *logger, TCP_Connections *tcp_c, const IP_Port *tcp_forwarder,
const IP_Port *dht_node,
const uint8_t *chain_keys, uint16_t chain_length,
const uint8_t *data, uint16_t data_length);
int tcp_send_forward_request(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull tcp_forwarder, const IP_Port *_Nonnull dht_node,
const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data, uint16_t data_length);
/** @brief Send an oob packet via the TCP relay corresponding to tcp_connections_number.
*
* return 0 on success.
* return -1 on failure.
*/
non_null()
int tcp_send_oob_packet(const TCP_Connections *tcp_c, unsigned int tcp_connections_number, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);
int tcp_send_oob_packet(const TCP_Connections *_Nonnull tcp_c, unsigned int tcp_connections_number, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet, uint16_t length);
typedef int tcp_data_cb(void *object, int crypt_connection_id, const uint8_t *packet, uint16_t length, void *userdata);
typedef int tcp_data_cb(void *_Nonnull object, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
non_null()
int tcp_send_oob_packet_using_relay(const TCP_Connections *tcp_c, const uint8_t *relay_pk, const uint8_t *public_key,
const uint8_t *packet, uint16_t length);
int tcp_send_oob_packet_using_relay(const TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull relay_pk, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull packet,
uint16_t length);
/** @brief Set the callback for TCP data packets. */
non_null()
void set_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_data_cb *tcp_data_callback, void *object);
void set_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_data_cb *_Nonnull tcp_data_callback, void *_Nonnull object);
typedef int tcp_onion_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
typedef int tcp_onion_cb(void *_Nullable object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/** @brief Set the callback for TCP onion packets. */
non_null(1) nullable(2, 3)
void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_cb *tcp_onion_callback, void *object);
void set_onion_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_onion_cb *_Nullable tcp_onion_callback, void *_Nullable object);
/** @brief Set the callback for TCP forwarding packets. */
non_null(1) nullable(2, 3)
void set_forwarding_packet_tcp_connection_callback(TCP_Connections *tcp_c,
forwarded_response_cb *tcp_forwarded_response_callback,
void *object);
typedef int tcp_oob_cb(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *packet, uint16_t length, void *userdata);
void set_forwarding_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c,
forwarded_response_cb *_Nullable tcp_forwarded_response_callback,
void *_Nullable object);
typedef int tcp_oob_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, unsigned int tcp_connections_number,
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata);
/** @brief Set the callback for TCP oob data packets. */
non_null()
void set_oob_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_oob_cb *tcp_oob_callback, void *object);
void set_oob_packet_tcp_connection_callback(TCP_Connections *_Nonnull tcp_c, tcp_oob_cb *_Nonnull tcp_oob_callback, void *_Nonnull object);
/** @brief Encode tcp_connections_number as a custom ip_port.
*
@@ -205,8 +182,7 @@ IP_Port tcp_connections_number_to_ip_port(unsigned int tcp_connections_number);
* return true on success.
* return false if ip_port is invalid.
*/
non_null()
bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp_connections_number);
bool ip_port_to_tcp_connections_number(const IP_Port *_Nonnull ip_port, unsigned int *_Nonnull tcp_connections_number);
/** @brief Create a new TCP connection to public_key.
*
@@ -217,15 +193,13 @@ bool ip_port_to_tcp_connections_number(const IP_Port *ip_port, unsigned int *tcp
* return connections_number on success.
* return -1 on failure.
*/
non_null()
int new_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key, int id);
int new_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, const uint8_t *_Nonnull public_key, int id);
/**
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null()
int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
int kill_tcp_connection_to(TCP_Connections *_Nonnull tcp_c, int connections_number);
/** @brief Set connection status.
*
@@ -237,15 +211,13 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number);
* return 0 on success.
* return -1 on failure.
*/
non_null()
int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_number, bool status);
int set_tcp_connection_to_status(const TCP_Connections *_Nonnull tcp_c, int connections_number, bool status);
/**
* @return number of online tcp relays tied to the connection on success.
* @retval 0 on failure.
*/
non_null()
uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int connections_number);
uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *_Nonnull tcp_c, int connections_number);
/** @brief Add a TCP relay tied to a connection.
*
@@ -254,9 +226,7 @@ uint32_t tcp_connection_to_online_tcp_relays(const TCP_Connections *tcp_c, int c
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connections_number,
unsigned int tcp_connections_number);
int add_tcp_number_relay_connection(const TCP_Connections *_Nonnull tcp_c, int connections_number, unsigned int tcp_connections_number);
/** @brief Add a TCP relay tied to a connection.
*
@@ -265,17 +235,14 @@ int add_tcp_number_relay_connection(const TCP_Connections *tcp_c, int connection
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_relay_connection(TCP_Connections *tcp_c, int connections_number, const IP_Port *ip_port,
const uint8_t *relay_pk);
int add_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int connections_number, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk);
/** @brief Add a TCP relay to the TCP_Connections instance.
*
* return 0 on success.
* return -1 on failure.
*/
non_null()
int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const uint8_t *relay_pk);
int add_tcp_relay_global(TCP_Connections *_Nonnull tcp_c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull relay_pk);
/** @brief Copy a maximum of max_num TCP relays we are connected to to tcp_relays.
*
@@ -284,8 +251,7 @@ int add_tcp_relay_global(TCP_Connections *tcp_c, const IP_Port *ip_port, const u
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
non_null()
uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num);
uint32_t tcp_copy_connected_relays(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relays, uint16_t max_num);
/** @brief Copy a maximum of `max_num` TCP relays we are connected to starting at idx.
*
@@ -294,9 +260,7 @@ uint32_t tcp_copy_connected_relays(const TCP_Connections *tcp_c, Node_format *tc
*
* Returns the number of relays successfully copied.
*/
non_null()
uint32_t tcp_copy_connected_relays_index(const TCP_Connections *tcp_c, Node_format *tcp_relays, uint16_t max_num,
uint32_t idx);
uint32_t tcp_copy_connected_relays_index(const TCP_Connections *_Nonnull tcp_c, Node_format *_Nonnull tcp_relays, uint16_t max_num, uint32_t idx);
/** @brief Returns a new TCP_Connections object associated with the secret_key.
*
@@ -305,17 +269,11 @@ uint32_t tcp_copy_connected_relays_index(const TCP_Connections *tcp_c, Node_form
*
* Returns NULL on failure.
*/
non_null()
TCP_Connections *new_tcp_connections(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
Mono_Time *mono_time, const uint8_t *secret_key, const TCP_Proxy_Info *proxy_info, Net_Profile *tcp_np);
TCP_Connections *_Nullable new_tcp_connections(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time,
const uint8_t *_Nonnull secret_key, const TCP_Proxy_Info *_Nonnull proxy_info, Net_Profile *_Nonnull tcp_np);
non_null()
int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number);
non_null(1, 2) nullable(3)
void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata);
nullable(1)
void kill_tcp_connections(TCP_Connections *tcp_c);
int kill_tcp_relay_connection(TCP_Connections *_Nonnull tcp_c, int tcp_connections_number);
void do_tcp_connections(const Logger *_Nonnull logger, TCP_Connections *_Nonnull tcp_c, void *_Nullable userdata);
void kill_tcp_connections(TCP_Connections *_Nullable tcp_c);
#endif /* C_TOXCORE_TOXCORE_TCP_CONNECTION_H */

View File

@@ -122,8 +122,7 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server)
* @retval -1 on failure
* @retval 0 on success.
*/
non_null()
static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
static int alloc_new_connections(TCP_Server *_Nonnull tcp_server, uint32_t num)
{
const uint32_t new_size = tcp_server->size_accepted_connections + num;
@@ -149,8 +148,7 @@ static int alloc_new_connections(TCP_Server *tcp_server, uint32_t num)
return 0;
}
non_null()
static void wipe_secure_connection(TCP_Secure_Connection *con)
static void wipe_secure_connection(TCP_Secure_Connection *_Nonnull con)
{
if (con->status != 0) {
wipe_priority_list(con->con.mem, con->con.priority_queue_start);
@@ -158,15 +156,13 @@ static void wipe_secure_connection(TCP_Secure_Connection *con)
}
}
non_null()
static void move_secure_connection(TCP_Secure_Connection *con_new, TCP_Secure_Connection *con_old)
static void move_secure_connection(TCP_Secure_Connection *_Nonnull con_new, TCP_Secure_Connection *_Nonnull con_old)
{
*con_new = *con_old;
crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
}
non_null()
static void free_accepted_connection_array(TCP_Server *tcp_server)
static void free_accepted_connection_array(TCP_Server *_Nonnull tcp_server)
{
if (tcp_server->accepted_connection_array == nullptr) {
return;
@@ -185,22 +181,19 @@ static void free_accepted_connection_array(TCP_Server *tcp_server)
* @return index corresponding to connection with peer on success
* @retval -1 on failure.
*/
non_null()
static int get_tcp_connection_index(const TCP_Server *tcp_server, const uint8_t *public_key)
static int get_tcp_connection_index(const TCP_Server *_Nonnull tcp_server, const uint8_t *_Nonnull public_key)
{
return bs_list_find(&tcp_server->accepted_key_list, public_key);
}
non_null()
static int kill_accepted(TCP_Server *tcp_server, int index);
static int kill_accepted(TCP_Server *_Nonnull tcp_server, int index);
/** @brief Add accepted TCP connection to the list.
*
* @return index on success
* @retval -1 on failure
*/
non_null()
static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con)
static int add_accepted(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, TCP_Secure_Connection *_Nonnull con)
{
int index = get_tcp_connection_index(tcp_server, con->public_key);
@@ -250,8 +243,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_
* @retval 0 on success
* @retval -1 on failure
*/
non_null()
static int del_accepted(TCP_Server *tcp_server, int index)
static int del_accepted(TCP_Server *_Nonnull tcp_server, int index)
{
if ((uint32_t)index >= tcp_server->size_accepted_connections) {
return -1;
@@ -276,15 +268,17 @@ static int del_accepted(TCP_Server *tcp_server, int index)
}
/** Kill a TCP_Secure_Connection */
non_null()
static void kill_tcp_secure_connection(TCP_Secure_Connection *con)
static void kill_tcp_secure_connection(TCP_Secure_Connection *_Nullable con)
{
if (con == nullptr) {
return;
}
kill_sock(con->con.ns, con->con.sock);
wipe_secure_connection(con);
}
non_null()
static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *con, uint8_t con_number);
static int rm_connection_index(TCP_Server *_Nonnull tcp_server, TCP_Secure_Connection *_Nonnull con, uint8_t con_number);
/** @brief Kill an accepted TCP_Secure_Connection
*
@@ -315,9 +309,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index)
* @retval 1 if everything went well.
* @retval -1 if the connection must be killed.
*/
non_null()
static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
const uint8_t *self_secret_key)
static int handle_tcp_handshake(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length, const uint8_t *_Nonnull self_secret_key)
{
if (length != TCP_CLIENT_HANDSHAKE_SIZE) {
LOGGER_ERROR(logger, "invalid handshake length: %d != %d", length, TCP_CLIENT_HANDSHAKE_SIZE);
@@ -380,8 +372,7 @@ static int handle_tcp_handshake(const Logger *logger, TCP_Secure_Connection *con
* @retval 0 if we didn't get it yet.
* @retval -1 if the connection must be killed.
*/
non_null()
static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key)
static int read_connection_handshake(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull self_secret_key)
{
uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
const int len = read_tcp_packet(logger, con->con.mem, con->con.ns, con->con.sock, data, TCP_CLIENT_HANDSHAKE_SIZE, &con->con.ip_port);
@@ -399,9 +390,7 @@ static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int send_routing_response(const Logger *logger, TCP_Secure_Connection *con, uint8_t rpid,
const uint8_t *public_key)
static int send_routing_response(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t rpid, const uint8_t *_Nonnull public_key)
{
uint8_t data[2 + CRYPTO_PUBLIC_KEY_SIZE];
data[0] = TCP_PACKET_ROUTING_RESPONSE;
@@ -416,8 +405,7 @@ static int send_routing_response(const Logger *logger, TCP_Secure_Connection *co
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int send_connect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
static int send_connect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
@@ -428,8 +416,7 @@ static int send_connect_notification(const Logger *logger, TCP_Secure_Connection
* @retval 0 if could not send packet.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connection *con, uint8_t id)
static int send_disconnect_notification(const Logger *_Nonnull logger, TCP_Secure_Connection *_Nonnull con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
return write_packet_tcp_secure_connection(logger, &con->con, data, sizeof(data), true);
@@ -439,8 +426,7 @@ static int send_disconnect_notification(const Logger *logger, TCP_Secure_Connect
* @retval 0 on success.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key)
static int handle_tcp_routing_req(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull public_key)
{
uint32_t index = -1;
TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id];
@@ -522,9 +508,7 @@ static int handle_tcp_routing_req(TCP_Server *tcp_server, uint32_t con_id, const
* @retval 0 on success.
* @retval -1 on failure (connection must be killed).
*/
non_null()
static int handle_tcp_oob_send(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
uint16_t length)
static int handle_tcp_oob_send(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull data, uint16_t length)
{
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH) {
return -1;
@@ -602,8 +586,7 @@ static IP_Port con_id_to_ip_port(uint32_t con_id, uint64_t identifier)
* @retval true on success.
* @retval false if ip_port is invalid.
*/
non_null()
static bool ip_port_to_con_id(const TCP_Server *tcp_server, const IP_Port *ip_port, uint32_t *con_id)
static bool ip_port_to_con_id(const TCP_Server *_Nonnull tcp_server, const IP_Port *_Nonnull ip_port, uint32_t *_Nonnull con_id)
{
*con_id = ip_port->ip.ip.v6.uint32[0];
@@ -612,8 +595,7 @@ static bool ip_port_to_con_id(const TCP_Server *tcp_server, const IP_Port *ip_po
tcp_server->accepted_connection_array[*con_id].identifier == ip_port->ip.ip.v6.uint64[1];
}
non_null()
static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length)
static int handle_onion_recv_1(void *_Nonnull object, const IP_Port *_Nonnull dest, const uint8_t *_Nonnull data, uint16_t length)
{
TCP_Server *tcp_server = (TCP_Server *)object;
uint32_t index;
@@ -636,9 +618,7 @@ static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t
return 0;
}
non_null()
static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *data, uint16_t length)
static bool handle_forward_reply_tcp(void *_Nonnull object, const uint8_t *_Nonnull sendback_data, uint16_t sendback_data_len, const uint8_t *_Nonnull data, uint16_t length)
{
TCP_Server *tcp_server = (TCP_Server *)object;
@@ -677,8 +657,7 @@ static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data,
* @retval 0 on success
* @retval -1 on failure
*/
non_null()
static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *data, uint16_t length)
static int handle_tcp_packet(TCP_Server *_Nonnull tcp_server, uint32_t con_id, const uint8_t *_Nonnull data, uint16_t length)
{
if (length == 0) {
return -1;
@@ -693,7 +672,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling routing request for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling routing request for %u", con_id);
return handle_tcp_routing_req(tcp_server, con_id, data + 1);
}
@@ -702,7 +681,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling connection notification for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling connection notification for %u", con_id);
break;
}
@@ -711,7 +690,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling disconnect notification for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling disconnect notification for %u", con_id);
return rm_connection_index(tcp_server, con, data[1] - NUM_RESERVED_PORTS);
}
@@ -720,7 +699,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling ping for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling ping for %u", con_id);
uint8_t response[1 + sizeof(uint64_t)];
response[0] = TCP_PACKET_PONG;
@@ -734,7 +713,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling pong for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling pong for %u", con_id);
uint64_t ping_id;
memcpy(&ping_id, data + 1, sizeof(uint64_t));
@@ -755,14 +734,14 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling oob send for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling oob send for %u", con_id);
return handle_tcp_oob_send(tcp_server, con_id, data + 1, data + 1 + CRYPTO_PUBLIC_KEY_SIZE,
length - (1 + CRYPTO_PUBLIC_KEY_SIZE));
}
case TCP_PACKET_ONION_REQUEST: {
LOGGER_TRACE(tcp_server->logger, "handling onion request for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling onion request for %u", con_id);
if (tcp_server->onion != nullptr) {
if (length <= 1 + CRYPTO_NONCE_SIZE + ONION_SEND_BASE * 2) {
@@ -778,7 +757,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
}
case TCP_PACKET_ONION_RESPONSE: {
LOGGER_TRACE(tcp_server->logger, "handling onion response for %d", con_id);
LOGGER_TRACE(tcp_server->logger, "handling onion response for %u", con_id);
return -1;
}
@@ -821,7 +800,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
}
const uint8_t c_id = data[0] - NUM_RESERVED_PORTS;
LOGGER_TRACE(tcp_server->logger, "handling packet id %d for %d", c_id, con_id);
LOGGER_TRACE(tcp_server->logger, "handling packet id %u for %u", c_id, con_id);
if (c_id >= NUM_CLIENT_CONNECTIONS) {
return -1;
@@ -854,9 +833,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
return 0;
}
non_null()
static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_Secure_Connection *con,
const uint8_t *data, uint16_t length)
static int confirm_tcp_connection(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, TCP_Secure_Connection *_Nonnull con, const uint8_t *_Nonnull data, uint16_t length)
{
const int index = add_accepted(tcp_server, mono_time, con);
@@ -882,8 +859,7 @@ static int confirm_tcp_connection(TCP_Server *tcp_server, const Mono_Time *mono_
* @return index on success
* @retval -1 on failure
*/
non_null()
static int accept_connection(TCP_Server *tcp_server, Socket sock)
static int accept_connection(TCP_Server *_Nonnull tcp_server, Socket sock)
{
if (!sock_valid(sock)) {
return -1;
@@ -919,8 +895,7 @@ static int accept_connection(TCP_Server *tcp_server, Socket sock)
return index;
}
non_null()
static Socket new_listening_tcp_socket(const Logger *logger, const Memory *mem, const Network *ns, Family family, uint16_t port)
static Socket new_listening_tcp_socket(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Network *_Nonnull ns, Family family, uint16_t port)
{
const Socket sock = net_socket(ns, family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
@@ -1062,8 +1037,7 @@ TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random
}
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_tcp_accept_new(TCP_Server *tcp_server)
static void do_tcp_accept_new(TCP_Server *_Nonnull tcp_server)
{
for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {
@@ -1078,8 +1052,7 @@ static void do_tcp_accept_new(TCP_Server *tcp_server)
}
#endif /* TCP_SERVER_USE_EPOLL */
non_null()
static int do_incoming(TCP_Server *tcp_server, uint32_t i)
static int do_incoming(TCP_Server *_Nonnull tcp_server, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->incoming_connection_queue[i];
@@ -1087,12 +1060,12 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling incoming TCP connection %d", i);
LOGGER_TRACE(tcp_server->logger, "handling incoming TCP connection %u", i);
const int ret = read_connection_handshake(tcp_server->logger, conn, tcp_server->secret_key);
if (ret == -1) {
LOGGER_TRACE(tcp_server->logger, "incoming connection %d dropped due to failed handshake", i);
LOGGER_TRACE(tcp_server->logger, "incoming connection %u dropped due to failed handshake", i);
kill_tcp_secure_connection(conn);
return -1;
}
@@ -1106,7 +1079,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
TCP_Secure_Connection *conn_new = &tcp_server->unconfirmed_connection_queue[index_new];
if (conn_new->status != TCP_STATUS_NO_STATUS) {
LOGGER_ERROR(tcp_server->logger, "incoming connection %d would overwrite existing", i);
LOGGER_ERROR(tcp_server->logger, "incoming connection %u would overwrite existing", i);
kill_tcp_secure_connection(conn_new);
}
@@ -1116,8 +1089,7 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i)
return index_new;
}
non_null()
static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, uint32_t i)
static int do_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->unconfirmed_connection_queue[i];
@@ -1125,7 +1097,7 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
return -1;
}
LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %d", i);
LOGGER_TRACE(tcp_server->logger, "handling unconfirmed TCP connection %u", i);
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet,
@@ -1143,15 +1115,14 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui
return confirm_tcp_connection(tcp_server, mono_time, conn, packet, len);
}
non_null()
static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
static bool tcp_process_secure_packet(TCP_Server *_Nonnull tcp_server, uint32_t i)
{
TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i];
uint8_t packet[MAX_PACKET_SIZE];
const int len = read_packet_tcp_secure_connection(tcp_server->logger, conn->con.mem, conn->con.ns, conn->con.sock, &conn->next_packet_length, conn->con.shared_key, conn->recv_nonce, packet,
sizeof(packet), &conn->con.ip_port);
LOGGER_TRACE(tcp_server->logger, "processing packet for %d: %d", i, len);
LOGGER_TRACE(tcp_server->logger, "processing packet for %u: %d", i, len);
if (len == 0) {
return false;
@@ -1163,7 +1134,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
}
if (handle_tcp_packet(tcp_server, i, packet, len) == -1) {
LOGGER_TRACE(tcp_server->logger, "dropping connection %d: data packet (len=%d) not handled", i, len);
LOGGER_TRACE(tcp_server->logger, "dropping connection %u: data packet (len=%d) not handled", i, len);
kill_accepted(tcp_server, i);
return false;
}
@@ -1171,8 +1142,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i)
return true;
}
non_null()
static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
static void do_confirmed_recv(TCP_Server *_Nonnull tcp_server, uint32_t i)
{
while (tcp_process_secure_packet(tcp_server, i)) {
/* Keep reading until an error occurs or there is no more data to read. */
@@ -1180,16 +1150,14 @@ static void do_confirmed_recv(TCP_Server *tcp_server, uint32_t i)
}
#ifndef TCP_SERVER_USE_EPOLL
non_null()
static void do_tcp_incoming(TCP_Server *tcp_server)
static void do_tcp_incoming(TCP_Server *_Nonnull tcp_server)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_incoming(tcp_server, i);
}
}
non_null()
static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_unconfirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
{
for (uint32_t i = 0; i < MAX_INCOMING_CONNECTIONS; ++i) {
do_unconfirmed(tcp_server, mono_time, i);
@@ -1197,8 +1165,7 @@ static void do_tcp_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_tim
}
#endif /* TCP_SERVER_USE_EPOLL */
non_null()
static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_confirmed(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
{
#ifdef TCP_SERVER_USE_EPOLL
@@ -1255,8 +1222,7 @@ static void do_tcp_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
#ifdef TCP_SERVER_USE_EPOLL
non_null()
static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time)
static bool tcp_epoll_process(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
{
#define MAX_EVENTS 16
struct epoll_event events[MAX_EVENTS];
@@ -1381,8 +1347,7 @@ static bool tcp_epoll_process(TCP_Server *tcp_server, const Mono_Time *mono_time
return nfds > 0;
}
non_null()
static void do_tcp_epoll(TCP_Server *tcp_server, const Mono_Time *mono_time)
static void do_tcp_epoll(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time)
{
while (tcp_epoll_process(tcp_server, mono_time)) {
// Keep processing packets until there are no more FDs ready for reading.

View File

@@ -34,30 +34,21 @@ typedef enum TCP_Status {
typedef struct TCP_Server TCP_Server;
non_null()
const uint8_t *tcp_server_public_key(const TCP_Server *tcp_server);
non_null()
size_t tcp_server_listen_count(const TCP_Server *tcp_server);
const uint8_t *_Nonnull tcp_server_public_key(const TCP_Server *_Nonnull tcp_server);
size_t tcp_server_listen_count(const TCP_Server *_Nonnull tcp_server);
/** Create new TCP server instance. */
non_null(1, 2, 3, 4, 7, 8) nullable(9, 10)
TCP_Server *new_tcp_server(const Logger *logger, const Memory *mem, const Random *rng, const Network *ns,
bool ipv6_enabled, uint16_t num_sockets, const uint16_t *ports,
const uint8_t *secret_key, Onion *onion, Forwarding *forwarding);
TCP_Server *_Nullable new_tcp_server(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns,
bool ipv6_enabled, uint16_t num_sockets, const uint16_t *_Nonnull ports,
const uint8_t *_Nonnull secret_key, Onion *_Nullable onion, Forwarding *_Nullable forwarding);
/** Run the TCP_server */
non_null()
void do_tcp_server(TCP_Server *tcp_server, const Mono_Time *mono_time);
void do_tcp_server(TCP_Server *_Nonnull tcp_server, const Mono_Time *_Nonnull mono_time);
/** Kill the TCP server */
nullable(1)
void kill_tcp_server(TCP_Server *tcp_server);
void kill_tcp_server(TCP_Server *_Nullable tcp_server);
/** @brief Returns a pointer to the net profile associated with `tcp_server`.
*
* Returns null if `tcp_server` is null.
*/
nullable(1)
const Net_Profile *tcp_server_get_net_profile(const TCP_Server *tcp_server);
const Net_Profile *_Nullable tcp_server_get_net_profile(const TCP_Server *_Nullable tcp_server);
#endif /* C_TOXCORE_TOXCORE_TCP_SERVER_H */

View File

@@ -85,21 +85,18 @@ void announce_set_synch_offset(Announcements *announce, int32_t synch_offset)
* An entry is considered to be "deleted" for the purposes of the protocol
* once it has timed out.
*/
non_null()
static bool entry_is_empty(const Announcements *announce, const Announce_Entry *entry)
static bool entry_is_empty(const Announcements *_Nonnull announce, const Announce_Entry *_Nonnull entry)
{
return mono_time_get(announce->mono_time) >= entry->store_until;
}
non_null()
static void delete_entry(Announce_Entry *entry)
static void delete_entry(Announce_Entry *_Nonnull entry)
{
entry->store_until = 0;
}
/** Return bits (at most 8) from pk starting at index as uint8_t */
non_null()
static uint8_t truncate_pk_at_index(const uint8_t *pk, uint16_t index, uint16_t bits)
static uint8_t truncate_pk_at_index(const uint8_t *_Nonnull pk, uint16_t index, uint16_t bits)
{
assert(bits < 8);
const uint8_t i = index / 8;
@@ -116,14 +113,12 @@ uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk)
truncate_pk_at_index(pk, index + 1, ANNOUNCE_BUCKET_PREFIX_LENGTH);
}
non_null()
static Announce_Entry *bucket_of_key(Announcements *announce, const uint8_t *pk)
static Announce_Entry *bucket_of_key(Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
{
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
}
non_null()
static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_public_key)
static Announce_Entry *get_stored(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
{
Announce_Entry *const bucket = bucket_of_key(announce, data_public_key);
@@ -140,14 +135,12 @@ static Announce_Entry *get_stored(Announcements *announce, const uint8_t *data_p
return nullptr;
}
non_null()
static const Announce_Entry *bucket_of_key_const(const Announcements *announce, const uint8_t *pk)
static const Announce_Entry *bucket_of_key_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull pk)
{
return &announce->entries[announce_get_bucketnum(announce->public_key, pk) * ANNOUNCE_BUCKET_SIZE];
}
non_null()
static const Announce_Entry *get_stored_const(const Announcements *announce, const uint8_t *data_public_key)
static const Announce_Entry *get_stored_const(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
{
const Announce_Entry *const bucket = bucket_of_key_const(announce, data_public_key);
@@ -186,8 +179,7 @@ bool announce_on_stored(const Announcements *announce, const uint8_t *data_publi
* of greatest 2-adic distance greater than that of the key bucket if one
* exists, else nullptr.
*/
non_null()
static Announce_Entry *find_entry_slot(Announcements *announce, const uint8_t *data_public_key)
static Announce_Entry *find_entry_slot(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
{
Announce_Entry *const bucket = bucket_of_key(announce, data_public_key);
@@ -216,8 +208,7 @@ static Announce_Entry *find_entry_slot(Announcements *announce, const uint8_t *d
return slot;
}
non_null()
static bool would_accept_store_request(Announcements *announce, const uint8_t *data_public_key)
static bool would_accept_store_request(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key)
{
return find_entry_slot(announce, data_public_key) != nullptr;
}
@@ -258,8 +249,7 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
return true;
}
non_null()
static uint32_t calculate_timeout(const Announcements *announce, uint32_t requested_timeout)
static uint32_t calculate_timeout(const Announcements *_Nonnull announce, uint32_t requested_timeout)
{
const uint64_t uptime = mono_time_get(announce->mono_time) - announce->start_time;
const uint32_t max_announcement_timeout = max_u32(
@@ -273,11 +263,10 @@ static uint32_t calculate_timeout(const Announcements *announce, uint32_t reques
#define DATA_SEARCH_TO_AUTH_MAX_SIZE (CRYPTO_PUBLIC_KEY_SIZE * 2 + MAX_PACKED_IPPORT_SIZE + MAX_SENDBACK_SIZE)
non_null(1, 2, 3, 4, 7) nullable(5)
static int create_data_search_to_auth(const Logger *logger, const uint8_t *data_public_key,
const uint8_t *requester_key,
const IP_Port *source, const uint8_t *sendback, uint16_t sendback_length,
uint8_t *dest, uint16_t max_length)
static int create_data_search_to_auth(const Logger *_Nonnull logger, const uint8_t *_Nonnull data_public_key,
const uint8_t *_Nonnull requester_key,
const IP_Port *_Nonnull source, const uint8_t *_Nullable sendback, uint16_t sendback_length,
uint8_t *_Nonnull dest, uint16_t max_length)
{
if (max_length < DATA_SEARCH_TO_AUTH_MAX_SIZE
|| sendback_length > MAX_SENDBACK_SIZE) {
@@ -303,12 +292,8 @@ static int create_data_search_to_auth(const Logger *logger, const uint8_t *data_
#define DATA_SEARCH_TIMEOUT 60
non_null()
static int create_reply_plain_data_search_request(Announcements *announce,
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
static int create_reply_plain_data_search_request(Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length, uint8_t *_Nonnull reply,
uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
{
if (length != CRYPTO_PUBLIC_KEY_SIZE &&
length != CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA256_SIZE) {
@@ -382,13 +367,8 @@ static int create_reply_plain_data_search_request(Announcements *announce,
return reply_len;
}
non_null()
static int create_reply_plain_data_retrieve_request(
const Announcements *announce,
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
static int create_reply_plain_data_retrieve_request(const Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length,
uint8_t *_Nonnull reply, uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
{
if (length != CRYPTO_PUBLIC_KEY_SIZE + 1 + TIMED_AUTH_SIZE) {
return -1;
@@ -425,12 +405,8 @@ static int create_reply_plain_data_retrieve_request(
return reply_len;
}
non_null()
static int create_reply_plain_store_announce_request(Announcements *announce,
const IP_Port *source,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length,
const uint8_t *to_auth, uint16_t to_auth_length)
static int create_reply_plain_store_announce_request(Announcements *_Nonnull announce, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length, uint8_t *_Nonnull reply,
uint16_t reply_max_length, const uint8_t *_Nonnull to_auth, uint16_t to_auth_length)
{
const int plain_len = (int)length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
const int announcement_len = plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1);
@@ -513,12 +489,11 @@ static int create_reply_plain_store_announce_request(Announcements *announce,
return reply_len;
}
non_null(1, 2, 3, 7, 9) nullable(5)
static int create_reply_plain(Announcements *announce,
const uint8_t *requester_key, const IP_Port *source, uint8_t type,
const uint8_t *sendback, uint16_t sendback_length,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length)
static int create_reply_plain(Announcements *_Nonnull announce,
const uint8_t *_Nonnull requester_key, const IP_Port *_Nonnull source, uint8_t type,
const uint8_t *_Nullable sendback, uint16_t sendback_length,
const uint8_t *_Nonnull data, uint16_t length,
uint8_t *_Nonnull reply, uint16_t reply_max_length)
{
if (length < CRYPTO_PUBLIC_KEY_SIZE) {
return -1;
@@ -552,14 +527,12 @@ static int create_reply_plain(Announcements *announce,
}
}
non_null(1, 2, 5, 7) nullable(3)
static int create_reply(Announcements *announce, const IP_Port *source,
const uint8_t *sendback, uint16_t sendback_length,
const uint8_t *data, uint16_t length,
uint8_t *reply, uint16_t reply_max_length)
static int create_reply(Announcements *_Nonnull announce, const IP_Port *_Nonnull source,
const uint8_t *_Nullable sendback, uint16_t sendback_length,
const uint8_t *_Nonnull data, uint16_t length,
uint8_t *_Nonnull reply, uint16_t reply_max_length)
{
const int plain_len = (int)length - (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE);
if (plain_len < (int)sizeof(uint64_t)) {
return -1;
}
@@ -605,13 +578,11 @@ static int create_reply(Announcements *announce, const IP_Port *source,
response_type, plain_reply, plain_reply_len, reply, reply_max_length);
}
non_null(1, 2, 3, 5) nullable(7)
static void forwarded_request_callback(void *object, const IP_Port *forwarder,
const uint8_t *sendback, uint16_t sendback_length,
const uint8_t *data, uint16_t length, void *userdata)
static void forwarded_request_callback(void *_Nonnull object, const IP_Port *_Nonnull forwarder,
const uint8_t *_Nonnull sendback, uint16_t sendback_length,
const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata)
{
Announcements *announce = (Announcements *) object;
uint8_t reply[MAX_FORWARD_DATA_SIZE];
const int len = create_reply(announce, forwarder,
@@ -625,12 +596,10 @@ static void forwarded_request_callback(void *object, const IP_Port *forwarder,
forward_reply(announce->net, forwarder, sendback, sendback_length, reply, len);
}
non_null(1, 2, 3) nullable(5)
static int handle_dht_announce_request(
void *object, const IP_Port *source, const uint8_t *packet, uint16_t length, void *userdata)
void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata)
{
Announcements *announce = (Announcements *)object;
uint8_t reply[MAX_FORWARD_DATA_SIZE];
const int len

View File

@@ -16,45 +16,35 @@
#define MAX_ANNOUNCEMENT_SIZE 512
typedef void announce_on_retrieve_cb(void *object, const uint8_t *data, uint16_t length);
typedef void announce_on_retrieve_cb(void *_Nullable object, const uint8_t *_Nullable data, uint16_t length);
uint8_t announce_response_of_request_type(uint8_t request_type);
typedef struct Announcements Announcements;
non_null()
Announcements *new_announcements(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time,
Forwarding *forwarding);
Announcements *_Nullable new_announcements(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, Forwarding *_Nonnull forwarding);
/**
* @brief If data is stored, run `on_retrieve_callback` on it.
*
* @return true if data is stored, false otherwise.
*/
non_null(1, 2) nullable(3, 4)
bool announce_on_stored(const Announcements *announce, const uint8_t *data_public_key,
announce_on_retrieve_cb *on_retrieve_callback, void *object);
non_null()
void announce_set_synch_offset(Announcements *announce, int32_t synch_offset);
nullable(1)
void kill_announcements(Announcements *announce);
bool announce_on_stored(const Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
announce_on_retrieve_cb *_Nullable on_retrieve_callback, void *_Nullable object);
void announce_set_synch_offset(Announcements *_Nonnull announce, int32_t synch_offset);
void kill_announcements(Announcements *_Nullable announce);
/* The declarations below are not public, they are exposed only for tests. */
/** @private
* Return xor of first ANNOUNCE_BUCKET_PREFIX_LENGTH bits from one bit after
* base and pk first differ
*/
non_null()
uint16_t announce_get_bucketnum(const uint8_t *base, const uint8_t *pk);
uint16_t announce_get_bucketnum(const uint8_t *_Nonnull base, const uint8_t *_Nonnull pk);
/** @private */
non_null(1, 2) nullable(3)
bool announce_store_data(Announcements *announce, const uint8_t *data_public_key,
const uint8_t *data, uint32_t length, uint32_t timeout);
bool announce_store_data(Announcements *_Nonnull announce, const uint8_t *_Nonnull data_public_key,
const uint8_t *_Nullable data, uint32_t length, uint32_t timeout);
/** @private */
#define MAX_MAX_ANNOUNCEMENT_TIMEOUT 900
#define MIN_MAX_ANNOUNCEMENT_TIMEOUT 10

View File

@@ -18,14 +18,11 @@
#define GNU_PRINTF(f, a)
#endif
#if defined(__GNUC__) && defined(_DEBUG)
#define non_null(...) __attribute__((__nonnull__(__VA_ARGS__)))
#else
#define non_null(...)
#ifndef __clang__
#define _Nonnull
#define _Nullable
#endif
#define nullable(...)
#ifdef SPARSE
#define bitwise __attribute__((bitwise))
#define force __attribute__((force))

View File

@@ -19,22 +19,19 @@ struct Bin_Pack {
cmp_ctx_t ctx;
};
non_null()
static bool null_reader(cmp_ctx_t *ctx, void *data, size_t limit)
static bool null_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
{
assert(limit == 0);
return false;
}
non_null()
static bool null_skipper(cmp_ctx_t *ctx, size_t count)
static bool null_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
{
assert(count == 0);
return false;
}
non_null()
static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
static size_t buf_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
{
const uint8_t *bytes = (const uint8_t *)data;
Bin_Pack *bp = (Bin_Pack *)ctx->buf;
@@ -55,8 +52,7 @@ static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
return count;
}
non_null(1) nullable(2)
static void bin_pack_init(Bin_Pack *bp, uint8_t *buf, uint32_t buf_size)
static void bin_pack_init(Bin_Pack *_Nonnull bp, uint8_t *_Nullable buf, uint32_t buf_size)
{
bp->bytes = buf;
bp->bytes_size = buf_size;

View File

@@ -44,7 +44,7 @@ typedef struct Bin_Pack Bin_Pack;
* This function would typically cast the `void *` to the actual object pointer type and then call
* more appropriately typed packing functions.
*/
typedef bool bin_pack_cb(const void *obj, const Logger *logger, Bin_Pack *bp);
typedef bool bin_pack_cb(const void *_Nullable obj, const Logger *_Nullable logger, Bin_Pack *_Nonnull bp);
/** @brief Function used to pack an array of objects.
*
@@ -54,7 +54,7 @@ typedef bool bin_pack_cb(const void *obj, const Logger *logger, Bin_Pack *bp);
* @param arr is the object array as void pointer.
* @param index is the index in the object array that is currently being packed.
*/
typedef bool bin_pack_array_cb(const void *arr, uint32_t index, const Logger *logger, Bin_Pack *bp);
typedef bool bin_pack_array_cb(const void *_Nullable arr, uint32_t index, const Logger *_Nullable logger, Bin_Pack *_Nonnull bp);
/** @brief Determine the serialised size of an object.
*
@@ -65,9 +65,7 @@ typedef bool bin_pack_array_cb(const void *arr, uint32_t index, const Logger *lo
* @return The packed size of the passed object according to the callback.
* @retval UINT32_MAX in case of errors such as buffer overflow.
*/
non_null(1) nullable(2, 3)
uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj, const Logger *logger);
uint32_t bin_pack_obj_size(bin_pack_cb *_Nonnull callback, const void *_Nullable obj, const Logger *_Nullable logger);
/** @brief Pack an object into a buffer of a given size.
*
* This function creates and initialises a `Bin_Pack` packer object, calls the callback with the
@@ -88,9 +86,7 @@ uint32_t bin_pack_obj_size(bin_pack_cb *callback, const void *obj, const Logger
*
* @retval false if an error occurred (e.g. buffer overflow).
*/
non_null(1, 4) nullable(2, 3)
bool bin_pack_obj(bin_pack_cb *callback, const void *obj, const Logger *logger, uint8_t *buf, uint32_t buf_size);
bool bin_pack_obj(bin_pack_cb *_Nonnull callback, const void *_Nullable obj, const Logger *_Nullable logger, uint8_t *_Nonnull buf, uint32_t buf_size);
/** @brief Determine the serialised size of an object array.
*
* Behaves exactly like `bin_pack_obj_b_array` but doesn't write.
@@ -104,9 +100,7 @@ bool bin_pack_obj(bin_pack_cb *callback, const void *obj, const Logger *logger,
* @return The packed size of the passed object array according to the callback.
* @retval UINT32_MAX in case of errors such as buffer overflow.
*/
non_null(1) nullable(2, 4)
uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger);
uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger);
/** @brief Pack an object array into a buffer of a given size.
*
* Similar to `bin_pack_obj_array` but does not write the array length, so
@@ -124,9 +118,7 @@ uint32_t bin_pack_obj_array_b_size(bin_pack_array_cb *callback, const void *arr,
*
* @retval false if an error occurred (e.g. buffer overflow).
*/
non_null(1, 5) nullable(2, 4)
bool bin_pack_obj_array_b(bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger, uint8_t *buf, uint32_t buf_size);
bool bin_pack_obj_array_b(bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger, uint8_t *_Nonnull buf, uint32_t buf_size);
/** @brief Encode an object array as MessagePack array into a bin packer.
*
* Calls the callback `arr_size` times with increasing `index` argument from 0 to
@@ -150,51 +142,48 @@ bool bin_pack_obj_array_b(bin_pack_array_cb *callback, const void *arr, uint32_t
*
* @retval false if an error occurred (e.g. buffer overflow).
*/
non_null(1, 2) nullable(3, 5)
bool bin_pack_obj_array(Bin_Pack *bp, bin_pack_array_cb *callback, const void *arr, uint32_t arr_size, const Logger *logger);
bool bin_pack_obj_array(Bin_Pack *_Nonnull bp, bin_pack_array_cb *_Nonnull callback, const void *_Nullable arr, uint32_t arr_size, const Logger *_Nullable logger);
/** @brief Start packing a MessagePack array.
*
* A call to this function must be followed by exactly `size` calls to other functions below.
*/
non_null()
bool bin_pack_array(Bin_Pack *bp, uint32_t size);
bool bin_pack_array(Bin_Pack *_Nonnull bp, uint32_t size);
/** @brief Pack a MessagePack bool. */
non_null() bool bin_pack_bool(Bin_Pack *bp, bool val);
bool bin_pack_bool(Bin_Pack *_Nonnull bp, bool val);
/** @brief Pack a `uint8_t` as MessagePack positive integer. */
non_null() bool bin_pack_u08(Bin_Pack *bp, uint8_t val);
bool bin_pack_u08(Bin_Pack *_Nonnull bp, uint8_t val);
/** @brief Pack a `uint16_t` as MessagePack positive integer. */
non_null() bool bin_pack_u16(Bin_Pack *bp, uint16_t val);
bool bin_pack_u16(Bin_Pack *_Nonnull bp, uint16_t val);
/** @brief Pack a `uint32_t` as MessagePack positive integer. */
non_null() bool bin_pack_u32(Bin_Pack *bp, uint32_t val);
bool bin_pack_u32(Bin_Pack *_Nonnull bp, uint32_t val);
/** @brief Pack a `uint64_t` as MessagePack positive integer. */
non_null() bool bin_pack_u64(Bin_Pack *bp, uint64_t val);
bool bin_pack_u64(Bin_Pack *_Nonnull bp, uint64_t val);
/** @brief Pack an empty array member as a MessagePack nil value. */
non_null() bool bin_pack_nil(Bin_Pack *bp);
bool bin_pack_nil(Bin_Pack *_Nonnull bp);
/** @brief Pack a byte array as MessagePack bin. */
non_null() bool bin_pack_bin(Bin_Pack *bp, const uint8_t *data, uint32_t length);
bool bin_pack_bin(Bin_Pack *_Nonnull bp, const uint8_t *_Nonnull data, uint32_t length);
/** @brief Start packing a custom binary representation.
*
* A call to this function must be followed by exactly `size` bytes packed by functions below.
*/
non_null() bool bin_pack_bin_marker(Bin_Pack *bp, uint32_t size);
bool bin_pack_bin_marker(Bin_Pack *_Nonnull bp, uint32_t size);
/** @brief Write a `uint8_t` directly to the packer in 1 byte. */
non_null() bool bin_pack_u08_b(Bin_Pack *bp, uint8_t val);
bool bin_pack_u08_b(Bin_Pack *_Nonnull bp, uint8_t val);
/** @brief Write a `uint16_t` as big endian 16 bit int in 2 bytes. */
non_null() bool bin_pack_u16_b(Bin_Pack *bp, uint16_t val);
bool bin_pack_u16_b(Bin_Pack *_Nonnull bp, uint16_t val);
/** @brief Write a `uint32_t` as big endian 32 bit int in 4 bytes. */
non_null() bool bin_pack_u32_b(Bin_Pack *bp, uint32_t val);
bool bin_pack_u32_b(Bin_Pack *_Nonnull bp, uint32_t val);
/** @brief Write a `uint64_t` as big endian 64 bit int in 8 bytes. */
non_null() bool bin_pack_u64_b(Bin_Pack *bp, uint64_t val);
bool bin_pack_u64_b(Bin_Pack *_Nonnull bp, uint64_t val);
/** @brief Write a byte array directly to the packer in `length` bytes.
*
* Note that unless you prepend the array length manually, there is no record of it in the resulting
* serialised representation.
*/
non_null() bool bin_pack_bin_b(Bin_Pack *bp, const uint8_t *data, uint32_t length);
bool bin_pack_bin_b(Bin_Pack *_Nonnull bp, const uint8_t *_Nonnull data, uint32_t length);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -20,8 +20,7 @@ struct Bin_Unpack {
cmp_ctx_t ctx;
};
non_null()
static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
static bool buf_reader(cmp_ctx_t *_Nonnull ctx, void *_Nonnull data, size_t limit)
{
uint8_t *bytes = (uint8_t *)data;
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
@@ -35,8 +34,7 @@ static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
return true;
}
non_null()
static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
static bool buf_skipper(cmp_ctx_t *_Nonnull ctx, size_t count)
{
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
assert(reader != nullptr && reader->bytes != nullptr);
@@ -48,15 +46,13 @@ static bool buf_skipper(cmp_ctx_t *ctx, size_t count)
return true;
}
non_null()
static size_t null_writer(cmp_ctx_t *ctx, const void *data, size_t count)
static size_t null_writer(cmp_ctx_t *_Nonnull ctx, const void *_Nonnull data, size_t count)
{
assert(count == 0);
return 0;
}
non_null()
static void bin_unpack_init(Bin_Unpack *bu, const Memory *mem, const uint8_t *buf, uint32_t buf_size)
static void bin_unpack_init(Bin_Unpack *_Nonnull bu, const Memory *_Nonnull mem, const uint8_t *_Nonnull buf, uint32_t buf_size)
{
bu->mem = mem;
bu->bytes = buf;

View File

@@ -29,7 +29,7 @@ typedef struct Bin_Unpack Bin_Unpack;
* This function would typically cast the `void *` to the actual object pointer type and then call
* more appropriately typed unpacking functions.
*/
typedef bool bin_unpack_cb(void *obj, Bin_Unpack *bu);
typedef bool bin_unpack_cb(void *_Nonnull obj, Bin_Unpack *_Nonnull bu);
/** @brief Unpack an object from a buffer of a given size.
*
@@ -46,8 +46,7 @@ typedef bool bin_unpack_cb(void *obj, Bin_Unpack *bu);
*
* @retval false if an error occurred (e.g. buffer overrun).
*/
non_null()
bool bin_unpack_obj(const Memory *mem, bin_unpack_cb *callback, void *obj, const uint8_t *buf, uint32_t buf_size);
bool bin_unpack_obj(const Memory *_Nonnull mem, bin_unpack_cb *_Nonnull callback, void *_Nonnull obj, const uint8_t *_Nonnull buf, uint32_t buf_size);
/** @brief Start unpacking a MessagePack array.
*
@@ -55,7 +54,7 @@ bool bin_unpack_obj(const Memory *mem, bin_unpack_cb *callback, void *obj, const
*
* @param size Will contain the number of array elements following the array marker.
*/
non_null() bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size);
bool bin_unpack_array(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull size);
/** @brief Start unpacking a fixed size MessagePack array.
*
@@ -64,21 +63,19 @@ non_null() bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size);
*
* @retval false if the packed array size is not exactly the required size.
*/
non_null(1) nullable(3)
bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size, uint32_t *actual_size);
bool bin_unpack_array_fixed(Bin_Unpack *_Nonnull bu, uint32_t required_size, uint32_t *_Nullable actual_size);
/** @brief Unpack a MessagePack bool. */
non_null() bool bin_unpack_bool(Bin_Unpack *bu, bool *val);
bool bin_unpack_bool(Bin_Unpack *_Nonnull bu, bool *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint8_t`. */
non_null() bool bin_unpack_u08(Bin_Unpack *bu, uint8_t *val);
bool bin_unpack_u08(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint16_t`. */
non_null() bool bin_unpack_u16(Bin_Unpack *bu, uint16_t *val);
bool bin_unpack_u16(Bin_Unpack *_Nonnull bu, uint16_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint32_t`. */
non_null() bool bin_unpack_u32(Bin_Unpack *bu, uint32_t *val);
bool bin_unpack_u32(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull val);
/** @brief Unpack a MessagePack positive int into a `uint64_t`. */
non_null() bool bin_unpack_u64(Bin_Unpack *bu, uint64_t *val);
bool bin_unpack_u64(Bin_Unpack *_Nonnull bu, uint64_t *_Nonnull val);
/** @brief Unpack a Messagepack nil value. */
non_null() bool bin_unpack_nil(Bin_Unpack *bu);
bool bin_unpack_nil(Bin_Unpack *_Nonnull bu);
/** @brief Unpack a MessagePack bin into a newly allocated byte array.
*
@@ -87,37 +84,37 @@ non_null() bool bin_unpack_nil(Bin_Unpack *bu);
* remaining to be unpacked as the bin claims to need, so it's not possible to cause an arbitrarily
* large allocation unless the input array was already that large.
*/
non_null() bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_ptr);
bool bin_unpack_bin(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull *_Nonnull data_ptr, uint32_t *_Nonnull data_length_ptr);
/** @brief Unpack a variable size MessagePack bin into a fixed size byte array.
*
* Stores unpacked data into `data` with its length stored in `data_length_ptr`. This function does
* not allocate memory and requires that `max_data_length` is less than or equal to `sizeof(arr)`
* when `arr` is passed as `data` pointer.
*/
non_null() bool bin_unpack_bin_max(Bin_Unpack *bu, uint8_t *data, uint16_t *data_length_ptr, uint16_t max_data_length);
bool bin_unpack_bin_max(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint16_t *_Nonnull data_length_ptr, uint16_t max_data_length);
/** @brief Unpack a MessagePack bin of a fixed length into a pre-allocated byte array.
*
* Similar to the function above, but doesn't output the data length.
*/
non_null() bool bin_unpack_bin_fixed(Bin_Unpack *bu, uint8_t *data, uint32_t data_length);
bool bin_unpack_bin_fixed(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint32_t data_length);
/** @brief Start unpacking a custom binary representation.
*
* A call to this function must be followed by exactly `size` bytes packed by functions below.
*/
non_null() bool bin_unpack_bin_size(Bin_Unpack *bu, uint32_t *size);
bool bin_unpack_bin_size(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull size);
/** @brief Read a `uint8_t` directly from the unpacker, consuming 1 byte. */
non_null() bool bin_unpack_u08_b(Bin_Unpack *bu, uint8_t *val);
bool bin_unpack_u08_b(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull val);
/** @brief Read a `uint16_t` as big endian 16 bit int, consuming 2 bytes. */
non_null() bool bin_unpack_u16_b(Bin_Unpack *bu, uint16_t *val);
bool bin_unpack_u16_b(Bin_Unpack *_Nonnull bu, uint16_t *_Nonnull val);
/** @brief Read a `uint32_t` as big endian 32 bit int, consuming 4 bytes. */
non_null() bool bin_unpack_u32_b(Bin_Unpack *bu, uint32_t *val);
bool bin_unpack_u32_b(Bin_Unpack *_Nonnull bu, uint32_t *_Nonnull val);
/** @brief Read a `uint64_t` as big endian 64 bit int, consuming 8 bytes. */
non_null() bool bin_unpack_u64_b(Bin_Unpack *bu, uint64_t *val);
bool bin_unpack_u64_b(Bin_Unpack *_Nonnull bu, uint64_t *_Nonnull val);
/** @brief Read a byte array directly from the packer, consuming `length` bytes. */
non_null() bool bin_unpack_bin_b(Bin_Unpack *bu, uint8_t *data, uint32_t length);
bool bin_unpack_bin_b(Bin_Unpack *_Nonnull bu, uint8_t *_Nonnull data, uint32_t length);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -88,8 +88,7 @@ const uint8_t *get_chat_id(const Extended_Public_Key *key)
}
#if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
non_null()
static uint8_t *crypto_malloc(const Memory *mem, size_t bytes)
static uint8_t *crypto_malloc(const Memory *_Nonnull mem, size_t bytes)
{
uint8_t *ptr = (uint8_t *)mem_balloc(mem, bytes);
@@ -100,8 +99,7 @@ static uint8_t *crypto_malloc(const Memory *mem, size_t bytes)
return ptr;
}
non_null(1) nullable(2)
static void crypto_free(const Memory *mem, uint8_t *ptr, size_t bytes)
static void crypto_free(const Memory *_Nonnull mem, uint8_t *_Nullable ptr, size_t bytes)
{
if (ptr != nullptr) {
crypto_memzero(ptr, bytes);
@@ -495,14 +493,12 @@ void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
}
non_null()
static void sys_random_bytes(void *obj, uint8_t *bytes, size_t length)
static void sys_random_bytes(void *_Nonnull obj, uint8_t *_Nonnull bytes, size_t length)
{
randombytes(bytes, length);
}
non_null()
static uint32_t sys_random_uniform(void *obj, uint32_t upper_bound)
static uint32_t sys_random_uniform(void *_Nonnull obj, uint32_t upper_bound)
{
return randombytes_uniform(upper_bound);
}

View File

@@ -84,19 +84,19 @@ extern "C" {
* secure pseudo-random number generator (CSPRNG). The security of Tox heavily
* depends on the security of this RNG.
*/
typedef void crypto_random_bytes_cb(void *obj, uint8_t *bytes, size_t length);
typedef void crypto_random_bytes_cb(void *_Nullable obj, uint8_t *_Nonnull bytes, size_t length);
/** @brief Generate a random integer between 0 and @p upper_bound.
*
* Should produce a uniform random distribution, but Tox security does not
* depend on this being correct. In principle, it could even be a non-CSPRNG.
*/
typedef uint32_t crypto_random_uniform_cb(void *obj, uint32_t upper_bound);
typedef uint32_t crypto_random_uniform_cb(void *_Nullable obj, uint32_t upper_bound);
/** @brief Virtual function table for Random. */
typedef struct Random_Funcs {
crypto_random_bytes_cb *random_bytes;
crypto_random_uniform_cb *random_uniform;
crypto_random_bytes_cb *_Nullable random_bytes;
crypto_random_uniform_cb *_Nullable random_uniform;
} Random_Funcs;
/** @brief Random number generator object.
@@ -106,15 +106,15 @@ typedef struct Random_Funcs {
* CSPRNG and use `os_random` below.
*/
typedef struct Random {
const Random_Funcs *funcs;
void *obj;
const Random_Funcs *_Nullable funcs;
void *_Nullable obj;
} Random;
/** @brief System random number generator.
*
* Uses libsodium's CSPRNG (on Linux, `/dev/urandom`).
*/
const Random *os_random(void);
const Random *_Nullable os_random(void);
/**
* @brief The number of bytes in an encryption public key used by DHT group chats.
@@ -168,24 +168,21 @@ const Random *os_random(void);
* will be no reads to the written data. Use this function if you want to be
* sure the memory is indeed zeroed.
*/
non_null()
void crypto_memzero(void *data, size_t length);
void crypto_memzero(void *_Nonnull data, size_t length);
/**
* @brief Compute a SHA256 hash (32 bytes).
*
* @param[out] hash The SHA256 hash of @p data will be written to this byte array.
*/
non_null()
void crypto_sha256(uint8_t hash[CRYPTO_SHA256_SIZE], const uint8_t *data, size_t length);
void crypto_sha256(uint8_t hash[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t *_Nonnull data, size_t length);
/**
* @brief Compute a SHA512 hash (64 bytes).
*
* @param[out] hash The SHA512 hash of @p data will be written to this byte array.
*/
non_null()
void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t length);
void crypto_sha512(uint8_t hash[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t *_Nonnull data, size_t length);
/**
* @brief Compute an HMAC authenticator (32 bytes).
@@ -193,16 +190,12 @@ void crypto_sha512(uint8_t hash[CRYPTO_SHA512_SIZE], const uint8_t *data, size_t
* @param[out] auth Resulting authenticator.
* @param key Secret key, as generated by `new_hmac_key()`.
*/
non_null()
void crypto_hmac(uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[CRYPTO_HMAC_KEY_SIZE],
const uint8_t *data, size_t length);
void crypto_hmac(uint8_t auth[_Nonnull CRYPTO_HMAC_SIZE], const uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE], const uint8_t *_Nonnull data, size_t length);
/**
* @brief Verify an HMAC authenticator.
*/
non_null()
bool crypto_hmac_verify(const uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[CRYPTO_HMAC_KEY_SIZE],
const uint8_t *data, size_t length);
bool crypto_hmac_verify(const uint8_t auth[_Nonnull CRYPTO_HMAC_SIZE], const uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE], const uint8_t *_Nonnull data, size_t length);
/**
* @brief Compare 2 public keys of length @ref CRYPTO_PUBLIC_KEY_SIZE, not vulnerable to
@@ -211,14 +204,12 @@ bool crypto_hmac_verify(const uint8_t auth[CRYPTO_HMAC_SIZE], const uint8_t key[
* @retval true if both mem locations of length are equal
* @retval false if they are not
*/
non_null()
bool pk_equal(const uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]);
bool pk_equal(const uint8_t pk1[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t pk2[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
/**
* @brief Copy a public key from `src` to `dest`.
*/
non_null()
void pk_copy(uint8_t dest[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[CRYPTO_PUBLIC_KEY_SIZE]);
void pk_copy(uint8_t dest[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
/**
* @brief Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to
@@ -226,8 +217,7 @@ void pk_copy(uint8_t dest[CRYPTO_PUBLIC_KEY_SIZE], const uint8_t src[CRYPTO_PUBL
*
* @return true if both mem locations of length are equal, false if they are not.
*/
non_null()
bool crypto_sha512_eq(const uint8_t cksum1[CRYPTO_SHA512_SIZE], const uint8_t cksum2[CRYPTO_SHA512_SIZE]);
bool crypto_sha512_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA512_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA512_SIZE]);
/**
* @brief Compare 2 SHA256 checksums of length CRYPTO_SHA256_SIZE, not vulnerable to
@@ -235,40 +225,34 @@ bool crypto_sha512_eq(const uint8_t cksum1[CRYPTO_SHA512_SIZE], const uint8_t ck
*
* @return true if both mem locations of length are equal, false if they are not.
*/
non_null()
bool crypto_sha256_eq(const uint8_t cksum1[CRYPTO_SHA256_SIZE], const uint8_t cksum2[CRYPTO_SHA256_SIZE]);
bool crypto_sha256_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA256_SIZE]);
/**
* @brief Return a random 8 bit integer.
*/
non_null()
uint8_t random_u08(const Random *rng);
uint8_t random_u08(const Random *_Nonnull rng);
/**
* @brief Return a random 16 bit integer.
*/
non_null()
uint16_t random_u16(const Random *rng);
uint16_t random_u16(const Random *_Nonnull rng);
/**
* @brief Return a random 32 bit integer.
*/
non_null()
uint32_t random_u32(const Random *rng);
uint32_t random_u32(const Random *_Nonnull rng);
/**
* @brief Return a random 64 bit integer.
*/
non_null()
uint64_t random_u64(const Random *rng);
uint64_t random_u64(const Random *_Nonnull rng);
/**
* @brief Return a random 32 bit integer between 0 and upper_bound (excluded).
*
* This function guarantees a uniform distribution of possible outputs.
*/
non_null()
uint32_t random_range_u32(const Random *rng, uint32_t upper_bound);
uint32_t random_range_u32(const Random *_Nonnull rng, uint32_t upper_bound);
/**
* @brief Cryptographically signs a message using the supplied secret key and puts the resulting signature
@@ -283,10 +267,7 @@ uint32_t random_range_u32(const Random *rng, uint32_t upper_bound);
*
* @retval true on success.
*/
non_null()
bool crypto_signature_create(uint8_t signature[CRYPTO_SIGNATURE_SIZE],
const uint8_t *message, uint64_t message_length,
const uint8_t secret_key[SIG_SECRET_KEY_SIZE]);
bool crypto_signature_create(uint8_t signature[_Nonnull CRYPTO_SIGNATURE_SIZE], const uint8_t *_Nonnull message, uint64_t message_length, const uint8_t secret_key[_Nonnull SIG_SECRET_KEY_SIZE]);
/** @brief Verifies that the given signature was produced by a given message and public key.
*
@@ -298,22 +279,18 @@ bool crypto_signature_create(uint8_t signature[CRYPTO_SIGNATURE_SIZE],
*
* @retval true on success.
*/
non_null()
bool crypto_signature_verify(const uint8_t signature[CRYPTO_SIGNATURE_SIZE],
const uint8_t *message, uint64_t message_length,
const uint8_t public_key[SIG_PUBLIC_KEY_SIZE]);
bool crypto_signature_verify(const uint8_t signature[_Nonnull CRYPTO_SIGNATURE_SIZE], const uint8_t *_Nonnull message, uint64_t message_length,
const uint8_t public_key[_Nonnull SIG_PUBLIC_KEY_SIZE]);
/**
* @brief Fill the given nonce with random bytes.
*/
non_null()
void random_nonce(const Random *rng, uint8_t nonce[CRYPTO_NONCE_SIZE]);
void random_nonce(const Random *_Nonnull rng, uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
/**
* @brief Fill an array of bytes with random values.
*/
non_null()
void random_bytes(const Random *rng, uint8_t *bytes, size_t length);
void random_bytes(const Random *_Nonnull rng, uint8_t *_Nonnull bytes, size_t length);
/**
* @brief Check if a Tox public key CRYPTO_PUBLIC_KEY_SIZE is valid or not.
@@ -322,8 +299,7 @@ void random_bytes(const Random *rng, uint8_t *bytes, size_t length);
*
* @return false if it isn't, true if it is.
*/
non_null()
bool public_key_valid(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]);
bool public_key_valid(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE]);
typedef struct Extended_Public_Key {
uint8_t enc[CRYPTO_PUBLIC_KEY_SIZE];
@@ -348,32 +324,26 @@ typedef struct Extended_Secret_Key {
*
* @retval true on success.
*/
non_null()
bool create_extended_keypair(Extended_Public_Key *pk, Extended_Secret_Key *sk, const Random *rng);
bool create_extended_keypair(Extended_Public_Key *_Nonnull pk, Extended_Secret_Key *_Nonnull sk, const Random *_Nonnull rng);
/** Functions for groupchat extended keys */
non_null() const uint8_t *get_enc_key(const Extended_Public_Key *key);
non_null() const uint8_t *get_sig_pk(const Extended_Public_Key *key);
non_null() void set_sig_pk(Extended_Public_Key *key, const uint8_t *sig_pk);
non_null() const uint8_t *get_sig_sk(const Extended_Secret_Key *key);
non_null() const uint8_t *get_chat_id(const Extended_Public_Key *key);
const uint8_t *_Nonnull get_enc_key(const Extended_Public_Key *_Nonnull key);
const uint8_t *_Nonnull get_sig_pk(const Extended_Public_Key *_Nonnull key);
void set_sig_pk(Extended_Public_Key *_Nonnull key, const uint8_t *_Nonnull sig_pk);
const uint8_t *_Nonnull get_sig_sk(const Extended_Secret_Key *_Nonnull key);
const uint8_t *_Nonnull get_chat_id(const Extended_Public_Key *_Nonnull key);
/**
* @brief Generate a new random keypair.
*
* Every call to this function is likely to generate a different keypair.
*/
non_null()
int32_t crypto_new_keypair(const Random *rng,
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
int32_t crypto_new_keypair(const Random *_Nonnull rng, uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE]);
/**
* @brief Derive the public key from a given secret key.
*/
non_null()
void crypto_derive_public_key(uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE]);
void crypto_derive_public_key(uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE]);
/**
* @brief Encrypt message to send from secret key to public key.
@@ -386,12 +356,8 @@ void crypto_derive_public_key(uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
* @retval -1 if there was a problem.
* @return length of encrypted data if everything was fine.
*/
non_null()
int32_t encrypt_data(const Memory *mem,
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *plain, size_t length, uint8_t *encrypted);
int32_t encrypt_data(const Memory *_Nonnull mem, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
/**
* @brief Decrypt message from public key to secret key.
@@ -404,12 +370,8 @@ int32_t encrypt_data(const Memory *mem,
* @retval -1 if there was a problem (decryption failed).
* @return length of plain text data if everything was fine.
*/
non_null()
int32_t decrypt_data(const Memory *mem,
const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *encrypted, size_t length, uint8_t *plain);
int32_t decrypt_data(const Memory *_Nonnull mem, const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
/**
* @brief Fast encrypt/decrypt operations.
@@ -418,62 +380,51 @@ int32_t decrypt_data(const Memory *mem,
* shared-key generation once so it does not have to be performed on every
* encrypt/decrypt.
*/
non_null()
int32_t encrypt_precompute(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t secret_key[CRYPTO_SECRET_KEY_SIZE],
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]);
int32_t encrypt_precompute(const uint8_t public_key[_Nonnull CRYPTO_PUBLIC_KEY_SIZE], const uint8_t secret_key[_Nonnull CRYPTO_SECRET_KEY_SIZE],
uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE]);
/**
* @brief Encrypt message with precomputed shared key.
*
* Encrypts plain of length length to encrypted of length + @ref CRYPTO_MAC_SIZE
* using a shared key @ref CRYPTO_SHARED_KEY_SIZE big and a @ref CRYPTO_NONCE_SIZE
* using a shared key @ref CRYPTO_SYMMETRIC_KEY_SIZE big and a @ref CRYPTO_NONCE_SIZE
* byte nonce.
*
* @retval -1 if there was a problem.
* @return length of encrypted data if everything was fine.
*/
non_null()
int32_t encrypt_data_symmetric(const Memory *mem,
const uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *plain, size_t length, uint8_t *encrypted);
int32_t encrypt_data_symmetric(const Memory *_Nonnull mem, const uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE], const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE],
const uint8_t *_Nonnull plain, size_t length, uint8_t *_Nonnull encrypted);
/**
* @brief Decrypt message with precomputed shared key.
*
* Decrypts encrypted of length length to plain of length
* `length - CRYPTO_MAC_SIZE` using a shared key @ref CRYPTO_SHARED_KEY_SIZE
* `length - CRYPTO_MAC_SIZE` using a shared key @ref CRYPTO_SYMMETRIC_KEY_SIZE
* big and a @ref CRYPTO_NONCE_SIZE byte nonce.
*
* @retval -1 if there was a problem (decryption failed).
* @return length of plain data if everything was fine.
*/
non_null()
int32_t decrypt_data_symmetric(const Memory *mem,
const uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE],
const uint8_t nonce[CRYPTO_NONCE_SIZE],
const uint8_t *encrypted, size_t length, uint8_t *plain);
int32_t decrypt_data_symmetric(const Memory *_Nonnull mem, const uint8_t shared_key[_Nonnull CRYPTO_SHARED_KEY_SIZE], const uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE],
const uint8_t *_Nonnull encrypted, size_t length, uint8_t *_Nonnull plain);
/**
* @brief Increment the given nonce by 1 in big endian (rightmost byte incremented first).
*/
non_null()
void increment_nonce(uint8_t nonce[CRYPTO_NONCE_SIZE]);
void increment_nonce(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE]);
/**
* @brief Increment the given nonce by a given number.
*
* The number should be in host byte order.
*/
non_null()
void increment_nonce_number(uint8_t nonce[CRYPTO_NONCE_SIZE], uint32_t increment);
void increment_nonce_number(uint8_t nonce[_Nonnull CRYPTO_NONCE_SIZE], uint32_t increment);
/**
* @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
*/
non_null()
void new_symmetric_key(const Random *rng, uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]);
void new_symmetric_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_SYMMETRIC_KEY_SIZE]);
/**
* @brief Locks `length` bytes of memory pointed to by `data`.
@@ -483,8 +434,7 @@ void new_symmetric_key(const Random *rng, uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]
*
* @return true on success.
*/
non_null()
bool crypto_memlock(void *data, size_t length);
bool crypto_memlock(void *_Nonnull data, size_t length);
/**
* @brief Unlocks `length` bytes of memory pointed to by `data`.
@@ -497,14 +447,12 @@ bool crypto_memlock(void *data, size_t length);
*
* @return true on success.
*/
non_null()
bool crypto_memunlock(void *data, size_t length);
bool crypto_memunlock(void *_Nonnull data, size_t length);
/**
* @brief Generate a random secret HMAC key.
*/
non_null()
void new_hmac_key(const Random *rng, uint8_t key[CRYPTO_HMAC_KEY_SIZE]);
void new_hmac_key(const Random *_Nonnull rng, uint8_t key[_Nonnull CRYPTO_HMAC_KEY_SIZE]);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -12,7 +12,7 @@
#include "ccompat.h"
#include "crypto_core.h"
bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp)
bool pack_extended_public_key(const Extended_Public_Key *_Nonnull key, Bin_Pack *_Nonnull bp)
{
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE];
static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig),
@@ -23,7 +23,7 @@ bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp)
return bin_pack_bin(bp, ext_key, sizeof(ext_key));
}
bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp)
bool pack_extended_secret_key(const Extended_Secret_Key *_Nonnull key, Bin_Pack *_Nonnull bp)
{
uint8_t ext_key[EXT_SECRET_KEY_SIZE];
static_assert(sizeof(ext_key) == sizeof(key->enc) + sizeof(key->sig),
@@ -36,7 +36,7 @@ bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp)
return result;
}
bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu)
bool unpack_extended_public_key(Extended_Public_Key *_Nonnull key, Bin_Unpack *_Nonnull bu)
{
uint8_t ext_key[EXT_PUBLIC_KEY_SIZE];
@@ -50,7 +50,7 @@ bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu)
return true;
}
bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu)
bool unpack_extended_secret_key(Extended_Secret_Key *_Nonnull key, Bin_Unpack *_Nonnull bu)
{
uint8_t ext_key[EXT_SECRET_KEY_SIZE];

View File

@@ -19,10 +19,10 @@
extern "C" {
#endif
non_null() bool pack_extended_public_key(const Extended_Public_Key *key, Bin_Pack *bp);
non_null() bool pack_extended_secret_key(const Extended_Secret_Key *key, Bin_Pack *bp);
non_null() bool unpack_extended_public_key(Extended_Public_Key *key, Bin_Unpack *bu);
non_null() bool unpack_extended_secret_key(Extended_Secret_Key *key, Bin_Unpack *bu);
bool pack_extended_public_key(const Extended_Public_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
bool pack_extended_secret_key(const Extended_Secret_Key *_Nonnull key, Bin_Pack *_Nonnull bp);
bool unpack_extended_public_key(Extended_Public_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
bool unpack_extended_secret_key(Extended_Secret_Key *_Nonnull key, Bin_Unpack *_Nonnull bu);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Connected {
uint32_t conference_number;
};
non_null()
static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *conference_connected,
uint32_t conference_number)
static void tox_event_conference_connected_set_conference_number(Tox_Event_Conference_Connected *_Nonnull conference_connected, uint32_t conference_number)
{
assert(conference_connected != nullptr);
conference_connected->conference_number = conference_number;
@@ -38,15 +36,13 @@ uint32_t tox_event_conference_connected_get_conference_number(const Tox_Event_Co
return conference_connected->conference_number;
}
non_null()
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *conference_connected)
static void tox_event_conference_connected_construct(Tox_Event_Conference_Connected *_Nonnull conference_connected)
{
*conference_connected = (Tox_Event_Conference_Connected) {
0
};
}
non_null()
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *conference_connected, const Memory *mem)
static void tox_event_conference_connected_destruct(Tox_Event_Conference_Connected *_Nonnull conference_connected, const Memory *_Nonnull mem)
{
return;
}
@@ -57,9 +53,7 @@ bool tox_event_conference_connected_pack(
return bin_pack_u32(bp, event->conference_number);
}
non_null()
static bool tox_event_conference_connected_unpack_into(
Tox_Event_Conference_Connected *event, Bin_Unpack *bu)
static bool tox_event_conference_connected_unpack_into(Tox_Event_Conference_Connected *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
return bin_unpack_u32(bu, &event->conference_number);
@@ -97,8 +91,7 @@ void tox_event_conference_connected_free(Tox_Event_Conference_Connected *confere
mem_delete(mem, conference_connected);
}
non_null()
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Connected *tox_events_add_conference_connected(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Connected *const conference_connected = tox_event_conference_connected_new(mem);
@@ -131,8 +124,7 @@ bool tox_event_conference_connected_unpack(
return tox_event_conference_connected_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *user_data)
static Tox_Event_Conference_Connected *tox_event_conference_connected_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -32,9 +32,7 @@ struct Tox_Event_Conference_Invite {
uint32_t cookie_length;
};
non_null()
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *conference_invite,
uint32_t friend_number)
static void tox_event_conference_invite_set_friend_number(Tox_Event_Conference_Invite *_Nonnull conference_invite, uint32_t friend_number)
{
assert(conference_invite != nullptr);
conference_invite->friend_number = friend_number;
@@ -45,9 +43,7 @@ uint32_t tox_event_conference_invite_get_friend_number(const Tox_Event_Conferenc
return conference_invite->friend_number;
}
non_null()
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *conference_invite,
Tox_Conference_Type type)
static void tox_event_conference_invite_set_type(Tox_Event_Conference_Invite *_Nonnull conference_invite, Tox_Conference_Type type)
{
assert(conference_invite != nullptr);
conference_invite->type = type;
@@ -58,12 +54,10 @@ Tox_Conference_Type tox_event_conference_invite_get_type(const Tox_Event_Confere
return conference_invite->type;
}
non_null(1) nullable(2)
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *conference_invite,
const uint8_t *cookie, uint32_t cookie_length)
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *_Nonnull conference_invite,
const uint8_t *_Nullable cookie, uint32_t cookie_length)
{
assert(conference_invite != nullptr);
if (conference_invite->cookie != nullptr) {
free(conference_invite->cookie);
conference_invite->cookie = nullptr;
@@ -97,15 +91,13 @@ const uint8_t *tox_event_conference_invite_get_cookie(const Tox_Event_Conference
return conference_invite->cookie;
}
non_null()
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *conference_invite)
static void tox_event_conference_invite_construct(Tox_Event_Conference_Invite *_Nonnull conference_invite)
{
*conference_invite = (Tox_Event_Conference_Invite) {
0
};
}
non_null()
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *conference_invite, const Memory *mem)
static void tox_event_conference_invite_destruct(Tox_Event_Conference_Invite *_Nonnull conference_invite, const Memory *_Nonnull mem)
{
free(conference_invite->cookie);
}
@@ -119,9 +111,7 @@ bool tox_event_conference_invite_pack(
&& bin_pack_bin(bp, event->cookie, event->cookie_length);
}
non_null()
static bool tox_event_conference_invite_unpack_into(
Tox_Event_Conference_Invite *event, Bin_Unpack *bu)
static bool tox_event_conference_invite_unpack_into(Tox_Event_Conference_Invite *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -165,8 +155,7 @@ void tox_event_conference_invite_free(Tox_Event_Conference_Invite *conference_in
mem_delete(mem, conference_invite);
}
non_null()
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Invite *tox_events_add_conference_invite(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Invite *const conference_invite = tox_event_conference_invite_new(mem);
@@ -199,8 +188,7 @@ bool tox_event_conference_invite_unpack(
return tox_event_conference_invite_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *user_data)
static Tox_Event_Conference_Invite *tox_event_conference_invite_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -33,9 +33,7 @@ struct Tox_Event_Conference_Message {
uint32_t message_length;
};
non_null()
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *conference_message,
uint32_t conference_number)
static void tox_event_conference_message_set_conference_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t conference_number)
{
assert(conference_message != nullptr);
conference_message->conference_number = conference_number;
@@ -46,9 +44,7 @@ uint32_t tox_event_conference_message_get_conference_number(const Tox_Event_Conf
return conference_message->conference_number;
}
non_null()
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *conference_message,
uint32_t peer_number)
static void tox_event_conference_message_set_peer_number(Tox_Event_Conference_Message *_Nonnull conference_message, uint32_t peer_number)
{
assert(conference_message != nullptr);
conference_message->peer_number = peer_number;
@@ -59,9 +55,7 @@ uint32_t tox_event_conference_message_get_peer_number(const Tox_Event_Conference
return conference_message->peer_number;
}
non_null()
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *conference_message,
Tox_Message_Type type)
static void tox_event_conference_message_set_type(Tox_Event_Conference_Message *_Nonnull conference_message, Tox_Message_Type type)
{
assert(conference_message != nullptr);
conference_message->type = type;
@@ -72,12 +66,10 @@ Tox_Message_Type tox_event_conference_message_get_type(const Tox_Event_Conferenc
return conference_message->type;
}
non_null(1) nullable(2)
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *conference_message,
const uint8_t *message, uint32_t message_length)
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *_Nonnull conference_message,
const uint8_t *_Nullable message, uint32_t message_length)
{
assert(conference_message != nullptr);
if (conference_message->message != nullptr) {
free(conference_message->message);
conference_message->message = nullptr;
@@ -111,15 +103,13 @@ const uint8_t *tox_event_conference_message_get_message(const Tox_Event_Conferen
return conference_message->message;
}
non_null()
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *conference_message)
static void tox_event_conference_message_construct(Tox_Event_Conference_Message *_Nonnull conference_message)
{
*conference_message = (Tox_Event_Conference_Message) {
0
};
}
non_null()
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *conference_message, const Memory *mem)
static void tox_event_conference_message_destruct(Tox_Event_Conference_Message *_Nonnull conference_message, const Memory *_Nonnull mem)
{
free(conference_message->message);
}
@@ -134,9 +124,7 @@ bool tox_event_conference_message_pack(
&& bin_pack_bin(bp, event->message, event->message_length);
}
non_null()
static bool tox_event_conference_message_unpack_into(
Tox_Event_Conference_Message *event, Bin_Unpack *bu)
static bool tox_event_conference_message_unpack_into(Tox_Event_Conference_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -181,8 +169,7 @@ void tox_event_conference_message_free(Tox_Event_Conference_Message *conference_
mem_delete(mem, conference_message);
}
non_null()
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Message *tox_events_add_conference_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Message *const conference_message = tox_event_conference_message_new(mem);
@@ -215,8 +202,7 @@ bool tox_event_conference_message_unpack(
return tox_event_conference_message_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *user_data)
static Tox_Event_Conference_Message *tox_event_conference_message_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -25,9 +25,7 @@ struct Tox_Event_Conference_Peer_List_Changed {
uint32_t conference_number;
};
non_null()
static void tox_event_conference_peer_list_changed_set_conference_number(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed,
uint32_t conference_number)
static void tox_event_conference_peer_list_changed_set_conference_number(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed, uint32_t conference_number)
{
assert(conference_peer_list_changed != nullptr);
conference_peer_list_changed->conference_number = conference_number;
@@ -38,15 +36,13 @@ uint32_t tox_event_conference_peer_list_changed_get_conference_number(const Tox_
return conference_peer_list_changed->conference_number;
}
non_null()
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed)
static void tox_event_conference_peer_list_changed_construct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed)
{
*conference_peer_list_changed = (Tox_Event_Conference_Peer_List_Changed) {
0
};
}
non_null()
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *conference_peer_list_changed, const Memory *mem)
static void tox_event_conference_peer_list_changed_destruct(Tox_Event_Conference_Peer_List_Changed *_Nonnull conference_peer_list_changed, const Memory *_Nonnull mem)
{
return;
}
@@ -57,9 +53,7 @@ bool tox_event_conference_peer_list_changed_pack(
return bin_pack_u32(bp, event->conference_number);
}
non_null()
static bool tox_event_conference_peer_list_changed_unpack_into(
Tox_Event_Conference_Peer_List_Changed *event, Bin_Unpack *bu)
static bool tox_event_conference_peer_list_changed_unpack_into(Tox_Event_Conference_Peer_List_Changed *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
return bin_unpack_u32(bu, &event->conference_number);
@@ -97,8 +91,7 @@ void tox_event_conference_peer_list_changed_free(Tox_Event_Conference_Peer_List_
mem_delete(mem, conference_peer_list_changed);
}
non_null()
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Peer_List_Changed *tox_events_add_conference_peer_list_changed(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Peer_List_Changed *const conference_peer_list_changed = tox_event_conference_peer_list_changed_new(mem);
@@ -131,8 +124,7 @@ bool tox_event_conference_peer_list_changed_unpack(
return tox_event_conference_peer_list_changed_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *user_data)
static Tox_Event_Conference_Peer_List_Changed *tox_event_conference_peer_list_changed_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Peer_Name {
uint32_t name_length;
};
non_null()
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t conference_number)
static void tox_event_conference_peer_name_set_conference_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t conference_number)
{
assert(conference_peer_name != nullptr);
conference_peer_name->conference_number = conference_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_conference_peer_name_get_conference_number(const Tox_Event_Co
return conference_peer_name->conference_number;
}
non_null()
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *conference_peer_name,
uint32_t peer_number)
static void tox_event_conference_peer_name_set_peer_number(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, uint32_t peer_number)
{
assert(conference_peer_name != nullptr);
conference_peer_name->peer_number = peer_number;
@@ -56,12 +52,10 @@ uint32_t tox_event_conference_peer_name_get_peer_number(const Tox_Event_Conferen
return conference_peer_name->peer_number;
}
non_null(1) nullable(2)
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *conference_peer_name,
const uint8_t *name, uint32_t name_length)
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name,
const uint8_t *_Nullable name, uint32_t name_length)
{
assert(conference_peer_name != nullptr);
if (conference_peer_name->name != nullptr) {
free(conference_peer_name->name);
conference_peer_name->name = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_conference_peer_name_get_name(const Tox_Event_Conferenc
return conference_peer_name->name;
}
non_null()
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *conference_peer_name)
static void tox_event_conference_peer_name_construct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name)
{
*conference_peer_name = (Tox_Event_Conference_Peer_Name) {
0
};
}
non_null()
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *conference_peer_name, const Memory *mem)
static void tox_event_conference_peer_name_destruct(Tox_Event_Conference_Peer_Name *_Nonnull conference_peer_name, const Memory *_Nonnull mem)
{
free(conference_peer_name->name);
}
@@ -117,9 +109,7 @@ bool tox_event_conference_peer_name_pack(
&& bin_pack_bin(bp, event->name, event->name_length);
}
non_null()
static bool tox_event_conference_peer_name_unpack_into(
Tox_Event_Conference_Peer_Name *event, Bin_Unpack *bu)
static bool tox_event_conference_peer_name_unpack_into(Tox_Event_Conference_Peer_Name *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_conference_peer_name_free(Tox_Event_Conference_Peer_Name *confere
mem_delete(mem, conference_peer_name);
}
non_null()
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Peer_Name *tox_events_add_conference_peer_name(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Peer_Name *const conference_peer_name = tox_event_conference_peer_name_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_conference_peer_name_unpack(
return tox_event_conference_peer_name_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *user_data)
static Tox_Event_Conference_Peer_Name *tox_event_conference_peer_name_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Conference_Title {
uint32_t title_length;
};
non_null()
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *conference_title,
uint32_t conference_number)
static void tox_event_conference_title_set_conference_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t conference_number)
{
assert(conference_title != nullptr);
conference_title->conference_number = conference_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_conference_title_get_conference_number(const Tox_Event_Confer
return conference_title->conference_number;
}
non_null()
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *conference_title,
uint32_t peer_number)
static void tox_event_conference_title_set_peer_number(Tox_Event_Conference_Title *_Nonnull conference_title, uint32_t peer_number)
{
assert(conference_title != nullptr);
conference_title->peer_number = peer_number;
@@ -56,12 +52,10 @@ uint32_t tox_event_conference_title_get_peer_number(const Tox_Event_Conference_T
return conference_title->peer_number;
}
non_null(1) nullable(2)
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *conference_title,
const uint8_t *title, uint32_t title_length)
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *_Nonnull conference_title,
const uint8_t *_Nullable title, uint32_t title_length)
{
assert(conference_title != nullptr);
if (conference_title->title != nullptr) {
free(conference_title->title);
conference_title->title = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_conference_title_get_title(const Tox_Event_Conference_T
return conference_title->title;
}
non_null()
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *conference_title)
static void tox_event_conference_title_construct(Tox_Event_Conference_Title *_Nonnull conference_title)
{
*conference_title = (Tox_Event_Conference_Title) {
0
};
}
non_null()
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *conference_title, const Memory *mem)
static void tox_event_conference_title_destruct(Tox_Event_Conference_Title *_Nonnull conference_title, const Memory *_Nonnull mem)
{
free(conference_title->title);
}
@@ -117,9 +109,7 @@ bool tox_event_conference_title_pack(
&& bin_pack_bin(bp, event->title, event->title_length);
}
non_null()
static bool tox_event_conference_title_unpack_into(
Tox_Event_Conference_Title *event, Bin_Unpack *bu)
static bool tox_event_conference_title_unpack_into(Tox_Event_Conference_Title *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_conference_title_free(Tox_Event_Conference_Title *conference_titl
mem_delete(mem, conference_title);
}
non_null()
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *events, const Memory *mem)
static Tox_Event_Conference_Title *tox_events_add_conference_title(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Conference_Title *const conference_title = tox_event_conference_title_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_conference_title_unpack(
return tox_event_conference_title_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *user_data)
static Tox_Event_Conference_Title *tox_event_conference_title_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,20 +30,17 @@ struct Tox_Event_Dht_Nodes_Response {
uint16_t port;
};
non_null()
static bool tox_event_dht_nodes_response_set_public_key(Tox_Event_Dht_Nodes_Response *dht_nodes_response, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE])
static bool tox_event_dht_nodes_response_set_public_key(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE])
{
memcpy(dht_nodes_response->public_key, public_key, TOX_PUBLIC_KEY_SIZE);
return true;
}
const uint8_t *tox_event_dht_nodes_response_get_public_key(const Tox_Event_Dht_Nodes_Response *dht_nodes_response)
const uint8_t *_Nonnull tox_event_dht_nodes_response_get_public_key(const Tox_Event_Dht_Nodes_Response *dht_nodes_response)
{
return dht_nodes_response->public_key;
}
non_null()
static bool tox_event_dht_nodes_response_set_ip(Tox_Event_Dht_Nodes_Response *dht_nodes_response,
const char *ip, uint32_t ip_length, const Memory *mem)
static bool tox_event_dht_nodes_response_set_ip(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const char *_Nonnull ip, uint32_t ip_length, const Memory *_Nonnull mem)
{
if (dht_nodes_response->ip != nullptr) {
mem_delete(mem, dht_nodes_response->ip);
@@ -71,8 +68,7 @@ const uint8_t *tox_event_dht_nodes_response_get_ip(const Tox_Event_Dht_Nodes_Res
return dht_nodes_response->ip;
}
non_null()
static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *dht_nodes_response, uint16_t port)
static bool tox_event_dht_nodes_response_set_port(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, uint16_t port)
{
dht_nodes_response->port = port;
return true;
@@ -82,8 +78,7 @@ uint16_t tox_event_dht_nodes_response_get_port(const Tox_Event_Dht_Nodes_Respons
return dht_nodes_response->port;
}
non_null()
static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *dht_nodes_response)
static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response)
{
*dht_nodes_response = (Tox_Event_Dht_Nodes_Response) {
{
@@ -91,8 +86,7 @@ static void tox_event_dht_nodes_response_construct(Tox_Event_Dht_Nodes_Response
}
};
}
non_null()
static void tox_event_dht_nodes_response_destruct(Tox_Event_Dht_Nodes_Response *dht_nodes_response, const Memory *mem)
static void tox_event_dht_nodes_response_destruct(Tox_Event_Dht_Nodes_Response *_Nonnull dht_nodes_response, const Memory *_Nonnull mem)
{
mem_delete(mem, dht_nodes_response->ip);
}
@@ -106,9 +100,7 @@ bool tox_event_dht_nodes_response_pack(
&& bin_pack_u16(bp, event->port);
}
non_null()
static bool tox_event_dht_nodes_response_unpack_into(
Tox_Event_Dht_Nodes_Response *event, Bin_Unpack *bu)
static bool tox_event_dht_nodes_response_unpack_into(Tox_Event_Dht_Nodes_Response *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
return false;
@@ -146,8 +138,7 @@ void tox_event_dht_nodes_response_free(Tox_Event_Dht_Nodes_Response *dht_nodes_r
mem_delete(mem, dht_nodes_response);
}
non_null()
static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *events, const Memory *mem)
static Tox_Event_Dht_Nodes_Response *tox_events_add_dht_nodes_response(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Dht_Nodes_Response *const dht_nodes_response = tox_event_dht_nodes_response_new(mem);
@@ -178,8 +169,7 @@ bool tox_event_dht_nodes_response_unpack(
return tox_event_dht_nodes_response_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *user_data)
static Tox_Event_Dht_Nodes_Response *tox_event_dht_nodes_response_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -16,17 +16,17 @@ extern "C" {
#endif
struct Tox_Events {
Tox_Event *events;
Tox_Event *_Nonnull events;
uint32_t events_size;
uint32_t events_capacity;
const Memory *mem;
const Memory *_Nonnull mem;
};
typedef struct Tox_Events_State {
Tox_Err_Events_Iterate error;
const Memory *mem;
Tox_Events *events;
const Memory *_Nonnull mem;
Tox_Events *_Nonnull events;
} Tox_Events_State;
tox_conference_connected_cb tox_events_handle_conference_connected;
@@ -70,11 +70,9 @@ tox_group_self_join_cb tox_events_handle_group_self_join;
tox_group_join_fail_cb tox_events_handle_group_join_fail;
tox_group_moderation_cb tox_events_handle_group_moderation;
non_null()
Tox_Events_State *tox_events_alloc(void *user_data);
Tox_Events_State *_Nonnull tox_events_alloc(void *_Nonnull user_data);
non_null()
bool tox_events_add(Tox_Events *events, const Tox_Event *event);
bool tox_events_add(Tox_Events *_Nonnull events, const Tox_Event *_Nonnull event);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -28,9 +28,7 @@ struct Tox_Event_File_Chunk_Request {
uint16_t length;
};
non_null()
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t friend_number)
static void tox_event_file_chunk_request_set_friend_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t friend_number)
{
assert(file_chunk_request != nullptr);
file_chunk_request->friend_number = friend_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_file_chunk_request_get_friend_number(const Tox_Event_File_Chu
return file_chunk_request->friend_number;
}
non_null()
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *file_chunk_request,
uint32_t file_number)
static void tox_event_file_chunk_request_set_file_number(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint32_t file_number)
{
assert(file_chunk_request != nullptr);
file_chunk_request->file_number = file_number;
@@ -54,9 +50,7 @@ uint32_t tox_event_file_chunk_request_get_file_number(const Tox_Event_File_Chunk
return file_chunk_request->file_number;
}
non_null()
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *file_chunk_request,
uint64_t position)
static void tox_event_file_chunk_request_set_position(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint64_t position)
{
assert(file_chunk_request != nullptr);
file_chunk_request->position = position;
@@ -67,9 +61,7 @@ uint64_t tox_event_file_chunk_request_get_position(const Tox_Event_File_Chunk_Re
return file_chunk_request->position;
}
non_null()
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *file_chunk_request,
uint16_t length)
static void tox_event_file_chunk_request_set_length(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, uint16_t length)
{
assert(file_chunk_request != nullptr);
file_chunk_request->length = length;
@@ -80,15 +72,13 @@ uint16_t tox_event_file_chunk_request_get_length(const Tox_Event_File_Chunk_Requ
return file_chunk_request->length;
}
non_null()
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *file_chunk_request)
static void tox_event_file_chunk_request_construct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request)
{
*file_chunk_request = (Tox_Event_File_Chunk_Request) {
0
};
}
non_null()
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *file_chunk_request, const Memory *mem)
static void tox_event_file_chunk_request_destruct(Tox_Event_File_Chunk_Request *_Nonnull file_chunk_request, const Memory *_Nonnull mem)
{
return;
}
@@ -103,9 +93,7 @@ bool tox_event_file_chunk_request_pack(
&& bin_pack_u16(bp, event->length);
}
non_null()
static bool tox_event_file_chunk_request_unpack_into(
Tox_Event_File_Chunk_Request *event, Bin_Unpack *bu)
static bool tox_event_file_chunk_request_unpack_into(Tox_Event_File_Chunk_Request *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -150,8 +138,7 @@ void tox_event_file_chunk_request_free(Tox_Event_File_Chunk_Request *file_chunk_
mem_delete(mem, file_chunk_request);
}
non_null()
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *events, const Memory *mem)
static Tox_Event_File_Chunk_Request *tox_events_add_file_chunk_request(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_File_Chunk_Request *const file_chunk_request = tox_event_file_chunk_request_new(mem);
@@ -184,8 +171,7 @@ bool tox_event_file_chunk_request_unpack(
return tox_event_file_chunk_request_unpack_into(*event, bu);
}
non_null()
static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *user_data)
static Tox_Event_File_Chunk_Request *tox_event_file_chunk_request_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -32,9 +32,7 @@ struct Tox_Event_File_Recv {
uint32_t filename_length;
};
non_null()
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *file_recv,
uint32_t friend_number)
static void tox_event_file_recv_set_friend_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t friend_number)
{
assert(file_recv != nullptr);
file_recv->friend_number = friend_number;
@@ -45,9 +43,7 @@ uint32_t tox_event_file_recv_get_friend_number(const Tox_Event_File_Recv *file_r
return file_recv->friend_number;
}
non_null()
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *file_recv,
uint32_t file_number)
static void tox_event_file_recv_set_file_number(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t file_number)
{
assert(file_recv != nullptr);
file_recv->file_number = file_number;
@@ -58,9 +54,7 @@ uint32_t tox_event_file_recv_get_file_number(const Tox_Event_File_Recv *file_rec
return file_recv->file_number;
}
non_null()
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *file_recv,
uint32_t kind)
static void tox_event_file_recv_set_kind(Tox_Event_File_Recv *_Nonnull file_recv, uint32_t kind)
{
assert(file_recv != nullptr);
file_recv->kind = kind;
@@ -71,9 +65,7 @@ uint32_t tox_event_file_recv_get_kind(const Tox_Event_File_Recv *file_recv)
return file_recv->kind;
}
non_null()
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *file_recv,
uint64_t file_size)
static void tox_event_file_recv_set_file_size(Tox_Event_File_Recv *_Nonnull file_recv, uint64_t file_size)
{
assert(file_recv != nullptr);
file_recv->file_size = file_size;
@@ -84,12 +76,10 @@ uint64_t tox_event_file_recv_get_file_size(const Tox_Event_File_Recv *file_recv)
return file_recv->file_size;
}
non_null(1) nullable(2)
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv,
const uint8_t *filename, uint32_t filename_length)
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *_Nonnull file_recv,
const uint8_t *_Nullable filename, uint32_t filename_length)
{
assert(file_recv != nullptr);
if (file_recv->filename != nullptr) {
free(file_recv->filename);
file_recv->filename = nullptr;
@@ -123,15 +113,13 @@ const uint8_t *tox_event_file_recv_get_filename(const Tox_Event_File_Recv *file_
return file_recv->filename;
}
non_null()
static void tox_event_file_recv_construct(Tox_Event_File_Recv *file_recv)
static void tox_event_file_recv_construct(Tox_Event_File_Recv *_Nonnull file_recv)
{
*file_recv = (Tox_Event_File_Recv) {
0
};
}
non_null()
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *file_recv, const Memory *mem)
static void tox_event_file_recv_destruct(Tox_Event_File_Recv *_Nonnull file_recv, const Memory *_Nonnull mem)
{
free(file_recv->filename);
}
@@ -147,9 +135,7 @@ bool tox_event_file_recv_pack(
&& bin_pack_bin(bp, event->filename, event->filename_length);
}
non_null()
static bool tox_event_file_recv_unpack_into(
Tox_Event_File_Recv *event, Bin_Unpack *bu)
static bool tox_event_file_recv_unpack_into(Tox_Event_File_Recv *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
@@ -195,8 +181,7 @@ void tox_event_file_recv_free(Tox_Event_File_Recv *file_recv, const Memory *mem)
mem_delete(mem, file_recv);
}
non_null()
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *events, const Memory *mem)
static Tox_Event_File_Recv *tox_events_add_file_recv(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_File_Recv *const file_recv = tox_event_file_recv_new(mem);
@@ -229,8 +214,7 @@ bool tox_event_file_recv_unpack(
return tox_event_file_recv_unpack_into(*event, bu);
}
non_null()
static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *user_data)
static Tox_Event_File_Recv *tox_event_file_recv_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -31,9 +31,7 @@ struct Tox_Event_File_Recv_Chunk {
uint32_t data_length;
};
non_null()
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t friend_number)
static void tox_event_file_recv_chunk_set_friend_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t friend_number)
{
assert(file_recv_chunk != nullptr);
file_recv_chunk->friend_number = friend_number;
@@ -44,9 +42,7 @@ uint32_t tox_event_file_recv_chunk_get_friend_number(const Tox_Event_File_Recv_C
return file_recv_chunk->friend_number;
}
non_null()
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint32_t file_number)
static void tox_event_file_recv_chunk_set_file_number(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint32_t file_number)
{
assert(file_recv_chunk != nullptr);
file_recv_chunk->file_number = file_number;
@@ -57,9 +53,7 @@ uint32_t tox_event_file_recv_chunk_get_file_number(const Tox_Event_File_Recv_Chu
return file_recv_chunk->file_number;
}
non_null()
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *file_recv_chunk,
uint64_t position)
static void tox_event_file_recv_chunk_set_position(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, uint64_t position)
{
assert(file_recv_chunk != nullptr);
file_recv_chunk->position = position;
@@ -70,12 +64,10 @@ uint64_t tox_event_file_recv_chunk_get_position(const Tox_Event_File_Recv_Chunk
return file_recv_chunk->position;
}
non_null(1) nullable(2)
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_recv_chunk,
const uint8_t *data, uint32_t data_length)
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk,
const uint8_t *_Nullable data, uint32_t data_length)
{
assert(file_recv_chunk != nullptr);
if (file_recv_chunk->data != nullptr) {
free(file_recv_chunk->data);
file_recv_chunk->data = nullptr;
@@ -109,15 +101,13 @@ const uint8_t *tox_event_file_recv_chunk_get_data(const Tox_Event_File_Recv_Chun
return file_recv_chunk->data;
}
non_null()
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *file_recv_chunk)
static void tox_event_file_recv_chunk_construct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk)
{
*file_recv_chunk = (Tox_Event_File_Recv_Chunk) {
0
};
}
non_null()
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *file_recv_chunk, const Memory *mem)
static void tox_event_file_recv_chunk_destruct(Tox_Event_File_Recv_Chunk *_Nonnull file_recv_chunk, const Memory *_Nonnull mem)
{
free(file_recv_chunk->data);
}
@@ -132,9 +122,7 @@ bool tox_event_file_recv_chunk_pack(
&& bin_pack_bin(bp, event->data, event->data_length);
}
non_null()
static bool tox_event_file_recv_chunk_unpack_into(
Tox_Event_File_Recv_Chunk *event, Bin_Unpack *bu)
static bool tox_event_file_recv_chunk_unpack_into(Tox_Event_File_Recv_Chunk *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -179,8 +167,7 @@ void tox_event_file_recv_chunk_free(Tox_Event_File_Recv_Chunk *file_recv_chunk,
mem_delete(mem, file_recv_chunk);
}
non_null()
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *events, const Memory *mem)
static Tox_Event_File_Recv_Chunk *tox_events_add_file_recv_chunk(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_File_Recv_Chunk *const file_recv_chunk = tox_event_file_recv_chunk_new(mem);
@@ -213,8 +200,7 @@ bool tox_event_file_recv_chunk_unpack(
return tox_event_file_recv_chunk_unpack_into(*event, bu);
}
non_null()
static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *user_data)
static Tox_Event_File_Recv_Chunk *tox_event_file_recv_chunk_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_File_Recv_Control {
Tox_File_Control control;
};
non_null()
static void tox_event_file_recv_control_set_friend_number(Tox_Event_File_Recv_Control *file_recv_control,
uint32_t friend_number)
static void tox_event_file_recv_control_set_friend_number(Tox_Event_File_Recv_Control *_Nonnull file_recv_control, uint32_t friend_number)
{
assert(file_recv_control != nullptr);
file_recv_control->friend_number = friend_number;
@@ -42,9 +40,7 @@ uint32_t tox_event_file_recv_control_get_friend_number(const Tox_Event_File_Recv
return file_recv_control->friend_number;
}
non_null()
static void tox_event_file_recv_control_set_file_number(Tox_Event_File_Recv_Control *file_recv_control,
uint32_t file_number)
static void tox_event_file_recv_control_set_file_number(Tox_Event_File_Recv_Control *_Nonnull file_recv_control, uint32_t file_number)
{
assert(file_recv_control != nullptr);
file_recv_control->file_number = file_number;
@@ -55,9 +51,7 @@ uint32_t tox_event_file_recv_control_get_file_number(const Tox_Event_File_Recv_C
return file_recv_control->file_number;
}
non_null()
static void tox_event_file_recv_control_set_control(Tox_Event_File_Recv_Control *file_recv_control,
Tox_File_Control control)
static void tox_event_file_recv_control_set_control(Tox_Event_File_Recv_Control *_Nonnull file_recv_control, Tox_File_Control control)
{
assert(file_recv_control != nullptr);
file_recv_control->control = control;
@@ -68,15 +62,13 @@ Tox_File_Control tox_event_file_recv_control_get_control(const Tox_Event_File_Re
return file_recv_control->control;
}
non_null()
static void tox_event_file_recv_control_construct(Tox_Event_File_Recv_Control *file_recv_control)
static void tox_event_file_recv_control_construct(Tox_Event_File_Recv_Control *_Nonnull file_recv_control)
{
*file_recv_control = (Tox_Event_File_Recv_Control) {
0
};
}
non_null()
static void tox_event_file_recv_control_destruct(Tox_Event_File_Recv_Control *file_recv_control, const Memory *mem)
static void tox_event_file_recv_control_destruct(Tox_Event_File_Recv_Control *_Nonnull file_recv_control, const Memory *_Nonnull mem)
{
return;
}
@@ -90,9 +82,7 @@ bool tox_event_file_recv_control_pack(
&& tox_file_control_pack(event->control, bp);
}
non_null()
static bool tox_event_file_recv_control_unpack_into(
Tox_Event_File_Recv_Control *event, Bin_Unpack *bu)
static bool tox_event_file_recv_control_unpack_into(Tox_Event_File_Recv_Control *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -136,8 +126,7 @@ void tox_event_file_recv_control_free(Tox_Event_File_Recv_Control *file_recv_con
mem_delete(mem, file_recv_control);
}
non_null()
static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events *events, const Memory *mem)
static Tox_Event_File_Recv_Control *tox_events_add_file_recv_control(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_File_Recv_Control *const file_recv_control = tox_event_file_recv_control_new(mem);
@@ -170,8 +159,7 @@ bool tox_event_file_recv_control_unpack(
return tox_event_file_recv_control_unpack_into(*event, bu);
}
non_null()
static Tox_Event_File_Recv_Control *tox_event_file_recv_control_alloc(void *user_data)
static Tox_Event_File_Recv_Control *tox_event_file_recv_control_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Friend_Connection_Status {
Tox_Connection connection_status;
};
non_null()
static void tox_event_friend_connection_status_set_friend_number(Tox_Event_Friend_Connection_Status *friend_connection_status,
uint32_t friend_number)
static void tox_event_friend_connection_status_set_friend_number(Tox_Event_Friend_Connection_Status *_Nonnull friend_connection_status, uint32_t friend_number)
{
assert(friend_connection_status != nullptr);
friend_connection_status->friend_number = friend_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_friend_connection_status_get_friend_number(const Tox_Event_Fr
return friend_connection_status->friend_number;
}
non_null()
static void tox_event_friend_connection_status_set_connection_status(Tox_Event_Friend_Connection_Status *friend_connection_status,
Tox_Connection connection_status)
static void tox_event_friend_connection_status_set_connection_status(Tox_Event_Friend_Connection_Status *_Nonnull friend_connection_status, Tox_Connection connection_status)
{
assert(friend_connection_status != nullptr);
friend_connection_status->connection_status = connection_status;
@@ -54,15 +50,13 @@ Tox_Connection tox_event_friend_connection_status_get_connection_status(const To
return friend_connection_status->connection_status;
}
non_null()
static void tox_event_friend_connection_status_construct(Tox_Event_Friend_Connection_Status *friend_connection_status)
static void tox_event_friend_connection_status_construct(Tox_Event_Friend_Connection_Status *_Nonnull friend_connection_status)
{
*friend_connection_status = (Tox_Event_Friend_Connection_Status) {
0
};
}
non_null()
static void tox_event_friend_connection_status_destruct(Tox_Event_Friend_Connection_Status *friend_connection_status, const Memory *mem)
static void tox_event_friend_connection_status_destruct(Tox_Event_Friend_Connection_Status *_Nonnull friend_connection_status, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_friend_connection_status_pack(
&& tox_connection_pack(event->connection_status, bp);
}
non_null()
static bool tox_event_friend_connection_status_unpack_into(
Tox_Event_Friend_Connection_Status *event, Bin_Unpack *bu)
static bool tox_event_friend_connection_status_unpack_into(Tox_Event_Friend_Connection_Status *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_friend_connection_status_free(Tox_Event_Friend_Connection_Status
mem_delete(mem, friend_connection_status);
}
non_null()
static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_status(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Connection_Status *tox_events_add_friend_connection_status(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Connection_Status *const friend_connection_status = tox_event_friend_connection_status_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_friend_connection_status_unpack(
return tox_event_friend_connection_status_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Connection_Status *tox_event_friend_connection_status_alloc(void *user_data)
static Tox_Event_Friend_Connection_Status *tox_event_friend_connection_status_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Friend_Lossless_Packet {
uint32_t data_length;
};
non_null()
static void tox_event_friend_lossless_packet_set_friend_number(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet,
uint32_t friend_number)
static void tox_event_friend_lossless_packet_set_friend_number(Tox_Event_Friend_Lossless_Packet *_Nonnull friend_lossless_packet, uint32_t friend_number)
{
assert(friend_lossless_packet != nullptr);
friend_lossless_packet->friend_number = friend_number;
@@ -42,12 +40,10 @@ uint32_t tox_event_friend_lossless_packet_get_friend_number(const Tox_Event_Frie
return friend_lossless_packet->friend_number;
}
non_null(1) nullable(2)
static bool tox_event_friend_lossless_packet_set_data(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet,
const uint8_t *data, uint32_t data_length)
static bool tox_event_friend_lossless_packet_set_data(Tox_Event_Friend_Lossless_Packet *_Nonnull friend_lossless_packet,
const uint8_t *_Nullable data, uint32_t data_length)
{
assert(friend_lossless_packet != nullptr);
if (friend_lossless_packet->data != nullptr) {
free(friend_lossless_packet->data);
friend_lossless_packet->data = nullptr;
@@ -81,15 +77,13 @@ const uint8_t *tox_event_friend_lossless_packet_get_data(const Tox_Event_Friend_
return friend_lossless_packet->data;
}
non_null()
static void tox_event_friend_lossless_packet_construct(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet)
static void tox_event_friend_lossless_packet_construct(Tox_Event_Friend_Lossless_Packet *_Nonnull friend_lossless_packet)
{
*friend_lossless_packet = (Tox_Event_Friend_Lossless_Packet) {
0
};
}
non_null()
static void tox_event_friend_lossless_packet_destruct(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet, const Memory *mem)
static void tox_event_friend_lossless_packet_destruct(Tox_Event_Friend_Lossless_Packet *_Nonnull friend_lossless_packet, const Memory *_Nonnull mem)
{
free(friend_lossless_packet->data);
}
@@ -102,9 +96,7 @@ bool tox_event_friend_lossless_packet_pack(
&& bin_pack_bin(bp, event->data, event->data_length);
}
non_null()
static bool tox_event_friend_lossless_packet_unpack_into(
Tox_Event_Friend_Lossless_Packet *event, Bin_Unpack *bu)
static bool tox_event_friend_lossless_packet_unpack_into(Tox_Event_Friend_Lossless_Packet *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -147,8 +139,7 @@ void tox_event_friend_lossless_packet_free(Tox_Event_Friend_Lossless_Packet *fri
mem_delete(mem, friend_lossless_packet);
}
non_null()
static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Lossless_Packet *tox_events_add_friend_lossless_packet(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Lossless_Packet *const friend_lossless_packet = tox_event_friend_lossless_packet_new(mem);
@@ -181,8 +172,7 @@ bool tox_event_friend_lossless_packet_unpack(
return tox_event_friend_lossless_packet_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Lossless_Packet *tox_event_friend_lossless_packet_alloc(void *user_data)
static Tox_Event_Friend_Lossless_Packet *tox_event_friend_lossless_packet_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Friend_Lossy_Packet {
uint32_t data_length;
};
non_null()
static void tox_event_friend_lossy_packet_set_friend_number(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet,
uint32_t friend_number)
static void tox_event_friend_lossy_packet_set_friend_number(Tox_Event_Friend_Lossy_Packet *_Nonnull friend_lossy_packet, uint32_t friend_number)
{
assert(friend_lossy_packet != nullptr);
friend_lossy_packet->friend_number = friend_number;
@@ -42,12 +40,10 @@ uint32_t tox_event_friend_lossy_packet_get_friend_number(const Tox_Event_Friend_
return friend_lossy_packet->friend_number;
}
non_null(1) nullable(2)
static bool tox_event_friend_lossy_packet_set_data(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet,
const uint8_t *data, uint32_t data_length)
static bool tox_event_friend_lossy_packet_set_data(Tox_Event_Friend_Lossy_Packet *_Nonnull friend_lossy_packet,
const uint8_t *_Nullable data, uint32_t data_length)
{
assert(friend_lossy_packet != nullptr);
if (friend_lossy_packet->data != nullptr) {
free(friend_lossy_packet->data);
friend_lossy_packet->data = nullptr;
@@ -81,15 +77,13 @@ const uint8_t *tox_event_friend_lossy_packet_get_data(const Tox_Event_Friend_Los
return friend_lossy_packet->data;
}
non_null()
static void tox_event_friend_lossy_packet_construct(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet)
static void tox_event_friend_lossy_packet_construct(Tox_Event_Friend_Lossy_Packet *_Nonnull friend_lossy_packet)
{
*friend_lossy_packet = (Tox_Event_Friend_Lossy_Packet) {
0
};
}
non_null()
static void tox_event_friend_lossy_packet_destruct(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet, const Memory *mem)
static void tox_event_friend_lossy_packet_destruct(Tox_Event_Friend_Lossy_Packet *_Nonnull friend_lossy_packet, const Memory *_Nonnull mem)
{
free(friend_lossy_packet->data);
}
@@ -102,9 +96,7 @@ bool tox_event_friend_lossy_packet_pack(
&& bin_pack_bin(bp, event->data, event->data_length);
}
non_null()
static bool tox_event_friend_lossy_packet_unpack_into(
Tox_Event_Friend_Lossy_Packet *event, Bin_Unpack *bu)
static bool tox_event_friend_lossy_packet_unpack_into(Tox_Event_Friend_Lossy_Packet *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -147,8 +139,7 @@ void tox_event_friend_lossy_packet_free(Tox_Event_Friend_Lossy_Packet *friend_lo
mem_delete(mem, friend_lossy_packet);
}
non_null()
static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Lossy_Packet *tox_events_add_friend_lossy_packet(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Lossy_Packet *const friend_lossy_packet = tox_event_friend_lossy_packet_new(mem);
@@ -181,8 +172,7 @@ bool tox_event_friend_lossy_packet_unpack(
return tox_event_friend_lossy_packet_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Lossy_Packet *tox_event_friend_lossy_packet_alloc(void *user_data)
static Tox_Event_Friend_Lossy_Packet *tox_event_friend_lossy_packet_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -32,9 +32,7 @@ struct Tox_Event_Friend_Message {
uint32_t message_length;
};
non_null()
static void tox_event_friend_message_set_friend_number(Tox_Event_Friend_Message *friend_message,
uint32_t friend_number)
static void tox_event_friend_message_set_friend_number(Tox_Event_Friend_Message *_Nonnull friend_message, uint32_t friend_number)
{
assert(friend_message != nullptr);
friend_message->friend_number = friend_number;
@@ -45,9 +43,7 @@ uint32_t tox_event_friend_message_get_friend_number(const Tox_Event_Friend_Messa
return friend_message->friend_number;
}
non_null()
static void tox_event_friend_message_set_type(Tox_Event_Friend_Message *friend_message,
Tox_Message_Type type)
static void tox_event_friend_message_set_type(Tox_Event_Friend_Message *_Nonnull friend_message, Tox_Message_Type type)
{
assert(friend_message != nullptr);
friend_message->type = type;
@@ -58,12 +54,10 @@ Tox_Message_Type tox_event_friend_message_get_type(const Tox_Event_Friend_Messag
return friend_message->type;
}
non_null(1) nullable(2)
static bool tox_event_friend_message_set_message(Tox_Event_Friend_Message *friend_message,
const uint8_t *message, uint32_t message_length)
static bool tox_event_friend_message_set_message(Tox_Event_Friend_Message *_Nonnull friend_message,
const uint8_t *_Nullable message, uint32_t message_length)
{
assert(friend_message != nullptr);
if (friend_message->message != nullptr) {
free(friend_message->message);
friend_message->message = nullptr;
@@ -97,15 +91,13 @@ const uint8_t *tox_event_friend_message_get_message(const Tox_Event_Friend_Messa
return friend_message->message;
}
non_null()
static void tox_event_friend_message_construct(Tox_Event_Friend_Message *friend_message)
static void tox_event_friend_message_construct(Tox_Event_Friend_Message *_Nonnull friend_message)
{
*friend_message = (Tox_Event_Friend_Message) {
0
};
}
non_null()
static void tox_event_friend_message_destruct(Tox_Event_Friend_Message *friend_message, const Memory *mem)
static void tox_event_friend_message_destruct(Tox_Event_Friend_Message *_Nonnull friend_message, const Memory *_Nonnull mem)
{
free(friend_message->message);
}
@@ -119,9 +111,7 @@ bool tox_event_friend_message_pack(
&& bin_pack_bin(bp, event->message, event->message_length);
}
non_null()
static bool tox_event_friend_message_unpack_into(
Tox_Event_Friend_Message *event, Bin_Unpack *bu)
static bool tox_event_friend_message_unpack_into(Tox_Event_Friend_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -165,8 +155,7 @@ void tox_event_friend_message_free(Tox_Event_Friend_Message *friend_message, con
mem_delete(mem, friend_message);
}
non_null()
static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Message *tox_events_add_friend_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Message *const friend_message = tox_event_friend_message_new(mem);
@@ -199,8 +188,7 @@ bool tox_event_friend_message_unpack(
return tox_event_friend_message_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Message *tox_event_friend_message_alloc(void *user_data)
static Tox_Event_Friend_Message *tox_event_friend_message_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Friend_Name {
uint32_t name_length;
};
non_null()
static void tox_event_friend_name_set_friend_number(Tox_Event_Friend_Name *friend_name,
uint32_t friend_number)
static void tox_event_friend_name_set_friend_number(Tox_Event_Friend_Name *_Nonnull friend_name, uint32_t friend_number)
{
assert(friend_name != nullptr);
friend_name->friend_number = friend_number;
@@ -42,12 +40,10 @@ uint32_t tox_event_friend_name_get_friend_number(const Tox_Event_Friend_Name *fr
return friend_name->friend_number;
}
non_null(1) nullable(2)
static bool tox_event_friend_name_set_name(Tox_Event_Friend_Name *friend_name,
const uint8_t *name, uint32_t name_length)
static bool tox_event_friend_name_set_name(Tox_Event_Friend_Name *_Nonnull friend_name,
const uint8_t *_Nullable name, uint32_t name_length)
{
assert(friend_name != nullptr);
if (friend_name->name != nullptr) {
free(friend_name->name);
friend_name->name = nullptr;
@@ -81,15 +77,13 @@ const uint8_t *tox_event_friend_name_get_name(const Tox_Event_Friend_Name *frien
return friend_name->name;
}
non_null()
static void tox_event_friend_name_construct(Tox_Event_Friend_Name *friend_name)
static void tox_event_friend_name_construct(Tox_Event_Friend_Name *_Nonnull friend_name)
{
*friend_name = (Tox_Event_Friend_Name) {
0
};
}
non_null()
static void tox_event_friend_name_destruct(Tox_Event_Friend_Name *friend_name, const Memory *mem)
static void tox_event_friend_name_destruct(Tox_Event_Friend_Name *_Nonnull friend_name, const Memory *_Nonnull mem)
{
free(friend_name->name);
}
@@ -102,9 +96,7 @@ bool tox_event_friend_name_pack(
&& bin_pack_bin(bp, event->name, event->name_length);
}
non_null()
static bool tox_event_friend_name_unpack_into(
Tox_Event_Friend_Name *event, Bin_Unpack *bu)
static bool tox_event_friend_name_unpack_into(Tox_Event_Friend_Name *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -147,8 +139,7 @@ void tox_event_friend_name_free(Tox_Event_Friend_Name *friend_name, const Memory
mem_delete(mem, friend_name);
}
non_null()
static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Name *tox_events_add_friend_name(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Name *const friend_name = tox_event_friend_name_new(mem);
@@ -181,8 +172,7 @@ bool tox_event_friend_name_unpack(
return tox_event_friend_name_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Name *tox_event_friend_name_alloc(void *user_data)
static Tox_Event_Friend_Name *tox_event_friend_name_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -26,9 +26,7 @@ struct Tox_Event_Friend_Read_Receipt {
uint32_t message_id;
};
non_null()
static void tox_event_friend_read_receipt_set_friend_number(Tox_Event_Friend_Read_Receipt *friend_read_receipt,
uint32_t friend_number)
static void tox_event_friend_read_receipt_set_friend_number(Tox_Event_Friend_Read_Receipt *_Nonnull friend_read_receipt, uint32_t friend_number)
{
assert(friend_read_receipt != nullptr);
friend_read_receipt->friend_number = friend_number;
@@ -39,9 +37,7 @@ uint32_t tox_event_friend_read_receipt_get_friend_number(const Tox_Event_Friend_
return friend_read_receipt->friend_number;
}
non_null()
static void tox_event_friend_read_receipt_set_message_id(Tox_Event_Friend_Read_Receipt *friend_read_receipt,
uint32_t message_id)
static void tox_event_friend_read_receipt_set_message_id(Tox_Event_Friend_Read_Receipt *_Nonnull friend_read_receipt, uint32_t message_id)
{
assert(friend_read_receipt != nullptr);
friend_read_receipt->message_id = message_id;
@@ -52,15 +48,13 @@ uint32_t tox_event_friend_read_receipt_get_message_id(const Tox_Event_Friend_Rea
return friend_read_receipt->message_id;
}
non_null()
static void tox_event_friend_read_receipt_construct(Tox_Event_Friend_Read_Receipt *friend_read_receipt)
static void tox_event_friend_read_receipt_construct(Tox_Event_Friend_Read_Receipt *_Nonnull friend_read_receipt)
{
*friend_read_receipt = (Tox_Event_Friend_Read_Receipt) {
0
};
}
non_null()
static void tox_event_friend_read_receipt_destruct(Tox_Event_Friend_Read_Receipt *friend_read_receipt, const Memory *mem)
static void tox_event_friend_read_receipt_destruct(Tox_Event_Friend_Read_Receipt *_Nonnull friend_read_receipt, const Memory *_Nonnull mem)
{
return;
}
@@ -73,9 +67,7 @@ bool tox_event_friend_read_receipt_pack(
&& bin_pack_u32(bp, event->message_id);
}
non_null()
static bool tox_event_friend_read_receipt_unpack_into(
Tox_Event_Friend_Read_Receipt *event, Bin_Unpack *bu)
static bool tox_event_friend_read_receipt_unpack_into(Tox_Event_Friend_Read_Receipt *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -118,8 +110,7 @@ void tox_event_friend_read_receipt_free(Tox_Event_Friend_Read_Receipt *friend_re
mem_delete(mem, friend_read_receipt);
}
non_null()
static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Read_Receipt *tox_events_add_friend_read_receipt(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Read_Receipt *const friend_read_receipt = tox_event_friend_read_receipt_new(mem);
@@ -152,8 +143,7 @@ bool tox_event_friend_read_receipt_unpack(
return tox_event_friend_read_receipt_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Read_Receipt *tox_event_friend_read_receipt_alloc(void *user_data)
static Tox_Event_Friend_Read_Receipt *tox_event_friend_read_receipt_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,8 +29,7 @@ struct Tox_Event_Friend_Request {
uint32_t message_length;
};
non_null()
static bool tox_event_friend_request_set_public_key(Tox_Event_Friend_Request *friend_request, const uint8_t *public_key)
static bool tox_event_friend_request_set_public_key(Tox_Event_Friend_Request *_Nonnull friend_request, const uint8_t *_Nonnull public_key)
{
assert(friend_request != nullptr);
@@ -43,9 +42,7 @@ const uint8_t *tox_event_friend_request_get_public_key(const Tox_Event_Friend_Re
return friend_request->public_key;
}
non_null()
static bool tox_event_friend_request_set_message(Tox_Event_Friend_Request *friend_request,
const uint8_t *message, uint32_t message_length, const Memory *mem)
static bool tox_event_friend_request_set_message(Tox_Event_Friend_Request *_Nonnull friend_request, const uint8_t *_Nonnull message, uint32_t message_length, const Memory *_Nonnull mem)
{
assert(friend_request != nullptr);
@@ -77,8 +74,7 @@ const uint8_t *tox_event_friend_request_get_message(const Tox_Event_Friend_Reque
return friend_request->message;
}
non_null()
static void tox_event_friend_request_construct(Tox_Event_Friend_Request *friend_request)
static void tox_event_friend_request_construct(Tox_Event_Friend_Request *_Nonnull friend_request)
{
*friend_request = (Tox_Event_Friend_Request) {
{
@@ -86,8 +82,7 @@ static void tox_event_friend_request_construct(Tox_Event_Friend_Request *friend_
}
};
}
non_null()
static void tox_event_friend_request_destruct(Tox_Event_Friend_Request *friend_request, const Memory *mem)
static void tox_event_friend_request_destruct(Tox_Event_Friend_Request *_Nonnull friend_request, const Memory *_Nonnull mem)
{
mem_delete(mem, friend_request->message);
}
@@ -100,9 +95,7 @@ bool tox_event_friend_request_pack(
&& bin_pack_bin(bp, event->message, event->message_length);
}
non_null()
static bool tox_event_friend_request_unpack_into(
Tox_Event_Friend_Request *event, Bin_Unpack *bu)
static bool tox_event_friend_request_unpack_into(Tox_Event_Friend_Request *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -140,8 +133,7 @@ void tox_event_friend_request_free(Tox_Event_Friend_Request *friend_request, con
mem_delete(mem, friend_request);
}
non_null()
static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Request *tox_events_add_friend_request(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Request *const friend_request = tox_event_friend_request_new(mem);
@@ -174,8 +166,7 @@ bool tox_event_friend_request_unpack(
return tox_event_friend_request_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Request *tox_event_friend_request_alloc(void *user_data)
static Tox_Event_Friend_Request *tox_event_friend_request_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Friend_Status {
Tox_User_Status status;
};
non_null()
static void tox_event_friend_status_set_friend_number(Tox_Event_Friend_Status *friend_status,
uint32_t friend_number)
static void tox_event_friend_status_set_friend_number(Tox_Event_Friend_Status *_Nonnull friend_status, uint32_t friend_number)
{
assert(friend_status != nullptr);
friend_status->friend_number = friend_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_friend_status_get_friend_number(const Tox_Event_Friend_Status
return friend_status->friend_number;
}
non_null()
static void tox_event_friend_status_set_status(Tox_Event_Friend_Status *friend_status,
Tox_User_Status status)
static void tox_event_friend_status_set_status(Tox_Event_Friend_Status *_Nonnull friend_status, Tox_User_Status status)
{
assert(friend_status != nullptr);
friend_status->status = status;
@@ -54,15 +50,13 @@ Tox_User_Status tox_event_friend_status_get_status(const Tox_Event_Friend_Status
return friend_status->status;
}
non_null()
static void tox_event_friend_status_construct(Tox_Event_Friend_Status *friend_status)
static void tox_event_friend_status_construct(Tox_Event_Friend_Status *_Nonnull friend_status)
{
*friend_status = (Tox_Event_Friend_Status) {
0
};
}
non_null()
static void tox_event_friend_status_destruct(Tox_Event_Friend_Status *friend_status, const Memory *mem)
static void tox_event_friend_status_destruct(Tox_Event_Friend_Status *_Nonnull friend_status, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_friend_status_pack(
&& tox_user_status_pack(event->status, bp);
}
non_null()
static bool tox_event_friend_status_unpack_into(
Tox_Event_Friend_Status *event, Bin_Unpack *bu)
static bool tox_event_friend_status_unpack_into(Tox_Event_Friend_Status *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_friend_status_free(Tox_Event_Friend_Status *friend_status, const
mem_delete(mem, friend_status);
}
non_null()
static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Status *tox_events_add_friend_status(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Status *const friend_status = tox_event_friend_status_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_friend_status_unpack(
return tox_event_friend_status_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Status *tox_event_friend_status_alloc(void *user_data)
static Tox_Event_Friend_Status *tox_event_friend_status_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Friend_Status_Message {
uint32_t message_length;
};
non_null()
static void tox_event_friend_status_message_set_friend_number(Tox_Event_Friend_Status_Message *friend_status_message,
uint32_t friend_number)
static void tox_event_friend_status_message_set_friend_number(Tox_Event_Friend_Status_Message *_Nonnull friend_status_message, uint32_t friend_number)
{
assert(friend_status_message != nullptr);
friend_status_message->friend_number = friend_number;
@@ -42,12 +40,10 @@ uint32_t tox_event_friend_status_message_get_friend_number(const Tox_Event_Frien
return friend_status_message->friend_number;
}
non_null(1) nullable(2)
static bool tox_event_friend_status_message_set_message(Tox_Event_Friend_Status_Message *friend_status_message,
const uint8_t *message, uint32_t message_length)
static bool tox_event_friend_status_message_set_message(Tox_Event_Friend_Status_Message *_Nonnull friend_status_message,
const uint8_t *_Nullable message, uint32_t message_length)
{
assert(friend_status_message != nullptr);
if (friend_status_message->message != nullptr) {
free(friend_status_message->message);
friend_status_message->message = nullptr;
@@ -81,15 +77,13 @@ const uint8_t *tox_event_friend_status_message_get_message(const Tox_Event_Frien
return friend_status_message->message;
}
non_null()
static void tox_event_friend_status_message_construct(Tox_Event_Friend_Status_Message *friend_status_message)
static void tox_event_friend_status_message_construct(Tox_Event_Friend_Status_Message *_Nonnull friend_status_message)
{
*friend_status_message = (Tox_Event_Friend_Status_Message) {
0
};
}
non_null()
static void tox_event_friend_status_message_destruct(Tox_Event_Friend_Status_Message *friend_status_message, const Memory *mem)
static void tox_event_friend_status_message_destruct(Tox_Event_Friend_Status_Message *_Nonnull friend_status_message, const Memory *_Nonnull mem)
{
free(friend_status_message->message);
}
@@ -102,9 +96,7 @@ bool tox_event_friend_status_message_pack(
&& bin_pack_bin(bp, event->message, event->message_length);
}
non_null()
static bool tox_event_friend_status_message_unpack_into(
Tox_Event_Friend_Status_Message *event, Bin_Unpack *bu)
static bool tox_event_friend_status_message_unpack_into(Tox_Event_Friend_Status_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -147,8 +139,7 @@ void tox_event_friend_status_message_free(Tox_Event_Friend_Status_Message *frien
mem_delete(mem, friend_status_message);
}
non_null()
static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Status_Message *tox_events_add_friend_status_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Status_Message *const friend_status_message = tox_event_friend_status_message_new(mem);
@@ -181,8 +172,7 @@ bool tox_event_friend_status_message_unpack(
return tox_event_friend_status_message_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Status_Message *tox_event_friend_status_message_alloc(void *user_data)
static Tox_Event_Friend_Status_Message *tox_event_friend_status_message_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -26,9 +26,7 @@ struct Tox_Event_Friend_Typing {
bool typing;
};
non_null()
static void tox_event_friend_typing_set_friend_number(Tox_Event_Friend_Typing *friend_typing,
uint32_t friend_number)
static void tox_event_friend_typing_set_friend_number(Tox_Event_Friend_Typing *_Nonnull friend_typing, uint32_t friend_number)
{
assert(friend_typing != nullptr);
friend_typing->friend_number = friend_number;
@@ -39,9 +37,7 @@ uint32_t tox_event_friend_typing_get_friend_number(const Tox_Event_Friend_Typing
return friend_typing->friend_number;
}
non_null()
static void tox_event_friend_typing_set_typing(Tox_Event_Friend_Typing *friend_typing,
bool typing)
static void tox_event_friend_typing_set_typing(Tox_Event_Friend_Typing *_Nonnull friend_typing, bool typing)
{
assert(friend_typing != nullptr);
friend_typing->typing = typing;
@@ -52,15 +48,13 @@ bool tox_event_friend_typing_get_typing(const Tox_Event_Friend_Typing *friend_ty
return friend_typing->typing;
}
non_null()
static void tox_event_friend_typing_construct(Tox_Event_Friend_Typing *friend_typing)
static void tox_event_friend_typing_construct(Tox_Event_Friend_Typing *_Nonnull friend_typing)
{
*friend_typing = (Tox_Event_Friend_Typing) {
0
};
}
non_null()
static void tox_event_friend_typing_destruct(Tox_Event_Friend_Typing *friend_typing, const Memory *mem)
static void tox_event_friend_typing_destruct(Tox_Event_Friend_Typing *_Nonnull friend_typing, const Memory *_Nonnull mem)
{
return;
}
@@ -73,9 +67,7 @@ bool tox_event_friend_typing_pack(
&& bin_pack_bool(bp, event->typing);
}
non_null()
static bool tox_event_friend_typing_unpack_into(
Tox_Event_Friend_Typing *event, Bin_Unpack *bu)
static bool tox_event_friend_typing_unpack_into(Tox_Event_Friend_Typing *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -118,8 +110,7 @@ void tox_event_friend_typing_free(Tox_Event_Friend_Typing *friend_typing, const
mem_delete(mem, friend_typing);
}
non_null()
static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *events, const Memory *mem)
static Tox_Event_Friend_Typing *tox_events_add_friend_typing(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Friend_Typing *const friend_typing = tox_event_friend_typing_new(mem);
@@ -152,8 +143,7 @@ bool tox_event_friend_typing_unpack(
return tox_event_friend_typing_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Friend_Typing *tox_event_friend_typing_alloc(void *user_data)
static Tox_Event_Friend_Typing *tox_event_friend_typing_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Group_Custom_Packet {
uint32_t data_length;
};
non_null()
static void tox_event_group_custom_packet_set_group_number(Tox_Event_Group_Custom_Packet *group_custom_packet,
uint32_t group_number)
static void tox_event_group_custom_packet_set_group_number(Tox_Event_Group_Custom_Packet *_Nonnull group_custom_packet, uint32_t group_number)
{
assert(group_custom_packet != nullptr);
group_custom_packet->group_number = group_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_group_custom_packet_get_group_number(const Tox_Event_Group_Cu
return group_custom_packet->group_number;
}
non_null()
static void tox_event_group_custom_packet_set_peer_id(Tox_Event_Group_Custom_Packet *group_custom_packet,
uint32_t peer_id)
static void tox_event_group_custom_packet_set_peer_id(Tox_Event_Group_Custom_Packet *_Nonnull group_custom_packet, uint32_t peer_id)
{
assert(group_custom_packet != nullptr);
group_custom_packet->peer_id = peer_id;
@@ -56,12 +52,10 @@ uint32_t tox_event_group_custom_packet_get_peer_id(const Tox_Event_Group_Custom_
return group_custom_packet->peer_id;
}
non_null(1) nullable(2)
static bool tox_event_group_custom_packet_set_data(Tox_Event_Group_Custom_Packet *group_custom_packet,
const uint8_t *data, uint32_t data_length)
static bool tox_event_group_custom_packet_set_data(Tox_Event_Group_Custom_Packet *_Nonnull group_custom_packet,
const uint8_t *_Nullable data, uint32_t data_length)
{
assert(group_custom_packet != nullptr);
if (group_custom_packet->data != nullptr) {
free(group_custom_packet->data);
group_custom_packet->data = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_group_custom_packet_get_data(const Tox_Event_Group_Cust
return group_custom_packet->data;
}
non_null()
static void tox_event_group_custom_packet_construct(Tox_Event_Group_Custom_Packet *group_custom_packet)
static void tox_event_group_custom_packet_construct(Tox_Event_Group_Custom_Packet *_Nonnull group_custom_packet)
{
*group_custom_packet = (Tox_Event_Group_Custom_Packet) {
0
};
}
non_null()
static void tox_event_group_custom_packet_destruct(Tox_Event_Group_Custom_Packet *group_custom_packet, const Memory *mem)
static void tox_event_group_custom_packet_destruct(Tox_Event_Group_Custom_Packet *_Nonnull group_custom_packet, const Memory *_Nonnull mem)
{
free(group_custom_packet->data);
}
@@ -117,9 +109,7 @@ bool tox_event_group_custom_packet_pack(
&& bin_pack_bin(bp, event->data, event->data_length);
}
non_null()
static bool tox_event_group_custom_packet_unpack_into(
Tox_Event_Group_Custom_Packet *event, Bin_Unpack *bu)
static bool tox_event_group_custom_packet_unpack_into(Tox_Event_Group_Custom_Packet *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_group_custom_packet_free(Tox_Event_Group_Custom_Packet *group_cus
mem_delete(mem, group_custom_packet);
}
non_null()
static Tox_Event_Group_Custom_Packet *tox_events_add_group_custom_packet(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Custom_Packet *tox_events_add_group_custom_packet(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Custom_Packet *const group_custom_packet = tox_event_group_custom_packet_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_group_custom_packet_unpack(
return tox_event_group_custom_packet_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Custom_Packet *tox_event_group_custom_packet_alloc(void *user_data)
static Tox_Event_Group_Custom_Packet *tox_event_group_custom_packet_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Group_Custom_Private_Packet {
uint32_t data_length;
};
non_null()
static void tox_event_group_custom_private_packet_set_group_number(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet,
uint32_t group_number)
static void tox_event_group_custom_private_packet_set_group_number(Tox_Event_Group_Custom_Private_Packet *_Nonnull group_custom_private_packet, uint32_t group_number)
{
assert(group_custom_private_packet != nullptr);
group_custom_private_packet->group_number = group_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_group_custom_private_packet_get_group_number(const Tox_Event_
return group_custom_private_packet->group_number;
}
non_null()
static void tox_event_group_custom_private_packet_set_peer_id(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet,
uint32_t peer_id)
static void tox_event_group_custom_private_packet_set_peer_id(Tox_Event_Group_Custom_Private_Packet *_Nonnull group_custom_private_packet, uint32_t peer_id)
{
assert(group_custom_private_packet != nullptr);
group_custom_private_packet->peer_id = peer_id;
@@ -56,12 +52,10 @@ uint32_t tox_event_group_custom_private_packet_get_peer_id(const Tox_Event_Group
return group_custom_private_packet->peer_id;
}
non_null(1) nullable(2)
static bool tox_event_group_custom_private_packet_set_data(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet,
const uint8_t *data, uint32_t data_length)
static bool tox_event_group_custom_private_packet_set_data(Tox_Event_Group_Custom_Private_Packet *_Nonnull group_custom_private_packet,
const uint8_t *_Nullable data, uint32_t data_length)
{
assert(group_custom_private_packet != nullptr);
if (group_custom_private_packet->data != nullptr) {
free(group_custom_private_packet->data);
group_custom_private_packet->data = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_group_custom_private_packet_get_data(const Tox_Event_Gr
return group_custom_private_packet->data;
}
non_null()
static void tox_event_group_custom_private_packet_construct(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet)
static void tox_event_group_custom_private_packet_construct(Tox_Event_Group_Custom_Private_Packet *_Nonnull group_custom_private_packet)
{
*group_custom_private_packet = (Tox_Event_Group_Custom_Private_Packet) {
0
};
}
non_null()
static void tox_event_group_custom_private_packet_destruct(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet, const Memory *mem)
static void tox_event_group_custom_private_packet_destruct(Tox_Event_Group_Custom_Private_Packet *_Nonnull group_custom_private_packet, const Memory *_Nonnull mem)
{
free(group_custom_private_packet->data);
}
@@ -117,9 +109,7 @@ bool tox_event_group_custom_private_packet_pack(
&& bin_pack_bin(bp, event->data, event->data_length);
}
non_null()
static bool tox_event_group_custom_private_packet_unpack_into(
Tox_Event_Group_Custom_Private_Packet *event, Bin_Unpack *bu)
static bool tox_event_group_custom_private_packet_unpack_into(Tox_Event_Group_Custom_Private_Packet *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_group_custom_private_packet_free(Tox_Event_Group_Custom_Private_P
mem_delete(mem, group_custom_private_packet);
}
non_null()
static Tox_Event_Group_Custom_Private_Packet *tox_events_add_group_custom_private_packet(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Custom_Private_Packet *tox_events_add_group_custom_private_packet(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Custom_Private_Packet *const group_custom_private_packet = tox_event_group_custom_private_packet_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_group_custom_private_packet_unpack(
return tox_event_group_custom_private_packet_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Custom_Private_Packet *tox_event_group_custom_private_packet_alloc(void *user_data)
static Tox_Event_Group_Custom_Private_Packet *tox_event_group_custom_private_packet_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -31,9 +31,7 @@ struct Tox_Event_Group_Invite {
uint32_t group_name_length;
};
non_null()
static void tox_event_group_invite_set_friend_number(Tox_Event_Group_Invite *group_invite,
uint32_t friend_number)
static void tox_event_group_invite_set_friend_number(Tox_Event_Group_Invite *_Nonnull group_invite, uint32_t friend_number)
{
assert(group_invite != nullptr);
group_invite->friend_number = friend_number;
@@ -44,12 +42,10 @@ uint32_t tox_event_group_invite_get_friend_number(const Tox_Event_Group_Invite *
return group_invite->friend_number;
}
non_null(1) nullable(2)
static bool tox_event_group_invite_set_invite_data(Tox_Event_Group_Invite *group_invite,
const uint8_t *invite_data, uint32_t invite_data_length)
static bool tox_event_group_invite_set_invite_data(Tox_Event_Group_Invite *_Nonnull group_invite,
const uint8_t *_Nullable invite_data, uint32_t invite_data_length)
{
assert(group_invite != nullptr);
if (group_invite->invite_data != nullptr) {
free(group_invite->invite_data);
group_invite->invite_data = nullptr;
@@ -83,12 +79,10 @@ const uint8_t *tox_event_group_invite_get_invite_data(const Tox_Event_Group_Invi
return group_invite->invite_data;
}
non_null(1) nullable(2)
static bool tox_event_group_invite_set_group_name(Tox_Event_Group_Invite *group_invite,
const uint8_t *group_name, uint32_t group_name_length)
static bool tox_event_group_invite_set_group_name(Tox_Event_Group_Invite *_Nonnull group_invite,
const uint8_t *_Nullable group_name, uint32_t group_name_length)
{
assert(group_invite != nullptr);
if (group_invite->group_name != nullptr) {
free(group_invite->group_name);
group_invite->group_name = nullptr;
@@ -122,15 +116,13 @@ const uint8_t *tox_event_group_invite_get_group_name(const Tox_Event_Group_Invit
return group_invite->group_name;
}
non_null()
static void tox_event_group_invite_construct(Tox_Event_Group_Invite *group_invite)
static void tox_event_group_invite_construct(Tox_Event_Group_Invite *_Nonnull group_invite)
{
*group_invite = (Tox_Event_Group_Invite) {
0
};
}
non_null()
static void tox_event_group_invite_destruct(Tox_Event_Group_Invite *group_invite, const Memory *mem)
static void tox_event_group_invite_destruct(Tox_Event_Group_Invite *_Nonnull group_invite, const Memory *_Nonnull mem)
{
free(group_invite->invite_data);
free(group_invite->group_name);
@@ -145,9 +137,7 @@ bool tox_event_group_invite_pack(
&& bin_pack_bin(bp, event->group_name, event->group_name_length);
}
non_null()
static bool tox_event_group_invite_unpack_into(
Tox_Event_Group_Invite *event, Bin_Unpack *bu)
static bool tox_event_group_invite_unpack_into(Tox_Event_Group_Invite *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -191,8 +181,7 @@ void tox_event_group_invite_free(Tox_Event_Group_Invite *group_invite, const Mem
mem_delete(mem, group_invite);
}
non_null()
static Tox_Event_Group_Invite *tox_events_add_group_invite(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Invite *tox_events_add_group_invite(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Invite *const group_invite = tox_event_group_invite_new(mem);
@@ -225,8 +214,7 @@ bool tox_event_group_invite_unpack(
return tox_event_group_invite_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Invite *tox_event_group_invite_alloc(void *user_data)
static Tox_Event_Group_Invite *tox_event_group_invite_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Group_Join_Fail {
Tox_Group_Join_Fail fail_type;
};
non_null()
static void tox_event_group_join_fail_set_group_number(Tox_Event_Group_Join_Fail *group_join_fail,
uint32_t group_number)
static void tox_event_group_join_fail_set_group_number(Tox_Event_Group_Join_Fail *_Nonnull group_join_fail, uint32_t group_number)
{
assert(group_join_fail != nullptr);
group_join_fail->group_number = group_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_group_join_fail_get_group_number(const Tox_Event_Group_Join_F
return group_join_fail->group_number;
}
non_null()
static void tox_event_group_join_fail_set_fail_type(Tox_Event_Group_Join_Fail *group_join_fail,
Tox_Group_Join_Fail fail_type)
static void tox_event_group_join_fail_set_fail_type(Tox_Event_Group_Join_Fail *_Nonnull group_join_fail, Tox_Group_Join_Fail fail_type)
{
assert(group_join_fail != nullptr);
group_join_fail->fail_type = fail_type;
@@ -54,15 +50,13 @@ Tox_Group_Join_Fail tox_event_group_join_fail_get_fail_type(const Tox_Event_Grou
return group_join_fail->fail_type;
}
non_null()
static void tox_event_group_join_fail_construct(Tox_Event_Group_Join_Fail *group_join_fail)
static void tox_event_group_join_fail_construct(Tox_Event_Group_Join_Fail *_Nonnull group_join_fail)
{
*group_join_fail = (Tox_Event_Group_Join_Fail) {
0
};
}
non_null()
static void tox_event_group_join_fail_destruct(Tox_Event_Group_Join_Fail *group_join_fail, const Memory *mem)
static void tox_event_group_join_fail_destruct(Tox_Event_Group_Join_Fail *_Nonnull group_join_fail, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_group_join_fail_pack(
&& tox_group_join_fail_pack(event->fail_type, bp);
}
non_null()
static bool tox_event_group_join_fail_unpack_into(
Tox_Event_Group_Join_Fail *event, Bin_Unpack *bu)
static bool tox_event_group_join_fail_unpack_into(Tox_Event_Group_Join_Fail *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_group_join_fail_free(Tox_Event_Group_Join_Fail *group_join_fail,
mem_delete(mem, group_join_fail);
}
non_null()
static Tox_Event_Group_Join_Fail *tox_events_add_group_join_fail(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Join_Fail *tox_events_add_group_join_fail(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Join_Fail *const group_join_fail = tox_event_group_join_fail_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_group_join_fail_unpack(
return tox_event_group_join_fail_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Join_Fail *tox_event_group_join_fail_alloc(void *user_data)
static Tox_Event_Group_Join_Fail *tox_event_group_join_fail_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -34,9 +34,7 @@ struct Tox_Event_Group_Message {
uint32_t message_id;
};
non_null()
static void tox_event_group_message_set_group_number(Tox_Event_Group_Message *group_message,
uint32_t group_number)
static void tox_event_group_message_set_group_number(Tox_Event_Group_Message *_Nonnull group_message, uint32_t group_number)
{
assert(group_message != nullptr);
group_message->group_number = group_number;
@@ -47,9 +45,7 @@ uint32_t tox_event_group_message_get_group_number(const Tox_Event_Group_Message
return group_message->group_number;
}
non_null()
static void tox_event_group_message_set_peer_id(Tox_Event_Group_Message *group_message,
uint32_t peer_id)
static void tox_event_group_message_set_peer_id(Tox_Event_Group_Message *_Nonnull group_message, uint32_t peer_id)
{
assert(group_message != nullptr);
group_message->peer_id = peer_id;
@@ -60,9 +56,7 @@ uint32_t tox_event_group_message_get_peer_id(const Tox_Event_Group_Message *grou
return group_message->peer_id;
}
non_null()
static void tox_event_group_message_set_message_type(Tox_Event_Group_Message *group_message,
Tox_Message_Type message_type)
static void tox_event_group_message_set_message_type(Tox_Event_Group_Message *_Nonnull group_message, Tox_Message_Type message_type)
{
assert(group_message != nullptr);
group_message->message_type = message_type;
@@ -73,12 +67,10 @@ Tox_Message_Type tox_event_group_message_get_message_type(const Tox_Event_Group_
return group_message->message_type;
}
non_null(1) nullable(2)
static bool tox_event_group_message_set_message(Tox_Event_Group_Message *group_message,
const uint8_t *message, uint32_t message_length)
static bool tox_event_group_message_set_message(Tox_Event_Group_Message *_Nonnull group_message,
const uint8_t *_Nullable message, uint32_t message_length)
{
assert(group_message != nullptr);
if (group_message->message != nullptr) {
free(group_message->message);
group_message->message = nullptr;
@@ -112,9 +104,7 @@ const uint8_t *tox_event_group_message_get_message(const Tox_Event_Group_Message
return group_message->message;
}
non_null()
static void tox_event_group_message_set_message_id(Tox_Event_Group_Message *group_message,
uint32_t message_id)
static void tox_event_group_message_set_message_id(Tox_Event_Group_Message *_Nonnull group_message, uint32_t message_id)
{
assert(group_message != nullptr);
group_message->message_id = message_id;
@@ -125,15 +115,13 @@ uint32_t tox_event_group_message_get_message_id(const Tox_Event_Group_Message *g
return group_message->message_id;
}
non_null()
static void tox_event_group_message_construct(Tox_Event_Group_Message *group_message)
static void tox_event_group_message_construct(Tox_Event_Group_Message *_Nonnull group_message)
{
*group_message = (Tox_Event_Group_Message) {
0
};
}
non_null()
static void tox_event_group_message_destruct(Tox_Event_Group_Message *group_message, const Memory *mem)
static void tox_event_group_message_destruct(Tox_Event_Group_Message *_Nonnull group_message, const Memory *_Nonnull mem)
{
free(group_message->message);
}
@@ -149,9 +137,7 @@ bool tox_event_group_message_pack(
&& bin_pack_u32(bp, event->message_id);
}
non_null()
static bool tox_event_group_message_unpack_into(
Tox_Event_Group_Message *event, Bin_Unpack *bu)
static bool tox_event_group_message_unpack_into(Tox_Event_Group_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
@@ -197,8 +183,7 @@ void tox_event_group_message_free(Tox_Event_Group_Message *group_message, const
mem_delete(mem, group_message);
}
non_null()
static Tox_Event_Group_Message *tox_events_add_group_message(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Message *tox_events_add_group_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Message *const group_message = tox_event_group_message_new(mem);
@@ -231,8 +216,7 @@ bool tox_event_group_message_unpack(
return tox_event_group_message_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Message *tox_event_group_message_alloc(void *user_data)
static Tox_Event_Group_Message *tox_event_group_message_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Group_Moderation {
Tox_Group_Mod_Event mod_type;
};
non_null()
static void tox_event_group_moderation_set_group_number(Tox_Event_Group_Moderation *group_moderation,
uint32_t group_number)
static void tox_event_group_moderation_set_group_number(Tox_Event_Group_Moderation *_Nonnull group_moderation, uint32_t group_number)
{
assert(group_moderation != nullptr);
group_moderation->group_number = group_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_group_moderation_get_group_number(const Tox_Event_Group_Moder
return group_moderation->group_number;
}
non_null()
static void tox_event_group_moderation_set_source_peer_id(Tox_Event_Group_Moderation *group_moderation,
uint32_t source_peer_id)
static void tox_event_group_moderation_set_source_peer_id(Tox_Event_Group_Moderation *_Nonnull group_moderation, uint32_t source_peer_id)
{
assert(group_moderation != nullptr);
group_moderation->source_peer_id = source_peer_id;
@@ -56,9 +52,7 @@ uint32_t tox_event_group_moderation_get_source_peer_id(const Tox_Event_Group_Mod
return group_moderation->source_peer_id;
}
non_null()
static void tox_event_group_moderation_set_target_peer_id(Tox_Event_Group_Moderation *group_moderation,
uint32_t target_peer_id)
static void tox_event_group_moderation_set_target_peer_id(Tox_Event_Group_Moderation *_Nonnull group_moderation, uint32_t target_peer_id)
{
assert(group_moderation != nullptr);
group_moderation->target_peer_id = target_peer_id;
@@ -69,9 +63,7 @@ uint32_t tox_event_group_moderation_get_target_peer_id(const Tox_Event_Group_Mod
return group_moderation->target_peer_id;
}
non_null()
static void tox_event_group_moderation_set_mod_type(Tox_Event_Group_Moderation *group_moderation,
Tox_Group_Mod_Event mod_type)
static void tox_event_group_moderation_set_mod_type(Tox_Event_Group_Moderation *_Nonnull group_moderation, Tox_Group_Mod_Event mod_type)
{
assert(group_moderation != nullptr);
group_moderation->mod_type = mod_type;
@@ -82,15 +74,13 @@ Tox_Group_Mod_Event tox_event_group_moderation_get_mod_type(const Tox_Event_Grou
return group_moderation->mod_type;
}
non_null()
static void tox_event_group_moderation_construct(Tox_Event_Group_Moderation *group_moderation)
static void tox_event_group_moderation_construct(Tox_Event_Group_Moderation *_Nonnull group_moderation)
{
*group_moderation = (Tox_Event_Group_Moderation) {
0
};
}
non_null()
static void tox_event_group_moderation_destruct(Tox_Event_Group_Moderation *group_moderation, const Memory *mem)
static void tox_event_group_moderation_destruct(Tox_Event_Group_Moderation *_Nonnull group_moderation, const Memory *_Nonnull mem)
{
return;
}
@@ -105,9 +95,7 @@ bool tox_event_group_moderation_pack(
&& tox_group_mod_event_pack(event->mod_type, bp);
}
non_null()
static bool tox_event_group_moderation_unpack_into(
Tox_Event_Group_Moderation *event, Bin_Unpack *bu)
static bool tox_event_group_moderation_unpack_into(Tox_Event_Group_Moderation *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
@@ -152,8 +140,7 @@ void tox_event_group_moderation_free(Tox_Event_Group_Moderation *group_moderatio
mem_delete(mem, group_moderation);
}
non_null()
static Tox_Event_Group_Moderation *tox_events_add_group_moderation(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Moderation *tox_events_add_group_moderation(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Moderation *const group_moderation = tox_event_group_moderation_new(mem);
@@ -186,8 +173,7 @@ bool tox_event_group_moderation_unpack(
return tox_event_group_moderation_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Moderation *tox_event_group_moderation_alloc(void *user_data)
static Tox_Event_Group_Moderation *tox_event_group_moderation_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Group_Password {
uint32_t password_length;
};
non_null()
static void tox_event_group_password_set_group_number(Tox_Event_Group_Password *group_password,
uint32_t group_number)
static void tox_event_group_password_set_group_number(Tox_Event_Group_Password *_Nonnull group_password, uint32_t group_number)
{
assert(group_password != nullptr);
group_password->group_number = group_number;
@@ -42,12 +40,10 @@ uint32_t tox_event_group_password_get_group_number(const Tox_Event_Group_Passwor
return group_password->group_number;
}
non_null(1) nullable(2)
static bool tox_event_group_password_set_password(Tox_Event_Group_Password *group_password,
const uint8_t *password, uint32_t password_length)
static bool tox_event_group_password_set_password(Tox_Event_Group_Password *_Nonnull group_password,
const uint8_t *_Nullable password, uint32_t password_length)
{
assert(group_password != nullptr);
if (group_password->password != nullptr) {
free(group_password->password);
group_password->password = nullptr;
@@ -81,15 +77,13 @@ const uint8_t *tox_event_group_password_get_password(const Tox_Event_Group_Passw
return group_password->password;
}
non_null()
static void tox_event_group_password_construct(Tox_Event_Group_Password *group_password)
static void tox_event_group_password_construct(Tox_Event_Group_Password *_Nonnull group_password)
{
*group_password = (Tox_Event_Group_Password) {
0
};
}
non_null()
static void tox_event_group_password_destruct(Tox_Event_Group_Password *group_password, const Memory *mem)
static void tox_event_group_password_destruct(Tox_Event_Group_Password *_Nonnull group_password, const Memory *_Nonnull mem)
{
free(group_password->password);
}
@@ -102,9 +96,7 @@ bool tox_event_group_password_pack(
&& bin_pack_bin(bp, event->password, event->password_length);
}
non_null()
static bool tox_event_group_password_unpack_into(
Tox_Event_Group_Password *event, Bin_Unpack *bu)
static bool tox_event_group_password_unpack_into(Tox_Event_Group_Password *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -147,8 +139,7 @@ void tox_event_group_password_free(Tox_Event_Group_Password *group_password, con
mem_delete(mem, group_password);
}
non_null()
static Tox_Event_Group_Password *tox_events_add_group_password(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Password *tox_events_add_group_password(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Password *const group_password = tox_event_group_password_new(mem);
@@ -181,8 +172,7 @@ bool tox_event_group_password_unpack(
return tox_event_group_password_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Password *tox_event_group_password_alloc(void *user_data)
static Tox_Event_Group_Password *tox_event_group_password_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -35,9 +35,7 @@ struct Tox_Event_Group_Peer_Exit {
uint32_t part_message_length;
};
non_null()
static void tox_event_group_peer_exit_set_group_number(Tox_Event_Group_Peer_Exit *group_peer_exit,
uint32_t group_number)
static void tox_event_group_peer_exit_set_group_number(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit, uint32_t group_number)
{
assert(group_peer_exit != nullptr);
group_peer_exit->group_number = group_number;
@@ -48,9 +46,7 @@ uint32_t tox_event_group_peer_exit_get_group_number(const Tox_Event_Group_Peer_E
return group_peer_exit->group_number;
}
non_null()
static void tox_event_group_peer_exit_set_peer_id(Tox_Event_Group_Peer_Exit *group_peer_exit,
uint32_t peer_id)
static void tox_event_group_peer_exit_set_peer_id(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit, uint32_t peer_id)
{
assert(group_peer_exit != nullptr);
group_peer_exit->peer_id = peer_id;
@@ -61,9 +57,7 @@ uint32_t tox_event_group_peer_exit_get_peer_id(const Tox_Event_Group_Peer_Exit *
return group_peer_exit->peer_id;
}
non_null()
static void tox_event_group_peer_exit_set_exit_type(Tox_Event_Group_Peer_Exit *group_peer_exit,
Tox_Group_Exit_Type exit_type)
static void tox_event_group_peer_exit_set_exit_type(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit, Tox_Group_Exit_Type exit_type)
{
assert(group_peer_exit != nullptr);
group_peer_exit->exit_type = exit_type;
@@ -74,12 +68,10 @@ Tox_Group_Exit_Type tox_event_group_peer_exit_get_exit_type(const Tox_Event_Grou
return group_peer_exit->exit_type;
}
non_null(1) nullable(2)
static bool tox_event_group_peer_exit_set_name(Tox_Event_Group_Peer_Exit *group_peer_exit,
const uint8_t *name, uint32_t name_length)
static bool tox_event_group_peer_exit_set_name(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit,
const uint8_t *_Nullable name, uint32_t name_length)
{
assert(group_peer_exit != nullptr);
if (group_peer_exit->name != nullptr) {
free(group_peer_exit->name);
group_peer_exit->name = nullptr;
@@ -113,12 +105,10 @@ const uint8_t *tox_event_group_peer_exit_get_name(const Tox_Event_Group_Peer_Exi
return group_peer_exit->name;
}
non_null(1) nullable(2)
static bool tox_event_group_peer_exit_set_part_message(Tox_Event_Group_Peer_Exit *group_peer_exit,
const uint8_t *part_message, uint32_t part_message_length)
static bool tox_event_group_peer_exit_set_part_message(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit,
const uint8_t *_Nullable part_message, uint32_t part_message_length)
{
assert(group_peer_exit != nullptr);
if (group_peer_exit->part_message != nullptr) {
free(group_peer_exit->part_message);
group_peer_exit->part_message = nullptr;
@@ -152,15 +142,13 @@ const uint8_t *tox_event_group_peer_exit_get_part_message(const Tox_Event_Group_
return group_peer_exit->part_message;
}
non_null()
static void tox_event_group_peer_exit_construct(Tox_Event_Group_Peer_Exit *group_peer_exit)
static void tox_event_group_peer_exit_construct(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit)
{
*group_peer_exit = (Tox_Event_Group_Peer_Exit) {
0
};
}
non_null()
static void tox_event_group_peer_exit_destruct(Tox_Event_Group_Peer_Exit *group_peer_exit, const Memory *mem)
static void tox_event_group_peer_exit_destruct(Tox_Event_Group_Peer_Exit *_Nonnull group_peer_exit, const Memory *_Nonnull mem)
{
free(group_peer_exit->name);
free(group_peer_exit->part_message);
@@ -177,9 +165,7 @@ bool tox_event_group_peer_exit_pack(
&& bin_pack_bin(bp, event->part_message, event->part_message_length);
}
non_null()
static bool tox_event_group_peer_exit_unpack_into(
Tox_Event_Group_Peer_Exit *event, Bin_Unpack *bu)
static bool tox_event_group_peer_exit_unpack_into(Tox_Event_Group_Peer_Exit *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
@@ -225,8 +211,7 @@ void tox_event_group_peer_exit_free(Tox_Event_Group_Peer_Exit *group_peer_exit,
mem_delete(mem, group_peer_exit);
}
non_null()
static Tox_Event_Group_Peer_Exit *tox_events_add_group_peer_exit(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Peer_Exit *tox_events_add_group_peer_exit(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Peer_Exit *const group_peer_exit = tox_event_group_peer_exit_new(mem);
@@ -259,8 +244,7 @@ bool tox_event_group_peer_exit_unpack(
return tox_event_group_peer_exit_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Peer_Exit *tox_event_group_peer_exit_alloc(void *user_data)
static Tox_Event_Group_Peer_Exit *tox_event_group_peer_exit_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -26,9 +26,7 @@ struct Tox_Event_Group_Peer_Join {
uint32_t peer_id;
};
non_null()
static void tox_event_group_peer_join_set_group_number(Tox_Event_Group_Peer_Join *group_peer_join,
uint32_t group_number)
static void tox_event_group_peer_join_set_group_number(Tox_Event_Group_Peer_Join *_Nonnull group_peer_join, uint32_t group_number)
{
assert(group_peer_join != nullptr);
group_peer_join->group_number = group_number;
@@ -39,9 +37,7 @@ uint32_t tox_event_group_peer_join_get_group_number(const Tox_Event_Group_Peer_J
return group_peer_join->group_number;
}
non_null()
static void tox_event_group_peer_join_set_peer_id(Tox_Event_Group_Peer_Join *group_peer_join,
uint32_t peer_id)
static void tox_event_group_peer_join_set_peer_id(Tox_Event_Group_Peer_Join *_Nonnull group_peer_join, uint32_t peer_id)
{
assert(group_peer_join != nullptr);
group_peer_join->peer_id = peer_id;
@@ -52,15 +48,13 @@ uint32_t tox_event_group_peer_join_get_peer_id(const Tox_Event_Group_Peer_Join *
return group_peer_join->peer_id;
}
non_null()
static void tox_event_group_peer_join_construct(Tox_Event_Group_Peer_Join *group_peer_join)
static void tox_event_group_peer_join_construct(Tox_Event_Group_Peer_Join *_Nonnull group_peer_join)
{
*group_peer_join = (Tox_Event_Group_Peer_Join) {
0
};
}
non_null()
static void tox_event_group_peer_join_destruct(Tox_Event_Group_Peer_Join *group_peer_join, const Memory *mem)
static void tox_event_group_peer_join_destruct(Tox_Event_Group_Peer_Join *_Nonnull group_peer_join, const Memory *_Nonnull mem)
{
return;
}
@@ -73,9 +67,7 @@ bool tox_event_group_peer_join_pack(
&& bin_pack_u32(bp, event->peer_id);
}
non_null()
static bool tox_event_group_peer_join_unpack_into(
Tox_Event_Group_Peer_Join *event, Bin_Unpack *bu)
static bool tox_event_group_peer_join_unpack_into(Tox_Event_Group_Peer_Join *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -118,8 +110,7 @@ void tox_event_group_peer_join_free(Tox_Event_Group_Peer_Join *group_peer_join,
mem_delete(mem, group_peer_join);
}
non_null()
static Tox_Event_Group_Peer_Join *tox_events_add_group_peer_join(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Peer_Join *tox_events_add_group_peer_join(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Peer_Join *const group_peer_join = tox_event_group_peer_join_new(mem);
@@ -152,8 +143,7 @@ bool tox_event_group_peer_join_unpack(
return tox_event_group_peer_join_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Peer_Join *tox_event_group_peer_join_alloc(void *user_data)
static Tox_Event_Group_Peer_Join *tox_event_group_peer_join_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -26,9 +26,7 @@ struct Tox_Event_Group_Peer_Limit {
uint32_t peer_limit;
};
non_null()
static void tox_event_group_peer_limit_set_group_number(Tox_Event_Group_Peer_Limit *group_peer_limit,
uint32_t group_number)
static void tox_event_group_peer_limit_set_group_number(Tox_Event_Group_Peer_Limit *_Nonnull group_peer_limit, uint32_t group_number)
{
assert(group_peer_limit != nullptr);
group_peer_limit->group_number = group_number;
@@ -39,9 +37,7 @@ uint32_t tox_event_group_peer_limit_get_group_number(const Tox_Event_Group_Peer_
return group_peer_limit->group_number;
}
non_null()
static void tox_event_group_peer_limit_set_peer_limit(Tox_Event_Group_Peer_Limit *group_peer_limit,
uint32_t peer_limit)
static void tox_event_group_peer_limit_set_peer_limit(Tox_Event_Group_Peer_Limit *_Nonnull group_peer_limit, uint32_t peer_limit)
{
assert(group_peer_limit != nullptr);
group_peer_limit->peer_limit = peer_limit;
@@ -52,15 +48,13 @@ uint32_t tox_event_group_peer_limit_get_peer_limit(const Tox_Event_Group_Peer_Li
return group_peer_limit->peer_limit;
}
non_null()
static void tox_event_group_peer_limit_construct(Tox_Event_Group_Peer_Limit *group_peer_limit)
static void tox_event_group_peer_limit_construct(Tox_Event_Group_Peer_Limit *_Nonnull group_peer_limit)
{
*group_peer_limit = (Tox_Event_Group_Peer_Limit) {
0
};
}
non_null()
static void tox_event_group_peer_limit_destruct(Tox_Event_Group_Peer_Limit *group_peer_limit, const Memory *mem)
static void tox_event_group_peer_limit_destruct(Tox_Event_Group_Peer_Limit *_Nonnull group_peer_limit, const Memory *_Nonnull mem)
{
return;
}
@@ -73,9 +67,7 @@ bool tox_event_group_peer_limit_pack(
&& bin_pack_u32(bp, event->peer_limit);
}
non_null()
static bool tox_event_group_peer_limit_unpack_into(
Tox_Event_Group_Peer_Limit *event, Bin_Unpack *bu)
static bool tox_event_group_peer_limit_unpack_into(Tox_Event_Group_Peer_Limit *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -118,8 +110,7 @@ void tox_event_group_peer_limit_free(Tox_Event_Group_Peer_Limit *group_peer_limi
mem_delete(mem, group_peer_limit);
}
non_null()
static Tox_Event_Group_Peer_Limit *tox_events_add_group_peer_limit(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Peer_Limit *tox_events_add_group_peer_limit(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Peer_Limit *const group_peer_limit = tox_event_group_peer_limit_new(mem);
@@ -152,8 +143,7 @@ bool tox_event_group_peer_limit_unpack(
return tox_event_group_peer_limit_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Peer_Limit *tox_event_group_peer_limit_alloc(void *user_data)
static Tox_Event_Group_Peer_Limit *tox_event_group_peer_limit_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Group_Peer_Name {
uint32_t name_length;
};
non_null()
static void tox_event_group_peer_name_set_group_number(Tox_Event_Group_Peer_Name *group_peer_name,
uint32_t group_number)
static void tox_event_group_peer_name_set_group_number(Tox_Event_Group_Peer_Name *_Nonnull group_peer_name, uint32_t group_number)
{
assert(group_peer_name != nullptr);
group_peer_name->group_number = group_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_group_peer_name_get_group_number(const Tox_Event_Group_Peer_N
return group_peer_name->group_number;
}
non_null()
static void tox_event_group_peer_name_set_peer_id(Tox_Event_Group_Peer_Name *group_peer_name,
uint32_t peer_id)
static void tox_event_group_peer_name_set_peer_id(Tox_Event_Group_Peer_Name *_Nonnull group_peer_name, uint32_t peer_id)
{
assert(group_peer_name != nullptr);
group_peer_name->peer_id = peer_id;
@@ -56,12 +52,10 @@ uint32_t tox_event_group_peer_name_get_peer_id(const Tox_Event_Group_Peer_Name *
return group_peer_name->peer_id;
}
non_null(1) nullable(2)
static bool tox_event_group_peer_name_set_name(Tox_Event_Group_Peer_Name *group_peer_name,
const uint8_t *name, uint32_t name_length)
static bool tox_event_group_peer_name_set_name(Tox_Event_Group_Peer_Name *_Nonnull group_peer_name,
const uint8_t *_Nullable name, uint32_t name_length)
{
assert(group_peer_name != nullptr);
if (group_peer_name->name != nullptr) {
free(group_peer_name->name);
group_peer_name->name = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_group_peer_name_get_name(const Tox_Event_Group_Peer_Nam
return group_peer_name->name;
}
non_null()
static void tox_event_group_peer_name_construct(Tox_Event_Group_Peer_Name *group_peer_name)
static void tox_event_group_peer_name_construct(Tox_Event_Group_Peer_Name *_Nonnull group_peer_name)
{
*group_peer_name = (Tox_Event_Group_Peer_Name) {
0
};
}
non_null()
static void tox_event_group_peer_name_destruct(Tox_Event_Group_Peer_Name *group_peer_name, const Memory *mem)
static void tox_event_group_peer_name_destruct(Tox_Event_Group_Peer_Name *_Nonnull group_peer_name, const Memory *_Nonnull mem)
{
free(group_peer_name->name);
}
@@ -117,9 +109,7 @@ bool tox_event_group_peer_name_pack(
&& bin_pack_bin(bp, event->name, event->name_length);
}
non_null()
static bool tox_event_group_peer_name_unpack_into(
Tox_Event_Group_Peer_Name *event, Bin_Unpack *bu)
static bool tox_event_group_peer_name_unpack_into(Tox_Event_Group_Peer_Name *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_group_peer_name_free(Tox_Event_Group_Peer_Name *group_peer_name,
mem_delete(mem, group_peer_name);
}
non_null()
static Tox_Event_Group_Peer_Name *tox_events_add_group_peer_name(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Peer_Name *tox_events_add_group_peer_name(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Peer_Name *const group_peer_name = tox_event_group_peer_name_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_group_peer_name_unpack(
return tox_event_group_peer_name_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Peer_Name *tox_event_group_peer_name_alloc(void *user_data)
static Tox_Event_Group_Peer_Name *tox_event_group_peer_name_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -29,9 +29,7 @@ struct Tox_Event_Group_Peer_Status {
Tox_User_Status status;
};
non_null()
static void tox_event_group_peer_status_set_group_number(Tox_Event_Group_Peer_Status *group_peer_status,
uint32_t group_number)
static void tox_event_group_peer_status_set_group_number(Tox_Event_Group_Peer_Status *_Nonnull group_peer_status, uint32_t group_number)
{
assert(group_peer_status != nullptr);
group_peer_status->group_number = group_number;
@@ -42,9 +40,7 @@ uint32_t tox_event_group_peer_status_get_group_number(const Tox_Event_Group_Peer
return group_peer_status->group_number;
}
non_null()
static void tox_event_group_peer_status_set_peer_id(Tox_Event_Group_Peer_Status *group_peer_status,
uint32_t peer_id)
static void tox_event_group_peer_status_set_peer_id(Tox_Event_Group_Peer_Status *_Nonnull group_peer_status, uint32_t peer_id)
{
assert(group_peer_status != nullptr);
group_peer_status->peer_id = peer_id;
@@ -55,9 +51,7 @@ uint32_t tox_event_group_peer_status_get_peer_id(const Tox_Event_Group_Peer_Stat
return group_peer_status->peer_id;
}
non_null()
static void tox_event_group_peer_status_set_status(Tox_Event_Group_Peer_Status *group_peer_status,
Tox_User_Status status)
static void tox_event_group_peer_status_set_status(Tox_Event_Group_Peer_Status *_Nonnull group_peer_status, Tox_User_Status status)
{
assert(group_peer_status != nullptr);
group_peer_status->status = status;
@@ -68,15 +62,13 @@ Tox_User_Status tox_event_group_peer_status_get_status(const Tox_Event_Group_Pee
return group_peer_status->status;
}
non_null()
static void tox_event_group_peer_status_construct(Tox_Event_Group_Peer_Status *group_peer_status)
static void tox_event_group_peer_status_construct(Tox_Event_Group_Peer_Status *_Nonnull group_peer_status)
{
*group_peer_status = (Tox_Event_Group_Peer_Status) {
0
};
}
non_null()
static void tox_event_group_peer_status_destruct(Tox_Event_Group_Peer_Status *group_peer_status, const Memory *mem)
static void tox_event_group_peer_status_destruct(Tox_Event_Group_Peer_Status *_Nonnull group_peer_status, const Memory *_Nonnull mem)
{
return;
}
@@ -90,9 +82,7 @@ bool tox_event_group_peer_status_pack(
&& tox_user_status_pack(event->status, bp);
}
non_null()
static bool tox_event_group_peer_status_unpack_into(
Tox_Event_Group_Peer_Status *event, Bin_Unpack *bu)
static bool tox_event_group_peer_status_unpack_into(Tox_Event_Group_Peer_Status *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -136,8 +126,7 @@ void tox_event_group_peer_status_free(Tox_Event_Group_Peer_Status *group_peer_st
mem_delete(mem, group_peer_status);
}
non_null()
static Tox_Event_Group_Peer_Status *tox_events_add_group_peer_status(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Peer_Status *tox_events_add_group_peer_status(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Peer_Status *const group_peer_status = tox_event_group_peer_status_new(mem);
@@ -170,8 +159,7 @@ bool tox_event_group_peer_status_unpack(
return tox_event_group_peer_status_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Peer_Status *tox_event_group_peer_status_alloc(void *user_data)
static Tox_Event_Group_Peer_Status *tox_event_group_peer_status_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Group_Privacy_State {
Tox_Group_Privacy_State privacy_state;
};
non_null()
static void tox_event_group_privacy_state_set_group_number(Tox_Event_Group_Privacy_State *group_privacy_state,
uint32_t group_number)
static void tox_event_group_privacy_state_set_group_number(Tox_Event_Group_Privacy_State *_Nonnull group_privacy_state, uint32_t group_number)
{
assert(group_privacy_state != nullptr);
group_privacy_state->group_number = group_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_group_privacy_state_get_group_number(const Tox_Event_Group_Pr
return group_privacy_state->group_number;
}
non_null()
static void tox_event_group_privacy_state_set_privacy_state(Tox_Event_Group_Privacy_State *group_privacy_state,
Tox_Group_Privacy_State privacy_state)
static void tox_event_group_privacy_state_set_privacy_state(Tox_Event_Group_Privacy_State *_Nonnull group_privacy_state, Tox_Group_Privacy_State privacy_state)
{
assert(group_privacy_state != nullptr);
group_privacy_state->privacy_state = privacy_state;
@@ -54,15 +50,13 @@ Tox_Group_Privacy_State tox_event_group_privacy_state_get_privacy_state(const To
return group_privacy_state->privacy_state;
}
non_null()
static void tox_event_group_privacy_state_construct(Tox_Event_Group_Privacy_State *group_privacy_state)
static void tox_event_group_privacy_state_construct(Tox_Event_Group_Privacy_State *_Nonnull group_privacy_state)
{
*group_privacy_state = (Tox_Event_Group_Privacy_State) {
0
};
}
non_null()
static void tox_event_group_privacy_state_destruct(Tox_Event_Group_Privacy_State *group_privacy_state, const Memory *mem)
static void tox_event_group_privacy_state_destruct(Tox_Event_Group_Privacy_State *_Nonnull group_privacy_state, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_group_privacy_state_pack(
&& tox_group_privacy_state_pack(event->privacy_state, bp);
}
non_null()
static bool tox_event_group_privacy_state_unpack_into(
Tox_Event_Group_Privacy_State *event, Bin_Unpack *bu)
static bool tox_event_group_privacy_state_unpack_into(Tox_Event_Group_Privacy_State *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_group_privacy_state_free(Tox_Event_Group_Privacy_State *group_pri
mem_delete(mem, group_privacy_state);
}
non_null()
static Tox_Event_Group_Privacy_State *tox_events_add_group_privacy_state(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Privacy_State *tox_events_add_group_privacy_state(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Privacy_State *const group_privacy_state = tox_event_group_privacy_state_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_group_privacy_state_unpack(
return tox_event_group_privacy_state_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Privacy_State *tox_event_group_privacy_state_alloc(void *user_data)
static Tox_Event_Group_Privacy_State *tox_event_group_privacy_state_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -34,9 +34,7 @@ struct Tox_Event_Group_Private_Message {
uint32_t message_id;
};
non_null()
static void tox_event_group_private_message_set_group_number(Tox_Event_Group_Private_Message *group_private_message,
uint32_t group_number)
static void tox_event_group_private_message_set_group_number(Tox_Event_Group_Private_Message *_Nonnull group_private_message, uint32_t group_number)
{
assert(group_private_message != nullptr);
group_private_message->group_number = group_number;
@@ -47,9 +45,7 @@ uint32_t tox_event_group_private_message_get_group_number(const Tox_Event_Group_
return group_private_message->group_number;
}
non_null()
static void tox_event_group_private_message_set_peer_id(Tox_Event_Group_Private_Message *group_private_message,
uint32_t peer_id)
static void tox_event_group_private_message_set_peer_id(Tox_Event_Group_Private_Message *_Nonnull group_private_message, uint32_t peer_id)
{
assert(group_private_message != nullptr);
group_private_message->peer_id = peer_id;
@@ -60,9 +56,7 @@ uint32_t tox_event_group_private_message_get_peer_id(const Tox_Event_Group_Priva
return group_private_message->peer_id;
}
non_null()
static void tox_event_group_private_message_set_message_type(Tox_Event_Group_Private_Message *group_private_message,
Tox_Message_Type message_type)
static void tox_event_group_private_message_set_message_type(Tox_Event_Group_Private_Message *_Nonnull group_private_message, Tox_Message_Type message_type)
{
assert(group_private_message != nullptr);
group_private_message->message_type = message_type;
@@ -73,12 +67,10 @@ Tox_Message_Type tox_event_group_private_message_get_message_type(const Tox_Even
return group_private_message->message_type;
}
non_null(1) nullable(2)
static bool tox_event_group_private_message_set_message(Tox_Event_Group_Private_Message *group_private_message,
const uint8_t *message, uint32_t message_length)
static bool tox_event_group_private_message_set_message(Tox_Event_Group_Private_Message *_Nonnull group_private_message,
const uint8_t *_Nullable message, uint32_t message_length)
{
assert(group_private_message != nullptr);
if (group_private_message->message != nullptr) {
free(group_private_message->message);
group_private_message->message = nullptr;
@@ -112,9 +104,7 @@ const uint8_t *tox_event_group_private_message_get_message(const Tox_Event_Group
return group_private_message->message;
}
non_null()
static void tox_event_group_private_message_set_message_id(Tox_Event_Group_Private_Message *group_private_message,
uint32_t message_id)
static void tox_event_group_private_message_set_message_id(Tox_Event_Group_Private_Message *_Nonnull group_private_message, uint32_t message_id)
{
assert(group_private_message != nullptr);
group_private_message->message_id = message_id;
@@ -125,15 +115,13 @@ uint32_t tox_event_group_private_message_get_message_id(const Tox_Event_Group_Pr
return group_private_message->message_id;
}
non_null()
static void tox_event_group_private_message_construct(Tox_Event_Group_Private_Message *group_private_message)
static void tox_event_group_private_message_construct(Tox_Event_Group_Private_Message *_Nonnull group_private_message)
{
*group_private_message = (Tox_Event_Group_Private_Message) {
0
};
}
non_null()
static void tox_event_group_private_message_destruct(Tox_Event_Group_Private_Message *group_private_message, const Memory *mem)
static void tox_event_group_private_message_destruct(Tox_Event_Group_Private_Message *_Nonnull group_private_message, const Memory *_Nonnull mem)
{
free(group_private_message->message);
}
@@ -149,9 +137,7 @@ bool tox_event_group_private_message_pack(
&& bin_pack_u32(bp, event->message_id);
}
non_null()
static bool tox_event_group_private_message_unpack_into(
Tox_Event_Group_Private_Message *event, Bin_Unpack *bu)
static bool tox_event_group_private_message_unpack_into(Tox_Event_Group_Private_Message *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
@@ -197,8 +183,7 @@ void tox_event_group_private_message_free(Tox_Event_Group_Private_Message *group
mem_delete(mem, group_private_message);
}
non_null()
static Tox_Event_Group_Private_Message *tox_events_add_group_private_message(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Private_Message *tox_events_add_group_private_message(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Private_Message *const group_private_message = tox_event_group_private_message_new(mem);
@@ -231,8 +216,7 @@ bool tox_event_group_private_message_unpack(
return tox_event_group_private_message_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Private_Message *tox_event_group_private_message_alloc(void *user_data)
static Tox_Event_Group_Private_Message *tox_event_group_private_message_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -25,9 +25,7 @@ struct Tox_Event_Group_Self_Join {
uint32_t group_number;
};
non_null()
static void tox_event_group_self_join_set_group_number(Tox_Event_Group_Self_Join *group_self_join,
uint32_t group_number)
static void tox_event_group_self_join_set_group_number(Tox_Event_Group_Self_Join *_Nonnull group_self_join, uint32_t group_number)
{
assert(group_self_join != nullptr);
group_self_join->group_number = group_number;
@@ -38,15 +36,13 @@ uint32_t tox_event_group_self_join_get_group_number(const Tox_Event_Group_Self_J
return group_self_join->group_number;
}
non_null()
static void tox_event_group_self_join_construct(Tox_Event_Group_Self_Join *group_self_join)
static void tox_event_group_self_join_construct(Tox_Event_Group_Self_Join *_Nonnull group_self_join)
{
*group_self_join = (Tox_Event_Group_Self_Join) {
0
};
}
non_null()
static void tox_event_group_self_join_destruct(Tox_Event_Group_Self_Join *group_self_join, const Memory *mem)
static void tox_event_group_self_join_destruct(Tox_Event_Group_Self_Join *_Nonnull group_self_join, const Memory *_Nonnull mem)
{
return;
}
@@ -57,9 +53,7 @@ bool tox_event_group_self_join_pack(
return bin_pack_u32(bp, event->group_number);
}
non_null()
static bool tox_event_group_self_join_unpack_into(
Tox_Event_Group_Self_Join *event, Bin_Unpack *bu)
static bool tox_event_group_self_join_unpack_into(Tox_Event_Group_Self_Join *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
return bin_unpack_u32(bu, &event->group_number);
@@ -97,8 +91,7 @@ void tox_event_group_self_join_free(Tox_Event_Group_Self_Join *group_self_join,
mem_delete(mem, group_self_join);
}
non_null()
static Tox_Event_Group_Self_Join *tox_events_add_group_self_join(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Self_Join *tox_events_add_group_self_join(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Self_Join *const group_self_join = tox_event_group_self_join_new(mem);
@@ -131,8 +124,7 @@ bool tox_event_group_self_join_unpack(
return tox_event_group_self_join_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Self_Join *tox_event_group_self_join_alloc(void *user_data)
static Tox_Event_Group_Self_Join *tox_event_group_self_join_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -30,9 +30,7 @@ struct Tox_Event_Group_Topic {
uint32_t topic_length;
};
non_null()
static void tox_event_group_topic_set_group_number(Tox_Event_Group_Topic *group_topic,
uint32_t group_number)
static void tox_event_group_topic_set_group_number(Tox_Event_Group_Topic *_Nonnull group_topic, uint32_t group_number)
{
assert(group_topic != nullptr);
group_topic->group_number = group_number;
@@ -43,9 +41,7 @@ uint32_t tox_event_group_topic_get_group_number(const Tox_Event_Group_Topic *gro
return group_topic->group_number;
}
non_null()
static void tox_event_group_topic_set_peer_id(Tox_Event_Group_Topic *group_topic,
uint32_t peer_id)
static void tox_event_group_topic_set_peer_id(Tox_Event_Group_Topic *_Nonnull group_topic, uint32_t peer_id)
{
assert(group_topic != nullptr);
group_topic->peer_id = peer_id;
@@ -56,12 +52,10 @@ uint32_t tox_event_group_topic_get_peer_id(const Tox_Event_Group_Topic *group_to
return group_topic->peer_id;
}
non_null(1) nullable(2)
static bool tox_event_group_topic_set_topic(Tox_Event_Group_Topic *group_topic,
const uint8_t *topic, uint32_t topic_length)
static bool tox_event_group_topic_set_topic(Tox_Event_Group_Topic *_Nonnull group_topic,
const uint8_t *_Nullable topic, uint32_t topic_length)
{
assert(group_topic != nullptr);
if (group_topic->topic != nullptr) {
free(group_topic->topic);
group_topic->topic = nullptr;
@@ -95,15 +89,13 @@ const uint8_t *tox_event_group_topic_get_topic(const Tox_Event_Group_Topic *grou
return group_topic->topic;
}
non_null()
static void tox_event_group_topic_construct(Tox_Event_Group_Topic *group_topic)
static void tox_event_group_topic_construct(Tox_Event_Group_Topic *_Nonnull group_topic)
{
*group_topic = (Tox_Event_Group_Topic) {
0
};
}
non_null()
static void tox_event_group_topic_destruct(Tox_Event_Group_Topic *group_topic, const Memory *mem)
static void tox_event_group_topic_destruct(Tox_Event_Group_Topic *_Nonnull group_topic, const Memory *_Nonnull mem)
{
free(group_topic->topic);
}
@@ -117,9 +109,7 @@ bool tox_event_group_topic_pack(
&& bin_pack_bin(bp, event->topic, event->topic_length);
}
non_null()
static bool tox_event_group_topic_unpack_into(
Tox_Event_Group_Topic *event, Bin_Unpack *bu)
static bool tox_event_group_topic_unpack_into(Tox_Event_Group_Topic *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 3, nullptr)) {
@@ -163,8 +153,7 @@ void tox_event_group_topic_free(Tox_Event_Group_Topic *group_topic, const Memory
mem_delete(mem, group_topic);
}
non_null()
static Tox_Event_Group_Topic *tox_events_add_group_topic(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Topic *tox_events_add_group_topic(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Topic *const group_topic = tox_event_group_topic_new(mem);
@@ -197,8 +186,7 @@ bool tox_event_group_topic_unpack(
return tox_event_group_topic_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Topic *tox_event_group_topic_alloc(void *user_data)
static Tox_Event_Group_Topic *tox_event_group_topic_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Group_Topic_Lock {
Tox_Group_Topic_Lock topic_lock;
};
non_null()
static void tox_event_group_topic_lock_set_group_number(Tox_Event_Group_Topic_Lock *group_topic_lock,
uint32_t group_number)
static void tox_event_group_topic_lock_set_group_number(Tox_Event_Group_Topic_Lock *_Nonnull group_topic_lock, uint32_t group_number)
{
assert(group_topic_lock != nullptr);
group_topic_lock->group_number = group_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_group_topic_lock_get_group_number(const Tox_Event_Group_Topic
return group_topic_lock->group_number;
}
non_null()
static void tox_event_group_topic_lock_set_topic_lock(Tox_Event_Group_Topic_Lock *group_topic_lock,
Tox_Group_Topic_Lock topic_lock)
static void tox_event_group_topic_lock_set_topic_lock(Tox_Event_Group_Topic_Lock *_Nonnull group_topic_lock, Tox_Group_Topic_Lock topic_lock)
{
assert(group_topic_lock != nullptr);
group_topic_lock->topic_lock = topic_lock;
@@ -54,15 +50,13 @@ Tox_Group_Topic_Lock tox_event_group_topic_lock_get_topic_lock(const Tox_Event_G
return group_topic_lock->topic_lock;
}
non_null()
static void tox_event_group_topic_lock_construct(Tox_Event_Group_Topic_Lock *group_topic_lock)
static void tox_event_group_topic_lock_construct(Tox_Event_Group_Topic_Lock *_Nonnull group_topic_lock)
{
*group_topic_lock = (Tox_Event_Group_Topic_Lock) {
0
};
}
non_null()
static void tox_event_group_topic_lock_destruct(Tox_Event_Group_Topic_Lock *group_topic_lock, const Memory *mem)
static void tox_event_group_topic_lock_destruct(Tox_Event_Group_Topic_Lock *_Nonnull group_topic_lock, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_group_topic_lock_pack(
&& tox_group_topic_lock_pack(event->topic_lock, bp);
}
non_null()
static bool tox_event_group_topic_lock_unpack_into(
Tox_Event_Group_Topic_Lock *event, Bin_Unpack *bu)
static bool tox_event_group_topic_lock_unpack_into(Tox_Event_Group_Topic_Lock *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_group_topic_lock_free(Tox_Event_Group_Topic_Lock *group_topic_loc
mem_delete(mem, group_topic_lock);
}
non_null()
static Tox_Event_Group_Topic_Lock *tox_events_add_group_topic_lock(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Topic_Lock *tox_events_add_group_topic_lock(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Topic_Lock *const group_topic_lock = tox_event_group_topic_lock_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_group_topic_lock_unpack(
return tox_event_group_topic_lock_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Topic_Lock *tox_event_group_topic_lock_alloc(void *user_data)
static Tox_Event_Group_Topic_Lock *tox_event_group_topic_lock_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -28,9 +28,7 @@ struct Tox_Event_Group_Voice_State {
Tox_Group_Voice_State voice_state;
};
non_null()
static void tox_event_group_voice_state_set_group_number(Tox_Event_Group_Voice_State *group_voice_state,
uint32_t group_number)
static void tox_event_group_voice_state_set_group_number(Tox_Event_Group_Voice_State *_Nonnull group_voice_state, uint32_t group_number)
{
assert(group_voice_state != nullptr);
group_voice_state->group_number = group_number;
@@ -41,9 +39,7 @@ uint32_t tox_event_group_voice_state_get_group_number(const Tox_Event_Group_Voic
return group_voice_state->group_number;
}
non_null()
static void tox_event_group_voice_state_set_voice_state(Tox_Event_Group_Voice_State *group_voice_state,
Tox_Group_Voice_State voice_state)
static void tox_event_group_voice_state_set_voice_state(Tox_Event_Group_Voice_State *_Nonnull group_voice_state, Tox_Group_Voice_State voice_state)
{
assert(group_voice_state != nullptr);
group_voice_state->voice_state = voice_state;
@@ -54,15 +50,13 @@ Tox_Group_Voice_State tox_event_group_voice_state_get_voice_state(const Tox_Even
return group_voice_state->voice_state;
}
non_null()
static void tox_event_group_voice_state_construct(Tox_Event_Group_Voice_State *group_voice_state)
static void tox_event_group_voice_state_construct(Tox_Event_Group_Voice_State *_Nonnull group_voice_state)
{
*group_voice_state = (Tox_Event_Group_Voice_State) {
0
};
}
non_null()
static void tox_event_group_voice_state_destruct(Tox_Event_Group_Voice_State *group_voice_state, const Memory *mem)
static void tox_event_group_voice_state_destruct(Tox_Event_Group_Voice_State *_Nonnull group_voice_state, const Memory *_Nonnull mem)
{
return;
}
@@ -75,9 +69,7 @@ bool tox_event_group_voice_state_pack(
&& tox_group_voice_state_pack(event->voice_state, bp);
}
non_null()
static bool tox_event_group_voice_state_unpack_into(
Tox_Event_Group_Voice_State *event, Bin_Unpack *bu)
static bool tox_event_group_voice_state_unpack_into(Tox_Event_Group_Voice_State *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
@@ -120,8 +112,7 @@ void tox_event_group_voice_state_free(Tox_Event_Group_Voice_State *group_voice_s
mem_delete(mem, group_voice_state);
}
non_null()
static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events *events, const Memory *mem)
static Tox_Event_Group_Voice_State *tox_events_add_group_voice_state(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Group_Voice_State *const group_voice_state = tox_event_group_voice_state_new(mem);
@@ -154,8 +145,7 @@ bool tox_event_group_voice_state_unpack(
return tox_event_group_voice_state_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Group_Voice_State *tox_event_group_voice_state_alloc(void *user_data)
static Tox_Event_Group_Voice_State *tox_event_group_voice_state_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -27,9 +27,7 @@ struct Tox_Event_Self_Connection_Status {
Tox_Connection connection_status;
};
non_null()
static void tox_event_self_connection_status_set_connection_status(Tox_Event_Self_Connection_Status *self_connection_status,
Tox_Connection connection_status)
static void tox_event_self_connection_status_set_connection_status(Tox_Event_Self_Connection_Status *_Nonnull self_connection_status, Tox_Connection connection_status)
{
assert(self_connection_status != nullptr);
self_connection_status->connection_status = connection_status;
@@ -40,15 +38,13 @@ Tox_Connection tox_event_self_connection_status_get_connection_status(const Tox_
return self_connection_status->connection_status;
}
non_null()
static void tox_event_self_connection_status_construct(Tox_Event_Self_Connection_Status *self_connection_status)
static void tox_event_self_connection_status_construct(Tox_Event_Self_Connection_Status *_Nonnull self_connection_status)
{
*self_connection_status = (Tox_Event_Self_Connection_Status) {
TOX_CONNECTION_NONE
};
}
non_null()
static void tox_event_self_connection_status_destruct(Tox_Event_Self_Connection_Status *self_connection_status, const Memory *mem)
static void tox_event_self_connection_status_destruct(Tox_Event_Self_Connection_Status *_Nonnull self_connection_status, const Memory *_Nonnull mem)
{
return;
}
@@ -59,9 +55,7 @@ bool tox_event_self_connection_status_pack(
return tox_connection_pack(event->connection_status, bp);
}
non_null()
static bool tox_event_self_connection_status_unpack_into(
Tox_Event_Self_Connection_Status *event, Bin_Unpack *bu)
static bool tox_event_self_connection_status_unpack_into(Tox_Event_Self_Connection_Status *_Nonnull event, Bin_Unpack *_Nonnull bu)
{
assert(event != nullptr);
return tox_connection_unpack(&event->connection_status, bu);
@@ -99,8 +93,7 @@ void tox_event_self_connection_status_free(Tox_Event_Self_Connection_Status *sel
mem_delete(mem, self_connection_status);
}
non_null()
static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(Tox_Events *events, const Memory *mem)
static Tox_Event_Self_Connection_Status *tox_events_add_self_connection_status(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)
{
Tox_Event_Self_Connection_Status *const self_connection_status = tox_event_self_connection_status_new(mem);
@@ -133,8 +126,7 @@ bool tox_event_self_connection_status_unpack(
return tox_event_self_connection_status_unpack_into(*event, bu);
}
non_null()
static Tox_Event_Self_Connection_Status *tox_event_self_connection_status_alloc(void *user_data)
static Tox_Event_Self_Connection_Status *tox_event_self_connection_status_alloc(void *_Nonnull user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
assert(state != nullptr);

View File

@@ -87,21 +87,18 @@ bool create_forward_chain_packet(const uint8_t *chain_keys, uint16_t chain_lengt
return true;
}
non_null()
static uint16_t forwarding_packet_length(uint16_t sendback_data_len, uint16_t data_length)
{
const uint16_t sendback_len = sendback_data_len == 0 ? 0 : TIMED_AUTH_SIZE + sendback_data_len;
return 1 + 1 + sendback_len + data_length;
}
non_null(1, 4, 6) nullable(2)
static bool create_forwarding_packet(const Forwarding *forwarding,
const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *data, uint16_t length,
uint8_t *packet)
static bool create_forwarding_packet(const Forwarding *_Nonnull forwarding,
const uint8_t *_Nullable sendback_data, uint16_t sendback_data_len,
const uint8_t *_Nonnull data, uint16_t length,
uint8_t *_Nonnull packet)
{
packet[0] = NET_PACKET_FORWARDING;
if (sendback_data_len == 0) {
packet[1] = 0;
memcpy(packet + 1 + 1, data, length);
@@ -143,10 +140,9 @@ bool send_forwarding(const Forwarding *forwarding, const IP_Port *dest,
#define FORWARD_REQUEST_MIN_PACKET_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE)
non_null(1) nullable(2, 4)
static bool handle_forward_request_dht(const Forwarding *forwarding,
const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *packet, uint16_t length)
static bool handle_forward_request_dht(const Forwarding *_Nonnull forwarding,
const uint8_t *_Nullable sendback_data, uint16_t sendback_data_len,
const uint8_t *_Nullable packet, uint16_t length)
{
if (length < FORWARD_REQUEST_MIN_PACKET_SIZE) {
return false;
@@ -170,12 +166,10 @@ static bool handle_forward_request_dht(const Forwarding *forwarding,
return route_packet(forwarding->dht, public_key, forwarding_packet, len) == len;
}
non_null(1, 2) nullable(3, 5)
static int handle_forward_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_forward_request(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nullable packet, uint16_t length,
void *_Nullable userdata)
{
const Forwarding *forwarding = (const Forwarding *)object;
uint8_t sendback_data[1 + MAX_PACKED_IPPORT_SIZE];
sendback_data[0] = SENDBACK_IPPORT;
@@ -191,12 +185,10 @@ static int handle_forward_request(void *object, const IP_Port *source, const uin
#define MIN_NONEMPTY_SENDBACK_SIZE TIMED_AUTH_SIZE
#define FORWARD_REPLY_MIN_PACKET_SIZE (1 + 1 + MIN_NONEMPTY_SENDBACK_SIZE)
non_null(1, 2) nullable(3, 5)
static int handle_forward_reply(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_forward_reply(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nullable packet, uint16_t length,
void *_Nullable userdata)
{
const Forwarding *forwarding = (const Forwarding *)object;
if (length < FORWARD_REPLY_MIN_PACKET_SIZE) {
return 1;
}
@@ -265,12 +257,10 @@ static int handle_forward_reply(void *object, const IP_Port *source, const uint8
#define FORWARDING_MIN_PACKET_SIZE (1 + 1)
non_null(1, 2) nullable(3, 5)
static int handle_forwarding(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_forwarding(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nullable packet, uint16_t length,
void *_Nullable userdata)
{
const Forwarding *forwarding = (const Forwarding *)object;
if (length < FORWARDING_MIN_PACKET_SIZE) {
return 1;
}
@@ -358,7 +348,7 @@ void set_callback_forward_reply(Forwarding *forwarding, forward_reply_cb *functi
forwarding->forward_reply_callback_object = object;
}
Forwarding *new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht)
Forwarding *_Nullable new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht)
{
if (log == nullptr || mono_time == nullptr || dht == nullptr) {
return nullptr;

View File

@@ -30,8 +30,7 @@ extern "C" {
typedef struct Forwarding Forwarding;
non_null()
DHT *forwarding_get_dht(const Forwarding *forwarding);
DHT *_Nonnull forwarding_get_dht(const Forwarding *_Nonnull forwarding);
/**
* @brief Send data to forwarder for forwarding via chain of dht nodes.
@@ -45,10 +44,8 @@ DHT *forwarding_get_dht(const Forwarding *forwarding);
*
* @return true on success, false otherwise.
*/
non_null()
bool send_forward_request(const Networking_Core *net, const IP_Port *forwarder,
const uint8_t *chain_keys, uint16_t chain_length,
const uint8_t *data, uint16_t data_length);
bool send_forward_request(const Networking_Core *_Nonnull net, const IP_Port *_Nonnull forwarder, const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data,
uint16_t data_length);
/** Returns size of packet written by create_forward_chain_packet. */
uint16_t forward_chain_packet_size(uint16_t chain_length, uint16_t data_length);
@@ -67,10 +64,7 @@ uint16_t forward_chain_packet_size(uint16_t chain_length, uint16_t data_length);
*
* @return true on success, false otherwise.
*/
non_null()
bool create_forward_chain_packet(const uint8_t *chain_keys, uint16_t chain_length,
const uint8_t *data, uint16_t data_length,
uint8_t *packet);
bool create_forward_chain_packet(const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data, uint16_t data_length, uint8_t *_Nonnull packet);
/**
* @brief Send reply to forwarded packet via forwarder.
@@ -79,49 +73,36 @@ bool create_forward_chain_packet(const uint8_t *chain_keys, uint16_t chain_lengt
*
* @return true on success, false otherwise.
*/
non_null()
bool forward_reply(const Networking_Core *net, const IP_Port *forwarder,
const uint8_t *sendback, uint16_t sendback_length,
const uint8_t *data, uint16_t length);
bool forward_reply(const Networking_Core *_Nonnull net, const IP_Port *_Nonnull forwarder, const uint8_t *_Nonnull sendback, uint16_t sendback_length, const uint8_t *_Nonnull data,
uint16_t length);
/**
* @brief Set callback to handle a forwarded request.
* To reply to the packet, callback should use `forward_reply()` to send a reply
* forwarded via forwarder, passing the provided sendback.
*/
typedef void forwarded_request_cb(void *object, const IP_Port *forwarder, const uint8_t *sendback,
uint16_t sendback_length, const uint8_t *data,
uint16_t length, void *userdata);
non_null(1) nullable(2, 3)
void set_callback_forwarded_request(Forwarding *forwarding, forwarded_request_cb *function, void *object);
typedef void forwarded_request_cb(void *_Nullable object, const IP_Port *_Nonnull forwarder, const uint8_t *_Nonnull sendback,
uint16_t sendback_length, const uint8_t *_Nonnull data,
uint16_t length, void *_Nullable userdata);
void set_callback_forwarded_request(Forwarding *_Nonnull forwarding, forwarded_request_cb *_Nullable function, void *_Nullable object);
/** @brief Set callback to handle a forwarded response. */
typedef void forwarded_response_cb(void *object, const uint8_t *data, uint16_t length, void *userdata);
non_null(1) nullable(2, 3)
void set_callback_forwarded_response(Forwarding *forwarding, forwarded_response_cb *function, void *object);
typedef void forwarded_response_cb(void *_Nullable object, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
void set_callback_forwarded_response(Forwarding *_Nonnull forwarding, forwarded_response_cb *_Nullable function, void *_Nullable object);
/** @brief Send forwarding packet to dest with given sendback data and data. */
non_null(1, 2, 5) nullable(3)
bool send_forwarding(const Forwarding *forwarding, const IP_Port *dest,
const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *data, uint16_t length);
typedef bool forward_reply_cb(void *object, const uint8_t *sendback_data, uint16_t sendback_data_len,
const uint8_t *data, uint16_t length);
bool send_forwarding(const Forwarding *_Nonnull forwarding, const IP_Port *_Nonnull dest,
const uint8_t *_Nullable sendback_data, uint16_t sendback_data_len,
const uint8_t *_Nonnull data, uint16_t length);
typedef bool forward_reply_cb(void *_Nullable object, const uint8_t *_Nullable sendback_data, uint16_t sendback_data_len,
const uint8_t *_Nonnull data, uint16_t length);
/**
* @brief Set callback to handle a forward reply with an otherwise unhandled
* sendback.
*/
non_null(1) nullable(2, 3)
void set_callback_forward_reply(Forwarding *forwarding, forward_reply_cb *function, void *object);
non_null()
Forwarding *new_forwarding(const Logger *log, const Memory *mem, const Random *rng, const Mono_Time *mono_time, DHT *dht);
nullable(1)
void kill_forwarding(Forwarding *forwarding);
void set_callback_forward_reply(Forwarding *_Nonnull forwarding, forward_reply_cb *_Nullable function, void *_Nullable object);
Forwarding *_Nullable new_forwarding(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, DHT *_Nonnull dht);
void kill_forwarding(Forwarding *_Nullable forwarding);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -110,8 +110,7 @@ const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc)
* @retval true if the friendcon_id is valid.
* @retval false if the friendcon_id is not valid.
*/
non_null()
static bool friendconn_id_valid(const Friend_Connections *fr_c, int friendcon_id)
static bool friendconn_id_valid(const Friend_Connections *_Nonnull fr_c, int friendcon_id)
{
return (unsigned int)friendcon_id < fr_c->num_cons &&
fr_c->conns != nullptr &&
@@ -123,8 +122,7 @@ static bool friendconn_id_valid(const Friend_Connections *fr_c, int friendcon_id
* @retval false if realloc fails.
* @retval true if it succeeds.
*/
non_null()
static bool realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
static bool realloc_friendconns(Friend_Connections *_Nonnull fr_c, uint32_t num)
{
if (num == 0) {
mem_delete(fr_c->mem, fr_c->conns);
@@ -147,8 +145,7 @@ static bool realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
* @retval -1 on failure.
* @return friendcon_id on success.
*/
non_null()
static int create_friend_conn(Friend_Connections *fr_c)
static int create_friend_conn(Friend_Connections *_Nonnull fr_c)
{
for (uint32_t i = 0; i < fr_c->num_cons; ++i) {
if (fr_c->conns[i].status == FRIENDCONN_STATUS_NONE) {
@@ -172,8 +169,7 @@ static int create_friend_conn(Friend_Connections *fr_c)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
static int wipe_friend_conn(Friend_Connections *_Nonnull fr_c, int friendcon_id)
{
if (!friendconn_id_valid(fr_c, friendcon_id)) {
return -1;
@@ -197,7 +193,7 @@ static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
return 0;
}
Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
Friend_Conn *_Nullable get_conn(const Friend_Connections *fr_c, int friendcon_id)
{
if (!friendconn_id_valid(fr_c, friendcon_id)) {
return nullptr;
@@ -230,9 +226,7 @@ int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, const IP_Port *ip_port,
const uint8_t *public_key)
static int friend_add_tcp_relay(Friend_Connections *_Nonnull fr_c, int friendcon_id, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key)
{
IP_Port ipp_copy = *ip_port;
@@ -268,8 +262,7 @@ static int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, cons
}
/** Connect to number saved relays for friend. */
non_null()
static void connect_to_saved_tcp_relays(Friend_Connections *fr_c, int friendcon_id, unsigned int number)
static void connect_to_saved_tcp_relays(Friend_Connections *_Nonnull fr_c, int friendcon_id, unsigned int number)
{
const Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@@ -289,8 +282,7 @@ static void connect_to_saved_tcp_relays(Friend_Connections *fr_c, int friendcon_
}
}
non_null()
static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
static unsigned int send_relays(Friend_Connections *_Nonnull fr_c, int friendcon_id)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@@ -330,8 +322,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
}
/** callback for recv TCP relay nodes. */
non_null()
static int tcp_relay_node_callback(void *object, uint32_t number, const IP_Port *ip_port, const uint8_t *public_key)
static int tcp_relay_node_callback(void *_Nonnull object, uint32_t number, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key)
{
Friend_Connections *fr_c = (Friend_Connections *)object;
const Friend_Conn *friend_con = get_conn(fr_c, number);
@@ -347,12 +338,10 @@ static int tcp_relay_node_callback(void *object, uint32_t number, const IP_Port
return add_tcp_relay(fr_c->net_crypto, ip_port, public_key);
}
non_null()
static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id);
static int friend_new_connection(Friend_Connections *_Nonnull fr_c, int friendcon_id);
/** Callback for DHT ip_port changes. */
non_null()
static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port)
static void dht_ip_callback(void *_Nonnull object, int32_t number, const IP_Port *_Nonnull ip_port)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
Friend_Conn *const friend_con = get_conn(fr_c, number);
@@ -375,8 +364,7 @@ static void dht_ip_callback(void *object, int32_t number, const IP_Port *ip_port
}
}
non_null()
static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_public_key)
static void change_dht_pk(Friend_Connections *_Nonnull fr_c, int friendcon_id, const uint8_t *_Nonnull dht_public_key)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@@ -398,8 +386,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
}
non_null()
static int handle_status(void *object, int id, bool status, void *userdata)
static int handle_status(void *_Nonnull object, int id, bool status, void *_Nonnull userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
Friend_Conn *const friend_con = get_conn(fr_c, id);
@@ -446,8 +433,7 @@ static int handle_status(void *object, int id, bool status, void *userdata)
}
/** Callback for dht public key changes. */
non_null()
static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata)
static void dht_pk_callback(void *_Nonnull object, int32_t number, const uint8_t *_Nonnull dht_public_key, void *_Nonnull userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
Friend_Conn *const friend_con = get_conn(fr_c, number);
@@ -473,8 +459,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
onion_set_friend_dht_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
non_null()
static int handle_packet(void *object, int id, const uint8_t *data, uint16_t length, void *userdata)
static int handle_packet(void *_Nonnull object, int id, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
@@ -533,8 +518,7 @@ static int handle_packet(void *object, int id, const uint8_t *data, uint16_t len
return 0;
}
non_null()
static int handle_lossy_packet(void *object, int id, const uint8_t *data, uint16_t length, void *userdata)
static int handle_lossy_packet(void *_Nonnull object, int id, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
const Friend_Connections *const fr_c = (const Friend_Connections *)object;
@@ -565,8 +549,7 @@ static int handle_lossy_packet(void *object, int id, const uint8_t *data, uint16
return 0;
}
non_null()
static int handle_new_connections(void *object, const New_Connection *n_c)
static int handle_new_connections(void *_Nonnull object, const New_Connection *_Nonnull n_c)
{
Friend_Connections *const fr_c = (Friend_Connections *)object;
const int friendcon_id = getfriend_conn_id_pk(fr_c, n_c->public_key);
@@ -638,8 +621,7 @@ static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id)
return 0;
}
non_null()
static int send_ping(const Friend_Connections *fr_c, int friendcon_id)
static int send_ping(const Friend_Connections *_Nonnull fr_c, int friendcon_id)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@@ -832,7 +814,7 @@ int new_friend_connection(Friend_Connections *fr_c, const uint8_t *real_public_k
* @retval -1 on failure.
* @retval 0 on success.
*/
int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id)
int kill_friend_connection(Friend_Connections *_Nonnull fr_c, int friendcon_id)
{
Friend_Conn *const friend_con = get_conn(fr_c, friendcon_id);
@@ -952,8 +934,7 @@ Friend_Connections *new_friend_connections(
}
/** Send a LAN discovery packet every LAN_DISCOVERY_INTERVAL seconds. */
non_null()
static void lan_discovery(Friend_Connections *fr_c)
static void lan_discovery(Friend_Connections *_Nonnull fr_c)
{
if (fr_c->last_lan_discovery + LAN_DISCOVERY_INTERVAL < mono_time_get(fr_c->mono_time)) {
const uint16_t first = fr_c->next_lan_port;

View File

@@ -53,52 +53,45 @@ typedef enum Friendconn_Status {
typedef struct Friend_Connections Friend_Connections;
non_null() Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c);
Net_Crypto *_Nonnull friendconn_net_crypto(const Friend_Connections *_Nonnull fr_c);
/** @return friendcon_id corresponding to the real public key on success.
/**
* @return friendcon_id corresponding to the real public key on success.
* @retval -1 on failure.
*/
non_null()
int getfriend_conn_id_pk(const Friend_Connections *fr_c, const uint8_t *real_pk);
int getfriend_conn_id_pk(const Friend_Connections *_Nonnull fr_c, const uint8_t *_Nonnull real_pk);
/** @brief Increases lock_count for the connection with friendcon_id by 1.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null()
int friend_connection_lock(const Friend_Connections *fr_c, int friendcon_id);
int friend_connection_lock(const Friend_Connections *_Nonnull fr_c, int friendcon_id);
/**
* @retval FRIENDCONN_STATUS_CONNECTED if the friend is connected.
* @retval FRIENDCONN_STATUS_CONNECTING if the friend isn't connected.
* @retval FRIENDCONN_STATUS_NONE on failure.
*/
non_null()
unsigned int friend_con_connected(const Friend_Connections *fr_c, int friendcon_id);
unsigned int friend_con_connected(const Friend_Connections *_Nonnull fr_c, int friendcon_id);
/** @brief Copy public keys associated to friendcon_id.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null(3) nullable(1, 2)
int get_friendcon_public_keys(uint8_t *real_pk, uint8_t *dht_temp_pk, const Friend_Connections *fr_c, int friendcon_id);
int get_friendcon_public_keys(uint8_t *_Nullable real_pk, uint8_t *_Nullable dht_temp_pk, const Friend_Connections *_Nonnull fr_c, int friendcon_id);
/** Set temp dht key for connection. */
non_null()
void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *dht_temp_pk, void *userdata);
void set_dht_temp_pk(Friend_Connections *_Nonnull fr_c, int friendcon_id, const uint8_t *_Nonnull dht_temp_pk, void *_Nonnull userdata);
typedef int global_status_cb(void *object, int friendcon_id, bool status, void *userdata);
typedef int global_status_cb(void *_Nullable object, int friendcon_id, bool status, void *_Nullable userdata);
typedef int fc_status_cb(void *object, int friendcon_id, bool status, void *userdata);
typedef int fc_data_cb(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
typedef int fc_lossy_data_cb(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
typedef int fc_status_cb(void *_Nullable object, int friendcon_id, bool status, void *_Nullable userdata);
typedef int fc_data_cb(void *_Nullable object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
typedef int fc_lossy_data_cb(void *_Nullable object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/** Set global status callback for friend connections. */
non_null(1) nullable(2, 3)
void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *global_status_callback, void *object);
void set_global_status_callback(Friend_Connections *_Nonnull fr_c, global_status_cb *_Nullable global_status_callback, void *_Nullable object);
/** @brief Set the callbacks for the friend connection.
* @param index is the index (0 to (MAX_FRIEND_CONNECTION_CALLBACKS - 1)) we
* want the callback to set in the array.
@@ -106,20 +99,17 @@ void set_global_status_callback(Friend_Connections *fr_c, global_status_cb *glob
* @retval 0 on success.
* @retval -1 on failure
*/
non_null(1) nullable(4, 5, 6, 7)
int friend_connection_callbacks(const Friend_Connections *fr_c, int friendcon_id, unsigned int index,
fc_status_cb *status_callback,
fc_data_cb *data_callback,
fc_lossy_data_cb *lossy_data_callback,
void *object, int number);
int friend_connection_callbacks(const Friend_Connections *_Nonnull fr_c, int friendcon_id, unsigned int index,
fc_status_cb *_Nullable status_callback,
fc_data_cb *_Nullable data_callback,
fc_lossy_data_cb *_Nullable lossy_data_callback,
void *_Nullable object, int number);
/** @brief return the crypt_connection_id for the connection.
*
* @return crypt_connection_id on success.
* @retval -1 on failure.
*/
non_null()
int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int friendcon_id);
int friend_connection_crypt_connection_id(const Friend_Connections *_Nonnull fr_c, int friendcon_id);
/** @brief Create a new friend connection.
* If one to that real public key already exists, increase lock count and return it.
@@ -127,16 +117,14 @@ int friend_connection_crypt_connection_id(const Friend_Connections *fr_c, int fr
* @retval -1 on failure.
* @return connection id on success.
*/
non_null()
int new_friend_connection(Friend_Connections *fr_c, const uint8_t *real_public_key);
int new_friend_connection(Friend_Connections *_Nonnull fr_c, const uint8_t *_Nonnull real_public_key);
/** @brief Kill a friend connection.
*
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id);
int kill_friend_connection(Friend_Connections *_Nonnull fr_c, int friendcon_id);
/** @brief Send a Friend request packet.
*
@@ -144,38 +132,30 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id);
* @retval 0 if it sent the friend request directly to the friend.
* @return the number of peers it was routed through if it did not send it directly.
*/
non_null()
int send_friend_request_packet(
Friend_Connections *fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *data, uint16_t length);
int send_friend_request_packet(Friend_Connections *_Nonnull fr_c, int friendcon_id, uint32_t nospam_num, const uint8_t *_Nonnull data, uint16_t length);
typedef int fr_request_cb(
void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length, void *userdata);
void *_Nonnull object, const uint8_t *_Nonnull source_pubkey, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/** @brief Set friend request callback.
*
* This function will be called every time a friend request packet is received.
*/
non_null()
void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_request_callback, void *object);
void set_friend_request_callback(Friend_Connections *_Nonnull fr_c, fr_request_cb *_Nonnull fr_request_callback, void *_Nonnull object);
/** Create new friend_connections instance. */
non_null()
Friend_Connections *new_friend_connections(
const Logger *logger, const Memory *mem, const Mono_Time *mono_time, const Network *ns,
Onion_Client *onion_c, bool local_discovery_enabled);
Friend_Connections *_Nullable new_friend_connections(const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, const Network *_Nonnull ns,
Onion_Client *_Nonnull onion_c, bool local_discovery_enabled);
/** main friend_connections loop. */
non_null()
void do_friend_connections(Friend_Connections *fr_c, void *userdata);
void do_friend_connections(Friend_Connections *_Nonnull fr_c, void *_Nonnull userdata);
/** Free everything related with friend_connections. */
nullable(1)
void kill_friend_connections(Friend_Connections *fr_c);
void kill_friend_connections(Friend_Connections *_Nullable fr_c);
typedef struct Friend_Conn Friend_Conn;
non_null() Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id);
non_null() int friend_conn_get_onion_friendnum(const Friend_Conn *fc);
non_null() const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc);
Friend_Conn *_Nullable get_conn(const Friend_Connections *_Nonnull fr_c, int friendcon_id);
int friend_conn_get_onion_friendnum(const Friend_Conn *_Nonnull fc);
const IP_Port *_Nullable friend_conn_get_dht_ip_port(const Friend_Conn *_Nonnull fc);
#endif /* C_TOXCORE_TOXCORE_FRIEND_CONNECTION_H */

View File

@@ -78,8 +78,7 @@ void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void
}
/** Add to list of received friend requests. */
non_null()
static void addto_receivedlist(Friend_Requests *fr, const uint8_t *real_pk)
static void addto_receivedlist(Friend_Requests *_Nonnull fr, const uint8_t *_Nonnull real_pk)
{
if (fr->received.requests_index >= MAX_RECEIVED_STORED) {
fr->received.requests_index = 0;
@@ -94,8 +93,7 @@ static void addto_receivedlist(Friend_Requests *fr, const uint8_t *real_pk)
* @retval false if it did not.
* @retval true if it did.
*/
non_null()
static bool request_received(const Friend_Requests *fr, const uint8_t *real_pk)
static bool request_received(const Friend_Requests *_Nonnull fr, const uint8_t *_Nonnull real_pk)
{
for (uint32_t i = 0; i < MAX_RECEIVED_STORED; ++i) {
if (pk_equal(fr->received.requests[i], real_pk)) {
@@ -111,7 +109,7 @@ static bool request_received(const Friend_Requests *fr, const uint8_t *real_pk)
* @retval 0 if it removed it successfully.
* @retval -1 if it didn't find it.
*/
int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk)
int remove_request_received(Friend_Requests *_Nonnull fr, const uint8_t *_Nonnull real_pk)
{
for (uint32_t i = 0; i < MAX_RECEIVED_STORED; ++i) {
if (pk_equal(fr->received.requests[i], real_pk)) {
@@ -123,9 +121,7 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk)
return -1;
}
non_null()
static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length,
void *userdata)
static int friendreq_handlepacket(void *_Nonnull object, const uint8_t *_Nonnull source_pubkey, const uint8_t *_Nonnull data, uint16_t length, void *_Nonnull userdata)
{
Friend_Requests *const fr = (Friend_Requests *)object;

View File

@@ -21,40 +21,33 @@
typedef struct Friend_Requests Friend_Requests;
/** Set and get the nospam variable used to prevent one type of friend request spam. */
non_null() void set_nospam(Friend_Requests *fr, uint32_t num);
non_null() uint32_t get_nospam(const Friend_Requests *fr);
void set_nospam(Friend_Requests *_Nonnull fr, uint32_t num);
uint32_t get_nospam(const Friend_Requests *_Nonnull fr);
/** @brief Remove real_pk from received_requests list.
*
* @retval 0 if it removed it successfully.
* @retval -1 if it didn't find it.
*/
non_null()
int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk);
int remove_request_received(Friend_Requests *_Nonnull fr, const uint8_t *_Nonnull real_pk);
typedef void fr_friend_request_cb(void *object, const uint8_t *public_key, const uint8_t *message, size_t length,
void *user_data);
typedef void fr_friend_request_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull message, size_t length,
void *_Nullable user_data);
/** Set the function that will be executed when a friend request for us is received. */
non_null()
void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object);
void callback_friendrequest(Friend_Requests *_Nonnull fr, fr_friend_request_cb *_Nonnull function, void *_Nonnull object);
typedef int filter_function_cb(void *object, const uint8_t *public_key);
typedef int filter_function_cb(void *_Nonnull object, const uint8_t *_Nonnull public_key);
/** @brief Set the function used to check if a friend request should be displayed to the user or not.
* It must return 0 if the request is ok (anything else if it is bad).
*/
non_null()
void set_filter_function(Friend_Requests *fr, filter_function_cb *function, void *userdata);
void set_filter_function(Friend_Requests *_Nonnull fr, filter_function_cb *_Nonnull function, void *_Nonnull userdata);
/** Sets up friendreq packet handlers. */
non_null()
void friendreq_init(Friend_Requests *fr, Friend_Connections *fr_c);
void friendreq_init(Friend_Requests *_Nonnull fr, Friend_Connections *_Nonnull fr_c);
non_null()
Friend_Requests *friendreq_new(const Memory *mem);
nullable(1)
void friendreq_kill(Friend_Requests *fr);
Friend_Requests *_Nullable friendreq_new(const Memory *_Nonnull mem);
void friendreq_kill(Friend_Requests *_Nullable fr);
#endif /* C_TOXCORE_TOXCORE_FRIEND_REQUESTS_H */

View File

@@ -216,20 +216,17 @@ const Mono_Time *g_mono_time(const Group_Chats *g_c)
return g_c->mono_time;
}
non_null()
static bool group_id_eq(const uint8_t *a, const uint8_t *b)
static bool group_id_eq(const uint8_t *_Nonnull a, const uint8_t *_Nonnull b)
{
return pk_equal(a, b);
}
non_null()
static bool g_title_eq(const Group_c *g, const uint8_t *title, uint8_t title_len)
static bool g_title_eq(const Group_c *_Nonnull g, const uint8_t *_Nonnull title, uint8_t title_len)
{
return memeq(g->title, g->title_len, title, title_len);
}
non_null()
static bool g_peer_nick_eq(const Group_Peer *peer, const uint8_t *nick, uint8_t nick_len)
static bool g_peer_nick_eq(const Group_Peer *_Nonnull peer, const uint8_t *_Nonnull nick, uint8_t nick_len)
{
return memeq(peer->nick, peer->nick_len, nick, nick_len);
}
@@ -238,8 +235,7 @@ static bool g_peer_nick_eq(const Group_Peer *peer, const uint8_t *nick, uint8_t
* @retval false if the groupnumber is not valid.
* @retval true if the groupnumber is valid.
*/
non_null()
static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
static bool is_groupnumber_valid(const Group_Chats *_Nonnull g_c, uint32_t groupnumber)
{
return groupnumber < g_c->num_chats
&& g_c->chats != nullptr
@@ -251,8 +247,7 @@ static bool is_groupnumber_valid(const Group_Chats *g_c, uint32_t groupnumber)
* @retval false if mem_vrealloc fails.
* @retval true if it succeeds.
*/
non_null()
static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
static bool realloc_conferences(Group_Chats *_Nonnull g_c, uint16_t num)
{
if (num == 0) {
mem_delete(g_c->mem, g_c->chats);
@@ -270,8 +265,7 @@ static bool realloc_conferences(Group_Chats *g_c, uint16_t num)
return true;
}
non_null()
static void setup_conference(Group_c *g)
static void setup_conference(Group_c *_Nonnull g)
{
*g = empty_group_c;
g->maxfrozen = MAX_FROZEN_DEFAULT;
@@ -282,8 +276,7 @@ static void setup_conference(Group_c *g)
* @retval -1 on failure.
* @return groupnumber on success.
*/
non_null()
static int32_t create_group_chat(Group_Chats *g_c)
static int32_t create_group_chat(Group_Chats *_Nonnull g_c)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
if (g_c->chats[i].status == GROUPCHAT_STATUS_NONE) {
@@ -301,8 +294,7 @@ static int32_t create_group_chat(Group_Chats *g_c)
return -1;
}
non_null()
static void wipe_group_c(const Memory *mem, Group_c *g)
static void wipe_group_c(const Memory *_Nonnull mem, Group_c *_Nonnull g)
{
mem_delete(mem, g->frozen);
mem_delete(mem, g->group);
@@ -313,8 +305,7 @@ static void wipe_group_c(const Memory *mem, Group_c *g)
*
* @retval true on success.
*/
non_null()
static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
static bool wipe_group_chat(Group_Chats *_Nonnull g_c, uint32_t groupnumber)
{
if (groupnumber >= g_c->num_chats || g_c->chats == nullptr) {
return false;
@@ -338,8 +329,7 @@ static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber)
return true;
}
non_null()
static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber)
static Group_c *get_group_c(const Group_Chats *_Nonnull g_c, uint32_t groupnumber)
{
if (!is_groupnumber_valid(g_c, groupnumber)) {
return nullptr;
@@ -356,8 +346,7 @@ static Group_c *get_group_c(const Group_Chats *g_c, uint32_t groupnumber)
*
* TODO(irungentoo): make this more efficient.
*/
non_null()
static int peer_in_group(const Group_c *g, const uint8_t *real_pk)
static int peer_in_group(const Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk)
{
for (uint32_t i = 0; i < g->numpeers; ++i) {
if (pk_equal(g->group[i].real_pk, real_pk)) {
@@ -368,8 +357,7 @@ static int peer_in_group(const Group_c *g, const uint8_t *real_pk)
return -1;
}
non_null()
static int frozen_in_group(const Group_c *g, const uint8_t *real_pk)
static int frozen_in_group(const Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk)
{
for (uint32_t i = 0; i < g->numfrozen; ++i) {
if (pk_equal(g->frozen[i].real_pk, real_pk)) {
@@ -388,8 +376,7 @@ static int frozen_in_group(const Group_c *g, const uint8_t *real_pk)
*
* TODO(irungentoo): make this more efficient and maybe use constant time comparisons?
*/
non_null()
static int32_t get_group_num(const Group_Chats *g_c, const uint8_t type, const uint8_t *id)
static int32_t get_group_num(const Group_Chats *_Nonnull g_c, const uint8_t type, const uint8_t *_Nonnull id)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
if (g_c->chats[i].type == type && group_id_eq(g_c->chats[i].id, id)) {
@@ -419,8 +406,7 @@ int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id)
*
* TODO(irungentoo): make this more efficient.
*/
non_null()
static int get_peer_index(const Group_c *g, uint16_t peer_number)
static int get_peer_index(const Group_c *_Nonnull g, uint16_t peer_number)
{
for (uint32_t i = 0; i < g->numpeers; ++i) {
if (g->group[i].peer_number == peer_number) {
@@ -431,8 +417,7 @@ static int get_peer_index(const Group_c *g, uint16_t peer_number)
return -1;
}
non_null()
static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2)
static uint64_t calculate_comp_value(const uint8_t *_Nonnull pk1, const uint8_t *_Nonnull pk2)
{
uint64_t cmp1 = 0;
uint64_t cmp2 = 0;
@@ -451,8 +436,7 @@ typedef enum Groupchat_Closest_Change {
GROUPCHAT_CLOSEST_CHANGE_REMOVED,
} Groupchat_Closest_Change;
non_null()
static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *temp_pk)
static bool add_to_closest(Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk, const uint8_t *_Nonnull temp_pk)
{
if (pk_equal(g->real_pk, real_pk)) {
return false;
@@ -527,8 +511,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te
return true;
}
non_null()
static bool pk_in_closest_peers(const Group_c *g, const uint8_t *real_pk)
static bool pk_in_closest_peers(const Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk)
{
for (unsigned int i = 0; i < DESIRED_CLOSEST; ++i) {
if (!g->closest_peers[i].active) {
@@ -543,11 +526,9 @@ static bool pk_in_closest_peers(const Group_c *g, const uint8_t *real_pk)
return false;
}
non_null()
static void remove_connection_reason(Group_Chats *g_c, Group_c *g, uint16_t i, uint8_t reason);
static void remove_connection_reason(Group_Chats *_Nonnull g_c, Group_c *_Nonnull g, uint16_t i, uint8_t reason);
non_null()
static void purge_closest(Group_Chats *g_c, uint32_t groupnumber)
static void purge_closest(Group_Chats *_Nonnull g_c, uint32_t groupnumber)
{
Group_c *g = get_group_c(g_c, groupnumber);
@@ -573,19 +554,13 @@ static void purge_closest(Group_Chats *g_c, uint32_t groupnumber)
}
}
non_null()
static bool send_packet_online(const Friend_Connections *fr_c, int friendcon_id, uint16_t group_num,
uint8_t type, const uint8_t *id);
static bool send_packet_online(const Friend_Connections *_Nonnull fr_c, int friendcon_id, uint16_t group_num, uint8_t type, const uint8_t *_Nonnull id);
non_null()
static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g, uint8_t reason,
bool lock);
static int add_conn_to_groupchat(Group_Chats *_Nonnull g_c, int friendcon_id, Group_c *_Nonnull g, uint8_t reason, bool lock);
non_null(1) nullable(3)
static void add_closest_connections(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
static void add_closest_connections(Group_Chats *_Nonnull g_c, uint32_t groupnumber, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return;
}
@@ -628,11 +603,9 @@ static void add_closest_connections(Group_Chats *g_c, uint32_t groupnumber, void
}
}
non_null(1) nullable(3)
static bool connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
static bool connect_to_closest(Group_Chats *_Nonnull g_c, uint32_t groupnumber, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return false;
}
@@ -656,8 +629,7 @@ static bool connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *use
return true;
}
non_null()
static int get_frozen_index(const Group_c *g, uint16_t peer_number)
static int get_frozen_index(const Group_c *_Nonnull g, uint16_t peer_number)
{
for (uint32_t i = 0; i < g->numfrozen; ++i) {
if (g->frozen[i].peer_number == peer_number) {
@@ -668,8 +640,7 @@ static int get_frozen_index(const Group_c *g, uint16_t peer_number)
return -1;
}
non_null()
static bool delete_frozen(const Memory *mem, Group_c *g, uint32_t frozen_index)
static bool delete_frozen(const Memory *_Nonnull mem, Group_c *_Nonnull g, uint32_t frozen_index)
{
if (frozen_index >= g->numfrozen) {
return false;
@@ -702,11 +673,9 @@ static bool delete_frozen(const Memory *mem, Group_c *g, uint32_t frozen_index)
* @return peer index if peer is in the conference.
* @retval -1 otherwise, and on error.
*/
non_null(1) nullable(4)
static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_number, void *userdata)
static int note_peer_active(Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint16_t peer_number, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return -1;
}
@@ -758,14 +727,10 @@ static int note_peer_active(Group_Chats *g_c, uint32_t groupnumber, uint16_t pee
return thawed_index;
}
non_null(1) nullable(4)
static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata);
non_null(1, 3) nullable(4)
static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, void *userdata)
static bool delpeer(Group_Chats *_Nonnull g_c, uint32_t groupnumber, int peer_index, void *_Nullable userdata);
static void delete_any_peer_with_pk(Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull real_pk, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return;
}
@@ -795,12 +760,10 @@ static void delete_any_peer_with_pk(Group_Chats *g_c, uint32_t groupnumber, cons
* @return peer_index if success or peer already in chat.
* @retval -1 if error.
*/
non_null(1, 3, 4) nullable(6)
static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_pk, const uint8_t *temp_pk,
uint16_t peer_number, void *userdata, bool fresh, bool do_gc_callback)
static int addpeer(Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull real_pk, const uint8_t *_Nonnull temp_pk,
uint16_t peer_number, void *_Nullable userdata, bool fresh, bool do_gc_callback)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return -1;
}
@@ -871,8 +834,7 @@ static int addpeer(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *real_p
return new_index;
}
non_null()
static void remove_connection(Group_Chats *g_c, Group_c *g, uint16_t i)
static void remove_connection(Group_Chats *_Nonnull g_c, Group_c *_Nonnull g, uint16_t i)
{
if ((g->connections[i].reasons & GROUPCHAT_CONNECTION_REASON_INTRODUCER) != 0) {
--g->num_introducer_connections;
@@ -882,8 +844,7 @@ static void remove_connection(Group_Chats *g_c, Group_c *g, uint16_t i)
g->connections[i].type = GROUPCHAT_CONNECTION_NONE;
}
non_null()
static void remove_from_closest(Group_c *g, int peer_index)
static void remove_from_closest(Group_c *_Nonnull g, int peer_index)
{
for (uint32_t i = 0; i < DESIRED_CLOSEST; ++i) {
if (g->closest_peers[i].active
@@ -958,8 +919,7 @@ static bool delpeer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void
}
/** Order peers with friends first and with more recently active earlier */
non_null()
static bool group_peer_less_handler(const void *object, const void *a, const void *b)
static bool group_peer_less_handler(const void *_Nonnull object, const void *_Nonnull a, const void *_Nonnull b)
{
const Group_Peer *pa = (const Group_Peer *)a;
const Group_Peer *pb = (const Group_Peer *)b;
@@ -971,30 +931,26 @@ static bool group_peer_less_handler(const void *object, const void *a, const voi
return cmp_uint(pb->last_active, pa->last_active) < 0;
}
non_null()
static const void *group_peer_get_handler(const void *arr, uint32_t index)
static const void *group_peer_get_handler(const void *_Nonnull arr, uint32_t index)
{
const Group_Peer *entries = (const Group_Peer *)arr;
return &entries[index];
}
non_null()
static void group_peer_set_handler(void *arr, uint32_t index, const void *val)
static void group_peer_set_handler(void *_Nonnull arr, uint32_t index, const void *_Nonnull val)
{
Group_Peer *entries = (Group_Peer *)arr;
const Group_Peer *entry = (const Group_Peer *)val;
entries[index] = *entry;
}
non_null()
static void *group_peer_subarr_handler(void *arr, uint32_t index, uint32_t size)
static void *group_peer_subarr_handler(void *_Nonnull arr, uint32_t index, uint32_t size)
{
Group_Peer *entries = (Group_Peer *)arr;
return &entries[index];
}
non_null()
static void *group_peer_alloc_handler(const void *object, uint32_t size)
static void *group_peer_alloc_handler(const void *_Nonnull object, uint32_t size)
{
const Memory *mem = (const Memory *)object;
Group_Peer *tmp = (Group_Peer *)mem_valloc(mem, size, sizeof(Group_Peer));
@@ -1006,8 +962,7 @@ static void *group_peer_alloc_handler(const void *object, uint32_t size)
return tmp;
}
non_null()
static void group_peer_delete_handler(const void *object, void *arr, uint32_t size)
static void group_peer_delete_handler(const void *_Nonnull object, void *_Nonnull arr, uint32_t size)
{
const Memory *mem = (const Memory *)object;
mem_delete(mem, arr);
@@ -1026,8 +981,7 @@ static const Sort_Funcs group_peer_cmp_funcs = {
*
* @retval true if any frozen peers are removed.
*/
non_null()
static bool delete_old_frozen(Group_c *g, const Memory *mem)
static bool delete_old_frozen(Group_c *_Nonnull g, const Memory *_Nonnull mem)
{
if (g->numfrozen <= g->maxfrozen) {
return false;
@@ -1055,14 +1009,11 @@ static bool delete_old_frozen(Group_c *g, const Memory *mem)
return true;
}
non_null()
static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk);
static bool try_send_rejoin(Group_Chats *_Nonnull g_c, Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk);
non_null(1) nullable(4)
static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index, void *userdata)
static bool freeze_peer(Group_Chats *_Nonnull g_c, uint32_t groupnumber, int peer_index, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return false;
}
@@ -1098,9 +1049,8 @@ static bool freeze_peer(Group_Chats *g_c, uint32_t groupnumber, int peer_index,
*
* @retval true on success.
*/
non_null(1, 4) nullable(6)
static bool setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *nick, uint16_t nick_len,
void *userdata, bool do_gc_callback)
static bool setnick(Group_Chats *_Nonnull g_c, uint32_t groupnumber, int peer_index, const uint8_t *_Nonnull nick, uint16_t nick_len,
void *_Nullable userdata, bool do_gc_callback)
{
if (nick_len > MAX_NAME_LENGTH) {
return false;
@@ -1136,9 +1086,8 @@ static bool setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, cons
*
* @retval true on success.
*/
non_null(1, 4) nullable(6)
static bool settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, const uint8_t *title, uint8_t title_len,
void *userdata)
static bool settitle(Group_Chats *_Nonnull g_c, uint32_t groupnumber, int peer_index, const uint8_t *_Nonnull title, uint8_t title_len,
void *_Nullable userdata)
{
if (title_len > MAX_NAME_LENGTH || title_len == 0) {
return false;
@@ -1168,11 +1117,9 @@ static bool settitle(Group_Chats *g_c, uint32_t groupnumber, int peer_index, con
}
/** Check if the group has no online connection, and freeze all peers if so */
non_null(1) nullable(3)
static void check_disconnected(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
static void check_disconnected(Group_Chats *_Nonnull g_c, uint32_t groupnumber, void *_Nullable userdata)
{
const Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return;
}
@@ -1190,12 +1137,10 @@ static void check_disconnected(Group_Chats *g_c, uint32_t groupnumber, void *use
}
}
non_null(1) nullable(5)
static void set_conns_type_connections(Group_Chats *g_c, uint32_t groupnumber, int friendcon_id, uint8_t type,
void *userdata)
static void set_conns_type_connections(Group_Chats *_Nonnull g_c, uint32_t groupnumber, int friendcon_id, uint8_t type,
void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return;
}
@@ -1219,16 +1164,14 @@ static void set_conns_type_connections(Group_Chats *g_c, uint32_t groupnumber, i
}
/** Set the type for all connections with friendcon_id */
non_null(1) nullable(4)
static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t type, void *userdata)
static void set_conns_status_groups(Group_Chats *_Nonnull g_c, int friendcon_id, uint8_t type, void *_Nullable userdata)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
set_conns_type_connections(g_c, i, friendcon_id, type, userdata);
}
}
non_null()
static void rejoin_frozen_friend(Group_Chats *g_c, int friendcon_id)
static void rejoin_frozen_friend(Group_Chats *_Nonnull g_c, int friendcon_id)
{
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
get_friendcon_public_keys(real_pk, nullptr, g_c->fr_c, friendcon_id);
@@ -1249,11 +1192,9 @@ static void rejoin_frozen_friend(Group_Chats *g_c, int friendcon_id)
}
}
non_null(1) nullable(4)
static int g_handle_any_status(void *object, int friendcon_id, bool status, void *userdata)
static int g_handle_any_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata)
{
Group_Chats *g_c = (Group_Chats *)object;
if (status) {
rejoin_frozen_friend(g_c, friendcon_id);
}
@@ -1261,11 +1202,9 @@ static int g_handle_any_status(void *object, int friendcon_id, bool status, void
return 0;
}
non_null(1) nullable(4)
static int g_handle_status(void *object, int friendcon_id, bool status, void *userdata)
static int g_handle_status(void *_Nonnull object, int friendcon_id, bool status, void *_Nullable userdata)
{
Group_Chats *g_c = (Group_Chats *)object;
if (status) { /* Went online */
set_conns_status_groups(g_c, friendcon_id, GROUPCHAT_CONNECTION_ONLINE, userdata);
} else { /* Went offline */
@@ -1276,11 +1215,8 @@ static int g_handle_status(void *object, int friendcon_id, bool status, void *us
return 0;
}
non_null(1, 3) nullable(5)
static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
non_null(1, 3) nullable(5)
static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata);
static int g_handle_packet(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
static int handle_lossy(void *_Nonnull object, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
/** @brief Add friend to group chat.
*
* @return connections index on success
@@ -1333,8 +1269,7 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g,
return ind;
}
non_null()
static bool send_peer_introduced(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
static bool send_peer_introduced(const Group_Chats *_Nonnull g_c, int friendcon_id, uint16_t group_num);
/** @brief Removes reason for keeping connection.
*
@@ -1397,8 +1332,7 @@ int add_groupchat(Group_Chats *g_c, const Random *rng, uint8_t type)
return groupnumber;
}
non_null()
static bool group_leave(const Group_Chats *g_c, uint32_t groupnumber, bool permanent);
static bool group_leave(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, bool permanent);
/** @brief Delete a groupchat from the chats array, informing the group first as
* appropriate.
@@ -1438,8 +1372,7 @@ bool del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanentl
return wipe_group_chat(g_c, groupnumber);
}
non_null()
static const Group_Peer *peer_in_list(const Group_c *g, uint32_t peernumber, bool frozen)
static const Group_Peer *peer_in_list(const Group_c *_Nonnull g, uint32_t peernumber, bool frozen)
{
const Group_Peer *list = frozen ? g->frozen : g->group;
const uint32_t num = frozen ? g->numfrozen : g->numpeers;
@@ -1658,9 +1591,7 @@ bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id
* @retval true on success
* @retval false on failure
*/
non_null()
static bool send_packet_group_peer(const Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
uint16_t group_num, const uint8_t *data, uint16_t length)
static bool send_packet_group_peer(const Friend_Connections *_Nonnull fr_c, int friendcon_id, uint8_t packet_id, uint16_t group_num, const uint8_t *_Nonnull data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
return false;
@@ -1681,9 +1612,7 @@ static bool send_packet_group_peer(const Friend_Connections *fr_c, int friendcon
* @retval true on success
* @retval false on failure
*/
non_null()
static bool send_lossy_group_peer(const Friend_Connections *fr_c, int friendcon_id, uint8_t packet_id,
uint16_t group_num, const uint8_t *data, uint16_t length)
static bool send_lossy_group_peer(const Friend_Connections *_Nonnull fr_c, int friendcon_id, uint8_t packet_id, uint16_t group_num, const uint8_t *_Nonnull data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
return false;
@@ -1759,12 +1688,9 @@ static bool try_send_rejoin(Group_Chats *g_c, Group_c *g, const uint8_t *real_pk
return true;
}
non_null()
static bool send_peer_query(const Group_Chats *g_c, int friendcon_id, uint16_t group_num);
static bool send_peer_query(const Group_Chats *_Nonnull g_c, int friendcon_id, uint16_t group_num);
non_null()
static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t friendnumber, const uint8_t *data,
uint16_t length);
static bool send_invite_response(Group_Chats *_Nonnull g_c, int groupnumber, uint32_t friendnumber, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Join a group (we need to have been invited first).
*
@@ -1972,15 +1898,12 @@ int callback_groupchat_delete(const Group_Chats *g_c, uint32_t groupnumber, grou
return 0;
}
non_null(1) nullable(4)
static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *data,
static int send_message_group(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint8_t message_id, const uint8_t *_Nullable data,
uint16_t len);
/** @brief send a ping message
* return true on success
*/
non_null()
static bool group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
static bool group_ping_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber)
{
return send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0;
}
@@ -1988,9 +1911,7 @@ static bool group_ping_send(const Group_Chats *g_c, uint32_t groupnumber)
/** @brief send a new_peer message
* return true on success
*/
non_null()
static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *real_pk,
const uint8_t *temp_pk)
static bool group_new_peer_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint16_t peer_num, const uint8_t *_Nonnull real_pk, const uint8_t *_Nonnull temp_pk)
{
uint8_t packet[GROUP_MESSAGE_NEW_PEER_LENGTH];
@@ -2005,8 +1926,7 @@ static bool group_new_peer_send(const Group_Chats *g_c, uint32_t groupnumber, ui
/** @brief send a kill_peer message
* return true on success
*/
non_null()
static bool group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num)
static bool group_kill_peer_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint16_t peer_num)
{
uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
@@ -2019,8 +1939,7 @@ static bool group_kill_peer_send(const Group_Chats *g_c, uint32_t groupnumber, u
/** @brief send a freeze_peer message
* return true on success
*/
non_null()
static bool group_freeze_peer_send(const Group_Chats *g_c, uint32_t groupnumber, uint16_t peer_num)
static bool group_freeze_peer_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint16_t peer_num)
{
uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
@@ -2033,8 +1952,7 @@ static bool group_freeze_peer_send(const Group_Chats *g_c, uint32_t groupnumber,
/** @brief send a name message
* return true on success
*/
non_null()
static bool group_name_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *nick, uint16_t nick_len)
static bool group_name_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull nick, uint16_t nick_len)
{
if (nick_len > MAX_NAME_LENGTH) {
return false;
@@ -2141,8 +2059,7 @@ int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title
return g->title_len;
}
non_null()
static bool get_peer_number(const Group_c *g, const uint8_t *real_pk, uint16_t *peer_number)
static bool get_peer_number(const Group_c *_Nonnull g, const uint8_t *_Nonnull real_pk, uint16_t *_Nonnull peer_number)
{
const int peer_index = peer_in_group(g, real_pk);
@@ -2161,12 +2078,10 @@ static bool get_peer_number(const Group_c *g, const uint8_t *real_pk, uint16_t *
return false;
}
non_null(1, 3) nullable(5)
static void handle_friend_invite_packet(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length,
void *user_data)
static void handle_friend_invite_packet(Messenger *_Nonnull m, uint32_t friend_number, const uint8_t *_Nonnull cookie, uint16_t length,
void *_Nullable user_data)
{
Group_Chats *g_c = m->conferences_object;
if (length <= 1) {
return;
}
@@ -2289,8 +2204,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friend_number, co
* return index on success
* return -1 on failure.
*/
non_null()
static int friend_in_connections(const Group_c *g, int friendcon_id)
static int friend_in_connections(const Group_c *_Nonnull g, int friendcon_id)
{
for (unsigned int i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
if (g->connections[i].type == GROUPCHAT_CONNECTION_NONE) {
@@ -2306,8 +2220,7 @@ static int friend_in_connections(const Group_c *g, int friendcon_id)
}
/** return number of connections. */
non_null()
static unsigned int count_connected(const Group_c *g)
static unsigned int count_connected(const Group_c *_Nonnull g)
{
unsigned int count = 0;
@@ -2333,11 +2246,9 @@ static bool send_packet_online(const Friend_Connections *fr_c, int friendcon_id,
sizeof(packet), false) != -1;
}
non_null()
static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber);
static bool ping_groupchat(const Group_Chats *_Nonnull g_c, uint32_t groupnumber);
non_null()
static int handle_packet_online(const Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length)
static int handle_packet_online(const Group_Chats *_Nonnull g_c, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length)
{
if (length != ONLINE_PACKET_DATA_SIZE) {
return -1;
@@ -2396,9 +2307,8 @@ static int handle_packet_online(const Group_Chats *g_c, int friendcon_id, const
return 0;
}
non_null(1, 3) nullable(5)
static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_t *data, uint16_t length,
void *userdata)
static int handle_packet_rejoin(Group_Chats *_Nonnull g_c, int friendcon_id, const uint8_t *_Nonnull data, uint16_t length,
void *_Nullable userdata)
{
if (length < 1 + GROUP_ID_LENGTH) {
return -1;
@@ -2461,8 +2371,7 @@ static bool send_peer_query(const Group_Chats *g_c, int friendcon_id, uint16_t g
* @return number of peers sent on success.
* @retval 0 on failure.
*/
non_null()
static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int friendcon_id, uint16_t group_num)
static unsigned int send_peers(const Group_Chats *_Nonnull g_c, const Group_c *_Nonnull g, int friendcon_id, uint16_t group_num)
{
uint8_t response_packet[MAX_CRYPTO_DATA_SIZE - (1 + sizeof(uint16_t))];
response_packet[0] = PEER_RESPONSE_ID;
@@ -2513,9 +2422,8 @@ static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int fri
return sent;
}
non_null(1, 3) nullable(5)
static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
void *userdata)
static int handle_send_peers(Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull data, uint16_t length,
void *_Nullable userdata)
{
if (length == 0) {
return -1;
@@ -2571,9 +2479,8 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8
return 0;
}
non_null(1, 3) nullable(6)
static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
uint32_t connection_index, void *userdata)
static void handle_direct_packet(Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull data, uint16_t length,
uint32_t connection_index, void *_Nullable userdata)
{
if (length == 0) {
return;
@@ -2621,9 +2528,7 @@ static void handle_direct_packet(Group_Chats *g_c, uint32_t groupnumber, const u
*
* @return number of messages sent.
*/
non_null()
static unsigned int send_message_all_connections(const Group_Chats *g_c, const Group_c *g, const uint8_t *data,
uint16_t length, int receiver)
static unsigned int send_message_all_connections(const Group_Chats *_Nonnull g_c, const Group_c *_Nonnull g, const uint8_t *_Nonnull data, uint16_t length, int receiver)
{
uint16_t sent = 0;
@@ -2651,9 +2556,7 @@ static unsigned int send_message_all_connections(const Group_Chats *g_c, const G
*
* @return number of messages sent.
*/
non_null()
static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Group_c *g, const uint8_t *data,
uint16_t length, int receiver)
static unsigned int send_lossy_all_connections(const Group_Chats *_Nonnull g_c, const Group_c *_Nonnull g, const uint8_t *_Nonnull data, uint16_t length, int receiver)
{
unsigned int sent = 0;
unsigned int num_connected_closest = 0;
@@ -2829,8 +2732,7 @@ int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const
return 0;
}
non_null()
static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_t message_id, Group_Peer *peer)
static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_t message_id, Group_Peer *_Nonnull peer)
{
const bool ignore_older = message_id == GROUP_MESSAGE_NAME_ID || message_id == GROUP_MESSAGE_TITLE_ID;
@@ -2858,8 +2760,7 @@ static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_
* @retval true if message should be processed.
* @retval false otherwise.
*/
non_null()
static bool check_message_info(uint32_t message_number, uint8_t message_id, Group_Peer *peer)
static bool check_message_info(uint32_t message_number, uint8_t message_id, Group_Peer *_Nonnull peer)
{
Message_Info *const i = find_message_slot_or_reject(message_number, message_id, peer);
@@ -2883,9 +2784,8 @@ static bool check_message_info(uint32_t message_number, uint8_t message_id, Grou
return true;
}
non_null(1, 3) nullable(6)
static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length,
uint32_t connection_index, void *userdata)
static void handle_message_packet_group(Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull data, uint16_t length,
uint32_t connection_index, void *_Nullable userdata)
{
if (length < sizeof(uint16_t) + sizeof(uint32_t) + 1) {
return;
@@ -3115,8 +3015,7 @@ static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data,
*
* TODO(irungentoo): test this
*/
non_null()
static int lossy_packet_not_received(const Group_c *g, int peer_index, uint16_t message_number)
static int lossy_packet_not_received(const Group_c *_Nonnull g, int peer_index, uint16_t message_number)
{
if (peer_index == -1) {
return -1;
@@ -3337,11 +3236,9 @@ static bool ping_groupchat(const Group_Chats *g_c, uint32_t groupnumber)
/** Seconds of inactivity after which to freeze a peer */
#define FREEZE_TIMEOUT (GROUP_PING_INTERVAL * 3)
non_null(1) nullable(3)
static bool groupchat_freeze_timedout(Group_Chats *g_c, uint32_t groupnumber, void *userdata)
static bool groupchat_freeze_timedout(Group_Chats *_Nonnull g_c, uint32_t groupnumber, void *_Nullable userdata)
{
Group_c *g = get_group_c(g_c, groupnumber);
if (g == nullptr) {
return false;
}
@@ -3364,8 +3261,7 @@ static bool groupchat_freeze_timedout(Group_Chats *g_c, uint32_t groupnumber, vo
}
/** Push non-empty slots to start. */
non_null()
static void squash_connections(Group_c *g)
static void squash_connections(Group_c *_Nonnull g)
{
uint16_t num_connected = 0;
@@ -3383,8 +3279,7 @@ static void squash_connections(Group_c *g)
#define MIN_EMPTY_CONNECTIONS (1 + MAX_GROUP_CONNECTIONS / 10)
non_null()
static uint16_t empty_connection_count(const Group_c *g)
static uint16_t empty_connection_count(const Group_c *_Nonnull g)
{
uint16_t to_clear = MIN_EMPTY_CONNECTIONS;
@@ -3408,8 +3303,7 @@ static uint16_t empty_connection_count(const Group_c *g)
* This invalidates connections array indices (which is
* why we do this periodically rather than on adding a connection).
*/
non_null()
static void clean_connections(Group_Chats *g_c, Group_c *g)
static void clean_connections(Group_Chats *_Nonnull g_c, Group_c *_Nonnull g)
{
for (uint16_t to_clear = empty_connection_count(g); to_clear > 0; --to_clear) {
// Remove a connection. Prefer non-closest connections, and given
@@ -3460,14 +3354,12 @@ void send_name_all_groups(const Group_Chats *g_c)
#define SAVED_PEER_SIZE_CONSTANT (2 * CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint16_t) + sizeof(uint64_t) + 1)
non_null()
static uint32_t saved_peer_size(const Group_Peer *peer)
static uint32_t saved_peer_size(const Group_Peer *_Nonnull peer)
{
return SAVED_PEER_SIZE_CONSTANT + peer->nick_len;
}
non_null()
static uint8_t *save_peer(const Group_Peer *peer, uint8_t *data)
static uint8_t *save_peer(const Group_Peer *_Nonnull peer, uint8_t *_Nonnull data)
{
memcpy(data, peer->real_pk, CRYPTO_PUBLIC_KEY_SIZE);
data += CRYPTO_PUBLIC_KEY_SIZE;
@@ -3494,8 +3386,7 @@ static uint8_t *save_peer(const Group_Peer *peer, uint8_t *data)
#define SAVED_CONF_SIZE_CONSTANT (1 + GROUP_ID_LENGTH + sizeof(uint32_t) \
+ sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + 1)
non_null()
static uint32_t saved_conf_size(const Group_c *g)
static uint32_t saved_conf_size(const Group_c *_Nonnull g)
{
uint32_t len = SAVED_CONF_SIZE_CONSTANT + g->title_len;
@@ -3519,8 +3410,7 @@ static uint32_t saved_conf_size(const Group_c *g)
#define SAVE_OFFSET_MESSAGE_NUMBER (1 << 16)
#define SAVE_OFFSET_LOSSY_MESSAGE_NUMBER (1 << 13)
non_null()
static uint8_t *save_conf(const Group_c *g, uint8_t *data)
static uint8_t *save_conf(const Group_c *_Nonnull g, uint8_t *_Nonnull data)
{
*data = g->type;
++data;
@@ -3564,8 +3454,7 @@ static uint8_t *save_conf(const Group_c *g, uint8_t *data)
return data;
}
non_null()
static uint32_t conferences_section_size(const Group_Chats *g_c)
static uint32_t conferences_section_size(const Group_Chats *_Nonnull g_c)
{
uint32_t len = 0;
@@ -3613,8 +3502,7 @@ uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data)
* @param length Length of data
* @return 0 on error, number of consumed bytes otherwise
*/
non_null()
static uint32_t load_group(Group_c *g, const Group_Chats *g_c, const uint8_t *data, uint32_t length)
static uint32_t load_group(Group_c *_Nonnull g, const Group_Chats *_Nonnull g_c, const uint8_t *_Nonnull data, uint32_t length)
{
const uint8_t *init_data = data;
@@ -3721,8 +3609,7 @@ static uint32_t load_group(Group_c *g, const Group_Chats *g_c, const uint8_t *da
return (uint32_t)(data - init_data);
}
non_null()
static State_Load_Status load_conferences_helper(Group_Chats *g_c, const uint8_t *data, uint32_t length)
static State_Load_Status load_conferences_helper(Group_Chats *_Nonnull g_c, const uint8_t *_Nonnull data, uint32_t length)
{
const uint8_t *init_data = data;
@@ -3772,8 +3659,7 @@ static State_Load_Status load_conferences_helper(Group_Chats *g_c, const uint8_t
return STATE_LOAD_STATUS_CONTINUE;
}
non_null()
static State_Load_Status load_conferences(Group_Chats *g_c, const uint8_t *data, uint32_t length)
static State_Load_Status load_conferences(Group_Chats *_Nonnull g_c, const uint8_t *_Nonnull data, uint32_t length)
{
const State_Load_Status res = load_conferences_helper(g_c, data, length);

View File

@@ -24,79 +24,72 @@ typedef enum Groupchat_Type {
GROUPCHAT_TYPE_AV,
} Groupchat_Type;
typedef void peer_on_join_cb(void *object, uint32_t conference_number, uint32_t peer_number);
typedef void peer_on_leave_cb(void *object, uint32_t conference_number, void *peer_object);
typedef void group_on_delete_cb(void *object, uint32_t conference_number);
typedef void peer_on_join_cb(void *_Nullable object, uint32_t conference_number, uint32_t peer_number);
typedef void peer_on_leave_cb(void *_Nullable object, uint32_t conference_number, void *_Nullable peer_object);
typedef void group_on_delete_cb(void *_Nullable object, uint32_t conference_number);
/** @brief Callback for group invites.
*
* data of length is what needs to be passed to `join_groupchat()`.
*/
typedef void g_conference_invite_cb(Messenger *m, uint32_t friend_number, int type, const uint8_t *cookie,
size_t length, void *user_data);
typedef void g_conference_invite_cb(Messenger *_Nonnull m, uint32_t friend_number, int type, const uint8_t *_Nonnull cookie,
size_t length, void *_Nullable user_data);
/** Callback for group connection. */
typedef void g_conference_connected_cb(Messenger *m, uint32_t conference_number, void *user_data);
typedef void g_conference_connected_cb(Messenger *_Nonnull m, uint32_t conference_number, void *_Nullable user_data);
/** Callback for group messages. */
typedef void g_conference_message_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, int type,
const uint8_t *message, size_t length, void *user_data);
typedef void g_conference_message_cb(Messenger *_Nonnull m, uint32_t conference_number, uint32_t peer_number, int type,
const uint8_t *_Nonnull message, size_t length, void *_Nullable user_data);
/** Callback for peer nickname changes. */
typedef void peer_name_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *name,
size_t length, void *user_data);
typedef void peer_name_cb(Messenger *_Nonnull m, uint32_t conference_number, uint32_t peer_number, const uint8_t *_Nonnull name,
size_t length, void *_Nullable user_data);
/** Set callback function for peer list changes. */
typedef void peer_list_changed_cb(Messenger *m, uint32_t conference_number, void *user_data);
typedef void peer_list_changed_cb(Messenger *_Nonnull m, uint32_t conference_number, void *_Nullable user_data);
/** @brief Callback for title changes.
*
* If peer_number == -1, then author is unknown (e.g. initial joining the group).
*/
typedef void title_cb(Messenger *m, uint32_t conference_number, uint32_t peer_number, const uint8_t *title,
size_t length, void *user_data);
typedef void title_cb(Messenger *_Nonnull m, uint32_t conference_number, uint32_t peer_number, const uint8_t *_Nonnull title,
size_t length, void *_Nullable user_data);
/** @brief Callback for lossy packets.
*
* NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed.
*/
typedef int lossy_packet_cb(void *object, uint32_t conference_number, uint32_t peer_number, void *peer_object,
const uint8_t *packet, uint16_t length);
typedef int lossy_packet_cb(void *_Nullable object, uint32_t conference_number, uint32_t peer_number, void *_Nullable peer_object,
const uint8_t *_Nonnull packet, uint16_t length);
typedef struct Group_Chats Group_Chats;
non_null()
const Mono_Time *g_mono_time(const Group_Chats *g_c);
const Mono_Time *_Nonnull g_mono_time(const Group_Chats *_Nonnull g_c);
/** Set the callback for group invites. */
non_null()
void g_callback_group_invite(Group_Chats *g_c, g_conference_invite_cb *function);
void g_callback_group_invite(Group_Chats *_Nonnull g_c, g_conference_invite_cb *_Nonnull function);
/** Set the callback for group connection. */
non_null()
void g_callback_group_connected(Group_Chats *g_c, g_conference_connected_cb *function);
void g_callback_group_connected(Group_Chats *_Nonnull g_c, g_conference_connected_cb *_Nonnull function);
/** Set the callback for group messages. */
non_null()
void g_callback_group_message(Group_Chats *g_c, g_conference_message_cb *function);
void g_callback_group_message(Group_Chats *_Nonnull g_c, g_conference_message_cb *_Nonnull function);
/** Set callback function for title changes. */
non_null()
void g_callback_group_title(Group_Chats *g_c, title_cb *function);
void g_callback_group_title(Group_Chats *_Nonnull g_c, title_cb *_Nonnull function);
/** @brief Set callback function for peer nickname changes.
*
* It gets called every time a peer changes their nickname.
*/
non_null()
void g_callback_peer_name(Group_Chats *g_c, peer_name_cb *function);
void g_callback_peer_name(Group_Chats *_Nonnull g_c, peer_name_cb *_Nonnull function);
/** @brief Set callback function for peer list changes.
*
* It gets called every time the name list changes(new peer, deleted peer)
*/
non_null()
void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *function);
void g_callback_peer_list_changed(Group_Chats *_Nonnull g_c, peer_list_changed_cb *_Nonnull function);
/** @brief Creates a new groupchat and puts it in the chats array.
*
@@ -106,8 +99,7 @@ void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *functi
* @return group number on success.
* @retval -1 on failure.
*/
non_null()
int add_groupchat(Group_Chats *g_c, const Random *rng, uint8_t type);
int add_groupchat(Group_Chats *_Nonnull g_c, const Random *_Nonnull rng, uint8_t type);
/** @brief Delete a groupchat from the chats array, informing the group first as
* appropriate.
@@ -115,8 +107,7 @@ int add_groupchat(Group_Chats *g_c, const Random *rng, uint8_t type);
* @retval true on success.
* @retval false if groupnumber is invalid.
*/
non_null()
bool del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently);
bool del_groupchat(Group_Chats *_Nonnull g_c, uint32_t groupnumber, bool leave_permanently);
/**
* @brief Copy the public key of (frozen, if frozen is true) peernumber who is in
@@ -128,8 +119,7 @@ bool del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanentl
* @retval -1 if groupnumber is invalid.
* @retval -2 if peernumber is invalid.
*/
non_null()
int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *pk, bool frozen);
int group_peer_pubkey(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *_Nonnull pk, bool frozen);
/**
* @brief Return the size of (frozen, if frozen is true) peernumber's name.
@@ -137,8 +127,7 @@ int group_peer_pubkey(const Group_Chats *g_c, uint32_t groupnumber, uint32_t pee
* @retval -1 if groupnumber is invalid.
* @retval -2 if peernumber is invalid.
*/
non_null()
int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, bool frozen);
int group_peername_size(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber, bool frozen);
/**
* @brief Copy the name of (frozen, if frozen is true) peernumber who is in
@@ -150,9 +139,7 @@ int group_peername_size(const Group_Chats *g_c, uint32_t groupnumber, uint32_t p
* @retval -1 if groupnumber is invalid.
* @retval -2 if peernumber is invalid.
*/
non_null()
int group_peername(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *name,
bool frozen);
int group_peername(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber, uint8_t *_Nonnull name, bool frozen);
/**
* @brief Copy last active timestamp of frozen peernumber who is in groupnumber to
@@ -162,17 +149,14 @@ int group_peername(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernu
* @retval -1 if groupnumber is invalid.
* @retval -2 if peernumber is invalid.
*/
non_null()
int group_frozen_last_active(
const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, uint64_t *last_active);
int group_frozen_last_active(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber, uint64_t *_Nonnull last_active);
/** @brief Set maximum number of frozen peers.
*
* @retval 0 on success.
* @retval -1 if groupnumber is invalid.
*/
non_null()
int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t maxfrozen);
int group_set_max_frozen(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t maxfrozen);
/** @brief invite friendnumber to groupnumber.
*
@@ -181,8 +165,7 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
* @retval -2 if invite packet failed to send.
* @retval -3 if we are not connected to the group chat.
*/
non_null()
int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupnumber);
int invite_friend(const Group_Chats *_Nonnull g_c, uint32_t friendnumber, uint32_t groupnumber);
/** @brief Join a group (we need to have been invited first).
*
@@ -197,23 +180,19 @@ int invite_friend(const Group_Chats *g_c, uint32_t friendnumber, uint32_t groupn
* @retval -5 if group instance failed to initialize.
* @retval -6 if join packet fails to send.
*/
non_null()
int join_groupchat(
Group_Chats *g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length);
int join_groupchat(Group_Chats *_Nonnull g_c, uint32_t friendnumber, uint8_t expected_type, const uint8_t *_Nonnull data, uint16_t length);
/** @brief send a group message
* @retval 0 on success
* @see send_message_group for error codes.
*/
non_null()
int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *message, uint16_t length);
int group_message_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull message, uint16_t length);
/** @brief send a group action
* @retval 0 on success
* @see send_message_group for error codes.
*/
non_null()
int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length);
int group_action_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull action, uint16_t length);
/** @brief set the group's title, limited to MAX_NAME_LENGTH.
* @retval 0 on success
@@ -221,15 +200,13 @@ int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_
* @retval -2 if title is too long or empty.
* @retval -3 if packet fails to send.
*/
non_null()
int group_title_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *title, uint8_t title_len);
int group_title_send(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull title, uint8_t title_len);
/** @brief return the group's title size.
* @retval -1 of groupnumber is invalid.
* @retval -2 if title is too long or empty.
*/
non_null()
int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber);
int group_title_get_size(const Group_Chats *_Nonnull g_c, uint32_t groupnumber);
/** @brief Get group title from groupnumber and put it in title.
*
@@ -239,15 +216,13 @@ int group_title_get_size(const Group_Chats *g_c, uint32_t groupnumber);
* @retval -1 if groupnumber is invalid.
* @retval -2 if title is too long or empty.
*/
non_null()
int group_title_get(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *title);
int group_title_get(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint8_t *_Nonnull title);
/**
* @return the number of (frozen, if frozen is true) peers in the group chat on success.
* @retval -1 if groupnumber is invalid.
*/
non_null()
int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen);
int group_number_peers(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, bool frozen);
/**
* @retval 1 if the peernumber corresponds to ours.
@@ -256,20 +231,17 @@ int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen
* @retval -2 if peernumber is invalid.
* @retval -3 if we are not connected to the group chat.
*/
non_null()
int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber);
int group_peernumber_is_ours(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber);
/** Set handlers for custom lossy packets. */
non_null()
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function);
void group_lossy_packet_registerhandler(Group_Chats *_Nonnull g_c, uint8_t byte, lossy_packet_cb *_Nonnull function);
/** @brief High level function to send custom lossy packets.
*
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *data, uint16_t length);
int send_group_lossy_packet(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, const uint8_t *_Nonnull data, uint16_t length);
/**
* @brief Return the number of chats in the instance m.
@@ -277,8 +249,7 @@ int send_group_lossy_packet(const Group_Chats *g_c, uint32_t groupnumber, const
* You should use this to determine how much memory to allocate
* for copy_chatlist.
*/
non_null()
uint32_t count_chatlist(const Group_Chats *g_c);
uint32_t count_chatlist(const Group_Chats *_Nonnull g_c);
/** @brief Copy a list of valid chat IDs into the array out_list.
*
@@ -287,94 +258,76 @@ uint32_t count_chatlist(const Group_Chats *g_c);
* If the array was too small, the contents
* of out_list will be truncated to list_size.
*/
non_null()
uint32_t copy_chatlist(const Group_Chats *g_c, uint32_t *out_list, uint32_t list_size);
uint32_t copy_chatlist(const Group_Chats *_Nonnull g_c, uint32_t *_Nonnull out_list, uint32_t list_size);
/** @brief return the type of groupchat (GROUPCHAT_TYPE_) that groupnumber is.
*
* @retval -1 on failure.
* @return type on success.
*/
non_null()
int group_get_type(const Group_Chats *g_c, uint32_t groupnumber);
int group_get_type(const Group_Chats *_Nonnull g_c, uint32_t groupnumber);
/** @brief Copies the unique id of `group_chat[groupnumber]` into `id`.
*
* @retval false on failure.
* @retval true on success.
*/
non_null()
bool conference_get_id(const Group_Chats *g_c, uint32_t groupnumber, uint8_t *id);
bool conference_get_id(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint8_t *_Nonnull id);
non_null() int32_t conference_by_id(const Group_Chats *g_c, const uint8_t *id);
int32_t conference_by_id(const Group_Chats *_Nonnull g_c, const uint8_t *_Nonnull id);
/** Send current name (set in messenger) to all online groups. */
non_null()
void send_name_all_groups(const Group_Chats *g_c);
void send_name_all_groups(const Group_Chats *_Nonnull g_c);
/** @brief Set the object that is tied to the group chat.
*
* @retval 0 on success.
* @retval -1 on failure
*/
non_null(1) nullable(3)
int group_set_object(const Group_Chats *g_c, uint32_t groupnumber, void *object);
int group_set_object(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, void *_Nullable object);
/** @brief Set the object that is tied to the group peer.
*
* @retval 0 on success.
* @retval -1 on failure
*/
non_null(1) nullable(4)
int group_peer_set_object(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber, void *object);
int group_peer_set_object(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber, void *_Nullable object);
/** @brief Return the object tied to the group chat previously set by group_set_object.
*
* @retval NULL on failure.
* @return object on success.
*/
non_null()
void *group_get_object(const Group_Chats *g_c, uint32_t groupnumber);
void *_Nullable group_get_object(const Group_Chats *_Nonnull g_c, uint32_t groupnumber);
/** @brief Return the object tied to the group chat peer previously set by group_peer_set_object.
*
* @retval NULL on failure.
* @return object on success.
*/
non_null()
void *group_peer_get_object(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber);
void *_Nullable group_peer_get_object(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, uint32_t peernumber);
/** @brief Set a function to be called when a new peer joins a group chat.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null(1) nullable(3)
int callback_groupchat_peer_new(const Group_Chats *g_c, uint32_t groupnumber, peer_on_join_cb *function);
int callback_groupchat_peer_new(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, peer_on_join_cb *_Nullable function);
/** @brief Set a function to be called when a peer leaves a group chat.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null(1) nullable(3)
int callback_groupchat_peer_delete(const Group_Chats *g_c, uint32_t groupnumber, peer_on_leave_cb *function);
int callback_groupchat_peer_delete(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, peer_on_leave_cb *_Nullable function);
/** @brief Set a function to be called when the group chat is deleted.
*
* @retval 0 on success.
* @retval -1 on failure.
*/
non_null(1) nullable(3)
int callback_groupchat_delete(const Group_Chats *g_c, uint32_t groupnumber, group_on_delete_cb *function);
int callback_groupchat_delete(const Group_Chats *_Nonnull g_c, uint32_t groupnumber, group_on_delete_cb *_Nullable function);
/** Return size of the conferences data (for saving). */
non_null()
uint32_t conferences_size(const Group_Chats *g_c);
uint32_t conferences_size(const Group_Chats *_Nonnull g_c);
/** Save the conferences in data (must be allocated memory of size at least `conferences_size()`). */
non_null()
uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data);
uint8_t *_Nonnull conferences_save(const Group_Chats *_Nonnull g_c, uint8_t *_Nonnull data);
/**
* Load a state section.
@@ -385,20 +338,13 @@ uint8_t *conferences_save(const Group_Chats *g_c, uint8_t *data);
* @param status Result of loading section is stored here if the section is handled.
* @return true iff section handled.
*/
non_null()
bool conferences_load_state_section(
Group_Chats *g_c, const uint8_t *data, uint32_t length, uint16_t type, State_Load_Status *status);
bool conferences_load_state_section(Group_Chats *_Nonnull g_c, const uint8_t *_Nonnull data, uint32_t length, uint16_t type, State_Load_Status *_Nonnull status);
/** Create new groupchat instance. */
non_null()
Group_Chats *new_groupchats(const Mono_Time *mono_time, const Memory *mem, Messenger *m);
Group_Chats *_Nullable new_groupchats(const Mono_Time *_Nonnull mono_time, const Memory *_Nonnull mem, Messenger *_Nonnull m);
/** main groupchats loop. */
non_null(1) nullable(2)
void do_groupchats(Group_Chats *g_c, void *userdata);
void do_groupchats(Group_Chats *_Nonnull g_c, void *_Nullable userdata);
/** Free everything related with group chats. */
nullable(1)
void kill_groupchats(Group_Chats *g_c);
void kill_groupchats(Group_Chats *_Nullable g_c);
#endif /* C_TOXCORE_TOXCORE_GROUP_H */

View File

@@ -19,8 +19,7 @@
/**
* Removes `announces` from `gc_announces_list`.
*/
non_null()
static void remove_announces(GC_Announces_List *gc_announces_list, GC_Announces *announces)
static void remove_announces(GC_Announces_List *_Nonnull gc_announces_list, GC_Announces *_Nonnull announces)
{
if (announces == nullptr || gc_announces_list == nullptr) {
return;
@@ -43,8 +42,7 @@ static void remove_announces(GC_Announces_List *gc_announces_list, GC_Announces
* Returns the announce designated by `chat_id`.
* Returns null if no announce is found.
*/
non_null()
static GC_Announces *get_announces_by_chat_id(const GC_Announces_List *gc_announces_list, const uint8_t *chat_id)
static GC_Announces *_Nullable get_announces_by_chat_id(const GC_Announces_List *_Nonnull gc_announces_list, const uint8_t *_Nonnull chat_id)
{
GC_Announces *announces = gc_announces_list->root_announces;
@@ -167,8 +165,7 @@ int gca_pack_announce(const Logger *log, uint8_t *data, uint16_t length, const G
* Returns the size of the unpacked data on success.
* Returns -1 on failure.
*/
non_null()
static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t length, GC_Announce *announce)
static int gca_unpack_announce(const Logger *_Nonnull log, const uint8_t *_Nonnull data, uint16_t length, GC_Announce *_Nonnull announce)
{
if (length < ENC_PUBLIC_KEY_SIZE + 2) {
LOGGER_ERROR(log, "Invalid announce length: %u", length);
@@ -341,11 +338,7 @@ int gca_unpack_announces_list(const Logger *log, const uint8_t *data, uint16_t l
return announces_count;
}
non_null()
static GC_Announces *gca_new_announces(
const Memory *mem,
GC_Announces_List *gc_announces_list,
const GC_Public_Announce *public_announce)
static GC_Announces *_Nullable gca_new_announces(const Memory *_Nonnull mem, GC_Announces_List *_Nonnull gc_announces_list, const GC_Public_Announce *_Nonnull public_announce)
{
GC_Announces *announces = (GC_Announces *)mem_alloc(mem, sizeof(GC_Announces));

View File

@@ -74,15 +74,15 @@ struct GC_Announces {
GC_Peer_Announce peer_announces[GCA_MAX_SAVED_ANNOUNCES_PER_GC];
GC_Announces *next_announce;
GC_Announces *prev_announce;
GC_Announces *_Nullable next_announce;
GC_Announces *_Nullable prev_announce;
};
/* A list of all announces. */
struct GC_Announces_List {
const Memory *mem;
const Memory *_Nonnull mem;
GC_Announces *root_announces;
GC_Announces *_Nullable root_announces;
uint64_t last_timeout_check;
};
@@ -90,13 +90,10 @@ struct GC_Announces_List {
*
* The caller is responsible for freeing the memory with `kill_gca`.
*/
non_null()
GC_Announces_List *new_gca_list(const Memory *mem);
GC_Announces_List *_Nullable new_gca_list(const Memory *_Nonnull mem);
/** @brief Frees all dynamically allocated memory associated with `announces_list`. */
nullable(1)
void kill_gca(GC_Announces_List *announces_list);
void kill_gca(GC_Announces_List *_Nullable announces_list);
/** @brief Iterates through the announces list and removes announces that are considered stale.
*
* @param gc_announces_list The list of announces to iterate.
@@ -104,16 +101,14 @@ void kill_gca(GC_Announces_List *announces_list);
* This function should be called from the main loop, and will iterate the list a
* maxmimum of once per second.
*/
non_null()
void do_gca(const Mono_Time *mono_time, GC_Announces_List *gc_announces_list);
void do_gca(const Mono_Time *_Nonnull mono_time, GC_Announces_List *_Nonnull gc_announces_list);
/** @brief Frees all dynamically allocated memory associated with an announces list entry.
*
* @param gc_announces_list The announces list we want to search through.
* @param chat_id The chat ID that designates the entry we want to remove.
*/
non_null()
void cleanup_gca(GC_Announces_List *gc_announces_list, const uint8_t *chat_id);
void cleanup_gca(GC_Announces_List *_Nonnull gc_announces_list, const uint8_t *_Nonnull chat_id);
/** @brief Puts a set of announces from the announces list in supplied list.
*
@@ -126,9 +121,8 @@ void cleanup_gca(GC_Announces_List *gc_announces_list, const uint8_t *chat_id);
* @return the number of added nodes on success.
* @retval -1 on failure.
*/
non_null()
int gca_get_announces(const GC_Announces_List *gc_announces_list, GC_Announce *gc_announces, uint8_t max_nodes,
const uint8_t *chat_id, const uint8_t *except_public_key);
int gca_get_announces(const GC_Announces_List *_Nonnull gc_announces_list, GC_Announce *_Nonnull gc_announces, uint8_t max_nodes, const uint8_t *_Nonnull chat_id,
const uint8_t *_Nonnull except_public_key);
/** @brief Adds a public_announce to list of announces.
*
@@ -138,9 +132,8 @@ int gca_get_announces(const GC_Announces_List *gc_announces_list, GC_Announce *g
* @return the peer announce on success.
* @retval null on failure.
*/
non_null()
GC_Peer_Announce *gca_add_announce(const Memory *mem, const Mono_Time *mono_time, GC_Announces_List *gc_announces_list,
const GC_Public_Announce *public_announce);
GC_Peer_Announce *_Nullable gca_add_announce(const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, GC_Announces_List *_Nonnull gc_announces_list,
const GC_Public_Announce *_Nonnull public_announce);
/** @brief Packs an announce into a data buffer.
*
@@ -151,8 +144,7 @@ GC_Peer_Announce *gca_add_announce(const Memory *mem, const Mono_Time *mono_time
* @return the size of the packed data on success.
* @retval -1 on failure.
*/
non_null()
int gca_pack_announce(const Logger *log, uint8_t *data, uint16_t length, const GC_Announce *announce);
int gca_pack_announce(const Logger *_Nonnull log, uint8_t *_Nonnull data, uint16_t length, const GC_Announce *_Nonnull announce);
/** @brief Returns the number of bytes needed for a buff in which to pack `count` announces. */
uint16_t gca_pack_announces_list_size(uint16_t count);
@@ -169,10 +161,8 @@ uint16_t gca_pack_announces_list_size(uint16_t count);
* @return the number of packed announces on success.
* @retval -1 on failure.
*/
non_null(1, 2, 4) nullable(6)
int gca_pack_announces_list(const Logger *log, uint8_t *data, uint16_t length, const GC_Announce *announces,
uint8_t announces_count, size_t *processed);
int gca_pack_announces_list(const Logger *_Nonnull log, uint8_t *_Nonnull data, uint16_t length, const GC_Announce *_Nonnull announces,
uint8_t announces_count, size_t *_Nullable processed);
/** @brief Unpacks packed announces from a data buffer into a supplied list.
*
* @param data The data buffer to unpack from.
@@ -183,9 +173,7 @@ int gca_pack_announces_list(const Logger *log, uint8_t *data, uint16_t length, c
* @return the number of unpacked announces on success.
* @retval -1 on failure.
*/
non_null()
int gca_unpack_announces_list(const Logger *log, const uint8_t *data, uint16_t length, GC_Announce *announces,
uint8_t max_count);
int gca_unpack_announces_list(const Logger *_Nonnull log, const uint8_t *_Nonnull data, uint16_t length, GC_Announce *_Nonnull announces, uint8_t max_count);
/** @brief Packs a public announce into a data buffer.
*
@@ -196,9 +184,7 @@ int gca_unpack_announces_list(const Logger *log, const uint8_t *data, uint16_t l
* @return the size of the packed data on success.
* @retval -1 on failure.
*/
non_null()
int gca_pack_public_announce(const Logger *log, uint8_t *data, uint16_t length,
const GC_Public_Announce *public_announce);
int gca_pack_public_announce(const Logger *_Nonnull log, uint8_t *_Nonnull data, uint16_t length, const GC_Public_Announce *_Nonnull public_announce);
/** @brief Unpacks a public announce from a data buffer into a supplied public announce.
*
@@ -209,16 +195,13 @@ int gca_pack_public_announce(const Logger *log, uint8_t *data, uint16_t length,
* @return the size of the unpacked data on success.
* @retval -1 on failure.
*/
non_null()
int gca_unpack_public_announce(const Logger *log, const uint8_t *data, uint16_t length,
GC_Public_Announce *public_announce);
int gca_unpack_public_announce(const Logger *_Nonnull log, const uint8_t *_Nonnull data, uint16_t length, GC_Public_Announce *_Nonnull public_announce);
/** @brief Returns true if the announce is valid.
*
* An announce is considered valid if there is at least one TCP relay, or the ip_port is set.
*/
non_null()
bool gca_is_valid_announce(const GC_Announce *announce);
bool gca_is_valid_announce(const GC_Announce *_Nonnull announce);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -55,7 +55,7 @@ TEST_F(Announces, CanBeCreatedAndDeleted)
GC_Public_Announce ann{};
ann.chat_public_key[0] = 0x88;
ASSERT_NE(gca_add_announce(mem_, mono_time_, gca_, &ann), nullptr);
#ifndef _DEBUG
#ifndef __clang__
ASSERT_EQ(gca_add_announce(mem_, mono_time_, gca_, nullptr), nullptr);
ASSERT_EQ(gca_add_announce(mem_, mono_time_, nullptr, &ann), nullptr);
#endif
@@ -110,7 +110,7 @@ TEST_F(Announces, AnnouncesGetAndCleanup)
cleanup_gca(gca_, ann2.chat_public_key);
ASSERT_EQ(gca_get_announces(gca_, &announces, 1, ann2.chat_public_key, empty_pk), 0);
#ifndef _DEBUG
#ifndef __clang__
ASSERT_EQ(gca_get_announces(gca_, nullptr, 1, ann2.chat_public_key, empty_pk), -1);
#endif
}
@@ -172,7 +172,7 @@ TEST_F(AnnouncesPack, PublicAnnounceCanBePackedAndUnpacked)
TEST_F(AnnouncesPack, UnpackEmptyPublicAnnounce)
{
#ifndef _DEBUG
#ifndef __clang__
GC_Public_Announce ann{};
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
@@ -183,7 +183,7 @@ TEST_F(AnnouncesPack, UnpackEmptyPublicAnnounce)
TEST_F(AnnouncesPack, PackEmptyPublicAnnounce)
{
#ifndef _DEBUG
#ifndef __clang__
GC_Public_Announce ann{};
std::vector<uint8_t> packed(GCA_PUBLIC_ANNOUNCE_MAX_SIZE);
EXPECT_EQ(gca_pack_public_announce(logger_, packed.data(), packed.size(), nullptr), -1);
@@ -212,7 +212,7 @@ TEST_F(AnnouncesPack, PublicAnnouncePackNull)
TEST_F(AnnouncesPack, AnnouncesValidationCheck)
{
#ifndef _DEBUG
#ifndef __clang__
EXPECT_EQ(gca_is_valid_announce(nullptr), false);
#endif
@@ -233,7 +233,7 @@ TEST_F(AnnouncesPack, UnpackIncompleteAnnouncesList)
GC_Announce announce;
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), &announce, 1), -1);
#ifndef _DEBUG
#ifndef __clang__
EXPECT_EQ(gca_unpack_announces_list(logger_, data, sizeof(data), nullptr, 1), -1);
EXPECT_EQ(gca_unpack_announces_list(logger_, nullptr, 0, &announce, 1), -1);
#endif
@@ -264,7 +264,7 @@ TEST_F(AnnouncesPack, PackingEmptyAnnounceFails)
std::vector<uint8_t> packed(gca_pack_announces_list_size(1));
EXPECT_EQ(
gca_pack_announces_list(logger_, packed.data(), packed.size(), &announce, 1, nullptr), -1);
#ifndef _DEBUG
#ifndef __clang__
EXPECT_EQ(
gca_pack_announces_list(logger_, packed.data(), packed.size(), nullptr, 1, nullptr), -1);
EXPECT_EQ(gca_pack_announces_list(logger_, nullptr, 0, &announce, 1, nullptr), -1);
@@ -273,7 +273,7 @@ TEST_F(AnnouncesPack, PackingEmptyAnnounceFails)
TEST_F(AnnouncesPack, PackAnnounceNull)
{
#ifndef _DEBUG
#ifndef __clang__
std::vector<uint8_t> data(GCA_ANNOUNCE_MAX_SIZE);
GC_Announce announce;
ASSERT_EQ(gca_pack_announce(logger_, nullptr, 0, &announce), -1);

File diff suppressed because it is too large Load Diff

View File

@@ -115,12 +115,10 @@ typedef enum Group_Message_Ack_Type {
/** @brief Returns the GC_Connection object associated with `peer_number`.
* Returns null if peer_number does not designate a valid peer.
*/
non_null()
GC_Connection *get_gc_connection(const GC_Chat *chat, int peer_number);
GC_Connection *_Nullable get_gc_connection(const GC_Chat *_Nonnull chat, int peer_number);
/** @brief Returns the jenkins hash of a 32 byte public encryption key. */
non_null()
uint32_t gc_get_pk_jenkins_hash(const uint8_t *public_key);
uint32_t gc_get_pk_jenkins_hash(const uint8_t *_Nonnull public_key);
/** @brief Check if peer with the public encryption key is in peer list.
*
@@ -129,8 +127,7 @@ uint32_t gc_get_pk_jenkins_hash(const uint8_t *public_key);
*
* If `confirmed` is true the peer number will only be returned if the peer is confirmed.
*/
non_null()
int get_peer_number_of_enc_pk(const GC_Chat *chat, const uint8_t *public_enc_key, bool confirmed);
int get_peer_number_of_enc_pk(const GC_Chat *_Nonnull chat, const uint8_t *_Nonnull public_enc_key, bool confirmed);
/** @brief Encrypts `data` of size `length` using the peer's shared key and a new nonce.
*
@@ -142,12 +139,10 @@ int get_peer_number_of_enc_pk(const GC_Chat *chat, const uint8_t *public_enc_key
* Return -2 if malloc fails.
* Return -3 if encryption fails.
*/
non_null(1, 2, 3, 4, 5, 6) nullable(8)
int group_packet_wrap(
const Logger *log, const Memory *mem, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet,
uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id,
const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const uint8_t *_Nonnull self_pk, const uint8_t *_Nonnull shared_key, uint8_t *_Nonnull packet,
uint16_t packet_size, const uint8_t *_Nullable data, uint16_t length, uint64_t message_id,
uint8_t gp_packet_type, Net_Packet_Type net_packet_type);
/** @brief Returns the size of a wrapped/encrypted packet with a plain size of `length`.
*
* `packet_type` should be either NET_PACKET_GC_LOSSY or NET_PACKET_GC_LOSSLESS.
@@ -166,10 +161,8 @@ uint16_t gc_get_wrapped_packet_size(uint16_t length, Net_Packet_Type packet_type
* Returns -4 if the sender does not have permission to speak.
* Returns -5 if the packet fails to send.
*/
non_null(1, 2) nullable(5)
int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length, uint8_t type,
uint32_t *message_id);
int gc_send_message(const GC_Chat *_Nonnull chat, const uint8_t *_Nonnull message, uint16_t length, uint8_t type,
uint32_t *_Nullable message_id);
/** @brief Sends a private message to peer_id.
*
* `length` must not exceed MAX_GC_MESSAGE_SIZE and must not be equal to zero.
@@ -182,10 +175,8 @@ int gc_send_message(const GC_Chat *chat, const uint8_t *message, uint16_t length
* Returns -5 if the sender has the observer role.
* Returns -6 if the packet fails to send.
*/
non_null(1, 4) nullable(6)
int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t type, const uint8_t *message,
uint16_t length, uint32_t *message_id);
int gc_send_private_message(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id, uint8_t type, const uint8_t *_Nonnull message,
uint16_t length, uint32_t *_Nullable message_id);
/** @brief Sends a custom packet to the group. If lossless is true, the packet will be lossless.
*
* `length` must not exceed MAX_GC_MESSAGE_SIZE and must not be equal to zero.
@@ -195,8 +186,7 @@ int gc_send_private_message(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t typ
* Returns -2 if the message pointer is NULL or length is zero.
* Returns -3 if the packet did not successfully send to any peer.
*/
non_null()
int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *data, uint16_t length);
int gc_send_custom_packet(const GC_Chat *_Nonnull chat, bool lossless, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Sends a custom private packet to the peer designated by peer_id.
*
@@ -208,9 +198,7 @@ int gc_send_custom_packet(const GC_Chat *chat, bool lossless, const uint8_t *dat
* @retval -3 if the supplied peer_id does not designate a valid peer.
* @retval -4 if the packet fails to send.
*/
non_null()
int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id peer_id, const uint8_t *message,
uint16_t length);
int gc_send_custom_private_packet(const GC_Chat *_Nonnull chat, bool lossless, GC_Peer_Id peer_id, const uint8_t *_Nonnull message, uint16_t length);
/** @brief Sets ignore for peer_id.
*
@@ -218,8 +206,7 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, GC_Peer_Id
* Returns -1 if the peer_id is invalid.
* Returns -2 if the caller attempted to ignore himself.
*/
non_null()
int gc_set_ignore(const GC_Chat *chat, GC_Peer_Id peer_id, bool ignore);
int gc_set_ignore(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id, bool ignore);
/** @brief Sets the group topic and broadcasts it to the group.
*
@@ -231,36 +218,29 @@ int gc_set_ignore(const GC_Chat *chat, GC_Peer_Id peer_id, bool ignore);
* Returns -3 if the packet cannot be created or signing fails.
* Returns -4 if the packet fails
*/
non_null(1) nullable(2)
int gc_set_topic(GC_Chat *chat, const uint8_t *topic, uint16_t length);
int gc_set_topic(GC_Chat *_Nonnull chat, const uint8_t *_Nullable topic, uint16_t length);
/** @brief Copies the group topic to `topic`. If topic is null this function has no effect.
*
* Call `gc_get_topic_size` to determine the allocation size for the `topic` parameter.
*
* The data written to `topic` is equal to the data received by the last topic callback.
*/
non_null(1) nullable(2)
void gc_get_topic(const GC_Chat *chat, uint8_t *topic);
void gc_get_topic(const GC_Chat *_Nonnull chat, uint8_t *_Nullable topic);
/** @brief Returns the topic length.
*
* The return value is equal to the `length` agument received by the last topic callback.
*/
non_null()
uint16_t gc_get_topic_size(const GC_Chat *chat);
uint16_t gc_get_topic_size(const GC_Chat *_Nonnull chat);
/** @brief Copies group name to `group_name`. If `group_name` is null this function has no effect.
*
* Call `gc_get_group_name_size` to determine the allocation size for the `group_name`
* parameter.
*/
non_null()
void gc_get_group_name(const GC_Chat *chat, uint8_t *group_name);
void gc_get_group_name(const GC_Chat *_Nonnull chat, uint8_t *_Nonnull group_name);
/** @brief Returns the group name length. */
non_null()
uint16_t gc_get_group_name_size(const GC_Chat *chat);
uint16_t gc_get_group_name_size(const GC_Chat *_Nonnull chat);
/** @brief Copies the group password to password.
*
@@ -271,40 +251,34 @@ uint16_t gc_get_group_name_size(const GC_Chat *chat);
*
* The data received is equal to the data received by the last password callback.
*/
non_null()
void gc_get_password(const GC_Chat *chat, uint8_t *password);
void gc_get_password(const GC_Chat *_Nonnull chat, uint8_t *_Nonnull password);
/** @brief Returns the group password length. */
non_null()
uint16_t gc_get_password_size(const GC_Chat *chat);
uint16_t gc_get_password_size(const GC_Chat *_Nonnull chat);
/** @brief Returns the group privacy state.
*
* The value returned is equal to the data receieved by the last privacy_state callback.
*/
non_null()
Group_Privacy_State gc_get_privacy_state(const GC_Chat *chat);
Group_Privacy_State gc_get_privacy_state(const GC_Chat *_Nonnull chat);
/** @brief Returns the group topic lock state.
*
* The value returned is equal to the data received by the last last topic_lock callback.
*/
non_null()
Group_Topic_Lock gc_get_topic_lock_state(const GC_Chat *chat);
Group_Topic_Lock gc_get_topic_lock_state(const GC_Chat *_Nonnull chat);
/** @brief Returns the group voice state.
*
* The value returned is equal to the data received by the last voice_state callback.
*/
non_null()
Group_Voice_State gc_get_voice_state(const GC_Chat *chat);
Group_Voice_State gc_get_voice_state(const GC_Chat *_Nonnull chat);
/** @brief Returns the group peer limit.
*
* The value returned is equal to the data receieved by the last peer_limit callback.
*/
non_null()
uint16_t gc_get_max_peers(const GC_Chat *chat);
uint16_t gc_get_max_peers(const GC_Chat *_Nonnull chat);
/** @brief Sets your own nick to `nick`.
*
@@ -317,34 +291,28 @@ uint16_t gc_get_max_peers(const GC_Chat *chat);
* Returns -3 if the length is zero or nick is a NULL pointer.
* Returns -4 if the packet fails to send.
*/
non_null()
int gc_set_self_nick(const Messenger *m, int group_number, const uint8_t *nick, uint16_t length);
int gc_set_self_nick(const Messenger *_Nonnull m, int group_number, const uint8_t *_Nonnull nick, uint16_t length);
/** @brief Copies your own name to `nick`.
*
* If `nick` is null this function has no effect.
*/
non_null()
void gc_get_self_nick(const GC_Chat *chat, uint8_t *nick);
void gc_get_self_nick(const GC_Chat *_Nonnull chat, uint8_t *_Nonnull nick);
/** @brief Return your own nick length.
*
* If no nick was set before calling this function it will return 0.
*/
non_null()
uint16_t gc_get_self_nick_size(const GC_Chat *chat);
uint16_t gc_get_self_nick_size(const GC_Chat *_Nonnull chat);
/** @brief Returns your own group role. */
non_null()
Group_Role gc_get_self_role(const GC_Chat *chat);
Group_Role gc_get_self_role(const GC_Chat *_Nonnull chat);
/** @brief Return your own status. */
non_null()
uint8_t gc_get_self_status(const GC_Chat *chat);
uint8_t gc_get_self_status(const GC_Chat *_Nonnull chat);
/** @brief Returns your own peer id. */
non_null()
GC_Peer_Id gc_get_self_peer_id(const GC_Chat *chat);
GC_Peer_Id gc_get_self_peer_id(const GC_Chat *_Nonnull chat);
/** @brief Copies self public key to `public_key`.
*
@@ -354,9 +322,7 @@ GC_Peer_Id gc_get_self_peer_id(const GC_Chat *chat);
* exit the group. This key is the only way for other peers to reliably identify
* us across client restarts.
*/
non_null(1) nullable(2)
void gc_get_self_public_key(const GC_Chat *chat, uint8_t *public_key);
void gc_get_self_public_key(const GC_Chat *_Nonnull chat, uint8_t *_Nullable public_key);
/** @brief Copies nick designated by `peer_id` to `name`.
*
* Call `gc_get_peer_nick_size` to determine the allocation size for the `name` parameter.
@@ -366,17 +332,14 @@ void gc_get_self_public_key(const GC_Chat *chat, uint8_t *public_key);
* Returns true on success.
* Returns false if peer_id is invalid.
*/
non_null(1) nullable(3)
bool gc_get_peer_nick(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t *name);
bool gc_get_peer_nick(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id, uint8_t *_Nullable name);
/** @brief Returns the length of the nick for the peer designated by `peer_id`.
* Returns -1 if peer_id is invalid.
*
* The value returned is equal to the `length` argument received by the last
* nick_change callback.
*/
non_null()
int gc_get_peer_nick_size(const GC_Chat *chat, GC_Peer_Id peer_id);
int gc_get_peer_nick_size(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id);
/** @brief Copies peer_id's public key to `public_key`.
*
@@ -390,14 +353,11 @@ int gc_get_peer_nick_size(const GC_Chat *chat, GC_Peer_Id peer_id);
* Returns -1 if peer_id is invalid or doesn't correspond to a valid peer connection.
* Returns -2 if `public_key` is null.
*/
non_null(1) nullable(3)
int gc_get_peer_public_key_by_peer_id(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t *public_key);
int gc_get_peer_public_key_by_peer_id(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id, uint8_t *_Nullable public_key);
/** @brief Returns the length of the IP address for the peer designated by `peer_id`.
* Returns -1 if peer_id is invalid.
*/
non_null()
int gc_get_peer_ip_address_size(const GC_Chat *chat, GC_Peer_Id peer_id);
int gc_get_peer_ip_address_size(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id);
/** @brief Copies peer_id's IP address to `ip_addr`.
*
@@ -413,9 +373,7 @@ int gc_get_peer_ip_address_size(const GC_Chat *chat, GC_Peer_Id peer_id);
* Returns -1 if peer_id is invalid or doesn't correspond to a valid peer connection.
* Returns -2 if `ip_addr` is null.
*/
non_null(1) nullable(3)
int gc_get_peer_ip_address(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t *ip_addr);
int gc_get_peer_ip_address(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id, uint8_t *_Nullable ip_addr);
/** @brief Gets the connection status for peer associated with `peer_id`.
*
* If `peer_id` designates ourself, the return value indicates whether we're capable
@@ -427,8 +385,7 @@ int gc_get_peer_ip_address(const GC_Chat *chat, GC_Peer_Id peer_id, uint8_t *ip_
*
* Note: Return values must correspond to Tox_Connection enum in API.
*/
non_null()
unsigned int gc_get_peer_connection_status(const GC_Chat *chat, GC_Peer_Id peer_id);
unsigned int gc_get_peer_connection_status(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id);
/** @brief Sets the caller's status to `status`.
*
@@ -436,8 +393,7 @@ unsigned int gc_get_peer_connection_status(const GC_Chat *chat, GC_Peer_Id peer_
* Returns -1 if the group_number is invalid.
* Returns -2 if the packet failed to send.
*/
non_null()
int gc_set_self_status(const Messenger *m, int group_number, Group_Peer_Status status);
int gc_set_self_status(const Messenger *_Nonnull m, int group_number, Group_Peer_Status status);
/** @brief Returns the status of peer designated by `peer_id`.
* Returns UINT8_MAX on failure.
@@ -445,16 +401,14 @@ int gc_set_self_status(const Messenger *m, int group_number, Group_Peer_Status s
* The status returned is equal to the last status received through the status_change
* callback.
*/
non_null()
uint8_t gc_get_status(const GC_Chat *chat, GC_Peer_Id peer_id);
uint8_t gc_get_status(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id);
/** @brief Returns the group role of peer designated by `peer_id`.
* Returns UINT8_MAX on failure.
*
* The role returned is equal to the last role received through the moderation callback.
*/
non_null()
uint8_t gc_get_role(const GC_Chat *chat, GC_Peer_Id peer_id);
uint8_t gc_get_role(const GC_Chat *_Nonnull chat, GC_Peer_Id peer_id);
/** @brief Sets the role of peer_id. role must be one of: GR_MODERATOR, GR_USER, GR_OBSERVER
*
@@ -466,8 +420,7 @@ uint8_t gc_get_role(const GC_Chat *chat, GC_Peer_Id peer_id);
* Returns -5 if the role failed to be set.
* Returns -6 if the caller attempted to kick himself.
*/
non_null()
int gc_set_peer_role(const Messenger *m, int group_number, GC_Peer_Id peer_id, Group_Role new_role);
int gc_set_peer_role(const Messenger *_Nonnull m, int group_number, GC_Peer_Id peer_id, Group_Role new_role);
/** @brief Sets the group password and distributes the new shared state to the group.
*
@@ -481,9 +434,7 @@ int gc_set_peer_role(const Messenger *m, int group_number, GC_Peer_Id peer_id, G
* Returns -3 if the packet failed to send.
* Returns -4 if malloc failed.
*/
non_null(1) nullable(2)
int gc_founder_set_password(GC_Chat *chat, const uint8_t *password, uint16_t password_length);
int gc_founder_set_password(GC_Chat *_Nonnull chat, const uint8_t *_Nullable password, uint16_t password_length);
/** @brief Sets the topic lock and distributes the new shared state to the group.
*
* When the topic lock is enabled, only the group founder and moderators may set the topic.
@@ -499,8 +450,7 @@ int gc_founder_set_password(GC_Chat *chat, const uint8_t *password, uint16_t pas
* Returns -5 if the topic lock could not be set.
* Returns -6 if the packet failed to send.
*/
non_null()
int gc_founder_set_topic_lock(const Messenger *m, int group_number, Group_Topic_Lock new_lock_state);
int gc_founder_set_topic_lock(const Messenger *_Nonnull m, int group_number, Group_Topic_Lock new_lock_state);
/** @brief Sets the group privacy state and distributes the new shared state to the group.
*
@@ -516,8 +466,7 @@ int gc_founder_set_topic_lock(const Messenger *m, int group_number, Group_Topic_
* Returns -4 if the privacy state could not be set.
* Returns -5 if the packet failed to send.
*/
non_null()
int gc_founder_set_privacy_state(const Messenger *m, int group_number, Group_Privacy_State new_privacy_state);
int gc_founder_set_privacy_state(const Messenger *_Nonnull m, int group_number, Group_Privacy_State new_privacy_state);
/** @brief Sets the group voice state and distributes the new shared state to the group.
*
@@ -533,8 +482,7 @@ int gc_founder_set_privacy_state(const Messenger *m, int group_number, Group_Pri
* Returns -4 if the voice state could not be set.
* Returns -5 if the packet failed to send.
*/
non_null()
int gc_founder_set_voice_state(const Messenger *m, int group_number, Group_Voice_State new_voice_state);
int gc_founder_set_voice_state(const Messenger *_Nonnull m, int group_number, Group_Voice_State new_voice_state);
/** @brief Sets the peer limit to maxpeers and distributes the new shared state to the group.
*
@@ -545,8 +493,7 @@ int gc_founder_set_voice_state(const Messenger *m, int group_number, Group_Voice
* Returns -2 if the peer limit could not be set.
* Returns -3 if the packet failed to send.
*/
non_null()
int gc_founder_set_max_peers(GC_Chat *chat, uint16_t max_peers);
int gc_founder_set_max_peers(GC_Chat *_Nonnull chat, uint16_t max_peers);
/** @brief Removes peer designated by `peer_id` from peer list and sends a broadcast instructing
* all other peers to remove the peer from their peerlist as well.
@@ -561,51 +508,42 @@ int gc_founder_set_max_peers(GC_Chat *chat, uint16_t max_peers);
* Returns -5 if the packet failed to send.
* Returns -6 if the caller attempted to kick himself.
*/
non_null()
int gc_kick_peer(const Messenger *m, int group_number, GC_Peer_Id peer_id);
int gc_kick_peer(const Messenger *_Nonnull m, int group_number, GC_Peer_Id peer_id);
/** @brief Copies the chat_id to dest. If dest is null this function has no effect.
*
* `dest` should have room for at least CHAT_ID_SIZE bytes.
*/
non_null(1) nullable(2)
void gc_get_chat_id(const GC_Chat *chat, uint8_t *dest);
void gc_get_chat_id(const GC_Chat *_Nonnull chat, uint8_t *_Nullable dest);
/** Group callbacks */
non_null(1) nullable(2) void gc_callback_message(const Messenger *m, gc_message_cb *function);
non_null(1) nullable(2) void gc_callback_private_message(const Messenger *m, gc_private_message_cb *function);
non_null(1) nullable(2) void gc_callback_custom_packet(const Messenger *m, gc_custom_packet_cb *function);
non_null(1) nullable(2) void gc_callback_custom_private_packet(const Messenger *m,
gc_custom_private_packet_cb *function);
non_null(1) nullable(2) void gc_callback_moderation(const Messenger *m, gc_moderation_cb *function);
non_null(1) nullable(2) void gc_callback_nick_change(const Messenger *m, gc_nick_change_cb *function);
non_null(1) nullable(2) void gc_callback_status_change(const Messenger *m, gc_status_change_cb *function);
non_null(1) nullable(2) void gc_callback_topic_change(const Messenger *m, gc_topic_change_cb *function);
non_null(1) nullable(2) void gc_callback_peer_limit(const Messenger *m, gc_peer_limit_cb *function);
non_null(1) nullable(2) void gc_callback_privacy_state(const Messenger *m, gc_privacy_state_cb *function);
non_null(1) nullable(2) void gc_callback_topic_lock(const Messenger *m, gc_topic_lock_cb *function);
non_null(1) nullable(2) void gc_callback_password(const Messenger *m, gc_password_cb *function);
non_null(1) nullable(2) void gc_callback_peer_join(const Messenger *m, gc_peer_join_cb *function);
non_null(1) nullable(2) void gc_callback_peer_exit(const Messenger *m, gc_peer_exit_cb *function);
non_null(1) nullable(2) void gc_callback_self_join(const Messenger *m, gc_self_join_cb *function);
non_null(1) nullable(2) void gc_callback_rejected(const Messenger *m, gc_rejected_cb *function);
non_null(1) nullable(2) void gc_callback_voice_state(const Messenger *m, gc_voice_state_cb *function);
void gc_callback_message(const Messenger *_Nonnull m, gc_message_cb *_Nullable function);
void gc_callback_private_message(const Messenger *_Nonnull m, gc_private_message_cb *_Nullable function);
void gc_callback_custom_packet(const Messenger *_Nonnull m, gc_custom_packet_cb *_Nullable function);
void gc_callback_custom_private_packet(const Messenger *_Nonnull m,
gc_custom_private_packet_cb *_Nullable function);
void gc_callback_moderation(const Messenger *_Nonnull m, gc_moderation_cb *_Nullable function);
void gc_callback_nick_change(const Messenger *_Nonnull m, gc_nick_change_cb *_Nullable function);
void gc_callback_status_change(const Messenger *_Nonnull m, gc_status_change_cb *_Nullable function);
void gc_callback_topic_change(const Messenger *_Nonnull m, gc_topic_change_cb *_Nullable function);
void gc_callback_peer_limit(const Messenger *_Nonnull m, gc_peer_limit_cb *_Nullable function);
void gc_callback_privacy_state(const Messenger *_Nonnull m, gc_privacy_state_cb *_Nullable function);
void gc_callback_topic_lock(const Messenger *_Nonnull m, gc_topic_lock_cb *_Nullable function);
void gc_callback_password(const Messenger *_Nonnull m, gc_password_cb *_Nullable function);
void gc_callback_peer_join(const Messenger *_Nonnull m, gc_peer_join_cb *_Nullable function);
void gc_callback_peer_exit(const Messenger *_Nonnull m, gc_peer_exit_cb *_Nullable function);
void gc_callback_self_join(const Messenger *_Nonnull m, gc_self_join_cb *_Nullable function);
void gc_callback_rejected(const Messenger *_Nonnull m, gc_rejected_cb *_Nullable function);
void gc_callback_voice_state(const Messenger *_Nonnull m, gc_voice_state_cb *_Nullable function);
/** @brief The main loop. Should be called with every Messenger iteration. */
non_null(1) nullable(2)
void do_gc(GC_Session *c, void *userdata);
void do_gc(GC_Session *_Nonnull c, void *_Nullable userdata);
/**
* Make sure that DHT is initialized before calling this.
* Returns a NULL pointer on failure.
*/
nullable(1)
GC_Session *new_dht_groupchats(Messenger *m);
GC_Session *_Nullable new_dht_groupchats(Messenger *_Nullable m);
/** @brief Cleans up groupchat structures and calls `gc_group_exit()` for every group chat */
nullable(1)
void kill_dht_groupchats(GC_Session *c);
void kill_dht_groupchats(GC_Session *_Nullable c);
/** @brief Loads a previously saved group and attempts to join it.
*
* `bu` is the packed group info.
@@ -613,14 +551,12 @@ void kill_dht_groupchats(GC_Session *c);
* Returns group_number on success.
* Returns -1 on failure.
*/
non_null()
int gc_group_load(GC_Session *c, Bin_Unpack *bu);
int gc_group_load(GC_Session *_Nonnull c, Bin_Unpack *_Nonnull bu);
/**
* @brief Saves info from `chat` to `bp` in binary format.
*/
non_null()
void gc_group_save(const GC_Chat *chat, Bin_Pack *bp);
void gc_group_save(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp);
/** @brief Creates a new group and adds it to the group sessions group array.
*
@@ -635,10 +571,7 @@ void gc_group_save(const GC_Chat *chat, Bin_Pack *bp);
* Return -4 if the group state fails to initialize.
* Return -5 if the Messenger friend connection fails to initialize.
*/
non_null()
int gc_group_add(GC_Session *c, Group_Privacy_State privacy_state, const uint8_t *group_name,
uint16_t group_name_length,
const uint8_t *nick, size_t nick_length);
int gc_group_add(GC_Session *_Nonnull c, Group_Privacy_State privacy_state, const uint8_t *_Nonnull group_name, uint16_t group_name_length, const uint8_t *_Nonnull nick, size_t nick_length);
/** @brief Joins a group designated by `chat_id`.
*
@@ -656,17 +589,14 @@ int gc_group_add(GC_Session *c, Group_Privacy_State privacy_state, const uint8_t
* Return -5 if there is an error setting the group password.
* Return -6 if the Messenger friend connection fails to initialize.
*/
non_null(1, 2, 3) nullable(5)
int gc_group_join(GC_Session *c, const uint8_t *chat_id, const uint8_t *nick, size_t nick_length, const uint8_t *passwd,
int gc_group_join(GC_Session *_Nonnull c, const uint8_t *_Nonnull chat_id, const uint8_t *_Nonnull nick, size_t nick_length, const uint8_t *_Nullable passwd,
uint16_t passwd_len);
/** @brief Disconnects from all peers in a group but saves the group state for later use.
*
* Return true on sucess.
* Return false if the group handler object or chat object is null.
*/
non_null()
bool gc_disconnect_from_group(const GC_Session *c, GC_Chat *chat);
bool gc_disconnect_from_group(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat);
/** @brief Disconnects from all peers in a group and attempts to reconnect.
*
@@ -676,9 +606,7 @@ bool gc_disconnect_from_group(const GC_Session *c, GC_Chat *chat);
* Returns -1 if the group handler object or chat object is null.
* Returns -2 if the Messenger friend connection fails to initialize.
*/
non_null(1, 2) nullable(3)
int gc_rejoin_group(GC_Session *c, GC_Chat *chat, const uint8_t *passwd, uint16_t passwd_len);
int gc_rejoin_group(GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, const uint8_t *_Nullable passwd, uint16_t passwd_len);
/** @brief Joins a group using the invite data received in a friend's group invite.
*
* The invite is only valid while the inviter is present in the group.
@@ -692,11 +620,9 @@ int gc_rejoin_group(GC_Session *c, GC_Chat *chat, const uint8_t *passwd, uint16_
* Return -6 if friend doesn't exist.
* Return -7 if sending packet failed.
*/
non_null(1, 3, 5) nullable(7)
int gc_accept_invite(GC_Session *c, int32_t friend_number, const uint8_t *data, uint16_t length, const uint8_t *nick,
size_t nick_length, const uint8_t *passwd, uint16_t passwd_len);
typedef bool gc_send_group_invite_packet_cb(const Messenger *m, uint32_t friendnumber, const uint8_t *packet,
int gc_accept_invite(GC_Session *_Nonnull c, int32_t friend_number, const uint8_t *_Nonnull data, uint16_t length, const uint8_t *_Nonnull nick,
size_t nick_length, const uint8_t *_Nullable passwd, uint16_t passwd_len);
typedef bool gc_send_group_invite_packet_cb(const Messenger *_Nonnull m, uint32_t friendnumber, const uint8_t *_Nonnull packet,
uint16_t length);
/** @brief Invites friend designated by `friendnumber` to chat.
@@ -707,9 +633,7 @@ typedef bool gc_send_group_invite_packet_cb(const Messenger *m, uint32_t friendn
* Return -2 on failure to create the invite data.
* Return -3 if the packet fails to send.
*/
non_null()
int gc_invite_friend(const GC_Session *c, GC_Chat *chat, int32_t friend_number,
gc_send_group_invite_packet_cb *callback);
int gc_invite_friend(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, int32_t friend_number, gc_send_group_invite_packet_cb *_Nonnull callback);
/** @brief Leaves a group and sends an exit broadcast packet with an optional parting message.
*
@@ -719,31 +643,25 @@ int gc_invite_friend(const GC_Session *c, GC_Chat *chat, int32_t friend_number,
* Return -1 if the parting message is too long.
* Return -2 if the parting message failed to send.
*/
non_null(1, 2) nullable(3)
int gc_group_exit(GC_Session *c, GC_Chat *chat, const uint8_t *message, uint16_t length);
int gc_group_exit(GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, const uint8_t *_Nullable message, uint16_t length);
/** @brief Returns true if `chat` is a valid group chat.
*
* A valid group chat constitutes an initialized chat instance with a non-zero shared state version.
* The shared state version will be non-zero either if a peer has created the group, or if
* they have ever successfully connected to the group.
*/
non_null()
bool gc_group_is_valid(const GC_Chat *chat);
bool gc_group_is_valid(const GC_Chat *_Nonnull chat);
/** @brief Returns the number of active groups in `c`. */
non_null()
uint32_t gc_count_groups(const GC_Session *c);
uint32_t gc_count_groups(const GC_Session *_Nonnull c);
/** @brief Returns true if peer_number exists */
non_null()
bool gc_peer_number_is_valid(const GC_Chat *chat, int peer_number);
bool gc_peer_number_is_valid(const GC_Chat *_Nonnull chat, int peer_number);
/** @brief Return group_number's GC_Chat pointer on success
* Return NULL on failure
*/
non_null()
GC_Chat *gc_get_group(const GC_Session *c, int group_number);
GC_Chat *_Nullable gc_get_group(const GC_Session *_Nonnull c, int group_number);
/** @brief Sends a lossy message acknowledgement to peer associated with `gconn`.
*
@@ -754,8 +672,7 @@ GC_Chat *gc_get_group(const GC_Session *c, int group_number);
*
* @retval true on success.
*/
non_null()
bool gc_send_message_ack(const GC_Chat *chat, GC_Connection *gconn, uint64_t message_id, Group_Message_Ack_Type type);
bool gc_send_message_ack(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, uint64_t message_id, Group_Message_Ack_Type type);
/** @brief Helper function for `handle_gc_lossless_packet()`.
*
@@ -763,23 +680,19 @@ bool gc_send_message_ack(const GC_Chat *chat, GC_Connection *gconn, uint64_t mes
*
* @retval true if packet is successfully handled.
*/
non_null(1, 2) nullable(4, 7)
bool handle_gc_lossless_helper(const GC_Session *c, GC_Chat *chat, uint32_t peer_number, const uint8_t *data,
uint16_t length, uint8_t packet_type, void *userdata);
bool handle_gc_lossless_helper(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, uint32_t peer_number, const uint8_t *_Nullable data,
uint16_t length, uint8_t packet_type, void *_Nullable userdata);
/** @brief Handles an invite accept packet.
*
* @retval true on success.
*/
non_null()
bool handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, const uint8_t *data, uint16_t length);
bool handle_gc_invite_accepted_packet(const GC_Session *_Nonnull c, int friend_number, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Return true if `chat_id` is not present in our group sessions array.
*
* `length` must be at least CHAT_ID_SIZE bytes in length.
*/
non_null()
bool group_not_added(const GC_Session *c, const uint8_t *chat_id, uint32_t length);
bool group_not_added(const GC_Session *_Nonnull c, const uint8_t *_Nonnull chat_id, uint32_t length);
/** @brief Handles an invite confirmed packet.
*
@@ -790,21 +703,18 @@ bool group_not_added(const GC_Session *c, const uint8_t *chat_id, uint32_t lengt
* Return -4 if `friend_number` does not designate a valid friend.
* Return -5 if data contains invalid connection info.
*/
non_null()
int handle_gc_invite_confirmed_packet(const GC_Session *c, int friend_number, const uint8_t *data, uint16_t length);
int handle_gc_invite_confirmed_packet(const GC_Session *_Nonnull c, int friend_number, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Returns the group designated by `public_key`.
* Returns null if group does not exist.
*/
non_null()
GC_Chat *gc_get_group_by_public_key(const GC_Session *c, const uint8_t *public_key);
GC_Chat *_Nullable gc_get_group_by_public_key(const GC_Session *_Nonnull c, const uint8_t *_Nonnull public_key);
/** @brief Attempts to add peers from `announces` to our peer list and initiate an invite request.
*
* Returns the number of peers added on success.
* Returns -1 on failure.
*/
non_null()
int gc_add_peers_from_announces(GC_Chat *chat, const GC_Announce *announces, uint8_t gc_announces_count);
int gc_add_peers_from_announces(GC_Chat *_Nonnull chat, const GC_Announce *_Nonnull announces, uint8_t gc_announces_count);
#endif /* C_TOXCORE_TOXCORE_GROUP_CHATS_H */

View File

@@ -85,7 +85,7 @@ typedef struct GC_PeerAddress {
} GC_PeerAddress;
typedef struct GC_Message_Array_Entry {
uint8_t *data;
uint8_t *_Nullable data;
uint16_t data_length;
uint8_t packet_type;
uint64_t message_id;
@@ -97,10 +97,10 @@ typedef struct GC_Connection {
uint64_t send_message_id; /* message_id of the next message we send to peer */
uint16_t send_array_start; /* send_array index of oldest item */
GC_Message_Array_Entry *send_array;
GC_Message_Array_Entry *_Nullable send_array;
uint64_t received_message_id; /* message_id of peer's last message to us */
GC_Message_Array_Entry *recv_array;
GC_Message_Array_Entry *_Nullable recv_array;
uint64_t last_chunk_id; /* The message ID of the last packet fragment we received */
@@ -265,22 +265,22 @@ typedef struct GC_TopicInfo {
} GC_TopicInfo;
typedef struct GC_Chat {
Mono_Time *mono_time;
const Logger *log;
const Memory *mem;
const Random *rng;
Mono_Time *_Nonnull mono_time;
const Logger *_Nonnull log;
const Memory *_Nonnull mem;
const Random *_Nonnull rng;
uint32_t connected_tcp_relays;
Self_UDP_Status self_udp_status;
IP_Port self_ip_port;
Networking_Core *net;
TCP_Connections *tcp_conn;
Networking_Core *_Nonnull net;
TCP_Connections *_Nullable tcp_conn;
uint64_t last_checked_tcp_relays;
Group_Handshake_Join_Type join_type;
GC_Peer *group;
GC_Peer *_Nullable group;
Moderation moderation;
GC_Conn_State connection_state;
@@ -347,60 +347,60 @@ typedef struct GC_Chat {
typedef struct Messenger Messenger;
#endif /* MESSENGER_DEFINED */
typedef void gc_message_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type,
const uint8_t *message, size_t length, uint32_t message_id, void *user_data);
typedef void gc_private_message_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type,
const uint8_t *message, size_t length, uint32_t message_id, void *user_data);
typedef void gc_custom_packet_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *data,
size_t length, void *user_data);
typedef void gc_custom_private_packet_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id,
const uint8_t *data, size_t length, void *user_data);
typedef void gc_moderation_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id source_peer_number,
GC_Peer_Id target_peer_number, unsigned int mod_type, void *user_data);
typedef void gc_nick_change_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *name,
size_t length, void *user_data);
typedef void gc_status_change_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int status,
void *user_data);
typedef void gc_topic_change_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *topic,
size_t length, void *user_data);
typedef void gc_topic_lock_cb(const Messenger *m, uint32_t group_number, unsigned int topic_lock, void *user_data);
typedef void gc_voice_state_cb(const Messenger *m, uint32_t group_number, unsigned int voice_state, void *user_data);
typedef void gc_peer_limit_cb(const Messenger *m, uint32_t group_number, uint32_t peer_limit, void *user_data);
typedef void gc_privacy_state_cb(const Messenger *m, uint32_t group_number, unsigned int privacy_state, void *user_data);
typedef void gc_password_cb(const Messenger *m, uint32_t group_number, const uint8_t *password, size_t length,
void *user_data);
typedef void gc_peer_join_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, void *user_data);
typedef void gc_peer_exit_cb(const Messenger *m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int exit_type,
const uint8_t *name, size_t name_length, const uint8_t *part_message, size_t length,
void *user_data);
typedef void gc_self_join_cb(const Messenger *m, uint32_t group_number, void *user_data);
typedef void gc_rejected_cb(const Messenger *m, uint32_t group_number, unsigned int fail_type, void *user_data);
typedef void gc_message_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type,
const uint8_t *_Nonnull message, size_t length, uint32_t message_id, void *_Nullable user_data);
typedef void gc_private_message_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int type,
const uint8_t *_Nonnull message, size_t length, uint32_t message_id, void *_Nullable user_data);
typedef void gc_custom_packet_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *_Nonnull data,
size_t length, void *_Nullable user_data);
typedef void gc_custom_private_packet_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id,
const uint8_t *_Nonnull data, size_t length, void *_Nullable user_data);
typedef void gc_moderation_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id source_peer_number,
GC_Peer_Id target_peer_number, unsigned int mod_type, void *_Nullable user_data);
typedef void gc_nick_change_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *_Nonnull name,
size_t length, void *_Nullable user_data);
typedef void gc_status_change_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int status,
void *_Nullable user_data);
typedef void gc_topic_change_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, const uint8_t *_Nullable topic,
size_t length, void *_Nullable user_data);
typedef void gc_topic_lock_cb(const Messenger *_Nonnull m, uint32_t group_number, unsigned int topic_lock, void *_Nullable user_data);
typedef void gc_voice_state_cb(const Messenger *_Nonnull m, uint32_t group_number, unsigned int voice_state, void *_Nullable user_data);
typedef void gc_peer_limit_cb(const Messenger *_Nonnull m, uint32_t group_number, uint32_t peer_limit, void *_Nullable user_data);
typedef void gc_privacy_state_cb(const Messenger *_Nonnull m, uint32_t group_number, unsigned int privacy_state, void *_Nullable user_data);
typedef void gc_password_cb(const Messenger *_Nonnull m, uint32_t group_number, const uint8_t *_Nullable password, size_t length,
void *_Nullable user_data);
typedef void gc_peer_join_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, void *_Nullable user_data);
typedef void gc_peer_exit_cb(const Messenger *_Nonnull m, uint32_t group_number, GC_Peer_Id peer_id, unsigned int exit_type,
const uint8_t *_Nullable name, size_t name_length, const uint8_t *_Nullable part_message, size_t length,
void *_Nullable user_data);
typedef void gc_self_join_cb(const Messenger *_Nonnull m, uint32_t group_number, void *_Nullable user_data);
typedef void gc_rejected_cb(const Messenger *_Nonnull m, uint32_t group_number, unsigned int fail_type, void *_Nullable user_data);
typedef struct GC_Session {
Messenger *messenger;
GC_Chat *chats;
Net_Profile *tcp_np;
struct GC_Announces_List *announces_list;
Messenger *_Nonnull messenger;
GC_Chat *_Nullable chats;
Net_Profile *_Nullable tcp_np;
struct GC_Announces_List *_Nullable announces_list;
uint32_t chats_index;
gc_message_cb *message;
gc_private_message_cb *private_message;
gc_custom_packet_cb *custom_packet;
gc_custom_private_packet_cb *custom_private_packet;
gc_moderation_cb *moderation;
gc_nick_change_cb *nick_change;
gc_status_change_cb *status_change;
gc_topic_change_cb *topic_change;
gc_topic_lock_cb *topic_lock;
gc_voice_state_cb *voice_state;
gc_peer_limit_cb *peer_limit;
gc_privacy_state_cb *privacy_state;
gc_password_cb *password;
gc_peer_join_cb *peer_join;
gc_peer_exit_cb *peer_exit;
gc_self_join_cb *self_join;
gc_rejected_cb *rejected;
gc_message_cb *_Nullable message;
gc_private_message_cb *_Nullable private_message;
gc_custom_packet_cb *_Nullable custom_packet;
gc_custom_private_packet_cb *_Nullable custom_private_packet;
gc_moderation_cb *_Nullable moderation;
gc_nick_change_cb *_Nullable nick_change;
gc_status_change_cb *_Nullable status_change;
gc_topic_change_cb *_Nullable topic_change;
gc_topic_lock_cb *_Nullable topic_lock;
gc_voice_state_cb *_Nullable voice_state;
gc_peer_limit_cb *_Nullable peer_limit;
gc_privacy_state_cb *_Nullable privacy_state;
gc_password_cb *_Nullable password;
gc_peer_join_cb *_Nullable peer_join;
gc_peer_exit_cb *_Nullable peer_exit;
gc_self_join_cb *_Nullable self_join;
gc_rejected_cb *_Nullable rejected;
} GC_Session;
/** @brief Adds a new peer to group_number's peer list.
@@ -409,16 +409,13 @@ typedef struct GC_Session {
* Return -1 on failure.
* Return -2 if a peer with public_key is already in our peerlist.
*/
non_null(1, 3) nullable(2)
int peer_add(GC_Chat *chat, const IP_Port *ipp, const uint8_t *public_key);
int peer_add(GC_Chat *_Nonnull chat, const IP_Port *_Nullable ipp, const uint8_t *_Nonnull public_key);
/** @brief Unpacks saved peers from `data` of size `length` into `chat`.
*
* Returns the number of unpacked peers on success.
* Returns -1 on failure.
*/
non_null()
int unpack_gc_saved_peers(GC_Chat *chat, const uint8_t *data, uint16_t length);
int unpack_gc_saved_peers(GC_Chat *_Nonnull chat, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Packs all valid entries from saved peerlist into `data`.
*
@@ -428,7 +425,5 @@ int unpack_gc_saved_peers(GC_Chat *chat, const uint8_t *data, uint16_t length);
* Return the number of packed saved peers on success.
* Return -1 if buffer is too small.
*/
non_null(1, 2) nullable(4)
int pack_gc_saved_peers(const GC_Chat *chat, uint8_t *data, uint16_t length, uint16_t *processed);
int pack_gc_saved_peers(const GC_Chat *_Nonnull chat, uint8_t *_Nonnull data, uint16_t length, uint16_t *_Nullable processed);
#endif /* C_TOXCORE_TOXCORE_GROUP_COMMON_H */

View File

@@ -33,16 +33,14 @@
#define GCC_UDP_DIRECT_RETRY 1
/** Returns true if array entry does not contain an active packet. */
non_null()
static bool array_entry_is_empty(const GC_Message_Array_Entry *array_entry)
static bool array_entry_is_empty(const GC_Message_Array_Entry *_Nonnull array_entry)
{
assert(array_entry != nullptr);
return array_entry->time_added == 0;
}
/** @brief Clears an array entry. */
non_null()
static void clear_array_entry(const Memory *mem, GC_Message_Array_Entry *const array_entry)
static void clear_array_entry(const Memory *_Nonnull mem, GC_Message_Array_Entry *_Nonnull array_entry)
{
mem_delete(mem, array_entry->data);
@@ -56,8 +54,7 @@ static void clear_array_entry(const Memory *mem, GC_Message_Array_Entry *const a
* `start_id` and ending at `end_id`, and sets the send_message_id for `gconn`
* to `start_id`.
*/
non_null()
static void clear_send_queue_id_range(const Memory *mem, GC_Connection *gconn, uint64_t start_id, uint64_t end_id)
static void clear_send_queue_id_range(const Memory *_Nonnull mem, GC_Connection *_Nonnull gconn, uint64_t start_id, uint64_t end_id)
{
const uint16_t start_idx = gcc_get_array_index(start_id);
const uint16_t end_idx = gcc_get_array_index(end_id);
@@ -93,9 +90,8 @@ void gcc_set_recv_message_id(GC_Connection *gconn, uint64_t id)
*
* Return true on success.
*/
non_null(1, 2, 3, 4) nullable(5)
static bool create_array_entry(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Message_Array_Entry *array_entry,
const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id)
static bool create_array_entry(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, GC_Message_Array_Entry *_Nonnull array_entry,
const uint8_t *_Nullable data, uint16_t length, uint8_t packet_type, uint64_t message_id)
{
if (!array_entry_is_empty(array_entry)) {
LOGGER_WARNING(log, "Failed to create array entry; entry is not empty.");
@@ -137,9 +133,8 @@ static bool create_array_entry(const Logger *log, const Memory *mem, const Mono_
*
* Returns true and increments gconn's send_message_id on success.
*/
non_null(1, 2, 3, 4) nullable(5)
static bool add_to_send_array(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Connection *gconn,
const uint8_t *data, uint16_t length, uint8_t packet_type)
static bool add_to_send_array(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, GC_Connection *_Nonnull gconn,
const uint8_t *_Nullable data, uint16_t length, uint8_t packet_type)
{
/* check if send_array is full */
if ((gconn->send_message_id % GCC_BUFFER_SIZE) == (uint16_t)(gconn->send_array_start - 1)) {
@@ -339,9 +334,8 @@ int gcc_save_tcp_relay(const Random *rng, GC_Connection *gconn, const Node_forma
*
* Return true on success.
*/
non_null(1, 2, 3, 4) nullable(5)
static bool store_in_recv_array(const Logger *log, const Memory *mem, const Mono_Time *mono_time,
GC_Connection *gconn, const uint8_t *data,
static bool store_in_recv_array(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time,
GC_Connection *_Nonnull gconn, const uint8_t *_Nullable data,
uint16_t length, uint8_t packet_type, uint64_t message_id)
{
const uint16_t idx = gcc_get_array_index(message_id);
@@ -361,8 +355,7 @@ static bool store_in_recv_array(const Logger *log, const Memory *mem, const Mono
* Return the length of the fully reassembled packet on success.
* Return 0 on failure.
*/
non_null(1, 2, 4) nullable(3)
static uint16_t reassemble_packet(const Logger *log, const Memory *mem, GC_Connection *gconn, uint8_t **payload, uint64_t message_id)
static uint16_t reassemble_packet(const Logger *_Nonnull log, const Memory *_Nonnull mem, GC_Connection *_Nullable gconn, uint8_t *_Nonnull *payload, uint64_t message_id)
{
uint16_t end_idx = gcc_get_array_index(message_id - 1);
uint16_t start_idx = end_idx;
@@ -511,9 +504,8 @@ int gcc_handle_received_message(const Logger *log, const Memory *mem, const Mono
*
* Return true on success.
*/
non_null(1, 2, 3, 5) nullable(6)
static bool process_recv_array_entry(const GC_Session *c, GC_Chat *chat, GC_Connection *gconn, uint32_t peer_number,
GC_Message_Array_Entry *const array_entry, void *userdata)
static bool process_recv_array_entry(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, uint32_t peer_number,
GC_Message_Array_Entry *_Nonnull array_entry, void *_Nullable userdata)
{
uint8_t sender_pk[ENC_PUBLIC_KEY_SIZE];
memcpy(sender_pk, get_enc_key(&gconn->addr.public_key), ENC_PUBLIC_KEY_SIZE);

View File

@@ -24,10 +24,8 @@
#define GCC_MAX_TCP_SHARED_RELAYS 3
/** Marks a peer for deletion. If gconn is null or already marked for deletion this function has no effect. */
non_null(1, 2) nullable(4)
void gcc_mark_for_deletion(GC_Connection *gconn, TCP_Connections *tcp_conn, Group_Exit_Type type,
const uint8_t *part_message, uint16_t length);
void gcc_mark_for_deletion(GC_Connection *_Nonnull gconn, TCP_Connections *_Nonnull tcp_conn, Group_Exit_Type type,
const uint8_t *_Nullable part_message, uint16_t length);
/** @brief Decides if message need to be put in recv_array or immediately handled.
*
* Return 3 if message is in correct sequence and is a fragment packet.
@@ -36,11 +34,9 @@ void gcc_mark_for_deletion(GC_Connection *gconn, TCP_Connections *tcp_conn, Grou
* Return 0 if message is a duplicate.
* Return -1 on failure
*/
non_null(1, 2, 3, 4) nullable(5)
int gcc_handle_received_message(const Logger *log, const Memory *mem, const Mono_Time *mono_time, GC_Connection *gconn,
const uint8_t *data, uint16_t length, uint8_t packet_type, uint64_t message_id,
int gcc_handle_received_message(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, GC_Connection *_Nonnull gconn,
const uint8_t *_Nullable data, uint16_t length, uint8_t packet_type, uint64_t message_id,
bool direct_conn);
/** @brief Handles a packet fragment.
*
* If the fragment is incomplete, it gets stored in the recv
@@ -51,11 +47,9 @@ int gcc_handle_received_message(const Logger *log, const Memory *mem, const Mono
* Return 0 if fragment is the end of a sequence and successfully handled.
* Return -1 on failure.
*/
non_null(1, 2, 4) nullable(5, 9)
int gcc_handle_packet_fragment(const GC_Session *c, GC_Chat *chat, uint32_t peer_number, GC_Connection *gconn,
const uint8_t *chunk, uint16_t length, uint8_t packet_type, uint64_t message_id,
void *userdata);
int gcc_handle_packet_fragment(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, uint32_t peer_number, GC_Connection *_Nonnull gconn,
const uint8_t *_Nullable chunk, uint16_t length, uint8_t packet_type, uint64_t message_id,
void *_Nullable userdata);
/** @brief Return array index for message_id */
uint16_t gcc_get_array_index(uint64_t message_id);
@@ -63,40 +57,33 @@ uint16_t gcc_get_array_index(uint64_t message_id);
*
* Return true on success.
*/
non_null()
bool gcc_handle_ack(const Logger *log, const Memory *mem, GC_Connection *gconn, uint64_t message_id);
bool gcc_handle_ack(const Logger *_Nonnull log, const Memory *_Nonnull mem, GC_Connection *_Nonnull gconn, uint64_t message_id);
/** @brief Sets the send_message_id and send_array_start for `gconn` to `id`.
*
* This should only be used to initialize a new lossless connection.
*/
non_null()
void gcc_set_send_message_id(GC_Connection *gconn, uint64_t id);
void gcc_set_send_message_id(GC_Connection *_Nonnull gconn, uint64_t id);
/** @brief Sets the received_message_id for `gconn` to `id`. */
non_null()
void gcc_set_recv_message_id(GC_Connection *gconn, uint64_t id);
void gcc_set_recv_message_id(GC_Connection *_Nonnull gconn, uint64_t id);
/**
* @brief Returns true if the ip_port is set for gconn.
*/
non_null()
bool gcc_ip_port_is_set(const GC_Connection *gconn);
bool gcc_ip_port_is_set(const GC_Connection *_Nonnull gconn);
/**
* @brief Sets the ip_port for gconn to ipp.
*
* If ipp is not set this function has no effect.
*/
non_null(1) nullable(2)
void gcc_set_ip_port(GC_Connection *gconn, const IP_Port *ipp);
void gcc_set_ip_port(GC_Connection *_Nonnull gconn, const IP_Port *_Nullable ipp);
/** @brief Copies a random TCP relay node from gconn to tcp_node.
*
* Return true on success.
*/
non_null()
bool gcc_copy_tcp_relay(const Random *rng, Node_format *tcp_node, const GC_Connection *gconn);
bool gcc_copy_tcp_relay(const Random *_Nonnull rng, Node_format *_Nonnull tcp_node, const GC_Connection *_Nonnull gconn);
/** @brief Saves tcp_node to gconn's list of connected tcp relays.
*
@@ -106,19 +93,15 @@ bool gcc_copy_tcp_relay(const Random *rng, Node_format *tcp_node, const GC_Conne
* Return -1 on failure.
* Return -2 if node is already in list.
*/
non_null()
int gcc_save_tcp_relay(const Random *rng, GC_Connection *gconn, const Node_format *tcp_node);
int gcc_save_tcp_relay(const Random *_Nonnull rng, GC_Connection *_Nonnull gconn, const Node_format *_Nonnull tcp_node);
/** @brief Checks for and handles messages that are in proper sequence in gconn's recv_array.
* This should always be called after a new packet is successfully handled.
*/
non_null(1, 2, 3) nullable(5)
void gcc_check_recv_array(const GC_Session *c, GC_Chat *chat, GC_Connection *gconn, uint32_t peer_number,
void *userdata);
void gcc_check_recv_array(const GC_Session *_Nonnull c, GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, uint32_t peer_number,
void *_Nullable userdata);
/** @brief Attempts to re-send lossless packets that have not yet received an ack. */
non_null()
void gcc_resend_packets(const GC_Chat *chat, GC_Connection *gconn);
void gcc_resend_packets(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn);
/**
* Uses public encryption key `sender_pk` and the shared secret key associated with `gconn`
@@ -128,20 +111,16 @@ void gcc_resend_packets(const GC_Chat *chat, GC_Connection *gconn);
* Puts the result in the shared session key buffer for `gconn`, which must have room for
* CRYPTO_SHARED_KEY_SIZE bytes. This resulting shared key should be treated as a secret key.
*/
non_null()
void gcc_make_session_shared_key(GC_Connection *gconn, const uint8_t *sender_pk);
void gcc_make_session_shared_key(GC_Connection *_Nonnull gconn, const uint8_t *_Nonnull sender_pk);
/** @brief Return true if we have a direct connection with `gconn`. */
non_null()
bool gcc_conn_is_direct(const Mono_Time *mono_time, const GC_Connection *gconn);
bool gcc_conn_is_direct(const Mono_Time *_Nonnull mono_time, const GC_Connection *_Nonnull gconn);
/** @brief Return true if we can try a direct connection with `gconn` again. */
non_null()
bool gcc_conn_should_try_direct(const Mono_Time *mono_time, const GC_Connection *gconn);
bool gcc_conn_should_try_direct(const Mono_Time *_Nonnull mono_time, const GC_Connection *_Nonnull gconn);
/** @brief Return true if a direct UDP connection is possible with `gconn`. */
non_null()
bool gcc_direct_conn_is_possible(const GC_Chat *chat, const GC_Connection *gconn);
bool gcc_direct_conn_is_possible(const GC_Chat *_Nonnull chat, const GC_Connection *_Nonnull gconn);
/** @brief Sends a packet to the peer associated with gconn.
*
@@ -149,8 +128,7 @@ bool gcc_direct_conn_is_possible(const GC_Chat *chat, const GC_Connection *gconn
*
* Return true on success.
*/
non_null()
bool gcc_send_packet(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *packet, uint16_t length);
bool gcc_send_packet(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, const uint8_t *_Nonnull packet, uint16_t length);
/** @brief Sends a lossless packet to `gconn` comprised of `data` of size `length`.
*
@@ -161,10 +139,8 @@ bool gcc_send_packet(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *p
* Return -1 if the packet couldn't be added to the send array.
* Return -2 if the packet failed to be wrapped or encrypted.
*/
non_null(1, 2) nullable(3)
int gcc_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *data, uint16_t length,
int gcc_send_lossless_packet(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, const uint8_t *_Nullable data, uint16_t length,
uint8_t packet_type);
/** @brief Splits a lossless packet up into fragments, wraps each fragment in a GP_FRAGMENT
* header, encrypts them, and send them in succession.
*
@@ -174,9 +150,7 @@ int gcc_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const ui
*
* Return true if all fragments are successfully added to the send array.
*/
non_null()
bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *data,
uint16_t length, uint8_t packet_type);
bool gcc_send_lossless_packet_fragments(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, const uint8_t *_Nonnull data, uint16_t length, uint8_t packet_type);
/** @brief Encrypts `data` of `length` bytes, designated by `message_id`, using the shared key
* associated with `gconn` and sends lossless packet over the wire.
@@ -187,16 +161,12 @@ bool gcc_send_lossless_packet_fragments(const GC_Chat *chat, GC_Connection *gcon
* Return -1 if packet wrapping and encryption fails.
* Return -2 if the packet fails to send.
*/
non_null(1, 2) nullable(3)
int gcc_encrypt_and_send_lossless_packet(const GC_Chat *chat, GC_Connection *gconn, const uint8_t *data,
int gcc_encrypt_and_send_lossless_packet(const GC_Chat *_Nonnull chat, GC_Connection *_Nonnull gconn, const uint8_t *_Nullable data,
uint16_t length, uint64_t message_id, uint8_t packet_type);
/** @brief Called when a peer leaves the group. */
non_null()
void gcc_peer_cleanup(const Memory *mem, GC_Connection *gconn);
void gcc_peer_cleanup(const Memory *_Nonnull mem, GC_Connection *_Nonnull gconn);
/** @brief Called on group exit. */
non_null()
void gcc_cleanup(const GC_Chat *chat);
void gcc_cleanup(const GC_Chat *_Nonnull chat);
#endif /* C_TOXCORE_TOXCORE_GROUP_CONNECTION_H */

View File

@@ -34,12 +34,12 @@ static_assert(MOD_MAX_NUM_MODERATORS <= MOD_MAX_NUM_MODERATORS_LIMIT,
static_assert(MOD_MAX_NUM_SANCTIONS <= MOD_MAX_NUM_SANCTIONS_LIMIT,
"MOD_MAX_NUM_SANCTIONS must be <= MOD_MAX_NUM_SANCTIONS_LIMIT");
uint16_t mod_list_packed_size(const Moderation *moderation)
uint16_t mod_list_packed_size(const Moderation *_Nonnull moderation)
{
return moderation->num_mods * MOD_LIST_ENTRY_SIZE;
}
int mod_list_unpack(Moderation *moderation, const uint8_t *data, uint16_t length, uint16_t num_mods)
int mod_list_unpack(Moderation *_Nonnull moderation, const uint8_t *_Nonnull data, uint16_t length, uint16_t num_mods)
{
if (length < num_mods * MOD_LIST_ENTRY_SIZE) {
return -1;
@@ -79,19 +79,19 @@ int mod_list_unpack(Moderation *moderation, const uint8_t *data, uint16_t length
return unpacked_len;
}
void mod_list_pack(const Moderation *moderation, uint8_t *data)
void mod_list_pack(const Moderation *_Nonnull moderation, uint8_t *_Nonnull data)
{
for (uint16_t i = 0; i < moderation->num_mods; ++i) {
memcpy(&data[i * MOD_LIST_ENTRY_SIZE], moderation->mod_list[i], MOD_LIST_ENTRY_SIZE);
}
}
void mod_list_get_data_hash(uint8_t *hash, const uint8_t *packed_mod_list, uint16_t length)
void mod_list_get_data_hash(uint8_t *_Nonnull hash, const uint8_t *_Nonnull packed_mod_list, uint16_t length)
{
crypto_sha256(hash, packed_mod_list, length);
}
bool mod_list_make_hash(const Moderation *moderation, uint8_t *hash)
bool mod_list_make_hash(const Moderation *_Nonnull moderation, uint8_t *_Nonnull hash)
{
if (moderation->num_mods == 0) {
memzero(hash, MOD_MODERATION_HASH_SIZE);
@@ -121,8 +121,7 @@ bool mod_list_make_hash(const Moderation *moderation, uint8_t *hash)
* Returns moderator list index for public_sig_key.
* Returns -1 if key is not in the list.
*/
non_null()
static int mod_list_index_of_sig_pk(const Moderation *moderation, const uint8_t *public_sig_key)
static int mod_list_index_of_sig_pk(const Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_sig_key)
{
for (uint16_t i = 0; i < moderation->num_mods; ++i) {
if (memcmp(moderation->mod_list[i], public_sig_key, SIG_PUBLIC_KEY_SIZE) == 0) {
@@ -133,7 +132,7 @@ static int mod_list_index_of_sig_pk(const Moderation *moderation, const uint8_t
return -1;
}
bool mod_list_verify_sig_pk(const Moderation *moderation, const uint8_t *sig_pk)
bool mod_list_verify_sig_pk(const Moderation *_Nonnull moderation, const uint8_t *_Nonnull sig_pk)
{
if (memcmp(moderation->founder_public_sig_key, sig_pk, SIG_PUBLIC_KEY_SIZE) == 0) {
return true;
@@ -148,7 +147,7 @@ bool mod_list_verify_sig_pk(const Moderation *moderation, const uint8_t *sig_pk)
return false;
}
bool mod_list_remove_index(Moderation *moderation, uint16_t index)
bool mod_list_remove_index(Moderation *_Nonnull moderation, uint16_t index)
{
if (index >= moderation->num_mods) {
return false;
@@ -180,7 +179,7 @@ bool mod_list_remove_index(Moderation *moderation, uint16_t index)
return true;
}
bool mod_list_remove_entry(Moderation *moderation, const uint8_t *public_sig_key)
bool mod_list_remove_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_sig_key)
{
if (moderation->num_mods == 0) {
return false;
@@ -197,7 +196,7 @@ bool mod_list_remove_entry(Moderation *moderation, const uint8_t *public_sig_key
return mod_list_remove_index(moderation, (uint16_t)idx);
}
bool mod_list_add_entry(Moderation *moderation, const uint8_t *mod_data)
bool mod_list_add_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull mod_data)
{
if (moderation->num_mods >= MOD_MAX_NUM_MODERATORS) {
return false;
@@ -225,14 +224,14 @@ bool mod_list_add_entry(Moderation *moderation, const uint8_t *mod_data)
return true;
}
void mod_list_cleanup(Moderation *moderation)
void mod_list_cleanup(Moderation *_Nullable moderation)
{
free_uint8_t_pointer_array(moderation->mem, moderation->mod_list, moderation->num_mods);
moderation->num_mods = 0;
moderation->mod_list = nullptr;
}
uint16_t sanctions_creds_pack(const Mod_Sanction_Creds *creds, uint8_t *data)
uint16_t sanctions_creds_pack(const Mod_Sanction_Creds *_Nonnull creds, uint8_t *_Nonnull data)
{
uint16_t packed_len = 0;
@@ -255,8 +254,8 @@ uint16_t sanctions_list_packed_size(uint16_t num_sanctions)
return MOD_SANCTION_PACKED_SIZE * num_sanctions;
}
int sanctions_list_pack(uint8_t *data, uint16_t length, const Mod_Sanction *sanctions, uint16_t num_sanctions,
const Mod_Sanction_Creds *creds)
int sanctions_list_pack(uint8_t *_Nonnull data, uint16_t length, const Mod_Sanction *_Nullable sanctions, uint16_t num_sanctions,
const Mod_Sanction_Creds *_Nullable creds)
{
assert(sanctions != nullptr || num_sanctions == 0);
assert(sanctions != nullptr || creds != nullptr);
@@ -314,7 +313,7 @@ int sanctions_list_pack(uint8_t *data, uint16_t length, const Mod_Sanction *sanc
return packed_len + cred_len;
}
uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *creds, const uint8_t *data)
uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *_Nonnull creds, const uint8_t *_Nonnull data)
{
uint16_t len_processed = 0;
@@ -332,8 +331,8 @@ uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *creds, const uint8_t *data)
return len_processed;
}
int sanctions_list_unpack(Mod_Sanction *sanctions, Mod_Sanction_Creds *creds, uint16_t max_sanctions,
const uint8_t *data, uint16_t length, uint16_t *processed_data_len)
int sanctions_list_unpack(Mod_Sanction *_Nonnull sanctions, Mod_Sanction_Creds *_Nonnull creds, uint16_t max_sanctions,
const uint8_t *_Nonnull data, uint16_t length, uint16_t *_Nullable processed_data_len)
{
uint16_t num = 0;
uint16_t len_processed = 0;
@@ -405,9 +404,8 @@ int sanctions_list_unpack(Mod_Sanction *sanctions, Mod_Sanction_Creds *creds, ui
*
* Return true on success.
*/
non_null(1, 5) nullable(2)
static bool sanctions_list_make_hash(const Memory *mem, const Mod_Sanction *sanctions, uint32_t new_version, uint16_t num_sanctions,
uint8_t *hash)
static bool sanctions_list_make_hash(const Memory *_Nonnull mem, const Mod_Sanction *_Nullable sanctions, uint32_t new_version, uint16_t num_sanctions,
uint8_t *_Nonnull hash)
{
if (num_sanctions == 0 || sanctions == nullptr) {
memzero(hash, MOD_SANCTION_HASH_SIZE);
@@ -444,8 +442,7 @@ static bool sanctions_list_make_hash(const Memory *mem, const Mod_Sanction *sanc
*
* Returns true on success.
*/
non_null()
static bool sanctions_list_validate_entry(const Moderation *moderation, const Mod_Sanction *sanction)
static bool sanctions_list_validate_entry(const Moderation *_Nonnull moderation, const Mod_Sanction *_Nonnull sanction)
{
if (!mod_list_verify_sig_pk(moderation, sanction->setter_public_sig_key)) {
return false;
@@ -470,19 +467,17 @@ static bool sanctions_list_validate_entry(const Moderation *moderation, const Mo
sanction->setter_public_sig_key);
}
non_null()
static uint16_t sanctions_creds_get_checksum(const Mod_Sanction_Creds *creds)
static uint16_t sanctions_creds_get_checksum(const Mod_Sanction_Creds *_Nonnull creds)
{
return data_checksum(creds->hash, sizeof(creds->hash));
}
non_null()
static void sanctions_creds_set_checksum(Mod_Sanction_Creds *creds)
static void sanctions_creds_set_checksum(Mod_Sanction_Creds *_Nonnull creds)
{
creds->checksum = sanctions_creds_get_checksum(creds);
}
bool sanctions_list_make_creds(Moderation *moderation)
bool sanctions_list_make_creds(Moderation *_Nonnull moderation)
{
const Mod_Sanction_Creds old_creds = moderation->sanctions_creds;
@@ -522,9 +517,8 @@ bool sanctions_list_make_creds(Moderation *moderation)
*
* Returns true on success.
*/
non_null(1, 3) nullable(2)
static bool sanctions_creds_validate(const Moderation *moderation, const Mod_Sanction *sanctions,
const Mod_Sanction_Creds *creds, uint16_t num_sanctions)
static bool sanctions_creds_validate(const Moderation *_Nonnull moderation, const Mod_Sanction *_Nullable sanctions,
const Mod_Sanction_Creds *_Nonnull creds, uint16_t num_sanctions)
{
if (!mod_list_verify_sig_pk(moderation, creds->sig_pk)) {
LOGGER_WARNING(moderation->log, "Invalid credentials signature pk");
@@ -563,8 +557,8 @@ static bool sanctions_creds_validate(const Moderation *moderation, const Mod_San
return true;
}
bool sanctions_list_check_integrity(const Moderation *moderation, const Mod_Sanction_Creds *creds,
const Mod_Sanction *sanctions, uint16_t num_sanctions)
bool sanctions_list_check_integrity(const Moderation *_Nonnull moderation, const Mod_Sanction_Creds *_Nonnull creds,
const Mod_Sanction *_Nonnull sanctions, uint16_t num_sanctions)
{
for (uint16_t i = 0; i < num_sanctions; ++i) {
if (!sanctions_list_validate_entry(moderation, &sanctions[i])) {
@@ -587,9 +581,8 @@ bool sanctions_list_check_integrity(const Moderation *moderation, const Mod_Sanc
*
* @retval false if sanctions credentials validation fails.
*/
non_null(1, 2) nullable(3)
static bool sanctions_apply_new(Moderation *moderation, Mod_Sanction *new_sanctions,
const Mod_Sanction_Creds *new_creds,
static bool sanctions_apply_new(Moderation *_Nonnull moderation, Mod_Sanction *_Nonnull new_sanctions,
const Mod_Sanction_Creds *_Nullable new_creds,
uint16_t num_sanctions)
{
if (new_creds != nullptr) {
@@ -611,8 +604,7 @@ static bool sanctions_apply_new(Moderation *moderation, Mod_Sanction *new_sancti
/** @brief Returns a copy of the sanctions list. The caller is responsible for freeing the
* memory returned by this function.
*/
non_null()
static Mod_Sanction *sanctions_list_copy(const Memory *mem, const Mod_Sanction *sanctions, uint16_t num_sanctions)
static Mod_Sanction *sanctions_list_copy(const Memory *_Nonnull mem, const Mod_Sanction *_Nonnull sanctions, uint16_t num_sanctions)
{
Mod_Sanction *copy = (Mod_Sanction *)mem_valloc(mem, num_sanctions, sizeof(Mod_Sanction));
@@ -631,8 +623,7 @@ static Mod_Sanction *sanctions_list_copy(const Memory *mem, const Mod_Sanction *
*
* Returns true on success.
*/
non_null(1) nullable(3)
static bool sanctions_list_remove_index(Moderation *moderation, uint16_t index, const Mod_Sanction_Creds *creds)
static bool sanctions_list_remove_index(Moderation *_Nonnull moderation, uint16_t index, const Mod_Sanction_Creds *_Nullable creds)
{
if (index >= moderation->num_sanctions) {
return false;
@@ -680,8 +671,8 @@ static bool sanctions_list_remove_index(Moderation *moderation, uint16_t index,
return true;
}
bool sanctions_list_remove_observer(Moderation *moderation, const uint8_t *public_key,
const Mod_Sanction_Creds *creds)
bool sanctions_list_remove_observer(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key,
const Mod_Sanction_Creds *_Nullable creds)
{
for (uint16_t i = 0; i < moderation->num_sanctions; ++i) {
const Mod_Sanction *curr_sanction = &moderation->sanctions[i];
@@ -706,7 +697,7 @@ bool sanctions_list_remove_observer(Moderation *moderation, const uint8_t *publi
return false;
}
bool sanctions_list_is_observer(const Moderation *moderation, const uint8_t *public_key)
bool sanctions_list_is_observer(const Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key)
{
for (uint16_t i = 0; i < moderation->num_sanctions; ++i) {
const Mod_Sanction *curr_sanction = &moderation->sanctions[i];
@@ -723,7 +714,7 @@ bool sanctions_list_is_observer(const Moderation *moderation, const uint8_t *pub
return false;
}
bool sanctions_list_entry_exists(const Moderation *moderation, const Mod_Sanction *sanction)
bool sanctions_list_entry_exists(const Moderation *_Nonnull moderation, const Mod_Sanction *_Nonnull sanction)
{
if (sanction->type == SA_OBSERVER) {
return sanctions_list_is_observer(moderation, sanction->target_public_enc_key);
@@ -732,7 +723,7 @@ bool sanctions_list_entry_exists(const Moderation *moderation, const Mod_Sanctio
return false;
}
bool sanctions_list_add_entry(Moderation *moderation, const Mod_Sanction *sanction, const Mod_Sanction_Creds *creds)
bool sanctions_list_add_entry(Moderation *_Nonnull moderation, const Mod_Sanction *_Nonnull sanction, const Mod_Sanction_Creds *_Nullable creds)
{
if (moderation->num_sanctions >= MOD_MAX_NUM_SANCTIONS) {
LOGGER_WARNING(moderation->log, "num_sanctions %d exceeds maximum", moderation->num_sanctions);
@@ -784,8 +775,7 @@ bool sanctions_list_add_entry(Moderation *moderation, const Mod_Sanction *sancti
*
* Returns true on success.
*/
non_null()
static bool sanctions_list_sign_entry(const Moderation *moderation, Mod_Sanction *sanction)
static bool sanctions_list_sign_entry(const Moderation *_Nonnull moderation, Mod_Sanction *_Nonnull sanction)
{
uint8_t packed_data[MOD_SANCTION_PACKED_SIZE];
const int packed_len = sanctions_list_pack(packed_data, sizeof(packed_data), sanction, 1, nullptr);
@@ -799,7 +789,7 @@ static bool sanctions_list_sign_entry(const Moderation *moderation, Mod_Sanction
moderation->self_secret_sig_key);
}
bool sanctions_list_make_entry(Moderation *moderation, const uint8_t *public_key, Mod_Sanction *sanction,
bool sanctions_list_make_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key, Mod_Sanction *_Nonnull sanction,
uint8_t type)
{
*sanction = (Mod_Sanction) {
@@ -834,7 +824,7 @@ bool sanctions_list_make_entry(Moderation *moderation, const uint8_t *public_key
return true;
}
uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *public_sig_key)
uint16_t sanctions_list_replace_sig(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_sig_key)
{
uint16_t count = 0;
@@ -862,7 +852,7 @@ uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *publi
return count;
}
void sanctions_list_cleanup(Moderation *moderation)
void sanctions_list_cleanup(Moderation *_Nonnull moderation)
{
mem_delete(moderation->mem, moderation->sanctions);

View File

@@ -81,27 +81,26 @@ typedef struct Mod_Sanction {
} Mod_Sanction;
typedef struct Moderation {
const Memory *mem;
const Logger *log;
const Memory *_Nonnull mem;
const Logger *_Nonnull log;
Mod_Sanction *sanctions;
Mod_Sanction *_Nullable sanctions;
uint16_t num_sanctions;
Mod_Sanction_Creds sanctions_creds;
uint8_t **mod_list; // array of public signature keys of all the mods
uint8_t *_Nullable *_Nullable mod_list; // array of public signature keys of all the mods
uint16_t num_mods;
// copies from parent/sibling chat/shared state objects
uint8_t founder_public_sig_key[SIG_PUBLIC_KEY_SIZE];
uint8_t founder_public_sig_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_public_sig_key[SIG_PUBLIC_KEY_SIZE];
uint8_t self_secret_sig_key[SIG_SECRET_KEY_SIZE];
uint32_t shared_state_version;
} Moderation;
/** @brief Returns the size in bytes of the packed moderation list. */
non_null()
uint16_t mod_list_packed_size(const Moderation *moderation);
uint16_t mod_list_packed_size(const Moderation *_Nonnull moderation);
/** @brief Unpacks data into the moderator list.
*
@@ -110,14 +109,12 @@ uint16_t mod_list_packed_size(const Moderation *moderation);
* Returns length of unpacked data on success.
* Returns -1 on failure.
*/
non_null()
int mod_list_unpack(Moderation *moderation, const uint8_t *data, uint16_t length, uint16_t num_mods);
int mod_list_unpack(Moderation *_Nonnull moderation, const uint8_t *_Nonnull data, uint16_t length, uint16_t num_mods);
/** @brief Packs moderator list into data.
* @param data must have room for the number of bytes returned by `mod_list_packed_size`.
*/
non_null()
void mod_list_pack(const Moderation *moderation, uint8_t *data);
void mod_list_pack(const Moderation *_Nonnull moderation, uint8_t *_Nonnull data);
/** @brief Creates a new moderator list hash and puts it in `hash`.
*
@@ -127,29 +124,25 @@ void mod_list_pack(const Moderation *moderation, uint8_t *data);
*
* Returns true on sucess.
*/
non_null()
bool mod_list_make_hash(const Moderation *moderation, uint8_t *hash);
bool mod_list_make_hash(const Moderation *_Nonnull moderation, uint8_t *_Nonnull hash);
/** @brief Puts a sha256 hash of `packed_mod_list` of `length` bytes in `hash`.
*
* @param hash must have room for at least MOD_MODERATION_HASH_SIZE bytes.
*/
non_null()
void mod_list_get_data_hash(uint8_t *hash, const uint8_t *packed_mod_list, uint16_t length);
void mod_list_get_data_hash(uint8_t *_Nonnull hash, const uint8_t *_Nonnull packed_mod_list, uint16_t length);
/** @brief Removes moderator at index-th position in the moderator list.
*
* Returns true on success.
*/
non_null()
bool mod_list_remove_index(Moderation *moderation, uint16_t index);
bool mod_list_remove_index(Moderation *_Nonnull moderation, uint16_t index);
/** @brief Removes public_sig_key from the moderator list.
*
* Returns true on success.
*/
non_null()
bool mod_list_remove_entry(Moderation *moderation, const uint8_t *public_sig_key);
bool mod_list_remove_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_sig_key);
/** @brief Adds a mod to the moderator list.
*
@@ -157,17 +150,13 @@ bool mod_list_remove_entry(Moderation *moderation, const uint8_t *public_sig_key
*
* Returns true on success.
*/
non_null()
bool mod_list_add_entry(Moderation *moderation, const uint8_t *mod_data);
bool mod_list_add_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull mod_data);
/** @return true if the public signature key belongs to a moderator or the founder */
non_null()
bool mod_list_verify_sig_pk(const Moderation *moderation, const uint8_t *sig_pk);
bool mod_list_verify_sig_pk(const Moderation *_Nonnull moderation, const uint8_t *_Nonnull sig_pk);
/** @brief Frees all memory associated with the moderator list and sets num_mods to 0. */
nullable(1)
void mod_list_cleanup(Moderation *moderation);
void mod_list_cleanup(Moderation *_Nullable moderation);
/** @brief Returns the size in bytes of num_sanctions packed sanctions. */
uint16_t sanctions_list_packed_size(uint16_t num_sanctions);
@@ -184,10 +173,8 @@ uint16_t sanctions_list_packed_size(uint16_t num_sanctions);
* @retval The length of packed data on success.
* @retval -1 on failure.
*/
non_null(1) nullable(3, 5)
int sanctions_list_pack(uint8_t *data, uint16_t length, const Mod_Sanction *sanctions, uint16_t num_sanctions,
const Mod_Sanction_Creds *creds);
int sanctions_list_pack(uint8_t *_Nonnull data, uint16_t length, const Mod_Sanction *_Nullable sanctions, uint16_t num_sanctions,
const Mod_Sanction_Creds *_Nullable creds);
/** @brief Unpacks sanctions and new sanctions credentials.
*
* @param sanctions The sanctions array the sanctions data is unpacked into.
@@ -200,18 +187,15 @@ int sanctions_list_pack(uint8_t *data, uint16_t length, const Mod_Sanction *sanc
* @retval The number of unpacked entries on success.
* @retval -1 on failure.
*/
non_null(1, 2, 4) nullable(6)
int sanctions_list_unpack(Mod_Sanction *sanctions, Mod_Sanction_Creds *creds, uint16_t max_sanctions,
const uint8_t *data, uint16_t length, uint16_t *processed_data_len);
int sanctions_list_unpack(Mod_Sanction *_Nonnull sanctions, Mod_Sanction_Creds *_Nonnull creds, uint16_t max_sanctions,
const uint8_t *_Nonnull data, uint16_t length, uint16_t *_Nullable processed_data_len);
/** @brief Packs sanction list credentials into data.
*
* @param data must have room for MOD_SANCTIONS_CREDS_SIZE bytes.
*
* Returns length of packed data.
*/
non_null()
uint16_t sanctions_creds_pack(const Mod_Sanction_Creds *creds, uint8_t *data);
uint16_t sanctions_creds_pack(const Mod_Sanction_Creds *_Nonnull creds, uint8_t *_Nonnull data);
/** @brief Unpacks sanctions credentials into creds from data.
*
@@ -219,8 +203,7 @@ uint16_t sanctions_creds_pack(const Mod_Sanction_Creds *creds, uint8_t *data);
*
* Returns the length of the data processed.
*/
non_null()
uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *creds, const uint8_t *data);
uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *_Nonnull creds, const uint8_t *_Nonnull data);
/** @brief Updates sanction list credentials.
*
@@ -229,17 +212,14 @@ uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *creds, const uint8_t *data);
*
* Returns true on success.
*/
non_null()
bool sanctions_list_make_creds(Moderation *moderation);
bool sanctions_list_make_creds(Moderation *_Nonnull moderation);
/** @brief Validates all sanctions list entries as well as the list itself.
*
* Returns true if all entries are valid.
* Returns false if one or more entries are invalid.
*/
non_null()
bool sanctions_list_check_integrity(const Moderation *moderation, const Mod_Sanction_Creds *creds,
const Mod_Sanction *sanctions, uint16_t num_sanctions);
bool sanctions_list_check_integrity(const Moderation *_Nonnull moderation, const Mod_Sanction_Creds *_Nonnull creds, const Mod_Sanction *_Nonnull sanctions, uint16_t num_sanctions);
/** @brief Adds an entry to the sanctions list.
*
@@ -250,26 +230,20 @@ bool sanctions_list_check_integrity(const Moderation *moderation, const Mod_Sanc
*
* Returns true on success.
*/
non_null(1, 2) nullable(3)
bool sanctions_list_add_entry(Moderation *moderation, const Mod_Sanction *sanction, const Mod_Sanction_Creds *creds);
bool sanctions_list_add_entry(Moderation *_Nonnull moderation, const Mod_Sanction *_Nonnull sanction, const Mod_Sanction_Creds *_Nullable creds);
/** @brief Creates a new sanction entry for `public_key` where type is one of Mod_Sanction_Type.
*
* New entry is signed and placed in the sanctions list.
*
* Returns true on success.
*/
non_null()
bool sanctions_list_make_entry(Moderation *moderation, const uint8_t *public_key, Mod_Sanction *sanction,
uint8_t type);
bool sanctions_list_make_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key, Mod_Sanction *_Nonnull sanction, uint8_t type);
/** @return true if public key is in the observer list. */
non_null()
bool sanctions_list_is_observer(const Moderation *moderation, const uint8_t *public_key);
bool sanctions_list_is_observer(const Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key);
/** @return true if sanction already exists in the sanctions list. */
non_null()
bool sanctions_list_entry_exists(const Moderation *moderation, const Mod_Sanction *sanction);
bool sanctions_list_entry_exists(const Moderation *_Nonnull moderation, const Mod_Sanction *_Nonnull sanction);
/** @brief Removes observer entry for public key from sanction list.
*
@@ -277,21 +251,17 @@ bool sanctions_list_entry_exists(const Moderation *moderation, const Mod_Sanctio
*
* Returns false on failure or if entry was not found.
*/
non_null(1, 2) nullable(3)
bool sanctions_list_remove_observer(Moderation *moderation, const uint8_t *public_key,
const Mod_Sanction_Creds *creds);
bool sanctions_list_remove_observer(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_key,
const Mod_Sanction_Creds *_Nullable creds);
/** @brief Replaces all sanctions list signatures made by public_sig_key with the caller's.
*
* This is called whenever the founder demotes a moderator.
*
* Returns the number of entries re-signed.
*/
non_null()
uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *public_sig_key);
uint16_t sanctions_list_replace_sig(Moderation *_Nonnull moderation, const uint8_t *_Nonnull public_sig_key);
non_null()
void sanctions_list_cleanup(Moderation *moderation);
void sanctions_list_cleanup(Moderation *_Nonnull moderation);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -28,10 +28,8 @@ static_assert(GCA_ANNOUNCE_MAX_SIZE <= ONION_MAX_EXTRA_DATA_SIZE,
"GC_Announce does not fit into the onion packet extra data");
static pack_extra_data_cb pack_group_announces;
non_null()
static int pack_group_announces(void *object, const Logger *logger, const Memory *mem, const Mono_Time *mono_time,
uint8_t num_nodes, uint8_t *plain, uint16_t plain_size,
uint8_t *response, uint16_t response_size, uint16_t offset)
static int pack_group_announces(void *_Nonnull object, const Logger *_Nonnull logger, const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, uint8_t num_nodes,
uint8_t *_Nonnull plain, uint16_t plain_size, uint8_t *_Nonnull response, uint16_t response_size, uint16_t offset)
{
GC_Announces_List *gc_announces_list = (GC_Announces_List *)object;
GC_Public_Announce public_announce;

View File

@@ -12,14 +12,10 @@
#include "mem.h"
#include "onion_announce.h"
non_null()
void gca_onion_init(GC_Announces_List *group_announce, Onion_Announce *onion_a);
void gca_onion_init(GC_Announces_List *_Nonnull group_announce, Onion_Announce *_Nonnull onion_a);
non_null()
int create_gca_announce_request(
const Memory *mem, const Random *rng, uint8_t *packet, uint16_t max_packet_length,
const uint8_t *dest_client_id, const uint8_t *public_key, const uint8_t *secret_key,
const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
uint64_t sendback_data, const uint8_t *gc_data, uint16_t gc_data_length);
int create_gca_announce_request(const Memory *_Nonnull mem, const Random *_Nonnull rng, uint8_t *_Nonnull packet, uint16_t max_packet_length, const uint8_t *_Nonnull dest_client_id,
const uint8_t *_Nonnull public_key, const uint8_t *_Nonnull secret_key, const uint8_t *_Nonnull ping_id, const uint8_t *_Nonnull client_id, const uint8_t *_Nonnull data_public_key,
uint64_t sendback_data, const uint8_t *_Nonnull gc_data, uint16_t gc_data_length);
#endif /* C_TOXCORE_TOXCORE_GROUP_ONION_ANNOUNCE_H */

View File

@@ -74,8 +74,7 @@ bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out_enum)
}
}
non_null()
static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_state_values(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 8, nullptr)) {
LOGGER_ERROR(chat->log, "Group state values array malformed");
@@ -110,8 +109,7 @@ static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_state_bin(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_state_bin(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 5, nullptr)) {
LOGGER_ERROR(chat->log, "Group state binary array malformed");
@@ -138,8 +136,7 @@ static bool load_unpack_state_bin(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_topic_info(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_topic_info(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 6, nullptr)) {
LOGGER_ERROR(chat->log, "Group topic array malformed");
@@ -159,12 +156,11 @@ static bool load_unpack_topic_info(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_mod_list(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
uint32_t actual_size = 0;
if (!bin_unpack_array_fixed(bu, 2, &actual_size)) {
LOGGER_ERROR(chat->log, "Group mod list array malformed: %d != 2", actual_size);
LOGGER_ERROR(chat->log, "Group mod list array malformed: %u != 2", actual_size);
return false;
}
@@ -179,7 +175,7 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
}
if (chat->moderation.num_mods > MOD_MAX_NUM_MODERATORS) {
LOGGER_ERROR(chat->log, "moderation count %u exceeds maximum %u", chat->moderation.num_mods, MOD_MAX_NUM_MODERATORS);
LOGGER_ERROR(chat->log, "moderation count %u exceeds maximum %u", chat->moderation.num_mods, (unsigned int)MOD_MAX_NUM_MODERATORS);
chat->moderation.num_mods = MOD_MAX_NUM_MODERATORS;
}
@@ -209,8 +205,7 @@ static bool load_unpack_mod_list(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_keys(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_keys(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
LOGGER_ERROR(chat->log, "Group keys array malformed");
@@ -228,8 +223,7 @@ static bool load_unpack_keys(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_self_info(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 4, nullptr)) {
LOGGER_ERROR(chat->log, "Group self info array malformed");
@@ -281,8 +275,7 @@ static bool load_unpack_self_info(GC_Chat *chat, Bin_Unpack *bu)
return true;
}
non_null()
static bool load_unpack_saved_peers(GC_Chat *chat, Bin_Unpack *bu)
static bool load_unpack_saved_peers(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu)
{
if (!bin_unpack_array_fixed(bu, 2, nullptr)) {
LOGGER_ERROR(chat->log, "Group saved peers array malformed");
@@ -328,7 +321,7 @@ bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu)
{
uint32_t actual_size;
if (!bin_unpack_array_fixed(bu, 7, &actual_size)) {
LOGGER_ERROR(chat->log, "Group info array malformed: %d != 7", actual_size);
LOGGER_ERROR(chat->log, "Group info array malformed: %u != 7", actual_size);
return false;
}
@@ -341,8 +334,7 @@ bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu)
&& load_unpack_saved_peers(chat, bu);
}
non_null()
static void save_pack_state_values(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_state_values(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 8);
bin_pack_bool(bp, chat->connection_state == CS_DISCONNECTED); // 1
@@ -355,8 +347,7 @@ static void save_pack_state_values(const GC_Chat *chat, Bin_Pack *bp)
bin_pack_u08(bp, chat->shared_state.voice_state); // 8
}
non_null()
static void save_pack_state_bin(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_state_bin(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 5);
@@ -367,8 +358,7 @@ static void save_pack_state_bin(const GC_Chat *chat, Bin_Pack *bp)
bin_pack_bin(bp, chat->shared_state.mod_list_hash, MOD_MODERATION_HASH_SIZE); // 5
}
non_null()
static void save_pack_topic_info(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_topic_info(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 6);
@@ -380,8 +370,7 @@ static void save_pack_topic_info(const GC_Chat *chat, Bin_Pack *bp)
bin_pack_bin(bp, chat->topic_sig, SIGNATURE_SIZE); // 6
}
non_null()
static void save_pack_mod_list(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_mod_list(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 2);
@@ -414,8 +403,7 @@ static void save_pack_mod_list(const GC_Chat *chat, Bin_Pack *bp)
mem_delete(chat->mem, packed_mod_list);
}
non_null()
static void save_pack_keys(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_keys(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 4);
@@ -425,8 +413,7 @@ static void save_pack_keys(const GC_Chat *chat, Bin_Pack *bp)
pack_extended_secret_key(&chat->self_secret_key, bp); // 4
}
non_null()
static void save_pack_self_info(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_self_info(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 4);
@@ -443,8 +430,7 @@ static void save_pack_self_info(const GC_Chat *chat, Bin_Pack *bp)
bin_pack_bin(bp, self->nick, self->nick_length); // 4
}
non_null()
static void save_pack_saved_peers(const GC_Chat *chat, Bin_Pack *bp)
static void save_pack_saved_peers(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp)
{
bin_pack_array(bp, 2);

View File

@@ -21,8 +21,7 @@
* Packs group data from `chat` into `mp` in binary format. Parallel to the
* `gc_load_unpack_group` function.
*/
non_null()
void gc_save_pack_group(const GC_Chat *chat, Bin_Pack *bp);
void gc_save_pack_group(const GC_Chat *_Nonnull chat, Bin_Pack *_Nonnull bp);
/**
* Unpacks binary group data from `obj` into `chat`. Parallel to the `gc_save_pack_group`
@@ -30,12 +29,9 @@ void gc_save_pack_group(const GC_Chat *chat, Bin_Pack *bp);
*
* Return true if unpacking is successful.
*/
non_null()
bool gc_load_unpack_group(GC_Chat *chat, Bin_Unpack *bu);
bool gc_load_unpack_group(GC_Chat *_Nonnull chat, Bin_Unpack *_Nonnull bu);
non_null()
bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out_enum);
non_null()
bool group_voice_state_from_int(uint8_t value, Group_Voice_State *out_enum);
bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *_Nonnull out_enum);
bool group_voice_state_from_int(uint8_t value, Group_Voice_State *_Nonnull out_enum);
#endif /* C_TOXCORE_TOXCORE_GROUP_PACK_H */

View File

@@ -41,8 +41,7 @@ static int32_t list_index(uint32_t i)
* @retval <0 no match, returns index (return value is `list_index(index)`) where
* the data should be inserted
*/
non_null()
static int find(const BS_List *list, const uint8_t *data)
static int find(const BS_List *_Nonnull list, const uint8_t *_Nonnull data)
{
// should work well, but could be improved
if (list->n == 0) {
@@ -60,7 +59,7 @@ static int find(const BS_List *list, const uint8_t *data)
// closest match is found if we move back to where we have already been
while (true) {
const int r = list->cmp_callback(data, list->data + list->element_size * i, list->element_size);
const int r = list->cmp_callback(data, (const void *_Nonnull)(list->data + list->element_size * i), list->element_size);
if (r == 0) {
return i;
@@ -107,8 +106,7 @@ static int find(const BS_List *list, const uint8_t *data)
*
* @return true on success.
*/
non_null()
static bool resize(BS_List *list, uint32_t new_size)
static bool resize(BS_List *_Nonnull list, uint32_t new_size)
{
if (new_size == 0) {
bs_list_free(list);

View File

@@ -22,17 +22,17 @@
extern "C" {
#endif
typedef int bs_list_cmp_cb(const void *a, const void *b, size_t size);
typedef int bs_list_cmp_cb(const void *_Nonnull a, const void *_Nonnull b, size_t size);
typedef struct BS_List {
const Memory *mem;
const Memory *_Nonnull mem;
uint32_t n; // number of elements
uint32_t capacity; // number of elements memory is allocated for
uint32_t element_size; // size of the elements
uint8_t *data; // array of elements
int *ids; // array of element ids
bs_list_cmp_cb *cmp_callback;
uint8_t *_Nullable data; // array of elements
int *_Nullable ids; // array of element ids
bs_list_cmp_cb *_Nullable cmp_callback;
} BS_List;
/** @brief Initialize a list.
@@ -43,36 +43,30 @@ typedef struct BS_List {
* @retval 1 success
* @retval 0 failure
*/
non_null()
int bs_list_init(BS_List *list, const Memory *mem, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *cmp_callback);
int bs_list_init(BS_List *_Nonnull list, const Memory *_Nonnull mem, uint32_t element_size, uint32_t initial_capacity, bs_list_cmp_cb *_Nonnull cmp_callback);
/** Free a list initiated with list_init */
nullable(1)
void bs_list_free(BS_List *list);
void bs_list_free(BS_List *_Nullable list);
/** @brief Retrieve the id of an element in the list
*
* @retval >=0 id associated with data
* @retval -1 failure
*/
non_null()
int bs_list_find(const BS_List *list, const uint8_t *data);
int bs_list_find(const BS_List *_Nonnull list, const uint8_t *_Nonnull data);
/** @brief Add an element with associated id to the list
*
* @retval true success
* @retval false failure (data already in list)
*/
non_null()
bool bs_list_add(BS_List *list, const uint8_t *data, int id);
bool bs_list_add(BS_List *_Nonnull list, const uint8_t *_Nonnull data, int id);
/** @brief Remove element from the list
*
* @retval true success
* @retval false failure (element not found or id does not match)
*/
non_null()
bool bs_list_remove(BS_List *list, const uint8_t *data, int id);
bool bs_list_remove(BS_List *_Nonnull list, const uint8_t *_Nonnull data, int id);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -33,28 +33,23 @@ typedef enum Logger_Level {
typedef struct Logger Logger;
typedef void logger_cb(void *context, Logger_Level level, const char *file, uint32_t line,
const char *func, const char *message, void *userdata);
typedef void logger_cb(void *_Nullable context, Logger_Level level, const char *_Nonnull file, uint32_t line,
const char *_Nonnull func, const char *_Nonnull message, void *_Nullable userdata);
/**
* Creates a new logger with logging disabled (callback is NULL) by default.
*/
non_null()
Logger *logger_new(const Memory *mem);
Logger *_Nullable logger_new(const Memory *_Nonnull mem);
/**
* Frees all resources associated with the logger.
*/
nullable(1)
void logger_kill(Logger *log);
void logger_kill(Logger *_Nullable log);
/**
* Sets the logger callback. Disables logging if set to NULL.
* The context parameter is passed to the callback as first argument.
*/
non_null(1) nullable(2, 3, 4)
void logger_callback_log(Logger *log, logger_cb *function, void *context, void *userdata);
void logger_callback_log(Logger *_Nonnull log, logger_cb *_Nullable function, void *_Nullable context, void *_Nullable userdata);
/** @brief Main write function. If logging is disabled, this does nothing.
*
* If the logger is NULL and `NDEBUG` is not defined, this writes to stderr.
@@ -64,10 +59,8 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void *
*
* If `NDEBUG` is defined, the NULL logger does nothing.
*/
non_null(3, 5, 6) nullable(1) GNU_PRINTF(6, 7)
void logger_write(
const Logger *log, Logger_Level level, const char *file, uint32_t line, const char *func,
const char *format, ...);
GNU_PRINTF(6, 7)
void logger_write(const Logger *_Nullable log, Logger_Level level, const char *_Nonnull file, uint32_t line, const char *_Nonnull func, const char *_Nonnull format, ...);
/* @brief Terminate the program with a signal. */
void logger_abort(void);

View File

@@ -10,26 +10,22 @@
#include "attributes.h"
#include "ccompat.h"
nullable(1)
static void *sys_malloc(void *obj, uint32_t size)
static void *sys_malloc(void *_Nullable obj, uint32_t size)
{
return malloc(size);
}
nullable(1)
static void *sys_calloc(void *obj, uint32_t nmemb, uint32_t size)
static void *sys_calloc(void *_Nullable obj, uint32_t nmemb, uint32_t size)
{
return calloc(nmemb, size);
}
nullable(1, 2)
static void *sys_realloc(void *obj, void *ptr, uint32_t size)
static void *sys_realloc(void *_Nullable obj, void *_Nullable ptr, uint32_t size)
{
return realloc(ptr, size);
}
nullable(1, 2)
static void sys_free(void *obj, void *ptr)
static void sys_free(void *_Nullable obj, void *_Nullable ptr)
{
free(ptr);
}

View File

@@ -17,25 +17,25 @@
extern "C" {
#endif
typedef void *mem_malloc_cb(void *obj, uint32_t size);
typedef void *mem_calloc_cb(void *obj, uint32_t nmemb, uint32_t size);
typedef void *mem_realloc_cb(void *obj, void *ptr, uint32_t size);
typedef void mem_free_cb(void *obj, void *ptr);
typedef void *mem_malloc_cb(void *_Nullable obj, uint32_t size);
typedef void *mem_calloc_cb(void *_Nullable obj, uint32_t nmemb, uint32_t size);
typedef void *mem_realloc_cb(void *_Nullable obj, void *_Nullable ptr, uint32_t size);
typedef void mem_free_cb(void *_Nullable obj, void *_Nullable ptr);
/** @brief Functions wrapping standard C memory allocation functions. */
typedef struct Memory_Funcs {
mem_malloc_cb *malloc;
mem_calloc_cb *calloc;
mem_realloc_cb *realloc;
mem_free_cb *free;
mem_malloc_cb *_Nullable malloc;
mem_calloc_cb *_Nullable calloc;
mem_realloc_cb *_Nullable realloc;
mem_free_cb *_Nullable free;
} Memory_Funcs;
typedef struct Memory {
const Memory_Funcs *funcs;
void *obj;
const Memory_Funcs *_Nullable funcs;
void *_Nullable obj;
} Memory;
const Memory *os_memory(void);
const Memory *_Nullable os_memory(void);
/**
* @brief Allocate an array of a given size for built-in types.
@@ -43,7 +43,7 @@ const Memory *os_memory(void);
* The array will not be initialised. Supported built-in types are
* `uint8_t`, `int8_t`, and `int16_t`.
*/
non_null() void *mem_balloc(const Memory *mem, uint32_t size);
void *_Nullable mem_balloc(const Memory *_Nonnull mem, uint32_t size);
/**
* @brief Resize an array of a given size for built-in types.
@@ -51,21 +51,21 @@ non_null() void *mem_balloc(const Memory *mem, uint32_t size);
* If used for a type other than byte-sized types, `size` needs to be manually
* multiplied by the element size.
*/
non_null(1) nullable(2) void *mem_brealloc(const Memory *mem, void *ptr, uint32_t size);
void *_Nullable mem_brealloc(const Memory *_Nonnull mem, void *_Nullable ptr, uint32_t size);
/**
* @brief Allocate a single object.
*
* Always use as `(T *)mem_alloc(mem, sizeof(T))`.
*/
non_null() void *mem_alloc(const Memory *mem, uint32_t size);
void *_Nullable mem_alloc(const Memory *_Nonnull mem, uint32_t size);
/**
* @brief Allocate a vector (array) of objects.
*
* Always use as `(T *)mem_valloc(mem, N, sizeof(T))`.
*/
non_null() void *mem_valloc(const Memory *mem, uint32_t nmemb, uint32_t size);
void *_Nullable mem_valloc(const Memory *_Nonnull mem, uint32_t nmemb, uint32_t size);
/**
* @brief Resize an object vector.
@@ -82,10 +82,10 @@ non_null() void *mem_valloc(const Memory *mem, uint32_t nmemb, uint32_t size);
* case where the multiplication would overflow. If such an overflow occurs,
* `mem_vrealloc()` returns `nullptr`.
*/
non_null(1) nullable(2) void *mem_vrealloc(const Memory *mem, void *ptr, uint32_t nmemb, uint32_t size);
void *_Nullable mem_vrealloc(const Memory *_Nonnull mem, void *_Nullable ptr, uint32_t nmemb, uint32_t size);
/** @brief Free an array, object, or object vector. */
non_null(1) nullable(2) void mem_delete(const Memory *mem, void *ptr);
void mem_delete(const Memory *_Nonnull mem, void *_Nullable ptr);
#ifdef __cplusplus
} /* extern "C" */

View File

@@ -57,8 +57,7 @@ static uint64_t timespec_to_u64(struct timespec clock_mono)
}
#ifdef OS_WIN32
non_null()
static uint64_t current_time_monotonic_default(void *user_data)
static uint64_t current_time_monotonic_default(void *_Nonnull user_data)
{
LARGE_INTEGER freq;
LARGE_INTEGER count;
@@ -79,8 +78,7 @@ static uint64_t current_time_monotonic_default(void *user_data)
}
#else
#ifdef __APPLE__
non_null()
static uint64_t current_time_monotonic_default(void *user_data)
static uint64_t current_time_monotonic_default(void *_Nonnull user_data)
{
struct timespec clock_mono;
clock_serv_t muhclock;
@@ -95,8 +93,7 @@ static uint64_t current_time_monotonic_default(void *user_data)
return timespec_to_u64(clock_mono);
}
#else // !__APPLE__
non_null()
static uint64_t current_time_monotonic_default(void *user_data)
static uint64_t current_time_monotonic_default(void *_Nonnull user_data)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
// This assert should always fail. If it does, the fuzzing harness didn't

View File

@@ -46,48 +46,39 @@ extern "C" {
*/
typedef struct Mono_Time Mono_Time;
typedef uint64_t mono_time_current_time_cb(void *user_data);
non_null(1) nullable(2, 3)
Mono_Time *mono_time_new(const Memory *mem, mono_time_current_time_cb *current_time_callback, void *user_data);
non_null(1) nullable(2)
void mono_time_free(const Memory *mem, Mono_Time *mono_time);
typedef uint64_t mono_time_current_time_cb(void *_Nullable user_data);
Mono_Time *_Nullable mono_time_new(const Memory *_Nonnull mem, mono_time_current_time_cb *_Nullable current_time_callback, void *_Nullable user_data);
void mono_time_free(const Memory *_Nonnull mem, Mono_Time *_Nullable mono_time);
/**
* Update mono_time; subsequent calls to mono_time_get or mono_time_is_timeout
* will use the time at the call to mono_time_update.
*/
non_null()
void mono_time_update(Mono_Time *mono_time);
void mono_time_update(Mono_Time *_Nonnull mono_time);
/** @brief Return current monotonic time in milliseconds (ms).
*
* The starting point is UNIX epoch as measured by `time()` in `mono_time_new()`.
*/
non_null()
uint64_t mono_time_get_ms(const Mono_Time *mono_time);
uint64_t mono_time_get_ms(const Mono_Time *_Nonnull mono_time);
/** @brief Return a monotonically increasing time in seconds.
*
* The starting point is UNIX epoch as measured by `time()` in `mono_time_new()`.
*/
non_null()
uint64_t mono_time_get(const Mono_Time *mono_time);
uint64_t mono_time_get(const Mono_Time *_Nonnull mono_time);
/**
* Return true iff timestamp is at least timeout seconds in the past.
*/
non_null()
bool mono_time_is_timeout(const Mono_Time *mono_time, uint64_t timestamp, uint64_t timeout);
bool mono_time_is_timeout(const Mono_Time *_Nonnull mono_time, uint64_t timestamp, uint64_t timeout);
/** @brief Return current monotonic time in milliseconds (ms).
*
* The starting point is unspecified and in particular is likely not comparable
* to the return value of `mono_time_get_ms()`.
*/
non_null()
uint64_t current_time_monotonic(const Mono_Time *mono_time);
uint64_t current_time_monotonic(const Mono_Time *_Nonnull mono_time);
/**
* Override implementation of `current_time_monotonic()` (for tests).
@@ -95,10 +86,8 @@ uint64_t current_time_monotonic(const Mono_Time *mono_time);
* The caller is obligated to ensure that `current_time_monotonic()` continues
* to increase monotonically.
*/
non_null(1) nullable(2, 3)
void mono_time_set_current_time_callback(Mono_Time *mono_time,
mono_time_current_time_cb *current_time_callback, void *user_data);
void mono_time_set_current_time_callback(Mono_Time *_Nonnull mono_time,
mono_time_current_time_cb *_Nullable current_time_callback, void *_Nullable user_data);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -181,8 +181,7 @@ DHT *nc_get_dht(const Net_Crypto *c)
return c->dht;
}
non_null()
static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connection_id)
static bool crypt_connection_id_is_valid(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) {
return false;
@@ -216,9 +215,7 @@ static bool crypt_connection_id_is_valid(const Net_Crypto *c, int crypt_connecti
* @retval -1 on failure.
* @retval COOKIE_REQUEST_LENGTH on success.
*/
non_null()
static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uint8_t *dht_public_key,
uint64_t number, uint8_t *shared_key)
static int create_cookie_request(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull packet, const uint8_t *_Nonnull dht_public_key, uint64_t number, uint8_t *_Nonnull shared_key)
{
uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH];
@@ -247,9 +244,8 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, const uin
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int create_cookie(const Memory *mem, const Random *rng, const Mono_Time *mono_time, uint8_t *cookie, const uint8_t *bytes,
const uint8_t *encryption_key)
static int create_cookie(const Memory *_Nonnull mem, const Random *_Nonnull rng, const Mono_Time *_Nonnull mono_time, uint8_t *_Nonnull cookie, const uint8_t *_Nonnull bytes,
const uint8_t *_Nonnull encryption_key)
{
uint8_t contents[COOKIE_CONTENTS_LENGTH];
const uint64_t temp_time = mono_time_get(mono_time);
@@ -270,9 +266,7 @@ static int create_cookie(const Memory *mem, const Random *rng, const Mono_Time *
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int open_cookie(const Memory *mem, const Mono_Time *mono_time, uint8_t *bytes, const uint8_t *cookie,
const uint8_t *encryption_key)
static int open_cookie(const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, uint8_t *_Nonnull bytes, const uint8_t *_Nonnull cookie, const uint8_t *_Nonnull encryption_key)
{
uint8_t contents[COOKIE_CONTENTS_LENGTH];
const int len = decrypt_data_symmetric(mem, encryption_key, cookie, cookie + CRYPTO_NONCE_SIZE,
@@ -301,9 +295,8 @@ static int open_cookie(const Memory *mem, const Mono_Time *mono_time, uint8_t *b
* @retval -1 on failure.
* @retval COOKIE_RESPONSE_LENGTH on success.
*/
non_null()
static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const uint8_t *request_plain,
const uint8_t *shared_key, const uint8_t *dht_public_key)
static int create_cookie_response(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull packet, const uint8_t *_Nonnull request_plain, const uint8_t *_Nonnull shared_key,
const uint8_t *_Nonnull dht_public_key)
{
uint8_t cookie_plain[COOKIE_DATA_LENGTH];
memcpy(cookie_plain, request_plain, CRYPTO_PUBLIC_KEY_SIZE);
@@ -333,9 +326,8 @@ static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const ui
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key,
uint8_t *dht_public_key, const uint8_t *packet, uint16_t length)
static int handle_cookie_request(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull request_plain, uint8_t *_Nonnull shared_key, uint8_t *_Nonnull dht_public_key,
const uint8_t *_Nonnull packet, uint16_t length)
{
if (length != COOKIE_REQUEST_LENGTH) {
return -1;
@@ -356,9 +348,8 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
}
/** Handle the cookie request packet (for raw UDP) */
non_null(1, 2, 3) nullable(5)
static int udp_handle_cookie_request(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int udp_handle_cookie_request(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
const Net_Crypto *c = (const Net_Crypto *)object;
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
@@ -383,9 +374,7 @@ static int udp_handle_cookie_request(void *object, const IP_Port *source, const
}
/** Handle the cookie request packet (for TCP) */
non_null()
static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number, const uint8_t *packet,
uint16_t length)
static int tcp_handle_cookie_request(const Net_Crypto *_Nonnull c, int connections_number, const uint8_t *_Nonnull packet, uint16_t length)
{
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
@@ -406,9 +395,8 @@ static int tcp_handle_cookie_request(const Net_Crypto *c, int connections_number
}
/** Handle the cookie request packet (for TCP oob packets) */
non_null()
static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_connections_number,
const uint8_t *dht_public_key, const uint8_t *packet, uint16_t length)
static int tcp_oob_handle_cookie_request(const Net_Crypto *_Nonnull c, unsigned int tcp_connections_number, const uint8_t *_Nonnull dht_public_key, const uint8_t *_Nonnull packet,
uint16_t length)
{
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
@@ -440,10 +428,8 @@ static int tcp_oob_handle_cookie_request(const Net_Crypto *c, unsigned int tcp_c
* @retval -1 on failure.
* @retval COOKIE_LENGTH on success.
*/
non_null()
static int handle_cookie_response(const Memory *mem, uint8_t *cookie, uint64_t *number,
const uint8_t *packet, uint16_t length,
const uint8_t *shared_key)
static int handle_cookie_response(const Memory *_Nonnull mem, uint8_t *_Nonnull cookie, uint64_t *_Nonnull number, const uint8_t *_Nonnull packet, uint16_t length,
const uint8_t *_Nonnull shared_key)
{
if (length != COOKIE_RESPONSE_LENGTH) {
return -1;
@@ -471,9 +457,8 @@ static int handle_cookie_response(const Memory *mem, uint8_t *cookie, uint64_t *
* @retval -1 on failure.
* @retval HANDSHAKE_PACKET_LENGTH on success.
*/
non_null()
static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const uint8_t *cookie, const uint8_t *nonce,
const uint8_t *session_pk, const uint8_t *peer_real_pk, const uint8_t *peer_dht_pubkey)
static int create_crypto_handshake(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull packet, const uint8_t *_Nonnull cookie, const uint8_t *_Nonnull nonce, const uint8_t *_Nonnull session_pk,
const uint8_t *_Nonnull peer_real_pk, const uint8_t *_Nonnull peer_dht_pubkey)
{
uint8_t plain[CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SHA512_SIZE + COOKIE_LENGTH];
memcpy(plain, nonce, CRYPTO_NONCE_SIZE);
@@ -520,9 +505,8 @@ static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const u
* @retval false on failure.
* @retval true on success.
*/
non_null(1, 2, 3, 4, 5, 6, 7) nullable(9)
static bool handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint16_t length, const uint8_t *expected_real_pk)
static bool handle_crypto_handshake(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull nonce, uint8_t *_Nonnull session_pk, uint8_t *_Nonnull peer_real_pk,
uint8_t *_Nonnull dht_public_key, uint8_t *_Nonnull cookie, const uint8_t *_Nonnull packet, uint16_t length, const uint8_t *_Nullable expected_real_pk)
{
if (length != HANDSHAKE_PACKET_LENGTH) {
return false;
@@ -562,8 +546,7 @@ static bool handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
return true;
}
non_null()
static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
static Crypto_Connection *get_crypto_connection(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
if (!crypt_connection_id_is_valid(c, crypt_connection_id)) {
return nullptr;
@@ -577,8 +560,7 @@ static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_c
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port)
static int add_ip_port_connection(Net_Crypto *_Nonnull c, int crypt_connection_id, const IP_Port *_Nonnull ip_port)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -616,8 +598,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, const
* @retval IP_Port with family 0 on failure.
* @return IP_Port on success.
*/
non_null()
static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connection_id)
static IP_Port return_ip_port_connection(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
const IP_Port empty = {{{0}}};
@@ -674,8 +655,7 @@ static IP_Port return_ip_port_connection(const Net_Crypto *c, int crypt_connecti
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
static int send_packet_to(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull data, uint16_t length)
{
// TODO(irungentoo): TCP, etc...
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -734,8 +714,7 @@ static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const ui
/** @brief Return number of packets in array
* Note that holes are counted too.
*/
non_null()
static uint32_t num_packets_array(const Packets_Array *array)
static uint32_t num_packets_array(const Packets_Array *_Nonnull array)
{
return array->buffer_end - array->buffer_start;
}
@@ -745,8 +724,7 @@ static uint32_t num_packets_array(const Packets_Array *array)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int add_data_to_buffer(const Memory *mem, Packets_Array *array, uint32_t number, const Packet_Data *data)
static int add_data_to_buffer(const Memory *_Nonnull mem, Packets_Array *_Nonnull array, uint32_t number, const Packet_Data *_Nonnull data)
{
if (number - array->buffer_start >= CRYPTO_PACKET_BUFFER_SIZE) {
return -1;
@@ -780,8 +758,7 @@ static int add_data_to_buffer(const Memory *mem, Packets_Array *array, uint32_t
* @retval 0 if data at number is empty.
* @retval 1 if data pointer was put in data.
*/
non_null()
static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number)
static int get_data_pointer(const Packets_Array *_Nonnull array, Packet_Data *_Nonnull *_Nonnull data, uint32_t number)
{
const uint32_t num_spots = num_packets_array(array);
@@ -804,8 +781,7 @@ static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint
* @retval -1 on failure.
* @return packet number on success.
*/
non_null()
static int64_t add_data_end_of_buffer(const Logger *logger, const Memory *mem, Packets_Array *array, const Packet_Data *data)
static int64_t add_data_end_of_buffer(const Logger *_Nonnull logger, const Memory *_Nonnull mem, Packets_Array *_Nonnull array, const Packet_Data *_Nonnull data)
{
const uint32_t num_spots = num_packets_array(array);
@@ -833,8 +809,7 @@ static int64_t add_data_end_of_buffer(const Logger *logger, const Memory *mem, P
* @retval -1 on failure.
* @return packet number on success.
*/
non_null()
static int64_t read_data_beg_buffer(const Memory *mem, Packets_Array *array, Packet_Data *data)
static int64_t read_data_beg_buffer(const Memory *_Nonnull mem, Packets_Array *_Nonnull array, Packet_Data *_Nonnull data)
{
if (array->buffer_end == array->buffer_start) {
return -1;
@@ -859,8 +834,7 @@ static int64_t read_data_beg_buffer(const Memory *mem, Packets_Array *array, Pac
* @retval -1 on failure.
* @retval 0 on success
*/
non_null()
static int clear_buffer_until(const Memory *mem, Packets_Array *array, uint32_t number)
static int clear_buffer_until(const Memory *_Nonnull mem, Packets_Array *_Nonnull array, uint32_t number)
{
const uint32_t num_spots = num_packets_array(array);
@@ -883,8 +857,7 @@ static int clear_buffer_until(const Memory *mem, Packets_Array *array, uint32_t
return 0;
}
non_null()
static int clear_buffer(const Memory *mem, Packets_Array *array)
static int clear_buffer(const Memory *_Nonnull mem, Packets_Array *_Nonnull array)
{
uint32_t i;
@@ -906,8 +879,7 @@ static int clear_buffer(const Memory *mem, Packets_Array *array)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int set_buffer_end(Packets_Array *array, uint32_t number)
static int set_buffer_end(Packets_Array *_Nonnull array, uint32_t number)
{
if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE) {
return -1;
@@ -928,8 +900,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number)
* @retval -1 on failure.
* @return length of packet on success.
*/
non_null()
static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array)
static int generate_request_packet(uint8_t *_Nonnull data, uint16_t length, const Packets_Array *_Nonnull recv_array)
{
if (length == 0) {
return -1;
@@ -982,10 +953,8 @@ static int generate_request_packet(uint8_t *data, uint16_t length, const Packets
* @retval -1 on failure.
* @return number of requested packets on success.
*/
non_null()
static int handle_request_packet(const Memory *mem, const Mono_Time *mono_time, Packets_Array *send_array,
const uint8_t *data, uint16_t length,
uint64_t *latest_send_time, uint64_t rtt_time)
static int handle_request_packet(const Memory *_Nonnull mem, const Mono_Time *_Nonnull mono_time, Packets_Array *_Nonnull send_array, const uint8_t *_Nonnull data, uint16_t length,
uint64_t *_Nonnull latest_send_time, uint64_t rtt_time)
{
if (length == 0) {
return -1;
@@ -1065,8 +1034,7 @@ static int handle_request_packet(const Memory *mem, const Mono_Time *mono_time,
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_data_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
static int send_data_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull data, uint16_t length)
{
const uint16_t max_length = MAX_CRYPTO_PACKET_SIZE - (1 + sizeof(uint16_t) + CRYPTO_MAC_SIZE);
@@ -1103,9 +1071,7 @@ static int send_data_packet(const Net_Crypto *c, int crypt_connection_id, const
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
const uint8_t *data, uint16_t length)
static int send_data_packet_helper(const Net_Crypto *_Nonnull c, int crypt_connection_id, uint32_t buffer_start, uint32_t num, const uint8_t *_Nonnull data, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) {
LOGGER_ERROR(c->log, "zero-length or too large data packet: %d (max: %d)", length, MAX_CRYPTO_PACKET_SIZE);
@@ -1125,8 +1091,7 @@ static int send_data_packet_helper(const Net_Crypto *c, int crypt_connection_id,
return send_data_packet(c, crypt_connection_id, packet, packet_size);
}
non_null()
static int reset_max_speed_reached(const Net_Crypto *c, int crypt_connection_id)
static int reset_max_speed_reached(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1160,9 +1125,7 @@ static int reset_max_speed_reached(const Net_Crypto *c, int crypt_connection_id)
* @retval -1 if data could not be put in packet queue.
* @return positive packet number if data was put into the queue.
*/
non_null()
static int64_t send_lossless_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length,
bool congestion_control)
static int64_t send_lossless_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull data, uint16_t length, bool congestion_control)
{
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) {
LOGGER_ERROR(c->log, "rejecting too large (or empty) packet of size %d on crypt connection %d", length,
@@ -1217,8 +1180,7 @@ static int64_t send_lossless_packet(const Net_Crypto *c, int crypt_connection_id
* @brief Get the lowest 2 bytes from the nonce and convert
* them to host byte format before returning them.
*/
non_null()
static uint16_t get_nonce_uint16(const uint8_t *nonce)
static uint16_t get_nonce_uint16(const uint8_t *_Nonnull nonce)
{
uint16_t num;
memcpy(&num, nonce + (CRYPTO_NONCE_SIZE - sizeof(uint16_t)), sizeof(uint16_t));
@@ -1234,9 +1196,7 @@ static uint16_t get_nonce_uint16(const uint8_t *nonce)
* @retval -1 on failure.
* @return length of data on success.
*/
non_null()
static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet,
uint16_t length)
static int handle_data_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id, uint8_t *_Nonnull data, const uint8_t *_Nonnull packet, uint16_t length)
{
const uint16_t crypto_packet_overhead = 1 + sizeof(uint16_t) + CRYPTO_MAC_SIZE;
@@ -1276,8 +1236,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_request_packet(const Net_Crypto *c, int crypt_connection_id)
static int send_request_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1301,8 +1260,7 @@ static int send_request_packet(const Net_Crypto *c, int crypt_connection_id)
* @retval -1 on failure.
* @return number of packets sent on success.
*/
non_null()
static int send_requested_packets(const Net_Crypto *c, int crypt_connection_id, uint32_t max_num)
static int send_requested_packets(const Net_Crypto *_Nonnull c, int crypt_connection_id, uint32_t max_num)
{
if (max_num == 0) {
return -1;
@@ -1354,8 +1312,7 @@ static int send_requested_packets(const Net_Crypto *c, int crypt_connection_id,
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
static int new_temp_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
return -1;
@@ -1390,8 +1347,7 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
static int clear_temp_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1415,8 +1371,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_temp_packet(const Net_Crypto *c, int crypt_connection_id)
static int send_temp_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1443,9 +1398,7 @@ static int send_temp_packet(const Net_Crypto *c, int crypt_connection_id)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int create_send_handshake(const Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie,
const uint8_t *dht_public_key)
static int create_send_handshake(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull cookie, const uint8_t *_Nonnull dht_public_key)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1473,8 +1426,7 @@ static int create_send_handshake(const Net_Crypto *c, int crypt_connection_id, c
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int send_kill_packet(const Net_Crypto *c, int crypt_connection_id)
static int send_kill_packet(const Net_Crypto *_Nonnull c, int crypt_connection_id)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1487,11 +1439,9 @@ static int send_kill_packet(const Net_Crypto *c, int crypt_connection_id)
kill_packet, sizeof(kill_packet));
}
non_null(1) nullable(3)
static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userdata)
static void connection_kill(Net_Crypto *_Nonnull c, int crypt_connection_id, void *_Nullable userdata)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == nullptr) {
return;
}
@@ -1509,9 +1459,8 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null(1, 3) nullable(6)
static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
static int handle_data_packet_core(Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length,
bool udp, void *_Nullable userdata)
{
if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) {
return -1;
@@ -1648,8 +1597,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
return 0;
}
non_null()
static int handle_packet_cookie_response(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
static int handle_packet_cookie_response(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1680,12 +1628,10 @@ static int handle_packet_cookie_response(const Net_Crypto *c, int crypt_connecti
return 0;
}
non_null(1, 3) nullable(5)
static int handle_packet_crypto_hs(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
void *userdata)
static int handle_packet_crypto_hs(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == nullptr) {
return -1;
}
@@ -1724,12 +1670,10 @@ static int handle_packet_crypto_hs(const Net_Crypto *c, int crypt_connection_id,
return 0;
}
non_null(1, 3) nullable(6)
static int handle_packet_crypto_data(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
static int handle_packet_crypto_data(Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length,
bool udp, void *_Nullable userdata)
{
const Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == nullptr) {
return -1;
}
@@ -1746,9 +1690,8 @@ static int handle_packet_crypto_data(Net_Crypto *c, int crypt_connection_id, con
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null(1, 3) nullable(6)
static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length,
bool udp, void *userdata)
static int handle_packet_connection(Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length,
bool udp, void *_Nullable userdata)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
return -1;
@@ -1774,8 +1717,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
* @retval -1 if mem_vrealloc fails.
* @retval 0 if it succeeds.
*/
non_null()
static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
static int realloc_cryptoconnection(Net_Crypto *_Nonnull c, uint32_t num)
{
if (num == 0) {
mem_delete(c->mem, c->crypto_connections);
@@ -1799,8 +1741,7 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
* @retval -1 on failure.
* @return connection id on success.
*/
non_null()
static int create_crypto_connection(Net_Crypto *c)
static int create_crypto_connection(Net_Crypto *_Nonnull c)
{
int id = -1;
@@ -1839,8 +1780,7 @@ static int create_crypto_connection(Net_Crypto *c)
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null()
static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
static int wipe_crypto_connection(Net_Crypto *_Nonnull c, int crypt_connection_id)
{
if ((uint32_t)crypt_connection_id >= c->crypto_connections_length) {
return -1;
@@ -1880,8 +1820,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
* @retval -1 if there are no connections like we are looking for.
* @return id if it found it.
*/
non_null()
static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
static int getcryptconnection_id(const Net_Crypto *_Nonnull c, const uint8_t *_Nonnull public_key)
{
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
if (!crypt_connection_id_is_valid(c, i)) {
@@ -1903,8 +1842,7 @@ static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
* @retval 0 if source was a direct UDP connection.
* @return positive number on success.
*/
non_null()
static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, const IP_Port *source)
static int crypto_connection_add_source(Net_Crypto *_Nonnull c, int crypt_connection_id, const IP_Port *_Nonnull source)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@@ -1955,12 +1893,10 @@ void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_cal
* @retval -1 on failure.
* @retval 0 on success.
*/
non_null(1, 2, 3) nullable(5)
static int handle_new_connection_handshake(Net_Crypto *c, const IP_Port *source, const uint8_t *data, uint16_t length,
void *userdata)
static int handle_new_connection_handshake(Net_Crypto *_Nonnull c, const IP_Port *_Nonnull source, const uint8_t *_Nonnull data, uint16_t length,
void *_Nullable userdata)
{
uint8_t *cookie = (uint8_t *)mem_balloc(c->mem, COOKIE_LENGTH);
if (cookie == nullptr) {
return -1;
}
@@ -2155,12 +2091,10 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
return 0;
}
non_null(1, 3) nullable(5)
static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_t *packet, uint16_t length,
void *userdata)
static int tcp_data_callback(void *_Nonnull object, int crypt_connection_id, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
Net_Crypto *c = (Net_Crypto *)object;
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
return -1;
}
@@ -2185,12 +2119,10 @@ static int tcp_data_callback(void *object, int crypt_connection_id, const uint8_
return 0;
}
non_null(1, 2, 4) nullable(6)
static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned int tcp_connections_number,
const uint8_t *packet, uint16_t length, void *userdata)
static int tcp_oob_callback(void *_Nonnull object, const uint8_t *_Nonnull public_key, unsigned int tcp_connections_number,
const uint8_t *_Nonnull packet, uint16_t length, void *_Nullable userdata)
{
Net_Crypto *c = (Net_Crypto *)object;
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE) {
return -1;
}
@@ -2312,8 +2244,7 @@ uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_r
return tcp_copy_connected_relays_index(c->tcp_c, tcp_relays, num, idx);
}
non_null()
static void do_tcp(Net_Crypto *c, void *userdata)
static void do_tcp(Net_Crypto *_Nonnull c, void *_Nonnull userdata)
{
do_tcp_connections(c->log, c->tcp_c, userdata);
@@ -2439,8 +2370,7 @@ int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id, dht_pk_cb *
* return -1 on failure.
* return connection id on success.
*/
non_null()
static int crypto_id_ip_port(const Net_Crypto *c, const IP_Port *ip_port)
static int crypto_id_ip_port(const Net_Crypto *_Nonnull c, const IP_Port *_Nonnull ip_port)
{
return bs_list_find(&c->ip_port_list, (const uint8_t *)ip_port);
}
@@ -2455,12 +2385,10 @@ static int crypto_id_ip_port(const Net_Crypto *c, const IP_Port *ip_port)
* Crypto data packets.
*
*/
non_null(1, 2, 3) nullable(5)
static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t *packet, uint16_t length,
void *userdata)
static int udp_handle_packet(void *_Nonnull object, const IP_Port *_Nonnull source, const uint8_t *_Nonnull packet, uint16_t length,
void *_Nullable userdata)
{
Net_Crypto *c = (Net_Crypto *)object;
if (length <= CRYPTO_MIN_PACKET_SIZE || length > MAX_CRYPTO_PACKET_SIZE) {
return 1;
}
@@ -2518,8 +2446,7 @@ static int udp_handle_packet(void *object, const IP_Port *source, const uint8_t
*/
#define SEND_QUEUE_RATIO 2.0
non_null()
static void send_crypto_packets(Net_Crypto *c)
static void send_crypto_packets(Net_Crypto *_Nonnull c)
{
const uint64_t temp_time = current_time_monotonic(c->mono_time);
double total_send_rate = 0;
@@ -3033,12 +2960,10 @@ Net_Crypto *new_net_crypto(const Logger *log, const Memory *mem, const Random *r
return temp;
}
non_null(1) nullable(2)
static void kill_timedout(Net_Crypto *c, void *userdata)
static void kill_timedout(Net_Crypto *_Nonnull c, void *_Nullable userdata)
{
for (uint32_t i = 0; i < c->crypto_connections_length; ++i) {
const Crypto_Connection *conn = get_crypto_connection(c, i);
if (conn == nullptr) {
continue;
}

View File

@@ -123,10 +123,10 @@ typedef enum Packet_Id {
typedef struct Net_Crypto Net_Crypto;
non_null() const uint8_t *nc_get_self_public_key(const Net_Crypto *c);
non_null() const uint8_t *nc_get_self_secret_key(const Net_Crypto *c);
non_null() TCP_Connections *nc_get_tcp_c(const Net_Crypto *c);
non_null() DHT *nc_get_dht(const Net_Crypto *c);
const uint8_t *_Nonnull nc_get_self_public_key(const Net_Crypto *_Nonnull c);
const uint8_t *_Nonnull nc_get_self_secret_key(const Net_Crypto *_Nonnull c);
TCP_Connections *_Nonnull nc_get_tcp_c(const Net_Crypto *_Nonnull c);
DHT *_Nonnull nc_get_dht(const Net_Crypto *_Nonnull c);
typedef struct New_Connection {
IP_Port source;
@@ -134,15 +134,15 @@ typedef struct New_Connection {
uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The dht public key of the peer. */
uint8_t recv_nonce[CRYPTO_NONCE_SIZE]; /* Nonce of received packets. */
uint8_t peersessionpublic_key[CRYPTO_PUBLIC_KEY_SIZE]; /* The public key of the peer. */
uint8_t *cookie;
uint8_t *_Nullable cookie;
uint8_t cookie_length;
} New_Connection;
typedef int connection_status_cb(void *object, int id, bool status, void *userdata);
typedef int connection_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
typedef int connection_lossy_data_cb(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
typedef void dht_pk_cb(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata);
typedef int new_connection_cb(void *object, const New_Connection *n_c);
typedef int connection_status_cb(void *_Nonnull object, int id, bool status, void *_Nullable userdata);
typedef int connection_data_cb(void *_Nonnull object, int id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
typedef int connection_lossy_data_cb(void *_Nonnull object, int id, const uint8_t *_Nonnull data, uint16_t length, void *_Nullable userdata);
typedef void dht_pk_cb(void *_Nonnull object, int32_t number, const uint8_t *_Nonnull dht_public_key, void *_Nullable userdata);
typedef int new_connection_cb(void *_Nonnull object, const New_Connection *_Nonnull n_c);
/** @brief Set function to be called when someone requests a new connection to us.
*
@@ -150,16 +150,14 @@ typedef int new_connection_cb(void *object, const New_Connection *n_c);
*
* n_c is only valid for the duration of the function call.
*/
non_null()
void new_connection_handler(Net_Crypto *c, new_connection_cb *new_connection_callback, void *object);
void new_connection_handler(Net_Crypto *_Nonnull c, new_connection_cb *_Nonnull new_connection_callback, void *_Nonnull object);
/** @brief Accept a crypto connection.
*
* return -1 on failure.
* return connection id on success.
*/
non_null()
int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c);
int accept_crypto_connection(Net_Crypto *_Nonnull c, const New_Connection *_Nonnull n_c);
/** @brief Create a crypto connection.
* If one to that real public key already exists, return it.
@@ -167,8 +165,7 @@ int accept_crypto_connection(Net_Crypto *c, const New_Connection *n_c);
* return -1 on failure.
* return connection id on success.
*/
non_null()
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const uint8_t *dht_public_key);
int new_crypto_connection(Net_Crypto *_Nonnull c, const uint8_t *_Nonnull real_public_key, const uint8_t *_Nonnull dht_public_key);
/** @brief Set the direct ip of the crypto connection.
*
@@ -177,8 +174,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
* return -1 on failure.
* return 0 on success.
*/
non_null()
int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port, bool connected);
int set_direct_ip_port(Net_Crypto *_Nonnull c, int crypt_connection_id, const IP_Port *_Nonnull ip_port, bool connected);
/** @brief Set function to be called when connection with crypt_connection_id goes connects/disconnects.
*
@@ -190,9 +186,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip
* return -1 on failure.
* return 0 on success.
*/
non_null()
int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
connection_status_cb *connection_status_callback, void *object, int id);
int connection_status_handler(const Net_Crypto *_Nonnull c, int crypt_connection_id, connection_status_cb *_Nonnull connection_status_callback, void *_Nonnull object, int id);
/** @brief Set function to be called when connection with crypt_connection_id receives a lossless data packet of length.
*
@@ -202,9 +196,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
non_null()
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
connection_data_cb *connection_data_callback, void *object, int id);
int connection_data_handler(const Net_Crypto *_Nonnull c, int crypt_connection_id, connection_data_cb *_Nonnull connection_data_callback, void *_Nonnull object, int id);
/** @brief Set function to be called when connection with crypt_connection_id receives a lossy data packet of length.
*
@@ -214,9 +206,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
non_null()
int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id,
connection_lossy_data_cb *connection_lossy_data_callback, void *object, int id);
int connection_lossy_data_handler(const Net_Crypto *_Nonnull c, int crypt_connection_id, connection_lossy_data_cb *_Nonnull connection_lossy_data_callback, void *_Nonnull object, int id);
/** @brief Set the function for this friend that will be callbacked with object and number if
* the friend sends us a different dht public key than we have associated to him.
@@ -228,23 +218,19 @@ int connection_lossy_data_handler(const Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return 0 on success.
*/
non_null()
int nc_dht_pk_callback(const Net_Crypto *c, int crypt_connection_id,
dht_pk_cb *function, void *object, uint32_t number);
int nc_dht_pk_callback(const Net_Crypto *_Nonnull c, int crypt_connection_id, dht_pk_cb *_Nonnull function, void *_Nonnull object, uint32_t number);
/**
* @return the number of packet slots left in the sendbuffer.
* @retval 0 if failure.
*/
non_null()
uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id);
uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *_Nonnull c, int crypt_connection_id);
/**
* @retval 1 if max speed was reached for this connection (no more data can be physically through the pipe).
* @retval 0 if it wasn't reached.
*/
non_null()
bool max_speed_reached(const Net_Crypto *c, int crypt_connection_id);
bool max_speed_reached(const Net_Crypto *_Nonnull c, int crypt_connection_id);
/** @brief Sends a lossless cryptopacket.
*
@@ -255,9 +241,7 @@ bool max_speed_reached(const Net_Crypto *c, int crypt_connection_id);
*
* congestion_control: should congestion control apply to this packet?
*/
non_null()
int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id,
const uint8_t *data, uint16_t length, bool congestion_control);
int64_t write_cryptpacket(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull data, uint16_t length, bool congestion_control);
/** @brief Check if packet_number was received by the other side.
*
@@ -273,8 +257,7 @@ int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id,
* It CANNOT be simplified to `packet_number < buffer_start`, as it will fail
* when `buffer_end < buffer_start`.
*/
non_null()
int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t packet_number);
int cryptpacket_received(const Net_Crypto *_Nonnull c, int crypt_connection_id, uint32_t packet_number);
/** @brief Sends a lossy cryptopacket.
*
@@ -283,25 +266,21 @@ int cryptpacket_received(const Net_Crypto *c, int crypt_connection_id, uint32_t
*
* The first byte of data must be in the PACKET_ID_RANGE_LOSSY.
*/
non_null()
int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length);
int send_lossy_cryptpacket(const Net_Crypto *_Nonnull c, int crypt_connection_id, const uint8_t *_Nonnull data, uint16_t length);
/** @brief Add a tcp relay, associating it to a crypt_connection_id.
*
* return 0 if it was added.
* return -1 if it wasn't.
*/
non_null()
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, const IP_Port *ip_port,
const uint8_t *public_key);
int add_tcp_relay_peer(Net_Crypto *_Nonnull c, int crypt_connection_id, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
/** @brief Add a tcp relay to the array.
*
* return 0 if it was added.
* return -1 if it wasn't.
*/
non_null()
int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_key);
int add_tcp_relay(Net_Crypto *_Nonnull c, const IP_Port *_Nonnull ip_port, const uint8_t *_Nonnull public_key);
/** @brief Return a random TCP connection number for use in send_tcp_onion_request.
*
@@ -311,25 +290,21 @@ int add_tcp_relay(Net_Crypto *c, const IP_Port *ip_port, const uint8_t *public_k
* return TCP connection number on success.
* return -1 on failure.
*/
non_null()
int get_random_tcp_con_number(const Net_Crypto *c);
int get_random_tcp_con_number(const Net_Crypto *_Nonnull c);
/** @brief Put IP_Port of a random onion TCP connection in ip_port.
*
* return true on success.
* return false on failure.
*/
non_null()
bool get_random_tcp_conn_ip_port(const Net_Crypto *c, IP_Port *ip_port);
bool get_random_tcp_conn_ip_port(const Net_Crypto *_Nonnull c, IP_Port *_Nonnull ip_port);
/** @brief Send an onion packet via the TCP relay corresponding to tcp_connections_number.
*
* return 0 on success.
* return -1 on failure.
*/
non_null()
int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number,
const uint8_t *data, uint16_t length);
int send_tcp_onion_request(Net_Crypto *_Nonnull c, unsigned int tcp_connections_number, const uint8_t *_Nonnull data, uint16_t length);
/**
* Send a forward request to the TCP relay with IP_Port tcp_forwarder,
@@ -339,10 +314,8 @@ int send_tcp_onion_request(Net_Crypto *c, unsigned int tcp_connections_number,
* return 0 on success.
* return -1 on failure.
*/
non_null()
int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port *tcp_forwarder, const IP_Port *dht_node,
const uint8_t *chain_keys, uint16_t chain_length,
const uint8_t *data, uint16_t data_length);
int send_tcp_forward_request(const Logger *_Nonnull logger, Net_Crypto *_Nonnull c, const IP_Port *_Nonnull tcp_forwarder, const IP_Port *_Nonnull dht_node,
const uint8_t *_Nonnull chain_keys, uint16_t chain_length, const uint8_t *_Nonnull data, uint16_t data_length);
/** @brief Copy a maximum of num random TCP relays we are connected to to tcp_relays.
*
@@ -351,8 +324,7 @@ int send_tcp_forward_request(const Logger *logger, Net_Crypto *c, const IP_Port
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
non_null()
unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
unsigned int copy_connected_tcp_relays(const Net_Crypto *_Nonnull c, Node_format *_Nonnull tcp_relays, uint16_t num);
/**
* Copy a maximum of `max_num` TCP relays we are connected to starting at the index in the TCP relay array
@@ -360,16 +332,14 @@ unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_rel
*
* Returns the number of relays successfully copied.
*/
non_null()
uint32_t copy_connected_tcp_relays_index(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num, uint32_t idx);
uint32_t copy_connected_tcp_relays_index(const Net_Crypto *_Nonnull c, Node_format *_Nonnull tcp_relays, uint16_t num, uint32_t idx);
/** @brief Kill a crypto connection.
*
* return -1 on failure.
* return 0 on success.
*/
non_null()
int crypto_kill(Net_Crypto *c, int crypt_connection_id);
int crypto_kill(Net_Crypto *_Nonnull c, int crypt_connection_id);
/**
* @retval true if connection is valid, false otherwise
@@ -377,48 +347,37 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
* sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
* sets online_tcp_relays to the number of connected tcp relays this connection has.
*/
non_null(1, 3) nullable(4)
bool crypto_connection_status(
const Net_Crypto *c, int crypt_connection_id, bool *direct_connected, uint32_t *online_tcp_relays);
const Net_Crypto *_Nonnull c, int crypt_connection_id, bool *_Nonnull direct_connected, uint32_t *_Nullable online_tcp_relays);
/** @brief Generate our public and private keys.
* Only call this function the first time the program starts.
*/
non_null()
void new_keys(Net_Crypto *c);
void new_keys(Net_Crypto *_Nonnull c);
/** @brief Save the public and private keys to the keys array.
* Length must be CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE.
*
* TODO(irungentoo): Save only secret key.
*/
non_null()
void save_keys(const Net_Crypto *c, uint8_t *keys);
void save_keys(const Net_Crypto *_Nonnull c, uint8_t *_Nonnull keys);
/** @brief Load the secret key.
* Length must be CRYPTO_SECRET_KEY_SIZE.
*/
non_null()
void load_secret_key(Net_Crypto *c, const uint8_t *sk);
void load_secret_key(Net_Crypto *_Nonnull c, const uint8_t *_Nonnull sk);
/** @brief Create new instance of Net_Crypto.
* Sets all the global connection variables to their default values.
*/
non_null()
Net_Crypto *new_net_crypto(const Logger *log, const Memory *mem, const Random *rng, const Network *ns,
Mono_Time *mono_time, DHT *dht, const TCP_Proxy_Info *proxy_info, Net_Profile *tcp_np);
Net_Crypto *_Nullable new_net_crypto(const Logger *_Nonnull log, const Memory *_Nonnull mem, const Random *_Nonnull rng, const Network *_Nonnull ns, Mono_Time *_Nonnull mono_time, DHT *_Nonnull dht,
const TCP_Proxy_Info *_Nonnull proxy_info, Net_Profile *_Nonnull tcp_np);
/** return the optimal interval in ms for running do_net_crypto. */
non_null()
uint32_t crypto_run_interval(const Net_Crypto *c);
uint32_t crypto_run_interval(const Net_Crypto *_Nonnull c);
/** Main loop. */
non_null(1) nullable(2)
void do_net_crypto(Net_Crypto *c, void *userdata);
nullable(1)
void kill_net_crypto(Net_Crypto *c);
void do_net_crypto(Net_Crypto *_Nonnull c, void *_Nullable userdata);
void kill_net_crypto(Net_Crypto *_Nullable c);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -33,8 +33,7 @@ typedef struct Net_Profile {
} Net_Profile;
/** Returns the number of sent or received packets for all ID's between `start_id` and `end_id`. */
nullable(1)
static uint64_t netprof_get_packet_count_id_range(const Net_Profile *profile, uint8_t start_id, uint8_t end_id,
static uint64_t netprof_get_packet_count_id_range(const Net_Profile *_Nullable profile, uint8_t start_id, uint8_t end_id,
Packet_Direction dir)
{
if (profile == nullptr) {
@@ -52,8 +51,7 @@ static uint64_t netprof_get_packet_count_id_range(const Net_Profile *profile, ui
}
/** Returns the number of sent or received bytes for all ID's between `start_id` and `end_id`. */
nullable(1)
static uint64_t netprof_get_bytes_id_range(const Net_Profile *profile, uint8_t start_id, uint8_t end_id,
static uint64_t netprof_get_bytes_id_range(const Net_Profile *_Nullable profile, uint8_t start_id, uint8_t end_id,
Packet_Direction dir)
{
if (profile == nullptr) {

View File

@@ -34,46 +34,33 @@ typedef enum Packet_Direction {
/**
* Records a sent or received packet of type `id` and size `length` to the given profile.
*/
nullable(1)
void netprof_record_packet(Net_Profile *profile, uint8_t id, size_t length, Packet_Direction dir);
void netprof_record_packet(Net_Profile *_Nullable profile, uint8_t id, size_t length, Packet_Direction dir);
/**
* Returns the number of sent or received packets of type `id` for the given profile.
*/
nullable(1)
uint64_t netprof_get_packet_count_id(const Net_Profile *profile, uint8_t id, Packet_Direction dir);
uint64_t netprof_get_packet_count_id(const Net_Profile *_Nullable profile, uint8_t id, Packet_Direction dir);
/**
* Returns the total number of sent or received packets for the given profile.
*/
nullable(1)
uint64_t netprof_get_packet_count_total(const Net_Profile *profile, Packet_Direction dir);
uint64_t netprof_get_packet_count_total(const Net_Profile *_Nullable profile, Packet_Direction dir);
/**
* Returns the number of bytes sent or received of packet type `id` for the given profile.
*/
nullable(1)
uint64_t netprof_get_bytes_id(const Net_Profile *profile, uint8_t id, Packet_Direction dir);
uint64_t netprof_get_bytes_id(const Net_Profile *_Nullable profile, uint8_t id, Packet_Direction dir);
/**
* Returns the total number of bytes sent or received for the given profile.
*/
nullable(1)
uint64_t netprof_get_bytes_total(const Net_Profile *profile, Packet_Direction dir);
uint64_t netprof_get_bytes_total(const Net_Profile *_Nullable profile, Packet_Direction dir);
/**
* Returns a new net_profile object. The caller is responsible for freeing the
* returned memory via `netprof_kill`.
*/
non_null()
Net_Profile *netprof_new(const Logger *log, const Memory *mem);
Net_Profile *_Nullable netprof_new(const Logger *_Nonnull log, const Memory *_Nonnull mem);
/**
* Kills a net_profile object and frees all associated memory.
*/
non_null(1) nullable(2)
void netprof_kill(const Memory *mem, Net_Profile *net_profile);
void netprof_kill(const Memory *_Nonnull mem, Net_Profile *_Nullable net_profile);
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -118,26 +118,22 @@ static bool should_ignore_connect_error(int err)
return err == EWOULDBLOCK || err == EINPROGRESS;
}
non_null()
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
static const char *inet_ntop4(const struct in_addr *_Nonnull addr, char *_Nonnull buf, size_t bufsize)
{
return inet_ntop(AF_INET, addr, buf, bufsize);
}
non_null()
static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t bufsize)
static const char *inet_ntop6(const struct in6_addr *_Nonnull addr, char *_Nonnull buf, size_t bufsize)
{
return inet_ntop(AF_INET6, addr, buf, bufsize);
}
non_null()
static int inet_pton4(const char *addr_string, struct in_addr *addrbuf)
static int inet_pton4(const char *_Nonnull addr_string, struct in_addr *_Nonnull addrbuf)
{
return inet_pton(AF_INET, addr_string, addrbuf);
}
non_null()
static int inet_pton6(const char *addr_string, struct in6_addr *addrbuf)
static int inet_pton6(const char *_Nonnull addr_string, struct in6_addr *_Nonnull addrbuf)
{
return inet_pton(AF_INET6, addr_string, addrbuf);
}
@@ -159,8 +155,7 @@ static bool should_ignore_connect_error(int err)
return err == WSAEWOULDBLOCK || err == WSAEINPROGRESS;
}
non_null()
static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufsize)
static const char *inet_ntop4(const struct in_addr *_Nonnull addr, char *_Nonnull buf, size_t bufsize)
{
struct sockaddr_in saddr = {0};
@@ -176,8 +171,7 @@ static const char *inet_ntop4(const struct in_addr *addr, char *buf, size_t bufs
return buf;
}
non_null()
static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t bufsize)
static const char *inet_ntop6(const struct in6_addr *_Nonnull addr, char *_Nonnull buf, size_t bufsize)
{
struct sockaddr_in6 saddr = {0};
@@ -193,8 +187,7 @@ static const char *inet_ntop6(const struct in6_addr *addr, char *buf, size_t buf
return buf;
}
non_null()
static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
static int inet_pton4(const char *_Nonnull addrString, struct in_addr *_Nonnull addrbuf)
{
struct sockaddr_in saddr = {0};
@@ -209,8 +202,7 @@ static int inet_pton4(const char *addrString, struct in_addr *addrbuf)
return 1;
}
non_null()
static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
static int inet_pton6(const char *_Nonnull addrString, struct in6_addr *_Nonnull addrbuf)
{
struct sockaddr_in6 saddr = {0};
@@ -306,30 +298,26 @@ static const Family *make_tox_family(int family)
}
}
non_null()
static void get_ip4(IP4 *result, const struct in_addr *addr)
static void get_ip4(IP4 *_Nonnull result, const struct in_addr *_Nonnull addr)
{
static_assert(sizeof(result->uint32) == sizeof(addr->s_addr),
"Tox and operating system don't agree on size of IPv4 addresses");
result->uint32 = addr->s_addr;
}
non_null()
static void get_ip6(IP6 *result, const struct in6_addr *addr)
static void get_ip6(IP6 *_Nonnull result, const struct in6_addr *_Nonnull addr)
{
static_assert(sizeof(result->uint8) == sizeof(addr->s6_addr),
"Tox and operating system don't agree on size of IPv6 addresses");
memcpy(result->uint8, addr->s6_addr, sizeof(result->uint8));
}
non_null()
static void fill_addr4(const IP4 *ip, struct in_addr *addr)
static void fill_addr4(const IP4 *_Nonnull ip, struct in_addr *_Nonnull addr)
{
addr->s_addr = ip->uint32;
}
non_null()
static void fill_addr6(const IP6 *ip, struct in6_addr *addr)
static void fill_addr6(const IP6 *_Nonnull ip, struct in6_addr *_Nonnull addr)
{
memcpy(addr->s6_addr, ip->uint8, sizeof(ip->uint8));
}
@@ -488,8 +476,7 @@ struct Network_Addr {
size_t size;
};
non_null()
static int sys_close(void *obj, Socket sock)
static int sys_close(void *_Nonnull obj, Socket sock)
{
#if defined(OS_WIN32)
return closesocket(net_socket_to_native(sock));
@@ -498,32 +485,27 @@ static int sys_close(void *obj, Socket sock)
#endif /* OS_WIN32 */
}
non_null()
static Socket sys_accept(void *obj, Socket sock)
static Socket sys_accept(void *_Nonnull obj, Socket sock)
{
return net_socket_from_native(accept(net_socket_to_native(sock), nullptr, nullptr));
}
non_null()
static int sys_bind(void *obj, Socket sock, const Network_Addr *addr)
static int sys_bind(void *_Nonnull obj, Socket sock, const Network_Addr *_Nonnull addr)
{
return bind(net_socket_to_native(sock), (const struct sockaddr *)&addr->addr, addr->size);
}
non_null()
static int sys_listen(void *obj, Socket sock, int backlog)
static int sys_listen(void *_Nonnull obj, Socket sock, int backlog)
{
return listen(net_socket_to_native(sock), backlog);
}
non_null()
static int sys_connect(void *obj, Socket sock, const Network_Addr *addr)
static int sys_connect(void *_Nonnull obj, Socket sock, const Network_Addr *_Nonnull addr)
{
return connect(net_socket_to_native(sock), (const struct sockaddr *)&addr->addr, addr->size);
}
non_null()
static int sys_recvbuf(void *obj, Socket sock)
static int sys_recvbuf(void *_Nonnull obj, Socket sock)
{
#ifdef OS_WIN32
u_long count = 0;
@@ -536,26 +518,22 @@ static int sys_recvbuf(void *obj, Socket sock)
return count;
}
non_null()
static int sys_recv(void *obj, Socket sock, uint8_t *buf, size_t len)
static int sys_recv(void *_Nonnull obj, Socket sock, uint8_t *_Nonnull buf, size_t len)
{
return recv(net_socket_to_native(sock), (char *)buf, len, MSG_NOSIGNAL);
}
non_null()
static int sys_send(void *obj, Socket sock, const uint8_t *buf, size_t len)
static int sys_send(void *_Nonnull obj, Socket sock, const uint8_t *_Nonnull buf, size_t len)
{
return send(net_socket_to_native(sock), (const char *)buf, len, MSG_NOSIGNAL);
}
non_null()
static int sys_sendto(void *obj, Socket sock, const uint8_t *buf, size_t len, const Network_Addr *addr)
static int sys_sendto(void *_Nonnull obj, Socket sock, const uint8_t *_Nonnull buf, size_t len, const Network_Addr *_Nonnull addr)
{
return sendto(net_socket_to_native(sock), (const char *)buf, len, 0, (const struct sockaddr *)&addr->addr, addr->size);
}
non_null()
static int sys_recvfrom(void *obj, Socket sock, uint8_t *buf, size_t len, Network_Addr *addr)
static int sys_recvfrom(void *_Nonnull obj, Socket sock, uint8_t *_Nonnull buf, size_t len, Network_Addr *_Nonnull addr)
{
socklen_t size = addr->size;
const int ret = recvfrom(net_socket_to_native(sock), (char *)buf, len, 0, (struct sockaddr *)&addr->addr, &size);
@@ -563,14 +541,12 @@ static int sys_recvfrom(void *obj, Socket sock, uint8_t *buf, size_t len, Networ
return ret;
}
non_null()
static Socket sys_socket(void *obj, int domain, int type, int proto)
static Socket sys_socket(void *_Nonnull obj, int domain, int type, int proto)
{
return net_socket_from_native(socket(domain, type, proto));
}
non_null()
static int sys_socket_nonblock(void *obj, Socket sock, bool nonblock)
static int sys_socket_nonblock(void *_Nonnull obj, Socket sock, bool nonblock)
{
#ifdef OS_WIN32
u_long mode = nonblock ? 1 : 0;
@@ -580,8 +556,7 @@ static int sys_socket_nonblock(void *obj, Socket sock, bool nonblock)
#endif /* OS_WIN32 */
}
non_null()
static int sys_getsockopt(void *obj, Socket sock, int level, int optname, void *optval, size_t *optlen)
static int sys_getsockopt(void *_Nonnull obj, Socket sock, int level, int optname, void *_Nonnull optval, size_t *_Nonnull optlen)
{
socklen_t len = *optlen;
const int ret = getsockopt(net_socket_to_native(sock), level, optname, (char *)optval, &len);
@@ -589,8 +564,7 @@ static int sys_getsockopt(void *obj, Socket sock, int level, int optname, void *
return ret;
}
non_null()
static int sys_setsockopt(void *obj, Socket sock, int level, int optname, const void *optval, size_t optlen)
static int sys_setsockopt(void *_Nonnull obj, Socket sock, int level, int optname, const void *_Nonnull optval, size_t optlen)
{
#ifdef EMSCRIPTEN
return 0;
@@ -601,8 +575,7 @@ static int sys_setsockopt(void *obj, Socket sock, int level, int optname, const
// sets and fills an array of addrs for address
// returns the number of entries in addrs
non_null()
static int sys_getaddrinfo(void *obj, const Memory *mem, const char *address, int family, int sock_type, Network_Addr **addrs)
static int sys_getaddrinfo(void *_Nonnull obj, const Memory *_Nonnull mem, const char *_Nonnull address, int family, int sock_type, Network_Addr **_Nonnull addrs)
{
assert(addrs != nullptr);
@@ -673,8 +646,7 @@ static int sys_getaddrinfo(void *obj, const Memory *mem, const char *address, in
return result;
}
non_null()
static int sys_freeaddrinfo(void *obj, const Memory *mem, Network_Addr *addrs)
static int sys_freeaddrinfo(void *_Nonnull obj, const Memory *_Nonnull mem, Network_Addr *_Nonnull addrs)
{
if (addrs == nullptr) {
return 0;
@@ -732,20 +704,17 @@ void os_network_deinit(const Network *ns)
}
#endif /* 0 */
non_null()
static int net_setsockopt(const Network *ns, Socket sock, int level, int optname, const void *optval, size_t optlen)
static int net_setsockopt(const Network *_Nonnull ns, Socket sock, int level, int optname, const void *_Nonnull optval, size_t optlen)
{
return ns->funcs->setsockopt(ns->obj, sock, level, optname, optval, optlen);
}
non_null()
static int net_getsockopt(const Network *ns, Socket sock, int level, int optname, void *optval, size_t *optlen)
static int net_getsockopt(const Network *_Nonnull ns, Socket sock, int level, int optname, void *_Nonnull optval, size_t *_Nonnull optlen)
{
return ns->funcs->getsockopt(ns->obj, sock, level, optname, optval, optlen);
}
non_null()
static uint32_t data_0(uint16_t buflen, const uint8_t *buffer)
static uint32_t data_0(uint16_t buflen, const uint8_t *_Nonnull buffer)
{
uint32_t data = 0;
@@ -755,8 +724,7 @@ static uint32_t data_0(uint16_t buflen, const uint8_t *buffer)
return data;
}
non_null()
static uint32_t data_1(uint16_t buflen, const uint8_t *buffer)
static uint32_t data_1(uint16_t buflen, const uint8_t *_Nonnull buffer)
{
uint32_t data = 0;
@@ -882,9 +850,7 @@ static const char *net_packet_type_name(Net_Packet_Type type)
return "<unknown>";
}
non_null()
static void loglogdata(const Logger *log, const char *message, const uint8_t *buffer,
uint16_t buflen, const IP_Port *ip_port, long res)
static void loglogdata(const Logger *_Nonnull log, const char *_Nonnull message, const uint8_t *_Nonnull buffer, uint16_t buflen, const IP_Port *_Nonnull ip_port, long res)
{
if (res < 0) { /* Windows doesn't necessarily know `%zu` */
Ip_Ntoa ip_str;
@@ -893,21 +859,21 @@ static void loglogdata(const Logger *log, const char *message, const uint8_t *bu
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
min_u16(buflen, 999), 'E',
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), error,
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)error,
net_strerror(error, &error_str), data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
} else if ((res > 0) && ((size_t)res <= buflen)) {
Ip_Ntoa ip_str;
LOGGER_TRACE(log, "[%02x = %-21s] %s %3u%c %s:%u (%u: %s) | %08x%08x...%02x",
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
min_u16(res, 999), (size_t)res < buflen ? '<' : '=',
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)0, "OK",
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
} else { /* empty or overwrite */
Ip_Ntoa ip_str;
LOGGER_TRACE(log, "[%02x = %-21s] %s %lu%c%u %s:%u (%u: %s) | %08x%08x...%02x",
buffer[0], net_packet_type_name((Net_Packet_Type)buffer[0]), message,
res, res == 0 ? '!' : '>', buflen,
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), 0, "OK",
(unsigned long)res, res == 0 ? '!' : '>', buflen,
net_ip_ntoa(&ip_port->ip, &ip_str), net_ntohs(ip_port->port), (unsigned int)0, "OK",
data_0(buflen, buffer), data_1(buflen, buffer), buffer[buflen - 1]);
}
}
@@ -925,10 +891,7 @@ int net_send(const Network *ns, const Logger *log,
return res;
}
non_null()
static int net_sendto(
const Network *ns,
Socket sock, const uint8_t *buf, size_t len, const Network_Addr *addr, const IP_Port *ip_port)
static int net_sendto(const Network *_Nonnull ns, Socket sock, const uint8_t *_Nonnull buf, size_t len, const Network_Addr *_Nonnull addr, const IP_Port *_Nonnull ip_port)
{
return ns->funcs->sendto(ns->obj, sock, buf, len, addr);
}
@@ -941,9 +904,7 @@ int net_recv(const Network *ns, const Logger *log,
return res;
}
non_null()
static int net_recvfrom(const Network *ns,
Socket sock, uint8_t *buf, size_t len, Network_Addr *addr)
static int net_recvfrom(const Network *_Nonnull ns, Socket sock, uint8_t *_Nonnull buf, size_t len, Network_Addr *_Nonnull addr)
{
return ns->funcs->recvfrom(ns->obj, sock, buf, len, addr);
}
@@ -953,8 +914,7 @@ int net_listen(const Network *ns, Socket sock, int backlog)
return ns->funcs->listen(ns->obj, sock, backlog);
}
non_null()
static int net_bind(const Network *ns, Socket sock, const Network_Addr *addr)
static int net_bind(const Network *_Nonnull ns, Socket sock, const Network_Addr *_Nonnull addr)
{
return ns->funcs->bind(ns->obj, sock, addr);
}
@@ -1135,8 +1095,7 @@ int sendpacket(const Networking_Core *net, const IP_Port *ip_port, const uint8_t
* Packet data is put into data.
* Packet length is put into length.
*/
non_null()
static int receivepacket(const Network *ns, const Logger *log, Socket sock, IP_Port *ip_port, uint8_t *data, uint32_t *length)
static int receivepacket(const Network *_Nonnull ns, const Logger *_Nonnull log, Socket sock, IP_Port *_Nonnull ip_port, uint8_t *_Nonnull data, uint32_t *_Nonnull length)
{
memset(ip_port, 0, sizeof(IP_Port));
Network_Addr addr = {{0}};
@@ -1150,7 +1109,7 @@ static int receivepacket(const Network *ns, const Logger *log, Socket sock, IP_P
if (!should_ignore_recv_error(error)) {
Net_Strerror error_str;
LOGGER_ERROR(log, "unexpected error reading from socket: %u, %s", error, net_strerror(error, &error_str));
LOGGER_ERROR(log, "unexpected error reading from socket: %u, %s", (unsigned int)error, net_strerror(error, &error_str));
}
return -1; /* Nothing received. */
@@ -1568,14 +1527,12 @@ bool ipport_equal(const IP_Port *a, const IP_Port *b)
return ip_equal(&a->ip, &b->ip);
}
non_null()
static int ip4_cmp(const IP4 *a, const IP4 *b)
static int ip4_cmp(const IP4 *_Nonnull a, const IP4 *_Nonnull b)
{
return cmp_uint(a->uint32, b->uint32);
}
non_null()
static int ip6_cmp(const IP6 *a, const IP6 *b)
static int ip6_cmp(const IP6 *_Nonnull a, const IP6 *_Nonnull b)
{
const int res = cmp_uint(a->uint64[0], b->uint64[0]);
if (res != 0) {
@@ -1584,8 +1541,7 @@ static int ip6_cmp(const IP6 *a, const IP6 *b)
return cmp_uint(a->uint64[1], b->uint64[1]);
}
non_null()
static int ip_cmp(const IP *a, const IP *b)
static int ip_cmp(const IP *_Nonnull a, const IP *_Nonnull b)
{
const int res = cmp_uint(a->family.value, b->family.value);
if (res != 0) {
@@ -1718,8 +1674,7 @@ void ipport_copy(IP_Port *target, const IP_Port *source)
*
* @retval true on success.
*/
non_null()
static bool bin_pack_ip(Bin_Pack *bp, const IP *ip, bool is_ipv4)
static bool bin_pack_ip(Bin_Pack *_Nonnull bp, const IP *_Nonnull ip, bool is_ipv4)
{
if (is_ipv4) {
return bin_pack_bin_b(bp, ip->ip.v4.uint8, SIZE_IP4);
@@ -1763,8 +1718,7 @@ bool bin_pack_ip_port(Bin_Pack *bp, const Logger *logger, const IP_Port *ip_port
&& bin_pack_u16_b(bp, net_ntohs(ip_port->port));
}
non_null()
static bool bin_pack_ip_port_handler(const void *obj, const Logger *logger, Bin_Pack *bp)
static bool bin_pack_ip_port_handler(const void *_Nonnull obj, const Logger *_Nonnull logger, Bin_Pack *_Nonnull bp)
{
const IP_Port *ip_port = (const IP_Port *)obj;
return bin_pack_ip_port(bp, logger, ip_port);
@@ -1941,8 +1895,7 @@ bool addr_parse_ip(const char *address, IP *to)
*
* @return false on failure, true on success.
*/
non_null(1, 2, 3, 4) nullable(5)
static bool addr_resolve(const Network *ns, const Memory *mem, const char *address, IP *to, IP *extra)
static bool addr_resolve(const Network *_Nonnull ns, const Memory *_Nonnull mem, const char *_Nonnull address, IP *_Nonnull to, IP *_Nullable extra)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if ((true)) {
@@ -2374,8 +2327,7 @@ char *net_strerror(int error, Net_Strerror *buf)
}
#else
#if defined(_GNU_SOURCE) && defined(__GLIBC__)
non_null()
static const char *net_strerror_r(int error, char *tmp, size_t tmp_size)
static const char *net_strerror_r(int error, char *_Nonnull tmp, size_t tmp_size)
{
const char *retstr = strerror_r(error, tmp, tmp_size);
@@ -2386,8 +2338,7 @@ static const char *net_strerror_r(int error, char *tmp, size_t tmp_size)
return retstr;
}
#else
non_null()
static const char *net_strerror_r(int error, char *tmp, size_t tmp_size)
static const char *net_strerror_r(int error, char *_Nonnull tmp, size_t tmp_size)
{
const int fmt_error = strerror_r(error, tmp, tmp_size);

Some files were not shown because too many files have changed in this diff Show More