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 #ifndef PUBLIC_NSAPI_H
35 #define PUBLIC_NSAPI_H
36
37
38
39
40
41
42
43
44
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50
51 #define NSAPI_VERSION 303
52
53
54 #ifdef USE_NSAPI_VERSION
55 #if USE_NSAPI_VERSION <
300 ||
USE_NSAPI_VERSION >
NSAPI_VERSION
56 #error This header file does not support the requested
NSAPI version
57 #else
58 #undef NSAPI_VERSION
59 #define NSAPI_VERSION USE_NSAPI_VERSION
60 #endif
61 #endif
62
63
64
65 #if !defined(
XP_WIN32) && !defined(
XP_UNIX)
66 #if defined(
WIN32) || defined(
_WIN32) || defined(
__WIN32__)
67 #define XP_WIN32
68 #else
69 #define XP_UNIX
70 #endif
71 #endif
72
73 #ifdef XP_UNIX
74 #define NSAPI_PUBLIC
75 #define ZERO(ptr, len) memset(ptr,
0, len)
76 #ifdef AIX
77 #define TCPLEN_T size_t
78 #endif
79 #ifdef HPUX
80 #define TCPLEN_T int
81 #endif
82 #ifndef TCPLEN_T
83 #define TCPLEN_T socklen_t
84 #endif
85 #endif
86
87 #ifdef XP_WIN32
88 #define NSAPI_PUBLIC __declspec(dllexport)
89 struct iovec {
90 char *iov_base;
91 unsigned iov_len;
92 };
93 #ifndef S_ISDIR
94 #define S_ISDIR(mode) ((mode &
S_IFMT) ==
S_IFDIR)
95 #endif
96 #ifndef S_ISREG
97 #define S_ISREG(mode) ((mode &
S_IFMT) ==
S_IFREG)
98 #endif
99 #ifndef S_ISLNK
100 #define S_ISLNK(x) (
0)
101 #endif
102 #define caddr_t PCHAR
103 #define NEED_STRCASECMP
104 #define NEED_STRNCASECMP
105 #define ZERO(ptr, len) ZeroMemory(ptr, len)
106 #define TCPLEN_T int
107 #endif
108
109
110
111
112
113 #define WS_TRUE 1
114 #define WS_FALSE 0
115
116
117 #define MAGNUS_ERROR_LEN 1024
118
119
120 #define CR 13
121 #define LF 10
122 #ifdef XP_WIN32
123 #define ENDLINE "\r\n"
124 #else
125 #define ENDLINE "\n"
126 #endif
127
128
129 #define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
130 #define NCC_MT_MAGIC_LEN 55
131
132
133 #define CINFO_SEPARATOR '.'
134
135
136 #define CINFO_MAX_LEN 1024
137
138
139 #define MAX_ERROR_LEN 4096
140
141
142
143
144 #define LOG_WARN 0
145
146
147
148
149
150 #define LOG_MISCONFIG 1
151
152
153
154
155
156 #define LOG_SECURITY 2
157
158
159
160
161
162
163 #define LOG_FAILURE 3
164
165
166
167
168
169
170 #define LOG_CATASTROPHE 4
171
172
173
174
175 #define LOG_INFORM 5
176
177
178
179
180 #define LOG_VERBOSE 6
181
182
183 #define LOG_DEBUG 7
184
185
186
187
188 #define ERR_TIMEFMT "[%d/%b/%Y:%H:%M:%S]"
189
190
191
192 #define ERRORS_TO_SYSLOG NULL
193
194
195 #define IO_OKAY 1
196 #define IO_ERROR -
1
197 #define IO_EOF 0
198 #define NETBUF_EOF -
1
199 #define NETBUF_ERROR -
2
200 #define NETBUF_FULL -
3
201
202
203 #define FILE_BUFFERSIZE 4096
204
205 #ifdef XP_UNIX
206
207 #define FILE_PATHSEP '/'
208 #define FILE_PARENT "../"
209
210 #elif defined(
XP_WIN32)
211
212 #define FILE_PATHSEP '/'
213 #define FILE_PARENT "..\\"
214
215 #endif
216
217 #define NET_INFINITE_TIMEOUT 0
218 #define NET_ZERO_TIMEOUT -
1
219
220 #ifdef USE_REGEX
221
222 #define WILDPAT_VALID(exp) regexp_valid(exp)
223 #define WILDPAT_MATCH(str, exp) regexp_match(str, exp)
224 #define WILDPAT_CMP(str, exp) regexp_cmp(str, exp)
225 #define WILDPAT_CASECMP(str, exp) regexp_casecmp(str, exp)
226 #define WILDPAT_USES_REGEXP 1
227 #else
228
229 #define WILDPAT_VALID(exp) shexp_valid(exp)
230 #define WILDPAT_MATCH(str, exp) shexp_match(str, exp)
231 #define WILDPAT_CMP(str, exp) shexp_cmp(str, exp)
232 #define WILDPAT_CASECMP(str, exp) shexp_casecmp(str, exp)
233 #define WILDPAT_USES_SHEXP 1
234 #endif
235
236
237 #define NON_WILDPAT -
1
238 #define INVALID_WILDPAT -
2
239 #define VALID_WILDPAT 1
240
241
242 #define NON_SXP NON_WILDPAT
243 #define INVALID_SXP INVALID_WILDPAT
244 #define VALID_SXP VALID_WILDPAT
245
246 #define NON_REGEXP NON_SXP
247 #define INVALID_REGEXP INVALID_SXP
248 #define VALID_REGEXP VALID_SXP
249
250 #define SYSTHREAD_DEFAULT_PRIORITY 16
251
252
253 #define CONF_MAXLEN 16384
254
255 #define HTTP_DATE_LEN 30
256 #define HTTP_DATE_FMT "%a, %d %b %Y %T GMT"
257
258
259 #define PROTOCOL_CONTINUE 100
260 #define PROTOCOL_SWITCHING 101
261 #define PROTOCOL_OK 200
262 #define PROTOCOL_CREATED 201
263 #define PROTOCOL_ACCEPTED 202
264 #define PROTOCOL_NONAUTHORITATIVE 203
265 #define PROTOCOL_NO_RESPONSE 204
266 #define PROTOCOL_NO_CONTENT 204
267 #define PROTOCOL_RESET_CONTENT 205
268 #define PROTOCOL_PARTIAL_CONTENT 206
269 #define PROTOCOL_MULTI_STATUS 207
270 #define PROTOCOL_MULTIPLE_CHOICES 300
271 #define PROTOCOL_MOVED_PERMANENTLY 301
272 #define PROTOCOL_REDIRECT 302
273 #define PROTOCOL_SEE_OTHER 303
274 #define PROTOCOL_NOT_MODIFIED 304
275 #define PROTOCOL_USE_PROXY 305
276 #define PROTOCOL_TEMPORARY_REDIRECT 307
277 #define PROTOCOL_BAD_REQUEST 400
278 #define PROTOCOL_UNAUTHORIZED 401
279 #define PROTOCOL_PAYMENT_REQUIRED 402
280 #define PROTOCOL_FORBIDDEN 403
281 #define PROTOCOL_NOT_FOUND 404
282 #define PROTOCOL_METHOD_NOT_ALLOWED 405
283 #define PROTOCOL_NOT_ACCEPTABLE 406
284 #define PROTOCOL_PROXY_UNAUTHORIZED 407
285 #define PROTOCOL_REQUEST_TIMEOUT 408
286 #define PROTOCOL_CONFLICT 409
287 #define PROTOCOL_GONE 410
288 #define PROTOCOL_LENGTH_REQUIRED 411
289 #define PROTOCOL_PRECONDITION_FAIL 412
290 #define PROTOCOL_ENTITY_TOO_LARGE 413
291 #define PROTOCOL_URI_TOO_LARGE 414
292 #define PROTOCOL_UNSUPPORTED_MEDIA_TYPE 415
293 #define PROTOCOL_REQUESTED_RANGE_NOT_SATISFIABLE 416
294 #define PROTOCOL_EXPECTATION_FAILED 417
295 #define PROTOCOL_LOCKED 423
296 #define PROTOCOL_FAILED_DEPENDENCY 424
297 #define PROTOCOL_SERVER_ERROR 500
298 #define PROTOCOL_NOT_IMPLEMENTED 501
299 #define PROTOCOL_BAD_GATEWAY 502
300 #define PROTOCOL_SERVICE_UNAVAILABLE 503
301 #define PROTOCOL_GATEWAY_TIMEOUT 504
302 #define PROTOCOL_VERSION_NOT_SUPPORTED 505
303 #define PROTOCOL_INSUFFICIENT_STORAGE 507
304
305 #define PROTOCOL_VERSION_HTTP09 9
306 #define PROTOCOL_VERSION_HTTP10 100
307 #define PROTOCOL_VERSION_HTTP11 101
308 #define CURRENT_PROTOCOL_VERSION PROTOCOL_VERSION_HTTP11
309
310
311 #define HTTPS_PORT 443
312 #define HTTPS_URL "https"
313
314
315 #define HTTP_PORT 80
316 #define HTTP_URL "http"
317
318
319 #define REQ_MAX_LINE 4096
320
321
322
323
324
325
326
327
328
329 #define REQ_PROCEED 0
330
331 #define REQ_ABORTED -
1
332
333 #define REQ_NOACTION -
2
334
335 #define REQ_EXIT -
3
336
337 #define REQ_RESTART -
4
338
339 #define REQ_TOOBUSY -
5
340
341
342
343
344
345 #define REQ_PROCESSING -
8
346
347
348
349
350
351
352
353
354 #ifdef XP_UNIX
355 #include <unistd.h>
356 #include <sys/file.h>
357 #include <pthread.h>
358 #ifndef HPUX
359 #include <sys/select.h>
360 #endif
361 #include <sys/socket.h>
362 #include <sys/time.h>
363 #include <sys/types.h>
364 #include <sys/uio.h>
365 #include <fcntl.h>
366 #include <dirent.h>
367 #include <pwd.h>
368 #include <netinet/in.h>
369 #endif
370
371 #ifdef XP_WIN32
372 #include <wtypes.h>
373 #include <winbase.h>
374 #include <direct.h>
375 #include <dirent.h>
376 #include <winsock.h>
377 #endif
378
379 #include <sys/stat.h>
380 #include <ctype.h>
381 #include <stdio.h>
382 #include <stdarg.h>
383 #include <stdlib.h>
384 #include <string.h>
385 #include <errno.h>
386 #include <time.h>
387 #include <inttypes.h>
388
389
390
391 #ifndef TRUE
392 #define TRUE 1
393 #endif
394 #ifndef FALSE
395 #define FALSE 0
396 #endif
397
398
399
400
401
402
403
404
405
406
407 typedef int WSBool;
408
409 #ifndef SYS_FILE_T
410 typedef struct VFSFile *
SYS_FILE;
411 #define SYS_FILE_T void *
412 #endif
413
414 #define SYS_ERROR_FD ((
SYS_FILE)-
1)
415
416 #ifndef SYS_NETFD_T
417 typedef void *
SYS_NETFD;
418 #define SYS_NETFD_T void *
419 #endif
420
421
422 #ifndef SYS_NET_ERRORFD
423 #define SYS_NET_ERRORFD ((
SYS_NETFD)-
1)
424 #endif
425
426
427
428
429
430
431
432
433 typedef struct directive directive;
434 typedef struct dtable dtable;
435 typedef struct httpd_object httpd_object;
436 typedef struct httpd_objset httpd_objset;
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456 typedef struct filebuffer filebuffer;
457
458
459 struct filebuffer {
460 SYS_FILE fd;
461 #ifdef XP_WIN32
462 HANDLE fdmap;
463 #endif
464 caddr_t fp;
465 int len;
466
467 unsigned char *inbuf;
468 int cursize;
469
470 int pos;
471 const char *errmsg;
472 };
473
474
475 #define filebuf_getc(b) ((b)->pos == (b)->len ?
IO_EOF : (
int)((b)->fp)[(b)->pos++])
476
477 #define filebuf_iseof(b) ((b)->pos == (b)->len)
478
479
480 typedef filebuffer
filebuf_t;
481
482 #ifdef XP_WIN32
483
484 #define pipebuf_getc(b) \
485 ((b)->pos != (b)->cursize ? (
int)((b)->inbuf[(b)->pos++]) : pipebuf_next(b,
1))
486 #endif
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505 typedef struct netbuf netbuf;
506 struct netbuf {
507 SYS_NETFD sd;
508
509 int pos, cursize, maxsize, rdtimeout;
510 #ifdef XP_WIN32
511 CHAR address[
64];
512 #endif
513 unsigned char *inbuf;
514 char *errmsg;
515 #ifndef XP_WIN32
516 char address[
64];
517 #endif
518 };
519
520
521
522
523
524
525
526
527 #define netbuf_getc(b) \
528 ((b)->pos != (b)->cursize ? (
int)((b)->inbuf[(b)->pos++]) : netbuf_next(b,
1))
529
530
531
532
533
534 #define buffer_error(b) ((b)->errmsg)
535
536
537
538
539
540
541
542
543
544
545 typedef struct sendfiledata sendfiledata;
546 struct sendfiledata {
547 SYS_FILE fd;
548 off_t offset;
549 size_t len;
550 const void *header;
551 int hlen;
552 const void *trailer;
553 int tlen;
554 };
555
556
557
558
559
560
561
562
563
564 typedef struct iovec NSAPIIOVec;
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 typedef struct cinfo cinfo;
602 struct cinfo {
603 char *type;
604 char *encoding;
605 char *language;
606 };
607
608
609
610
611 #define EVENT_POLLIN 0x1
612 #define EVENT_POLLOUT 0x2
613
614 typedef struct EventHandler EventHandler;
615 typedef struct Event Event;
616
617 typedef int(*eventfunc)(EventHandler*, Event*);
618
619 struct Event {
620 eventfunc fn;
621 eventfunc finish;
622 void *cookie;
623 intptr_t object;
624 int events;
625 int error;
626 };
627
628
629
630
631 typedef void*
CONDVAR;
632 typedef void *
COUNTING_SEMAPHORE;
633 typedef void*
CRITICAL;
634
635 #ifdef XP_UNIX
636 typedef DIR*
SYS_DIR;
637 typedef struct dirent
SYS_DIRENT;
638 #endif
639
640 #ifdef XP_WIN32
641
642 typedef struct dirent_s dirent_s;
643 struct dirent_s {
644 char *d_name;
645 };
646
647 typedef struct dir_s dir_s;
648 struct dir_s {
649 HANDLE dp;
650 WIN32_FIND_DATA fdata;
651 dirent_s de;
652 };
653
654 typedef dir_s*
SYS_DIR;
655 typedef dirent_s
SYS_DIRENT;
656
657 #endif
658
659 typedef struct pb_param pb_param;
660 struct pb_param {
661 char *name,*value;
662 };
663
664 typedef struct pb_entry pb_entry;
665 struct pb_entry {
666 pb_param *param;
667 struct pb_entry *next;
668 };
669
670 typedef struct pblock pblock;
671 struct pblock {
672 int hsize;
673 struct pb_entry **ht;
674 };
675
676 #ifndef POOL_HANDLE_T
677 #define POOL_HANDLE_T
678 typedef void *
pool_handle_t;
679 #endif
680
681 #ifndef SEMAPHORE_T
682
683
684
685 #endif
686
687 #define SESSION_HASHSIZE 5
688
689 typedef struct PListStruct_s PListStruct_s;
690 typedef struct ACLListHandle ACLListHandle;
691 typedef struct VFS VFS;
692 typedef struct VFSContext VFSContext;
693
694 enum WSConfigNodeType {
695 WS_CONFIG_NODE_OBJECT =
0,
696 WS_CONFIG_NODE_DIRECTIVE
697 };
698
699 typedef struct ServerConfiguration ServerConfiguration;
700 typedef struct ConfigNode WSConfigNode;
701 typedef enum WSConfigNodeType WSConfigNodeType;
702
703
704 typedef struct HttpResponseWriter HttpResponseWriter;
705
706 #ifndef PR_AF_INET
707 typedef union PRNetAddr PRNetAddr;
708 #endif
709
710 typedef struct Session Session;
711 typedef struct Request Request;
712 struct Session {
713 pblock *client;
714
715 SYS_NETFD csd;
716 netbuf *inbuf;
717 int csd_open;
718
719 struct in_addr iaddr;
720
721 pool_handle_t *pool;
722
723 EventHandler *ev;
724
725 void *clauth;
726 struct Session *next;
727 int fill;
728 struct sockaddr_in local_addr;
729
730 PListStruct_s *subject;
731 int ssl;
732 int clientauth;
733
734 PRNetAddr *pr_client_addr;
735 PRNetAddr *pr_local_addr;
736 };
737
738
739 typedef struct FuncStruct FuncStruct;
740
741
742
743
744
745
746 #ifdef XP_UNIX
747 typedef int Func(pblock *, Session *, Request *);
748
749 typedef int FuncExec(FuncStruct *, pblock *, Session *, Request *);
750 #else
751 typedef int _cdecl Func(pblock *, Session *, Request *);
752 typedef int _cdecl FuncExec(FuncStruct *, pblock *, Session *, Request *);
753 #endif
754
755 typedef Func *FuncPtr;
756 typedef FuncExec *FuncExecPtr;
757
758
759
760
761
762
763
764 struct FuncStruct {
765 const char *name;
766 FuncPtr func;
767
768 FuncExecPtr func_exec;
769 void *exec_data;
770 unsigned flags;
771 unsigned poolID;
772 unsigned pool_resolved;
773 };
774
775
776
777 typedef struct _http_listener HttpListener;
778
779 typedef struct ResourcePool ResourcePool;
780
781 typedef struct ResourceType ResourceType;
782 typedef struct ResourceData ResourceData;
783
784 typedef void * (*resource_pool_init_func)(
pool_handle_t *,
const char *, pblock *);
785 typedef void (*resource_pool_destroy_func)(
void *);
786 typedef void * (*resource_pool_createresource_func)(
void *);
787 typedef void (*resource_pool_freeresource_func)(
void *,
void *);
788 typedef int (*resource_pool_prepare_func)(
void *,
void *);
789 typedef int (*resource_pool_finish_func)(
void *,
void *);
790 typedef void * (*resource_pool_getresourcedata_func)(
void *);
791
792 struct ResourceType {
793 void * (*init)(
pool_handle_t *,
const char *, pblock *);
794 void (*destroy)(
void *);
795 void * (*createresource)(
void *);
796 void (*freeresource)(
void *,
void *);
797 int (*prepare)(
void *,
void *);
798 int (*finish)(
void *,
void *);
799 void * (*getresourcedata)(
void *);
800 };
801
802 struct ResourceData {
803 ResourcePool *resourcepool;
804 void *data;
805 };
806
807 int resourcepool_register_type(
const char *type_name, ResourceType *type_info);
808
809
810
811
812
813 typedef struct VirtualServer VirtualServer;
814 typedef int VSInitFunc(VirtualServer *incoming,
const VirtualServer *current);
815 typedef void VSDestroyFunc(VirtualServer *outgoing);
816 typedef VSInitFunc *VSInitFuncPtr;
817 typedef VSDestroyFunc *VSDestroyFuncPtr;
818 typedef int VSDirectiveInitFunc(
const directive *dir, VirtualServer *incoming,
const VirtualServer *current);
819 typedef void VSDirectiveDestroyFunc(
const directive *dir, VirtualServer *outgoing);
820 typedef VSDirectiveInitFunc *VSDirectiveInitFuncPtr;
821 typedef VSDirectiveDestroyFunc *VSDirectiveDestroyFuncPtr;
822
823
824
825
826 typedef struct Filter Filter;
827
828
829
830
831
832 typedef struct FilterContext FilterContext;
833
834 struct FilterContext {
835 pool_handle_t *pool;
836 Session *sn;
837 Request *rq;
838 void *data;
839 };
840
841
842
843
844
845 typedef struct FilterLayer FilterLayer;
846
847 struct FilterLayer {
848 Filter *filter;
849 FilterContext *context;
850 SYS_NETFD lower;
851 };
852
853
854
855
856
857
858
859
860 typedef int (*FilterInsertFunc)(FilterLayer *layer, pblock *pb);
861 typedef void (*FilterRemoveFunc)(FilterLayer *layer);
862 typedef int (*FilterFlushFunc)(FilterLayer *layer);
863 typedef int (*FilterReadFunc)(FilterLayer *layer,
void *buf,
int amount,
int timeout);
864 typedef int (*FilterWriteFunc)(FilterLayer *layer,
const void *buf,
int amount);
865 typedef int (*FilterWritevFunc)(FilterLayer *layer,
const NSAPIIOVec *iov,
int iov_size);
866 typedef int (*FilterSendfileFunc)(FilterLayer *layer, sendfiledata *sfd);
867
868
869
870
871
872
873
874 typedef struct FilterMethods FilterMethods;
875
876 struct FilterMethods {
877 size_t size;
878 #if NSAPI_VERSION >=
302
879 FilterInsertFunc *insert;
880 FilterRemoveFunc *remove;
881 FilterFlushFunc *flush;
882 FilterReadFunc *read;
883 FilterWriteFunc *write;
884 FilterWritevFunc *writev;
885 FilterSendfileFunc *sendfile;
886 #else
887 void *reserved1;
888 void *reserved2;
889 void *reserved3;
890 void *reserved4;
891 void *reserved5;
892 void *reserved6;
893 void *reserved7;
894 #endif
895 };
896
897 #define FILTER_METHODS_INITIALIZER \
898 { \
899 sizeof(FilterMethods), \
900 NULL, \
901 NULL, \
902 NULL, \
903 NULL, \
904 NULL, \
905 NULL, \
906 NULL \
907 }
908
909
910
911
912 #define FILTER_CONTENT_GENERATION 0xf0000
913 #define FILTER_CONTENT_TRANSLATION_HIGH 0xa0000
914 #define FILTER_CONTENT_TRANSLATION 0x90000
915 #define FILTER_CONTENT_TRANSLATION_LOW 0x80000
916 #define FILTER_CONTENT_CODING 0x50000
917 #define FILTER_TRANSFER_CODING 0x40000
918 #define FILTER_MESSAGE_CODING 0x30000
919 #define FILTER_TRANSPORT_CODING 0x20000
920 #define FILTER_NETWORK 0x10000
921
922 typedef struct shmem_s shmem_s;
923 struct shmem_s {
924 void *data;
925 #ifdef XP_WIN32
926 HANDLE fdmap;
927 #endif
928 int size;
929
930 char *name;
931 SYS_FILE fd;
932 };
933
934
935
936
937 #ifdef XP_UNIX
938 typedef pthread_t SYS_THREAD;
939 #else
940 typedef void*
SYS_THREAD;
941 #endif
942
943
944 #define SYS_THREAD_ERROR NULL
945
946
947 typedef struct conf_global_vars_s conf_global_vars_s;
948 struct conf_global_vars_s {
949
950
951 int Vport;
952 #define server_portnum
80
953
954
955 char *Vaddr;
956
957
958 struct passwd *Vuserpw;
959
960
961 char *Vchr;
962
963
964 char *Vpidfn;
965
966 #define pool_max conf_getglobals()->Vpool_max
967 int Vpool_max;
968 #define pool_min conf_getglobals()->Vpool_min
969 int Vpool_min;
970 #define pool_life conf_getglobals()->Vpool_life
971 int Vpool_life;
972
973
974 #define pool_maxthreads conf_getglobals()->Vpool_maxthreads
975 int Vpool_maxthreads;
976
977 #define pool_minthreads conf_getglobals()->Vpool_minthreads
978 int Vpool_minthreads;
979
980 char *Vsecure_keyfn;
981 char *Vsecure_certfn;
982
983 #define security_active
0
984 int Vsecurity_active;
985 int Vssl3_active;
986 int Vssl2_active;
987 int Vsecure_auth;
988 int Vsecurity_session_timeout;
989 long Vssl3_session_timeout;
990
991
992 #define server_hostname
"x4"
993 char *Vserver_hostname;
994
995
996 #define root_object conf_getglobals()->Vroot_object
997 char *Vroot_object;
998
999
1000 #define std_os conf_getglobals()->Vstd_os
1001 httpd_objset *Vstd_os;
1002
1003
1004 void *Vacl_root;
1005
1006
1007 char *Vmaster_error_log;
1008
1009
1010 #define server_root conf_getglobals()->Vserver_root
1011 char *Vserver_root;
1012
1013
1014 #define server_id conf_getglobals()->Vserver_id
1015 char *Vserver_id;
1016
1017
1018 char *Vadmin_users;
1019
1020
1021 char *Vnetsite_root;
1022
1023
1024 int digest_stale_timeout;
1025
1026 int single_accept;
1027 int num_keep_alives;
1028 int log_verbose;
1029 int mmap_flags;
1030 int mmap_prots;
1031 int unused1;
1032 int unused2;
1033
1034
1035 int accept_language;
1036
1037 char *mtahost;
1038 char *nntphost;
1039
1040
1041 void *Vacl_root_30;
1042
1043 char *agentFilePath;
1044
1045 int Allowed;
1046
1047 pblock *genericGlobals;
1048
1049 char *agentsACLFile;
1050
1051 int wait_for_cgi;
1052 int cgiwatch_timeout;
1053 int started_by_watchdog;
1054 int restarted_by_watchdog;
1055 int old_accel_cache_enabled;
1056 int Vssl_cache_entries;
1057 int blocking_listen_socket;
1058 pblock **initfns;
1059 char *vs_config_file;
1060 };
1061
1062
1063 #ifdef AIX
1064 #define RQATTR unsigned
1065 #else
1066 #define RQATTR unsigned long
1067 #endif
1068
1069 struct Request {
1070
1071 pblock *vars;
1072
1073
1074 pblock *reqpb;
1075
1076 int loadhdrs;
1077 pblock *headers;
1078
1079
1080 int senthdrs;
1081 pblock *srvhdrs;
1082
1083
1084 httpd_objset *os;
1085
1086 httpd_objset *tmpos;
1087
1088
1089 char *statpath;
1090 char *staterr;
1091 struct stat *finfo;
1092
1093
1094 int aclstate;
1095 int acldirno;
1096 char *aclname;
1097 pblock *aclpb;
1098
1099 ACLListHandle *acllist;
1100 uint32_t aclreqaccess;
1101
1102 VFS *vfs;
1103
1104 void *davCollection;
1105
1106 int request_is_cacheable;
1107 int directive_is_cacheable;
1108
1109 char *cached_headers;
1110 int cached_headers_len;
1111 char *unused;
1112
1113
1114 #define REQ_TIME(x) (x)->req_start
1115 time_t req_start;
1116 short protv_num;
1117 short method_num;
1118 struct rq_attr {
1119 RQATTR abs_uri:
1;
1120 RQATTR chunked:
1;
1121 RQATTR keep_alive:
1;
1122 RQATTR pipelined:
1;
1123 RQATTR internal_req:
1;
1124 RQATTR perm_req:
1;
1125 RQATTR header_file_present:
1;
1126 RQATTR footer_file_present:
1;
1127 RQATTR jvm_attached:
1;
1128 RQATTR req_restarted:
1;
1129 RQATTR jvm_request_locked:
1;
1130 RQATTR default_type_set:
1;
1131 RQATTR is_web_app:
1;
1132 RQATTR ssl_unclean_shutdown:
1;
1133 RQATTR vary_accept_language:
1;
1134 RQATTR reserved:
17;
1135 } rq_attr;
1136 char *hostname;
1137 int allowed;
1138 int byterange;
1139 short status_num;
1140
1141 int staterrno;
1142 Request *orig_rq;
1143 };
1144
1145
1146 #define ABS_URI(x) (x)->rq_attr.abs_uri
1147 #define CHUNKED(x) (x)->rq_attr.chunked
1148 #define KEEP_ALIVE(x) (x)->rq_attr.keep_alive
1149 #define PIPELINED(x) (x)->rq_attr.pipelined
1150 #define INTERNAL_REQUEST(x) (x)->rq_attr.internal_req
1151 #define RESTARTED_REQUEST(x) (x)->rq_attr.req_restarted
1152 #define PERM_REQUEST(x) (x)->rq_attr.perm_req
1153 #define JVM_REQUEST_LOCKED(x) (x)->rq_attr.jvm_request_locked
1154 #define SSL_UNCLEAN_SHUTDOWN(x) (x)->rq_attr.ssl_unclean_shutdown
1155 #define VARY_ACCEPT_LANGUAGE(x) (x)->rq_attr.vary_accept_language
1156
1157
1158 #define METHOD_HEAD 0
1159 #define METHOD_GET 1
1160 #define METHOD_PUT 2
1161 #define METHOD_POST 3
1162 #define METHOD_DELETE 4
1163 #define METHOD_TRACE 5
1164 #define METHOD_OPTIONS 6
1165
1166 #define METHOD_MOVE 7
1167 #define METHOD_INDEX 8
1168 #define METHOD_MKDIR 9
1169 #define METHOD_RMDIR 10
1170 #define METHOD_COPY 11
1171 #define METHOD_MAX 12
1172
1173 #define ISMGET(r) ((r)->method_num ==
METHOD_GET)
1174 #define ISMHEAD(r) ((r)->method_num ==
METHOD_HEAD)
1175 #define ISMPUT(r) ((r)->method_num ==
METHOD_PUT)
1176 #define ISMPOST(r) ((r)->method_num ==
METHOD_POST)
1177 #define ISMDELETE(r) ((r)->method_num ==
METHOD_DELETE)
1178 #define ISMMOVE(r) ((r)->method_num ==
METHOD_MOVE)
1179 #define ISMINDEX(r) ((r)->method_num ==
METHOD_INDEX)
1180 #define ISMMKDIR(r) ((r)->method_num ==
METHOD_MKDIR)
1181 #define ISMRMDIR(r) ((r)->method_num ==
METHOD_RMDIR)
1182 #define ISMCOPY(r) ((r)->method_num ==
METHOD_COPY)
1183 #define ISMTRACE(r) ((r)->method_num ==
METHOD_TRACE)
1184 #define ISMOPTIONS(r) ((r)->method_num ==
METHOD_OPTIONS)
1185
1186
1187
1188 typedef struct aiocb_s {
1189 SYS_FILE filedes;
1190 void *buf;
1191 size_t nbytes;
1192 off_t offset;
1193 ssize_t result;
1194 int result_errno;
1195 Event *event;
1196 EventHandler *evhandler;
1197 } aiocb_s;
1198
1199
1200 typedef struct _thread_pool
threadpool_t;
1201 typedef struct _threadpool_job threadpool_job;
1202 typedef void*(*job_callback_f)(
void *data);
1203
1204
1205 typedef struct WebSocket WebSocket;
1206 typedef struct WSMessage WSMessage;
1207
1208 struct WebSocket {
1209 int (*on_open)(WebSocket *);
1210 int (*on_error)(WebSocket *);
1211 int (*on_message)(WebSocket *, WSMessage *msg);
1212 int (*on_close)(WebSocket *);
1213 void *userdata;
1214 };
1215
1216 struct WSMessage {
1217
1218
1219
1220 char *data;
1221
1222
1223
1224
1225 size_t length;
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 int type;
1239
1240
1241
1242
1243 WSMessage *next;
1244 };
1245
1246
1247
1248
1249
1250
1251
1252
1253 #ifndef INTNSAPI
1254
1255 #if NSAPI_VERSION >=
301
1256
1257
1258
1259
1260
1261 1262
1263
1264
1265 #define __NSAPI_RUNTIME_VERSION nsapi_runtime_version()
1266
1267
1268
1269
1270
1271
1272 1273
1274
1275
1276 #define NSAPI_RUNTIME_VERSION nsapi_runtime_version()
1277
1278 #endif
1279
1280
1281
1282 NSAPI_PUBLIC char* system_version();
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293 #endif
1294
1295 #ifdef XP_UNIX
1296 #define dir_open opendir
1297 #define dir_read readdir
1298 #define dir_close closedir
1299 #define dir_create(path) mkdir(path,
0755)
1300 #define dir_remove rmdir
1301 #define system_chdir chdir
1302 #define file_unix2local(path,p2) strcpy(p2,path)
1303 #endif
1304
1305 #ifdef XP_WIN32
1306 #define dir_create _mkdir
1307 #define dir_remove _rmdir
1308 #define system_chdir SetCurrentDirectory
1309 #endif
1310
1311
1312
1313
1314 #define system_localtime(curtime, ret) util_localtime(curtime, ret)
1315 #define system_gmtime(curtime, ret) util_gmtime(curtime, ret)
1316
1317
1318
1319
1320
1321
1322 #define pblock_find(name, pb) (pblock_fr(name,pb,
0))
1323
1324
1325
1326
1327
1328 #define pblock_remove(name, pb) (pblock_fr(name,pb,
1))
1329
1330
1331
1332
1333
1334 #define session_dns(sn) session_dns_lookup(sn,
0)
1335
1336
1337
1338
1339
1340 #define session_maxdns(sn) session_dns_lookup(sn,
1)
1341
1342
1343
1344
1345 NSAPI_PUBLIC conf_global_vars_s* conf_getglobals();
1346
1347
1348
1349
1350 const VirtualServer* request_get_vs(Request *rq);
1351 #define request_get_vs request_get_vs
1352
1353 struct stat* request_stat_path(
const char *path, Request *rq);
1354 #define request_stat_path request_stat_path
1355
1356 void request_free(Request *rq);
1357 #define request_free request_free
1358
1359 Request* request_restart_internal(
const char *uri, Request *rq);
1360 #define request_restart_internal request_restart_internal
1361
1362
1363 char* vs_translate_uri(
const VirtualServer *vs,
const char *uri);
1364 #define vs_translate_uri vs_translate_uri
1365
1366 char* servact_translate_uri(
char *uri, Session *sn);
1367 #define servact_translate_uri servact_translate_uri
1368 #define request_translate_uri servact_translate_uri
1369
1370 ssize_t net_write(
SYS_NETFD fd,
const void *buf,
size_t nbytes);
1371 ssize_t net_writev(
SYS_NETFD fd,
struct iovec *iovec,
int iovcnt);
1372 ssize_t net_sendfile(
SYS_NETFD fd, sendfiledata *sfd);
1373 ssize_t net_read(
SYS_NETFD fd,
void *buf,
size_t nbytes);
1374 int net_flush(
SYS_NETFD sd);
1375 void net_close(
SYS_NETFD fd);
1376
1377
1378 ssize_t net_printf(
SYS_NETFD fd,
char *format, ...);
1379
1380 int net_setnonblock(
SYS_NETFD fd,
int nonblock);
1381 int net_errno(
SYS_NETFD fd);
1382
1383 NSAPI_PUBLIC pb_param *INTparam_create(
const char *name,
const char *value);
1384
1385 NSAPI_PUBLIC int INTparam_free(pb_param *pp);
1386
1387 NSAPI_PUBLIC pblock *INTpblock_create(
int n);
1388
1389 NSAPI_PUBLIC void INTpblock_free(pblock *pb);
1390
1391 NSAPI_PUBLIC char *INTpblock_findval(
const char *name,
const pblock *pb);
1392
1393 NSAPI_PUBLIC pb_param *INTpblock_nvinsert(
const char *name,
const char *value, pblock *pb);
1394
1395 NSAPI_PUBLIC pb_param *pblock_nvlinsert(
const char *name,
int namelen,
const char *value,
int valuelen, pblock *pb);
1396
1397 NSAPI_PUBLIC pb_param *INTpblock_nninsert(
const char *name,
int value, pblock *pb);
1398
1399 NSAPI_PUBLIC void INTpblock_pinsert(pb_param *pp, pblock *pb);
1400
1401 NSAPI_PUBLIC int INTpblock_str2pblock(
const char *str, pblock *pb);
1402
1403 NSAPI_PUBLIC char *INTpblock_pblock2str(
const pblock *pb,
char *str);
1404
1405 NSAPI_PUBLIC int INTpblock_copy(
const pblock *src, pblock *dst);
1406
1407 NSAPI_PUBLIC pblock *INTpblock_dup(
const pblock *src);
1408
1409 NSAPI_PUBLIC char **INTpblock_pb2env(
const pblock *pb,
char **env);
1410
1411 NSAPI_PUBLIC void pblock_nvreplace (
const char *name,
const char *value, pblock *pb);
1412
1413 NSAPI_PUBLIC pb_param *pblock_param_create(pblock *pb,
const char *name,
const char *value);
1414
1415 NSAPI_PUBLIC pblock *pblock_create_pool(
pool_handle_t *pool_handle,
int n);
1416
1417 NSAPI_PUBLIC pb_param *INTpblock_fr(
const char *name, pblock *pb,
int remove);
1418
1419 NSAPI_PUBLIC char *INTpblock_replace(
const char *name,
char * new_value,pblock *pb);
1420
1421 NSAPI_PUBLIC int INTpblock_str2pblock_lowercasename(
const char *str, pblock *pb);
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445 #define pblock_remove(name, pb) (pblock_fr(name,pb,
1))
1446
1447 #define param_create INTparam_create
1448 #define param_free INTparam_free
1449 #define pblock_create INTpblock_create
1450 #define pblock_free INTpblock_free
1451 #define pblock_findval INTpblock_findval
1452 #define pblock_nvinsert INTpblock_nvinsert
1453 #define pblock_nninsert INTpblock_nninsert
1454 #define pblock_pinsert INTpblock_pinsert
1455 #define pblock_str2pblock INTpblock_str2pblock
1456 #define pblock_pblock2str INTpblock_pblock2str
1457 #define pblock_copy INTpblock_copy
1458 #define pblock_dup INTpblock_dup
1459 #define pblock_pb2env INTpblock_pb2env
1460 #define pblock_fr INTpblock_fr
1461 #define pblock_replace INTpblock_replace
1462
1463
1464
1465 NSAPI_PUBLIC pool_handle_t *INTpool_create(
void);
1466
1467 NSAPI_PUBLIC void *INTpool_mark(
pool_handle_t *pool_handle);
1468
1469 NSAPI_PUBLIC void INTpool_recycle(
pool_handle_t *pool_handle,
void *mark);
1470
1471 NSAPI_PUBLIC void INTpool_destroy(
pool_handle_t *pool_handle);
1472
1473 NSAPI_PUBLIC int INTpool_enabled(
void);
1474
1475 NSAPI_PUBLIC void *INTpool_malloc(
pool_handle_t *pool_handle,
size_t size );
1476
1477 NSAPI_PUBLIC void INTpool_free(
pool_handle_t *pool_handle,
void *ptr );
1478
1479 NSAPI_PUBLIC
1480 void *INTpool_calloc(
pool_handle_t *pool_handle,
size_t nelem,
size_t elsize);
1481
1482 NSAPI_PUBLIC
1483 void *INTpool_realloc(
pool_handle_t *pool_handle,
void *ptr,
size_t size );
1484
1485 NSAPI_PUBLIC
1486 char *INTpool_strdup(
pool_handle_t *pool_handle,
const char *orig_str );
1487
1488 #define pool_create INTpool_create
1489 #define pool_mark INTpool_mark
1490 #define pool_recycle INTpool_recycle
1491 #define pool_destroy INTpool_destroy
1492 #define pool_enabled INTpool_enabled
1493 #define pool_malloc INTpool_malloc
1494 #define pool_free INTpool_free
1495 #define pool_calloc INTpool_calloc
1496 #define pool_realloc INTpool_realloc
1497 #define pool_strdup INTpool_strdup
1498
1499
1500 #define MALLOC malloc
1501 #define CALLOC(size) calloc(
1, size)
1502 #define REALLOC realloc
1503 #define FREE free
1504 #define STRDUP strdup
1505
1506
1507 FuncStruct* func_resolve(pblock *pb, Session *sn, Request *rq);
1508 int func_exec(pblock *pb, Session *sn, Request *rq);
1509 struct FuncStruct func_insert(
char *name, FuncPtr fn);
1510 #define func_insert func_insert
1511
1512
1513 void protocol_status(Session *sn, Request *rq,
int n,
const char *m);
1514
1515 int http_start_response(Session *sn, Request *rq);
1516 #define protocol_start_response http_start_response
1517
1518 HttpResponseWriter *http_create_response(Session *sn, Request *rq);
1519
1520
1521
1522
1523
1524
1525 int http_send_response(HttpResponseWriter *writer);
1526
1527 int request_header(
char *name,
char **value, Session *sn, Request *rq);
1528
1529 char *http_uri2url(
const char *prefix,
const char *suffix);
1530 char *http_uri2url_dynamic(
const char *prefix,
const char *suffix,
1531 Session *sn, Request *rq);
1532 #define protocol_uri2url http_uri2url
1533 #define protocol_uri2url_dynamic http_uri2url_dynamic
1534
1535
1536 NSAPI_PUBLIC void http_format_etag(Session *sn, Request *rq,
char *etagp,
int etaglen,
off_t size,
time_t mtime);
1537 NSAPI_PUBLIC int http_check_preconditions(Session *sn, Request *rq,
struct tm *mtm,
const char *etag);
1538 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq,
struct stat *finfo);
1539 NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq,
struct stat *finfo,
const char *etag);
1540
1541 NSAPI_PUBLIC char **http_hdrs2env(pblock *pb);
1542
1543
1544
1545 NSAPI_PUBLIC int http_handle_websocket(Session *sn, Request *rq, WebSocket *websocket);
1546
1547 NSAPI_PUBLIC int websocket_send_text(
SYS_NETFD csd,
char *msg,
size_t len);
1548
1549
1550
1551
1552 typedef void (*thrstartfunc)(
void *);
1553 SYS_THREAD INTsysthread_start(
int prio,
int stksz, thrstartfunc fn,
void *arg);
1554 NSAPI_PUBLIC void INTsysthread_sleep(
int milliseconds);
1555
1556 #define systhread_start INTsysthread_start
1557 #define systhread_sleep INTsysthread_sleep
1558
1559
1560 void webserver_atrestart(
void (*fn)(
void *),
void *data);
1561 #define magnus_atrestart webserver_atrestart
1562 #define daemon_atrestart webserver_atrestart
1563
1564
1565 NSAPI_PUBLIC int INTshexp_match(
const char *str,
const char *exp);
1566 #define shexp_match INTshexp_match
1567
1568
1569
1570 NSAPI_PUBLIC char *session_dns_lookup(Session *s,
int verify);
1571
1572
1573
1574
1575 NSAPI_PUBLIC netbuf *netbuf_open(
SYS_NETFD sd,
int sz);
1576
1577 NSAPI_PUBLIC void netbuf_close(netbuf *buf);
1578
1579 NSAPI_PUBLIC unsigned char * netbuf_replace(netbuf *buf,
1580 unsigned char *inbuf,
int pos,
int cursize,
int maxsize);
1581
1582 NSAPI_PUBLIC int netbuf_next(netbuf *buf,
int advance);
1583
1584 NSAPI_PUBLIC int netbuf_getbytes(netbuf *buf,
char *buffer,
int size);
1585
1586 NSAPI_PUBLIC int netbuf_grab(netbuf *buf,
int sz);
1587
1588 #define netbuf_open netbuf_open
1589 #define netbuf_close netbuf_close
1590 #define netbuf_replace netbuf_replace
1591 #define netbuf_next netbuf_next
1592 #define netbuf_getbytes netbuf_getbytes
1593 #define netbuf_grab netbuf_grab
1594
1595
1596 NSAPI_PUBLIC int system_fread(
SYS_FILE fd,
void *buf,
int nbyte);
1597 NSAPI_PUBLIC int system_fwrite(
SYS_FILE fd,
const void *buf,
int nbyte);
1598 NSAPI_PUBLIC int system_pread(
SYS_FILE fd,
void *buf,
int nbyte,
off_t offset);
1599 NSAPI_PUBLIC int system_pwrite(
SYS_FILE fd,
const void *buf,
int nbyte,
off_t offset);
1600 NSAPI_PUBLIC off_t system_lseek(
SYS_FILE fd,
off_t offset,
int whence);
1601 NSAPI_PUBLIC int system_fclose(
SYS_FILE fd);
1602
1603 NSAPI_PUBLIC int system_aio_read(aiocb_s *aiocb);
1604 NSAPI_PUBLIC int system_aio_write(aiocb_s *aiocb);
1605
1606
1607 int log_ereport(
int degree,
const char *format, ...);
1608 int log_ereport_v(
int degree,
const char *format, va_list args);
1609 int log_error(
int degree,
const char *func, Session *sn, Request *rq,
1610 const char *format, ...);
1611 int log_error_v(
int degree,
const char *func, Session *sn, Request *rq,
1612 const char *format, va_list args);
1613 int log_message(
const char *degree,
const char *format, ...);
1614 int log_message_v(
const char *degree,
const char *format, va_list args);
1615
1616
1617
1618 NSAPI_PUBLIC int util_errno2status(
int errno_value);
1619 #define util_errno2status util_errno2status
1620 NSAPI_PUBLIC pblock* util_parse_param(
pool_handle_t *pool,
char *query);
1621 #define util_parse_param util_parse_param
1622
1623 void nsapi_function_return(Session *sn, Request *rq,
int ret);
1624
1625
1626 threadpool_t* threadpool_new(
int min,
int max);
1627 int threadpool_start(
threadpool_t *pool);
1628 void* threadpool_func(
void *data);
1629 threadpool_job* threadpool_get_job(
threadpool_t *pool);
1630 void threadpool_run(
threadpool_t *pool, job_callback_f func,
void *data);
1631
1632 int event_pollin(EventHandler *ev,
SYS_NETFD fd, Event *event);
1633 int event_pollout(EventHandler *ev,
SYS_NETFD fd, Event *event);
1634 int event_removepoll(EventHandler *ev,
SYS_NETFD fd);
1635 int event_send(EventHandler *ev, Event *event);
1636
1637
1638 ResourceData* resourcepool_lookup(Session *sn, Request *rq,
const char *name,
int flags);
1639 ResourceData* resourcepool_cfg_lookup(ServerConfiguration *cfg,
const char *name,
int flags);
1640 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource);
1641
1642
1643 NSAPI_PUBLIC char *util_html_escape(
const char *s);
1644
1645
1646 void ws_log_assert(
const char *file,
const char *func,
int line);
1647 #ifdef _DEBUG
1648 #ifndef __FUNCTION__
1649 #define __FUNCTION__ __func__
1650 #endif
1651 #define WS_ASSERT(c)
if(!c) ws_log_assert(
__FILE__,
__FUNCTION__,
__LINE__)
1652 #else
1653 #define WS_ASSERT(c)
1654 #endif
1655
1656
1657
1658 #define SYS_STDERR STDERR_FILENO
1659
1660 #ifdef XP_WIN32
1661
1662
1663
1664 #define ERROR_PIPE \
1665 (
ERROR_BROKEN_PIPE |
ERROR_BAD_PIPE | \
1666 ERROR_PIPE_BUSY |
ERROR_PIPE_LISTENING |
ERROR_PIPE_NOT_CONNECTED)
1667 #define CONVERT_TO_PRINTABLE_FORMAT(Filename) \
1668 { \
1669 register char *s; \
1670 if (Filename) \
1671 for (s = Filename; *s; s++) \
1672 if ( *s ==
'\\') \
1673 *s =
'/'; \
1674 }
1675 #define CONVERT_TO_NATIVE_FS(Filename) \
1676 { \
1677 register char *s; \
1678 if (Filename) \
1679 for (s = Filename; *s; s++) \
1680 if ( *s ==
'/') \
1681 *s =
'\\'; \
1682 }
1683
1684 #ifdef INTNSAPI
1685
1686 #if NSAPI_VERSION >=
302
1687
1688 #endif
1689 #if NSAPI_VERSION >=
303
1690
1691 #endif
1692 #else
1693
1694 #if NSAPI_VERSION >=
302
1695
1696 #endif
1697 #if NSAPI_VERSION >=
303
1698
1699 #endif
1700 #endif
1701
1702 #else
1703
1704
1705 #endif
1706
1707 #ifdef __cplusplus
1708 }
1709 #endif
1710
1711 #endif
1712