diff options
-rw-r--r-- | testing/nTox.c | 6 | ||||
-rw-r--r-- | toxcore/Messenger.c | 44 | ||||
-rw-r--r-- | toxcore/tox.c | 12 | ||||
-rw-r--r-- | toxcore/tox.h | 12 |
4 files changed, 37 insertions, 37 deletions
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) | |||
131 | continue; | 131 | continue; |
132 | 132 | ||
133 | while (1) { | 133 | while (1) { |
134 | if (!tox_file_senddata(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece, | 134 | if (tox_file_senddata(m, file_senders[i].friendnum, file_senders[i].filenumber, file_senders[i].nextpiece, |
135 | file_senders[i].piecelength)) | 135 | file_senders[i].piecelength) == -1) |
136 | break; | 136 | break; |
137 | 137 | ||
138 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum), | 138 | 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 | |||
1182 | sprintf(msg, "[t] %u is sending us: %s of size %llu", friendnumber, filename, (long long unsigned int)filesize); | 1182 | sprintf(msg, "[t] %u is sending us: %s of size %llu", friendnumber, filename, (long long unsigned int)filesize); |
1183 | new_lines(msg); | 1183 | new_lines(msg); |
1184 | 1184 | ||
1185 | if (tox_file_sendcontrol(m, friendnumber, 1, filenumber, 0, 0, 0)) { | 1185 | if (tox_file_sendcontrol(m, friendnumber, 1, filenumber, 0, 0, 0) == 0) { |
1186 | sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friendnumber, filenumber); | 1186 | sprintf(msg, "Accepted file transfer. (saving file as: %u.%u.bin)", friendnumber, filenumber); |
1187 | new_lines(msg); | 1187 | new_lines(msg); |
1188 | } else | 1188 | } else |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 5e9758dd..a3295170 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 | |||
1185 | /* Send a file control request. | 1185 | /* Send a file control request. |
1186 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. | 1186 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. |
1187 | * | 1187 | * |
1188 | * return 1 on success | 1188 | * return 0 on success |
1189 | * return 0 on failure | 1189 | * return -1 on failure |
1190 | */ | 1190 | */ |
1191 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 1191 | int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
1192 | uint8_t *data, uint16_t length) | 1192 | uint8_t *data, uint16_t length) |
1193 | { | 1193 | { |
1194 | if (length > MAX_DATA_SIZE - 3) | 1194 | if (length > MAX_DATA_SIZE - 3) |
1195 | return 0; | 1195 | return -1; |
1196 | 1196 | ||
1197 | if (friend_not_valid(m, friendnumber)) | 1197 | if (friend_not_valid(m, friendnumber)) |
1198 | return 0; | 1198 | return -1; |
1199 | 1199 | ||
1200 | if (send_receive == 1) { | 1200 | if (send_receive == 1) { |
1201 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) | 1201 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) |
1202 | return 0; | 1202 | return -1; |
1203 | } else { | 1203 | } else { |
1204 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) | 1204 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) |
1205 | return 0; | 1205 | return -1; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | if (send_receive > 1) | 1208 | if (send_receive > 1) |
1209 | return 0; | 1209 | return -1; |
1210 | 1210 | ||
1211 | uint8_t packet[MAX_DATA_SIZE]; | 1211 | uint8_t packet[MAX_DATA_SIZE]; |
1212 | packet[0] = send_receive; | 1212 | packet[0] = send_receive; |
@@ -1216,7 +1216,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
1216 | 1216 | ||
1217 | if (message_id == FILECONTROL_RESUME_BROKEN) { | 1217 | if (message_id == FILECONTROL_RESUME_BROKEN) { |
1218 | if (length != sizeof(uint64_t)) | 1218 | if (length != sizeof(uint64_t)) |
1219 | return 0; | 1219 | return -1; |
1220 | 1220 | ||
1221 | uint8_t remaining[sizeof(uint64_t)]; | 1221 | uint8_t remaining[sizeof(uint64_t)]; |
1222 | memcpy(remaining, data, sizeof(uint64_t)); | 1222 | memcpy(remaining, data, sizeof(uint64_t)); |
@@ -1264,32 +1264,32 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f | |||
1264 | break; | 1264 | break; |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | return 1; | ||
1268 | } else { | ||
1269 | return 0; | 1267 | return 0; |
1268 | } else { | ||
1269 | return -1; | ||
1270 | } | 1270 | } |
1271 | } | 1271 | } |
1272 | 1272 | ||
1273 | #define MIN_SLOTS_FREE 4 | 1273 | #define MIN_SLOTS_FREE 4 |
1274 | /* Send file data. | 1274 | /* Send file data. |
1275 | * | 1275 | * |
1276 | * return 1 on success | 1276 | * return 0 on success |
1277 | * return 0 on failure | 1277 | * return -1 on failure |
1278 | */ | 1278 | */ |
1279 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 1279 | int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
1280 | { | 1280 | { |
1281 | if (length > MAX_DATA_SIZE - 1) | 1281 | if (length > MAX_DATA_SIZE - 1) |
1282 | return 0; | 1282 | return -1; |
1283 | 1283 | ||
1284 | if (friend_not_valid(m, friendnumber)) | 1284 | if (friend_not_valid(m, friendnumber)) |
1285 | return 0; | 1285 | return -1; |
1286 | 1286 | ||
1287 | if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) | 1287 | if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING) |
1288 | return 0; | 1288 | return -1; |
1289 | 1289 | ||
1290 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ | 1290 | /* Prevent file sending from filling up the entire buffer preventing messages from being sent. */ |
1291 | if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) | 1291 | if (crypto_num_free_sendqueue_slots(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id) < MIN_SLOTS_FREE) |
1292 | return 0; | 1292 | return -1; |
1293 | 1293 | ||
1294 | uint8_t packet[MAX_DATA_SIZE]; | 1294 | uint8_t packet[MAX_DATA_SIZE]; |
1295 | packet[0] = filenumber; | 1295 | packet[0] = filenumber; |
@@ -1297,10 +1297,10 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
1297 | 1297 | ||
1298 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_DATA, packet, length + 1)) { | 1298 | if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_DATA, packet, length + 1)) { |
1299 | m->friendlist[friendnumber].file_sending[filenumber].transferred += length; | 1299 | m->friendlist[friendnumber].file_sending[filenumber].transferred += length; |
1300 | return 1; | 1300 | return 0; |
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | return 0; | 1303 | return -1; |
1304 | 1304 | ||
1305 | } | 1305 | } |
1306 | 1306 | ||
@@ -1309,22 +1309,22 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, | |||
1309 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 1309 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |
1310 | * | 1310 | * |
1311 | * return number of bytes remaining to be sent/received on success | 1311 | * return number of bytes remaining to be sent/received on success |
1312 | * return 0 on failure | 1312 | * return -1 on failure |
1313 | */ | 1313 | */ |
1314 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 1314 | uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive) |
1315 | { | 1315 | { |
1316 | if (friend_not_valid(m, friendnumber)) | 1316 | if (friend_not_valid(m, friendnumber)) |
1317 | return 0; | 1317 | return -1; |
1318 | 1318 | ||
1319 | if (send_receive == 0) { | 1319 | if (send_receive == 0) { |
1320 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) | 1320 | if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) |
1321 | return 0; | 1321 | return -1; |
1322 | 1322 | ||
1323 | return m->friendlist[friendnumber].file_sending[filenumber].size - | 1323 | return m->friendlist[friendnumber].file_sending[filenumber].size - |
1324 | m->friendlist[friendnumber].file_sending[filenumber].transferred; | 1324 | m->friendlist[friendnumber].file_sending[filenumber].transferred; |
1325 | } else { | 1325 | } else { |
1326 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) | 1326 | if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) |
1327 | return 0; | 1327 | return -1; |
1328 | 1328 | ||
1329 | return m->friendlist[friendnumber].file_receiving[filenumber].size - | 1329 | return m->friendlist[friendnumber].file_receiving[filenumber].size - |
1330 | m->friendlist[friendnumber].file_receiving[filenumber].transferred; | 1330 | m->friendlist[friendnumber].file_receiving[filenumber].transferred; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index d5bc1c35..02137b3c 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 | |||
585 | /* Send a file control request. | 585 | /* Send a file control request. |
586 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. | 586 | * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file. |
587 | * | 587 | * |
588 | * return 1 on success | 588 | * return 0 on success |
589 | * return 0 on failure | 589 | * return -1 on failure |
590 | */ | 590 | */ |
591 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 591 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
592 | uint8_t *data, uint16_t length) | 592 | uint8_t *data, uint16_t length) |
@@ -596,8 +596,8 @@ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8 | |||
596 | } | 596 | } |
597 | /* Send file data. | 597 | /* Send file data. |
598 | * | 598 | * |
599 | * return 1 on success | 599 | * return 0 on success |
600 | * return 0 on failure | 600 | * return -1 on failure |
601 | */ | 601 | */ |
602 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 602 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
603 | { | 603 | { |
@@ -608,7 +608,7 @@ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *d | |||
608 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() | 608 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() |
609 | * | 609 | * |
610 | * return size on success | 610 | * return size on success |
611 | * return 0 on failure (currently will never return 0) | 611 | * return -1 on failure (currently will never return -1) |
612 | */ | 612 | */ |
613 | int tox_filedata_size(Tox *tox, int friendnumber) | 613 | int tox_filedata_size(Tox *tox, int friendnumber) |
614 | { | 614 | { |
@@ -620,7 +620,7 @@ int tox_filedata_size(Tox *tox, int friendnumber) | |||
620 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 620 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |
621 | * | 621 | * |
622 | * return number of bytes remaining to be sent/received on success | 622 | * return number of bytes remaining to be sent/received on success |
623 | * return 0 on failure | 623 | * return -1 on failure |
624 | */ | 624 | */ |
625 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 625 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) |
626 | { | 626 | { |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 469a1f78..735d991a 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 | |||
519 | * send_receive is 0 if we want the control packet to target a file we are currently sending, | 519 | * send_receive is 0 if we want the control packet to target a file we are currently sending, |
520 | * 1 if it targets a file we are currently receiving. | 520 | * 1 if it targets a file we are currently receiving. |
521 | * | 521 | * |
522 | * return 1 on success | 522 | * return 0 on success |
523 | * return 0 on failure | 523 | * return -1 on failure |
524 | */ | 524 | */ |
525 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 525 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
526 | uint8_t *data, uint16_t length); | 526 | uint8_t *data, uint16_t length); |
527 | 527 | ||
528 | /* Send file data. | 528 | /* Send file data. |
529 | * | 529 | * |
530 | * return 1 on success | 530 | * return 0 on success |
531 | * return 0 on failure | 531 | * return -1 on failure |
532 | */ | 532 | */ |
533 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); | 533 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); |
534 | 534 | ||
535 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() | 535 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() |
536 | * | 536 | * |
537 | * return size on success | 537 | * return size on success |
538 | * return 0 on failure (currently will never return 0) | 538 | * return -1 on failure (currently will never return -1) |
539 | */ | 539 | */ |
540 | int tox_filedata_size(Tox *tox, int friendnumber); | 540 | int tox_filedata_size(Tox *tox, int friendnumber); |
541 | 541 | ||
@@ -544,7 +544,7 @@ int tox_filedata_size(Tox *tox, int friendnumber); | |||
544 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 544 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |
545 | * | 545 | * |
546 | * return number of bytes remaining to be sent/received on success | 546 | * return number of bytes remaining to be sent/received on success |
547 | * return 0 on failure | 547 | * return -1 on failure |
548 | */ | 548 | */ |
549 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive); | 549 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive); |
550 | 550 | ||