summaryrefslogtreecommitdiff
path: root/toxcore/tox.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r--toxcore/tox.h42
1 files changed, 29 insertions, 13 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h
index a5efee34..c5484fba 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -37,8 +37,9 @@ extern "C" {
37#define TOX_MAX_MESSAGE_LENGTH 1368 37#define TOX_MAX_MESSAGE_LENGTH 1368
38#define TOX_MAX_STATUSMESSAGE_LENGTH 1007 38#define TOX_MAX_STATUSMESSAGE_LENGTH 1007
39#define TOX_CLIENT_ID_SIZE 32 39#define TOX_CLIENT_ID_SIZE 32
40#define TOX_MAX_AVATAR_DATA_LENGTH 16384 40#define TOX_AVATAR_MAX_DATA_LENGTH 16384
41#define TOX_AVATAR_HASH_LENGTH 32 41#define TOX_AVATAR_HASH_LENGTH /*crypto_hash_sha256_BYTES*/ 32
42#define TOX_HASH_LENGTH TOX_AVATAR_HASH_LENGTH
42 43
43#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t)) 44#define TOX_FRIEND_ADDRESS_SIZE (TOX_CLIENT_ID_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
44 45
@@ -73,14 +74,14 @@ typedef enum {
73TOX_USERSTATUS; 74TOX_USERSTATUS;
74 75
75 76
76/* AVATARFORMAT - 77/* AVATAR_FORMAT -
77 * Data formats for user avatar images 78 * Data formats for user avatar images
78 */ 79 */
79typedef enum { 80typedef enum {
80 TOX_AVATARFORMAT_NONE, 81 TOX_AVATAR_FORMAT_NONE = 0,
81 TOX_AVATARFORMAT_PNG 82 TOX_AVATAR_FORMAT_PNG
82} 83}
83TOX_AVATARFORMAT; 84TOX_AVATAR_FORMAT;
84 85
85#ifndef __TOX_DEFINED__ 86#ifndef __TOX_DEFINED__
86#define __TOX_DEFINED__ 87#define __TOX_DEFINED__
@@ -538,7 +539,7 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size);
538 * Function format is: 539 * Function format is:
539 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata) 540 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata)
540 * 541 *
541 * where 'format' is the avatar image format (see TOX_AVATARFORMAT) and 'hash' is the hash of 542 * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT) 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 * 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 * image format is NONE, the hash is zeroed.
544 * 545 *
@@ -554,7 +555,7 @@ void tox_callback_avatar_info(Tox *tox, void (*function)(Tox *tox, int32_t, uint
554 * Function format is: 555 * 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 * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata)
556 * 557 *
557 * where 'format' is the avatar image format (see TOX_AVATARFORMAT); 'hash' is the 558 * where 'format' is the avatar image format (see TOX_AVATAR_FORMAT); 'hash' is the
558 * locally-calculated cryptographic hash of the avatar data and it is exactly 559 * 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 * TOX_AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length
560 * of such data. 561 * of such data.
@@ -577,9 +578,9 @@ void tox_callback_avatar_data(Tox *tox, void (*function)(Tox *tox, int32_t, uint
577 * Notice that the library treats the image as raw data and does not interpret it by any way. 578 * Notice that the library treats the image as raw data and does not interpret it by any way.
578 * 579 *
579 * Arguments: 580 * Arguments:
580 * format - Avatar image format or NONE for user with no avatar (see TOX_AVATARFORMAT); 581 * format - Avatar image format or NONE for user with no avatar (see TOX_AVATAR_FORMAT);
581 * data - pointer to the avatar data (may be NULL it the format is NONE); 582 * 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 * length - length of image data. Must be <= TOX_AVATAR_MAX_DATA_LENGTH.
583 * 584 *
584 * returns 0 on success 585 * returns 0 on success
585 * returns -1 on failure. 586 * returns -1 on failure.
@@ -597,7 +598,7 @@ int tox_set_avatar(Tox *tox, uint8_t format, const uint8_t *data, uint32_t lengt
597 * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored. 598 * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored.
598 * 599 *
599 * Arguments: 600 * Arguments:
600 * format - destination pointer to the avatar image format (see TOX_AVATARFORMAT); 601 * format - destination pointer to the avatar image format (see TOX_AVATAR_FORMAT);
601 * buf - destination buffer to the image data. Must have at least 'maxlen' bytes; 602 * buf - destination buffer to the image data. Must have at least 'maxlen' bytes;
602 * length - destination pointer to the image data length; 603 * length - destination pointer to the image data length;
603 * maxlen - length of the destination buffer 'buf'; 604 * maxlen - length of the destination buffer 'buf';
@@ -611,15 +612,30 @@ int tox_get_self_avatar(const Tox *tox, uint8_t *format, uint8_t *buf, uint32_t
611 uint8_t *hash); 612 uint8_t *hash);
612 613
613 614
615/* Generates a cryptographic hash of the given data.
616 * This function may be used by clients for any purpose, but is provided primarily for
617 * validating cached avatars.
618 * This function is a wrapper to internal message-digest functions.
619 *
620 * Arguments:
621 * hash - destination buffer for the hash data, it must be exactly TOX_HASH_LENGTH bytes long.
622 * data - data to be hashed;
623 * datalen - length of the data;
624 *
625 * returns 0 on success
626 * returns -1 on failure.
627 */
628int m_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen);
629
614/* Generates a cryptographic hash of the given avatar data. 630/* Generates a cryptographic hash of the given avatar data.
615 * This function is a wrapper to internal message-digest functions and specifically provided 631 * This function is a wrapper to tox_hash and specifically provided
616 * to generate hashes from user avatars that may be memcmp()ed with the values returned by the 632 * 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. 633 * other avatar functions. It is specially important to validate cached avatars.
618 * 634 *
619 * Arguments: 635 * Arguments:
620 * hash - destination buffer for the hash data, it must be exactly TOX_AVATAR_HASH_LENGTH bytes long. 636 * hash - destination buffer for the hash data, it must be exactly TOX_AVATAR_HASH_LENGTH bytes long.
621 * data - avatar image data; 637 * data - avatar image data;
622 * datalen - length of the avatar image data; it must be <= TOX_MAX_AVATAR_DATA_LENGTH. 638 * datalen - length of the avatar image data; it must be <= MAX_AVATAR_DATA_LENGTH.
623 * 639 *
624 * returns 0 on success 640 * returns 0 on success
625 * returns -1 on failure. 641 * returns -1 on failure.