This commit is contained in:
irungentoo 2014-07-02 15:41:59 -04:00
commit 6d4fdb3597
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
20 changed files with 518 additions and 491 deletions

View File

@ -56,7 +56,7 @@
#endif
void print_message(Messenger *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
void print_message(Messenger *m, int friendnumber, const uint8_t *string, uint16_t length, void *userdata)
{
printf("Message with length %u received from %u: %s \n", length, friendnumber, string);
m_sendmessage(m, friendnumber, (uint8_t *)"Test1", 6);

View File

@ -130,7 +130,7 @@ int not_sending()
static char path[1024];
void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename,
uint16_t filename_length, void *userdata)
{
char fullpath[1024];
@ -169,7 +169,7 @@ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t
}
void file_print_control(Tox *m, int friendnumber, uint8_t recieve_send, uint8_t filenumber, uint8_t control_type,
uint8_t *data,
const uint8_t *data,
uint16_t length, void *userdata)
{
if (recieve_send == 1 && (control_type == TOX_FILECONTROL_KILL || control_type == TOX_FILECONTROL_FINISHED)) {
@ -185,7 +185,7 @@ void file_print_control(Tox *m, int friendnumber, uint8_t recieve_send, uint8_t
}
}
void write_file(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length, void *userdata)
{
if (file_recv[filenumber].file != 0)
if (fwrite(data, length, 1, file_recv[filenumber].file) != 1)

View File

@ -2212,7 +2212,7 @@ static int random_node_fromlist(Client_data *list, uint16_t list_size, Node_form
*
* TODO: remove the LAN stuff from this.
*/
uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num)
uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num)
{
if (max_num == 0)
return 0;

View File

@ -306,7 +306,7 @@ uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
*
* NOTE:this is used to pick nodes for paths.
*/
uint16_t random_nodes_path(DHT *dht, Node_format *nodes, uint16_t max_num);
uint16_t random_nodes_path(const DHT *dht, Node_format *nodes, uint16_t max_num);
/* Run this function at least a couple times per second (It's the main loop). */
void do_DHT(DHT *dht);

View File

@ -40,10 +40,11 @@
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status);
static int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length);
// friend_not_valid determines if the friendnumber passed is valid in the Messenger object
static uint8_t friend_not_valid(Messenger *m, int32_t friendnumber)
static uint8_t friend_not_valid(const Messenger *m, int32_t friendnumber)
{
return (unsigned int)friendnumber >= m->numfriends;
}
@ -109,7 +110,7 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *client_id)
* return 0 if success.
* return -1 if failure.
*/
int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id)
int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -125,7 +126,7 @@ int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id)
*
* return a uint16_t that represents the checksum of address of length len.
*/
static uint16_t address_checksum(uint8_t *address, uint32_t len)
static uint16_t address_checksum(const uint8_t *address, uint32_t len)
{
uint8_t checksum[2] = {0};
uint16_t check;
@ -142,7 +143,7 @@ static uint16_t address_checksum(uint8_t *address, uint32_t len)
*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
*/
void getaddress(Messenger *m, uint8_t *address)
void getaddress(const Messenger *m, uint8_t *address)
{
id_copy(address, m->net_crypto->self_public_key);
uint32_t nospam = get_nospam(&(m->fr));
@ -152,7 +153,7 @@ void getaddress(Messenger *m, uint8_t *address)
}
/* callback for recv TCP relay nodes. */
static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_port, uint8_t *public_key)
static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key)
{
Messenger *m = object;
@ -183,7 +184,7 @@ static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_por
* (the nospam for that friend was set to the new one).
* return FAERR_NOMEM if increasing the friend list size fails.
*/
int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length)
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length)
{
if (length > MAX_FRIEND_REQUEST_DATA_SIZE)
return FAERR_TOOLONG;
@ -346,7 +347,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
return 0;
}
int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber)
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -354,7 +355,7 @@ int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].status == FRIEND_ONLINE;
}
int m_friend_exists(Messenger *m, int32_t friendnumber)
int m_friend_exists(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return 0;
@ -402,7 +403,7 @@ uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid
* return the message id if packet was successfully put into the send queue.
* return 0 if it was not.
*/
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint32_t length)
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, const uint8_t *action, uint32_t length)
{
if (friend_not_valid(m, friendnumber))
return 0;
@ -419,7 +420,8 @@ uint32_t m_sendaction(Messenger *m, int32_t friendnumber, uint8_t *action, uint3
return 0;
}
uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *action,
uint32_t length)
{
if (length >= (MAX_CRYPTO_DATA_SIZE - sizeof(theid)))
return 0;
@ -434,7 +436,7 @@ uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid,
/* Send a name packet to friendnumber.
* length is the length with the NULL terminator.
*/
static int m_sendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length)
static int m_sendname(const Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
{
if (length > MAX_NAME_LENGTH || length == 0)
return 0;
@ -447,7 +449,7 @@ static int m_sendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_
* return 0 if success.
* return -1 if failure.
*/
int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length)
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -492,7 +494,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length)
*
* return the length of the name.
*/
uint16_t getself_name(Messenger *m, uint8_t *name)
uint16_t getself_name(const Messenger *m, uint8_t *name)
{
if (name == NULL) {
return 0;
@ -509,7 +511,7 @@ uint16_t getself_name(Messenger *m, uint8_t *name)
* return length of name if success.
* return -1 if failure.
*/
int getname(Messenger *m, int32_t friendnumber, uint8_t *name)
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -518,7 +520,7 @@ int getname(Messenger *m, int32_t friendnumber, uint8_t *name)
return m->friendlist[friendnumber].name_length;
}
int m_get_name_size(Messenger *m, int32_t friendnumber)
int m_get_name_size(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -526,7 +528,7 @@ int m_get_name_size(Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].name_length;
}
int m_get_self_name_size(Messenger *m)
int m_get_self_name_size(const Messenger *m)
{
return m->name_length;
}
@ -565,7 +567,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
/* return the size of friendnumber's user status.
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
*/
int m_get_statusmessage_size(Messenger *m, int32_t friendnumber)
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -576,7 +578,7 @@ int m_get_statusmessage_size(Messenger *m, int32_t friendnumber)
/* 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.
*/
int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -591,12 +593,12 @@ int m_copy_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *buf, uint3
/* return the size of friendnumber's user status.
* Guaranteed to be at most MAX_STATUSMESSAGE_LENGTH.
*/
int m_get_self_statusmessage_size(Messenger *m)
int m_get_self_statusmessage_size(const Messenger *m)
{
return m->statusmessage_length;
}
int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf, uint32_t maxlen)
{
int msglen = MIN(maxlen, m->statusmessage_length);
memcpy(buf, m->statusmessage, msglen);
@ -604,7 +606,7 @@ int m_copy_self_statusmessage(Messenger *m, uint8_t *buf, uint32_t maxlen)
return msglen;
}
uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber)
uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return USERSTATUS_INVALID;
@ -618,12 +620,12 @@ uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber)
return status;
}
uint8_t m_get_self_userstatus(Messenger *m)
uint8_t m_get_self_userstatus(const Messenger *m)
{
return m->userstatus;
}
uint64_t m_get_last_online(Messenger *m, int32_t friendnumber)
uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -647,7 +649,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
return 0;
}
uint8_t m_get_istyping(Messenger *m, int32_t friendnumber)
uint8_t m_get_istyping(const Messenger *m, int32_t friendnumber)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -655,23 +657,23 @@ uint8_t m_get_istyping(Messenger *m, int32_t friendnumber)
return m->friendlist[friendnumber].is_typing;
}
static int send_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
static int send_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length);
}
static int send_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
static int send_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &status, sizeof(status));
}
static int send_user_istyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
static int send_user_istyping(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
{
uint8_t typing = is_typing;
return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing));
}
static int send_ping(Messenger *m, int32_t friendnumber)
static int send_ping(const Messenger *m, int32_t friendnumber)
{
int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_ALIVE, 0, 0);
@ -681,7 +683,7 @@ static int send_ping(Messenger *m, int32_t friendnumber)
return ret;
}
static int send_relays(Messenger *m, int32_t friendnumber)
static int send_relays(const Messenger *m, int32_t friendnumber)
{
Node_format nodes[MAX_SHARED_RELAYS];
uint8_t data[1024];
@ -700,7 +702,7 @@ static int send_relays(Messenger *m, int32_t friendnumber)
static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t *status, uint16_t length)
static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, const uint8_t *status, uint16_t length)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -713,12 +715,12 @@ static int set_friend_statusmessage(Messenger *m, int32_t friendnumber, uint8_t
return 0;
}
static void set_friend_userstatus(Messenger *m, int32_t friendnumber, uint8_t status)
static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
{
m->friendlist[friendnumber].userstatus = status;
}
static void set_friend_typing(Messenger *m, int32_t friendnumber, uint8_t is_typing)
static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
{
m->friendlist[friendnumber].is_typing = is_typing;
}
@ -745,28 +747,28 @@ void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const
}
/* 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, int32_t, uint8_t *, uint16_t, void *),
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->friend_message = function;
m->friend_message_userdata = userdata;
}
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->friend_action = function;
m->friend_action_userdata = userdata;
}
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->friend_namechange = function;
m->friend_namechange_userdata = userdata;
}
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->friend_statusmessagechange = function;
@ -804,7 +806,7 @@ void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Mess
m->friend_connectionstatuschange_internal_userdata = userdata;
}
static void break_files(Messenger *m, int32_t friendnumber);
static void break_files(const Messenger *m, int32_t friendnumber);
static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, uint8_t status)
{
if (status == NOFRIEND)
@ -840,7 +842,8 @@ void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status)
m->friendlist[friendnumber].status = status;
}
int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length)
int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
uint32_t length)
{
if (friend_not_valid(m, friendnumber))
return 0;
@ -862,7 +865,7 @@ int write_cryptpacket_id(Messenger *m, int32_t friendnumber, uint8_t packet_id,
/* return 1 if the groupnumber is not valid.
* return 0 if the groupnumber is valid.
*/
static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
static uint8_t groupnumber_not_valid(const Messenger *m, int groupnumber)
{
if ((unsigned int)groupnumber >= m->numchats)
return 1;
@ -880,7 +883,7 @@ static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
/* returns valid ip port of connected friend on success
* returns zeroed out IP_Port on failure
*/
static IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber)
static IP_Port get_friend_ipport(const Messenger *m, int32_t friendnumber)
{
IP_Port zero;
memset(&zero, 0, sizeof(zero));
@ -904,7 +907,7 @@ static IP_Port get_friend_ipport(Messenger *m, int32_t friendnumber)
/* returns the group number of the chat with public key group_public_key.
* returns -1 on failure.
*/
static int group_num(Messenger *m, uint8_t *group_public_key)
static int group_num(const Messenger *m, const uint8_t *group_public_key)
{
uint32_t i;
@ -921,7 +924,8 @@ static int group_num(Messenger *m, uint8_t *group_public_key)
*
* Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
*/
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata)
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, void *),
void *userdata)
{
m->group_invite = function;
m->group_invite_userdata = userdata;
@ -931,7 +935,7 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->group_message = function;
@ -942,7 +946,7 @@ void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int,
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->group_action = function;
@ -961,7 +965,7 @@ void m_callback_group_namelistchange(Messenger *m, void (*function)(Messenger *m
m->group_namelistchange_userdata = userdata;
}
static int get_chat_num(Messenger *m, Group_Chat *chat)
static int get_chat_num(const Messenger *m, const Group_Chat *chat)
{
uint32_t i;
@ -1114,7 +1118,7 @@ int del_groupchat(Messenger *m, int groupnumber)
* return length of name if success
* return -1 if failure
*/
int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name)
int m_group_peername(const Messenger *m, int groupnumber, int peernumber, uint8_t *name)
{
if ((unsigned int)groupnumber >= m->numchats)
return -1;
@ -1141,7 +1145,7 @@ static void group_store_friendinvite(Messenger *m, int32_t friendnumber, int gro
/* return 1 if that friend was invited to the group
* return 0 if the friend was not or error.
*/
static uint8_t group_invited(Messenger *m, int32_t friendnumber, int groupnumber)
static uint8_t group_invited(const Messenger *m, int32_t friendnumber, int groupnumber)
{
uint32_t i;
@ -1189,7 +1193,7 @@ int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber)
* returns group number on success
* returns -1 on failure.
*/
int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key)
int join_groupchat(Messenger *m, int32_t friendnumber, const uint8_t *friend_group_public_key)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1222,7 +1226,7 @@ int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_pub
* return 0 on success
* return -1 on failure
*/
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length)
int group_message_send(const Messenger *m, int groupnumber, const uint8_t *message, uint32_t length)
{
if (groupnumber_not_valid(m, groupnumber))
return -1;
@ -1237,7 +1241,7 @@ int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t
* return 0 on success
* return -1 on failure
*/
int group_action_send(Messenger *m, int groupnumber, uint8_t *action, uint32_t length)
int group_action_send(const Messenger *m, int groupnumber, const uint8_t *action, uint32_t length)
{
if (groupnumber_not_valid(m, groupnumber))
return -1;
@ -1251,7 +1255,7 @@ int group_action_send(Messenger *m, int groupnumber, uint8_t *action, uint32_t l
/* Return the number of peers in the group chat on success.
* return -1 on failure
*/
int group_number_peers(Messenger *m, int groupnumber)
int group_number_peers(const Messenger *m, int groupnumber)
{
if (groupnumber_not_valid(m, groupnumber))
return -1;
@ -1269,7 +1273,8 @@ int group_number_peers(Messenger *m, int groupnumber)
*
* return -1 on failure.
*/
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length)
int group_names(const Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[],
uint16_t length)
{
if (groupnumber_not_valid(m, groupnumber))
return -1;
@ -1315,7 +1320,7 @@ static void do_allgroupchats(Messenger *m)
*
* 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, int32_t, uint8_t, uint64_t, uint8_t *,
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *,
uint16_t, void *), void *userdata)
{
m->file_sendrequest = function;
@ -1327,8 +1332,8 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int3
* 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, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
uint16_t, void *), void *userdata)
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t,
const uint8_t *, uint16_t, void *), void *userdata)
{
m->file_filecontrol = function;
m->file_filecontrol_userdata = userdata;
@ -1339,7 +1344,7 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t,
* 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, int32_t, uint8_t, uint8_t *, uint16_t length,
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t length,
void *), void *userdata)
{
m->file_filedata = function;
@ -1353,8 +1358,8 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, ui
* return 1 on success
* return 0 on failure
*/
int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
uint16_t filename_length)
int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
const uint8_t *filename, uint16_t filename_length)
{
if (friend_not_valid(m, friendnumber))
return 0;
@ -1376,7 +1381,8 @@ int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uin
* return file number on success
* return -1 on failure
*/
int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
int new_filesender(const Messenger *m, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
uint16_t filename_length)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1406,8 +1412,8 @@ int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_
* return 0 on success
* return -1 on failure
*/
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)
int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
const uint8_t *data, uint16_t length)
{
if (length > MAX_CRYPTO_DATA_SIZE - 3)
return -1;
@ -1494,7 +1500,7 @@ int file_control(Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8
* return 0 on success
* return -1 on failure
*/
int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length)
{
if (length > MAX_CRYPTO_DATA_SIZE - 1)
return -1;
@ -1529,7 +1535,7 @@ int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *d
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
{
if (friend_not_valid(m, friendnumber))
return 0;
@ -1552,7 +1558,7 @@ uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumb
/* Run this when the friend disconnects.
* Sets all current file transfers to broken.
*/
static void break_files(Messenger *m, int32_t friendnumber)
static void break_files(const Messenger *m, int32_t friendnumber)
{
uint32_t i;
@ -1565,7 +1571,7 @@ static void break_files(Messenger *m, int32_t friendnumber)
}
}
static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
static int handle_filecontrol(const Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
uint8_t message_id, uint8_t *data,
uint16_t length)
{
@ -1655,7 +1661,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
*
* Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
*/
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
m->msi_packet = function;
@ -1667,12 +1673,12 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t,
* return 1 on success
* return 0 on failure
*/
int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length)
int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
{
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MSI, data, length);
}
static int handle_custom_lossy_packet(void *object, int friend_num, uint8_t *packet, uint16_t length)
static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
{
Messenger *m = object;
@ -1687,7 +1693,7 @@ static int handle_custom_lossy_packet(void *object, int friend_num, uint8_t *pac
}
int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
int (*packet_handler_callback)(void *object, uint8_t *data, uint32_t len), void *object)
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1703,7 +1709,7 @@ int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint
return 0;
}
int send_custom_lossy_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length)
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1717,7 +1723,7 @@ int send_custom_lossy_packet(Messenger *m, int32_t friendnumber, uint8_t *data,
return send_lossy_cryptpacket(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id, data, length);
}
static int handle_custom_lossless_packet(void *object, int friend_num, uint8_t *packet, uint16_t length)
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
{
Messenger *m = object;
@ -1738,7 +1744,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, uint8_t *
}
int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
int (*packet_handler_callback)(void *object, uint8_t *data, uint32_t len), void *object)
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1755,7 +1761,7 @@ int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, u
return 0;
}
int send_custom_lossless_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length)
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -1772,7 +1778,7 @@ int send_custom_lossless_packet(Messenger *m, int32_t friendnumber, uint8_t *dat
/* Function to filter out some friend requests*/
static int friend_already_added(const uint8_t *client_id, void *data)
{
Messenger *m = data;
const Messenger *m = data;
if (getfriend_id(m, client_id) == -1)
return 0;
@ -2029,13 +2035,13 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
}
case PACKET_ID_MESSAGE: {
uint8_t *message_id = data;
const uint8_t *message_id = data;
uint8_t message_id_length = 4;
if (data_length <= message_id_length)
break;
uint8_t *message = data + message_id_length;
const uint8_t *message = data + message_id_length;
uint16_t message_length = data_length - message_id_length;
/* Make sure the NULL terminator is present. */
@ -2054,13 +2060,13 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
}
case PACKET_ID_ACTION: {
uint8_t *message_id = data;
const uint8_t *message_id = data;
uint8_t message_id_length = 4;
if (data_length <= message_id_length)
break;
uint8_t *action = data + message_id_length;
const uint8_t *action = data + message_id_length;
uint16_t action_length = data_length - message_id_length;
/* Make sure the NULL terminator is present. */
@ -2128,8 +2134,8 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
uint8_t filenumber = data[0];
uint64_t filesize;
net_to_host(data + 1, sizeof(filesize));
memcpy(&filesize, data + 1, sizeof(filesize));
net_to_host((uint8_t *) &filesize, sizeof(filesize));
m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED;
m->friendlist[i].file_receiving[filenumber].size = filesize;
m->friendlist[i].file_receiving[filenumber].transferred = 0;
@ -2216,7 +2222,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
return 0;
}
static int friend_new_connection(Messenger *m, int32_t friendnumber, uint8_t *real_public_key)
static int friend_new_connection(Messenger *m, int32_t friendnumber, const uint8_t *real_public_key)
{
if (friend_not_valid(m, friendnumber))
return -1;
@ -2337,7 +2343,7 @@ void do_friends(Messenger *m)
#define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL
static time_t lastdump = 0;
static char IDString[CLIENT_ID_SIZE * 2 + 1];
static char *ID2String(uint8_t *client_id)
static char *ID2String(const uint8_t *client_id)
{
uint32_t i;
@ -2530,12 +2536,12 @@ struct SAVED_FRIEND {
uint64_t ping_lastrecv;
};
static uint32_t saved_friendslist_size(Messenger *m)
static uint32_t saved_friendslist_size(const Messenger *m)
{
return count_friendlist(m) * sizeof(struct SAVED_FRIEND);
}
static uint32_t friends_list_save(Messenger *m, uint8_t *data)
static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
{
uint32_t i;
uint32_t num = 0;
@ -2614,7 +2620,7 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
}
/* return size of the messenger data (for saving) */
uint32_t messenger_size(Messenger *m)
uint32_t messenger_size(const Messenger *m)
{
uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
return size32 * 2 // global cookie
@ -2639,7 +2645,7 @@ static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t typ
/* Save the messenger in data of size Messenger_size(). */
void messenger_save(Messenger *m, uint8_t *data)
void messenger_save(const Messenger *m, uint8_t *data)
{
uint32_t len;
uint16_t type;
@ -2776,7 +2782,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
}
/* Load the messenger from data of size length. */
int messenger_load(Messenger *m, uint8_t *data, uint32_t length)
int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
{
uint32_t data32[2];
uint32_t cookie_len = sizeof(data32);
@ -2796,7 +2802,7 @@ int messenger_load(Messenger *m, uint8_t *data, uint32_t length)
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t count_friendlist(Messenger *m)
uint32_t count_friendlist(const Messenger *m)
{
uint32_t ret = 0;
uint32_t i;
@ -2811,7 +2817,7 @@ uint32_t count_friendlist(Messenger *m)
}
/* Return the number of online friends in the instance m. */
uint32_t get_num_online_friends(Messenger *m)
uint32_t get_num_online_friends(const Messenger *m)
{
return m->numonline_friends;
}
@ -2821,7 +2827,7 @@ uint32_t get_num_online_friends(Messenger *m)
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size)
uint32_t copy_friendlist(Messenger const *m, int32_t *out_list, uint32_t list_size)
{
if (!out_list)
return 0;
@ -2853,7 +2859,7 @@ uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size)
* retun 0 if success.
* return -1 if failure.
*/
int get_friendlist(Messenger *m, int32_t **out_list, uint32_t *out_list_length)
int get_friendlist(const Messenger *m, int32_t **out_list, uint32_t *out_list_length)
{
uint32_t i;
@ -2883,7 +2889,7 @@ int get_friendlist(Messenger *m, int32_t **out_list, uint32_t *out_list_length)
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_chatlist. */
uint32_t count_chatlist(Messenger *m)
uint32_t count_chatlist(const Messenger *m)
{
uint32_t ret = 0;
uint32_t i;
@ -2902,7 +2908,7 @@ uint32_t count_chatlist(Messenger *m)
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size)
uint32_t copy_chatlist(const Messenger *m, int *out_list, uint32_t list_size)
{
if (!out_list)
return 0;

View File

@ -172,12 +172,12 @@ typedef struct {
uint16_t invited_groups_num;
struct {
int (*function)(void *object, uint8_t *data, uint32_t len);
int (*function)(void *object, const uint8_t *data, uint32_t len);
void *object;
} lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
struct {
int (*function)(void *object, uint8_t *data, uint32_t len);
int (*function)(void *object, const uint8_t *data, uint32_t len);
void *object;
} lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
} Friend;
@ -212,13 +212,13 @@ typedef struct Messenger {
uint64_t last_LANdiscovery;
void (*friend_message)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
void (*friend_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *friend_message_userdata;
void (*friend_action)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
void (*friend_action)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *friend_action_userdata;
void (*friend_namechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
void (*friend_namechange)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *friend_namechange_userdata;
void (*friend_statusmessagechange)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
void (*friend_statusmessagechange)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *friend_statusmessagechange_userdata;
void (*friend_userstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
void *friend_userstatuschange_userdata;
@ -233,23 +233,23 @@ typedef struct Messenger {
void (*friend_connectionstatuschange_internal)(struct Messenger *m, int32_t, uint8_t, void *);
void *friend_connectionstatuschange_internal_userdata;
void (*group_invite)(struct Messenger *m, int32_t, uint8_t *, void *);
void (*group_invite)(struct Messenger *m, int32_t, const uint8_t *, void *);
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, const uint8_t *, uint16_t, void *);
void *group_message_userdata;
void (*group_action)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *);
void (*group_action)(struct Messenger *m, int, int, const uint8_t *, uint16_t, void *);
void *group_action_userdata;
void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *);
void *group_namelistchange_userdata;
void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t, void *);
void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *);
void *file_sendrequest_userdata;
void (*file_filecontrol)(struct Messenger *m, int32_t, 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, const uint8_t *, uint16_t, void *);
void *file_filecontrol_userdata;
void (*file_filedata)(struct Messenger *m, int32_t, uint8_t, uint8_t *, uint16_t length, void *);
void (*file_filedata)(struct Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t length, void *);
void *file_filedata_userdata;
void (*msi_packet)(struct Messenger *m, int32_t, uint8_t *, uint16_t, void *);
void (*msi_packet)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
void *msi_packet_userdata;
} Messenger;
@ -258,7 +258,7 @@ typedef struct Messenger {
*
* return FRIEND_ADDRESS_SIZE byte address to give to others.
*/
void getaddress(Messenger *m, uint8_t *address);
void getaddress(const Messenger *m, uint8_t *address);
/* Add a friend.
* Set the data that will be sent along with friend request.
@ -276,7 +276,7 @@ void getaddress(Messenger *m, uint8_t *address);
* (the nospam for that friend was set to the new one).
* return -8 if increasing the friend list size fails.
*/
int32_t m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length);
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
/* Add a friend without sending a friendrequest.
@ -296,7 +296,7 @@ int32_t getfriend_id(const Messenger *m, const uint8_t *client_id);
* return 0 if success
* return -1 if failure
*/
int getclient_id(Messenger *m, int32_t friendnumber, uint8_t *client_id);
int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id);
/* Remove a friend.
*
@ -311,14 +311,14 @@ int m_delfriend(Messenger *m, int32_t friendnumber);
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int m_get_friend_connectionstatus(Messenger *m, int32_t friendnumber);
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
/* Checks if there exists a friend with given friendnumber.
*
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int m_friend_exists(Messenger *m, int32_t friendnumber);
int m_friend_exists(const Messenger *m, int32_t friendnumber);
/* Send a text chat message to an online friend.
*
@ -344,8 +344,9 @@ uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid
* 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.
*/
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, 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);
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, const uint8_t *action, uint32_t length);
uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *action,
uint32_t length);
/* Set the name and name_length of a friend.
* name must be a string of maximum MAX_NAME_LENGTH length.
@ -355,7 +356,7 @@ uint32_t m_sendaction_withid(Messenger *m, int32_t friendnumber, uint32_t theid,
* return 0 if success.
* return -1 if failure.
*/
int setfriendname(Messenger *m, int32_t friendnumber, uint8_t *name, uint16_t length);
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
/* Set our nickname.
* name must be a string of maximum MAX_NAME_LENGTH length.
@ -375,7 +376,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length);
* return length of the name.
* return 0 on error.
*/
uint16_t getself_name(Messenger *m, uint8_t *name);
uint16_t getself_name(const Messenger *m, uint8_t *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.
@ -383,13 +384,13 @@ uint16_t getself_name(Messenger *m, uint8_t *name);
* return length of name if success.
* return -1 if failure.
*/
int getname(Messenger *m, int32_t friendnumber, uint8_t *name);
int getname(const 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);
int m_get_name_size(const Messenger *m, int32_t friendnumber);
int m_get_self_name_size(const Messenger *m);
/* Set our user status.
* You are responsible for freeing status after.
@ -403,8 +404,8 @@ int m_set_userstatus(Messenger *m, uint8_t status);
/* return the length of friendnumber's status message, including null on success.
* return -1 on failure.
*/
int m_get_statusmessage_size(Messenger *m, int32_t friendnumber);
int m_get_self_statusmessage_size(Messenger *m);
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
int m_get_self_statusmessage_size(const Messenger *m);
/* 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.
@ -413,21 +414,21 @@ int m_get_self_statusmessage_size(Messenger *m);
* returns the length of the copied data on success
* retruns -1 on failure.
*/
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_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf, uint32_t maxlen);
/* return one of USERSTATUS values.
* Values unknown to your application should be represented as USERSTATUS_NONE.
* As above, the self variant will return our own USERSTATUS.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
uint8_t m_get_userstatus(Messenger *m, int32_t friendnumber);
uint8_t m_get_self_userstatus(Messenger *m);
uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
uint8_t m_get_self_userstatus(const Messenger *m);
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
* returns -1 on error.
*/
uint64_t m_get_last_online(Messenger *m, int32_t friendnumber);
uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
/* Set our typing status for a friend.
* You are responsible for turning it on or off.
@ -442,7 +443,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
* returns 0 if friend is not typing.
* returns 1 if friend is typing.
*/
uint8_t m_get_istyping(Messenger *m, int32_t friendnumber);
uint8_t m_get_istyping(const Messenger *m, int32_t 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).
@ -458,20 +459,20 @@ void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const
/* Set the function that will be executed when a message from a friend is received.
* Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
*/
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the function that will be executed when an action from a friend is received.
* Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
*/
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for name changes.
* Function(int32_t friendnumber, uint8_t *newname, uint16_t length)
* You are not responsible for freeing newname.
*/
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for status message changes.
@ -479,7 +480,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t,
*
* You are not responsible for freeing newstatus
*/
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, uint16_t, void *),
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for status type changes.
@ -526,20 +527,21 @@ void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Mess
*
* Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
*/
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t *, void *), void *userdata);
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, void *),
void *userdata);
/* Set the callback for group messages.
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for group actions.
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *),
void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set callback function for peer name list changes.
@ -570,7 +572,7 @@ int del_groupchat(Messenger *m, int groupnumber);
* return length of name if success
* return -1 if failure
*/
int m_group_peername(Messenger *m, int groupnumber, int peernumber, uint8_t *name);
int m_group_peername(const Messenger *m, int groupnumber, int peernumber, uint8_t *name);
/* invite friendnumber to groupnumber
* return 0 on success
@ -583,24 +585,24 @@ int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber);
* returns group number on success
* returns -1 on failure.
*/
int join_groupchat(Messenger *m, int32_t friendnumber, uint8_t *friend_group_public_key);
int join_groupchat(Messenger *m, int32_t friendnumber, const uint8_t *friend_group_public_key);
/* send a group message
* return 0 on success
* return -1 on failure
*/
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length);
int group_message_send(const Messenger *m, int groupnumber, const uint8_t *message, uint32_t length);
/* send a group action
* return 0 on success
* return -1 on failure
*/
int group_action_send(Messenger *m, int groupnumber, uint8_t *action, uint32_t length);
int group_action_send(const Messenger *m, int groupnumber, const uint8_t *action, uint32_t length);
/* Return the number of peers in the group chat on success.
* return -1 on failure
*/
int group_number_peers(Messenger *m, int groupnumber);
int group_number_peers(const Messenger *m, int groupnumber);
/* List all the peers in the group chat.
*
@ -612,7 +614,8 @@ int group_number_peers(Messenger *m, int groupnumber);
*
* return -1 on failure.
*/
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[], uint16_t length);
int group_names(const Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[],
uint16_t length);
/****************FILE SENDING*****************/
@ -621,7 +624,7 @@ int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES],
*
* 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, int32_t, uint8_t, uint64_t, uint8_t *,
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *,
uint16_t, void *), void *userdata);
/* Set the callback for file control requests.
@ -629,15 +632,15 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int3
* 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, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
uint16_t, void *), void *userdata);
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t,
const uint8_t *, uint16_t, void *), void *userdata);
/* Set the callback for file data.
*
* 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, int32_t, uint8_t, uint8_t *, uint16_t length,
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t length,
void *), void *userdata);
/* Send a file send request.
@ -645,15 +648,16 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, ui
* return 1 on success
* return 0 on failure
*/
int file_sendrequest(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
uint16_t filename_length);
int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
const uint8_t *filename, uint16_t filename_length);
/* Send a file send request.
* Maximum filename length is 255 bytes.
* return file number on success
* return -1 on failure
*/
int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
int new_filesender(const Messenger *m, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
uint16_t filename_length);
/* 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.
@ -661,15 +665,15 @@ int new_filesender(Messenger *m, int32_t friendnumber, uint64_t filesize, uint8_
* return 1 on success
* return 0 on failure
*/
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);
int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
const uint8_t *data, uint16_t length);
/* Send file data.
*
* return 1 on success
* return 0 on failure
*/
int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length);
/* Give the number of bytes left to be sent/received.
*
@ -678,7 +682,7 @@ int file_data(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t *d
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
/*************** A/V related ******************/
@ -686,7 +690,7 @@ uint64_t file_dataremaining(Messenger *m, int32_t friendnumber, uint8_t filenumb
*
* 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, int32_t, uint8_t *, uint16_t, void *),
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Send an msi packet.
@ -694,7 +698,7 @@ void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t,
* return 1 on success
* return 0 on failure
*/
int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length);
int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
/**********************************************/
@ -704,14 +708,14 @@ int m_msi_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t len
* return 0 on success.
*/
int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
int (*packet_handler_callback)(void *object, uint8_t *data, uint32_t len), void *object);
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
/* High level function to send custom lossy packets.
*
* return -1 on failure.
* return 0 on success.
*/
int send_custom_lossy_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length);
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/* Set handlers for custom lossless packets.
@ -722,14 +726,14 @@ int send_custom_lossy_packet(Messenger *m, int32_t friendnumber, uint8_t *data,
* return 0 on success.
*/
int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
int (*packet_handler_callback)(void *object, uint8_t *data, uint32_t len), void *object);
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
/* High level function to send custom lossless packets.
*
* return -1 on failure.
* return 0 on success.
*/
int send_custom_lossless_packet(Messenger *m, int32_t friendnumber, uint8_t *data, uint32_t length);
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
/**********************************************/
/* Run this at startup.
@ -756,28 +760,28 @@ uint32_t messenger_run_interval(Messenger *m);
/* SAVING AND LOADING FUNCTIONS: */
/* return size of the messenger data (for saving). */
uint32_t messenger_size(Messenger *m);
uint32_t messenger_size(const Messenger *m);
/* Save the messenger in data (must be allocated memory of size Messenger_size()) */
void messenger_save(Messenger *m, uint8_t *data);
void messenger_save(const Messenger *m, uint8_t *data);
/* Load the messenger from data of size length. */
int messenger_load(Messenger *m, uint8_t *data, uint32_t length);
int messenger_load(Messenger *m, const uint8_t *data, uint32_t length);
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t count_friendlist(Messenger *m);
uint32_t count_friendlist(const Messenger *m);
/* Return the number of online friends in the instance m. */
uint32_t get_num_online_friends(Messenger *m);
uint32_t get_num_online_friends(const Messenger *m);
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size);
uint32_t copy_friendlist(const 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
* caller.
@ -785,18 +789,18 @@ uint32_t copy_friendlist(Messenger *m, int32_t *out_list, uint32_t list_size);
* retun 0 if success.
* return -1 if failure.
*/
int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length);
int get_friendlist(const Messenger *m, int **out_list, uint32_t *out_list_length);
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_chatlist. */
uint32_t count_chatlist(Messenger *m);
uint32_t count_chatlist(const Messenger *m);
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size);
uint32_t copy_chatlist(const Messenger *m, int *out_list, uint32_t list_size);
#endif

View File

@ -65,7 +65,8 @@ static int connect_sock_to(sock_t sock, IP_Port ip_port)
/* return 0 on success.
* return -1 on failure.
*/
static int generate_handshake(TCP_Client_Connection *TCP_conn, uint8_t *self_public_key, uint8_t *self_secret_key)
static int generate_handshake(TCP_Client_Connection *TCP_conn, const uint8_t *self_public_key,
const uint8_t *self_secret_key)
{
uint8_t plain[crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES];
crypto_box_keypair(plain, TCP_conn->temp_secret_key);
@ -90,7 +91,7 @@ static int generate_handshake(TCP_Client_Connection *TCP_conn, uint8_t *self_pub
* return 0 on success.
* return -1 on failure.
*/
static int handle_handshake(TCP_Client_Connection *TCP_conn, uint8_t *data)
static int handle_handshake(TCP_Client_Connection *TCP_conn, const uint8_t *data)
{
uint8_t plain[crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES];
int len = decrypt_data_symmetric(TCP_conn->shared_key, data, data + crypto_box_NONCEBYTES,
@ -137,7 +138,7 @@ static int send_pending_data(TCP_Client_Connection *con)
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, uint8_t *data, uint16_t length)
static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const uint8_t *data, uint16_t length)
{
if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE)
return -1;
@ -183,7 +184,7 @@ int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key)
}
void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id,
uint8_t *public_key), void *object)
const uint8_t *public_key), void *object)
{
con->response_callback = response_callback;
con->response_callback_object = object;
@ -200,7 +201,7 @@ void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(v
* return 0 if could not send packet.
* return -1 on failure.
*/
int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_t length)
int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length)
{
if (con_id >= NUM_CLIENT_CONNECTIONS)
return -1;
@ -218,7 +219,7 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_
* return 0 if could not send packet.
* return -1 on failure.
*/
int send_oob_packet(TCP_Client_Connection *con, uint8_t *public_key, uint8_t *data, uint16_t length)
int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length)
{
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH)
return -1;
@ -251,14 +252,14 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32
}
void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number,
uint8_t connection_id, uint8_t *data, uint16_t length), void *object)
uint8_t connection_id, const uint8_t *data, uint16_t length), void *object)
{
con->data_callback = data_callback;
con->data_callback_object = object;
}
void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, uint8_t *public_key,
uint8_t *data, uint16_t length), void *object)
void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key,
const uint8_t *data, uint16_t length), void *object)
{
con->oob_data_callback = oob_data_callback;
con->oob_data_callback_object = object;
@ -318,7 +319,7 @@ int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id)
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_onion_request(TCP_Client_Connection *con, uint8_t *data, uint16_t length)
int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length)
{
uint8_t packet[1 + length];
packet[0] = TCP_PACKET_ONION_REQUEST;
@ -326,7 +327,7 @@ int send_onion_request(TCP_Client_Connection *con, uint8_t *data, uint16_t lengt
return write_packet_TCP_secure_connection(con, packet, sizeof(packet));
}
void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, uint8_t *data,
void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data,
uint16_t length), void *object)
{
con->onion_callback = onion_callback;
@ -335,8 +336,8 @@ void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(vo
/* Create new TCP connection to ip_port/public_key
*/
TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, uint8_t *public_key, uint8_t *self_public_key,
uint8_t *self_secret_key)
TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public_key, const uint8_t *self_public_key,
const uint8_t *self_secret_key)
{
if (networking_at_startup() != 0) {
return NULL;
@ -388,7 +389,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, uint8_t *public_key,
/* return 0 on success
* return -1 on failure
*/
static int handle_TCP_packet(TCP_Client_Connection *conn, uint8_t *data, uint16_t length)
static int handle_TCP_packet(TCP_Client_Connection *conn, const uint8_t *data, uint16_t length)
{
if (length <= 1)
return -1;

View File

@ -64,23 +64,23 @@ typedef struct {
uint8_t public_key[crypto_box_PUBLICKEYBYTES];
uint32_t number;
} connections[NUM_CLIENT_CONNECTIONS];
int (*response_callback)(void *object, uint8_t connection_id, uint8_t *public_key);
int (*response_callback)(void *object, uint8_t connection_id, const uint8_t *public_key);
void *response_callback_object;
int (*status_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t status);
void *status_callback_object;
int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, uint8_t *data, uint16_t length);
int (*data_callback)(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length);
void *data_callback_object;
int (*oob_data_callback)(void *object, uint8_t *public_key, uint8_t *data, uint16_t length);
int (*oob_data_callback)(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length);
void *oob_data_callback_object;
int (*onion_callback)(void *object, uint8_t *data, uint16_t length);
int (*onion_callback)(void *object, const uint8_t *data, uint16_t length);
void *onion_callback_object;
} TCP_Client_Connection;
/* Create new TCP connection to ip_port/public_key
*/
TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, uint8_t *public_key, uint8_t *self_public_key,
uint8_t *self_secret_key);
TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public_key, const uint8_t *self_public_key,
const uint8_t *self_secret_key);
/* Run the TCP connection
*/
@ -94,8 +94,8 @@ void kill_TCP_connection(TCP_Client_Connection *TCP_connection);
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
int send_onion_request(TCP_Client_Connection *con, uint8_t *data, uint16_t length);
void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, uint8_t *data,
int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length);
void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data,
uint16_t length), void *object);
/* return 1 on success.
@ -104,7 +104,7 @@ void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(vo
*/
int send_routing_request(TCP_Client_Connection *con, uint8_t *public_key);
void routing_response_handler(TCP_Client_Connection *con, int (*response_callback)(void *object, uint8_t connection_id,
uint8_t *public_key), void *object);
const uint8_t *public_key), void *object);
void routing_status_handler(TCP_Client_Connection *con, int (*status_callback)(void *object, uint32_t number,
uint8_t connection_id, uint8_t status), void *object);
@ -127,17 +127,17 @@ int set_tcp_connection_number(TCP_Client_Connection *con, uint8_t con_id, uint32
* return 0 if could not send packet.
* return -1 on failure.
*/
int send_data(TCP_Client_Connection *con, uint8_t con_id, uint8_t *data, uint16_t length);
int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, uint16_t length);
void routing_data_handler(TCP_Client_Connection *con, int (*data_callback)(void *object, uint32_t number,
uint8_t connection_id, uint8_t *data, uint16_t length), void *object);
uint8_t connection_id, const uint8_t *data, uint16_t length), void *object);
/* return 1 on success.
* return 0 if could not send packet.
* return -1 on failure.
*/
int send_oob_packet(TCP_Client_Connection *con, uint8_t *public_key, uint8_t *data, uint16_t length);
void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, uint8_t *public_key,
uint8_t *data, uint16_t length), void *object);
int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const uint8_t *data, uint16_t length);
void oob_data_handler(TCP_Client_Connection *con, int (*oob_data_callback)(void *object, const uint8_t *public_key,
const uint8_t *data, uint16_t length), void *object);
#endif

View File

@ -97,7 +97,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
/* return index corresponding to connection with peer on success
* return -1 on failure.
*/
static int get_TCP_connection_index(TCP_Server *TCP_server, uint8_t *public_key)
static int get_TCP_connection_index(const TCP_Server *TCP_server, const uint8_t *public_key)
{
return bs_list_find(&TCP_server->accepted_key_list, public_key);
}
@ -110,7 +110,7 @@ static int kill_accepted(TCP_Server *TCP_server, int index);
* return index on success
* return -1 on failure
*/
static int add_accepted(TCP_Server *TCP_server, TCP_Secure_Connection *con)
static int add_accepted(TCP_Server *TCP_server, const TCP_Secure_Connection *con)
{
int index = get_TCP_connection_index(TCP_server, con->public_key);
@ -249,7 +249,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length)
* return 0 if could not read any packet.
* return -1 on failure (connection must be killed).
*/
int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, uint8_t *shared_key,
int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, const uint8_t *shared_key,
uint8_t *recv_nonce, uint8_t *data, uint16_t max_len)
{
if (*next_packet_length == 0) {
@ -318,7 +318,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, uint8_t *data, uint16_t length)
static int write_packet_TCP_secure_connection(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length)
{
if (length + crypto_box_MACBYTES > MAX_PACKET_SIZE)
return -1;
@ -389,7 +389,8 @@ static int kill_accepted(TCP_Server *TCP_server, int index)
/* return 1 if everything went well.
* return -1 if the connection must be killed.
*/
static int handle_TCP_handshake(TCP_Secure_Connection *con, uint8_t *data, uint16_t length, uint8_t *self_secret_key)
static int handle_TCP_handshake(TCP_Secure_Connection *con, const uint8_t *data, uint16_t length,
const uint8_t *self_secret_key)
{
if (length != TCP_CLIENT_HANDSHAKE_SIZE)
return -1;
@ -435,7 +436,7 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, uint8_t *data, uint1
* return 0 if we didn't get it yet.
* return -1 if the connection must be killed.
*/
static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_secret_key)
static int read_connection_handshake(TCP_Secure_Connection *con, const uint8_t *self_secret_key)
{
uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE];
int len = 0;
@ -451,7 +452,7 @@ static int read_connection_handshake(TCP_Secure_Connection *con, uint8_t *self_s
* return 0 if could not send packet.
* return -1 on failure (connection must be killed).
*/
static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, uint8_t *public_key)
static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, const uint8_t *public_key)
{
uint8_t data[1 + 1 + crypto_box_PUBLICKEYBYTES];
data[0] = TCP_PACKET_ROUTING_RESPONSE;
@ -484,7 +485,7 @@ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id)
/* return 0 on success.
* return -1 on failure (connection must be killed).
*/
static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key)
static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *public_key)
{
uint32_t i;
uint32_t index = ~0;
@ -562,7 +563,7 @@ static int handle_TCP_routing_req(TCP_Server *TCP_server, uint32_t con_id, uint8
/* return 0 on success.
* return -1 on failure (connection must be killed).
*/
static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, uint8_t *public_key, uint8_t *data,
static int handle_TCP_oob_send(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *public_key, const uint8_t *data,
uint16_t length)
{
if (length == 0 || length > TCP_MAX_OOB_DATA_LENGTH)
@ -645,7 +646,7 @@ static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data,
/* return 0 on success
* return -1 on failure
*/
static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *data, uint16_t length)
static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, const uint8_t *data, uint16_t length)
{
if (length == 0)
return -1;
@ -764,7 +765,8 @@ static int handle_TCP_packet(TCP_Server *TCP_server, uint32_t con_id, uint8_t *d
}
static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, uint8_t *data, uint16_t length)
static int confirm_TCP_connection(TCP_Server *TCP_server, TCP_Secure_Connection *con, const uint8_t *data,
uint16_t length)
{
int index = add_accepted(TCP_server, con);
@ -838,8 +840,8 @@ static sock_t new_listening_TCP_socket(int family, uint16_t port)
return sock;
}
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key,
uint8_t *secret_key, Onion *onion)
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *public_key,
const uint8_t *secret_key, Onion *onion)
{
if (num_sockets == 0 || ports == NULL)
return NULL;

View File

@ -133,8 +133,8 @@ typedef struct {
/* Create new TCP server instance.
*/
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, uint16_t *ports, uint8_t *public_key,
uint8_t *secret_key, Onion *onion);
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *public_key,
const uint8_t *secret_key, Onion *onion);
/* Run the TCP_server
*/
@ -164,7 +164,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length);
* return 0 if could not read any packet.
* return -1 on failure (connection must be killed).
*/
int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, uint8_t *shared_key,
int read_packet_TCP_secure_connection(sock_t sock, uint16_t *next_packet_length, const uint8_t *shared_key,
uint8_t *recv_nonce, uint8_t *data, uint16_t max_len);

View File

@ -32,7 +32,7 @@
#include "util.h"
#include "math.h"
static uint8_t crypt_connection_id_not_valid(Net_Crypto *c, int crypt_connection_id)
static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_connection_id)
{
return (uint32_t)crypt_connection_id >= c->crypto_connections_length;
}
@ -70,7 +70,7 @@ static int is_alive(uint8_t status)
* return -1 on failure.
* return COOKIE_REQUEST_LENGTH on success.
*/
static int create_cookie_request(Net_Crypto *c, uint8_t *packet, uint8_t *dht_public_key, uint64_t number,
static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *dht_public_key, uint64_t number,
uint8_t *shared_key)
{
uint8_t plain[COOKIE_REQUEST_PLAIN_LENGTH];
@ -100,7 +100,7 @@ static int create_cookie_request(Net_Crypto *c, uint8_t *packet, uint8_t *dht_pu
* return -1 on failure.
* return 0 on success.
*/
static int create_cookie(uint8_t *cookie, uint8_t *bytes, uint8_t *encryption_key)
static int create_cookie(uint8_t *cookie, const uint8_t *bytes, const uint8_t *encryption_key)
{
uint8_t contents[COOKIE_CONTENTS_LENGTH];
uint64_t temp_time = unix_time();
@ -148,8 +148,8 @@ static int open_cookie(uint8_t *bytes, const uint8_t *cookie, const uint8_t *enc
* return -1 on failure.
* return COOKIE_RESPONSE_LENGTH on success.
*/
static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *request_plain, uint8_t *shared_key,
uint8_t *dht_public_key)
static int create_cookie_response(const Net_Crypto *c, uint8_t *packet, const uint8_t *request_plain,
const uint8_t *shared_key, const uint8_t *dht_public_key)
{
uint8_t cookie_plain[COOKIE_DATA_LENGTH];
memcpy(cookie_plain, request_plain, crypto_box_PUBLICKEYBYTES);
@ -177,8 +177,8 @@ static int create_cookie_response(Net_Crypto *c, uint8_t *packet, uint8_t *reque
* return -1 on failure.
* return 0 on success.
*/
static int handle_cookie_request(Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key, uint8_t *dht_public_key,
const uint8_t *packet, uint16_t length)
static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, uint8_t *shared_key,
uint8_t *dht_public_key, const uint8_t *packet, uint16_t length)
{
if (length != COOKIE_REQUEST_LENGTH)
return -1;
@ -220,8 +220,8 @@ static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t
/* Handle the cookie request packet (for TCP)
*/
static int tcp_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t conn_id, uint8_t *packet,
uint32_t length)
static int tcp_handle_cookie_request(const Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t conn_id,
const uint8_t *packet, uint32_t length)
{
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[crypto_box_BEFORENMBYTES];
@ -243,8 +243,8 @@ static int tcp_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_c
/* Handle the cookie request packet (for TCP oob packets)
*/
static int tcp_oob_handle_cookie_request(Net_Crypto *c, TCP_Client_Connection *TCP_con, uint8_t *dht_public_key,
uint8_t *packet, uint32_t length)
static int tcp_oob_handle_cookie_request(const Net_Crypto *c, TCP_Client_Connection *TCP_con,
const uint8_t *dht_public_key, const uint8_t *packet, uint32_t length)
{
uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
uint8_t shared_key[crypto_box_BEFORENMBYTES];
@ -302,8 +302,8 @@ static int handle_cookie_response(uint8_t *cookie, uint64_t *number, const uint8
* return -1 on failure.
* return HANDSHAKE_PACKET_LENGTH on success.
*/
static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cookie, uint8_t *nonce, uint8_t *session_pk,
uint8_t *peer_real_pk, uint8_t *peer_dht_pubkey)
static int create_crypto_handshake(const Net_Crypto *c, uint8_t *packet, const uint8_t *cookie, const uint8_t *nonce,
const uint8_t *session_pk, const uint8_t *peer_real_pk, const uint8_t *peer_dht_pubkey)
{
uint8_t plain[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + crypto_hash_sha512_BYTES + COOKIE_LENGTH];
memcpy(plain, nonce, crypto_box_NONCEBYTES);
@ -348,8 +348,8 @@ static int create_crypto_handshake(Net_Crypto *c, uint8_t *packet, uint8_t *cook
* return -1 on failure.
* return 0 on success.
*/
static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, uint8_t *expected_real_pk)
static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t *session_pk, uint8_t *peer_real_pk,
uint8_t *dht_public_key, uint8_t *cookie, const uint8_t *packet, uint32_t length, const uint8_t *expected_real_pk)
{
if (length != HANDSHAKE_PACKET_LENGTH)
return -1;
@ -386,7 +386,7 @@ static int handle_crypto_handshake(Net_Crypto *c, uint8_t *nonce, uint8_t *sessi
}
static Crypto_Connection *get_crypto_connection(Net_Crypto *c, int crypt_connection_id)
static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
{
if (crypt_connection_id_not_valid(c, crypt_connection_id))
return 0;
@ -400,7 +400,7 @@ static Crypto_Connection *get_crypto_connection(Net_Crypto *c, int crypt_connect
* return -1 on failure.
* return 0 on success.
*/
static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint16_t length)
static int send_packet_to(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
{
//TODO TCP, etc...
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -456,7 +456,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
/* Return number of packets in array
* Note that holes are counted too.
*/
static uint32_t num_packets_array(Packets_Array *array)
static uint32_t num_packets_array(const Packets_Array *array)
{
return array->buffer_end - array->buffer_start;
}
@ -466,7 +466,7 @@ static uint32_t num_packets_array(Packets_Array *array)
* return -1 on failure.
* return 0 on success.
*/
static int add_data_to_buffer(Packets_Array *array, uint32_t number, Packet_Data *data)
static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packet_Data *data)
{
if (number - array->buffer_start > CRYPTO_PACKET_BUFFER_SIZE)
return -1;
@ -496,7 +496,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, Packet_Data
* return 0 if data at number is empty.
* return 1 if data pointer was put in data.
*/
static int get_data_pointer(Packets_Array *array, Packet_Data **data, uint32_t number)
static int get_data_pointer(const Packets_Array *array, Packet_Data **data, uint32_t number)
{
uint32_t num_spots = array->buffer_end - array->buffer_start;
@ -517,7 +517,7 @@ static int get_data_pointer(Packets_Array *array, Packet_Data **data, uint32_t n
* return -1 on failure.
* return packet number on success.
*/
static int64_t add_data_end_of_buffer(Packets_Array *array, Packet_Data *data)
static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *data)
{
if (num_packets_array(array) >= CRYPTO_PACKET_BUFFER_SIZE)
return -1;
@ -607,7 +607,7 @@ static int set_buffer_end(Packets_Array *array, uint32_t number)
* return -1 on failure.
* return length of packet on success.
*/
static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array *recv_array)
static int generate_request_packet(uint8_t *data, uint16_t length, const Packets_Array *recv_array)
{
if (length == 0)
return -1;
@ -656,7 +656,7 @@ static int generate_request_packet(uint8_t *data, uint16_t length, Packets_Array
* return -1 on failure.
* return number of requested packets on success.
*/
static int handle_request_packet(Packets_Array *send_array, uint8_t *data, uint16_t length)
static int handle_request_packet(Packets_Array *send_array, const uint8_t *data, uint16_t length)
{
if (length < 1)
return -1;
@ -718,7 +718,7 @@ static int handle_request_packet(Packets_Array *send_array, uint8_t *data, uint1
* return -1 on failure.
* return 0 on success.
*/
static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint16_t length)
static int send_data_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint16_t length)
{
if (length == 0 || length + (1 + sizeof(uint16_t) + crypto_box_MACBYTES) > MAX_CRYPTO_PACKET_SIZE)
return -1;
@ -750,8 +750,8 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
* return -1 on failure.
* return 0 on success.
*/
static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
uint8_t *data, uint32_t length)
static int send_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
const uint8_t *data, uint32_t length)
{
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
return -1;
@ -771,7 +771,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3
/* return -1 if data could not be put in packet queue.
* return positive packet number if data was put into the queue.
*/
static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
static int64_t send_lossless_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
{
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
return -1;
@ -827,7 +827,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, uint
/* Get the lowest 2 bytes from the nonce and convert
* them to host byte format before returning them.
*/
static uint16_t get_nonce_uint16(uint8_t *nonce)
static uint16_t get_nonce_uint16(const uint8_t *nonce)
{
uint16_t num;
memcpy(&num, nonce + (crypto_box_NONCEBYTES - sizeof(uint16_t)), sizeof(uint16_t));
@ -843,7 +843,7 @@ static uint16_t get_nonce_uint16(uint8_t *nonce)
* return -1 on failure.
* return length of data on success.
*/
static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet,
static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint8_t *data, const uint8_t *packet,
uint16_t length)
{
if (length <= (1 + sizeof(uint16_t) + crypto_box_MACBYTES) || length > MAX_CRYPTO_PACKET_SIZE)
@ -880,7 +880,7 @@ static int handle_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *d
* return -1 on failure.
* return 0 on success.
*/
static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
static int send_request_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -902,7 +902,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return number of packets sent on success.
*/
static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint16_t max_num)
static int send_requested_packets(const Net_Crypto *c, int crypt_connection_id, uint16_t max_num)
{
if (max_num == 0)
return -1;
@ -948,7 +948,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint16
* return -1 on failure.
* return 0 on success.
*/
static int new_temp_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *packet, uint16_t length)
static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
return -1;
@ -979,7 +979,7 @@ static int new_temp_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *pack
* return -1 on failure.
* return 0 on success.
*/
static int clear_temp_packet(Net_Crypto *c, int crypt_connection_id)
static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1002,7 +1002,7 @@ static int clear_temp_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
static int send_temp_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1026,7 +1026,8 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t *cookie, uint8_t *dht_public_key)
static int create_send_handshake(const Net_Crypto *c, int crypt_connection_id, const uint8_t *cookie,
const uint8_t *dht_public_key)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1051,7 +1052,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, uint8_t
* return -1 on failure.
* return 0 on success.
*/
static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
static int send_kill_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1068,7 +1069,8 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length)
static int handle_data_packet_helper(const Net_Crypto *c, int crypt_connection_id, const uint8_t *packet,
uint16_t length)
{
if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE)
return -1;
@ -1317,7 +1319,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
* return -1 if there are no connections like we are looking for.
* return id if it found it.
*/
static int getcryptconnection_id(Net_Crypto *c, uint8_t *public_key)
static int getcryptconnection_id(const Net_Crypto *c, const uint8_t *public_key)
{
uint32_t i;
@ -1335,7 +1337,7 @@ static int getcryptconnection_id(Net_Crypto *c, uint8_t *public_key)
* return -1 if there are no connections like we are looking for.
* return id if it found it.
*/
static int getcryptconnection_id_dht_pubkey(Net_Crypto *c, uint8_t *dht_public_key)
static int getcryptconnection_id_dht_pubkey(const Net_Crypto *c, const uint8_t *dht_public_key)
{
uint32_t i;
@ -1493,7 +1495,7 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c)
* return -1 on failure.
* return connection id on success.
*/
int new_crypto_connection(Net_Crypto *c, uint8_t *real_public_key)
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key)
{
int crypt_connection_id = getcryptconnection_id(c, real_public_key);
@ -1523,7 +1525,7 @@ int new_crypto_connection(Net_Crypto *c, uint8_t *real_public_key)
* return -1 on failure.
* return 0 on success.
*/
static int disconnect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
static int disconnect_peer_tcp(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1548,7 +1550,7 @@ static int disconnect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
* return -1 on failure.
* return 0 on success.
*/
static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
static int connect_peer_tcp(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1573,7 +1575,7 @@ static int connect_peer_tcp(Net_Crypto *c, int crypt_connection_id)
* return 0 on failure (no key copied).
* return timestamp on success (key copied).
*/
uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key)
uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1595,7 +1597,8 @@ uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t
* return -1 on failure.
* return 0 on success.
*/
int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key, uint64_t timestamp)
int set_connection_dht_public_key(const Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key,
uint64_t timestamp)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1656,7 +1659,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port)
return -1;
}
static int tcp_response_callback(void *object, uint8_t connection_id, uint8_t *public_key)
static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
{
TCP_Client_Connection *TCP_con = object;
Net_Crypto *c = TCP_con->net_crypto_pointer;
@ -1723,7 +1726,7 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
return 0;
}
static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t *data, uint16_t length)
static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length)
{
if (length == 0)
@ -1748,7 +1751,7 @@ static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_i
return 0;
}
static int tcp_oob_callback(void *object, uint8_t *public_key, uint8_t *data, uint16_t length)
static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8_t *data, uint16_t length)
{
if (length == 0 || length > MAX_CRYPTO_PACKET_SIZE)
return -1;
@ -1790,7 +1793,7 @@ static int tcp_oob_callback(void *object, uint8_t *public_key, uint8_t *data, ui
* return -1 if it can't.
* return 0 if it can.
*/
static int tcp_connection_check(Net_Crypto *c, uint8_t *public_key)
static int tcp_connection_check(const Net_Crypto *c, const uint8_t *public_key)
{
uint32_t i;
@ -1825,7 +1828,7 @@ static int tcp_connection_check(Net_Crypto *c, uint8_t *public_key)
* return 0 if it was added.
* return -1 if it wasn't.
*/
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, uint8_t *public_key)
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, const uint8_t *public_key)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -1878,7 +1881,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
* return 0 if it was added.
* return -1 if it wasn't.
*/
int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, uint8_t *public_key)
int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, const uint8_t *public_key)
{
if (ip_port.ip.family == TCP_INET) {
ip_port.ip.family = AF_INET;
@ -1910,7 +1913,7 @@ int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, uint8_t *public_key)
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num)
{
if (num == 0)
return 0;
@ -2074,8 +2077,8 @@ static void clear_disconnected_tcp(Net_Crypto *c)
* return -1 on failure.
* return 0 on success.
*/
int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object,
int id, uint8_t status), void *object, int id)
int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
int (*connection_status_callback)(void *object, int id, uint8_t status), void *object, int id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2096,7 +2099,7 @@ int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*conn
* return -1 on failure.
* return 0 on success.
*/
int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int id, uint8_t *data, uint16_t length), void *object, int id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2119,7 +2122,7 @@ int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connec
* return 0 on success.
*/
int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
int (*connection_lossy_data_callback)(void *object, int id, uint8_t *data, uint16_t length), void *object, int id)
int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object, int id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2137,7 +2140,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
* return -1 on failure.
* return connection id on success.
*/
static int crypto_id_ip_port(Net_Crypto *c, IP_Port ip_port)
static int crypto_id_ip_port(const Net_Crypto *c, IP_Port ip_port)
{
return bs_list_find(&c->ip_port_list, &ip_port);
}
@ -2373,7 +2376,7 @@ static void send_crypto_packets(Net_Crypto *c)
/* returns the number of packet slots left in the sendbuffer.
* return 0 if failure.
*/
uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id)
uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2390,7 +2393,7 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id)
*
* The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range.
*/
int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
{
if (length == 0)
return -1;
@ -2427,7 +2430,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data,
*
* Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
*/
int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length)
int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length)
{
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
return -1;
@ -2469,7 +2472,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
*
* sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
*/
unsigned int crypto_connection_status(Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected)
unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
@ -2492,7 +2495,7 @@ void new_keys(Net_Crypto *c)
/* Save the public and private keys to the keys array.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
*/
void save_keys(Net_Crypto *c, uint8_t *keys)
void save_keys(const Net_Crypto *c, uint8_t *keys)
{
memcpy(keys, c->self_public_key, crypto_box_PUBLICKEYBYTES);
memcpy(keys + crypto_box_PUBLICKEYBYTES, c->self_secret_key, crypto_box_SECRETKEYBYTES);
@ -2580,7 +2583,7 @@ static void kill_timedout(Net_Crypto *c)
/* return the optimal interval in ms for running do_net_crypto.
*/
uint32_t crypto_run_interval(Net_Crypto *c)
uint32_t crypto_run_interval(const Net_Crypto *c)
{
return c->current_sleep_time;
}

View File

@ -129,7 +129,7 @@ typedef struct {
void *connection_data_callback_object;
int connection_data_callback_id;
int (*connection_lossy_data_callback)(void *object, int id, uint8_t *data, uint16_t length);
int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length);
void *connection_lossy_data_callback_object;
int connection_lossy_data_callback_id;
@ -220,14 +220,14 @@ int accept_crypto_connection(Net_Crypto *c, New_Connection *n_c);
* return -1 on failure.
* return connection id on success.
*/
int new_crypto_connection(Net_Crypto *c, uint8_t *real_public_key);
int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key);
/* Copy friends DHT public key into dht_key.
*
* return 0 on failure (no key copied).
* return timestamp on success (key copied).
*/
uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key);
uint64_t get_connection_dht_key(const Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key);
/* Set the DHT public key of the crypto connection.
* timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
@ -236,7 +236,8 @@ uint64_t get_connection_dht_key(Net_Crypto *c, int crypt_connection_id, uint8_t
* return -1 on failure.
* return 0 on success.
*/
int set_connection_dht_public_key(Net_Crypto *c, int crypt_connection_id, uint8_t *dht_public_key, uint64_t timestamp);
int set_connection_dht_public_key(const Net_Crypto *c, int crypt_connection_id, const uint8_t *dht_public_key,
uint64_t timestamp);
/* Set the direct ip of the crypto connection.
*
@ -255,8 +256,8 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port);
* return -1 on failure.
* return 0 on success.
*/
int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_status_callback)(void *object,
int id, uint8_t status), void *object, int id);
int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
int (*connection_status_callback)(void *object, int id, uint8_t status), void *object, int id);
/* Set function to be called when connection with crypt_connection_id receives a lossless data packet of length.
*
@ -266,7 +267,7 @@ int connection_status_handler(Net_Crypto *c, int crypt_connection_id, int (*conn
* return -1 on failure.
* return 0 on success.
*/
int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int id, uint8_t *data, uint16_t length), void *object, int id);
@ -279,12 +280,13 @@ int connection_data_handler(Net_Crypto *c, int crypt_connection_id, int (*connec
* return 0 on success.
*/
int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
int (*connection_lossy_data_callback)(void *object, int id, uint8_t *data, uint16_t length), void *object, int id);
int (*connection_lossy_data_callback)(void *object, int id, const uint8_t *data, uint16_t length), void *object,
int id);
/* returns the number of packet slots left in the sendbuffer.
* return 0 if failure.
*/
uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id);
uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connection_id);
/* Sends a lossless cryptopacket.
*
@ -293,28 +295,28 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id)
*
* The first byte of data must be in the CRYPTO_RESERVED_PACKETS to PACKET_ID_LOSSY_RANGE_START range.
*/
int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length);
int64_t write_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length);
/* return -1 on failure.
* return 0 on success.
*
* Sends a lossy cryptopacket. (first byte must in the PACKET_ID_LOSSY_RANGE_*)
*/
int send_lossy_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length);
int send_lossy_cryptpacket(const Net_Crypto *c, int crypt_connection_id, const uint8_t *data, uint32_t length);
/* Add a tcp relay, associating it to a crypt_connection_id.
*
* return 0 if it was added.
* return -1 if it wasn't.
*/
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, uint8_t *public_key);
int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port, const uint8_t *public_key);
/* Add a tcp relay to the array.
*
* return 0 if it was added.
* return -1 if it wasn't.
*/
int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, uint8_t *public_key);
int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, const uint8_t *public_key);
/* Copy a maximum of num TCP relays we are connected to to tcp_relays.
* NOTE that the family of the copied ip ports will be set to TCP_INET or TCP_INET6.
@ -322,7 +324,7 @@ int add_tcp_relay(Net_Crypto *c, IP_Port ip_port, uint8_t *public_key);
* return number of relays copied to tcp_relays on success.
* return 0 on failure.
*/
unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
unsigned int copy_connected_tcp_relays(const Net_Crypto *c, Node_format *tcp_relays, uint16_t num);
/* Kill a crypto connection.
*
@ -336,7 +338,7 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id);
*
* sets direct_connected to 1 if connection connects directly to other, 0 if it isn't.
*/
unsigned int crypto_connection_status(Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected);
unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_id, uint8_t *direct_connected);
/* Generate our public and private keys.
@ -347,7 +349,7 @@ void new_keys(Net_Crypto *c);
/* Save the public and private keys to the keys array.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
*/
void save_keys(Net_Crypto *c, uint8_t *keys);
void save_keys(const Net_Crypto *c, uint8_t *keys);
/* Load the public and private keys from the keys array.
* Length must be crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES.
@ -361,7 +363,7 @@ Net_Crypto *new_net_crypto(DHT *dht);
/* return the optimal interval in ms for running do_net_crypto.
*/
uint32_t crypto_run_interval(Net_Crypto *c);
uint32_t crypto_run_interval(const Net_Crypto *c);
/* Main loop. */
void do_net_crypto(Net_Crypto *c);

View File

@ -54,7 +54,7 @@ static void change_symmetric_key(Onion *onion)
* return -1 on failure.
* return 0 on success.
*/
int create_onion_path(DHT *dht, Onion_Path *new_path, Node_format *nodes)
int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *nodes)
{
if (!new_path || !nodes)
return -1;
@ -93,8 +93,8 @@ int create_onion_path(DHT *dht, Onion_Path *new_path, Node_format *nodes)
* return -1 on failure.
* return length of created packet on success.
*/
int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, IP_Port dest, uint8_t *data,
uint32_t length)
int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest,
const uint8_t *data, uint32_t length)
{
if (1 + length + SEND_1 > max_packet_length || length == 0)
return -1;
@ -149,7 +149,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, Onion_Path
* return -1 on failure.
* return 0 on success.
*/
int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *data, uint32_t length)
int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint32_t length)
{
uint8_t packet[ONION_MAX_PACKET_SIZE];
int len = create_onion_packet(packet, sizeof(packet), path, dest, data, length);
@ -209,7 +209,7 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack
return onion_send_1(onion, plain, len, source, packet + 1);
}
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce)
int onion_send_1(const Onion *onion, const uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce)
{
IP_Port send_to;
ipport_unpack(&send_to, plain);

View File

@ -76,7 +76,7 @@ typedef struct {
* return -1 on failure.
* return 0 on success.
*/
int create_onion_path(DHT *dht, Onion_Path *new_path, Node_format *nodes);
int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *nodes);
/* Create a onion packet.
*
@ -87,8 +87,8 @@ int create_onion_path(DHT *dht, Onion_Path *new_path, Node_format *nodes);
* return -1 on failure.
* return length of created packet on success.
*/
int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, IP_Port dest, uint8_t *data,
uint32_t length);
int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest,
const uint8_t *data, uint32_t length);
/* Create and send a onion packet.
*
@ -98,7 +98,7 @@ int create_onion_packet(uint8_t *packet, uint16_t max_packet_length, Onion_Path
* return -1 on failure.
* return 0 on success.
*/
int send_onion_packet(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *data, uint32_t length);
int send_onion_packet(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *data, uint32_t length);
/* Create and send a onion response sent initially to dest with.
* Maximum length of data is ONION_RESPONSE_MAX_DATA_SIZE.
@ -118,7 +118,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data,
* Source family must be set to something else than AF_INET6 or AF_INET so that the callback gets called
* when the response is received.
*/
int onion_send_1(Onion *onion, uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce);
int onion_send_1(const Onion *onion, const uint8_t *plain, uint32_t len, IP_Port source, const uint8_t *nonce);
/* Set the callback to be called when the dest ip_port doesn't have AF_INET6 or AF_INET as the family.
*

View File

@ -49,9 +49,9 @@
* return -1 on failure.
* return packet length on success.
*/
int create_announce_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, Node_format dest,
uint8_t *public_key, uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key,
uint64_t sendback_data)
int create_announce_request(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, Node_format dest,
const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id,
const uint8_t *data_public_key, uint64_t sendback_data)
{
uint8_t plain[ONION_PING_ID_SIZE + crypto_box_PUBLICKEYBYTES + crypto_box_PUBLICKEYBYTES +
ONION_ANNOUNCE_SENDBACK_DATA_LENGTH];
@ -89,8 +89,9 @@ int create_announce_request(uint8_t *packet, uint16_t max_packet_length, Onion_P
* return -1 on failure.
* return 0 on success.
*/
int create_data_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, IP_Port dest,
uint8_t *public_key, uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length)
int create_data_request(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest,
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data,
uint16_t length)
{
if ((unsigned int)DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE)
return -1;
@ -129,8 +130,9 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path
* return -1 on failure.
* return 0 on success.
*/
int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format dest, uint8_t *public_key,
uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key, uint64_t sendback_data)
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
uint64_t sendback_data)
{
uint8_t packet[ONION_MAX_PACKET_SIZE];
int len = create_announce_request(packet, sizeof(packet), path, dest, public_key, secret_key, ping_id, client_id,
@ -159,8 +161,8 @@ int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format de
* return -1 on failure.
* return 0 on success.
*/
int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *public_key,
uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length)
int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length)
{
uint8_t packet[ONION_MAX_PACKET_SIZE];
int len = create_data_request(packet, sizeof(packet), path, dest, public_key, encrypt_public_key, nonce, data, length);
@ -175,8 +177,8 @@ int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint
}
/* Generate a ping_id and put it in ping_id */
static void generate_ping_id(Onion_Announce *onion_a, uint64_t time, const uint8_t *public_key, IP_Port ret_ip_port,
uint8_t *ping_id)
static void generate_ping_id(const Onion_Announce *onion_a, uint64_t time, const uint8_t *public_key,
IP_Port ret_ip_port, uint8_t *ping_id)
{
time /= PING_ID_TIMEOUT;
uint8_t data[crypto_box_KEYBYTES + sizeof(time) + crypto_box_PUBLICKEYBYTES + sizeof(ret_ip_port)];

View File

@ -75,9 +75,9 @@ typedef struct {
* return -1 on failure.
* return packet length on success.
*/
int create_announce_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, Node_format dest,
uint8_t *public_key, uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key,
uint64_t sendback_data);
int create_announce_request(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, Node_format dest,
const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id,
const uint8_t *data_public_key, uint64_t sendback_data);
/* Create an onion data request packet in packet of max_packet_length (recommended size ONION_MAX_PACKET_SIZE).
*
@ -93,8 +93,9 @@ int create_announce_request(uint8_t *packet, uint16_t max_packet_length, Onion_P
* return -1 on failure.
* return 0 on success.
*/
int create_data_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path *path, IP_Port dest,
uint8_t *public_key, uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length);
int create_data_request(uint8_t *packet, uint16_t max_packet_length, const Onion_Path *path, IP_Port dest,
const uint8_t *public_key, const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data,
uint16_t length);
/* Create and send an onion announce request packet.
*
@ -110,8 +111,9 @@ int create_data_request(uint8_t *packet, uint16_t max_packet_length, Onion_Path
* return -1 on failure.
* return 0 on success.
*/
int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format dest, uint8_t *public_key,
uint8_t *secret_key, uint8_t *ping_id, uint8_t *client_id, uint8_t *data_public_key, uint64_t sendback_data);
int send_announce_request(Networking_Core *net, const Onion_Path *path, Node_format dest, const uint8_t *public_key,
const uint8_t *secret_key, const uint8_t *ping_id, const uint8_t *client_id, const uint8_t *data_public_key,
uint64_t sendback_data);
/* Create and send an onion data request packet.
*
@ -129,8 +131,8 @@ int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format de
* return -1 on failure.
* return 0 on success.
*/
int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *public_key,
uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length);
int send_data_request(Networking_Core *net, const Onion_Path *path, IP_Port dest, const uint8_t *public_key,
const uint8_t *encrypt_public_key, const uint8_t *nonce, const uint8_t *data, uint16_t length);
Onion_Announce *new_onion_announce(DHT *dht);

View File

@ -38,7 +38,7 @@
* return -1 if nodes are suitable for creating a new path.
* return path number of already existing similar path if one already exists.
*/
static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes)
static int is_path_used(const Onion_Client_Paths *onion_paths, const Node_format *nodes)
{
uint32_t i;
@ -68,7 +68,7 @@ static int is_path_used(Onion_Client_Paths *onion_paths, Node_format *nodes)
* TODO: Make this function better, it currently probably is vulnerable to some attacks that
* could de anonimize us.
*/
static int random_path(DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path)
static int random_path(const DHT *dht, Onion_Client_Paths *onion_paths, uint32_t pathnum, Onion_Path *path)
{
if (pathnum >= NUMBER_ONION_PATHS)
pathnum = rand() % NUMBER_ONION_PATHS;
@ -130,7 +130,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, IP_Port s
* return -1 on failure.
* return 0 on success.
*/
static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_port, uint8_t *data, uint32_t length)
static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_port, const uint8_t *data, uint32_t length)
{
if (ip_port.ip.family == AF_INET || ip_port.ip.family == AF_INET6) {
if ((uint32_t)sendpacket(onion_c->net, ip_port, data, length) != length)
@ -157,7 +157,8 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, IP_Port ip_por
* return 0 on success
*
*/
static int new_sendback(Onion_Client *onion_c, uint32_t num, uint8_t *public_key, IP_Port ip_port, uint64_t *sendback)
static int new_sendback(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port,
uint64_t *sendback)
{
uint8_t data[sizeof(uint32_t) + crypto_box_PUBLICKEYBYTES + sizeof(IP_Port)];
memcpy(data, &num, sizeof(uint32_t));
@ -198,8 +199,8 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u
return num;
}
static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_Port dest, uint8_t *dest_pubkey,
uint8_t *ping_id, uint32_t pathnum)
static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_Port dest, const uint8_t *dest_pubkey,
const uint8_t *ping_id, uint32_t pathnum)
{
if (num > onion_c->num_friends)
return -1;
@ -279,8 +280,8 @@ static int cmp_entry(const void *a, const void *b)
return 0;
}
static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *public_key, IP_Port ip_port,
uint8_t is_stored, uint8_t *pingid_or_key, IP_Port source)
static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t *public_key, IP_Port ip_port,
uint8_t is_stored, const uint8_t *pingid_or_key, IP_Port source)
{
if (num > onion_c->num_friends)
return -1;
@ -338,7 +339,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, uint8_t *publ
return 0;
}
static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, uint8_t *client_id)
static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *client_id)
{
uint32_t i;
@ -354,7 +355,7 @@ static int good_to_ping(Last_Pinged *last_pinged, uint8_t *last_pinged_index, ui
return 1;
}
static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, Node_format *nodes, uint16_t num_nodes,
static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_format *nodes, uint16_t num_nodes,
IP_Port source)
{
if (num > onion_c->num_friends)
@ -630,7 +631,7 @@ int send_onion_data(const Onion_Client *onion_c, int friend_num, const uint8_t *
* return the number of packets sent on success
* return -1 on failure.
*/
static int send_dht_fakeid(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32_t length)
static int send_dht_fakeid(const Onion_Client *onion_c, int friend_num, const uint8_t *data, uint32_t length)
{
if ((uint32_t)friend_num >= onion_c->num_friends)
return -1;
@ -693,7 +694,7 @@ static int handle_dht_fakeid(void *object, IP_Port source, const uint8_t *source
* return the number of packets sent on success
* return -1 on failure.
*/
static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
static int send_fakeid_announce(const Onion_Client *onion_c, uint16_t friend_num, uint8_t onion_dht_both)
{
if (friend_num >= onion_c->num_friends)
return -1;
@ -851,7 +852,7 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
* return 0 on success.
*/
int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object,
uint32_t number, IP_Port ip_port, uint8_t *public_key), void *object, uint32_t number)
uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number)
{
if ((uint32_t)friend_num >= onion_c->num_friends)
return -1;
@ -905,7 +906,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
* return 0 on failure (no key copied).
* return timestamp on success (key copied).
*/
uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key)
{
if ((uint32_t)friend_num >= onion_c->num_friends)
return 0;
@ -927,7 +928,7 @@ uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8
* return 1, ip if client_id refers to a friend and we found him
*
*/
int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port)
{
uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];

View File

@ -97,7 +97,7 @@ typedef struct {
Last_Pinged last_pinged[MAX_STORED_PINGED_NODES];
uint8_t last_pinged_index;
int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, uint8_t *public_key);
int (*tcp_relay_node_callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key);
void *tcp_relay_node_callback_object;
uint32_t tcp_relay_node_callback_number;
} Onion_Friend;
@ -171,7 +171,7 @@ int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_on
* return 1, ip if client_id refers to a friend and we found him
*
*/
int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port);
int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_port);
/* Set the function for this friend that will be callbacked with object and number
* when that friends gives us one of the TCP relays he is connected to.
@ -182,7 +182,7 @@ int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port);
* return 0 on success.
*/
int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object,
uint32_t number, IP_Port ip_port, uint8_t *public_key), void *object, uint32_t number);
uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number);
/* Set a friends DHT public key.
* timestamp is the time (current_time_monotonic()) at which the key was last confirmed belonging to
@ -198,7 +198,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin
* return 0 on failure (no key copied).
* return timestamp on success (key copied).
*/
uint64_t onion_getfriend_DHT_pubkey(Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
uint64_t onion_getfriend_DHT_pubkey(const Onion_Client *onion_c, int friend_num, uint8_t *dht_key);
#define ONION_DATA_IN_RESPONSE_MIN_SIZE (crypto_box_PUBLICKEYBYTES + crypto_box_MACBYTES)
#define ONION_CLIENT_MAX_DATA_SIZE (MAX_DATA_REQUEST_SIZE - ONION_DATA_IN_RESPONSE_MIN_SIZE)

View File

@ -38,9 +38,9 @@ typedef struct Messenger Tox;
* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
*
*/
void tox_get_address(Tox *tox, uint8_t *address)
void tox_get_address(const Tox *tox, uint8_t *address)
{
Messenger *m = tox;
const Messenger *m = tox;
getaddress(m, address);
}
@ -61,7 +61,7 @@ void tox_get_address(Tox *tox, uint8_t *address)
* (the nospam for that friend was set to the new one).
* return FAERR_NOMEM if increasing the friend list size fails.
*/
int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length)
int32_t tox_add_friend(Tox *tox, const uint8_t *address, const uint8_t *data, uint16_t length)
{
Messenger *m = tox;
return m_addfriend(m, address, data, length);
@ -81,9 +81,9 @@ int32_t tox_add_friend_norequest(Tox *tox, const uint8_t *client_id)
/* return the friend number associated to that client id.
* return -1 if no such friend.
*/
int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id)
int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id)
{
Messenger *m = tox;
const Messenger *m = tox;
return getfriend_id(m, client_id);
}
@ -93,9 +93,9 @@ int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id)
* return 0 if success.
* return -1 if failure.
*/
int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id)
int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id)
{
Messenger *m = tox;
const Messenger *m = tox;
return getclient_id(m, friendnumber, client_id);
}
@ -112,9 +112,9 @@ int tox_del_friend(Tox *tox, int32_t friendnumber)
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber)
int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_friend_connectionstatus(m, friendnumber);
}
@ -123,9 +123,9 @@ int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber)
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int tox_friend_exists(Tox *tox, int32_t friendnumber)
int tox_friend_exists(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_friend_exists(m, friendnumber);
}
@ -144,7 +144,8 @@ uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message
return m_sendmessage(m, friendnumber, message, length);
}
uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length)
uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *message,
uint32_t length)
{
Messenger *m = tox;
return m_sendmessage_withid(m, friendnumber, theid, message, length);
@ -160,13 +161,13 @@ uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid,
* 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.
*/
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length)
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, const uint8_t *action, uint32_t length)
{
Messenger *m = tox;
return m_sendaction(m, friendnumber, action, length);
}
uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length)
uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *action, uint32_t length)
{
Messenger *m = tox;
return m_sendaction_withid(m, friendnumber, theid, action, length);
@ -180,7 +181,7 @@ uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid,
* return 0 if success.
* return -1 if failure.
*/
int tox_set_name(Tox *tox, uint8_t *name, uint16_t length)
int tox_set_name(Tox *tox, const uint8_t *name, uint16_t length)
{
Messenger *m = tox;
return setname(m, name, length);
@ -193,9 +194,9 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length)
* return length of the name.
* return 0 on error.
*/
uint16_t tox_get_self_name(Tox *tox, uint8_t *name)
uint16_t tox_get_self_name(const Tox *tox, uint8_t *name)
{
Messenger *m = tox;
const Messenger *m = tox;
return getself_name(m, name);
}
@ -205,24 +206,24 @@ uint16_t tox_get_self_name(Tox *tox, uint8_t *name)
* return length of name (with the NULL terminator) if success.
* return -1 if failure.
*/
int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name)
int tox_get_name(const Tox *tox, int32_t friendnumber, uint8_t *name)
{
Messenger *m = tox;
const Messenger *m = tox;
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)
int tox_get_name_size(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_name_size(m, friendnumber);
}
int tox_get_self_name_size(Tox *tox)
int tox_get_self_name_size(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_self_name_size(m);
}
@ -231,7 +232,7 @@ int tox_get_self_name_size(Tox *tox)
*
* return 0 on success, -1 on failure.
*/
int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length)
int tox_set_status_message(Tox *tox, const uint8_t *status, uint16_t length)
{
Messenger *m = tox;
return m_set_statusmessage(m, status, length);
@ -246,15 +247,15 @@ int tox_set_user_status(Tox *tox, uint8_t status)
/* returns the length of status message on success.
* returns -1 on failure.
*/
int tox_get_status_message_size(Tox *tox, int32_t friendnumber)
int tox_get_status_message_size(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_statusmessage_size(m, friendnumber);
}
int tox_get_self_status_message_size(Tox *tox)
int tox_get_self_status_message_size(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_self_statusmessage_size(m);
}
@ -262,15 +263,15 @@ int tox_get_self_status_message_size(Tox *tox)
* Get the size you need to allocate from m_get_statusmessage_size.
* The self variant will copy our own status message.
*/
int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
int tox_get_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_copy_statusmessage(m, friendnumber, buf, maxlen);
}
int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen)
int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_copy_self_statusmessage(m, buf, maxlen);
}
@ -279,24 +280,24 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen)
* As above, the self variant will return our own USERSTATUS.
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
*/
uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber)
uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_userstatus(m, friendnumber);
}
uint8_t tox_get_self_user_status(Tox *tox)
uint8_t tox_get_self_user_status(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_self_userstatus(m);
}
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
* returns -1 on error.
*/
uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber)
uint64_t tox_get_last_online(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_last_online(m, friendnumber);
}
@ -317,9 +318,9 @@ int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing)
* returns 0 if friend is not typing.
* returns 1 if friend is typing.
*/
uint8_t tox_get_is_typing(Tox *tox, int32_t friendnumber)
uint8_t tox_get_is_typing(const Tox *tox, int32_t friendnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_get_istyping(m, friendnumber);
}
@ -335,16 +336,16 @@ void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno)
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t tox_count_friendlist(Tox *tox)
uint32_t tox_count_friendlist(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return count_friendlist(m);
}
/* Return the number of online friends in the instance m. */
uint32_t tox_get_num_online_friends(Tox *tox)
uint32_t tox_get_num_online_friends(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return get_num_online_friends(m);
}
@ -353,9 +354,9 @@ uint32_t tox_get_num_online_friends(Tox *tox)
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size)
uint32_t tox_get_friendlist(const Tox *tox, int32_t *out_list, uint32_t list_size)
{
Messenger *m = tox;
const Messenger *m = tox;
return copy_friendlist(m, out_list, list_size);
}
@ -373,7 +374,7 @@ void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, const uint
/* Set the function that will be executed when a message from a friend is received.
* Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
*/
void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -383,7 +384,7 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int3
/* Set the function that will be executed when an action from a friend is received.
* function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
*/
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -394,7 +395,7 @@ void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32
* function(int32_t friendnumber, uint8_t *newname, uint16_t length)
* You are not responsible for freeing newname.
*/
void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -405,7 +406,7 @@ void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t
* function(int32_t friendnumber, uint8_t *newstatus, uint16_t length)
* You are not responsible for freeing newstatus.
*/
void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -468,9 +469,9 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i
/* Functions to get/set the nospam part of the id.
*/
uint32_t tox_get_nospam(Tox *tox)
uint32_t tox_get_nospam(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return get_nospam(&(m->fr));
}
@ -486,7 +487,8 @@ void tox_set_nospam(Tox *tox, uint32_t nospam)
*
* Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
*/
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, void *), void *userdata)
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, void *),
void *userdata)
{
Messenger *m = tox;
m_callback_group_invite(m, function, userdata);
@ -496,7 +498,7 @@ void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *),
void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -507,7 +509,7 @@ void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int,
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * action, uint16_t length, void *userdata)
*/
void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *),
void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *),
void *userdata)
{
Messenger *m = tox;
@ -552,9 +554,9 @@ int tox_del_groupchat(Tox *tox, int groupnumber)
* return length of name if success
* return -1 if failure
*/
int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name)
int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name)
{
Messenger *m = tox;
const Messenger *m = tox;
return m_group_peername(m, groupnumber, peernumber, name);
}
/* invite friendnumber to groupnumber
@ -571,7 +573,7 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
* returns group number on success
* returns -1 on failure.
*/
int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key)
int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *friend_group_public_key)
{
Messenger *m = tox;
return join_groupchat(m, friendnumber, friend_group_public_key);
@ -581,7 +583,7 @@ int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_pub
* return 0 on success
* return -1 on failure
*/
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length)
int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint32_t length)
{
Messenger *m = tox;
return group_message_send(m, groupnumber, message, length);
@ -591,7 +593,7 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
* return 0 on success
* return -1 on failure
*/
int tox_group_action_send(Tox *tox, int groupnumber, uint8_t *action, uint32_t length)
int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint32_t length)
{
Messenger *m = tox;
return group_action_send(m, groupnumber, action, length);
@ -600,9 +602,9 @@ int tox_group_action_send(Tox *tox, int groupnumber, uint8_t *action, uint32_t l
/* Return the number of peers in the group chat on success.
* return -1 on failure
*/
int tox_group_number_peers(Tox *tox, int groupnumber)
int tox_group_number_peers(const Tox *tox, int groupnumber)
{
Messenger *m = tox;
const Messenger *m = tox;
return group_number_peers(m, groupnumber);
}
@ -616,19 +618,19 @@ int tox_group_number_peers(Tox *tox, int groupnumber)
*
* return -1 on failure.
*/
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
uint16_t length)
{
Messenger *m = tox;
const Messenger *m = tox;
return group_names(m, groupnumber, names, lengths, length);
}
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_chatlist. */
uint32_t tox_count_chatlist(Tox *tox)
uint32_t tox_count_chatlist(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return count_chatlist(m);
}
@ -637,9 +639,9 @@ uint32_t tox_count_chatlist(Tox *tox)
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size)
uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size)
{
Messenger *m = tox;
const Messenger *m = tox;
return copy_chatlist(m, out_list, list_size);
}
@ -651,9 +653,8 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size)
*
* 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, int32_t, uint8_t, uint64_t, uint8_t *,
uint16_t,
void *), void *userdata)
void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t,
const uint8_t *, uint16_t, void *), void *userdata)
{
Messenger *m = tox;
callback_file_sendrequest(m, function, userdata);
@ -663,8 +664,8 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, i
* 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, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *,
uint16_t, void *), void *userdata)
void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t,
const uint8_t *, uint16_t, void *), void *userdata)
{
Messenger *m = tox;
callback_file_control(m, function, userdata);
@ -674,9 +675,8 @@ void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_
* 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, int32_t, uint8_t, uint8_t *, uint16_t length,
void *),
void *userdata)
void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *,
uint16_t length, void *), void *userdata)
{
Messenger *m = tox;
@ -687,7 +687,8 @@ void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t,
* return file number on success
* return -1 on failure
*/
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length)
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
uint16_t filename_length)
{
Messenger *m = tox;
return new_filesender(m, friendnumber, filesize, filename, filename_length);
@ -699,7 +700,7 @@ int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8
* return -1 on failure
*/
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)
const uint8_t *data, uint16_t length)
{
Messenger *m = tox;
return file_control(m, friendnumber, send_receive, filenumber, message_id, data, length);
@ -709,7 +710,7 @@ int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive,
* return 0 on success
* return -1 on failure
*/
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length)
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length)
{
Messenger *m = tox;
return file_data(m, friendnumber, filenumber, data, length);
@ -720,7 +721,7 @@ int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8
* return size on success
* return -1 on failure (currently will never return -1)
*/
int tox_file_data_size(Tox *tox, int32_t friendnumber)
int tox_file_data_size(const Tox *tox, int32_t friendnumber)
{
return MAX_CRYPTO_DATA_SIZE - 2;
}
@ -732,16 +733,17 @@ int tox_file_data_size(Tox *tox, int32_t friendnumber)
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
{
Messenger *m = tox;
const Messenger *m = tox;
return file_dataremaining(m, friendnumber, filenumber, send_receive);
}
/***************END OF FILE SENDING FUNCTIONS******************/
/* TODO: expose this properly. */
static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, uint16_t port, uint8_t *public_key)
static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, uint16_t port,
const uint8_t *public_key)
{
Messenger *m = tox;
IP_Port ip_port_v64;
@ -766,7 +768,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled,
}
int tox_bootstrap_from_address(Tox *tox, const char *address,
uint8_t ipv6enabled, uint16_t port, uint8_t *public_key)
uint8_t ipv6enabled, uint16_t port, const uint8_t *public_key)
{
Messenger *m = tox;
tox_add_tcp_relay(tox, address, ipv6enabled, port, public_key);
@ -776,9 +778,9 @@ int tox_bootstrap_from_address(Tox *tox, const char *address,
/* return 0 if we are not connected to the DHT.
* return 1 if we are.
*/
int tox_isconnected(Tox *tox)
int tox_isconnected(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return DHT_isconnected(m->dht);
}
@ -823,21 +825,21 @@ void tox_do(Tox *tox)
/* SAVING AND LOADING FUNCTIONS: */
/* return size of the messenger data (for saving). */
uint32_t tox_size(Tox *tox)
uint32_t tox_size(const Tox *tox)
{
Messenger *m = tox;
const Messenger *m = tox;
return messenger_size(m);
}
/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
void tox_save(Tox *tox, uint8_t *data)
void tox_save(const Tox *tox, uint8_t *data)
{
Messenger *m = tox;
const Messenger *m = tox;
messenger_save(m, data);
}
/* Load the messenger from data of size length. */
int tox_load(Tox *tox, uint8_t *data, uint32_t length)
int tox_load(Tox *tox, const uint8_t *data, uint32_t length)
{
Messenger *m = tox;
return messenger_load(m, data, length);

View File

@ -82,7 +82,7 @@ typedef struct Tox Tox;
/* return TOX_FRIEND_ADDRESS_SIZE byte address to give to others.
* format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
*/
void tox_get_address(Tox *tox, uint8_t *address);
void tox_get_address(const Tox *tox, uint8_t *address);
/* Add a friend.
* Set the data that will be sent along with friend request.
@ -100,7 +100,7 @@ void tox_get_address(Tox *tox, uint8_t *address);
* (the nospam for that friend was set to the new one).
* return TOX_FAERR_NOMEM if increasing the friend list size fails.
*/
int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length);
int32_t tox_add_friend(Tox *tox, const uint8_t *address, const uint8_t *data, uint16_t length);
/* Add a friend without sending a friendrequest.
@ -111,14 +111,14 @@ int32_t tox_add_friend_norequest(Tox *tox, const uint8_t *client_id);
/* return the friend number associated to that client id.
return -1 if no such friend */
int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id);
int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id);
/* Copies the public key associated to that friend id into client_id buffer.
* Make sure that client_id is of size CLIENT_ID_SIZE.
* return 0 if success.
* return -1 if failure.
*/
int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id);
int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id);
/* Remove a friend.
*
@ -133,14 +133,14 @@ int tox_del_friend(Tox *tox, int32_t friendnumber);
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber);
int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber);
/* Checks if there exists a friend with given friendnumber.
*
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int tox_friend_exists(Tox *tox, int32_t friendnumber);
int tox_friend_exists(const Tox *tox, int32_t friendnumber);
/* Send a text chat message to an online friend.
*
@ -157,7 +157,8 @@ int tox_friend_exists(Tox *tox, int32_t friendnumber);
* however we can generate an id for you by calling plain m_sendmessage.
*/
uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const 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);
uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *message,
uint32_t length);
/* Send an action to an online friend.
*
@ -173,8 +174,8 @@ uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid,
* 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.
*/
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, 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);
uint32_t tox_send_action(Tox *tox, int32_t friendnumber, const uint8_t *action, uint32_t length);
uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *action, uint32_t length);
/* Set our nickname.
* name must be a string of maximum MAX_NAME_LENGTH length.
@ -184,7 +185,7 @@ uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid,
* return 0 if success.
* return -1 if failure.
*/
int tox_set_name(Tox *tox, uint8_t *name, uint16_t length);
int tox_set_name(Tox *tox, const uint8_t *name, uint16_t length);
/*
* Get your nickname.
@ -194,7 +195,7 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length);
* return length of name.
* return 0 on error.
*/
uint16_t tox_get_self_name(Tox *tox, uint8_t *name);
uint16_t tox_get_self_name(const Tox *tox, uint8_t *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.
@ -202,13 +203,13 @@ uint16_t tox_get_self_name(Tox *tox, uint8_t *name);
* return length of name if success.
* return -1 if failure.
*/
int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name);
int tox_get_name(const 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);
int tox_get_name_size(const Tox *tox, int32_t friendnumber);
int tox_get_self_name_size(const Tox *tox);
/* Set our user status.
*
@ -218,14 +219,14 @@ int tox_get_self_name_size(Tox *tox);
* returns 0 on success.
* returns -1 on failure.
*/
int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length);
int tox_set_status_message(Tox *tox, const uint8_t *status, uint16_t length);
int tox_set_user_status(Tox *tox, uint8_t userstatus);
/* returns the length of status message on success.
* returns -1 on failure.
*/
int tox_get_status_message_size(Tox *tox, int32_t friendnumber);
int tox_get_self_status_message_size(Tox *tox);
int tox_get_status_message_size(const Tox *tox, int32_t friendnumber);
int tox_get_self_status_message_size(const Tox *tox);
/* 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.
@ -234,22 +235,22 @@ int tox_get_self_status_message_size(Tox *tox);
* returns the length of the copied data on success
* retruns -1 on failure.
*/
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_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen);
/* return one of TOX_USERSTATUS values.
* Values unknown to your application should be represented as TOX_USERSTATUS_NONE.
* As above, the self variant will return our own TOX_USERSTATUS.
* If friendnumber is invalid, this shall return TOX_USERSTATUS_INVALID.
*/
uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber);
uint8_t tox_get_self_user_status(Tox *tox);
uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber);
uint8_t tox_get_self_user_status(const Tox *tox);
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
* returns -1 on error.
*/
uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber);
uint64_t tox_get_last_online(const Tox *tox, int32_t friendnumber);
/* Set our typing status for a friend.
* You are responsible for turning it on or off.
@ -264,7 +265,7 @@ int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing);
* returns 0 if friend is not typing.
* returns 1 if friend is typing.
*/
uint8_t tox_get_is_typing(Tox *tox, int32_t friendnumber);
uint8_t tox_get_is_typing(const Tox *tox, int32_t 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).
@ -274,17 +275,17 @@ void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno);
/* Return the number of friends in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t tox_count_friendlist(Tox *tox);
uint32_t tox_count_friendlist(const Tox *tox);
/* Return the number of online friends in the instance m. */
uint32_t tox_get_num_online_friends(Tox *tox);
uint32_t tox_get_num_online_friends(const Tox *tox);
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size);
uint32_t tox_get_friendlist(const Tox *tox, int32_t *out_list, uint32_t list_size);
/* Set the function that will be executed when a friend request is received.
* Function format is function(Tox *tox, uint8_t * public_key, uint8_t * data, uint16_t length, void *userdata)
@ -295,27 +296,27 @@ void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, const uint
/* Set the function that will be executed when a message from a friend is received.
* Function format is: function(Tox *tox, int32_t friendnumber, uint8_t * message, uint32_t length, void *userdata)
*/
void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_friend_message(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the function that will be executed when an action from a friend is received.
* 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, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_friend_action(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for name changes.
* function(Tox *tox, int32_t friendnumber, uint8_t *newname, uint16_t length, void *userdata)
* You are not responsible for freeing newname
*/
void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_name_change(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for status message changes.
* function(Tox *tox, int32_t friendnumber, uint8_t *newstatus, uint16_t length, void *userdata)
* You are not responsible for freeing newstatus.
*/
void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, uint16_t, void *),
void tox_callback_status_message(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for status type changes.
@ -357,7 +358,7 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int32_t
/* Functions to get/set the nospam part of the id.
*/
uint32_t tox_get_nospam(Tox *tox);
uint32_t tox_get_nospam(const Tox *tox);
void tox_set_nospam(Tox *tox, uint32_t nospam);
@ -367,20 +368,20 @@ void tox_set_nospam(Tox *tox, uint32_t nospam);
*
* Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata)
*/
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t *, void *), void *userdata);
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, void *), void *userdata);
/* Set the callback for group messages.
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
*/
void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t *, uint16_t, void *),
void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set the callback for group actions.
*
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * action, uint16_t length, void *userdata)
*/
void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t *, uint16_t, void *),
void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *),
void *userdata);
/* Set callback function for peer name list changes.
@ -417,7 +418,7 @@ int tox_del_groupchat(Tox *tox, int groupnumber);
* return length of name if success
* return -1 if failure
*/
int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name);
int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name);
/* invite friendnumber to groupnumber
* return 0 on success
@ -430,24 +431,24 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber);
* returns group number on success
* returns -1 on failure.
*/
int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key);
int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *friend_group_public_key);
/* send a group message
* return 0 on success
* return -1 on failure
*/
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint32_t length);
/* send a group action
* return 0 on success
* return -1 on failure
*/
int tox_group_action_send(Tox *tox, int groupnumber, uint8_t *action, uint32_t length);
int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint32_t length);
/* Return the number of peers in the group chat on success.
* return -1 on failure
*/
int tox_group_number_peers(Tox *tox, int groupnumber);
int tox_group_number_peers(const Tox *tox, int groupnumber);
/* List all the peers in the group chat.
*
@ -459,20 +460,20 @@ int tox_group_number_peers(Tox *tox, int groupnumber);
*
* return -1 on failure.
*/
int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
uint16_t length);
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_chatlist. */
uint32_t tox_count_chatlist(Tox *tox);
uint32_t tox_count_chatlist(const Tox *tox);
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size);
uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size);
/****************FILE SENDING FUNCTIONS*****************/
@ -523,8 +524,8 @@ enum {
*
* 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, int32_t, uint8_t, uint64_t, uint8_t *, uint16_t,
void *), void *userdata);
void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, uint64_t, const uint8_t *,
uint16_t, void *), void *userdata);
/* Set the callback for file control requests.
*
@ -534,7 +535,7 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Tox *m, int32_t,
* 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, int32_t, 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, const uint8_t *,
uint16_t, void *), void *userdata);
/* Set the callback for file data.
@ -542,8 +543,8 @@ void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int32_t, uint8
* 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, int32_t, uint8_t, uint8_t *, uint16_t length, void *),
void *userdata);
void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t, const uint8_t *, uint16_t length,
void *), void *userdata);
/* Send a file send request.
@ -551,7 +552,8 @@ void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int32_t, uint8_t,
* return file number on success
* return -1 on failure
*/
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
uint16_t filename_length);
/* Send a file control request.
*
@ -562,21 +564,21 @@ int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8
* return -1 on failure
*/
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);
const uint8_t *data, uint16_t length);
/* Send file data.
*
* return 0 on success
* return -1 on failure
*/
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length);
/* Returns the recommended/maximum size of the filedata you send with tox_file_send_data()
*
* return size on success
* return -1 on failure (currently will never return -1)
*/
int tox_file_data_size(Tox *tox, int32_t friendnumber);
int tox_file_data_size(const Tox *tox, int32_t friendnumber);
/* Give the number of bytes left to be sent/received.
*
@ -585,7 +587,7 @@ int tox_file_data_size(Tox *tox, int32_t friendnumber);
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
/***************END OF FILE SENDING FUNCTIONS******************/
@ -606,12 +608,12 @@ uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenum
* returns 0 otherwise
*/
int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enabled,
uint16_t port, uint8_t *public_key);
uint16_t port, const uint8_t *public_key);
/* return 0 if we are not connected to the DHT.
* return 1 if we are.
*/
int tox_isconnected(Tox *tox);
int tox_isconnected(const Tox *tox);
/*
* Run this function at startup.
@ -645,17 +647,17 @@ void tox_do(Tox *tox);
/* SAVING AND LOADING FUNCTIONS: */
/* return size of messenger data (for saving). */
uint32_t tox_size(Tox *tox);
uint32_t tox_size(const Tox *tox);
/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
void tox_save(Tox *tox, uint8_t *data);
void tox_save(const Tox *tox, uint8_t *data);
/* Load the messenger from data of size length.
*
* returns 0 on success
* returns -1 on failure
*/
int tox_load(Tox *tox, uint8_t *data, uint32_t length);
int tox_load(Tox *tox, const uint8_t *data, uint32_t length);
#ifdef __cplusplus
}