forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 291
/
Copy pathtox.h
5373 lines (4538 loc) · 165 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-2025 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.
*
* @section deprecations
*
* Some functions and types are deprecated. We recommend compiling with
* `-DTOX_HIDE_DEPRECATED` to hide them. They will be removed in the next major
* version of Tox (and since we're in major version 0, that means the next
* minor version).
*/
#ifndef C_TOXCORE_TOXCORE_TOX_H
#define C_TOXCORE_TOXCORE_TOX_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "tox_options.h" // IWYU pragma: export
#ifdef __cplusplus
extern "C" {
#endif
/** @{ @namespace tox */
/**
* @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;
/** @{
* @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 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);
/**
* @brief Protocols that can be used to connect to the network or friends.
*/
typedef enum Tox_Connection {
/**
* @brief There is no connection.
*
* This instance, or the friend the state change is about, is now offline.
*/
TOX_CONNECTION_NONE,
/**
* @brief A TCP connection has been established.
*
* For the own instance, this means it is connected through a TCP relay,
* only. For a friend, this means that the connection to that particular
* friend goes through a TCP relay.
*/
TOX_CONNECTION_TCP,
/**
* @brief A UDP connection has been established.
*
* For the own instance, this means it is able to send UDP packets to DHT
* nodes, but may still be connected to a TCP relay. For a friend, this
* means that the connection to that particular friend was built using
* direct UDP packets.
*/
TOX_CONNECTION_UDP,
} Tox_Connection;
const char *tox_connection_to_string(Tox_Connection value);
/**
* @brief Return whether we are connected to the DHT.
*
* The return value is equal to the last value received through the
* `self_connection_status` callback.
*
* @deprecated This getter is deprecated. Use the event and store the status
* in the client state.
*/
Tox_Connection tox_self_get_connection_status(const Tox *tox);
/**
* @param connection_status Whether we are connected to the DHT.
*/
typedef void tox_self_connection_status_cb(Tox *tox, Tox_Connection connection_status, void *user_data);
/**
* @brief Set the callback for the `self_connection_status` event.
*
* Pass NULL to unset.
*
* This event is triggered whenever there is a change in the DHT connection
* state. When disconnected, a client may choose to call tox_bootstrap again, to
* reconnect to the DHT. Note that this state may frequently change for short
* amounts of time. Clients should therefore not immediately bootstrap on
* receiving a disconnect.
*
* TODO(iphydf): how long should a client wait before bootstrapping again?
*/
void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback);
/**
* @brief Return the time in milliseconds before `tox_iterate()` should be
* called again for optimal performance.
*/
uint32_t tox_iteration_interval(const Tox *tox);
/**
* @brief The main loop that needs to be run in intervals of
* `tox_iteration_interval()` milliseconds.
* @param user_data Any pointer a client wishes the Tox instance to pass into
* the event callbacks, including NULL.
*/
void tox_iterate(Tox *tox, void *user_data);
/** @} */
/** @{
* @name Internal client information (Tox address/id)
*/
/**
* @brief Writes the Tox friend address of the client to a byte array.
*
* The address is not in human-readable format. If a client wants to display
* the address, formatting is required.
*
* @param address A memory region of at least TOX_ADDRESS_SIZE bytes. If this
* parameter is NULL, this function has no effect.
* @see TOX_ADDRESS_SIZE for the address format.
*/
void tox_self_get_address(const Tox *tox, uint8_t address[TOX_ADDRESS_SIZE]);
/**
* @brief Set the 4-byte nospam part of the address.
*
* This value is expected in host byte order. I.e. 0x12345678 will form the
* bytes `[12, 34, 56, 78]` in the nospam part of the Tox friend address.
*
* @param nospam Any 32 bit unsigned integer.
*/
void tox_self_set_nospam(Tox *tox, uint32_t nospam);
/**
* @brief Get the 4-byte nospam part of the address.
*
* This value is returned in host byte order.
*/
uint32_t tox_self_get_nospam(const Tox *tox);
/**
* @brief Copy the Tox Public Key (long term) from the Tox object.
*
* @param public_key A memory region of at least TOX_PUBLIC_KEY_SIZE bytes. If
* this parameter is NULL, this function has no effect.
*/
void tox_self_get_public_key(const Tox *tox, uint8_t public_key[TOX_PUBLIC_KEY_SIZE]);
/**
* @brief Copy the Tox Secret Key from the Tox object.
*
* @param secret_key A memory region of at least TOX_SECRET_KEY_SIZE bytes. If
* this parameter is NULL, this function has no effect.
*/
void tox_self_get_secret_key(const Tox *tox, uint8_t secret_key[TOX_SECRET_KEY_SIZE]);
/** @} */
/** @{
* @name User-visible client information (nickname/status)
*/
/**
* @brief Common error codes for all functions that set a piece of user-visible
* client information.
*/
typedef enum Tox_Err_Set_Info {
/**
* The function returned successfully.
*/
TOX_ERR_SET_INFO_OK,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_SET_INFO_NULL,
/**
* Information length exceeded maximum permissible size.
*/
TOX_ERR_SET_INFO_TOO_LONG,
} Tox_Err_Set_Info;
const char *tox_err_set_info_to_string(Tox_Err_Set_Info value);
/**
* @brief Set the nickname for the Tox client.
*
* Nickname length cannot exceed TOX_MAX_NAME_LENGTH. If length is 0, the name
* parameter is ignored (it can be NULL), and the nickname is set back to empty.
*
* @param name A byte array containing the new nickname.
* @param length The size of the name byte array.
*
* @return true on success.
*/
bool tox_self_set_name(Tox *tox, const uint8_t name[], size_t length, Tox_Err_Set_Info *error);
/**
* @brief Return the length of the current nickname as passed to
* tox_self_set_name.
*
* If no nickname was set before calling this function, the name is empty,
* and this function returns 0.
*
* @see threading for concurrency implications.
*/
size_t tox_self_get_name_size(const Tox *tox);
/**
* @brief Write the nickname set by tox_self_set_name to a byte array.
*
* If no nickname was set before calling this function, the name is empty,
* and this function has no effect.
*
* Call tox_self_get_name_size to find out how much memory to allocate for
* the result.
*
* @param name A valid memory location large enough to hold the nickname.
* If this parameter is NULL, the function has no effect.
*/
void tox_self_get_name(const Tox *tox, uint8_t name[]);
/**
* @brief Set the client's status message.
*
* Status message length cannot exceed TOX_MAX_STATUS_MESSAGE_LENGTH. If
* length is 0, the status parameter is ignored (it can be NULL), and the
* user status is set back to empty.
*/
bool tox_self_set_status_message(
Tox *tox, const uint8_t status_message[], size_t length, Tox_Err_Set_Info *error);
/**
* @brief Return the length of the current status message as passed to
* tox_self_set_status_message.
*
* If no status message was set before calling this function, the status
* is empty, and this function returns 0.
*
* @see threading for concurrency implications.
*/
size_t tox_self_get_status_message_size(const Tox *tox);
/**
* @brief Write the status message set by tox_self_set_status_message to a byte
* array.
*
* If no status message was set before calling this function, the status is
* empty, and this function has no effect.
*
* Call tox_self_get_status_message_size to find out how much memory to allocate
* for the result.
*
* @param status_message A valid memory location large enough to hold the
* status message. If this parameter is NULL, the function has no effect.
*/
void tox_self_get_status_message(const Tox *tox, uint8_t status_message[]);
/**
* @brief Set the client's user status.
*
* @param status One of the user statuses listed in the enumeration above.
*/
void tox_self_set_status(Tox *tox, Tox_User_Status status);
/**
* @brief Returns the client's user status.
*/
Tox_User_Status tox_self_get_status(const Tox *tox);
/** @} */
/** @{
* @name Friend list management
*/
typedef uint32_t Tox_Friend_Number;
typedef enum Tox_Err_Friend_Add {
/**
* The function returned successfully.
*/
TOX_ERR_FRIEND_ADD_OK,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_FRIEND_ADD_NULL,
/**
* The length of the friend request message exceeded
* TOX_MAX_FRIEND_REQUEST_LENGTH.
*/
TOX_ERR_FRIEND_ADD_TOO_LONG,
/**
* The friend request message was empty. This, and the TOO_LONG code will
* never be returned from tox_friend_add_norequest.
*/
TOX_ERR_FRIEND_ADD_NO_MESSAGE,
/**
* The friend address belongs to the sending client.
*/
TOX_ERR_FRIEND_ADD_OWN_KEY,
/**
* A friend request has already been sent, or the address belongs to a
* friend that is already on the friend list.
*/
TOX_ERR_FRIEND_ADD_ALREADY_SENT,
/**
* The friend address checksum failed.
*/
TOX_ERR_FRIEND_ADD_BAD_CHECKSUM,
/**
* The friend was already there, but the nospam value was different.
*/
TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM,
/**
* A memory allocation failed when trying to increase the friend list size.
*/
TOX_ERR_FRIEND_ADD_MALLOC,
} Tox_Err_Friend_Add;
const char *tox_err_friend_add_to_string(Tox_Err_Friend_Add value);
/**
* @brief Add a friend to the friend list and send a friend request.
*
* A friend request message must be at least 1 byte long and at most
* TOX_MAX_FRIEND_REQUEST_LENGTH.
*
* Friend numbers are unique identifiers used in all functions that operate on
* friends. Once added, a friend number is stable for the lifetime of the Tox
* object. After saving the state and reloading it, the friend numbers may not
* be the same as before. Deleting a friend creates a gap in the friend number
* set, which is filled by the next adding of a friend. Any pattern in friend
* numbers should not be relied on.
*
* If more than INT32_MAX friends are added, this function causes undefined
* behaviour.
*
* @param address The address of the friend (returned by tox_self_get_address of
* the friend you wish to add) it must be TOX_ADDRESS_SIZE bytes.
* @param message The message that will be sent along with the friend request.
* @param length The length of the data byte array.
*
* @return the friend number on success, an unspecified value on failure.
*/
Tox_Friend_Number tox_friend_add(
Tox *tox, const uint8_t address[TOX_ADDRESS_SIZE],
const uint8_t message[], size_t length,
Tox_Err_Friend_Add *error);
/**
* @brief Add a friend without sending a friend request.
*
* This function is used to add a friend in response to a friend request. If the
* client receives a friend request, it can be reasonably sure that the other
* client added this client as a friend, eliminating the need for a friend
* request.
*
* This function is also useful in a situation where both instances are
* controlled by the same entity, so that this entity can perform the mutual
* friend adding. In this case, there is no need for a friend request, either.
*
* @param public_key A byte array of length TOX_PUBLIC_KEY_SIZE containing the
* Public Key (not the Address) of the friend to add.
*
* @return the friend number on success, an unspecified value on failure.
* @see tox_friend_add for a more detailed description of friend numbers.
*/
Tox_Friend_Number tox_friend_add_norequest(
Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_Add *error);
typedef enum Tox_Err_Friend_Delete {
/**
* The function returned successfully.
*/
TOX_ERR_FRIEND_DELETE_OK,
/**
* There was no friend with the given friend number. No friends were
* deleted.
*/
TOX_ERR_FRIEND_DELETE_FRIEND_NOT_FOUND,
} Tox_Err_Friend_Delete;
const char *tox_err_friend_delete_to_string(Tox_Err_Friend_Delete value);
/**
* @brief Remove a friend from the friend list.
*
* This does not notify the friend of their deletion. After calling this
* function, this client will appear offline to the friend and no communication
* can occur between the two.
*
* @param friend_number Friend number for the friend to be deleted.
*
* @return true on success.
*/
bool tox_friend_delete(Tox *tox, Tox_Friend_Number friend_number, Tox_Err_Friend_Delete *error);
/** @} */
/** @{
* @name Friend list queries
*/
typedef enum Tox_Err_Friend_By_Public_Key {
/**
* The function returned successfully.
*/
TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK,
/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL,
/**
* No friend with the given Public Key exists on the friend list.
*/
TOX_ERR_FRIEND_BY_PUBLIC_KEY_NOT_FOUND,
} Tox_Err_Friend_By_Public_Key;
const char *tox_err_friend_by_public_key_to_string(Tox_Err_Friend_By_Public_Key value);
/**
* @brief Return the friend number associated with that Public Key.
*
* @param public_key A byte array containing the Public Key.
*
* @return the friend number on success, an unspecified value on failure.
*/
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);
/**