This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkorchestra.h
2217 lines (1933 loc) · 73.4 KB
/
mkorchestra.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
// Part of Measurement Kit <https://measurement-kit.github.io/>.
// Measurement Kit is free software under the BSD license. See AUTHORS
// and LICENSE for more information on the copying conditions.
#ifndef MEASUREMENT_KIT_MKORCHESTRA_H
#define MEASUREMENT_KIT_MKORCHESTRA_H
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/// mkorchestra_metadata_t contains client metadata.
typedef struct mkorchestra_metadata mkorchestra_metadata_t;
/// mkorchestra_metadata_new_nonnull creates a client metadata
/// instance. It always returns a valid pointer and aborts if allocating
/// the new metadata instance fails.
mkorchestra_metadata_t *mkorchestra_metadata_new_nonnull(void);
/// mkorchestra_metadata_set_available_bandwidth sets the
/// bandwidth available to the client. This function aborts if it
/// is passed any null pointer argument.
void mkorchestra_metadata_set_available_bandwidth(
mkorchestra_metadata_t *metadata,
const char *available_bandwidth);
/// mkorchestra_metadata_set_device_token sets the device token. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_device_token(
mkorchestra_metadata_t *metadata,
const char *device_token);
/// mkorchestra_metadata_set_language sets the language. This function
/// aborts if passed any null pointer argument.
void mkorchestra_metadata_set_language(
mkorchestra_metadata_t *metadata,
const char *language);
/// mkorchestra_metadata_set_network_type sets the network_type. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_network_type(
mkorchestra_metadata_t *metadata,
const char *network_type);
/// mkorchestra_metadata_set_platform sets the platform. This function
/// aborts if passed any null pointer argument.
void mkorchestra_metadata_set_platform(
mkorchestra_metadata_t *metadata,
const char *platform);
/// mkorchestra_metadata_set_probe_asn sets the probe_asn. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_probe_asn(
mkorchestra_metadata_t *metadata,
const char *probe_asn);
/// mkorchestra_metadata_set_probe_cc sets the probe_cc. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_probe_cc(
mkorchestra_metadata_t *metadata,
const char *probe_cc);
/// mkorchestra_metadata_set_probe_family sets the probe_family. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_probe_family(
mkorchestra_metadata_t *metadata,
const char *probe_family);
/// mkorchestra_metadata_set_probe_timezone sets the probe_timezone. It
/// aborts if passed any null pointer argument.
void mkorchestra_metadata_set_probe_timezone(
mkorchestra_metadata_t *metadata,
const char *probe_timezone);
/// mkorchestra_metadata_set_software_name sets the software_name. This
/// function aborts if passed any null pointer argument.
void mkorchestra_metadata_set_software_name(
mkorchestra_metadata_t *metadata,
const char *software_name);
/// mkorchestra_metadata_set_software_version sets the software_version.
/// It aborts if passed any null pointer argument.
void mkorchestra_metadata_set_software_version(
mkorchestra_metadata_t *metadata,
const char *software_version);
/// mkorchestra_metadata_add_supported_test adds @p supported_test
/// to the list of tests supported by this probe. This function aborts
/// when passed any null pointer argument.
void mkorchestra_metadata_add_supported_test(
mkorchestra_metadata_t *metadata,
const char *supported_test);
/// mkorchestra_metadata_delete destroys @p metadata. Note that
/// @p metadata MAY be null.
void mkorchestra_metadata_delete(
mkorchestra_metadata_t *metadata);
/// mkorchestra_register_request_t is a request to the register API.
typedef struct mkorchestra_register_request mkorchestra_register_request_t;
/// mkorchestra_register_response_t is a response to the register API.
typedef struct mkorchestra_register_response mkorchestra_register_response_t;
/// mkorchestra_register_request_new_nonnull creates a new register request. It
/// always returns a valid pointer. It aborts if allocation fails.
mkorchestra_register_request_t *mkorchestra_register_request_new_nonnull(void);
/// mkorchestra_register_request_set_password sets @p password as
/// the password to be used to identify this probe. This function aborts
/// if passed any null pointer argument.
void mkorchestra_register_request_set_password(
mkorchestra_register_request_t *request,
const char *password);
/// mkorchestra_register_request_set_metadata copies @p metadata
/// as the metadata associated with the register request. This function
/// aborts if passed any null pointer argument.
void mkorchestra_register_request_set_metadata(
mkorchestra_register_request_t *request,
const mkorchestra_metadata_t *metadata);
/// mkorchestra_register_request_set_base_url sets the base URL for
/// the @p request. It aborts if passed any null pointer.
void mkorchestra_register_request_set_base_url(
mkorchestra_register_request_t *request,
const char *base_url);
/// mkorchestra_register_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_register_request_set_ca_bundle_path(
mkorchestra_register_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_register_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_register_request_set_timeout(
mkorchestra_register_request_t *request,
int64_t timeout);
/// mkorchestra_register_request_perform_nonnull performs @p request. It will
/// always return a valid pointer. It aborts if any malloc fails.
mkorchestra_register_response_t *mkorchestra_register_request_perform_nonnull(
const mkorchestra_register_request_t *request);
/// mkorchestra_register_request_delete destroys @p request. Note that
/// @p request MAY be a null pointer.
void mkorchestra_register_request_delete(
mkorchestra_register_request_t *request);
/// mkorchestra_register_response_good returns true if we received a response
/// from the API and such response indicated success, false otherwise. It
/// calls abort if @p response is a null pointer.
int64_t mkorchestra_register_response_good(
const mkorchestra_register_response_t *response);
/// mkorchestra_register_response_get_client_id returns the client ID as
/// parsed by mkorchestra_register_response_parse. It always returns a valid
/// string owned by @p response. It aborts if passed null arguments.
const char *mkorchestra_register_response_get_client_id(
const mkorchestra_register_response_t *response);
/// mkorchestra_register_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_register_response_get_binary_logs(
const mkorchestra_register_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_register_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_register_response_delete(
mkorchestra_register_response_t *response);
/// mkorchestra_login_request_t is a request to the login API.
typedef struct mkorchestra_login_request mkorchestra_login_request_t;
/// mkorchestra_login_response_t is a response from the login API.
typedef struct mkorchestra_login_response mkorchestra_login_response_t;
/// mkorchestra_login_request_new_nonnull creates a new login request. It will
/// always return a valid pointer and will abort if out of memory.
mkorchestra_login_request_t *mkorchestra_login_request_new_nonnull(void);
/// mkorchestra_login_request_set_username sets the login request username. It
/// will abort if passed any null pointer argument.
void mkorchestra_login_request_set_username(
mkorchestra_login_request_t *request,
const char *username);
/// mkorchestra_login_request_set_password sets the login request password. It
/// will abort if passed any null pointer argument.
void mkorchestra_login_request_set_password(
mkorchestra_login_request_t *request,
const char *password);
/// mkorchestra_login_request_set_base_url sets the base URL for
/// the @p request. It will abort if passed null pointers.
void mkorchestra_login_request_set_base_url(
mkorchestra_login_request_t *request,
const char *base_url);
/// mkorchestra_login_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_login_request_set_ca_bundle_path(
mkorchestra_login_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_login_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_login_request_set_timeout(
mkorchestra_login_request_t *request,
int64_t timeout);
/// mkorchestra_login_request_perform_nonnull performs @p request. It will
/// always return a valid pointer. It aborts if passed a null @p request.
mkorchestra_login_response_t *mkorchestra_login_request_perform_nonnull(
const mkorchestra_login_request_t *request);
/// mkorchestra_login_request_delete destroys @p request. Note that @p
/// request MAY be a null pointer.
void mkorchestra_login_request_delete(mkorchestra_login_request_t *request);
/// mkorchestra_login_response_good returns true if we received a response
/// from the API and that response is successful, false otherwise. It
/// calls abort if passed a null pointer argument.
int64_t mkorchestra_login_response_good(
const mkorchestra_login_response_t *response);
/// mkorchestra_login_response_get_expire returns when the authentication
/// token will expire. It always returns a valid string owned by @p response,
/// which MAY be an empty string if the request failed. This function will
/// call abort if passed a null pointer.
const char *mkorchestra_login_response_get_expire(
const mkorchestra_login_response_t *response);
/// mkorchestra_login_response_get_token returns the authentication token. It
/// always returns a valid string owned by @p response, which MAY be an empty
/// string if the request failed. It aborts if passed a null pointer.
const char *mkorchestra_login_response_get_token(
const mkorchestra_login_response_t *response);
/// mkorchestra_login_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_login_response_get_binary_logs(
const mkorchestra_login_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_login_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_login_response_delete(
mkorchestra_login_response_t *response);
/// mkorchestra_update_request_t is a request to the update API.
typedef struct mkorchestra_update_request mkorchestra_update_request_t;
/// mkorchestra_update_response_t is a response to the update API.
typedef struct mkorchestra_update_response mkorchestra_update_response_t;
/// mkorchestra_update_request_new_nonnull creates a new update request. It
/// always returns a valid pointer. It aborts if allocation fails.
mkorchestra_update_request_t *mkorchestra_update_request_new_nonnull(void);
/// mkorchestra_update_request_set_token sets @p token as the token to be used
/// to identify this probe. This function aborts if passed any null rgument.
void mkorchestra_update_request_set_token(
mkorchestra_update_request_t *request,
const char *token);
/// mkorchestra_update_request_client_id sets @p client_id as the ID to be used
/// to identify this probe. This function aborts if passed any null rgument.
void mkorchestra_update_request_set_client_id(
mkorchestra_update_request_t *request,
const char *client_id);
/// mkorchestra_update_request_set_metadata copies @p metadata
/// as the metadata associated with the update request. This function
/// aborts if passed any null pointer argument.
void mkorchestra_update_request_set_metadata(
mkorchestra_update_request_t *request,
const mkorchestra_metadata_t *metadata);
/// mkorchestra_update_request_set_base_url sets the base URL for
/// the @p request. It aborts if passed any null pointer.
void mkorchestra_update_request_set_base_url(
mkorchestra_update_request_t *request,
const char *base_url);
/// mkorchestra_update_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_update_request_set_ca_bundle_path(
mkorchestra_update_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_update_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_update_request_set_timeout(
mkorchestra_update_request_t *request,
int64_t timeout);
/// mkorchestra_update_request_perform_nonnull performs @p request. It will
/// always return a valid pointer. It aborts if any malloc fails.
mkorchestra_update_response_t *mkorchestra_update_request_perform_nonnull(
const mkorchestra_update_request_t *request);
/// mkorchestra_update_request_delete destroys @p request. Note that
/// @p request MAY be a null pointer.
void mkorchestra_update_request_delete(
mkorchestra_update_request_t *request);
/// mkorchestra_update_response_good returns true if we received a response
/// from the API and such response indicated success, false otherwise. It
/// calls abort if @p response is a null pointer.
int64_t mkorchestra_update_response_good(
const mkorchestra_update_response_t *response);
/// mkorchestra_update_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_update_response_get_binary_logs(
const mkorchestra_update_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_update_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_update_response_delete(
mkorchestra_update_response_t *response);
/// mkorchestra_collector_t is a collector.
typedef struct mkorchestra_collector mkorchestra_collector_t;
/// mkorchestra_collector_get_type returns the collector type. It always
/// returns a valid string. Aborts if passed a null pointer.
const char *mkorchestra_collector_get_type(const mkorchestra_collector_t *c);
/// mkorchestra_collector_get_address returns the collector address. It always
/// returns a valid string. Aborts if passed a null pointer.
const char *mkorchestra_collector_get_address(const mkorchestra_collector_t *c);
/// mkorchestra_collector_delete delets @p c, which MAY be null.
void mkorchestra_collector_delete(mkorchestra_collector_t *c);
/// mkorchestra_collectors_request_t is a request for the collectors API.
typedef struct mkorchestra_collectors_request mkorchestra_collectors_request_t;
/// mkorchestra_collectors_response_t is a response for the collectors API.
typedef struct mkorchestra_collectors_response mkorchestra_collectors_response_t;
/// mkorchestra_collectors_request_new_nonnull creates a new request for the
/// collectors endpoint. The returned pointer is always valid. This function
/// calls abort if allocating new memory fails.
mkorchestra_collectors_request_t *
mkorchestra_collectors_request_new_nonnull(void);
/// mkorchestra_collectors_request_set_base_url sets the base URL for
/// the @p request. It aborts if passed any null pointer.
void mkorchestra_collectors_request_set_base_url(
mkorchestra_collectors_request_t *request,
const char *base_url);
/// mkorchestra_collectors_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_collectors_request_set_ca_bundle_path(
mkorchestra_collectors_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_collectors_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_collectors_request_set_timeout(
mkorchestra_collectors_request_t *request,
int64_t timeout);
/// mkorchestra_collectors_request_perform_nonnull performs @p request. It
/// always returns a valid pointer. It aborts if allocation fails.
mkorchestra_collectors_response_t *
mkorchestra_collectors_request_perform_nonnull(
const mkorchestra_collectors_request_t *request);
/// mkorchestra_collectors_request_delete destroys @p request. Note that
/// @p request MAY be a null pointer.
void mkorchestra_collectors_request_delete(
mkorchestra_collectors_request_t *request);
/// mkorchestra_collectors_response_good returns true if we received a response
/// from the API and such response indicated success, false otherwise. It
/// calls abort if @p response is a null pointer.
int64_t mkorchestra_collectors_response_good(
const mkorchestra_collectors_response_t *response);
/// mkorchestra_collectors_response_get_collectors_size returns the
/// number of available collectors. This function aborts if passed
/// a null pointer @p response.
size_t mkorchestra_collectors_response_get_collectors_size(
const mkorchestra_collectors_response_t *response);
/// mkorchestra_collectors_response_get_collector_at returns the
/// collector at index @p idx. It never returns an invalid or null
/// pointer. This function aborts if passed a null @p response or
/// if the provided @p idx is out of range.
mkorchestra_collector_t *mkorchestra_collectors_response_get_collector_at(
const mkorchestra_collectors_response_t *response, size_t idx);
/// mkorchestra_collectors_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_collectors_response_get_binary_logs(
const mkorchestra_collectors_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_collectors_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_collectors_response_delete(
mkorchestra_collectors_response_t *response);
/// mkorchestra_testhelper_t is a test helper.
typedef struct mkorchestra_testhelper mkorchestra_testhelper_t;
/// mkorchestra_testhelper_get_name returns the name of a test helper. The
/// returned string is owned by @p th. This function aborts if @p th is null.
const char *mkorchestra_testhelper_get_name(
const mkorchestra_testhelper_t *th);
/// mkorchestra_testhelper_get_type returns the type of a test helper. The
/// returned string is owned by @p th. This function aborts if @p th is null.
const char *mkorchestra_testhelper_get_type(
const mkorchestra_testhelper_t *th);
/// mkorchestra_testhelper_get_address returns the address of a test helper. The
/// returned string is owned by @p th. This function aborts if @p th is null.
const char *mkorchestra_testhelper_get_address(
const mkorchestra_testhelper_t *th);
/// mkorchestra_testhelper_delete deletes @p th, which MAY be null.
void mkorchestra_testhelper_delete(mkorchestra_testhelper_t *th);
/// mkorchestra_testhelpers_request_t is a request for the test-helpers API.
typedef struct mkorchestra_testhelpers_request mkorchestra_testhelpers_request_t;
/// mkorchestra_testhelpers_response_t is a response for the test-helpers API.
typedef struct mkorchestra_testhelpers_response mkorchestra_testhelpers_response_t;
/// mkorchestra_testhelpers_request_new_nonnull creates a new request for the
/// test-helpers endpoint. The returned pointer is always valid. This function
/// calls abort if allocating new memory fails.
mkorchestra_testhelpers_request_t *
mkorchestra_testhelpers_request_new_nonnull(void);
/// mkorchestra_testhelpers_request_set_base_url sets the base URL for
/// the @p request. It aborts if passed any null pointer.
void mkorchestra_testhelpers_request_set_base_url(
mkorchestra_testhelpers_request_t *request,
const char *base_url);
/// mkorchestra_testhelpers_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_testhelpers_request_set_ca_bundle_path(
mkorchestra_testhelpers_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_testhelpers_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_testhelpers_request_set_timeout(
mkorchestra_testhelpers_request_t *request,
int64_t timeout);
/// mkorchestra_testhelpers_request_perform_nonnull performs @p request. It
/// always returns a valid pointer. It aborts if allocation fails.
mkorchestra_testhelpers_response_t *
mkorchestra_testhelpers_request_perform_nonnull(
const mkorchestra_testhelpers_request_t *request);
/// mkorchestra_testhelpers_request_delete destroys @p request. Note that
/// @p request MAY be a null pointer.
void mkorchestra_testhelpers_request_delete(
mkorchestra_testhelpers_request_t *request);
/// mkorchestra_testhelpers_response_good returns true if we received a response
/// from the API and such response indicated success, false otherwise. It
/// calls abort if @p response is a null pointer.
int64_t mkorchestra_testhelpers_response_good(
const mkorchestra_testhelpers_response_t *response);
/// mkorchestra_testhelpers_response_get_testhelpers_size returns the number
/// of available test helpers. This function aborts if passed a null pointer @p
/// response.
size_t mkorchestra_testhelpers_response_get_testhelpers_size(
const mkorchestra_testhelpers_response_t *response);
/// mkorchestra_testhelpers_response_get_testhelper_at returns the test helper
/// at index @p idx. This function aborts if passed a null @p response or if
/// @p idx is out of range. The returned pointer is always valid.
mkorchestra_testhelper_t *mkorchestra_testhelpers_response_get_testhelper_at(
const mkorchestra_testhelpers_response_t *response, size_t idx);
/// mkorchestra_testhelpers_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_testhelpers_response_get_binary_logs(
const mkorchestra_testhelpers_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_testhelpers_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_testhelpers_response_delete(
mkorchestra_testhelpers_response_t *response);
/// mkorchestra_urls_request_t is a request to the urls API.
typedef struct mkorchestra_urls_request mkorchestra_urls_request_t;
/// mkorchestra_urls_response_t is a response from the urls API.
typedef struct mkorchestra_urls_response mkorchestra_urls_response_t;
/// mkorchestra_urls_request_new_nonnull creates a new urls request. It will
/// always return a valid pointer and will abort if out of memory.
mkorchestra_urls_request_t *mkorchestra_urls_request_new_nonnull(void);
/// mkorchestra_urls_request_set_limit sets the maximum number of URLs to
/// return in a page. It will abort if passed any null pointer argument.
void mkorchestra_urls_request_set_limit(
mkorchestra_urls_request_t *request,
int64_t limit);
/// mkorchestra_urls_request_set_country_code sets the country code. It
/// will abort if passed any null pointer argument.
void mkorchestra_urls_request_set_country_code(
mkorchestra_urls_request_t *request,
const char *country_code);
/// mkorchestra_urls_request_add_category_code adds a URL category. It
/// will abort if passed any null pointer argument.
void mkorchestra_urls_request_add_category_code(
mkorchestra_urls_request_t *request,
const char *category_code);
/// mkorchestra_urls_request_set_base_url sets the base URL for
/// the @p request. It will abort if passed null pointers.
void mkorchestra_urls_request_set_base_url(
mkorchestra_urls_request_t *request,
const char *base_url);
/// mkorchestra_urls_request_set_ca_bundle_path sets the CA bundle
/// path. Required on mobile. Aborts if passed null arguments.
void mkorchestra_urls_request_set_ca_bundle_path(
mkorchestra_urls_request_t *request,
const char *ca_bundle_path);
/// mkorchestra_urls_request_set_timeout sets the timeout. After that time has
/// expired, the request will fail. It aborts if passed null arguments.
void mkorchestra_urls_request_set_timeout(
mkorchestra_urls_request_t *request,
int64_t timeout);
/// mkorchestra_urls_request_perform_nonnull performs @p request. It will
/// always return a valid pointer. It aborts if passed a null @p request.
mkorchestra_urls_response_t *mkorchestra_urls_request_perform_nonnull(
const mkorchestra_urls_request_t *request);
/// mkorchestra_urls_request_delete destroys @p request. Note that @p
/// request MAY be a null pointer.
void mkorchestra_urls_request_delete(mkorchestra_urls_request_t *request);
/// mkorchestra_urls_response_good returns true if we received a response
/// from the API and that response is successful, false otherwise. It
/// calls abort if passed a null pointer argument.
int64_t mkorchestra_urls_response_good(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_metadata_count returns the count field of
/// the metadata. This function will call abort if passed a null pointer.
int64_t mkorchestra_urls_response_get_metadata_count(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_metadata_current_page returns the current
/// page field of the metadata. It will abort if passed a null pointer.
int64_t mkorchestra_urls_response_get_metadata_current_page(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_metadata_limit returns the limit field of
/// the metadata. It will abort if passed a null pointer.
int64_t mkorchestra_urls_response_get_metadata_limit(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_metadata_next_url returns the next URL field
/// of the metadata. It always returns a valid string owned by @p response,
/// which MAY be an empty string. It aborts if passed a null pointer.
const char *mkorchestra_urls_response_get_metadata_next_url(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_metadata_pages returns the pages field of
/// the metadata. It will abort if passed a null pointer.
int64_t mkorchestra_urls_response_get_metadata_pages(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_results_size returns the number of entries
/// that have been returned as results. It will abort if passed a null pointer.
size_t mkorchestra_urls_response_get_results_size(
const mkorchestra_urls_response_t *response);
/// mkorchestra_urls_response_get_result_category_code_at returns the category
/// code of the results entry at @p idx. It always returns a valid string owned
/// by @p response, which MAY be an empty string. It aborts if passed a null
/// pointer and if the provided @p idx is out of bounds.
const char *mkorchestra_urls_response_get_result_category_code_at(
const mkorchestra_urls_response_t *response, size_t idx);
/// mkorchestra_urls_response_get_result_country_code_at returns the country
/// code of the results entry at @p idx. It always returns a valid string owned
/// by @p response, which MAY be an empty string. It aborts if passed a null
/// pointer and if the provided @p idx is out of bounds.
const char *mkorchestra_urls_response_get_result_country_code_at(
const mkorchestra_urls_response_t *response, size_t idx);
/// mkorchestra_urls_response_get_result_url_at returns the URLof the results
/// entry at @p idx. It always returns a valid string owned by @p response,
/// which MAY be an empty string. It aborts if passed a null pointer and if the
/// provided @p idx is out of bounds.
const char *mkorchestra_urls_response_get_result_url_at(
const mkorchestra_urls_response_t *response, size_t idx);
/// mkorchestra_urls_response_get_binary_logs returns the (possibly
/// non UTF-8) logs in @p data and @p count. The byte array returned in @p
/// data is owned by @p response and becomes invalid after @p response
/// is deleted. It aborts if passed any null pointer argument.
void mkorchestra_urls_response_get_binary_logs(
const mkorchestra_urls_response_t *response,
const uint8_t **data, size_t *count);
/// mkorchestra_urls_response_delete destroys @p response. Note that
/// @p response MAY be a null pointer.
void mkorchestra_urls_response_delete(
mkorchestra_urls_response_t *response);
#ifdef __cplusplus
} // extern "C"
#include <deque>
#include <memory>
#include <regex>
#include <sstream>
#include <string>
/// mkorchestra_metadata_deleter is a deleter for
/// mkorchestra_metadata_t.
struct mkorchestra_metadata_deleter {
void operator()(mkorchestra_metadata_t *s) {
mkorchestra_metadata_delete(s);
}
};
/// mkorchestra_metadata_uptr is a unique pointer to a
/// mkorchestra_metadata_t instance.
using mkorchestra_metadata_uptr = std::unique_ptr<
mkorchestra_metadata_t, mkorchestra_metadata_deleter>;
/// mkorchestra_register_request_deleter is a deleter for
/// mkorchestra_register_request_t.
struct mkorchestra_register_request_deleter {
void operator()(mkorchestra_register_request_t *s) {
mkorchestra_register_request_delete(s);
}
};
/// mkorchestra_register_request_uptr is a unique pointer to a
/// mkorchestra_register_request_t instance.
using mkorchestra_register_request_uptr = std::unique_ptr<
mkorchestra_register_request_t, mkorchestra_register_request_deleter>;
/// mkorchestra_register_response_deleter is a deleter for
/// mkorchestra_register_response_t.
struct mkorchestra_register_response_deleter {
void operator()(mkorchestra_register_response_t *s) {
mkorchestra_register_response_delete(s);
}
};
/// mkorchestra_register_response_uptr is a unique pointer to a
/// mkorchestra_register_response_t instance.
using mkorchestra_register_response_uptr = std::unique_ptr<
mkorchestra_register_response_t, mkorchestra_register_response_deleter>;
/// mkorchestra_login_request_deleter is a deleter for
/// mkorchestra_login_request_t.
struct mkorchestra_login_request_deleter {
void operator()(mkorchestra_login_request_t *s) {
mkorchestra_login_request_delete(s);
}
};
/// mkorchestra_login_request_uptr is a unique pointer to a
/// mkorchestra_login_request_t instance.
using mkorchestra_login_request_uptr = std::unique_ptr<
mkorchestra_login_request_t, mkorchestra_login_request_deleter>;
/// mkorchestra_login_response_deleter is a deleter for
/// mkorchestra_login_response_t.
struct mkorchestra_login_response_deleter {
void operator()(mkorchestra_login_response_t *s) {
mkorchestra_login_response_delete(s);
}
};
/// mkorchestra_login_response_uptr is a unique pointer to a
/// mkorchestra_login_response_t instance.
using mkorchestra_login_response_uptr = std::unique_ptr<
mkorchestra_login_response_t, mkorchestra_login_response_deleter>;
/// mkorchestra_update_request_deleter is a deleter for
/// mkorchestra_update_request_t.
struct mkorchestra_update_request_deleter {
void operator()(mkorchestra_update_request_t *s) {
mkorchestra_update_request_delete(s);
}
};
/// mkorchestra_update_request_uptr is a unique pointer to a
/// mkorchestra_update_request_t instance.
using mkorchestra_update_request_uptr = std::unique_ptr<
mkorchestra_update_request_t, mkorchestra_update_request_deleter>;
/// mkorchestra_update_response_deleter is a deleter for
/// mkorchestra_update_response_t.
struct mkorchestra_update_response_deleter {
void operator()(mkorchestra_update_response_t *s) {
mkorchestra_update_response_delete(s);
}
};
/// mkorchestra_update_response_uptr is a unique pointer to a
/// mkorchestra_update_response_t instance.
using mkorchestra_update_response_uptr = std::unique_ptr<
mkorchestra_update_response_t, mkorchestra_update_response_deleter>;
/// mkorchestra_collector_deleter is a deleter for
/// mkorchestra_collector_t.
struct mkorchestra_collector_deleter {
void operator()(mkorchestra_collector_t *s) {
mkorchestra_collector_delete(s);
}
};
/// mkorchestra_collector_uptr is a unique pointer to a
/// mkorchestra_collector_t instance.
using mkorchestra_collector_uptr = std::unique_ptr<
mkorchestra_collector_t, mkorchestra_collector_deleter>;
/// mkorchestra_collectors_request_deleter is a deleter for
/// mkorchestra_collectors_request_t.
struct mkorchestra_collectors_request_deleter {
void operator()(mkorchestra_collectors_request_t *s) {
mkorchestra_collectors_request_delete(s);
}
};
/// mkorchestra_collectors_request_uptr is a unique pointer to a
/// mkorchestra_collectors_request_t instance.
using mkorchestra_collectors_request_uptr = std::unique_ptr<
mkorchestra_collectors_request_t, mkorchestra_collectors_request_deleter>;
/// mkorchestra_collectors_response_deleter is a deleter for
/// mkorchestra_collectors_response_t.
struct mkorchestra_collectors_response_deleter {
void operator()(mkorchestra_collectors_response_t *s) {
mkorchestra_collectors_response_delete(s);
}
};
/// mkorchestra_collectors_response_uptr is a unique pointer to a
/// mkorchestra_collectors_response_t instance.
using mkorchestra_collectors_response_uptr = std::unique_ptr<
mkorchestra_collectors_response_t, mkorchestra_collectors_response_deleter>;
/// mkorchestra_testhelper_deleter is a deleter for
/// mkorchestra_testhelper_t.
struct mkorchestra_testhelper_deleter {
void operator()(mkorchestra_testhelper_t *s) {
mkorchestra_testhelper_delete(s);
}
};
/// mkorchestra_testhelper_uptr is a unique pointer to a
/// mkorchestra_testhelper_t instance.
using mkorchestra_testhelper_uptr = std::unique_ptr<
mkorchestra_testhelper_t, mkorchestra_testhelper_deleter>;
/// mkorchestra_testhelpers_request_deleter is a deleter for
/// mkorchestra_testhelpers_request_t.
struct mkorchestra_testhelpers_request_deleter {
void operator()(mkorchestra_testhelpers_request_t *s) {
mkorchestra_testhelpers_request_delete(s);
}
};
/// mkorchestra_testhelpers_request_uptr is a unique pointer to a
/// mkorchestra_testhelpers_request_t instance.
using mkorchestra_testhelpers_request_uptr = std::unique_ptr<
mkorchestra_testhelpers_request_t, mkorchestra_testhelpers_request_deleter>;
/// mkorchestra_testhelpers_response_deleter is a deleter for
/// mkorchestra_testhelpers_response_t.
struct mkorchestra_testhelpers_response_deleter {
void operator()(mkorchestra_testhelpers_response_t *s) {
mkorchestra_testhelpers_response_delete(s);
}
};
/// mkorchestra_testhelpers_response_uptr is a unique pointer to a
/// mkorchestra_testhelpers_response_t instance.
using mkorchestra_testhelpers_response_uptr = std::unique_ptr<
mkorchestra_testhelpers_response_t, mkorchestra_testhelpers_response_deleter>;
/// mkorchestra_urls_request_deleter is a deleter for
/// mkorchestra_urls_request_t.
struct mkorchestra_urls_request_deleter {
void operator()(mkorchestra_urls_request_t *s) {
mkorchestra_urls_request_delete(s);
}
};
/// mkorchestra_urls_request_uptr is a unique pointer to a
/// mkorchestra_urls_request_t instance.
using mkorchestra_urls_request_uptr = std::unique_ptr<
mkorchestra_urls_request_t, mkorchestra_urls_request_deleter>;
/// mkorchestra_urls_response_deleter is a deleter for
/// mkorchestra_urls_response_t.
struct mkorchestra_urls_response_deleter {
void operator()(mkorchestra_urls_response_t *s) {
mkorchestra_urls_response_delete(s);
}
};
/// mkorchestra_urls_response_uptr is a unique pointer to a
/// mkorchestra_urls_response_t instance.
using mkorchestra_urls_response_uptr = std::unique_ptr<
mkorchestra_urls_response_t, mkorchestra_urls_response_deleter>;
/// mkorchestra_register_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_register_response_moveout_logs(
mkorchestra_register_response_uptr &response);
/// mkorchestra_login_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_login_response_moveout_logs(
mkorchestra_login_response_uptr &response);
/// mkorchestra_update_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_update_response_moveout_logs(
mkorchestra_update_response_uptr &response);
/// mkorchestra_collectors_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_collectors_response_moveout_logs(
mkorchestra_collectors_response_uptr &response);
/// mkorchestra_testhelpers_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_testhelpers_response_moveout_logs(
mkorchestra_testhelpers_response_uptr &response);
/// mkorchestra_urls_response_moveout_logs moves the logs out of
/// @p response. It aborts if passed a null pointer.
std::string mkorchestra_urls_response_moveout_logs(
mkorchestra_urls_response_uptr &response);
// The implementation can be included inline by defining this preprocessor
// symbol. If you only care about API, you can stop reading here.
#ifdef MKORCHESTRA_INLINE_IMPL
#include <vector>
#include "json.hpp"
#include "mkcurl.hpp"
#define MKORCHESTRA_CLIENT_METADATA(XX) \
XX(std::string, available_bandwidth) \
XX(std::string, device_token) \
XX(std::string, language) \
XX(std::string, network_type) \
XX(std::string, platform) \
XX(std::string, probe_asn) \
XX(std::string, probe_cc) \
XX(std::string, probe_family) \
XX(std::string, probe_timezone) \
XX(std::string, software_name) \
XX(std::string, software_version) \
XX(std::vector<std::string>, supported_tests)
struct mkorchestra_metadata {
#define declare_attribute(type_, value_) type_ value_;
MKORCHESTRA_CLIENT_METADATA(declare_attribute)
#undef declare_attribute
};
mkorchestra_metadata_t *mkorchestra_metadata_new_nonnull() {
return new mkorchestra_metadata_t;
}
void mkorchestra_metadata_set_available_bandwidth(
mkorchestra_metadata_t *metadata,
const char *available_bandwidth) {
if (metadata == nullptr || available_bandwidth == nullptr) {
abort();
}
metadata->available_bandwidth = available_bandwidth;
}
void mkorchestra_metadata_set_device_token(
mkorchestra_metadata_t *metadata,
const char *device_token) {
if (metadata == nullptr || device_token == nullptr) {
abort();
}
metadata->device_token = device_token;
}
void mkorchestra_metadata_set_language(
mkorchestra_metadata_t *metadata,
const char *language) {
if (metadata == nullptr || language == nullptr) {
abort();
}
metadata->language = language;
}
void mkorchestra_metadata_set_network_type(
mkorchestra_metadata_t *metadata,
const char *network_type) {
if (metadata == nullptr || network_type == nullptr) {
abort();
}
metadata->network_type = network_type;
}
void mkorchestra_metadata_set_platform(
mkorchestra_metadata_t *metadata,
const char *platform) {
if (metadata == nullptr || platform == nullptr) {
abort();
}
metadata->platform = platform;
}
void mkorchestra_metadata_set_probe_asn(
mkorchestra_metadata_t *metadata,
const char *probe_asn) {
if (metadata == nullptr || probe_asn == nullptr) {
abort();
}
metadata->probe_asn = probe_asn;
}
void mkorchestra_metadata_set_probe_cc(
mkorchestra_metadata_t *metadata,
const char *probe_cc) {
if (metadata == nullptr || probe_cc == nullptr) {
abort();
}
metadata->probe_cc = probe_cc;
}
void mkorchestra_metadata_set_probe_family(
mkorchestra_metadata_t *metadata,
const char *probe_family) {
if (metadata == nullptr || probe_family == nullptr) {
abort();
}
metadata->probe_family = probe_family;
}
void mkorchestra_metadata_set_probe_timezone(
mkorchestra_metadata_t *metadata,
const char *probe_timezone) {
if (metadata == nullptr || probe_timezone == nullptr) {
abort();
}
metadata->probe_timezone = probe_timezone;
}
void mkorchestra_metadata_set_software_name(
mkorchestra_metadata_t *metadata,
const char *software_name) {
if (metadata == nullptr || software_name == nullptr) {
abort();
}
metadata->software_name = software_name;
}
void mkorchestra_metadata_set_software_version(
mkorchestra_metadata_t *metadata,
const char *software_version) {