summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c184
1 files changed, 93 insertions, 91 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 79e4c042..1b6597ba 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -38,9 +38,9 @@ typedef struct Messenger Tox;
38 * Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] 38 * Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
39 * 39 *
40 */ 40 */
41void tox_get_address(Tox *tox, uint8_t *address) 41void tox_get_address(const Tox *tox, uint8_t *address)
42{ 42{
43 Messenger *m = tox; 43 const Messenger *m = tox;
44 getaddress(m, address); 44 getaddress(m, address);
45} 45}
46 46
@@ -61,7 +61,7 @@ void tox_get_address(Tox *tox, uint8_t *address)
61 * (the nospam for that friend was set to the new one). 61 * (the nospam for that friend was set to the new one).
62 * return FAERR_NOMEM if increasing the friend list size fails. 62 * return FAERR_NOMEM if increasing the friend list size fails.
63 */ 63 */
64int32_t tox_add_friend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length) 64int32_t tox_add_friend(Tox *tox, const uint8_t *address, const uint8_t *data, uint16_t length)
65{ 65{
66 Messenger *m = tox; 66 Messenger *m = tox;
67 return m_addfriend(m, address, data, length); 67 return m_addfriend(m, address, data, length);
@@ -81,9 +81,9 @@ int32_t tox_add_friend_norequest(Tox *tox, const uint8_t *client_id)
81/* return the friend number associated to that client id. 81/* return the friend number associated to that client id.
82 * return -1 if no such friend. 82 * return -1 if no such friend.
83 */ 83 */
84int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id) 84int32_t tox_get_friend_number(const Tox *tox, const uint8_t *client_id)
85{ 85{
86 Messenger *m = tox; 86 const Messenger *m = tox;
87 return getfriend_id(m, client_id); 87 return getfriend_id(m, client_id);
88} 88}
89 89
@@ -93,9 +93,9 @@ int32_t tox_get_friend_number(Tox *tox, uint8_t *client_id)
93 * return 0 if success. 93 * return 0 if success.
94 * return -1 if failure. 94 * return -1 if failure.
95 */ 95 */
96int tox_get_client_id(Tox *tox, int32_t friendnumber, uint8_t *client_id) 96int tox_get_client_id(const Tox *tox, int32_t friendnumber, uint8_t *client_id)
97{ 97{
98 Messenger *m = tox; 98 const Messenger *m = tox;
99 return getclient_id(m, friendnumber, client_id); 99 return getclient_id(m, friendnumber, client_id);
100} 100}
101 101
@@ -112,9 +112,9 @@ int tox_del_friend(Tox *tox, int32_t friendnumber)
112 * return 0 if friend is not connected to us (Offline). 112 * return 0 if friend is not connected to us (Offline).
113 * return -1 on failure. 113 * return -1 on failure.
114 */ 114 */
115int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber) 115int tox_get_friend_connection_status(const Tox *tox, int32_t friendnumber)
116{ 116{
117 Messenger *m = tox; 117 const Messenger *m = tox;
118 return m_get_friend_connectionstatus(m, friendnumber); 118 return m_get_friend_connectionstatus(m, friendnumber);
119} 119}
120 120
@@ -123,9 +123,9 @@ int tox_get_friend_connection_status(Tox *tox, int32_t friendnumber)
123 * return 1 if friend exists. 123 * return 1 if friend exists.
124 * return 0 if friend doesn't exist. 124 * return 0 if friend doesn't exist.
125 */ 125 */
126int tox_friend_exists(Tox *tox, int32_t friendnumber) 126int tox_friend_exists(const Tox *tox, int32_t friendnumber)
127{ 127{
128 Messenger *m = tox; 128 const Messenger *m = tox;
129 return m_friend_exists(m, friendnumber); 129 return m_friend_exists(m, friendnumber);
130} 130}
131 131
@@ -144,7 +144,8 @@ uint32_t tox_send_message(Tox *tox, int32_t friendnumber, const uint8_t *message
144 return m_sendmessage(m, friendnumber, message, length); 144 return m_sendmessage(m, friendnumber, message, length);
145} 145}
146 146
147uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *message, uint32_t length) 147uint32_t tox_send_message_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *message,
148 uint32_t length)
148{ 149{
149 Messenger *m = tox; 150 Messenger *m = tox;
150 return m_sendmessage_withid(m, friendnumber, theid, message, length); 151 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,
160 * m_sendaction_withid will send an action message with the id of your choosing, 161 * m_sendaction_withid will send an action message with the id of your choosing,
161 * however we can generate an id for you by calling plain m_sendaction. 162 * however we can generate an id for you by calling plain m_sendaction.
162 */ 163 */
163uint32_t tox_send_action(Tox *tox, int32_t friendnumber, uint8_t *action, uint32_t length) 164uint32_t tox_send_action(Tox *tox, int32_t friendnumber, const uint8_t *action, uint32_t length)
164{ 165{
165 Messenger *m = tox; 166 Messenger *m = tox;
166 return m_sendaction(m, friendnumber, action, length); 167 return m_sendaction(m, friendnumber, action, length);
167} 168}
168 169
169uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, uint8_t *action, uint32_t length) 170uint32_t tox_send_action_withid(Tox *tox, int32_t friendnumber, uint32_t theid, const uint8_t *action, uint32_t length)
170{ 171{
171 Messenger *m = tox; 172 Messenger *m = tox;
172 return m_sendaction_withid(m, friendnumber, theid, action, length); 173 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,
180 * return 0 if success. 181 * return 0 if success.
181 * return -1 if failure. 182 * return -1 if failure.
182 */ 183 */
183int tox_set_name(Tox *tox, uint8_t *name, uint16_t length) 184int tox_set_name(Tox *tox, const uint8_t *name, uint16_t length)
184{ 185{
185 Messenger *m = tox; 186 Messenger *m = tox;
186 return setname(m, name, length); 187 return setname(m, name, length);
@@ -193,9 +194,9 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length)
193 * return length of the name. 194 * return length of the name.
194 * return 0 on error. 195 * return 0 on error.
195 */ 196 */
196uint16_t tox_get_self_name(Tox *tox, uint8_t *name) 197uint16_t tox_get_self_name(const Tox *tox, uint8_t *name)
197{ 198{
198 Messenger *m = tox; 199 const Messenger *m = tox;
199 return getself_name(m, name); 200 return getself_name(m, name);
200} 201}
201 202
@@ -205,24 +206,24 @@ uint16_t tox_get_self_name(Tox *tox, uint8_t *name)
205 * return length of name (with the NULL terminator) if success. 206 * return length of name (with the NULL terminator) if success.
206 * return -1 if failure. 207 * return -1 if failure.
207 */ 208 */
208int tox_get_name(Tox *tox, int32_t friendnumber, uint8_t *name) 209int tox_get_name(const Tox *tox, int32_t friendnumber, uint8_t *name)
209{ 210{
210 Messenger *m = tox; 211 const Messenger *m = tox;
211 return getname(m, friendnumber, name); 212 return getname(m, friendnumber, name);
212} 213}
213 214
214/* returns the length of name on success. 215/* returns the length of name on success.
215 * returns -1 on failure. 216 * returns -1 on failure.
216 */ 217 */
217int tox_get_name_size(Tox *tox, int32_t friendnumber) 218int tox_get_name_size(const Tox *tox, int32_t friendnumber)
218{ 219{
219 Messenger *m = tox; 220 const Messenger *m = tox;
220 return m_get_name_size(m, friendnumber); 221 return m_get_name_size(m, friendnumber);
221} 222}
222 223
223int tox_get_self_name_size(Tox *tox) 224int tox_get_self_name_size(const Tox *tox)
224{ 225{
225 Messenger *m = tox; 226 const Messenger *m = tox;
226 return m_get_self_name_size(m); 227 return m_get_self_name_size(m);
227} 228}
228 229
@@ -231,7 +232,7 @@ int tox_get_self_name_size(Tox *tox)
231 * 232 *
232 * return 0 on success, -1 on failure. 233 * return 0 on success, -1 on failure.
233 */ 234 */
234int tox_set_status_message(Tox *tox, uint8_t *status, uint16_t length) 235int tox_set_status_message(Tox *tox, const uint8_t *status, uint16_t length)
235{ 236{
236 Messenger *m = tox; 237 Messenger *m = tox;
237 return m_set_statusmessage(m, status, length); 238 return m_set_statusmessage(m, status, length);
@@ -246,15 +247,15 @@ int tox_set_user_status(Tox *tox, uint8_t status)
246/* returns the length of status message on success. 247/* returns the length of status message on success.
247 * returns -1 on failure. 248 * returns -1 on failure.
248 */ 249 */
249int tox_get_status_message_size(Tox *tox, int32_t friendnumber) 250int tox_get_status_message_size(const Tox *tox, int32_t friendnumber)
250{ 251{
251 Messenger *m = tox; 252 const Messenger *m = tox;
252 return m_get_statusmessage_size(m, friendnumber); 253 return m_get_statusmessage_size(m, friendnumber);
253} 254}
254 255
255int tox_get_self_status_message_size(Tox *tox) 256int tox_get_self_status_message_size(const Tox *tox)
256{ 257{
257 Messenger *m = tox; 258 const Messenger *m = tox;
258 return m_get_self_statusmessage_size(m); 259 return m_get_self_statusmessage_size(m);
259} 260}
260 261
@@ -262,15 +263,15 @@ int tox_get_self_status_message_size(Tox *tox)
262 * Get the size you need to allocate from m_get_statusmessage_size. 263 * Get the size you need to allocate from m_get_statusmessage_size.
263 * The self variant will copy our own status message. 264 * The self variant will copy our own status message.
264 */ 265 */
265int tox_get_status_message(Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen) 266int tox_get_status_message(const Tox *tox, int32_t friendnumber, uint8_t *buf, uint32_t maxlen)
266{ 267{
267 Messenger *m = tox; 268 const Messenger *m = tox;
268 return m_copy_statusmessage(m, friendnumber, buf, maxlen); 269 return m_copy_statusmessage(m, friendnumber, buf, maxlen);
269} 270}
270 271
271int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen) 272int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen)
272{ 273{
273 Messenger *m = tox; 274 const Messenger *m = tox;
274 return m_copy_self_statusmessage(m, buf, maxlen); 275 return m_copy_self_statusmessage(m, buf, maxlen);
275} 276}
276 277
@@ -279,24 +280,24 @@ int tox_get_self_status_message(Tox *tox, uint8_t *buf, uint32_t maxlen)
279 * As above, the self variant will return our own USERSTATUS. 280 * As above, the self variant will return our own USERSTATUS.
280 * If friendnumber is invalid, this shall return USERSTATUS_INVALID. 281 * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
281 */ 282 */
282uint8_t tox_get_user_status(Tox *tox, int32_t friendnumber) 283uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber)
283{ 284{
284 Messenger *m = tox; 285 const Messenger *m = tox;
285 return m_get_userstatus(m, friendnumber); 286 return m_get_userstatus(m, friendnumber);
286} 287}
287 288
288uint8_t tox_get_self_user_status(Tox *tox) 289uint8_t tox_get_self_user_status(const Tox *tox)
289{ 290{
290 Messenger *m = tox; 291 const Messenger *m = tox;
291 return m_get_self_userstatus(m); 292 return m_get_self_userstatus(m);
292} 293}
293 294
294/* returns timestamp of last time friendnumber was seen online, or 0 if never seen. 295/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
295 * returns -1 on error. 296 * returns -1 on error.
296 */ 297 */
297uint64_t tox_get_last_online(Tox *tox, int32_t friendnumber) 298uint64_t tox_get_last_online(const Tox *tox, int32_t friendnumber)
298{ 299{
299 Messenger *m = tox; 300 const Messenger *m = tox;
300 return m_get_last_online(m, friendnumber); 301 return m_get_last_online(m, friendnumber);
301} 302}
302 303
@@ -317,9 +318,9 @@ int tox_set_user_is_typing(Tox *tox, int32_t friendnumber, uint8_t is_typing)
317 * returns 0 if friend is not typing. 318 * returns 0 if friend is not typing.
318 * returns 1 if friend is typing. 319 * returns 1 if friend is typing.
319 */ 320 */
320uint8_t tox_get_is_typing(Tox *tox, int32_t friendnumber) 321uint8_t tox_get_is_typing(const Tox *tox, int32_t friendnumber)
321{ 322{
322 Messenger *m = tox; 323 const Messenger *m = tox;
323 return m_get_istyping(m, friendnumber); 324 return m_get_istyping(m, friendnumber);
324} 325}
325 326
@@ -335,16 +336,16 @@ void tox_set_sends_receipts(Tox *tox, int32_t friendnumber, int yesno)
335/* Return the number of friends in the instance m. 336/* Return the number of friends in the instance m.
336 * You should use this to determine how much memory to allocate 337 * You should use this to determine how much memory to allocate
337 * for copy_friendlist. */ 338 * for copy_friendlist. */
338uint32_t tox_count_friendlist(Tox *tox) 339uint32_t tox_count_friendlist(const Tox *tox)
339{ 340{
340 Messenger *m = tox; 341 const Messenger *m = tox;
341 return count_friendlist(m); 342 return count_friendlist(m);
342} 343}
343 344
344/* Return the number of online friends in the instance m. */ 345/* Return the number of online friends in the instance m. */
345uint32_t tox_get_num_online_friends(Tox *tox) 346uint32_t tox_get_num_online_friends(const Tox *tox)
346{ 347{
347 Messenger *m = tox; 348 const Messenger *m = tox;
348 return get_num_online_friends(m); 349 return get_num_online_friends(m);
349} 350}
350 351
@@ -353,9 +354,9 @@ uint32_t tox_get_num_online_friends(Tox *tox)
353 * Otherwise, returns the number of elements copied. 354 * Otherwise, returns the number of elements copied.
354 * If the array was too small, the contents 355 * If the array was too small, the contents
355 * of out_list will be truncated to list_size. */ 356 * of out_list will be truncated to list_size. */
356uint32_t tox_get_friendlist(Tox *tox, int32_t *out_list, uint32_t list_size) 357uint32_t tox_get_friendlist(const Tox *tox, int32_t *out_list, uint32_t list_size)
357{ 358{
358 Messenger *m = tox; 359 const Messenger *m = tox;
359 return copy_friendlist(m, out_list, list_size); 360 return copy_friendlist(m, out_list, list_size);
360} 361}
361 362
@@ -373,7 +374,7 @@ void tox_callback_friend_request(Tox *tox, void (*function)(Tox *tox, const uint
373/* Set the function that will be executed when a message from a friend is received. 374/* Set the function that will be executed when a message from a friend is received.
374 * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length) 375 * Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
375 */ 376 */
376void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), 377void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
377 void *userdata) 378 void *userdata)
378{ 379{
379 Messenger *m = tox; 380 Messenger *m = tox;
@@ -383,7 +384,7 @@ void tox_callback_friend_message(Tox *tox, void (*function)(Messenger *tox, int3
383/* Set the function that will be executed when an action from a friend is received. 384/* Set the function that will be executed when an action from a friend is received.
384 * function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length) 385 * function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
385 */ 386 */
386void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), 387void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
387 void *userdata) 388 void *userdata)
388{ 389{
389 Messenger *m = tox; 390 Messenger *m = tox;
@@ -394,7 +395,7 @@ void tox_callback_friend_action(Tox *tox, void (*function)(Messenger *tox, int32
394 * function(int32_t friendnumber, uint8_t *newname, uint16_t length) 395 * function(int32_t friendnumber, uint8_t *newname, uint16_t length)
395 * You are not responsible for freeing newname. 396 * You are not responsible for freeing newname.
396 */ 397 */
397void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), 398void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
398 void *userdata) 399 void *userdata)
399{ 400{
400 Messenger *m = tox; 401 Messenger *m = tox;
@@ -405,7 +406,7 @@ void tox_callback_name_change(Tox *tox, void (*function)(Messenger *tox, int32_t
405 * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length) 406 * function(int32_t friendnumber, uint8_t *newstatus, uint16_t length)
406 * You are not responsible for freeing newstatus. 407 * You are not responsible for freeing newstatus.
407 */ 408 */
408void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, uint16_t, void *), 409void tox_callback_status_message(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
409 void *userdata) 410 void *userdata)
410{ 411{
411 Messenger *m = tox; 412 Messenger *m = tox;
@@ -468,9 +469,9 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i
468 469
469/* Functions to get/set the nospam part of the id. 470/* Functions to get/set the nospam part of the id.
470 */ 471 */
471uint32_t tox_get_nospam(Tox *tox) 472uint32_t tox_get_nospam(const Tox *tox)
472{ 473{
473 Messenger *m = tox; 474 const Messenger *m = tox;
474 return get_nospam(&(m->fr)); 475 return get_nospam(&(m->fr));
475} 476}
476 477
@@ -486,7 +487,8 @@ void tox_set_nospam(Tox *tox, uint32_t nospam)
486 * 487 *
487 * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata) 488 * Function(Tox *tox, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
488 */ 489 */
489void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t *, void *), void *userdata) 490void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, void *),
491 void *userdata)
490{ 492{
491 Messenger *m = tox; 493 Messenger *m = tox;
492 m_callback_group_invite(m, function, userdata); 494 m_callback_group_invite(m, function, userdata);
@@ -496,7 +498,7 @@ void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_
496 * 498 *
497 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) 499 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
498 */ 500 */
499void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *), 501void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *),
500 void *userdata) 502 void *userdata)
501{ 503{
502 Messenger *m = tox; 504 Messenger *m = tox;
@@ -507,7 +509,7 @@ void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int,
507 * 509 *
508 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * action, uint16_t length, void *userdata) 510 * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * action, uint16_t length, void *userdata)
509 */ 511 */
510void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *), 512void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *),
511 void *userdata) 513 void *userdata)
512{ 514{
513 Messenger *m = tox; 515 Messenger *m = tox;
@@ -552,9 +554,9 @@ int tox_del_groupchat(Tox *tox, int groupnumber)
552 * return length of name if success 554 * return length of name if success
553 * return -1 if failure 555 * return -1 if failure
554 */ 556 */
555int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name) 557int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name)
556{ 558{
557 Messenger *m = tox; 559 const Messenger *m = tox;
558 return m_group_peername(m, groupnumber, peernumber, name); 560 return m_group_peername(m, groupnumber, peernumber, name);
559} 561}
560/* invite friendnumber to groupnumber 562/* invite friendnumber to groupnumber
@@ -571,7 +573,7 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
571 * returns group number on success 573 * returns group number on success
572 * returns -1 on failure. 574 * returns -1 on failure.
573 */ 575 */
574int tox_join_groupchat(Tox *tox, int32_t friendnumber, uint8_t *friend_group_public_key) 576int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *friend_group_public_key)
575{ 577{
576 Messenger *m = tox; 578 Messenger *m = tox;
577 return join_groupchat(m, friendnumber, friend_group_public_key); 579 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
581 * return 0 on success 583 * return 0 on success
582 * return -1 on failure 584 * return -1 on failure
583 */ 585 */
584int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length) 586int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint32_t length)
585{ 587{
586 Messenger *m = tox; 588 Messenger *m = tox;
587 return group_message_send(m, groupnumber, message, length); 589 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
591 * return 0 on success 593 * return 0 on success
592 * return -1 on failure 594 * return -1 on failure
593 */ 595 */
594int tox_group_action_send(Tox *tox, int groupnumber, uint8_t *action, uint32_t length) 596int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint32_t length)
595{ 597{
596 Messenger *m = tox; 598 Messenger *m = tox;
597 return group_action_send(m, groupnumber, action, length); 599 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
600/* Return the number of peers in the group chat on success. 602/* Return the number of peers in the group chat on success.
601 * return -1 on failure 603 * return -1 on failure
602 */ 604 */
603int tox_group_number_peers(Tox *tox, int groupnumber) 605int tox_group_number_peers(const Tox *tox, int groupnumber)
604{ 606{
605 Messenger *m = tox; 607 const Messenger *m = tox;
606 return group_number_peers(m, groupnumber); 608 return group_number_peers(m, groupnumber);
607} 609}
608 610
@@ -616,19 +618,19 @@ int tox_group_number_peers(Tox *tox, int groupnumber)
616 * 618 *
617 * return -1 on failure. 619 * return -1 on failure.
618 */ 620 */
619int tox_group_get_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], 621int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
620 uint16_t length) 622 uint16_t length)
621{ 623{
622 Messenger *m = tox; 624 const Messenger *m = tox;
623 return group_names(m, groupnumber, names, lengths, length); 625 return group_names(m, groupnumber, names, lengths, length);
624} 626}
625 627
626/* Return the number of chats in the instance m. 628/* Return the number of chats in the instance m.
627 * You should use this to determine how much memory to allocate 629 * You should use this to determine how much memory to allocate
628 * for copy_chatlist. */ 630 * for copy_chatlist. */
629uint32_t tox_count_chatlist(Tox *tox) 631uint32_t tox_count_chatlist(const Tox *tox)
630{ 632{
631 Messenger *m = tox; 633 const Messenger *m = tox;
632 return count_chatlist(m); 634 return count_chatlist(m);
633} 635}
634 636
@@ -637,9 +639,9 @@ uint32_t tox_count_chatlist(Tox *tox)
637 * Otherwise, returns the number of elements copied. 639 * Otherwise, returns the number of elements copied.
638 * If the array was too small, the contents 640 * If the array was too small, the contents
639 * of out_list will be truncated to list_size. */ 641 * of out_list will be truncated to list_size. */
640uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size) 642uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size)
641{ 643{
642 Messenger *m = tox; 644 const Messenger *m = tox;
643 return copy_chatlist(m, out_list, list_size); 645 return copy_chatlist(m, out_list, list_size);
644} 646}
645 647
@@ -651,9 +653,8 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size)
651 * 653 *
652 * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) 654 * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
653 */ 655 */
654void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t, uint8_t *, 656void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint64_t,
655 uint16_t, 657 const uint8_t *, uint16_t, void *), void *userdata)
656 void *), void *userdata)
657{ 658{
658 Messenger *m = tox; 659 Messenger *m = tox;
659 callback_file_sendrequest(m, function, userdata); 660 callback_file_sendrequest(m, function, userdata);
@@ -663,8 +664,8 @@ void tox_callback_file_send_request(Tox *tox, void (*function)(Messenger *tox, i
663 * 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) 664 * 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)
664 * 665 *
665 */ 666 */
666void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t, uint8_t *, 667void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t, uint8_t,
667 uint16_t, void *), void *userdata) 668 const uint8_t *, uint16_t, void *), void *userdata)
668{ 669{
669 Messenger *m = tox; 670 Messenger *m = tox;
670 callback_file_control(m, function, userdata); 671 callback_file_control(m, function, userdata);
@@ -674,9 +675,8 @@ void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int32_
674 * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) 675 * Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
675 * 676 *
676 */ 677 */
677void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, uint8_t *, uint16_t length, 678void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *,
678 void *), 679 uint16_t length, void *), void *userdata)
679 void *userdata)
680 680
681{ 681{
682 Messenger *m = tox; 682 Messenger *m = tox;
@@ -687,7 +687,8 @@ void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int32_t,
687 * return file number on success 687 * return file number on success
688 * return -1 on failure 688 * return -1 on failure
689 */ 689 */
690int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) 690int tox_new_file_sender(Tox *tox, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
691 uint16_t filename_length)
691{ 692{
692 Messenger *m = tox; 693 Messenger *m = tox;
693 return new_filesender(m, friendnumber, filesize, filename, filename_length); 694 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
699 * return -1 on failure 700 * return -1 on failure
700 */ 701 */
701int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, 702int tox_file_send_control(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
702 uint8_t *data, uint16_t length) 703 const uint8_t *data, uint16_t length)
703{ 704{
704 Messenger *m = tox; 705 Messenger *m = tox;
705 return file_control(m, friendnumber, send_receive, filenumber, message_id, data, length); 706 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,
709 * return 0 on success 710 * return 0 on success
710 * return -1 on failure 711 * return -1 on failure
711 */ 712 */
712int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) 713int tox_file_send_data(Tox *tox, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length)
713{ 714{
714 Messenger *m = tox; 715 Messenger *m = tox;
715 return file_data(m, friendnumber, filenumber, data, length); 716 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
720 * return size on success 721 * return size on success
721 * return -1 on failure (currently will never return -1) 722 * return -1 on failure (currently will never return -1)
722 */ 723 */
723int tox_file_data_size(Tox *tox, int32_t friendnumber) 724int tox_file_data_size(const Tox *tox, int32_t friendnumber)
724{ 725{
725 return MAX_CRYPTO_DATA_SIZE - 2; 726 return MAX_CRYPTO_DATA_SIZE - 2;
726} 727}
@@ -732,16 +733,17 @@ int tox_file_data_size(Tox *tox, int32_t friendnumber)
732 * return number of bytes remaining to be sent/received on success 733 * return number of bytes remaining to be sent/received on success
733 * return 0 on failure 734 * return 0 on failure
734 */ 735 */
735uint64_t tox_file_data_remaining(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive) 736uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
736{ 737{
737 Messenger *m = tox; 738 const Messenger *m = tox;
738 return file_dataremaining(m, friendnumber, filenumber, send_receive); 739 return file_dataremaining(m, friendnumber, filenumber, send_receive);
739} 740}
740 741
741/***************END OF FILE SENDING FUNCTIONS******************/ 742/***************END OF FILE SENDING FUNCTIONS******************/
742 743
743/* TODO: expose this properly. */ 744/* TODO: expose this properly. */
744static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, uint16_t port, uint8_t *public_key) 745static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, uint16_t port,
746 const uint8_t *public_key)
745{ 747{
746 Messenger *m = tox; 748 Messenger *m = tox;
747 IP_Port ip_port_v64; 749 IP_Port ip_port_v64;
@@ -766,7 +768,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled,
766} 768}
767 769
768int tox_bootstrap_from_address(Tox *tox, const char *address, 770int tox_bootstrap_from_address(Tox *tox, const char *address,
769 uint8_t ipv6enabled, uint16_t port, uint8_t *public_key) 771 uint8_t ipv6enabled, uint16_t port, const uint8_t *public_key)
770{ 772{
771 Messenger *m = tox; 773 Messenger *m = tox;
772 tox_add_tcp_relay(tox, address, ipv6enabled, port, public_key); 774 tox_add_tcp_relay(tox, address, ipv6enabled, port, public_key);
@@ -776,9 +778,9 @@ int tox_bootstrap_from_address(Tox *tox, const char *address,
776/* return 0 if we are not connected to the DHT. 778/* return 0 if we are not connected to the DHT.
777 * return 1 if we are. 779 * return 1 if we are.
778 */ 780 */
779int tox_isconnected(Tox *tox) 781int tox_isconnected(const Tox *tox)
780{ 782{
781 Messenger *m = tox; 783 const Messenger *m = tox;
782 return DHT_isconnected(m->dht); 784 return DHT_isconnected(m->dht);
783} 785}
784 786
@@ -823,21 +825,21 @@ void tox_do(Tox *tox)
823/* SAVING AND LOADING FUNCTIONS: */ 825/* SAVING AND LOADING FUNCTIONS: */
824 826
825/* return size of the messenger data (for saving). */ 827/* return size of the messenger data (for saving). */
826uint32_t tox_size(Tox *tox) 828uint32_t tox_size(const Tox *tox)
827{ 829{
828 Messenger *m = tox; 830 const Messenger *m = tox;
829 return messenger_size(m); 831 return messenger_size(m);
830} 832}
831 833
832/* Save the messenger in data (must be allocated memory of size Messenger_size()). */ 834/* Save the messenger in data (must be allocated memory of size Messenger_size()). */
833void tox_save(Tox *tox, uint8_t *data) 835void tox_save(const Tox *tox, uint8_t *data)
834{ 836{
835 Messenger *m = tox; 837 const Messenger *m = tox;
836 messenger_save(m, data); 838 messenger_save(m, data);
837} 839}
838 840
839/* Load the messenger from data of size length. */ 841/* Load the messenger from data of size length. */
840int tox_load(Tox *tox, uint8_t *data, uint32_t length) 842int tox_load(Tox *tox, const uint8_t *data, uint32_t length)
841{ 843{
842 Messenger *m = tox; 844 Messenger *m = tox;
843 return messenger_load(m, data, length); 845 return messenger_load(m, data, length);