diff --git a/testing/nTox.c b/testing/nTox.c index 2dd8b874..6e333abf 100644 --- a/testing/nTox.c +++ b/testing/nTox.c @@ -131,8 +131,8 @@ void send_filesenders(Tox *m) continue; while (1) { - if (!tox_file_senddata(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece, - file_senders[i].piecelength)) + if (tox_file_senddata(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece, + file_senders[i].piecelength) == -1) break; file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum), @@ -1182,7 +1182,7 @@ void file_request_accept(Tox *m, int friendnumber, uint8_t filenumber, uint64_t sprintf(msg, "[t] %u is sending us: %s of size %llu", friendnumber, filename, (long long unsigned int)filesize); new_lines(msg); - if (tox_file_sendcontrol(m, friendnumber, 1, filenumber, 0, 0, 0)) { + if (tox_file_sendcontrol(m, friendnumber, 1, filenumber, 0, 0, 0) == 0) { sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friendnumber, filenumber); new_lines(msg); } else diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 5e9758dd..954b31dd 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1185,28 +1185,28 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f /* Send a file control request. * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, uint8_t *data, uint16_t length) { if (length > MAX_DATA_SIZE - 3) - return 0; + return -1; if (friend_not_valid(m, friendnumber)) - return 0; + return -1; if (send_receive == 1) { if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) - return 0; + return -1; } else { if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) - return 0; + return -1; } if (send_receive > 1) - return 0; + return -1; uint8_t packet[MAX_DATA_SIZE]; packet[0] = send_receive; @@ -1216,7 +1216,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f if (message_id == FILECONTROL_RESUME_BROKEN) { if (length != sizeof(uint64_t)) - return 0; + return -1; uint8_t remaining[sizeof(uint64_t)]; memcpy(remaining, data, sizeof(uint64_t)); @@ -1264,32 +1264,32 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f break; } - return 1; - } else { return 0; + } else { + return -1; } } #define MIN_SLOTS_FREE 4 /* Send file data. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) { if (length > MAX_DATA_SIZE - 1) - return 0; + return -1; if (friend_not_valid(m, friendnumber)) - return 0; + return -1; if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) - return 0; + return -1; /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) - return 0; + return -1; uint8_t packet[MAX_DATA_SIZE]; packet[0] = filenumber; @@ -1297,10 +1297,10 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_DATA, packet, length + 1)) { m->friendlist[friendnumber].file_sending[filenumber].transferred += length; - return 1; + return 0; } - return 0; + return -1; } @@ -1309,7 +1309,7 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, * send_receive is 0 if we want the sending files, 1 if we want the receiving. * * return number of bytes remaining to be sent/received on success - * return 0 on failure + * return -1 on failure */ uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) { diff --git a/toxcore/tox.c b/toxcore/tox.c index d5bc1c35..f4e65ec8 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -585,8 +585,8 @@ int tox_new_filesender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *f /* Send a file control request. * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, uint8_t *data, uint16_t length) @@ -596,8 +596,8 @@ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8 } /* Send file data. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) { @@ -608,7 +608,7 @@ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *d /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() * * return size on success - * return 0 on failure (currently will never return 0) + * return -1 on failure (currently will never return -1) */ int tox_filedata_size(Tox *tox, int friendnumber) { diff --git a/toxcore/tox.h b/toxcore/tox.h index 469a1f78..ea373488 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -519,23 +519,23 @@ int tox_new_filesender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *f * send_receive is 0 if we want the control packet to target a file we are currently sending, * 1 if it targets a file we are currently receiving. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, uint8_t *data, uint16_t length); /* Send file data. * - * return 1 on success - * return 0 on failure + * return 0 on success + * return -1 on failure */ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() * * return size on success - * return 0 on failure (currently will never return 0) + * return -1 on failure (currently will never return -1) */ int tox_filedata_size(Tox *tox, int friendnumber);