diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 3d96f6ca..99b95f67 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -576,10 +576,10 @@ int m_set_userstatus(Messenger *m, uint8_t status) | |||
576 | 576 | ||
577 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) | 577 | int m_set_avatar(Messenger *m, uint8_t format, const uint8_t *data, uint32_t length) |
578 | { | 578 | { |
579 | if (length > MAX_AVATAR_DATA_LENGTH) | 579 | if (length > AVATAR_MAX_DATA_LENGTH) |
580 | return -1; | 580 | return -1; |
581 | 581 | ||
582 | if (format == AVATARFORMAT_NONE) { | 582 | if (format == AVATAR_FORMAT_NONE) { |
583 | free(m->avatar_data); | 583 | free(m->avatar_data); |
584 | m->avatar_data = NULL; | 584 | m->avatar_data = NULL; |
585 | m->avatar_data_length = 0; | 585 | m->avatar_data_length = 0; |
@@ -632,15 +632,18 @@ int m_get_self_avatar(const Messenger *m, uint8_t *format, uint8_t *buf, uint32_ | |||
632 | return 0; | 632 | return 0; |
633 | } | 633 | } |
634 | 634 | ||
635 | int m_avatar_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen) | 635 | int m_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen) |
636 | { | 636 | { |
637 | if (hash == NULL) | 637 | if (hash == NULL) |
638 | return -1; | 638 | return -1; |
639 | 639 | ||
640 | crypto_hash_sha256(hash, data, datalen); | 640 | return crypto_hash_sha256(hash, data, datalen); |
641 | return 0; | ||
642 | } | 641 | } |
643 | 642 | ||
643 | int m_avatar_hash(uint8_t *hash, const uint8_t *data, const uint32_t datalen) | ||
644 | { | ||
645 | return m_hash(hash, data, datalen); | ||
646 | } | ||
644 | 647 | ||
645 | int m_request_avatar_info(const Messenger *m, const int32_t friendnumber) | 648 | int m_request_avatar_info(const Messenger *m, const int32_t friendnumber) |
646 | { | 649 | { |
@@ -673,10 +676,10 @@ int m_request_avatar_data(const Messenger *m, const int32_t friendnumber) | |||
673 | if (friend_not_valid(m, friendnumber)) | 676 | if (friend_not_valid(m, friendnumber)) |
674 | return -1; | 677 | return -1; |
675 | 678 | ||
676 | AVATARRECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; | 679 | AVATAR_RECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; |
677 | 680 | ||
678 | if (avrd == NULL) { | 681 | if (avrd == NULL) { |
679 | avrd = calloc(sizeof(AVATARRECEIVEDATA), 1); | 682 | avrd = calloc(sizeof(AVATAR_RECEIVEDATA), 1); |
680 | 683 | ||
681 | if (avrd == NULL) | 684 | if (avrd == NULL) |
682 | return -1; | 685 | return -1; |
@@ -693,9 +696,9 @@ int m_request_avatar_data(const Messenger *m, const int32_t friendnumber) | |||
693 | avrd->started = 0; | 696 | avrd->started = 0; |
694 | avrd->bytes_received = 0; | 697 | avrd->bytes_received = 0; |
695 | avrd->total_length = 0; | 698 | avrd->total_length = 0; |
696 | avrd->format = AVATARFORMAT_NONE; | 699 | avrd->format = AVATAR_FORMAT_NONE; |
697 | 700 | ||
698 | return send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_REQ); | 701 | return send_avatar_data_control(m, friendnumber, AVATAR_DATACONTROL_REQ); |
699 | } | 702 | } |
700 | 703 | ||
701 | 704 | ||
@@ -2006,7 +2009,7 @@ Messenger *new_messenger(Messenger_Options *options) | |||
2006 | m->net = new_networking(ip, TOX_PORT_DEFAULT); | 2009 | m->net = new_networking(ip, TOX_PORT_DEFAULT); |
2007 | } | 2010 | } |
2008 | 2011 | ||
2009 | m->avatar_format = AVATARFORMAT_NONE; | 2012 | m->avatar_format = AVATAR_FORMAT_NONE; |
2010 | m->avatar_data = NULL; | 2013 | m->avatar_data = NULL; |
2011 | 2014 | ||
2012 | if (m->net == NULL) { | 2015 | if (m->net == NULL) { |
@@ -2159,17 +2162,17 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber, | |||
2159 | LOGGER_DEBUG("Error: PACKET_ID_AVATAR_DATA_CONTROL with bad " | 2162 | LOGGER_DEBUG("Error: PACKET_ID_AVATAR_DATA_CONTROL with bad " |
2160 | "data_length = %u, friendnumber = %u", | 2163 | "data_length = %u, friendnumber = %u", |
2161 | data_length, friendnumber); | 2164 | data_length, friendnumber); |
2162 | send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR); | 2165 | send_avatar_data_control(m, friendnumber, AVATAR_DATACONTROL_ERROR); |
2163 | return -1; /* Error */ | 2166 | return -1; /* Error */ |
2164 | } | 2167 | } |
2165 | 2168 | ||
2166 | LOGGER_DEBUG("friendnumber = %u, op = %u", friendnumber, data[0]); | 2169 | LOGGER_DEBUG("friendnumber = %u, op = %u", friendnumber, data[0]); |
2167 | 2170 | ||
2168 | switch (data[0]) { | 2171 | switch (data[0]) { |
2169 | case AVATARDATACONTROL_REQ: { | 2172 | case AVATAR_DATACONTROL_REQ: { |
2170 | 2173 | ||
2171 | /* Check data transfer limits for this friend */ | 2174 | /* Check data transfer limits for this friend */ |
2172 | AVATARSENDDATA *const avsd = &(m->friendlist[friendnumber].avatar_send_data); | 2175 | AVATAR_SENDDATA *const avsd = &(m->friendlist[friendnumber].avatar_send_data); |
2173 | 2176 | ||
2174 | if (avsd->bytes_sent >= AVATAR_DATA_TRANSFER_LIMIT) { | 2177 | if (avsd->bytes_sent >= AVATAR_DATA_TRANSFER_LIMIT) { |
2175 | /* User reached data limit. Check timeout */ | 2178 | /* User reached data limit. Check timeout */ |
@@ -2183,7 +2186,7 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber, | |||
2183 | /* Friend still rate-limitted. Send an error and stops. */ | 2186 | /* Friend still rate-limitted. Send an error and stops. */ |
2184 | LOGGER_DEBUG("Avatar data transfer limit reached. " | 2187 | LOGGER_DEBUG("Avatar data transfer limit reached. " |
2185 | "friendnumber = %u", friendnumber); | 2188 | "friendnumber = %u", friendnumber); |
2186 | send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR); | 2189 | send_avatar_data_control(m, friendnumber, AVATAR_DATACONTROL_ERROR); |
2187 | return 0; | 2190 | return 0; |
2188 | } | 2191 | } |
2189 | } | 2192 | } |
@@ -2211,12 +2214,12 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber, | |||
2211 | if (!ret) { | 2214 | if (!ret) { |
2212 | /* Something went wrong, try to signal the error so the friend | 2215 | /* Something went wrong, try to signal the error so the friend |
2213 | * can clear up the state. */ | 2216 | * can clear up the state. */ |
2214 | send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR); | 2217 | send_avatar_data_control(m, friendnumber, AVATAR_DATACONTROL_ERROR); |
2215 | return 0; | 2218 | return 0; |
2216 | } | 2219 | } |
2217 | 2220 | ||
2218 | /* User have no avatar data, nothing more to do. */ | 2221 | /* User have no avatar data, nothing more to do. */ |
2219 | if (m->avatar_format == AVATARFORMAT_NONE) | 2222 | if (m->avatar_format == AVATAR_FORMAT_NONE) |
2220 | return 0; | 2223 | return 0; |
2221 | 2224 | ||
2222 | /* Send the actual avatar data. */ | 2225 | /* Send the actual avatar data. */ |
@@ -2241,7 +2244,7 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber, | |||
2241 | LOGGER_DEBUG("write_cryptpacket_id failed. ret = %d, " | 2244 | LOGGER_DEBUG("write_cryptpacket_id failed. ret = %d, " |
2242 | "friendnumber = %u, offset = %u", | 2245 | "friendnumber = %u, offset = %u", |
2243 | ret, friendnumber, offset); | 2246 | ret, friendnumber, offset); |
2244 | send_avatar_data_control(m, friendnumber, AVATARDATACONTROL_ERROR); | 2247 | send_avatar_data_control(m, friendnumber, AVATAR_DATACONTROL_ERROR); |
2245 | return -1; | 2248 | return -1; |
2246 | } | 2249 | } |
2247 | } | 2250 | } |
@@ -2249,7 +2252,7 @@ static int handle_avatar_data_control(Messenger *m, uint32_t friendnumber, | |||
2249 | return 0; | 2252 | return 0; |
2250 | } | 2253 | } |
2251 | 2254 | ||
2252 | case AVATARDATACONTROL_ERROR: { | 2255 | case AVATAR_DATACONTROL_ERROR: { |
2253 | if (m->friendlist[friendnumber].avatar_recv_data) { | 2256 | if (m->friendlist[friendnumber].avatar_recv_data) { |
2254 | /* We were receiving the data, sender detected an error | 2257 | /* We were receiving the data, sender detected an error |
2255 | (eg. changing avatar) and asked us to stop. */ | 2258 | (eg. changing avatar) and asked us to stop. */ |
@@ -2276,7 +2279,7 @@ static int handle_avatar_data_start(Messenger *m, uint32_t friendnumber, | |||
2276 | return -1; | 2279 | return -1; |
2277 | } | 2280 | } |
2278 | 2281 | ||
2279 | AVATARRECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; | 2282 | AVATAR_RECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; |
2280 | 2283 | ||
2281 | if (avrd == NULL) { | 2284 | if (avrd == NULL) { |
2282 | LOGGER_DEBUG("Received an unrequested DATA_START, friendnumber = %u", | 2285 | LOGGER_DEBUG("Received an unrequested DATA_START, friendnumber = %u", |
@@ -2307,7 +2310,7 @@ static int handle_avatar_data_start(Messenger *m, uint32_t friendnumber, | |||
2307 | friendnumber, avrd->format, avrd->total_length, | 2310 | friendnumber, avrd->format, avrd->total_length, |
2308 | avrd->bytes_received); | 2311 | avrd->bytes_received); |
2309 | 2312 | ||
2310 | if (avrd->total_length > MAX_AVATAR_DATA_LENGTH) { | 2313 | if (avrd->total_length > AVATAR_MAX_DATA_LENGTH) { |
2311 | /* Invalid data length. Stops. */ | 2314 | /* Invalid data length. Stops. */ |
2312 | LOGGER_DEBUG("Error: total_length > MAX_AVATAR_DATA_LENGTH, " | 2315 | LOGGER_DEBUG("Error: total_length > MAX_AVATAR_DATA_LENGTH, " |
2313 | "friendnumber = %u", friendnumber); | 2316 | "friendnumber = %u", friendnumber); |
@@ -2317,7 +2320,7 @@ static int handle_avatar_data_start(Messenger *m, uint32_t friendnumber, | |||
2317 | return 0; | 2320 | return 0; |
2318 | } | 2321 | } |
2319 | 2322 | ||
2320 | if (avrd->format == AVATARFORMAT_NONE || avrd->total_length == 0) { | 2323 | if (avrd->format == AVATAR_FORMAT_NONE || avrd->total_length == 0) { |
2321 | /* No real data to receive. Run callback function and finish. */ | 2324 | /* No real data to receive. Run callback function and finish. */ |
2322 | LOGGER_DEBUG("format == NONE, friendnumber = %u", friendnumber); | 2325 | LOGGER_DEBUG("format == NONE, friendnumber = %u", friendnumber); |
2323 | 2326 | ||
@@ -2343,7 +2346,7 @@ static int handle_avatar_data_push(Messenger *m, uint32_t friendnumber, | |||
2343 | { | 2346 | { |
2344 | LOGGER_DEBUG("friendnumber = %u, data_length = %u", friendnumber, data_length); | 2347 | LOGGER_DEBUG("friendnumber = %u, data_length = %u", friendnumber, data_length); |
2345 | 2348 | ||
2346 | AVATARRECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; | 2349 | AVATAR_RECEIVEDATA *avrd = m->friendlist[friendnumber].avatar_recv_data; |
2347 | 2350 | ||
2348 | if (avrd == NULL) { | 2351 | if (avrd == NULL) { |
2349 | /* No active transfer. It must be an error or a malicious request, | 2352 | /* No active transfer. It must be an error or a malicious request, |
@@ -2363,7 +2366,7 @@ static int handle_avatar_data_push(Messenger *m, uint32_t friendnumber, | |||
2363 | uint32_t new_length = avrd->bytes_received + data_length; | 2366 | uint32_t new_length = avrd->bytes_received + data_length; |
2364 | 2367 | ||
2365 | if (new_length > avrd->total_length | 2368 | if (new_length > avrd->total_length |
2366 | || new_length >= MAX_AVATAR_DATA_LENGTH) { | 2369 | || new_length >= AVATAR_MAX_DATA_LENGTH) { |
2367 | /* Invalid data length due to error or malice. Stops. */ | 2370 | /* Invalid data length due to error or malice. Stops. */ |
2368 | LOGGER_DEBUG("Invalid data length. friendnumber = %u, " | 2371 | LOGGER_DEBUG("Invalid data length. friendnumber = %u, " |
2369 | "new_length = %u, avrd->total_length = %u", | 2372 | "new_length = %u, avrd->total_length = %u", |