diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 8d4d6c4bc..43fb7a1cd 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -84,16 +84,19 @@ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t uint32_t file_sent; uint32_t sendf_ok; -void file_print_control(Tox *m, int friendnumber, uint8_t send_recieve, uint8_t filenumber, uint8_t control_type, +void file_print_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) return; - if (send_recieve == 0 && control_type == TOX_FILECONTROL_FINISHED) + if (receive_send == 0 && control_type == TOX_FILECONTROL_FINISHED) + tox_file_send_control(m, friendnumber, 1, filenumber, TOX_FILECONTROL_FINISHED, NULL, 0); + + if (receive_send == 1 && control_type == TOX_FILECONTROL_FINISHED) file_sent = 1; - if (send_recieve == 1 && control_type == TOX_FILECONTROL_ACCEPT) + if (receive_send == 1 && control_type == TOX_FILECONTROL_ACCEPT) sendf_ok = 1; } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index b65f09aea..5212b9c5a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1486,9 +1486,11 @@ int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive, break; case FILECONTROL_KILL: - case FILECONTROL_FINISHED: m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE; break; + + case FILECONTROL_FINISHED: + break; } return 0; @@ -1609,8 +1611,9 @@ static int handle_filecontrol(const Messenger *m, int32_t friendnumber, uint8_t return -1; case FILECONTROL_KILL: - case FILECONTROL_FINISHED: m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE; + + case FILECONTROL_FINISHED: return 0; } } else { diff --git a/toxcore/tox.h b/toxcore/tox.h index 39beb004b..8caa01e05 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -488,6 +488,8 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT * 3. Send the data with tox_file_send_data(...) with chunk size tox_file_data_size(...) * 4. When sending is done, send a tox_file_send_control(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED + * 5. when the callback set with tox_callback_file_control(...) is called with receive_send == 1 and control_type == TOX_FILECONTROL_FINISHED + * the other person has received the file correctly. * * HOW TO RECEIVE FILES CORRECTLY: * 1. wait for the callback set with tox_callback_file_send_request(...) @@ -495,6 +497,7 @@ uint32_t tox_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); * 3. save all the data received with the callback set with tox_callback_file_data(...) to a file. * 4. when the callback set with tox_callback_file_control(...) is called with receive_send == 0 and control_type == TOX_FILECONTROL_FINISHED * the file is done transferring. + * 5. send a tox_file_send_control(...) with send_receive = 1 and message_id = TOX_FILECONTROL_FINISHED to confirm that we did receive the file. * * tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive. *