diff options
-rw-r--r-- | testing/nTox.c | 6 | ||||
-rw-r--r-- | testing/tox_sync.c | 6 | ||||
-rw-r--r-- | toxcore/tox.c | 13 | ||||
-rw-r--r-- | toxcore/tox.h | 9 |
4 files changed, 28 insertions, 6 deletions
diff --git a/testing/nTox.c b/testing/nTox.c index d9fbb7c0..9b22ff5b 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -91,7 +91,8 @@ void send_filesenders(Tox *m) | |||
91 | file_senders[i].piecelength)) | 91 | file_senders[i].piecelength)) |
92 | break; | 92 | break; |
93 | 93 | ||
94 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, 1000, file_senders[i].file); | 94 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum), |
95 | file_senders[i].file); | ||
95 | 96 | ||
96 | if (file_senders[i].piecelength == 0) { | 97 | if (file_senders[i].piecelength == 0) { |
97 | fclose(file_senders[i].file); | 98 | fclose(file_senders[i].file); |
@@ -121,7 +122,8 @@ int add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
121 | return -1; | 122 | return -1; |
122 | 123 | ||
123 | file_senders[numfilesenders].file = tempfile; | 124 | file_senders[numfilesenders].file = tempfile; |
124 | file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, 1000, | 125 | file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, tox_filedata_size(m, |
126 | file_senders[numfilesenders].friendnum), | ||
125 | file_senders[numfilesenders].file); | 127 | file_senders[numfilesenders].file); |
126 | file_senders[numfilesenders].friendnum = friendnum; | 128 | file_senders[numfilesenders].friendnum = friendnum; |
127 | file_senders[numfilesenders].filenumber = filenum; | 129 | file_senders[numfilesenders].filenumber = filenum; |
diff --git a/testing/tox_sync.c b/testing/tox_sync.c index 441fdaa0..3207e297 100644 --- a/testing/tox_sync.c +++ b/testing/tox_sync.c | |||
@@ -66,7 +66,8 @@ void send_filesenders(Tox *m) | |||
66 | file_senders[i].piecelength)) | 66 | file_senders[i].piecelength)) |
67 | break; | 67 | break; |
68 | 68 | ||
69 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, 1000, file_senders[i].file); | 69 | file_senders[i].piecelength = fread(file_senders[i].nextpiece, 1, tox_filedata_size(m, file_senders[i].friendnum), |
70 | file_senders[i].file); | ||
70 | 71 | ||
71 | if (file_senders[i].piecelength == 0) { | 72 | if (file_senders[i].piecelength == 0) { |
72 | fclose(file_senders[i].file); | 73 | fclose(file_senders[i].file); |
@@ -95,7 +96,8 @@ int add_filesender(Tox *m, uint16_t friendnum, char *filename) | |||
95 | return -1; | 96 | return -1; |
96 | 97 | ||
97 | file_senders[numfilesenders].file = tempfile; | 98 | file_senders[numfilesenders].file = tempfile; |
98 | file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, 1000, | 99 | file_senders[numfilesenders].piecelength = fread(file_senders[numfilesenders].nextpiece, 1, tox_filedata_size(m, |
100 | file_senders[numfilesenders].friendnum), | ||
99 | file_senders[numfilesenders].file); | 101 | file_senders[numfilesenders].file); |
100 | file_senders[numfilesenders].friendnum = friendnum; | 102 | file_senders[numfilesenders].friendnum = friendnum; |
101 | file_senders[numfilesenders].filenumber = filenum; | 103 | file_senders[numfilesenders].filenumber = filenum; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index ea19753f..ded2da6d 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -359,7 +359,7 @@ void tox_callback_statusmessage(Tox *tox, void (*function)(Messenger *tox, int, | |||
359 | void tox_callback_userstatus(Tox *tox, void (*_function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata) | 359 | void tox_callback_userstatus(Tox *tox, void (*_function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata) |
360 | { | 360 | { |
361 | Messenger *m = tox; | 361 | Messenger *m = tox; |
362 | typedef void (*function_type)(Messenger *, int, USERSTATUS, void *); | 362 | typedef void (*function_type)(Messenger *, int, USERSTATUS, void *); |
363 | function_type function = (function_type)_function; | 363 | function_type function = (function_type)_function; |
364 | m_callback_userstatus(m, function, userdata); | 364 | m_callback_userstatus(m, function, userdata); |
365 | } | 365 | } |
@@ -551,6 +551,17 @@ int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *d | |||
551 | Messenger *m = tox; | 551 | Messenger *m = tox; |
552 | return file_data(m, friendnumber, filenumber, data, length); | 552 | return file_data(m, friendnumber, filenumber, data, length); |
553 | } | 553 | } |
554 | |||
555 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() | ||
556 | * | ||
557 | * return size on success | ||
558 | * return 0 on failure (currently will never return 0) | ||
559 | */ | ||
560 | int tox_filedata_size(Tox *tox, int friendnumber) | ||
561 | { | ||
562 | return MAX_DATA_SIZE - crypto_box_MACBYTES - 3; | ||
563 | } | ||
564 | |||
554 | /* Give the number of bytes left to be sent/received. | 565 | /* Give the number of bytes left to be sent/received. |
555 | * | 566 | * |
556 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 567 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |
diff --git a/toxcore/tox.h b/toxcore/tox.h index 3594b1c1..db4e6b57 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -435,7 +435,7 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t | |||
435 | * HOW TO SEND FILES CORRECTLY: | 435 | * HOW TO SEND FILES CORRECTLY: |
436 | * 1. Use tox_new_filesender(...) to create a new file sender. | 436 | * 1. Use tox_new_filesender(...) to create a new file sender. |
437 | * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT | 437 | * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT |
438 | * 3. Send the data with tox_file_senddata(...) | 438 | * 3. Send the data with tox_file_senddata(...) with chunk size tox_filedata_size(...) |
439 | * 4. When sending is done, send a tox_file_sendcontrol(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED | 439 | * 4. When sending is done, send a tox_file_sendcontrol(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED |
440 | * | 440 | * |
441 | * HOW TO RECEIVE FILES CORRECTLY: | 441 | * HOW TO RECEIVE FILES CORRECTLY: |
@@ -508,6 +508,13 @@ int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8 | |||
508 | */ | 508 | */ |
509 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); | 509 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); |
510 | 510 | ||
511 | /* Returns the recommended/maximum size of the filedata you send with tox_file_senddata() | ||
512 | * | ||
513 | * return size on success | ||
514 | * return 0 on failure (currently will never return 0) | ||
515 | */ | ||
516 | int tox_filedata_size(Tox *tox, int friendnumber); | ||
517 | |||
511 | /* Give the number of bytes left to be sent/received. | 518 | /* Give the number of bytes left to be sent/received. |
512 | * | 519 | * |
513 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | 520 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. |