forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 289
/
tox.h
5788 lines (4865 loc) · 178 KB
/
tox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2024 The TokTok team.
* Copyright © 2013 Tox project.
*/
/** @file
* @brief Public core API for Tox clients.
*
* Every function that can fail takes a function-specific error code pointer
* that can be used to diagnose problems with the Tox state or the function
* arguments. The error code pointer can be NULL, which does not influence the
* function's behaviour, but can be done if the reason for failure is irrelevant
* to the client.
*
* The exception to this rule are simple allocation functions whose only failure
* mode is allocation failure. They return NULL in that case, and do not set an
* error code.
*
* Every error code type has an OK value to which functions will set their error
* code value on success. Clients can keep their error code uninitialised before
* passing it to a function. The library guarantees that after returning, the
* value pointed to by the error code pointer has been initialised.
*
* Functions with pointer parameters often have a NULL error code, meaning they
* could not perform any operation, because one of the required parameters was
* NULL. Some functions operate correctly or are defined as effectless on NULL.
*
* Some functions additionally return a value outside their return type domain,
* or a bool containing true on success and false on failure.
*
* All functions that take a Tox instance pointer will cause undefined behaviour
* when passed a NULL Tox pointer.
*
* All integer values are expected in host byte order.
*
* Functions with parameters with enum types cause unspecified behaviour if the
* enumeration value is outside the valid range of the type. If possible, the
* function will try to use a sane default, but there will be no error code,
* and one possible action for the function to take is to have no effect.
*
* Integer constants and the memory layout of publicly exposed structs are not
* part of the ABI.
*
* @section events Events and callbacks
*
* Events are handled by callbacks. One callback can be registered per event.
* All events have a callback function type named `tox_{event}_cb` and a
* function to register it named `tox_callback_{event}`. Passing a NULL
* callback will result in no callback being registered for that event. Only
* one callback per event can be registered, so if a client needs multiple
* event listeners, it needs to implement the dispatch functionality itself.
*
* The last argument to a callback is the user data pointer. It is passed from
* tox_iterate to each callback in sequence. The user data pointer is never
* stored or dereferenced by any library code, so can be any pointer, including
* NULL.
*
* @section threading Threading implications
*
* It is possible to run multiple concurrent threads with a Tox instance for
* each thread. It is also possible to run all Tox instances in the same thread.
* A common way to run Tox (multiple or single instance) is to have one thread
* running a simple tox_iterate loop, sleeping for tox_iteration_interval
* milliseconds on each iteration.
*
* If you want to access a single Tox instance from multiple threads, access
* to the instance must be synchronised. While multiple threads can concurrently
* access multiple different Tox instances, no more than one API function can
* operate on a single instance at any given time.
*
* Functions that write to variable length byte arrays will always have a size
* function associated with them. The result of this size function is only valid
* until another mutating function (one that takes a pointer to non-const Tox)
* is called. Thus, clients must ensure that no other thread calls a mutating
* function between the call to the size function and the call to the retrieval
* function.
*
* E.g. to get the current nickname, one would write
*
* @code
* size_t length = tox_self_get_name_size(tox);
* uint8_t *name = malloc(length);
* if (!name) abort();
* tox_self_get_name(tox, name);
* @endcode
*
* If any other thread calls tox_self_set_name while this thread is allocating
* memory, the length may have become invalid, and the call to
* tox_self_get_name may cause undefined behaviour.
*/
#ifndef C_TOXCORE_TOXCORE_TOX_H
#define C_TOXCORE_TOXCORE_TOX_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/** @{ @namespace tox */
#ifndef TOX_DEFINED
#define TOX_DEFINED
/**
* @brief The Tox instance type.
*
* All the state associated with a connection is held
* within the instance. Multiple instances can exist and operate concurrently.
* The maximum number of Tox instances that can exist on a single network
* device is limited. Note that this is not just a per-process limit, since the
* limiting factor is the number of usable ports on a device.
*/
typedef struct Tox Tox;
#endif /* TOX_DEFINED */
/** @{
* @name API version
*/
/**
* @brief The major version number.
*
* Incremented when the API or ABI changes in an incompatible way.
*
* The function variants of these constants return the version number of the
* library. They can be used to display the Tox library version or to check
* whether the client is compatible with the dynamically linked version of Tox.
*/
#define TOX_VERSION_MAJOR 0
uint32_t tox_version_major(void);
/**
* @brief The minor version number.
*
* Incremented when functionality is added without breaking the API or ABI.
* Set to 0 when the major version number is incremented.
*/
#define TOX_VERSION_MINOR 2
uint32_t tox_version_minor(void);
/**
* @brief The patch or revision number.
*
* Incremented when bugfixes are applied without changing any functionality or
* API or ABI.
*/
#define TOX_VERSION_PATCH 20
uint32_t tox_version_patch(void);
//!TOKSTYLE-
/**
* @brief A macro to check at preprocessing time whether the client code is
* compatible with the installed version of Tox.
*
* Leading zeros in the version number are ignored. E.g. 0.1.5 is to 0.1.4
* what 1.5 is to 1.4, that is: it can add new features, but can't break the
* API.
*/
#define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \
((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \
/* 1.x.x, 2.x.x, etc. with matching major version. */ \
TOX_VERSION_MINOR > MINOR || \
(TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \
)) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \
/* 0.x.x makes minor behave like major above. */ \
((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \
TOX_VERSION_PATCH >= PATCH \
)) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \
/* 0.0.x and 0.0.y are only compatible if x == y. */ \
TOX_VERSION_PATCH == PATCH \
)) \
))
//!TOKSTYLE+
/**
* @brief Return whether the compiled library version is compatible with the
* passed version numbers.
*/
bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch);
/**
* @brief A convenience macro to call tox_version_is_compatible with the
* currently compiling API version.
*/
#define TOX_VERSION_IS_ABI_COMPATIBLE() \
tox_version_is_compatible(TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH)
/** @} */
/** @{
* @name Numeric constants
*
* The values of these are not part of the ABI. Prefer to use the function
* versions of them for code that should remain compatible with future versions
* of the Tox library.
*/
/**
* @brief The size of a Tox Public Key in bytes.
*/
#define TOX_PUBLIC_KEY_SIZE 32
uint32_t tox_public_key_size(void);
/**
* @brief The size of a Tox Secret Key in bytes.
*/
#define TOX_SECRET_KEY_SIZE 32
uint32_t tox_secret_key_size(void);
/**
* @brief The size of a Tox Conference unique id in bytes.
*
* @deprecated Use TOX_CONFERENCE_ID_SIZE instead.
*/
#define TOX_CONFERENCE_UID_SIZE 32
uint32_t tox_conference_uid_size(void);
/**
* @brief The size of a Tox Conference unique id in bytes.
*/
#define TOX_CONFERENCE_ID_SIZE 32
uint32_t tox_conference_id_size(void);
/**
* @brief The size of the nospam in bytes when written in a Tox address.
*/
#define TOX_NOSPAM_SIZE (sizeof(uint32_t))
uint32_t tox_nospam_size(void);
/**
* @brief The size of a Tox address in bytes.
*
* Tox addresses are in the format
* `[Public Key (TOX_PUBLIC_KEY_SIZE bytes)][nospam (4 bytes)][checksum (2 bytes)]`.
*
* The checksum is computed over the Public Key and the nospam value. The first
* byte is an XOR of all the even bytes (0, 2, 4, ...), the second byte is an
* XOR of all the odd bytes (1, 3, 5, ...) of the Public Key and nospam.
*/
#define TOX_ADDRESS_SIZE (TOX_PUBLIC_KEY_SIZE + TOX_NOSPAM_SIZE + sizeof(uint16_t))
uint32_t tox_address_size(void);
/**
* @brief Maximum length of a nickname in bytes.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_NAME_LENGTH 128
uint32_t tox_max_name_length(void);
/**
* @brief Maximum length of a status message in bytes.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_STATUS_MESSAGE_LENGTH 1007
uint32_t tox_max_status_message_length(void);
/**
* @brief Maximum length of a friend request message in bytes.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_FRIEND_REQUEST_LENGTH 921
uint32_t tox_max_friend_request_length(void);
/**
* @brief Maximum length of a single message after which it should be split.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_MESSAGE_LENGTH 1372
uint32_t tox_max_message_length(void);
/**
* @brief Maximum size of custom packets. TODO(iphydf): should be LENGTH?
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_CUSTOM_PACKET_SIZE 1373
uint32_t tox_max_custom_packet_size(void);
/**
* @brief The number of bytes in a hash generated by tox_hash.
*/
#define TOX_HASH_LENGTH 32
uint32_t tox_hash_length(void);
/**
* @brief The number of bytes in a file id.
*/
#define TOX_FILE_ID_LENGTH 32
uint32_t tox_file_id_length(void);
/**
* @brief Maximum file name length for file transfers.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_FILENAME_LENGTH 255
uint32_t tox_max_filename_length(void);
/**
* @brief Maximum length of a hostname, e.g. proxy or bootstrap node names.
*
* This length does not include the NUL byte. Hostnames are NUL-terminated C
* strings, so they are 255 characters plus one NUL byte.
*
* @deprecated The macro will be removed in 0.3.0. Use the function instead.
*/
#define TOX_MAX_HOSTNAME_LENGTH 255
uint32_t tox_max_hostname_length(void);
/** @} */
/** @{
* @name Global enumerations
*/
/**
* @brief Represents the possible statuses a client can have.
*/
typedef enum Tox_User_Status {
/**
* User is online and available.
*/
TOX_USER_STATUS_NONE,
/**
* User is away. Clients can set this e.g. after a user defined
* inactivity time.
*/
TOX_USER_STATUS_AWAY,
/**
* User is busy. Signals to other clients that this client does not
* currently wish to communicate.
*/
TOX_USER_STATUS_BUSY,
} Tox_User_Status;
const char *tox_user_status_to_string(Tox_User_Status value);
/**
* @brief Represents message types for tox_friend_send_message and conference
* messages.
*/
typedef enum Tox_Message_Type {
/**
* Normal text message. Similar to PRIVMSG on IRC.
*/
TOX_MESSAGE_TYPE_NORMAL,
/**
* A message describing an user action. This is similar to /me (CTCP ACTION)
* on IRC.
*/
TOX_MESSAGE_TYPE_ACTION,
} Tox_Message_Type;
const char *tox_message_type_to_string(Tox_Message_Type value);
/** @} */
/** @{
* @name Startup options
*/
/**
* @brief Type of proxy used to connect to TCP relays.
*/
typedef enum Tox_Proxy_Type {
/**
* Don't use a proxy.
*/
TOX_PROXY_TYPE_NONE,
/**
* HTTP proxy using CONNECT.
*/
TOX_PROXY_TYPE_HTTP,
/**
* SOCKS proxy for simple socket pipes.
*/
TOX_PROXY_TYPE_SOCKS5,
} Tox_Proxy_Type;
const char *tox_proxy_type_to_string(Tox_Proxy_Type value);
/**
* @brief Type of savedata to create the Tox instance from.
*/
typedef enum Tox_Savedata_Type {
/**
* No savedata.
*/
TOX_SAVEDATA_TYPE_NONE,
/**
* Savedata is one that was obtained from tox_get_savedata.
*/
TOX_SAVEDATA_TYPE_TOX_SAVE,
/**
* Savedata is a secret key of length TOX_SECRET_KEY_SIZE.
*/
TOX_SAVEDATA_TYPE_SECRET_KEY,
} Tox_Savedata_Type;
const char *tox_savedata_type_to_string(Tox_Savedata_Type value);
/**
* @brief Severity level of log messages.
*/
typedef enum Tox_Log_Level {
/**
* Very detailed traces including all network activity.
*/
TOX_LOG_LEVEL_TRACE,
/**
* Debug messages such as which port we bind to.
*/
TOX_LOG_LEVEL_DEBUG,
/**
* Informational log messages such as video call status changes.
*/
TOX_LOG_LEVEL_INFO,
/**
* Warnings about internal inconsistency or logic errors.
*/
TOX_LOG_LEVEL_WARNING,
/**
* Severe unexpected errors caused by external or internal inconsistency.
*/
TOX_LOG_LEVEL_ERROR,
} Tox_Log_Level;
const char *tox_log_level_to_string(Tox_Log_Level value);
/**
* @brief This event is triggered when Tox logs an internal message.
*
* This is mostly useful for debugging. This callback can be called from any
* function, not just tox_iterate. This means the user data lifetime must at
* least extend between registering and unregistering it or tox_kill.
*
* Other toxcore modules such as toxav may concurrently call this callback at
* any time. Thus, user code must make sure it is equipped to handle concurrent
* execution, e.g. by employing appropriate mutex locking.
*
* When using the experimental_thread_safety option, no Tox API functions can
* be called from within the log callback.
*
* @param level The severity of the log message.
* @param file The source file from which the message originated.
* @param line The source line from which the message originated.
* @param func The function from which the message originated.
* @param message The log message.
* @param user_data The user data pointer passed to tox_new in options.
*/
typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, const char *func,
const char *message, void *user_data);
/**
* @brief This struct contains all the startup options for Tox.
*
* You must tox_options_new to allocate an object of this type.
*
* WARNING: Although this struct happens to be visible in the API, it is
* effectively private. Do not allocate this yourself or access members
* directly, as it *will* break binary compatibility frequently.
*
* @deprecated The memory layout of this struct (size, alignment, and field
* order) is not part of the ABI. To remain compatible, prefer to use
* tox_options_new to allocate the object and accessor functions to set the
* members. The struct will become opaque (i.e. the definition will become
* private) in v0.3.0.
*/
typedef struct Tox_Options Tox_Options;
struct Tox_Options {
/**
* The type of socket to create.
*
* If this is set to false, an IPv4 socket is created, which subsequently
* only allows IPv4 communication.
* If it is set to true, an IPv6 socket is created, allowing both IPv4 and
* IPv6 communication.
*/
bool ipv6_enabled;
/**
* Enable the use of UDP communication when available.
*
* Setting this to false will force Tox to use TCP only. Communications will
* need to be relayed through a TCP relay node, potentially slowing them
* down.
*
* If a proxy is enabled, UDP will be disabled if either the Tox library or
* the proxy don't support proxying UDP messages.
*/
bool udp_enabled;
/**
* Enable local network peer discovery.
*
* Disabling this will cause Tox to not look for peers on the local network.
*/
bool local_discovery_enabled;
/**
* Enable storing DHT announcements and forwarding corresponding requests.
*
* Disabling this will cause Tox to ignore the relevant packets.
*/
bool dht_announcements_enabled;
/**
* Pass communications through a proxy.
*/
Tox_Proxy_Type proxy_type;
/**
* The IP address or DNS name of the proxy to be used.
*
* If used, this must be non-NULL and be a valid DNS name. The name must not
* exceed TOX_MAX_HOSTNAME_LENGTH characters, and be in a NUL-terminated C
* string format (TOX_MAX_HOSTNAME_LENGTH includes the NUL byte).
*
* This member is ignored (it can be NULL) if proxy_type is
* TOX_PROXY_TYPE_NONE.
*
* The data pointed at by this member is owned by the user, so must
* outlive the options object.
*/
const char *proxy_host;
/**
* The port to use to connect to the proxy server.
*
* Ports must be in the range (1, 65535). The value is ignored if
* proxy_type is TOX_PROXY_TYPE_NONE.
*/
uint16_t proxy_port;
/**
* The start port of the inclusive port range to attempt to use.
*
* If both start_port and end_port are 0, the default port range will be
* used: `[33445, 33545]`.
*
* If either start_port or end_port is 0 while the other is non-zero, the
* non-zero port will be the only port in the range.
*
* Having start_port > end_port will yield the same behavior as if
* start_port and end_port were swapped.
*/
uint16_t start_port;
/**
* The end port of the inclusive port range to attempt to use.
*/
uint16_t end_port;
/**
* The port to use for the TCP server (relay). If 0, the TCP server is
* disabled.
*
* Enabling it is not required for Tox to function properly.
*
* When enabled, your Tox instance can act as a TCP relay for other Tox
* instance. This leads to increased traffic, thus when writing a client
* it is recommended to enable TCP server only if the user has an option
* to disable it.
*/
uint16_t tcp_port;
/**
* Enables or disables UDP hole-punching. (Default: enabled).
*/
bool hole_punching_enabled;
/**
* The type of savedata to load from.
*/
Tox_Savedata_Type savedata_type;
/**
* The savedata.
*
* The data pointed at by this member is owned by the user, so must outlive
* the options object.
*/
const uint8_t *savedata_data;
/**
* The length of the savedata.
*/
size_t savedata_length;
/**
* Logging callback for the new Tox instance.
*/
tox_log_cb *log_callback;
/**
* User data pointer passed to the logging callback.
*/
void *log_user_data;
/**
* These options are experimental, so avoid writing code that depends on
* them. Options marked "experimental" may change their behaviour or go away
* entirely in the future, or may be renamed to something non-experimental
* if they become part of the supported API.
*/
/**
* Make public API functions thread-safe using a per-instance lock.
*
* Default: false.
*/
bool experimental_thread_safety;
/**
* Enable saving DHT-based group chats to Tox save data (via
* `tox_get_savedata`). This format will change in the future, so don't rely
* on it.
*
* As an alternative, clients can save the group chat ID in client-owned
* savedata. Then, when the client starts, it can use `tox_group_join`
* with the saved chat ID to recreate the group chat.
*
* Default: false.
*/
bool experimental_groups_persistence;
/**
* @brief Disable DNS hostname resolution.
*
* Hostnames or IP addresses are passed to the bootstrap/add_tcp_relay
* function and proxy host options. If disabled (this flag is true), only
* IP addresses are allowed.
*
* If this is set to true, the library will not attempt to resolve
* hostnames. This is useful for clients that want to resolve hostnames
* themselves and pass the resolved IP addresses to the library (e.g. in
* case it wants to use Tor).
* Passing hostnames will result in a TOX_ERR_BOOTSTRAP_BAD_HOST error if
* this is set to true.
*
* Default: false. May become true in the future (0.3.0).
*/
bool experimental_disable_dns;
};
bool tox_options_get_ipv6_enabled(const Tox_Options *options);
void tox_options_set_ipv6_enabled(Tox_Options *options, bool ipv6_enabled);
bool tox_options_get_udp_enabled(const Tox_Options *options);
void tox_options_set_udp_enabled(Tox_Options *options, bool udp_enabled);
bool tox_options_get_local_discovery_enabled(const Tox_Options *options);
void tox_options_set_local_discovery_enabled(Tox_Options *options, bool local_discovery_enabled);
bool tox_options_get_dht_announcements_enabled(const Tox_Options *options);
void tox_options_set_dht_announcements_enabled(Tox_Options *options, bool dht_announcements_enabled);
Tox_Proxy_Type tox_options_get_proxy_type(const Tox_Options *options);
void tox_options_set_proxy_type(Tox_Options *options, Tox_Proxy_Type proxy_type);
const char *tox_options_get_proxy_host(const Tox_Options *options);
void tox_options_set_proxy_host(Tox_Options *options, const char *proxy_host);
uint16_t tox_options_get_proxy_port(const Tox_Options *options);
void tox_options_set_proxy_port(Tox_Options *options, uint16_t proxy_port);
uint16_t tox_options_get_start_port(const Tox_Options *options);
void tox_options_set_start_port(Tox_Options *options, uint16_t start_port);
uint16_t tox_options_get_end_port(const Tox_Options *options);
void tox_options_set_end_port(Tox_Options *options, uint16_t end_port);
uint16_t tox_options_get_tcp_port(const Tox_Options *options);
void tox_options_set_tcp_port(Tox_Options *options, uint16_t tcp_port);
bool tox_options_get_hole_punching_enabled(const Tox_Options *options);
void tox_options_set_hole_punching_enabled(Tox_Options *options, bool hole_punching_enabled);
Tox_Savedata_Type tox_options_get_savedata_type(const Tox_Options *options);
void tox_options_set_savedata_type(Tox_Options *options, Tox_Savedata_Type savedata_type);
const uint8_t *tox_options_get_savedata_data(const Tox_Options *options);
void tox_options_set_savedata_data(Tox_Options *options, const uint8_t savedata_data[], size_t length);
size_t tox_options_get_savedata_length(const Tox_Options *options);
void tox_options_set_savedata_length(Tox_Options *options, size_t savedata_length);
tox_log_cb *tox_options_get_log_callback(const Tox_Options *options);
void tox_options_set_log_callback(Tox_Options *options, tox_log_cb *log_callback);
void *tox_options_get_log_user_data(const Tox_Options *options);
void tox_options_set_log_user_data(Tox_Options *options, void *log_user_data);
bool tox_options_get_experimental_thread_safety(const Tox_Options *options);
void tox_options_set_experimental_thread_safety(Tox_Options *options, bool experimental_thread_safety);
bool tox_options_get_experimental_groups_persistence(const Tox_Options *options);
void tox_options_set_experimental_groups_persistence(Tox_Options *options, bool experimental_groups_persistence);
bool tox_options_get_experimental_disable_dns(const Tox_Options *options);
void tox_options_set_experimental_disable_dns(Tox_Options *options, bool experimental_disable_dns);
/**
* @brief Initialises a Tox_Options object with the default options.
*
* The result of this function is independent of the original options. All
* values will be overwritten, no values will be read (so it is permissible
* to pass an uninitialised object).
*
* If options is NULL, this function has no effect.
*
* @param options An options object to be filled with default options.
*/
void tox_options_default(Tox_Options *options);
typedef enum Tox_Err_Options_New {
/**
* The function returned successfully.
*/
TOX_ERR_OPTIONS_NEW_OK,
/**
* The function failed to allocate enough memory for the options struct.
*/
TOX_ERR_OPTIONS_NEW_MALLOC,
} Tox_Err_Options_New;
const char *tox_err_options_new_to_string(Tox_Err_Options_New value);
/**
* @brief Allocates a new Tox_Options object and initialises it with the default
* options.
*
* This function can be used to preserve long term ABI compatibility by
* giving the responsibility of allocation and deallocation to the Tox library.
*
* Objects returned from this function must be freed using the tox_options_free
* function.
*
* @return A new Tox_Options object with default options or NULL on failure.
*/
Tox_Options *tox_options_new(Tox_Err_Options_New *error);
/**
* @brief Releases all resources associated with an options objects.
*
* Passing a pointer that was not returned by tox_options_new results in
* undefined behaviour.
*/
void tox_options_free(Tox_Options *options);
/** @} */
/** @{
* @name Creation and destruction
*/
typedef enum Tox_Err_New {
/**
* The function returned successfully.
*/
TOX_ERR_NEW_OK,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_NEW_NULL,
/**
* The function was unable to allocate enough memory to store the
* internal structures for the Tox object.
*/
TOX_ERR_NEW_MALLOC,
/**
* The function was unable to bind to a port. This may mean that all ports
* have already been bound, e.g. by other Tox instances, or it may mean
* a permission error. You may be able to gather more information from
* errno.
*/
TOX_ERR_NEW_PORT_ALLOC,
/**
* proxy_type was invalid.
*/
TOX_ERR_NEW_PROXY_BAD_TYPE,
/**
* proxy_type was valid but the proxy_host passed had an invalid format
* or was NULL.
*/
TOX_ERR_NEW_PROXY_BAD_HOST,
/**
* proxy_type was valid, but the proxy_port was invalid.
*/
TOX_ERR_NEW_PROXY_BAD_PORT,
/**
* The proxy address passed could not be resolved.
*/
TOX_ERR_NEW_PROXY_NOT_FOUND,
/**
* The byte array to be loaded contained an encrypted save.
*/
TOX_ERR_NEW_LOAD_ENCRYPTED,
/**
* The data format was invalid. This can happen when loading data that was
* saved by an older version of Tox, or when the data has been corrupted.
* When loading from badly formatted data, some data may have been loaded,
* and the rest is discarded. Passing an invalid length parameter also
* causes this error.
*/
TOX_ERR_NEW_LOAD_BAD_FORMAT,
} Tox_Err_New;
const char *tox_err_new_to_string(Tox_Err_New value);
/**
* @brief Creates and initialises a new Tox instance with the options passed.
*
* This function will bring the instance into a valid state. Running the event
* loop with a new instance will operate correctly.
*
* @param options An options object as described above. If this parameter is
* NULL, the default options are used.
*
* @see tox_iterate for the event loop.
*
* @return A new Tox instance pointer on success or NULL on failure.
*/
Tox *tox_new(const Tox_Options *options, Tox_Err_New *error);
/**
* @brief Releases all resources associated with the Tox instance and
* disconnects from the network.
*
* After calling this function, the Tox pointer becomes invalid. No other
* functions can be called, and the pointer value can no longer be read.
*/
void tox_kill(Tox *tox);
/**
* @brief Calculates the number of bytes required to store the Tox instance with
* tox_get_savedata.
*
* This function cannot fail. The result is always greater than 0.
*
* @see threading for concurrency implications.
*/
size_t tox_get_savedata_size(const Tox *tox);
/**
* @brief Store all information associated with the Tox instance to a byte
* array.
*
* @param savedata A memory region large enough to store the Tox instance
* data. Call tox_get_savedata_size to find the number of bytes required. If
* this parameter is NULL, this function has no effect.
*/
void tox_get_savedata(const Tox *tox, uint8_t savedata[]);
/** @} */
/** @{
* @name Connection lifecycle and event loop
*/
typedef enum Tox_Err_Bootstrap {
/**
* The function returned successfully.
*/
TOX_ERR_BOOTSTRAP_OK,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_BOOTSTRAP_NULL,
/**
* The hostname could not be resolved to an IP address, the IP address
* passed was invalid, or the function failed to send the initial request
* packet to the bootstrap node or TCP relay.
*/
TOX_ERR_BOOTSTRAP_BAD_HOST,
/**
* The port passed was invalid. The valid port range is (1, 65535).
*/
TOX_ERR_BOOTSTRAP_BAD_PORT,
} Tox_Err_Bootstrap;
const char *tox_err_bootstrap_to_string(Tox_Err_Bootstrap value);
/**
* @brief Sends a "get nodes" request to the given bootstrap node with IP, port,
* and public key to setup connections.
*
* This function will attempt to connect to the node using UDP. You must use
* this function even if Tox_Options.udp_enabled was set to false.
*
* @param host The hostname or IP address (IPv4 or IPv6) of the node. Must be
* at most TOX_MAX_HOSTNAME_LENGTH chars, including the NUL byte.
* @param port The port on the host on which the bootstrap Tox instance is
* listening.
* @param public_key The long term public key of the bootstrap node
* (TOX_PUBLIC_KEY_SIZE bytes).
* @return true on success.
*/
bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Bootstrap *error);
/**
* @brief Adds additional host:port pair as TCP relay.
*
* This function can be used to initiate TCP connections to different ports on
* the same bootstrap node, or to add TCP relays without using them as
* bootstrap nodes.
*
* @param host The hostname or IP address (IPv4 or IPv6) of the TCP relay.
* Must be at most TOX_MAX_HOSTNAME_LENGTH chars, including the NUL byte.
* @param port The port on the host on which the TCP relay is listening.
* @param public_key The long term public key of the TCP relay
* (TOX_PUBLIC_KEY_SIZE bytes).
* @return true on success.
*/
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);
/**