-
Notifications
You must be signed in to change notification settings - Fork 3
/
barracuda.h
21918 lines (15719 loc) · 555 KB
/
barracuda.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
/*
Barracuda Embedded Web Server Amalgamation for posix
Copyright Real Time Logic LLC. http://realtimelogic.com
*/
#ifndef _a_barracuda_h
#define _a_barracuda_h
#define BA_FILESIZE64
#define lobject_c
#define LUA_CORE
#define BA_API
#define ZIP_ENCRYPTION
#define HTTP_TRACE
#define BA_SHARKSSL
#define SHARKSSL_API
#define _Z_UTIL_H
#define LUA_USE_LINUX
#define _POSIX
#define _REENTRANT
#define _LINUX_
#define _GNU_SOURCE
#include "baextinc.h"
#define HTTP_E_BASE 1
#ifndef __BaErrorCodes_h
#define __BaErrorCodes_h
typedef enum {
FE_MALLOC = HTTP_E_BASE,
FE_ASSERT,
FE_NO_SERV_CON,
FE_SOCKET,
FE_GETHOSTBYNAME,
FE_GETHOSTBYNAME2,
FE_BIND,
FE_LISTEN,
FE_IOCTL,
FE_SETSOCKOPT,
FE_ACCEPT,
FE_NO_IPV6_SUPPORT,
FE_INVALID_CSPREADER,
FE_CANNOT_READ,
FE_MAGIC_NO,
FE_THREAD_LIB,
FE_SSL_ERROR,
FE_HTTPCON_INVALID_DISPEV,
FE_BLUA_PANIC,
FE_EXIT,
FE_INCORRECT_USE,
FE_TYPE_SIZE_ERROR,
FE_WRONG_ENDIAN,
FE_USER_ERROR_1 = HTTP_E_BASE+100,
FE_USER_ERROR_2,
FE_USER_ERROR_3,
FE_USER_ERROR_4,
FE_USER_ERROR_5,
FE_USER_ERROR_6,
FE_USER_ERROR_7,
FE_USER_ERROR_8,
FE_USER_ERROR_9,
FE_USER_ERROR_10
} BaFatalErrorCodes;
typedef enum {
E_NO_ERROR=0,
E_INVALID_SOCKET_CON=-1000,
E_GETHOSTBYNAME,
E_BIND,
E_SOCKET_CLOSED,
E_SOCKET_WRITE_FAILED,
E_SOCKET_READ_FAILED,
E_SOCKET_READ_TIMEOUT,
E_MALLOC,
E_ALREADY_INSERTED,
E_TOO_MUCH_DATA,
E_PAGE_NOT_FOUND,
E_IS_COMMITTED,
E_INVALID_PARAM,
E_MIXING_WRITE_SEND,
E_TOO_MANY_INCLUDES,
E_TOO_MANY_FORWARDS,
E_INCLUDE_OP_NOT_VALID,
E_CANNOT_RESOLVE,
E_CANNOT_CONNECT,
E_INVALID_URL,
E_INVALID_RESPONSE,
E_INCORRECT_USE,
E_SSL_NOT_ENABLED,
E_SHARK_ALERT_RECV,
E_SHARK_CRYPTOERR,
E_SHARK_HANDSHAKE,
E_NOT_TRUSTED,
E_PROXY_AUTH = -500,
E_PROXY_GENERAL,
E_PROXY_NOT_ALLOWED,
E_PROXY_NETWORK,
E_PROXY_HOST,
E_PROXY_REFUSED,
E_PROXY_TTL,
E_PROXY_COMMAND_NOT_SUP,
E_PROXY_ADDRESS_NOT_SUP,
E_PROXY_NOT_COMPATIBLE,
E_PROXY_UNKNOWN
} BaErrorCodes;
#define baFatalE(ecode1, ecode2) baFatalEf(ecode1, ecode2, __FILE__, __LINE__)
#ifdef __cplusplus
extern "C" {
#endif
BA_API void baFatalEf(BaFatalErrorCodes ecode1, unsigned int ecode2,
const char* file, int line);
BA_API const char* baErr2Str(int ecode);
BA_API int baErr2HttpCode(int ecode);
#ifdef __cplusplus
}
#endif
#endif
#ifndef __lxrc_h
#define __lxrc_h
#ifndef _SharkSsl_h
#define _SharkSsl_h
#ifndef _SharkSsl_cfg_h
#define _SharkSsl_cfg_h
#ifndef SHARKSSL_USE_AES_256
#define SHARKSSL_USE_AES_256 1
#endif
#ifndef SHARKSSL_USE_AES_128
#define SHARKSSL_USE_AES_128 1
#endif
#ifndef SHARKSSL_USE_AES_192
#define SHARKSSL_USE_AES_192 0
#endif
#ifndef SHARKSSL_ENABLE_AES_GCM
#define SHARKSSL_ENABLE_AES_GCM 1
#endif
#ifndef SHARKSSL_ENABLE_AES_CCM
#define SHARKSSL_ENABLE_AES_CCM 1
#endif
#ifndef SHARKSSL_USE_CHACHA20
#define SHARKSSL_USE_CHACHA20 1
#endif
#ifndef SHARKSSL_USE_3DES
#define SHARKSSL_USE_3DES 1
#endif
#ifndef SHARKSSL_USE_ARC4
#define SHARKSSL_USE_ARC4 0
#endif
#ifndef SHARKSSL_USE_DES
#define SHARKSSL_USE_DES 0
#endif
#ifndef SHARKSSL_USE_NULL_CIPHER
#define SHARKSSL_USE_NULL_CIPHER 0
#endif
#ifndef SHARKSSL_USE_SHA_256
#define SHARKSSL_USE_SHA_256 1
#endif
#ifndef SHARKSSL_USE_SHA_384
#define SHARKSSL_USE_SHA_384 1
#endif
#ifndef SHARKSSL_USE_SHA_512
#define SHARKSSL_USE_SHA_512 0
#endif
#ifndef SHARKSSL_USE_SHA1
#define SHARKSSL_USE_SHA1 1
#endif
#ifndef SHARKSSL_USE_MD5
#define SHARKSSL_USE_MD5 1
#endif
#ifndef SHARKSSL_USE_POLY1305
#define SHARKSSL_USE_POLY1305 1
#endif
#ifndef SHARKSSL_ENABLE_MD5_CIPHERSUITES
#define SHARKSSL_ENABLE_MD5_CIPHERSUITES 0
#endif
#if SHARKSSL_ENABLE_MD5_CIPHERSUITES
#undef SHARKSSL_USE_MD5
#define SHARKSSL_USE_MD5 1
#endif
#ifndef SHARKSSL_SSL_SERVER_CODE
#define SHARKSSL_SSL_SERVER_CODE 1
#endif
#ifndef SHARKSSL_ACCEPT_CLIENT_HELLO_2_0
#define SHARKSSL_ACCEPT_CLIENT_HELLO_2_0 1
#endif
#ifndef SHARKSSL_ENABLE_CLIENT_AUTH
#define SHARKSSL_ENABLE_CLIENT_AUTH 1
#endif
#ifndef SHARKSSL_SSL_CLIENT_CODE
#define SHARKSSL_SSL_CLIENT_CODE 1
#endif
#ifndef SHARKSSL_ENABLE_SNI
#define SHARKSSL_ENABLE_SNI 1
#endif
#ifndef SHARKSSL_ENABLE_RSA
#define SHARKSSL_ENABLE_RSA 1
#endif
#ifndef SHARKSSL_ENABLE_RSA_BLINDING
#define SHARKSSL_ENABLE_RSA_BLINDING 1
#endif
#ifndef SHARKSSL_ENABLE_SESSION_CACHE
#define SHARKSSL_ENABLE_SESSION_CACHE 1
#endif
#ifndef SHARKSSL_ENABLE_SECURE_RENEGOTIATION
#define SHARKSSL_ENABLE_SECURE_RENEGOTIATION 1
#endif
#ifndef SHARKSSL_ENABLE_CLIENT_INITIATED_RENEGOTIATION
#define SHARKSSL_ENABLE_CLIENT_INITIATED_RENEGOTIATION 0
#endif
#ifndef SHARKSSL_ENABLE_TLS_1_2
#define SHARKSSL_ENABLE_TLS_1_2 1
#endif
#if SHARKSSL_ENABLE_TLS_1_2
#undef SHARKSSL_USE_SHA_256
#define SHARKSSL_USE_SHA_256 1
#endif
#ifndef SHARKSSL_ENABLE_TLS_1_1
#define SHARKSSL_ENABLE_TLS_1_1 1
#endif
#ifndef SHARKSSL_ENABLE_SSL_3_0
#define SHARKSSL_ENABLE_SSL_3_0 0
#endif
#ifndef SHARKSSL_ENABLE_DHE_RSA
#define SHARKSSL_ENABLE_DHE_RSA 1
#endif
#ifndef SHARKSSL_ENABLE_SELECT_CIPHERSUITE
#define SHARKSSL_ENABLE_SELECT_CIPHERSUITE 1
#endif
#ifndef SHARKSSL_SELECT_CIPHERSUITE_LIST_DEPTH
#define SHARKSSL_SELECT_CIPHERSUITE_LIST_DEPTH 8
#endif
#ifndef SHARKSSL_ENABLE_PSK
#define SHARKSSL_ENABLE_PSK 0
#endif
#ifndef SHARKSSL_ENABLE_RSA_API
#define SHARKSSL_ENABLE_RSA_API 1
#endif
#ifndef SHARKSSL_ENABLE_RSA_PKCS1
#define SHARKSSL_ENABLE_RSA_PKCS1 1
#endif
#ifndef SHARKSSL_ENABLE_ECDSA_API
#define SHARKSSL_ENABLE_ECDSA_API 1
#endif
#ifndef SHARKSSL_ECDSA_ONLY_VERIFY
#define SHARKSSL_ECDSA_ONLY_VERIFY 0
#endif
#ifndef SHARKSSL_ENABLE_PEM_API
#define SHARKSSL_ENABLE_PEM_API 1
#endif
#ifndef SHARKSSL_ENABLE_INFO_API
#define SHARKSSL_ENABLE_INFO_API 1
#endif
#ifndef SHARKSSL_ENABLE_CERT_CHAIN
#define SHARKSSL_ENABLE_CERT_CHAIN 1
#endif
#ifndef SHARKSSL_ENABLE_CA_LIST
#define SHARKSSL_ENABLE_CA_LIST 1
#endif
#ifndef SHARKSSL_ENABLE_CERTSTORE_API
#define SHARKSSL_ENABLE_CERTSTORE_API 1
#endif
#ifndef SHARKSSL_ENABLE_CLONE_CERTINFO
#define SHARKSSL_ENABLE_CLONE_CERTINFO 1
#endif
#ifndef SHARKSSL_ENABLE_CERT_KEYUSAGE
#define SHARKSSL_ENABLE_CERT_KEYUSAGE 0
#endif
#ifndef SHARKSSL_MD5_SMALL_FOOTPRINT
#define SHARKSSL_MD5_SMALL_FOOTPRINT 0
#endif
#ifndef SHARKSSL_SHA1_SMALL_FOOTPRINT
#define SHARKSSL_SHA1_SMALL_FOOTPRINT 0
#endif
#ifndef SHARKSSL_SHA256_SMALL_FOOTPRINT
#define SHARKSSL_SHA256_SMALL_FOOTPRINT 0
#endif
#ifndef SHARKSSL_BIGINT_EXP_SLIDING_WINDOW_K
#define SHARKSSL_BIGINT_EXP_SLIDING_WINDOW_K 4
#endif
#ifndef SHARKSSL_BIGINT_MULT_LOOP_UNROLL
#define SHARKSSL_BIGINT_MULT_LOOP_UNROLL 1
#endif
#ifndef SHARKSSL_ENABLE_AES_CTR_MODE
#define SHARKSSL_ENABLE_AES_CTR_MODE 1
#endif
#ifndef SHARKSSL_DES_CIPHER_LOOP_UNROLL
#define SHARKSSL_DES_CIPHER_LOOP_UNROLL 1
#endif
#ifndef SHARKSSL_AES_CIPHER_LOOP_UNROLL
#define SHARKSSL_AES_CIPHER_LOOP_UNROLL 1
#endif
#ifndef SHARKSSL_UNALIGNED_ACCESS
#ifdef UNALIGNED_ACCESS
#define SHARKSSL_UNALIGNED_ACCESS 1
#else
#define SHARKSSL_UNALIGNED_ACCESS 0
#endif
#endif
#ifndef SHARKSSL_BIGINT_WORDSIZE
#define SHARKSSL_BIGINT_WORDSIZE 32
#endif
#ifndef SHARKSSL_USE_ECC
#define SHARKSSL_USE_ECC 1
#endif
#ifndef SHARKSSL_ENABLE_ECDSA
#define SHARKSSL_ENABLE_ECDSA 1
#endif
#ifndef SHARKSSL_ECC_VERIFY_POINT
#define SHARKSSL_ECC_VERIFY_POINT 1
#endif
#ifndef SHARKSSL_ECC_TIMING_RESISTANT
#define SHARKSSL_ECC_TIMING_RESISTANT 0
#endif
#ifndef SHARKSSL_ECC_USE_SECP192R1
#define SHARKSSL_ECC_USE_SECP192R1 0
#endif
#ifndef SHARKSSL_ECC_USE_SECP224R1
#define SHARKSSL_ECC_USE_SECP224R1 0
#endif
#ifndef SHARKSSL_ECC_USE_SECP256R1
#define SHARKSSL_ECC_USE_SECP256R1 1
#endif
#ifndef SHARKSSL_ECC_USE_SECP384R1
#define SHARKSSL_ECC_USE_SECP384R1 1
#endif
#ifndef SHARKSSL_ECC_USE_SECP521R1
#define SHARKSSL_ECC_USE_SECP521R1 1
#endif
#ifndef SHARKSSL_ENABLE_ECDHE_RSA
#define SHARKSSL_ENABLE_ECDHE_RSA 1
#endif
#ifndef SHARKSSL_ENABLE_ECDH_RSA
#define SHARKSSL_ENABLE_ECDH_RSA 1
#endif
#ifndef SHARKSSL_ENABLE_ECDHE_ECDSA
#define SHARKSSL_ENABLE_ECDHE_ECDSA 1
#endif
#ifndef SHARKSSL_ENABLE_ECDH_ECDSA
#define SHARKSSL_ENABLE_ECDH_ECDSA 1
#endif
#ifndef SHARKSSL_OPTIMIZED_BIGINT_ASM
#define SHARKSSL_OPTIMIZED_BIGINT_ASM 0
#endif
#ifndef SHARKSSL_OPTIMIZED_CHACHA_ASM
#define SHARKSSL_OPTIMIZED_CHACHA_ASM 0
#endif
#ifndef SHARKSSL_OPTIMIZED_POLY1305_ASM
#define SHARKSSL_OPTIMIZED_POLY1305_ASM 0
#endif
#ifndef SHARKSSL_USE_RNG_TINYMT
#define SHARKSSL_USE_RNG_TINYMT 0
#endif
#ifndef SHARKSSL_NOPACK
#define SHARKSSL_NOPACK 0
#endif
#endif
#ifdef __cplusplus
#endif
#ifndef SHARKSSL_API
#define SHARKSSL_API
#else
#define SHARKSSL_BA 1
#ifndef ThreadLib_hpp
#ifndef _TargConfig_h
#define _TargConfig_h
#if !defined(B_LITTLE_ENDIAN) && !defined(B_BIG_ENDIAN)
#define B_LITTLE_ENDIAN 1
#endif
#define BA_POSIX
#if defined(GNUC) || defined(__GNU__) || defined(__GNUC_MINOR__)
#ifndef __GNUC__
#define __GNUC__
#endif
#endif
#define HTTP_E_BASE 1
#ifndef SERVER_SOFTWARE_NAME
#define SERVER_SOFTWARE_NAME "BarracudaServer.com (Posix)"
#endif
#ifndef BA_API
#define BA_API
#endif
#if defined(SHARKSSL_LIB)
#if !defined(BA_LIB)
#define BA_LIB SHARKSSL_LIB
#endif
#endif
#if defined(BALUA_LIB)
#if !defined(BA_LIB)
#define BA_LIB BALUA_LIB
#endif
#endif
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__)
#define BAI_FUNC __attribute__((visibility("hidden"))) extern
#define BAI_DATA BAI_FUNC
#else
#define BAI_FUNC extern
#define BAI_DATA extern
#endif
#ifndef SHARKSSL_API
#define SHARKSSL_API BA_API
#endif
#ifndef BALUA_API
#define BALUA_API BA_API
#endif
#ifndef SHARKSSL_USE_SHA_512
#define SHARKSSL_USE_SHA_512 1
#endif
#ifdef BA_64BIT
#define UPTR U64
#define SHARKSSL_ALIGNMENT 4
#endif
#ifndef baAssert
#ifdef NDEBUG
#define baAssert(exp)
#else
#define baAssert(exp) ( (exp) ? (void)0 : baFatalEf(FE_ASSERT, 0, __FILE__, __LINE__) )
#endif
#endif
#ifdef BA_LEAK_CHECK
#else
#ifdef USE_DLMALLOC
#ifdef __cplusplus
extern "C" {
#endif
void init_dlmalloc(char* heapstart, char* heapend);
void* dlmalloc(size_t bytes);
void* dlrealloc(void* oldmem, size_t bytes);
void dlfree(void* mem);
#ifdef __cplusplus
}
#endif
#define baMalloc(size) dlmalloc(size)
#define baRealloc(ptr, size) dlrealloc(ptr, size);
#define baFree(ptr) dlfree(ptr)
#else
#define baMalloc(size) malloc(size)
#define baRealloc(ptr,size) realloc(ptr,size)
#define baFree(ptr) free(ptr)
#endif
#endif
#ifndef _GenPrimT_h
#define _GenPrimT_h
#ifndef _TargConfig_h
#endif
#if defined(__GNUC__) || defined(__CODEWARRIOR__) || defined(__DCC__) || defined(__ghs) || defined(__IAR_SYSTEMS_ICC__) || defined(__ARMCC_VERSION)
typedef unsigned long long U64;
typedef long long S64;
#elif defined(_MSC_VER)
typedef unsigned __int64 U64;
typedef __int64 S64;
#else
#error Add "typedef U64" for your platform
#endif
#ifndef B_OVERLOAD_BASIC_TYPES
typedef signed char S8;
typedef unsigned char U8;
typedef signed short S16;
typedef unsigned short U16;
typedef signed int S32;
typedef unsigned int U32;
#endif
typedef U32 BaTime;
typedef U8 BaBool;
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define S64_getMsw(o) ((S32)(0xFFFFFFFF & ((o) >> 32) ))
#ifdef BA_FILESIZE64
typedef U64 BaFileSize;
typedef S64 SBaFileSize;
#define BA_UFSF "llu"
#define BA_SFSF "lld"
#else
typedef U32 BaFileSize;
typedef S32 SBaFileSize;
#define BA_UFSF "lu"
#define BA_SFSF "ld"
#endif
#ifndef __BaAtoi_h
#define __BaAtoi_h
#ifndef BA_API
#define BA_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
BA_API U64 U64_atoll(const char* s);
BA_API U64 U64_atoll2(const char* s, const char* e);
#define S64_atoll(s) ((S64)U64_atoll(s))
BA_API U32 U32_negate(U32 n);
BA_API U32 U32_atoi(const char* s);
BA_API U32 U32_atoi2(const char* s, const char* e);
BA_API U32 U32_hextoi(const char *s);
#ifdef __cplusplus
}
#endif
#endif
#endif
#define baGetUnixTime() time(0)
#ifdef __cplusplus
extern "C" {
#endif
BA_API unsigned int baGetMsClock(void);
#ifdef __cplusplus
}
#endif
#define bStrncmp strncmp
#define bStrchr strchr
#define bStrstr strstr
#define bStrrchr strrchr
#define bStrncpy strncpy
#define bAtoi atoi
#define bTolower tolower
#define bIsspace isspace
#define bIsxdigit isxdigit
#endif
typedef enum {
ThreadPrioLowest,
ThreadPrioLow,
ThreadPrioNormal,
ThreadPrioHigh,
ThreadPrioHighest
} ThreadPriority;
#ifndef __DOXYGEN__
struct HttpRequest;
struct ThreadMutex;
struct Thread;
#endif
typedef void (*Thread_Run)(struct Thread* th);
#ifdef __cplusplus
extern "C" {
#else
struct ThreadReleaseLock;
#endif
BA_API void ThreadReleaseLock_internalConstructor(
struct ThreadReleaseLock* o, struct HttpRequest* req);
#ifdef __cplusplus
}
#endif
#if defined(__cplusplus)
#ifndef __DOXYGEN__
struct ThreadReleaseLock;
#endif
struct ThreadLock
{
ThreadLock(ThreadMutex& m);
ThreadLock(ThreadMutex* m);
~ThreadLock();
private:
friend struct ThreadReleaseLock;
struct ThreadMutex* mutex;
};
struct ThreadReleaseLock
{
ThreadReleaseLock(struct HttpRequest* req);
ThreadReleaseLock(ThreadMutex& m);
ThreadReleaseLock(ThreadMutex* m);
ThreadReleaseLock(ThreadLock& tl);
ThreadReleaseLock(ThreadLock* tl);
~ThreadReleaseLock();
private:
struct ThreadMutex* mutex;
};
#else
#define ThreadMutexBase ThreadMutex
#define ThreadSemaphoreBase ThreadSemaphore
#define ThreadBase Thread
#endif
#ifndef ThreadLib_hpp
#define ThreadLib_hpp
#ifndef POLICY
#define POLICY SCHED_FIFO
#endif
#ifdef __CYGWIN__
#define SYGW_SEM_FIX(sem) memset(&sem, 0, sizeof(sem))
#else
#define SYGW_SEM_FIX(sem)
#endif
#define INFINITE ((unsigned long)~0)
#ifdef NDEBUG
#define Thread_ce(x) x
#else
#ifdef __cplusplus
extern "C" {
#endif
BA_API void Thread_cef(int status, const char* file, int line);
#ifdef __cplusplus
}
#endif
#define Thread_ce(x) Thread_cef(x, __FILE__, __LINE__)
#endif
struct ThreadSemaphoreBase;
struct ThreadMutexBase;
typedef struct ThreadMutexBase
{
pthread_t tid;
pthread_mutex_t mutex;
} ThreadMutexBase;
#define ThreadMutex_destructor(o) Thread_ce(pthread_mutex_destroy(&(o)->mutex))
#define ThreadMutex_set(o) do {\
Thread_ce(pthread_mutex_lock(&(o)->mutex));\
(o)->tid = pthread_self();\
} while(0)
#define ThreadMutex_release(o) do{\
(o)->tid=0;\
Thread_ce(pthread_mutex_unlock(&(o)->mutex));\
} while(0)
#define ThreadMutex_isOwner(o) ((o)->tid == pthread_self())
#ifdef __cplusplus
extern "C" {
#endif
BA_API void ThreadMutex_constructor(struct ThreadMutexBase* o);
#ifdef __cplusplus
}
#endif
typedef struct ThreadSemaphoreBase
{
#ifdef __APPLE__
sem_t* semPtr;
#else
sem_t sem;
#endif
} ThreadSemaphoreBase;
#ifdef __cplusplus
extern "C" {
#endif
BA_API void ThreadSemaphore_constructor(struct ThreadSemaphoreBase* o);
BA_API void ThreadSemaphore_destructor(struct ThreadSemaphoreBase* o);
#ifdef __cplusplus
}
#endif
#ifdef __APPLE__
#define SEM_PTR(o) (o)->semPtr
#else
#define SEM_PTR(o) &(o)->sem
#endif
#if defined(EINTR)
#ifdef __cplusplus
extern "C" {
#endif