Coverage Report

Created: 2025-10-08 19:34

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