summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c23
1 files changed, 12 insertions, 11 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);