forked from Green-Sky/tomato
Green Sky
a3126d581b
82460b212 feat: add ngc events 24b54722a fix: Ensure we have allocators available for the error paths. 48dbcfebc cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions. 0cef46ee9 cleanup: Fix a few more clang-tidy warnings. 0c5b918e9 cleanup: Fix a few more clang-tidy warnings. 4d3c97f49 cleanup: Enforce stricter identifier naming using clang-tidy. a549807df refactor: Add `mem` module to allow tests to override allocators. 6133fb153 chore: Add devcontainer setup for codespaces. 620e07ecd chore: Set a timeout for tests started using Conan c0ec33b16 chore: Migrate Windows CI from Appveyor to Azure DevOps 8ed47f3ef fix incorrect documentation a1e245841 docs: Fix doxygen config and remove some redundant comments. b0f633185 chore: Fix the Android CI job 7469a529b fix: Add missing `#include <array>`. 2b1a6b0d2 add missing ngc constants getter declarations and definitions 2e02d5637 chore: Add missing module dependencies. REVERT: 67badf694 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 82460b2124216af1ac9d63060de310a682a2fd15
212 lines
5.0 KiB
C
212 lines
5.0 KiB
C
/* SPDX-License-Identifier: GPL-3.0-or-later
|
|
* Copyright © 2016-2021 The TokTok team.
|
|
*/
|
|
#include "tox.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "ccompat.h"
|
|
#include "tox_private.h"
|
|
|
|
#define SET_ERROR_PARAMETER(param, x) \
|
|
do { \
|
|
if (param != nullptr) { \
|
|
*param = x; \
|
|
} \
|
|
} while (0)
|
|
|
|
uint32_t tox_version_major(void)
|
|
{
|
|
return TOX_VERSION_MAJOR;
|
|
}
|
|
uint32_t tox_version_minor(void)
|
|
{
|
|
return TOX_VERSION_MINOR;
|
|
}
|
|
uint32_t tox_version_patch(void)
|
|
{
|
|
return TOX_VERSION_PATCH;
|
|
}
|
|
uint32_t tox_public_key_size(void)
|
|
{
|
|
return TOX_PUBLIC_KEY_SIZE;
|
|
}
|
|
uint32_t tox_secret_key_size(void)
|
|
{
|
|
return TOX_SECRET_KEY_SIZE;
|
|
}
|
|
uint32_t tox_conference_uid_size(void)
|
|
{
|
|
return TOX_CONFERENCE_UID_SIZE;
|
|
}
|
|
uint32_t tox_conference_id_size(void)
|
|
{
|
|
return TOX_CONFERENCE_ID_SIZE;
|
|
}
|
|
uint32_t tox_nospam_size(void)
|
|
{
|
|
return TOX_NOSPAM_SIZE;
|
|
}
|
|
uint32_t tox_address_size(void)
|
|
{
|
|
return TOX_ADDRESS_SIZE;
|
|
}
|
|
uint32_t tox_max_name_length(void)
|
|
{
|
|
return TOX_MAX_NAME_LENGTH;
|
|
}
|
|
uint32_t tox_max_status_message_length(void)
|
|
{
|
|
return TOX_MAX_STATUS_MESSAGE_LENGTH;
|
|
}
|
|
uint32_t tox_max_friend_request_length(void)
|
|
{
|
|
return TOX_MAX_FRIEND_REQUEST_LENGTH;
|
|
}
|
|
uint32_t tox_max_message_length(void)
|
|
{
|
|
return TOX_MAX_MESSAGE_LENGTH;
|
|
}
|
|
uint32_t tox_max_custom_packet_size(void)
|
|
{
|
|
return TOX_MAX_CUSTOM_PACKET_SIZE;
|
|
}
|
|
uint32_t tox_hash_length(void)
|
|
{
|
|
return TOX_HASH_LENGTH;
|
|
}
|
|
uint32_t tox_file_id_length(void)
|
|
{
|
|
return TOX_FILE_ID_LENGTH;
|
|
}
|
|
uint32_t tox_max_filename_length(void)
|
|
{
|
|
return TOX_MAX_FILENAME_LENGTH;
|
|
}
|
|
uint32_t tox_max_hostname_length(void)
|
|
{
|
|
return TOX_MAX_HOSTNAME_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_topic_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_TOPIC_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_part_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_PART_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_message_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_MESSAGE_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_custom_lossy_packet_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_custom_lossless_packet_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_CUSTOM_LOSSLESS_PACKET_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_group_name_length(void)
|
|
{
|
|
return TOX_GROUP_MAX_GROUP_NAME_LENGTH;
|
|
}
|
|
uint32_t tox_group_max_password_size(void)
|
|
{
|
|
return TOX_GROUP_MAX_PASSWORD_SIZE;
|
|
}
|
|
uint32_t tox_group_chat_id_size(void)
|
|
{
|
|
return TOX_GROUP_CHAT_ID_SIZE;
|
|
}
|
|
uint32_t tox_group_peer_public_key_size(void)
|
|
{
|
|
return TOX_GROUP_PEER_PUBLIC_KEY_SIZE;
|
|
}
|
|
uint32_t tox_dht_node_ip_string_size(void)
|
|
{
|
|
return TOX_DHT_NODE_IP_STRING_SIZE;
|
|
}
|
|
uint32_t tox_dht_node_public_key_size(void)
|
|
{
|
|
return TOX_DHT_NODE_PUBLIC_KEY_SIZE;
|
|
}
|
|
|
|
//!TOKSTYLE-
|
|
|
|
#define ACCESSORS(type, ns, name) \
|
|
type tox_options_get_##ns##name(const struct Tox_Options *options) \
|
|
{ \
|
|
return options->ns##name; \
|
|
} \
|
|
void tox_options_set_##ns##name(struct Tox_Options *options, type name) \
|
|
{ \
|
|
options->ns##name = name; \
|
|
}
|
|
|
|
ACCESSORS(bool,, ipv6_enabled)
|
|
ACCESSORS(bool,, udp_enabled)
|
|
ACCESSORS(Tox_Proxy_Type, proxy_, type)
|
|
ACCESSORS(const char *, proxy_, host)
|
|
ACCESSORS(uint16_t, proxy_, port)
|
|
ACCESSORS(uint16_t,, start_port)
|
|
ACCESSORS(uint16_t,, end_port)
|
|
ACCESSORS(uint16_t,, tcp_port)
|
|
ACCESSORS(bool,, hole_punching_enabled)
|
|
ACCESSORS(Tox_Savedata_Type, savedata_, type)
|
|
ACCESSORS(size_t, savedata_, length)
|
|
ACCESSORS(tox_log_cb *, log_, callback)
|
|
ACCESSORS(void *, log_, user_data)
|
|
ACCESSORS(bool,, local_discovery_enabled)
|
|
ACCESSORS(bool,, dht_announcements_enabled)
|
|
ACCESSORS(bool,, experimental_thread_safety)
|
|
ACCESSORS(const Tox_System *,, operating_system)
|
|
|
|
//!TOKSTYLE+
|
|
|
|
const uint8_t *tox_options_get_savedata_data(const struct Tox_Options *options)
|
|
{
|
|
return options->savedata_data;
|
|
}
|
|
|
|
void tox_options_set_savedata_data(struct Tox_Options *options, const uint8_t *data, size_t length)
|
|
{
|
|
options->savedata_data = data;
|
|
options->savedata_length = length;
|
|
}
|
|
|
|
void tox_options_default(struct Tox_Options *options)
|
|
{
|
|
if (options != nullptr) {
|
|
const struct Tox_Options default_options = {0};
|
|
*options = default_options;
|
|
tox_options_set_ipv6_enabled(options, true);
|
|
tox_options_set_udp_enabled(options, true);
|
|
tox_options_set_proxy_type(options, TOX_PROXY_TYPE_NONE);
|
|
tox_options_set_hole_punching_enabled(options, true);
|
|
tox_options_set_local_discovery_enabled(options, true);
|
|
tox_options_set_dht_announcements_enabled(options, true);
|
|
tox_options_set_experimental_thread_safety(options, false);
|
|
}
|
|
}
|
|
|
|
struct Tox_Options *tox_options_new(Tox_Err_Options_New *error)
|
|
{
|
|
struct Tox_Options *options = (struct Tox_Options *)calloc(1, sizeof(struct Tox_Options));
|
|
|
|
if (options != nullptr) {
|
|
tox_options_default(options);
|
|
SET_ERROR_PARAMETER(error, TOX_ERR_OPTIONS_NEW_OK);
|
|
return options;
|
|
}
|
|
|
|
SET_ERROR_PARAMETER(error, TOX_ERR_OPTIONS_NEW_MALLOC);
|
|
return nullptr;
|
|
}
|
|
|
|
void tox_options_free(struct Tox_Options *options)
|
|
{
|
|
free(options);
|
|
}
|