summaryrefslogtreecommitdiff
path: root/toxcore/tox.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r--toxcore/tox.h265
1 files changed, 131 insertions, 134 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 8f54697f..a5efee34 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -254,98 +254,6 @@ int tox_get_self_status_message(const Tox *tox, uint8_t *buf, uint32_t maxlen);
254uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber); 254uint8_t tox_get_user_status(const Tox *tox, int32_t friendnumber);
255uint8_t tox_get_self_user_status(const Tox *tox); 255uint8_t tox_get_self_user_status(const Tox *tox);
256 256
257
258/* Set the user avatar image data.
259 * This should be made before connecting, so we will not announce that the user have no avatar
260 * before setting and announcing a new one, forcing the peers to re-download it.
261 *
262 * Notice that the library treats the image as raw data and does not interpret it by any way.
263 *
264 * Arguments:
265 * format - Avatar image format or NONE for user with no avatar (see TOX_AVATARFORMAT);
266 * data - pointer to the avatar data (may be NULL it the format is NONE);
267 * length - length of image data. Must be <= TOX_MAX_AVATAR_DATA_LENGTH.
268 *
269 * returns 0 on success
270 * returns -1 on failure.
271 */
272int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length);
273
274
275/* Get avatar data from the current user.
276 * Copies the current user avatar data to the destination buffer and sets the image format
277 * accordingly.
278 *
279 * If the avatar format is NONE, the buffer 'buf' isleft uninitialized, 'hash' is zeroed, and
280 * 'length' is set to zero.
281 *
282 * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored.
283 *
284 * Arguments:
285 * format - destination pointer to the avatar image format (see TOX_AVATARFORMAT);
286 * buf - destination buffer to the image data. Must have at least 'maxlen' bytes;
287 * length - destination pointer to the image data length;
288 * maxlen - length of the destination buffer 'buf';
289 * hash - destination pointer to the avatar hash (it must be exactly TOX_AVATAR_HASH_LENGTH bytes long).
290 *
291 * returns 0 on success;
292 * returns -1 on failure.
293 *
294 */
295int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen,
296 uint8_t *hash);
297
298
299/* Generates a cryptographic hash of the given avatar data.
300 * This function is a wrapper to internal message-digest functions and specifically provided
301 * to generate hashes from user avatars that may be memcmp()ed with the values returned by the
302 * other avatar functions. It is specially important to validate cached avatars.
303 *
304 * Arguments:
305 * hash - destination buffer for the hash data, it must be exactly TOX_AVATAR_HASH_LENGTH bytes long.
306 * data - avatar image data;
307 * datalen - length of the avatar image data; it must be <= TOX_MAX_AVATAR_DATA_LENGTH.
308 *
309 * returns 0 on success
310 * returns -1 on failure.
311 */
312int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen);
313
314
315/* Request avatar information from a friend.
316 * Asks a friend to provide their avatar information (image format and hash). The friend may
317 * or may not answer this request and, if answered, the information will be provided through
318 * the callback 'avatar_info'.
319 *
320 * returns 0 on success
321 * returns -1 on failure.
322 */
323int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber);
324
325
326/* Send an unrequested avatar information to a friend.
327 * Sends our avatar format and hash to a friend; he/she can use this information to validate
328 * an avatar from the cache and may (or not) reply with an avatar data request.
329 *
330 * Notice: it is NOT necessary to send these notification after changing the avatar or
331 * connecting. The library already does this.
332 *
333 * returns 0 on success
334 * returns -1 on failure.
335 */
336int tox_send_avatar_info(Tox *tox, const int32_t friendnumber);
337
338
339/* Request the avatar data from a friend.
340 * Ask a friend to send their avatar data. The friend may or may not answer this request and,
341 * if answered, the information will be provided in callback 'avatar_data'.
342 *
343 * returns 0 on sucess
344 * returns -1 on failure.
345 */
346int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber);
347
348
349/* returns timestamp of last time friendnumber was seen online, or 0 if never seen. 257/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
350 * returns -1 on error. 258 * returns -1 on error.
351 */ 259 */
@@ -447,48 +355,6 @@ void tox_callback_read_receipt(Tox *tox, void (*function)(Tox *tox, int32_t, uin
447 */ 355 */
448void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata); 356void tox_callback_connection_status(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, void *), void *userdata);
449 357
450/* Set the callback function for avatar information.
451 * This callback will be called when avatar information are received from friends. These events
452 * can arrive at anytime, but are usually received uppon connection and in reply of avatar
453 * information requests.
454 *
455 * Function format is:
456 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata)
457 *
458 * where 'format' is the avatar image format (see TOX_AVATARFORMAT) and 'hash' is the hash of
459 * the avatar data for caching purposes and it is exactly TOX_AVATAR_HASH_LENGTH long. If the
460 * image format is NONE, the hash is zeroed.
461 *
462 */
463void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *),
464 void *userdata);
465
466
467/* Set the callback function for avatar data.
468 * This callback will be called when the complete avatar data was correctly received from a
469 * friend. This only happens in reply of a avatar data request (see tox_request_avatar_data);
470 *
471 * Function format is:
472 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata)
473 *
474 * where 'format' is the avatar image format (see TOX_AVATARFORMAT); 'hash' is the
475 * locally-calculated cryptographic hash of the avatar data and it is exactly
476 * TOX_AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length
477 * of such data.
478 *
479 * If format is NONE, 'data' is NULL, 'datalen' is zero, and the hash is zeroed. The hash is
480 * always validated locally with the function tox_avatar_hash and ensured to match the image
481 * data, so this value can be safely used to compare with cached avatars.
482 *
483 * WARNING: users MUST treat all avatar image data received from another peer as untrusted and
484 * potentially malicious. The library only ensures that the data which arrived is the same the
485 * other user sent, and does not interpret or validate any image data.
486 */
487void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t,
488 void *), void *userdata);
489
490
491
492 358
493/**********ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) ************/ 359/**********ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) ************/
494 360
@@ -662,6 +528,137 @@ uint32_t tox_count_chatlist(const Tox *tox);
662 * of out_list will be truncated to list_size. */ 528 * of out_list will be truncated to list_size. */
663uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); 529uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size);
664 530
531/****************AVATAR FUNCTIONS*****************/
532
533/* Set the callback function for avatar information.
534 * This callback will be called when avatar information are received from friends. These events
535 * can arrive at anytime, but are usually received uppon connection and in reply of avatar
536 * information requests.
537 *
538 * Function format is:
539 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata)
540 *
541 * where 'format' is the avatar image format (see TOX_AVATARFORMAT) and 'hash' is the hash of
542 * the avatar data for caching purposes and it is exactly TOX_AVATAR_HASH_LENGTH long. If the
543 * image format is NONE, the hash is zeroed.
544 *
545 */
546void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *),
547 void *userdata);
548
549
550/* Set the callback function for avatar data.
551 * This callback will be called when the complete avatar data was correctly received from a
552 * friend. This only happens in reply of a avatar data request (see tox_request_avatar_data);
553 *
554 * Function format is:
555 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata)
556 *
557 * where 'format' is the avatar image format (see TOX_AVATARFORMAT); 'hash' is the
558 * locally-calculated cryptographic hash of the avatar data and it is exactly
559 * TOX_AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length
560 * of such data.
561 *
562 * If format is NONE, 'data' is NULL, 'datalen' is zero, and the hash is zeroed. The hash is
563 * always validated locally with the function tox_avatar_hash and ensured to match the image
564 * data, so this value can be safely used to compare with cached avatars.
565 *
566 * WARNING: users MUST treat all avatar image data received from another peer as untrusted and
567 * potentially malicious. The library only ensures that the data which arrived is the same the
568 * other user sent, and does not interpret or validate any image data.
569 */
570void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t,
571 void *), void *userdata);
572
573/* Set the user avatar image data.
574 * This should be made before connecting, so we will not announce that the user have no avatar
575 * before setting and announcing a new one, forcing the peers to re-download it.
576 *
577 * Notice that the library treats the image as raw data and does not interpret it by any way.
578 *
579 * Arguments:
580 * format - Avatar image format or NONE for user with no avatar (see TOX_AVATARFORMAT);
581 * data - pointer to the avatar data (may be NULL it the format is NONE);
582 * length - length of image data. Must be <= TOX_MAX_AVATAR_DATA_LENGTH.
583 *
584 * returns 0 on success
585 * returns -1 on failure.
586 */
587int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length);
588
589
590/* Get avatar data from the current user.
591 * Copies the current user avatar data to the destination buffer and sets the image format
592 * accordingly.
593 *
594 * If the avatar format is NONE, the buffer 'buf' isleft uninitialized, 'hash' is zeroed, and
595 * 'length' is set to zero.
596 *
597 * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored.
598 *
599 * Arguments:
600 * format - destination pointer to the avatar image format (see TOX_AVATARFORMAT);
601 * buf - destination buffer to the image data. Must have at least 'maxlen' bytes;
602 * length - destination pointer to the image data length;
603 * maxlen - length of the destination buffer 'buf';
604 * hash - destination pointer to the avatar hash (it must be exactly TOX_AVATAR_HASH_LENGTH bytes long).
605 *
606 * returns 0 on success;
607 * returns -1 on failure.
608 *
609 */
610int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen,
611 uint8_t *hash);
612
613
614/* Generates a cryptographic hash of the given avatar data.
615 * This function is a wrapper to internal message-digest functions and specifically provided
616 * to generate hashes from user avatars that may be memcmp()ed with the values returned by the
617 * other avatar functions. It is specially important to validate cached avatars.
618 *
619 * Arguments:
620 * hash - destination buffer for the hash data, it must be exactly TOX_AVATAR_HASH_LENGTH bytes long.
621 * data - avatar image data;
622 * datalen - length of the avatar image data; it must be <= TOX_MAX_AVATAR_DATA_LENGTH.
623 *
624 * returns 0 on success
625 * returns -1 on failure.
626 */
627int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen);
628
629
630/* Request avatar information from a friend.
631 * Asks a friend to provide their avatar information (image format and hash). The friend may
632 * or may not answer this request and, if answered, the information will be provided through
633 * the callback 'avatar_info'.
634 *
635 * returns 0 on success
636 * returns -1 on failure.
637 */
638int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber);
639
640
641/* Send an unrequested avatar information to a friend.
642 * Sends our avatar format and hash to a friend; he/she can use this information to validate
643 * an avatar from the cache and may (or not) reply with an avatar data request.
644 *
645 * Notice: it is NOT necessary to send these notification after changing the avatar or
646 * connecting. The library already does this.
647 *
648 * returns 0 on success
649 * returns -1 on failure.
650 */
651int tox_send_avatar_info(Tox *tox, const int32_t friendnumber);
652
653
654/* Request the avatar data from a friend.
655 * Ask a friend to send their avatar data. The friend may or may not answer this request and,
656 * if answered, the information will be provided in callback 'avatar_data'.
657 *
658 * returns 0 on sucess
659 * returns -1 on failure.
660 */
661int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber);
665 662
666/****************FILE SENDING FUNCTIONS*****************/ 663/****************FILE SENDING FUNCTIONS*****************/
667/* NOTE: This how to will be updated. 664/* NOTE: This how to will be updated.