summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-20 21:15:44 -0400
committerirungentoo <irungentoo@gmail.com>2015-03-20 21:15:44 -0400
commitf2a017c055a8670d3bdbea2610455b45261a334e (patch)
tree65ec2203a66f00dd387b606f8ea98773b96cbf83 /toxcore
parentb1ec15717526679c6d107e3a5a4b2bf08c26b650 (diff)
Allow sending of file transfer requests with length 0 but don't allocate
any file number for them in core. These can be used to tell friends we don't have an avatar set or to unset a set avatar.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c55
-rw-r--r--toxcore/Messenger.h2
-rw-r--r--toxcore/tox.c4
-rw-r--r--toxcore/tox.h12
4 files changed, 50 insertions, 23 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 57e9c172..ac3c2752 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1091,7 +1091,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
1091 * return -2 if filename length invalid. 1091 * return -2 if filename length invalid.
1092 * return -3 if no more file sending slots left. 1092 * return -3 if no more file sending slots left.
1093 * return -4 if could not send packet (friend offline). 1093 * return -4 if could not send packet (friend offline).
1094 * 1094 * return -5 if succesfully sent file send request with filesize 0.
1095 */ 1095 */
1096long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, 1096long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
1097 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length) 1097 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length)
@@ -1115,18 +1115,22 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_
1115 if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0) 1115 if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0)
1116 return -4; 1116 return -4;
1117 1117
1118 struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i]; 1118 /* Only init file if filesize isn't 0. */
1119 ft->status = FILESTATUS_NOT_ACCEPTED; 1119 if (filesize) {
1120 ft->size = filesize; 1120 struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
1121 ft->transferred = 0; 1121 ft->status = FILESTATUS_NOT_ACCEPTED;
1122 ft->requested = 0; 1122 ft->size = filesize;
1123 ft->slots_allocated = 0; 1123 ft->transferred = 0;
1124 ft->paused = FILE_PAUSE_NOT; 1124 ft->requested = 0;
1125 memcpy(ft->id, file_id, FILE_ID_LENGTH); 1125 ft->slots_allocated = 0;
1126 1126 ft->paused = FILE_PAUSE_NOT;
1127 ++m->friendlist[friendnumber].num_sending_files; 1127 memcpy(ft->id, file_id, FILE_ID_LENGTH);
1128 1128
1129 return i; 1129 ++m->friendlist[friendnumber].num_sending_files;
1130 return i;
1131 } else {
1132 return -5;
1133 }
1130} 1134}
1131 1135
1132int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, 1136int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber,
@@ -2044,11 +2048,23 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2044 net_to_host((uint8_t *) &filesize, sizeof(filesize)); 2048 net_to_host((uint8_t *) &filesize, sizeof(filesize));
2045 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber]; 2049 struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
2046 2050
2047 ft->status = FILESTATUS_NOT_ACCEPTED; 2051 if (ft->status != FILESTATUS_NONE)
2048 ft->size = filesize; 2052 break;
2049 ft->transferred = 0; 2053
2050 ft->paused = FILE_PAUSE_NOT; 2054 uint32_t real_filenumber = UINT32_MAX;
2051 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH); 2055
2056 if (filesize) {
2057 /* Don't */
2058 ft->status = FILESTATUS_NOT_ACCEPTED;
2059 ft->size = filesize;
2060 ft->transferred = 0;
2061 ft->paused = FILE_PAUSE_NOT;
2062 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
2063
2064 real_filenumber = filenumber;
2065 real_filenumber += 1;
2066 real_filenumber <<= 16;
2067 }
2052 2068
2053 uint8_t filename_terminated[filename_length + 1]; 2069 uint8_t filename_terminated[filename_length + 1];
2054 uint8_t *filename = NULL; 2070 uint8_t *filename = NULL;
@@ -2060,9 +2076,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
2060 filename = filename_terminated; 2076 filename = filename_terminated;
2061 } 2077 }
2062 2078
2063 uint32_t real_filenumber = filenumber;
2064 real_filenumber += 1;
2065 real_filenumber <<= 16;
2066 2079
2067 if (m->file_sendrequest) 2080 if (m->file_sendrequest)
2068 (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length, 2081 (*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length,
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index d1a2ed9b..21b474f6 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -618,7 +618,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
618 * return -2 if filename length invalid. 618 * return -2 if filename length invalid.
619 * return -3 if no more file sending slots left. 619 * return -3 if no more file sending slots left.
620 * return -4 if could not send packet (friend offline). 620 * return -4 if could not send packet (friend offline).
621 * 621 * return -5 if succesfully sent file send request with filesize 0.
622 */ 622 */
623long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize, 623long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
624 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length); 624 const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 44845138..f17eb758 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -1000,6 +1000,10 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
1000 case -4: 1000 case -4:
1001 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED); 1001 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED);
1002 return UINT32_MAX; 1002 return UINT32_MAX;
1003
1004 case -5:
1005 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK_ZERO_LENGTH);
1006 return UINT32_MAX;
1003 } 1007 }
1004 1008
1005 /* can't happen */ 1009 /* can't happen */
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 5a8d6ab2..0953daee 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -1610,7 +1610,12 @@ typedef enum TOX_ERR_FILE_SEND {
1610 * Too many ongoing transfers. The maximum number of concurrent file transfers 1610 * Too many ongoing transfers. The maximum number of concurrent file transfers
1611 * is 256 per friend per direction (sending and receiving). 1611 * is 256 per friend per direction (sending and receiving).
1612 */ 1612 */
1613 TOX_ERR_FILE_SEND_TOO_MANY 1613 TOX_ERR_FILE_SEND_TOO_MANY,
1614 /**
1615 * A file request packet was successfully sent to the friend however since it was zero
1616 * length, no file number was allocated for the file transfer.
1617 */
1618 TOX_ERR_FILE_SEND_OK_ZERO_LENGTH
1614} TOX_ERR_FILE_SEND; 1619} TOX_ERR_FILE_SEND;
1615 1620
1616/** 1621/**
@@ -1629,6 +1634,9 @@ typedef enum TOX_ERR_FILE_SEND {
1629 * When a friend goes offline, all file transfers associated with the friend are 1634 * When a friend goes offline, all file transfers associated with the friend are
1630 * purged from core. 1635 * purged from core.
1631 * 1636 *
1637 * if file_size is 0, this function will not allocate a file transfer in core and so
1638 * will not return a valid file number however it will send a file request packet.
1639 *
1632 * If the file contents change during a transfer, the behaviour is unspecified 1640 * If the file contents change during a transfer, the behaviour is unspecified
1633 * in general. What will actually happen depends on the mode in which the file 1641 * in general. What will actually happen depends on the mode in which the file
1634 * was modified and how the client determines the file size. 1642 * was modified and how the client determines the file size.
@@ -1779,6 +1787,8 @@ void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *functi
1779 * control command before any other control commands. It can be accepted by 1787 * control command before any other control commands. It can be accepted by
1780 * sending TOX_FILE_CONTROL_RESUME. 1788 * sending TOX_FILE_CONTROL_RESUME.
1781 * 1789 *
1790 * If file_size is zero, the file_number is invalid and should be ignored.
1791 *
1782 * @param friend_number The friend number of the friend who is sending the file 1792 * @param friend_number The friend number of the friend who is sending the file
1783 * transfer request. 1793 * transfer request.
1784 * @param file_number The friend-specific file number the data received is 1794 * @param file_number The friend-specific file number the data received is