Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: GPL-3.0-or-later |
2 | | * Copyright © 2016-2018 The TokTok team. |
3 | | * Copyright © 2013 Tox project. |
4 | | */ |
5 | | |
6 | | /** @file |
7 | | * @brief Public core API for Tox clients. |
8 | | * |
9 | | * Every function that can fail takes a function-specific error code pointer |
10 | | * that can be used to diagnose problems with the Tox state or the function |
11 | | * arguments. The error code pointer can be NULL, which does not influence the |
12 | | * function's behaviour, but can be done if the reason for failure is irrelevant |
13 | | * to the client. |
14 | | * |
15 | | * The exception to this rule are simple allocation functions whose only failure |
16 | | * mode is allocation failure. They return NULL in that case, and do not set an |
17 | | * error code. |
18 | | * |
19 | | * Every error code type has an OK value to which functions will set their error |
20 | | * code value on success. Clients can keep their error code uninitialised before |
21 | | * passing it to a function. The library guarantees that after returning, the |
22 | | * value pointed to by the error code pointer has been initialised. |
23 | | * |
24 | | * Functions with pointer parameters often have a NULL error code, meaning they |
25 | | * could not perform any operation, because one of the required parameters was |
26 | | * NULL. Some functions operate correctly or are defined as effectless on NULL. |
27 | | * |
28 | | * Some functions additionally return a value outside their |
29 | | * return type domain, or a bool containing true on success and false on |
30 | | * failure. |
31 | | * |
32 | | * All functions that take a Tox instance pointer will cause undefined behaviour |
33 | | * when passed a NULL Tox pointer. |
34 | | * |
35 | | * All integer values are expected in host byte order. |
36 | | * |
37 | | * Functions with parameters with enum types cause unspecified behaviour if the |
38 | | * enumeration value is outside the valid range of the type. If possible, the |
39 | | * function will try to use a sane default, but there will be no error code, |
40 | | * and one possible action for the function to take is to have no effect. |
41 | | * |
42 | | * Integer constants and the memory layout of publicly exposed structs are not |
43 | | * part of the ABI. |
44 | | * |
45 | | * @section events Events and callbacks |
46 | | * |
47 | | * Events are handled by callbacks. One callback can be registered per event. |
48 | | * All events have a callback function type named `tox_{event}_cb` and a |
49 | | * function to register it named `tox_callback_{event}`. Passing a NULL |
50 | | * callback will result in no callback being registered for that event. Only |
51 | | * one callback per event can be registered, so if a client needs multiple |
52 | | * event listeners, it needs to implement the dispatch functionality itself. |
53 | | * |
54 | | * The last argument to a callback is the user data pointer. It is passed from |
55 | | * tox_iterate to each callback in sequence. |
56 | | * |
57 | | * The user data pointer is never stored or dereferenced by any library code, so |
58 | | * can be any pointer, including NULL. Callbacks must all operate on the same |
59 | | * object type. In the apidsl code (tox.in.h), this is denoted with `any`. The |
60 | | * `any` in tox_iterate must be the same `any` as in all callbacks. In C, |
61 | | * lacking parametric polymorphism, this is a pointer to void. |
62 | | * |
63 | | * Old style callbacks that are registered together with a user data pointer |
64 | | * receive that pointer as argument when they are called. They can each have |
65 | | * their own user data pointer of their own type. |
66 | | * |
67 | | * @section threading Threading implications |
68 | | * |
69 | | * It is possible to run multiple concurrent threads with a Tox instance for |
70 | | * each thread. It is also possible to run all Tox instances in the same thread. |
71 | | * A common way to run Tox (multiple or single instance) is to have one thread |
72 | | * running a simple tox_iterate loop, sleeping for tox_iteration_interval |
73 | | * milliseconds on each iteration. |
74 | | * |
75 | | * If you want to access a single Tox instance from multiple threads, access |
76 | | * to the instance must be synchronised. While multiple threads can concurrently |
77 | | * access multiple different Tox instances, no more than one API function can |
78 | | * operate on a single instance at any given time. |
79 | | * |
80 | | * Functions that write to variable length byte arrays will always have a size |
81 | | * function associated with them. The result of this size function is only valid |
82 | | * until another mutating function (one that takes a pointer to non-const Tox) |
83 | | * is called. Thus, clients must ensure that no other thread calls a mutating |
84 | | * function between the call to the size function and the call to the retrieval |
85 | | * function. |
86 | | * |
87 | | * E.g. to get the current nickname, one would write |
88 | | * |
89 | | * @code |
90 | | * size_t length = tox_self_get_name_size(tox); |
91 | | * uint8_t *name = malloc(length); |
92 | | * if (!name) abort(); |
93 | | * tox_self_get_name(tox, name); |
94 | | * @endcode |
95 | | * |
96 | | * If any other thread calls tox_self_set_name while this thread is allocating |
97 | | * memory, the length may have become invalid, and the call to |
98 | | * tox_self_get_name may cause undefined behaviour. |
99 | | */ |
100 | | #ifndef C_TOXCORE_TOXCORE_TOX_H |
101 | | #define C_TOXCORE_TOXCORE_TOX_H |
102 | | |
103 | | #include <stdbool.h> |
104 | | #include <stddef.h> |
105 | | #include <stdint.h> |
106 | | |
107 | | #ifdef __cplusplus |
108 | | extern "C" { |
109 | | #endif |
110 | | |
111 | | /** @{ @namespace tox */ |
112 | | |
113 | | #ifndef TOX_DEFINED |
114 | | #define TOX_DEFINED |
115 | | /** |
116 | | * @brief The Tox instance type. |
117 | | * |
118 | | * All the state associated with a connection is held |
119 | | * within the instance. Multiple instances can exist and operate concurrently. |
120 | | * The maximum number of Tox instances that can exist on a single network |
121 | | * device is limited. Note that this is not just a per-process limit, since the |
122 | | * limiting factor is the number of usable ports on a device. |
123 | | */ |
124 | | typedef struct Tox Tox; |
125 | | #endif /* TOX_DEFINED */ |
126 | | |
127 | | |
128 | | /** @{ |
129 | | * @name API version |
130 | | */ |
131 | | |
132 | | /** |
133 | | * @brief The major version number. |
134 | | * |
135 | | * Incremented when the API or ABI changes in an incompatible way. |
136 | | * |
137 | | * The function variants of these constants return the version number of the |
138 | | * library. They can be used to display the Tox library version or to check |
139 | | * whether the client is compatible with the dynamically linked version of Tox. |
140 | | */ |
141 | 5 | #define TOX_VERSION_MAJOR 0 |
142 | | |
143 | | uint32_t tox_version_major(void); |
144 | | |
145 | | /** |
146 | | * @brief The minor version number. |
147 | | * |
148 | | * Incremented when functionality is added without breaking the API or ABI. |
149 | | * Set to 0 when the major version number is incremented. |
150 | | */ |
151 | 5 | #define TOX_VERSION_MINOR 2 |
152 | | |
153 | | uint32_t tox_version_minor(void); |
154 | | |
155 | | /** |
156 | | * @brief The patch or revision number. |
157 | | * |
158 | | * Incremented when bugfixes are applied without changing any functionality or |
159 | | * API or ABI. |
160 | | */ |
161 | 3 | #define TOX_VERSION_PATCH 18 |
162 | | |
163 | | uint32_t tox_version_patch(void); |
164 | | |
165 | | //!TOKSTYLE- |
166 | | /** |
167 | | * @brief A macro to check at preprocessing time whether the client code is |
168 | | * compatible with the installed version of Tox. |
169 | | * |
170 | | * Leading zeros in the version number are ignored. E.g. 0.1.5 is to 0.1.4 |
171 | | * what 1.5 is to 1.4, that is: it can add new features, but can't break the |
172 | | * API. |
173 | | */ |
174 | | #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ |
175 | 158 | ((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ |
176 | 0 | /* 1.x.x, 2.x.x, etc. with matching major version. */ \ |
177 | 0 | TOX_VERSION_MINOR > MINOR || \ |
178 | 0 | (TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \ |
179 | 122 | )) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ |
180 | 54 | /* 0.x.x makes minor behave like major above. */ \ |
181 | 54 | ((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ |
182 | 2 | TOX_VERSION_PATCH >= PATCH \ |
183 | 44 | )) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ |
184 | 16 | /* 0.0.x and 0.0.y are only compatible if x == y. */ \ |
185 | 16 | TOX_VERSION_PATCH == PATCH \ |
186 | 16 | )) \ |
187 | 54 | )) |
188 | | //!TOKSTYLE+ |
189 | | |
190 | | /** |
191 | | * @brief Return whether the compiled library version is compatible with the |
192 | | * passed version numbers. |
193 | | */ |
194 | | bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch); |
195 | | |
196 | | /** |
197 | | * @brief A convenience macro to call tox_version_is_compatible with the |
198 | | * currently compiling API version. |
199 | | */ |
200 | | #define TOX_VERSION_IS_ABI_COMPATIBLE() \ |
201 | | tox_version_is_compatible(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH) |
202 | | |
203 | | /** @} */ |
204 | | |
205 | | |
206 | | /** @{ |
207 | | * @name Numeric constants |
208 | | * |
209 | | * The values of these are not part of the ABI. Prefer to use the function |
210 | | * versions of them for code that should remain compatible with future versions |
211 | | * of toxcore. |
212 | | */ |
213 | | |
214 | | /** |
215 | | * @brief The size of a Tox Public Key in bytes. |
216 | | */ |
217 | 168k | #define TOX_PUBLIC_KEY_SIZE 32 |
218 | | |
219 | | uint32_t tox_public_key_size(void); |
220 | | |
221 | | /** |
222 | | * @brief The size of a Tox Secret Key in bytes. |
223 | | */ |
224 | 2 | #define TOX_SECRET_KEY_SIZE 32 |
225 | | |
226 | | uint32_t tox_secret_key_size(void); |
227 | | |
228 | | /** |
229 | | * @brief The size of a Tox Conference unique id in bytes. |
230 | | * |
231 | | * @deprecated Use TOX_CONFERENCE_ID_SIZE instead. |
232 | | */ |
233 | 1 | #define TOX_CONFERENCE_UID_SIZE 32 |
234 | | |
235 | | uint32_t tox_conference_uid_size(void); |
236 | | |
237 | | /** |
238 | | * @brief The size of a Tox Conference unique id in bytes. |
239 | | */ |
240 | 1 | #define TOX_CONFERENCE_ID_SIZE 32 |
241 | | |
242 | | uint32_t tox_conference_id_size(void); |
243 | | |
244 | | /** |
245 | | * @brief The size of the nospam in bytes when written in a Tox address. |
246 | | */ |
247 | 3 | #define TOX_NOSPAM_SIZE (sizeof(uint32_t)) |
248 | | |
249 | | uint32_t tox_nospam_size(void); |
250 | | |
251 | | /** |
252 | | * @brief The size of a Tox address in bytes. |
253 | | * |
254 | | * Tox addresses are in the format |
255 | | * `[Public Key (TOX_PUBLIC_KEY_SIZE bytes)][nospam (4 bytes)][checksum (2 bytes)]`. |
256 | | * |
257 | | * The checksum is computed over the Public Key and the nospam value. The first |
258 | | * byte is an XOR of all the even bytes (0, 2, 4, ...), the second byte is an |
259 | | * XOR of all the odd bytes (1, 3, 5, ...) of the Public Key and nospam. |
260 | | */ |
261 | 2 | #define TOX_ADDRESS_SIZE (TOX_PUBLIC_KEY_SIZE + TOX_NOSPAM_SIZE + sizeof(uint16_t)) |
262 | | |
263 | | uint32_t tox_address_size(void); |
264 | | |
265 | | /** |
266 | | * @brief Maximum length of a nickname in bytes. |
267 | | * |
268 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
269 | | */ |
270 | 267 | #define TOX_MAX_NAME_LENGTH 128 |
271 | | |
272 | | uint32_t tox_max_name_length(void); |
273 | | |
274 | | /** |
275 | | * @brief Maximum length of a status message in bytes. |
276 | | * |
277 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
278 | | */ |
279 | 2.02k | #define TOX_MAX_STATUS_MESSAGE_LENGTH 1007 |
280 | | |
281 | | uint32_t tox_max_status_message_length(void); |
282 | | |
283 | | /** |
284 | | * @brief Maximum length of a friend request message in bytes. |
285 | | * |
286 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
287 | | */ |
288 | 4 | #define TOX_MAX_FRIEND_REQUEST_LENGTH 1016 |
289 | | |
290 | | uint32_t tox_max_friend_request_length(void); |
291 | | |
292 | | /** |
293 | | * @brief Maximum length of a single message after which it should be split. |
294 | | * |
295 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
296 | | */ |
297 | 453 | #define TOX_MAX_MESSAGE_LENGTH 1372 |
298 | | |
299 | | uint32_t tox_max_message_length(void); |
300 | | |
301 | | /** |
302 | | * @brief Maximum size of custom packets. TODO(iphydf): should be LENGTH? |
303 | | * |
304 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
305 | | */ |
306 | 89 | #define TOX_MAX_CUSTOM_PACKET_SIZE 1373 |
307 | | |
308 | | uint32_t tox_max_custom_packet_size(void); |
309 | | |
310 | | /** |
311 | | * @brief The number of bytes in a hash generated by tox_hash. |
312 | | */ |
313 | 1 | #define TOX_HASH_LENGTH 32 |
314 | | |
315 | | uint32_t tox_hash_length(void); |
316 | | |
317 | | /** |
318 | | * @brief The number of bytes in a file id. |
319 | | */ |
320 | 1 | #define TOX_FILE_ID_LENGTH 32 |
321 | | |
322 | | uint32_t tox_file_id_length(void); |
323 | | |
324 | | /** |
325 | | * @brief Maximum file name length for file transfers. |
326 | | * |
327 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
328 | | */ |
329 | 1 | #define TOX_MAX_FILENAME_LENGTH 255 |
330 | | |
331 | | uint32_t tox_max_filename_length(void); |
332 | | |
333 | | /** |
334 | | * @brief Maximum length of a hostname, e.g. proxy or bootstrap node names. |
335 | | * |
336 | | * This length does not include the NUL byte. Hostnames are NUL-terminated C |
337 | | * strings, so they are 255 characters plus one NUL byte. |
338 | | * |
339 | | * @deprecated The macro will be removed in 0.3.0. Use the function instead. |
340 | | */ |
341 | 1 | #define TOX_MAX_HOSTNAME_LENGTH 255 |
342 | | |
343 | | uint32_t tox_max_hostname_length(void); |
344 | | |
345 | | /** @} */ |
346 | | |
347 | | |
348 | | /** @{ |
349 | | * @name Global enumerations |
350 | | */ |
351 | | |
352 | | /** |
353 | | * @brief Represents the possible statuses a client can have. |
354 | | */ |
355 | | typedef enum Tox_User_Status { |
356 | | |
357 | | /** |
358 | | * User is online and available. |
359 | | */ |
360 | | TOX_USER_STATUS_NONE, |
361 | | |
362 | | /** |
363 | | * User is away. Clients can set this e.g. after a user defined |
364 | | * inactivity time. |
365 | | */ |
366 | | TOX_USER_STATUS_AWAY, |
367 | | |
368 | | /** |
369 | | * User is busy. Signals to other clients that this client does not |
370 | | * currently wish to communicate. |
371 | | */ |
372 | | TOX_USER_STATUS_BUSY, |
373 | | |
374 | | } Tox_User_Status; |
375 | | |
376 | | const char *tox_user_status_to_string(Tox_User_Status value); |
377 | | |
378 | | |
379 | | /** |
380 | | * @brief Represents message types for tox_friend_send_message and conference |
381 | | * messages. |
382 | | */ |
383 | | typedef enum Tox_Message_Type { |
384 | | |
385 | | /** |
386 | | * Normal text message. Similar to PRIVMSG on IRC. |
387 | | */ |
388 | | TOX_MESSAGE_TYPE_NORMAL, |
389 | | |
390 | | /** |
391 | | * A message describing an user action. This is similar to /me (CTCP ACTION) |
392 | | * on IRC. |
393 | | */ |
394 | | TOX_MESSAGE_TYPE_ACTION, |
395 | | |
396 | | } Tox_Message_Type; |
397 | | |
398 | | const char *tox_message_type_to_string(Tox_Message_Type value); |
399 | | |
400 | | /** @} */ |
401 | | |
402 | | |
403 | | /** @{ |
404 | | * @name Startup options |
405 | | */ |
406 | | |
407 | | /** |
408 | | * @brief Type of proxy used to connect to TCP relays. |
409 | | */ |
410 | | typedef enum Tox_Proxy_Type { |
411 | | |
412 | | /** |
413 | | * Don't use a proxy. |
414 | | */ |
415 | | TOX_PROXY_TYPE_NONE, |
416 | | |
417 | | /** |
418 | | * HTTP proxy using CONNECT. |
419 | | */ |
420 | | TOX_PROXY_TYPE_HTTP, |
421 | | |
422 | | /** |
423 | | * SOCKS proxy for simple socket pipes. |
424 | | */ |
425 | | TOX_PROXY_TYPE_SOCKS5, |
426 | | |
427 | | } Tox_Proxy_Type; |
428 | | |
429 | | const char *tox_proxy_type_to_string(Tox_Proxy_Type value); |
430 | | |
431 | | |
432 | | /** |
433 | | * @brief Type of savedata to create the Tox instance from. |
434 | | */ |
435 | | typedef enum Tox_Savedata_Type { |
436 | | |
437 | | /** |
438 | | * No savedata. |
439 | | */ |
440 | | TOX_SAVEDATA_TYPE_NONE, |
441 | | |
442 | | /** |
443 | | * Savedata is one that was obtained from tox_get_savedata. |
444 | | */ |
445 | | TOX_SAVEDATA_TYPE_TOX_SAVE, |
446 | | |
447 | | /** |
448 | | * Savedata is a secret key of length TOX_SECRET_KEY_SIZE. |
449 | | */ |
450 | | TOX_SAVEDATA_TYPE_SECRET_KEY, |
451 | | |
452 | | } Tox_Savedata_Type; |
453 | | |
454 | | const char *tox_savedata_type_to_string(Tox_Savedata_Type value); |
455 | | |
456 | | |
457 | | /** |
458 | | * @brief Severity level of log messages. |
459 | | */ |
460 | | typedef enum Tox_Log_Level { |
461 | | |
462 | | /** |
463 | | * Very detailed traces including all network activity. |
464 | | */ |
465 | | TOX_LOG_LEVEL_TRACE, |
466 | | |
467 | | /** |
468 | | * Debug messages such as which port we bind to. |
469 | | */ |
470 | | TOX_LOG_LEVEL_DEBUG, |
471 | | |
472 | | /** |
473 | | * Informational log messages such as video call status changes. |
474 | | */ |
475 | | TOX_LOG_LEVEL_INFO, |
476 | | |
477 | | /** |
478 | | * Warnings about events_alloc inconsistency or logic errors. |
479 | | */ |
480 | | TOX_LOG_LEVEL_WARNING, |
481 | | |
482 | | /** |
483 | | * Severe unexpected errors caused by external or events_alloc inconsistency. |
484 | | */ |
485 | | TOX_LOG_LEVEL_ERROR, |
486 | | |
487 | | } Tox_Log_Level; |
488 | | |
489 | | const char *tox_log_level_to_string(Tox_Log_Level value); |
490 | | |
491 | | |
492 | | /** |
493 | | * @brief This event is triggered when the toxcore library logs an events_alloc message. |
494 | | * |
495 | | * This is mostly useful for debugging. This callback can be called from any |
496 | | * function, not just tox_iterate. This means the user data lifetime must at |
497 | | * least extend between registering and unregistering it or tox_kill. |
498 | | * |
499 | | * Other toxcore modules such as toxav may concurrently call this callback at |
500 | | * any time. Thus, user code must make sure it is equipped to handle concurrent |
501 | | * execution, e.g. by employing appropriate mutex locking. |
502 | | * |
503 | | * @param level The severity of the log message. |
504 | | * @param file The source file from which the message originated. |
505 | | * @param line The source line from which the message originated. |
506 | | * @param func The function from which the message originated. |
507 | | * @param message The log message. |
508 | | * @param user_data The user data pointer passed to tox_new in options. |
509 | | */ |
510 | | typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func, |
511 | | const char *message, void *user_data); |
512 | | |
513 | | |
514 | | /** |
515 | | * @brief Operating system functions used by Tox. |
516 | | * |
517 | | * This struct is opaque and generally shouldn't be used in clients, but in |
518 | | * combination with tox_private.h, it allows tests to inject non-IO (hermetic) |
519 | | * versions of low level network, RNG, and time keeping functions. |
520 | | */ |
521 | | typedef struct Tox_System Tox_System; |
522 | | |
523 | | |
524 | | /** |
525 | | * @brief This struct contains all the startup options for Tox. |
526 | | * |
527 | | * You must tox_options_new to allocate an object of this type. |
528 | | * |
529 | | * WARNING: Although this struct happens to be visible in the API, it is |
530 | | * effectively private. Do not allocate this yourself or access members |
531 | | * directly, as it *will* break binary compatibility frequently. |
532 | | * |
533 | | * @deprecated The memory layout of this struct (size, alignment, and field |
534 | | * order) is not part of the ABI. To remain compatible, prefer to use |
535 | | * tox_options_new to allocate the object and accessor functions to set the |
536 | | * members. The struct will become opaque (i.e. the definition will become |
537 | | * private) in v0.3.0. |
538 | | */ |
539 | | typedef struct Tox_Options Tox_Options; |
540 | | struct Tox_Options { |
541 | | |
542 | | /** |
543 | | * The type of socket to create. |
544 | | * |
545 | | * If this is set to false, an IPv4 socket is created, which subsequently |
546 | | * only allows IPv4 communication. |
547 | | * If it is set to true, an IPv6 socket is created, allowing both IPv4 and |
548 | | * IPv6 communication. |
549 | | */ |
550 | | bool ipv6_enabled; |
551 | | |
552 | | |
553 | | /** |
554 | | * Enable the use of UDP communication when available. |
555 | | * |
556 | | * Setting this to false will force Tox to use TCP only. Communications will |
557 | | * need to be relayed through a TCP relay node, potentially slowing them down. |
558 | | * |
559 | | * If a proxy is enabled, UDP will be disabled if either toxcore or the |
560 | | * proxy don't support proxying UDP messages. |
561 | | */ |
562 | | bool udp_enabled; |
563 | | |
564 | | |
565 | | /** |
566 | | * Enable local network peer discovery. |
567 | | * |
568 | | * Disabling this will cause Tox to not look for peers on the local network. |
569 | | */ |
570 | | bool local_discovery_enabled; |
571 | | |
572 | | |
573 | | /** |
574 | | * Enable storing DHT announcements and forwarding corresponding requests. |
575 | | * |
576 | | * Disabling this will cause Tox to ignore the relevant packets. |
577 | | */ |
578 | | bool dht_announcements_enabled; |
579 | | |
580 | | /** |
581 | | * Pass communications through a proxy. |
582 | | */ |
583 | | Tox_Proxy_Type proxy_type; |
584 | | |
585 | | |
586 | | /** |
587 | | * The IP address or DNS name of the proxy to be used. |
588 | | * |
589 | | * If used, this must be non-NULL and be a valid DNS name. The name must not |
590 | | * exceed TOX_MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C string |
591 | | * format (TOX_MAX_HOSTNAME_LENGTH includes the NUL byte). |
592 | | * |
593 | | * This member is ignored (it can be NULL) if proxy_type is TOX_PROXY_TYPE_NONE. |
594 | | * |
595 | | * The data pointed at by this member is owned by the user, so must |
596 | | * outlive the options object. |
597 | | */ |
598 | | const char *proxy_host; |
599 | | |
600 | | |
601 | | /** |
602 | | * The port to use to connect to the proxy server. |
603 | | * |
604 | | * Ports must be in the range (1, 65535). The value is ignored if |
605 | | * proxy_type is TOX_PROXY_TYPE_NONE. |
606 | | */ |
607 | | uint16_t proxy_port; |
608 | | |
609 | | |
610 | | /** |
611 | | * The start port of the inclusive port range to attempt to use. |
612 | | * |
613 | | * If both start_port and end_port are 0, the default port range will be |
614 | | * used: `[33445, 33545]`. |
615 | | * |
616 | | * If either start_port or end_port is 0 while the other is non-zero, the |
617 | | * non-zero port will be the only port in the range. |
618 | | * |
619 | | * Having start_port > end_port will yield the same behavior as if start_port |
620 | | * and end_port were swapped. |
621 | | */ |
622 | | uint16_t start_port; |
623 | | |
624 | | |
625 | | /** |
626 | | * The end port of the inclusive port range to attempt to use. |
627 | | */ |
628 | | uint16_t end_port; |
629 | | |
630 | | |
631 | | /** |
632 | | * The port to use for the TCP server (relay). If 0, the TCP server is |
633 | | * disabled. |
634 | | * |
635 | | * Enabling it is not required for Tox to function properly. |
636 | | * |
637 | | * When enabled, your Tox instance can act as a TCP relay for other Tox |
638 | | * instance. This leads to increased traffic, thus when writing a client |
639 | | * it is recommended to enable TCP server only if the user has an option |
640 | | * to disable it. |
641 | | */ |
642 | | uint16_t tcp_port; |
643 | | |
644 | | |
645 | | /** |
646 | | * Enables or disables UDP hole-punching in toxcore. (Default: enabled). |
647 | | */ |
648 | | bool hole_punching_enabled; |
649 | | |
650 | | |
651 | | /** |
652 | | * The type of savedata to load from. |
653 | | */ |
654 | | Tox_Savedata_Type savedata_type; |
655 | | |
656 | | |
657 | | /** |
658 | | * The savedata. |
659 | | * |
660 | | * The data pointed at by this member is owned by the user, so must |
661 | | * outlive the options object. |
662 | | */ |
663 | | const uint8_t *savedata_data; |
664 | | |
665 | | |
666 | | /** |
667 | | * The length of the savedata. |
668 | | */ |
669 | | size_t savedata_length; |
670 | | |
671 | | |
672 | | /** |
673 | | * Logging callback for the new tox instance. |
674 | | */ |
675 | | tox_log_cb *log_callback; |
676 | | |
677 | | |
678 | | /** |
679 | | * User data pointer passed to the logging callback. |
680 | | */ |
681 | | void *log_user_data; |
682 | | |
683 | | |
684 | | /** |
685 | | * These options are experimental, so avoid writing code that depends on |
686 | | * them. Options marked "experimental" may change their behaviour or go away |
687 | | * entirely in the future, or may be renamed to something non-experimental |
688 | | * if they become part of the supported API. |
689 | | */ |
690 | | /** |
691 | | * Make public API functions thread-safe using a per-instance lock. |
692 | | * |
693 | | * Default: false. |
694 | | */ |
695 | | bool experimental_thread_safety; |
696 | | |
697 | | /** |
698 | | * Low level operating system functionality such as send/recv, random |
699 | | * number generation, and memory allocation. |
700 | | */ |
701 | | const Tox_System *operating_system; |
702 | | |
703 | | }; |
704 | | |
705 | | |
706 | | bool tox_options_get_ipv6_enabled(const Tox_Options *options); |
707 | | |
708 | | void tox_options_set_ipv6_enabled(Tox_Options *options, bool ipv6_enabled); |
709 | | |
710 | | bool tox_options_get_udp_enabled(const Tox_Options *options); |
711 | | |
712 | | void tox_options_set_udp_enabled(Tox_Options *options, bool udp_enabled); |
713 | | |
714 | | bool tox_options_get_local_discovery_enabled(const Tox_Options *options); |
715 | | |
716 | | void tox_options_set_local_discovery_enabled(Tox_Options *options, bool local_discovery_enabled); |
717 | | |
718 | | bool tox_options_get_dht_announcements_enabled(const Tox_Options *options); |
719 | | |
720 | | void tox_options_set_dht_announcements_enabled(Tox_Options *options, bool dht_announcements_enabled); |
721 | | |
722 | | Tox_Proxy_Type tox_options_get_proxy_type(const Tox_Options *options); |
723 | | |
724 | | void tox_options_set_proxy_type(Tox_Options *options, Tox_Proxy_Type proxy_type); |
725 | | |
726 | | const char *tox_options_get_proxy_host(const Tox_Options *options); |
727 | | |
728 | | void tox_options_set_proxy_host(Tox_Options *options, const char *proxy_host); |
729 | | |
730 | | uint16_t tox_options_get_proxy_port(const Tox_Options *options); |
731 | | |
732 | | void tox_options_set_proxy_port(Tox_Options *options, uint16_t proxy_port); |
733 | | |
734 | | uint16_t tox_options_get_start_port(const Tox_Options *options); |
735 | | |
736 | | void tox_options_set_start_port(Tox_Options *options, uint16_t start_port); |
737 | | |
738 | | uint16_t tox_options_get_end_port(const Tox_Options *options); |
739 | | |
740 | | void tox_options_set_end_port(Tox_Options *options, uint16_t end_port); |
741 | | |
742 | | uint16_t tox_options_get_tcp_port(const Tox_Options *options); |
743 | | |
744 | | void tox_options_set_tcp_port(Tox_Options *options, uint16_t tcp_port); |
745 | | |
746 | | bool tox_options_get_hole_punching_enabled(const Tox_Options *options); |
747 | | |
748 | | void tox_options_set_hole_punching_enabled(Tox_Options *options, bool hole_punching_enabled); |
749 | | |
750 | | Tox_Savedata_Type tox_options_get_savedata_type(const Tox_Options *options); |
751 | | |
752 | | void tox_options_set_savedata_type(Tox_Options *options, Tox_Savedata_Type savedata_type); |
753 | | |
754 | | const uint8_t *tox_options_get_savedata_data(const Tox_Options *options); |
755 | | |
756 | | void tox_options_set_savedata_data(Tox_Options *options, const uint8_t savedata_data[], size_t length); |
757 | | |
758 | | size_t tox_options_get_savedata_length(const Tox_Options *options); |
759 | | |
760 | | void tox_options_set_savedata_length(Tox_Options *options, size_t savedata_length); |
761 | | |
762 | | tox_log_cb *tox_options_get_log_callback(const Tox_Options *options); |
763 | | |
764 | | void tox_options_set_log_callback(Tox_Options *options, tox_log_cb *log_callback); |
765 | | |
766 | | void *tox_options_get_log_user_data(const Tox_Options *options); |
767 | | |
768 | | void tox_options_set_log_user_data(Tox_Options *options, void *log_user_data); |
769 | | |
770 | | bool tox_options_get_experimental_thread_safety(const Tox_Options *options); |
771 | | |
772 | | void tox_options_set_experimental_thread_safety(Tox_Options *options, bool experimental_thread_safety); |
773 | | |
774 | | const Tox_System *tox_options_get_operating_system(const Tox_Options *options); |
775 | | |
776 | | void tox_options_set_operating_system(Tox_Options *options, const Tox_System *operating_system); |
777 | | |
778 | | /** |
779 | | * @brief Initialises a Tox_Options object with the default options. |
780 | | * |
781 | | * The result of this function is independent of the original options. All |
782 | | * values will be overwritten, no values will be read (so it is permissible |
783 | | * to pass an uninitialised object). |
784 | | * |
785 | | * If options is NULL, this function has no effect. |
786 | | * |
787 | | * @param options An options object to be filled with default options. |
788 | | */ |
789 | | void tox_options_default(Tox_Options *options); |
790 | | |
791 | | typedef enum Tox_Err_Options_New { |
792 | | |
793 | | /** |
794 | | * The function returned successfully. |
795 | | */ |
796 | | TOX_ERR_OPTIONS_NEW_OK, |
797 | | |
798 | | /** |
799 | | * The function failed to allocate enough memory for the options struct. |
800 | | */ |
801 | | TOX_ERR_OPTIONS_NEW_MALLOC, |
802 | | |
803 | | } Tox_Err_Options_New; |
804 | | |
805 | | const char *tox_err_options_new_to_string(Tox_Err_Options_New value); |
806 | | |
807 | | |
808 | | /** |
809 | | * @brief Allocates a new Tox_Options object and initialises it with the default |
810 | | * options. |
811 | | * |
812 | | * This function can be used to preserve long term ABI compatibility by |
813 | | * giving the responsibility of allocation and deallocation to the Tox library. |
814 | | * |
815 | | * Objects returned from this function must be freed using the tox_options_free |
816 | | * function. |
817 | | * |
818 | | * @return A new Tox_Options object with default options or NULL on failure. |
819 | | */ |
820 | | Tox_Options *tox_options_new(Tox_Err_Options_New *error); |
821 | | |
822 | | /** |
823 | | * @brief Releases all resources associated with an options objects. |
824 | | * |
825 | | * Passing a pointer that was not returned by tox_options_new results in |
826 | | * undefined behaviour. |
827 | | */ |
828 | | void tox_options_free(Tox_Options *options); |
829 | | |
830 | | /** @} */ |
831 | | |
832 | | |
833 | | /** @{ |
834 | | * @name Creation and destruction |
835 | | */ |
836 | | |
837 | | typedef enum Tox_Err_New { |
838 | | |
839 | | /** |
840 | | * The function returned successfully. |
841 | | */ |
842 | | TOX_ERR_NEW_OK, |
843 | | |
844 | | /** |
845 | | * One of the arguments to the function was NULL when it was not expected. |
846 | | */ |
847 | | TOX_ERR_NEW_NULL, |
848 | | |
849 | | /** |
850 | | * The function was unable to allocate enough memory to store the events_alloc |
851 | | * structures for the Tox object. |
852 | | */ |
853 | | TOX_ERR_NEW_MALLOC, |
854 | | |
855 | | /** |
856 | | * The function was unable to bind to a port. This may mean that all ports |
857 | | * have already been bound, e.g. by other Tox instances, or it may mean |
858 | | * a permission error. You may be able to gather more information from errno. |
859 | | */ |
860 | | TOX_ERR_NEW_PORT_ALLOC, |
861 | | |
862 | | /** |
863 | | * proxy_type was invalid. |
864 | | */ |
865 | | TOX_ERR_NEW_PROXY_BAD_TYPE, |
866 | | |
867 | | /** |
868 | | * proxy_type was valid but the proxy_host passed had an invalid format |
869 | | * or was NULL. |
870 | | */ |
871 | | TOX_ERR_NEW_PROXY_BAD_HOST, |
872 | | |
873 | | /** |
874 | | * proxy_type was valid, but the proxy_port was invalid. |
875 | | */ |
876 | | TOX_ERR_NEW_PROXY_BAD_PORT, |
877 | | |
878 | | /** |
879 | | * The proxy address passed could not be resolved. |
880 | | */ |
881 | | TOX_ERR_NEW_PROXY_NOT_FOUND, |
882 | | |
883 | | /** |
884 | | * The byte array to be loaded contained an encrypted save. |
885 | | */ |
886 | | TOX_ERR_NEW_LOAD_ENCRYPTED, |
887 | | |
888 | | /** |
889 | | * The data format was invalid. This can happen when loading data that was |
890 | | * saved by an older version of Tox, or when the data has been corrupted. |
891 | | * When loading from badly formatted data, some data may have been loaded, |
892 | | * and the rest is discarded. Passing an invalid length parameter also |
893 | | * causes this error. |
894 | | */ |
895 | | TOX_ERR_NEW_LOAD_BAD_FORMAT, |
896 | | |
897 | | } Tox_Err_New; |
898 | | |
899 | | const char *tox_err_new_to_string(Tox_Err_New value); |
900 | | |
901 | | |
902 | | /** |
903 | | * @brief Creates and initialises a new Tox instance with the options passed. |
904 | | * |
905 | | * This function will bring the instance into a valid state. Running the event |
906 | | * loop with a new instance will operate correctly. |
907 | | * |
908 | | * @param options An options object as described above. If this parameter is |
909 | | * NULL, the default options are used. |
910 | | * |
911 | | * @see tox_iterate for the event loop. |
912 | | * |
913 | | * @return A new Tox instance pointer on success or NULL on failure. |
914 | | */ |
915 | | Tox *tox_new(const Tox_Options *options, Tox_Err_New *error); |
916 | | |
917 | | /** |
918 | | * @brief Releases all resources associated with the Tox instance and |
919 | | * disconnects from the network. |
920 | | * |
921 | | * After calling this function, the Tox pointer becomes invalid. No other |
922 | | * functions can be called, and the pointer value can no longer be read. |
923 | | */ |
924 | | void tox_kill(Tox *tox); |
925 | | |
926 | | /** |
927 | | * @brief Calculates the number of bytes required to store the tox instance with |
928 | | * tox_get_savedata. |
929 | | * |
930 | | * This function cannot fail. The result is always greater than 0. |
931 | | * |
932 | | * @see threading for concurrency implications. |
933 | | */ |
934 | | size_t tox_get_savedata_size(const Tox *tox); |
935 | | |
936 | | /** |
937 | | * @brief Store all information associated with the tox instance to a byte array. |
938 | | * |
939 | | * @param savedata A memory region large enough to store the tox instance |
940 | | * data. Call tox_get_savedata_size to find the number of bytes required. If this parameter |
941 | | * is NULL, this function has no effect. |
942 | | */ |
943 | | void tox_get_savedata(const Tox *tox, uint8_t savedata[]); |
944 | | |
945 | | /** @} */ |
946 | | |
947 | | |
948 | | /** @{ |
949 | | * @name Connection lifecycle and event loop |
950 | | */ |
951 | | |
952 | | typedef enum Tox_Err_Bootstrap { |
953 | | |
954 | | /** |
955 | | * The function returned successfully. |
956 | | */ |
957 | | TOX_ERR_BOOTSTRAP_OK, |
958 | | |
959 | | /** |
960 | | * One of the arguments to the function was NULL when it was not expected. |
961 | | */ |
962 | | TOX_ERR_BOOTSTRAP_NULL, |
963 | | |
964 | | /** |
965 | | * The hostname could not be resolved to an IP address, the IP address |
966 | | * passed was invalid, or the function failed to send the initial request |
967 | | * packet to the bootstrap node or TCP relay. |
968 | | */ |
969 | | TOX_ERR_BOOTSTRAP_BAD_HOST, |
970 | | |
971 | | /** |
972 | | * The port passed was invalid. The valid port range is (1, 65535). |
973 | | */ |
974 | | TOX_ERR_BOOTSTRAP_BAD_PORT, |
975 | | |
976 | | } Tox_Err_Bootstrap; |
977 | | |
978 | | const char *tox_err_bootstrap_to_string(Tox_Err_Bootstrap value); |
979 | | |
980 | | |
981 | | /** |
982 | | * @brief Sends a "get nodes" request to the given bootstrap node with IP, port, |
983 | | * and public key to setup connections. |
984 | | * |
985 | | * This function will attempt to connect to the node using UDP. You must use |
986 | | * this function even if Tox_Options.udp_enabled was set to false. |
987 | | * |
988 | | * @param host The hostname or IP address (IPv4 or IPv6) of the node. Must be |
989 | | * at most TOX_MAX_HOSTNAME_LENGTH chars, including the NUL byte. |
990 | | * @param port The port on the host on which the bootstrap Tox instance is |
991 | | * listening. |
992 | | * @param public_key The long term public key of the bootstrap node |
993 | | * (TOX_PUBLIC_KEY_SIZE bytes). |
994 | | * @return true on success. |
995 | | */ |
996 | | bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Bootstrap *error); |
997 | | |
998 | | /** |
999 | | * @brief Adds additional host:port pair as TCP relay. |
1000 | | * |
1001 | | * This function can be used to initiate TCP connections to different ports on |
1002 | | * the same bootstrap node, or to add TCP relays without using them as |
1003 | | * bootstrap nodes. |
1004 | | * |
1005 | | * @param host The hostname or IP address (IPv4 or IPv6) of the TCP relay. |
1006 | | * Must be at most TOX_MAX_HOSTNAME_LENGTH chars, including the NUL byte. |
1007 | | * @param port The port on the host on which the TCP relay is listening. |
1008 | | * @param public_key The long term public key of the TCP relay |
1009 | | * (TOX_PUBLIC_KEY_SIZE bytes). |
1010 | | * @return true on success. |
1011 | | */ |
1012 | | bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Bootstrap *error); |
1013 | | |
1014 | | /** |
1015 | | * @brief Protocols that can be used to connect to the network or friends. |
1016 | | */ |
1017 | | typedef enum Tox_Connection { |
1018 | | |
1019 | | /** |
1020 | | * @brief There is no connection. |
1021 | | * |
1022 | | * This instance, or the friend the state change is about, is now offline. |
1023 | | */ |
1024 | | TOX_CONNECTION_NONE, |
1025 | | |
1026 | | /** |
1027 | | * @brief A TCP connection has been established. |
1028 | | * |
1029 | | * For the own instance, this means it is connected through a TCP relay, |
1030 | | * only. For a friend, this means that the connection to that particular |
1031 | | * friend goes through a TCP relay. |
1032 | | */ |
1033 | | TOX_CONNECTION_TCP, |
1034 | | |
1035 | | /** |
1036 | | * @brief A UDP connection has been established. |
1037 | | * |
1038 | | * For the own instance, this means it is able to send UDP packets to DHT |
1039 | | * nodes, but may still be connected to a TCP relay. For a friend, this |
1040 | | * means that the connection to that particular friend was built using |
1041 | | * direct UDP packets. |
1042 | | */ |
1043 | | TOX_CONNECTION_UDP, |
1044 | | |
1045 | | } Tox_Connection; |
1046 | | |
1047 | | const char *tox_connection_to_string(Tox_Connection value); |
1048 | | |
1049 | | /** |
1050 | | * @brief Return whether we are connected to the DHT. |
1051 | | * |
1052 | | * The return value is equal to the last value received through the |
1053 | | * `self_connection_status` callback. |
1054 | | * |
1055 | | * @deprecated This getter is deprecated. Use the event and store the status |
1056 | | * in the client state. |
1057 | | */ |
1058 | | Tox_Connection tox_self_get_connection_status(const Tox *tox); |
1059 | | |
1060 | | /** |
1061 | | * @param connection_status Whether we are connected to the DHT. |
1062 | | */ |
1063 | | typedef void tox_self_connection_status_cb(Tox *tox, Tox_Connection connection_status, void *user_data); |
1064 | | |
1065 | | |
1066 | | /** |
1067 | | * @brief Set the callback for the `self_connection_status` event. |
1068 | | * |
1069 | | * Pass NULL to unset. |
1070 | | * |
1071 | | * This event is triggered whenever there is a change in the DHT connection |
1072 | | * state. When disconnected, a client may choose to call tox_bootstrap again, to |
1073 | | * reconnect to the DHT. Note that this state may frequently change for short |
1074 | | * amounts of time. Clients should therefore not immediately bootstrap on |
1075 | | * receiving a disconnect. |
1076 | | * |
1077 | | * TODO(iphydf): how long should a client wait before bootstrapping again? |
1078 | | */ |
1079 | | void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback); |
1080 | | |
1081 | | /** |
1082 | | * @brief Return the time in milliseconds before `tox_iterate()` should be called again |
1083 | | * for optimal performance. |
1084 | | */ |
1085 | | uint32_t tox_iteration_interval(const Tox *tox); |
1086 | | |
1087 | | /** |
1088 | | * @brief The main loop that needs to be run in intervals of `tox_iteration_interval()` |
1089 | | * milliseconds. |
1090 | | */ |
1091 | | void tox_iterate(Tox *tox, void *user_data); |
1092 | | |
1093 | | /** @} */ |
1094 | | |
1095 | | |
1096 | | /** @{ |
1097 | | * @name Internal client information (Tox address/id) |
1098 | | */ |
1099 | | |
1100 | | /** |
1101 | | * @brief Writes the Tox friend address of the client to a byte array. |
1102 | | * |
1103 | | * The address is not in human-readable format. If a client wants to display |
1104 | | * the address, formatting is required. |
1105 | | * |
1106 | | * @param address A memory region of at least TOX_ADDRESS_SIZE bytes. If this |
1107 | | * parameter is NULL, this function has no effect. |
1108 | | * @see TOX_ADDRESS_SIZE for the address format. |
1109 | | */ |
1110 | | void tox_self_get_address(const Tox *tox, uint8_t address[TOX_ADDRESS_SIZE]); |
1111 | | |
1112 | | /** |
1113 | | * @brief Set the 4-byte nospam part of the address. |
1114 | | * |
1115 | | * This value is expected in host byte order. I.e. 0x12345678 will form the |
1116 | | * bytes `[12, 34, 56, 78]` in the nospam part of the Tox friend address. |
1117 | | * |
1118 | | * @param nospam Any 32 bit unsigned integer. |
1119 | | */ |
1120 | | void tox_self_set_nospam(Tox *tox, uint32_t nospam); |
1121 | | |
1122 | | /** |
1123 | | * @brief Get the 4-byte nospam part of the address. |
1124 | | * |
1125 | | * This value is returned in host byte order. |
1126 | | */ |
1127 | | uint32_t tox_self_get_nospam(const Tox *tox); |
1128 | | |
1129 | | /** |
1130 | | * @brief Copy the Tox Public Key (long term) from the Tox object. |
1131 | | * |
1132 | | * @param public_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If |
1133 | | * this parameter is NULL, this function has no effect. |
1134 | | */ |
1135 | | void tox_self_get_public_key(const Tox *tox, uint8_t public_key[TOX_PUBLIC_KEY_SIZE]); |
1136 | | |
1137 | | /** |
1138 | | * @brief Copy the Tox Secret Key from the Tox object. |
1139 | | * |
1140 | | * @param secret_key A memory region of at least TOX_SECRET_KEY_SIZE bytes. If |
1141 | | * this parameter is NULL, this function has no effect. |
1142 | | */ |
1143 | | void tox_self_get_secret_key(const Tox *tox, uint8_t secret_key[TOX_SECRET_KEY_SIZE]); |
1144 | | |
1145 | | /** @} */ |
1146 | | |
1147 | | |
1148 | | /** @{ |
1149 | | * @name User-visible client information (nickname/status) |
1150 | | */ |
1151 | | |
1152 | | /** |
1153 | | * @brief Common error codes for all functions that set a piece of user-visible |
1154 | | * client information. |
1155 | | */ |
1156 | | typedef enum Tox_Err_Set_Info { |
1157 | | |
1158 | | /** |
1159 | | * The function returned successfully. |
1160 | | */ |
1161 | | TOX_ERR_SET_INFO_OK, |
1162 | | |
1163 | | /** |
1164 | | * One of the arguments to the function was NULL when it was not expected. |
1165 | | */ |
1166 | | TOX_ERR_SET_INFO_NULL, |
1167 | | |
1168 | | /** |
1169 | | * Information length exceeded maximum permissible size. |
1170 | | */ |
1171 | | TOX_ERR_SET_INFO_TOO_LONG, |
1172 | | |
1173 | | } Tox_Err_Set_Info; |
1174 | | |
1175 | | const char *tox_err_set_info_to_string(Tox_Err_Set_Info value); |
1176 | | |
1177 | | |
1178 | | /** |
1179 | | * @brief Set the nickname for the Tox client. |
1180 | | * |
1181 | | * Nickname length cannot exceed TOX_MAX_NAME_LENGTH. If length is 0, the name |
1182 | | * parameter is ignored (it can be NULL), and the nickname is set back to empty. |
1183 | | * |
1184 | | * @param name A byte array containing the new nickname. |
1185 | | * @param length The size of the name byte array. |
1186 | | * |
1187 | | * @return true on success. |
1188 | | */ |
1189 | | bool tox_self_set_name(Tox *tox, const uint8_t name[], size_t length, Tox_Err_Set_Info *error); |
1190 | | |
1191 | | /** |
1192 | | * @brief Return the length of the current nickname as passed to tox_self_set_name. |
1193 | | * |
1194 | | * If no nickname was set before calling this function, the name is empty, |
1195 | | * and this function returns 0. |
1196 | | * |
1197 | | * @see threading for concurrency implications. |
1198 | | */ |
1199 | | size_t tox_self_get_name_size(const Tox *tox); |
1200 | | |
1201 | | /** |
1202 | | * @brief Write the nickname set by tox_self_set_name to a byte array. |
1203 | | * |
1204 | | * If no nickname was set before calling this function, the name is empty, |
1205 | | * and this function has no effect. |
1206 | | * |
1207 | | * Call tox_self_get_name_size to find out how much memory to allocate for |
1208 | | * the result. |
1209 | | * |
1210 | | * @param name A valid memory location large enough to hold the nickname. |
1211 | | * If this parameter is NULL, the function has no effect. |
1212 | | */ |
1213 | | void tox_self_get_name(const Tox *tox, uint8_t name[]); |
1214 | | |
1215 | | /** |
1216 | | * @brief Set the client's status message. |
1217 | | * |
1218 | | * Status message length cannot exceed TOX_MAX_STATUS_MESSAGE_LENGTH. If |
1219 | | * length is 0, the status parameter is ignored (it can be NULL), and the |
1220 | | * user status is set back to empty. |
1221 | | */ |
1222 | | bool tox_self_set_status_message( |
1223 | | Tox *tox, const uint8_t status_message[], size_t length, Tox_Err_Set_Info *error); |
1224 | | |
1225 | | /** |
1226 | | * @brief Return the length of the current status message as passed to tox_self_set_status_message. |
1227 | | * |
1228 | | * If no status message was set before calling this function, the status |
1229 | | * is empty, and this function returns 0. |
1230 | | * |
1231 | | * @see threading for concurrency implications. |
1232 | | */ |
1233 | | size_t tox_self_get_status_message_size(const Tox *tox); |
1234 | | |
1235 | | /** |
1236 | | * @brief Write the status message set by tox_self_set_status_message to a byte array. |
1237 | | * |
1238 | | * If no status message was set before calling this function, the status is |
1239 | | * empty, and this function has no effect. |
1240 | | * |
1241 | | * Call tox_self_get_status_message_size to find out how much memory to allocate for |
1242 | | * the result. |
1243 | | * |
1244 | | * @param status_message A valid memory location large enough to hold the |
1245 | | * status message. If this parameter is NULL, the function has no effect. |
1246 | | */ |
1247 | | void tox_self_get_status_message(const Tox *tox, uint8_t status_message[]); |
1248 | | |
1249 | | /** |
1250 | | * @brief Set the client's user status. |
1251 | | * |
1252 | | * @param status One of the user statuses listed in the enumeration above. |
1253 | | */ |
1254 | | void tox_self_set_status(Tox *tox, Tox_User_Status status); |
1255 | | |
1256 | | /** |
1257 | | * @brief Returns the client's user status. |
1258 | | */ |
1259 | | Tox_User_Status tox_self_get_status(const Tox *tox); |
1260 | | |
1261 | | /** @} */ |
1262 | | |
1263 | | |
1264 | | /** @{ |
1265 | | * @name Friend list management |
1266 | | */ |
1267 | | |
1268 | | typedef uint32_t Tox_Friend_Number; |
1269 | | |
1270 | | typedef enum Tox_Err_Friend_Add { |
1271 | | |
1272 | | /** |
1273 | | * The function returned successfully. |
1274 | | */ |
1275 | | TOX_ERR_FRIEND_ADD_OK, |
1276 | | |
1277 | | /** |
1278 | | * One of the arguments to the function was NULL when it was not expected. |
1279 | | */ |
1280 | | TOX_ERR_FRIEND_ADD_NULL, |
1281 | | |
1282 | | /** |
1283 | | * The length of the friend request message exceeded |
1284 | | * TOX_MAX_FRIEND_REQUEST_LENGTH. |
1285 | | */ |
1286 | | TOX_ERR_FRIEND_ADD_TOO_LONG, |
1287 | | |
1288 | | /** |
1289 | | * The friend request message was empty. This, and the TOO_LONG code will |
1290 | | * never be returned from tox_friend_add_norequest. |
1291 | | */ |
1292 | | TOX_ERR_FRIEND_ADD_NO_MESSAGE, |
1293 | | |
1294 | | /** |
1295 | | * The friend address belongs to the sending client. |
1296 | | */ |
1297 | | TOX_ERR_FRIEND_ADD_OWN_KEY, |
1298 | | |
1299 | | /** |
1300 | | * A friend request has already been sent, or the address belongs to a friend |
1301 | | * that is already on the friend list. |
1302 | | */ |
1303 | | TOX_ERR_FRIEND_ADD_ALREADY_SENT, |
1304 | | |
1305 | | /** |
1306 | | * The friend address checksum failed. |
1307 | | */ |
1308 | | TOX_ERR_FRIEND_ADD_BAD_CHECKSUM, |
1309 | | |
1310 | | /** |
1311 | | * The friend was already there, but the nospam value was different. |
1312 | | */ |
1313 | | TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM, |
1314 | | |
1315 | | /** |
1316 | | * A memory allocation failed when trying to increase the friend list size. |
1317 | | */ |
1318 | | TOX_ERR_FRIEND_ADD_MALLOC, |
1319 | | |
1320 | | } Tox_Err_Friend_Add; |
1321 | | |
1322 | | const char *tox_err_friend_add_to_string(Tox_Err_Friend_Add value); |
1323 | | |
1324 | | |
1325 | | /** |
1326 | | * @brief Add a friend to the friend list and send a friend request. |
1327 | | * |
1328 | | * A friend request message must be at least 1 byte long and at most |
1329 | | * TOX_MAX_FRIEND_REQUEST_LENGTH. |
1330 | | * |
1331 | | * Friend numbers are unique identifiers used in all functions that operate on |
1332 | | * friends. Once added, a friend number is stable for the lifetime of the Tox |
1333 | | * object. After saving the state and reloading it, the friend numbers may not |
1334 | | * be the same as before. Deleting a friend creates a gap in the friend number |
1335 | | * set, which is filled by the next adding of a friend. Any pattern in friend |
1336 | | * numbers should not be relied on. |
1337 | | * |
1338 | | * If more than INT32_MAX friends are added, this function causes undefined |
1339 | | * behaviour. |
1340 | | * |
1341 | | * @param address The address of the friend (returned by tox_self_get_address of |
1342 | | * the friend you wish to add) it must be TOX_ADDRESS_SIZE bytes. |
1343 | | * @param message The message that will be sent along with the friend request. |
1344 | | * @param length The length of the data byte array. |
1345 | | * |
1346 | | * @return the friend number on success, an unspecified value on failure. |
1347 | | */ |
1348 | | Tox_Friend_Number tox_friend_add( |
1349 | | Tox *tox, const uint8_t address[TOX_ADDRESS_SIZE], |
1350 | | const uint8_t message[], size_t length, |
1351 | | Tox_Err_Friend_Add *error); |
1352 | | |
1353 | | /** |
1354 | | * @brief Add a friend without sending a friend request. |
1355 | | * |
1356 | | * This function is used to add a friend in response to a friend request. If the |
1357 | | * client receives a friend request, it can be reasonably sure that the other |
1358 | | * client added this client as a friend, eliminating the need for a friend |
1359 | | * request. |
1360 | | * |
1361 | | * This function is also useful in a situation where both instances are |
1362 | | * controlled by the same entity, so that this entity can perform the mutual |
1363 | | * friend adding. In this case, there is no need for a friend request, either. |
1364 | | * |
1365 | | * @param public_key A byte array of length TOX_PUBLIC_KEY_SIZE containing the |
1366 | | * Public Key (not the Address) of the friend to add. |
1367 | | * |
1368 | | * @return the friend number on success, an unspecified value on failure. |
1369 | | * @see tox_friend_add for a more detailed description of friend numbers. |
1370 | | */ |
1371 | | Tox_Friend_Number tox_friend_add_norequest( |
1372 | | Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_Add *error); |
1373 | | |
1374 | | typedef enum Tox_Err_Friend_Delete { |
1375 | | |
1376 | | /** |
1377 | | * The function returned successfully. |
1378 | | */ |
1379 | | TOX_ERR_FRIEND_DELETE_OK, |
1380 | | |
1381 | | /** |
1382 | | * There was no friend with the given friend number. No friends were deleted. |
1383 | | */ |
1384 | | TOX_ERR_FRIEND_DELETE_FRIEND_NOT_FOUND, |
1385 | | |
1386 | | } Tox_Err_Friend_Delete; |
1387 | | |
1388 | | const char *tox_err_friend_delete_to_string(Tox_Err_Friend_Delete value); |
1389 | | |
1390 | | |
1391 | | /** |
1392 | | * @brief Remove a friend from the friend list. |
1393 | | * |
1394 | | * This does not notify the friend of their deletion. After calling this |
1395 | | * function, this client will appear offline to the friend and no communication |
1396 | | * can occur between the two. |
1397 | | * |
1398 | | * @param friend_number Friend number for the friend to be deleted. |
1399 | | * |
1400 | | * @return true on success. |
1401 | | */ |
1402 | | bool tox_friend_delete(Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Delete *error); |
1403 | | |
1404 | | /** @} */ |
1405 | | |
1406 | | |
1407 | | /** @{ |
1408 | | * @name Friend list queries |
1409 | | */ |
1410 | | |
1411 | | typedef enum Tox_Err_Friend_By_Public_Key { |
1412 | | |
1413 | | /** |
1414 | | * The function returned successfully. |
1415 | | */ |
1416 | | TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK, |
1417 | | |
1418 | | /** |
1419 | | * One of the arguments to the function was NULL when it was not expected. |
1420 | | */ |
1421 | | TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL, |
1422 | | |
1423 | | /** |
1424 | | * No friend with the given Public Key exists on the friend list. |
1425 | | */ |
1426 | | TOX_ERR_FRIEND_BY_PUBLIC_KEY_NOT_FOUND, |
1427 | | |
1428 | | } Tox_Err_Friend_By_Public_Key; |
1429 | | |
1430 | | const char *tox_err_friend_by_public_key_to_string(Tox_Err_Friend_By_Public_Key value); |
1431 | | |
1432 | | |
1433 | | /** |
1434 | | * @brief Return the friend number associated with that Public Key. |
1435 | | * |
1436 | | * @return the friend number on success, an unspecified value on failure. |
1437 | | * @param public_key A byte array containing the Public Key. |
1438 | | */ |
1439 | | Tox_Friend_Number tox_friend_by_public_key(const Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_By_Public_Key *error); |
1440 | | |
1441 | | /** |
1442 | | * @brief Checks if a friend with the given friend number exists and returns true if |
1443 | | * it does. |
1444 | | */ |
1445 | | bool tox_friend_exists(const Tox *tox, Tox_Friend_Number friend_number); |
1446 | | |
1447 | | /** |
1448 | | * @brief Return the number of friends on the friend list. |
1449 | | * |
1450 | | * This function can be used to determine how much memory to allocate for |
1451 | | * tox_self_get_friend_list. |
1452 | | */ |
1453 | | size_t tox_self_get_friend_list_size(const Tox *tox); |
1454 | | |
1455 | | /** |
1456 | | * @brief Copy a list of valid friend numbers into an array. |
1457 | | * |
1458 | | * Call tox_self_get_friend_list_size to determine the number of elements to allocate. |
1459 | | * |
1460 | | * @param friend_list A memory region with enough space to hold the friend |
1461 | | * list. If this parameter is NULL, this function has no effect. |
1462 | | */ |
1463 | | void tox_self_get_friend_list(const Tox *tox, Tox_Friend_Number friend_list[]); |
1464 | | |
1465 | | typedef enum Tox_Err_Friend_Get_Public_Key { |
1466 | | |
1467 | | /** |
1468 | | * The function returned successfully. |
1469 | | */ |
1470 | | TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK, |
1471 | | |
1472 | | /** |
1473 | | * No friend with the given number exists on the friend list. |
1474 | | */ |
1475 | | TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND, |
1476 | | |
1477 | | } Tox_Err_Friend_Get_Public_Key; |
1478 | | |
1479 | | const char *tox_err_friend_get_public_key_to_string(Tox_Err_Friend_Get_Public_Key value); |
1480 | | |
1481 | | |
1482 | | /** |
1483 | | * @brief Copies the Public Key associated with a given friend number to a byte array. |
1484 | | * |
1485 | | * @param friend_number The friend number you want the Public Key of. |
1486 | | * @param public_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If |
1487 | | * this parameter is NULL, this function has no effect. |
1488 | | * |
1489 | | * @return true on success. |
1490 | | */ |
1491 | | bool tox_friend_get_public_key( |
1492 | | const Tox *tox, Tox_Friend_Number friend_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], |
1493 | | Tox_Err_Friend_Get_Public_Key *error); |
1494 | | |
1495 | | typedef enum Tox_Err_Friend_Get_Last_Online { |
1496 | | |
1497 | | /** |
1498 | | * The function returned successfully. |
1499 | | */ |
1500 | | TOX_ERR_FRIEND_GET_LAST_ONLINE_OK, |
1501 | | |
1502 | | /** |
1503 | | * No friend with the given number exists on the friend list. |
1504 | | */ |
1505 | | TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND, |
1506 | | |
1507 | | } Tox_Err_Friend_Get_Last_Online; |
1508 | | |
1509 | | const char *tox_err_friend_get_last_online_to_string(Tox_Err_Friend_Get_Last_Online value); |
1510 | | |
1511 | | |
1512 | | /** |
1513 | | * @brief Return a unix-time timestamp of the last time the friend associated with a given |
1514 | | * friend number was seen online. |
1515 | | * |
1516 | | * This function will return UINT64_MAX on error. |
1517 | | * |
1518 | | * @param friend_number The friend number you want to query. |
1519 | | */ |
1520 | | uint64_t tox_friend_get_last_online( |
1521 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Get_Last_Online *error); |
1522 | | |
1523 | | /** @} */ |
1524 | | |
1525 | | |
1526 | | /** @{ |
1527 | | * @name Friend-specific state queries (can also be received through callbacks) |
1528 | | */ |
1529 | | |
1530 | | /** |
1531 | | * @brief Common error codes for friend state query functions. |
1532 | | */ |
1533 | | typedef enum Tox_Err_Friend_Query { |
1534 | | |
1535 | | /** |
1536 | | * The function returned successfully. |
1537 | | */ |
1538 | | TOX_ERR_FRIEND_QUERY_OK, |
1539 | | |
1540 | | /** |
1541 | | * The pointer parameter for storing the query result (name, message) was |
1542 | | * NULL. Unlike the `_self_` variants of these functions, which have no effect |
1543 | | * when a parameter is NULL, these functions return an error in that case. |
1544 | | */ |
1545 | | TOX_ERR_FRIEND_QUERY_NULL, |
1546 | | |
1547 | | /** |
1548 | | * The friend_number did not designate a valid friend. |
1549 | | */ |
1550 | | TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND, |
1551 | | |
1552 | | } Tox_Err_Friend_Query; |
1553 | | |
1554 | | const char *tox_err_friend_query_to_string(Tox_Err_Friend_Query value); |
1555 | | |
1556 | | |
1557 | | /** |
1558 | | * @brief Return the length of the friend's name. |
1559 | | * |
1560 | | * If the friend number is invalid, the return value is unspecified. |
1561 | | * |
1562 | | * The return value is equal to the `length` argument received by the last |
1563 | | * `friend_name` callback. |
1564 | | */ |
1565 | | size_t tox_friend_get_name_size( |
1566 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); |
1567 | | |
1568 | | /** |
1569 | | * @brief Write the name of the friend designated by the given friend number to a byte |
1570 | | * array. |
1571 | | * |
1572 | | * Call tox_friend_get_name_size to determine the allocation size for the `name` |
1573 | | * parameter. |
1574 | | * |
1575 | | * The data written to `name` is equal to the data received by the last |
1576 | | * `friend_name` callback. |
1577 | | * |
1578 | | * @param name A valid memory region large enough to store the friend's name. |
1579 | | * |
1580 | | * @return true on success. |
1581 | | */ |
1582 | | bool tox_friend_get_name( |
1583 | | const Tox *tox, Tox_Friend_Number friend_number, uint8_t name[], Tox_Err_Friend_Query *error); |
1584 | | |
1585 | | /** |
1586 | | * @param friend_number The friend number of the friend whose name changed. |
1587 | | * @param name A byte array containing the same data as |
1588 | | * tox_friend_get_name would write to its `name` parameter. |
1589 | | * @param length A value equal to the return value of |
1590 | | * tox_friend_get_name_size. |
1591 | | */ |
1592 | | typedef void tox_friend_name_cb( |
1593 | | Tox *tox, Tox_Friend_Number friend_number, |
1594 | | const uint8_t name[], size_t length, void *user_data); |
1595 | | |
1596 | | |
1597 | | /** |
1598 | | * @brief Set the callback for the `friend_name` event. |
1599 | | * |
1600 | | * Pass NULL to unset. |
1601 | | * |
1602 | | * This event is triggered when a friend changes their name. |
1603 | | */ |
1604 | | void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback); |
1605 | | |
1606 | | /** |
1607 | | * @brief Return the length of the friend's status message. |
1608 | | * |
1609 | | * If the friend number isinvalid, the return value is SIZE_MAX. |
1610 | | */ |
1611 | | size_t tox_friend_get_status_message_size( |
1612 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); |
1613 | | |
1614 | | /** |
1615 | | * @brief Write the status message of the friend designated by the given friend number to a byte |
1616 | | * array. |
1617 | | * |
1618 | | * Call tox_friend_get_status_message_size to determine the allocation size for the `status_message` |
1619 | | * parameter. |
1620 | | * |
1621 | | * The data written to `status_message` is equal to the data received by the last |
1622 | | * `friend_status_message` callback. |
1623 | | * |
1624 | | * @param status_message A valid memory region large enough to store the friend's status message. |
1625 | | */ |
1626 | | bool tox_friend_get_status_message( |
1627 | | const Tox *tox, Tox_Friend_Number friend_number, uint8_t status_message[], |
1628 | | Tox_Err_Friend_Query *error); |
1629 | | |
1630 | | /** |
1631 | | * @param friend_number The friend number of the friend whose status message |
1632 | | * changed. |
1633 | | * @param message A byte array containing the same data as |
1634 | | * tox_friend_get_status_message would write to its `status_message` parameter. |
1635 | | * @param length A value equal to the return value of |
1636 | | * tox_friend_get_status_message_size. |
1637 | | */ |
1638 | | typedef void tox_friend_status_message_cb( |
1639 | | Tox *tox, Tox_Friend_Number friend_number, |
1640 | | const uint8_t message[], size_t length, void *user_data); |
1641 | | |
1642 | | |
1643 | | /** |
1644 | | * @brief Set the callback for the `friend_status_message` event. |
1645 | | * |
1646 | | * Pass NULL to unset. |
1647 | | * |
1648 | | * This event is triggered when a friend changes their status message. |
1649 | | */ |
1650 | | void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback); |
1651 | | |
1652 | | /** |
1653 | | * @brief Return the friend's user status (away/busy/...). |
1654 | | * |
1655 | | * If the friend number is invalid, the return value is unspecified. |
1656 | | * |
1657 | | * The status returned is equal to the last status received through the |
1658 | | * `friend_status` callback. |
1659 | | * |
1660 | | * @deprecated This getter is deprecated. Use the event and store the status |
1661 | | * in the client state. |
1662 | | */ |
1663 | | Tox_User_Status tox_friend_get_status( |
1664 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); |
1665 | | |
1666 | | /** |
1667 | | * @param friend_number The friend number of the friend whose user status |
1668 | | * changed. |
1669 | | * @param status The new user status. |
1670 | | */ |
1671 | | typedef void tox_friend_status_cb( |
1672 | | Tox *tox, Tox_Friend_Number friend_number, Tox_User_Status status, void *user_data); |
1673 | | |
1674 | | |
1675 | | /** |
1676 | | * @brief Set the callback for the `friend_status` event. |
1677 | | * |
1678 | | * Pass NULL to unset. |
1679 | | * |
1680 | | * This event is triggered when a friend changes their user status. |
1681 | | */ |
1682 | | void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback); |
1683 | | |
1684 | | /** |
1685 | | * @brief Check whether a friend is currently connected to this client. |
1686 | | * |
1687 | | * The result of this function is equal to the last value received by the |
1688 | | * `friend_connection_status` callback. |
1689 | | * |
1690 | | * @param friend_number The friend number for which to query the connection |
1691 | | * status. |
1692 | | * |
1693 | | * @return the friend's connection status as it was received through the |
1694 | | * `friend_connection_status` event. |
1695 | | * |
1696 | | * @deprecated This getter is deprecated. Use the event and store the status |
1697 | | * in the client state. |
1698 | | */ |
1699 | | Tox_Connection tox_friend_get_connection_status( |
1700 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); |
1701 | | |
1702 | | /** |
1703 | | * @param friend_number The friend number of the friend whose connection status |
1704 | | * changed. |
1705 | | * @param connection_status The result of calling |
1706 | | * tox_friend_get_connection_status on the passed friend_number. |
1707 | | */ |
1708 | | typedef void tox_friend_connection_status_cb( |
1709 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Connection connection_status, void *user_data); |
1710 | | |
1711 | | |
1712 | | /** |
1713 | | * @brief Set the callback for the `friend_connection_status` event. |
1714 | | * |
1715 | | * Pass NULL to unset. |
1716 | | * |
1717 | | * This event is triggered when a friend goes offline after having been online, |
1718 | | * or when a friend goes online. |
1719 | | * |
1720 | | * This callback is not called when adding friends. It is assumed that when |
1721 | | * adding friends, their connection status is initially offline. |
1722 | | */ |
1723 | | void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback); |
1724 | | |
1725 | | /** |
1726 | | * @brief Check whether a friend is currently typing a message. |
1727 | | * |
1728 | | * @param friend_number The friend number for which to query the typing status. |
1729 | | * |
1730 | | * @return true if the friend is typing. |
1731 | | * @return false if the friend is not typing, or the friend number was |
1732 | | * invalid. Inspect the error code to determine which case it is. |
1733 | | * |
1734 | | * @deprecated This getter is deprecated. Use the event and store the status |
1735 | | * in the client state. |
1736 | | */ |
1737 | | bool tox_friend_get_typing( |
1738 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Query *error); |
1739 | | |
1740 | | /** |
1741 | | * @param friend_number The friend number of the friend who started or stopped |
1742 | | * typing. |
1743 | | * @param typing The result of calling tox_friend_get_typing on the passed |
1744 | | * friend_number. |
1745 | | */ |
1746 | | typedef void tox_friend_typing_cb( |
1747 | | Tox *tox, Tox_Friend_Number friend_number, bool typing, void *user_data); |
1748 | | |
1749 | | |
1750 | | /** |
1751 | | * @brief Set the callback for the `friend_typing` event. |
1752 | | * |
1753 | | * Pass NULL to unset. |
1754 | | * |
1755 | | * This event is triggered when a friend starts or stops typing. |
1756 | | */ |
1757 | | void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback); |
1758 | | |
1759 | | /** @} */ |
1760 | | |
1761 | | |
1762 | | /** @{ |
1763 | | * @name Sending private messages |
1764 | | */ |
1765 | | |
1766 | | typedef enum Tox_Err_Set_Typing { |
1767 | | |
1768 | | /** |
1769 | | * The function returned successfully. |
1770 | | */ |
1771 | | TOX_ERR_SET_TYPING_OK, |
1772 | | |
1773 | | /** |
1774 | | * The friend number did not designate a valid friend. |
1775 | | */ |
1776 | | TOX_ERR_SET_TYPING_FRIEND_NOT_FOUND, |
1777 | | |
1778 | | } Tox_Err_Set_Typing; |
1779 | | |
1780 | | const char *tox_err_set_typing_to_string(Tox_Err_Set_Typing value); |
1781 | | |
1782 | | |
1783 | | /** |
1784 | | * @brief Set the client's typing status for a friend. |
1785 | | * |
1786 | | * The client is responsible for turning it on or off. |
1787 | | * |
1788 | | * @param friend_number The friend to which the client is typing a message. |
1789 | | * @param typing The typing status. True means the client is typing. |
1790 | | * |
1791 | | * @return true on success. |
1792 | | */ |
1793 | | bool tox_self_set_typing( |
1794 | | Tox *tox, Tox_Friend_Number friend_number, bool typing, Tox_Err_Set_Typing *error); |
1795 | | |
1796 | | typedef enum Tox_Err_Friend_Send_Message { |
1797 | | |
1798 | | /** |
1799 | | * The function returned successfully. |
1800 | | */ |
1801 | | TOX_ERR_FRIEND_SEND_MESSAGE_OK, |
1802 | | |
1803 | | /** |
1804 | | * One of the arguments to the function was NULL when it was not expected. |
1805 | | */ |
1806 | | TOX_ERR_FRIEND_SEND_MESSAGE_NULL, |
1807 | | |
1808 | | /** |
1809 | | * The friend number did not designate a valid friend. |
1810 | | */ |
1811 | | TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_FOUND, |
1812 | | |
1813 | | /** |
1814 | | * This client is currently not connected to the friend. |
1815 | | */ |
1816 | | TOX_ERR_FRIEND_SEND_MESSAGE_FRIEND_NOT_CONNECTED, |
1817 | | |
1818 | | /** |
1819 | | * An allocation error occurred while increasing the send queue size. |
1820 | | */ |
1821 | | TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ, |
1822 | | |
1823 | | /** |
1824 | | * Message length exceeded TOX_MAX_MESSAGE_LENGTH. |
1825 | | */ |
1826 | | TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, |
1827 | | |
1828 | | /** |
1829 | | * Attempted to send a zero-length message. |
1830 | | */ |
1831 | | TOX_ERR_FRIEND_SEND_MESSAGE_EMPTY, |
1832 | | |
1833 | | } Tox_Err_Friend_Send_Message; |
1834 | | |
1835 | | const char *tox_err_friend_send_message_to_string(Tox_Err_Friend_Send_Message value); |
1836 | | |
1837 | | typedef uint32_t Tox_Friend_Message_Id; |
1838 | | |
1839 | | /** |
1840 | | * @brief Send a text chat message to an online friend. |
1841 | | * |
1842 | | * This function creates a chat message packet and pushes it into the send |
1843 | | * queue. |
1844 | | * |
1845 | | * The message length may not exceed TOX_MAX_MESSAGE_LENGTH. Larger messages |
1846 | | * must be split by the client and sent as separate messages. Other clients can |
1847 | | * then reassemble the fragments. Messages may not be empty. |
1848 | | * |
1849 | | * The return value of this function is the message ID. If a read receipt is |
1850 | | * received, the triggered `friend_read_receipt` event will be passed this message ID. |
1851 | | * |
1852 | | * Message IDs are unique per friend. The first message ID is 0. Message IDs are |
1853 | | * incremented by 1 each time a message is sent. If UINT32_MAX messages were |
1854 | | * sent, the next message ID is 0. |
1855 | | * |
1856 | | * @param type Message type (normal, action, ...). |
1857 | | * @param friend_number The friend number of the friend to send the message to. |
1858 | | * @param message A non-NULL pointer to the first element of a byte array |
1859 | | * containing the message text. |
1860 | | * @param length Length of the message to be sent. |
1861 | | */ |
1862 | | Tox_Friend_Message_Id tox_friend_send_message( |
1863 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, |
1864 | | const uint8_t message[], size_t length, Tox_Err_Friend_Send_Message *error); |
1865 | | |
1866 | | /** |
1867 | | * @param friend_number The friend number of the friend who received the message. |
1868 | | * @param message_id The message ID as returned from tox_friend_send_message |
1869 | | * corresponding to the message sent. |
1870 | | */ |
1871 | | typedef void tox_friend_read_receipt_cb( |
1872 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Friend_Message_Id message_id, void *user_data); |
1873 | | |
1874 | | |
1875 | | /** |
1876 | | * @brief Set the callback for the `friend_read_receipt` event. |
1877 | | * |
1878 | | * Pass NULL to unset. |
1879 | | * |
1880 | | * This event is triggered when the friend receives the message sent with |
1881 | | * tox_friend_send_message with the corresponding message ID. |
1882 | | */ |
1883 | | void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback); |
1884 | | |
1885 | | /** @} */ |
1886 | | |
1887 | | |
1888 | | /** @{ |
1889 | | * @name Receiving private messages and friend requests |
1890 | | */ |
1891 | | |
1892 | | /** |
1893 | | * @param public_key The Public Key of the user who sent the friend request. |
1894 | | * @param message The message they sent along with the request. |
1895 | | * @param length The size of the message byte array. |
1896 | | */ |
1897 | | typedef void tox_friend_request_cb( |
1898 | | Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], |
1899 | | const uint8_t message[], size_t length, |
1900 | | void *user_data); |
1901 | | |
1902 | | |
1903 | | /** |
1904 | | * @brief Set the callback for the `friend_request` event. |
1905 | | * |
1906 | | * Pass NULL to unset. |
1907 | | * |
1908 | | * This event is triggered when a friend request is received. |
1909 | | */ |
1910 | | void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback); |
1911 | | |
1912 | | /** |
1913 | | * @param friend_number The friend number of the friend who sent the message. |
1914 | | * @param message The message data they sent. |
1915 | | * @param length The size of the message byte array. |
1916 | | */ |
1917 | | typedef void tox_friend_message_cb( |
1918 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Message_Type type, |
1919 | | const uint8_t message[], size_t length, void *user_data); |
1920 | | |
1921 | | |
1922 | | /** |
1923 | | * @brief Set the callback for the `friend_message` event. |
1924 | | * |
1925 | | * Pass NULL to unset. |
1926 | | * |
1927 | | * This event is triggered when a message from a friend is received. |
1928 | | */ |
1929 | | void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback); |
1930 | | |
1931 | | /** @} */ |
1932 | | |
1933 | | |
1934 | | /** @{ |
1935 | | * @name File transmission: common between sending and receiving |
1936 | | */ |
1937 | | |
1938 | | typedef uint32_t Tox_File_Number; |
1939 | | |
1940 | | /** |
1941 | | * @brief Generates a cryptographic hash of the given data. |
1942 | | * |
1943 | | * This function may be used by clients for any purpose, but is provided |
1944 | | * primarily for validating cached avatars. This use is highly recommended to |
1945 | | * avoid unnecessary avatar updates. |
1946 | | * |
1947 | | * If hash is NULL or data is NULL while length is not 0 the function returns false, |
1948 | | * otherwise it returns true. |
1949 | | * |
1950 | | * This function is a wrapper to events_alloc message-digest functions. |
1951 | | * |
1952 | | * @param hash A valid memory location the hash data. It must be at least |
1953 | | * TOX_HASH_LENGTH bytes in size. |
1954 | | * @param data Data to be hashed or NULL. |
1955 | | * @param length Size of the data array or 0. |
1956 | | * |
1957 | | * @return true if hash was not NULL. |
1958 | | */ |
1959 | | bool tox_hash(uint8_t hash[TOX_HASH_LENGTH], const uint8_t data[], size_t length); |
1960 | | |
1961 | | /** |
1962 | | * @brief A list of pre-defined file kinds. |
1963 | | * |
1964 | | * Toxcore itself does not behave differently for different file kinds. These |
1965 | | * are a hint to the client telling it what use the sender intended for the |
1966 | | * file. The `kind` parameter in the send function and recv callback are |
1967 | | * `uint32_t`, not Tox_File_Kind, because clients can invent their own file |
1968 | | * kind. Unknown file kinds should be treated as TOX_FILE_KIND_DATA. |
1969 | | */ |
1970 | | enum Tox_File_Kind { |
1971 | | |
1972 | | /** |
1973 | | * Arbitrary file data. Clients can choose to handle it based on the file name |
1974 | | * or magic or any other way they choose. |
1975 | | */ |
1976 | | TOX_FILE_KIND_DATA, |
1977 | | |
1978 | | /** |
1979 | | * Avatar file_id. This consists of tox_hash(image). |
1980 | | * Avatar data. This consists of the image data. |
1981 | | * |
1982 | | * Avatars can be sent at any time the client wishes. Generally, a client will |
1983 | | * send the avatar to a friend when that friend comes online, and to all |
1984 | | * friends when the avatar changed. A client can save some traffic by |
1985 | | * remembering which friend received the updated avatar already and only send |
1986 | | * it if the friend has an out of date avatar. |
1987 | | * |
1988 | | * Clients who receive avatar send requests can reject it (by sending |
1989 | | * TOX_FILE_CONTROL_CANCEL before any other controls), or accept it (by |
1990 | | * sending TOX_FILE_CONTROL_RESUME). The file_id of length TOX_HASH_LENGTH bytes |
1991 | | * (same length as TOX_FILE_ID_LENGTH) will contain the hash. A client can compare |
1992 | | * this hash with a saved hash and send TOX_FILE_CONTROL_CANCEL to terminate the avatar |
1993 | | * transfer if it matches. |
1994 | | * |
1995 | | * When file_size is set to 0 in the transfer request it means that the client |
1996 | | * has no avatar. |
1997 | | */ |
1998 | | TOX_FILE_KIND_AVATAR, |
1999 | | |
2000 | | }; |
2001 | | |
2002 | | |
2003 | | typedef enum Tox_File_Control { |
2004 | | |
2005 | | /** |
2006 | | * Sent by the receiving side to accept a file send request. Also sent after a |
2007 | | * TOX_FILE_CONTROL_PAUSE command to continue sending or receiving. |
2008 | | */ |
2009 | | TOX_FILE_CONTROL_RESUME, |
2010 | | |
2011 | | /** |
2012 | | * Sent by clients to pause the file transfer. The initial state of a file |
2013 | | * transfer is always paused on the receiving side and running on the sending |
2014 | | * side. If both the sending and receiving side pause the transfer, then both |
2015 | | * need to send TOX_FILE_CONTROL_RESUME for the transfer to resume. |
2016 | | */ |
2017 | | TOX_FILE_CONTROL_PAUSE, |
2018 | | |
2019 | | /** |
2020 | | * Sent by the receiving side to reject a file send request before any other |
2021 | | * commands are sent. Also sent by either side to terminate a file transfer. |
2022 | | */ |
2023 | | TOX_FILE_CONTROL_CANCEL, |
2024 | | |
2025 | | } Tox_File_Control; |
2026 | | |
2027 | | const char *tox_file_control_to_string(Tox_File_Control value); |
2028 | | |
2029 | | |
2030 | | typedef enum Tox_Err_File_Control { |
2031 | | |
2032 | | /** |
2033 | | * The function returned successfully. |
2034 | | */ |
2035 | | TOX_ERR_FILE_CONTROL_OK, |
2036 | | |
2037 | | /** |
2038 | | * The friend_number passed did not designate a valid friend. |
2039 | | */ |
2040 | | TOX_ERR_FILE_CONTROL_FRIEND_NOT_FOUND, |
2041 | | |
2042 | | /** |
2043 | | * This client is currently not connected to the friend. |
2044 | | */ |
2045 | | TOX_ERR_FILE_CONTROL_FRIEND_NOT_CONNECTED, |
2046 | | |
2047 | | /** |
2048 | | * No file transfer with the given file number was found for the given friend. |
2049 | | */ |
2050 | | TOX_ERR_FILE_CONTROL_NOT_FOUND, |
2051 | | |
2052 | | /** |
2053 | | * A RESUME control was sent, but the file transfer is running normally. |
2054 | | */ |
2055 | | TOX_ERR_FILE_CONTROL_NOT_PAUSED, |
2056 | | |
2057 | | /** |
2058 | | * A RESUME control was sent, but the file transfer was paused by the other |
2059 | | * party. Only the party that paused the transfer can resume it. |
2060 | | */ |
2061 | | TOX_ERR_FILE_CONTROL_DENIED, |
2062 | | |
2063 | | /** |
2064 | | * A PAUSE control was sent, but the file transfer was already paused. |
2065 | | */ |
2066 | | TOX_ERR_FILE_CONTROL_ALREADY_PAUSED, |
2067 | | |
2068 | | /** |
2069 | | * Packet queue is full. |
2070 | | */ |
2071 | | TOX_ERR_FILE_CONTROL_SENDQ, |
2072 | | |
2073 | | } Tox_Err_File_Control; |
2074 | | |
2075 | | const char *tox_err_file_control_to_string(Tox_Err_File_Control value); |
2076 | | |
2077 | | |
2078 | | /** |
2079 | | * @brief Sends a file control command to a friend for a given file transfer. |
2080 | | * |
2081 | | * @param friend_number The friend number of the friend the file is being |
2082 | | * transferred to or received from. |
2083 | | * @param file_number The friend-specific identifier for the file transfer. |
2084 | | * @param control The control command to send. |
2085 | | * |
2086 | | * @return true on success. |
2087 | | */ |
2088 | | bool tox_file_control( |
2089 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, |
2090 | | Tox_Err_File_Control *error); |
2091 | | |
2092 | | /** |
2093 | | * @brief When receiving TOX_FILE_CONTROL_CANCEL, the client should release the |
2094 | | * resources associated with the file number and consider the transfer failed. |
2095 | | * |
2096 | | * @param friend_number The friend number of the friend who is sending the file. |
2097 | | * @param file_number The friend-specific file number the data received is |
2098 | | * associated with. |
2099 | | * @param control The file control command received. |
2100 | | */ |
2101 | | typedef void tox_file_recv_control_cb( |
2102 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, Tox_File_Control control, |
2103 | | void *user_data); |
2104 | | |
2105 | | |
2106 | | /** |
2107 | | * @brief Set the callback for the `file_recv_control` event. |
2108 | | * |
2109 | | * Pass NULL to unset. |
2110 | | * |
2111 | | * This event is triggered when a file control command is received from a |
2112 | | * friend. |
2113 | | */ |
2114 | | void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback); |
2115 | | |
2116 | | typedef enum Tox_Err_File_Seek { |
2117 | | |
2118 | | /** |
2119 | | * The function returned successfully. |
2120 | | */ |
2121 | | TOX_ERR_FILE_SEEK_OK, |
2122 | | |
2123 | | /** |
2124 | | * The friend_number passed did not designate a valid friend. |
2125 | | */ |
2126 | | TOX_ERR_FILE_SEEK_FRIEND_NOT_FOUND, |
2127 | | |
2128 | | /** |
2129 | | * This client is currently not connected to the friend. |
2130 | | */ |
2131 | | TOX_ERR_FILE_SEEK_FRIEND_NOT_CONNECTED, |
2132 | | |
2133 | | /** |
2134 | | * No file transfer with the given file number was found for the given friend. |
2135 | | */ |
2136 | | TOX_ERR_FILE_SEEK_NOT_FOUND, |
2137 | | |
2138 | | /** |
2139 | | * File was not in a state where it could be seeked. |
2140 | | */ |
2141 | | TOX_ERR_FILE_SEEK_DENIED, |
2142 | | |
2143 | | /** |
2144 | | * Seek position was invalid |
2145 | | */ |
2146 | | TOX_ERR_FILE_SEEK_INVALID_POSITION, |
2147 | | |
2148 | | /** |
2149 | | * Packet queue is full. |
2150 | | */ |
2151 | | TOX_ERR_FILE_SEEK_SENDQ, |
2152 | | |
2153 | | } Tox_Err_File_Seek; |
2154 | | |
2155 | | const char *tox_err_file_seek_to_string(Tox_Err_File_Seek value); |
2156 | | |
2157 | | |
2158 | | /** |
2159 | | * @brief Sends a file seek control command to a friend for a given file transfer. |
2160 | | * |
2161 | | * This function can only be called to resume a file transfer right before |
2162 | | * TOX_FILE_CONTROL_RESUME is sent. |
2163 | | * |
2164 | | * @param friend_number The friend number of the friend the file is being |
2165 | | * received from. |
2166 | | * @param file_number The friend-specific identifier for the file transfer. |
2167 | | * @param position The position that the file should be seeked to. |
2168 | | */ |
2169 | | bool tox_file_seek( |
2170 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, Tox_Err_File_Seek *error); |
2171 | | |
2172 | | typedef enum Tox_Err_File_Get { |
2173 | | |
2174 | | /** |
2175 | | * The function returned successfully. |
2176 | | */ |
2177 | | TOX_ERR_FILE_GET_OK, |
2178 | | |
2179 | | /** |
2180 | | * One of the arguments to the function was NULL when it was not expected. |
2181 | | */ |
2182 | | TOX_ERR_FILE_GET_NULL, |
2183 | | |
2184 | | /** |
2185 | | * The friend_number passed did not designate a valid friend. |
2186 | | */ |
2187 | | TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, |
2188 | | |
2189 | | /** |
2190 | | * No file transfer with the given file number was found for the given friend. |
2191 | | */ |
2192 | | TOX_ERR_FILE_GET_NOT_FOUND, |
2193 | | |
2194 | | } Tox_Err_File_Get; |
2195 | | |
2196 | | const char *tox_err_file_get_to_string(Tox_Err_File_Get value); |
2197 | | |
2198 | | |
2199 | | /** |
2200 | | * @brief Copy the file id associated to the file transfer to a byte array. |
2201 | | * |
2202 | | * @param friend_number The friend number of the friend the file is being |
2203 | | * transferred to or received from. |
2204 | | * @param file_number The friend-specific identifier for the file transfer. |
2205 | | * @param file_id A memory region of at least TOX_FILE_ID_LENGTH bytes. If |
2206 | | * this parameter is NULL, this function has no effect. |
2207 | | * |
2208 | | * @return true on success. |
2209 | | */ |
2210 | | bool tox_file_get_file_id( |
2211 | | const Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, |
2212 | | uint8_t file_id[TOX_FILE_ID_LENGTH], |
2213 | | Tox_Err_File_Get *error); |
2214 | | |
2215 | | /** @} */ |
2216 | | |
2217 | | |
2218 | | /** @{ |
2219 | | * @name File transmission: sending |
2220 | | */ |
2221 | | |
2222 | | typedef enum Tox_Err_File_Send { |
2223 | | |
2224 | | /** |
2225 | | * The function returned successfully. |
2226 | | */ |
2227 | | TOX_ERR_FILE_SEND_OK, |
2228 | | |
2229 | | /** |
2230 | | * One of the arguments to the function was NULL when it was not expected. |
2231 | | */ |
2232 | | TOX_ERR_FILE_SEND_NULL, |
2233 | | |
2234 | | /** |
2235 | | * The friend_number passed did not designate a valid friend. |
2236 | | */ |
2237 | | TOX_ERR_FILE_SEND_FRIEND_NOT_FOUND, |
2238 | | |
2239 | | /** |
2240 | | * This client is currently not connected to the friend. |
2241 | | */ |
2242 | | TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED, |
2243 | | |
2244 | | /** |
2245 | | * Filename length exceeded TOX_MAX_FILENAME_LENGTH bytes. |
2246 | | */ |
2247 | | TOX_ERR_FILE_SEND_NAME_TOO_LONG, |
2248 | | |
2249 | | /** |
2250 | | * Too many ongoing transfers. The maximum number of concurrent file transfers |
2251 | | * is 256 per friend per direction (sending and receiving). |
2252 | | */ |
2253 | | TOX_ERR_FILE_SEND_TOO_MANY, |
2254 | | |
2255 | | } Tox_Err_File_Send; |
2256 | | |
2257 | | const char *tox_err_file_send_to_string(Tox_Err_File_Send value); |
2258 | | |
2259 | | |
2260 | | /** |
2261 | | * @brief Send a file transmission request. |
2262 | | * |
2263 | | * Maximum filename length is TOX_MAX_FILENAME_LENGTH bytes. The filename |
2264 | | * should generally just be a file name, not a path with directory names. |
2265 | | * |
2266 | | * If a non-UINT64_MAX file size is provided, it can be used by both sides to |
2267 | | * determine the sending progress. File size can be set to UINT64_MAX for |
2268 | | * streaming data of unknown size. |
2269 | | * |
2270 | | * File transmission occurs in chunks, which are requested through the |
2271 | | * `file_chunk_request` event. |
2272 | | * |
2273 | | * When a friend goes offline, all file transfers associated with the friend are |
2274 | | * purged from core. |
2275 | | * |
2276 | | * If the file contents change during a transfer, the behaviour is unspecified |
2277 | | * in general. What will actually happen depends on the mode in which the file |
2278 | | * was modified and how the client determines the file size. |
2279 | | * |
2280 | | * - If the file size was increased |
2281 | | * - and sending mode was streaming (file_size = UINT64_MAX), the behaviour |
2282 | | * will be as expected. |
2283 | | * - and sending mode was file (file_size != UINT64_MAX), the file_chunk_request |
2284 | | * callback will receive length = 0 when Core thinks the file transfer has |
2285 | | * finished. If the client remembers the file size as it was when sending the |
2286 | | * request, it will terminate the transfer normally. If the client re-reads the |
2287 | | * size, it will think the friend cancelled the transfer. |
2288 | | * - If the file size was decreased |
2289 | | * - and sending mode was streaming, the behaviour is as expected. |
2290 | | * - and sending mode was file, the callback will return 0 at the new |
2291 | | * (earlier) end-of-file, signalling to the friend that the transfer was |
2292 | | * cancelled. |
2293 | | * - If the file contents were modified |
2294 | | * - at a position before the current read, the two files (local and remote) |
2295 | | * will differ after the transfer terminates. |
2296 | | * - at a position after the current read, the file transfer will succeed as |
2297 | | * expected. |
2298 | | * - In either case, both sides will regard the transfer as complete and |
2299 | | * successful. |
2300 | | * |
2301 | | * @param friend_number The friend number of the friend the file send request |
2302 | | * should be sent to. |
2303 | | * @param kind The meaning of the file to be sent. |
2304 | | * @param file_size Size in bytes of the file the client wants to send, UINT64_MAX if |
2305 | | * unknown or streaming. |
2306 | | * @param file_id A file identifier of length TOX_FILE_ID_LENGTH that can be used to |
2307 | | * uniquely identify file transfers across core restarts. If NULL, a random one will |
2308 | | * be generated by core. It can then be obtained by using `tox_file_get_file_id()`. |
2309 | | * @param filename Name of the file. Does not need to be the actual name. This |
2310 | | * name will be sent along with the file send request. |
2311 | | * @param filename_length Size in bytes of the filename. |
2312 | | * |
2313 | | * @return A file number used as an identifier in subsequent callbacks. This |
2314 | | * number is per friend. File numbers are reused after a transfer terminates. |
2315 | | * On failure, this function returns an unspecified value. Any pattern in file numbers |
2316 | | * should not be relied on. |
2317 | | */ |
2318 | | Tox_File_Number tox_file_send( |
2319 | | Tox *tox, Tox_Friend_Number friend_number, uint32_t kind, uint64_t file_size, |
2320 | | const uint8_t file_id[TOX_FILE_ID_LENGTH], const uint8_t filename[], size_t filename_length, |
2321 | | Tox_Err_File_Send *error); |
2322 | | |
2323 | | typedef enum Tox_Err_File_Send_Chunk { |
2324 | | |
2325 | | /** |
2326 | | * The function returned successfully. |
2327 | | */ |
2328 | | TOX_ERR_FILE_SEND_CHUNK_OK, |
2329 | | |
2330 | | /** |
2331 | | * The length parameter was non-zero, but data was NULL. |
2332 | | */ |
2333 | | TOX_ERR_FILE_SEND_CHUNK_NULL, |
2334 | | |
2335 | | /** |
2336 | | * The friend_number passed did not designate a valid friend. |
2337 | | */ |
2338 | | TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_FOUND, |
2339 | | |
2340 | | /** |
2341 | | * This client is currently not connected to the friend. |
2342 | | */ |
2343 | | TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED, |
2344 | | |
2345 | | /** |
2346 | | * No file transfer with the given file number was found for the given friend. |
2347 | | */ |
2348 | | TOX_ERR_FILE_SEND_CHUNK_NOT_FOUND, |
2349 | | |
2350 | | /** |
2351 | | * File transfer was found but isn't in a transferring state: (paused, done, |
2352 | | * broken, etc...) (happens only when not called from the request chunk callback). |
2353 | | */ |
2354 | | TOX_ERR_FILE_SEND_CHUNK_NOT_TRANSFERRING, |
2355 | | |
2356 | | /** |
2357 | | * Attempted to send more or less data than requested. The requested data size is |
2358 | | * adjusted according to maximum transmission unit and the expected end of |
2359 | | * the file. Trying to send less or more than requested will return this error. |
2360 | | */ |
2361 | | TOX_ERR_FILE_SEND_CHUNK_INVALID_LENGTH, |
2362 | | |
2363 | | /** |
2364 | | * Packet queue is full. |
2365 | | */ |
2366 | | TOX_ERR_FILE_SEND_CHUNK_SENDQ, |
2367 | | |
2368 | | /** |
2369 | | * Position parameter was wrong. |
2370 | | */ |
2371 | | TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION, |
2372 | | |
2373 | | } Tox_Err_File_Send_Chunk; |
2374 | | |
2375 | | const char *tox_err_file_send_chunk_to_string(Tox_Err_File_Send_Chunk value); |
2376 | | |
2377 | | |
2378 | | /** |
2379 | | * @brief Send a chunk of file data to a friend. |
2380 | | * |
2381 | | * This function is called in response to the `file_chunk_request` callback. The |
2382 | | * length parameter should be equal to the one received though the callback. |
2383 | | * If it is zero, the transfer is assumed complete. For files with known size, |
2384 | | * Core will know that the transfer is complete after the last byte has been |
2385 | | * received, so it is not necessary (though not harmful) to send a zero-length |
2386 | | * chunk to terminate. For streams, core will know that the transfer is finished |
2387 | | * if a chunk with length less than the length requested in the callback is sent. |
2388 | | * |
2389 | | * @param friend_number The friend number of the receiving friend for this file. |
2390 | | * @param file_number The file transfer identifier returned by tox_file_send. |
2391 | | * @param position The file or stream position from which to continue reading. |
2392 | | * @return true on success. |
2393 | | */ |
2394 | | bool tox_file_send_chunk( |
2395 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, |
2396 | | const uint8_t data[], size_t length, Tox_Err_File_Send_Chunk *error); |
2397 | | |
2398 | | /** |
2399 | | * If the length parameter is 0, the file transfer is finished, and the client's |
2400 | | * resources associated with the file number should be released. After a call |
2401 | | * with zero length, the file number can be reused for future file transfers. |
2402 | | * |
2403 | | * If the requested position is not equal to the client's idea of the current |
2404 | | * file or stream position, it will need to seek. In case of read-once streams, |
2405 | | * the client should keep the last read chunk so that a seek back can be |
2406 | | * supported. A seek-back only ever needs to read from the last requested chunk. |
2407 | | * This happens when a chunk was requested, but the send failed. A seek-back |
2408 | | * request can occur an arbitrary number of times for any given chunk. |
2409 | | * |
2410 | | * In response to receiving this callback, the client should call the function |
2411 | | * `tox_file_send_chunk` with the requested chunk. If the number of bytes sent |
2412 | | * through that function is zero, the file transfer is assumed complete. A |
2413 | | * client must send the full length of data requested with this callback. |
2414 | | * |
2415 | | * @param friend_number The friend number of the receiving friend for this file. |
2416 | | * @param file_number The file transfer identifier returned by tox_file_send. |
2417 | | * @param position The file or stream position from which to continue reading. |
2418 | | * @param length The number of bytes requested for the current chunk. |
2419 | | */ |
2420 | | typedef void tox_file_chunk_request_cb( |
2421 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, |
2422 | | size_t length, void *user_data); |
2423 | | |
2424 | | |
2425 | | /** |
2426 | | * @brief Set the callback for the `file_chunk_request` event. |
2427 | | * |
2428 | | * Pass NULL to unset. |
2429 | | * |
2430 | | * This event is triggered when Core is ready to send more file data. |
2431 | | */ |
2432 | | void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback); |
2433 | | |
2434 | | /** @} */ |
2435 | | |
2436 | | |
2437 | | /** @{ |
2438 | | * @name File transmission: receiving |
2439 | | */ |
2440 | | |
2441 | | /** |
2442 | | * The client should acquire resources to be associated with the file transfer. |
2443 | | * Incoming file transfers start in the PAUSED state. After this callback |
2444 | | * returns, a transfer can be rejected by sending a TOX_FILE_CONTROL_CANCEL |
2445 | | * control command before any other control commands. It can be accepted by |
2446 | | * sending TOX_FILE_CONTROL_RESUME. |
2447 | | * |
2448 | | * @param friend_number The friend number of the friend who is sending the file |
2449 | | * transfer request. |
2450 | | * @param file_number The friend-specific file number the data received is |
2451 | | * associated with. |
2452 | | * @param kind The meaning of the file that was sent. |
2453 | | * @param file_size Size in bytes of the file the client wants to send, |
2454 | | * UINT64_MAX if unknown or streaming. |
2455 | | * @param filename Name of the file. Does not need to be the actual name. This |
2456 | | * name will be sent along with the file send request. |
2457 | | * @param filename_length Size in bytes of the filename. |
2458 | | */ |
2459 | | typedef void tox_file_recv_cb( |
2460 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint32_t kind, uint64_t file_size, |
2461 | | const uint8_t filename[], size_t filename_length, void *user_data); |
2462 | | |
2463 | | |
2464 | | /** |
2465 | | * @brief Set the callback for the `file_recv` event. |
2466 | | * |
2467 | | * Pass NULL to unset. |
2468 | | * |
2469 | | * This event is triggered when a file transfer request is received. |
2470 | | */ |
2471 | | void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback); |
2472 | | |
2473 | | /** |
2474 | | * When length is 0, the transfer is finished and the client should release the |
2475 | | * resources it acquired for the transfer. After a call with length = 0, the |
2476 | | * file number can be reused for new file transfers. |
2477 | | * |
2478 | | * If position is equal to file_size (received in the file_receive callback) |
2479 | | * when the transfer finishes, the file was received completely. Otherwise, if |
2480 | | * file_size was UINT64_MAX, streaming ended successfully when length is 0. |
2481 | | * |
2482 | | * @param friend_number The friend number of the friend who is sending the file. |
2483 | | * @param file_number The friend-specific file number the data received is |
2484 | | * associated with. |
2485 | | * @param position The file position of the first byte in data. |
2486 | | * @param data A byte array containing the received chunk. |
2487 | | * @param length The length of the received chunk. |
2488 | | */ |
2489 | | typedef void tox_file_recv_chunk_cb( |
2490 | | Tox *tox, Tox_Friend_Number friend_number, Tox_File_Number file_number, uint64_t position, |
2491 | | const uint8_t data[], size_t length, void *user_data); |
2492 | | |
2493 | | |
2494 | | /** |
2495 | | * @brief Set the callback for the `file_recv_chunk` event. |
2496 | | * |
2497 | | * Pass NULL to unset. |
2498 | | * |
2499 | | * This event is first triggered when a file transfer request is received, and |
2500 | | * subsequently when a chunk of file data for an accepted request was received. |
2501 | | */ |
2502 | | void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback); |
2503 | | |
2504 | | /** @} */ |
2505 | | |
2506 | | |
2507 | | /** @{ |
2508 | | * @name Conference management |
2509 | | */ |
2510 | | |
2511 | | typedef uint32_t Tox_Conference_Number; |
2512 | | typedef uint32_t Tox_Conference_Peer_Number; |
2513 | | |
2514 | | /** |
2515 | | * @brief Conference types for the conference_invite event. |
2516 | | */ |
2517 | | typedef enum Tox_Conference_Type { |
2518 | | |
2519 | | /** |
2520 | | * Text-only conferences that must be accepted with the tox_conference_join function. |
2521 | | */ |
2522 | | TOX_CONFERENCE_TYPE_TEXT, |
2523 | | |
2524 | | /** |
2525 | | * Video conference. The function to accept these is in toxav. |
2526 | | */ |
2527 | | TOX_CONFERENCE_TYPE_AV, |
2528 | | |
2529 | | } Tox_Conference_Type; |
2530 | | |
2531 | | const char *tox_conference_type_to_string(Tox_Conference_Type value); |
2532 | | |
2533 | | |
2534 | | /** |
2535 | | * The invitation will remain valid until the inviting friend goes offline |
2536 | | * or exits the conference. |
2537 | | * |
2538 | | * @param friend_number The friend who invited us. |
2539 | | * @param type The conference type (text only or audio/video). |
2540 | | * @param cookie A piece of data of variable length required to join the |
2541 | | * conference. |
2542 | | * @param length The length of the cookie. |
2543 | | */ |
2544 | | typedef void tox_conference_invite_cb( |
2545 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Type type, |
2546 | | const uint8_t cookie[], size_t length, void *user_data); |
2547 | | |
2548 | | |
2549 | | /** |
2550 | | * @brief Set the callback for the `conference_invite` event. |
2551 | | * |
2552 | | * Pass NULL to unset. |
2553 | | * |
2554 | | * This event is triggered when the client is invited to join a conference. |
2555 | | */ |
2556 | | void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback); |
2557 | | |
2558 | | /** |
2559 | | * @param conference_number The conference number of the conference to which we have connected. |
2560 | | */ |
2561 | | typedef void tox_conference_connected_cb(Tox *tox, Tox_Conference_Number conference_number, void *user_data); |
2562 | | |
2563 | | |
2564 | | /** |
2565 | | * @brief Set the callback for the `conference_connected` event. |
2566 | | * |
2567 | | * Pass NULL to unset. |
2568 | | * |
2569 | | * This event is triggered when the client successfully connects to a |
2570 | | * conference after joining it with the tox_conference_join function. |
2571 | | */ |
2572 | | void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback); |
2573 | | |
2574 | | /** |
2575 | | * @param conference_number The conference number of the conference the message |
2576 | | * is intended for. |
2577 | | * @param peer_number The ID of the peer who sent the message. |
2578 | | * @param type The type of message (normal, action, ...). |
2579 | | * @param message The message data. |
2580 | | * @param length The length of the message. |
2581 | | */ |
2582 | | typedef void tox_conference_message_cb( |
2583 | | Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2584 | | Tox_Message_Type type, const uint8_t message[], size_t length, void *user_data); |
2585 | | |
2586 | | |
2587 | | /** |
2588 | | * @brief Set the callback for the `conference_message` event. |
2589 | | * |
2590 | | * Pass NULL to unset. |
2591 | | * |
2592 | | * This event is triggered when the client receives a conference message. |
2593 | | */ |
2594 | | void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback); |
2595 | | |
2596 | | /** |
2597 | | * @param conference_number The conference number of the conference the title |
2598 | | * change is intended for. |
2599 | | * @param peer_number The ID of the peer who changed the title. |
2600 | | * @param title The title data. |
2601 | | * @param length The title length. |
2602 | | */ |
2603 | | typedef void tox_conference_title_cb( |
2604 | | Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2605 | | const uint8_t title[], size_t length, void *user_data); |
2606 | | |
2607 | | |
2608 | | /** |
2609 | | * @brief Set the callback for the `conference_title` event. |
2610 | | * |
2611 | | * Pass NULL to unset. |
2612 | | * |
2613 | | * This event is triggered when a peer changes the conference title. |
2614 | | * |
2615 | | * If peer_number == UINT32_MAX, then author is unknown (e.g. initial joining the conference). |
2616 | | */ |
2617 | | void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback); |
2618 | | |
2619 | | /** |
2620 | | * @param conference_number The conference number of the conference the |
2621 | | * peer is in. |
2622 | | * @param peer_number The ID of the peer who changed their nickname. |
2623 | | * @param name A byte array containing the new nickname. |
2624 | | * @param length The size of the name byte array. |
2625 | | */ |
2626 | | typedef void tox_conference_peer_name_cb( |
2627 | | Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2628 | | const uint8_t name[], size_t length, void *user_data); |
2629 | | |
2630 | | |
2631 | | /** |
2632 | | * @brief Set the callback for the `conference_peer_name` event. |
2633 | | * |
2634 | | * Pass NULL to unset. |
2635 | | * |
2636 | | * This event is triggered when a peer changes their name. |
2637 | | */ |
2638 | | void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback); |
2639 | | |
2640 | | /** |
2641 | | * @param conference_number The conference number of the conference the |
2642 | | * peer is in. |
2643 | | */ |
2644 | | typedef void tox_conference_peer_list_changed_cb(Tox *tox, Tox_Conference_Number conference_number, void *user_data); |
2645 | | |
2646 | | |
2647 | | /** |
2648 | | * @brief Set the callback for the `conference_peer_list_changed` event. |
2649 | | * |
2650 | | * Pass NULL to unset. |
2651 | | * |
2652 | | * This event is triggered when a peer joins or leaves the conference. |
2653 | | */ |
2654 | | void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback); |
2655 | | |
2656 | | typedef enum Tox_Err_Conference_New { |
2657 | | |
2658 | | /** |
2659 | | * The function returned successfully. |
2660 | | */ |
2661 | | TOX_ERR_CONFERENCE_NEW_OK, |
2662 | | |
2663 | | /** |
2664 | | * The conference instance failed to initialize. |
2665 | | */ |
2666 | | TOX_ERR_CONFERENCE_NEW_INIT, |
2667 | | |
2668 | | } Tox_Err_Conference_New; |
2669 | | |
2670 | | const char *tox_err_conference_new_to_string(Tox_Err_Conference_New value); |
2671 | | |
2672 | | |
2673 | | /** |
2674 | | * @brief Creates a new conference. |
2675 | | * |
2676 | | * This function creates and connects to a new text conference. |
2677 | | * |
2678 | | * @return |
2679 | | * - conference number on success |
2680 | | * - an unspecified value on failure |
2681 | | */ |
2682 | | Tox_Conference_Number tox_conference_new(Tox *tox, Tox_Err_Conference_New *error); |
2683 | | |
2684 | | typedef enum Tox_Err_Conference_Delete { |
2685 | | |
2686 | | /** |
2687 | | * The function returned successfully. |
2688 | | */ |
2689 | | TOX_ERR_CONFERENCE_DELETE_OK, |
2690 | | |
2691 | | /** |
2692 | | * The conference number passed did not designate a valid conference. |
2693 | | */ |
2694 | | TOX_ERR_CONFERENCE_DELETE_CONFERENCE_NOT_FOUND, |
2695 | | |
2696 | | } Tox_Err_Conference_Delete; |
2697 | | |
2698 | | const char *tox_err_conference_delete_to_string(Tox_Err_Conference_Delete value); |
2699 | | |
2700 | | |
2701 | | /** |
2702 | | * @brief This function deletes a conference. |
2703 | | * |
2704 | | * @param conference_number The conference number of the conference to be deleted. |
2705 | | * |
2706 | | * @return true on success. |
2707 | | */ |
2708 | | bool tox_conference_delete(Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Delete *error); |
2709 | | |
2710 | | /** |
2711 | | * @brief Error codes for peer info queries. |
2712 | | */ |
2713 | | typedef enum Tox_Err_Conference_Peer_Query { |
2714 | | |
2715 | | /** |
2716 | | * The function returned successfully. |
2717 | | */ |
2718 | | TOX_ERR_CONFERENCE_PEER_QUERY_OK, |
2719 | | |
2720 | | /** |
2721 | | * The conference number passed did not designate a valid conference. |
2722 | | */ |
2723 | | TOX_ERR_CONFERENCE_PEER_QUERY_CONFERENCE_NOT_FOUND, |
2724 | | |
2725 | | /** |
2726 | | * The peer number passed did not designate a valid peer. |
2727 | | */ |
2728 | | TOX_ERR_CONFERENCE_PEER_QUERY_PEER_NOT_FOUND, |
2729 | | |
2730 | | /** |
2731 | | * The client is not connected to the conference. |
2732 | | */ |
2733 | | TOX_ERR_CONFERENCE_PEER_QUERY_NO_CONNECTION, |
2734 | | |
2735 | | } Tox_Err_Conference_Peer_Query; |
2736 | | |
2737 | | const char *tox_err_conference_peer_query_to_string(Tox_Err_Conference_Peer_Query value); |
2738 | | |
2739 | | |
2740 | | /** |
2741 | | * @brief Return the number of online peers in the conference. |
2742 | | * |
2743 | | * The unsigned integers less than this number are the valid values of |
2744 | | * peer_number for the functions querying these peers. Return value is |
2745 | | * unspecified on failure. |
2746 | | */ |
2747 | | Tox_Conference_Peer_Number tox_conference_peer_count( |
2748 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Peer_Query *error); |
2749 | | |
2750 | | /** |
2751 | | * @brief Return the length of the peer's name. |
2752 | | * |
2753 | | * Return value is unspecified on failure. |
2754 | | */ |
2755 | | size_t tox_conference_peer_get_name_size( |
2756 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2757 | | Tox_Err_Conference_Peer_Query *error); |
2758 | | |
2759 | | /** |
2760 | | * @brief Copy the name of peer_number who is in conference_number to name. |
2761 | | * |
2762 | | * Call tox_conference_peer_get_name_size to determine the allocation size for the `name` parameter. |
2763 | | * |
2764 | | * @param name A valid memory region large enough to store the peer's name. |
2765 | | * |
2766 | | * @return true on success. |
2767 | | */ |
2768 | | bool tox_conference_peer_get_name( |
2769 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2770 | | uint8_t name[], Tox_Err_Conference_Peer_Query *error); |
2771 | | |
2772 | | /** |
2773 | | * @brief Copy the public key of peer_number who is in conference_number to public_key. |
2774 | | * |
2775 | | * public_key must be TOX_PUBLIC_KEY_SIZE long. |
2776 | | * |
2777 | | * @return true on success. |
2778 | | */ |
2779 | | bool tox_conference_peer_get_public_key( |
2780 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2781 | | uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); |
2782 | | |
2783 | | /** |
2784 | | * @brief Return true if passed peer_number corresponds to our own. |
2785 | | */ |
2786 | | bool tox_conference_peer_number_is_ours( |
2787 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number peer_number, |
2788 | | Tox_Err_Conference_Peer_Query *error); |
2789 | | |
2790 | | /** |
2791 | | * @brief Return the number of offline peers in the conference. |
2792 | | * |
2793 | | * The unsigned integers less than this number are the valid values of |
2794 | | * offline_peer_number for the functions querying these peers. |
2795 | | * |
2796 | | * Return value is unspecified on failure. |
2797 | | */ |
2798 | | uint32_t tox_conference_offline_peer_count( |
2799 | | const Tox *tox, Tox_Conference_Number conference_number, |
2800 | | Tox_Err_Conference_Peer_Query *error); |
2801 | | |
2802 | | /** |
2803 | | * @brief Return the length of the offline peer's name. |
2804 | | * |
2805 | | * Return value is unspecified on failure. |
2806 | | */ |
2807 | | size_t tox_conference_offline_peer_get_name_size( |
2808 | | const Tox *tox, Tox_Conference_Number conference_number, |
2809 | | Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); |
2810 | | |
2811 | | /** |
2812 | | * @brief Copy the name of offline_peer_number who is in conference_number to name. |
2813 | | * |
2814 | | * Call tox_conference_offline_peer_get_name_size to determine the allocation |
2815 | | * size for the `name` parameter. |
2816 | | * |
2817 | | * @param name A valid memory region large enough to store the peer's name. |
2818 | | * |
2819 | | * @return true on success. |
2820 | | */ |
2821 | | bool tox_conference_offline_peer_get_name( |
2822 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Conference_Peer_Number offline_peer_number, |
2823 | | uint8_t name[], Tox_Err_Conference_Peer_Query *error); |
2824 | | |
2825 | | /** |
2826 | | * @brief Copy the public key of offline_peer_number who is in conference_number to public_key. |
2827 | | * |
2828 | | * public_key must be TOX_PUBLIC_KEY_SIZE long. |
2829 | | * |
2830 | | * @return true on success. |
2831 | | */ |
2832 | | bool tox_conference_offline_peer_get_public_key( |
2833 | | const Tox *tox, Tox_Conference_Number conference_number, |
2834 | | Tox_Conference_Peer_Number offline_peer_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error); |
2835 | | |
2836 | | /** |
2837 | | * @brief Return a unix-time timestamp of the last time offline_peer_number was seen to be active. |
2838 | | */ |
2839 | | uint64_t tox_conference_offline_peer_get_last_active( |
2840 | | const Tox *tox, Tox_Conference_Number conference_number, |
2841 | | Tox_Conference_Peer_Number offline_peer_number, Tox_Err_Conference_Peer_Query *error); |
2842 | | |
2843 | | typedef enum Tox_Err_Conference_Set_Max_Offline { |
2844 | | |
2845 | | /** |
2846 | | * The function returned successfully. |
2847 | | */ |
2848 | | TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK, |
2849 | | |
2850 | | /** |
2851 | | * The conference number passed did not designate a valid conference. |
2852 | | */ |
2853 | | TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_CONFERENCE_NOT_FOUND, |
2854 | | |
2855 | | } Tox_Err_Conference_Set_Max_Offline; |
2856 | | |
2857 | | const char *tox_err_conference_set_max_offline_to_string(Tox_Err_Conference_Set_Max_Offline value); |
2858 | | |
2859 | | |
2860 | | /** |
2861 | | * @brief Set maximum number of offline peers to store, overriding the default. |
2862 | | */ |
2863 | | bool tox_conference_set_max_offline( |
2864 | | Tox *tox, Tox_Conference_Number conference_number, uint32_t max_offline, |
2865 | | Tox_Err_Conference_Set_Max_Offline *error); |
2866 | | |
2867 | | typedef enum Tox_Err_Conference_Invite { |
2868 | | |
2869 | | /** |
2870 | | * The function returned successfully. |
2871 | | */ |
2872 | | TOX_ERR_CONFERENCE_INVITE_OK, |
2873 | | |
2874 | | /** |
2875 | | * The conference number passed did not designate a valid conference. |
2876 | | */ |
2877 | | TOX_ERR_CONFERENCE_INVITE_CONFERENCE_NOT_FOUND, |
2878 | | |
2879 | | /** |
2880 | | * The invite packet failed to send. |
2881 | | */ |
2882 | | TOX_ERR_CONFERENCE_INVITE_FAIL_SEND, |
2883 | | |
2884 | | /** |
2885 | | * The client is not connected to the conference. |
2886 | | */ |
2887 | | TOX_ERR_CONFERENCE_INVITE_NO_CONNECTION, |
2888 | | |
2889 | | } Tox_Err_Conference_Invite; |
2890 | | |
2891 | | const char *tox_err_conference_invite_to_string(Tox_Err_Conference_Invite value); |
2892 | | |
2893 | | |
2894 | | /** |
2895 | | * @brief Invites a friend to a conference. |
2896 | | * |
2897 | | * @param friend_number The friend number of the friend we want to invite. |
2898 | | * @param conference_number The conference number of the conference we want to invite the friend to. |
2899 | | * |
2900 | | * @return true on success. |
2901 | | */ |
2902 | | bool tox_conference_invite( |
2903 | | Tox *tox, Tox_Friend_Number friend_number, Tox_Conference_Number conference_number, |
2904 | | Tox_Err_Conference_Invite *error); |
2905 | | |
2906 | | typedef enum Tox_Err_Conference_Join { |
2907 | | |
2908 | | /** |
2909 | | * The function returned successfully. |
2910 | | */ |
2911 | | TOX_ERR_CONFERENCE_JOIN_OK, |
2912 | | |
2913 | | /** |
2914 | | * The cookie passed has an invalid length. |
2915 | | */ |
2916 | | TOX_ERR_CONFERENCE_JOIN_INVALID_LENGTH, |
2917 | | |
2918 | | /** |
2919 | | * The conference is not the expected type. This indicates an invalid cookie. |
2920 | | */ |
2921 | | TOX_ERR_CONFERENCE_JOIN_WRONG_TYPE, |
2922 | | |
2923 | | /** |
2924 | | * The friend number passed does not designate a valid friend. |
2925 | | */ |
2926 | | TOX_ERR_CONFERENCE_JOIN_FRIEND_NOT_FOUND, |
2927 | | |
2928 | | /** |
2929 | | * Client is already in this conference. |
2930 | | */ |
2931 | | TOX_ERR_CONFERENCE_JOIN_DUPLICATE, |
2932 | | |
2933 | | /** |
2934 | | * Conference instance failed to initialize. |
2935 | | */ |
2936 | | TOX_ERR_CONFERENCE_JOIN_INIT_FAIL, |
2937 | | |
2938 | | /** |
2939 | | * The join packet failed to send. |
2940 | | */ |
2941 | | TOX_ERR_CONFERENCE_JOIN_FAIL_SEND, |
2942 | | |
2943 | | } Tox_Err_Conference_Join; |
2944 | | |
2945 | | const char *tox_err_conference_join_to_string(Tox_Err_Conference_Join value); |
2946 | | |
2947 | | |
2948 | | /** |
2949 | | * @brief Joins a conference that the client has been invited to. |
2950 | | * |
2951 | | * After successfully joining the conference, the client will not be "connected" |
2952 | | * to it until a handshaking procedure has been completed. A |
2953 | | * `conference_connected` event will then occur for the conference. The client |
2954 | | * will then remain connected to the conference until the conference is deleted, |
2955 | | * even across core restarts. Many operations on a conference will fail with a |
2956 | | * corresponding error if attempted on a conference to which the client is not |
2957 | | * yet connected. |
2958 | | * |
2959 | | * @param friend_number The friend number of the friend who sent the invite. |
2960 | | * @param cookie Received via the `conference_invite` event. |
2961 | | * @param length The size of cookie. |
2962 | | * |
2963 | | * @return conference number on success, an unspecified value on failure. |
2964 | | */ |
2965 | | Tox_Conference_Number tox_conference_join( |
2966 | | Tox *tox, Tox_Friend_Number friend_number, |
2967 | | const uint8_t cookie[], size_t length, |
2968 | | Tox_Err_Conference_Join *error); |
2969 | | |
2970 | | typedef enum Tox_Err_Conference_Send_Message { |
2971 | | |
2972 | | /** |
2973 | | * The function returned successfully. |
2974 | | */ |
2975 | | TOX_ERR_CONFERENCE_SEND_MESSAGE_OK, |
2976 | | |
2977 | | /** |
2978 | | * The conference number passed did not designate a valid conference. |
2979 | | */ |
2980 | | TOX_ERR_CONFERENCE_SEND_MESSAGE_CONFERENCE_NOT_FOUND, |
2981 | | |
2982 | | /** |
2983 | | * The message is too long. |
2984 | | */ |
2985 | | TOX_ERR_CONFERENCE_SEND_MESSAGE_TOO_LONG, |
2986 | | |
2987 | | /** |
2988 | | * The client is not connected to the conference. |
2989 | | */ |
2990 | | TOX_ERR_CONFERENCE_SEND_MESSAGE_NO_CONNECTION, |
2991 | | |
2992 | | /** |
2993 | | * The message packet failed to send. |
2994 | | */ |
2995 | | TOX_ERR_CONFERENCE_SEND_MESSAGE_FAIL_SEND, |
2996 | | |
2997 | | } Tox_Err_Conference_Send_Message; |
2998 | | |
2999 | | const char *tox_err_conference_send_message_to_string(Tox_Err_Conference_Send_Message value); |
3000 | | |
3001 | | |
3002 | | /** |
3003 | | * @brief Send a text chat message to the conference. |
3004 | | * |
3005 | | * This function creates a conference message packet and pushes it into the send |
3006 | | * queue. |
3007 | | * |
3008 | | * The message length may not exceed TOX_MAX_MESSAGE_LENGTH. Larger messages |
3009 | | * must be split by the client and sent as separate messages. Other clients can |
3010 | | * then reassemble the fragments. |
3011 | | * |
3012 | | * @param conference_number The conference number of the conference the message |
3013 | | * is intended for. |
3014 | | * @param type Message type (normal, action, ...). |
3015 | | * @param message A non-NULL pointer to the first element of a byte array |
3016 | | * containing the message text. |
3017 | | * @param length Length of the message to be sent. |
3018 | | * |
3019 | | * @return true on success. |
3020 | | */ |
3021 | | bool tox_conference_send_message( |
3022 | | Tox *tox, Tox_Conference_Number conference_number, Tox_Message_Type type, |
3023 | | const uint8_t message[], size_t length, |
3024 | | Tox_Err_Conference_Send_Message *error); |
3025 | | |
3026 | | typedef enum Tox_Err_Conference_Title { |
3027 | | |
3028 | | /** |
3029 | | * The function returned successfully. |
3030 | | */ |
3031 | | TOX_ERR_CONFERENCE_TITLE_OK, |
3032 | | |
3033 | | /** |
3034 | | * The conference number passed did not designate a valid conference. |
3035 | | */ |
3036 | | TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND, |
3037 | | |
3038 | | /** |
3039 | | * The title is too long or empty. |
3040 | | */ |
3041 | | TOX_ERR_CONFERENCE_TITLE_INVALID_LENGTH, |
3042 | | |
3043 | | /** |
3044 | | * The title packet failed to send. |
3045 | | */ |
3046 | | TOX_ERR_CONFERENCE_TITLE_FAIL_SEND, |
3047 | | |
3048 | | } Tox_Err_Conference_Title; |
3049 | | |
3050 | | const char *tox_err_conference_title_to_string(Tox_Err_Conference_Title value); |
3051 | | |
3052 | | |
3053 | | /** |
3054 | | * @brief Return the length of the conference title. |
3055 | | * |
3056 | | * Return value is unspecified on failure. |
3057 | | * |
3058 | | * The return value is equal to the `length` argument received by the last |
3059 | | * `conference_title` callback. |
3060 | | */ |
3061 | | size_t tox_conference_get_title_size( |
3062 | | const Tox *tox, Tox_Conference_Number conference_number, Tox_Err_Conference_Title *error); |
3063 | | |
3064 | | /** |
3065 | | * @brief Write the title designated by the given conference number to a byte array. |
3066 | | * |
3067 | | * Call tox_conference_get_title_size to determine the allocation size for the `title` parameter. |
3068 | | * |
3069 | | * The data written to `title` is equal to the data received by the last |
3070 | | * `conference_title` callback. |
3071 | | * |
3072 | | * @param title A valid memory region large enough to store the title. |
3073 | | * If this parameter is NULL, this function has no effect. |
3074 | | * |
3075 | | * @return true on success. |
3076 | | */ |
3077 | | bool tox_conference_get_title( |
3078 | | const Tox *tox, Tox_Conference_Number conference_number, |
3079 | | uint8_t title[], |
3080 | | Tox_Err_Conference_Title *error); |
3081 | | |
3082 | | /** |
3083 | | * @brief Set the conference title and broadcast it to the rest of the conference. |
3084 | | * |
3085 | | * Title length cannot be longer than TOX_MAX_NAME_LENGTH. |
3086 | | * |
3087 | | * @return true on success. |
3088 | | */ |
3089 | | bool tox_conference_set_title( |
3090 | | Tox *tox, Tox_Conference_Number conference_number, |
3091 | | const uint8_t title[], size_t length, |
3092 | | Tox_Err_Conference_Title *error); |
3093 | | |
3094 | | /** |
3095 | | * @brief Return the number of conferences in the Tox instance. |
3096 | | * |
3097 | | * This should be used to determine how much memory to allocate for `tox_conference_get_chatlist`. |
3098 | | */ |
3099 | | size_t tox_conference_get_chatlist_size(const Tox *tox); |
3100 | | |
3101 | | /** |
3102 | | * @brief Copy a list of valid conference numbers into the array chatlist. |
3103 | | * |
3104 | | * Determine how much space to allocate for the array with the |
3105 | | * `tox_conference_get_chatlist_size` function. |
3106 | | * |
3107 | | * Note that `tox_get_savedata` saves all connected conferences; |
3108 | | * when toxcore is created from savedata in which conferences were saved, those |
3109 | | * conferences will be connected at startup, and will be listed by |
3110 | | * `tox_conference_get_chatlist`. |
3111 | | * |
3112 | | * The conference number of a loaded conference may differ from the conference |
3113 | | * number it had when it was saved. |
3114 | | */ |
3115 | | void tox_conference_get_chatlist(const Tox *tox, Tox_Conference_Number chatlist[]); |
3116 | | |
3117 | | /** |
3118 | | * @brief Returns the type of conference (Tox_Conference_Type) that conference_number is. |
3119 | | * |
3120 | | * Return value is unspecified on failure. |
3121 | | */ |
3122 | | typedef enum Tox_Err_Conference_Get_Type { |
3123 | | |
3124 | | /** |
3125 | | * The function returned successfully. |
3126 | | */ |
3127 | | TOX_ERR_CONFERENCE_GET_TYPE_OK, |
3128 | | |
3129 | | /** |
3130 | | * The conference number passed did not designate a valid conference. |
3131 | | */ |
3132 | | TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND, |
3133 | | |
3134 | | } Tox_Err_Conference_Get_Type; |
3135 | | |
3136 | | const char *tox_err_conference_get_type_to_string(Tox_Err_Conference_Get_Type value); |
3137 | | |
3138 | | |
3139 | | /** |
3140 | | * @brief Get the type (text or A/V) for the conference. |
3141 | | */ |
3142 | | Tox_Conference_Type tox_conference_get_type( |
3143 | | const Tox *tox, Tox_Conference_Number conference_number, |
3144 | | Tox_Err_Conference_Get_Type *error); |
3145 | | |
3146 | | /** |
3147 | | * @brief Get the conference unique ID. |
3148 | | * |
3149 | | * If id is NULL, this function has no effect. |
3150 | | * |
3151 | | * @param id A memory region large enough to store TOX_CONFERENCE_ID_SIZE bytes. |
3152 | | * |
3153 | | * @return true on success. |
3154 | | */ |
3155 | | bool tox_conference_get_id( |
3156 | | const Tox *tox, Tox_Conference_Number conference_number, uint8_t id[TOX_CONFERENCE_ID_SIZE]); |
3157 | | |
3158 | | typedef enum Tox_Err_Conference_By_Id { |
3159 | | |
3160 | | /** |
3161 | | * The function returned successfully. |
3162 | | */ |
3163 | | TOX_ERR_CONFERENCE_BY_ID_OK, |
3164 | | |
3165 | | /** |
3166 | | * One of the arguments to the function was NULL when it was not expected. |
3167 | | */ |
3168 | | TOX_ERR_CONFERENCE_BY_ID_NULL, |
3169 | | |
3170 | | /** |
3171 | | * No conference with the given id exists on the conference list. |
3172 | | */ |
3173 | | TOX_ERR_CONFERENCE_BY_ID_NOT_FOUND, |
3174 | | |
3175 | | } Tox_Err_Conference_By_Id; |
3176 | | |
3177 | | const char *tox_err_conference_by_id_to_string(Tox_Err_Conference_By_Id value); |
3178 | | |
3179 | | |
3180 | | /** |
3181 | | * @brief Return the conference number associated with the specified id. |
3182 | | * |
3183 | | * @param id A byte array containing the conference id (TOX_CONFERENCE_ID_SIZE). |
3184 | | * |
3185 | | * @return the conference number on success, an unspecified value on failure. |
3186 | | */ |
3187 | | Tox_Conference_Number tox_conference_by_id( |
3188 | | const Tox *tox, const uint8_t id[TOX_CONFERENCE_ID_SIZE], Tox_Err_Conference_By_Id *error); |
3189 | | |
3190 | | /** |
3191 | | * @brief Get the conference unique ID. |
3192 | | * |
3193 | | * If uid is NULL, this function has no effect. |
3194 | | * |
3195 | | * @param uid A memory region large enough to store TOX_CONFERENCE_UID_SIZE bytes. |
3196 | | * |
3197 | | * @return true on success. |
3198 | | * @deprecated use tox_conference_get_id instead (exactly the same function, just renamed). |
3199 | | */ |
3200 | | bool tox_conference_get_uid( |
3201 | | const Tox *tox, Tox_Conference_Number conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE]); |
3202 | | |
3203 | | typedef enum Tox_Err_Conference_By_Uid { |
3204 | | |
3205 | | /** |
3206 | | * The function returned successfully. |
3207 | | */ |
3208 | | TOX_ERR_CONFERENCE_BY_UID_OK, |
3209 | | |
3210 | | /** |
3211 | | * One of the arguments to the function was NULL when it was not expected. |
3212 | | */ |
3213 | | TOX_ERR_CONFERENCE_BY_UID_NULL, |
3214 | | |
3215 | | /** |
3216 | | * No conference with the given uid exists on the conference list. |
3217 | | */ |
3218 | | TOX_ERR_CONFERENCE_BY_UID_NOT_FOUND, |
3219 | | |
3220 | | } Tox_Err_Conference_By_Uid; |
3221 | | |
3222 | | const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value); |
3223 | | |
3224 | | |
3225 | | /** |
3226 | | * @brief Return the conference number associated with the specified uid. |
3227 | | * |
3228 | | * @param uid A byte array containing the conference id (TOX_CONFERENCE_UID_SIZE). |
3229 | | * |
3230 | | * @return the conference number on success, an unspecified value on failure. |
3231 | | * @deprecated use tox_conference_by_id instead (exactly the same function, just renamed). |
3232 | | */ |
3233 | | Tox_Conference_Number tox_conference_by_uid( |
3234 | | const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error); |
3235 | | |
3236 | | /** @} */ |
3237 | | |
3238 | | |
3239 | | /** @{ |
3240 | | * @name Low-level custom packet sending and receiving |
3241 | | */ |
3242 | | |
3243 | | typedef enum Tox_Err_Friend_Custom_Packet { |
3244 | | |
3245 | | /** |
3246 | | * The function returned successfully. |
3247 | | */ |
3248 | | TOX_ERR_FRIEND_CUSTOM_PACKET_OK, |
3249 | | |
3250 | | /** |
3251 | | * One of the arguments to the function was NULL when it was not expected. |
3252 | | */ |
3253 | | TOX_ERR_FRIEND_CUSTOM_PACKET_NULL, |
3254 | | |
3255 | | /** |
3256 | | * The friend number did not designate a valid friend. |
3257 | | */ |
3258 | | TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_FOUND, |
3259 | | |
3260 | | /** |
3261 | | * This client is currently not connected to the friend. |
3262 | | */ |
3263 | | TOX_ERR_FRIEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED, |
3264 | | |
3265 | | /** |
3266 | | * The first byte of data was not in the specified range for the packet type. |
3267 | | * This range is 192-254 for lossy, and 69, 160-191 for lossless packets. |
3268 | | */ |
3269 | | TOX_ERR_FRIEND_CUSTOM_PACKET_INVALID, |
3270 | | |
3271 | | /** |
3272 | | * Attempted to send an empty packet. |
3273 | | */ |
3274 | | TOX_ERR_FRIEND_CUSTOM_PACKET_EMPTY, |
3275 | | |
3276 | | /** |
3277 | | * Packet data length exceeded TOX_MAX_CUSTOM_PACKET_SIZE. |
3278 | | */ |
3279 | | TOX_ERR_FRIEND_CUSTOM_PACKET_TOO_LONG, |
3280 | | |
3281 | | /** |
3282 | | * Packet queue is full. |
3283 | | */ |
3284 | | TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ, |
3285 | | |
3286 | | } Tox_Err_Friend_Custom_Packet; |
3287 | | |
3288 | | const char *tox_err_friend_custom_packet_to_string(Tox_Err_Friend_Custom_Packet value); |
3289 | | |
3290 | | |
3291 | | /** |
3292 | | * @brief Send a custom lossy packet to a friend. |
3293 | | * |
3294 | | * The first byte of data must be in the range 192-254. Maximum length of a |
3295 | | * custom packet is TOX_MAX_CUSTOM_PACKET_SIZE. |
3296 | | * |
3297 | | * Lossy packets behave like UDP packets, meaning they might never reach the |
3298 | | * other side or might arrive more than once (if someone is messing with the |
3299 | | * connection) or might arrive in the wrong order. |
3300 | | * |
3301 | | * Unless latency is an issue, it is recommended that you use lossless custom |
3302 | | * packets instead. |
3303 | | * |
3304 | | * @param friend_number The friend number of the friend this lossy packet |
3305 | | * should be sent to. |
3306 | | * @param data A byte array containing the packet data. |
3307 | | * @param length The length of the packet data byte array. |
3308 | | * |
3309 | | * @return true on success. |
3310 | | */ |
3311 | | bool tox_friend_send_lossy_packet( |
3312 | | Tox *tox, Tox_Friend_Number friend_number, |
3313 | | const uint8_t data[], size_t length, |
3314 | | Tox_Err_Friend_Custom_Packet *error); |
3315 | | |
3316 | | /** |
3317 | | * @brief Send a custom lossless packet to a friend. |
3318 | | * |
3319 | | * The first byte of data must be in the range 69, 160-191. Maximum length of a |
3320 | | * custom packet is TOX_MAX_CUSTOM_PACKET_SIZE. |
3321 | | * |
3322 | | * Lossless packet behaviour is comparable to TCP (reliability, arrive in order) |
3323 | | * but with packets instead of a stream. |
3324 | | * |
3325 | | * @param friend_number The friend number of the friend this lossless packet |
3326 | | * should be sent to. |
3327 | | * @param data A byte array containing the packet data. |
3328 | | * @param length The length of the packet data byte array. |
3329 | | * |
3330 | | * @return true on success. |
3331 | | */ |
3332 | | bool tox_friend_send_lossless_packet( |
3333 | | Tox *tox, Tox_Friend_Number friend_number, |
3334 | | const uint8_t data[], size_t length, |
3335 | | Tox_Err_Friend_Custom_Packet *error); |
3336 | | |
3337 | | /** |
3338 | | * @param friend_number The friend number of the friend who sent a lossy packet. |
3339 | | * @param data A byte array containing the received packet data. |
3340 | | * @param length The length of the packet data byte array. |
3341 | | */ |
3342 | | typedef void tox_friend_lossy_packet_cb( |
3343 | | Tox *tox, Tox_Friend_Number friend_number, |
3344 | | const uint8_t data[], size_t length, |
3345 | | void *user_data); |
3346 | | |
3347 | | |
3348 | | /** |
3349 | | * @brief Set the callback for the `friend_lossy_packet` event. |
3350 | | * |
3351 | | * Pass NULL to unset. |
3352 | | */ |
3353 | | void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback); |
3354 | | |
3355 | | /** |
3356 | | * @param friend_number The friend number of the friend who sent the packet. |
3357 | | * @param data A byte array containing the received packet data. |
3358 | | * @param length The length of the packet data byte array. |
3359 | | */ |
3360 | | typedef void tox_friend_lossless_packet_cb( |
3361 | | Tox *tox, Tox_Friend_Number friend_number, |
3362 | | const uint8_t data[], size_t length, |
3363 | | void *user_data); |
3364 | | |
3365 | | |
3366 | | /** |
3367 | | * @brief Set the callback for the `friend_lossless_packet` event. |
3368 | | * |
3369 | | * Pass NULL to unset. |
3370 | | */ |
3371 | | void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback); |
3372 | | |
3373 | | /** @} */ |
3374 | | |
3375 | | |
3376 | | /** @{ |
3377 | | * @name Low-level network information |
3378 | | */ |
3379 | | |
3380 | | typedef enum Tox_Err_Get_Port { |
3381 | | |
3382 | | /** |
3383 | | * The function returned successfully. |
3384 | | */ |
3385 | | TOX_ERR_GET_PORT_OK, |
3386 | | |
3387 | | /** |
3388 | | * The instance was not bound to any port. |
3389 | | */ |
3390 | | TOX_ERR_GET_PORT_NOT_BOUND, |
3391 | | |
3392 | | } Tox_Err_Get_Port; |
3393 | | |
3394 | | const char *tox_err_get_port_to_string(Tox_Err_Get_Port value); |
3395 | | |
3396 | | |
3397 | | /** |
3398 | | * @brief Writes the temporary DHT public key of this instance to a byte array. |
3399 | | * |
3400 | | * This can be used in combination with an externally accessible IP address and |
3401 | | * the bound port (from tox_self_get_udp_port) to run a temporary bootstrap node. |
3402 | | * |
3403 | | * Be aware that every time a new instance is created, the DHT public key |
3404 | | * changes, meaning this cannot be used to run a permanent bootstrap node. |
3405 | | * |
3406 | | * @param dht_id A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If this |
3407 | | * parameter is NULL, this function has no effect. |
3408 | | */ |
3409 | | void tox_self_get_dht_id(const Tox *tox, uint8_t dht_id[TOX_PUBLIC_KEY_SIZE]); |
3410 | | |
3411 | | /** |
3412 | | * @brief Return the UDP port this Tox instance is bound to. |
3413 | | */ |
3414 | | uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error); |
3415 | | |
3416 | | /** |
3417 | | * @brief Return the TCP port this Tox instance is bound to. |
3418 | | * |
3419 | | * This is only relevant if the instance is acting as a TCP relay. |
3420 | | */ |
3421 | | uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error); |
3422 | | |
3423 | | /** @} */ |
3424 | | |
3425 | | /** @{ |
3426 | | * @name Group chats |
3427 | | */ |
3428 | | |
3429 | | typedef uint32_t Tox_Group_Number; |
3430 | | typedef uint32_t Tox_Group_Peer_Number; |
3431 | | typedef uint32_t Tox_Group_Message_Id; |
3432 | | |
3433 | | |
3434 | | |
3435 | | /******************************************************************************* |
3436 | | * |
3437 | | * :: Group chat numeric constants |
3438 | | * |
3439 | | ******************************************************************************/ |
3440 | | |
3441 | | |
3442 | | |
3443 | | /** |
3444 | | * Maximum length of a group topic. |
3445 | | */ |
3446 | 1 | #define TOX_GROUP_MAX_TOPIC_LENGTH 512 |
3447 | | |
3448 | | uint32_t tox_group_max_topic_length(void); |
3449 | | |
3450 | | /** |
3451 | | * Maximum length of a peer part message. |
3452 | | */ |
3453 | 1 | #define TOX_GROUP_MAX_PART_LENGTH 128 |
3454 | | |
3455 | | uint32_t tox_group_max_part_length(void); |
3456 | | |
3457 | | /** |
3458 | | * Maximum length of a group text message. |
3459 | | */ |
3460 | 603 | #define TOX_GROUP_MAX_MESSAGE_LENGTH 1372 |
3461 | | |
3462 | | uint32_t tox_group_max_message_length(void); |
3463 | | |
3464 | | /** |
3465 | | * Maximum length of a group custom lossy packet. |
3466 | | */ |
3467 | 1 | #define TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH 1373 |
3468 | | |
3469 | | uint32_t tox_group_max_custom_lossy_packet_length(void); |
3470 | | |
3471 | | /** |
3472 | | * Maximum length of a group custom lossless packet. |
3473 | | */ |
3474 | 1 | #define TOX_GROUP_MAX_CUSTOM_LOSSLESS_PACKET_LENGTH 1373 |
3475 | | |
3476 | | uint32_t tox_group_max_custom_lossless_packet_length(void); |
3477 | | |
3478 | | /** |
3479 | | * Maximum length of a group name. |
3480 | | */ |
3481 | 1 | #define TOX_GROUP_MAX_GROUP_NAME_LENGTH 48 |
3482 | | |
3483 | | uint32_t tox_group_max_group_name_length(void); |
3484 | | |
3485 | | /** |
3486 | | * Maximum length of a group password. |
3487 | | */ |
3488 | 1 | #define TOX_GROUP_MAX_PASSWORD_SIZE 32 |
3489 | | |
3490 | | uint32_t tox_group_max_password_size(void); |
3491 | | |
3492 | | /** |
3493 | | * Number of bytes in a group Chat ID. |
3494 | | */ |
3495 | 10 | #define TOX_GROUP_CHAT_ID_SIZE 32 |
3496 | | |
3497 | | uint32_t tox_group_chat_id_size(void); |
3498 | | |
3499 | | /** |
3500 | | * Size of a peer public key. |
3501 | | */ |
3502 | 10 | #define TOX_GROUP_PEER_PUBLIC_KEY_SIZE 32 |
3503 | | |
3504 | | uint32_t tox_group_peer_public_key_size(void); |
3505 | | |
3506 | | |
3507 | | /******************************************************************************* |
3508 | | * |
3509 | | * :: Group chat state enumerators |
3510 | | * |
3511 | | ******************************************************************************/ |
3512 | | |
3513 | | |
3514 | | |
3515 | | /** |
3516 | | * Represents the group privacy state. |
3517 | | */ |
3518 | | typedef enum Tox_Group_Privacy_State { |
3519 | | |
3520 | | /** |
3521 | | * The group is considered to be public. Anyone may join the group using the Chat ID. |
3522 | | * |
3523 | | * If the group is in this state, even if the Chat ID is never explicitly shared |
3524 | | * with someone outside of the group, information including the Chat ID, IP addresses, |
3525 | | * and peer ID's (but not Tox ID's) is visible to anyone with access to a node |
3526 | | * storing a DHT entry for the given group. |
3527 | | */ |
3528 | | TOX_GROUP_PRIVACY_STATE_PUBLIC, |
3529 | | |
3530 | | /** |
3531 | | * The group is considered to be private. The only way to join the group is by having |
3532 | | * someone in your contact list send you an invite. |
3533 | | * |
3534 | | * If the group is in this state, no group information (mentioned above) is present in the DHT; |
3535 | | * the DHT is not used for any purpose at all. If a public group is set to private, |
3536 | | * all DHT information related to the group will expire shortly. |
3537 | | */ |
3538 | | TOX_GROUP_PRIVACY_STATE_PRIVATE, |
3539 | | |
3540 | | } Tox_Group_Privacy_State; |
3541 | | |
3542 | | const char *tox_group_privacy_state_to_string(Tox_Group_Privacy_State value); |
3543 | | |
3544 | | |
3545 | | /** |
3546 | | * Represents the state of the group topic lock. |
3547 | | */ |
3548 | | typedef enum Tox_Group_Topic_Lock { |
3549 | | |
3550 | | /** |
3551 | | * The topic lock is enabled. Only peers with the founder and moderator roles may set the topic. |
3552 | | */ |
3553 | | TOX_GROUP_TOPIC_LOCK_ENABLED, |
3554 | | |
3555 | | /** |
3556 | | * The topic lock is disabled. All peers except those with the observer role may set the topic. |
3557 | | */ |
3558 | | TOX_GROUP_TOPIC_LOCK_DISABLED, |
3559 | | |
3560 | | } Tox_Group_Topic_Lock; |
3561 | | |
3562 | | const char *tox_group_topic_lock_to_string(Tox_Group_Topic_Lock value); |
3563 | | |
3564 | | /** |
3565 | | * Represents the group voice state, which determines which Group Roles have permission to speak |
3566 | | * in the group chat. The voice state does not have any effect private messages or topic setting. |
3567 | | */ |
3568 | | typedef enum Tox_Group_Voice_State { |
3569 | | /** |
3570 | | * All group roles above Observer have permission to speak. |
3571 | | */ |
3572 | | TOX_GROUP_VOICE_STATE_ALL, |
3573 | | |
3574 | | /** |
3575 | | * Moderators and Founders have permission to speak. |
3576 | | */ |
3577 | | TOX_GROUP_VOICE_STATE_MODERATOR, |
3578 | | |
3579 | | /** |
3580 | | * Only the founder may speak. |
3581 | | */ |
3582 | | TOX_GROUP_VOICE_STATE_FOUNDER, |
3583 | | } Tox_Group_Voice_State; |
3584 | | |
3585 | | const char *tox_group_voice_state_to_string(Tox_Group_Voice_State value); |
3586 | | |
3587 | | /** |
3588 | | * Represents group roles. |
3589 | | * |
3590 | | * Roles are hierarchical in that each role has a set of privileges plus all the privileges |
3591 | | * of the roles below it. |
3592 | | */ |
3593 | | typedef enum Tox_Group_Role { |
3594 | | |
3595 | | /** |
3596 | | * May kick all other peers as well as set their role to anything (except founder). |
3597 | | * Founders may also set the group password, toggle the privacy state, and set the peer limit. |
3598 | | */ |
3599 | | TOX_GROUP_ROLE_FOUNDER, |
3600 | | |
3601 | | /** |
3602 | | * May kick and set the user and observer roles for peers below this role. |
3603 | | * May also set the group topic. |
3604 | | */ |
3605 | | TOX_GROUP_ROLE_MODERATOR, |
3606 | | |
3607 | | /** |
3608 | | * May communicate with other peers normally. |
3609 | | */ |
3610 | | TOX_GROUP_ROLE_USER, |
3611 | | |
3612 | | /** |
3613 | | * May observe the group and ignore peers; may not communicate with other peers or with the group. |
3614 | | */ |
3615 | | TOX_GROUP_ROLE_OBSERVER, |
3616 | | |
3617 | | } Tox_Group_Role; |
3618 | | |
3619 | | const char *tox_group_role_to_string(Tox_Group_Role value); |
3620 | | |
3621 | | |
3622 | | |
3623 | | /******************************************************************************* |
3624 | | * |
3625 | | * :: Group chat instance management |
3626 | | * |
3627 | | ******************************************************************************/ |
3628 | | |
3629 | | |
3630 | | |
3631 | | typedef enum Tox_Err_Group_New { |
3632 | | |
3633 | | /** |
3634 | | * The function returned successfully. |
3635 | | */ |
3636 | | TOX_ERR_GROUP_NEW_OK, |
3637 | | |
3638 | | /** |
3639 | | * name exceeds TOX_MAX_NAME_LENGTH or group_name exceeded TOX_GROUP_MAX_GROUP_NAME_LENGTH. |
3640 | | */ |
3641 | | TOX_ERR_GROUP_NEW_TOO_LONG, |
3642 | | |
3643 | | /** |
3644 | | * name or group_name is NULL or length is zero. |
3645 | | */ |
3646 | | TOX_ERR_GROUP_NEW_EMPTY, |
3647 | | |
3648 | | /** |
3649 | | * The group instance failed to initialize. |
3650 | | */ |
3651 | | TOX_ERR_GROUP_NEW_INIT, |
3652 | | |
3653 | | /** |
3654 | | * The group state failed to initialize. This usually indicates that something went wrong |
3655 | | * related to cryptographic signing. |
3656 | | */ |
3657 | | TOX_ERR_GROUP_NEW_STATE, |
3658 | | |
3659 | | /** |
3660 | | * The group failed to announce to the DHT. This indicates a network related error. |
3661 | | */ |
3662 | | TOX_ERR_GROUP_NEW_ANNOUNCE, |
3663 | | |
3664 | | } Tox_Err_Group_New; |
3665 | | |
3666 | | const char *tox_err_group_new_to_string(Tox_Err_Group_New value); |
3667 | | |
3668 | | |
3669 | | /** |
3670 | | * Creates a new group chat. |
3671 | | * |
3672 | | * This function creates a new group chat object and adds it to the chats array. |
3673 | | * |
3674 | | * The caller of this function has Founder role privileges. |
3675 | | * |
3676 | | * The client should initiate its peer list with self info after calling this function, as |
3677 | | * the peer_join callback will not be triggered. |
3678 | | * |
3679 | | * @param privacy_state The privacy state of the group. If this is set to TOX_GROUP_PRIVACY_STATE_PUBLIC, |
3680 | | * the group will attempt to announce itself to the DHT and anyone with the Chat ID may join. |
3681 | | * Otherwise a friend invite will be required to join the group. |
3682 | | * @param group_name The name of the group. The name must be non-NULL. |
3683 | | * @param group_name_length The length of the group name. This must be greater than zero and no larger than |
3684 | | * TOX_GROUP_MAX_GROUP_NAME_LENGTH. |
3685 | | * @param name The name of the peer creating the group. |
3686 | | * @param name_length The length of the peer's name. This must be greater than zero and no larger |
3687 | | * than TOX_MAX_NAME_LENGTH. |
3688 | | * |
3689 | | * @return group_number on success, UINT32_MAX on failure. |
3690 | | */ |
3691 | | Tox_Group_Number tox_group_new( |
3692 | | Tox *tox, Tox_Group_Privacy_State privacy_state, |
3693 | | const uint8_t group_name[], size_t group_name_length, |
3694 | | const uint8_t name[], size_t name_length, Tox_Err_Group_New *error); |
3695 | | |
3696 | | typedef enum Tox_Err_Group_Join { |
3697 | | |
3698 | | /** |
3699 | | * The function returned successfully. |
3700 | | */ |
3701 | | TOX_ERR_GROUP_JOIN_OK, |
3702 | | |
3703 | | /** |
3704 | | * The group instance failed to initialize. |
3705 | | */ |
3706 | | TOX_ERR_GROUP_JOIN_INIT, |
3707 | | |
3708 | | /** |
3709 | | * The chat_id pointer is set to NULL or a group with chat_id already exists. This usually |
3710 | | * happens if the client attempts to create multiple sessions for the same group. |
3711 | | */ |
3712 | | TOX_ERR_GROUP_JOIN_BAD_CHAT_ID, |
3713 | | |
3714 | | /** |
3715 | | * name is NULL or name_length is zero. |
3716 | | */ |
3717 | | TOX_ERR_GROUP_JOIN_EMPTY, |
3718 | | |
3719 | | /** |
3720 | | * name exceeds TOX_MAX_NAME_LENGTH. |
3721 | | */ |
3722 | | TOX_ERR_GROUP_JOIN_TOO_LONG, |
3723 | | |
3724 | | /** |
3725 | | * Failed to set password. This usually occurs if the password exceeds TOX_GROUP_MAX_PASSWORD_SIZE. |
3726 | | */ |
3727 | | TOX_ERR_GROUP_JOIN_PASSWORD, |
3728 | | |
3729 | | /** |
3730 | | * There was a core error when initiating the group. |
3731 | | */ |
3732 | | TOX_ERR_GROUP_JOIN_CORE, |
3733 | | |
3734 | | } Tox_Err_Group_Join; |
3735 | | |
3736 | | const char *tox_err_group_join_to_string(Tox_Err_Group_Join value); |
3737 | | |
3738 | | |
3739 | | /** |
3740 | | * Joins a group chat with specified Chat ID. |
3741 | | * |
3742 | | * This function creates a new group chat object, adds it to the chats array, and sends |
3743 | | * a DHT announcement to find peers in the group associated with chat_id. Once a peer has been |
3744 | | * found a join attempt will be initiated. |
3745 | | * |
3746 | | * @param chat_id The Chat ID of the group you wish to join. This must be TOX_GROUP_CHAT_ID_SIZE bytes. |
3747 | | * @param password The password required to join the group. Set to NULL if no password is required. |
3748 | | * @param password_length The length of the password. If length is equal to zero, |
3749 | | * the password parameter is ignored. length must be no larger than TOX_GROUP_MAX_PASSWORD_SIZE. |
3750 | | * @param name The name of the peer joining the group. |
3751 | | * @param name_length The length of the peer's name. This must be greater than zero and no larger |
3752 | | * than TOX_MAX_NAME_LENGTH. |
3753 | | * |
3754 | | * @return group_number on success, UINT32_MAX on failure. |
3755 | | */ |
3756 | | Tox_Group_Number tox_group_join( |
3757 | | Tox *tox, const uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], |
3758 | | const uint8_t name[], size_t name_length, |
3759 | | const uint8_t password[], size_t password_length, |
3760 | | Tox_Err_Group_Join *error); |
3761 | | |
3762 | | typedef enum Tox_Err_Group_Is_Connected { |
3763 | | |
3764 | | /** |
3765 | | * The function returned successfully. |
3766 | | */ |
3767 | | TOX_ERR_GROUP_IS_CONNECTED_OK, |
3768 | | |
3769 | | /** |
3770 | | * The group number passed did not designate a valid group. |
3771 | | */ |
3772 | | TOX_ERR_GROUP_IS_CONNECTED_GROUP_NOT_FOUND, |
3773 | | |
3774 | | } Tox_Err_Group_Is_Connected; |
3775 | | |
3776 | | const char *tox_err_group_is_connected_to_string(Tox_Err_Group_Is_Connected value); |
3777 | | |
3778 | | |
3779 | | /** |
3780 | | * Returns true if the group chat is currently connected or attempting to connect to other peers |
3781 | | * in the group. |
3782 | | * |
3783 | | * @param group_number The group number of the designated group. |
3784 | | */ |
3785 | | bool tox_group_is_connected(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Is_Connected *error); |
3786 | | |
3787 | | typedef enum Tox_Err_Group_Disconnect { |
3788 | | |
3789 | | /** |
3790 | | * The function returned successfully. |
3791 | | */ |
3792 | | TOX_ERR_GROUP_DISCONNECT_OK, |
3793 | | |
3794 | | /** |
3795 | | * The group number passed did not designate a valid group. |
3796 | | */ |
3797 | | TOX_ERR_GROUP_DISCONNECT_GROUP_NOT_FOUND, |
3798 | | |
3799 | | /** |
3800 | | * The group is already disconnected. |
3801 | | */ |
3802 | | TOX_ERR_GROUP_DISCONNECT_ALREADY_DISCONNECTED, |
3803 | | } Tox_Err_Group_Disconnect; |
3804 | | |
3805 | | const char *tox_err_group_disconnect_to_string(Tox_Err_Group_Disconnect value); |
3806 | | |
3807 | | |
3808 | | /** |
3809 | | * Disconnects from a group chat while retaining the group state and credentials. |
3810 | | * |
3811 | | * Returns true if we successfully disconnect from the group. |
3812 | | * |
3813 | | * @param group_number The group number of the designated group. |
3814 | | */ |
3815 | | bool tox_group_disconnect(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Disconnect *error); |
3816 | | |
3817 | | typedef enum Tox_Err_Group_Reconnect { |
3818 | | |
3819 | | /** |
3820 | | * The function returned successfully. |
3821 | | */ |
3822 | | TOX_ERR_GROUP_RECONNECT_OK, |
3823 | | |
3824 | | /** |
3825 | | * The group number passed did not designate a valid group. |
3826 | | */ |
3827 | | TOX_ERR_GROUP_RECONNECT_GROUP_NOT_FOUND, |
3828 | | |
3829 | | /** |
3830 | | * There was a core error when initiating the group. |
3831 | | */ |
3832 | | TOX_ERR_GROUP_RECONNECT_CORE, |
3833 | | |
3834 | | } Tox_Err_Group_Reconnect; |
3835 | | |
3836 | | const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value); |
3837 | | |
3838 | | |
3839 | | /** |
3840 | | * Reconnects to a group. |
3841 | | * |
3842 | | * This function disconnects from all peers in the group, then attempts to reconnect with the group. |
3843 | | * The caller's state is not changed (i.e. name, status, role, chat public key etc.). |
3844 | | * |
3845 | | * @param group_number The group number of the group we wish to reconnect to. |
3846 | | * |
3847 | | * @return true on success. |
3848 | | */ |
3849 | | bool tox_group_reconnect(Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Reconnect *error); |
3850 | | |
3851 | | typedef enum Tox_Err_Group_Leave { |
3852 | | |
3853 | | /** |
3854 | | * The function returned successfully. |
3855 | | */ |
3856 | | TOX_ERR_GROUP_LEAVE_OK, |
3857 | | |
3858 | | /** |
3859 | | * The group number passed did not designate a valid group. |
3860 | | */ |
3861 | | TOX_ERR_GROUP_LEAVE_GROUP_NOT_FOUND, |
3862 | | |
3863 | | /** |
3864 | | * Message length exceeded TOX_GROUP_MAX_PART_LENGTH. |
3865 | | */ |
3866 | | TOX_ERR_GROUP_LEAVE_TOO_LONG, |
3867 | | |
3868 | | /** |
3869 | | * The parting packet failed to send. |
3870 | | */ |
3871 | | TOX_ERR_GROUP_LEAVE_FAIL_SEND, |
3872 | | } Tox_Err_Group_Leave; |
3873 | | |
3874 | | const char *tox_err_group_leave_to_string(Tox_Err_Group_Leave value); |
3875 | | |
3876 | | |
3877 | | /** |
3878 | | * Leaves a group. |
3879 | | * |
3880 | | * This function sends a parting packet containing a custom (non-obligatory) message to all |
3881 | | * peers in a group, and deletes the group from the chat array. All group state information is permanently |
3882 | | * lost, including keys and role credentials. |
3883 | | * |
3884 | | * @param group_number The group number of the group we wish to leave. |
3885 | | * @param part_message The parting message to be sent to all the peers. Set to NULL if we do not wish to |
3886 | | * send a parting message. |
3887 | | * @param length The length of the parting message. Set to 0 if we do not wish to send a parting message. |
3888 | | * |
3889 | | * @return true if the group chat instance is successfully deleted. |
3890 | | */ |
3891 | | bool tox_group_leave( |
3892 | | Tox *tox, Tox_Group_Number group_number, |
3893 | | const uint8_t part_message[], size_t length, |
3894 | | Tox_Err_Group_Leave *error); |
3895 | | |
3896 | | |
3897 | | /******************************************************************************* |
3898 | | * |
3899 | | * :: Group user-visible client information (nickname/status/role/public key) |
3900 | | * |
3901 | | ******************************************************************************/ |
3902 | | |
3903 | | |
3904 | | |
3905 | | /** |
3906 | | * General error codes for self state get and size functions. |
3907 | | */ |
3908 | | typedef enum Tox_Err_Group_Self_Query { |
3909 | | |
3910 | | /** |
3911 | | * The function returned successfully. |
3912 | | */ |
3913 | | TOX_ERR_GROUP_SELF_QUERY_OK, |
3914 | | |
3915 | | /** |
3916 | | * The group number passed did not designate a valid group. |
3917 | | */ |
3918 | | TOX_ERR_GROUP_SELF_QUERY_GROUP_NOT_FOUND, |
3919 | | |
3920 | | } Tox_Err_Group_Self_Query; |
3921 | | |
3922 | | const char *tox_err_group_self_query_to_string(Tox_Err_Group_Self_Query value); |
3923 | | |
3924 | | |
3925 | | /** |
3926 | | * Error codes for self name setting. |
3927 | | */ |
3928 | | typedef enum Tox_Err_Group_Self_Name_Set { |
3929 | | |
3930 | | /** |
3931 | | * The function returned successfully. |
3932 | | */ |
3933 | | TOX_ERR_GROUP_SELF_NAME_SET_OK, |
3934 | | |
3935 | | /** |
3936 | | * The group number passed did not designate a valid group. |
3937 | | */ |
3938 | | TOX_ERR_GROUP_SELF_NAME_SET_GROUP_NOT_FOUND, |
3939 | | |
3940 | | /** |
3941 | | * Name length exceeded TOX_MAX_NAME_LENGTH. |
3942 | | */ |
3943 | | TOX_ERR_GROUP_SELF_NAME_SET_TOO_LONG, |
3944 | | |
3945 | | /** |
3946 | | * The length given to the set function is zero or name is a NULL pointer. |
3947 | | */ |
3948 | | TOX_ERR_GROUP_SELF_NAME_SET_INVALID, |
3949 | | |
3950 | | /** |
3951 | | * The packet failed to send. |
3952 | | */ |
3953 | | TOX_ERR_GROUP_SELF_NAME_SET_FAIL_SEND, |
3954 | | |
3955 | | } Tox_Err_Group_Self_Name_Set; |
3956 | | |
3957 | | const char *tox_err_group_self_name_set_to_string(Tox_Err_Group_Self_Name_Set value); |
3958 | | |
3959 | | |
3960 | | /** |
3961 | | * Set the client's nickname for the group instance designated by the given group number. |
3962 | | * |
3963 | | * Nickname length cannot exceed TOX_MAX_NAME_LENGTH. If length is equal to zero or name is a NULL |
3964 | | * pointer, the function call will fail. |
3965 | | * |
3966 | | * @param name A byte array containing the new nickname. |
3967 | | * @param length The size of the name byte array. |
3968 | | * |
3969 | | * @return true on success. |
3970 | | */ |
3971 | | bool tox_group_self_set_name( |
3972 | | Tox *tox, Tox_Group_Number group_number, |
3973 | | const uint8_t name[], size_t length, |
3974 | | Tox_Err_Group_Self_Name_Set *error); |
3975 | | |
3976 | | /** |
3977 | | * Return the length of the client's current nickname for the group instance designated |
3978 | | * by group_number as passed to tox_group_self_set_name. |
3979 | | * |
3980 | | * If no nickname was set before calling this function, the name is empty, |
3981 | | * and this function returns 0. |
3982 | | * |
3983 | | * @see threading for concurrency implications. |
3984 | | */ |
3985 | | size_t tox_group_self_get_name_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Self_Query *error); |
3986 | | |
3987 | | /** |
3988 | | * Write the nickname set by tox_group_self_set_name to a byte array. |
3989 | | * |
3990 | | * If no nickname was set before calling this function, the name is empty, |
3991 | | * and this function has no effect. |
3992 | | * |
3993 | | * Call tox_group_self_get_name_size to find out how much memory to allocate for the result. |
3994 | | * |
3995 | | * @param name A valid memory location large enough to hold the nickname. |
3996 | | * If this parameter is NULL, the function has no effect. |
3997 | | * |
3998 | | * @return true on success. |
3999 | | */ |
4000 | | bool tox_group_self_get_name( |
4001 | | const Tox *tox, Tox_Group_Number group_number, |
4002 | | uint8_t name[], Tox_Err_Group_Self_Query *error); |
4003 | | |
4004 | | /** |
4005 | | * Error codes for self status setting. |
4006 | | */ |
4007 | | typedef enum Tox_Err_Group_Self_Status_Set { |
4008 | | |
4009 | | /** |
4010 | | * The function returned successfully. |
4011 | | */ |
4012 | | TOX_ERR_GROUP_SELF_STATUS_SET_OK, |
4013 | | |
4014 | | /** |
4015 | | * The group number passed did not designate a valid group. |
4016 | | */ |
4017 | | TOX_ERR_GROUP_SELF_STATUS_SET_GROUP_NOT_FOUND, |
4018 | | |
4019 | | /** |
4020 | | * The packet failed to send. |
4021 | | */ |
4022 | | TOX_ERR_GROUP_SELF_STATUS_SET_FAIL_SEND, |
4023 | | |
4024 | | } Tox_Err_Group_Self_Status_Set; |
4025 | | |
4026 | | const char *tox_err_group_self_status_set_to_string(Tox_Err_Group_Self_Status_Set value); |
4027 | | |
4028 | | |
4029 | | /** |
4030 | | * Set the client's status for the group instance. Status must be a Tox_User_Status. |
4031 | | * |
4032 | | * @return true on success. |
4033 | | */ |
4034 | | bool tox_group_self_set_status(Tox *tox, Tox_Group_Number group_number, Tox_User_Status status, |
4035 | | Tox_Err_Group_Self_Status_Set *error); |
4036 | | |
4037 | | /** |
4038 | | * returns the client's status for the group instance on success. |
4039 | | * return value is unspecified on failure. |
4040 | | */ |
4041 | | Tox_User_Status tox_group_self_get_status(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Self_Query *error); |
4042 | | |
4043 | | /** |
4044 | | * returns the client's role for the group instance on success. |
4045 | | * return value is unspecified on failure. |
4046 | | */ |
4047 | | Tox_Group_Role tox_group_self_get_role(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Self_Query *error); |
4048 | | |
4049 | | /** |
4050 | | * returns the client's peer id for the group instance on success. |
4051 | | * return value is unspecified on failure. |
4052 | | */ |
4053 | | Tox_Group_Peer_Number tox_group_self_get_peer_id(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Self_Query *error); |
4054 | | |
4055 | | /** |
4056 | | * Write the client's group public key designated by the given group number to a byte array. |
4057 | | * |
4058 | | * This key will be permanently tied to the client's identity for this particular group until |
4059 | | * the client explicitly leaves the group. This key is the only way for other peers to reliably |
4060 | | * identify the client across client restarts. |
4061 | | * |
4062 | | * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE bytes. |
4063 | | * |
4064 | | * @param public_key A valid memory region large enough to store the public key. |
4065 | | * If this parameter is NULL, this function call has no effect. |
4066 | | * |
4067 | | * @return true on success. |
4068 | | */ |
4069 | | bool tox_group_self_get_public_key(const Tox *tox, Tox_Group_Number group_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE], |
4070 | | Tox_Err_Group_Self_Query *error); |
4071 | | |
4072 | | |
4073 | | /******************************************************************************* |
4074 | | * |
4075 | | * :: Peer-specific group state queries. |
4076 | | * |
4077 | | ******************************************************************************/ |
4078 | | |
4079 | | |
4080 | | |
4081 | | /** |
4082 | | * Error codes for peer info queries. |
4083 | | */ |
4084 | | typedef enum Tox_Err_Group_Peer_Query { |
4085 | | |
4086 | | /** |
4087 | | * The function returned successfully. |
4088 | | */ |
4089 | | TOX_ERR_GROUP_PEER_QUERY_OK, |
4090 | | |
4091 | | /** |
4092 | | * The group number passed did not designate a valid group. |
4093 | | */ |
4094 | | TOX_ERR_GROUP_PEER_QUERY_GROUP_NOT_FOUND, |
4095 | | |
4096 | | /** |
4097 | | * The ID passed did not designate a valid peer. |
4098 | | */ |
4099 | | TOX_ERR_GROUP_PEER_QUERY_PEER_NOT_FOUND, |
4100 | | |
4101 | | } Tox_Err_Group_Peer_Query; |
4102 | | |
4103 | | const char *tox_err_group_peer_query_to_string(Tox_Err_Group_Peer_Query value); |
4104 | | |
4105 | | |
4106 | | /** |
4107 | | * Return the length of the peer's name. If the group number or ID is invalid, the |
4108 | | * return value is unspecified. |
4109 | | * |
4110 | | * @param group_number The group number of the group we wish to query. |
4111 | | * @param peer_id The ID of the peer whose name length we want to retrieve. |
4112 | | * |
4113 | | * The return value is equal to the `length` argument received by the last |
4114 | | * `group_peer_name` callback. |
4115 | | */ |
4116 | | size_t tox_group_peer_get_name_size(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4117 | | Tox_Err_Group_Peer_Query *error); |
4118 | | |
4119 | | /** |
4120 | | * Write the name of the peer designated by the given ID to a byte |
4121 | | * array. |
4122 | | * |
4123 | | * Call tox_group_peer_get_name_size to determine the allocation size for the `name` parameter. |
4124 | | * |
4125 | | * The data written to `name` is equal to the data received by the last |
4126 | | * `group_peer_name` callback. |
4127 | | * |
4128 | | * @param group_number The group number of the group we wish to query. |
4129 | | * @param peer_id The ID of the peer whose name we wish to retrieve. |
4130 | | * @param name A valid memory region large enough to store the friend's name. |
4131 | | * |
4132 | | * @return true on success. |
4133 | | */ |
4134 | | bool tox_group_peer_get_name( |
4135 | | const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4136 | | uint8_t name[], Tox_Err_Group_Peer_Query *error); |
4137 | | |
4138 | | /** |
4139 | | * Return the peer's user status (away/busy/...). If the ID or group number is |
4140 | | * invalid, the return value is unspecified. |
4141 | | * |
4142 | | * @param group_number The group number of the group we wish to query. |
4143 | | * @param peer_id The ID of the peer whose status we wish to query. |
4144 | | * |
4145 | | * The status returned is equal to the last status received through the |
4146 | | * `group_peer_status` callback. |
4147 | | */ |
4148 | | Tox_User_Status tox_group_peer_get_status(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4149 | | Tox_Err_Group_Peer_Query *error); |
4150 | | |
4151 | | /** |
4152 | | * Return the peer's role (user/moderator/founder...). If the ID or group number is |
4153 | | * invalid, the return value is unspecified. |
4154 | | * |
4155 | | * @param group_number The group number of the group we wish to query. |
4156 | | * @param peer_id The ID of the peer whose role we wish to query. |
4157 | | * |
4158 | | * The role returned is equal to the last role received through the |
4159 | | * `group_moderation` callback. |
4160 | | */ |
4161 | | Tox_Group_Role tox_group_peer_get_role(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4162 | | Tox_Err_Group_Peer_Query *error); |
4163 | | |
4164 | | /** |
4165 | | * Return the type of connection we have established with a peer. |
4166 | | * |
4167 | | * If `peer_id` designates ourself, the return value indicates whether we're capable |
4168 | | * of making UDP connections with other peers, or are limited to TCP connections. |
4169 | | * |
4170 | | * @param group_number The group number of the group we wish to query. |
4171 | | * @param peer_id The ID of the peer whose connection status we wish to query. |
4172 | | */ |
4173 | | Tox_Connection tox_group_peer_get_connection_status(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4174 | | Tox_Err_Group_Peer_Query *error); |
4175 | | |
4176 | | /** |
4177 | | * Write the group public key with the designated peer_id for the designated group number to public_key. |
4178 | | * |
4179 | | * This key will be permanently tied to a particular peer until they explicitly leave the group and is |
4180 | | * the only way to reliably identify the same peer across client restarts. |
4181 | | * |
4182 | | * `public_key` should have room for at least TOX_GROUP_PEER_PUBLIC_KEY_SIZE bytes. If `public_key` is null |
4183 | | * this function has no effect. |
4184 | | * |
4185 | | * @param group_number The group number of the group we wish to query. |
4186 | | * @param peer_id The ID of the peer whose public key we wish to retrieve. |
4187 | | * @param public_key A valid memory region large enough to store the public key. |
4188 | | * If this parameter is NULL, this function call has no effect. |
4189 | | * |
4190 | | * @return true on success. |
4191 | | */ |
4192 | | bool tox_group_peer_get_public_key( |
4193 | | const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4194 | | uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Group_Peer_Query *error); |
4195 | | |
4196 | | /** |
4197 | | * @param group_number The group number of the group the name change is intended for. |
4198 | | * @param peer_id The ID of the peer who has changed their name. |
4199 | | * @param name The name data. |
4200 | | * @param length The length of the name. |
4201 | | */ |
4202 | | typedef void tox_group_peer_name_cb( |
4203 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4204 | | const uint8_t name[], size_t length, void *user_data); |
4205 | | |
4206 | | |
4207 | | /** |
4208 | | * Set the callback for the `group_peer_name` event. Pass NULL to unset. |
4209 | | * |
4210 | | * This event is triggered when a peer changes their nickname. |
4211 | | */ |
4212 | | void tox_callback_group_peer_name(Tox *tox, tox_group_peer_name_cb *callback); |
4213 | | |
4214 | | /** |
4215 | | * @param group_number The group number of the group the status change is intended for. |
4216 | | * @param peer_id The ID of the peer who has changed their status. |
4217 | | * @param status The new status of the peer. |
4218 | | */ |
4219 | | typedef void tox_group_peer_status_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_User_Status status, |
4220 | | void *user_data); |
4221 | | |
4222 | | |
4223 | | /** |
4224 | | * Set the callback for the `group_peer_status` event. Pass NULL to unset. |
4225 | | * |
4226 | | * This event is triggered when a peer changes their status. |
4227 | | */ |
4228 | | void tox_callback_group_peer_status(Tox *tox, tox_group_peer_status_cb *callback); |
4229 | | |
4230 | | |
4231 | | /******************************************************************************* |
4232 | | * |
4233 | | * :: Group chat state queries and events. |
4234 | | * |
4235 | | ******************************************************************************/ |
4236 | | |
4237 | | |
4238 | | |
4239 | | /** |
4240 | | * General error codes for group state get and size functions. |
4241 | | */ |
4242 | | typedef enum Tox_Err_Group_State_Queries { |
4243 | | |
4244 | | /** |
4245 | | * The function returned successfully. |
4246 | | */ |
4247 | | TOX_ERR_GROUP_STATE_QUERIES_OK, |
4248 | | |
4249 | | /** |
4250 | | * The group number passed did not designate a valid group. |
4251 | | */ |
4252 | | TOX_ERR_GROUP_STATE_QUERIES_GROUP_NOT_FOUND, |
4253 | | |
4254 | | } Tox_Err_Group_State_Queries; |
4255 | | |
4256 | | const char *tox_err_group_state_queries_to_string(Tox_Err_Group_State_Queries value); |
4257 | | |
4258 | | |
4259 | | /** |
4260 | | * Error codes for group topic setting. |
4261 | | */ |
4262 | | typedef enum Tox_Err_Group_Topic_Set { |
4263 | | |
4264 | | /** |
4265 | | * The function returned successfully. |
4266 | | */ |
4267 | | TOX_ERR_GROUP_TOPIC_SET_OK, |
4268 | | |
4269 | | /** |
4270 | | * The group number passed did not designate a valid group. |
4271 | | */ |
4272 | | TOX_ERR_GROUP_TOPIC_SET_GROUP_NOT_FOUND, |
4273 | | |
4274 | | /** |
4275 | | * Topic length exceeded TOX_GROUP_MAX_TOPIC_LENGTH. |
4276 | | */ |
4277 | | TOX_ERR_GROUP_TOPIC_SET_TOO_LONG, |
4278 | | |
4279 | | /** |
4280 | | * The caller does not have the required permissions to set the topic. |
4281 | | */ |
4282 | | TOX_ERR_GROUP_TOPIC_SET_PERMISSIONS, |
4283 | | |
4284 | | /** |
4285 | | * The packet could not be created. This error is usually related to cryptographic signing. |
4286 | | */ |
4287 | | TOX_ERR_GROUP_TOPIC_SET_FAIL_CREATE, |
4288 | | |
4289 | | /** |
4290 | | * The packet failed to send. |
4291 | | */ |
4292 | | TOX_ERR_GROUP_TOPIC_SET_FAIL_SEND, |
4293 | | |
4294 | | /** |
4295 | | * The group is disconnected. |
4296 | | */ |
4297 | | TOX_ERR_GROUP_TOPIC_SET_DISCONNECTED, |
4298 | | |
4299 | | } Tox_Err_Group_Topic_Set; |
4300 | | |
4301 | | const char *tox_err_group_topic_set_to_string(Tox_Err_Group_Topic_Set value); |
4302 | | |
4303 | | |
4304 | | /** |
4305 | | * Set the group topic and broadcast it to the rest of the group. |
4306 | | * |
4307 | | * topic length cannot be longer than TOX_GROUP_MAX_TOPIC_LENGTH. If length is equal to zero or |
4308 | | * topic is set to NULL, the topic will be unset. |
4309 | | * |
4310 | | * @return true on success. |
4311 | | */ |
4312 | | bool tox_group_set_topic( |
4313 | | Tox *tox, Tox_Group_Number group_number, |
4314 | | const uint8_t topic[], size_t length, |
4315 | | Tox_Err_Group_Topic_Set *error); |
4316 | | |
4317 | | /** |
4318 | | * Return the length of the group topic. If the group number is invalid, the |
4319 | | * return value is unspecified. |
4320 | | * |
4321 | | * The return value is equal to the `length` argument received by the last |
4322 | | * `group_topic` callback. |
4323 | | */ |
4324 | | size_t tox_group_get_topic_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); |
4325 | | |
4326 | | /** |
4327 | | * Write the topic designated by the given group number to a byte array. |
4328 | | * |
4329 | | * Call tox_group_get_topic_size to determine the allocation size for the `topic` parameter. |
4330 | | * |
4331 | | * The data written to `topic` is equal to the data received by the last |
4332 | | * `group_topic` callback. |
4333 | | * |
4334 | | * @param topic A valid memory region large enough to store the topic. |
4335 | | * If this parameter is NULL, this function has no effect. |
4336 | | * |
4337 | | * @return true on success. |
4338 | | */ |
4339 | | bool tox_group_get_topic( |
4340 | | const Tox *tox, Tox_Group_Number group_number, |
4341 | | uint8_t topic[], Tox_Err_Group_State_Queries *error); |
4342 | | |
4343 | | /** |
4344 | | * @param group_number The group number of the group the topic change is intended for. |
4345 | | * @param peer_id The ID of the peer who changed the topic. If the peer who set the topic |
4346 | | * is not present in our peer list this value will be set to 0. |
4347 | | * @param topic The topic data. |
4348 | | * @param length The topic length. |
4349 | | */ |
4350 | | typedef void tox_group_topic_cb( |
4351 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4352 | | const uint8_t topic[], size_t length, |
4353 | | void *user_data); |
4354 | | |
4355 | | |
4356 | | /** |
4357 | | * Set the callback for the `group_topic` event. Pass NULL to unset. |
4358 | | * |
4359 | | * This event is triggered when a peer changes the group topic. |
4360 | | */ |
4361 | | void tox_callback_group_topic(Tox *tox, tox_group_topic_cb *callback); |
4362 | | |
4363 | | /** |
4364 | | * Return the length of the group name. If the group number is invalid, the |
4365 | | * return value is unspecified. |
4366 | | */ |
4367 | | size_t tox_group_get_name_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); |
4368 | | |
4369 | | /** |
4370 | | * Write the name of the group designated by the given group number to a byte array. |
4371 | | * |
4372 | | * Call tox_group_get_name_size to determine the allocation size for the `name` parameter. |
4373 | | * |
4374 | | * @param name A valid memory region large enough to store the group name. |
4375 | | * If this parameter is NULL, this function call has no effect. |
4376 | | * |
4377 | | * @return true on success. |
4378 | | */ |
4379 | | bool tox_group_get_name( |
4380 | | const Tox *tox, Tox_Group_Number group_number, |
4381 | | uint8_t name[], Tox_Err_Group_State_Queries *error); |
4382 | | |
4383 | | /** |
4384 | | * Write the Chat ID designated by the given group number to a byte array. |
4385 | | * |
4386 | | * `chat_id` should have room for at least TOX_GROUP_CHAT_ID_SIZE bytes. |
4387 | | * |
4388 | | * @param chat_id A valid memory region large enough to store the Chat ID. |
4389 | | * If this parameter is NULL, this function call has no effect. |
4390 | | * |
4391 | | * @return true on success. |
4392 | | */ |
4393 | | bool tox_group_get_chat_id( |
4394 | | const Tox *tox, Tox_Group_Number group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], |
4395 | | Tox_Err_Group_State_Queries *error); |
4396 | | |
4397 | | /** |
4398 | | * Return the number of groups in the Tox chats array. |
4399 | | */ |
4400 | | uint32_t tox_group_get_number_groups(const Tox *tox); |
4401 | | |
4402 | | /** |
4403 | | * Return the privacy state of the group designated by the given group number. If group number |
4404 | | * is invalid, the return value is unspecified. |
4405 | | * |
4406 | | * The value returned is equal to the data received by the last |
4407 | | * `group_privacy_state` callback. |
4408 | | * |
4409 | | * @see the `Group chat founder controls` section for the respective set function. |
4410 | | */ |
4411 | | Tox_Group_Privacy_State tox_group_get_privacy_state(const Tox *tox, Tox_Group_Number group_number, |
4412 | | Tox_Err_Group_State_Queries *error); |
4413 | | |
4414 | | /** |
4415 | | * @param group_number The group number of the group the privacy state is intended for. |
4416 | | * @param privacy_state The new privacy state. |
4417 | | */ |
4418 | | typedef void tox_group_privacy_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, |
4419 | | void *user_data); |
4420 | | |
4421 | | |
4422 | | /** |
4423 | | * Set the callback for the `group_privacy_state` event. Pass NULL to unset. |
4424 | | * |
4425 | | * This event is triggered when the group founder changes the privacy state. |
4426 | | */ |
4427 | | void tox_callback_group_privacy_state(Tox *tox, tox_group_privacy_state_cb *callback); |
4428 | | |
4429 | | /** |
4430 | | * Return the voice state of the group designated by the given group number. If group number |
4431 | | * is invalid, the return value is unspecified. |
4432 | | * |
4433 | | * The value returned is equal to the data received by the last `group_voice_state` callback. |
4434 | | * |
4435 | | * @see the `Group chat founder controls` section for the respective set function. |
4436 | | */ |
4437 | | Tox_Group_Voice_State tox_group_get_voice_state(const Tox *tox, Tox_Group_Number group_number, |
4438 | | Tox_Err_Group_State_Queries *error); |
4439 | | |
4440 | | /** |
4441 | | * @param group_number The group number of the group the voice state change is intended for. |
4442 | | * @param voice_state The new voice state. |
4443 | | */ |
4444 | | typedef void tox_group_voice_state_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, |
4445 | | void *user_data); |
4446 | | |
4447 | | |
4448 | | /** |
4449 | | * Set the callback for the `group_privacy_state` event. Pass NULL to unset. |
4450 | | * |
4451 | | * This event is triggered when the group founder changes the voice state. |
4452 | | */ |
4453 | | void tox_callback_group_voice_state(Tox *tox, tox_group_voice_state_cb *callback); |
4454 | | |
4455 | | /** |
4456 | | * Return the topic lock status of the group designated by the given group number. If group number |
4457 | | * is invalid, the return value is unspecified. |
4458 | | * |
4459 | | * The value returned is equal to the data received by the last |
4460 | | * `group_topic_lock` callback. |
4461 | | * |
4462 | | * @see the `Group chat founder contols` section for the respective set function. |
4463 | | */ |
4464 | | Tox_Group_Topic_Lock tox_group_get_topic_lock(const Tox *tox, Tox_Group_Number group_number, |
4465 | | Tox_Err_Group_State_Queries *error); |
4466 | | |
4467 | | /** |
4468 | | * @param group_number The group number of the group for which the topic lock has changed. |
4469 | | * @param topic_lock The new topic lock state. |
4470 | | */ |
4471 | | typedef void tox_group_topic_lock_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, void *user_data); |
4472 | | |
4473 | | |
4474 | | |
4475 | | /** |
4476 | | * Set the callback for the `group_topic_lock` event. Pass NULL to unset. |
4477 | | * |
4478 | | * This event is triggered when the group founder changes the topic lock status. |
4479 | | */ |
4480 | | void tox_callback_group_topic_lock(Tox *tox, tox_group_topic_lock_cb *callback); |
4481 | | |
4482 | | /** |
4483 | | * Return the maximum number of peers allowed for the group designated by the given group number. |
4484 | | * If the group number is invalid, the return value is unspecified. |
4485 | | * |
4486 | | * The value returned is equal to the data received by the last |
4487 | | * `group_peer_limit` callback. |
4488 | | * |
4489 | | * @see the `Group chat founder controls` section for the respective set function. |
4490 | | */ |
4491 | | uint16_t tox_group_get_peer_limit(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); |
4492 | | |
4493 | | /** |
4494 | | * @param group_number The group number of the group for which the peer limit has changed. |
4495 | | * @param peer_limit The new peer limit for the group. |
4496 | | */ |
4497 | | typedef void tox_group_peer_limit_cb(Tox *tox, Tox_Group_Number group_number, uint32_t peer_limit, void *user_data); |
4498 | | |
4499 | | |
4500 | | /** |
4501 | | * Set the callback for the `group_peer_limit` event. Pass NULL to unset. |
4502 | | * |
4503 | | * This event is triggered when the group founder changes the maximum peer limit. |
4504 | | */ |
4505 | | void tox_callback_group_peer_limit(Tox *tox, tox_group_peer_limit_cb *callback); |
4506 | | |
4507 | | /** |
4508 | | * Return the length of the group password. If the group number is invalid, the |
4509 | | * return value is unspecified. |
4510 | | */ |
4511 | | size_t tox_group_get_password_size(const Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_State_Queries *error); |
4512 | | |
4513 | | /** |
4514 | | * Write the password for the group designated by the given group number to a byte array. |
4515 | | * |
4516 | | * Call tox_group_get_password_size to determine the allocation size for the `password` parameter. |
4517 | | * |
4518 | | * The data received is equal to the data received by the last |
4519 | | * `group_password` callback. |
4520 | | * |
4521 | | * @see the `Group chat founder controls` section for the respective set function. |
4522 | | * |
4523 | | * @param password A valid memory region large enough to store the group password. |
4524 | | * If this parameter is NULL, this function call has no effect. |
4525 | | * |
4526 | | * @return true on success. |
4527 | | */ |
4528 | | bool tox_group_get_password( |
4529 | | const Tox *tox, Tox_Group_Number group_number, uint8_t password[], |
4530 | | Tox_Err_Group_State_Queries *error); |
4531 | | |
4532 | | /** |
4533 | | * @param group_number The group number of the group for which the password has changed. |
4534 | | * @param password The new group password. |
4535 | | * @param length The length of the password. |
4536 | | */ |
4537 | | typedef void tox_group_password_cb( |
4538 | | Tox *tox, Tox_Group_Number group_number, |
4539 | | const uint8_t password[], size_t length, |
4540 | | void *user_data); |
4541 | | |
4542 | | |
4543 | | /** |
4544 | | * Set the callback for the `group_password` event. Pass NULL to unset. |
4545 | | * |
4546 | | * This event is triggered when the group founder changes the group password. |
4547 | | */ |
4548 | | void tox_callback_group_password(Tox *tox, tox_group_password_cb *callback); |
4549 | | |
4550 | | |
4551 | | /******************************************************************************* |
4552 | | * |
4553 | | * :: Group chat message sending |
4554 | | * |
4555 | | ******************************************************************************/ |
4556 | | |
4557 | | |
4558 | | |
4559 | | typedef enum Tox_Err_Group_Send_Message { |
4560 | | |
4561 | | /** |
4562 | | * The function returned successfully. |
4563 | | */ |
4564 | | TOX_ERR_GROUP_SEND_MESSAGE_OK, |
4565 | | |
4566 | | /** |
4567 | | * The group number passed did not designate a valid group. |
4568 | | */ |
4569 | | TOX_ERR_GROUP_SEND_MESSAGE_GROUP_NOT_FOUND, |
4570 | | |
4571 | | /** |
4572 | | * Message length exceeded TOX_GROUP_MAX_MESSAGE_LENGTH. |
4573 | | */ |
4574 | | TOX_ERR_GROUP_SEND_MESSAGE_TOO_LONG, |
4575 | | |
4576 | | /** |
4577 | | * The message pointer is null or length is zero. |
4578 | | */ |
4579 | | TOX_ERR_GROUP_SEND_MESSAGE_EMPTY, |
4580 | | |
4581 | | /** |
4582 | | * The message type is invalid. |
4583 | | */ |
4584 | | TOX_ERR_GROUP_SEND_MESSAGE_BAD_TYPE, |
4585 | | |
4586 | | /** |
4587 | | * The caller does not have the required permissions to send group messages. |
4588 | | */ |
4589 | | TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS, |
4590 | | |
4591 | | /** |
4592 | | * Packet failed to send. |
4593 | | */ |
4594 | | TOX_ERR_GROUP_SEND_MESSAGE_FAIL_SEND, |
4595 | | |
4596 | | /** |
4597 | | * The group is disconnected. |
4598 | | */ |
4599 | | TOX_ERR_GROUP_SEND_MESSAGE_DISCONNECTED, |
4600 | | |
4601 | | } Tox_Err_Group_Send_Message; |
4602 | | |
4603 | | const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message value); |
4604 | | |
4605 | | |
4606 | | /** |
4607 | | * Send a text chat message to the group. |
4608 | | * |
4609 | | * This function creates a group message packet and pushes it into the send |
4610 | | * queue. |
4611 | | * |
4612 | | * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger messages |
4613 | | * must be split by the client and sent as separate messages. Other clients can |
4614 | | * then reassemble the fragments. Messages may not be empty. |
4615 | | * |
4616 | | * @param group_number The group number of the group the message is intended for. |
4617 | | * @param type Message type (normal, action, ...). |
4618 | | * @param message A non-NULL pointer to the first element of a byte array |
4619 | | * containing the message text. |
4620 | | * @param length Length of the message to be sent. |
4621 | | * |
4622 | | * @return The message_id of this message. If this function has an error, the |
4623 | | * returned message ID value will be undefined. |
4624 | | */ |
4625 | | Tox_Group_Message_Id tox_group_send_message( |
4626 | | const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type, |
4627 | | const uint8_t message[], size_t length, |
4628 | | Tox_Err_Group_Send_Message *error); |
4629 | | |
4630 | | typedef enum Tox_Err_Group_Send_Private_Message { |
4631 | | |
4632 | | /** |
4633 | | * The function returned successfully. |
4634 | | */ |
4635 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, |
4636 | | |
4637 | | /** |
4638 | | * The group number passed did not designate a valid group. |
4639 | | */ |
4640 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_GROUP_NOT_FOUND, |
4641 | | |
4642 | | /** |
4643 | | * The peer ID passed did not designate a valid peer. |
4644 | | */ |
4645 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PEER_NOT_FOUND, |
4646 | | |
4647 | | /** |
4648 | | * Message length exceeded TOX_GROUP_MAX_MESSAGE_LENGTH. |
4649 | | */ |
4650 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_TOO_LONG, |
4651 | | |
4652 | | /** |
4653 | | * The message pointer is null or length is zero. |
4654 | | */ |
4655 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_EMPTY, |
4656 | | |
4657 | | /** |
4658 | | * The caller does not have the required permissions to send group messages. |
4659 | | */ |
4660 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS, |
4661 | | |
4662 | | /** |
4663 | | * Packet failed to send. |
4664 | | */ |
4665 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_FAIL_SEND, |
4666 | | |
4667 | | /** |
4668 | | * The group is disconnected. |
4669 | | */ |
4670 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_DISCONNECTED, |
4671 | | |
4672 | | /** |
4673 | | * The message type is invalid. |
4674 | | */ |
4675 | | TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_BAD_TYPE, |
4676 | | |
4677 | | } Tox_Err_Group_Send_Private_Message; |
4678 | | |
4679 | | const char *tox_err_group_send_private_message_to_string(Tox_Err_Group_Send_Private_Message value); |
4680 | | |
4681 | | |
4682 | | /** |
4683 | | * Send a text chat message to the specified peer in the specified group. |
4684 | | * |
4685 | | * This function creates a group private message packet and pushes it into the send |
4686 | | * queue. |
4687 | | * |
4688 | | * The message length may not exceed TOX_GROUP_MAX_MESSAGE_LENGTH. Larger messages |
4689 | | * must be split by the client and sent as separate messages. Other clients can |
4690 | | * then reassemble the fragments. Messages may not be empty. |
4691 | | * |
4692 | | * @param group_number The group number of the group the message is intended for. |
4693 | | * @param peer_id The ID of the peer the message is intended for. |
4694 | | * @param message A non-NULL pointer to the first element of a byte array |
4695 | | * containing the message text. |
4696 | | * @param length Length of the message to be sent. |
4697 | | * |
4698 | | * @return true on success. |
4699 | | */ |
4700 | | bool tox_group_send_private_message( |
4701 | | const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, |
4702 | | const uint8_t message[], size_t length, |
4703 | | Tox_Err_Group_Send_Private_Message *error); |
4704 | | |
4705 | | typedef enum Tox_Err_Group_Send_Custom_Packet { |
4706 | | |
4707 | | /** |
4708 | | * The function returned successfully. |
4709 | | */ |
4710 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, |
4711 | | |
4712 | | /** |
4713 | | * The group number passed did not designate a valid group. |
4714 | | */ |
4715 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_GROUP_NOT_FOUND, |
4716 | | |
4717 | | /** |
4718 | | * Message length exceeded TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH if the |
4719 | | * packet was lossy, or TOX_GROUP_MAX_CUSTOM_LOSSLESS_PACKET_LENGTH if the |
4720 | | * packet was lossless. |
4721 | | */ |
4722 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_TOO_LONG, |
4723 | | |
4724 | | /** |
4725 | | * The message pointer is null or length is zero. |
4726 | | */ |
4727 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_EMPTY, |
4728 | | |
4729 | | /** |
4730 | | * The caller does not have the required permissions to send group messages. |
4731 | | */ |
4732 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_PERMISSIONS, |
4733 | | |
4734 | | /** |
4735 | | * The group is disconnected. |
4736 | | */ |
4737 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_DISCONNECTED, |
4738 | | |
4739 | | /** |
4740 | | * The packet did not successfully send to any peer. This often indicates |
4741 | | * a connection issue on the sender's side. |
4742 | | */ |
4743 | | TOX_ERR_GROUP_SEND_CUSTOM_PACKET_FAIL_SEND, |
4744 | | |
4745 | | } Tox_Err_Group_Send_Custom_Packet; |
4746 | | |
4747 | | const char *tox_err_group_send_custom_packet_to_string(Tox_Err_Group_Send_Custom_Packet value); |
4748 | | |
4749 | | |
4750 | | /** |
4751 | | * Send a custom packet to the group. |
4752 | | * |
4753 | | * If lossless is true the packet will be lossless. Lossless packet behaviour is comparable |
4754 | | * to TCP (reliability, arrive in order) but with packets instead of a stream. |
4755 | | * |
4756 | | * If lossless is false, the packet will be lossy. Lossy packets behave like UDP packets, |
4757 | | * meaning they might never reach the other side or might arrive more than once (if someone |
4758 | | * is messing with the connection) or might arrive in the wrong order. |
4759 | | * |
4760 | | * Unless latency is an issue or message reliability is not important, it is recommended that you use |
4761 | | * lossless packets. |
4762 | | * |
4763 | | * The message length may not exceed TOX_MAX_CUSTOM_PACKET_SIZE. Larger packets |
4764 | | * must be split by the client and sent as separate packets. Other clients can |
4765 | | * then reassemble the fragments. Packets may not be empty. |
4766 | | * |
4767 | | * @param group_number The group number of the group the packet is intended for. |
4768 | | * @param lossless True if the packet should be lossless. |
4769 | | * @param data A byte array containing the packet data. |
4770 | | * @param length The length of the packet data byte array. |
4771 | | * |
4772 | | * @return true on success. |
4773 | | */ |
4774 | | bool tox_group_send_custom_packet( |
4775 | | const Tox *tox, Tox_Group_Number group_number, bool lossless, |
4776 | | const uint8_t data[], size_t length, |
4777 | | Tox_Err_Group_Send_Custom_Packet *error); |
4778 | | |
4779 | | |
4780 | | typedef enum Tox_Err_Group_Send_Custom_Private_Packet { |
4781 | | |
4782 | | /** |
4783 | | * The function returned successfully. |
4784 | | */ |
4785 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK, |
4786 | | |
4787 | | /** |
4788 | | * The group number passed did not designate a valid group. |
4789 | | */ |
4790 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_GROUP_NOT_FOUND, |
4791 | | |
4792 | | /** |
4793 | | * Message length exceeded TOX_GROUP_MAX_CUSTOM_LOSSY_PACKET_LENGTH if the |
4794 | | * packet was lossy, or TOX_GROUP_MAX_CUSTOM_LOSSLESS_PACKET_LENGTH if the |
4795 | | * packet was lossless. |
4796 | | */ |
4797 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_TOO_LONG, |
4798 | | |
4799 | | /** |
4800 | | * The message pointer is null or length is zero. |
4801 | | */ |
4802 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_EMPTY, |
4803 | | |
4804 | | /** |
4805 | | * The peer ID passed did no designate a valid peer. |
4806 | | */ |
4807 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PEER_NOT_FOUND, |
4808 | | |
4809 | | /** |
4810 | | * The caller does not have the required permissions to send group messages. |
4811 | | */ |
4812 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_PERMISSIONS, |
4813 | | |
4814 | | /** |
4815 | | * The packet failed to send. |
4816 | | */ |
4817 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_FAIL_SEND, |
4818 | | |
4819 | | /** |
4820 | | * The group is disconnected. |
4821 | | */ |
4822 | | TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_DISCONNECTED, |
4823 | | |
4824 | | } Tox_Err_Group_Send_Custom_Private_Packet; |
4825 | | |
4826 | | const char *tox_err_group_send_custom_private_packet_to_string(Tox_Err_Group_Send_Custom_Private_Packet value); |
4827 | | |
4828 | | /** |
4829 | | * Send a custom private packet to a designated peer in the group. |
4830 | | * |
4831 | | * If lossless is true the packet will be lossless. Lossless packet behaviour is comparable |
4832 | | * to TCP (reliability, arrive in order) but with packets instead of a stream. |
4833 | | * |
4834 | | * If lossless is false, the packet will be lossy. Lossy packets behave like UDP packets, |
4835 | | * meaning they might never reach the other side or might arrive more than once (if someone |
4836 | | * is messing with the connection) or might arrive in the wrong order. |
4837 | | * |
4838 | | * Unless latency is an issue or message reliability is not important, it is recommended that you use |
4839 | | * lossless packets. |
4840 | | * |
4841 | | * The packet length may not exceed TOX_MAX_CUSTOM_PACKET_SIZE. Larger packets |
4842 | | * must be split by the client and sent as separate packets. Other clients can |
4843 | | * then reassemble the fragments. Packets may not be empty. |
4844 | | * |
4845 | | * @param group_number The group number of the group the packet is intended for. |
4846 | | * @param peer_id The ID of the peer the packet is intended for. |
4847 | | * @param lossless True if the packet should be lossless. |
4848 | | * @param data A byte array containing the packet data. |
4849 | | * @param length The length of the packet data byte array. |
4850 | | * |
4851 | | * @return true on success. |
4852 | | */ |
4853 | | bool tox_group_send_custom_private_packet(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, bool lossless, |
4854 | | const uint8_t data[], size_t length, |
4855 | | Tox_Err_Group_Send_Custom_Private_Packet *error); |
4856 | | |
4857 | | |
4858 | | /******************************************************************************* |
4859 | | * |
4860 | | * :: Group chat message receiving |
4861 | | * |
4862 | | ******************************************************************************/ |
4863 | | |
4864 | | |
4865 | | |
4866 | | /** |
4867 | | * @param group_number The group number of the group the message is intended for. |
4868 | | * @param peer_id The ID of the peer who sent the message. |
4869 | | * @param type The type of message (normal, action, ...). |
4870 | | * @param message The message data. |
4871 | | * @param message_id A pseudo message id that clients can use to uniquely identify this group message. |
4872 | | * @param length The length of the message. |
4873 | | */ |
4874 | | typedef void tox_group_message_cb( |
4875 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, |
4876 | | const uint8_t message[], size_t length, Tox_Group_Message_Id message_id, void *user_data); |
4877 | | |
4878 | | |
4879 | | /** |
4880 | | * Set the callback for the `group_message` event. Pass NULL to unset. |
4881 | | * |
4882 | | * This event is triggered when the client receives a group message. |
4883 | | */ |
4884 | | void tox_callback_group_message(Tox *tox, tox_group_message_cb *callback); |
4885 | | |
4886 | | /** |
4887 | | * @param group_number The group number of the group the private message is intended for. |
4888 | | * @param peer_id The ID of the peer who sent the private message. |
4889 | | * @param message The message data. |
4890 | | * @param length The length of the message. |
4891 | | */ |
4892 | | typedef void tox_group_private_message_cb( |
4893 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Message_Type type, |
4894 | | const uint8_t message[], size_t length, void *user_data); |
4895 | | |
4896 | | |
4897 | | /** |
4898 | | * Set the callback for the `group_private_message` event. Pass NULL to unset. |
4899 | | * |
4900 | | * This event is triggered when the client receives a private message. |
4901 | | */ |
4902 | | void tox_callback_group_private_message(Tox *tox, tox_group_private_message_cb *callback); |
4903 | | |
4904 | | /** |
4905 | | * @param group_number The group number of the group the packet is intended for. |
4906 | | * @param peer_id The ID of the peer who sent the packet. |
4907 | | * @param data The packet data. |
4908 | | * @param length The length of the data. |
4909 | | */ |
4910 | | typedef void tox_group_custom_packet_cb( |
4911 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4912 | | const uint8_t data[], size_t length, void *user_data); |
4913 | | |
4914 | | |
4915 | | /** |
4916 | | * Set the callback for the `group_custom_packet` event. Pass NULL to unset. |
4917 | | * |
4918 | | * This event is triggered when the client receives a custom packet. |
4919 | | */ |
4920 | | void tox_callback_group_custom_packet(Tox *tox, tox_group_custom_packet_cb *callback); |
4921 | | |
4922 | | /** |
4923 | | * @param group_number The group number of the group the packet is intended for. |
4924 | | * @param peer_id The ID of the peer who sent the packet. |
4925 | | * @param data The packet data. |
4926 | | * @param length The length of the data. |
4927 | | */ |
4928 | | typedef void tox_group_custom_private_packet_cb( |
4929 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
4930 | | const uint8_t data[], size_t length, void *user_data); |
4931 | | |
4932 | | |
4933 | | /** |
4934 | | * Set the callback for the `group_custom_private_packet` event. Pass NULL to unset. |
4935 | | * |
4936 | | * This event is triggered when the client receives a custom private packet. |
4937 | | */ |
4938 | | void tox_callback_group_custom_private_packet(Tox *tox, tox_group_custom_private_packet_cb *callback); |
4939 | | |
4940 | | |
4941 | | /******************************************************************************* |
4942 | | * |
4943 | | * :: Group chat inviting and join/part events |
4944 | | * |
4945 | | ******************************************************************************/ |
4946 | | |
4947 | | |
4948 | | |
4949 | | typedef enum Tox_Err_Group_Invite_Friend { |
4950 | | |
4951 | | /** |
4952 | | * The function returned successfully. |
4953 | | */ |
4954 | | TOX_ERR_GROUP_INVITE_FRIEND_OK, |
4955 | | |
4956 | | /** |
4957 | | * The group number passed did not designate a valid group. |
4958 | | */ |
4959 | | TOX_ERR_GROUP_INVITE_FRIEND_GROUP_NOT_FOUND, |
4960 | | |
4961 | | /** |
4962 | | * The friend number passed did not designate a valid friend. |
4963 | | */ |
4964 | | TOX_ERR_GROUP_INVITE_FRIEND_FRIEND_NOT_FOUND, |
4965 | | |
4966 | | /** |
4967 | | * Creation of the invite packet failed. This indicates a network related error. |
4968 | | */ |
4969 | | TOX_ERR_GROUP_INVITE_FRIEND_INVITE_FAIL, |
4970 | | |
4971 | | /** |
4972 | | * Packet failed to send. |
4973 | | */ |
4974 | | TOX_ERR_GROUP_INVITE_FRIEND_FAIL_SEND, |
4975 | | |
4976 | | /** |
4977 | | * The group is disconnected. |
4978 | | */ |
4979 | | TOX_ERR_GROUP_INVITE_FRIEND_DISCONNECTED, |
4980 | | |
4981 | | } Tox_Err_Group_Invite_Friend; |
4982 | | |
4983 | | const char *tox_err_group_invite_friend_to_string(Tox_Err_Group_Invite_Friend value); |
4984 | | |
4985 | | |
4986 | | /** |
4987 | | * Invite a friend to a group. |
4988 | | * |
4989 | | * This function creates an invite request packet and pushes it to the send queue. |
4990 | | * |
4991 | | * @param group_number The group number of the group the message is intended for. |
4992 | | * @param friend_number The friend number of the friend the invite is intended for. |
4993 | | * |
4994 | | * @return true on success. |
4995 | | */ |
4996 | | bool tox_group_invite_friend( |
4997 | | const Tox *tox, Tox_Group_Number group_number, Tox_Friend_Number friend_number, |
4998 | | Tox_Err_Group_Invite_Friend *error); |
4999 | | |
5000 | | typedef enum Tox_Err_Group_Invite_Accept { |
5001 | | |
5002 | | /** |
5003 | | * The function returned successfully. |
5004 | | */ |
5005 | | TOX_ERR_GROUP_INVITE_ACCEPT_OK, |
5006 | | |
5007 | | /** |
5008 | | * The invite data is not in the expected format. |
5009 | | */ |
5010 | | TOX_ERR_GROUP_INVITE_ACCEPT_BAD_INVITE, |
5011 | | |
5012 | | /** |
5013 | | * The group instance failed to initialize. |
5014 | | */ |
5015 | | TOX_ERR_GROUP_INVITE_ACCEPT_INIT_FAILED, |
5016 | | |
5017 | | /** |
5018 | | * name exceeds TOX_MAX_NAME_LENGTH |
5019 | | */ |
5020 | | TOX_ERR_GROUP_INVITE_ACCEPT_TOO_LONG, |
5021 | | |
5022 | | /** |
5023 | | * name is NULL or name_length is zero. |
5024 | | */ |
5025 | | TOX_ERR_GROUP_INVITE_ACCEPT_EMPTY, |
5026 | | |
5027 | | /** |
5028 | | * Failed to set password. This usually occurs if the password exceeds TOX_GROUP_MAX_PASSWORD_SIZE. |
5029 | | */ |
5030 | | TOX_ERR_GROUP_INVITE_ACCEPT_PASSWORD, |
5031 | | |
5032 | | /** |
5033 | | * There was a core error when initiating the group. |
5034 | | */ |
5035 | | TOX_ERR_GROUP_INVITE_ACCEPT_CORE, |
5036 | | |
5037 | | /** |
5038 | | * Packet failed to send. |
5039 | | */ |
5040 | | TOX_ERR_GROUP_INVITE_ACCEPT_FAIL_SEND, |
5041 | | |
5042 | | } Tox_Err_Group_Invite_Accept; |
5043 | | |
5044 | | const char *tox_err_group_invite_accept_to_string(Tox_Err_Group_Invite_Accept value); |
5045 | | |
5046 | | |
5047 | | /** |
5048 | | * Accept an invite to a group chat that the client previously received from a friend. The invite |
5049 | | * is only valid while the inviter is present in the group. |
5050 | | * |
5051 | | * @param invite_data The invite data received from the `group_invite` event. |
5052 | | * @param length The length of the invite data. |
5053 | | * @param name The name of the peer joining the group. |
5054 | | * @param name_length The length of the peer's name. This must be greater than zero and no larger |
5055 | | * than TOX_MAX_NAME_LENGTH. |
5056 | | * @param password The password required to join the group. Set to NULL if no password is required. |
5057 | | * @param password_length The length of the password. If password_length is equal to zero, the password |
5058 | | * parameter will be ignored. password_length must be no larger than TOX_GROUP_MAX_PASSWORD_SIZE. |
5059 | | * |
5060 | | * @return the group_number on success, UINT32_MAX on failure. |
5061 | | */ |
5062 | | Tox_Group_Number tox_group_invite_accept( |
5063 | | Tox *tox, Tox_Friend_Number friend_number, |
5064 | | const uint8_t invite_data[], size_t length, |
5065 | | const uint8_t name[], size_t name_length, |
5066 | | const uint8_t password[], size_t password_length, |
5067 | | Tox_Err_Group_Invite_Accept *error); |
5068 | | |
5069 | | /** |
5070 | | * @param friend_number The friend number of the contact who sent the invite. |
5071 | | * @param invite_data The invite data. |
5072 | | * @param length The length of invite_data. |
5073 | | */ |
5074 | | typedef void tox_group_invite_cb( |
5075 | | Tox *tox, Tox_Friend_Number friend_number, |
5076 | | const uint8_t invite_data[], size_t length, |
5077 | | const uint8_t group_name[], size_t group_name_length, |
5078 | | void *user_data); |
5079 | | |
5080 | | |
5081 | | /** |
5082 | | * Set the callback for the `group_invite` event. Pass NULL to unset. |
5083 | | * |
5084 | | * This event is triggered when the client receives a group invite from a friend. The client must store |
5085 | | * invite_data which is used to join the group via tox_group_invite_accept. |
5086 | | */ |
5087 | | void tox_callback_group_invite(Tox *tox, tox_group_invite_cb *callback); |
5088 | | |
5089 | | /** |
5090 | | * @param group_number The group number of the group in which a new peer has joined. |
5091 | | * @param peer_id The permanent ID of the new peer. This id should not be relied on for |
5092 | | * client behaviour and should be treated as a random value. |
5093 | | */ |
5094 | | typedef void tox_group_peer_join_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, void *user_data); |
5095 | | |
5096 | | |
5097 | | /** |
5098 | | * Set the callback for the `group_peer_join` event. Pass NULL to unset. |
5099 | | * |
5100 | | * This event is triggered when a peer other than self joins the group. |
5101 | | */ |
5102 | | void tox_callback_group_peer_join(Tox *tox, tox_group_peer_join_cb *callback); |
5103 | | |
5104 | | /** |
5105 | | * Represents peer exit events. These should be used with the `group_peer_exit` event. |
5106 | | */ |
5107 | | typedef enum Tox_Group_Exit_Type { |
5108 | | |
5109 | | /** |
5110 | | * The peer has quit the group. |
5111 | | */ |
5112 | | TOX_GROUP_EXIT_TYPE_QUIT, |
5113 | | |
5114 | | /** |
5115 | | * Your connection with this peer has timed out. |
5116 | | */ |
5117 | | TOX_GROUP_EXIT_TYPE_TIMEOUT, |
5118 | | |
5119 | | /** |
5120 | | * Your connection with this peer has been severed. |
5121 | | */ |
5122 | | TOX_GROUP_EXIT_TYPE_DISCONNECTED, |
5123 | | |
5124 | | /** |
5125 | | * Your connection with all peers has been severed. This will occur when you are kicked from |
5126 | | * a group, rejoin a group, or manually disconnect from a group. |
5127 | | */ |
5128 | | TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED, |
5129 | | |
5130 | | /** |
5131 | | * The peer has been kicked. |
5132 | | */ |
5133 | | TOX_GROUP_EXIT_TYPE_KICK, |
5134 | | |
5135 | | /** |
5136 | | * The peer provided invalid group sync information. |
5137 | | */ |
5138 | | TOX_GROUP_EXIT_TYPE_SYNC_ERROR, |
5139 | | |
5140 | | } Tox_Group_Exit_Type; |
5141 | | |
5142 | | const char *tox_group_exit_type_to_string(Tox_Group_Exit_Type value); |
5143 | | |
5144 | | |
5145 | | /** |
5146 | | * @param group_number The group number of the group in which a peer has left. |
5147 | | * @param peer_id The ID of the peer who left the group. This ID no longer designates a valid peer |
5148 | | * and cannot be used for API calls. |
5149 | | * @param exit_type The type of exit event. One of Tox_Group_Exit_Type. |
5150 | | * @param name The nickname of the peer who left the group. |
5151 | | * @param name_length The length of the peer name. |
5152 | | * @param part_message The parting message data. |
5153 | | * @param part_message_length The length of the parting message. |
5154 | | */ |
5155 | | typedef void tox_group_peer_exit_cb( |
5156 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Exit_Type exit_type, |
5157 | | const uint8_t name[], size_t name_length, |
5158 | | const uint8_t part_message[], size_t part_message_length, void *user_data); |
5159 | | |
5160 | | |
5161 | | /** |
5162 | | * Set the callback for the `group_peer_exit` event. Pass NULL to unset. |
5163 | | * |
5164 | | * This event is triggered when a peer other than self exits the group. |
5165 | | */ |
5166 | | void tox_callback_group_peer_exit(Tox *tox, tox_group_peer_exit_cb *callback); |
5167 | | |
5168 | | /** |
5169 | | * @param group_number The group number of the group that the client has joined. |
5170 | | */ |
5171 | | typedef void tox_group_self_join_cb(Tox *tox, Tox_Group_Number group_number, void *user_data); |
5172 | | |
5173 | | |
5174 | | /** |
5175 | | * Set the callback for the `group_self_join` event. Pass NULL to unset. |
5176 | | * |
5177 | | * This event is triggered when the client has successfully joined a group. Use this to initialize |
5178 | | * any group information the client may need. |
5179 | | */ |
5180 | | void tox_callback_group_self_join(Tox *tox, tox_group_self_join_cb *callback); |
5181 | | |
5182 | | /** |
5183 | | * Represents types of failed group join attempts. These are used in the tox_callback_group_rejected |
5184 | | * callback when a peer fails to join a group. |
5185 | | */ |
5186 | | typedef enum Tox_Group_Join_Fail { |
5187 | | |
5188 | | /** |
5189 | | * The group peer limit has been reached. |
5190 | | */ |
5191 | | TOX_GROUP_JOIN_FAIL_PEER_LIMIT, |
5192 | | |
5193 | | /** |
5194 | | * You have supplied an invalid password. |
5195 | | */ |
5196 | | TOX_GROUP_JOIN_FAIL_INVALID_PASSWORD, |
5197 | | |
5198 | | /** |
5199 | | * The join attempt failed due to an unspecified error. This often occurs when the group is |
5200 | | * not found in the DHT. |
5201 | | */ |
5202 | | TOX_GROUP_JOIN_FAIL_UNKNOWN, |
5203 | | |
5204 | | } Tox_Group_Join_Fail; |
5205 | | |
5206 | | const char *tox_group_join_fail_to_string(Tox_Group_Join_Fail value); |
5207 | | |
5208 | | |
5209 | | /** |
5210 | | * @param group_number The group number of the group for which the join has failed. |
5211 | | * @param fail_type The type of group rejection. |
5212 | | */ |
5213 | | typedef void tox_group_join_fail_cb(Tox *tox, Tox_Group_Number group_number, Tox_Group_Join_Fail fail_type, void *user_data); |
5214 | | |
5215 | | |
5216 | | /** |
5217 | | * Set the callback for the `group_join_fail` event. Pass NULL to unset. |
5218 | | * |
5219 | | * This event is triggered when the client fails to join a group. |
5220 | | */ |
5221 | | void tox_callback_group_join_fail(Tox *tox, tox_group_join_fail_cb *callback); |
5222 | | |
5223 | | |
5224 | | /******************************************************************************* |
5225 | | * |
5226 | | * :: Group chat founder controls (these only work for the group founder) |
5227 | | * |
5228 | | ******************************************************************************/ |
5229 | | |
5230 | | |
5231 | | |
5232 | | typedef enum Tox_Err_Group_Founder_Set_Password { |
5233 | | |
5234 | | /** |
5235 | | * The function returned successfully. |
5236 | | */ |
5237 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, |
5238 | | |
5239 | | /** |
5240 | | * The group number passed did not designate a valid group. |
5241 | | */ |
5242 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_GROUP_NOT_FOUND, |
5243 | | |
5244 | | /** |
5245 | | * The caller does not have the required permissions to set the password. |
5246 | | */ |
5247 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS, |
5248 | | |
5249 | | /** |
5250 | | * Password length exceeded TOX_GROUP_MAX_PASSWORD_SIZE. |
5251 | | */ |
5252 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG, |
5253 | | |
5254 | | /** |
5255 | | * The packet failed to send. |
5256 | | */ |
5257 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_FAIL_SEND, |
5258 | | |
5259 | | /** |
5260 | | * The function failed to allocate enough memory for the operation. |
5261 | | */ |
5262 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_MALLOC, |
5263 | | |
5264 | | /** |
5265 | | * The group is disconnected. |
5266 | | */ |
5267 | | TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_DISCONNECTED, |
5268 | | |
5269 | | } Tox_Err_Group_Founder_Set_Password; |
5270 | | |
5271 | | const char *tox_err_group_founder_set_password_to_string(Tox_Err_Group_Founder_Set_Password value); |
5272 | | |
5273 | | |
5274 | | /** |
5275 | | * Set or unset the group password. |
5276 | | * |
5277 | | * This function sets the groups password, creates a new group shared state including the change, |
5278 | | * and distributes it to the rest of the group. |
5279 | | * |
5280 | | * @param group_number The group number of the group for which we wish to set the password. |
5281 | | * @param password The password we want to set. Set password to NULL to unset the password. |
5282 | | * @param length The length of the password. length must be no longer than TOX_GROUP_MAX_PASSWORD_SIZE. |
5283 | | * |
5284 | | * @return true on success. |
5285 | | */ |
5286 | | bool tox_group_founder_set_password( |
5287 | | Tox *tox, Tox_Group_Number group_number, |
5288 | | const uint8_t password[], size_t length, |
5289 | | Tox_Err_Group_Founder_Set_Password *error); |
5290 | | |
5291 | | typedef enum Tox_Err_Group_Founder_Set_Topic_Lock { |
5292 | | |
5293 | | /** |
5294 | | * The function returned successfully. |
5295 | | */ |
5296 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, |
5297 | | |
5298 | | /** |
5299 | | * The group number passed did not designate a valid group. |
5300 | | */ |
5301 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_GROUP_NOT_FOUND, |
5302 | | |
5303 | | /** |
5304 | | * Tox_Group_Topic_Lock is an invalid type. |
5305 | | */ |
5306 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_INVALID, |
5307 | | |
5308 | | /** |
5309 | | * The caller does not have the required permissions to set the topic lock. |
5310 | | */ |
5311 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS, |
5312 | | |
5313 | | /** |
5314 | | * The topic lock could not be set. This may occur due to an error related to |
5315 | | * cryptographic signing of the new shared state. |
5316 | | */ |
5317 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SET, |
5318 | | |
5319 | | /** |
5320 | | * The packet failed to send. |
5321 | | */ |
5322 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_FAIL_SEND, |
5323 | | |
5324 | | /** |
5325 | | * The group is disconnected. |
5326 | | */ |
5327 | | TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_DISCONNECTED, |
5328 | | |
5329 | | } Tox_Err_Group_Founder_Set_Topic_Lock; |
5330 | | |
5331 | | const char *tox_err_group_founder_set_topic_lock_to_string(Tox_Err_Group_Founder_Set_Topic_Lock value); |
5332 | | |
5333 | | |
5334 | | /** |
5335 | | * Set the group topic lock state. |
5336 | | * |
5337 | | * This function sets the group's topic lock state to enabled or disabled, creates a new shared |
5338 | | * state including the change, and distributes it to the rest of the group. |
5339 | | * |
5340 | | * When the topic lock is enabled, only the group founder and moderators may set the topic. |
5341 | | * When disabled, all peers except those with the observer role may set the topic. |
5342 | | * |
5343 | | * @param group_number The group number of the group for which we wish to change the topic lock state. |
5344 | | * @param topic_lock The state we wish to set the topic lock to. |
5345 | | * |
5346 | | * @return true on success. |
5347 | | */ |
5348 | | bool tox_group_founder_set_topic_lock(Tox *tox, Tox_Group_Number group_number, Tox_Group_Topic_Lock topic_lock, |
5349 | | Tox_Err_Group_Founder_Set_Topic_Lock *error); |
5350 | | |
5351 | | typedef enum Tox_Err_Group_Founder_Set_Voice_State { |
5352 | | |
5353 | | /** |
5354 | | * The function returned successfully. |
5355 | | */ |
5356 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK, |
5357 | | |
5358 | | /** |
5359 | | * The group number passed did not designate a valid group. |
5360 | | */ |
5361 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_GROUP_NOT_FOUND, |
5362 | | |
5363 | | /** |
5364 | | * The caller does not have the required permissions to set the privacy state. |
5365 | | */ |
5366 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS, |
5367 | | |
5368 | | /** |
5369 | | * The voice state could not be set. This may occur due to an error related to |
5370 | | * cryptographic signing of the new shared state. |
5371 | | */ |
5372 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SET, |
5373 | | |
5374 | | /** |
5375 | | * The packet failed to send. |
5376 | | */ |
5377 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_FAIL_SEND, |
5378 | | |
5379 | | /** |
5380 | | * The group is disconnected. |
5381 | | */ |
5382 | | TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_DISCONNECTED, |
5383 | | |
5384 | | } Tox_Err_Group_Founder_Set_Voice_State; |
5385 | | |
5386 | | const char *tox_err_group_founder_set_voice_state_to_string(Tox_Err_Group_Founder_Set_Voice_State value); |
5387 | | |
5388 | | /** |
5389 | | * Set the group voice state. |
5390 | | * |
5391 | | * This function sets the group's voice state, creates a new group shared state |
5392 | | * including the change, and distributes it to the rest of the group. |
5393 | | * |
5394 | | * If an attempt is made to set the voice state to the same state that the group is already |
5395 | | * in, the function call will be successful and no action will be taken. |
5396 | | * |
5397 | | * @param group_number The group number of the group for which we wish to change the voice state. |
5398 | | * @param voice_state The voice state we wish to set the group to. |
5399 | | * |
5400 | | * @return true on success. |
5401 | | */ |
5402 | | bool tox_group_founder_set_voice_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Voice_State voice_state, |
5403 | | Tox_Err_Group_Founder_Set_Voice_State *error); |
5404 | | |
5405 | | typedef enum Tox_Err_Group_Founder_Set_Privacy_State { |
5406 | | |
5407 | | /** |
5408 | | * The function returned successfully. |
5409 | | */ |
5410 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, |
5411 | | |
5412 | | /** |
5413 | | * The group number passed did not designate a valid group. |
5414 | | */ |
5415 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_GROUP_NOT_FOUND, |
5416 | | |
5417 | | /** |
5418 | | * The caller does not have the required permissions to set the privacy state. |
5419 | | */ |
5420 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS, |
5421 | | |
5422 | | /** |
5423 | | * The privacy state could not be set. This may occur due to an error related to |
5424 | | * cryptographic signing of the new shared state. |
5425 | | */ |
5426 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SET, |
5427 | | |
5428 | | /** |
5429 | | * The packet failed to send. |
5430 | | */ |
5431 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_FAIL_SEND, |
5432 | | |
5433 | | /** |
5434 | | * The group is disconnected. |
5435 | | */ |
5436 | | TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_DISCONNECTED, |
5437 | | |
5438 | | } Tox_Err_Group_Founder_Set_Privacy_State; |
5439 | | |
5440 | | const char *tox_err_group_founder_set_privacy_state_to_string(Tox_Err_Group_Founder_Set_Privacy_State value); |
5441 | | |
5442 | | /** |
5443 | | * Set the group privacy state. |
5444 | | * |
5445 | | * This function sets the group's privacy state, creates a new group shared state |
5446 | | * including the change, and distributes it to the rest of the group. |
5447 | | * |
5448 | | * If an attempt is made to set the privacy state to the same state that the group is already |
5449 | | * in, the function call will be successful and no action will be taken. |
5450 | | * |
5451 | | * @param group_number The group number of the group for which we wish to change the privacy state. |
5452 | | * @param privacy_state The privacy state we wish to set the group to. |
5453 | | * |
5454 | | * @return true on success. |
5455 | | */ |
5456 | | bool tox_group_founder_set_privacy_state(Tox *tox, Tox_Group_Number group_number, Tox_Group_Privacy_State privacy_state, |
5457 | | Tox_Err_Group_Founder_Set_Privacy_State *error); |
5458 | | |
5459 | | typedef enum Tox_Err_Group_Founder_Set_Peer_Limit { |
5460 | | |
5461 | | /** |
5462 | | * The function returned successfully. |
5463 | | */ |
5464 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, |
5465 | | |
5466 | | /** |
5467 | | * The group number passed did not designate a valid group. |
5468 | | */ |
5469 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_GROUP_NOT_FOUND, |
5470 | | |
5471 | | /** |
5472 | | * The caller does not have the required permissions to set the peer limit. |
5473 | | */ |
5474 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS, |
5475 | | |
5476 | | /** |
5477 | | * The peer limit could not be set. This may occur due to an error related to |
5478 | | * cryptographic signing of the new shared state. |
5479 | | */ |
5480 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SET, |
5481 | | |
5482 | | /** |
5483 | | * The packet failed to send. |
5484 | | */ |
5485 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_FAIL_SEND, |
5486 | | |
5487 | | /** |
5488 | | * The group is disconnected. |
5489 | | */ |
5490 | | TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_DISCONNECTED, |
5491 | | |
5492 | | } Tox_Err_Group_Founder_Set_Peer_Limit; |
5493 | | |
5494 | | const char *tox_err_group_founder_set_peer_limit_to_string(Tox_Err_Group_Founder_Set_Peer_Limit value); |
5495 | | |
5496 | | |
5497 | | /** |
5498 | | * Set the group peer limit. |
5499 | | * |
5500 | | * This function sets a limit for the number of peers who may be in the group, creates a new |
5501 | | * group shared state including the change, and distributes it to the rest of the group. |
5502 | | * |
5503 | | * @param group_number The group number of the group for which we wish to set the peer limit. |
5504 | | * @param peer_limit The maximum number of peers to allow in the group. |
5505 | | * |
5506 | | * @return true on success. |
5507 | | */ |
5508 | | bool tox_group_founder_set_peer_limit(Tox *tox, Tox_Group_Number group_number, uint16_t peer_limit, |
5509 | | Tox_Err_Group_Founder_Set_Peer_Limit *error); |
5510 | | |
5511 | | |
5512 | | /******************************************************************************* |
5513 | | * |
5514 | | * :: Group chat moderation |
5515 | | * |
5516 | | ******************************************************************************/ |
5517 | | |
5518 | | |
5519 | | |
5520 | | typedef enum Tox_Err_Group_Set_Ignore { |
5521 | | |
5522 | | /** |
5523 | | * The function returned successfully. |
5524 | | */ |
5525 | | TOX_ERR_GROUP_SET_IGNORE_OK, |
5526 | | |
5527 | | /** |
5528 | | * The group number passed did not designate a valid group. |
5529 | | */ |
5530 | | TOX_ERR_GROUP_SET_IGNORE_GROUP_NOT_FOUND, |
5531 | | |
5532 | | /** |
5533 | | * The ID passed did not designate a valid peer. |
5534 | | */ |
5535 | | TOX_ERR_GROUP_SET_IGNORE_PEER_NOT_FOUND, |
5536 | | |
5537 | | /** |
5538 | | * The caller attempted to ignore himself. |
5539 | | */ |
5540 | | TOX_ERR_GROUP_SET_IGNORE_SELF, |
5541 | | |
5542 | | } Tox_Err_Group_Set_Ignore; |
5543 | | |
5544 | | const char *tox_err_group_set_ignore_to_string(Tox_Err_Group_Set_Ignore value); |
5545 | | |
5546 | | |
5547 | | /** |
5548 | | * Ignore or unignore a peer. |
5549 | | * |
5550 | | * @param group_number The group number of the group in which you wish to ignore a peer. |
5551 | | * @param peer_id The ID of the peer who shall be ignored or unignored. |
5552 | | * @param ignore True to ignore the peer, false to unignore the peer. |
5553 | | * |
5554 | | * @return true on success. |
5555 | | */ |
5556 | | bool tox_group_set_ignore(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, bool ignore, |
5557 | | Tox_Err_Group_Set_Ignore *error); |
5558 | | |
5559 | | typedef enum Tox_Err_Group_Mod_Set_Role { |
5560 | | |
5561 | | /** |
5562 | | * The function returned successfully. |
5563 | | */ |
5564 | | TOX_ERR_GROUP_MOD_SET_ROLE_OK, |
5565 | | |
5566 | | /** |
5567 | | * The group number passed did not designate a valid group. |
5568 | | */ |
5569 | | TOX_ERR_GROUP_MOD_SET_ROLE_GROUP_NOT_FOUND, |
5570 | | |
5571 | | /** |
5572 | | * The ID passed did not designate a valid peer. Note: you cannot set your own role. |
5573 | | */ |
5574 | | TOX_ERR_GROUP_MOD_SET_ROLE_PEER_NOT_FOUND, |
5575 | | |
5576 | | /** |
5577 | | * The caller does not have the required permissions for this action. |
5578 | | */ |
5579 | | TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS, |
5580 | | |
5581 | | /** |
5582 | | * The role assignment is invalid. This will occur if you try to set a peer's role to |
5583 | | * the role they already have. |
5584 | | */ |
5585 | | TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT, |
5586 | | |
5587 | | /** |
5588 | | * The role was not successfully set. This may occur if the packet failed to send, or |
5589 | | * if the role limit has been reached. |
5590 | | */ |
5591 | | TOX_ERR_GROUP_MOD_SET_ROLE_FAIL_ACTION, |
5592 | | |
5593 | | /** |
5594 | | * The caller attempted to set their own role. |
5595 | | */ |
5596 | | TOX_ERR_GROUP_MOD_SET_ROLE_SELF, |
5597 | | |
5598 | | } Tox_Err_Group_Mod_Set_Role; |
5599 | | |
5600 | | const char *tox_err_group_mod_set_role_to_string(Tox_Err_Group_Mod_Set_Role value); |
5601 | | |
5602 | | |
5603 | | /** |
5604 | | * Set a peer's role. |
5605 | | * |
5606 | | * This function will first remove the peer's previous role and then assign them a new role. |
5607 | | * It will also send a packet to the rest of the group, requesting that they perform |
5608 | | * the role reassignment. Note: peers cannot be set to the founder role. |
5609 | | * |
5610 | | * @param group_number The group number of the group the in which you wish set the peer's role. |
5611 | | * @param peer_id The ID of the peer whose role you wish to set. |
5612 | | * @param role The role you wish to set the peer to. |
5613 | | * |
5614 | | * @return true on success. |
5615 | | */ |
5616 | | bool tox_group_mod_set_role(Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, Tox_Group_Role role, |
5617 | | Tox_Err_Group_Mod_Set_Role *error); |
5618 | | |
5619 | | typedef enum Tox_Err_Group_Mod_Kick_Peer { |
5620 | | |
5621 | | /** |
5622 | | * The function returned successfully. |
5623 | | */ |
5624 | | TOX_ERR_GROUP_MOD_KICK_PEER_OK, |
5625 | | |
5626 | | /** |
5627 | | * The group number passed did not designate a valid group. |
5628 | | */ |
5629 | | TOX_ERR_GROUP_MOD_KICK_PEER_GROUP_NOT_FOUND, |
5630 | | |
5631 | | /** |
5632 | | * The ID passed did not designate a valid peer. |
5633 | | */ |
5634 | | TOX_ERR_GROUP_MOD_KICK_PEER_PEER_NOT_FOUND, |
5635 | | |
5636 | | /** |
5637 | | * The caller does not have the required permissions for this action. |
5638 | | */ |
5639 | | TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS, |
5640 | | |
5641 | | /** |
5642 | | * The peer could not be kicked from the group. |
5643 | | */ |
5644 | | TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_ACTION, |
5645 | | |
5646 | | /** |
5647 | | * The packet failed to send. |
5648 | | */ |
5649 | | TOX_ERR_GROUP_MOD_KICK_PEER_FAIL_SEND, |
5650 | | |
5651 | | /** |
5652 | | * The caller attempted to set their own role. |
5653 | | */ |
5654 | | TOX_ERR_GROUP_MOD_KICK_PEER_SELF, |
5655 | | |
5656 | | } Tox_Err_Group_Mod_Kick_Peer; |
5657 | | |
5658 | | const char *tox_err_group_mod_kick_peer_to_string(Tox_Err_Group_Mod_Kick_Peer value); |
5659 | | |
5660 | | |
5661 | | /** |
5662 | | * Kick a peer. |
5663 | | * |
5664 | | * This function will remove a peer from the caller's peer list and send a packet to all |
5665 | | * group members requesting them to do the same. Note: This function will not trigger |
5666 | | * the `group_peer_exit` event for the caller. |
5667 | | * |
5668 | | * @param group_number The group number of the group the action is intended for. |
5669 | | * @param peer_id The ID of the peer who will be kicked. |
5670 | | * |
5671 | | * @return true on success. |
5672 | | */ |
5673 | | bool tox_group_mod_kick_peer(const Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number peer_id, |
5674 | | Tox_Err_Group_Mod_Kick_Peer *error); |
5675 | | |
5676 | | /** |
5677 | | * Represents moderation events. These should be used with the `group_moderation` event. |
5678 | | */ |
5679 | | typedef enum Tox_Group_Mod_Event { |
5680 | | |
5681 | | /** |
5682 | | * A peer has been kicked from the group. |
5683 | | */ |
5684 | | TOX_GROUP_MOD_EVENT_KICK, |
5685 | | |
5686 | | /** |
5687 | | * A peer as been given the observer role. |
5688 | | */ |
5689 | | TOX_GROUP_MOD_EVENT_OBSERVER, |
5690 | | |
5691 | | /** |
5692 | | * A peer has been given the user role. |
5693 | | */ |
5694 | | TOX_GROUP_MOD_EVENT_USER, |
5695 | | |
5696 | | /** |
5697 | | * A peer has been given the moderator role. |
5698 | | */ |
5699 | | TOX_GROUP_MOD_EVENT_MODERATOR, |
5700 | | |
5701 | | } Tox_Group_Mod_Event; |
5702 | | |
5703 | | const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value); |
5704 | | |
5705 | | |
5706 | | /** |
5707 | | * @param group_number The group number of the group the event is intended for. |
5708 | | * @param source_peer_id The ID of the peer who initiated the event. |
5709 | | * @param target_peer_id The ID of the peer who is the target of the event. |
5710 | | * @param mod_type The type of event. |
5711 | | */ |
5712 | | typedef void tox_group_moderation_cb( |
5713 | | Tox *tox, Tox_Group_Number group_number, Tox_Group_Peer_Number source_peer_id, Tox_Group_Peer_Number target_peer_id, |
5714 | | Tox_Group_Mod_Event mod_type, void *user_data); |
5715 | | |
5716 | | |
5717 | | /** |
5718 | | * Set the callback for the `group_moderation` event. Pass NULL to unset. |
5719 | | * |
5720 | | * This event is triggered when a moderator or founder executes a moderation event, with |
5721 | | * the exception of the peer who initiates the event. It is also triggered when the |
5722 | | * observer and moderator lists are silently modified (this may occur during group syncing). |
5723 | | * |
5724 | | * If either peer id does not designate a valid peer in the group chat, the client should |
5725 | | * manually update all peer roles. |
5726 | | */ |
5727 | | void tox_callback_group_moderation(Tox *tox, tox_group_moderation_cb *callback); |
5728 | | |
5729 | | /** @} */ |
5730 | | |
5731 | | /** @} */ |
5732 | | |
5733 | | #ifdef __cplusplus |
5734 | | } /* extern "C" */ |
5735 | | #endif |
5736 | | |
5737 | | //!TOKSTYLE- |
5738 | | #ifndef DOXYGEN_IGNORE |
5739 | | |
5740 | | typedef Tox_Err_Options_New TOX_ERR_OPTIONS_NEW; |
5741 | | typedef Tox_Err_New TOX_ERR_NEW; |
5742 | | typedef Tox_Err_Bootstrap TOX_ERR_BOOTSTRAP; |
5743 | | typedef Tox_Err_Set_Info TOX_ERR_SET_INFO; |
5744 | | typedef Tox_Err_Friend_Add TOX_ERR_FRIEND_ADD; |
5745 | | typedef Tox_Err_Friend_Delete TOX_ERR_FRIEND_DELETE; |
5746 | | typedef Tox_Err_Friend_By_Public_Key TOX_ERR_FRIEND_BY_PUBLIC_KEY; |
5747 | | typedef Tox_Err_Friend_Get_Public_Key TOX_ERR_FRIEND_GET_PUBLIC_KEY; |
5748 | | typedef Tox_Err_Friend_Get_Last_Online TOX_ERR_FRIEND_GET_LAST_ONLINE; |
5749 | | typedef Tox_Err_Friend_Query TOX_ERR_FRIEND_QUERY; |
5750 | | typedef Tox_Err_Set_Typing TOX_ERR_SET_TYPING; |
5751 | | typedef Tox_Err_Friend_Send_Message TOX_ERR_FRIEND_SEND_MESSAGE; |
5752 | | typedef Tox_Err_File_Control TOX_ERR_FILE_CONTROL; |
5753 | | typedef Tox_Err_File_Seek TOX_ERR_FILE_SEEK; |
5754 | | typedef Tox_Err_File_Get TOX_ERR_FILE_GET; |
5755 | | typedef Tox_Err_File_Send TOX_ERR_FILE_SEND; |
5756 | | typedef Tox_Err_File_Send_Chunk TOX_ERR_FILE_SEND_CHUNK; |
5757 | | typedef Tox_Err_Conference_New TOX_ERR_CONFERENCE_NEW; |
5758 | | typedef Tox_Err_Conference_Delete TOX_ERR_CONFERENCE_DELETE; |
5759 | | typedef Tox_Err_Conference_Peer_Query TOX_ERR_CONFERENCE_PEER_QUERY; |
5760 | | typedef Tox_Err_Conference_Set_Max_Offline TOX_ERR_CONFERENCE_SET_MAX_OFFLINE; |
5761 | | typedef Tox_Err_Conference_By_Id TOX_ERR_CONFERENCE_BY_ID; |
5762 | | typedef Tox_Err_Conference_By_Uid TOX_ERR_CONFERENCE_BY_UID; |
5763 | | typedef Tox_Err_Conference_Invite TOX_ERR_CONFERENCE_INVITE; |
5764 | | typedef Tox_Err_Conference_Join TOX_ERR_CONFERENCE_JOIN; |
5765 | | typedef Tox_Err_Conference_Send_Message TOX_ERR_CONFERENCE_SEND_MESSAGE; |
5766 | | typedef Tox_Err_Conference_Title TOX_ERR_CONFERENCE_TITLE; |
5767 | | typedef Tox_Err_Conference_Get_Type TOX_ERR_CONFERENCE_GET_TYPE; |
5768 | | typedef Tox_Err_Friend_Custom_Packet TOX_ERR_FRIEND_CUSTOM_PACKET; |
5769 | | typedef Tox_Err_Get_Port TOX_ERR_GET_PORT; |
5770 | | typedef Tox_User_Status TOX_USER_STATUS; |
5771 | | typedef Tox_Message_Type TOX_MESSAGE_TYPE; |
5772 | | typedef Tox_Proxy_Type TOX_PROXY_TYPE; |
5773 | | typedef Tox_Savedata_Type TOX_SAVEDATA_TYPE; |
5774 | | typedef Tox_Log_Level TOX_LOG_LEVEL; |
5775 | | typedef Tox_Connection TOX_CONNECTION; |
5776 | | typedef Tox_File_Control TOX_FILE_CONTROL; |
5777 | | typedef Tox_Conference_Type TOX_CONFERENCE_TYPE; |
5778 | | typedef enum Tox_File_Kind TOX_FILE_KIND; |
5779 | | |
5780 | | #endif |
5781 | | //!TOKSTYLE+ |
5782 | | |
5783 | | #endif /* C_TOXCORE_TOXCORE_TOX_H */ |