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
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
|
#ifndef INCGUARD_aM91R0ljMWoqtn7F
#define INCGUARD_aM91R0ljMWoqtn7F
#if 0
Qntan - A C module separations framework
http://git.hiddenalpha.ch/qntan.git/tree/README.txt
Doc comments for structs FOLLOW the top of the structs body. Doc comments
for members FOLLOW its signature declaration. Eg:
struct Foo {
/* Doc for 'Foo' goes here.
*/
int (*myFunc)( int x );
/* Here goes description of 'myFunc'.
*/
};
#endif
#ifdef Qntan_USERCONFIG
Qntan_USERCONFIG
#endif
#include <stddef.h> /* size_t */
#include <stdint.h> /* uintptr_t */
#if __cplusplus
extern "C" {
#endif
/*
* "Cls" aka "Closure". The userdata type to pass around for callbacks etc. */
#define Qntan_Cls uintptr_t
#define QNTAN_CLS(OBJ) ((Qntan_Cls)OBJ)
/* data fwd decls */
struct Qntan_EvLoop;
struct Qntan_Mallocator;
struct Qntan_MemArena;
struct Qntan_Executor;
struct Qntan_Scheduler;
struct Qntan_Logger;
struct Qntan_IoMux;
struct Qntan_File;
struct Qntan_FileSystem;
struct Qntan_FourierTransform;
struct Qntan_Process;
struct Qntan_HshTbl;
struct Qntan_HshTbl_Cursor;
struct Qntan_Socket;
struct Qntan_TarEnc;
struct Qntan_TarEnc_Hdr;
struct Qntan_TarDec;
struct Qntan_TarDec_Hdr;
struct Qntan_Cond;
struct Qntan_Mutx;
struct Qntan_Networker;
struct Qntan_CsvDec;
struct Qntan_CsvDec_Mentor;
struct Qntan_CsvIStream;
struct Qntan_CsvIStream_Mentor;
struct Qntan_JsonEnc;
struct Qntan_JsonDec;
struct Qntan_JsonDec_Mentor;
struct Qntan_JsonTreeDec;
struct Qntan_JsonTreeDec_JsonNode;
struct Qntan_XmlDec;
struct Qntan_XmlDec_Mentor;
struct Qntan_HttpClient;
struct Qntan_HttpClient_Exchg;
struct Qntan_HttpClient_Exchg_Opts;
struct Qntan_GfxRenderer;
struct Qntan_JavaBytecodeParser;
struct Qntan_JavaBytecodeParser_Mentor;
struct Qntan_CamtAccount;
struct Qntan_CamtTransaction;
struct Qntan_CamtDec;
struct Qntan_CamtDec_Mentor;
#ifndef Qntan_EvLoop_enque
# define Qntan_EvLoop_enque(A, B, C) (*A)->enque(A, B, C)
#endif
#ifndef Qntan_EvLoop_awaitTokenAdd
# define Qntan_EvLoop_awaitTokenAdd(A) (*A)->addAwaitToken(A)
#endif
#ifndef Qntan_EvLoop_awaitTokenDel
# define Qntan_EvLoop_awaitTokenDel(A) (*A)->delAwaitToken(A)
#endif
#ifndef Qntan_EvLoop_runUntilPause
# define Qntan_EvLoop_runUntilPause(A) (*A)->runUntilPause(A)
#endif
#ifndef Qntan_EvLoop_runUntilDone
# define Qntan_EvLoop_runUntilDone(A) (*A)->runUntilDone(A)
#endif
#ifndef Qntan_EvLoop_isEvLoopThread
# define Qntan_EvLoop_isEvLoopThread(A) (*A)->isEvLoopThread(A)
#endif
struct Qntan_EvLoop {
void (*enque)(
struct Qntan_EvLoop**, void(*fn)(Qntan_Cls), Qntan_Cls );
/* enque a task to the EvLoop. See also Qntan_ThreadPool.enque().
*/
void (*addAwaitToken)( struct Qntan_EvLoop** );
/* TODO write doc
*/
void (*delAwaitToken)( struct Qntan_EvLoop** );
/* TODO write doc
*/
int (*runUntilPause)( struct Qntan_EvLoop** );
/* Process reactor tasks until task queue gets drained.
* TODO document return value
*/
void (*runUntilDone)( struct Qntan_EvLoop** );
/* Process reactor tasks until event loop is signalized to end.
*/
int (*isEvLoopThread)( struct Qntan_EvLoop** );
/* returns NON-zero, if called from the EvLoopThread. This is intended for
* assertions, to check that one is running on the expected thread.
*/
};
#ifndef Qntan_Mallocator_realloc
# define Qntan_Mallocator_realloc(A, B, C, D) (*A)->realloc(A, B, C, D)
#endif
struct Qntan_Mallocator {
/**/
void* (*realloc)(
struct Qntan_Mallocator**, void*oldPtr, size_t oldPtr_sz, size_t newPtr_sz );
/* Basic idea is
* "https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html".
* But keep these details in mind:
*
* Errors are reported via 'errno' as defined by 'realloc' and related
* functions.
*
* In contrast to the traditional funcs, this API requires to also
* pass in the size of 'oldPtr'. If you disagree with this decision you
* should read "https://nullprogram.com/blog/2023/12/17/".
*
* Example "allocate space for an object":
* struct Foo *foo = (*m)->realloc(m, NULL, 0, sizeof*foo)
* if( !foo ){ handle errno... }
*
* Example "free foo":
* (*m)->realloc(m, foo, sizeof*foo, 0)
*
* Example "enlarge foo from 42 to 1042":
* void*tmp = (*m)->realloc(m, foo, 42, 1042)
* if( !tmp ){ handle errno... }
* foo = tmp;
*/
};
struct Qntan_MemArena {
/* Let's say, a special kind of mallocator. Traditionally on a mallocator, caller
* is responsible to ensure alloc/free pairs of calls to prevent memory leaks.
* On an arena in contrast, individual 'free' for every alloc is NOT needed, as
* all the allocated space will be free'd at the end of the arenas lifetime.
* Nevertheless, freeing blocks is still ok. Free calls MUST be transparent to
* the caller and behave like the one in a mallocator. But the arena CAN decide
* itself if it will free anything, or it just ignore the 'free' request (as it
* is going to free everything soon anyway for example).
*/
void* (*realloc)(
struct Qntan_MemArena**, void*oldPtr, size_t oldPtr_sz, size_t newPtr_sz );
/* See 'Qntan_Mallocator.realloc()'.
*/
};
#ifndef Qntan_Executor_enque
# define Qntan_Executor_enque(A, ...) (*A)->enque(A, __VA_ARGS__)
#endif
struct Qntan_Executor {
/**/
void (*enque)( struct Qntan_Executor**, void(*fn)(Qntan_Cls), Qntan_Cls );
/* enque a task to this executor. How the task gets executed depends on what
* executor instance got chosen. This also includes stuff like ThreadPools
* which may execute stuff out of order.
*/
};
#ifndef Qntan_Scheduler_onceAfterMs
# define Qntan_Scheduler_onceAfterMs(A, ...) (*A)->onceAfterMs(A, __VA_ARGS__)
#endif
struct Qntan_Scheduler {
/**/
void (*onceAfterMs)(
struct Qntan_Scheduler**, int delayMs, void(*fn)(int err,Qntan_Cls), Qntan_Cls );
/* Schedule 'fn' to be called after 'delayMs' milliseconds.
* `err` holds negative values on error. For example it could be
* `-ECANCELED` if the scheduled task got canceled.
* TODO: Specify if time refers to wall-clock, monotonic, etc. For now this
* behavior is implementation-defined, BUT MAY IT WILL BE SPECIFIED HERE IN
* FUTURE!
*/
};
struct Qntan_Logger {
/* Logger impls MUST prefer format specifiers that are specified in
* stdio printf and related functions.
* Logger impls SHOULD NOT implement format specifiers that could be
* confused by standard specifiers specified by stdio printf and
* related APIs.
*/
void (*fatal)( struct Qntan_Logger**, char const*fmt, ...);
/**/
void (*error)( struct Qntan_Logger**, char const*fmt, ...);
/**/
void (*warn)( struct Qntan_Logger**, char const*fmt, ...);
/**/
void (*info)( struct Qntan_Logger**, char const*fmt, ...);
/**/
void (*debug)( struct Qntan_Logger**, char const*fmt, ...);
/**/
void (*trace)( struct Qntan_Logger**, char const*fmt, ...);
/**/
};
struct Qntan_IoMux {
/* An IO Multiplexer.
*
* WARN: This is considered a low-level module! It SHOULD only be used by
* low-level modules which abstract away the details of the effective
* file/socket types in use. High-level modules SHOULD NOT use this type
* directly.
*/
void (*read)(
struct Qntan_IoMux**, void*buf, int sz, int cnt, uintptr_t ptrToFILE,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/009695399/functions/fread.html".
* BUT be aware that there are some differences mentioned here!
*
* WARN: 'sz' times 'cnt' outside range 0..INT_MAX is UNDEFINED BEHAVIOR! It
* is recommended that an implementation fails hard if this happens. For
* example by calling 'abort()'.
*
* @param ptrToFILE
* Is a `FILE*` (NOT FileDescriptor!). In most cases you'll need a
* cast to uintptr_t.
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Zero indicates EOF. Positive
* values indicate number of objects that where read.
*/
void (*write)(
struct Qntan_IoMux**, void const*buf, int sz, int cnt,
uintptr_t ptrToFILE, void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html".
* BUT be aware that there are some differences mentioned here!
*
* WARN: 'sz' times 'cnt' outside range 0..INT_MAX is UNDEFINED BEHAVIOR! It
* is recommended that an implementation fails hard if this happens. For
* example by calling 'abort()'.
*
* @param ptrToFILE
* Is a `FILE*` (NOT FileDescriptor!). In most cases you'll need a
* cast to uintptr_t.
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Positive values indicate
* number of objects written.
* TODO define what zero means.
* @param arg
* User defined pointer to pass a context to 'onDone'.
*/
void (*flush)( struct Qntan_IoMux**, uintptr_t ptrToFILE,
void(*onDone)(int,Qntan_Cls), Qntan_Cls );
/* @param ptrToFILE
* Is a `FILE*` (NOT FileDescriptor!). In most cases you'll need a
* cast to uintptr_t.
*/
void (*send)(
struct Qntan_IoMux**, uintptr_t fd, void const*buf, int len, int flags,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/000095399/functions/send.html".
* BUT be aware that there are some differences mentioned here!
* Calls to send MUST NOT overlap. So as long a send call is in progress,
* send MUST NOT be called meanwhile.
*
* @param fd
* FileDescriptor (NOT 'FILE*'!). (Or 'HANDLE' on some ugly platforms).
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Positive values indicate
* number of objects that where read.
* @param arg
* User defined pointer to pass a context to 'onDone'.
*/
void (*recv)(
struct Qntan_IoMux**, uintptr_t fd, void*buf, int len, int flags,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/009695399/functions/recv.html".
* BUT be aware that there are some differences mentioned here!
* Calls to recv MUST NOT overlap. So as long a recv call is in progress,
* recv MUST NOT be called meanwhile.
*
* @param fd
* FileDescriptor (NOT 'FILE*'!). (Or 'HANDLE' on some ugly platforms).
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Zero indicates EOF. Positive
* values indicate number of objects that where read.
* @param arg
* User defined pointer to pass a context to 'onDone'.
*/
void (*accept)(
struct Qntan_IoMux**, uintptr_t sockFd, int flgs,
void(*onDone)(int ret, uintptr_t newClientFd, void*sockaddr, int sockaddr_len, Qntan_Cls),
Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/009695399/functions/accept.html".
* Just with a slightly different API.
*
* @param sockFd
* FileDescriptor (NOT 'FILE*'!). Or 'HANDLE' on some ugly platforms.
* @param flgs
* Set 0x1 if you want 'sockaddr' to be filled.
* Setting any other bit is UNDEFINED BEHAVIOR!
* @param newClientFd
* FileDescriptor (NOT 'FILE*'!). Or 'HANDLE' on some ugly platforms.
* The newly accepted client.
* @param sockaddr, sockaddr_len
* Address of the new client. WARN: Only valid if it got
* requested via 'flgs'. This is only valid as long 'onDone'
* has not yet returned.
*/
};
struct Qntan_File {
/**/
void (*flush)(
struct Qntan_File**, void(*onDone)(int ret, Qntan_Cls), Qntan_Cls );
/**/
void (*write)(
struct Qntan_File**, void const*buf, int sz, int cnt,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/000095399/functions/write.html".
* BUT be aware that there are some differences mentioned here!
* Calls to write MUST NOT overlap. So as long a write call is in progress,
* write MUST NOT be called meanwhile.
*
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Positive values indicate
* number of objects that where read.
*/
void (*read)(
struct Qntan_File**, void*buf, int sz, int cnt,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Basic idea is from
* "https://pubs.opengroup.org/onlinepubs/009695399/functions/recv.html".
* BUT be aware that there are some differences mentioned here!
* Calls to recv MUST NOT overlap. So as long a recv call is in progress,
* recv MUST NOT be called meanwhile.
*
* @param onDone
* Called as soon operation has completed.
* @param ret
* Negative numbers indicate errors. Zero indicates EOF. Positive
* values indicate number of objects that where read.
*/
void (*seek)(
struct Qntan_File**, int64_t off, int whence,
void(*onDone)(int ret, Qntan_Cls), Qntan_Cls );
/* "https://pubs.opengroup.org/onlinepubs/007904875/functions/fseek.html"
* TODO: Maybe this func should be without cback?
*/
void (*tell)( struct Qntan_File**,
void(*onDone)(int64_t ret, Qntan_Cls), Qntan_Cls );
/* "https://pubs.opengroup.org/onlinepubs/007904875/functions/ftell.html"
* TODO: Maybe this func should be without cback?
*/
void (*truncate)( struct Qntan_File**, int64_t size,
void(*onDone)(int,Qntan_Cls), Qntan_Cls );
/* TODO doc
* TODO There's a duplicate in 'FileSystem' of this function.
* WARN: size MUST be zero. Any other value is UB! (aka reserved for
* future specifications)
*/
};
#ifndef Qntan_FileSystem_mkdir
# define Qntan_FileSystem_mkdir(A, ...) (*A)->mkdir(A, __VA_ARGS__)
#endif
#ifndef Qntan_FileSystem_unlink
# define Qntan_FileSystem_unlink(A, ...) (*A)->unlink(A, __VA_ARGS__)
#endif
#ifndef Qntan_FileSystem_rename
# define Qntan_FileSystem_rename(A, ...) (*A)->rename(A, __VA_ARGS__)
#endif
#ifndef Qntan_FileSystem_listDir
# define Qntan_FileSystem_listDir(A, ...) (*A)->listDir(A, __VA_ARGS__)
#endif
struct Qntan_FileSystem_Dirent {
/**/
char const *name;
/**/
char const *type;
/* f=File, d=Directory, b=BlockDev, c=CharDev, p=Pipe, l=Link, s=Socket.
* WARN: This field may not available on all systems! Be prepared for NULL.
*/
// uint64_t size;
// /* File size
// */
};
struct Qntan_FileSystem {
/* VFS (VirtualFileSystem)
* WARN: Heavily experimental API!
* TODO: Review/fix/adjust/tune function signatures.
*/
// void (*getattr)( struct Qntan_FileSystem**, const char*path,
// void(*onDone)(int, struct stat*buf, Qntan_Cls), Qntan_Cls);
// /* Get detail information of a file/dir.
// * 'buf' is only valid until return from 'onDone'.
// */
void (*mkdir)( struct Qntan_FileSystem**, char const*path, uint32_t mode,
void(*onDone)(int, Qntan_Cls), Qntan_Cls );
/* Same idea as
* "https://pubs.opengroup.org/onlinepubs/009696799/functions/mkdir.html"
* just using an async API.
*/
// void (*rmdir)( struct Qntan_FileSystem**, const char*path,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls );
// /**/
// void (*open)( struct Qntan_FileSystem**, const char*path,
// struct fuse_file_info*, void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
// void (*create)( struct Qntan_FileSystem**, const char*path, mode_t mode,
// struct fuse_file_info*, void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
void (*unlink)( struct Qntan_FileSystem**, const char*path,
void(*onDone)(int, Qntan_Cls), Qntan_Cls);
/* Same idea as
* "https://pubs.opengroup.org/onlinepubs/009696799/functions/unlink.html"
* just using an async API.
*/
// void (*truncate)( struct Qntan_FileSystem**, char const*path, off_t size,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /* TODO There's a duplicate in 'File' of this function.
// */
void (*rename)( struct Qntan_FileSystem**, char const*src, char const*dst,
void(*onDone)(int, Qntan_Cls), Qntan_Cls);
/**/
// void (*chmod)( struct Qntan_FileSystem**, char const*path, mode_t,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
// void (*chown)( struct Qntan_FileSystem**, char const*path, uid_t, gid_t,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
// void (*utimens)( struct Qntan_FileSystem**, char const*path, const struct timespec,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls );
// /**/
// void (*release)( struct Qntan_FileSystem**, char const*path, struct fuse_file_info*,
// void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
// /* TODO what about 'close()' ? */
// void (*fsync)( struct Qntan_FileSystem**, char const*path, int isdatasync,
// struct fuse_file_info*, void(*onDone)(int, Qntan_Cls), Qntan_Cls);
// /**/
void (*listDir)(
struct Qntan_FileSystem**,
char const*path,
int flgA,
void(*fn)(
int cnt,
struct Qntan_FileSystem_Dirent*dirents,
int flgB,
Qntan_Cls a,
void(*onFnDone)(Qntan_Cls b),
Qntan_Cls b ),
Qntan_Cls a );
/* `flgA` MUST be zero.
* On error, `cnt` will hold a negative value.
* `fn` gets (probably several times) called with `dirents` holding
* `cnt` number of entries.
* On the last call to `fn`, `flgB & 4` will be set.
* `a` a context passed to `fn`.
* `b` a context that MUST be passed to `onFnDone`.
* `onFnDone` MUST be called exactly once, as soon `fn` has
* completed its work.
*/
};
#ifndef Qntan_FourierTransform_transform
# define Qntan_FourierTransform_transform(A, ...) (*A)->transform(A, __VA_ARGS__)
#endif
struct Qntan_FourierTransform {
/**/
int (*transform)( struct Qntan_FourierTransform**, float*samples, size_t samples_cnt, float*output );
/* WARN: There may be implementations producing odd results if
* 'samples' and 'output' overlap.
* @return negative values on erorr. Zero on success.
*/
};
struct Qntan_Process {
/* TODO write doc
*/
void (*write)(
struct Qntan_Process**, void const*buf, int buf_len, int flgs,
void(*onWritten)(int ret,Qntan_Cls), Qntan_Cls );
/* Writes 'buf' to the childs stdin stream.
*
* @param buf
* This buffer MUST stay valid, until the corresponding
* 'onWritten' callback got called!
* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
int (*signal)( struct Qntan_Process**, int sig );
/* https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html
*
* (HINT: Do not confuse 'signal' and 'kill' names here)
*
* Windoof has no SIGKILL. But this API suports it anyway. You can
* define it as below in your app to use it:
* #define SIGKILL 132
*/
void (*join)( struct Qntan_Process**, int timeoutMs,
void (*onDone)(int,int,int,Qntan_Cls), Qntan_Cls );
/* TODO write doc
*/
};
struct Qntan_HshTbl {
/**/
int (*swap)( struct Qntan_HshTbl**, void*elm, void*ptrToDst );
/* Returns 0 if 'elm' got copied into the hashtable.
* Returns 1 is similar to 'Return 0'. BUT: a matching element did already
* exist and this old element now got swapped into 'ptrToDst'.
* Returns negative values to indicate errors.
*/
int (*addIfNew)( struct Qntan_HshTbl**, void*elm );
/* Returns 0 if 'elm' got copied into the hashtable.
* Returns '-EEXIST' (yep, negated) if 'elm' already exists. Nothing got
* copied anywhere.
* Returns negative values to indicate errors.
*/
int (*del)( struct Qntan_HshTbl**, void*srch, void*ptrToDst );
/* Returns 0 if nothing was removed (eg there's no matching object).
* Returns 1 if found object got moved to 'ptrToDst'.
* Returns negative values on error.
*/
int (*delAny)( struct Qntan_HshTbl**, void*ptrToDst );
/* Returns 0 if nothing was removed (eg there are no elements).
* Returns 1 if any object got moved to 'ptrToDst'. It is UNSPECIFIED which
* elements gets removed.
* Returns negative values on error.
*/
int (*get)( struct Qntan_HshTbl**, void*srch, void*ptrToDst );
/* Returns 0 if there's no object matching 'srch'.
* Returns 1 if found object got copied to 'ptrToDst'. The element itelf
* will swill be present in the table.
*/
uintptr_t (*nObj)( struct Qntan_HshTbl** );
/* Number of objects currently present in this collection.
*/
struct Qntan_HshTbl_Cursor** (*newCursor)( struct Qntan_HshTbl** );
/* Initializes and returns a new cursor. The cursor MUST be passed to
* 'delCursor' when no longer used.
*/
void (*delCursor)( struct Qntan_HshTbl**, struct Qntan_HshTbl_Cursor** );
/**/
};
struct Qntan_HshTbl_Cursor {
int (*next)( struct Qntan_HshTbl_Cursor**, void*ptrToDst );
/* Returns 1 if next element got placed in 'ptrToDst'.
* Returns 0 if there are no more elements to traverse.
* Returns negative values on error.
*/
void (*del)( struct Qntan_HshTbl_Cursor**, void*ptrToDst );
/* moves the element where cursor currently points to to 'ptrToDst' and
* removes it from the table.
*/
};
struct Qntan_Socket {
void (*accept)( struct Qntan_Socket**,
void(*onDone)(int ret,struct Qntan_Socket**clientSock,Qntan_Cls),
Qntan_Cls );
/* Conceptually same idea as
* "https://pubs.opengroup.org/onlinepubs/009696799/functions/accept.html".
*/
void (*send)( struct Qntan_Socket**, void*buf, int buf_len, int flgs,
void(*onDone)(int ret,void*rbuf,Qntan_Cls), Qntan_Cls );
/* Based on "https://pubs.opengroup.org/onlinepubs/000095399/functions/send.html".
*
* @param buf, buf_len
* The octets (and how many of them) to write. This 'buf' MUST stay
* valid until onDone got called.
*
* @param flgs
* (flgs & 1) indicates that data should be flushed.
* (flgs & 2) indicates that after sending buf we have to act like a
* call to
* "https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html"
* with SHUT_WR.
* All not specified flags MUST be set to zero. Passing any other flag
* is UNDEFINED BEHAVIOR!
*
* @param onDone
* The function that gets called when the send operation has completed.
* Negative 'ret' indicates errors. 'rbuf' MUST be the same as 'buf'.
*/
void (*recv)( struct Qntan_Socket**, void*buf, int buf_len,
void(*onDone)(int ret,void*buf,Qntan_Cls), Qntan_Cls );
/* Based on "https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html".
*
* @param onDone.buf
* MUST be the same ptr as passed via 'buf' initially.
*/
void (*close)( struct Qntan_Socket**, void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Based on "https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html".
* WARN: Read doc for 'send' carefully before calling 'close'!
* BROKEN: Api MUST be re-designed! Pooling doesn't work with TLS this way!
*/
};
struct Qntan_TarEnc_Hdr {
char const*path; int path_len;
unsigned mode;
uint32_t uid, gid;
char const usrNm[32], grpNm[32];
uint64_t mTimeEpchSec;
uint64_t nBodyOctets;
uint8_t linkType;
/* 0x30=file, 0x31=hardlink, 0x32=symlink.
*/
char const*link; int link_len;
};
struct Qntan_TarEnc {
/**/
void (*nextEntry)( struct Qntan_TarEnc**, struct Qntan_TarEnc_Hdr*hdr,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param hdr
* The header to begin the next tar entry. From now on, 'write'
* will provide the body belonging to this entry.
* @param ret
* Negative values on error.
* Zero on success.
* Any other values are UNDEFINED BEHAVIOR!
*/
void (*write)( struct Qntan_TarEnc**, void*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param buf
* The next content chunk which belongs to the most recently
* written header.
* @param buf_len
* How many octets to write from 'buf'.
* @param flgs
* 0x4 set means this is last chunk of this entry.
* 0x8 set means, that the whole archive has completed.
* Any other bit set is UNDEFINED BEHAVIOR!
* @param ret
* Negative on errors.
* Count of octets successfully written.
*/
char const* (*getLastErrorStr)( struct Qntan_TarEnc** );
/* Returns the most recent error as a short string message. The
* buffer onwership stays within the impl. So take a copy if you
* need it later.
*/
};
struct Qntan_TarDec_Hdr {
char const*path; int path_len;
unsigned mode;
uint32_t uid, gid;
char const *usrNm; int usrNm_len;
char const *grpNm; int grpNm_len;
uint64_t mTimeEpchSec;
uint64_t nBodyOctets;
uint8_t linkType;
/* 0x30=file, 0x31=hardlink, 0x32=symlink.
*/
char const*link; int link_len;
uint32_t checksum;
uint8_t filetype;
/* TODO doc
*/
};
struct Qntan_TarDec {
/**/
void (*nextHdr)( struct Qntan_TarDec**,
void(*onDone)(int ret, struct Qntan_TarDec_Hdr*hdr,Qntan_Cls), Qntan_Cls );
/* @param ret
* Negative values on error.
* 1 (one) if 'hdr' now contains the requested header.
* 0 (zero) if there are no more entries (EndOf archive reached).
* @param hdr
* Iff 'ret' is one, this contains the requested header.
* WARN: 'hdr' (and stuff where it points to) is only valid uppon
* return from 'onDone'.
* WARN: for any other value of 'ret', value of 'hdr' is unspecified!
*/
void (*readBody)( struct Qntan_TarDec**, void*buf, int buf_cap,
void(*onDone)(void*rbuf, int buf_len, int flg, Qntan_Cls), Qntan_Cls);
/* @param buf
* Where to write the read octets to.
* @param buf_cap
* Maximum count of octets to read.
* @param rbuf
* Same as 'buf', just for convenience to have a reference in
* the callback also.
* @param buf_len
* How many octets actually got read and placed into 'buf'.
* @param flg
* 'flg & 4' indicates that there is no more data (EndOf entry
* reached).
*/
};
#ifndef Qntan_Cond_wait
# define Qntan_Cond_wait(A, ...) (*(A))->wait(A, __VA_ARGS__)
#endif
#ifndef Qntan_Cond_bcast
# define Qntan_Cond_bcast(A) (*(A))->bcast(A)
#endif
#ifndef Qntan_Cond_signal
# define Qntan_Cond_signal(A) (*(A))->signal(A)
#endif
/**/
struct Qntan_Cond {
/* An asynchronous Conditional-Variable.
*/
void (*wait)( struct Qntan_Cond**, struct Qntan_Mutx**,
int64_t tv_sec, int32_t tv_nsec,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Same idea as `pthread_cond_timedwait()`.
* `tv_sec` and `tv_nsec` have the same idea as in `struct timespec`.
* on timeout, `onDone` will be called with `-ETIMEDOUT` (yep, negated).
*/
int (*bcast)( struct Qntan_Cond** );
/* Same idea as `pthread_cond_broadcast()`.
*/
int (*signal)( struct Qntan_Cond** );
/* Same idea as `pthread_cond_signal()`.
*/
};
#ifndef Qntan_Mutx_lock
# define Qntan_Mutx_lock(A) (*(A))->lock(A)
#endif
#ifndef Qntan_Mutx_unlock
# define Qntan_Mutx_unlock(A) (*(A))->unlock(A)
#endif
/**/
struct Qntan_Mutx {
/* Same idea as a `pthread_mutex_t`, just using virtual funcs, to
* increase overkill and make some people sad :D
*/
int (*lock)( struct Qntan_Mutx** );
/* Like `pthread_mutex_lock()`
* WARN: this call may block if mutx already locked! So make sure you
* either
* NEVER HOLD THE MUTX FOR TOO LONG ANYWHERE,
* or
* only `lock()` from threads where blocking is ok.
*/
int (*unlock)( struct Qntan_Mutx** );
/* Like `pthread_mutex_unlock()`
*/
};
struct Qntan_Networker {
/**/
void (*getaddrinfo)(
struct Qntan_Networker**, char const*node, int node_len,
char const*service, int service_len,
int(*onAddress)(int ai_flags, int ai_family, int ai_socktype, int ai_protocol,
void*sockaddr, int sockaddr_len, char const*ai_canonname, Qntan_Cls),
void(*onDone)(int ret, char const*errmsg, Qntan_Cls),
Qntan_Cls );
/* Inspired by
* "https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html"
* but tweaks the api a bit toward callbacks, so it fits better into the idea
* of this libraries asynchronous nature.
*
* @param onAddress
* MUST either return zero to indicate success or -ECANCELED (negated)
* if iteration should stop.
* Returning any other value is UNDEFINED BEHAVIOR!
* @param onDone
* called at end of operation.
*/
};
#ifndef Qntan_CsvDec_reset
# define Qntan_CsvDec_reset(A) (*A)->reset(A)
#endif
#ifndef Qntan_CsvDec_write
# define Qntan_CsvDec_write(A, B, C, D, E, F) (*A)->write(A, B, C, D, E, F)
#endif
struct Qntan_CsvDec {
/**/
void (*reset)( struct Qntan_CsvDec** );
/* Throws away parsing state and prepares to begin parsing on a new input
* document.
*/
void (*write)( struct Qntan_CsvDec**,
void const*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* Write more data to the csv parser. Another `write` call MUST ONLY
* happen after `onDone` of the previous call marks completion of
* the previous action.
* @param flgs
* 0x4 set means this is last chunk. All other bits MUST be set
* to zero.
*/
};
#ifndef Qntan_CsvDec_Mentor_onChunk
# define Qntan_CsvDec_Mentor_onChunk(A, B, C, D, E, F, G, H) (*A)->onChunk(A, B, C, D, E, F, G, H)
#endif
#ifndef Qntan_CsvDec_Mentor_onEnd
# define Qntan_CsvDec_Mentor_onEnd(A, B, C) (*A)->onEnd(A, B, C)
#endif
struct Qntan_CsvDec_Mentor {
/* WARN: Passed buffers only remain valid upon return.
*/
void (*onChunk)( struct Qntan_CsvDec_Mentor**,
int64_t row, int64_t col, char const*buf, int buf_len, int flg,
void(*onDone)(Qntan_Cls), Qntan_Cls );
/* Called repeatedly with chunks of data. `row` is the ONE-based row
* number (so 1st row has nr 1). `col` is the ONE-based column number (so
* 1st colum is nr 1). `flg & 4` indicates this is the last buffer
* for this cell.
*/
// TODO void (*onChunkRaw)( struct Qntan_CsvDec_Mentor**,
// TODO int64_t row, int64_t col, char const*buf, int buf_len, unsigned flg,
// TODO void(*onDone)(Qntan_Cls), Qntan_Cls );
// TODO /* Same as `onChunk`. BUT: Quotations will not be removed, but will
// TODO * be as found in the original document.
// TODO */
void (*onEnd)( struct Qntan_CsvDec_Mentor**, int err, char*emsg );
/* Called ONCE at end. with err `0` on success. `err` is a negated
* error number on erorr. In this case, `emsg` MAY contains error
* details in case of error.
*/
};
struct Qntan_CsvIStream {
/**/
void (*write)( struct Qntan_CsvIStream**,
void const*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
void (*pause)( struct Qntan_CsvIStream** );
/* TODO doc
*/
void (*resume)( struct Qntan_CsvIStream** );
/* TODO doc
*/
};
struct Qntan_CsvIStream_Mentor {
/**/
void (*onCsvRow)(
char const**values, int*values_len, int numCols, Qntan_Cls );
/* Called for every CSV row.
*
* How an implementation could look like:
* void onCsvRow(char const*values, int*values_len, int numCols, Qntan_Cls a){
* for( int iCol = 0 ; iCol < numCols ; ++iCol )
* printf("col[%d]: '%.*s'\n", iCol, values_len[i], values[i]);
* }
*
* @param values
* Array of strings of which this row consists of.
* @param values_len
* Lengths of the strings in 'values'.
* @param numCols
* Number of columns present in this row. Aka number of entries present
* in 'values' and 'values_len'.
*/
void (*onCsvDocEnd)( Qntan_Cls );
/* Called when there are no more rows.
*/
};
struct Qntan_JsonEnc {
/**/
void (*reset)( struct Qntan_JsonEnc** );
/* throws away the current state and sets the encoder for a new run.
*/
void (*flush)( struct Qntan_JsonEnc** );
/* TODO: to me, looks like this should be async and take an 'onDone' cback.
*/
void (*objBeg)( struct Qntan_JsonEnc** );
/**/
void (*objEnd)( struct Qntan_JsonEnc** );
/**/
void (*arrBeg)( struct Qntan_JsonEnc** );
/**/
void (*arrEnd)( struct Qntan_JsonEnc** );
/**/
void (*key)( struct Qntan_JsonEnc**, char const*key, int key_len, int flgs );
/* Can be called multiple times, which will append to the currently in
* progress key. The last call MUST have flg 0x4 set, to indicate end.
* 'key' MUST be in utf8 encoding!
* Any other flags set leads to UNDEFINED BEHAVIOR!
*/
void (*string)( struct Qntan_JsonEnc**, char const*str, int str_len, int flgs );
/* Can be called multiple times, which will append to the currently in
* progress string. The last call MUST have flg 0x4 set, to indicate end.
* 'str' MUST be in utf8 encoding!
* Any other flags set leads to UNDEFINED BEHAVIOR!
*/
void (*number)( struct Qntan_JsonEnc**, double );
/**/
void (*boolean)( struct Qntan_JsonEnc**, int );
/**/
void (*null)( struct Qntan_JsonEnc** );
/**/
};
struct Qntan_JsonDec {
/**/
void (*write)(struct Qntan_JsonDec**, void const*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
};
struct Qntan_JsonDec_Mentor {
/**/
void (*onError)( Qntan_Cls cls, uintmax_t errOff );
/* Called if a parsing error occurs. 'errOff' is a byte offset measured from
* the beginning of the json to the char where the error was detected. Be
* prepared that the error may not be exactly at the pointed location, but
* somewhere near that location.
*/
void (*onJsonDocEnd)( Qntan_Cls cls );
/**/
void (*onJsonObjBeg)( Qntan_Cls cls );
/**/
void (*onJsonObjEnd)( Qntan_Cls cls );
/**/
void (*onJsonArrBeg)( Qntan_Cls cls );
/**/
void (*onJsonArrEnd)( Qntan_Cls cls );
/**/
void (*onJsonNull)( Qntan_Cls cls );
/**/
void (*onJsonBool)( int val, Qntan_Cls cls );
/**/
void (*onJsonNumber)( double value, Qntan_Cls cls );
void (*onJsonStringKeyChunk)( char const*key, int key_len, Qntan_Cls cls );
/* zero-length chunk indicates EOF
*/
void (*onJsonStringChunk)( char const*buf, int buf_len, Qntan_Cls cls );
/* zero-length chunk indicates EOF
*/
};
struct Qntan_JsonTreeDec_JsonNode {
/**/
char type;
/* '{' object
* '[' array
* 'f' float (aka number)
* 'b' bool
* 's' string
* '0' null
*/
struct Qntan_JsonTreeDec_JsonNode *parent;
/* Is NULL for the root node.
*/
char *key; int key_len;
/* If this node is a child in an object, its key will be stored here. So
* for example in JSON '{"foo":42}' if we take current node to be
* number 42, the 'key' will contain "foo". 'key_len' is number of BYTES,
* NOT codepoints.
*/
union /* See 'type' to know which of those values is valid. */ {
double valNumber;
int valBool;
struct/*valString*/{
char const *valStr;
int valStr_len;
};
struct/*object or array. For object keys see 'childs[i]->key' */{
struct Qntan_JsonTreeDec_JsonNode **childs;
int childs_len;
};
};
};
struct Qntan_JsonTreeDec {
/**/
void (*write)( struct Qntan_JsonTreeDec**, void const*buf, int buf_len, int flg,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* flg bit 0x4 means "isLastChunk".
*/
};
struct Qntan_XmlDec {
/**/
void (*pause)( struct Qntan_XmlDec** );
/**/
void (*resume)( struct Qntan_XmlDec** );
/**/
void (*write)( struct Qntan_XmlDec**,
void const*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
};
struct Qntan_XmlDec_Mentor {
/**/
void (*onXmlDocEnd)( Qntan_Cls );
/**/
void (*onElemBeg)( char const*tagName, int tagName_len, Qntan_Cls );
/**/
void (*onElemEnd)( char const*tagName, int tagName_len, Qntan_Cls );
/**/
void (*onAttr)( char const*key, char const*val, Qntan_Cls );
/**/
void (*onChunk)( char const*buf, int buf_len, Qntan_Cls );
/**/
};
struct Qntan_HttpClient_Exchg_Opts {
/* WARN: HTTP IS EXPERMIMENTAL! DO NOT TRUST ANYTHING HERE!
*/
char const *mthd;
/* Eg: 'GET', 'POST', ...
*/
char const *host;
/* Eg: 'example.com', '127.0.0.1', ...
*/
uint16_t port;
/* TCP port to connect to.
*/
char const *url;
/* Eg: "/foo/bar?blubb=true"
*/
char **hdrs;
/* Eg: {"key1", "val1", "key2", "val2", NULL}
*/
uint8_t isTls;
/**/
char const *body;
/* can be NULL, which means body gets written through separate calls.
* MUST be null-byte-terminated.
* MUST NOT contain null-bytes. If you have to, set NULL and use separate
* write calls instead.
*/
Qntan_Cls cls;
/**/
void (*onRspHdr)( char const*proto, int code, char const*msg, char const*const*hdrs, Qntan_Cls );
/* 'proto' looks like "HTTP/1.1". Is zero-terminated.
* 'code' eg 404, simply the http response code.
* 'msg' eg "Not Found", simply the http response phrase. Is zero-terminated.
* 'hdrs' response headers. Same format as the request headers.
*/
void (*onBodyChunk)( char const*buf, int len, int flgs, Qntan_Cls );
/* @param len
* Negative values indicate errors.
* If positive, it indicates how long 'buf' is.
* WARN: if zero or negative, value of 'buf' is unspecified!
* @param flgs
* 'flgs & 4' means this is last buffer (EndOfMsg).
* WARN: Other flags are reserved and may hold ANY value.
*/
};
struct Qntan_HttpClient_Exchg {
/* WARN: HTTP IS EXPERMIMENTAL! DO NOT TRUST ANYTHING HERE!
*/
void (*write)( struct Qntan_HttpClient_Exchg**, void*buf, int len, int flgs,
void(*onDone)(int,Qntan_Cls), Qntan_Cls );
/* Write another request body chunk.
* @param flgs
* 'flgs & 4' means this is the last buffer (aka EndOfMsg).
* WARN: Other flags are reserved and may hold ANY value.
*/
void (*pause)( struct Qntan_HttpClient_Exchg** );
/* Set backpressure. This means that callbacks won't be called anymore.
* Events will be held back until resumed.
*/
void (*resume)( struct Qntan_HttpClient_Exchg** );
/* Cancel backpressure.
*/
};
struct Qntan_HttpClient {
/* WARN: HTTP IS EXPERMIMENTAL! DO NOT TRUST ANYTHING HERE!
*/
void (*httpReq)( struct Qntan_HttpClient**, struct Qntan_HttpClient_Exchg_Opts*,
void(*onDone)( int err, struct Qntan_HttpClient_Exchg**exchg,
void(*unref)(struct Qntan_HttpClient_Exchg**),
Qntan_Cls onDoneArg),
Qntan_Cls onDoneArg );
/* Creates a new HTTP exchange (aka request/response).
* @param onDone
* Will be called with the result.
* @param err
* Negative on erorrs. Zero if 'exchg' is ready-to-use.
* @param exchg
* WARN: Only valid if 'err' is zero. The requested instance.
* @param unref
* The function to be called as soon 'exchg' is no longer used.
* @param onDoneArg
* Passed through closure (aka context).
*/
};
#ifndef Qntan_GfxRenderer_setScissor
# define Qntan_GfxRenderer_setScissor(A, B, C, D, E) (*A)->setScissor(A, B, C, D, E)
#endif
#ifndef Qntan_GfxRenderer_triangleStrip2d
# define Qntan_GfxRenderer_triangleStrip2d(A, B, C) (*A)->triangleStrip2d(A, B, C)
#endif
#ifndef Qntan_GfxRenderer_triangleStrip2dOneColor
# define Qntan_GfxRenderer_triangleStrip2dOneColor(A, B, C, D) (*A)->triangleStrip2dOneColor(A, B, C, D)
#endif
#ifndef Qntan_GfxRenderer_circle2dOneColor
# define Qntan_GfxRenderer_circle2dOneColor(A, B, C, D, E, F) (*A)->circle2dOneColor(A, B, C, D, E, F)
#endif
#ifndef Qntan_GfxRenderer_lineStrip2dOneColor
# define Qntan_GfxRenderer_lineStrip2dOneColor(A, B, C, D, E) (*A)->lineStrip2dOneColor(A, B, C, D, E)
#endif
struct Qntan_GfxVtx2d {
float x, y;
};
struct Qntan_GfxVtx4d {
float x, y, z, w;
};
struct Qntan_GfxVtx2dColor {
float x, y;
uint32_t rgba8888;
};
struct Qntan_GfxMtx4d {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
};
struct Qntan_GfxRenderer {
/* WARN: All around graphics rendering is heavily experimental! Make
* sure you're ready to handle all kind of changes here.
*/
void (*setScissor)( struct Qntan_GfxRenderer**, int x, int y, int w, int h );
/**/
void (*triangleStrip2d)( struct Qntan_GfxRenderer**,
struct Qntan_GfxVtx2dColor const*vertices, int vertices_cnt );
/**/
void (*triangleStrip2dOneColor)( struct Qntan_GfxRenderer**,
struct Qntan_GfxVtx2d const*vertices, int vertices_cnt, uint32_t rgba8888 );
/**/
void (*circle2dOneColor)( struct Qntan_GfxRenderer**,
int x, int y, int w, int h, uint32_t colorRGBA8888 );
/* @param x NOT center.
* @param y NOT center.
* @param w horizontal diameter.
* @param h vertical diameter.
*/
void (*lineStrip2dOneColor)( struct Qntan_GfxRenderer**,
struct Qntan_GfxVtx2d const*vertices, int vertices_cnt,
float lineWidth, uint32_t rgba8888 );
/**/
};
struct Qntan_JavaBytecodeParser {
/**/
void (*write)(
struct Qntan_JavaBytecodeParser**, char const*buf, int buf_len, int flgs,
void(*onDone)(int ret,Qntan_Cls), Qntan_Cls );
/* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
};
struct Qntan_JavaBytecodeParser_Mentor {
/* WARN: Be aware that ConstPool indexes are ONE based as by the java
* specification.
*/
void (*onMagic)( uint32_t magic, struct Qntan_JavaBytecodeParser_Mentor** );
/**/
void (*onClassfileVersion)(
int major, int minor, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolBegin)( int poolSize, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolUtf8)( int poolNr, char const*buf, int buf_len,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolInteger)( int poolNr, int32_t intValue,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolFloat)( int poolNr, float value,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolLong)( int poolNr, int64_t value,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolDouble)( int poolNr, double value,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolStrRef)( int poolNr, int dstIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolClassRef)( int poolNr, int nameIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolMethodRef)( int poolNr, int classIdx, int nameAndTypeIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolIfaceMethodRef)( int poolNr, int nameIdx, int nameAndTypeIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolFieldRef)( int poolNr, int nameIdx, int nameAndTypeIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolNameAndType)( int poolNr, int nameIdx, int typeIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolMethodHandle)( int poolNr, int refKind, int refIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolMethodType)( int poolNr, int descrIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolInvokeDynamic)( int poolNr, int bootstrapMethodAttrIdx, int nameAndTypeIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolModule)( int poolNr, uint16_t nameIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolPackage)( int poolNr, uint16_t nameIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onConstPoolEnd)( struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onAccessFlags)( uint16_t accessFlags, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onThisClass)( int nameIdx, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onSuperClass)( int nameIdx, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onIfacesBegin)( int numIfaces, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onIface)( int iIface, int classIdx, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onIfacesEnd)( struct Qntan_JavaBytecodeParser_Mentor**cls );
/* TODO is this cback really needed?
*/
void (*onFieldsBegin)( uint16_t numFields,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onField)( uint16_t poolIdx, uint16_t accessFlags, uint16_t nameIdx,
uint16_t descrIdx, uint16_t numAttrs,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onMethodsBegin)( int numMethods, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onMethod)( uint16_t accessFlags, int nameIdx, int descrIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onClassAttrsBegin)( int numAttrs, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onAnnotRtVisible)( uint16_t typeIdx, uint16_t numKeyValPairs,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onAnnotRtInVisible)( uint16_t typeIdx, uint16_t numKeyValPairs,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onAnnotKeyValPair)( uint8_t type, uint16_t typeNameIdx,
uint16_t constNameIdx, struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onAnnotKey)( uint8_t type, uint16_t typeNameIdx,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onGenericAttribute)( int nameIdx, uint32_t bodyLength,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onGenericAttributeContent)( uint8_t const*buf, int buf_len,
struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
void (*onEnd)( struct Qntan_JavaBytecodeParser_Mentor**cls );
/**/
};
struct Qntan_CamtAccount {
char iban[32];
char ccy[4];
};
struct Qntan_CamtTransaction {
int valueDate_cap, valueDate_len; char *valueDate;
int bookDate_cap , bookDate_len ; char *bookDate ;
char isCrdt, isDbit;
char ccy[4];
int amtDst_cap , amtDst_len ; char *amtDst ;
int amtSrc_cap , amtSrc_len ; char *amtSrc ;
int dstIban_cap , dstIban_len ; char *dstIban ;
int srcIban_cap , srcIban_len ; char *srcIban ;
int ustrd_cap , ustrd_len ; char *ustrd ;
int addtlInf_cap , addtlInf_len ; char *addtlInf ;
int qrRef_cap , qrRef_len ; char *qrRef ;
};
struct Qntan_CamtDec_Mentor {
/**/
void (*onAccount)( struct Qntan_CamtDec_Mentor**,
struct Qntan_CamtAccount*, void(*onDone)(Qntan_Cls), Qntan_Cls );
/**/
void (*onRecord)( struct Qntan_CamtDec_Mentor**,
struct Qntan_CamtTransaction*, void(*onDone)(Qntan_Cls), Qntan_Cls );
/**/
};
struct Qntan_CamtDec {
/**/
void (*write)(
struct Qntan_CamtDec**, void*buf, int buf_len, int flgs,
void(*onDone)(int,Qntan_Cls), Qntan_Cls );
/* @param flgs
* 0x4 set means this is last chunk.
* Any other bit set is UNDEFINED BEHAVIOR!
*/
};
#if __cplusplus
} /* extern "C" */
#endif
#endif /* INCGUARD_aM91R0ljMWoqtn7F */
|