diff options
Diffstat (limited to 'toxcore/Messenger.h')
-rw-r--r-- | toxcore/Messenger.h | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index a107d80f..e6877002 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -36,8 +36,8 @@ | |||
36 | #define MAX_NAME_LENGTH 128 | 36 | #define MAX_NAME_LENGTH 128 |
37 | /* TODO: this must depend on other variable. */ | 37 | /* TODO: this must depend on other variable. */ |
38 | #define MAX_STATUSMESSAGE_LENGTH 1007 | 38 | #define MAX_STATUSMESSAGE_LENGTH 1007 |
39 | #define MAX_AVATAR_DATA_LENGTH 16384 | 39 | #define AVATAR_MAX_DATA_LENGTH 16384 |
40 | #define AVATAR_HASH_LENGTH 32 | 40 | #define AVATAR_HASH_LENGTH crypto_hash_sha256_BYTES |
41 | 41 | ||
42 | 42 | ||
43 | #define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t)) | 43 | #define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t)) |
@@ -121,7 +121,7 @@ enum { | |||
121 | #define AVATAR_DATA_MAX_CHUNK_SIZE (MAX_CRYPTO_DATA_SIZE-1) | 121 | #define AVATAR_DATA_MAX_CHUNK_SIZE (MAX_CRYPTO_DATA_SIZE-1) |
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*AVATAR_MAX_DATA_LENGTH) |
125 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ | 125 | #define AVATAR_DATA_TRANSFER_TIMEOUT (60) /* 164kB every 60 seconds is not a lot */ |
126 | 126 | ||
127 | 127 | ||
@@ -137,40 +137,40 @@ typedef enum { | |||
137 | } | 137 | } |
138 | USERSTATUS; | 138 | USERSTATUS; |
139 | 139 | ||
140 | /* AVATARFORMAT - | 140 | /* AVATAR_FORMAT - |
141 | * Data formats for user avatar images | 141 | * Data formats for user avatar images |
142 | */ | 142 | */ |
143 | typedef enum { | 143 | typedef enum { |
144 | AVATARFORMAT_NONE, | 144 | AVATAR_FORMAT_NONE = 0, |
145 | AVATARFORMAT_PNG | 145 | AVATAR_FORMAT_PNG |
146 | } | 146 | } |
147 | AVATARFORMAT; | 147 | AVATAR_FORMAT; |
148 | 148 | ||
149 | /* AVATARDATACONTROL | 149 | /* AVATAR_DATACONTROL |
150 | * To control avatar data requests (PACKET_ID_AVATAR_DATA_CONTROL) | 150 | * To control avatar data requests (PACKET_ID_AVATAR_DATA_CONTROL) |
151 | */ | 151 | */ |
152 | typedef enum { | 152 | typedef enum { |
153 | AVATARDATACONTROL_REQ, | 153 | AVATAR_DATACONTROL_REQ, |
154 | AVATARDATACONTROL_ERROR | 154 | AVATAR_DATACONTROL_ERROR |
155 | } | 155 | } |
156 | AVATARDATACONTROL; | 156 | AVATAR_DATACONTROL; |
157 | 157 | ||
158 | typedef struct { | 158 | typedef struct { |
159 | uint8_t started; | 159 | uint8_t started; |
160 | AVATARFORMAT format; | 160 | AVATAR_FORMAT format; |
161 | uint8_t hash[AVATAR_HASH_LENGTH]; | 161 | uint8_t hash[AVATAR_HASH_LENGTH]; |
162 | uint32_t total_length; | 162 | uint32_t total_length; |
163 | uint32_t bytes_received; | 163 | uint32_t bytes_received; |
164 | uint8_t data[MAX_AVATAR_DATA_LENGTH]; | 164 | uint8_t data[AVATAR_MAX_DATA_LENGTH]; |
165 | } | 165 | } |
166 | AVATARRECEIVEDATA; | 166 | AVATAR_RECEIVEDATA; |
167 | 167 | ||
168 | typedef struct { | 168 | typedef struct { |
169 | /* Fields only used to limit the network usage from a given friend */ | 169 | /* Fields only used to limit the network usage from a given friend */ |
170 | uint32_t bytes_sent; /* Total bytes send to this user */ | 170 | uint32_t bytes_sent; /* Total bytes send to this user */ |
171 | uint64_t last_reset; /* Time the data counter was last reset */ | 171 | uint64_t last_reset; /* Time the data counter was last reset */ |
172 | } | 172 | } |
173 | AVATARSENDDATA; | 173 | AVATAR_SENDDATA; |
174 | 174 | ||
175 | 175 | ||
176 | struct File_Transfers { | 176 | struct File_Transfers { |
@@ -230,8 +230,8 @@ typedef struct { | |||
230 | int invited_groups[MAX_INVITED_GROUPS]; | 230 | int invited_groups[MAX_INVITED_GROUPS]; |
231 | uint16_t invited_groups_num; | 231 | uint16_t invited_groups_num; |
232 | 232 | ||
233 | AVATARSENDDATA avatar_send_data; | 233 | AVATAR_SENDDATA avatar_send_data; |
234 | AVATARRECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend. | 234 | AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend. |
235 | 235 | ||
236 | struct { | 236 | struct { |
237 | int (*function)(void *object, const uint8_t *data, uint32_t len); | 237 | int (*function)(void *object, const uint8_t *data, uint32_t len); |
@@ -264,7 +264,7 @@ typedef struct Messenger { | |||
264 | 264 | ||
265 | USERSTATUS userstatus; | 265 | USERSTATUS userstatus; |
266 | 266 | ||
267 | AVATARFORMAT avatar_format; | 267 | AVATAR_FORMAT avatar_format; |
268 | uint8_t *avatar_data; | 268 | uint8_t *avatar_data; |
269 | uint32_t avatar_data_length; | 269 | uint32_t avatar_data_length; |
270 | uint8_t avatar_hash[AVATAR_HASH_LENGTH]; | 270 | uint8_t avatar_hash[AVATAR_HASH_LENGTH]; |
@@ -509,7 +509,7 @@ uint8_t m_get_self_userstatus(const Messenger *m); | |||
509 | * Notice that the library treats the image as raw data and does not interpret it by any way. | 509 | * Notice that the library treats the image as raw data and does not interpret it by any way. |
510 | * | 510 | * |
511 | * Arguments: | 511 | * Arguments: |
512 | * format - Avatar image format or NONE for user with no avatar (see AVATARFORMAT); | 512 | * format - Avatar image format or NONE for user with no avatar (see AVATAR_FORMAT); |
513 | * data - pointer to the avatar data (may be NULL it the format is NONE); | 513 | * data - pointer to the avatar data (may be NULL it the format is NONE); |
514 | * length - length of image data. Must be <= MAX_AVATAR_DATA_LENGTH. | 514 | * length - length of image data. Must be <= MAX_AVATAR_DATA_LENGTH. |
515 | * | 515 | * |
@@ -528,7 +528,7 @@ int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t len | |||
528 | * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored. | 528 | * If any of the pointers format, buf, length, and hash are NULL, that particular field will be ignored. |
529 | * | 529 | * |
530 | * Arguments: | 530 | * Arguments: |
531 | * format - destination pointer to the avatar image format (see AVATARFORMAT); | 531 | * format - destination pointer to the avatar image format (see AVATAR_FORMAT); |
532 | * buf - destination buffer to the image data. Must have at least 'maxlen' bytes; | 532 | * buf - destination buffer to the image data. Must have at least 'maxlen' bytes; |
533 | * length - destination pointer to the image data length; | 533 | * length - destination pointer to the image data length; |
534 | * maxlen - length of the destination buffer 'buf'; | 534 | * maxlen - length of the destination buffer 'buf'; |
@@ -541,8 +541,23 @@ int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t len | |||
541 | int m_get_self_avatar(const Messenger *m, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, | 541 | int m_get_self_avatar(const Messenger *m, uint8_t *format, uint8_t *buf, uint32_t *length, uint32_t maxlen, |
542 | uint8_t *hash); | 542 | uint8_t *hash); |
543 | 543 | ||
544 | /* Generates a cryptographic hash of the given data. | ||
545 | * This function may be used by clients for any purpose, but is provided primarily for | ||
546 | * validating cached avatars. | ||
547 | * This function is a wrapper to internal message-digest functions. | ||
548 | * | ||
549 | * Arguments: | ||
550 | * hash - destination buffer for the hash data, it must be exactly crypto_hash_sha256_BYTES bytes long. | ||
551 | * data - data to be hashed; | ||
552 | * datalen - length of the data; | ||
553 | * | ||
554 | * returns 0 on success | ||
555 | * returns -1 on failure. | ||
556 | */ | ||
557 | int m_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen); | ||
558 | |||
544 | /* Generates a cryptographic hash of the given avatar data. | 559 | /* Generates a cryptographic hash of the given avatar data. |
545 | * This function is a wrapper to internal message-digest functions and specifically provided | 560 | * This function is a wrapper to m_hash and specifically provided |
546 | * to generate hashes from user avatars that may be memcmp()ed with the values returned by the | 561 | * to generate hashes from user avatars that may be memcmp()ed with the values returned by the |
547 | * other avatar functions. It is specially important to validate cached avatars. | 562 | * other avatar functions. It is specially important to validate cached avatars. |
548 | * | 563 | * |
@@ -694,7 +709,7 @@ void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Mess | |||
694 | * Function format is: | 709 | * Function format is: |
695 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata) | 710 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, void *userdata) |
696 | * | 711 | * |
697 | * where 'format' is the avatar image format (see AVATARFORMAT) and 'hash' is the hash of | 712 | * where 'format' is the avatar image format (see AVATAR_FORMAT) and 'hash' is the hash of |
698 | * the avatar data for caching purposes and it is exactly AVATAR_HASH_LENGTH long. If the | 713 | * the avatar data for caching purposes and it is exactly AVATAR_HASH_LENGTH long. If the |
699 | * image format is NONE, the hash is zeroed. | 714 | * image format is NONE, the hash is zeroed. |
700 | * | 715 | * |
@@ -710,7 +725,7 @@ void m_callback_avatar_info(Messenger *m, void (*function)(Messenger *m, int32_t | |||
710 | * Function format is: | 725 | * Function format is: |
711 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata) | 726 | * function(Tox *tox, int32_t friendnumber, uint8_t format, uint8_t *hash, uint8_t *data, uint32_t datalen, void *userdata) |
712 | * | 727 | * |
713 | * where 'format' is the avatar image format (see AVATARFORMAT); 'hash' is the | 728 | * where 'format' is the avatar image format (see AVATAR_FORMAT); 'hash' is the |
714 | * locally-calculated cryptographic hash of the avatar data and it is exactly | 729 | * locally-calculated cryptographic hash of the avatar data and it is exactly |
715 | * AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length | 730 | * AVATAR_HASH_LENGTH long; 'data' is the avatar image data and 'datalen' is the length |
716 | * of such data. | 731 | * of such data. |