mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'api-fix'
Main changes: 1. Strings no longer need to be NULL terminated. 2. tox_get_friend_id is now named tox_get_friend_number. 3. The friend request callback function is now (Tox *tox, uint8_t *, uint8_t *, uint16_t, void *), the Tox object pointer has been added to it.
This commit is contained in:
commit
5770a0e29a
@ -116,7 +116,7 @@ int parent_friend_request(DHT *dht)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void child_got_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
void child_got_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
fputs("OK\nsending status to parent", stdout);
|
fputs("OK\nsending status to parent", stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -174,7 +174,7 @@ START_TEST(test_getself_name)
|
|||||||
char nick_check[len];
|
char nick_check[len];
|
||||||
|
|
||||||
setname(m, (uint8_t *)nickname, len);
|
setname(m, (uint8_t *)nickname, len);
|
||||||
getself_name(m, (uint8_t *)nick_check, len);
|
getself_name(m, (uint8_t *)nick_check);
|
||||||
|
|
||||||
ck_assert_msg((memcmp(nickname, nick_check, len) == 0),
|
ck_assert_msg((memcmp(nickname, nick_check, len) == 0),
|
||||||
"getself_name failed to return the known name!\n"
|
"getself_name failed to return the known name!\n"
|
||||||
|
@ -19,12 +19,13 @@
|
|||||||
#define c_sleep(x) usleep(1000*x)
|
#define c_sleep(x) usleep(1000*x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void accept_friend_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
void accept_friend_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
Tox *t = userdata;
|
if (*((uint32_t *)userdata) != 974536)
|
||||||
|
return;
|
||||||
|
|
||||||
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
|
||||||
tox_add_friend_norequest(t, public_key);
|
tox_add_friend_norequest(m, public_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t messages_received;
|
uint32_t messages_received;
|
||||||
@ -114,7 +115,8 @@ START_TEST(test_few_clients)
|
|||||||
Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
||||||
Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
||||||
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
||||||
tox_callback_friend_request(tox2, accept_friend_request, tox2);
|
uint32_t to_compare = 974536;
|
||||||
|
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
||||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||||
tox_get_address(tox2, address);
|
tox_get_address(tox2, address);
|
||||||
int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7);
|
int test = tox_add_friend(tox3, address, (uint8_t *)"Gentoo", 7);
|
||||||
@ -140,7 +142,7 @@ START_TEST(test_few_clients)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("tox clients connected\n");
|
printf("tox clients connected\n");
|
||||||
uint32_t to_compare = 974536;
|
to_compare = 974536;
|
||||||
tox_callback_friend_message(tox3, print_message, &to_compare);
|
tox_callback_friend_message(tox3, print_message, &to_compare);
|
||||||
tox_send_message(tox2, 0, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
|
tox_send_message(tox2, 0, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo"));
|
||||||
|
|
||||||
@ -267,7 +269,8 @@ START_TEST(test_many_clients)
|
|||||||
for (i = 0; i < NUM_TOXES; ++i) {
|
for (i = 0; i < NUM_TOXES; ++i) {
|
||||||
toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
||||||
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
|
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
|
||||||
tox_callback_friend_request(toxes[i], accept_friend_request, toxes[i]);
|
uint32_t to_comp = 974536;
|
||||||
|
tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -66,7 +66,7 @@ void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t len
|
|||||||
* networking_requesthandler and so cannot take a Messenger * */
|
* networking_requesthandler and so cannot take a Messenger * */
|
||||||
static Messenger *m;
|
static Messenger *m;
|
||||||
|
|
||||||
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
void print_request(Messenger *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
printf("Friend request received from: \n");
|
printf("Friend request received from: \n");
|
||||||
printf("ClientID: ");
|
printf("ClientID: ");
|
||||||
|
@ -862,7 +862,7 @@ void do_refresh()
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
void print_request(Tox *m, uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
new_lines("[i] received friend request with message:");
|
new_lines("[i] received friend request with message:");
|
||||||
new_lines((char *)data);
|
new_lines((char *)data);
|
||||||
@ -1243,7 +1243,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
new_lines("[i] change username with /n");
|
new_lines("[i] change username with /n");
|
||||||
uint8_t name[TOX_MAX_NAME_LENGTH + 1];
|
uint8_t name[TOX_MAX_NAME_LENGTH + 1];
|
||||||
uint16_t namelen = tox_get_self_name(m, name, sizeof(name));
|
uint16_t namelen = tox_get_self_name(m, name);
|
||||||
name[namelen] = 0;
|
name[namelen] = 0;
|
||||||
|
|
||||||
if (namelen > 0) {
|
if (namelen > 0) {
|
||||||
|
@ -1171,7 +1171,7 @@ int av_terminate_session(av_session_t *_phone)
|
|||||||
/****** AV HELPER FUNCTIONS ******/
|
/****** AV HELPER FUNCTIONS ******/
|
||||||
|
|
||||||
/* Auto accept friend request */
|
/* Auto accept friend request */
|
||||||
void av_friend_requ(uint8_t *_public_key, uint8_t *_data, uint16_t _length, void *_userdata)
|
void av_friend_requ(Tox *_messenger, uint8_t *_public_key, uint8_t *_data, uint16_t _length, void *_userdata)
|
||||||
{
|
{
|
||||||
av_session_t *_phone = _userdata;
|
av_session_t *_phone = _userdata;
|
||||||
av_allocate_friend (_phone, -1, 0);
|
av_allocate_friend (_phone, -1, 0);
|
||||||
|
@ -34,16 +34,16 @@
|
|||||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||||
|
|
||||||
|
|
||||||
static void set_friend_status(Messenger *m, int friendnumber, uint8_t status);
|
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status);
|
||||||
static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
|
static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
|
||||||
|
|
||||||
// friend_not_valid determines if the friendnumber passed is valid in the Messenger object
|
// friend_not_valid determines if the friendnumber passed is valid in the Messenger object
|
||||||
static uint8_t friend_not_valid(Messenger *m, int friendnumber)
|
static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
return (unsigned int)friendnumber >= m->numfriends;
|
return (unsigned int)friendnumber >= m->numfriends;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_online_friend(Messenger *m, int friendnumber)
|
static int add_online_friend(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -74,7 +74,7 @@ static int add_online_friend(Messenger *m, int friendnumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int remove_online_friend(Messenger *m, int friendnumber)
|
static int remove_online_friend(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
Online_Friend *temp;
|
Online_Friend *temp;
|
||||||
@ -132,7 +132,7 @@ int realloc_friendlist(Messenger *m, uint32_t num)
|
|||||||
/* return the friend id associated to that public key.
|
/* return the friend id associated to that public key.
|
||||||
* return -1 if no such friend.
|
* return -1 if no such friend.
|
||||||
*/
|
*/
|
||||||
int getfriend_id(Messenger *m, uint8_t *client_id)
|
int32_t getfriend_id(Messenger *m, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
@ -151,13 +151,13 @@ int getfriend_id(Messenger *m, uint8_t *client_id)
|
|||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int getclient_id(Messenger *m, int friend_id, uint8_t *client_id)
|
int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friend_id))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (m->friendlist[friend_id].status > 0) {
|
if (m->friendlist[friendnumber].status > 0) {
|
||||||
memcpy(client_id, m->friendlist[friend_id].client_id, CLIENT_ID_SIZE);
|
memcpy(client_id, m->friendlist[friendnumber].client_id, CLIENT_ID_SIZE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ void getaddress(Messenger *m, uint8_t *address)
|
|||||||
* (the nospam for that friend was set to the new one).
|
* (the nospam for that friend was set to the new one).
|
||||||
* return FAERR_NOMEM if increasing the friend list size fails.
|
* return FAERR_NOMEM if increasing the friend list size fails.
|
||||||
*/
|
*/
|
||||||
int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
|
if (length >= (MAX_DATA_SIZE - crypto_box_PUBLICKEYBYTES
|
||||||
- crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
|
- crypto_box_NONCEBYTES - crypto_box_BOXZEROBYTES
|
||||||
@ -231,7 +231,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
|||||||
if (id_equal(client_id, m->net_crypto->self_public_key))
|
if (id_equal(client_id, m->net_crypto->self_public_key))
|
||||||
return FAERR_OWNKEY;
|
return FAERR_OWNKEY;
|
||||||
|
|
||||||
int friend_id = getfriend_id(m, client_id);
|
int32_t friend_id = getfriend_id(m, client_id);
|
||||||
|
|
||||||
if (friend_id != -1) {
|
if (friend_id != -1) {
|
||||||
uint32_t nospam;
|
uint32_t nospam;
|
||||||
@ -250,7 +250,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
|||||||
|
|
||||||
memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
|
memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
|
||||||
|
|
||||||
int onion_friendnum = onion_addfriend(m->onion_c, client_id);
|
int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id);
|
||||||
|
|
||||||
if (onion_friendnum == -1)
|
if (onion_friendnum == -1)
|
||||||
return FAERR_UNKNOWN;
|
return FAERR_UNKNOWN;
|
||||||
@ -285,7 +285,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
|
|||||||
return FAERR_UNKNOWN;
|
return FAERR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
|
int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
if (getfriend_id(m, client_id) != -1)
|
if (getfriend_id(m, client_id) != -1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -299,7 +299,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
|
|||||||
|
|
||||||
memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
|
memset(&(m->friendlist[m->numfriends]), 0, sizeof(Friend));
|
||||||
|
|
||||||
int onion_friendnum = onion_addfriend(m->onion_c, client_id);
|
int32_t onion_friendnum = onion_addfriend(m->onion_c, client_id);
|
||||||
|
|
||||||
if (onion_friendnum == -1)
|
if (onion_friendnum == -1)
|
||||||
return FAERR_UNKNOWN;
|
return FAERR_UNKNOWN;
|
||||||
@ -335,7 +335,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id)
|
|||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int m_delfriend(Messenger *m, int friendnumber)
|
int m_delfriend(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -362,7 +362,7 @@ int m_delfriend(Messenger *m, int friendnumber)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_get_friend_connectionstatus(Messenger *m, int friendnumber)
|
int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -370,7 +370,7 @@ int m_get_friend_connectionstatus(Messenger *m, int friendnumber)
|
|||||||
return m->friendlist[friendnumber].status == FRIEND_ONLINE;
|
return m->friendlist[friendnumber].status == FRIEND_ONLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_friend_exists(Messenger *m, int friendnumber)
|
int m_friend_exists(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return 0;
|
return 0;
|
||||||
@ -383,7 +383,7 @@ int m_friend_exists(Messenger *m, int friendnumber)
|
|||||||
* return the message id if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*/
|
*/
|
||||||
uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_t length)
|
uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return 0;
|
return 0;
|
||||||
@ -400,7 +400,7 @@ uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length)
|
uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length)
|
||||||
{
|
{
|
||||||
if (length >= (MAX_DATA_SIZE - sizeof(theid)))
|
if (length >= (MAX_DATA_SIZE - sizeof(theid)))
|
||||||
return 0;
|
return 0;
|
||||||
@ -417,7 +417,7 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
|
|||||||
* return the message id if packet was successfully put into the send queue.
|
* return the message id if packet was successfully put into the send queue.
|
||||||
* return 0 if it was not.
|
* return 0 if it was not.
|
||||||
*/
|
*/
|
||||||
uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length)
|
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return 0;
|
return 0;
|
||||||
@ -434,7 +434,7 @@ uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
if (length >= (MAX_DATA_SIZE - sizeof(theid)))
|
if (length >= (MAX_DATA_SIZE - sizeof(theid)))
|
||||||
return 0;
|
return 0;
|
||||||
@ -449,7 +449,7 @@ uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uin
|
|||||||
/* Send a name packet to friendnumber.
|
/* Send a name packet to friendnumber.
|
||||||
* length is the length with the NULL terminator.
|
* length is the length with the NULL terminator.
|
||||||
*/
|
*/
|
||||||
static int m_sendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length)
|
static int m_sendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length > MAX_NAME_LENGTH || length == 0)
|
if (length > MAX_NAME_LENGTH || length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -462,7 +462,7 @@ static int m_sendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t le
|
|||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int setfriendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length)
|
int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -507,18 +507,15 @@ int setname(Messenger *m, uint8_t *name, uint16_t length)
|
|||||||
*
|
*
|
||||||
* return the length of the name.
|
* return the length of the name.
|
||||||
*/
|
*/
|
||||||
uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen)
|
uint16_t getself_name(Messenger *m, uint8_t *name)
|
||||||
{
|
{
|
||||||
uint16_t len;
|
if (name == NULL) {
|
||||||
|
|
||||||
if (name == NULL || nlen == 0) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = MIN(nlen, m->name_length);
|
memcpy(name, m->name, m->name_length);
|
||||||
memcpy(name, m->name, len);
|
|
||||||
|
|
||||||
return len;
|
return m->name_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get name of friendnumber and put it in name.
|
/* Get name of friendnumber and put it in name.
|
||||||
@ -527,7 +524,7 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen)
|
|||||||
* return length of name if success.
|
* return length of name if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int getname(Messenger *m, int friendnumber, uint8_t *name)
|
int getname(Messenger *m, int32_t friendnumber, uint8_t *name)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -536,6 +533,19 @@ int getname(Messenger *m, int friendnumber, uint8_t *name)
|
|||||||
return m->friendlist[friendnumber].name_length;
|
return m->friendlist[friendnumber].name_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int m_get_name_size(Messenger *m, int32_t friendnumber)
|
||||||
|
{
|
||||||
|
if (friend_not_valid(m, friendnumber))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return m->friendlist[friendnumber].name_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_get_self_name_size(Messenger *m)
|
||||||
|
{
|
||||||
|
return m->name_length;
|
||||||
|
}
|
||||||
|
|
||||||
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length)
|
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length > MAX_STATUSMESSAGE_LENGTH)
|
if (length > MAX_STATUSMESSAGE_LENGTH)
|
||||||
@ -552,7 +562,7 @@ int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_set_userstatus(Messenger *m, USERSTATUS status)
|
int m_set_userstatus(Messenger *m, uint8_t status)
|
||||||
{
|
{
|
||||||
if (status >= USERSTATUS_INVALID) {
|
if (status >= USERSTATUS_INVALID) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -570,7 +580,7 @@ int m_set_userstatus(Messenger *m, USERSTATUS status)
|
|||||||
/* return the size of friendnumber's user status.
|
/* return the size of friendnumber's user status.
|
||||||
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
|
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
|
||||||
*/
|
*/
|
||||||
int m_get_statusmessage_size(Messenger *m, int friendnumber)
|
int m_get_statusmessage_size(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -581,7 +591,7 @@ int m_get_statusmessage_size(Messenger *m, int friendnumber)
|
|||||||
/* Copy the user status of friendnumber into buf, truncating if needed to maxlen
|
/* Copy the user status of friendnumber into buf, truncating if needed to maxlen
|
||||||
* bytes, use m_get_statusmessage_size to find out how much you need to allocate.
|
* bytes, use m_get_statusmessage_size to find out how much you need to allocate.
|
||||||
*/
|
*/
|
||||||
int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t maxlen)
|
int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -591,6 +601,14 @@ int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t
|
|||||||
return MIN(maxlen, m->friendlist[friendnumber].statusmessage_length);
|
return MIN(maxlen, m->friendlist[friendnumber].statusmessage_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* return the size of friendnumber's user status.
|
||||||
|
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
|
||||||
|
*/
|
||||||
|
int m_get_self_statusmessage_size(Messenger *m)
|
||||||
|
{
|
||||||
|
return m->statusmessage_length;
|
||||||
|
}
|
||||||
|
|
||||||
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
|
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
|
||||||
{
|
{
|
||||||
memset(buf, 0, maxlen);
|
memset(buf, 0, maxlen);
|
||||||
@ -598,12 +616,12 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
|
|||||||
return MIN(maxlen, m->statusmessage_length);
|
return MIN(maxlen, m->statusmessage_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
USERSTATUS m_get_userstatus(Messenger *m, int friendnumber)
|
uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return USERSTATUS_INVALID;
|
return USERSTATUS_INVALID;
|
||||||
|
|
||||||
USERSTATUS status = m->friendlist[friendnumber].userstatus;
|
uint8_t status = m->friendlist[friendnumber].userstatus;
|
||||||
|
|
||||||
if (status >= USERSTATUS_INVALID) {
|
if (status >= USERSTATUS_INVALID) {
|
||||||
status = USERSTATUS_NONE;
|
status = USERSTATUS_NONE;
|
||||||
@ -612,12 +630,12 @@ USERSTATUS m_get_userstatus(Messenger *m, int friendnumber)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
USERSTATUS m_get_self_userstatus(Messenger *m)
|
uint8_t m_get_self_userstatus(Messenger *m)
|
||||||
{
|
{
|
||||||
return m->userstatus;
|
return m->userstatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t m_get_last_online(Messenger *m, int friendnumber)
|
uint64_t m_get_last_online(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -625,7 +643,8 @@ uint64_t m_get_last_online(Messenger *m, int friendnumber)
|
|||||||
return m->friendlist[friendnumber].ping_lastrecv;
|
return m->friendlist[friendnumber].ping_lastrecv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing)
|
int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (is_typing != 0 && is_typing != 1) {
|
if (is_typing != 0 && is_typing != 1) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -640,7 +659,7 @@ int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int m_get_istyping(Messenger *m, int friendnumber)
|
int m_get_istyping(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -648,24 +667,23 @@ int m_get_istyping(Messenger *m, int friendnumber)
|
|||||||
return m->friendlist[friendnumber].is_typing;
|
return m->friendlist[friendnumber].is_typing;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length)
|
static int send_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
|
||||||
{
|
{
|
||||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length);
|
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_userstatus(Messenger *m, int friendnumber, USERSTATUS status)
|
static int send_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
uint8_t stat = status;
|
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status));
|
||||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_user_istyping(Messenger *m, int friendnumber, uint8_t is_typing)
|
static int send_user_istyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
|
||||||
{
|
{
|
||||||
uint8_t typing = is_typing;
|
uint8_t typing = is_typing;
|
||||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing));
|
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_ping(Messenger *m, int friendnumber)
|
static int send_ping(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0);
|
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0);
|
||||||
|
|
||||||
@ -675,12 +693,12 @@ static int send_ping(Messenger *m, int friendnumber)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length)
|
static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint8_t *newstatus = calloc(length, 1);
|
uint8_t *newstatus = calloc(length + 1, 1);
|
||||||
memcpy(newstatus, status, length);
|
memcpy(newstatus, status, length);
|
||||||
free(m->friendlist[friendnumber].statusmessage);
|
free(m->friendlist[friendnumber].statusmessage);
|
||||||
m->friendlist[friendnumber].statusmessage = newstatus;
|
m->friendlist[friendnumber].statusmessage = newstatus;
|
||||||
@ -688,18 +706,18 @@ static int set_friend_statusmessage(Messenger *m, int friendnumber, uint8_t *sta
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_friend_userstatus(Messenger *m, int friendnumber, USERSTATUS status)
|
static void set_friend_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
m->friendlist[friendnumber].userstatus = status;
|
m->friendlist[friendnumber].userstatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_friend_typing(Messenger *m, int friendnumber, uint8_t is_typing)
|
static void set_friend_typing(Messenger *m, int32_t friendnumber, uint8_t is_typing)
|
||||||
{
|
{
|
||||||
m->friendlist[friendnumber].is_typing = is_typing;
|
m->friendlist[friendnumber].is_typing = is_typing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sets whether we send read receipts for friendnumber. */
|
/* Sets whether we send read receipts for friendnumber. */
|
||||||
void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno)
|
void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno)
|
||||||
{
|
{
|
||||||
if (yesno != 0 && yesno != 1)
|
if (yesno != 0 && yesno != 1)
|
||||||
return;
|
return;
|
||||||
@ -712,72 +730,75 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno)
|
|||||||
|
|
||||||
/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */
|
/* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); */
|
||||||
/* Set the function that will be executed when a friend request is received. */
|
/* Set the function that will be executed when a friend request is received. */
|
||||||
void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata)
|
void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
callback_friendrequest(&(m->fr), function, userdata);
|
void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *) = function;
|
||||||
|
callback_friendrequest(&(m->fr), handle_friendrequest, m, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the function that will be executed when a message from a friend is received. */
|
/* 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, int, uint8_t *, uint16_t, void *),
|
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_message = function;
|
m->friend_message = function;
|
||||||
m->friend_message_userdata = userdata;
|
m->friend_message_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), void *userdata)
|
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_action = function;
|
m->friend_action = function;
|
||||||
m->friend_action_userdata = userdata;
|
m->friend_action_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_namechange = function;
|
m->friend_namechange = function;
|
||||||
m->friend_namechange_userdata = userdata;
|
m->friend_namechange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_statusmessagechange = function;
|
m->friend_statusmessagechange = function;
|
||||||
m->friend_statuschange_userdata = userdata;
|
m->friend_statuschange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void *), void *userdata)
|
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_userstatuschange = function;
|
m->friend_userstatuschange = function;
|
||||||
m->friend_userstatuschange_userdata = userdata;
|
m->friend_userstatuschange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, int, void *), void *userdata)
|
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int32_t, int, void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_typingchange = function;
|
m->friend_typingchange = function;
|
||||||
m->friend_typingchange_userdata = userdata;
|
m->friend_typingchange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata)
|
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int32_t, uint32_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->read_receipt = function;
|
m->read_receipt = function;
|
||||||
m->read_receipt_userdata = userdata;
|
m->read_receipt_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata)
|
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_connectionstatuschange = function;
|
m->friend_connectionstatuschange = function;
|
||||||
m->friend_connectionstatuschange_userdata = userdata;
|
m->friend_connectionstatuschange_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *),
|
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->friend_connectionstatuschange_internal = function;
|
m->friend_connectionstatuschange_internal = function;
|
||||||
m->friend_connectionstatuschange_internal_userdata = userdata;
|
m->friend_connectionstatuschange_internal_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void break_files(Messenger *m, int friendnumber);
|
static void break_files(Messenger *m, int32_t friendnumber);
|
||||||
static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status)
|
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
if (status == NOFRIEND)
|
if (status == NOFRIEND)
|
||||||
return;
|
return;
|
||||||
@ -804,13 +825,13 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_friend_status(Messenger *m, int friendnumber, uint8_t status)
|
void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status)
|
||||||
{
|
{
|
||||||
check_friend_connectionstatus(m, friendnumber, status);
|
check_friend_connectionstatus(m, friendnumber, status);
|
||||||
m->friendlist[friendnumber].status = status;
|
m->friendlist[friendnumber].status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length)
|
int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return 0;
|
return 0;
|
||||||
@ -850,7 +871,7 @@ static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
|
|||||||
/* returns valid ip port of connected friend on success
|
/* returns valid ip port of connected friend on success
|
||||||
* returns zeroed out IP_Port on failure
|
* returns zeroed out IP_Port on failure
|
||||||
*/
|
*/
|
||||||
IP_Port get_friend_ipport(Messenger *m, int friendnumber)
|
IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
IP_Port zero;
|
IP_Port zero;
|
||||||
memset(&zero, 0, sizeof(zero));
|
memset(&zero, 0, sizeof(zero));
|
||||||
@ -884,9 +905,9 @@ static int group_num(Messenger *m, uint8_t *group_public_key)
|
|||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata)
|
* Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
|
||||||
*/
|
*/
|
||||||
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata)
|
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->group_invite = function;
|
m->group_invite = function;
|
||||||
m->group_invite_userdata = userdata;
|
m->group_invite_userdata = userdata;
|
||||||
@ -946,10 +967,12 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m
|
|||||||
if (i == -1)
|
if (i == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
message[length - 1] = 0; /* Force NULL terminator */
|
uint8_t message_terminated[length + 1];
|
||||||
|
memcpy(message_terminated, message, length);
|
||||||
|
message_terminated[length] = 0; /* Force NULL terminator */
|
||||||
|
|
||||||
if (m->group_message)
|
if (m->group_message)
|
||||||
(*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata);
|
(*m->group_message)(m, i, peer_number, message_terminated, length, m->group_message_userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *action, uint16_t length, void *userdata)
|
static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *action, uint16_t length, void *userdata)
|
||||||
@ -960,10 +983,12 @@ static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *ac
|
|||||||
if (i == -1)
|
if (i == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
action[length - 1] = 0; /* Force NULL terminator */
|
uint8_t action_terminated[length + 1];
|
||||||
|
memcpy(action_terminated, action, length);
|
||||||
|
action_terminated[length] = 0; /* Force NULL terminator */
|
||||||
|
|
||||||
if (m->group_action)
|
if (m->group_action)
|
||||||
(*m->group_action)(m, i, peer_number, action, length, m->group_action_userdata);
|
(*m->group_action)(m, i, peer_number, action_terminated, length, m->group_action_userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void group_namelistchange_function(Group_Chat *chat, int peer, uint8_t change, void *userdata)
|
static void group_namelistchange_function(Group_Chat *chat, int peer, uint8_t change, void *userdata)
|
||||||
@ -1089,7 +1114,7 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam
|
|||||||
|
|
||||||
/* Store the fact that we invited a specific friend.
|
/* Store the fact that we invited a specific friend.
|
||||||
*/
|
*/
|
||||||
static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnumber)
|
static void group_store_friendinvite(Messenger *m, int32_t friendnumber, int groupnumber)
|
||||||
{
|
{
|
||||||
/* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */
|
/* Add 1 to the groupchat number because 0 (default value in invited_groups) is a valid groupchat number */
|
||||||
m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] =
|
m->friendlist[friendnumber].invited_groups[m->friendlist[friendnumber].invited_groups_num % MAX_INVITED_GROUPS] =
|
||||||
@ -1100,7 +1125,7 @@ static void group_store_friendinvite(Messenger *m, int friendnumber, int groupnu
|
|||||||
/* return 1 if that friend was invited to the group
|
/* return 1 if that friend was invited to the group
|
||||||
* return 0 if the friend was not or error.
|
* return 0 if the friend was not or error.
|
||||||
*/
|
*/
|
||||||
static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber)
|
static uint8_t group_invited(Messenger *m, int32_t friendnumber, int groupnumber)
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
@ -1122,7 +1147,7 @@ static uint8_t group_invited(Messenger *m, int friendnumber, int groupnumber)
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int invite_friend(Messenger *m, int friendnumber, int groupnumber)
|
int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber) || (unsigned int)groupnumber >= m->numchats)
|
if (friend_not_valid(m, friendnumber) || (unsigned int)groupnumber >= m->numchats)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1148,7 +1173,7 @@ int invite_friend(Messenger *m, int friendnumber, int groupnumber)
|
|||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key)
|
int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -1265,9 +1290,10 @@ static void do_allgroupchats(Messenger *m)
|
|||||||
|
|
||||||
/* Set the callback for file send requests.
|
/* Set the callback for file send requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t,
|
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *,
|
||||||
|
uint16_t,
|
||||||
void *), void *userdata)
|
void *), void *userdata)
|
||||||
{
|
{
|
||||||
m->file_sendrequest = function;
|
m->file_sendrequest = function;
|
||||||
@ -1276,10 +1302,10 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int,
|
|||||||
|
|
||||||
/* Set the callback for file control requests.
|
/* Set the callback for file control requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *,
|
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
|
||||||
uint16_t,
|
uint16_t,
|
||||||
void *), void *userdata)
|
void *), void *userdata)
|
||||||
{
|
{
|
||||||
@ -1289,10 +1315,11 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uin
|
|||||||
|
|
||||||
/* Set the callback for file data.
|
/* Set the callback for file data.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *),
|
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length,
|
||||||
|
void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->file_filedata = function;
|
m->file_filedata = function;
|
||||||
@ -1306,7 +1333,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
|
int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
|
||||||
uint16_t filename_length)
|
uint16_t filename_length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
@ -1329,7 +1356,7 @@ int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_
|
|||||||
* return file number on success
|
* return file number on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
|
int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -1359,7 +1386,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
int file_control(Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
||||||
uint8_t *data, uint16_t length)
|
uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length > MAX_DATA_SIZE - 3)
|
if (length > MAX_DATA_SIZE - 3)
|
||||||
@ -1447,7 +1474,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
|
int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length > MAX_DATA_SIZE - 1)
|
if (length > MAX_DATA_SIZE - 1)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1482,7 +1509,7 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data,
|
|||||||
* return number of bytes remaining to be sent/received on success
|
* return number of bytes remaining to be sent/received on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive)
|
uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return 0;
|
return 0;
|
||||||
@ -1505,7 +1532,7 @@ uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber,
|
|||||||
/* Run this when the friend disconnects.
|
/* Run this when the friend disconnects.
|
||||||
* Sets all current file transfers to broken.
|
* Sets all current file transfers to broken.
|
||||||
*/
|
*/
|
||||||
static void break_files(Messenger *m, int friendnumber)
|
static void break_files(Messenger *m, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
@ -1518,7 +1545,7 @@ static void break_files(Messenger *m, int friendnumber)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t receive_send, uint8_t filenumber,
|
static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
|
||||||
uint8_t message_id, uint8_t *data,
|
uint8_t message_id, uint8_t *data,
|
||||||
uint16_t length)
|
uint16_t length)
|
||||||
{
|
{
|
||||||
@ -1608,7 +1635,7 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t receive_se
|
|||||||
*
|
*
|
||||||
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
m->msi_packet = function;
|
m->msi_packet = function;
|
||||||
@ -1620,12 +1647,12 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uin
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length)
|
int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length);
|
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int friendnum_from_ip_port(Messenger *m, IP_Port ip_port)
|
static int32_t friendnum_from_ip_port(Messenger *m, IP_Port ip_port)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
@ -1640,7 +1667,7 @@ static int friendnum_from_ip_port(Messenger *m, IP_Port ip_port)
|
|||||||
static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = object;
|
Messenger *m = object;
|
||||||
int friend_num = friendnum_from_ip_port(m, source);
|
int32_t friend_num = friendnum_from_ip_port(m, source);
|
||||||
|
|
||||||
if (friend_num == -1)
|
if (friend_num == -1)
|
||||||
return 1;
|
return 1;
|
||||||
@ -1653,7 +1680,7 @@ static int handle_custom_user_packet(void *object, IP_Port source, uint8_t *pack
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t byte, packet_handler_callback cb,
|
int custom_user_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, packet_handler_callback cb,
|
||||||
void *object)
|
void *object)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
@ -1668,7 +1695,7 @@ int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t b
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_custom_user_packet(Messenger *m, int friendnumber, uint8_t *data, uint32_t length)
|
int send_custom_user_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length)
|
||||||
{
|
{
|
||||||
if (friend_not_valid(m, friendnumber))
|
if (friend_not_valid(m, friendnumber))
|
||||||
return -1;
|
return -1;
|
||||||
@ -1905,13 +1932,15 @@ void do_friends(Messenger *m)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Make sure the NULL terminator is present. */
|
/* Make sure the NULL terminator is present. */
|
||||||
data[data_length - 1] = 0;
|
uint8_t data_terminated[data_length + 1];
|
||||||
|
memcpy(data_terminated, data, data_length);
|
||||||
|
data_terminated[data_length] = 0;
|
||||||
|
|
||||||
/* inform of namechange before we overwrite the old name */
|
/* inform of namechange before we overwrite the old name */
|
||||||
if (m->friend_namechange)
|
if (m->friend_namechange)
|
||||||
m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata);
|
m->friend_namechange(m, i, data_terminated, data_length, m->friend_namechange_userdata);
|
||||||
|
|
||||||
memcpy(m->friendlist[i].name, data, data_length);
|
memcpy(m->friendlist[i].name, data_terminated, data_length + 1);
|
||||||
m->friendlist[i].name_length = data_length;
|
m->friendlist[i].name_length = data_length;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1921,13 +1950,16 @@ void do_friends(Messenger *m)
|
|||||||
if (data_length == 0 || data_length > MAX_STATUSMESSAGE_LENGTH)
|
if (data_length == 0 || data_length > MAX_STATUSMESSAGE_LENGTH)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
data[data_length - 1] = 0; /* Make sure the NULL terminator is present. */
|
/* Make sure the NULL terminator is present. */
|
||||||
|
uint8_t data_terminated[data_length + 1];
|
||||||
|
memcpy(data_terminated, data, data_length);
|
||||||
|
data_terminated[data_length] = 0;
|
||||||
|
|
||||||
if (m->friend_statusmessagechange)
|
if (m->friend_statusmessagechange)
|
||||||
m->friend_statusmessagechange(m, i, data, data_length,
|
m->friend_statusmessagechange(m, i, data_terminated, data_length,
|
||||||
m->friend_statuschange_userdata);
|
m->friend_statuschange_userdata);
|
||||||
|
|
||||||
set_friend_statusmessage(m, i, data, data_length);
|
set_friend_statusmessage(m, i, data_terminated, data_length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1968,14 +2000,17 @@ void do_friends(Messenger *m)
|
|||||||
uint8_t *message = data + message_id_length;
|
uint8_t *message = data + message_id_length;
|
||||||
uint16_t message_length = data_length - message_id_length;
|
uint16_t message_length = data_length - message_id_length;
|
||||||
|
|
||||||
message[message_length - 1] = 0;/* Make sure the NULL terminator is present. */
|
/* Make sure the NULL terminator is present. */
|
||||||
|
uint8_t message_terminated[message_length + 1];
|
||||||
|
memcpy(message_terminated, message, message_length);
|
||||||
|
message_terminated[message_length] = 0;
|
||||||
|
|
||||||
if (m->friendlist[i].receives_read_receipts) {
|
if (m->friendlist[i].receives_read_receipts) {
|
||||||
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->friend_message)
|
if (m->friend_message)
|
||||||
(*m->friend_message)(m, i, message, message_length, m->friend_message_userdata);
|
(*m->friend_message)(m, i, message_terminated, message_length, m->friend_message_userdata);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1990,14 +2025,17 @@ void do_friends(Messenger *m)
|
|||||||
uint8_t *action = data + message_id_length;
|
uint8_t *action = data + message_id_length;
|
||||||
uint16_t action_length = data_length - message_id_length;
|
uint16_t action_length = data_length - message_id_length;
|
||||||
|
|
||||||
action[action_length - 1] = 0;/* Make sure the NULL terminator is present. */
|
/* Make sure the NULL terminator is present. */
|
||||||
|
uint8_t action_terminated[action_length + 1];
|
||||||
|
memcpy(action_terminated, action, action_length);
|
||||||
|
action_terminated[action_length] = 0;
|
||||||
|
|
||||||
if (m->friendlist[i].receives_read_receipts) {
|
if (m->friendlist[i].receives_read_receipts) {
|
||||||
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->friend_action)
|
if (m->friend_action)
|
||||||
(*m->friend_action)(m, i, action, action_length, m->friend_action_userdata);
|
(*m->friend_action)(m, i, action_terminated, action_length, m->friend_action_userdata);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2057,10 +2095,13 @@ void do_friends(Messenger *m)
|
|||||||
m->friendlist[i].file_receiving[filenumber].size = filesize;
|
m->friendlist[i].file_receiving[filenumber].size = filesize;
|
||||||
m->friendlist[i].file_receiving[filenumber].transferred = 0;
|
m->friendlist[i].file_receiving[filenumber].transferred = 0;
|
||||||
|
|
||||||
data[data_length - 1] = 0; /* Force NULL terminate file name. */
|
/* Force NULL terminate file name. */
|
||||||
|
uint8_t filename_terminated[data_length - 1 - sizeof(uint64_t) + 1];
|
||||||
|
memcpy(filename_terminated, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t));
|
||||||
|
filename_terminated[data_length - 1 - sizeof(uint64_t)] = 0;
|
||||||
|
|
||||||
if (m->file_sendrequest)
|
if (m->file_sendrequest)
|
||||||
(*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t),
|
(*m->file_sendrequest)(m, i, filenumber, filesize, filename_terminated, data_length - 1 - sizeof(uint64_t),
|
||||||
m->file_sendrequest_userdata);
|
m->file_sendrequest_userdata);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -2322,19 +2363,24 @@ void do_messenger(Messenger *m)
|
|||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr)
|
size_t wait_data_size()
|
||||||
{
|
{
|
||||||
return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data, lenptr);
|
return networking_wait_data_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
int wait_prepare_messenger(Messenger *m, uint8_t *data)
|
||||||
{
|
{
|
||||||
return networking_wait_execute(data, len, milliseconds);
|
return networking_wait_prepare(m->net, sendqueue_total(m->net_crypto->lossless_udp), data);
|
||||||
};
|
}
|
||||||
|
|
||||||
void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len)
|
int wait_execute_messenger(uint8_t *data, long seconds, long microseconds)
|
||||||
{
|
{
|
||||||
networking_wait_cleanup(m->net, data, len);
|
return networking_wait_execute(data, seconds, microseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wait_cleanup_messenger(Messenger *m, uint8_t *data)
|
||||||
|
{
|
||||||
|
return networking_wait_cleanup(m->net, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* new messenger format for load/save, more robust and forward compatible */
|
/* new messenger format for load/save, more robust and forward compatible */
|
||||||
@ -2791,7 +2837,7 @@ uint32_t get_num_online_friends(Messenger *m)
|
|||||||
* Otherwise, returns the number of elements copied.
|
* Otherwise, returns the number of elements copied.
|
||||||
* If the array was too small, the contents
|
* If the array was too small, the contents
|
||||||
* of out_list will be truncated to list_size. */
|
* of out_list will be truncated to list_size. */
|
||||||
uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
|
uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size)
|
||||||
{
|
{
|
||||||
if (!out_list)
|
if (!out_list)
|
||||||
return 0;
|
return 0;
|
||||||
@ -2823,7 +2869,7 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
|
|||||||
* retun 0 if success.
|
* retun 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
|
int get_friendlist(Messenger *m, int32_t **out_list, uint32_t *out_list_length)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
@ -2834,7 +2880,7 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_list = malloc(m->numfriends * sizeof(int));
|
*out_list = malloc(m->numfriends * sizeof(int32_t));
|
||||||
|
|
||||||
if (*out_list == NULL) {
|
if (*out_list == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -198,28 +198,28 @@ typedef struct Messenger {
|
|||||||
|
|
||||||
uint64_t last_LANdiscovery;
|
uint64_t last_LANdiscovery;
|
||||||
|
|
||||||
void (*friend_message)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
void (*friend_message)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
|
||||||
void *friend_message_userdata;
|
void *friend_message_userdata;
|
||||||
void (*friend_action)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
void (*friend_action)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
|
||||||
void *friend_action_userdata;
|
void *friend_action_userdata;
|
||||||
void (*friend_namechange)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
void (*friend_namechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
|
||||||
void *friend_namechange_userdata;
|
void *friend_namechange_userdata;
|
||||||
void (*friend_statusmessagechange)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
void (*friend_statusmessagechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
|
||||||
void *friend_statusmessagechange_userdata;
|
void *friend_statusmessagechange_userdata;
|
||||||
void (*friend_userstatuschange)(struct Messenger *m, int, USERSTATUS, void *);
|
void (*friend_userstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
||||||
void *friend_userstatuschange_userdata;
|
void *friend_userstatuschange_userdata;
|
||||||
void (*friend_typingchange)(struct Messenger *m, int, int, void *);
|
void (*friend_typingchange)(struct Messenger *m, int32_t, int, void *);
|
||||||
void *friend_typingchange_userdata;
|
void *friend_typingchange_userdata;
|
||||||
void (*read_receipt)(struct Messenger *m, int, uint32_t, void *);
|
void (*read_receipt)(struct Messenger *m, int32_t, uint32_t, void *);
|
||||||
void *read_receipt_userdata;
|
void *read_receipt_userdata;
|
||||||
void (*friend_statuschange)(struct Messenger *m, int, uint8_t, void *);
|
void (*friend_statuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
||||||
void *friend_statuschange_userdata;
|
void *friend_statuschange_userdata;
|
||||||
void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *);
|
void (*friend_connectionstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
||||||
void *friend_connectionstatuschange_userdata;
|
void *friend_connectionstatuschange_userdata;
|
||||||
void (*friend_connectionstatuschange_internal)(struct Messenger *m, int, uint8_t, void *);
|
void (*friend_connectionstatuschange_internal)(struct Messenger *m, int32_t, uint8_t, void *);
|
||||||
void *friend_connectionstatuschange_internal_userdata;
|
void *friend_connectionstatuschange_internal_userdata;
|
||||||
|
|
||||||
void (*group_invite)(struct Messenger *m, int, uint8_t *, void *);
|
void (*group_invite)(struct Messenger *m, int32_t, uint8_t *, void *);
|
||||||
void *group_invite_userdata;
|
void *group_invite_userdata;
|
||||||
void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *);
|
void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *);
|
||||||
void *group_message_userdata;
|
void *group_message_userdata;
|
||||||
@ -228,14 +228,14 @@ typedef struct Messenger {
|
|||||||
void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *);
|
void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *);
|
||||||
void *group_namelistchange_userdata;
|
void *group_namelistchange_userdata;
|
||||||
|
|
||||||
void (*file_sendrequest)(struct Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, void *);
|
void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t, void *);
|
||||||
void *file_sendrequest_userdata;
|
void *file_sendrequest_userdata;
|
||||||
void (*file_filecontrol)(struct Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t, void *);
|
void (*file_filecontrol)(struct Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t, void *);
|
||||||
void *file_filecontrol_userdata;
|
void *file_filecontrol_userdata;
|
||||||
void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *);
|
void (*file_filedata)(struct Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length, void *);
|
||||||
void *file_filedata_userdata;
|
void *file_filedata_userdata;
|
||||||
|
|
||||||
void (*msi_packet)(struct Messenger *m, int, uint8_t *, uint16_t, void *);
|
void (*msi_packet)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
|
||||||
void *msi_packet_userdata;
|
void *msi_packet_userdata;
|
||||||
|
|
||||||
} Messenger;
|
} Messenger;
|
||||||
@ -262,19 +262,19 @@ void getaddress(Messenger *m, uint8_t *address);
|
|||||||
* (the nospam for that friend was set to the new one).
|
* (the nospam for that friend was set to the new one).
|
||||||
* return -8 if increasing the friend list size fails.
|
* return -8 if increasing the friend list size fails.
|
||||||
*/
|
*/
|
||||||
int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
|
int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
|
|
||||||
/* Add a friend without sending a friendrequest.
|
/* Add a friend without sending a friendrequest.
|
||||||
* return the friend number if success.
|
* return the friend number if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int m_addfriend_norequest(Messenger *m, uint8_t *client_id);
|
int32_t m_addfriend_norequest(Messenger *m, uint8_t *client_id);
|
||||||
|
|
||||||
/* return the friend id associated to that client id.
|
/* return the friend number associated to that client id.
|
||||||
* return -1 if no such friend.
|
* return -1 if no such friend.
|
||||||
*/
|
*/
|
||||||
int getfriend_id(Messenger *m, uint8_t *client_id);
|
int32_t getfriend_id(Messenger *m, uint8_t *client_id);
|
||||||
|
|
||||||
/* Copies the public key associated to that friend id into client_id buffer.
|
/* Copies the public key associated to that friend id into client_id buffer.
|
||||||
* Make sure that client_id is of size CLIENT_ID_SIZE.
|
* Make sure that client_id is of size CLIENT_ID_SIZE.
|
||||||
@ -282,10 +282,14 @@ int getfriend_id(Messenger *m, uint8_t *client_id);
|
|||||||
* return 0 if success
|
* return 0 if success
|
||||||
* return -1 if failure
|
* return -1 if failure
|
||||||
*/
|
*/
|
||||||
int getclient_id(Messenger *m, int friend_id, uint8_t *client_id);
|
int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id);
|
||||||
|
|
||||||
/* Remove a friend. */
|
/* Remove a friend.
|
||||||
int m_delfriend(Messenger *m, int friendnumber);
|
*
|
||||||
|
* return 0 if success
|
||||||
|
* return -1 if failure
|
||||||
|
*/
|
||||||
|
int m_delfriend(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Checks friend's connecting status.
|
/* Checks friend's connecting status.
|
||||||
*
|
*
|
||||||
@ -293,14 +297,14 @@ int m_delfriend(Messenger *m, int friendnumber);
|
|||||||
* return 0 if friend is not connected to us (Offline).
|
* return 0 if friend is not connected to us (Offline).
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_get_friend_connectionstatus(Messenger *m, int friendnumber);
|
int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Checks if there exists a friend with given friendnumber.
|
/* Checks if there exists a friend with given friendnumber.
|
||||||
*
|
*
|
||||||
* return 1 if friend exists.
|
* return 1 if friend exists.
|
||||||
* return 0 if friend doesn't exist.
|
* return 0 if friend doesn't exist.
|
||||||
*/
|
*/
|
||||||
int m_friend_exists(Messenger *m, int friendnumber);
|
int m_friend_exists(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Send a text chat message to an online friend.
|
/* Send a text chat message to an online friend.
|
||||||
*
|
*
|
||||||
@ -312,8 +316,8 @@ int m_friend_exists(Messenger *m, int friendnumber);
|
|||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
*/
|
*/
|
||||||
uint32_t m_sendmessage(Messenger *m, int friendnumber, uint8_t *message, uint32_t length);
|
uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, uint8_t *message, uint32_t length);
|
||||||
uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
|
uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
*
|
*
|
||||||
@ -325,8 +329,8 @@ uint32_t m_sendmessage_withid(Messenger *m, int friendnumber, uint32_t theid, ui
|
|||||||
* m_sendaction_withid will send an action message with the id of your choosing,
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendaction.
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
uint32_t m_sendaction(Messenger *m, int friendnumber, uint8_t *action, uint32_t length);
|
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint32_t length);
|
||||||
uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
||||||
|
|
||||||
/* Set the name and name_length of a friend.
|
/* Set the name and name_length of a friend.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
@ -336,7 +340,7 @@ uint32_t m_sendaction_withid(Messenger *m, int friendnumber, uint32_t theid, uin
|
|||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int setfriendname(Messenger *m, int friendnumber, uint8_t *name, uint16_t length);
|
int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length);
|
||||||
|
|
||||||
/* Set our nickname.
|
/* Set our nickname.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
@ -351,13 +355,12 @@ int setname(Messenger *m, uint8_t *name, uint16_t length);
|
|||||||
/*
|
/*
|
||||||
* Get your nickname.
|
* Get your nickname.
|
||||||
* m - The messanger context to use.
|
* m - The messanger context to use.
|
||||||
* name - Pointer to a string for the name.
|
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
||||||
* nlen - The length of the string buffer.
|
|
||||||
*
|
*
|
||||||
* return length of the name.
|
* return length of the name.
|
||||||
* return 0 on error.
|
* return 0 on error.
|
||||||
*/
|
*/
|
||||||
uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen);
|
uint16_t getself_name(Messenger *m, uint8_t *name);
|
||||||
|
|
||||||
/* Get name of friendnumber and put it in name.
|
/* Get name of friendnumber and put it in name.
|
||||||
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
||||||
@ -365,12 +368,18 @@ uint16_t getself_name(Messenger *m, uint8_t *name, uint16_t nlen);
|
|||||||
* return length of name if success.
|
* return length of name if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int getname(Messenger *m, int friendnumber, uint8_t *name);
|
int getname(Messenger *m, int32_t friendnumber, uint8_t *name);
|
||||||
|
|
||||||
|
/* return the length of name, including null on success.
|
||||||
|
* return -1 on failure.
|
||||||
|
*/
|
||||||
|
int m_get_name_size(Messenger *m, int32_t friendnumber);
|
||||||
|
int m_get_self_name_size(Messenger *m);
|
||||||
|
|
||||||
/* returns valid ip port of connected friend on success
|
/* returns valid ip port of connected friend on success
|
||||||
* returns zeroed out IP_Port on failure
|
* returns zeroed out IP_Port on failure
|
||||||
*/
|
*/
|
||||||
IP_Port get_friend_ipport(Messenger *m, int friendnumber);
|
IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Set our user status.
|
/* Set our user status.
|
||||||
* You are responsible for freeing status after.
|
* You are responsible for freeing status after.
|
||||||
@ -379,12 +388,13 @@ IP_Port get_friend_ipport(Messenger *m, int friendnumber);
|
|||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length);
|
int m_set_statusmessage(Messenger *m, uint8_t *status, uint16_t length);
|
||||||
int m_set_userstatus(Messenger *m, USERSTATUS status);
|
int m_set_userstatus(Messenger *m, uint8_t status);
|
||||||
|
|
||||||
/* return the length of friendnumber's status message, including null.
|
/* return the length of friendnumber's status message, including null on success.
|
||||||
* Pass it into malloc.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_get_statusmessage_size(Messenger *m, int friendnumber);
|
int m_get_statusmessage_size(Messenger *m, int32_t friendnumber);
|
||||||
|
int m_get_self_statusmessage_size(Messenger *m);
|
||||||
|
|
||||||
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
||||||
* Get the size you need to allocate from m_get_statusmessage_size.
|
* Get the size you need to allocate from m_get_statusmessage_size.
|
||||||
@ -393,7 +403,7 @@ int m_get_statusmessage_size(Messenger *m, int friendnumber);
|
|||||||
* returns the length of the copied data on success
|
* returns the length of the copied data on success
|
||||||
* retruns -1 on failure.
|
* retruns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_copy_statusmessage(Messenger *m, int friendnumber, uint8_t *buf, uint32_t maxlen);
|
int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
|
||||||
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen);
|
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen);
|
||||||
|
|
||||||
/* return one of USERSTATUS values.
|
/* return one of USERSTATUS values.
|
||||||
@ -401,13 +411,13 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen);
|
|||||||
* 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.
|
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
|
||||||
*/
|
*/
|
||||||
USERSTATUS m_get_userstatus(Messenger *m, int friendnumber);
|
uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber);
|
||||||
USERSTATUS m_get_self_userstatus(Messenger *m);
|
uint8_t m_get_self_userstatus(Messenger *m);
|
||||||
|
|
||||||
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
||||||
* returns -1 on error.
|
* returns -1 on error.
|
||||||
*/
|
*/
|
||||||
uint64_t m_get_last_online(Messenger *m, int friendnumber);
|
uint64_t m_get_last_online(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Set our typing status for a friend.
|
/* Set our typing status for a friend.
|
||||||
* You are responsible for turning it on or off.
|
* You are responsible for turning it on or off.
|
||||||
@ -415,63 +425,65 @@ uint64_t m_get_last_online(Messenger *m, int friendnumber);
|
|||||||
* returns 0 on success.
|
* returns 0 on success.
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing);
|
int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
|
||||||
|
|
||||||
/* Get the typing status of a friend.
|
/* Get the typing status of a friend.
|
||||||
*
|
*
|
||||||
* returns 0 if friend is not typing.
|
* returns 0 if friend is not typing.
|
||||||
* returns 1 if friend is typing.
|
* returns 1 if friend is typing.
|
||||||
*/
|
*/
|
||||||
int m_get_istyping(Messenger *m, int friendnumber);
|
int m_get_istyping(Messenger *m, int32_t friendnumber);
|
||||||
|
|
||||||
/* Sets whether we send read receipts for friendnumber.
|
/* Sets whether we send read receipts for friendnumber.
|
||||||
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
||||||
*/
|
*/
|
||||||
void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno);
|
void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno);
|
||||||
|
|
||||||
/* Set the function that will be executed when a friend request is received.
|
/* Set the function that will be executed when a friend request is received.
|
||||||
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
||||||
*/
|
*/
|
||||||
void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata);
|
void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata);
|
||||||
|
|
||||||
/* Set the function that will be executed when a message from a friend is received.
|
/* Set the function that will be executed when a message from a friend is received.
|
||||||
* Function format is: function(int friendnumber, uint8_t * message, uint32_t length)
|
* Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
|
||||||
*/
|
*/
|
||||||
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the function that will be executed when an action from a friend is received.
|
/* Set the function that will be executed when an action from a friend is received.
|
||||||
* Function format is: function(int friendnumber, uint8_t * action, uint32_t length)
|
* Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
|
||||||
*/
|
*/
|
||||||
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *), void *userdata);
|
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for name changes.
|
/* Set the callback for name changes.
|
||||||
* Function(int friendnumber, uint8_t *newname, uint16_t length)
|
* Function(int32_t friendnumber, uint8_t *newname, uint16_t length)
|
||||||
* You are not responsible for freeing newname.
|
* You are not responsible for freeing newname.
|
||||||
*/
|
*/
|
||||||
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for status message changes.
|
/* Set the callback for status message changes.
|
||||||
* Function(int friendnumber, uint8_t *newstatus, uint16_t length)
|
* Function(int32_t friendnumber, uint8_t *newstatus, uint16_t length)
|
||||||
*
|
*
|
||||||
* You are not responsible for freeing newstatus
|
* You are not responsible for freeing newstatus
|
||||||
*/
|
*/
|
||||||
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for status type changes.
|
/* Set the callback for status type changes.
|
||||||
* Function(int friendnumber, USERSTATUS kind)
|
* Function(int32_t friendnumber, USERSTATUS kind)
|
||||||
*/
|
*/
|
||||||
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void *), void *userdata);
|
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for typing changes.
|
/* Set the callback for typing changes.
|
||||||
* Function(int friendnumber, int is_typing)
|
* Function(int32_t friendnumber, int is_typing)
|
||||||
*/
|
*/
|
||||||
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, int, void *), void *userdata);
|
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int32_t, int, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for read receipts.
|
/* Set the callback for read receipts.
|
||||||
* Function(int friendnumber, uint32_t receipt)
|
* Function(int32_t friendnumber, uint32_t receipt)
|
||||||
*
|
*
|
||||||
* If you are keeping a record of returns from m_sendmessage,
|
* If you are keeping a record of returns from m_sendmessage,
|
||||||
* receipt might be one of those values, meaning the message
|
* receipt might be one of those values, meaning the message
|
||||||
@ -479,10 +491,10 @@ void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, in
|
|||||||
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
||||||
* In that case, you should discard it.
|
* In that case, you should discard it.
|
||||||
*/
|
*/
|
||||||
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata);
|
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int32_t, uint32_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for connection status changes.
|
/* Set the callback for connection status changes.
|
||||||
* function(int friendnumber, uint8_t status)
|
* function(int32_t friendnumber, uint8_t status)
|
||||||
*
|
*
|
||||||
* Status:
|
* Status:
|
||||||
* 0 -- friend went offline after being previously online.
|
* 0 -- friend went offline after being previously online.
|
||||||
@ -492,18 +504,19 @@ void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, u
|
|||||||
* being previously online" part.
|
* being previously online" part.
|
||||||
* It's assumed that when adding friends, their connection status is offline.
|
* It's assumed that when adding friends, their connection status is offline.
|
||||||
*/
|
*/
|
||||||
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *), void *userdata);
|
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *),
|
||||||
|
void *userdata);
|
||||||
/* Same as previous but for internal A/V core usage only */
|
/* Same as previous but for internal A/V core usage only */
|
||||||
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void *),
|
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/**********GROUP CHATS************/
|
/**********GROUP CHATS************/
|
||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata)
|
* Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
|
||||||
*/
|
*/
|
||||||
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, void *), void *userdata);
|
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for group messages.
|
/* Set the callback for group messages.
|
||||||
*
|
*
|
||||||
@ -553,14 +566,14 @@ int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *nam
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int invite_friend(Messenger *m, int friendnumber, int groupnumber);
|
int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber);
|
||||||
|
|
||||||
/* Join a group (you need to have been invited first.)
|
/* Join a group (you need to have been invited first.)
|
||||||
*
|
*
|
||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_key);
|
int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key);
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
* return 0 on success
|
* return 0 on success
|
||||||
@ -594,25 +607,27 @@ int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES],
|
|||||||
|
|
||||||
/* Set the callback for file send requests.
|
/* Set the callback for file send requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t,
|
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *,
|
||||||
|
uint16_t,
|
||||||
void *), void *userdata);
|
void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for file control requests.
|
/* Set the callback for file control requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *,
|
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
|
||||||
uint16_t, void *), void *userdata);
|
uint16_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for file data.
|
/* Set the callback for file data.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *),
|
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length,
|
||||||
|
void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Send a file send request.
|
/* Send a file send request.
|
||||||
@ -620,7 +635,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
|
int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
|
||||||
uint16_t filename_length);
|
uint16_t filename_length);
|
||||||
|
|
||||||
/* Send a file send request.
|
/* Send a file send request.
|
||||||
@ -628,7 +643,7 @@ int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_
|
|||||||
* return file number on success
|
* return file number on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
|
int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
|
||||||
|
|
||||||
/* Send a file control request.
|
/* Send a file control request.
|
||||||
* send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file.
|
* send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file.
|
||||||
@ -636,7 +651,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
int file_control(Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
||||||
uint8_t *data, uint16_t length);
|
uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/* Send file data.
|
/* Send file data.
|
||||||
@ -644,7 +659,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
|
int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/* Give the number of bytes left to be sent/received.
|
/* Give the number of bytes left to be sent/received.
|
||||||
*
|
*
|
||||||
@ -653,15 +668,15 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data,
|
|||||||
* return number of bytes remaining to be sent/received on success
|
* return number of bytes remaining to be sent/received on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive);
|
uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
|
||||||
|
|
||||||
/*************** A/V related ******************/
|
/*************** A/V related ******************/
|
||||||
|
|
||||||
/* Set the callback for msi packets.
|
/* Set the callback for msi packets.
|
||||||
*
|
*
|
||||||
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void *),
|
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Send an msi packet.
|
/* Send an msi packet.
|
||||||
@ -669,7 +684,7 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int, uin
|
|||||||
* return 1 on success
|
* return 1 on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length);
|
int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/**********************************************/
|
/**********************************************/
|
||||||
|
|
||||||
@ -678,7 +693,7 @@ int m_msi_packet(Messenger *m, int friendnumber, uint8_t *data, uint16_t length)
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return 0 on success.
|
* return 0 on success.
|
||||||
*/
|
*/
|
||||||
int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t byte, packet_handler_callback cb,
|
int custom_user_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte, packet_handler_callback cb,
|
||||||
void *object);
|
void *object);
|
||||||
|
|
||||||
/* High level function to send custom user packets.
|
/* High level function to send custom user packets.
|
||||||
@ -686,7 +701,7 @@ int custom_user_packet_registerhandler(Messenger *m, int friendnumber, uint8_t b
|
|||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
* return number of bytes sent on success.
|
* return number of bytes sent on success.
|
||||||
*/
|
*/
|
||||||
int send_custom_user_packet(Messenger *m, int friendnumber, uint8_t *data, uint32_t length);
|
int send_custom_user_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length);
|
||||||
|
|
||||||
/**********************************************/
|
/**********************************************/
|
||||||
/* Run this at startup.
|
/* Run this at startup.
|
||||||
@ -706,9 +721,10 @@ void do_messenger(Messenger *m);
|
|||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int wait_prepare_messenger(Messenger *m, uint8_t *data, uint16_t *lenptr);
|
size_t wait_data_size();
|
||||||
int wait_execute_messenger(Messenger *m, uint8_t *data, uint16_t len, uint16_t milliseconds);
|
int wait_prepare_messenger(Messenger *m, uint8_t *data);
|
||||||
void wait_cleanup_messenger(Messenger *m, uint8_t *data, uint16_t len);
|
int wait_execute_messenger(uint8_t *data, long seconds, long microseconds);
|
||||||
|
int wait_cleanup_messenger(Messenger *m, uint8_t *data);
|
||||||
|
|
||||||
/* SAVING AND LOADING FUNCTIONS: */
|
/* SAVING AND LOADING FUNCTIONS: */
|
||||||
|
|
||||||
@ -752,7 +768,7 @@ uint32_t get_num_online_friends(Messenger *m);
|
|||||||
* Otherwise, returns the number of elements copied.
|
* Otherwise, returns the number of elements copied.
|
||||||
* If the array was too small, the contents
|
* If the array was too small, the contents
|
||||||
* of out_list will be truncated to list_size. */
|
* of out_list will be truncated to list_size. */
|
||||||
uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size);
|
uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size);
|
||||||
|
|
||||||
/* Allocate and return a list of valid friend id's. List must be freed by the
|
/* Allocate and return a list of valid friend id's. List must be freed by the
|
||||||
* caller.
|
* caller.
|
||||||
|
@ -72,11 +72,12 @@ uint32_t get_nospam(Friend_Requests *fr)
|
|||||||
|
|
||||||
|
|
||||||
/* Set the function that will be executed when a friend request is received. */
|
/* Set the function that will be executed when a friend request is received. */
|
||||||
void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *),
|
void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *object, void *userdata)
|
||||||
{
|
{
|
||||||
fr->handle_friendrequest = function;
|
fr->handle_friendrequest = function;
|
||||||
fr->handle_friendrequest_isset = 1;
|
fr->handle_friendrequest_isset = 1;
|
||||||
|
fr->handle_friendrequest_object = object;
|
||||||
fr->handle_friendrequest_userdata = userdata;
|
fr->handle_friendrequest_userdata = userdata;
|
||||||
}
|
}
|
||||||
/* Set the function used to check if a friend request should be displayed to the user or not. */
|
/* Set the function used to check if a friend request should be displayed to the user or not. */
|
||||||
@ -141,9 +142,12 @@ static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t
|
|||||||
|
|
||||||
addto_receivedlist(fr, source_pubkey);
|
addto_receivedlist(fr, source_pubkey);
|
||||||
|
|
||||||
packet[length - 1] = 0; /* Force NULL terminator. */
|
uint8_t message[length - 4 + 1];
|
||||||
|
memcpy(message, packet + 4, length - 4);
|
||||||
|
message[sizeof(message) - 1] = 0; /* Be sure the message is null terminated. */
|
||||||
|
|
||||||
(*fr->handle_friendrequest)(source_pubkey, packet + 4, length - 4, fr->handle_friendrequest_userdata);
|
(*fr->handle_friendrequest)(fr->handle_friendrequest_object, source_pubkey, message, length - 4,
|
||||||
|
fr->handle_friendrequest_userdata);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,9 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t nospam;
|
uint32_t nospam;
|
||||||
void (*handle_friendrequest)(uint8_t *, uint8_t *, uint16_t, void *);
|
void (*handle_friendrequest)(void *, uint8_t *, uint8_t *, uint16_t, void *);
|
||||||
uint8_t handle_friendrequest_isset;
|
uint8_t handle_friendrequest_isset;
|
||||||
|
void *handle_friendrequest_object;
|
||||||
void *handle_friendrequest_userdata;
|
void *handle_friendrequest_userdata;
|
||||||
|
|
||||||
int (*filter_function)(uint8_t *, void *);
|
int (*filter_function)(uint8_t *, void *);
|
||||||
@ -57,8 +58,8 @@ uint32_t get_nospam(Friend_Requests *fr);
|
|||||||
/* Set the function that will be executed when a friend request for us is received.
|
/* 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, uint16_t length, void * userdata)
|
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata)
|
||||||
*/
|
*/
|
||||||
void callback_friendrequest(Friend_Requests *fr, void (*function)(uint8_t *, uint8_t *, uint16_t, void *),
|
void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *object, void *userdata);
|
||||||
|
|
||||||
/* Set the function used to check if a friend request should be displayed to the user or not.
|
/* 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)
|
* Function format is int function(uint8_t * public_key, void * userdata)
|
||||||
|
@ -335,7 +335,7 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
|
|||||||
|
|
||||||
static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t contents_len)
|
static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t contents_len)
|
||||||
{
|
{
|
||||||
if (contents_len > MAX_NICK_BYTES || contents_len == 0)
|
if (contents_len >= MAX_NICK_BYTES || contents_len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* same name as already stored? */
|
/* same name as already stored? */
|
||||||
@ -345,7 +345,7 @@ static void setnick(Group_Chat *chat, int peernum, uint8_t *contents, uint16_t c
|
|||||||
|
|
||||||
memcpy(chat->group[peernum].nick, contents, contents_len);
|
memcpy(chat->group[peernum].nick, contents, contents_len);
|
||||||
/* Force null termination */
|
/* Force null termination */
|
||||||
chat->group[peernum].nick[contents_len - 1] = 0;
|
chat->group[peernum].nick[contents_len] = 0;
|
||||||
chat->group[peernum].nick_len = contents_len;
|
chat->group[peernum].nick_len = contents_len;
|
||||||
|
|
||||||
if (chat->peer_namelistchange != NULL)
|
if (chat->peer_namelistchange != NULL)
|
||||||
|
@ -311,17 +311,17 @@ typedef struct {
|
|||||||
uint64_t send_fail_eagain;
|
uint64_t send_fail_eagain;
|
||||||
} select_info;
|
} select_info;
|
||||||
|
|
||||||
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data, uint16_t *lenptr)
|
size_t networking_wait_data_size()
|
||||||
{
|
{
|
||||||
if ((data == NULL) || !lenptr || (*lenptr < sizeof(select_info))) {
|
return sizeof(select_info);
|
||||||
if (lenptr) {
|
}
|
||||||
*lenptr = sizeof(select_info);
|
|
||||||
return 0;
|
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data)
|
||||||
} else
|
{
|
||||||
return -1;
|
if (data == NULL) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*lenptr = sizeof(select_info);
|
|
||||||
select_info *s = (select_info *)data;
|
select_info *s = (select_info *)data;
|
||||||
s->sock = net->sock;
|
s->sock = net->sock;
|
||||||
s->sendqueue_length = sendqueue_length;
|
s->sendqueue_length = sendqueue_length;
|
||||||
@ -331,26 +331,42 @@ int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uin
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
|
/* *** Function MUSTN'T poll. ***
|
||||||
|
* The function mustn't modify anything at all, so it can be called completely
|
||||||
|
* asynchronously without any worry.
|
||||||
|
*/
|
||||||
|
int networking_wait_execute(uint8_t *data, long seconds, long microseconds)
|
||||||
{
|
{
|
||||||
/* WIN32: supported since Win2K, but might need some adjustements */
|
/* WIN32: supported since Win2K, but might need some adjustements */
|
||||||
/* UNIX: this should work for any remotely Unix'ish system */
|
/* UNIX: this should work for any remotely Unix'ish system */
|
||||||
|
|
||||||
|
if (data == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
select_info *s = (select_info *)data;
|
select_info *s = (select_info *)data;
|
||||||
|
|
||||||
/* add only if we had a failed write */
|
/* add only if we had a failed write */
|
||||||
int writefds_add = 0;
|
int writefds_add = 0;
|
||||||
|
|
||||||
|
/* if send_fail_eagain is set, that means that socket's buffer was full and couldn't fit data we tried to send,
|
||||||
|
* so this is the only case when we need to know when the socket becomes write-ready, i.e. socket's buffer gets
|
||||||
|
* some free space for us to put data to be sent in, but select will tell us that the socket is writable even
|
||||||
|
* if we can fit a small part of our data (say 1 byte), so we wait some time, in hope that large enough chunk
|
||||||
|
* of socket's buffer will be available (at least that's how I understand intentions of the previous author of
|
||||||
|
* that code)
|
||||||
|
*/
|
||||||
if (s->send_fail_eagain != 0) {
|
if (s->send_fail_eagain != 0) {
|
||||||
// current_time(): microseconds
|
// current_time(): microseconds
|
||||||
uint64_t now = current_time();
|
uint64_t now = current_time();
|
||||||
|
|
||||||
/* s->sendqueue_length: might be used to guess how long we keep checking */
|
/* s->sendqueue_length: might be used to guess how long we keep checking */
|
||||||
/* for now, threshold is hardcoded to 500ms, too long for a really really
|
/* for now, threshold is hardcoded to 250ms, too long for a really really
|
||||||
* fast link, but too short for a sloooooow link... */
|
* fast link, but too short for a sloooooow link... */
|
||||||
if (now - s->send_fail_eagain < 500000)
|
if (now - s->send_fail_eagain < 250000) {
|
||||||
writefds_add = 1;
|
writefds_add = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int nfds = 1 + s->sock;
|
int nfds = 1 + s->sock;
|
||||||
|
|
||||||
@ -362,27 +378,34 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
|
|||||||
fd_set writefds;
|
fd_set writefds;
|
||||||
FD_ZERO(&writefds);
|
FD_ZERO(&writefds);
|
||||||
|
|
||||||
if (writefds_add)
|
if (writefds_add) {
|
||||||
FD_SET(s->sock, &writefds);
|
FD_SET(s->sock, &writefds);
|
||||||
|
}
|
||||||
|
|
||||||
fd_set exceptfds;
|
fd_set exceptfds;
|
||||||
FD_ZERO(&exceptfds);
|
FD_ZERO(&exceptfds);
|
||||||
FD_SET(s->sock, &exceptfds);
|
FD_SET(s->sock, &exceptfds);
|
||||||
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeout.tv_sec = 0;
|
struct timeval *timeout_ptr = &timeout;
|
||||||
timeout.tv_usec = milliseconds * 1000;
|
|
||||||
|
if (seconds < 0 || microseconds < 0) {
|
||||||
|
timeout_ptr = NULL;
|
||||||
|
} else {
|
||||||
|
timeout.tv_sec = seconds;
|
||||||
|
timeout.tv_usec = microseconds;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#endif
|
#endif
|
||||||
/* returns -1 on error, 0 on timeout, the socket on activity */
|
/* returns -1 on error, 0 on timeout, the socket on activity */
|
||||||
int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
|
int res = select(nfds, &readfds, &writefds, &exceptfds, timeout_ptr);
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
|
|
||||||
/* only dump if not timeout */
|
/* only dump if not timeout */
|
||||||
if (res) {
|
if (res) {
|
||||||
sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno,
|
sprintf(logbuffer, "select(%d, %d): %d (%d, %s) - %d %d %d\n", microseconds, seconds, res, errno,
|
||||||
strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
|
strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
|
||||||
FD_ISSET(s->sock, &exceptfds));
|
FD_ISSET(s->sock, &exceptfds));
|
||||||
loglog(logbuffer);
|
loglog(logbuffer);
|
||||||
@ -390,20 +413,28 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (FD_ISSET(s->sock, &writefds))
|
if (FD_ISSET(s->sock, &writefds)) {
|
||||||
s->send_fail_reset = 1;
|
s->send_fail_reset = 1;
|
||||||
|
|
||||||
return res > 0 ? 1 : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void networking_wait_cleanup(Networking_Core *net, uint8_t *data, uint16_t len)
|
return res > 0 ? 2 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int networking_wait_cleanup(Networking_Core *net, uint8_t *data)
|
||||||
{
|
{
|
||||||
|
if (data == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
select_info *s = (select_info *)data;
|
select_info *s = (select_info *)data;
|
||||||
|
|
||||||
if (s->send_fail_reset)
|
if (s->send_fail_reset) {
|
||||||
net->send_fail_eagain = 0;
|
net->send_fail_eagain = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t at_startup_ran = 0;
|
uint8_t at_startup_ran = 0;
|
||||||
static int at_startup(void)
|
static int at_startup(void)
|
||||||
{
|
{
|
||||||
|
@ -316,9 +316,10 @@ void networking_poll(Networking_Core *net);
|
|||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data, uint16_t *lenptr);
|
size_t networking_wait_data_size();
|
||||||
int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds);
|
int networking_wait_prepare(Networking_Core *net, uint32_t sendqueue_length, uint8_t *data);
|
||||||
void networking_wait_cleanup(Networking_Core *net, uint8_t *data, uint16_t len);
|
int networking_wait_execute(uint8_t *data, long seconds, long microseconds);
|
||||||
|
int networking_wait_cleanup(Networking_Core *net, uint8_t *data);
|
||||||
|
|
||||||
/* Initialize networking.
|
/* Initialize networking.
|
||||||
* bind to ip and port.
|
* bind to ip and port.
|
||||||
|
172
toxcore/tox.c
172
toxcore/tox.c
@ -60,7 +60,7 @@ void tox_get_address(Tox *tox, uint8_t *address)
|
|||||||
* (the nospam for that friend was set to the new one).
|
* (the nospam for that friend was set to the new one).
|
||||||
* return FAERR_NOMEM if increasing the friend list size fails.
|
* return FAERR_NOMEM if increasing the friend list size fails.
|
||||||
*/
|
*/
|
||||||
int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length)
|
int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_addfriend(m, address, data, length);
|
return m_addfriend(m, address, data, length);
|
||||||
@ -71,16 +71,16 @@ int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length)
|
|||||||
* return the friend number if success.
|
* return the friend number if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_add_friend_norequest(Tox *tox, uint8_t *client_id)
|
int32_t tox_add_friend_norequest(Tox *tox, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_addfriend_norequest(m, client_id);
|
return m_addfriend_norequest(m, client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return the friend id associated to that client id.
|
/* return the friend number associated to that client id.
|
||||||
* return -1 if no such friend.
|
* return -1 if no such friend.
|
||||||
*/
|
*/
|
||||||
int tox_get_friend_id(Tox *tox, uint8_t *client_id)
|
int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return getfriend_id(m, client_id);
|
return getfriend_id(m, client_id);
|
||||||
@ -92,14 +92,14 @@ int tox_get_friend_id(Tox *tox, uint8_t *client_id)
|
|||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_client_id(Tox *tox, int friend_id, uint8_t *client_id)
|
int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return getclient_id(m, friend_id, client_id);
|
return getclient_id(m, friendnumber, client_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove a friend. */
|
/* Remove a friend. */
|
||||||
int tox_del_friend(Tox *tox, int friendnumber)
|
int tox_del_friend(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_delfriend(m, friendnumber);
|
return m_delfriend(m, friendnumber);
|
||||||
@ -111,7 +111,7 @@ int tox_del_friend(Tox *tox, int friendnumber)
|
|||||||
* return 0 if friend is not connected to us (Offline).
|
* return 0 if friend is not connected to us (Offline).
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_friend_connection_status(Tox *tox, int friendnumber)
|
int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_get_friend_connectionstatus(m, friendnumber);
|
return m_get_friend_connectionstatus(m, friendnumber);
|
||||||
@ -122,7 +122,7 @@ int tox_get_friend_connection_status(Tox *tox, int friendnumber)
|
|||||||
* return 1 if friend exists.
|
* return 1 if friend exists.
|
||||||
* return 0 if friend doesn't exist.
|
* return 0 if friend doesn't exist.
|
||||||
*/
|
*/
|
||||||
int tox_friend_exists(Tox *tox, int friendnumber)
|
int tox_friend_exists(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_friend_exists(m, friendnumber);
|
return m_friend_exists(m, friendnumber);
|
||||||
@ -137,13 +137,13 @@ int tox_friend_exists(Tox *tox, int friendnumber)
|
|||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
*/
|
*/
|
||||||
uint32_t tox_send_message(Tox *tox, int friendnumber, uint8_t *message, uint32_t length)
|
uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_sendmessage(m, friendnumber, message, length);
|
return m_sendmessage(m, friendnumber, message, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length)
|
uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_sendmessage_withid(m, friendnumber, theid, message, length);
|
return m_sendmessage_withid(m, friendnumber, theid, message, length);
|
||||||
@ -159,13 +159,13 @@ uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uin
|
|||||||
* m_sendaction_withid will send an action message with the id of your choosing,
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendaction.
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
uint32_t tox_send_action(Tox *tox, int friendnumber, uint8_t *action, uint32_t length)
|
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_sendaction(m, friendnumber, action, length);
|
return m_sendaction(m, friendnumber, action, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tox_send_action_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_sendaction_withid(m, friendnumber, theid, action, length);
|
return m_sendaction_withid(m, friendnumber, theid, action, length);
|
||||||
@ -187,16 +187,15 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length)
|
|||||||
|
|
||||||
/* Get your nickname.
|
/* Get your nickname.
|
||||||
* m - The messanger context to use.
|
* m - The messanger context to use.
|
||||||
* name - Pointer to a string for the name.
|
* name - Pointer to a string for the name. (must be at least MAX_NAME_LENGTH)
|
||||||
* nlen - The length of the string buffer.
|
|
||||||
*
|
*
|
||||||
* return length of the name.
|
* return length of the name.
|
||||||
* return 0 on error.
|
* return 0 on error.
|
||||||
*/
|
*/
|
||||||
uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen)
|
uint16_t tox_get_self_name(Tox *tox, uint8_t *name)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return getself_name(m, name, nlen);
|
return getself_name(m, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get name of friendnumber and put it in name.
|
/* Get name of friendnumber and put it in name.
|
||||||
@ -205,12 +204,27 @@ uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen)
|
|||||||
* return length of name (with the NULL terminator) if success.
|
* return length of name (with the NULL terminator) if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_name(Tox *tox, int friendnumber, uint8_t *name)
|
int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return getname(m, friendnumber, name);
|
return getname(m, friendnumber, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* returns the length of name on success.
|
||||||
|
* returns -1 on failure.
|
||||||
|
*/
|
||||||
|
int tox_get_name_size(Tox *tox, int32_t friendnumber)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return m_get_name_size(m, friendnumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
int tox_get_self_name_size(Tox *tox)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return m_get_self_name_size(m);
|
||||||
|
}
|
||||||
|
|
||||||
/* Set our user status;
|
/* Set our user status;
|
||||||
* you are responsible for freeing status after.
|
* you are responsible for freeing status after.
|
||||||
*
|
*
|
||||||
@ -222,26 +236,32 @@ int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length)
|
|||||||
return m_set_statusmessage(m, status, length);
|
return m_set_statusmessage(m, status, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int tox_set_user_status(Tox *tox, TOX_USERSTATUS status)
|
int tox_set_user_status(Tox *tox, uint8_t status)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_set_userstatus(m, (USERSTATUS)status);
|
return m_set_userstatus(m, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return the length of friendnumber's status message, including null.
|
/* returns the length of status message on success.
|
||||||
* Pass it into malloc.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_status_message_size(Tox *tox, int friendnumber)
|
int tox_get_status_message_size(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_get_statusmessage_size(m, friendnumber);
|
return m_get_statusmessage_size(m, friendnumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tox_get_self_status_message_size(Tox *tox)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return m_get_self_statusmessage_size(m);
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
||||||
* Get the size you need to allocate from m_get_statusmessage_size.
|
* Get the size you need to allocate from m_get_statusmessage_size.
|
||||||
* The self variant will copy our own status message.
|
* The self variant will copy our own status message.
|
||||||
*/
|
*/
|
||||||
int tox_get_status_message(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen)
|
int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_copy_statusmessage(m, friendnumber, buf, maxlen);
|
return m_copy_statusmessage(m, friendnumber, buf, maxlen);
|
||||||
@ -258,22 +278,22 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen)
|
|||||||
* 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.
|
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
|
||||||
*/
|
*/
|
||||||
TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber)
|
uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber);
|
return m_get_userstatus(m, friendnumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
TOX_USERSTATUS tox_get_self_user_status(Tox *tox)
|
uint8_t tox_get_self_user_status(Tox *tox)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return (TOX_USERSTATUS)m_get_self_userstatus(m);
|
return m_get_self_userstatus(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
||||||
* returns -1 on error.
|
* returns -1 on error.
|
||||||
*/
|
*/
|
||||||
uint64_t tox_get_last_online(Tox *tox, int friendnumber)
|
uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_get_last_online(m, friendnumber);
|
return m_get_last_online(m, friendnumber);
|
||||||
@ -285,7 +305,7 @@ uint64_t tox_get_last_online(Tox *tox, int friendnumber)
|
|||||||
* returns 0 on success.
|
* returns 0 on success.
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing)
|
int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_set_usertyping(m, friendnumber, is_typing);
|
return m_set_usertyping(m, friendnumber, is_typing);
|
||||||
@ -296,7 +316,7 @@ int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing)
|
|||||||
* returns 0 if friend is not typing.
|
* returns 0 if friend is not typing.
|
||||||
* returns 1 if friend is typing.
|
* returns 1 if friend is typing.
|
||||||
*/
|
*/
|
||||||
int tox_get_is_typing(Tox *tox, int friendnumber)
|
int tox_get_is_typing(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return m_get_istyping(m, friendnumber);
|
return m_get_istyping(m, friendnumber);
|
||||||
@ -305,7 +325,7 @@ int tox_get_is_typing(Tox *tox, int friendnumber)
|
|||||||
/* Sets whether we send read receipts for friendnumber.
|
/* Sets whether we send read receipts for friendnumber.
|
||||||
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
||||||
*/
|
*/
|
||||||
void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno)
|
void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_set_sends_receipts(m, friendnumber, yesno);
|
m_set_sends_receipts(m, friendnumber, yesno);
|
||||||
@ -332,7 +352,7 @@ uint32_t tox_get_num_online_friends(Tox *tox)
|
|||||||
* Otherwise, returns the number of elements copied.
|
* Otherwise, returns the number of elements copied.
|
||||||
* If the array was too small, the contents
|
* If the array was too small, the contents
|
||||||
* of out_list will be truncated to list_size. */
|
* of out_list will be truncated to list_size. */
|
||||||
uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size)
|
uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return copy_friendlist(m, out_list, list_size);
|
return copy_friendlist(m, out_list, list_size);
|
||||||
@ -341,7 +361,8 @@ uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size)
|
|||||||
/* Set the function that will be executed when a friend request is received.
|
/* Set the function that will be executed when a friend request is received.
|
||||||
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata)
|
void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_friendrequest(m, function, userdata);
|
m_callback_friendrequest(m, function, userdata);
|
||||||
@ -349,9 +370,9 @@ void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *
|
|||||||
|
|
||||||
|
|
||||||
/* Set the function that will be executed when a message from a friend is received.
|
/* Set the function that will be executed when a message from a friend is received.
|
||||||
* Function format is: function(int friendnumber, uint8_t * message, uint32_t length)
|
* Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -359,9 +380,9 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the function that will be executed when an action from a friend is received.
|
/* Set the function that will be executed when an action from a friend is received.
|
||||||
* function format is: function(int friendnumber, uint8_t * action, uint32_t length)
|
* function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -369,10 +390,10 @@ void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for name changes.
|
/* Set the callback for name changes.
|
||||||
* function(int friendnumber, uint8_t *newname, uint16_t length)
|
* function(int32_t friendnumber, uint8_t *newname, uint16_t length)
|
||||||
* You are not responsible for freeing newname.
|
* You are not responsible for freeing newname.
|
||||||
*/
|
*/
|
||||||
void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -380,10 +401,10 @@ void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for status message changes.
|
/* Set the callback for status message changes.
|
||||||
* function(int friendnumber, uint8_t *newstatus, uint16_t length)
|
* function(int32_t friendnumber, uint8_t *newstatus, uint16_t length)
|
||||||
* You are not responsible for freeing newstatus.
|
* You are not responsible for freeing newstatus.
|
||||||
*/
|
*/
|
||||||
void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -391,25 +412,26 @@ void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for status type changes.
|
/* Set the callback for status type changes.
|
||||||
* function(int friendnumber, USERSTATUS kind)
|
* function(int32_t friendnumber, USERSTATUS kind)
|
||||||
*/
|
*/
|
||||||
void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int, TOX_USERSTATUS, void *), void *userdata)
|
void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_userstatus(m, function, userdata);
|
m_callback_userstatus(m, function, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for typing changes.
|
/* Set the callback for typing changes.
|
||||||
* function (int friendnumber, int is_typing)
|
* function (int32_t friendnumber, int is_typing)
|
||||||
*/
|
*/
|
||||||
void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int, int, void *), void *userdata)
|
void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int32_t, int, void *), void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_typingchange(m, function, userdata);
|
m_callback_typingchange(m, function, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for read receipts.
|
/* Set the callback for read receipts.
|
||||||
* function(int friendnumber, uint32_t receipt)
|
* function(int32_t friendnumber, uint32_t receipt)
|
||||||
*
|
*
|
||||||
* If you are keeping a record of returns from m_sendmessage;
|
* If you are keeping a record of returns from m_sendmessage;
|
||||||
* receipt might be one of those values, meaning the message
|
* receipt might be one of those values, meaning the message
|
||||||
@ -417,14 +439,14 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Messenger *tox, int,
|
|||||||
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
||||||
* in that case, you should discard it.
|
* in that case, you should discard it.
|
||||||
*/
|
*/
|
||||||
void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, uint32_t, void *), void *userdata)
|
void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int32_t, uint32_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_read_receipt(m, function, userdata);
|
m_callback_read_receipt(m, function, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the callback for connection status changes.
|
/* Set the callback for connection status changes.
|
||||||
* function(int friendnumber, uint8_t status)
|
* function(int32_t friendnumber, uint8_t status)
|
||||||
*
|
*
|
||||||
* Status:
|
* Status:
|
||||||
* 0 -- friend went offline after being previously online
|
* 0 -- friend went offline after being previously online
|
||||||
@ -434,7 +456,8 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, u
|
|||||||
* being previously online" part. It's assumed that when adding friends,
|
* being previously online" part. It's assumed that when adding friends,
|
||||||
* their connection status is offline.
|
* their connection status is offline.
|
||||||
*/
|
*/
|
||||||
void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, void *), void *userdata)
|
void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *),
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_connectionstatus(m, function, userdata);
|
m_callback_connectionstatus(m, function, userdata);
|
||||||
@ -444,9 +467,9 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i
|
|||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata)
|
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, void *), void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
m_callback_group_invite(m, function, userdata);
|
m_callback_group_invite(m, function, userdata);
|
||||||
@ -521,7 +544,7 @@ int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name)
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber)
|
int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return invite_friend(m, friendnumber, groupnumber);
|
return invite_friend(m, friendnumber, groupnumber);
|
||||||
@ -531,7 +554,7 @@ int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber)
|
|||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key)
|
int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return join_groupchat(m, friendnumber, friend_group_public_key);
|
return join_groupchat(m, friendnumber, friend_group_public_key);
|
||||||
@ -606,9 +629,9 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size)
|
|||||||
|
|
||||||
/* Set the callback for file send requests.
|
/* Set the callback for file send requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint64_t, uint8_t *,
|
void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t, uint8_t *,
|
||||||
uint16_t,
|
uint16_t,
|
||||||
void *), void *userdata)
|
void *), void *userdata)
|
||||||
{
|
{
|
||||||
@ -617,10 +640,10 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, i
|
|||||||
}
|
}
|
||||||
/* Set the callback for file control requests.
|
/* Set the callback for file control requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t, uint8_t, uint8_t *,
|
void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
|
||||||
uint16_t, void *), void *userdata)
|
uint16_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -628,10 +651,10 @@ void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, u
|
|||||||
}
|
}
|
||||||
/* Set the callback for file data.
|
/* Set the callback for file data.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t *, uint16_t length,
|
void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t *, uint16_t length,
|
||||||
void *),
|
void *),
|
||||||
void *userdata)
|
void *userdata)
|
||||||
|
|
||||||
@ -644,7 +667,7 @@ void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint
|
|||||||
* return file number on success
|
* return file number on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
|
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return new_filesender(m, friendnumber, filesize, filename, filename_length);
|
return new_filesender(m, friendnumber, filesize, filename, filename_length);
|
||||||
@ -655,7 +678,7 @@ int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
||||||
uint8_t *data, uint16_t length)
|
uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
@ -666,7 +689,7 @@ int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
|
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return file_data(m, friendnumber, filenumber, data, length);
|
return file_data(m, friendnumber, filenumber, data, length);
|
||||||
@ -677,7 +700,7 @@ int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *
|
|||||||
* return size on success
|
* return size on success
|
||||||
* return -1 on failure (currently will never return -1)
|
* return -1 on failure (currently will never return -1)
|
||||||
*/
|
*/
|
||||||
int tox_file_data_size(Tox *tox, int friendnumber)
|
int tox_file_data_size(Tox *tox, int32_t friendnumber)
|
||||||
{
|
{
|
||||||
return MAX_DATA_SIZE - crypto_box_MACBYTES - 3;
|
return MAX_DATA_SIZE - crypto_box_MACBYTES - 3;
|
||||||
}
|
}
|
||||||
@ -689,7 +712,7 @@ int tox_file_data_size(Tox *tox, int friendnumber)
|
|||||||
* return number of bytes remaining to be sent/received on success
|
* return number of bytes remaining to be sent/received on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
uint64_t tox_file_data_remaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive)
|
uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return file_dataremaining(m, friendnumber, filenumber, send_receive);
|
return file_dataremaining(m, friendnumber, filenumber, send_receive);
|
||||||
@ -753,22 +776,27 @@ void tox_do(Tox *tox)
|
|||||||
/*
|
/*
|
||||||
* functions to avoid excessive polling
|
* functions to avoid excessive polling
|
||||||
*/
|
*/
|
||||||
int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr)
|
|
||||||
|
size_t tox_wait_data_size()
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
return wait_data_size();
|
||||||
return wait_prepare_messenger(m, data, lenptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds)
|
int tox_wait_prepare(Tox *tox, uint8_t *data)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return wait_execute_messenger(m, data, len, milliseconds);
|
return wait_prepare_messenger(m, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len)
|
int tox_wait_execute(uint8_t *data, long seconds, long microseconds)
|
||||||
|
{
|
||||||
|
return wait_execute_messenger(data, seconds, microseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
int tox_wait_cleanup(Tox *tox, uint8_t *data)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
wait_cleanup_messenger(m, data, len);
|
return wait_cleanup_messenger(m, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SAVING AND LOADING FUNCTIONS: */
|
/* SAVING AND LOADING FUNCTIONS: */
|
||||||
|
261
toxcore/tox.h
261
toxcore/tox.h
@ -36,8 +36,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */
|
|
||||||
typedef short sa_family_t;
|
|
||||||
|
|
||||||
#ifndef true
|
#ifndef true
|
||||||
#define true 1
|
#define true 1
|
||||||
@ -58,7 +56,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TOX_MAX_NAME_LENGTH 128
|
#define TOX_MAX_NAME_LENGTH 128
|
||||||
#define TOX_MAX_STATUSMESSAGE_LENGTH 128
|
#define TOX_MAX_STATUSMESSAGE_LENGTH 1007
|
||||||
#define TOX_CLIENT_ID_SIZE 32
|
#define TOX_CLIENT_ID_SIZE 32
|
||||||
|
|
||||||
#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
|
#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
|
||||||
@ -67,37 +65,8 @@ extern "C" {
|
|||||||
#define TOX_PORTRANGE_TO 33545
|
#define TOX_PORTRANGE_TO 33545
|
||||||
#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
|
#define TOX_PORT_DEFAULT TOX_PORTRANGE_FROM
|
||||||
|
|
||||||
typedef union {
|
|
||||||
uint8_t c[4];
|
|
||||||
uint16_t s[2];
|
|
||||||
uint32_t i;
|
|
||||||
} tox_IP4;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
uint8_t uint8[16];
|
|
||||||
uint16_t uint16[8];
|
|
||||||
uint32_t uint32[4];
|
|
||||||
struct in6_addr in6_addr;
|
|
||||||
} tox_IP6;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
sa_family_t family;
|
|
||||||
union {
|
|
||||||
tox_IP4 ip4;
|
|
||||||
tox_IP6 ip6;
|
|
||||||
};
|
|
||||||
} tox_IP;
|
|
||||||
|
|
||||||
/* will replace IP_Port as soon as the complete infrastructure is in place
|
|
||||||
* removed the unused union and padding also */
|
|
||||||
typedef struct {
|
|
||||||
tox_IP ip;
|
|
||||||
uint16_t port;
|
|
||||||
} tox_IP_Port;
|
|
||||||
|
|
||||||
#define TOX_ENABLE_IPV6_DEFAULT 1
|
#define TOX_ENABLE_IPV6_DEFAULT 1
|
||||||
|
|
||||||
|
|
||||||
/* Errors for m_addfriend
|
/* Errors for m_addfriend
|
||||||
* FAERR - Friend Add Error
|
* FAERR - Friend Add Error
|
||||||
*/
|
*/
|
||||||
@ -128,11 +97,11 @@ TOX_USERSTATUS;
|
|||||||
typedef struct Tox Tox;
|
typedef struct Tox Tox;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* NOTE: Strings in Tox are all UTF-8, also the last byte in all strings must be NULL (0).
|
/* NOTE: Strings in Tox are all UTF-8, (This means that there is no terminating NULL character.)
|
||||||
*
|
*
|
||||||
* The length when passing those strings to the core includes that NULL character.
|
* The exact buffer you send will be received at the other end without modification.
|
||||||
*
|
*
|
||||||
* If you send non NULL terminated strings Tox will force NULL terminates them when it receives them.
|
* Do not treat Tox strings as C strings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* return TOX_FRIEND_ADDRESS_SIZE byte address to give to others.
|
/* return TOX_FRIEND_ADDRESS_SIZE byte address to give to others.
|
||||||
@ -156,28 +125,32 @@ void tox_get_address(Tox *tox, uint8_t *address);
|
|||||||
* (the nospam for that friend was set to the new one).
|
* (the nospam for that friend was set to the new one).
|
||||||
* return TOX_FAERR_NOMEM if increasing the friend list size fails.
|
* return TOX_FAERR_NOMEM if increasing the friend list size fails.
|
||||||
*/
|
*/
|
||||||
int tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length);
|
int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
|
|
||||||
/* Add a friend without sending a friendrequest.
|
/* Add a friend without sending a friendrequest.
|
||||||
* return the friend number if success.
|
* return the friend number if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_add_friend_norequest(Tox *tox, uint8_t *client_id);
|
int32_t tox_add_friend_norequest(Tox *tox, uint8_t *client_id);
|
||||||
|
|
||||||
/* return the friend id associated to that client id.
|
/* return the friend number associated to that client id.
|
||||||
return -1 if no such friend */
|
return -1 if no such friend */
|
||||||
int tox_get_friend_id(Tox *tox, uint8_t *client_id);
|
int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id);
|
||||||
|
|
||||||
/* Copies the public key associated to that friend id into client_id buffer.
|
/* Copies the public key associated to that friend id into client_id buffer.
|
||||||
* Make sure that client_id is of size CLIENT_ID_SIZE.
|
* Make sure that client_id is of size CLIENT_ID_SIZE.
|
||||||
* return 0 if success.
|
* return 0 if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_client_id(Tox *tox, int friend_id, uint8_t *client_id);
|
int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id);
|
||||||
|
|
||||||
/* Remove a friend. */
|
/* Remove a friend.
|
||||||
int tox_del_friend(Tox *tox, int friendnumber);
|
*
|
||||||
|
* return 0 if success.
|
||||||
|
* return -1 if failure.
|
||||||
|
*/
|
||||||
|
int tox_del_friend(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Checks friend's connecting status.
|
/* Checks friend's connecting status.
|
||||||
*
|
*
|
||||||
@ -185,14 +158,14 @@ int tox_del_friend(Tox *tox, int friendnumber);
|
|||||||
* return 0 if friend is not connected to us (Offline).
|
* return 0 if friend is not connected to us (Offline).
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_friend_connection_status(Tox *tox, int friendnumber);
|
int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Checks if there exists a friend with given friendnumber.
|
/* Checks if there exists a friend with given friendnumber.
|
||||||
*
|
*
|
||||||
* return 1 if friend exists.
|
* return 1 if friend exists.
|
||||||
* return 0 if friend doesn't exist.
|
* return 0 if friend doesn't exist.
|
||||||
*/
|
*/
|
||||||
int tox_friend_exists(Tox *tox, int friendnumber);
|
int tox_friend_exists(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Send a text chat message to an online friend.
|
/* Send a text chat message to an online friend.
|
||||||
*
|
*
|
||||||
@ -204,8 +177,8 @@ int tox_friend_exists(Tox *tox, int friendnumber);
|
|||||||
* m_sendmessage_withid will send a message with the id of your choosing,
|
* m_sendmessage_withid will send a message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendmessage.
|
* however we can generate an id for you by calling plain m_sendmessage.
|
||||||
*/
|
*/
|
||||||
uint32_t tox_send_message(Tox *tox, int friendnumber, uint8_t *message, uint32_t length);
|
uint32_t tox_send_message(Tox *tox, int32_t friendnumber, uint8_t *message, uint32_t length);
|
||||||
uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
|
uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length);
|
||||||
|
|
||||||
/* Send an action to an online friend.
|
/* Send an action to an online friend.
|
||||||
*
|
*
|
||||||
@ -217,8 +190,8 @@ uint32_t tox_send_message_withid(Tox *tox, int friendnumber, uint32_t theid, uin
|
|||||||
* m_sendaction_withid will send an action message with the id of your choosing,
|
* m_sendaction_withid will send an action message with the id of your choosing,
|
||||||
* however we can generate an id for you by calling plain m_sendaction.
|
* however we can generate an id for you by calling plain m_sendaction.
|
||||||
*/
|
*/
|
||||||
uint32_t tox_send_action(Tox *tox, int friendnumber, uint8_t *action, uint32_t length);
|
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length);
|
||||||
uint32_t tox_send_action_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
|
||||||
|
|
||||||
/* Set our nickname.
|
/* Set our nickname.
|
||||||
* name must be a string of maximum MAX_NAME_LENGTH length.
|
* name must be a string of maximum MAX_NAME_LENGTH length.
|
||||||
@ -233,34 +206,42 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length);
|
|||||||
/*
|
/*
|
||||||
* Get your nickname.
|
* Get your nickname.
|
||||||
* m - The messanger context to use.
|
* m - The messanger context to use.
|
||||||
* name - Pointer to a string for the name.
|
* name - needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
||||||
* nlen - The length of the string buffer.
|
|
||||||
*
|
*
|
||||||
* return length of name.
|
* return length of name.
|
||||||
* return 0 on error.
|
* return 0 on error.
|
||||||
*/
|
*/
|
||||||
uint16_t tox_get_self_name(Tox *tox, uint8_t *name, uint16_t nlen);
|
uint16_t tox_get_self_name(Tox *tox, uint8_t *name);
|
||||||
|
|
||||||
/* Get name of friendnumber and put it in name.
|
/* Get name of friendnumber and put it in name.
|
||||||
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
||||||
*
|
*
|
||||||
* return length of name (with the NULL terminator) if success.
|
* return length of name if success.
|
||||||
* return -1 if failure.
|
* return -1 if failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_name(Tox *tox, int friendnumber, uint8_t *name);
|
int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name);
|
||||||
|
|
||||||
|
/* returns the length of name on success.
|
||||||
|
* returns -1 on failure.
|
||||||
|
*/
|
||||||
|
int tox_get_name_size(Tox *tox, int32_t friendnumber);
|
||||||
|
int tox_get_self_name_size(Tox *tox);
|
||||||
|
|
||||||
/* Set our user status.
|
/* Set our user status.
|
||||||
|
*
|
||||||
|
* userstatus must be one of TOX_USERSTATUS values.
|
||||||
*
|
*
|
||||||
* returns 0 on success.
|
* returns 0 on success.
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length);
|
int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length);
|
||||||
int tox_set_user_status(Tox *tox, TOX_USERSTATUS status);
|
int tox_set_user_status(Tox *tox, uint8_t userstatus);
|
||||||
|
|
||||||
/* return the length of friendnumber's status message, including null.
|
/* returns the length of status message on success.
|
||||||
* Pass it into malloc
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_status_message_size(Tox *tox, int friendnumber);
|
int tox_get_status_message_size(Tox *tox, int32_t friendnumber);
|
||||||
|
int tox_get_self_status_message_size(Tox *tox);
|
||||||
|
|
||||||
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
||||||
* Get the size you need to allocate from m_get_statusmessage_size.
|
* Get the size you need to allocate from m_get_statusmessage_size.
|
||||||
@ -269,22 +250,22 @@ int tox_get_status_message_size(Tox *tox, int friendnumber);
|
|||||||
* returns the length of the copied data on success
|
* returns the length of the copied data on success
|
||||||
* retruns -1 on failure.
|
* retruns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_get_status_message(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen);
|
int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
|
||||||
int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen);
|
int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen);
|
||||||
|
|
||||||
/* return one of USERSTATUS values.
|
/* return one of TOX_USERSTATUS values.
|
||||||
* Values unknown to your application should be represented as USERSTATUS_NONE.
|
* Values unknown to your application should be represented as TOX_USERSTATUS_NONE.
|
||||||
* As above, the self variant will return our own USERSTATUS.
|
* As above, the self variant will return our own TOX_USERSTATUS.
|
||||||
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
|
* If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID.
|
||||||
*/
|
*/
|
||||||
TOX_USERSTATUS tox_get_user_status(Tox *tox, int friendnumber);
|
uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber);
|
||||||
TOX_USERSTATUS tox_get_self_user_status(Tox *tox);
|
uint8_t tox_get_self_user_status(Tox *tox);
|
||||||
|
|
||||||
|
|
||||||
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
||||||
* returns -1 on error.
|
* returns -1 on error.
|
||||||
*/
|
*/
|
||||||
uint64_t tox_get_last_online(Tox *tox, int friendnumber);
|
uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Set our typing status for a friend.
|
/* Set our typing status for a friend.
|
||||||
* You are responsible for turning it on or off.
|
* You are responsible for turning it on or off.
|
||||||
@ -292,19 +273,19 @@ uint64_t tox_get_last_online(Tox *tox, int friendnumber);
|
|||||||
* returns 0 on success.
|
* returns 0 on success.
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_set_user_is_typing(Tox *tox, int friendnumber, uint8_t is_typing);
|
int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing);
|
||||||
|
|
||||||
/* Get the typing status of a friend.
|
/* Get the typing status of a friend.
|
||||||
*
|
*
|
||||||
* returns 0 if friend is not typing.
|
* returns 0 if friend is not typing.
|
||||||
* returns 1 if friend is typing.
|
* returns 1 if friend is typing.
|
||||||
*/
|
*/
|
||||||
int tox_get_is_typing(Tox *tox, int friendnumber);
|
int tox_get_is_typing(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Sets whether we send read receipts for friendnumber.
|
/* Sets whether we send read receipts for friendnumber.
|
||||||
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
||||||
*/
|
*/
|
||||||
void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno);
|
void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno);
|
||||||
|
|
||||||
/* Return the number of friends in the instance m.
|
/* Return the number of friends in the instance m.
|
||||||
* You should use this to determine how much memory to allocate
|
* You should use this to determine how much memory to allocate
|
||||||
@ -319,50 +300,52 @@ uint32_t tox_get_num_online_friends(Tox *tox);
|
|||||||
* Otherwise, returns the number of elements copied.
|
* Otherwise, returns the number of elements copied.
|
||||||
* If the array was too small, the contents
|
* If the array was too small, the contents
|
||||||
* of out_list will be truncated to list_size. */
|
* of out_list will be truncated to list_size. */
|
||||||
uint32_t tox_get_friendlist(Tox *tox, int *out_list, uint32_t list_size);
|
uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size);
|
||||||
|
|
||||||
/* Set the function that will be executed when a friend request is received.
|
/* Set the function that will be executed when a friend request is received.
|
||||||
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
* Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_request(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata);
|
void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, uint8_t *, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata);
|
||||||
|
|
||||||
/* Set the function that will be executed when a message from a friend is received.
|
/* Set the function that will be executed when a message from a friend is received.
|
||||||
* Function format is: function(int friendnumber, uint8_t * message, uint32_t length)
|
* Function format is: function(Tox *tox, int friendnumber, uint8_t * message, uint32_t length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the function that will be executed when an action from a friend is received.
|
/* Set the function that will be executed when an action from a friend is received.
|
||||||
* Function format is: function(int friendnumber, uint8_t * action, uint32_t length)
|
* Function format is: function(Tox *tox, int32_t friendnumber, uint8_t * action, uint32_t length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *), void *userdata);
|
void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for name changes.
|
/* Set the callback for name changes.
|
||||||
* function(int friendnumber, uint8_t *newname, uint16_t length)
|
* function(Tox *tox, int32_t friendnumber, uint8_t *newname, uint16_t length, void *userdata)
|
||||||
* You are not responsible for freeing newname
|
* You are not responsible for freeing newname
|
||||||
*/
|
*/
|
||||||
void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for status message changes.
|
/* Set the callback for status message changes.
|
||||||
* function(int friendnumber, uint8_t *newstatus, uint16_t length)
|
* function(Tox *tox, int32_t friendnumber, uint8_t *newstatus, uint16_t length, void *userdata)
|
||||||
* You are not responsible for freeing newstatus.
|
* You are not responsible for freeing newstatus.
|
||||||
*/
|
*/
|
||||||
void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, uint16_t, void *),
|
void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Set the callback for status type changes.
|
/* Set the callback for status type changes.
|
||||||
* function(int friendnumber, USERSTATUS kind)
|
* function(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata);
|
void tox_callback_user_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for typing changes.
|
/* Set the callback for typing changes.
|
||||||
* function (int friendnumber, int is_typing)
|
* function (Tox *tox, int32_t friendnumber, int is_typing, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int, int, void *), void *userdata);
|
void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int32_t, int, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for read receipts.
|
/* Set the callback for read receipts.
|
||||||
* function(int friendnumber, uint32_t receipt)
|
* function(Tox *tox, int32_t friendnumber, uint32_t receipt, void *userdata)
|
||||||
*
|
*
|
||||||
* If you are keeping a record of returns from m_sendmessage;
|
* If you are keeping a record of returns from m_sendmessage;
|
||||||
* receipt might be one of those values, meaning the message
|
* receipt might be one of those values, meaning the message
|
||||||
@ -370,10 +353,10 @@ void tox_callback_typing_change(Tox *tox, void (*function)(Tox *tox, int, int, v
|
|||||||
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
||||||
* In that case, you should discard it.
|
* In that case, you should discard it.
|
||||||
*/
|
*/
|
||||||
void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_t, void *), void *userdata);
|
void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int32_t, uint32_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for connection status changes.
|
/* Set the callback for connection status changes.
|
||||||
* function(int friendnumber, uint8_t status)
|
* function(Tox *tox, int32_t friendnumber, uint8_t status, void *userdata)
|
||||||
*
|
*
|
||||||
* Status:
|
* Status:
|
||||||
* 0 -- friend went offline after being previously online
|
* 0 -- friend went offline after being previously online
|
||||||
@ -383,7 +366,7 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int, uint32_
|
|||||||
* being previously online" part. it's assumed that when adding friends,
|
* being previously online" part. it's assumed that when adding friends,
|
||||||
* their connection status is offline.
|
* their connection status is offline.
|
||||||
*/
|
*/
|
||||||
void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int, uint8_t, void *), void *userdata);
|
void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata);
|
||||||
|
|
||||||
/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
|
/**********GROUP CHAT FUNCTIONS: WARNING WILL BREAK A LOT************/
|
||||||
|
|
||||||
@ -391,7 +374,7 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int, ui
|
|||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
|
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int, uint8_t *, void *), void *userdata);
|
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for group messages.
|
/* Set the callback for group messages.
|
||||||
*
|
*
|
||||||
@ -447,14 +430,14 @@ int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name)
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber);
|
int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber);
|
||||||
|
|
||||||
/* Join a group (you need to have been invited first.)
|
/* Join a group (you need to have been invited first.)
|
||||||
*
|
*
|
||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
|
int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key);
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
* return 0 on success
|
* return 0 on success
|
||||||
@ -533,9 +516,9 @@ enum {
|
|||||||
};
|
};
|
||||||
/* Set the callback for file send requests.
|
/* Set the callback for file send requests.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint64_t, uint8_t *, uint16_t,
|
void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t,
|
||||||
void *), void *userdata);
|
void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for file control requests.
|
/* Set the callback for file control requests.
|
||||||
@ -543,18 +526,18 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int, uint
|
|||||||
* receive_send is 1 if the message is for a slot on which we are currently sending a file and 0 if the message
|
* receive_send is 1 if the message is for a slot on which we are currently sending a file and 0 if the message
|
||||||
* is for a slot on which we are receiving the file
|
* is for a slot on which we are receiving the file
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t, uint8_t, uint8_t *,
|
void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
|
||||||
uint16_t, void *), void *userdata);
|
uint16_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for file data.
|
/* Set the callback for file data.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t *, uint16_t length, void *),
|
void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint8_t *, uint16_t length, void *),
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
|
|
||||||
@ -563,7 +546,7 @@ void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int, uint8_t, uin
|
|||||||
* return file number on success
|
* return file number on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
|
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
|
||||||
|
|
||||||
/* Send a file control request.
|
/* Send a file control request.
|
||||||
*
|
*
|
||||||
@ -573,7 +556,7 @@ int tox_new_file_sender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
||||||
uint8_t *data, uint16_t length);
|
uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/* Send file data.
|
/* Send file data.
|
||||||
@ -581,14 +564,14 @@ int tox_file_send_control(Tox *tox, int friendnumber, uint8_t send_receive, uint
|
|||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_file_send_data(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
|
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/* Returns the recommended/maximum size of the filedata you send with tox_file_send_data()
|
/* Returns the recommended/maximum size of the filedata you send with tox_file_send_data()
|
||||||
*
|
*
|
||||||
* return size on success
|
* return size on success
|
||||||
* return -1 on failure (currently will never return -1)
|
* return -1 on failure (currently will never return -1)
|
||||||
*/
|
*/
|
||||||
int tox_file_data_size(Tox *tox, int friendnumber);
|
int tox_file_data_size(Tox *tox, int32_t friendnumber);
|
||||||
|
|
||||||
/* Give the number of bytes left to be sent/received.
|
/* Give the number of bytes left to be sent/received.
|
||||||
*
|
*
|
||||||
@ -597,19 +580,51 @@ int tox_file_data_size(Tox *tox, int friendnumber);
|
|||||||
* return number of bytes remaining to be sent/received on success
|
* return number of bytes remaining to be sent/received on success
|
||||||
* return 0 on failure
|
* return 0 on failure
|
||||||
*/
|
*/
|
||||||
uint64_t tox_file_data_remaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive);
|
uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
|
||||||
|
|
||||||
/***************END OF FILE SENDING FUNCTIONS******************/
|
/***************END OF FILE SENDING FUNCTIONS******************/
|
||||||
|
|
||||||
|
/* WARNING: DEPRECATED, DO NOT USE. */
|
||||||
|
typedef union {
|
||||||
|
uint8_t c[4];
|
||||||
|
uint16_t s[2];
|
||||||
|
uint32_t i;
|
||||||
|
} tox_IP4;
|
||||||
|
|
||||||
/*
|
typedef union {
|
||||||
* Use these two functions to bootstrap the client.
|
uint8_t uint8[16];
|
||||||
*/
|
uint16_t uint16[8];
|
||||||
|
uint32_t uint32[4];
|
||||||
|
struct in6_addr in6_addr;
|
||||||
|
} tox_IP6;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t family;
|
||||||
|
/* Not used for anything right now. */
|
||||||
|
uint8_t padding[3];
|
||||||
|
union {
|
||||||
|
tox_IP4 ip4;
|
||||||
|
tox_IP6 ip6;
|
||||||
|
};
|
||||||
|
} tox_IP;
|
||||||
|
|
||||||
|
/* will replace IP_Port as soon as the complete infrastructure is in place
|
||||||
|
* removed the unused union and padding also */
|
||||||
|
typedef struct {
|
||||||
|
tox_IP ip;
|
||||||
|
uint16_t port;
|
||||||
|
} tox_IP_Port;
|
||||||
|
/* WARNING: DEPRECATED, DO NOT USE. */
|
||||||
/* Sends a "get nodes" request to the given node with ip, port and public_key
|
/* Sends a "get nodes" request to the given node with ip, port and public_key
|
||||||
* to setup connections
|
* to setup connections
|
||||||
*/
|
*/
|
||||||
void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key);
|
void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port ip_port, uint8_t *public_key);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this function to bootstrap the client.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Resolves address into an IP address. If successful, sends a "get nodes"
|
/* Resolves address into an IP address. If successful, sends a "get nodes"
|
||||||
* request to the given node with ip, port (in network byte order, HINT: use htons())
|
* request to the given node with ip, port (in network byte order, HINT: use htons())
|
||||||
* and public_key to setup connections
|
* and public_key to setup connections
|
||||||
@ -653,37 +668,43 @@ void tox_kill(Tox *tox);
|
|||||||
void tox_do(Tox *tox);
|
void tox_do(Tox *tox);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tox_wait_prepare(): function should be called under lock
|
* tox_wait_data_size():
|
||||||
|
*
|
||||||
|
* returns a size of data buffer to allocate. the size is constant.
|
||||||
|
*
|
||||||
|
* tox_wait_prepare(): function should be called under lock every time we want to call tox_wait_execute()
|
||||||
* Prepares the data required to call tox_wait_execute() asynchronously
|
* Prepares the data required to call tox_wait_execute() asynchronously
|
||||||
*
|
*
|
||||||
* data[] is reserved and kept by the caller
|
* data[] should be of at least tox_wait_data_size() size and it's reserved and kept by the caller
|
||||||
* *lenptr is in/out: in = reserved data[], out = required data[]
|
* Use that data[] to call tox_wait_execute()
|
||||||
*
|
*
|
||||||
* returns 1 on success
|
* returns 1 on success
|
||||||
* returns 0 if *lenptr is insufficient
|
* returns 0 if data was NULL
|
||||||
* returns -1 if lenptr is NULL
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* tox_wait_execute(): function can be called asynchronously
|
* tox_wait_execute(): function can be called asynchronously
|
||||||
* Waits for something to happen on the socket for up to milliseconds milliseconds.
|
* Waits for something to happen on the socket for up to seconds seconds and mircoseconds microseconds.
|
||||||
* *** Function MUSTN'T poll. ***
|
* mircoseconds should be between 0 and 999999.
|
||||||
* The function mustn't modify anything at all, so it can be called completely
|
* If you set either or both seconds and microseconds to negatives, it will block indefinetly until there
|
||||||
* asynchronously without any worry.
|
* is an activity.
|
||||||
*
|
*
|
||||||
* returns 1 if there is socket activity (i.e. tox_do() should be called)
|
* returns 2 if there is socket activity (i.e. tox_do() should be called)
|
||||||
* returns 0 if the timeout was reached
|
* returns 1 if the timeout was reached (tox_do() should be called anyway. it's advised to call it at least
|
||||||
* returns -1 if data was NULL or len too short
|
* once per second)
|
||||||
|
* returns 0 if data was NULL
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* tox_wait_cleanup(): function should be called under lock
|
* tox_wait_cleanup(): function should be called under lock, every time tox_wait_execute() finishes
|
||||||
* Stores results from tox_wait_execute().
|
* Stores results from tox_wait_execute().
|
||||||
*
|
*
|
||||||
* data[]/len shall be the exact same as given to tox_wait_execute()
|
* returns 1 on success
|
||||||
|
* returns 0 if data was NULL
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr);
|
size_t tox_wait_data_size();
|
||||||
int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds);
|
int tox_wait_prepare(Tox *tox, uint8_t *data);
|
||||||
void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len);
|
int tox_wait_execute(uint8_t *data, long seconds, long microseconds);
|
||||||
|
int tox_wait_cleanup(Tox *tox, uint8_t *data);
|
||||||
|
|
||||||
|
|
||||||
/* SAVING AND LOADING FUNCTIONS: */
|
/* SAVING AND LOADING FUNCTIONS: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user