summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.h')
-rw-r--r--toxcore/Messenger.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 0ff14de4..5d31e15b 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -44,6 +44,9 @@
44#define PACKET_ID_RECEIPT 65 44#define PACKET_ID_RECEIPT 65
45#define PACKET_ID_MESSAGE 64 45#define PACKET_ID_MESSAGE 64
46#define PACKET_ID_ACTION 63 46#define PACKET_ID_ACTION 63
47#define PACKET_ID_FILE_SENDREQUEST 80
48#define PACKET_ID_FILE_CONTROL 81
49#define PACKET_ID_FILE_DATA 82
47#define PACKET_ID_INVITE_GROUPCHAT 144 50#define PACKET_ID_INVITE_GROUPCHAT 144
48#define PACKET_ID_JOIN_GROUPCHAT 145 51#define PACKET_ID_JOIN_GROUPCHAT 145
49#define PACKET_ID_ACCEPT_GROUPCHAT 146 52#define PACKET_ID_ACCEPT_GROUPCHAT 146
@@ -96,6 +99,22 @@ typedef enum {
96} 99}
97USERSTATUS; 100USERSTATUS;
98 101
102struct File_Transfers {
103 uint64_t size;
104 uint64_t transferred;
105 uint8_t status; /* 0 == no transfer, 1 = not accepted, 2 = paused by the other, 3 = transferring, 4 = broken, 5 = paused by us */
106};
107
108/* This cannot be bigger than 256 */
109#define MAX_CONCURRENT_FILE_PIPES 256
110
111enum {
112 FILECONTROL_ACCEPT,
113 FILECONTROL_PAUSE,
114 FILECONTROL_KILL,
115 FILECONTROL_FINISHED
116};
117
99typedef struct { 118typedef struct {
100 uint8_t client_id[CLIENT_ID_SIZE]; 119 uint8_t client_id[CLIENT_ID_SIZE];
101 int crypt_connection_id; 120 int crypt_connection_id;
@@ -117,6 +136,8 @@ typedef struct {
117 uint32_t friendrequest_nospam; // The nospam number used in the friend request. 136 uint32_t friendrequest_nospam; // The nospam number used in the friend request.
118 uint64_t ping_lastrecv; 137 uint64_t ping_lastrecv;
119 uint64_t ping_lastsent; 138 uint64_t ping_lastsent;
139 struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
140 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
120} Friend; 141} Friend;
121 142
122typedef struct Messenger { 143typedef struct Messenger {
@@ -157,11 +178,19 @@ typedef struct Messenger {
157 void *friend_statuschange_userdata; 178 void *friend_statuschange_userdata;
158 void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *); 179 void (*friend_connectionstatuschange)(struct Messenger *m, int, uint8_t, void *);
159 void *friend_connectionstatuschange_userdata; 180 void *friend_connectionstatuschange_userdata;
181
160 void (*group_invite)(struct Messenger *m, int, uint8_t *, void *); 182 void (*group_invite)(struct Messenger *m, int, uint8_t *, void *);
161 void *group_invite_userdata; 183 void *group_invite_userdata;
162 void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *); 184 void (*group_message)(struct Messenger *m, int, int, uint8_t *, uint16_t, void *);
163 void *group_message_userdata; 185 void *group_message_userdata;
164 186
187 void (*file_sendrequest)(struct Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, void *);
188 void *file_sendrequest_userdata;
189 void (*file_filecontrol)(struct Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t, void *);
190 void *file_filecontrol_userdata;
191 void (*file_filedata)(struct Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *);
192 void *file_filedata_userdata;
193
165} Messenger; 194} Messenger;
166 195
167/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] 196/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
@@ -439,6 +468,72 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
439 468
440int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length); 469int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length);
441 470
471/****************FILE SENDING*****************/
472
473
474/* Set the callback for file send requests.
475 *
476 * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
477 */
478void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint64_t, uint8_t *, uint16_t,
479 void *), void *userdata);
480
481/* Set the callback for file control requests.
482 *
483 * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
484 *
485 */
486void callback_file_control(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t, uint8_t, uint8_t *,
487 uint16_t, void *), void *userdata);
488
489/* Set the callback for file data.
490 *
491 * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
492 *
493 */
494void callback_file_data(Messenger *m, void (*function)(Messenger *m, int, uint8_t, uint8_t *, uint16_t length, void *),
495 void *userdata);
496
497/* Send a file send request.
498 * Maximum filename length is 255 bytes.
499 * return 1 on success
500 * return 0 on failure
501 */
502int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename,
503 uint16_t filename_length);
504
505/* Send a file send request.
506 * Maximum filename length is 255 bytes.
507 * return file number on success
508 * return -1 on failure
509 */
510int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length);
511
512/* Send a file control request.
513 * send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file.
514 *
515 * return 1 on success
516 * return 0 on failure
517 */
518int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
519 uint8_t *data, uint16_t length);
520
521/* Send file data.
522 *
523 * return 1 on success
524 * return 0 on failure
525 */
526int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length);
527
528/* Give the number of bytes left to be sent/received.
529 *
530 * send_receive is 0 if we want the sending files, 1 if we want the receiving.
531 *
532 * return number of bytes remaining to be sent/received on success
533 * return 0 on failure
534 */
535uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t send_receive);
536
442/*********************************/ 537/*********************************/
443 538
444/* Run this at startup. 539/* Run this at startup.