diff options
-rw-r--r-- | toxcore/Messenger.c | 45 | ||||
-rw-r--r-- | toxcore/Messenger.h | 11 |
2 files changed, 33 insertions, 23 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 373fc334..9b5d75fc 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -959,11 +959,10 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin | |||
959 | 959 | ||
960 | /* Set the callback for file send requests. | 960 | /* Set the callback for file send requests. |
961 | * | 961 | * |
962 | * Function(Tox *tox, uint32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 962 | * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) |
963 | */ | 963 | */ |
964 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, uint64_t, | 964 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, uint64_t, |
965 | const uint8_t *, | 965 | const uint8_t *, size_t, void *), void *userdata) |
966 | uint16_t, void *), void *userdata) | ||
967 | { | 966 | { |
968 | m->file_sendrequest = function; | 967 | m->file_sendrequest = function; |
969 | m->file_sendrequest_userdata = userdata; | 968 | m->file_sendrequest_userdata = userdata; |
@@ -1001,8 +1000,8 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u | |||
1001 | * return 1 on success | 1000 | * return 1 on success |
1002 | * return 0 on failure | 1001 | * return 0 on failure |
1003 | */ | 1002 | */ |
1004 | static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, | 1003 | static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint32_t file_type, |
1005 | const uint8_t *filename, uint16_t filename_length) | 1004 | uint64_t filesize, const uint8_t *filename, uint16_t filename_length) |
1006 | { | 1005 | { |
1007 | if (friend_not_valid(m, friendnumber)) | 1006 | if (friend_not_valid(m, friendnumber)) |
1008 | return 0; | 1007 | return 0; |
@@ -1010,13 +1009,14 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi | |||
1010 | if (filename_length > MAX_FILENAME_LENGTH) | 1009 | if (filename_length > MAX_FILENAME_LENGTH) |
1011 | return 0; | 1010 | return 0; |
1012 | 1011 | ||
1013 | uint8_t packet[MAX_FILENAME_LENGTH + 1 + sizeof(filesize)]; | 1012 | uint8_t packet[1 + sizeof(file_type) + sizeof(filesize) + filename_length]; |
1014 | packet[0] = filenumber; | 1013 | packet[0] = filenumber; |
1014 | file_type = htonl(file_type); | ||
1015 | memcpy(packet + 1, &file_type, sizeof(file_type)); | ||
1015 | host_to_net((uint8_t *)&filesize, sizeof(filesize)); | 1016 | host_to_net((uint8_t *)&filesize, sizeof(filesize)); |
1016 | memcpy(packet + 1, &filesize, sizeof(filesize)); | 1017 | memcpy(packet + 1 + sizeof(file_type), &filesize, sizeof(filesize)); |
1017 | memcpy(packet + 1 + sizeof(filesize), filename, filename_length); | 1018 | memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize), filename, filename_length); |
1018 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, | 1019 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, sizeof(packet), 0); |
1019 | 1 + sizeof(filesize) + filename_length, 0); | ||
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | /* Send a file send request. | 1022 | /* Send a file send request. |
@@ -1040,7 +1040,7 @@ int new_filesender(const Messenger *m, int32_t friendnumber, uint64_t filesize, | |||
1040 | if (i == MAX_CONCURRENT_FILE_PIPES) | 1040 | if (i == MAX_CONCURRENT_FILE_PIPES) |
1041 | return -1; | 1041 | return -1; |
1042 | 1042 | ||
1043 | if (file_sendrequest(m, friendnumber, i, filesize, filename, filename_length) == 0) | 1043 | if (file_sendrequest(m, friendnumber, i, 0, filesize, filename, filename_length) == 0) |
1044 | return -1; | 1044 | return -1; |
1045 | 1045 | ||
1046 | m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NOT_ACCEPTED; | 1046 | m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NOT_ACCEPTED; |
@@ -1742,24 +1742,33 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len) | |||
1742 | } | 1742 | } |
1743 | 1743 | ||
1744 | case PACKET_ID_FILE_SENDREQUEST: { | 1744 | case PACKET_ID_FILE_SENDREQUEST: { |
1745 | if (data_length < 1 + sizeof(uint64_t) + 1) | 1745 | const unsigned int head_length = 1 + sizeof(uint32_t) + sizeof(uint64_t); |
1746 | |||
1747 | if (data_length < head_length + 1) | ||
1746 | break; | 1748 | break; |
1747 | 1749 | ||
1748 | uint8_t filenumber = data[0]; | 1750 | uint8_t filenumber = data[0]; |
1749 | uint64_t filesize; | 1751 | uint64_t filesize; |
1750 | memcpy(&filesize, data + 1, sizeof(filesize)); | 1752 | uint32_t file_type; |
1753 | memcpy(&file_type, data + 1, sizeof(file_type)); | ||
1754 | file_type = ntohl(file_type); | ||
1755 | |||
1756 | memcpy(&filesize, data + 1 + sizeof(uint32_t), sizeof(filesize)); | ||
1751 | net_to_host((uint8_t *) &filesize, sizeof(filesize)); | 1757 | net_to_host((uint8_t *) &filesize, sizeof(filesize)); |
1752 | m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED; | 1758 | m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED; |
1753 | m->friendlist[i].file_receiving[filenumber].size = filesize; | 1759 | m->friendlist[i].file_receiving[filenumber].size = filesize; |
1754 | m->friendlist[i].file_receiving[filenumber].transferred = 0; | 1760 | m->friendlist[i].file_receiving[filenumber].transferred = 0; |
1755 | 1761 | ||
1756 | /* Force NULL terminate file name. */ | 1762 | /* Force NULL terminate file name. */ |
1757 | uint8_t filename_terminated[data_length - 1 - sizeof(uint64_t) + 1]; | 1763 | uint8_t filename_terminated[data_length - head_length + 1]; |
1758 | memcpy(filename_terminated, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t)); | 1764 | memcpy(filename_terminated, data + head_length, data_length - head_length); |
1759 | filename_terminated[data_length - 1 - sizeof(uint64_t)] = 0; | 1765 | filename_terminated[data_length - head_length] = 0; |
1766 | |||
1767 | uint32_t real_filenumber = filenumber; | ||
1768 | real_filenumber <<= 16; | ||
1760 | 1769 | ||
1761 | if (m->file_sendrequest) | 1770 | if (m->file_sendrequest) |
1762 | (*m->file_sendrequest)(m, i, filenumber, filesize, filename_terminated, data_length - 1 - sizeof(uint64_t), | 1771 | (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename_terminated, data_length - head_length, |
1763 | m->file_sendrequest_userdata); | 1772 | m->file_sendrequest_userdata); |
1764 | 1773 | ||
1765 | break; | 1774 | break; |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 90c66e2c..fa0d241c 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -245,7 +245,8 @@ struct Messenger { | |||
245 | void (*group_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t); | 245 | void (*group_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t); |
246 | void (*group_message)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t); | 246 | void (*group_message)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t); |
247 | 247 | ||
248 | void (*file_sendrequest)(struct Messenger *m, uint32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *); | 248 | void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, unsigned int, uint64_t, const uint8_t *, size_t, |
249 | void *); | ||
249 | void *file_sendrequest_userdata; | 250 | void *file_sendrequest_userdata; |
250 | void (*file_filecontrol)(struct Messenger *m, uint32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t, void *); | 251 | void (*file_filecontrol)(struct Messenger *m, uint32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t, void *); |
251 | void *file_filecontrol_userdata; | 252 | void *file_filecontrol_userdata; |
@@ -552,11 +553,11 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin | |||
552 | 553 | ||
553 | /* Set the callback for file send requests. | 554 | /* Set the callback for file send requests. |
554 | * | 555 | * |
555 | * Function(Tox *tox, uint32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 556 | * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) |
556 | */ | 557 | */ |
557 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, uint64_t, | 558 | void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, uint64_t, |
558 | const uint8_t *, | 559 | const uint8_t *, size_t, void *), void *userdata); |
559 | uint16_t, void *), void *userdata); | 560 | |
560 | 561 | ||
561 | /* Set the callback for file control requests. | 562 | /* Set the callback for file control requests. |
562 | * | 563 | * |