summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 39bcd704..49be4a0a 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1038,7 +1038,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t mes
1038 if (friend_not_valid(m, friendnumber)) 1038 if (friend_not_valid(m, friendnumber))
1039 return 0; 1039 return 0;
1040 1040
1041 if (m->friendlist[friendnumber].file_sending[filenumber].status == 0) 1041 if (m->friendlist[friendnumber].file_receiving[filenumber].status == 0)
1042 return 0; 1042 return 0;
1043 1043
1044 uint8_t packet[MAX_DATA_SIZE]; 1044 uint8_t packet[MAX_DATA_SIZE];
@@ -1097,6 +1097,34 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data,
1097 return 0; 1097 return 0;
1098 1098
1099} 1099}
1100
1101/* Give the number of bytes left to be sent/received.
1102 *
1103 * send_receive is 0 if we want the sending files, 1 if we want the receiving.
1104 *
1105 * return number of bytes remaining to be sent/received on success
1106 * return 0 on failure
1107 */
1108uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive)
1109{
1110 if (friend_not_valid(m, friendnumber))
1111 return 0;
1112
1113 if (send_receive == 0) {
1114 if (m->friendlist[friendnumber].file_sending[filenumber].status == 0)
1115 return 0;
1116
1117 return m->friendlist[friendnumber].file_sending[filenumber].size -
1118 m->friendlist[friendnumber].file_sending[filenumber].transferred;
1119 } else {
1120 if (m->friendlist[friendnumber].file_receiving[filenumber].status == 0)
1121 return 0;
1122
1123 return m->friendlist[friendnumber].file_receiving[filenumber].size -
1124 m->friendlist[friendnumber].file_receiving[filenumber].transferred;
1125 }
1126}
1127
1100/* Run this when the friend disconnects. 1128/* Run this when the friend disconnects.
1101 * Sets all current file transfers to broken. 1129 * Sets all current file transfers to broken.
1102 */ 1130 */
@@ -1427,9 +1455,11 @@ void doFriends(Messenger *m)
1427 uint8_t filenumber = data[0]; 1455 uint8_t filenumber = data[0];
1428 uint64_t filesize; 1456 uint64_t filesize;
1429 memcpy(&filesize, data + 1, sizeof(filesize)); 1457 memcpy(&filesize, data + 1, sizeof(filesize));
1430
1431 //TODO: 1458 //TODO:
1432 //filesize = ntohll(filesize); 1459 //filesize = ntohll(filesize);
1460 m->friendlist[i].file_receiving[filenumber].status = 1;
1461 m->friendlist[i].file_receiving[filenumber].size = filesize;
1462
1433 if (m->file_sendrequest) 1463 if (m->file_sendrequest)
1434 (*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t), 1464 (*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t),
1435 m->file_sendrequest_userdata); 1465 m->file_sendrequest_userdata);
@@ -1462,6 +1492,8 @@ void doFriends(Messenger *m)
1462 if (m->friendlist[i].file_receiving[filenumber].status == 0) 1492 if (m->friendlist[i].file_receiving[filenumber].status == 0)
1463 break; 1493 break;
1464 1494
1495 m->friendlist[i].file_receiving[filenumber].transferred += (data_length - 1);
1496
1465 if (m->file_filedata) 1497 if (m->file_filedata)
1466 (*m->file_filedata)(m, i, filenumber, data + 1, data_length - 1, m->file_filedata_userdata); 1498 (*m->file_filedata)(m, i, filenumber, data + 1, data_length - 1, m->file_filedata_userdata);
1467 1499