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