summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-17 13:44:48 -0400
committerirungentoo <irungentoo@gmail.com>2015-03-17 13:44:48 -0400
commit24c70c9e8479a528e02afefa4afc5c3219f9afd7 (patch)
tree8cef607ff7afc7cad003665c4a3da0d7d85eb807 /toxcore/tox.c
parent2757b254fef9354feff7527d9209232654d58126 (diff)
Added and implemented file_id parameter to file tranfers.
file_id is a 32byte identifier that can be used by users to identify file tranfers across core/client restarts in order to resume broken file tranfers. In avatar tranfers it corresponds to the hash of the avatar. Added tox_file_get_file_id() function to api to obtain the file_id of an ongoing file transfer. If not set, core will generate a random one.
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index da109502..b793bd8c 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -889,21 +889,42 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *function
889 callback_file_control(m, function, user_data); 889 callback_file_control(m, function, user_data);
890} 890}
891 891
892uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *filename, 892bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
893 size_t filename_length, TOX_ERR_FILE_SEND *error) 893 TOX_ERR_FILE_GET *error)
894{
895 const Messenger *m = tox;
896 int ret = file_get_id(m, friend_number, file_number, file_id);
897
898 if (ret == 0) {
899 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_OK);
900 return 1;
901 } else if (ret == -1) {
902 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_FRIEND_NOT_FOUND);
903 } else {
904 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NOT_FOUND);
905 }
906
907 return 0;
908}
909
910uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
911 const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error)
894{ 912{
895 if (!filename) { 913 if (!filename) {
896 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); 914 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
897 return UINT32_MAX; 915 return UINT32_MAX;
898 } 916 }
899 917
900 if (!filename_length) { 918 uint8_t f_id[FILE_ID_LENGTH];
901 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NAME_EMPTY); 919
902 return UINT32_MAX; 920 if (!file_id) {
921 /* Tox keys are 32 bytes like FILE_ID_LENGTH. */
922 new_symmetric_key(f_id);
923 file_id = f_id;
903 } 924 }
904 925
905 Messenger *m = tox; 926 Messenger *m = tox;
906 long int file_num = new_filesender(m, friend_number, kind, file_size, filename, filename_length); 927 long int file_num = new_filesender(m, friend_number, kind, file_size, file_id, filename, filename_length);
907 928
908 if (file_num >= 0) { 929 if (file_num >= 0) {
909 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK); 930 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_OK);