mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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.
This commit is contained in:
parent
b1ec157175
commit
f2a017c055
|
@ -202,6 +202,10 @@ void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t file_numb
|
|||
}
|
||||
|
||||
if (length == 0) {
|
||||
if (file_sending_done) {
|
||||
ck_abort_msg("File sending already done.");
|
||||
}
|
||||
|
||||
file_sending_done = 1;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1091,7 +1091,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi
|
|||
* return -2 if filename length invalid.
|
||||
* return -3 if no more file sending slots left.
|
||||
* return -4 if could not send packet (friend offline).
|
||||
*
|
||||
* return -5 if succesfully sent file send request with filesize 0.
|
||||
*/
|
||||
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
||||
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_
|
|||
if (file_sendrequest(m, friendnumber, i, file_type, filesize, file_id, filename, filename_length) == 0)
|
||||
return -4;
|
||||
|
||||
struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
|
||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||
ft->size = filesize;
|
||||
ft->transferred = 0;
|
||||
ft->requested = 0;
|
||||
ft->slots_allocated = 0;
|
||||
ft->paused = FILE_PAUSE_NOT;
|
||||
memcpy(ft->id, file_id, FILE_ID_LENGTH);
|
||||
/* Only init file if filesize isn't 0. */
|
||||
if (filesize) {
|
||||
struct File_Transfers *ft = &m->friendlist[friendnumber].file_sending[i];
|
||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||
ft->size = filesize;
|
||||
ft->transferred = 0;
|
||||
ft->requested = 0;
|
||||
ft->slots_allocated = 0;
|
||||
ft->paused = FILE_PAUSE_NOT;
|
||||
memcpy(ft->id, file_id, FILE_ID_LENGTH);
|
||||
|
||||
++m->friendlist[friendnumber].num_sending_files;
|
||||
|
||||
return i;
|
||||
++m->friendlist[friendnumber].num_sending_files;
|
||||
return i;
|
||||
} else {
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
int 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)
|
|||
net_to_host((uint8_t *) &filesize, sizeof(filesize));
|
||||
struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
|
||||
|
||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||
ft->size = filesize;
|
||||
ft->transferred = 0;
|
||||
ft->paused = FILE_PAUSE_NOT;
|
||||
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
||||
if (ft->status != FILESTATUS_NONE)
|
||||
break;
|
||||
|
||||
uint32_t real_filenumber = UINT32_MAX;
|
||||
|
||||
if (filesize) {
|
||||
/* Don't */
|
||||
ft->status = FILESTATUS_NOT_ACCEPTED;
|
||||
ft->size = filesize;
|
||||
ft->transferred = 0;
|
||||
ft->paused = FILE_PAUSE_NOT;
|
||||
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
|
||||
|
||||
real_filenumber = filenumber;
|
||||
real_filenumber += 1;
|
||||
real_filenumber <<= 16;
|
||||
}
|
||||
|
||||
uint8_t filename_terminated[filename_length + 1];
|
||||
uint8_t *filename = NULL;
|
||||
|
@ -2060,9 +2076,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
|||
filename = filename_terminated;
|
||||
}
|
||||
|
||||
uint32_t real_filenumber = filenumber;
|
||||
real_filenumber += 1;
|
||||
real_filenumber <<= 16;
|
||||
|
||||
if (m->file_sendrequest)
|
||||
(*m->file_sendrequest)(m, i, real_filenumber, file_type, filesize, filename, filename_length,
|
||||
|
|
|
@ -618,7 +618,7 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
|
|||
* return -2 if filename length invalid.
|
||||
* return -3 if no more file sending slots left.
|
||||
* return -4 if could not send packet (friend offline).
|
||||
*
|
||||
* return -5 if succesfully sent file send request with filesize 0.
|
||||
*/
|
||||
long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_type, uint64_t filesize,
|
||||
const uint8_t *file_id, const uint8_t *filename, uint16_t filename_length);
|
||||
|
|
|
@ -1000,6 +1000,10 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
|
|||
case -4:
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED);
|
||||
return UINT32_MAX;
|
||||
|
||||
case -5:
|
||||
SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK_ZERO_LENGTH);
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
/* can't happen */
|
||||
|
|
|
@ -1610,7 +1610,12 @@ typedef enum TOX_ERR_FILE_SEND {
|
|||
* Too many ongoing transfers. The maximum number of concurrent file transfers
|
||||
* is 256 per friend per direction (sending and receiving).
|
||||
*/
|
||||
TOX_ERR_FILE_SEND_TOO_MANY
|
||||
TOX_ERR_FILE_SEND_TOO_MANY,
|
||||
/**
|
||||
* A file request packet was successfully sent to the friend however since it was zero
|
||||
* length, no file number was allocated for the file transfer.
|
||||
*/
|
||||
TOX_ERR_FILE_SEND_OK_ZERO_LENGTH
|
||||
} TOX_ERR_FILE_SEND;
|
||||
|
||||
/**
|
||||
|
@ -1629,6 +1634,9 @@ typedef enum TOX_ERR_FILE_SEND {
|
|||
* When a friend goes offline, all file transfers associated with the friend are
|
||||
* purged from core.
|
||||
*
|
||||
* if file_size is 0, this function will not allocate a file transfer in core and so
|
||||
* will not return a valid file number however it will send a file request packet.
|
||||
*
|
||||
* If the file contents change during a transfer, the behaviour is unspecified
|
||||
* in general. What will actually happen depends on the mode in which the file
|
||||
* 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
|
|||
* control command before any other control commands. It can be accepted by
|
||||
* sending TOX_FILE_CONTROL_RESUME.
|
||||
*
|
||||
* If file_size is zero, the file_number is invalid and should be ignored.
|
||||
*
|
||||
* @param friend_number The friend number of the friend who is sending the file
|
||||
* transfer request.
|
||||
* @param file_number The friend-specific file number the data received is
|
||||
|
|
Loading…
Reference in New Issue
Block a user