ffi-tox 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ProjectTox-Core/AUTHORS +0 -0
- data/ProjectTox-Core/ChangeLog +0 -0
- data/ProjectTox-Core/INSTALL +370 -0
- data/ProjectTox-Core/INSTALL.md +455 -56
- data/ProjectTox-Core/Makefile.am +35 -0
- data/ProjectTox-Core/NEWS +0 -0
- data/ProjectTox-Core/README +43 -0
- data/ProjectTox-Core/README.md +34 -44
- data/ProjectTox-Core/auto_tests/Makefile.inc +110 -0
- data/ProjectTox-Core/auto_tests/TCP_test.c +519 -0
- data/ProjectTox-Core/auto_tests/assoc_test.c +160 -0
- data/ProjectTox-Core/auto_tests/crypto_test.c +302 -0
- data/ProjectTox-Core/auto_tests/dht_test.c +362 -0
- data/ProjectTox-Core/auto_tests/encryptsave_test.c +104 -0
- data/ProjectTox-Core/auto_tests/friends_test.c +238 -0
- data/ProjectTox-Core/auto_tests/helpers.h +15 -0
- data/ProjectTox-Core/auto_tests/messenger_test.c +365 -0
- data/ProjectTox-Core/auto_tests/network_test.c +171 -0
- data/ProjectTox-Core/auto_tests/onion_test.c +363 -0
- data/ProjectTox-Core/auto_tests/skeleton_test.c +49 -0
- data/ProjectTox-Core/auto_tests/tox_test.c +454 -0
- data/ProjectTox-Core/auto_tests/toxav_basic_test.c +597 -0
- data/ProjectTox-Core/auto_tests/toxav_many_test.c +402 -0
- data/ProjectTox-Core/autogen.sh +6 -0
- data/ProjectTox-Core/build/Makefile.am +14 -0
- data/ProjectTox-Core/configure.ac +694 -0
- data/ProjectTox-Core/dist-build/android-arm.sh +3 -0
- data/ProjectTox-Core/dist-build/android-armv7.sh +3 -0
- data/ProjectTox-Core/dist-build/android-build.sh +59 -0
- data/ProjectTox-Core/dist-build/android-mips.sh +3 -0
- data/ProjectTox-Core/dist-build/android-x86.sh +3 -0
- data/ProjectTox-Core/docs/Group-Chats.md +71 -0
- data/ProjectTox-Core/docs/Hardening.txt +60 -0
- data/ProjectTox-Core/docs/Hardening_docs.txt +30 -0
- data/ProjectTox-Core/docs/Prevent_Tracking.txt +160 -0
- data/ProjectTox-Core/docs/TCP_Network.txt +154 -0
- data/ProjectTox-Core/docs/TODO +62 -0
- data/ProjectTox-Core/docs/Tox_middle_level_network_protocol.txt +120 -0
- data/ProjectTox-Core/docs/av_api.md +194 -0
- data/ProjectTox-Core/libtoxav.pc.in +11 -0
- data/ProjectTox-Core/libtoxcore.pc.in +11 -0
- data/ProjectTox-Core/m4/ax_have_epoll.m4 +104 -0
- data/ProjectTox-Core/m4/ax_pthread.m4 +317 -0
- data/ProjectTox-Core/m4/pkg.m4 +199 -0
- data/ProjectTox-Core/other/DHT_bootstrap.c +121 -58
- data/ProjectTox-Core/other/DHTnodes +3 -0
- data/ProjectTox-Core/other/Makefile.inc +20 -0
- data/ProjectTox-Core/other/bootstrap_node_packets.c +65 -0
- data/ProjectTox-Core/other/tox.png +0 -0
- data/ProjectTox-Core/testing/DHT_test.c +170 -98
- data/ProjectTox-Core/testing/Makefile.inc +112 -0
- data/ProjectTox-Core/testing/Messenger_test.c +133 -69
- data/ProjectTox-Core/testing/dns3_test.c +115 -0
- data/ProjectTox-Core/testing/misc_tools.c +59 -13
- data/ProjectTox-Core/testing/nTox.c +1127 -264
- data/ProjectTox-Core/testing/nTox.h +10 -19
- data/ProjectTox-Core/testing/tox_shell.c +159 -0
- data/ProjectTox-Core/testing/tox_sync.c +299 -0
- data/ProjectTox-Core/tools/README +11 -0
- data/ProjectTox-Core/tools/astylerc +11 -0
- data/ProjectTox-Core/tools/pre-commit +17 -0
- data/ProjectTox-Core/toxav/Makefile.inc +36 -0
- data/ProjectTox-Core/toxav/codec.c +357 -0
- data/ProjectTox-Core/toxav/codec.h +116 -0
- data/ProjectTox-Core/toxav/msi.c +1949 -0
- data/ProjectTox-Core/toxav/msi.h +267 -0
- data/ProjectTox-Core/toxav/rtp.c +600 -0
- data/ProjectTox-Core/toxav/rtp.h +196 -0
- data/ProjectTox-Core/toxav/toxav.c +1148 -0
- data/ProjectTox-Core/toxav/toxav.h +389 -0
- data/ProjectTox-Core/toxcore/DHT.c +2521 -0
- data/ProjectTox-Core/toxcore/DHT.h +412 -0
- data/ProjectTox-Core/toxcore/LAN_discovery.c +322 -0
- data/ProjectTox-Core/{core → toxcore}/LAN_discovery.h +17 -12
- data/ProjectTox-Core/toxcore/Makefile.inc +67 -0
- data/ProjectTox-Core/toxcore/Messenger.c +3006 -0
- data/ProjectTox-Core/toxcore/Messenger.h +818 -0
- data/ProjectTox-Core/toxcore/TCP_client.c +858 -0
- data/ProjectTox-Core/toxcore/TCP_client.h +156 -0
- data/ProjectTox-Core/toxcore/TCP_server.c +1332 -0
- data/ProjectTox-Core/toxcore/TCP_server.h +181 -0
- data/ProjectTox-Core/toxcore/assoc.c +1033 -0
- data/ProjectTox-Core/toxcore/assoc.h +104 -0
- data/ProjectTox-Core/toxcore/crypto_core.c +278 -0
- data/ProjectTox-Core/toxcore/crypto_core.h +151 -0
- data/ProjectTox-Core/toxcore/friend_requests.c +175 -0
- data/ProjectTox-Core/toxcore/friend_requests.h +83 -0
- data/ProjectTox-Core/toxcore/group_chats.c +837 -0
- data/ProjectTox-Core/toxcore/group_chats.h +199 -0
- data/ProjectTox-Core/toxcore/list.c +256 -0
- data/ProjectTox-Core/toxcore/list.h +85 -0
- data/ProjectTox-Core/toxcore/logger.c +153 -0
- data/ProjectTox-Core/toxcore/logger.h +84 -0
- data/ProjectTox-Core/toxcore/misc_tools.h +70 -0
- data/ProjectTox-Core/toxcore/net_crypto.c +2753 -0
- data/ProjectTox-Core/toxcore/net_crypto.h +410 -0
- data/ProjectTox-Core/toxcore/network.c +979 -0
- data/ProjectTox-Core/toxcore/network.h +367 -0
- data/ProjectTox-Core/toxcore/onion.c +540 -0
- data/ProjectTox-Core/toxcore/onion.h +150 -0
- data/ProjectTox-Core/toxcore/onion_announce.c +433 -0
- data/ProjectTox-Core/toxcore/onion_announce.h +139 -0
- data/ProjectTox-Core/toxcore/onion_client.c +1347 -0
- data/ProjectTox-Core/toxcore/onion_client.h +253 -0
- data/ProjectTox-Core/toxcore/ping.c +346 -0
- data/ProjectTox-Core/toxcore/ping.h +47 -0
- data/ProjectTox-Core/toxcore/ping_array.c +162 -0
- data/ProjectTox-Core/toxcore/ping_array.h +75 -0
- data/ProjectTox-Core/toxcore/tox.c +940 -0
- data/ProjectTox-Core/toxcore/tox.h +734 -0
- data/ProjectTox-Core/toxcore/util.c +193 -0
- data/ProjectTox-Core/toxcore/util.h +63 -0
- data/ProjectTox-Core/toxdns/Makefile.inc +29 -0
- data/ProjectTox-Core/toxdns/toxdns.c +238 -0
- data/ProjectTox-Core/toxdns/toxdns.h +88 -0
- data/ProjectTox-Core/toxencryptsave/Makefile.inc +45 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.c +179 -0
- data/ProjectTox-Core/toxencryptsave/toxencryptsave.h +74 -0
- data/interfaces/libtox.i +2 -6
- data/lib/ffi-tox/libtox.rb +406 -28
- metadata +124 -46
- data/ProjectTox-Core/CMakeLists.txt +0 -50
- data/ProjectTox-Core/cmake/FindLIBCONFIG.cmake +0 -15
- data/ProjectTox-Core/cmake/FindNaCl.cmake +0 -17
- data/ProjectTox-Core/cmake/FindSODIUM.cmake +0 -15
- data/ProjectTox-Core/core/CMakeLists.txt +0 -19
- data/ProjectTox-Core/core/DHT.c +0 -1104
- data/ProjectTox-Core/core/DHT.h +0 -111
- data/ProjectTox-Core/core/LAN_discovery.c +0 -79
- data/ProjectTox-Core/core/Lossless_UDP.c +0 -755
- data/ProjectTox-Core/core/Lossless_UDP.h +0 -106
- data/ProjectTox-Core/core/Messenger.c +0 -596
- data/ProjectTox-Core/core/Messenger.h +0 -165
- data/ProjectTox-Core/core/friend_requests.c +0 -131
- data/ProjectTox-Core/core/friend_requests.h +0 -51
- data/ProjectTox-Core/core/net_crypto.c +0 -575
- data/ProjectTox-Core/core/net_crypto.h +0 -134
- data/ProjectTox-Core/core/network.c +0 -205
- data/ProjectTox-Core/core/network.h +0 -134
- data/ProjectTox-Core/docs/commands.md +0 -25
- data/ProjectTox-Core/docs/start_guide.de.md +0 -40
- data/ProjectTox-Core/docs/start_guide.md +0 -38
- data/ProjectTox-Core/other/CMakeLists.txt +0 -9
- data/ProjectTox-Core/testing/CMakeLists.txt +0 -18
- data/ProjectTox-Core/testing/DHT_cryptosendfiletest.c +0 -228
- data/ProjectTox-Core/testing/DHT_sendfiletest.c +0 -176
- data/ProjectTox-Core/testing/Lossless_UDP_testclient.c +0 -214
- data/ProjectTox-Core/testing/Lossless_UDP_testserver.c +0 -201
- data/ProjectTox-Core/testing/misc_tools.h +0 -29
- data/ProjectTox-Core/testing/nTox_win32.c +0 -387
- data/ProjectTox-Core/testing/nTox_win32.h +0 -40
- data/ProjectTox-Core/testing/rect.py +0 -45
@@ -0,0 +1,818 @@
|
|
1
|
+
/* Messenger.h
|
2
|
+
*
|
3
|
+
* An implementation of a simple text chat only messenger on the tox network core.
|
4
|
+
*
|
5
|
+
* NOTE: All the text in the messages must be encoded using UTF-8
|
6
|
+
*
|
7
|
+
* Copyright (C) 2013 Tox project All Rights Reserved.
|
8
|
+
*
|
9
|
+
* This file is part of Tox.
|
10
|
+
*
|
11
|
+
* Tox is free software: you can redistribute it and/or modify
|
12
|
+
* it under the terms of the GNU General Public License as published by
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
14
|
+
* (at your option) any later version.
|
15
|
+
*
|
16
|
+
* Tox is distributed in the hope that it will be useful,
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
* GNU General Public License for more details.
|
20
|
+
*
|
21
|
+
* You should have received a copy of the GNU General Public License
|
22
|
+
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
23
|
+
*
|
24
|
+
*/
|
25
|
+
|
26
|
+
#ifndef MESSENGER_H
|
27
|
+
#define MESSENGER_H
|
28
|
+
|
29
|
+
#include "net_crypto.h"
|
30
|
+
#include "DHT.h"
|
31
|
+
#include "friend_requests.h"
|
32
|
+
#include "LAN_discovery.h"
|
33
|
+
#include "group_chats.h"
|
34
|
+
#include "onion_client.h"
|
35
|
+
|
36
|
+
#define MAX_NAME_LENGTH 128
|
37
|
+
/* TODO: this must depend on other variable. */
|
38
|
+
#define MAX_STATUSMESSAGE_LENGTH 1007
|
39
|
+
|
40
|
+
#define FRIEND_ADDRESS_SIZE (crypto_box_PUBLICKEYBYTES + sizeof(uint32_t) + sizeof(uint16_t))
|
41
|
+
|
42
|
+
/* NOTE: Packet ids below 16 must never be used. */
|
43
|
+
#define PACKET_ID_ALIVE 16
|
44
|
+
#define PACKET_ID_SHARE_RELAYS 17
|
45
|
+
#define PACKET_ID_NICKNAME 48
|
46
|
+
#define PACKET_ID_STATUSMESSAGE 49
|
47
|
+
#define PACKET_ID_USERSTATUS 50
|
48
|
+
#define PACKET_ID_TYPING 51
|
49
|
+
#define PACKET_ID_RECEIPT 63
|
50
|
+
#define PACKET_ID_MESSAGE 64
|
51
|
+
#define PACKET_ID_ACTION 65
|
52
|
+
#define PACKET_ID_MSI 69
|
53
|
+
#define PACKET_ID_FILE_SENDREQUEST 80
|
54
|
+
#define PACKET_ID_FILE_CONTROL 81
|
55
|
+
#define PACKET_ID_FILE_DATA 82
|
56
|
+
#define PACKET_ID_INVITE_GROUPCHAT 144
|
57
|
+
#define PACKET_ID_JOIN_GROUPCHAT 145
|
58
|
+
#define PACKET_ID_ACCEPT_GROUPCHAT 146
|
59
|
+
|
60
|
+
/* Max number of groups we can invite someone at the same time to. */
|
61
|
+
#define MAX_INVITED_GROUPS 64
|
62
|
+
|
63
|
+
/* Max number of tcp relays sent to friends */
|
64
|
+
#define MAX_SHARED_RELAYS 16
|
65
|
+
|
66
|
+
/* All packets starting with a byte in this range can be used for anything. */
|
67
|
+
#define PACKET_ID_LOSSLESS_RANGE_START 160
|
68
|
+
#define PACKET_ID_LOSSLESS_RANGE_SIZE 32
|
69
|
+
|
70
|
+
typedef struct {
|
71
|
+
uint8_t ipv6enabled;
|
72
|
+
uint8_t udp_disabled;
|
73
|
+
uint8_t proxy_enabled;
|
74
|
+
TCP_Proxy_Info proxy_info;
|
75
|
+
} Messenger_Options;
|
76
|
+
|
77
|
+
/* Status definitions. */
|
78
|
+
enum {
|
79
|
+
NOFRIEND,
|
80
|
+
FRIEND_ADDED,
|
81
|
+
FRIEND_REQUESTED,
|
82
|
+
FRIEND_CONFIRMED,
|
83
|
+
FRIEND_ONLINE,
|
84
|
+
};
|
85
|
+
|
86
|
+
/* Errors for m_addfriend
|
87
|
+
* FAERR - Friend Add Error
|
88
|
+
*/
|
89
|
+
enum {
|
90
|
+
FAERR_TOOLONG = -1,
|
91
|
+
FAERR_NOMESSAGE = -2,
|
92
|
+
FAERR_OWNKEY = -3,
|
93
|
+
FAERR_ALREADYSENT = -4,
|
94
|
+
FAERR_UNKNOWN = -5,
|
95
|
+
FAERR_BADCHECKSUM = -6,
|
96
|
+
FAERR_SETNEWNOSPAM = -7,
|
97
|
+
FAERR_NOMEM = -8
|
98
|
+
};
|
99
|
+
|
100
|
+
/* Default start timeout in seconds between friend requests. */
|
101
|
+
#define FRIENDREQUEST_TIMEOUT 5;
|
102
|
+
|
103
|
+
/* Interval between the sending of ping packets. */
|
104
|
+
#define FRIEND_PING_INTERVAL 6
|
105
|
+
|
106
|
+
/* Interval between the sending of tcp relay information */
|
107
|
+
#define FRIEND_SHARE_RELAYS_INTERVAL (5 * 60)
|
108
|
+
|
109
|
+
/* If no packets are received from friend in this time interval, kill the connection. */
|
110
|
+
#define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 3)
|
111
|
+
|
112
|
+
|
113
|
+
/* USERSTATUS -
|
114
|
+
* Represents userstatuses someone can have.
|
115
|
+
*/
|
116
|
+
|
117
|
+
typedef enum {
|
118
|
+
USERSTATUS_NONE,
|
119
|
+
USERSTATUS_AWAY,
|
120
|
+
USERSTATUS_BUSY,
|
121
|
+
USERSTATUS_INVALID
|
122
|
+
}
|
123
|
+
USERSTATUS;
|
124
|
+
|
125
|
+
struct File_Transfers {
|
126
|
+
uint64_t size;
|
127
|
+
uint64_t transferred;
|
128
|
+
uint8_t status; /* 0 == no transfer, 1 = not accepted, 2 = paused by the other, 3 = transferring, 4 = broken, 5 = paused by us */
|
129
|
+
};
|
130
|
+
enum {
|
131
|
+
FILESTATUS_NONE,
|
132
|
+
FILESTATUS_NOT_ACCEPTED,
|
133
|
+
FILESTATUS_PAUSED_BY_OTHER,
|
134
|
+
FILESTATUS_TRANSFERRING,
|
135
|
+
FILESTATUS_BROKEN,
|
136
|
+
FILESTATUS_PAUSED_BY_US,
|
137
|
+
FILESTATUS_TEMPORARY
|
138
|
+
};
|
139
|
+
/* This cannot be bigger than 256 */
|
140
|
+
#define MAX_CONCURRENT_FILE_PIPES 256
|
141
|
+
|
142
|
+
enum {
|
143
|
+
FILECONTROL_ACCEPT,
|
144
|
+
FILECONTROL_PAUSE,
|
145
|
+
FILECONTROL_KILL,
|
146
|
+
FILECONTROL_FINISHED,
|
147
|
+
FILECONTROL_RESUME_BROKEN
|
148
|
+
};
|
149
|
+
|
150
|
+
typedef struct {
|
151
|
+
uint8_t client_id[CLIENT_ID_SIZE];
|
152
|
+
uint32_t onion_friendnum;
|
153
|
+
int crypt_connection_id;
|
154
|
+
uint64_t friendrequest_lastsent; // Time at which the last friend request was sent.
|
155
|
+
uint32_t friendrequest_timeout; // The timeout between successful friendrequest sending attempts.
|
156
|
+
uint8_t status; // 0 if no friend, 1 if added, 2 if friend request sent, 3 if confirmed friend, 4 if online.
|
157
|
+
uint8_t info[MAX_FRIEND_REQUEST_DATA_SIZE]; // the data that is sent during the friend requests we do.
|
158
|
+
uint8_t name[MAX_NAME_LENGTH];
|
159
|
+
uint16_t name_length;
|
160
|
+
uint8_t name_sent; // 0 if we didn't send our name to this friend 1 if we have.
|
161
|
+
uint8_t *statusmessage;
|
162
|
+
uint16_t statusmessage_length;
|
163
|
+
uint8_t statusmessage_sent;
|
164
|
+
USERSTATUS userstatus;
|
165
|
+
uint8_t userstatus_sent;
|
166
|
+
uint8_t user_istyping;
|
167
|
+
uint8_t user_istyping_sent;
|
168
|
+
uint8_t is_typing;
|
169
|
+
uint16_t info_size; // Length of the info.
|
170
|
+
uint32_t message_id; // a semi-unique id used in read receipts.
|
171
|
+
uint8_t receives_read_receipts; // shall we send read receipts to this person?
|
172
|
+
uint32_t friendrequest_nospam; // The nospam number used in the friend request.
|
173
|
+
uint64_t ping_lastrecv;
|
174
|
+
uint64_t ping_lastsent;
|
175
|
+
uint64_t share_relays_lastsent;
|
176
|
+
struct File_Transfers file_sending[MAX_CONCURRENT_FILE_PIPES];
|
177
|
+
struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
|
178
|
+
int invited_groups[MAX_INVITED_GROUPS];
|
179
|
+
uint16_t invited_groups_num;
|
180
|
+
|
181
|
+
struct {
|
182
|
+
int (*function)(void *object, const uint8_t *data, uint32_t len);
|
183
|
+
void *object;
|
184
|
+
} lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
|
185
|
+
|
186
|
+
struct {
|
187
|
+
int (*function)(void *object, const uint8_t *data, uint32_t len);
|
188
|
+
void *object;
|
189
|
+
} lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
|
190
|
+
} Friend;
|
191
|
+
|
192
|
+
|
193
|
+
typedef struct Messenger {
|
194
|
+
|
195
|
+
Networking_Core *net;
|
196
|
+
Net_Crypto *net_crypto;
|
197
|
+
DHT *dht;
|
198
|
+
|
199
|
+
Onion *onion;
|
200
|
+
Onion_Announce *onion_a;
|
201
|
+
Onion_Client *onion_c;
|
202
|
+
|
203
|
+
Friend_Requests fr;
|
204
|
+
uint8_t name[MAX_NAME_LENGTH];
|
205
|
+
uint16_t name_length;
|
206
|
+
|
207
|
+
uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
|
208
|
+
uint16_t statusmessage_length;
|
209
|
+
|
210
|
+
USERSTATUS userstatus;
|
211
|
+
|
212
|
+
Friend *friendlist;
|
213
|
+
uint32_t numfriends;
|
214
|
+
|
215
|
+
uint32_t numonline_friends;
|
216
|
+
|
217
|
+
Group_Chat **chats;
|
218
|
+
uint32_t numchats;
|
219
|
+
|
220
|
+
uint64_t last_LANdiscovery;
|
221
|
+
|
222
|
+
#define NUM_SAVED_TCP_RELAYS 8
|
223
|
+
uint8_t has_added_relays; // If the first connection has occurred in do_messenger
|
224
|
+
Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
|
225
|
+
|
226
|
+
void (*friend_message)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
227
|
+
void *friend_message_userdata;
|
228
|
+
void (*friend_action)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
229
|
+
void *friend_action_userdata;
|
230
|
+
void (*friend_namechange)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
231
|
+
void *friend_namechange_userdata;
|
232
|
+
void (*friend_statusmessagechange)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
233
|
+
void *friend_statusmessagechange_userdata;
|
234
|
+
void (*friend_userstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
235
|
+
void *friend_userstatuschange_userdata;
|
236
|
+
void (*friend_typingchange)(struct Messenger *m, int32_t, uint8_t, void *);
|
237
|
+
void *friend_typingchange_userdata;
|
238
|
+
void (*read_receipt)(struct Messenger *m, int32_t, uint32_t, void *);
|
239
|
+
void *read_receipt_userdata;
|
240
|
+
void (*friend_statuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
241
|
+
void *friend_statuschange_userdata;
|
242
|
+
void (*friend_connectionstatuschange)(struct Messenger *m, int32_t, uint8_t, void *);
|
243
|
+
void *friend_connectionstatuschange_userdata;
|
244
|
+
void (*friend_connectionstatuschange_internal)(struct Messenger *m, int32_t, uint8_t, void *);
|
245
|
+
void *friend_connectionstatuschange_internal_userdata;
|
246
|
+
|
247
|
+
void (*group_invite)(struct Messenger *m, int32_t, const uint8_t *, void *);
|
248
|
+
void *group_invite_userdata;
|
249
|
+
void (*group_message)(struct Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
250
|
+
void *group_message_userdata;
|
251
|
+
void (*group_action)(struct Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
252
|
+
void *group_action_userdata;
|
253
|
+
void (*group_namelistchange)(struct Messenger *m, int, int, uint8_t, void *);
|
254
|
+
void *group_namelistchange_userdata;
|
255
|
+
|
256
|
+
void (*file_sendrequest)(struct Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *, uint16_t, void *);
|
257
|
+
void *file_sendrequest_userdata;
|
258
|
+
void (*file_filecontrol)(struct Messenger *m, int32_t, uint8_t, uint8_t, uint8_t, const uint8_t *, uint16_t, void *);
|
259
|
+
void *file_filecontrol_userdata;
|
260
|
+
void (*file_filedata)(struct Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t length, void *);
|
261
|
+
void *file_filedata_userdata;
|
262
|
+
|
263
|
+
void (*msi_packet)(struct Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
264
|
+
void *msi_packet_userdata;
|
265
|
+
|
266
|
+
Messenger_Options options;
|
267
|
+
} Messenger;
|
268
|
+
|
269
|
+
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
|
270
|
+
*
|
271
|
+
* return FRIEND_ADDRESS_SIZE byte address to give to others.
|
272
|
+
*/
|
273
|
+
void getaddress(const Messenger *m, uint8_t *address);
|
274
|
+
|
275
|
+
/* Add a friend.
|
276
|
+
* Set the data that will be sent along with friend request.
|
277
|
+
* address is the address of the friend (returned by getaddress of the friend you wish to add) it must be FRIEND_ADDRESS_SIZE bytes. TODO: add checksum.
|
278
|
+
* data is the data and length is the length.
|
279
|
+
*
|
280
|
+
* return the friend number if success.
|
281
|
+
* return -1 if message length is too long.
|
282
|
+
* return -2 if no message (message length must be >= 1 byte).
|
283
|
+
* return -3 if user's own key.
|
284
|
+
* return -4 if friend request already sent or already a friend.
|
285
|
+
* return -5 for unknown error.
|
286
|
+
* return -6 if bad checksum in address.
|
287
|
+
* return -7 if the friend was already there but the nospam was different.
|
288
|
+
* (the nospam for that friend was set to the new one).
|
289
|
+
* return -8 if increasing the friend list size fails.
|
290
|
+
*/
|
291
|
+
int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, uint16_t length);
|
292
|
+
|
293
|
+
|
294
|
+
/* Add a friend without sending a friendrequest.
|
295
|
+
* return the friend number if success.
|
296
|
+
* return -1 if failure.
|
297
|
+
*/
|
298
|
+
int32_t m_addfriend_norequest(Messenger *m, const uint8_t *client_id);
|
299
|
+
|
300
|
+
/* return the friend number associated to that client id.
|
301
|
+
* return -1 if no such friend.
|
302
|
+
*/
|
303
|
+
int32_t getfriend_id(const Messenger *m, const uint8_t *client_id);
|
304
|
+
|
305
|
+
/* Copies the public key associated to that friend id into client_id buffer.
|
306
|
+
* Make sure that client_id is of size CLIENT_ID_SIZE.
|
307
|
+
*
|
308
|
+
* return 0 if success
|
309
|
+
* return -1 if failure
|
310
|
+
*/
|
311
|
+
int getclient_id(const Messenger *m, int32_t friendnumber, uint8_t *client_id);
|
312
|
+
|
313
|
+
/* Remove a friend.
|
314
|
+
*
|
315
|
+
* return 0 if success
|
316
|
+
* return -1 if failure
|
317
|
+
*/
|
318
|
+
int m_delfriend(Messenger *m, int32_t friendnumber);
|
319
|
+
|
320
|
+
/* Checks friend's connecting status.
|
321
|
+
*
|
322
|
+
* return 1 if friend is connected to us (Online).
|
323
|
+
* return 0 if friend is not connected to us (Offline).
|
324
|
+
* return -1 on failure.
|
325
|
+
*/
|
326
|
+
int m_get_friend_connectionstatus(const Messenger *m, int32_t friendnumber);
|
327
|
+
|
328
|
+
/* Checks if there exists a friend with given friendnumber.
|
329
|
+
*
|
330
|
+
* return 1 if friend exists.
|
331
|
+
* return 0 if friend doesn't exist.
|
332
|
+
*/
|
333
|
+
int m_friend_exists(const Messenger *m, int32_t friendnumber);
|
334
|
+
|
335
|
+
/* Send a text chat message to an online friend.
|
336
|
+
*
|
337
|
+
* return the message id if packet was successfully put into the send queue.
|
338
|
+
* return 0 if it was not.
|
339
|
+
*
|
340
|
+
* You will want to retain the return value, it will be passed to your read_receipt callback
|
341
|
+
* if one is received.
|
342
|
+
* m_sendmessage_withid will send a message with the id of your choosing,
|
343
|
+
* however we can generate an id for you by calling plain m_sendmessage.
|
344
|
+
*/
|
345
|
+
uint32_t m_sendmessage(Messenger *m, int32_t friendnumber, const uint8_t *message, uint32_t length);
|
346
|
+
uint32_t m_sendmessage_withid(Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *message,
|
347
|
+
uint32_t length);
|
348
|
+
|
349
|
+
/* Send an action to an online friend.
|
350
|
+
*
|
351
|
+
* return the message id if packet was successfully put into the send queue.
|
352
|
+
* return 0 if it was not.
|
353
|
+
*
|
354
|
+
* You will want to retain the return value, it will be passed to your read_receipt callback
|
355
|
+
* if one is received.
|
356
|
+
* m_sendaction_withid will send an action message with the id of your choosing,
|
357
|
+
* however we can generate an id for you by calling plain m_sendaction.
|
358
|
+
*/
|
359
|
+
uint32_t m_sendaction(Messenger *m, int32_t friendnumber, const uint8_t *action, uint32_t length);
|
360
|
+
uint32_t m_sendaction_withid(const Messenger *m, int32_t friendnumber, uint32_t theid, const uint8_t *action,
|
361
|
+
uint32_t length);
|
362
|
+
|
363
|
+
/* Set the name and name_length of a friend.
|
364
|
+
* name must be a string of maximum MAX_NAME_LENGTH length.
|
365
|
+
* length must be at least 1 byte.
|
366
|
+
* length is the length of name with the NULL terminator.
|
367
|
+
*
|
368
|
+
* return 0 if success.
|
369
|
+
* return -1 if failure.
|
370
|
+
*/
|
371
|
+
int setfriendname(Messenger *m, int32_t friendnumber, const uint8_t *name, uint16_t length);
|
372
|
+
|
373
|
+
/* Set our nickname.
|
374
|
+
* name must be a string of maximum MAX_NAME_LENGTH length.
|
375
|
+
* length must be at least 1 byte.
|
376
|
+
* length is the length of name with the NULL terminator.
|
377
|
+
*
|
378
|
+
* return 0 if success.
|
379
|
+
* return -1 if failure.
|
380
|
+
*/
|
381
|
+
int setname(Messenger *m, const uint8_t *name, uint16_t length);
|
382
|
+
|
383
|
+
/*
|
384
|
+
* Get your nickname.
|
385
|
+
* m - The messenger context to use.
|
386
|
+
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes.
|
387
|
+
*
|
388
|
+
* return length of the name.
|
389
|
+
* return 0 on error.
|
390
|
+
*/
|
391
|
+
uint16_t getself_name(const Messenger *m, uint8_t *name);
|
392
|
+
|
393
|
+
/* Get name of friendnumber and put it in name.
|
394
|
+
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
|
395
|
+
*
|
396
|
+
* return length of name if success.
|
397
|
+
* return -1 if failure.
|
398
|
+
*/
|
399
|
+
int getname(const Messenger *m, int32_t friendnumber, uint8_t *name);
|
400
|
+
|
401
|
+
/* return the length of name, including null on success.
|
402
|
+
* return -1 on failure.
|
403
|
+
*/
|
404
|
+
int m_get_name_size(const Messenger *m, int32_t friendnumber);
|
405
|
+
int m_get_self_name_size(const Messenger *m);
|
406
|
+
|
407
|
+
/* Set our user status.
|
408
|
+
* You are responsible for freeing status after.
|
409
|
+
*
|
410
|
+
* returns 0 on success.
|
411
|
+
* returns -1 on failure.
|
412
|
+
*/
|
413
|
+
int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length);
|
414
|
+
int m_set_userstatus(Messenger *m, uint8_t status);
|
415
|
+
|
416
|
+
/* return the length of friendnumber's status message, including null on success.
|
417
|
+
* return -1 on failure.
|
418
|
+
*/
|
419
|
+
int m_get_statusmessage_size(const Messenger *m, int32_t friendnumber);
|
420
|
+
int m_get_self_statusmessage_size(const Messenger *m);
|
421
|
+
|
422
|
+
/* Copy friendnumber's status message into buf, truncating if size is over maxlen.
|
423
|
+
* Get the size you need to allocate from m_get_statusmessage_size.
|
424
|
+
* The self variant will copy our own status message.
|
425
|
+
*
|
426
|
+
* returns the length of the copied data on success
|
427
|
+
* retruns -1 on failure.
|
428
|
+
*/
|
429
|
+
int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
|
430
|
+
int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf, uint32_t maxlen);
|
431
|
+
|
432
|
+
/* return one of USERSTATUS values.
|
433
|
+
* Values unknown to your application should be represented as USERSTATUS_NONE.
|
434
|
+
* As above, the self variant will return our own USERSTATUS.
|
435
|
+
* If friendnumber is invalid, this shall return USERSTATUS_INVALID.
|
436
|
+
*/
|
437
|
+
uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
|
438
|
+
uint8_t m_get_self_userstatus(const Messenger *m);
|
439
|
+
|
440
|
+
/* returns timestamp of last time friendnumber was seen online, or 0 if never seen.
|
441
|
+
* returns -1 on error.
|
442
|
+
*/
|
443
|
+
uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber);
|
444
|
+
|
445
|
+
/* Set our typing status for a friend.
|
446
|
+
* You are responsible for turning it on or off.
|
447
|
+
*
|
448
|
+
* returns 0 on success.
|
449
|
+
* returns -1 on failure.
|
450
|
+
*/
|
451
|
+
int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing);
|
452
|
+
|
453
|
+
/* Get the typing status of a friend.
|
454
|
+
*
|
455
|
+
* returns 0 if friend is not typing.
|
456
|
+
* returns 1 if friend is typing.
|
457
|
+
*/
|
458
|
+
uint8_t m_get_istyping(const Messenger *m, int32_t friendnumber);
|
459
|
+
|
460
|
+
/* Sets whether we send read receipts for friendnumber.
|
461
|
+
* This function is not lazy, and it will fail if yesno is not (0 or 1).
|
462
|
+
*/
|
463
|
+
void m_set_sends_receipts(Messenger *m, int32_t friendnumber, int yesno);
|
464
|
+
|
465
|
+
/* Set the function that will be executed when a friend request is received.
|
466
|
+
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
467
|
+
*/
|
468
|
+
void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, uint16_t,
|
469
|
+
void *), void *userdata);
|
470
|
+
|
471
|
+
/* Set the function that will be executed when a message from a friend is received.
|
472
|
+
* Function format is: function(int32_t friendnumber, uint8_t * message, uint32_t length)
|
473
|
+
*/
|
474
|
+
void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
|
475
|
+
void *userdata);
|
476
|
+
|
477
|
+
/* Set the function that will be executed when an action from a friend is received.
|
478
|
+
* Function format is: function(int32_t friendnumber, uint8_t * action, uint32_t length)
|
479
|
+
*/
|
480
|
+
void m_callback_action(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
|
481
|
+
void *userdata);
|
482
|
+
|
483
|
+
/* Set the callback for name changes.
|
484
|
+
* Function(int32_t friendnumber, uint8_t *newname, uint16_t length)
|
485
|
+
* You are not responsible for freeing newname.
|
486
|
+
*/
|
487
|
+
void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
|
488
|
+
void *userdata);
|
489
|
+
|
490
|
+
/* Set the callback for status message changes.
|
491
|
+
* Function(int32_t friendnumber, uint8_t *newstatus, uint16_t length)
|
492
|
+
*
|
493
|
+
* You are not responsible for freeing newstatus
|
494
|
+
*/
|
495
|
+
void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
|
496
|
+
void *userdata);
|
497
|
+
|
498
|
+
/* Set the callback for status type changes.
|
499
|
+
* Function(int32_t friendnumber, USERSTATUS kind)
|
500
|
+
*/
|
501
|
+
void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata);
|
502
|
+
|
503
|
+
/* Set the callback for typing changes.
|
504
|
+
* Function(int32_t friendnumber, uint8_t is_typing)
|
505
|
+
*/
|
506
|
+
void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int32_t, uint8_t, void *), void *userdata);
|
507
|
+
|
508
|
+
/* Set the callback for read receipts.
|
509
|
+
* Function(int32_t friendnumber, uint32_t receipt)
|
510
|
+
*
|
511
|
+
* If you are keeping a record of returns from m_sendmessage,
|
512
|
+
* receipt might be one of those values, meaning the message
|
513
|
+
* has been received on the other side.
|
514
|
+
* Since core doesn't track ids for you, receipt may not correspond to any message.
|
515
|
+
* In that case, you should discard it.
|
516
|
+
*/
|
517
|
+
void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int32_t, uint32_t, void *), void *userdata);
|
518
|
+
|
519
|
+
/* Set the callback for connection status changes.
|
520
|
+
* function(int32_t friendnumber, uint8_t status)
|
521
|
+
*
|
522
|
+
* Status:
|
523
|
+
* 0 -- friend went offline after being previously online.
|
524
|
+
* 1 -- friend went online.
|
525
|
+
*
|
526
|
+
* Note that this callback is not called when adding friends, thus the "after
|
527
|
+
* being previously online" part.
|
528
|
+
* It's assumed that when adding friends, their connection status is offline.
|
529
|
+
*/
|
530
|
+
void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *),
|
531
|
+
void *userdata);
|
532
|
+
/* Same as previous but for internal A/V core usage only */
|
533
|
+
void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, void *),
|
534
|
+
void *userdata);
|
535
|
+
|
536
|
+
/**********GROUP CHATS************/
|
537
|
+
|
538
|
+
/* Set the callback for group invites.
|
539
|
+
*
|
540
|
+
* Function(Messenger *m, int32_t friendnumber, uint8_t *group_public_key, void *userdata)
|
541
|
+
*/
|
542
|
+
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, void *),
|
543
|
+
void *userdata);
|
544
|
+
|
545
|
+
/* Set the callback for group messages.
|
546
|
+
*
|
547
|
+
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
548
|
+
*/
|
549
|
+
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
|
550
|
+
void *userdata);
|
551
|
+
|
552
|
+
/* Set the callback for group actions.
|
553
|
+
*
|
554
|
+
* Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
|
555
|
+
*/
|
556
|
+
void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *),
|
557
|
+
void *userdata);
|
558
|
+
|
559
|
+
/* Set callback function for peer name list changes.
|
560
|
+
*
|
561
|
+
* It gets called every time the name list changes(new peer/name, deleted peer)
|
562
|
+
* Function(Tox *tox, int groupnumber, void *userdata)
|
563
|
+
*/
|
564
|
+
void m_callback_group_namelistchange(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t, void *),
|
565
|
+
void *userdata);
|
566
|
+
|
567
|
+
/* Creates a new groupchat and puts it in the chats array.
|
568
|
+
*
|
569
|
+
* return group number on success.
|
570
|
+
* return -1 on failure.
|
571
|
+
*/
|
572
|
+
int add_groupchat(Messenger *m);
|
573
|
+
|
574
|
+
/* Delete a groupchat from the chats array.
|
575
|
+
*
|
576
|
+
* return 0 on success.
|
577
|
+
* return -1 if failure.
|
578
|
+
*/
|
579
|
+
int del_groupchat(Messenger *m, int groupnumber);
|
580
|
+
|
581
|
+
/* Copy the name of peernumber who is in groupnumber to name.
|
582
|
+
* name must be at least MAX_NICK_BYTES long.
|
583
|
+
*
|
584
|
+
* return length of name if success
|
585
|
+
* return -1 if failure
|
586
|
+
*/
|
587
|
+
int m_group_peername(const Messenger *m, int groupnumber, int peernumber, uint8_t *name);
|
588
|
+
|
589
|
+
/* invite friendnumber to groupnumber
|
590
|
+
* return 0 on success
|
591
|
+
* return -1 on failure
|
592
|
+
*/
|
593
|
+
int invite_friend(Messenger *m, int32_t friendnumber, int groupnumber);
|
594
|
+
|
595
|
+
/* Join a group (you need to have been invited first.)
|
596
|
+
*
|
597
|
+
* returns group number on success
|
598
|
+
* returns -1 on failure.
|
599
|
+
*/
|
600
|
+
int join_groupchat(Messenger *m, int32_t friendnumber, const uint8_t *friend_group_public_key);
|
601
|
+
|
602
|
+
/* send a group message
|
603
|
+
* return 0 on success
|
604
|
+
* return -1 on failure
|
605
|
+
*/
|
606
|
+
int group_message_send(const Messenger *m, int groupnumber, const uint8_t *message, uint32_t length);
|
607
|
+
|
608
|
+
/* send a group action
|
609
|
+
* return 0 on success
|
610
|
+
* return -1 on failure
|
611
|
+
*/
|
612
|
+
int group_action_send(const Messenger *m, int groupnumber, const uint8_t *action, uint32_t length);
|
613
|
+
|
614
|
+
/* Return the number of peers in the group chat on success.
|
615
|
+
* return -1 on failure
|
616
|
+
*/
|
617
|
+
int group_number_peers(const Messenger *m, int groupnumber);
|
618
|
+
|
619
|
+
/* List all the peers in the group chat.
|
620
|
+
*
|
621
|
+
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
622
|
+
*
|
623
|
+
* Copies the lengths of the names to lengths[length]
|
624
|
+
*
|
625
|
+
* returns the number of peers on success.
|
626
|
+
*
|
627
|
+
* return -1 on failure.
|
628
|
+
*/
|
629
|
+
int group_names(const Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t lengths[],
|
630
|
+
uint16_t length);
|
631
|
+
|
632
|
+
/****************FILE SENDING*****************/
|
633
|
+
|
634
|
+
|
635
|
+
/* Set the callback for file send requests.
|
636
|
+
*
|
637
|
+
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata)
|
638
|
+
*/
|
639
|
+
void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint64_t, const uint8_t *,
|
640
|
+
uint16_t, void *), void *userdata);
|
641
|
+
|
642
|
+
/* Set the callback for file control requests.
|
643
|
+
*
|
644
|
+
* Function(Tox *tox, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata)
|
645
|
+
*
|
646
|
+
*/
|
647
|
+
void callback_file_control(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, uint8_t, uint8_t,
|
648
|
+
const uint8_t *, uint16_t, void *), void *userdata);
|
649
|
+
|
650
|
+
/* Set the callback for file data.
|
651
|
+
*
|
652
|
+
* Function(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata)
|
653
|
+
*
|
654
|
+
*/
|
655
|
+
void callback_file_data(Messenger *m, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t length,
|
656
|
+
void *), void *userdata);
|
657
|
+
|
658
|
+
/* Send a file send request.
|
659
|
+
* Maximum filename length is 255 bytes.
|
660
|
+
* return 1 on success
|
661
|
+
* return 0 on failure
|
662
|
+
*/
|
663
|
+
int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
|
664
|
+
const uint8_t *filename, uint16_t filename_length);
|
665
|
+
|
666
|
+
/* Send a file send request.
|
667
|
+
* Maximum filename length is 255 bytes.
|
668
|
+
* return file number on success
|
669
|
+
* return -1 on failure
|
670
|
+
*/
|
671
|
+
int new_filesender(const Messenger *m, int32_t friendnumber, uint64_t filesize, const uint8_t *filename,
|
672
|
+
uint16_t filename_length);
|
673
|
+
|
674
|
+
/* Send a file control request.
|
675
|
+
* send_receive is 0 if we want the control packet to target a sending file, 1 if it targets a receiving file.
|
676
|
+
*
|
677
|
+
* return 1 on success
|
678
|
+
* return 0 on failure
|
679
|
+
*/
|
680
|
+
int file_control(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id,
|
681
|
+
const uint8_t *data, uint16_t length);
|
682
|
+
|
683
|
+
/* Send file data.
|
684
|
+
*
|
685
|
+
* return 1 on success
|
686
|
+
* return 0 on failure
|
687
|
+
*/
|
688
|
+
int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, const uint8_t *data, uint16_t length);
|
689
|
+
|
690
|
+
/* Give the number of bytes left to be sent/received.
|
691
|
+
*
|
692
|
+
* send_receive is 0 if we want the sending files, 1 if we want the receiving.
|
693
|
+
*
|
694
|
+
* return number of bytes remaining to be sent/received on success
|
695
|
+
* return 0 on failure
|
696
|
+
*/
|
697
|
+
uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
|
698
|
+
|
699
|
+
/*************** A/V related ******************/
|
700
|
+
|
701
|
+
/* Set the callback for msi packets.
|
702
|
+
*
|
703
|
+
* Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
704
|
+
*/
|
705
|
+
void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *),
|
706
|
+
void *userdata);
|
707
|
+
|
708
|
+
/* Send an msi packet.
|
709
|
+
*
|
710
|
+
* return 1 on success
|
711
|
+
* return 0 on failure
|
712
|
+
*/
|
713
|
+
int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
714
|
+
|
715
|
+
/**********************************************/
|
716
|
+
|
717
|
+
/* Set handlers for custom lossy packets (RTP packets for example.)
|
718
|
+
*
|
719
|
+
* return -1 on failure.
|
720
|
+
* return 0 on success.
|
721
|
+
*/
|
722
|
+
int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
723
|
+
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
724
|
+
|
725
|
+
/* High level function to send custom lossy packets.
|
726
|
+
*
|
727
|
+
* return -1 on failure.
|
728
|
+
* return 0 on success.
|
729
|
+
*/
|
730
|
+
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
731
|
+
|
732
|
+
|
733
|
+
/* Set handlers for custom lossless packets.
|
734
|
+
*
|
735
|
+
* byte must be in PACKET_ID_LOSSLESS_RANGE_START PACKET_ID_LOSSLESS_RANGE_SIZE range.
|
736
|
+
*
|
737
|
+
* return -1 on failure.
|
738
|
+
* return 0 on success.
|
739
|
+
*/
|
740
|
+
int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
741
|
+
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
742
|
+
|
743
|
+
/* High level function to send custom lossless packets.
|
744
|
+
*
|
745
|
+
* return -1 on failure.
|
746
|
+
* return 0 on success.
|
747
|
+
*/
|
748
|
+
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
|
749
|
+
|
750
|
+
/**********************************************/
|
751
|
+
/* Run this at startup.
|
752
|
+
* return allocated instance of Messenger on success.
|
753
|
+
* return 0 if there are problems.
|
754
|
+
*/
|
755
|
+
Messenger *new_messenger(Messenger_Options *options);
|
756
|
+
|
757
|
+
/* Run this before closing shop
|
758
|
+
* Free all datastructures.
|
759
|
+
*/
|
760
|
+
void kill_messenger(Messenger *m);
|
761
|
+
|
762
|
+
/* The main loop that needs to be run at least 20 times per second. */
|
763
|
+
void do_messenger(Messenger *m);
|
764
|
+
|
765
|
+
/* Return the time in milliseconds before do_messenger() should be called again
|
766
|
+
* for optimal performance.
|
767
|
+
*
|
768
|
+
* returns time (in ms) before the next do_messenger() needs to be run on success.
|
769
|
+
*/
|
770
|
+
uint32_t messenger_run_interval(Messenger *m);
|
771
|
+
|
772
|
+
/* SAVING AND LOADING FUNCTIONS: */
|
773
|
+
|
774
|
+
/* return size of the messenger data (for saving). */
|
775
|
+
uint32_t messenger_size(const Messenger *m);
|
776
|
+
|
777
|
+
/* Save the messenger in data (must be allocated memory of size Messenger_size()) */
|
778
|
+
void messenger_save(const Messenger *m, uint8_t *data);
|
779
|
+
|
780
|
+
/* Load the messenger from data of size length. */
|
781
|
+
int messenger_load(Messenger *m, const uint8_t *data, uint32_t length);
|
782
|
+
|
783
|
+
/* Return the number of friends in the instance m.
|
784
|
+
* You should use this to determine how much memory to allocate
|
785
|
+
* for copy_friendlist. */
|
786
|
+
uint32_t count_friendlist(const Messenger *m);
|
787
|
+
|
788
|
+
/* Return the number of online friends in the instance m. */
|
789
|
+
uint32_t get_num_online_friends(const Messenger *m);
|
790
|
+
|
791
|
+
/* Copy a list of valid friend IDs into the array out_list.
|
792
|
+
* If out_list is NULL, returns 0.
|
793
|
+
* Otherwise, returns the number of elements copied.
|
794
|
+
* If the array was too small, the contents
|
795
|
+
* of out_list will be truncated to list_size. */
|
796
|
+
uint32_t copy_friendlist(const Messenger *m, int32_t *out_list, uint32_t list_size);
|
797
|
+
|
798
|
+
/* Allocate and return a list of valid friend id's. List must be freed by the
|
799
|
+
* caller.
|
800
|
+
*
|
801
|
+
* retun 0 if success.
|
802
|
+
* return -1 if failure.
|
803
|
+
*/
|
804
|
+
int get_friendlist(const Messenger *m, int **out_list, uint32_t *out_list_length);
|
805
|
+
|
806
|
+
/* Return the number of chats in the instance m.
|
807
|
+
* You should use this to determine how much memory to allocate
|
808
|
+
* for copy_chatlist. */
|
809
|
+
uint32_t count_chatlist(const Messenger *m);
|
810
|
+
|
811
|
+
/* Copy a list of valid chat IDs into the array out_list.
|
812
|
+
* If out_list is NULL, returns 0.
|
813
|
+
* Otherwise, returns the number of elements copied.
|
814
|
+
* If the array was too small, the contents
|
815
|
+
* of out_list will be truncated to list_size. */
|
816
|
+
uint32_t copy_chatlist(const Messenger *m, int *out_list, uint32_t list_size);
|
817
|
+
|
818
|
+
#endif
|