File transfer fixes.

Don't allow non transferring files to be paused and then resumed
starting the file transfer.
This commit is contained in:
irungentoo 2015-04-03 17:16:36 -04:00
parent 6315ff2362
commit 62dad7b3f7
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -1198,10 +1198,11 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
if (control > FILECONTROL_KILL) if (control > FILECONTROL_KILL)
return -4; return -4;
if (control == FILECONTROL_PAUSE && (ft->paused & FILE_PAUSE_US)) if (control == FILECONTROL_PAUSE && ((ft->paused & FILE_PAUSE_US) || ft->status != FILESTATUS_TRANSFERRING))
return -5; return -5;
if (control == FILECONTROL_ACCEPT && ft->status == FILESTATUS_TRANSFERRING) { if (control == FILECONTROL_ACCEPT) {
if (ft->status == FILESTATUS_TRANSFERRING) {
if (!(ft->paused & FILE_PAUSE_US)) { if (!(ft->paused & FILE_PAUSE_US)) {
if (ft->paused & FILE_PAUSE_OTHER) { if (ft->paused & FILE_PAUSE_OTHER) {
return -6; return -6;
@ -1209,6 +1210,13 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
return -7; return -7;
} }
} }
} else {
if (ft->status != FILESTATUS_NOT_ACCEPTED)
return -7;
if (!send_receive)
return -6;
}
} }
if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, 0, 0)) { if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, 0, 0)) {
@ -1550,15 +1558,23 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
} }
if (control_type == FILECONTROL_ACCEPT) { if (control_type == FILECONTROL_ACCEPT) {
if (receive_send && ft->status == FILESTATUS_NOT_ACCEPTED) {
ft->status = FILESTATUS_TRANSFERRING; ft->status = FILESTATUS_TRANSFERRING;
} else {
if (ft->paused & FILE_PAUSE_OTHER) { if (ft->paused & FILE_PAUSE_OTHER) {
ft->paused ^= FILE_PAUSE_OTHER; ft->paused ^= FILE_PAUSE_OTHER;
} else {
return -1;
}
} }
if (m->file_filecontrol) if (m->file_filecontrol)
(*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, m->file_filecontrol_userdata); (*m->file_filecontrol)(m, friendnumber, real_filenumber, control_type, m->file_filecontrol_userdata);
} else if (control_type == FILECONTROL_PAUSE) { } else if (control_type == FILECONTROL_PAUSE) {
if ((ft->paused & FILE_PAUSE_OTHER) || ft->status != FILESTATUS_TRANSFERRING) {
return -1;
}
ft->paused |= FILE_PAUSE_OTHER; ft->paused |= FILE_PAUSE_OTHER;
if (m->file_filecontrol) if (m->file_filecontrol)