Make tox.c unambiguously parseable.

Rules:
1. Constants are uppercase names: THE_CONSTANT.
2. SUE[1] types start with an uppercase letter and have at least one
   lowercase letter in it: The_Type, THE_Type.
3. Function types end in "_cb": tox_friend_connection_cb.
4. Variable and function names are all lowercase: the_function.

This makes it easier for humans reading the code to determine what an
identifier means. I'm not convinced by the enum type name change, but I
don't know a better rule. Currently, a lot of enum types are spelled like
constants, which is confusing.

[1] struct/union/enum
This commit is contained in:
iphydf 2018-07-05 10:31:29 +00:00
parent 64d0297acc
commit 8739f7fccb
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
24 changed files with 428 additions and 336 deletions

View File

@ -330,7 +330,7 @@ static void test_addto_lists(IP ip)
Networking_Core *net = new_networking(log, ip, TOX_PORT_DEFAULT);
ck_assert_msg(net != nullptr, "Failed to create Networking_Core");
DHT *dht = new_DHT(log, net, true);
DHT *dht = new_dht(log, net, true);
ck_assert_msg(dht != nullptr, "Failed to create DHT");
IP_Port ip_port;
@ -391,7 +391,7 @@ static void test_addto_lists(IP ip)
test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
dht->friends_list[i].public_key);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(log);
}
@ -475,7 +475,7 @@ static void test_list_main(void)
index[i] = i + 1;
logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]);
dhts[i] = new_DHT(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
dhts[i] = new_dht(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i,
"Bound to wrong port: %d", net_port(dhts[i]->net));
@ -580,7 +580,7 @@ static void test_list_main(void)
for (i = 0; i < NUM_DHT; ++i) {
Networking_Core *n = dhts[i]->net;
kill_DHT(dhts[i]);
kill_dht(dhts[i]);
kill_networking(n);
logger_kill(logs[i]);
}
@ -620,7 +620,7 @@ START_TEST(test_DHT_test)
index[i] = i + 1;
logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]);
dhts[i] = new_DHT(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
dhts[i] = new_dht(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, "Bound to wrong port");
}
@ -642,7 +642,7 @@ loop_top:
}
uint16_t lock_count = 0;
ck_assert_msg(DHT_addfriend(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &ip_callback, &to_comp, 1337,
ck_assert_msg(dht_addfriend(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &ip_callback, &to_comp, 1337,
&lock_count) == 0, "Failed to add friend");
ck_assert_msg(lock_count == 1, "bad lock count: %u %u", lock_count, i);
}
@ -651,7 +651,7 @@ loop_top:
IP_Port ip_port;
ip_port.ip = get_loopback();
ip_port.port = net_htons(DHT_DEFAULT_PORT + i);
DHT_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key);
dht_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key);
}
while (1) {
@ -660,7 +660,7 @@ loop_top:
for (i = 0; i < NUM_DHT_FRIENDS; ++i) {
IP_Port a;
if (DHT_getfriendip(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &a) == 1) {
if (dht_getfriendip(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &a) == 1) {
++counter;
}
}
@ -671,7 +671,7 @@ loop_top:
for (i = 0; i < NUM_DHT; ++i) {
networking_poll(dhts[i]->net, nullptr);
do_DHT(dhts[i]);
do_dht(dhts[i]);
}
c_sleep(500);
@ -679,7 +679,7 @@ loop_top:
for (i = 0; i < NUM_DHT; ++i) {
Networking_Core *n = dhts[i]->net;
kill_DHT(dhts[i]);
kill_dht(dhts[i]);
kill_networking(n);
logger_kill(logs[i]);
}
@ -694,7 +694,7 @@ START_TEST(test_dht_create_packet)
uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE];
new_symmetric_key(key);
int length = DHT_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt);
int length = dht_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt);
ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet.");
ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet.");

View File

@ -241,18 +241,18 @@ START_TEST(test_dht_state_saveloadsave)
* c) a second save() is of equal size
* d) the second save() is of equal content */
const size_t extra = 64;
const size_t size = DHT_size(m->dht);
const size_t size = dht_size(m->dht);
VLA(uint8_t, buffer, size + 2 * extra);
memset(buffer, 0xCD, extra);
memset(buffer + extra + size, 0xCD, extra);
DHT_save(m->dht, buffer + extra);
dht_save(m->dht, buffer + extra);
for (size_t i = 0; i < extra; i++) {
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", (unsigned)i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", (unsigned)i);
ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from dht_save() @%u", (unsigned)i);
ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from dht_save() @%u", (unsigned)i);
}
const int res = DHT_load(m->dht, buffer + extra, size);
const int res = dht_load(m->dht, buffer + extra, size);
if (res == -1) {
ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
@ -264,12 +264,12 @@ START_TEST(test_dht_state_saveloadsave)
(unsigned)offset, (unsigned)size, res & 0x0F);
}
const size_t size2 = DHT_size(m->dht);
const size_t size2 = dht_size(m->dht);
ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", (unsigned)size,
(unsigned)size2);
VLA(uint8_t, buffer2, size2);
DHT_save(m->dht, buffer2);
dht_save(m->dht, buffer2);
ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle");
}

View File

@ -40,7 +40,7 @@ static inline IP get_loopback()
static void do_onion(Onion *onion)
{
networking_poll(onion->net, nullptr);
do_DHT(onion->dht);
do_dht(onion->dht);
}
static int handled_test_1;
@ -167,8 +167,8 @@ START_TEST(test_basic)
logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]);
IP ip = get_loopback();
Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 36567), true));
Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 36568), true));
Onion *onion1 = new_onion(new_dht(log1, new_networking(log1, ip, 36567), true));
Onion *onion2 = new_onion(new_dht(log2, new_networking(log2, ip, 36568), true));
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
@ -256,7 +256,7 @@ START_TEST(test_basic)
Logger *log3 = logger_new();
logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]);
Onion *onion3 = new_onion(new_DHT(log3, new_networking(log3, ip, 36569), true));
Onion *onion3 = new_onion(new_dht(log3, new_networking(log3, ip, 36569), true));
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
random_nonce(nonce);
@ -282,7 +282,7 @@ START_TEST(test_basic)
Networking_Core *net = dht_get_net(onion->dht);
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(log3);
}
@ -293,7 +293,7 @@ START_TEST(test_basic)
Networking_Core *net = dht_get_net(onion->dht);
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(log2);
}
@ -304,7 +304,7 @@ START_TEST(test_basic)
Networking_Core *net = dht_get_net(onion->dht);
DHT *dht = onion->dht;
kill_onion(onion);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(log1);
}
@ -345,7 +345,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
return nullptr;
}
DHT *dht = new_DHT(on->log, net, true);
DHT *dht = new_dht(on->log, net, true);
if (!dht) {
kill_networking(net);
@ -357,7 +357,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
on->onion = new_onion(dht);
if (!on->onion) {
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(on->log);
free(on);
@ -368,7 +368,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
if (!on->onion_a) {
kill_onion(on->onion);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(on->log);
free(on);
@ -381,7 +381,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
if (!on->onion_c) {
kill_onion_announce(on->onion_a);
kill_onion(on->onion);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(on->log);
free(on);
@ -394,7 +394,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
static void do_onions(Onions *on)
{
networking_poll(on->onion->net, nullptr);
do_DHT(on->onion->dht);
do_dht(on->onion->dht);
do_onion_client(on->onion_c);
}
@ -407,7 +407,7 @@ static void kill_onions(Onions *on)
kill_onion_announce(on->onion_a);
kill_onion(on->onion);
kill_net_crypto(c);
kill_DHT(dht);
kill_dht(dht);
kill_networking(net);
logger_kill(on->log);
free(on);
@ -442,8 +442,8 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) {
Onions *on = (Onions *)object;
uint16_t count = 0;
int ret = DHT_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count);
ck_assert_msg(ret == 0, "DHT_addfriend() did not return 0");
int ret = dht_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count);
ck_assert_msg(ret == 0, "dht_addfriend() did not return 0");
ck_assert_msg(count == 1, "Count not 1, count is %u", count);
if (NUM_FIRST == number && !first) {
@ -486,11 +486,11 @@ START_TEST(test_announce)
for (i = 3; i < NUM_ONIONS; ++i) {
IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)};
DHT_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
dht_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)};
DHT_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht));
dht_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht));
IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)};
DHT_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht));
dht_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht));
}
uint32_t connected = 0;
@ -500,7 +500,7 @@ START_TEST(test_announce)
for (i = 0; i < NUM_ONIONS; ++i) {
do_onions(onions[i]);
connected += DHT_isconnected(onions[i]->onion->dht);
connected += dht_isconnected(onions[i]->onion->dht);
}
c_sleep(50);

View File

@ -117,7 +117,7 @@ int main(int argc, char *argv[])
ip_init(&ip, ipv6enabled);
Logger *logger = logger_new();
DHT *dht = new_DHT(logger, new_networking(logger, ip, PORT), true);
DHT *dht = new_dht(logger, new_networking(logger, ip, PORT), true);
Onion *onion = new_onion(dht);
Onion_Announce *onion_a = new_onion_announce(dht);
@ -171,7 +171,7 @@ int main(int argc, char *argv[])
printf("Trying to bootstrap into the network...\n");
uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1],
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);
@ -187,12 +187,12 @@ int main(int argc, char *argv[])
lan_discovery_init(dht);
while (1) {
if (is_waiting_for_dht_connection && DHT_isconnected(dht)) {
if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
printf("Connected to other bootstrap node successfully.\n");
is_waiting_for_dht_connection = 0;
}
do_DHT(dht);
do_dht(dht);
if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(net_htons(PORT), dht);

View File

@ -408,7 +408,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
}
bs_public_key_bin = hex_string_to_bin(bs_public_key);
address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port),
address_resolved = dht_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port),
bs_public_key_bin);
free(bs_public_key_bin);

View File

@ -250,7 +250,7 @@ int main(int argc, char *argv[])
}
}
DHT *dht = new_DHT(logger, net, true);
DHT *dht = new_dht(logger, net, true);
if (dht == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
@ -333,7 +333,7 @@ int main(int argc, char *argv[])
}
while (1) {
do_DHT(dht);
do_dht(dht);
if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) {
lan_discovery_send(net_htons_port, dht);
@ -346,7 +346,7 @@ int main(int argc, char *argv[])
networking_poll(dht_get_net(dht), nullptr);
if (waiting_for_dht_connection && DHT_isconnected(dht)) {
if (waiting_for_dht_connection && dht_isconnected(dht)) {
log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
waiting_for_dht_connection = 0;
}

View File

@ -128,7 +128,7 @@ static void print_friendlist(DHT *dht)
print_client_id(dht_get_friend_public_key(dht, k));
int friendok = DHT_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip);
int friendok = dht_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip);
char ip_str[IP_NTOA_LEN];
printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok);
@ -190,7 +190,7 @@ int main(int argc, char *argv[])
IP ip;
ip_init(&ip, ipv6enabled);
DHT *dht = new_DHT(nullptr, new_networking(nullptr, ip, PORT), true);
DHT *dht = new_dht(nullptr, new_networking(nullptr, ip, PORT), true);
printf("OUR ID: ");
uint32_t i;
@ -216,14 +216,14 @@ int main(int argc, char *argv[])
}
uint8_t *bin_id = hex_string_to_bin(temp_id);
DHT_addfriend(dht, bin_id, 0, 0, 0, 0);
dht_addfriend(dht, bin_id, 0, 0, 0, 0);
free(bin_id);
perror("Initialization");
uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
free(binary_string);
if (!res) {
@ -238,12 +238,12 @@ int main(int argc, char *argv[])
#endif
while (1) {
do_DHT(dht);
do_dht(dht);
#if 0 /* TODO(slvr): */
while (receivepacket(&ip_port, data, &length) != -1) {
if (DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) {
if (dht_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) {
//unhandled packet
printpacket(data, length, ip_port);
} else {

View File

@ -121,7 +121,7 @@ int main(int argc, char *argv[])
if (argc == argvoffset + 4) {
uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1],
int res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1],
ipv6enabled, port, bootstrap_key);
free(bootstrap_key);

View File

@ -283,7 +283,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t
/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive.
*/
void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
{
get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key);
}
@ -291,7 +291,7 @@ void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *publi
/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send.
*/
void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
{
get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key);
}
@ -455,7 +455,7 @@ int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
}
}
static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet)
{
VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE);
@ -1315,9 +1315,9 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, &ping_id, sizeof(ping_id));
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
DHT_get_shared_key_sent(dht, shared_key, public_key);
dht_get_shared_key_sent(dht, shared_key, public_key);
const int len = DHT_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES,
const int len = dht_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES,
plain, sizeof(plain), data);
if (len != sizeof(data)) {
@ -1364,7 +1364,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE;
VLA(uint8_t, data, 1 + nodes_length + length + crypto_size);
const int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6,
const int len = dht_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6,
plain, 1 + nodes_length + length, data);
if (len != SIZEOF_VLA(data)) {
@ -1392,7 +1392,7 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
uint8_t plain[CRYPTO_NODE_SIZE];
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
DHT_get_shared_key_recv(dht, shared_key, packet + 1);
dht_get_shared_key_recv(dht, shared_key, packet + 1);
const int len = decrypt_data_symmetric(
shared_key,
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
@ -1462,7 +1462,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
VLA(uint8_t, plain, 1 + data_size + sizeof(uint64_t));
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
DHT_get_shared_key_sent(dht, shared_key, packet + 1);
dht_get_shared_key_sent(dht, shared_key, packet + 1);
const int len = decrypt_data_symmetric(
shared_key,
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
@ -1538,7 +1538,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *pa
/*----------------------------------------------------------------------------------*/
/*------------------------END of packet handling functions--------------------------*/
int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
int dht_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
void *data, int32_t number, uint16_t *lock_count)
{
const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key);
@ -1595,7 +1595,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
return 0;
}
int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
{
const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key);
@ -1639,7 +1639,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
}
/* TODO(irungentoo): Optimize this. */
int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
{
ip_reset(&ip_port->ip);
ip_port->port = 0;
@ -1743,7 +1743,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
* every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
*/
static void do_DHT_friends(DHT *dht)
static void do_dht_friends(DHT *dht)
{
for (size_t i = 0; i < dht->num_friends; ++i) {
DHT_Friend *const dht_friend = &dht->friends_list[i];
@ -1803,16 +1803,16 @@ static void do_Close(DHT *dht)
}
}
void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id)
void dht_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id)
{
getnodes(dht, *from_ipp, from_id, which_id, nullptr);
}
void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
void dht_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
{
getnodes(dht, ip_port, public_key, dht->self_public_key, nullptr);
}
int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
uint16_t port, const uint8_t *public_key)
{
IP_Port ip_port_v64;
@ -1829,11 +1829,11 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) {
ip_port_v64.port = port;
DHT_bootstrap(dht, ip_port_v64, public_key);
dht_bootstrap(dht, ip_port_v64, public_key);
if ((ip_extra != nullptr) && ip_isset(ip_extra)) {
ip_port_v4.port = port;
DHT_bootstrap(dht, ip_port_v4, public_key);
dht_bootstrap(dht, ip_port_v4, public_key);
}
return 1;
@ -2673,7 +2673,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
/*----------------------------------------------------------------------------------*/
DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled)
{
/* init time */
unix_time_update();
@ -2696,7 +2696,7 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
dht->ping = ping_new(dht);
if (dht->ping == nullptr) {
kill_DHT(dht);
kill_dht(dht);
return nullptr;
}
@ -2715,8 +2715,8 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
random_bytes(random_key_bytes, sizeof(random_key_bytes));
if (DHT_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) {
kill_DHT(dht);
if (dht_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) {
kill_dht(dht);
return nullptr;
}
}
@ -2724,7 +2724,7 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
return dht;
}
void do_DHT(DHT *dht)
void do_dht(DHT *dht)
{
unix_time_update();
@ -2732,13 +2732,13 @@ void do_DHT(DHT *dht)
return;
}
// Load friends/clients if first call to do_DHT
// Load friends/clients if first call to do_dht
if (dht->loaded_num_nodes) {
DHT_connect_after_load(dht);
dht_connect_after_load(dht);
}
do_Close(dht);
do_DHT_friends(dht);
do_dht_friends(dht);
do_NAT(dht);
ping_iterate(dht->ping);
#if DHT_HARDENING
@ -2747,7 +2747,7 @@ void do_DHT(DHT *dht)
dht->last_run = unix_time();
}
void kill_DHT(DHT *dht)
void kill_dht(DHT *dht)
{
networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr);
@ -2771,7 +2771,7 @@ void kill_DHT(DHT *dht)
#define MAX_SAVED_DHT_NODES (((DHT_FAKE_FRIEND_NUMBER * MAX_FRIEND_CLIENTS) + LCLIENT_LIST) * 2)
/* Get the size of the DHT (for saving). */
uint32_t DHT_size(const DHT *dht)
uint32_t dht_size(const DHT *dht)
{
uint32_t numv4 = 0;
uint32_t numv6 = 0;
@ -2796,7 +2796,7 @@ uint32_t DHT_size(const DHT *dht)
return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6;
}
static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
static uint8_t *dht_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
{
host_to_lendian32(data, len);
data += sizeof(uint32_t);
@ -2806,8 +2806,8 @@ static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
}
/* Save the DHT in data where data is an array of size DHT_size(). */
void DHT_save(const DHT *dht, uint8_t *data)
/* Save the DHT in data where data is an array of size dht_size(). */
void dht_save(const DHT *dht, uint8_t *data)
{
host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
data += sizeof(uint32_t);
@ -2815,7 +2815,7 @@ void DHT_save(const DHT *dht, uint8_t *data)
uint8_t *const old_data = data;
/* get right offset. we write the actual header later. */
data = DHT_save_subheader(data, 0, 0);
data = dht_save_subheader(data, 0, 0);
Node_format clients[MAX_SAVED_DHT_NODES];
@ -2853,14 +2853,14 @@ void DHT_save(const DHT *dht, uint8_t *data)
}
}
DHT_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES);
dht_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES);
}
/* Bootstrap from this number of nodes every time DHT_connect_after_load() is called */
/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
#define SAVE_BOOTSTAP_FREQUENCY 8
/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */
int DHT_connect_after_load(DHT *dht)
int dht_connect_after_load(DHT *dht)
{
if (dht == nullptr) {
return -1;
@ -2871,7 +2871,7 @@ int DHT_connect_after_load(DHT *dht)
}
/* DHT is connected, stop. */
if (DHT_non_lan_connected(dht)) {
if (dht_non_lan_connected(dht)) {
free(dht->loaded_nodes_list);
dht->loaded_nodes_list = nullptr;
dht->loaded_num_nodes = 0;
@ -2880,7 +2880,7 @@ int DHT_connect_after_load(DHT *dht)
for (uint32_t i = 0; i < dht->loaded_num_nodes && i < SAVE_BOOTSTAP_FREQUENCY; ++i) {
const unsigned int index = dht->loaded_nodes_index % dht->loaded_num_nodes;
DHT_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key);
dht_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key);
++dht->loaded_nodes_index;
}
@ -2926,7 +2926,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
* return -1 if failure.
* return 0 if success.
*/
int DHT_load(DHT *dht, const uint8_t *data, uint32_t length)
int dht_load(DHT *dht, const uint8_t *data, uint32_t length)
{
const uint32_t cookie_len = sizeof(uint32_t);
@ -2946,7 +2946,7 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length)
/* return false if we are not connected to the DHT.
* return true if we are.
*/
bool DHT_isconnected(const DHT *dht)
bool dht_isconnected(const DHT *dht)
{
unix_time_update();
@ -2965,7 +2965,7 @@ bool DHT_isconnected(const DHT *dht)
/* return false if we are not connected or only connected to lan peers with the DHT.
* return true if we are.
*/
bool DHT_non_lan_connected(const DHT *dht)
bool dht_non_lan_connected(const DHT *dht)
{
unix_time_update();

View File

@ -252,14 +252,14 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t
/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we receive.
*/
void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
* for packets that we send.
*/
void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id);
void dht_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id);
/* Add a new friend to the friends list.
* public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
@ -267,13 +267,13 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con
* ip_callback is the callback of a function that will be called when the ip address
* is found along with arguments data and number.
*
* lock_count will be set to a non zero number that must be passed to DHT_delfriend()
* lock_count will be set to a non zero number that must be passed to dht_delfriend()
* to properly remove the callback.
*
* return 0 if success.
* return -1 if failure (friends list is full).
*/
int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
int dht_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
void *data, int32_t number, uint16_t *lock_count);
/* Delete a friend from the friends list.
@ -282,20 +282,20 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
* return 0 if success.
* return -1 if failure (public_key not in friends list).
*/
int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count);
int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count);
/* Get ip of friend.
* public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
* ip must be 4 bytes long.
* port must be 2 bytes long.
*
* int DHT_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port);
* int dht_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port);
*
* return -1, -- if public_key does NOT refer to a friend
* return 0, -- if public_key refers to a friend and we failed to find the friend (yet)
* return 1, ip if public_key refers to a friend and we found him
*/
int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
/* Compares pk1 and pk2 with pk.
*
@ -341,7 +341,7 @@ uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
/* Run this function at least a couple times per second (It's the main loop). */
void do_DHT(DHT *dht);
void do_dht(DHT *dht);
/*
* Use these two functions to bootstrap the client.
@ -349,7 +349,7 @@ void do_DHT(DHT *dht);
/* Sends a "get nodes" request to the given node with ip, port and public_key
* to setup connections
*/
void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
void dht_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
/* Resolves address into an IP address. If successful, sends a "get nodes"
* request to the given node with ip, port and public_key to setup connections
*
@ -361,7 +361,7 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
* returns 1 if the address could be converted into an IP address
* returns 0 otherwise
*/
int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
uint16_t port, const uint8_t *public_key);
/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
@ -369,7 +369,7 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
* returns 0 if successful
* returns -1 otherwise
*/
int DHT_connect_after_load(DHT *dht);
int dht_connect_after_load(DHT *dht);
/* ROUTING FUNCTIONS */
@ -392,32 +392,32 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
/* SAVE/LOAD functions */
/* Get the size of the DHT (for saving). */
uint32_t DHT_size(const DHT *dht);
uint32_t dht_size(const DHT *dht);
/* Save the DHT in data where data is an array of size DHT_size(). */
void DHT_save(const DHT *dht, uint8_t *data);
/* Save the DHT in data where data is an array of size dht_size(). */
void dht_save(const DHT *dht, uint8_t *data);
/* Load the DHT from data of size size.
*
* return -1 if failure.
* return 0 if success.
*/
int DHT_load(DHT *dht, const uint8_t *data, uint32_t length);
int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
/* Initialize DHT. */
DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled);
DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled);
void kill_DHT(DHT *dht);
void kill_dht(DHT *dht);
/* return false if we are not connected to the DHT.
* return true if we are.
*/
bool DHT_isconnected(const DHT *dht);
bool dht_isconnected(const DHT *dht);
/* return false if we are not connected or only connected to lan peers with the DHT.
* return true if we are.
*/
bool DHT_non_lan_connected(const DHT *dht);
bool dht_non_lan_connected(const DHT *dht);
uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key);

View File

@ -371,7 +371,7 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
return 1;
}
DHT_bootstrap(dht, source, packet + 1);
dht_bootstrap(dht, source, packet + 1);
return 0;
}

View File

@ -383,7 +383,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
}
if (m->read_receipt) {
(*m->read_receipt)(m, friendnumber, receipts->msg_id, userdata);
m->read_receipt(m, friendnumber, receipts->msg_id, userdata);
}
struct Receipts *r_next = receipts->next;
@ -684,7 +684,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
return 0;
}
m->userstatus = (USERSTATUS)status;
m->userstatus = (Userstatus)status;
uint32_t i;
for (i = 0; i < m->numfriends; ++i) {
@ -830,7 +830,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{
m->friendlist[friendnumber].userstatus = (USERSTATUS)status;
m->friendlist[friendnumber].userstatus = (Userstatus)status;
}
static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
@ -844,55 +844,53 @@ void m_callback_log(Messenger *m, logger_cb *function, void *context, void *user
}
/* Set the function that will be executed when a friend request is received. */
void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t,
void *))
void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function)
{
callback_friendrequest(m->fr, (void (*)(void *, const uint8_t *, const uint8_t *, size_t, void *))function, m);
callback_friendrequest(m->fr, (fr_friend_request_cb *)function, m);
}
/* Set the function that will be executed when a message from a friend is received. */
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, const uint8_t *,
size_t, void *))
void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function)
{
m->friend_message = function;
}
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *))
void m_callback_namechange(Messenger *m, m_friend_name_cb *function)
{
m->friend_namechange = function;
}
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *))
void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function)
{
m->friend_statusmessagechange = function;
}
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *))
void m_callback_userstatus(Messenger *m, m_friend_status_cb *function)
{
m->friend_userstatuschange = function;
}
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, bool, void *))
void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function)
{
m->friend_typingchange = function;
}
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *))
void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function)
{
m->read_receipt = function;
}
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *))
void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function)
{
m->friend_connectionstatuschange = function;
}
void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *))
void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function)
{
m->core_connection_change = function;
}
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *),
void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function,
void *userdata)
{
m->friend_connectionstatuschange_internal = function;
@ -993,8 +991,7 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_
*
* Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
*/
void m_callback_conference_invite(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t,
void *))
void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function)
{
m->conference_invite = function;
}
@ -1017,8 +1014,7 @@ int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, cons
*
* Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata)
*/
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t,
const uint8_t *, size_t, void *))
void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function)
{
m->file_sendrequest = function;
}
@ -1028,7 +1024,7 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uin
* Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata)
*
*/
void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *))
void callback_file_control(Messenger *m, m_file_recv_control_cb *function)
{
m->file_filecontrol = function;
}
@ -1038,8 +1034,7 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t
* Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, uint8_t *data, size_t length, void *userdata)
*
*/
void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *,
size_t, void *))
void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function)
{
m->file_filedata = function;
}
@ -1049,7 +1044,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u
* Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata)
*
*/
void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *))
void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function)
{
m->file_reqchunk = function;
}
@ -1579,7 +1574,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
}
// Allocate 1 slot to this file transfer.
ft->slots_allocated++;
++ft->slots_allocated;
const uint16_t length = min_u64(ft->size - ft->requested, MAX_FILE_DATA_SIZE);
const uint64_t position = ft->requested;
@ -1628,11 +1623,11 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat
//
// TODO(zoff99): Fix this to exit the loop properly when we're done
// requesting all chunks for all file transfers.
const uint32_t MAX_FT_LOOPS = 16;
const uint32_t max_ft_loops = 16;
while (((free_slots > 0) || loop_counter == 0) && any_active_fts && (loop_counter < MAX_FT_LOOPS)) {
while (((free_slots > 0) || loop_counter == 0) && any_active_fts && (loop_counter < max_ft_loops)) {
any_active_fts = do_all_filetransfers(m, friendnumber, userdata, &free_slots);
loop_counter++;
++loop_counter;
}
}
@ -1773,7 +1768,8 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
return -1;
}
ft->transferred = ft->requested = position;
ft->requested = position;
ft->transferred = position;
return 0;
}
@ -1791,8 +1787,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
*
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
*/
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *),
void *userdata)
void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata)
{
m->msi_packet = function;
m->msi_packet_userdata = userdata;
@ -1834,14 +1829,13 @@ static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint
return 1;
}
void custom_lossy_packet_registerhandler(Messenger *m, void (*lossy_packethandler)(Messenger *m,
uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler)
{
m->lossy_packethandler = lossy_packethandler;
}
int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*function)(Messenger *m,
uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object)
int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function,
void *object)
{
if (friend_not_valid(m, friendnumber)) {
return -1;
@ -1915,8 +1909,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
return 1;
}
void custom_lossless_packet_registerhandler(Messenger *m, void (*lossless_packethandler)(Messenger *m,
uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler)
{
m->lossless_packethandler = lossless_packethandler;
}
@ -2025,7 +2018,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
return nullptr;
}
m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled);
m->dht = new_dht(m->log, m->net, options->hole_punching_enabled);
if (m->dht == nullptr) {
kill_networking(m->net);
@ -2039,7 +2032,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
if (m->net_crypto == nullptr) {
kill_networking(m->net);
kill_DHT(m->dht);
kill_dht(m->dht);
friendreq_kill(m->fr);
logger_kill(m->log);
free(m);
@ -2057,7 +2050,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_DHT(m->dht);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
@ -2075,7 +2068,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_DHT(m->dht);
kill_dht(m->dht);
kill_networking(m->net);
friendreq_kill(m->fr);
logger_kill(m->log);
@ -2121,7 +2114,7 @@ void kill_messenger(Messenger *m)
kill_onion_announce(m->onion_a);
kill_onion_client(m->onion_c);
kill_net_crypto(m->net_crypto);
kill_DHT(m->dht);
kill_dht(m->dht);
kill_networking(m->net);
for (i = 0; i < m->numfriends; ++i) {
@ -2241,7 +2234,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
break;
}
USERSTATUS status = (USERSTATUS)data[0];
Userstatus status = (Userstatus)data[0];
if (status >= USERSTATUS_INVALID) {
break;
@ -2541,7 +2534,7 @@ static void do_friends(Messenger *m, void *userdata)
}
}
static void connection_status_cb(Messenger *m, void *userdata)
static void connection_status_callback(Messenger *m, void *userdata)
{
unsigned int conn_status = onion_connection_status(m->onion_c);
@ -2566,7 +2559,7 @@ static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
return id_str;
}
for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; i++) {
for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) {
sprintf(&id_str[i * 2], "%02X", pk[i]);
}
@ -2622,7 +2615,7 @@ void do_messenger(Messenger *m, void *userdata)
if (!m->options.udp_disabled) {
networking_poll(m->net, userdata);
do_DHT(m->dht);
do_dht(m->dht);
}
if (m->tcp_server) {
@ -2633,18 +2626,18 @@ void do_messenger(Messenger *m, void *userdata)
do_onion_client(m->onion_c);
do_friend_connections(m->fr_c, userdata);
do_friends(m, userdata);
connection_status_cb(m, userdata);
connection_status_callback(m, userdata);
if (unix_time() > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
m->lastdump = unix_time();
uint32_t client, last_pinged;
for (client = 0; client < LCLIENT_LIST; client++) {
for (client = 0; client < LCLIENT_LIST; ++client) {
const Client_data *cptr = dht_get_close_client(m->dht, client);
const IPPTsPng *assoc = nullptr;
uint32_t a;
for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
for (a = 0, assoc = &cptr->assoc4; a < 2; ++a, assoc = &cptr->assoc6) {
if (ip_isset(&assoc->ip_port.ip)) {
last_pinged = m->lastdump - assoc->last_pinged;
@ -2670,7 +2663,7 @@ void do_messenger(Messenger *m, void *userdata)
VLA(int32_t, m2dht, num_dhtfriends);
VLA(int32_t, dht2m, num_dhtfriends);
for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
m2dht[friend_idx] = -1;
dht2m[friend_idx] = -1;
@ -2678,7 +2671,7 @@ void do_messenger(Messenger *m, void *userdata)
continue;
}
for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); dhtfriend++) {
for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); ++dhtfriend) {
if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) {
m2dht[friend_idx] = dhtfriend;
break;
@ -2686,7 +2679,7 @@ void do_messenger(Messenger *m, void *userdata)
}
}
for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
if (m2dht[friend_idx] >= 0) {
dht2m[m2dht[friend_idx]] = friend_idx;
}
@ -2699,7 +2692,7 @@ void do_messenger(Messenger *m, void *userdata)
Friend *msgfptr;
DHT_Friend *dhtfptr;
for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
if (dht2m[friend_idx] >= 0) {
msgfptr = &m->friendlist[dht2m[friend_idx]];
} else {
@ -2719,11 +2712,11 @@ void do_messenger(Messenger *m, void *userdata)
id_to_string(dht_friend_public_key(dhtfptr), id_str, sizeof(id_str)));
}
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
for (client = 0; client < MAX_FRIEND_CLIENTS; ++client) {
const Client_data *cptr = dht_friend_client(dhtfptr, client);
const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6};
for (size_t a = 0; a < sizeof(assocs) / sizeof(assocs[0]); a++) {
for (size_t a = 0; a < sizeof(assocs) / sizeof(assocs[0]); ++a) {
const IPPTsPng *const assoc = assocs[a];
if (ip_isset(&assoc->ip_port.ip)) {
@ -2764,7 +2757,7 @@ void do_messenger(Messenger *m, void *userdata)
#define SAVED_FRIEND_REQUEST_SIZE 1024
#define NUM_SAVED_PATH_NODES 8
struct SAVED_FRIEND {
struct Saved_Friend {
uint8_t status;
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do.
@ -2781,21 +2774,21 @@ struct SAVED_FRIEND {
static uint32_t friend_size(void)
{
uint32_t data = 0;
const struct SAVED_FRIEND *const temp = nullptr;
const struct Saved_Friend *const temp = nullptr;
#define VALUE_MEMBER(NAME) data += sizeof(temp->NAME)
#define ARRAY_MEMBER(NAME) data += sizeof(temp->NAME)
#define VALUE_MEMBER(name) do { data += sizeof(temp->name); } while (0)
#define ARRAY_MEMBER(name) do { data += sizeof(temp->name); } while (0)
// Exactly the same in friend_load, friend_save, and friend_size
VALUE_MEMBER(status);
ARRAY_MEMBER(real_pk);
ARRAY_MEMBER(info);
data++; // padding
++data; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
++data; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
@ -2813,26 +2806,28 @@ static uint32_t saved_friendslist_size(const Messenger *m)
return count_friendlist(m) * friend_size();
}
static uint8_t *friend_save(const struct SAVED_FRIEND *temp, uint8_t *data)
static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
{
#define VALUE_MEMBER(NAME) \
memcpy(data, &temp->NAME, sizeof(temp->NAME)); \
data += sizeof(temp->NAME)
#define VALUE_MEMBER(name) do { \
memcpy(data, &temp->name, sizeof(temp->name)); \
data += sizeof(temp->name); \
} while (0)
#define ARRAY_MEMBER(NAME) \
memcpy(data, temp->NAME, sizeof(temp->NAME)); \
data += sizeof(temp->NAME)
#define ARRAY_MEMBER(name) do { \
memcpy(data, temp->name, sizeof(temp->name)); \
data += sizeof(temp->name); \
} while (0)
// Exactly the same in friend_load, friend_save, and friend_size
VALUE_MEMBER(status);
ARRAY_MEMBER(real_pk);
ARRAY_MEMBER(info);
data++; // padding
++data; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
++data; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
@ -2851,9 +2846,9 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
uint32_t num = 0;
uint8_t *cur_data = data;
for (i = 0; i < m->numfriends; i++) {
for (i = 0; i < m->numfriends; ++i) {
if (m->friendlist[i].status > 0) {
struct SAVED_FRIEND temp = { 0 };
struct Saved_Friend temp = { 0 };
temp.status = m->friendlist[i].status;
memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE);
@ -2884,7 +2879,7 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
assert(memcmp(cur_data, &temp, friend_size()) == 0);
#endif
cur_data = next_data;
num++;
++num;
}
}
@ -2892,26 +2887,28 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
return cur_data - data;
}
static const uint8_t *friend_load(struct SAVED_FRIEND *temp, const uint8_t *data)
static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
{
#define VALUE_MEMBER(NAME) \
memcpy(&temp->NAME, data, sizeof(temp->NAME)); \
data += sizeof(temp->NAME)
#define VALUE_MEMBER(name) do { \
memcpy(&temp->name, data, sizeof(temp->name)); \
data += sizeof(temp->name); \
} while (0)
#define ARRAY_MEMBER(NAME) \
memcpy(temp->NAME, data, sizeof(temp->NAME)); \
data += sizeof(temp->NAME)
#define ARRAY_MEMBER(name) do { \
memcpy(temp->name, data, sizeof(temp->name)); \
data += sizeof(temp->name); \
} while (0)
// Exactly the same in friend_load, friend_save, and friend_size
VALUE_MEMBER(status);
ARRAY_MEMBER(real_pk);
ARRAY_MEMBER(info);
data++; // padding
++data; // padding
VALUE_MEMBER(info_size);
ARRAY_MEMBER(name);
VALUE_MEMBER(name_length);
ARRAY_MEMBER(statusmessage);
data++; // padding
++data; // padding
VALUE_MEMBER(statusmessage_length);
VALUE_MEMBER(userstatus);
data += 3; // padding
@ -2935,7 +2932,7 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
const uint8_t *cur_data = data;
for (i = 0; i < num; ++i) {
struct SAVED_FRIEND temp = { 0 };
struct Saved_Friend temp = { 0 };
const uint8_t *next_data = friend_load(&temp, cur_data);
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
@ -2977,7 +2974,7 @@ uint32_t messenger_size(const Messenger *m)
uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
return size32 * 2 // global cookie
+ sizesubhead + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE
+ sizesubhead + DHT_size(m->dht) // DHT
+ sizesubhead + dht_size(m->dht) // DHT
+ sizesubhead + saved_friendslist_size(m) // Friendlist itself.
+ sizesubhead + m->name_length // Own nickname.
+ sizesubhead + m->statusmessage_length // status message
@ -3042,10 +3039,10 @@ void messenger_save(const Messenger *m, uint8_t *data)
*data = m->userstatus;
data += len;
len = DHT_size(m->dht);
len = dht_size(m->dht);
type = MESSENGER_STATE_TYPE_DHT;
data = messenger_save_subheader(data, len, type);
DHT_save(m->dht, data);
dht_save(m->dht, data);
data += len;
Node_format relays[NUM_SAVED_TCP_RELAYS];
@ -3098,7 +3095,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
break;
case MESSENGER_STATE_TYPE_DHT:
DHT_load(m->dht, data, length);
dht_load(m->dht, data, length);
break;
case MESSENGER_STATE_TYPE_FRIENDS:
@ -3199,9 +3196,9 @@ uint32_t count_friendlist(const Messenger *m)
uint32_t ret = 0;
uint32_t i;
for (i = 0; i < m->numfriends; i++) {
for (i = 0; i < m->numfriends; ++i) {
if (m->friendlist[i].status > 0) {
ret++;
++ret;
}
}
@ -3226,14 +3223,14 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s
uint32_t i;
uint32_t ret = 0;
for (i = 0; i < m->numfriends; i++) {
for (i = 0; i < m->numfriends; ++i) {
if (ret >= list_size) {
break; /* Abandon ship */
}
if (m->friendlist[i].status > 0) {
out_list[ret] = i;
ret++;
++ret;
}
}

View File

@ -136,8 +136,7 @@ typedef enum {
USERSTATUS_AWAY,
USERSTATUS_BUSY,
USERSTATUS_INVALID
}
USERSTATUS;
} Userstatus;
#define FILE_ID_LENGTH 32
@ -181,6 +180,26 @@ enum {
typedef struct Messenger Messenger;
typedef void m_self_connection_status_cb(Messenger *, unsigned int, void *);
typedef void m_friend_status_cb(Messenger *, uint32_t, unsigned int, void *);
typedef void m_friend_connection_status_cb(Messenger *, uint32_t, unsigned int, void *);
typedef void m_friend_message_cb(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *);
typedef void m_file_recv_control_cb(Messenger *, uint32_t, uint32_t, unsigned int, void *);
typedef void m_friend_request_cb(Messenger *, const uint8_t *, const uint8_t *, size_t, void *);
typedef void m_friend_name_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
typedef void m_friend_status_message_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
typedef void m_friend_typing_cb(Messenger *m, uint32_t, bool, void *);
typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t, uint32_t, void *);
typedef void m_file_recv_cb(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
typedef void m_file_chunk_request_cb(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t, uint8_t, void *);
typedef void m_conference_invite_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
typedef void m_msi_packet_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object);
typedef struct {
uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
int friendcon_id;
@ -195,7 +214,7 @@ typedef struct {
uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmessage_length;
uint8_t statusmessage_sent;
USERSTATUS userstatus;
Userstatus userstatus;
uint8_t userstatus_sent;
uint8_t user_istyping;
uint8_t user_istyping_sent;
@ -210,7 +229,7 @@ typedef struct {
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
struct {
int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object);
m_lossy_rtp_packet_cb *function;
void *object;
} lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
@ -239,7 +258,7 @@ struct Messenger {
uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmessage_length;
USERSTATUS userstatus;
Userstatus userstatus;
Friend *friendlist;
uint32_t numfriends;
@ -249,32 +268,31 @@ struct Messenger {
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *);
void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *);
void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *);
void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *);
void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *);
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_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
void *friend_connectionstatuschange_internal_userdata;
void *conferences_object; /* Set by new_groupchats()*/
void (*conference_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
m_conference_invite_cb *conference_invite;
void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t,
void *);
void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *);
void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
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;
void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
m_msi_packet_cb *msi_packet;
void *msi_packet_userdata;
void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *);
m_friend_lossy_packet_cb *lossy_packethandler;
m_friend_lossless_packet_cb *lossless_packethandler;
void (*core_connection_change)(struct Messenger *m, unsigned int, void *);
m_self_connection_status_cb *core_connection_change;
unsigned int last_connection_status;
Messenger_Options options;
@ -440,9 +458,9 @@ int m_get_self_statusmessage_size(const Messenger *m);
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
/* return one of USERSTATUS values.
/* return one of Userstatus values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own USERSTATUS.
* As above, the self variant will return our own Userstatus.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
@ -499,7 +517,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *));
/* Set the callback for status type changes.
* Function(uint32_t friendnumber, USERSTATUS kind)
* Function(uint32_t friendnumber, Userstatus kind)
*/
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *));

View File

@ -354,7 +354,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
friend_con->dht_pk_lastrecv = unix_time();
if (friend_con->dht_lock) {
if (DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) {
if (dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) {
printf("a. Could not delete dht peer. Please report this.\n");
return;
}
@ -362,7 +362,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
friend_con->dht_lock = 0;
}
DHT_addfriend(fr_c->dht, dht_public_key, dht_ip_callback, fr_c, friendcon_id, &friend_con->dht_lock);
dht_addfriend(fr_c->dht, dht_public_key, dht_ip_callback, fr_c, friendcon_id, &friend_con->dht_lock);
memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
}
@ -789,7 +789,7 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id)
crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
if (friend_con->dht_lock) {
DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
}
return wipe_friend_conn(fr_c, friendcon_id);
@ -909,7 +909,7 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
if (friend_con->status == FRIENDCONN_STATUS_CONNECTING) {
if (friend_con->dht_pk_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
if (friend_con->dht_lock) {
DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
friend_con->dht_lock = 0;
memset(friend_con->dht_temp_pk, 0, CRYPTO_PUBLIC_KEY_SIZE);
}

View File

@ -41,11 +41,12 @@ uint32_t get_nospam(const Friend_Requests *fr);
*/
int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk);
typedef void fr_friend_request_cb(void *, const uint8_t *, const uint8_t *, size_t, void *);
/* Set the function that will be executed when a friend request for us is received.
* Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata)
*/
void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t,
void *), void *object);
void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object);
/* Set the function used to check if a friend request should be displayed to the user or not.
* Function format is int function(uint8_t * public_key, void * userdata)

View File

@ -108,6 +108,9 @@ typedef struct {
void (*group_on_delete)(void *, uint32_t);
} Group_c;
typedef void g_conference_invite_cb(Messenger *, uint32_t, int, const uint8_t *, size_t, void *);
typedef void g_conference_message_cb(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
typedef struct {
Messenger *m;
Friend_Connections *fr_c;
@ -115,8 +118,8 @@ typedef struct {
Group_c *chats;
uint32_t num_chats;
void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *);
void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
g_conference_invite_cb *invite_callback;
g_conference_message_cb *message_callback;
void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *);
void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);

View File

@ -224,7 +224,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *
memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, padding, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(plain + (CRYPTO_PUBLIC_KEY_SIZE * 2), &number, sizeof(uint64_t));
DHT_get_shared_key_sent(c->dht, shared_key, dht_public_key);
dht_get_shared_key_sent(c->dht, shared_key, dht_public_key);
uint8_t nonce[CRYPTO_NONCE_SIZE];
random_nonce(nonce);
packet[0] = NET_PACKET_COOKIE_REQUEST;
@ -335,7 +335,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
}
memcpy(dht_public_key, packet + 1, CRYPTO_PUBLIC_KEY_SIZE);
DHT_get_shared_key_sent(c->dht, shared_key, dht_public_key);
dht_get_shared_key_sent(c->dht, shared_key, dht_public_key);
int len = decrypt_data_symmetric(shared_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, COOKIE_REQUEST_PLAIN_LENGTH + CRYPTO_MAC_SIZE,
request_plain);

View File

@ -265,8 +265,8 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES;
//if (DHT_non_lan_connected(onion_c->dht)) {
if (DHT_isconnected(onion_c->dht)) {
//if (dht_non_lan_connected(onion_c->dht)) {
if (dht_isconnected(onion_c->dht)) {
if (num_nodes == 0) {
return 0;
}
@ -990,7 +990,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
const Family family = nodes[i].ip_port.ip.family;
if (net_family_is_ipv4(family) || net_family_is_ipv6(family)) {
DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key);
dht_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key);
} else if (net_family_is_tcp_ipv4(family) || net_family_is_tcp_ipv6(family)) {
if (onion_c->friends_list[friend_num].tcp_relay_node_callback) {
void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object;
@ -1326,8 +1326,13 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
return -1;
}
//if (onion_c->friends_list[friend_num].know_dht_public_key)
// DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0);
#if 0
if (onion_c->friends_list[friend_num].know_dht_public_key) {
dht_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0);
}
#endif
crypto_memzero(&onion_c->friends_list[friend_num], sizeof(Onion_Friend));
unsigned int i;
@ -1456,7 +1461,7 @@ int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_p
return -1;
}
return DHT_getfriendip(onion_c->dht, dht_public_key, ip_port);
return dht_getfriendip(onion_c->dht, dht_public_key, ip_port);
}
@ -1824,7 +1829,7 @@ void do_onion_client(Onion_Client *onion_c)
}
}
bool UDP_connected = DHT_non_lan_connected(onion_c->dht);
bool UDP_connected = dht_non_lan_connected(onion_c->dht);
if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) {
set_tcp_onion_status(nc_get_tcp_c(onion_c->c), !UDP_connected);

View File

@ -72,7 +72,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
// generate key to encrypt ping_id with recipient privkey
DHT_get_shared_key_sent(ping->dht, shared_key, public_key);
dht_get_shared_key_sent(ping->dht, shared_key, public_key);
// Generate random ping_id.
uint8_t data[PING_DATA_SIZE];
id_copy(data, public_key);
@ -154,7 +154,7 @@ static int handle_ping_request(void *object, IP_Port source, const uint8_t *pack
uint8_t ping_plain[PING_PLAIN_SIZE];
// Decrypt ping_id
DHT_get_shared_key_recv(dht, shared_key, packet + 1);
dht_get_shared_key_recv(dht, shared_key, packet + 1);
rc = decrypt_data_symmetric(shared_key,
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE,
@ -196,7 +196,7 @@ static int handle_ping_response(void *object, IP_Port source, const uint8_t *pac
uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
// generate key to encrypt ping_id with recipient privkey
DHT_get_shared_key_sent(ping->dht, shared_key, packet + 1);
dht_get_shared_key_sent(ping->dht, shared_key, packet + 1);
uint8_t ping_plain[PING_PLAIN_SIZE];
// Decrypt ping_id
@ -291,7 +291,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port)
IP_Port temp;
if (DHT_getfriendip(ping->dht, public_key, &temp) == 0) {
if (dht_getfriendip(ping->dht, public_key, &temp) == 0) {
ping_send_request(ping, ip_port, public_key);
return -1;
}

View File

@ -2616,5 +2616,41 @@ inline namespace self {
}
#endif
typedef TOX_ERR_OPTIONS_NEW Tox_Err_Options_New;
typedef TOX_ERR_NEW Tox_Err_New;
typedef TOX_ERR_BOOTSTRAP Tox_Err_Bootstrap;
typedef TOX_ERR_SET_INFO Tox_Err_Set_Info;
typedef TOX_ERR_FRIEND_ADD Tox_Err_Friend_Add;
typedef TOX_ERR_FRIEND_DELETE Tox_Err_Friend_Delete;
typedef TOX_ERR_FRIEND_BY_PUBLIC_KEY Tox_Err_Friend_By_Public_Key;
typedef TOX_ERR_FRIEND_GET_PUBLIC_KEY Tox_Err_Friend_Get_Public_Key;
typedef TOX_ERR_FRIEND_GET_LAST_ONLINE Tox_Err_Friend_Get_Last_Online;
typedef TOX_ERR_FRIEND_QUERY Tox_Err_Friend_Query;
typedef TOX_ERR_SET_TYPING Tox_Err_Set_Typing;
typedef TOX_ERR_FRIEND_SEND_MESSAGE Tox_Err_Friend_Send_Message;
typedef TOX_ERR_FILE_CONTROL Tox_Err_File_Control;
typedef TOX_ERR_FILE_SEEK Tox_Err_File_Seek;
typedef TOX_ERR_FILE_GET Tox_Err_File_Get;
typedef TOX_ERR_FILE_SEND Tox_Err_File_Send;
typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk;
typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New;
typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete;
typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query;
typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite;
typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join;
typedef TOX_ERR_CONFERENCE_SEND_MESSAGE Tox_Err_Conference_Send_Message;
typedef TOX_ERR_CONFERENCE_TITLE Tox_Err_Conference_Title;
typedef TOX_ERR_CONFERENCE_GET_TYPE Tox_Err_Conference_Get_Type;
typedef TOX_ERR_FRIEND_CUSTOM_PACKET Tox_Err_Friend_Custom_Packet;
typedef TOX_ERR_GET_PORT Tox_Err_Get_Port;
typedef TOX_USER_STATUS Tox_User_Status;
typedef TOX_MESSAGE_TYPE Tox_Message_Type;
typedef TOX_PROXY_TYPE Tox_Proxy_Type;
typedef TOX_SAVEDATA_TYPE Tox_Savedata_Type;
typedef TOX_LOG_LEVEL Tox_Log_Level;
typedef TOX_CONNECTION Tox_Connection;
typedef TOX_FILE_CONTROL Tox_File_Control;
typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
#endif
%}

View File

@ -40,38 +40,38 @@ typedef struct Messenger Tox;
#include "../toxencryptsave/defines.h"
#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE
#error TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE
#error "TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE"
#endif
#if FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
#error FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE
#error "FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
#endif
#if TOX_FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
#error TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE
#error "TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
#endif
#if TOX_FILE_ID_LENGTH != TOX_HASH_LENGTH
#error TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH
#error "TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH"
#endif
#if TOX_PUBLIC_KEY_SIZE != CRYPTO_PUBLIC_KEY_SIZE
#error TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE
#error "TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE"
#endif
#if TOX_SECRET_KEY_SIZE != CRYPTO_SECRET_KEY_SIZE
#error TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE
#error "TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE"
#endif
#if TOX_MAX_NAME_LENGTH != MAX_NAME_LENGTH
#error TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH
#error "TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH"
#endif
#if TOX_MAX_STATUS_MESSAGE_LENGTH != MAX_STATUSMESSAGE_LENGTH
#error TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH
#error "TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH"
#endif
@ -81,7 +81,7 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
}
Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
{
Messenger_Options m_options = {0};
@ -90,7 +90,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
struct Tox_Options *default_options = nullptr;
if (options == nullptr) {
TOX_ERR_OPTIONS_NEW err;
Tox_Err_Options_New err;
default_options = tox_options_new(&err);
switch (err) {
@ -248,7 +248,7 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata)
}
}
bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, TOX_ERR_BOOTSTRAP *error)
bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error)
{
if (!host || !public_key) {
SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
@ -272,12 +272,12 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
unsigned int i;
for (i = 0; i < count; i++) {
for (i = 0; i < count; ++i) {
root[i].port = net_htons(port);
Messenger *m = tox;
onion_add_bs_path_node(m->onion_c, root[i], public_key);
DHT_bootstrap(m->dht, root[i], public_key);
dht_bootstrap(m->dht, root[i], public_key);
}
net_freeipport(root);
@ -292,7 +292,7 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
}
bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
TOX_ERR_BOOTSTRAP *error)
Tox_Err_Bootstrap *error)
{
if (!host || !public_key) {
SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
@ -316,7 +316,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
unsigned int i;
for (i = 0; i < count; i++) {
for (i = 0; i < count; ++i) {
root[i].port = net_htons(port);
Messenger *m = tox;
@ -334,7 +334,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
return 0;
}
TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
Tox_Connection tox_self_get_connection_status(const Tox *tox)
{
const Messenger *m = tox;
@ -355,7 +355,7 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback)
{
Messenger *m = tox;
m_callback_core_connection(m, (void (*)(Messenger *, unsigned int, void *))callback);
m_callback_core_connection(m, (m_self_connection_status_cb *)callback);
}
uint32_t tox_iteration_interval(const Tox *tox)
@ -409,7 +409,7 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
}
}
bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET_INFO *error)
bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error)
{
if (!name && length != 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
@ -443,7 +443,7 @@ void tox_self_get_name(const Tox *tox, uint8_t *name)
}
}
bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, TOX_ERR_SET_INFO *error)
bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error)
{
if (!status_message && length != 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
@ -475,20 +475,20 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
}
}
void tox_self_set_status(Tox *tox, TOX_USER_STATUS status)
void tox_self_set_status(Tox *tox, Tox_User_Status status)
{
Messenger *m = tox;
m_set_userstatus(m, status);
}
TOX_USER_STATUS tox_self_get_status(const Tox *tox)
Tox_User_Status tox_self_get_status(const Tox *tox)
{
const Messenger *m = tox;
const uint8_t status = m_get_self_userstatus(m);
return (TOX_USER_STATUS)status;
return (Tox_User_Status)status;
}
static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
static void set_friend_error(int32_t ret, Tox_Err_Friend_Add *error)
{
switch (ret) {
case FAERR_TOOLONG:
@ -522,7 +522,7 @@ static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
}
uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length,
TOX_ERR_FRIEND_ADD *error)
Tox_Err_Friend_Add *error)
{
if (!address || !message) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
@ -541,7 +541,7 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message
return UINT32_MAX;
}
uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_ADD *error)
uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error)
{
if (!public_key) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
@ -560,7 +560,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_F
return UINT32_MAX;
}
bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error)
bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error)
{
Messenger *m = tox;
int ret = m_delfriend(m, friend_number);
@ -575,7 +575,7 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *
return 1;
}
uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_BY_PUBLIC_KEY *error)
uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error)
{
if (!public_key) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL);
@ -595,7 +595,7 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX
}
bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key,
TOX_ERR_FRIEND_GET_PUBLIC_KEY *error)
Tox_Err_Friend_Get_Public_Key *error)
{
if (!public_key) {
return 0;
@ -618,13 +618,13 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
return m_friend_exists(m, friend_number);
}
uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_GET_LAST_ONLINE *error)
uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error)
{
const Messenger *m = tox;
uint64_t timestamp = m_get_last_online(m, friend_number);
if (timestamp == UINT64_MAX) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND)
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND);
return UINT64_MAX;
}
@ -647,7 +647,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
}
}
size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
const Messenger *m = tox;
int ret = m_get_name_size(m, friend_number);
@ -661,7 +661,7 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_
return ret;
}
bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, TOX_ERR_FRIEND_QUERY *error)
bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error)
{
if (!name) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
@ -686,7 +686,7 @@ void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback)
m_callback_namechange(m, callback);
}
size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
const Messenger *m = tox;
int ret = m_get_statusmessage_size(m, friend_number);
@ -701,7 +701,7 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number
}
bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message,
TOX_ERR_FRIEND_QUERY *error)
Tox_Err_Friend_Query *error)
{
if (!status_message) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
@ -727,7 +727,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *
m_callback_statusmessage(m, callback);
}
TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
const Messenger *m = tox;
@ -735,20 +735,20 @@ TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TO
if (ret == USERSTATUS_INVALID) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
return (TOX_USER_STATUS)(TOX_USER_STATUS_BUSY + 1);
return (Tox_User_Status)(TOX_USER_STATUS_BUSY + 1);
}
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
return (TOX_USER_STATUS)ret;
return (Tox_User_Status)ret;
}
void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback)
{
Messenger *m = tox;
m_callback_userstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback);
m_callback_userstatus(m, (m_friend_status_cb *)callback);
}
TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
const Messenger *m = tox;
@ -760,16 +760,16 @@ TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
}
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
return (TOX_CONNECTION)ret;
return (Tox_Connection)ret;
}
void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
{
Messenger *m = tox;
m_callback_connectionstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback);
m_callback_connectionstatus(m, (m_friend_connection_status_cb *)callback);
}
bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
{
const Messenger *m = tox;
int ret = m_get_istyping(m, friend_number);
@ -789,7 +789,7 @@ void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback)
m_callback_typingchange(m, callback);
}
bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, TOX_ERR_SET_TYPING *error)
bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error)
{
Messenger *m = tox;
@ -802,7 +802,7 @@ bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, TOX_ERR_
return 1;
}
static void set_message_error(int ret, TOX_ERR_FRIEND_SEND_MESSAGE *error)
static void set_message_error(int ret, Tox_Err_Friend_Send_Message *error)
{
switch (ret) {
case 0:
@ -831,8 +831,8 @@ static void set_message_error(int ret, TOX_ERR_FRIEND_SEND_MESSAGE *error)
}
}
uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type, const uint8_t *message,
size_t length, TOX_ERR_FRIEND_SEND_MESSAGE *error)
uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message,
size_t length, Tox_Err_Friend_Send_Message *error)
{
if (!message) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL);
@ -865,7 +865,7 @@ void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback)
void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback)
{
Messenger *m = tox;
m_callback_friendmessage(m, (void (*)(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *))callback);
m_callback_friendmessage(m, (m_friend_message_cb *)callback);
}
bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
@ -878,8 +878,8 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
return 1;
}
bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control,
TOX_ERR_FILE_CONTROL *error)
bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
Tox_Err_File_Control *error)
{
Messenger *m = tox;
int ret = file_control(m, friend_number, file_number, control);
@ -928,7 +928,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TO
}
bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
TOX_ERR_FILE_SEEK *error)
Tox_Err_File_Seek *error)
{
Messenger *m = tox;
int ret = file_seek(m, friend_number, file_number, position);
@ -972,11 +972,11 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
{
Messenger *m = tox;
callback_file_control(m, (void (*)(Messenger *, uint32_t, uint32_t, unsigned int, void *))callback);
callback_file_control(m, (m_file_recv_control_cb *)callback);
}
bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
TOX_ERR_FILE_GET *error)
Tox_Err_File_Get *error)
{
if (!file_id) {
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL);
@ -1001,7 +1001,7 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
}
uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error)
const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error)
{
if (filename_length && !filename) {
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
@ -1047,7 +1047,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
}
bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
size_t length, TOX_ERR_FILE_SEND_CHUNK *error)
size_t length, Tox_Err_File_Send_Chunk *error)
{
Messenger *m = tox;
int ret = file_data(m, friend_number, file_number, position, data, length);
@ -1112,17 +1112,13 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback)
void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback)
{
Messenger *m = tox;
g_callback_group_invite((Group_Chats *)m->conferences_object, (void (*)(Messenger * m, uint32_t, int, const uint8_t *,
size_t,
void *))callback);
g_callback_group_invite((Group_Chats *)m->conferences_object, (g_conference_invite_cb *)callback);
}
void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback)
{
Messenger *m = tox;
g_callback_group_message((Group_Chats *)m->conferences_object, (void (*)(Messenger * m, uint32_t, uint32_t, int,
const uint8_t *,
size_t, void *))callback);
g_callback_group_message((Group_Chats *)m->conferences_object, (g_conference_message_cb *)callback);
}
void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback)
@ -1143,7 +1139,7 @@ void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_lis
g_callback_peer_list_changed((Group_Chats *)m->conferences_object, callback);
}
uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE_NEW *error)
uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
{
Messenger *m = tox;
int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT);
@ -1157,7 +1153,7 @@ uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE_NEW *error)
return ret;
}
bool tox_conference_delete(Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_DELETE *error)
bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
{
Messenger *m = tox;
int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number);
@ -1171,7 +1167,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, TOX_ERR_CONFERE
return true;
}
uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_PEER_QUERY *error)
uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox;
int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number);
@ -1186,7 +1182,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T
}
size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
TOX_ERR_CONFERENCE_PEER_QUERY *error)
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox;
int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number);
@ -1206,7 +1202,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num
}
bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name,
TOX_ERR_CONFERENCE_PEER_QUERY *error)
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox;
int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name);
@ -1226,7 +1222,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
}
bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
uint8_t *public_key, TOX_ERR_CONFERENCE_PEER_QUERY *error)
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox;
int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key);
@ -1246,7 +1242,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb
}
bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
TOX_ERR_CONFERENCE_PEER_QUERY *error)
Tox_Err_Conference_Peer_Query *error)
{
const Messenger *m = tox;
int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number);
@ -1270,7 +1266,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb
}
bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number,
TOX_ERR_CONFERENCE_INVITE *error)
Tox_Err_Conference_Invite *error)
{
Messenger *m = tox;
int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number);
@ -1290,7 +1286,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference
}
uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length,
TOX_ERR_CONFERENCE_JOIN *error)
Tox_Err_Conference_Join *error)
{
Messenger *m = tox;
int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
@ -1325,8 +1321,8 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
return ret;
}
bool tox_conference_send_message(Tox *tox, uint32_t conference_number, TOX_MESSAGE_TYPE type, const uint8_t *message,
size_t length, TOX_ERR_CONFERENCE_SEND_MESSAGE *error)
bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message,
size_t length, Tox_Err_Conference_Send_Message *error)
{
Messenger *m = tox;
int ret = 0;
@ -1359,7 +1355,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, TOX_MESSA
return true;
}
size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_TITLE *error)
size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error)
{
const Messenger *m = tox;
int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number);
@ -1379,7 +1375,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number,
}
bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title,
TOX_ERR_CONFERENCE_TITLE *error)
Tox_Err_Conference_Title *error)
{
const Messenger *m = tox;
int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title);
@ -1399,7 +1395,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_
}
bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length,
TOX_ERR_CONFERENCE_TITLE *error)
Tox_Err_Conference_Title *error)
{
Messenger *m = tox;
int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length);
@ -1435,22 +1431,22 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size);
}
TOX_CONFERENCE_TYPE tox_conference_get_type(const Tox *tox, uint32_t conference_number,
TOX_ERR_CONFERENCE_GET_TYPE *error)
Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number,
Tox_Err_Conference_Get_Type *error)
{
const Messenger *m = tox;
int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number);
if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND);
return (TOX_CONFERENCE_TYPE)ret;
return (Tox_Conference_Type)ret;
}
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_OK);
return (TOX_CONFERENCE_TYPE)ret;
return (Tox_Conference_Type)ret;
}
static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error)
static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error)
{
switch (ret) {
case 0:
@ -1480,7 +1476,7 @@ static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error
}
bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
TOX_ERR_FRIEND_CUSTOM_PACKET *error)
Tox_Err_Friend_Custom_Packet *error)
{
if (!data) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
@ -1517,7 +1513,7 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call
}
bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
TOX_ERR_FRIEND_CUSTOM_PACKET *error)
Tox_Err_Friend_Custom_Packet *error)
{
if (!data) {
SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
@ -1556,7 +1552,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
}
}
uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
{
const Messenger *m = tox;
uint16_t port = net_htons(net_port(m->net));
@ -1570,7 +1566,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
return port;
}
uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error)
{
const Messenger *m = tox;

View File

@ -2976,4 +2976,40 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error);
}
#endif
typedef TOX_ERR_OPTIONS_NEW Tox_Err_Options_New;
typedef TOX_ERR_NEW Tox_Err_New;
typedef TOX_ERR_BOOTSTRAP Tox_Err_Bootstrap;
typedef TOX_ERR_SET_INFO Tox_Err_Set_Info;
typedef TOX_ERR_FRIEND_ADD Tox_Err_Friend_Add;
typedef TOX_ERR_FRIEND_DELETE Tox_Err_Friend_Delete;
typedef TOX_ERR_FRIEND_BY_PUBLIC_KEY Tox_Err_Friend_By_Public_Key;
typedef TOX_ERR_FRIEND_GET_PUBLIC_KEY Tox_Err_Friend_Get_Public_Key;
typedef TOX_ERR_FRIEND_GET_LAST_ONLINE Tox_Err_Friend_Get_Last_Online;
typedef TOX_ERR_FRIEND_QUERY Tox_Err_Friend_Query;
typedef TOX_ERR_SET_TYPING Tox_Err_Set_Typing;
typedef TOX_ERR_FRIEND_SEND_MESSAGE Tox_Err_Friend_Send_Message;
typedef TOX_ERR_FILE_CONTROL Tox_Err_File_Control;
typedef TOX_ERR_FILE_SEEK Tox_Err_File_Seek;
typedef TOX_ERR_FILE_GET Tox_Err_File_Get;
typedef TOX_ERR_FILE_SEND Tox_Err_File_Send;
typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk;
typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New;
typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete;
typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query;
typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite;
typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join;
typedef TOX_ERR_CONFERENCE_SEND_MESSAGE Tox_Err_Conference_Send_Message;
typedef TOX_ERR_CONFERENCE_TITLE Tox_Err_Conference_Title;
typedef TOX_ERR_CONFERENCE_GET_TYPE Tox_Err_Conference_Get_Type;
typedef TOX_ERR_FRIEND_CUSTOM_PACKET Tox_Err_Friend_Custom_Packet;
typedef TOX_ERR_GET_PORT Tox_Err_Get_Port;
typedef TOX_USER_STATUS Tox_User_Status;
typedef TOX_MESSAGE_TYPE Tox_Message_Type;
typedef TOX_PROXY_TYPE Tox_Proxy_Type;
typedef TOX_SAVEDATA_TYPE Tox_Savedata_Type;
typedef TOX_LOG_LEVEL Tox_Log_Level;
typedef TOX_CONNECTION Tox_Connection;
typedef TOX_FILE_CONTROL Tox_File_Control;
typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
#endif

View File

@ -5,7 +5,7 @@
#include <stdlib.h>
#include <string.h>
#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
#define CONST_FUNCTION(lowercase, uppercase) \

View File

@ -29,7 +29,7 @@
#include "../toxcore/crypto_core.h"
#include "defines.h"
#include "toxencryptsave.h"
#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
#ifdef VANILLA_NACL
#include <crypto_box.h>