-
Notifications
You must be signed in to change notification settings - Fork 0
/
uemf.h
executable file
·1125 lines (974 loc) · 29.6 KB
/
uemf.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
/*
* uemf.h -- GoAhead Micro Embedded Management Framework Header
*
* Copyright (c) GoAhead Software Inc., 1995-2010. All Rights Reserved.
*
* See the file "license.txt" for usage and redistribution license requirements
*
*/
#ifndef _h_UEMF
#define _h_UEMF 1
/******************************** Description *********************************/
/*
* GoAhead Web Server header. This defines the Web public APIs
*/
/******************************* Per O/S Includes *****************************/
#ifdef WIN
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#include <limits.h>
#include <tchar.h>
#include <windows.h>
#include <winnls.h>
#include <time.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#endif /* WIN */
#ifdef CE
/*#include <errno.h>*/
#include <limits.h>
#include <tchar.h>
#include <windows.h>
#include <winsock.h>
#include <winnls.h>
#include "CE/wincompat.h"
#include <winsock.h>
#endif /* CE */
#ifdef NW
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#include <time.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <niterror.h>
#define EINTR EINUSE
#define WEBS 1
#include <limits.h>
#include <netdb.h>
#include <process.h>
#include <tiuser.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/filio.h>
#include <netinet/in.h>
#endif /* NW */
#ifdef SCOV5
#include <sys/types.h>
#include <stdio.h>
#include "sys/socket.h"
#include "sys/select.h"
#include "netinet/in.h"
#include "arpa/inet.h"
#include "netdb.h"
#endif /* SCOV5 */
#ifdef UNIX
#include <stdio.h>
#endif /* UNIX */
#ifdef LINUX
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#endif /* LINUX */
#ifdef LYNX
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#endif /* LYNX */
#ifdef MACOSX
#include <limits.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#endif /* MACOSX */
#ifdef UW
#include <stdio.h>
#endif /* UW */
#ifdef VXWORKS
#include <vxWorks.h>
#include <sockLib.h>
#include <selectLib.h>
#include <inetLib.h>
#include <ioLib.h>
#include <stdio.h>
#include <stat.h>
#include <time.h>
#include <usrLib.h>
#include <fcntl.h>
#include <errno.h>
#endif /* VXWORKS */
#ifdef sparc
# define __NO_PACK
#endif /* sparc */
#ifdef SOLARIS
#include <sys/types.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#endif /* SOLARIS */
#ifdef QNX4
#include <sys/types.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/uio.h>
#include <sys/wait.h>
#endif /* QNX4 */
#ifdef ECOS
#include <limits.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/kernel/kapi.h>
#include <time.h>
#include <network.h>
#include <errno.h>
#endif /* ECOS */
/********************************** Includes **********************************/
#include <ctype.h>
#include <stdarg.h>
#include <string.h>
#ifndef WEBS
#include "messages.h"
#endif /* ! WEBS */
/******************************* Per O/S Defines *****************************/
#ifdef UW
#define __NO_PACK 1
#endif /* UW */
#if (defined (SCOV5) || defined (VXWORKS) || defined (LINUX) || defined (LYNX) || defined (MACOSX))
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#define SOCKET_ERROR -1
#endif /* SCOV5 || VXWORKS || LINUX || LYNX || MACOSX */
#if (defined (WIN) || defined (CE))
/*
* __NO_FCNTL means can't access fcntl function. Fcntl.h is still available.
*/
#define __NO_FCNTL 1
#undef R_OK
#define R_OK 4
#undef W_OK
#define W_OK 2
#undef X_OK
#define X_OK 1
#undef F_OK
#define F_OK 0
typedef int socklen_t;
#endif /* WIN || CE */
#if (defined (LINUX) && !defined (_STRUCT_TIMEVAL))
struct timeval
{
time_t tv_sec; /* Seconds. */
time_t tv_usec; /* Microseconds. */
};
#define _STRUCT_TIMEVAL 1
#endif /* LINUX && ! _STRUCT_TIMEVAL */
#ifdef ECOS
#define O_RDONLY 1
#define O_BINARY 2
#define __NO_PACK 1
#define __NO_EJ_FILE 1
#define __NO_CGI_BIN 1
#define __NO_FCNTL 1
/*
* #define LIBKERN_INLINE to avoid kernel inline functions
*/
#define LIBKERN_INLINE
#endif /* ECOS */
#ifdef QNX4
typedef long fd_mask;
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#endif /* QNX4 */
#ifdef MACOSX
typedef int32_t fd_mask;
#endif
#ifdef NW
#define fd_mask fd_set
#define INADDR_NONE -1l
#define Sleep delay
#define __NO_FCNTL 1
#undef R_OK
#define R_OK 4
#undef W_OK
#define W_OK 2
#undef X_OK
#define X_OK 1
#undef F_OK
#define F_OK 0
#endif /* NW */
/********************************** Unicode ***********************************/
/*
* Constants and limits. Also FNAMESIZE and PATHSIZE are currently defined
* in param.h to be 128 and 512
*/
#define TRACE_MAX (4096 - 48)
#define VALUE_MAX_STRING (4096 - 48)
#define SYM_MAX (512)
#define XML_MAX 4096 /* Maximum size for tags/tokens */
#define BUF_MAX 4096 /* General sanity check for bufs */
#ifndef LINE_MAX
#define LINE_MAX 2048 /* General sanity check for a single line */
#endif /* LINE_MAX */
#define FMT_STATIC_MAX 256 /* Maximum for fmtStatic calls */
#if (defined (LITTLEFOOT) || defined (WEBS))
#define LF_BUF_MAX (510)
#define LF_PATHSIZE LF_BUF_MAX
#else
#define LF_BUF_MAX BUF_MAX
#define LF_PATHSIZE PATHSIZE
#define UPPATHSIZE PATHSIZE
#endif /* LITTLEFOOT || WEBS */
#ifndef CHAR_T_DEFINED
#define CHAR_T_DEFINED 1
#ifdef UNICODE
/*
* To convert strings to UNICODE. We have a level of indirection so things
* like T(__FILE__) will expand properly.
*/
#define T(x) __TXT(x)
#define __TXT(s) L ## s
typedef unsigned short char_t;
typedef unsigned short uchar_t;
/*
* Text size of buffer macro. A buffer bytes will hold (size / char size)
* characters.
*/
#define TSZ(x) (sizeof(x) / sizeof(char_t))
/*
* How many ASCII bytes are required to represent this UNICODE string?
*/
#define TASTRL(x) ((wcslen(x) + 1) * sizeof(char_t))
#else
#define T(s) s
typedef char char_t;
#define TSZ(x) (sizeof(x))
#define TASTRL(x) (strlen(x) + 1)
#ifdef WIN
typedef unsigned char uchar_t;
#endif /* WIN */
#endif /* UNICODE */
#endif /* ! CHAR_T_DEFINED */
/*
* "Boolean" constants
*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
* GoAhead Copyright.
*/
#define GOAHEAD_COPYRIGHT \
T("Copyright (c) GoAhead Software Inc., 1995-2010. All Rights Reserved.")
/*
* The following include has to be after the unicode defines. By putting it
* here, many modules in various parts of the tree are cleaner.
*/
#if (defined (LITTLEFOOT) && defined (INMEM))
#include "lf/inmem.h"
#endif /* LITTLEFOOT && INMEM */
/*
* Type for unicode systems
*/
#ifdef UNICODE
#define gmain wmain
#define gasctime _wasctime
#define gsprintf swprintf
#define gprintf wprintf
#define gfprintf fwprintf
#define gsscanf swscanf
#define gvsprintf vswprintf
#define gstrcpy wcscpy
#define gstrncpy wcsncpy
#define gstrncat wcsncat
#define gstrlen wcslen
#define gstrcat wcscat
#define gstrcmp wcscmp
#define gstrncmp wcsncmp
#define gstricmp wcsicmp
#define gstrchr wcschr
#define gstrrchr wcsrchr
#define gstrtok wcstok
#define gstrnset wcsnset
#define gstrrchr wcsrchr
#define gstrspn wcsspn
#define gstrcspn wcscspn
#define gstrstr wcsstr
#define gstrtol wcstol
#define gfopen _wfopen
#define gopen _wopen
#define gclose close
#define gcreat _wcreat
#define gfgets fgetws
#define gfputs fputws
#define gfscanf fwscanf
#define ggets _getws
#define glseek lseek
#define gunlink _wunlink
#define gread read
#define grename _wrename
#define gwrite write
#define gtmpnam _wtmpnam
#define gtempnam _wtempnam
#define gfindfirst _wfindfirst
#define gfinddata_t _wfinddata_t
#define gfindnext _wfindnext
#define gfindclose _findclose
#define gstat _wstat
#define gaccess _waccess
#define gchmod _wchmod
typedef struct _stat gstat_t;
#define gmkdir _wmkdir
#define gchdir _wchdir
#define grmdir _wrmdir
#define ggetcwd _wgetcwd
#define gtolower towlower
#define gtoupper towupper
#ifdef CE
#define gisspace isspace
#define gisdigit isdigit
#define gisxdigit isxdigit
#define gisupper isupper
#define gislower islower
#define gisprint isprint
#else
#define gremove _wremove
#define gisspace iswspace
#define gisdigit iswdigit
#define gisxdigit iswxdigit
#define gisupper iswupper
#define gislower iswlower
#endif /* if CE */
#define gisalnum iswalnum
#define gisalpha iswalpha
#define gatoi(s) wcstol(s, NULL, 10)
#define gctime _wctime
#define ggetenv _wgetenv
#define gexecvp _wexecvp
#else /* ! UNICODE */
#ifdef VXWORKS
#define gchdir vxchdir
#define gmkdir vxmkdir
#define grmdir vxrmdir
#elif (defined (LYNX) || defined (LINUX) || defined (MACOSX) || defined (SOLARIS))
#define gchdir chdir
#define gmkdir(s) mkdir(s,0755)
#define grmdir rmdir
#else
#define gchdir chdir
#define gmkdir mkdir
#define grmdir rmdir
#endif /* VXWORKS #elif LYNX || LINUX || MACOSX || SOLARIS*/
#define gclose close
#define gclosedir closedir
#define gchmod chmod
#define ggetcwd getcwd
#define glseek lseek
#define gloadModule loadModule
#define gopen open
#define gopendir opendir
#define gread read
#define greaddir readdir
#define grename rename
#define gstat stat
#define gunlink unlink
#define gwrite write
#define gasctime asctime
#define gsprintf sprintf
#define gprintf printf
#define gfprintf fprintf
#define gsscanf sscanf
#define gvsprintf vsprintf
#define gstrcpy strcpy
#define gstrncpy strncpy
#define gstrncat strncat
#define gstrlen strlen
#define gstrcat strcat
#define gstrcmp strcmp
#define gstrncmp strncmp
#define gstricmp strcmpci
#define gstrchr strchr
#define gstrrchr strrchr
#define gstrtok strtok
#define gstrnset strnset
#define gstrrchr strrchr
#define gstrspn strspn
#define gstrcspn strcspn
#define gstrstr strstr
#define gstrtol strtol
#define gfopen fopen
#define gcreat creat
#define gfgets fgets
#define gfputs fputs
#define gfscanf fscanf
#define ggets gets
#define gtmpnam tmpnam
#define gtempnam tempnam
#define gfindfirst _findfirst
#define gfinddata_t _finddata_t
#define gfindnext _findnext
#define gfindclose _findclose
#define gaccess access
typedef struct stat gstat_t;
#define gremove remove
#define gtolower tolower
#define gtoupper toupper
#define gisspace isspace
#define gisdigit isdigit
#define gisxdigit isxdigit
#define gisalnum isalnum
#define gisalpha isalpha
#define gisupper isupper
#define gislower islower
#define gatoi atoi
#define gctime ctime
#define ggetenv getenv
#define gexecvp execvp
#ifndef VXWORKS
#define gmain main
#endif /* ! VXWORKS */
#ifdef VXWORKS
#define fcntl(a, b, c)
#endif /* VXWORKS */
#endif /* ! UNICODE */
#ifdef WIN32
#define getcwd _getcwd
#define tempnam _tempnam
#define open _open
#define close _close
#define read _read
#define write _write
#define chdir _chdir
#define lseek _lseek
#define unlink _unlink
//#define strtok(x, y) strtok_s(x, y, NULL)
#define localtime localtime_s
//#define strcat(x, y) strcat_s(x, elementsof(x), y)
#endif
/*
* Include inmem.h here because it redefines many of the file access fucntions.
* Otherwise there would be lots more #if-#elif-#else-#endif ugliness.
*/
#ifdef INMEM
#include "lf/inmem.h"
#endif
/********************************** Defines ***********************************/
#ifndef FNAMESIZE
#define FNAMESIZE 254 /* Max length of file names */
#endif /* FNAMESIZE */
#define E_MAX_ERROR 4096
#define URL_MAX 4096
#define E_MAX_REQUEST 2048 /* Request safeguard max */
/*
* Error types
*/
#define E_ASSERT 0x1 /* Assertion error */
#define E_LOG 0x2 /* Log error to log file */
#define E_USER 0x3 /* Error that must be displayed */
#define E_L T(__FILE__), __LINE__
#define E_ARGS_DEC char_t *file, int line
#define E_ARGS file, line
#if (defined (ASSERT) || defined (ASSERT_CE))
#define a_assert(C) if (C) ; else error(E_L, E_ASSERT, T("%s"), T(#C))
#else
#define a_assert(C) if (1) ; else
#endif /* ASSERT || ASSERT_CE */
#define elementsof(X) sizeof(X) / sizeof(X[0])
/******************************************************************************/
/* VALUE */
/******************************************************************************/
/*
* These values are not prefixed so as to aid code readability
*/
typedef enum {
undefined = 0,
byteint = 1,
shortint = 2,
integer = 3,
hex = 4,
percent = 5,
octal = 6,
big = 7,
flag = 8,
floating = 9,
string = 10,
bytes = 11,
symbol = 12,
errmsg = 13
} vtype_t;
#ifndef __NO_PACK
#pragma pack(2)
#endif /* _NO_PACK */
typedef struct {
union {
char flag;
char byteint;
short shortint;
char percent;
long integer;
long hex;
long octal;
long big[2];
#ifdef FLOATING_POINT_SUPPORT
double floating;
#endif /* FLOATING_POINT_SUPPORT */
char_t *string;
char *bytes;
char_t *errmsg;
void *symbol;
} value;
vtype_t type;
unsigned int valid : 8;
unsigned int allocated : 8; /* String was balloced */
} value_t;
#ifndef __NO_PACK
#pragma pack()
#endif /* __NO_PACK */
/*
* Allocation flags
*/
#define VALUE_ALLOCATE 0x1
#define value_numeric(t) (t >= byteint && t <= big)
#define value_str(t) (t >= string && t <= bytes)
#define value_ok(t) (t > undefined && t <= symbol)
#define VALUE_VALID { {0}, integer, 1 }
#define VALUE_INVALID { {0}, undefined, 0 }
/******************************************************************************/
/*
* A ring queue allows maximum utilization of memory for data storage and is
* ideal for input/output buffering. This module provides a highly effecient
* implementation and a vehicle for dynamic strings.
*
* WARNING: This is a public implementation and callers have full access to
* the queue structure and pointers. Change this module very carefully.
*
* This module follows the open/close model.
*
* Operation of a ringq where rq is a pointer to a ringq :
*
* rq->buflen contains the size of the buffer.
* rq->buf will point to the start of the buffer.
* rq->servp will point to the first (un-consumed) data byte.
* rq->endp will point to the next free location to which new data is added
* rq->endbuf will point to one past the end of the buffer.
*
* Eg. If the ringq contains the data "abcdef", it might look like :
*
* +-------------------------------------------------------------------+
* | | | | | | | | a | b | c | d | e | f | | | | |
* +-------------------------------------------------------------------+
* ^ ^ ^ ^
* | | | |
* rq->buf rq->servp rq->endp rq->enduf
*
* The queue is empty when servp == endp. This means that the queue will hold
* at most rq->buflen -1 bytes. It is the fillers responsibility to ensure
* the ringq is never filled such that servp == endp.
*
* It is the fillers responsibility to "wrap" the endp back to point to
* rq->buf when the pointer steps past the end. Correspondingly it is the
* consumers responsibility to "wrap" the servp when it steps to rq->endbuf.
* The ringqPutc and ringqGetc routines will do this automatically.
*/
/*
* Ring queue buffer structure
*/
typedef struct {
unsigned char *buf; /* Holding buffer for data */
unsigned char *servp; /* Pointer to start of data */
unsigned char *endp; /* Pointer to end of data */
unsigned char *endbuf; /* Pointer to end of buffer */
int buflen; /* Length of ring queue */
int maxsize; /* Maximum size */
int increment; /* Growth increment */
} ringq_t;
/*
* Block allocation (balloc) definitions
*/
#ifdef B_STATS
#ifndef B_L
#define B_L T(__FILE__), __LINE__
#define B_ARGS_DEC char_t *file, int line
#define B_ARGS file, line
#endif /* B_L */
#endif /* B_STATS */
/*
* Block classes are: 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192,
* 16384, 32768, 65536
*/
typedef struct {
union {
void *next; /* Pointer to next in q */
int size; /* Actual requested size */
} u;
int flags; /* Per block allocation flags */
} bType;
#define B_SHIFT 4 /* Convert size to class */
#define B_ROUND ((1 << (B_SHIFT)) - 1)
#define B_MAX_CLASS 13 /* Maximum class number + 1 */
#define B_MALLOCED 0x80000000 /* Block was malloced */
#define B_DEFAULT_MEM (64 * 1024) /* Default memory allocation */
#define B_MAX_FILES (512) /* Maximum number of files */
#define B_FILL_CHAR (0x77) /* Fill byte for buffers */
#define B_FILL_WORD (0x77777777) /* Fill word for buffers */
#define B_MAX_BLOCKS (64 * 1024) /* Maximum allocated blocks */
/*
* Flags. The integrity value is used as an arbitrary value to fill the flags.
*/
#define B_INTEGRITY 0x8124000 /* Integrity value */
#define B_INTEGRITY_MASK 0xFFFF000 /* Integrity mask */
#define B_USE_MALLOC 0x1 /* Okay to use malloc if required */
#define B_USER_BUF 0x2 /* User supplied buffer for mem */
/*
* The symbol table record for each symbol entry
*/
typedef struct sym_t {
struct sym_t *forw; /* Pointer to next hash list */
value_t name; /* Name of symbol */
value_t content; /* Value of symbol */
int arg; /* Parameter value */
} sym_t;
typedef int sym_fd_t; /* Returned by symOpen */
/*
* Script engines
*/
#define EMF_SCRIPT_JSCRIPT 0 /* javascript */
#define EMF_SCRIPT_TCL 1 /* tcl */
#define EMF_SCRIPT_EJSCRIPT 2 /* Ejscript */
#define EMF_SCRIPT_MAX 3
#if !defined(HAVE_MAXINT)
#define MAXINT INT_MAX
#endif
#define BITSPERBYTE 8
#define BITS(type) (BITSPERBYTE * (int) sizeof(type))
#define STRSPACE T("\t \n\r\t")
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif /* max */
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif /* min */
/******************************************************************************/
/* CRON */
/******************************************************************************/
typedef struct {
char_t *minute;
char_t *hour;
char_t *day;
char_t *month;
char_t *dayofweek;
} cron_t;
extern long cronUntil(cron_t *cp, int period, time_t testTime);
extern int cronAlloc(cron_t *cp, char_t *str);
extern int cronFree(cron_t *cp);
/******************************************************************************/
/* SOCKET */
/******************************************************************************/
/*
* Socket flags
*/
#if ((defined (WIN) || defined (CE)) && defined (WEBS) && !defined(WIN32))
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
#ifndef ENETDOWN
#define ENETDOWN WSAENETDOWN
#endif
#ifndef ECONNRESET
#define ECONNRESET WSAECONNRESET
#endif
#endif /* (WIN || CE) && WEBS) */
#define SOCKET_EOF 0x1 /* Seen end of file */
#define SOCKET_CONNECTING 0x2 /* Connect in progress */
#define SOCKET_BROADCAST 0x4 /* Broadcast mode */
#define SOCKET_PENDING 0x8 /* Message pending on this socket */
#define SOCKET_FLUSHING 0x10 /* Background flushing */
#define SOCKET_DATAGRAM 0x20 /* Use datagrams */
#define SOCKET_ASYNC 0x40 /* Use async connect */
#define SOCKET_BLOCK 0x80 /* Use blocking I/O */
#define SOCKET_LISTENING 0x100 /* Socket is server listener */
#define SOCKET_CLOSING 0x200 /* Socket is closing */
#define SOCKET_CONNRESET 0x400 /* Socket connection was reset */
#define SOCKET_MYOWNBUFFERS 0x800 /* Not using inBuf/outBuf ringq */
#define SOCKET_PORT_MAX 0xffff /* Max Port size */
/*
* Socket error values
*/
#define SOCKET_WOULDBLOCK 1 /* Socket would block on I/O */
#define SOCKET_RESET 2 /* Socket has been reset */
#define SOCKET_NETDOWN 3 /* Network is down */
#define SOCKET_AGAIN 4 /* Issue the request again */
#define SOCKET_INTR 5 /* Call was interrupted */
#define SOCKET_INVAL 6 /* Invalid */
/*
* Handler event masks
*/
#define SOCKET_READABLE 0x2 /* Make socket readable */
#define SOCKET_WRITABLE 0x4 /* Make socket writable */
#define SOCKET_EXCEPTION 0x8 /* Interested in exceptions */
#define EMF_SOCKET_MESSAGE (WM_USER+13)
#define WEBS_MAX_REQUEST 2048 /* Request safeguard max */
#ifdef LITTLEFOOT
#define SOCKET_BUFSIZ 510 /* Underlying buffer size */
#else
#define SOCKET_BUFSIZ 1024 /* Underlying buffer size */
#endif /* LITTLEFOOT */
typedef void (*socketHandler_t)(int sid, int mask, void* data);
typedef int (*socketAccept_t)(int sid, char *ipaddr, int port,
int listenSid);
typedef struct {
char host[64]; /* Host name */
ringq_t inBuf; /* Input ring queue */
ringq_t outBuf; /* Output ring queue */
ringq_t lineBuf; /* Line ring queue */
socketAccept_t accept; /* Accept handler */
socketHandler_t handler; /* User I/O handler */
void *handler_data; /* User handler data */
int handlerMask; /* Handler events of interest */
int sid; /* Index into socket[] */
int port; /* Port to listen on */
int flags; /* Current state flags */
int sock; /* Actual socket handle */
int fileHandle; /* ID of the file handler */
int interestEvents; /* Mask of events to watch for */
int currentEvents; /* Mask of ready events (FD_xx) */
int selectEvents; /* Events being selected */
int saveMask; /* saved Mask for socketFlush */
int error; /* Last error */
} socket_t;
/********************************* Prototypes *********************************/
/*
* Balloc module
*
*/
extern void bclose();
extern int bopen(void *buf, int bufsize, int flags);
/*
* Define NO_BALLOC to turn off our balloc module altogether
* #define NO_BALLOC 1
*/
#ifdef NO_BALLOC
#define balloc(B_ARGS, num) malloc(num)
#define bfree(B_ARGS, p) free(p)
#define bfreeSafe(B_ARGS, p) \
if (p) { free(p); } else
#define brealloc(B_ARGS, p, num) realloc(p, num)
extern char_t *bstrdupNoBalloc(char_t *s);
extern char *bstrdupANoBalloc(char *s);
#define bstrdup(B_ARGS, s) bstrdupNoBalloc(s)
#define bstrdupA(B_ARGS, s) bstrdupANoBalloc(s)
#define gstrdup(B_ARGS, s) bstrdupNoBalloc(s)
#else /* BALLOC */
#ifndef B_STATS
#define balloc(B_ARGS, num) balloc(num)
#define bfree(B_ARGS, p) bfree(p)
#define bfreeSafe(B_ARGS, p) bfreeSafe(p)
#define brealloc(B_ARGS, p, size) brealloc(p, size)
#define bstrdup(B_ARGS, p) bstrdup(p)
#ifdef UNICODE
#define bstrdupA(B_ARGS, p) bstrdupA(p)
#else /* UNICODE */
#define bstrdupA bstrdup
#endif /* UNICODE */
#endif /* B_STATS */
#define gstrdup bstrdup
extern void *balloc(B_ARGS_DEC, int size);
extern void bfree(B_ARGS_DEC, void *mp);
extern void bfreeSafe(B_ARGS_DEC, void *mp);
extern void *brealloc(B_ARGS_DEC, void *buf, int newsize);
extern char_t *bstrdup(B_ARGS_DEC, char_t *s);
#ifdef UNICODE
extern char *bstrdupA(B_ARGS_DEC, char *s);
#else /* UNICODE */
#define bstrdupA bstrdup
#endif /* UNICODE */
#endif /* BALLOC */
extern void bstats(int handle, void (*writefn)(int handle, char_t *fmt, ...));
/*
* Flags. The integrity value is used as an arbitrary value to fill the flags.
*/
#define B_USE_MALLOC 0x1 /* Okay to use malloc if required */
#define B_USER_BUF 0x2 /* User supplied buffer for mem */
#ifndef LINUX
extern char_t *basename(char_t *name);
#endif /* !LINUX */
typedef void (emfSchedProc)(void *data, int id);
extern int emfSchedCallback(int delay, emfSchedProc *proc, void *arg);
extern void emfUnschedCallback(int id);
extern void emfReschedCallback(int id, int delay);
extern void emfSchedProcess();
extern int emfInstGet();
extern void emfInstSet(int inst);
extern void error(E_ARGS_DEC, int flags, char_t *fmt, ...);
extern void (*errorSetHandler(void (*function)(int etype, char_t *msg))) \
(int etype, char_t *msg);
#ifdef B_STATS
#define hAlloc(x) HALLOC(B_L, x)
#define hAllocEntry(x, y, z) HALLOCENTRY(B_L, x, y, z)
extern int HALLOC(B_ARGS_DEC, void ***map);
extern int HALLOCENTRY(B_ARGS_DEC, void ***list, int *max, int size);
#else
extern int hAlloc(void ***map);
extern int hAllocEntry(void ***list, int *max, int size);
#endif /* B_STATS */