summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-22 15:12:48 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-22 15:12:48 -0400
commit21be438b2b3f7aa1b65b76a7f528eacfe5b634db (patch)
treefd96353c1fefa6f8ca7c4096244fc396645fcc48
parentb52da45aebe79b54bbd00564a050fcdaca028617 (diff)
Some fixes to avatar pull request.
Some bug fixes. Grouped all avatar related functions in the same place in tox.h
-rw-r--r--toxcore/Messenger.c23
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/tox.c105
-rw-r--r--toxcore/tox.h265
4 files changed, 195 insertions, 200 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 108159a3..1c710522 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -304,6 +304,10 @@ int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id)
304 m->friendlist[i].statusmessage = calloc(1, 1); 304 m->friendlist[i].statusmessage = calloc(1, 1);
305 m->friendlist[i].statusmessage_length = 1; 305 m->friendlist[i].statusmessage_length = 1;
306 m->friendlist[i].userstatus = USERSTATUS_NONE; 306 m->friendlist[i].userstatus = USERSTATUS_NONE;
307 m->friendlist[i].avatar_info_sent = 0;
308 m->friendlist[i].avatar_recv_data = NULL;
309 m->friendlist[i].avatar_send_data.bytes_sent = 0;
310 m->friendlist[i].avatar_send_data.last_reset = 0;
307 m->friendlist[i].is_typing = 0; 311 m->friendlist[i].is_typing = 0;
308 m->friendlist[i].message_id = 0; 312 m->friendlist[i].message_id = 0;
309 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */ 313 m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */
@@ -643,7 +647,7 @@ int m_request_avatar_info(const Messenger *m, const int32_t friendnumber)
643 if (friend_not_valid(m, friendnumber)) 647 if (friend_not_valid(m, friendnumber))
644 return -1; 648 return -1;
645 649
646 if (write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_INFO_REQ, 0, 0, 0) >= 0) 650 if (write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_INFO_REQ, 0, 0, 0))
647 return 0; 651 return 0;
648 else 652 else
649 return -1; 653 return -1;
@@ -658,9 +662,7 @@ int m_send_avatar_info(const Messenger *m, const int32_t friendnumber)
658 data[0] = m->avatar_format; 662 data[0] = m->avatar_format;
659 memcpy(data + 1, m->avatar_hash, AVATAR_HASH_LENGTH); 663 memcpy(data + 1, m->avatar_hash, AVATAR_HASH_LENGTH);
660 664
661 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_INFO, data, sizeof(data), 0); 665 if (write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_INFO, data, sizeof(data), 0))
662
663 if (ret >= 0)
664 return 0; 666 return 0;
665 else 667 else
666 return -1; 668 return -1;
@@ -674,12 +676,11 @@ int m_request_avatar_data(const Messenger *m, const int32_t friendnumber)
674 AVATARRECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; 676 AVATARRECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data;
675 677
676 if (avrd == NULL) { 678 if (avrd == NULL) {
677 avrd = malloc(sizeof(AVATARRECEIVEDATA)); 679 avrd = calloc(sizeof(AVATARRECEIVEDATA), 1);
678 680
679 if (avrd == NULL) 681 if (avrd == NULL)
680 return -1; 682 return -1;
681 683
682 memset(avrd, 0, sizeof(AVATARRECEIVEDATA));
683 avrd->started = 0; 684 avrd->started = 0;
684 m->friendlist[friendnumber].avatar_recv_data = avrd; 685 m->friendlist[friendnumber].avatar_recv_data = avrd;
685 } 686 }
@@ -2081,8 +2082,8 @@ void kill_messenger(Messenger *m)
2081 kill_networking(m->net); 2082 kill_networking(m->net);
2082 2083
2083 for (i = 0; i < m->numfriends; ++i) { 2084 for (i = 0; i < m->numfriends; ++i) {
2084 if (m->friendlist[i].statusmessage) 2085 free(m->friendlist[i].statusmessage);
2085 free(m->friendlist[i].statusmessage); 2086 free(m->friendlist[friendnumber].avatar_recv_data);
2086 } 2087 }
2087 2088
2088 free(m->avatar_data); 2089 free(m->avatar_data);
@@ -2147,7 +2148,7 @@ static int send_avatar_data_control(const Messenger *m, const uint32_t friendnum
2147 &op, sizeof(op), 0); 2148 &op, sizeof(op), 0);
2148 LOGGER_DEBUG("friendnumber = %u, op = %u, ret = %d", 2149 LOGGER_DEBUG("friendnumber = %u, op = %u, ret = %d",
2149 friendnumber, op, ret); 2150 friendnumber, op, ret);
2150 return (ret >= 0) ? 0 : -1; 2151 return ret ? 0 : -1;
2151} 2152}
2152 2153
2153 2154
@@ -2207,7 +2208,7 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber,
2207 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_DATA_START, 2208 int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_AVATAR_DATA_START,
2208 start_data, sizeof(start_data), 0); 2209 start_data, sizeof(start_data), 0);
2209 2210
2210 if (ret < 0) { 2211 if (!ret) {
2211 /* Something went wrong, try to signal the error so the friend 2212 /* Something went wrong, try to signal the error so the friend
2212 * can clear up the state. */ 2213 * can clear up the state. */
2213 send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR); 2214 send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR);
@@ -2236,7 +2237,7 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber,
2236 PACKET_ID_AVATAR_DATA_PUSH, 2237 PACKET_ID_AVATAR_DATA_PUSH,
2237 chunk, chunk_len, 0); 2238 chunk, chunk_len, 0);
2238 2239
2239 if (ret < 0) { 2240 if (!ret) {
2240 LOGGER_DEBUG("write_cryptpacket_id failed. ret = %d, " 2241 LOGGER_DEBUG("write_cryptpacket_id failed. ret = %d, "
2241 "friendnumber = %u, offset = %u", 2242 "friendnumber = %u, offset = %u",
2242 ret, friendnumber, offset); 2243 ret, friendnumber, offset);
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 01632126..a107d80f 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -122,7 +122,7 @@ enum {
122 122
123/* Per-friend data limit for avatar data requests */ 123/* Per-friend data limit for avatar data requests */
124#define AVATAR_DATA_TRANSFER_LIMIT (10*MAX_AVATAR_DATA_LENGTH) 124#define AVATAR_DATA_TRANSFER_LIMIT (10*MAX_AVATAR_DATA_LENGTH)
125#define AVATAR_DATA_TRANSFER_TIMEOUT (20*60) 125#define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */
126 126
127 127
128/* USERSTATUS - 128/* USERSTATUS -
diff --git a/toxcore/tox.c b/toxcore/tox.c
index c5bea846..b44f0ee6 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -275,42 +275,6 @@ uint8_t tox_get_self_user_status(const Tox *tox)
275 return m_get_self_userstatus(m); 275 return m_get_self_userstatus(m);
276} 276}
277 277
278int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length)
279{
280 Messenger *m = tox;
281 return m_set_avatar(m, format, data, length);
282}
283
284int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash)
285{
286 const Messenger *m = tox;
287 return m_get_self_avatar(m, format, buf, length, maxlen, hash);
288}
289
290int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen)
291{
292 return m_avatar_hash(hash, data, datalen);
293}
294
295int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber)
296{
297 const Messenger *m = tox;
298 return m_request_avatar_info(m, friendnumber);
299}
300
301int tox_send_avatar_info(Tox *tox, const int32_t friendnumber)
302{
303 const Messenger *m = tox;
304 return m_send_avatar_info(m, friendnumber);
305}
306
307int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber)
308{
309 const Messenger *m = tox;
310 return m_request_avatar_data(m, friendnumber);
311}
312
313
314/* returns timestamp of last time friendnumber was seen online, or 0 if never seen. 278/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
315 * returns -1 on error. 279 * returns -1 on error.
316 */ 280 */
@@ -475,24 +439,6 @@ void tox_callback_connection_status(Tox *tox, void (*function)(Messenger *tox, i
475 m_callback_connectionstatus(m, function, userdata); 439 m_callback_connectionstatus(m, function, userdata);
476} 440}
477 441
478void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), void *userdata)
479{
480 Messenger *m = tox;
481 m_callback_avatar_info(m, function, userdata);
482}
483
484
485void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t,
486 void *), void *userdata)
487{
488 Messenger *m = tox;
489 m_callback_avatar_data(m, function, userdata);
490}
491
492
493
494
495
496/**********ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) ************/ 442/**********ADVANCED FUNCTIONS (If you don't know what they do you can safely ignore them.) ************/
497 443
498/* Functions to get/set the nospam part of the id. 444/* Functions to get/set the nospam part of the id.
@@ -852,6 +798,57 @@ uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t f
852 return file_dataremaining(m, friendnumber, filenumber, send_receive); 798 return file_dataremaining(m, friendnumber, filenumber, send_receive);
853} 799}
854 800
801
802/****************AVATAR FUNCTIONS*****************/
803
804void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, void *), void *userdata)
805{
806 Messenger *m = tox;
807 m_callback_avatar_info(m, function, userdata);
808}
809
810void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, uint8_t *, uint8_t *, uint32_t,
811 void *), void *userdata)
812{
813 Messenger *m = tox;
814 m_callback_avatar_data(m, function, userdata);
815}
816
817int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t length)
818{
819 Messenger *m = tox;
820 return m_set_avatar(m, format, data, length);
821}
822
823int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, uint8_t *hash)
824{
825 const Messenger *m = tox;
826 return m_get_self_avatar(m, format, buf, length, maxlen, hash);
827}
828
829int tox_avatar_hash(const Tox *tox, uint8_t *hash, const uint8_t *data, const uint32_t datalen)
830{
831 return m_avatar_hash(hash, data, datalen);
832}
833
834int tox_request_avatar_info(const Tox *tox, const int32_t friendnumber)
835{
836 const Messenger *m = tox;
837 return m_request_avatar_info(m, friendnumber);
838}
839
840int tox_send_avatar_info(Tox *tox, const int32_t friendnumber)
841{
842 const Messenger *m = tox;
843 return m_send_avatar_info(m, friendnumber);
844}
845
846int tox_request_avatar_data(const Tox *tox, const int32_t friendnumber)
847{
848 const Messenger *m = tox;
849 return m_request_avatar_data(m, friendnumber);
850}
851
855/***************END OF FILE SENDING FUNCTIONS******************/ 852/***************END OF FILE SENDING FUNCTIONS******************/
856 853
857/* Like tox_bootstrap_from_address but for TCP relays only. 854/* Like tox_bootstrap_from_address but for TCP relays only.
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.