diff options
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r-- | toxcore/tox.c | 152 |
1 files changed, 92 insertions, 60 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c index 21e8bf75..ea19753f 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -26,12 +26,18 @@ | |||
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #include "Messenger.h" | 28 | #include "Messenger.h" |
29 | |||
30 | #define __TOX_DEFINED__ | ||
31 | typedef struct Messenger Tox; | ||
32 | |||
33 | #include "tox.h" | ||
34 | |||
29 | /* | 35 | /* |
30 | * returns a FRIEND_ADDRESS_SIZE byte address to give to others. | 36 | * returns a FRIEND_ADDRESS_SIZE byte address to give to others. |
31 | * Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] | 37 | * Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)] |
32 | * | 38 | * |
33 | */ | 39 | */ |
34 | void tox_getaddress(void *tox, uint8_t *address) | 40 | void tox_getaddress(Tox *tox, uint8_t *address) |
35 | { | 41 | { |
36 | Messenger *m = tox; | 42 | Messenger *m = tox; |
37 | getaddress(m, address); | 43 | getaddress(m, address); |
@@ -54,7 +60,7 @@ void tox_getaddress(void *tox, uint8_t *address) | |||
54 | * (the nospam for that friend was set to the new one). | 60 | * (the nospam for that friend was set to the new one). |
55 | * return FAERR_NOMEM if increasing the friend list size fails. | 61 | * return FAERR_NOMEM if increasing the friend list size fails. |
56 | */ | 62 | */ |
57 | int tox_addfriend(void *tox, uint8_t *address, uint8_t *data, uint16_t length) | 63 | int tox_addfriend(Tox *tox, uint8_t *address, uint8_t *data, uint16_t length) |
58 | { | 64 | { |
59 | Messenger *m = tox; | 65 | Messenger *m = tox; |
60 | return m_addfriend(m, address, data, length); | 66 | return m_addfriend(m, address, data, length); |
@@ -65,7 +71,7 @@ int tox_addfriend(void *tox, uint8_t *address, uint8_t *data, uint16_t length) | |||
65 | * return the friend number if success. | 71 | * return the friend number if success. |
66 | * return -1 if failure. | 72 | * return -1 if failure. |
67 | */ | 73 | */ |
68 | int tox_addfriend_norequest(void *tox, uint8_t *client_id) | 74 | int tox_addfriend_norequest(Tox *tox, uint8_t *client_id) |
69 | { | 75 | { |
70 | Messenger *m = tox; | 76 | Messenger *m = tox; |
71 | return m_addfriend_norequest(m, client_id); | 77 | return m_addfriend_norequest(m, client_id); |
@@ -74,7 +80,7 @@ int tox_addfriend_norequest(void *tox, uint8_t *client_id) | |||
74 | /* return the friend id associated to that client id. | 80 | /* return the friend id associated to that client id. |
75 | * return -1 if no such friend. | 81 | * return -1 if no such friend. |
76 | */ | 82 | */ |
77 | int tox_getfriend_id(void *tox, uint8_t *client_id) | 83 | int tox_getfriend_id(Tox *tox, uint8_t *client_id) |
78 | { | 84 | { |
79 | Messenger *m = tox; | 85 | Messenger *m = tox; |
80 | return getfriend_id(m, client_id); | 86 | return getfriend_id(m, client_id); |
@@ -86,14 +92,14 @@ int tox_getfriend_id(void *tox, uint8_t *client_id) | |||
86 | * return 0 if success. | 92 | * return 0 if success. |
87 | * return -1 if failure. | 93 | * return -1 if failure. |
88 | */ | 94 | */ |
89 | int tox_getclient_id(void *tox, int friend_id, uint8_t *client_id) | 95 | int tox_getclient_id(Tox *tox, int friend_id, uint8_t *client_id) |
90 | { | 96 | { |
91 | Messenger *m = tox; | 97 | Messenger *m = tox; |
92 | return getclient_id(m, friend_id, client_id); | 98 | return getclient_id(m, friend_id, client_id); |
93 | } | 99 | } |
94 | 100 | ||
95 | /* Remove a friend. */ | 101 | /* Remove a friend. */ |
96 | int tox_delfriend(void *tox, int friendnumber) | 102 | int tox_delfriend(Tox *tox, int friendnumber) |
97 | { | 103 | { |
98 | Messenger *m = tox; | 104 | Messenger *m = tox; |
99 | return m_delfriend(m, friendnumber); | 105 | return m_delfriend(m, friendnumber); |
@@ -105,7 +111,7 @@ int tox_delfriend(void *tox, int friendnumber) | |||
105 | * return 0 if friend is not connected to us (Offline). | 111 | * return 0 if friend is not connected to us (Offline). |
106 | * return -1 on failure. | 112 | * return -1 on failure. |
107 | */ | 113 | */ |
108 | int tox_get_friend_connectionstatus(void *tox, int friendnumber) | 114 | int tox_get_friend_connectionstatus(Tox *tox, int friendnumber) |
109 | { | 115 | { |
110 | Messenger *m = tox; | 116 | Messenger *m = tox; |
111 | return m_get_friend_connectionstatus(m, friendnumber); | 117 | return m_get_friend_connectionstatus(m, friendnumber); |
@@ -116,7 +122,7 @@ int tox_get_friend_connectionstatus(void *tox, int friendnumber) | |||
116 | * return 1 if friend exists. | 122 | * return 1 if friend exists. |
117 | * return 0 if friend doesn't exist. | 123 | * return 0 if friend doesn't exist. |
118 | */ | 124 | */ |
119 | int tox_friend_exists(void *tox, int friendnumber) | 125 | int tox_friend_exists(Tox *tox, int friendnumber) |
120 | { | 126 | { |
121 | Messenger *m = tox; | 127 | Messenger *m = tox; |
122 | return m_friend_exists(m, friendnumber); | 128 | return m_friend_exists(m, friendnumber); |
@@ -131,13 +137,13 @@ int tox_friend_exists(void *tox, int friendnumber) | |||
131 | * m_sendmessage_withid will send a message with the id of your choosing, | 137 | * m_sendmessage_withid will send a message with the id of your choosing, |
132 | * however we can generate an id for you by calling plain m_sendmessage. | 138 | * however we can generate an id for you by calling plain m_sendmessage. |
133 | */ | 139 | */ |
134 | uint32_t tox_sendmessage(void *tox, int friendnumber, uint8_t *message, uint32_t length) | 140 | uint32_t tox_sendmessage(Tox *tox, int friendnumber, uint8_t *message, uint32_t length) |
135 | { | 141 | { |
136 | Messenger *m = tox; | 142 | Messenger *m = tox; |
137 | return m_sendmessage(m, friendnumber, message, length); | 143 | return m_sendmessage(m, friendnumber, message, length); |
138 | } | 144 | } |
139 | 145 | ||
140 | uint32_t tox_sendmessage_withid(void *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length) | 146 | uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *message, uint32_t length) |
141 | { | 147 | { |
142 | Messenger *m = tox; | 148 | Messenger *m = tox; |
143 | return m_sendmessage_withid(m, friendnumber, theid, message, length); | 149 | return m_sendmessage_withid(m, friendnumber, theid, message, length); |
@@ -147,7 +153,7 @@ uint32_t tox_sendmessage_withid(void *tox, int friendnumber, uint32_t theid, uin | |||
147 | * return 1 if packet was successfully put into the send queue. | 153 | * return 1 if packet was successfully put into the send queue. |
148 | * return 0 if it was not. | 154 | * return 0 if it was not. |
149 | */ | 155 | */ |
150 | int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length) | 156 | int tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length) |
151 | { | 157 | { |
152 | Messenger *m = tox; | 158 | Messenger *m = tox; |
153 | return m_sendaction(m, friendnumber, action, length); | 159 | return m_sendaction(m, friendnumber, action, length); |
@@ -161,7 +167,7 @@ int tox_sendaction(void *tox, int friendnumber, uint8_t *action, uint32_t length | |||
161 | * return 0 if success. | 167 | * return 0 if success. |
162 | * return -1 if failure. | 168 | * return -1 if failure. |
163 | */ | 169 | */ |
164 | int tox_setfriendname(void *tox, int friendnumber, uint8_t *name, uint16_t length) | 170 | int tox_setfriendname(Tox *tox, int friendnumber, uint8_t *name, uint16_t length) |
165 | { | 171 | { |
166 | Messenger *m = tox; | 172 | Messenger *m = tox; |
167 | return setfriendname(m, friendnumber, name, length); | 173 | return setfriendname(m, friendnumber, name, length); |
@@ -175,7 +181,7 @@ int tox_setfriendname(void *tox, int friendnumber, uint8_t *name, uint16_t lengt | |||
175 | * return 0 if success. | 181 | * return 0 if success. |
176 | * return -1 if failure. | 182 | * return -1 if failure. |
177 | */ | 183 | */ |
178 | int tox_setname(void *tox, uint8_t *name, uint16_t length) | 184 | int tox_setname(Tox *tox, uint8_t *name, uint16_t length) |
179 | { | 185 | { |
180 | Messenger *m = tox; | 186 | Messenger *m = tox; |
181 | return setname(m, name, length); | 187 | return setname(m, name, length); |
@@ -189,7 +195,7 @@ int tox_setname(void *tox, uint8_t *name, uint16_t length) | |||
189 | * return length of the name. | 195 | * return length of the name. |
190 | * return 0 on error. | 196 | * return 0 on error. |
191 | */ | 197 | */ |
192 | uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen) | 198 | uint16_t tox_getselfname(Tox *tox, uint8_t *name, uint16_t nlen) |
193 | { | 199 | { |
194 | Messenger *m = tox; | 200 | Messenger *m = tox; |
195 | return getself_name(m, name, nlen); | 201 | return getself_name(m, name, nlen); |
@@ -201,7 +207,7 @@ uint16_t tox_getselfname(void *tox, uint8_t *name, uint16_t nlen) | |||
201 | * return length of name (with the NULL terminator) if success. | 207 | * return length of name (with the NULL terminator) if success. |
202 | * return -1 if failure. | 208 | * return -1 if failure. |
203 | */ | 209 | */ |
204 | int tox_getname(void *tox, int friendnumber, uint8_t *name) | 210 | int tox_getname(Tox *tox, int friendnumber, uint8_t *name) |
205 | { | 211 | { |
206 | Messenger *m = tox; | 212 | Messenger *m = tox; |
207 | return getname(m, friendnumber, name); | 213 | return getname(m, friendnumber, name); |
@@ -212,22 +218,22 @@ int tox_getname(void *tox, int friendnumber, uint8_t *name) | |||
212 | * | 218 | * |
213 | * return 0 on success, -1 on failure. | 219 | * return 0 on success, -1 on failure. |
214 | */ | 220 | */ |
215 | int tox_set_statusmessage(void *tox, uint8_t *status, uint16_t length) | 221 | int tox_set_statusmessage(Tox *tox, uint8_t *status, uint16_t length) |
216 | { | 222 | { |
217 | Messenger *m = tox; | 223 | Messenger *m = tox; |
218 | return m_set_statusmessage(m, status, length); | 224 | return m_set_statusmessage(m, status, length); |
219 | } | 225 | } |
220 | 226 | ||
221 | int tox_set_userstatus(void *tox, USERSTATUS status) | 227 | int tox_set_userstatus(Tox *tox, TOX_USERSTATUS status) |
222 | { | 228 | { |
223 | Messenger *m = tox; | 229 | Messenger *m = tox; |
224 | return m_set_userstatus(m, status); | 230 | return m_set_userstatus(m, (USERSTATUS)status); |
225 | } | 231 | } |
226 | 232 | ||
227 | /* return the length of friendnumber's status message, including null. | 233 | /* return the length of friendnumber's status message, including null. |
228 | * Pass it into malloc. | 234 | * Pass it into malloc. |
229 | */ | 235 | */ |
230 | int tox_get_statusmessage_size(void *tox, int friendnumber) | 236 | int tox_get_statusmessage_size(Tox *tox, int friendnumber) |
231 | { | 237 | { |
232 | Messenger *m = tox; | 238 | Messenger *m = tox; |
233 | return m_get_statusmessage_size(m, friendnumber); | 239 | return m_get_statusmessage_size(m, friendnumber); |
@@ -237,13 +243,13 @@ int tox_get_statusmessage_size(void *tox, int friendnumber) | |||
237 | * Get the size you need to allocate from m_get_statusmessage_size. | 243 | * Get the size you need to allocate from m_get_statusmessage_size. |
238 | * The self variant will copy our own status message. | 244 | * The self variant will copy our own status message. |
239 | */ | 245 | */ |
240 | int tox_copy_statusmessage(void *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) | 246 | int tox_copy_statusmessage(Tox *tox, int friendnumber, uint8_t *buf, uint32_t maxlen) |
241 | { | 247 | { |
242 | Messenger *m = tox; | 248 | Messenger *m = tox; |
243 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); | 249 | return m_copy_statusmessage(m, friendnumber, buf, maxlen); |
244 | } | 250 | } |
245 | 251 | ||
246 | int tox_copy_self_statusmessage(void *tox, uint8_t *buf, uint32_t maxlen) | 252 | int tox_copy_self_statusmessage(Tox *tox, uint8_t *buf, uint32_t maxlen) |
247 | { | 253 | { |
248 | Messenger *m = tox; | 254 | Messenger *m = tox; |
249 | return m_copy_self_statusmessage(m, buf, maxlen); | 255 | return m_copy_self_statusmessage(m, buf, maxlen); |
@@ -254,23 +260,23 @@ int tox_copy_self_statusmessage(void *tox, uint8_t *buf, uint32_t maxlen) | |||
254 | * As above, the self variant will return our own USERSTATUS. | 260 | * As above, the self variant will return our own USERSTATUS. |
255 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. | 261 | * If friendnumber is invalid, this shall return USERSTATUS_INVALID. |
256 | */ | 262 | */ |
257 | USERSTATUS tox_get_userstatus(void *tox, int friendnumber) | 263 | TOX_USERSTATUS tox_get_userstatus(Tox *tox, int friendnumber) |
258 | { | 264 | { |
259 | Messenger *m = tox; | 265 | Messenger *m = tox; |
260 | return m_get_userstatus(m, friendnumber); | 266 | return (TOX_USERSTATUS)m_get_userstatus(m, friendnumber); |
261 | } | 267 | } |
262 | 268 | ||
263 | USERSTATUS tox_get_selfuserstatus(void *tox) | 269 | TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox) |
264 | { | 270 | { |
265 | Messenger *m = tox; | 271 | Messenger *m = tox; |
266 | return m_get_self_userstatus(m); | 272 | return (TOX_USERSTATUS)m_get_self_userstatus(m); |
267 | } | 273 | } |
268 | 274 | ||
269 | 275 | ||
270 | /* Sets whether we send read receipts for friendnumber. | 276 | /* Sets whether we send read receipts for friendnumber. |
271 | * This function is not lazy, and it will fail if yesno is not (0 or 1). | 277 | * This function is not lazy, and it will fail if yesno is not (0 or 1). |
272 | */ | 278 | */ |
273 | void tox_set_sends_receipts(void *tox, int friendnumber, int yesno) | 279 | void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno) |
274 | { | 280 | { |
275 | Messenger *m = tox; | 281 | Messenger *m = tox; |
276 | m_set_sends_receipts(m, friendnumber, yesno); | 282 | m_set_sends_receipts(m, friendnumber, yesno); |
@@ -279,7 +285,7 @@ void tox_set_sends_receipts(void *tox, int friendnumber, int yesno) | |||
279 | /* Return the number of friends in the instance m. | 285 | /* Return the number of friends in the instance m. |
280 | * You should use this to determine how much memory to allocate | 286 | * You should use this to determine how much memory to allocate |
281 | * for copy_friendlist. */ | 287 | * for copy_friendlist. */ |
282 | uint32_t tox_count_friendlist(void *tox) | 288 | uint32_t tox_count_friendlist(Tox *tox) |
283 | { | 289 | { |
284 | Messenger *m = tox; | 290 | Messenger *m = tox; |
285 | return count_friendlist(m); | 291 | return count_friendlist(m); |
@@ -290,7 +296,7 @@ uint32_t tox_count_friendlist(void *tox) | |||
290 | * Otherwise, returns the number of elements copied. | 296 | * Otherwise, returns the number of elements copied. |
291 | * If the array was too small, the contents | 297 | * If the array was too small, the contents |
292 | * of out_list will be truncated to list_size. */ | 298 | * of out_list will be truncated to list_size. */ |
293 | uint32_t tox_copy_friendlist(void *tox, int *out_list, uint32_t list_size) | 299 | uint32_t tox_copy_friendlist(Tox *tox, int *out_list, uint32_t list_size) |
294 | { | 300 | { |
295 | Messenger *m = tox; | 301 | Messenger *m = tox; |
296 | return copy_friendlist(m, out_list, list_size); | 302 | return copy_friendlist(m, out_list, list_size); |
@@ -299,7 +305,7 @@ uint32_t tox_copy_friendlist(void *tox, int *out_list, uint32_t list_size) | |||
299 | /* Set the function that will be executed when a friend request is received. | 305 | /* Set the function that will be executed when a friend request is received. |
300 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) | 306 | * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length) |
301 | */ | 307 | */ |
302 | void tox_callback_friendrequest(void *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata) | 308 | void tox_callback_friendrequest(Tox *tox, void (*function)(uint8_t *, uint8_t *, uint16_t, void *), void *userdata) |
303 | { | 309 | { |
304 | Messenger *m = tox; | 310 | Messenger *m = tox; |
305 | m_callback_friendrequest(m, function, userdata); | 311 | m_callback_friendrequest(m, function, userdata); |
@@ -309,7 +315,7 @@ void tox_callback_friendrequest(void *tox, void (*function)(uint8_t *, uint8_t * | |||
309 | /* Set the function that will be executed when a message from a friend is received. | 315 | /* Set the function that will be executed when a message from a friend is received. |
310 | * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) | 316 | * Function format is: function(int friendnumber, uint8_t * message, uint32_t length) |
311 | */ | 317 | */ |
312 | void tox_callback_friendmessage(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 318 | void tox_callback_friendmessage(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), |
313 | void *userdata) | 319 | void *userdata) |
314 | { | 320 | { |
315 | Messenger *m = tox; | 321 | Messenger *m = tox; |
@@ -319,7 +325,7 @@ void tox_callback_friendmessage(void *tox, void (*function)(Messenger *tox, int, | |||
319 | /* Set the function that will be executed when an action from a friend is received. | 325 | /* Set the function that will be executed when an action from a friend is received. |
320 | * function format is: function(int friendnumber, uint8_t * action, uint32_t length) | 326 | * function format is: function(int friendnumber, uint8_t * action, uint32_t length) |
321 | */ | 327 | */ |
322 | void tox_callback_action(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), void *userdata) | 328 | void tox_callback_action(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), void *userdata) |
323 | { | 329 | { |
324 | Messenger *m = tox; | 330 | Messenger *m = tox; |
325 | m_callback_action(m, function, userdata); | 331 | m_callback_action(m, function, userdata); |
@@ -329,7 +335,7 @@ void tox_callback_action(void *tox, void (*function)(Messenger *tox, int, uint8_ | |||
329 | * function(int friendnumber, uint8_t *newname, uint16_t length) | 335 | * function(int friendnumber, uint8_t *newname, uint16_t length) |
330 | * You are not responsible for freeing newname. | 336 | * You are not responsible for freeing newname. |
331 | */ | 337 | */ |
332 | void tox_callback_namechange(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 338 | void tox_callback_namechange(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), |
333 | void *userdata) | 339 | void *userdata) |
334 | { | 340 | { |
335 | Messenger *m = tox; | 341 | Messenger *m = tox; |
@@ -340,7 +346,7 @@ void tox_callback_namechange(void *tox, void (*function)(Messenger *tox, int, ui | |||
340 | * function(int friendnumber, uint8_t *newstatus, uint16_t length) | 346 | * function(int friendnumber, uint8_t *newstatus, uint16_t length) |
341 | * You are not responsible for freeing newstatus. | 347 | * You are not responsible for freeing newstatus. |
342 | */ | 348 | */ |
343 | void tox_callback_statusmessage(void *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), | 349 | void tox_callback_statusmessage(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, uint16_t, void *), |
344 | void *userdata) | 350 | void *userdata) |
345 | { | 351 | { |
346 | Messenger *m = tox; | 352 | Messenger *m = tox; |
@@ -350,9 +356,11 @@ void tox_callback_statusmessage(void *tox, void (*function)(Messenger *tox, int, | |||
350 | /* Set the callback for status type changes. | 356 | /* Set the callback for status type changes. |
351 | * function(int friendnumber, USERSTATUS kind) | 357 | * function(int friendnumber, USERSTATUS kind) |
352 | */ | 358 | */ |
353 | void tox_callback_userstatus(void *tox, void (*function)(Messenger *tox, int, USERSTATUS, void *), void *userdata) | 359 | void tox_callback_userstatus(Tox *tox, void (*_function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata) |
354 | { | 360 | { |
355 | Messenger *m = tox; | 361 | Messenger *m = tox; |
362 | typedef void (*function_type)(Messenger *, int, USERSTATUS, void *); | ||
363 | function_type function = (function_type)_function; | ||
356 | m_callback_userstatus(m, function, userdata); | 364 | m_callback_userstatus(m, function, userdata); |
357 | } | 365 | } |
358 | 366 | ||
@@ -365,7 +373,7 @@ void tox_callback_userstatus(void *tox, void (*function)(Messenger *tox, int, US | |||
365 | * Since core doesn't track ids for you, receipt may not correspond to any message. | 373 | * Since core doesn't track ids for you, receipt may not correspond to any message. |
366 | * in that case, you should discard it. | 374 | * in that case, you should discard it. |
367 | */ | 375 | */ |
368 | void tox_callback_read_receipt(void *tox, void (*function)(Messenger *tox, int, uint32_t, void *), void *userdata) | 376 | void tox_callback_read_receipt(Tox *tox, void (*function)(Messenger *tox, int, uint32_t, void *), void *userdata) |
369 | { | 377 | { |
370 | Messenger *m = tox; | 378 | Messenger *m = tox; |
371 | m_callback_read_receipt(m, function, userdata); | 379 | m_callback_read_receipt(m, function, userdata); |
@@ -382,7 +390,7 @@ void tox_callback_read_receipt(void *tox, void (*function)(Messenger *tox, int, | |||
382 | * being previously online" part. It's assumed that when adding friends, | 390 | * being previously online" part. It's assumed that when adding friends, |
383 | * their connection status is offline. | 391 | * their connection status is offline. |
384 | */ | 392 | */ |
385 | void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, int, uint8_t, void *), void *userdata) | 393 | void tox_callback_connectionstatus(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, void *), void *userdata) |
386 | { | 394 | { |
387 | Messenger *m = tox; | 395 | Messenger *m = tox; |
388 | m_callback_connectionstatus(m, function, userdata); | 396 | m_callback_connectionstatus(m, function, userdata); |
@@ -394,7 +402,7 @@ void tox_callback_connectionstatus(void *tox, void (*function)(Messenger *tox, i | |||
394 | * | 402 | * |
395 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) | 403 | * Function(Tox *tox, int friendnumber, uint8_t *group_public_key, void *userdata) |
396 | */ | 404 | */ |
397 | void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata) | 405 | void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int, uint8_t *, void *), void *userdata) |
398 | { | 406 | { |
399 | Messenger *m = tox; | 407 | Messenger *m = tox; |
400 | m_callback_group_invite(m, function, userdata); | 408 | m_callback_group_invite(m, function, userdata); |
@@ -403,7 +411,7 @@ void tox_callback_group_invite(void *tox, void (*function)(Messenger *tox, int, | |||
403 | * | 411 | * |
404 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 412 | * Function(Tox *tox, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
405 | */ | 413 | */ |
406 | void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *), | 414 | void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, uint8_t *, uint16_t, void *), |
407 | void *userdata) | 415 | void *userdata) |
408 | { | 416 | { |
409 | Messenger *m = tox; | 417 | Messenger *m = tox; |
@@ -414,7 +422,7 @@ void tox_callback_group_message(void *tox, void (*function)(Messenger *tox, int, | |||
414 | * return group number on success. | 422 | * return group number on success. |
415 | * return -1 on failure. | 423 | * return -1 on failure. |
416 | */ | 424 | */ |
417 | int tox_add_groupchat(void *tox) | 425 | int tox_add_groupchat(Tox *tox) |
418 | { | 426 | { |
419 | Messenger *m = tox; | 427 | Messenger *m = tox; |
420 | return add_groupchat(m); | 428 | return add_groupchat(m); |
@@ -424,7 +432,7 @@ int tox_add_groupchat(void *tox) | |||
424 | * return 0 on success. | 432 | * return 0 on success. |
425 | * return -1 if failure. | 433 | * return -1 if failure. |
426 | */ | 434 | */ |
427 | int tox_del_groupchat(void *tox, int groupnumber) | 435 | int tox_del_groupchat(Tox *tox, int groupnumber) |
428 | { | 436 | { |
429 | Messenger *m = tox; | 437 | Messenger *m = tox; |
430 | return del_groupchat(m, groupnumber); | 438 | return del_groupchat(m, groupnumber); |
@@ -436,7 +444,7 @@ int tox_del_groupchat(void *tox, int groupnumber) | |||
436 | * return length of name if success | 444 | * return length of name if success |
437 | * return -1 if failure | 445 | * return -1 if failure |
438 | */ | 446 | */ |
439 | int tox_group_peername(void *tox, int groupnumber, int peernumber, uint8_t *name) | 447 | int tox_group_peername(Tox *tox, int groupnumber, int peernumber, uint8_t *name) |
440 | { | 448 | { |
441 | Messenger *m = tox; | 449 | Messenger *m = tox; |
442 | return m_group_peername(m, groupnumber, peernumber, name); | 450 | return m_group_peername(m, groupnumber, peernumber, name); |
@@ -445,7 +453,7 @@ int tox_group_peername(void *tox, int groupnumber, int peernumber, uint8_t *name | |||
445 | * return 0 on success | 453 | * return 0 on success |
446 | * return -1 on failure | 454 | * return -1 on failure |
447 | */ | 455 | */ |
448 | int tox_invite_friend(void *tox, int friendnumber, int groupnumber) | 456 | int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber) |
449 | { | 457 | { |
450 | Messenger *m = tox; | 458 | Messenger *m = tox; |
451 | return invite_friend(m, friendnumber, groupnumber); | 459 | return invite_friend(m, friendnumber, groupnumber); |
@@ -455,7 +463,7 @@ int tox_invite_friend(void *tox, int friendnumber, int groupnumber) | |||
455 | * returns group number on success | 463 | * returns group number on success |
456 | * returns -1 on failure. | 464 | * returns -1 on failure. |
457 | */ | 465 | */ |
458 | int tox_join_groupchat(void *tox, int friendnumber, uint8_t *friend_group_public_key) | 466 | int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key) |
459 | { | 467 | { |
460 | Messenger *m = tox; | 468 | Messenger *m = tox; |
461 | return join_groupchat(m, friendnumber, friend_group_public_key); | 469 | return join_groupchat(m, friendnumber, friend_group_public_key); |
@@ -465,7 +473,7 @@ int tox_join_groupchat(void *tox, int friendnumber, uint8_t *friend_group_public | |||
465 | * return 0 on success | 473 | * return 0 on success |
466 | * return -1 on failure | 474 | * return -1 on failure |
467 | */ | 475 | */ |
468 | int tox_group_message_send(void *tox, int groupnumber, uint8_t *message, uint32_t length) | 476 | int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length) |
469 | { | 477 | { |
470 | Messenger *m = tox; | 478 | Messenger *m = tox; |
471 | return group_message_send(m, groupnumber, message, length); | 479 | return group_message_send(m, groupnumber, message, length); |
@@ -480,7 +488,7 @@ int tox_group_message_send(void *tox, int groupnumber, uint8_t *message, uint32_ | |||
480 | * | 488 | * |
481 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | 489 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) |
482 | */ | 490 | */ |
483 | void tox_callback_file_sendrequest(void *tox, void (*function)(Messenger *tox, int, uint8_t, uint64_t, uint8_t *, | 491 | void tox_callback_file_sendrequest(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint64_t, uint8_t *, |
484 | uint16_t, | 492 | uint16_t, |
485 | void *), void *userdata) | 493 | void *), void *userdata) |
486 | { | 494 | { |
@@ -492,7 +500,7 @@ void tox_callback_file_sendrequest(void *tox, void (*function)(Messenger *tox, i | |||
492 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | 500 | * Function(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) |
493 | * | 501 | * |
494 | */ | 502 | */ |
495 | void tox_callback_file_control(void *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t, uint8_t, uint8_t *, | 503 | void tox_callback_file_control(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t, uint8_t, uint8_t *, |
496 | uint16_t, void *), void *userdata) | 504 | uint16_t, void *), void *userdata) |
497 | { | 505 | { |
498 | Messenger *m = tox; | 506 | Messenger *m = tox; |
@@ -503,7 +511,7 @@ void tox_callback_file_control(void *tox, void (*function)(Messenger *tox, int, | |||
503 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | 511 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) |
504 | * | 512 | * |
505 | */ | 513 | */ |
506 | void tox_callback_file_data(void *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t *, uint16_t length, | 514 | void tox_callback_file_data(Tox *tox, void (*function)(Messenger *tox, int, uint8_t, uint8_t *, uint16_t length, |
507 | void *), | 515 | void *), |
508 | void *userdata) | 516 | void *userdata) |
509 | 517 | ||
@@ -516,7 +524,7 @@ void tox_callback_file_data(void *tox, void (*function)(Messenger *tox, int, uin | |||
516 | * return file number on success | 524 | * return file number on success |
517 | * return -1 on failure | 525 | * return -1 on failure |
518 | */ | 526 | */ |
519 | int tox_new_filesender(void *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) | 527 | int tox_new_filesender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length) |
520 | { | 528 | { |
521 | Messenger *m = tox; | 529 | Messenger *m = tox; |
522 | return new_filesender(m, friendnumber, filesize, filename, filename_length); | 530 | return new_filesender(m, friendnumber, filesize, filename, filename_length); |
@@ -527,7 +535,7 @@ int tox_new_filesender(void *tox, int friendnumber, uint64_t filesize, uint8_t * | |||
527 | * return 1 on success | 535 | * return 1 on success |
528 | * return 0 on failure | 536 | * return 0 on failure |
529 | */ | 537 | */ |
530 | int tox_file_sendcontrol(void *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | 538 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, |
531 | uint8_t *data, uint16_t length) | 539 | uint8_t *data, uint16_t length) |
532 | { | 540 | { |
533 | Messenger *m = tox; | 541 | Messenger *m = tox; |
@@ -538,7 +546,7 @@ int tox_file_sendcontrol(void *tox, int friendnumber, uint8_t send_receive, uint | |||
538 | * return 1 on success | 546 | * return 1 on success |
539 | * return 0 on failure | 547 | * return 0 on failure |
540 | */ | 548 | */ |
541 | int tox_file_senddata(void *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) | 549 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length) |
542 | { | 550 | { |
543 | Messenger *m = tox; | 551 | Messenger *m = tox; |
544 | return file_data(m, friendnumber, filenumber, data, length); | 552 | return file_data(m, friendnumber, filenumber, data, length); |
@@ -550,7 +558,7 @@ int tox_file_senddata(void *tox, int friendnumber, uint8_t filenumber, uint8_t * | |||
550 | * return number of bytes remaining to be sent/received on success | 558 | * return number of bytes remaining to be sent/received on success |
551 | * return 0 on failure | 559 | * return 0 on failure |
552 | */ | 560 | */ |
553 | uint64_t tox_file_dataremaining(void *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) | 561 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive) |
554 | { | 562 | { |
555 | Messenger *m = tox; | 563 | Messenger *m = tox; |
556 | return file_dataremaining(m, friendnumber, filenumber, send_receive); | 564 | return file_dataremaining(m, friendnumber, filenumber, send_receive); |
@@ -561,12 +569,15 @@ uint64_t tox_file_dataremaining(void *tox, int friendnumber, uint8_t filenumber, | |||
561 | /* Use these functions to bootstrap the client. | 569 | /* Use these functions to bootstrap the client. |
562 | * Sends a get nodes request to the given node with ip port and public_key. | 570 | * Sends a get nodes request to the given node with ip port and public_key. |
563 | */ | 571 | */ |
564 | void tox_bootstrap_from_ip(void *tox, IP_Port ip_port, uint8_t *public_key) | 572 | void tox_bootstrap_from_ip(Tox *tox, tox_IP_Port _ip_port, uint8_t *public_key) |
565 | { | 573 | { |
566 | Messenger *m = tox; | 574 | Messenger *m = tox; |
575 | IP_Port ip_port; | ||
576 | memcpy(&ip_port, &_ip_port, sizeof(IP_Port)); | ||
567 | DHT_bootstrap(m->dht, ip_port, public_key); | 577 | DHT_bootstrap(m->dht, ip_port, public_key); |
568 | } | 578 | } |
569 | int tox_bootstrap_from_address(void *tox, const char *address, | 579 | |
580 | int tox_bootstrap_from_address(Tox *tox, const char *address, | ||
570 | uint8_t ipv6enabled, uint16_t port, uint8_t *public_key) | 581 | uint8_t ipv6enabled, uint16_t port, uint8_t *public_key) |
571 | { | 582 | { |
572 | Messenger *m = tox; | 583 | Messenger *m = tox; |
@@ -576,7 +587,7 @@ int tox_bootstrap_from_address(void *tox, const char *address, | |||
576 | /* return 0 if we are not connected to the DHT. | 587 | /* return 0 if we are not connected to the DHT. |
577 | * return 1 if we are. | 588 | * return 1 if we are. |
578 | */ | 589 | */ |
579 | int tox_isconnected(void *tox) | 590 | int tox_isconnected(Tox *tox) |
580 | { | 591 | { |
581 | Messenger *m = tox; | 592 | Messenger *m = tox; |
582 | return DHT_isconnected(m->dht); | 593 | return DHT_isconnected(m->dht); |
@@ -587,7 +598,7 @@ int tox_isconnected(void *tox) | |||
587 | * return allocated instance of tox on success. | 598 | * return allocated instance of tox on success. |
588 | * return 0 if there are problems. | 599 | * return 0 if there are problems. |
589 | */ | 600 | */ |
590 | void *tox_new(uint8_t ipv6enabled) | 601 | Tox *tox_new(uint8_t ipv6enabled) |
591 | { | 602 | { |
592 | return initMessenger(ipv6enabled); | 603 | return initMessenger(ipv6enabled); |
593 | } | 604 | } |
@@ -595,37 +606,58 @@ void *tox_new(uint8_t ipv6enabled) | |||
595 | /* Run this before closing shop. | 606 | /* Run this before closing shop. |
596 | * Free all datastructures. | 607 | * Free all datastructures. |
597 | */ | 608 | */ |
598 | void tox_kill(void *tox) | 609 | void tox_kill(Tox *tox) |
599 | { | 610 | { |
600 | Messenger *m = tox; | 611 | Messenger *m = tox; |
601 | cleanupMessenger(m); | 612 | cleanupMessenger(m); |
602 | } | 613 | } |
603 | 614 | ||
604 | /* The main loop that needs to be run at least 20 times per second. */ | 615 | /* The main loop that needs to be run at least 20 times per second. */ |
605 | void tox_do(void *tox) | 616 | void tox_do(Tox *tox) |
606 | { | 617 | { |
607 | Messenger *m = tox; | 618 | Messenger *m = tox; |
608 | doMessenger(m); | 619 | doMessenger(m); |
609 | } | 620 | } |
610 | 621 | ||
622 | /* | ||
623 | * functions to avoid excessive polling | ||
624 | */ | ||
625 | int tox_wait_prepare(Tox *tox, uint8_t *data, uint16_t *lenptr) | ||
626 | { | ||
627 | Messenger *m = tox; | ||
628 | return waitprepareMessenger(m, data, lenptr); | ||
629 | } | ||
630 | |||
631 | int tox_wait_execute(Tox *tox, uint8_t *data, uint16_t len, uint16_t milliseconds) | ||
632 | { | ||
633 | Messenger *m = tox; | ||
634 | return waitexecuteMessenger(m, data, len, milliseconds); | ||
635 | } | ||
636 | |||
637 | void tox_wait_cleanup(Tox *tox, uint8_t *data, uint16_t len) | ||
638 | { | ||
639 | Messenger *m = tox; | ||
640 | waitcleanupMessenger(m, data, len); | ||
641 | } | ||
642 | |||
611 | /* SAVING AND LOADING FUNCTIONS: */ | 643 | /* SAVING AND LOADING FUNCTIONS: */ |
612 | 644 | ||
613 | /* return size of the messenger data (for saving). */ | 645 | /* return size of the messenger data (for saving). */ |
614 | uint32_t tox_size(void *tox) | 646 | uint32_t tox_size(Tox *tox) |
615 | { | 647 | { |
616 | Messenger *m = tox; | 648 | Messenger *m = tox; |
617 | return Messenger_size(m); | 649 | return Messenger_size(m); |
618 | } | 650 | } |
619 | 651 | ||
620 | /* Save the messenger in data (must be allocated memory of size Messenger_size()). */ | 652 | /* Save the messenger in data (must be allocated memory of size Messenger_size()). */ |
621 | void tox_save(void *tox, uint8_t *data) | 653 | void tox_save(Tox *tox, uint8_t *data) |
622 | { | 654 | { |
623 | Messenger *m = tox; | 655 | Messenger *m = tox; |
624 | Messenger_save(m, data); | 656 | Messenger_save(m, data); |
625 | } | 657 | } |
626 | 658 | ||
627 | /* Load the messenger from data of size length. */ | 659 | /* Load the messenger from data of size length. */ |
628 | int tox_load(void *tox, uint8_t *data, uint32_t length) | 660 | int tox_load(Tox *tox, uint8_t *data, uint32_t length) |
629 | { | 661 | { |
630 | Messenger *m = tox; | 662 | Messenger *m = tox; |
631 | return Messenger_load(m, data, length); | 663 | return Messenger_load(m, data, length); |