forked from notsecure/uTox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_transfers.h
93 lines (81 loc) · 4.08 KB
/
file_transfers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#define MAX_FILE_TRANSFERS 32
#define FILE_TRANSFER_TEMP_PATH "transfers"
enum UTOX_FILE_TRANSFER_STATUS{
FILE_TRANSFER_STATUS_NONE,
FILE_TRANSFER_STATUS_ACTIVE,
FILE_TRANSFER_STATUS_PAUSED_US,
FILE_TRANSFER_STATUS_PAUSED_BOTH,
FILE_TRANSFER_STATUS_PAUSED_THEM,
FILE_TRANSFER_STATUS_BROKEN,
FILE_TRANSFER_STATUS_COMPLETED,
FILE_TRANSFER_STATUS_KILLED,
};
typedef struct FILE_TRANSFER {
uint32_t friend_number, file_number;
uint8_t file_id[TOX_FILE_ID_LENGTH];
uint8_t status, resume, kind;
_Bool incoming, in_memory, is_avatar; //, in_tmp_loc;
uint8_t *path, *name; //, *tmp_path;
size_t path_length, name_length; //, tmp_path_length;
uint64_t size, size_transferred;
uint8_t *memory, *avatar;
/* speed + progress calculations. */
uint32_t speed, num_packets;
uint64_t last_check_time, last_check_transferred;
FILE *file; //, *tmp_file;
MSG_FILE *ui_data;
} FILE_TRANSFER;
typedef struct {
_Bool used, incoming;
uint32_t friend_number, file_number;
uint8_t file_id[TOX_FILE_ID_LENGTH];
uint8_t file_path[UTOX_FILE_NAME_LENGTH];
FILE_TRANSFER *data;
} BROKEN_TRANSFER;
/** local callback for file transfers
*
* Called with a friend & file number, and will update it with control.
* It will also call the other needed functions for you because it's nice like
* that.
*/
void file_transfer_local_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control);
/** Callback for file transfer changes made by friend.
*
* Called via toxcore every time a friend changes file status.
*/
//static void file_transfer_callback_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, void *UNUSED(userdata));
/* Incoming files */
/* Called internally to handle avatar data */
//static void incoming_file_avatar(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data);
/* Function called by core with a new incoming file. */
//static void incoming_file_callback_request(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t kind, uint64_t file_size, const uint8_t *filename, size_t filename_length, void *user_data);
//static void incoming_file_callback_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, size_t length, void *user_data);
/* Outgoing files */
/* Send out a new file. */
void outgoing_file_send_new(Tox *tox, uint32_t friend_number, uint8_t *path, const uint8_t *filename, size_t filename_length);
/* Restarts a broken file. */
void outgoing_file_send_existing(Tox *tox, FILE_TRANSFER *broken_data, uint8_t broken_number);
/* Send an inline file/image. */
void outgoing_file_send_inline(Tox *tox, uint32_t friend_number, uint8_t *image, size_t image_size);
/* Send a newly changed avatar, called by avatar functions. */
int outgoing_file_send_avatar(Tox *tox, uint32_t friend_number, uint8_t *avatar, size_t avatar_size);
/* Function called by core to send of next chuck of *length size. */
//static void outgoing_file_callback_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, size_t length, void *user_data);
/** Helper functions
*
* utox_file_start_write() opens and sets the file handle on the disk (return -1 on failure, 0 on success)
* utox_set_callbacks_for_transfers() interfaces with toxcore setting the
* callbacks for incoming or outgoing transfers
*/
int utox_file_start_write(uint32_t friend_number, uint32_t file_number, void *filepath);
int utox_file_start_temp_write(uint32_t friend_number, uint32_t file_number);
void utox_set_callbacks_for_transfer(Tox *tox);
void utox_cleanup_file_transfers(uint32_t friend_number, uint32_t file_number);
/* Functions called when friend goes online or offline.
*/
void ft_friend_online(Tox *tox, uint32_t friend_number);
void ft_friend_offline(Tox *tox, uint32_t friend_number);
/** Functions called to store/load broken_list
*/
void utox_file_save_active(void);
void utox_file_load_active(void);