git » swiftpm » main » tree

[main] / Sources / c_snikket / include / snikket.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
/**
 * \file snikket.h the Snikket SDK for C
 *
 * Everything returned from an SDK procedure or passed to a function
 * pointer, both strings and opaque types, must be passed to
 * snikket_release when you are done with it.
 */

#ifndef __SNIKKET_H
#define __SNIKKET_H

#ifndef MKDOCS
#include <stdbool.h>
#include <stddef.h>

#ifndef API_PREFIX
	#ifdef _WIN32
		#define API_PREFIX __declspec(dllimport)
	#else
		#define API_PREFIX
	#endif
#endif

#endif

typedef void (*snikket_panic_callback) (const char *info);

enum
#ifdef __clang__
__attribute__((enum_extensibility(closed)))
#endif
snikket_message_type {
	MessageChat = 0,
	MessageCall = 1,
	MessageChannel = 2,
	MessageChannelPrivate = 3
};

enum
#ifdef __clang__
__attribute__((enum_extensibility(closed)))
#endif
snikket_message_direction {
	MessageReceived = 0,
	MessageSent = 1
};

enum
#ifdef __clang__
__attribute__((enum_extensibility(closed)))
#endif
snikket_message_status {
	MessagePending = 0,
	MessageDeliveredToServer = 1,
	MessageDeliveredToDevice = 2,
	MessageFailedToSend = 3
};

enum
#ifdef __clang__
__attribute__((enum_extensibility(closed)))
#endif
snikket_ui_state {
	Pinned = 0,
	Open = 1,
	Closed = 2
};

enum
#ifdef __clang__
__attribute__((enum_extensibility(closed)))
#endif
snikket_jingle_call_status {
	NoCall = 0,
	Incoming = 1,
	Outgoing = 2,
	Connecting = 3,
	Ongoing = 4,
	Failed = 5
};

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initializes the SDK
 *
 * This must be first before calling SDK functions (otherwise those calls will hang waiting for a response).
 *
 * @param panicCallback a callback to execute if the SDK panics. The SDK will continue processing events after a panic and you may want to stop it after receiving this callback. Use `NULL` for no callback
 * @returns `NULL` if the thread initializes successfully or a null-terminated C string if an error occurs during initialization
 */
API_PREFIX const char *snikket_setup(snikket_panic_callback panic_callback);

/**
 * Stops the SDK, blocking until the main thread has completed. Once ended, it cannot be restarted (this is because static variable state will be retained from the last run).
 *
 * It can be safely called any number of times – if the SDK is not running this function will just return.
 *
 * After executing no more calls to SDK functions can be made (as these will hang waiting for a response).
 *
 * Thread-safety: Can be called safely called on any thread.
 *
 * @param wait If `true`, this function will wait for all events scheduled to execute in the future on the SDK thread to complete. If `false`, immediate pending events will be finished and the SDK stopped without executing events scheduled in the future
 */
API_PREFIX void snikket_stop(bool wait);

/**
 * Informs the garbage collector that object is no longer needed by the C code.
 * 
 * If the object has no remaining reference the garbage collector can free the associated memory (which can happen at any time in the future). It does not free the memory immediately.
 * 
 * Thread-safety: can be called on any thread.
 * 
 * @param ptr a handle to an arbitrary SDK object returned from an SDK function
 */
API_PREFIX void snikket_release(const void *ptr);

API_PREFIX void *snikket_persistence_media_store_f_s_new(const char *path);

API_PREFIX void snikket_persistence_media_store_f_s_get_media_path(void *media_store_fs, const char *uri, void (*callback) (const char*, void*), void *callback__context);

/**
 * Create a basic persistence layer based on sqlite
 * 
 * @param dbfile path to sqlite database
 * @params media a MediaStore to use for media
 * @returns new persistence layer
 */
API_PREFIX void *snikket_persistence_sqlite_new(const char *dbfile, void *media);

API_PREFIX void snikket_persistence_sqlite_get_message(void *sqlite, const char *accountId, const char *chatId, const char *serverId, const char *localId, void (*callback) (void*, void*), void *callback__context);

API_PREFIX void snikket_persistence_sqlite_remove_account(void *sqlite, const char *accountId, bool completely);

API_PREFIX void snikket_persistence_sqlite_list_accounts(void *sqlite, void (*callback) (const char**, size_t, void*), void *callback__context);

/**
 * The ID as set by the creator of this message
 */
API_PREFIX const char *snikket_chat_message_local_id(void *chat_message);

/**
 * The ID as set by the authoritative server
 */
API_PREFIX const char *snikket_chat_message_server_id(void *chat_message);

/**
 * The ID of the server which set the serverId
 */
API_PREFIX const char *snikket_chat_message_server_id_by(void *chat_message);

/**
 * The type of this message (Chat, Call, etc)
 */
API_PREFIX enum snikket_message_type snikket_chat_message_type(void *chat_message);

/**
 * The timestamp of this message, in format YYYY-MM-DDThh:mm:ss[.sss]Z
 */
API_PREFIX const char *snikket_chat_message_timestamp(void *chat_message);

/**
 * The ID of the sender of this message
 */
API_PREFIX const char *snikket_chat_message_sender_id(void *chat_message);

/**
 * Message this one is in reply to, or NULL
 */
API_PREFIX void *snikket_chat_message_reply_to_message(void *chat_message);

/**
 * ID of the thread this message is in, or NULL
 */
API_PREFIX const char *snikket_chat_message_thread_id(void *chat_message);

/**
 * Array of attachments to this message
 */
API_PREFIX size_t snikket_chat_message_attachments(void *chat_message, void ***outPtr);

/**
 * List of reactions to this message
 */
API_PREFIX size_t snikket_chat_message_reaction_keys(void *chat_message, const char ***outPtr);

/**
 * Details of a set of reaction to this message
 */
API_PREFIX size_t snikket_chat_message_reaction_details(void *chat_message, const char *reactionKey, void ***outPtr);

/**
 * Body text of this message or NULL
 */
API_PREFIX const char *snikket_chat_message_text(void *chat_message);

/**
 * Language code for the body text
 */
API_PREFIX const char *snikket_chat_message_lang(void *chat_message);

/**
 * Direction of this message
 */
API_PREFIX enum snikket_message_direction snikket_chat_message_direction(void *chat_message);

/**
 * Status of this message
 */
API_PREFIX enum snikket_message_status snikket_chat_message_status(void *chat_message);

/**
 * Status of this message
 */
API_PREFIX void snikket_chat_message_set_status(void *chat_message, enum snikket_message_status value);

/**
 * Array of past versions of this message, if it has been edited
 */
API_PREFIX size_t snikket_chat_message_versions(void *chat_message, void ***outPtr);

/**
 * Create a new ChatMessage in reply to this one
 */
API_PREFIX void *snikket_chat_message_reply(void *chat_message);

API_PREFIX const char *snikket_chat_message_get_reply_id(void *chat_message);

/**
 * Get HTML version of the message body
 * 
 * WARNING: this is possibly untrusted HTML. You must parse or sanitize appropriately!
 */
API_PREFIX const char *snikket_chat_message_html(void *chat_message);

/**
 * The ID of the Chat this message is associated with
 */
API_PREFIX const char *snikket_chat_message_chat_id(void *chat_message);

/**
 * The ID of the account associated with this message
 */
API_PREFIX const char *snikket_chat_message_account(void *chat_message);

/**
 * Is this an incoming message?
 */
API_PREFIX bool snikket_chat_message_is_incoming(void *chat_message);

/**
 * The URI of an icon for the thread associated with this message, or NULL
 */
API_PREFIX const char *snikket_chat_message_thread_icon(void *chat_message);

/**
 * The last status of the call if this message is related to a call
 */
API_PREFIX const char *snikket_chat_message_call_status(void *chat_message);

/**
 * The session id of the call if this message is related to a call
 */
API_PREFIX const char *snikket_chat_message_call_sid(void *chat_message);

/**
 * The duration of the call if this message is related to a call
 */
API_PREFIX const char *snikket_chat_message_call_duration(void *chat_message);

API_PREFIX void *snikket_chat_attachment_create(const char *name, const char *mime, int size, const char *uri);

API_PREFIX const char *snikket_chat_attachment_name(void *chat_attachment);

API_PREFIX const char *snikket_chat_attachment_mime(void *chat_attachment);

API_PREFIX int snikket_chat_attachment_size(void *chat_attachment);

API_PREFIX size_t snikket_chat_attachment_uris(void *chat_attachment, const char ***outPtr);

API_PREFIX size_t snikket_chat_attachment_hashes(void *chat_attachment, void ***outPtr);

API_PREFIX void *snikket_hash_from_hex(const char *algorithm, const char *hash);

API_PREFIX void *snikket_hash_from_uri(const char *uri);

API_PREFIX const char *snikket_hash_algorithm(void *hash);

API_PREFIX const char *snikket_hash_to_uri(void *hash);

API_PREFIX const char *snikket_hash_to_hex(void *hash);

API_PREFIX const char *snikket_hash_to_base_64(void *hash);

API_PREFIX const char *snikket_hash_to_base_64_url(void *hash);

API_PREFIX const char *snikket_reaction_sender_id(void *reaction);

API_PREFIX const char *snikket_reaction_timestamp(void *reaction);

API_PREFIX const char *snikket_reaction_text(void *reaction);

API_PREFIX const char *snikket_reaction_key(void *reaction);

API_PREFIX const char *snikket_reaction_envelope_id(void *reaction);

/**
 * @returns a new blank ChatMessageBuilder
 */
API_PREFIX void *snikket_chat_message_builder_new();

/**
 * The ID as set by the creator of this message
 */
API_PREFIX const char *snikket_chat_message_builder_local_id(void *chat_message_builder);

/**
 * The ID as set by the creator of this message
 */
API_PREFIX void snikket_chat_message_builder_set_local_id(void *chat_message_builder, const char *value);

/**
 * The ID as set by the authoritative server
 */
API_PREFIX const char *snikket_chat_message_builder_server_id(void *chat_message_builder);

/**
 * The ID as set by the authoritative server
 */
API_PREFIX void snikket_chat_message_builder_set_server_id(void *chat_message_builder, const char *value);

/**
 * The ID of the server which set the serverId
 */
API_PREFIX const char *snikket_chat_message_builder_server_id_by(void *chat_message_builder);

/**
 * The ID of the server which set the serverId
 */
API_PREFIX void snikket_chat_message_builder_set_server_id_by(void *chat_message_builder, const char *value);

/**
 * The type of this message (Chat, Call, etc)
 */
API_PREFIX enum snikket_message_type snikket_chat_message_builder_type(void *chat_message_builder);

/**
 * The type of this message (Chat, Call, etc)
 */
API_PREFIX void snikket_chat_message_builder_set_type(void *chat_message_builder, enum snikket_message_type value);

/**
 * The timestamp of this message, in format YYYY-MM-DDThh:mm:ss[.sss]+00:00
 */
API_PREFIX const char *snikket_chat_message_builder_timestamp(void *chat_message_builder);

/**
 * The timestamp of this message, in format YYYY-MM-DDThh:mm:ss[.sss]+00:00
 */
API_PREFIX void snikket_chat_message_builder_set_timestamp(void *chat_message_builder, const char *value);

API_PREFIX const char *snikket_chat_message_builder_sender_id(void *chat_message_builder);

API_PREFIX void snikket_chat_message_builder_set_sender_id(void *chat_message_builder, const char *value);

/**
 * Message this one is in reply to, or NULL
 */
API_PREFIX void *snikket_chat_message_builder_reply_to_message(void *chat_message_builder);

/**
 * Message this one is in reply to, or NULL
 */
API_PREFIX void snikket_chat_message_builder_set_reply_to_message(void *chat_message_builder, void *value);

/**
 * ID of the thread this message is in, or NULL
 */
API_PREFIX const char *snikket_chat_message_builder_thread_id(void *chat_message_builder);

/**
 * ID of the thread this message is in, or NULL
 */
API_PREFIX void snikket_chat_message_builder_set_thread_id(void *chat_message_builder, const char *value);

/**
 * Array of attachments to this message
 */
API_PREFIX size_t snikket_chat_message_builder_attachments(void *chat_message_builder, void ***outPtr);

/**
 * Body text of this message or NULL
 */
API_PREFIX const char *snikket_chat_message_builder_text(void *chat_message_builder);

/**
 * Body text of this message or NULL
 */
API_PREFIX void snikket_chat_message_builder_set_text(void *chat_message_builder, const char *value);

/**
 * Language code for the body text
 */
API_PREFIX const char *snikket_chat_message_builder_lang(void *chat_message_builder);

/**
 * Language code for the body text
 */
API_PREFIX void snikket_chat_message_builder_set_lang(void *chat_message_builder, const char *value);

/**
 * Direction of this message
 */
API_PREFIX enum snikket_message_direction snikket_chat_message_builder_direction(void *chat_message_builder);

/**
 * Direction of this message
 */
API_PREFIX void snikket_chat_message_builder_set_direction(void *chat_message_builder, enum snikket_message_direction value);

/**
 * Status of this message
 */
API_PREFIX enum snikket_message_status snikket_chat_message_builder_status(void *chat_message_builder);

/**
 * Status of this message
 */
API_PREFIX void snikket_chat_message_builder_set_status(void *chat_message_builder, enum snikket_message_status value);

/**
 * Array of past versions of this message, if it has been edited
 */
API_PREFIX void snikket_chat_message_builder_set_versions(void *chat_message_builder, void *const *inPtr, size_t count);

/**
 * Array of past versions of this message, if it has been edited
 */
API_PREFIX size_t snikket_chat_message_builder_versions(void *chat_message_builder, void ***outPtr);

API_PREFIX void snikket_chat_message_builder_add_attachment(void *chat_message_builder, void *attachment);

/**
 * Set rich text using an HTML string
 * Also sets the plain text body appropriately
 */
API_PREFIX void snikket_chat_message_builder_set_html(void *chat_message_builder, const char *html);

/**
 * The ID of the Chat this message is associated with
 */
API_PREFIX const char *snikket_chat_message_builder_chat_id(void *chat_message_builder);

/**
 * The ID of the sender of this message
 */
API_PREFIX const char *snikket_chat_message_builder_get_sender_id(void *chat_message_builder);

API_PREFIX bool snikket_chat_message_builder_is_incoming(void *chat_message_builder);

API_PREFIX void *snikket_chat_message_builder_build(void *chat_message_builder);

/**
 * Create a basic persistence layer that persists nothing
 * 
 * @returns new persistence layer
 */
API_PREFIX void *snikket_persistence_dummy_new();

API_PREFIX void *snikket_push_receive(const char *data, void *persistence);

API_PREFIX const char *snikket_notification_title(void *notification);

API_PREFIX const char *snikket_notification_body(void *notification);

API_PREFIX const char *snikket_notification_account_id(void *notification);

API_PREFIX const char *snikket_notification_chat_id(void *notification);

API_PREFIX const char *snikket_notification_sender_id(void *notification);

API_PREFIX const char *snikket_notification_message_id(void *notification);

API_PREFIX enum snikket_message_type snikket_notification_type(void *notification);

API_PREFIX const char *snikket_notification_call_status(void *notification);

API_PREFIX const char *snikket_notification_call_sid(void *notification);

API_PREFIX const char *snikket_notification_image_uri(void *notification);

API_PREFIX const char *snikket_notification_lang(void *notification);

API_PREFIX const char *snikket_notification_timestamp(void *notification);

/**
 * Create a new Client to connect to a particular account
 * 
 * @param address the account to connect to
 * @param persistence the persistence layer to use for storage
 */
API_PREFIX void *snikket_client_new(const char *address, void *persistence);

/**
 * Set to false to suppress sending available presence
 */
API_PREFIX void snikket_client_set_send_available(void *client, bool value);

/**
 * Start this client running and trying to connect to the server
 */
API_PREFIX void snikket_client_start(void *client);

/**
 * Gets the client ready to use but does not connect to the server
 */
API_PREFIX void snikket_client_start_offline(void *client, void (*ready) (void*), void *ready__context);

/**
 * Destroy local data for this account
 * 
 * @param completely if true chats, messages, etc will be deleted as well
 */
API_PREFIX void snikket_client_logout(void *client, bool completely);

/**
 * Sets the password to be used in response to the password needed event
 * 
 * @param password
 */
API_PREFIX void snikket_client_use_password(void *client, const char *password);

/**
 * Get the account ID for this Client
 * 
 * @returns account id
 */
API_PREFIX const char *snikket_client_account_id(void *client);

/**
 * Get the current display name for this account
 * 
 * @returns display name
 */
API_PREFIX const char *snikket_client_display_name(void *client);

/**
 * Set the current display name for this account on the server
 * 
 * @param display name to set (ignored if empty or NULL)
 */
API_PREFIX void snikket_client_set_display_name(void *client, const char *displayName);

/**
 * Turn a file into a ChatAttachment for attaching to a ChatMessage
 */
API_PREFIX void snikket_client_prepare_attachment(void *client, void *source, void (*callback) (void*, void*), void *callback__context);

/**
 * @returns array of open chats, sorted by last activity
 */
API_PREFIX size_t snikket_client_get_chats(void *client, void ***outPtr);

/**
 * Search for chats the user can start or join
 * 
 * @param q the search query to use
 * @param callback takes two arguments, the query that was used and the array of results
 */
API_PREFIX void snikket_client_find_available_chats(void *client, const char *q, void (*callback) (const char*, void**, size_t, void*), void *callback__context);

/**
 * Start or join a chat from the search results
 * 
 * @returns the chat that was started
 */
API_PREFIX void *snikket_client_start_chat(void *client, void *availableChat);

/**
 * Find a chat by id
 * 
 * @returns the chat if known, or NULL
 */
API_PREFIX void *snikket_client_get_chat(void *client, const char *chatId);

/**
 * Enable push notifications
 * 
 * @param push_service the address of a push proxy
 * @param vapid_private_pkcs8 the private key for signing JWT of the push service
 * @param endpoint the final target for the push proxy to forward to
 * @param p256dh A P-256 uncompressed point in ANSI X9.62 format
 * @param auth Random 16 octed value
 * @param grace Grace period during which not to generate push if another app is active for same account, in seconds (negative for none)
 * @param claims Optional additional JWT claims as key then value
 */
API_PREFIX void snikket_client_enable_push(void *client, const char *push_service, const char *endpoint, const unsigned char *p256dh, size_t p256dh__len, const unsigned char *auth, size_t auth__len, int grace, const unsigned char *vapid_private_pkcs8, size_t vapid_private_pkcs8__len, const char *const *claims, size_t claims__len);

/**
 * Event fired when client needs a password for authentication
 * 
 * @param handler takes one argument, the Client that needs a password
 */
API_PREFIX void snikket_client_add_password_needed_listener(void *client, void (*handler) (void*, void*), void *handler__context);

/**
 * Event fired when client is connected and fully synchronized
 * 
 * @param handler takes no arguments
 */
API_PREFIX void snikket_client_add_status_online_listener(void *client, void (*handler) (void*), void *handler__context);

/**
 * Event fired when client is disconnected
 * 
 * @param handler takes no arguments
 */
API_PREFIX void snikket_client_add_status_offline_listener(void *client, void (*handler) (void*), void *handler__context);

/**
 * Event fired when connection fails with a fatal error and will not be retried
 * 
 * @param handler takes no arguments
 */
API_PREFIX void snikket_client_add_connection_failed_listener(void *client, void (*handler) (void*), void *handler__context);

/**
 * Event fired when TLS checks fail, to give client the chance to override
 * 
 * @param handler takes two arguments, the PEM of the cert and an array of DNS names, and must return true to accept or false to reject
 */
API_PREFIX void snikket_client_add_tls_check_listener(void *client, bool (*handler) (const char*, const char**, size_t, void*), void *handler__context);

/**
 * Event fired when a new ChatMessage comes in on any Chat
 * Also fires when status of a ChatMessage changes,
 * when a ChatMessage is edited, or when a reaction is added
 * 
 * @param handler takes two arguments, the ChatMessage and ChatMessageEvent enum describing what happened
 */
API_PREFIX void snikket_client_add_chat_message_listener(void *client, void (*handler) (void*, int, void*), void *handler__context);

/**
 * Event fired when syncing a new ChatMessage that was send when offline.
 * Normally you don't want this, but it may be useful if you want to notify on app start.
 * 
 * @param handler takes one argument, the ChatMessage
 */
API_PREFIX void snikket_client_add_sync_message_listener(void *client, void (*handler) (void*, void*), void *handler__context);

/**
 * Event fired when a Chat's metadata is updated, or when a new Chat is added
 * 
 * @param handler takes one argument, an array of Chats that were updated
 */
API_PREFIX void snikket_client_add_chats_updated_listener(void *client, void (*handler) (void**, size_t, void*), void *handler__context);

/**
 * Event fired when a new call comes in
 * 
 * @param handler takes one argument, the call Session
 */
API_PREFIX void snikket_client_add_call_ring_listener(void *client, void (*handler) (void*, void*), void *handler__context);

/**
 * Event fired when a call is retracted or hung up
 * 
 * @param handler takes two arguments, the associated Chat ID and Session ID
 */
API_PREFIX void snikket_client_add_call_retract_listener(void *client, void (*handler) (const char*, const char*, void*), void *handler__context);

/**
 * Event fired when an outgoing call starts ringing
 * 
 * @param handler takes two arguments, the associated Chat ID and Session ID
 */
API_PREFIX void snikket_client_add_call_ringing_listener(void *client, void (*handler) (const char*, const char*, void*), void *handler__context);

/**
 * Event fired when an existing call changes status (connecting, failed, etc)
 * 
 * @param handler takes one argument, the associated Session
 */
API_PREFIX void snikket_client_add_call_update_status_listener(void *client, void (*handler) (void*, void*), void *handler__context);

/**
 * Event fired when a call is asking for media to send
 * 
 * @param handler takes three arguments, the call Session,
 *        a boolean indicating if audio is desired,
 *        and a boolean indicating if video is desired
 */
API_PREFIX void snikket_client_add_call_media_listener(void *client, void (*handler) (void*, bool, bool, void*), void *handler__context);

/**
 * Event fired when call has a new MediaStreamTrack to play
 * 
 * @param handler takes three arguments, the associated Chat ID,
 *        the new MediaStreamTrack, and an array of any associated MediaStreams
 */
API_PREFIX void snikket_client_add_call_track_listener(void *client, void (*handler) (const char*, void*, void**, size_t, void*), void *handler__context);

/**
 * Let the SDK know the UI is in the foreground
 */
API_PREFIX void snikket_client_set_in_foreground(void *client);

/**
 * Let the SDK know the UI is in the foreground
 */
API_PREFIX void snikket_client_set_not_in_foreground(void *client);

/**
 * ID of this Chat
 */
API_PREFIX const char *snikket_chat_chat_id(void *chat);

/**
 * Current state of this chat
 */
API_PREFIX enum snikket_ui_state snikket_chat_ui_state(void *chat);

API_PREFIX bool snikket_chat_is_blocked(void *chat);

/**
 * Fetch a page of messages before some point
 * 
 * @param beforeId id of the message to look before
 * @param beforeTime timestamp of the message to look before,
 *        String in format YYYY-MM-DDThh:mm:ss[.sss]+00:00
 * @param handler takes one argument, an array of ChatMessage that are found
 */
API_PREFIX void snikket_chat_get_messages_before(void *chat, const char *beforeId, const char *beforeTime, void (*handler) (void**, size_t, void*), void *handler__context);

/**
 * Fetch a page of messages after some point
 * 
 * @param afterId id of the message to look after
 * @param afterTime timestamp of the message to look after,
 *        String in format YYYY-MM-DDThh:mm:ss[.sss]+00:00
 * @param handler takes one argument, an array of ChatMessage that are found
 */
API_PREFIX void snikket_chat_get_messages_after(void *chat, const char *afterId, const char *afterTime, void (*handler) (void**, size_t, void*), void *handler__context);

/**
 * Fetch a page of messages around (before, including, and after) some point
 * 
 * @param aroundId id of the message to look around
 * @param aroundTime timestamp of the message to look around,
 *        String in format YYYY-MM-DDThh:mm:ss[.sss]+00:00
 * @param handler takes one argument, an array of ChatMessage that are found
 */
API_PREFIX void snikket_chat_get_messages_around(void *chat, const char *aroundId, const char *aroundTime, void (*handler) (void**, size_t, void*), void *handler__context);

/**
 * Send a ChatMessage to this Chat
 * 
 * @param message the ChatMessage to send
 */
API_PREFIX void snikket_chat_send_message(void *chat, void *message);

/**
 * Signals that all messages up to and including this one have probably
 * been displayed to the user
 * 
 * @param message the ChatMessage most recently displayed
 */
API_PREFIX void snikket_chat_mark_read_up_to(void *chat, void *message);

/**
 * Save this Chat on the server
 */
API_PREFIX void snikket_chat_bookmark(void *chat);

/**
 * Get the list of IDs of participants in this Chat
 * 
 * @returns array of IDs
 */
API_PREFIX size_t snikket_chat_get_participants(void *chat, const char ***outPtr);

/**
 * Get the details for one participant in this Chat
 * 
 * @param participantId the ID of the participant to look up
 */
API_PREFIX void *snikket_chat_get_participant_details(void *chat, const char *participantId);

/**
 * Correct an already-send message by replacing it with a new one
 * 
 * @param localId the localId of the message to correct
 *        must be the localId of the first version ever sent, not a subsequent correction
 * @param message the new ChatMessage to replace it with
 */
API_PREFIX void snikket_chat_correct_message(void *chat, const char *localId, void *message);

/**
 * Add new reaction to a message in this Chat
 * 
 * @param m ChatMessage to react to
 * @param reaction emoji of the reaction
 */
API_PREFIX void snikket_chat_add_reaction(void *chat, void *m, void *reaction);

/**
 * Remove an already-sent reaction from a message
 * 
 * @param m ChatMessage to remove the reaction from
 * @param reaction the emoji to remove
 */
API_PREFIX void snikket_chat_remove_reaction(void *chat, void *m, void *reaction);

/**
 * Call this whenever the user is typing, can call on every keystroke
 * 
 * @param threadId optional, what thread the user has selected if any
 * @param content optional, what the user has typed so far
 */
API_PREFIX void snikket_chat_typing(void *chat, const char *threadId, const char *content);

/**
 * Call this whenever the user makes a chat or thread "active" in your UX
 * If you call this with true you MUST later call it will false
 * 
 * @param active true if the chat is "active", false otherwise
 * @param threadId optional, what thread the user has selected if any
 */
API_PREFIX void snikket_chat_set_active(void *chat, bool active, const char *threadId);

/**
 * Archive this chat
 */
API_PREFIX void snikket_chat_close(void *chat);

/**
 * Pin or unpin this chat
 */
API_PREFIX void snikket_chat_toggle_pinned(void *chat);

/**
 * Block this chat so it will not re-open
 */
API_PREFIX void snikket_chat_block(void *chat, void *reportSpam, bool onServer);

/**
 * Unblock this chat so it will open again
 */
API_PREFIX void snikket_chat_unblock(void *chat, bool onServer);

/**
 * Update notification preferences
 */
API_PREFIX void snikket_chat_set_notifications(void *chat, bool filtered, bool mention, bool reply);

/**
 * Should notifications be filtered?
 */
API_PREFIX bool snikket_chat_notifications_filtered(void *chat);

/**
 * Should a mention produce a notification?
 */
API_PREFIX bool snikket_chat_notify_mention(void *chat);

/**
 * Should a reply produce a notification?
 */
API_PREFIX bool snikket_chat_notify_reply(void *chat);

/**
 * An ID of the most recent message in this chat
 */
API_PREFIX const char *snikket_chat_last_message_id(void *chat);

/**
 * The timestamp of the most recent message in this chat
 */
API_PREFIX const char *snikket_chat_last_message_timestamp(void *chat);

/**
 * Get the URI image to represent this Chat, or null
 */
API_PREFIX const char *snikket_chat_get_photo(void *chat);

/**
 * Get the URI to a placeholder image to represent this Chat
 */
API_PREFIX const char *snikket_chat_get_placeholder(void *chat);

/**
 * An ID of the last message displayed to the user
 */
API_PREFIX const char *snikket_chat_read_up_to(void *chat);

/**
 * The number of message that have not yet been displayed to the user
 */
API_PREFIX int snikket_chat_unread_count(void *chat);

/**
 * A preview of the chat, such as the most recent message body
 */
API_PREFIX const char *snikket_chat_preview(void *chat);

API_PREFIX void snikket_chat_set_display_name(void *chat, const char *fn);

/**
 * The display name of this Chat
 */
API_PREFIX const char *snikket_chat_get_display_name(void *chat);

API_PREFIX void snikket_chat_set_trusted(void *chat, bool trusted);

/**
 * Is this a chat with an entity we trust to see our online status?
 */
API_PREFIX bool snikket_chat_is_trusted(void *chat);

API_PREFIX bool snikket_chat_syncing(void *chat);

/**
 * Can audio calls be started in this Chat?
 */
API_PREFIX bool snikket_chat_can_audio_call(void *chat);

/**
 * Can video calls be started in this Chat?
 */
API_PREFIX bool snikket_chat_can_video_call(void *chat);

/**
 * Start a new call in this Chat
 * 
 * @param audio do we want audio in this call
 * @param video do we want video in this call
 */
API_PREFIX void snikket_chat_start_call(void *chat, bool audio, bool video);

/**
 * Accept any incoming calls in this Chat
 */
API_PREFIX void snikket_chat_accept_call(void *chat);

/**
 * Hangup or reject any calls in this chat
 */
API_PREFIX void snikket_chat_hangup(void *chat);

/**
 * The current status of a call in this chat
 */
API_PREFIX enum snikket_jingle_call_status snikket_chat_call_status(void *chat);

/**
 * A DTMFSender for a call in this chat, or NULL
 */
API_PREFIX void *snikket_chat_dtmf(void *chat);

/**
 * All video tracks in all active calls in this chat
 */
API_PREFIX size_t snikket_chat_video_tracks(void *chat, void ***outPtr);

API_PREFIX const char *snikket_jingle_media_stream_track_id(void *media_stream_track);

API_PREFIX bool snikket_jingle_media_stream_track_muted(void *media_stream_track);

API_PREFIX const char *snikket_jingle_media_stream_track_kind(void *media_stream_track);

API_PREFIX size_t snikket_jingle_media_stream_track_supported_audio_formats(void *media_stream_track, void ***outPtr);

/**
 * Event fired for new inbound audio frame
 * 
 * @param callback takes three arguments, the Signed 16-bit PCM data, the clock rate, and the number of channels
 */
API_PREFIX void snikket_jingle_media_stream_track_add_pcm_listener(void *media_stream_track, void (*callback) (short*, size_t, int, int, void*), void *callback__context);

/**
 * Event fired when ready for next outbound audio frame
 * 
 * @param callback
 */
API_PREFIX void snikket_jingle_media_stream_track_add_ready_for_pcm_listener(void *media_stream_track, void (*callback) (void*), void *callback__context);

/**
 * Send new audio to this track
 * 
 * @param pcm 16-bit signed linear PCM data (interleaved)
 * @param clockRate the sampling rate of the data
 * @param channels the number of audio channels
 */
API_PREFIX void snikket_jingle_media_stream_track_write_pcm(void *media_stream_track, const short *pcm, size_t pcm__len, int clockRate, int channels);

API_PREFIX void snikket_jingle_media_stream_track_stop(void *media_stream_track);

API_PREFIX void *snikket_jingle_audio_format_new(const char *format, unsigned char payloadType, int clockRate, int channels);

API_PREFIX int snikket_jingle_audio_format_clock_rate(void *audio_format);

API_PREFIX int snikket_jingle_audio_format_channels(void *audio_format);

/**
 * The ID of the Chat this search result represents
 */
API_PREFIX const char *snikket_available_chat_chat_id(void *available_chat);

/**
 * The display name of this search result
 */
API_PREFIX const char *snikket_available_chat_display_name(void *available_chat);

/**
 * A human-readable note associated with this search result
 */
API_PREFIX const char *snikket_available_chat_note(void *available_chat);

/**
 * Is this search result a channel?
 */
API_PREFIX bool snikket_available_chat_is_channel(void *available_chat);

API_PREFIX const char *snikket_jingle_initiated_session_sid(void *initiated_session);

API_PREFIX const char *snikket_jingle_initiated_session_chat_id(void *initiated_session);

API_PREFIX void snikket_jingle_initiated_session_accept(void *initiated_session);

API_PREFIX void snikket_jingle_initiated_session_hangup(void *initiated_session);

API_PREFIX void snikket_jingle_initiated_session_add_media(void *initiated_session, void *const *streams, size_t streams__len);

API_PREFIX enum snikket_jingle_call_status snikket_jingle_initiated_session_call_status(void *initiated_session);

API_PREFIX size_t snikket_jingle_initiated_session_video_tracks(void *initiated_session, void ***outPtr);

API_PREFIX void *snikket_jingle_initiated_session_dtmf(void *initiated_session);

API_PREFIX void snikket_jingle_initiated_session_supply_media(void *initiated_session, void *const *streams, size_t streams__len);

API_PREFIX void *snikket_jingle_media_stream_new();

/**
 * Create default bidirectional audio track
 */
API_PREFIX void *snikket_jingle_media_stream_make_audio();

API_PREFIX void snikket_jingle_media_stream_add_track(void *media_stream, void *track);

API_PREFIX size_t snikket_jingle_media_stream_get_tracks(void *media_stream, void ***outPtr);

API_PREFIX const char *snikket_participant_display_name(void *participant);

API_PREFIX const char *snikket_participant_photo_uri(void *participant);

API_PREFIX const char *snikket_participant_placeholder_uri(void *participant);

API_PREFIX bool snikket_participant_is_self(void *participant);

API_PREFIX void *snikket_attachment_source_new(const char *path, const char *mime);

API_PREFIX const char *snikket_attachment_source_path(void *attachment_source);

API_PREFIX const char *snikket_attachment_source_type(void *attachment_source);

API_PREFIX const char *snikket_attachment_source_name(void *attachment_source);

API_PREFIX int snikket_attachment_source_size(void *attachment_source);

API_PREFIX bool snikket_channel_is_private(void *channel);

API_PREFIX const char *snikket_custom_emoji_reaction_uri(void *custom_emoji_reaction);

API_PREFIX const char *snikket_identicon_svg(const char *source);

/**
 * Produce /.well-known/ni/ paths instead of ni:/// URIs
 * for referencing media by hash.
 * 
 * This can be useful eg for intercepting with a Service Worker.
 */
API_PREFIX bool snikket_config_relative_hash_uri();

/**
 * Produce /.well-known/ni/ paths instead of ni:/// URIs
 * for referencing media by hash.
 * 
 * This can be useful eg for intercepting with a Service Worker.
 */
API_PREFIX void snikket_config_set_relative_hash_uri(bool value);

/**
 * Trades off some performance for lower / more consistent memory usage
 */
API_PREFIX void snikket_config_enable_constrained_memory_mode();

/**
 * Schedule DTMF events to be sent
 * 
 * @param tones can be any number of 0123456789#*ABCD,
 */
API_PREFIX void snikket_jingle_dtmf_sender_insert_dtmf(void *dtmf_sender, const char *tones);

#ifdef __cplusplus
}
#endif

#undef API_PREFIX

#endif