summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 2dccd4a8..b745d99b 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1122,8 +1122,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
1122 packet[0] = filenumber; 1122 packet[0] = filenumber;
1123 file_type = net_htonl(file_type); 1123 file_type = net_htonl(file_type);
1124 memcpy(packet + 1, &file_type, sizeof(file_type)); 1124 memcpy(packet + 1, &file_type, sizeof(file_type));
1125 host_to_net((uint8_t *)&filesize, sizeof(filesize)); 1125 net_pack_u64(packet + 1 + sizeof(file_type), filesize);
1126 memcpy(packet + 1 + sizeof(file_type), &filesize, sizeof(filesize));
1127 memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize), file_id, FILE_ID_LENGTH); 1126 memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize), file_id, FILE_ID_LENGTH);
1128 1127
1129 if (filename_length) { 1128 if (filename_length) {
@@ -1362,10 +1361,10 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
1362 return -6; 1361 return -6;
1363 } 1362 }
1364 1363
1365 uint64_t sending_pos = position; 1364 uint8_t sending_pos[sizeof(uint64_t)];
1366 host_to_net((uint8_t *)&sending_pos, sizeof(sending_pos)); 1365 net_pack_u64(sending_pos, position);
1367 1366
1368 if (send_file_control_packet(m, friendnumber, 1, file_number, FILECONTROL_SEEK, (uint8_t *)&sending_pos, 1367 if (send_file_control_packet(m, friendnumber, 1, file_number, FILECONTROL_SEEK, sending_pos,
1369 sizeof(sending_pos))) { 1368 sizeof(sending_pos))) {
1370 ft->transferred = position; 1369 ft->transferred = position;
1371 } else { 1370 } else {
@@ -1760,8 +1759,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1760 return -1; 1759 return -1;
1761 } 1760 }
1762 1761
1763 memcpy(&position, data, sizeof(position)); 1762 net_unpack_u64(data, &position);
1764 net_to_host((uint8_t *) &position, sizeof(position));
1765 1763
1766 if (position >= ft->size) { 1764 if (position >= ft->size) {
1767 LOGGER_DEBUG(m->log, 1765 LOGGER_DEBUG(m->log,
@@ -2327,8 +2325,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2327 memcpy(&file_type, data + 1, sizeof(file_type)); 2325 memcpy(&file_type, data + 1, sizeof(file_type));
2328 file_type = net_ntohl(file_type); 2326 file_type = net_ntohl(file_type);
2329 2327
2330 memcpy(&filesize, data + 1 + sizeof(uint32_t), sizeof(filesize)); 2328 net_unpack_u64(data + 1 + sizeof(uint32_t), &filesize);
2331 net_to_host((uint8_t *) &filesize, sizeof(filesize));
2332 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber]; 2329 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
2333 2330
2334 if (ft->status != FILESTATUS_NONE) { 2331 if (ft->status != FILESTATUS_NONE) {
@@ -2755,7 +2752,7 @@ struct Saved_Friend {
2755 uint16_t statusmessage_length; 2752 uint16_t statusmessage_length;
2756 uint8_t userstatus; 2753 uint8_t userstatus;
2757 uint32_t friendrequest_nospam; 2754 uint32_t friendrequest_nospam;
2758 uint64_t last_seen_time; 2755 uint8_t last_seen_time[sizeof(uint64_t)];
2759}; 2756};
2760 2757
2761static uint32_t friend_size(void) 2758static uint32_t friend_size(void)
@@ -2780,7 +2777,7 @@ static uint32_t friend_size(void)
2780 VALUE_MEMBER(userstatus); 2777 VALUE_MEMBER(userstatus);
2781 data += 3; // padding 2778 data += 3; // padding
2782 VALUE_MEMBER(friendrequest_nospam); 2779 VALUE_MEMBER(friendrequest_nospam);
2783 VALUE_MEMBER(last_seen_time); 2780 ARRAY_MEMBER(last_seen_time);
2784 2781
2785#undef VALUE_MEMBER 2782#undef VALUE_MEMBER
2786#undef ARRAY_MEMBER 2783#undef ARRAY_MEMBER
@@ -2814,7 +2811,7 @@ static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
2814 VALUE_MEMBER(userstatus); 2811 VALUE_MEMBER(userstatus);
2815 data += 3; // padding 2812 data += 3; // padding
2816 VALUE_MEMBER(friendrequest_nospam); 2813 VALUE_MEMBER(friendrequest_nospam);
2817 VALUE_MEMBER(last_seen_time); 2814 ARRAY_MEMBER(last_seen_time);
2818 2815
2819#undef VALUE_MEMBER 2816#undef VALUE_MEMBER
2820#undef ARRAY_MEMBER 2817#undef ARRAY_MEMBER
@@ -2849,7 +2846,7 @@ static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data
2849 VALUE_MEMBER(userstatus); 2846 VALUE_MEMBER(userstatus);
2850 data += 3; // padding 2847 data += 3; // padding
2851 VALUE_MEMBER(friendrequest_nospam); 2848 VALUE_MEMBER(friendrequest_nospam);
2852 VALUE_MEMBER(last_seen_time); 2849 ARRAY_MEMBER(last_seen_time);
2853 2850
2854#undef VALUE_MEMBER 2851#undef VALUE_MEMBER
2855#undef ARRAY_MEMBER 2852#undef ARRAY_MEMBER
@@ -3028,10 +3025,7 @@ static uint8_t *friends_list_save(const Messenger *m, uint8_t *data)
3028 temp.statusmessage_length = net_htons(m->friendlist[i].statusmessage_length); 3025 temp.statusmessage_length = net_htons(m->friendlist[i].statusmessage_length);
3029 temp.userstatus = m->friendlist[i].userstatus; 3026 temp.userstatus = m->friendlist[i].userstatus;
3030 3027
3031 uint8_t last_seen_time[sizeof(uint64_t)]; 3028 net_pack_u64(temp.last_seen_time, m->friendlist[i].last_seen_time);
3032 memcpy(last_seen_time, &m->friendlist[i].last_seen_time, sizeof(uint64_t));
3033 host_to_net(last_seen_time, sizeof(uint64_t));
3034 memcpy(&temp.last_seen_time, last_seen_time, sizeof(uint64_t));
3035 } 3029 }
3036 3030
3037 uint8_t *next_data = friend_save(&temp, cur_data); 3031 uint8_t *next_data = friend_save(&temp, cur_data);
@@ -3079,10 +3073,7 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui
3079 setfriendname(m, fnum, temp.name, net_ntohs(temp.name_length)); 3073 setfriendname(m, fnum, temp.name, net_ntohs(temp.name_length));
3080 set_friend_statusmessage(m, fnum, temp.statusmessage, net_ntohs(temp.statusmessage_length)); 3074 set_friend_statusmessage(m, fnum, temp.statusmessage, net_ntohs(temp.statusmessage_length));
3081 set_friend_userstatus(m, fnum, temp.userstatus); 3075 set_friend_userstatus(m, fnum, temp.userstatus);
3082 uint8_t last_seen_time[sizeof(uint64_t)]; 3076 net_unpack_u64(temp.last_seen_time, &m->friendlist[fnum].last_seen_time);
3083 memcpy(last_seen_time, &temp.last_seen_time, sizeof(uint64_t));
3084 net_to_host(last_seen_time, sizeof(uint64_t));
3085 memcpy(&m->friendlist[fnum].last_seen_time, last_seen_time, sizeof(uint64_t));
3086 } else if (temp.status != 0) { 3077 } else if (temp.status != 0) {
3087 /* TODO(irungentoo): This is not a good way to do this. */ 3078 /* TODO(irungentoo): This is not a good way to do this. */
3088 uint8_t address[FRIEND_ADDRESS_SIZE]; 3079 uint8_t address[FRIEND_ADDRESS_SIZE];