Coverage Report

Created: 2026-10-24 08:16

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