src/server/nsapi.h

changeset 1
3c066d52342d
child 3
137197831306
equal deleted inserted replaced
0:4c89c7683fb6 1:3c066d52342d
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
5 *
6 * THE BSD LICENSE
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * Neither the name of the nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef PUBLIC_NSAPI_H
35 #define PUBLIC_NSAPI_H
36
37 /*
38 * File: nsapi.h
39 *
40 * Description:
41 *
42 * This file defines an interface for extending the server with
43 * in-process plug-ins.
44 */
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /* NSAPI version defined by this header file */
51 #define NSAPI_VERSION 303
52
53 /* Define USE_NSAPI_VERSION to use a specific NSAPI version at compile time */
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 /* --- Begin native platform configuration definitions --- */
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 /* XP_UNIX */
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 /* XP_WIN32 */
108
109 /* --- End native platform configuration definitions --- */
110
111 /* --- Begin miscellaneous definitions --- */
112
113 /* Used in some places as a length limit on error messages */
114 #define MAGNUS_ERROR_LEN 1024
115
116 /* Carriage return and line feed */
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 /* mime.types file identification line */
126 #define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
127 #define NCC_MT_MAGIC_LEN 55
128
129 /* The character which separates extensions with cinfo_find */
130 #define CINFO_SEPARATOR '.'
131
132 /* The maximum length of a line in a mime.types file */
133 #define CINFO_MAX_LEN 1024
134
135 /* The maximum length of an error message */
136 #define MAX_ERROR_LEN 4096
137
138 /*
139 * A warning is a minor mishap, such as a 404 being issued.
140 */
141 #define LOG_WARN 0
142
143 /*
144 * A misconfig is when there is a syntax error or permission violation in
145 * a config file.
146 */
147 #define LOG_MISCONFIG 1
148
149 /*
150 * Security warnings are issued when authentication fails, or a host is
151 * given a 403 return code.
152 */
153 #define LOG_SECURITY 2
154
155 /*
156 * A failure is when a request could not be fulfilled due to an internal
157 * problem, such as a CGI script exiting prematurely, or a filesystem
158 * permissions problem.
159 */
160 #define LOG_FAILURE 3
161
162 /*
163 * A catastrophe is a fatal server error such as running out of
164 * memory or processes, or a system call failing, or even a server crash.
165 * The server child cannot recover from a catastrophe.
166 */
167 #define LOG_CATASTROPHE 4
168
169 /*
170 * Informational message, of no concern.
171 */
172 #define LOG_INFORM 5
173
174 /*
175 * Internal diagnostic message.
176 */
177 #define LOG_VERBOSE 6
178
179 /*
180 * The time format to use in the error log
181 */
182 #define ERR_TIMEFMT "[%d/%b/%Y:%H:%M:%S]"
183
184
185 /* The fd you will get if you are reporting errors to SYSLOG */
186 #define ERRORS_TO_SYSLOG NULL
187
188 /* Return codes from file I/O routines */
189 #define IO_OKAY 1
190 #define IO_ERROR -1
191 #define IO_EOF 0
192 #define NETBUF_EOF -1
193 #define NETBUF_ERROR -2
194 #define NETBUF_FULL -3
195
196 /* The disk page size on this machine. */
197 #define FILE_BUFFERSIZE 4096
198
199 #ifdef XP_UNIX
200
201 #define FILE_PATHSEP '/'
202 #define FILE_PARENT "../"
203
204 #elif defined(XP_WIN32)
205
206 #define FILE_PATHSEP '/'
207 #define FILE_PARENT "..\\"
208
209 #endif /* XP_WIN32 */
210
211 #define NET_INFINITE_TIMEOUT 0
212 #define NET_ZERO_TIMEOUT -1
213
214 #ifdef USE_REGEX
215 /* WILDPAT uses regular expressions */
216 #define WILDPAT_VALID(exp) regexp_valid(exp)
217 #define WILDPAT_MATCH(str, exp) regexp_match(str, exp)
218 #define WILDPAT_CMP(str, exp) regexp_cmp(str, exp)
219 #define WILDPAT_CASECMP(str, exp) regexp_casecmp(str, exp)
220 #define WILDPAT_USES_REGEXP 1
221 #else
222 /* WILDPAT uses shell expressions */
223 #define WILDPAT_VALID(exp) shexp_valid(exp)
224 #define WILDPAT_MATCH(str, exp) shexp_match(str, exp)
225 #define WILDPAT_CMP(str, exp) shexp_cmp(str, exp)
226 #define WILDPAT_CASECMP(str, exp) shexp_casecmp(str, exp)
227 #define WILDPAT_USES_SHEXP 1
228 #endif
229
230 /* Define return codes from WILDPAT_VALID */
231 #define NON_WILDPAT -1 /* exp is ordinary string */
232 #define INVALID_WILDPAT -2 /* exp is an invalid pattern */
233 #define VALID_WILDPAT 1 /* exp is a valid pattern */
234
235 /* Define return codes from regexp_valid and shexp_valid */
236 #define NON_SXP NON_WILDPAT /* exp is an ordinary string */
237 #define INVALID_SXP INVALID_WILDPAT /* exp is an invalid shell exp */
238 #define VALID_SXP VALID_WILDPAT /* exp is a valid shell exp */
239
240 #define NON_REGEXP NON_SXP
241 #define INVALID_REGEXP INVALID_SXP
242 #define VALID_REGEXP VALID_SXP
243
244 #define SYSTHREAD_DEFAULT_PRIORITY 16
245
246 /* The longest line in the configuration file */
247 #define CONF_MAXLEN 16384
248
249 #define HTTP_DATE_LEN 30
250 #define HTTP_DATE_FMT "%a, %d %b %Y %T GMT"
251
252 /* HTTP status codes */
253 #define PROTOCOL_CONTINUE 100
254 #define PROTOCOL_SWITCHING 101
255 #define PROTOCOL_OK 200
256 #define PROTOCOL_CREATED 201
257 #define PROTOCOL_ACCEPTED 202
258 #define PROTOCOL_NONAUTHORITATIVE 203
259 #define PROTOCOL_NO_RESPONSE 204
260 #define PROTOCOL_NO_CONTENT 204
261 #define PROTOCOL_RESET_CONTENT 205
262 #define PROTOCOL_PARTIAL_CONTENT 206
263 #define PROTOCOL_MULTI_STATUS 207
264 #define PROTOCOL_MULTIPLE_CHOICES 300
265 #define PROTOCOL_MOVED_PERMANENTLY 301
266 #define PROTOCOL_REDIRECT 302
267 #define PROTOCOL_SEE_OTHER 303
268 #define PROTOCOL_NOT_MODIFIED 304
269 #define PROTOCOL_USE_PROXY 305
270 #define PROTOCOL_TEMPORARY_REDIRECT 307
271 #define PROTOCOL_BAD_REQUEST 400
272 #define PROTOCOL_UNAUTHORIZED 401
273 #define PROTOCOL_PAYMENT_REQUIRED 402
274 #define PROTOCOL_FORBIDDEN 403
275 #define PROTOCOL_NOT_FOUND 404
276 #define PROTOCOL_METHOD_NOT_ALLOWED 405
277 #define PROTOCOL_NOT_ACCEPTABLE 406
278 #define PROTOCOL_PROXY_UNAUTHORIZED 407
279 #define PROTOCOL_REQUEST_TIMEOUT 408
280 #define PROTOCOL_CONFLICT 409
281 #define PROTOCOL_GONE 410
282 #define PROTOCOL_LENGTH_REQUIRED 411
283 #define PROTOCOL_PRECONDITION_FAIL 412
284 #define PROTOCOL_ENTITY_TOO_LARGE 413
285 #define PROTOCOL_URI_TOO_LARGE 414
286 #define PROTOCOL_UNSUPPORTED_MEDIA_TYPE 415
287 #define PROTOCOL_REQUESTED_RANGE_NOT_SATISFIABLE 416
288 #define PROTOCOL_EXPECTATION_FAILED 417
289 #define PROTOCOL_LOCKED 423
290 #define PROTOCOL_FAILED_DEPENDENCY 424
291 #define PROTOCOL_SERVER_ERROR 500
292 #define PROTOCOL_NOT_IMPLEMENTED 501
293 #define PROTOCOL_BAD_GATEWAY 502
294 #define PROTOCOL_SERVICE_UNAVAILABLE 503
295 #define PROTOCOL_GATEWAY_TIMEOUT 504
296 #define PROTOCOL_VERSION_NOT_SUPPORTED 505
297 #define PROTOCOL_INSUFFICIENT_STORAGE 507
298
299 #define PROTOCOL_VERSION_HTTP09 9
300 #define PROTOCOL_VERSION_HTTP10 100
301 #define PROTOCOL_VERSION_HTTP11 101
302 #define CURRENT_PROTOCOL_VERSION PROTOCOL_VERSION_HTTP11
303
304 /* Definitions for HTTP over SSL */
305 #define HTTPS_PORT 443
306 #define HTTPS_URL "https"
307
308 /* Definitions for HTTP over TCP */
309 #define HTTP_PORT 80
310 #define HTTP_URL "http"
311
312
313 #define REQ_MAX_LINE 4096
314
315 /*
316 * The REQ_ return codes. These codes are used to determine what the server
317 * should do after a particular module completes its task.
318 *
319 * Func type functions return these as do many internal functions.
320 */
321
322 /* The function performed its task, proceed with the request */
323 #define REQ_PROCEED 0
324 /* The entire request should be aborted: An error occurred */
325 #define REQ_ABORTED -1
326 /* The function performed no task, but proceed anyway */
327 #define REQ_NOACTION -2
328 /* Tear down the session and exit */
329 #define REQ_EXIT -3
330 /* Restart the entire request-response process */
331 #define REQ_RESTART -4
332 /* Too busy to execute this now */
333 #define REQ_TOOBUSY -5
334
335 /* --- End miscellaneous definitions --- */
336
337 /* --- Begin native platform includes --- */
338
339 #ifdef XP_UNIX
340 #include <unistd.h>
341 #include <sys/file.h>
342 #ifndef HPUX
343 #include <sys/select.h>
344 #endif
345 #include <sys/socket.h>
346 #include <sys/time.h>
347 #include <sys/types.h>
348 #include <sys/uio.h>
349 #include <fcntl.h>
350 #include <dirent.h>
351 #include <pwd.h>
352 #include <netinet/in.h>
353 #endif /* XP_UNIX */
354
355 #ifdef XP_WIN32
356 #include <wtypes.h>
357 #include <winbase.h>
358 #include <direct.h>
359 #include <winsock.h>
360 #endif /* XP_WIN32 */
361
362 #include <sys/stat.h>
363 #include <ctype.h>
364 #include <stdio.h>
365 #include <stdarg.h>
366 #include <stdlib.h>
367 #include <string.h>
368 #include <errno.h>
369 #include <time.h>
370
371 /* --- End native platform includes --- */
372
373 /* --- Begin type definitions --- */
374
375 /* NOTE: both SYS_FILE and SYS_NETFD are actually NSPR PRFileDesc * and can */
376 /* be used with NSPR API calls (after casting them to PRFileDesc *) */
377
378 #ifndef SYS_FILE_T
379 typedef void *SYS_FILE;
380 #define SYS_FILE_T void *
381 #endif /* !SYS_FILE_T */
382
383 #define SYS_ERROR_FD ((SYS_FILE)-1)
384
385 #ifndef SYS_NETFD_T
386 typedef void *SYS_NETFD;
387 #define SYS_NETFD_T void *
388 #endif /* !SYS_NETFD_T */
389
390 /* Error value for a SYS_NETFD */
391 #ifndef SYS_NET_ERRORFD
392 #define SYS_NET_ERRORFD ((SYS_NETFD)-1)
393 #endif /* !SYS_NET_ERRORFD */
394
395 /*
396 * These structures were originally defined in nsapi.h, but those definitions
397 * were removed in iPlanet Web Server 4.0. The contents of these structures
398 * are now private to the server implementation and must not be accessed
399 * directly. Instead, use the objset_*, object_*, directive_table_*, and
400 * directive_* accessor functions.
401 */
402 typedef struct directive directive;
403 typedef struct dtable dtable;
404 typedef struct httpd_object httpd_object;
405 typedef struct httpd_objset httpd_objset;
406
407 /*
408 * Type: filebuffer, filebuf_t
409 *
410 * Description:
411 *
412 * This structure is used to represent a buffered file. On some
413 * systems the file may be memory-mapped. A filebuffer is created
414 * by filebuf_open(), and destroyed by filebuf_close().
415 *
416 * Notes:
417 *
418 * Direct access to the members of this structure, not using
419 * macros defined here, is discouraged.
420 *
421 * The filebuf alias that used to be defined for this type was
422 * found to conflict with a C++ class of the same name, so it
423 * has been renamed to filebuf_t.
424 */
425 typedef struct filebuffer filebuffer;
426
427 /* Version of filebuffer when memory-mapped files are supported */
428 struct filebuffer {
429 SYS_FILE fd;
430 #ifdef XP_WIN32
431 HANDLE fdmap;
432 #endif
433 caddr_t fp;
434 int len;
435
436 unsigned char *inbuf;
437 int cursize;
438
439 int pos;
440 const char *errmsg;
441 };
442
443 /* Return next character or IO_EOF */
444 #define filebuf_getc(b) ((b)->pos == (b)->len ? IO_EOF : (int)((b)->fp)[(b)->pos++])
445
446 #define filebuf_iseof(b) ((b)->pos == (b)->len)
447
448 /* C++ streamio defines a filebuf class. */
449 typedef filebuffer filebuf_t;
450
451 #ifdef XP_WIN32
452 /* Use a filebuffer to read data from a pipe */
453 #define pipebuf_getc(b) \
454 ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : pipebuf_next(b,1))
455 #endif /* XP_WIN32 */
456
457 /*
458 * Type: netbuf
459 *
460 * Description:
461 *
462 * This structure is used to represent a buffered network socket.
463 * It is created by netbuf_open(), and destroyed by netbuf_close().
464 *
465 * Notes:
466 *
467 * Direct access to the members of this structure, not using
468 * macros defined here, is discouraged.
469 *
470 * The inbuf field used to be (unsigned char *), but is now
471 * simply (char *). The value returned by the netbuf_getc()
472 * macro is (int).
473 */
474 typedef struct netbuf netbuf;
475 struct netbuf {
476 SYS_NETFD sd;
477
478 int pos, cursize, maxsize, rdtimeout;
479 #ifdef XP_WIN32
480 CHAR address[64];
481 #endif /* XP_WIN32 */
482 unsigned char *inbuf;
483 char *errmsg;
484 #ifndef XP_WIN32
485 char address[64];
486 #endif /* !XP_WIN32 */
487 };
488
489 /*
490 * netbuf_getc gets a character from the given network buffer and returns
491 * it (as an integer).
492 *
493 * It will return (int) IO_ERROR for an error and (int) IO_EOF for
494 * an error condition or EOF respectively.
495 */
496 #define netbuf_getc(b) \
497 ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : netbuf_next(b,1))
498
499 /*
500 * buffer_error returns the last error that occurred with buffer. Don't use
501 * this unless you know an error occurred. Independent of network/file type.
502 */
503 #define buffer_error(b) ((b)->errmsg)
504
505 /*
506 * Type: sendfiledata
507 *
508 * Description:
509 *
510 * This structure is used to pass arguments to the net_sendfile()
511 * function. offset and len may be set to 0 to transmit a file in its
512 * entirety.
513 */
514 typedef struct sendfiledata sendfiledata;
515 struct sendfiledata {
516 SYS_FILE fd; /* file to send */
517 size_t offset; /* offset in file to start sending from */
518 size_t len; /* number of bytes to send from file */
519 const void *header; /* data to send before file */
520 int hlen; /* number of bytes to send before file */
521 const void *trailer; /* data to send after file */
522 int tlen; /* number of bytes to send after file */
523 };
524
525 /*
526 * Type: NSAPIIOVec
527 *
528 * Description:
529 *
530 * This structure is used to pass arguments to the net_writev()
531 * and FilterWritevFunc() functions.
532 */
533 #ifdef _LP64
534 typedef struct NSAPIIOVec NSAPIIOVec;
535 struct NSAPIIOVec {
536 char *iov_base;
537 int iov_len;
538 };
539 #else
540 typedef struct iovec NSAPIIOVec;
541 #endif /* _LP64 */
542
543
544 /*
545 * Type: cinfo
546 *
547 * Description:
548 *
549 * This is a structure that captures the information in the name/value
550 * pairs on one line of a mime.types file. A cinfo structure is
551 * stored in the memory-resident database, indexed by each of the
552 * file extensions specified in the "exts" name/value pair. It
553 * defines various attributes of resources with names containing
554 * the specified file extensions.
555 *
556 * Notes:
557 *
558 * Pointers to cinfo structures returned by this API may or may not
559 * need to freed by the caller. See the individual function
560 * descriptions.
561 *
562 * The strings referenced by the fields of cinfo structures returned
563 * by this API should be considered read-only, and do not need to be
564 * freed by the caller, even when the cinfo structure does.
565 */
566 typedef struct cinfo cinfo;
567 struct cinfo {
568 char *type;
569 char *encoding;
570 char *language;
571 };
572
573
574 typedef void* CONDVAR;
575 typedef void *COUNTING_SEMAPHORE;
576 typedef void* CRITICAL;
577
578 #ifdef XP_UNIX
579 typedef DIR* SYS_DIR;
580 typedef struct dirent SYS_DIRENT;
581 #endif /* XP_UNIX */
582
583 #ifdef XP_WIN32
584
585 typedef struct dirent_s dirent_s;
586 struct dirent_s {
587 char *d_name;
588 };
589
590 typedef struct dir_s dir_s;
591 struct dir_s {
592 HANDLE dp;
593 WIN32_FIND_DATA fdata;
594 dirent_s de;
595 };
596
597 typedef dir_s* SYS_DIR;
598 typedef dirent_s SYS_DIRENT;
599
600 #endif /* XP_WIN32 */
601
602 typedef struct pb_param pb_param;
603 struct pb_param {
604 char *name,*value;
605 };
606
607 typedef struct pb_entry pb_entry;
608 struct pb_entry {
609 pb_param *param;
610 struct pb_entry *next;
611 };
612
613 typedef struct pblock pblock;
614 struct pblock {
615 int hsize;
616 struct pb_entry **ht;
617 };
618
619 #ifndef POOL_HANDLE_T
620 #define POOL_HANDLE_T
621 typedef void *pool_handle_t;
622 #endif
623
624 #ifndef SEMAPHORE_T
625 typedef void *SEMAPHORE;
626 #define SEMAPHORE_T void *
627 #endif /* !SEMAPHORE_T */
628
629 #define SESSION_HASHSIZE 5
630
631 typedef struct PListStruct_s PListStruct_s;
632 typedef struct ACLListHandle ACLListHandle;
633
634 #ifndef PR_AF_INET
635 typedef union PRNetAddr PRNetAddr;
636 #endif
637
638 typedef struct Session Session;
639 typedef struct Request Request;
640 struct Session {
641 pblock *client; /* client-specific information */
642
643 SYS_NETFD csd; /* client file descriptor */
644 netbuf *inbuf; /* input buffer */
645 int csd_open;
646
647 struct in_addr iaddr;
648
649 pool_handle_t *pool;
650
651 void *clauth; /* v2 ACL client authentication information */
652 struct Session *next;
653 int fill;
654 struct sockaddr_in local_addr; /* local addr for this session */
655
656 PListStruct_s *subject;
657 int ssl; /* 0 = SSL OFF, 1 = SSL ON */
658 int clientauth; /* 0 = client auth OFF, 1 = client auth ON */
659
660 PRNetAddr *pr_client_addr;
661 PRNetAddr *pr_local_addr;
662 };
663
664 /*
665 * FuncPtr is a pointer to an NSAPI SAF function
666 */
667
668 #ifdef XP_UNIX
669 typedef int Func(pblock *, Session *, Request *);
670 #else /* XP_WIN32 */
671 typedef int _cdecl Func(pblock *, Session *, Request *);
672 #endif /* XP_WIN32 */
673
674 typedef Func *FuncPtr;
675
676 /*
677 * FuncStruct is a structure used in the static declaration of the
678 * functions. This static declaration is parsed into a hash table at
679 * startup.
680 */
681
682 typedef struct FuncStruct FuncStruct;
683
684 struct FuncStruct {
685 const char * name;
686 FuncPtr func;
687 struct FuncStruct *next;
688 unsigned flags;
689 unsigned poolID;
690 unsigned pool_resolved;
691 };
692
693 /*
694 * VSInitFunc, VSDestroyFunc, VSDirectiveInitFunc and VSDirectiveDestroyFunc
695 */
696 typedef struct VirtualServer VirtualServer;
697 typedef int VSInitFunc(VirtualServer *incoming, const VirtualServer *current);
698 typedef void VSDestroyFunc(VirtualServer *outgoing);
699 typedef VSInitFunc *VSInitFuncPtr;
700 typedef VSDestroyFunc *VSDestroyFuncPtr;
701 typedef int VSDirectiveInitFunc(const directive *dir, VirtualServer *incoming, const VirtualServer *current);
702 typedef void VSDirectiveDestroyFunc(const directive *dir, VirtualServer *outgoing);
703 typedef VSDirectiveInitFunc *VSDirectiveInitFuncPtr;
704 typedef VSDirectiveDestroyFunc *VSDirectiveDestroyFuncPtr;
705
706 /*
707 * Filter is an opaque filter identifier
708 */
709 typedef struct Filter Filter;
710
711 /*
712 * FilterContext stores context associated with a particular filter layer
713 */
714
715 typedef struct FilterContext FilterContext;
716
717 struct FilterContext {
718 pool_handle_t *pool; /* pool context was allocated from */
719 Session *sn; /* session being processed */
720 Request *rq; /* request being processed */
721 void *data; /* filter-defined private data */
722 };
723
724 /*
725 * FilterLayer represents one layer of a filter stack
726 */
727
728 typedef struct FilterLayer FilterLayer;
729
730 struct FilterLayer {
731 Filter *filter; /* the filter at this layer in the filter stack */
732 FilterContext *context; /* context for the filter */
733 SYS_NETFD lower; /* access to the next filter layer in the stack */
734 };
735
736 /*
737 * Function prototypes for filter methods
738 */
739 typedef int (FilterInsertFunc)(FilterLayer *layer, pblock *pb);
740 typedef void (FilterRemoveFunc)(FilterLayer *layer);
741 typedef int (FilterFlushFunc)(FilterLayer *layer);
742 typedef int (FilterReadFunc)(FilterLayer *layer, void *buf, int amount, int timeout);
743 typedef int (FilterWriteFunc)(FilterLayer *layer, const void *buf, int amount);
744 typedef int (FilterWritevFunc)(FilterLayer *layer, const NSAPIIOVec *iov, int iov_size);
745 typedef int (FilterSendfileFunc)(FilterLayer *layer, sendfiledata *sfd);
746
747 /*
748 * FilterMethods is passed to filter_create() to declare the filter methods for
749 * a new filter. Each instance of the FilterMethods structure should be
750 * initialized using the FILTER_METHODS_INITIALIZER macro.
751 */
752
753 typedef struct FilterMethods FilterMethods;
754
755 struct FilterMethods {
756 size_t size;
757 #if NSAPI_VERSION >= 302
758 FilterInsertFunc *insert;
759 FilterRemoveFunc *remove;
760 FilterFlushFunc *flush;
761 FilterReadFunc *read;
762 FilterWriteFunc *write;
763 FilterWritevFunc *writev;
764 FilterSendfileFunc *sendfile;
765 #else
766 void *reserved1;
767 void *reserved2;
768 void *reserved3;
769 void *reserved4;
770 void *reserved5;
771 void *reserved6;
772 void *reserved7;
773 #endif /* NSAPI_VERSION >= 302 */
774 };
775
776 #define FILTER_METHODS_INITIALIZER \
777 { \
778 sizeof(FilterMethods), \
779 NULL, /* insert */ \
780 NULL, /* remove */ \
781 NULL, /* flush */ \
782 NULL, /* read */ \
783 NULL, /* write */ \
784 NULL, /* writev */ \
785 NULL /* sendfile */ \
786 }
787
788 /*
789 * Filter order definitions for filter_create()
790 */
791 #define FILTER_CONTENT_GENERATION 0xf0000
792 #define FILTER_CONTENT_TRANSLATION_HIGH 0xa0000
793 #define FILTER_CONTENT_TRANSLATION 0x90000
794 #define FILTER_CONTENT_TRANSLATION_LOW 0x80000
795 #define FILTER_CONTENT_CODING 0x50000
796 #define FILTER_TRANSFER_CODING 0x40000
797 #define FILTER_MESSAGE_CODING 0x30000
798 #define FILTER_TRANSPORT_CODING 0x20000
799 #define FILTER_NETWORK 0x10000
800
801 typedef struct shmem_s shmem_s;
802 struct shmem_s {
803 void *data; /* the data */
804 #ifdef XP_WIN32
805 HANDLE fdmap;
806 #endif /* XP_WIN32 */
807 int size; /* the maximum length of the data */
808
809 char *name; /* internal use: filename to unlink if exposed */
810 SYS_FILE fd; /* internal use: file descriptor for region */
811 };
812
813 /* Define a handle for a thread */
814 typedef void* SYS_THREAD;
815
816 /* Define an error value for the thread handle */
817 #define SYS_THREAD_ERROR NULL
818
819
820 typedef struct conf_global_vars_s conf_global_vars_s;
821 struct conf_global_vars_s {
822
823 /* What port we listen to */
824 int Vport; /* OBSOLETE */
825 #define server_portnum conf_getglobals()->Vport
826
827 /* What address to bind to */
828 char *Vaddr; /* OBSOLETE */
829
830 /* User to run as */
831 struct passwd *Vuserpw;
832
833 /* Directory to chroot to */
834 char *Vchr;
835
836 /* Where to log our pid to */
837 char *Vpidfn;
838
839 #define pool_max conf_getglobals()->Vpool_max
840 int Vpool_max;
841 #define pool_min conf_getglobals()->Vpool_min
842 int Vpool_min; /* OBSOLETE */
843 #define pool_life conf_getglobals()->Vpool_life
844 int Vpool_life; /* OBSOLETE */
845
846 /* For multiprocess UNIX servers, the maximum threads per process */
847 #define pool_maxthreads conf_getglobals()->Vpool_maxthreads
848 int Vpool_maxthreads;
849
850 #define pool_minthreads conf_getglobals()->Vpool_minthreads
851 int Vpool_minthreads; /* OBSOLETE */
852
853 char *Vsecure_keyfn; /* OBSOLETE */
854 char *Vsecure_certfn; /* OBSOLETE */
855
856 #define security_active conf_getglobals()->Vsecurity_active
857 int Vsecurity_active;
858 int Vssl3_active; /* OBSOLETE */
859 int Vssl2_active; /* OBSOLETE */
860 int Vsecure_auth; /* OBSOLETE */
861 int Vsecurity_session_timeout;
862 long Vssl3_session_timeout;
863
864 /* The server's hostname as should be reported in self-ref URLs */
865 #define server_hostname conf_getglobals()->Vserver_hostname
866 char *Vserver_hostname;
867
868 /* The main object from which all are derived */
869 #define root_object conf_getglobals()->Vroot_object
870 char *Vroot_object;
871
872 /* The object set the administrator has asked us to load */
873 #define std_os conf_getglobals()->Vstd_os
874 httpd_objset *Vstd_os;
875
876 /* The root of ACL data structures */
877 void *Vacl_root;
878
879 /* The main error log, where all errors are logged */
880 char *Vmaster_error_log;
881
882 /* The server root directory (contains instance subdirectories) */
883 #define server_root conf_getglobals()->Vserver_root
884 char *Vserver_root;
885
886 /* This server's id */
887 #define server_id conf_getglobals()->Vserver_id
888 char *Vserver_id;
889
890 /* Admin server users file */
891 char *Vadmin_users;
892
893 /* The installation directory (contains bin and lib subdirectories) */
894 char *Vnetsite_root;
895
896 /* Digest authentication stale nonce timeout value */
897 int digest_stale_timeout;
898
899 int single_accept; /* OBSOLETE */
900 int num_keep_alives; /* OBSOLETE */
901 int log_verbose; /* OBSOLETE */
902 int mmap_flags; /* OBSOLETE */
903 int mmap_prots; /* OBSOLETE */
904 int unused1;
905 int unused2;
906
907 /* Begin Enterprise 3.0 fields */
908 int accept_language; /* turn accept-language on/off */
909
910 char *mtahost;
911 char *nntphost; /* OBSOLETE */
912
913 /* The root of ACL data structures */
914 void *Vacl_root_30;
915
916 char *agentFilePath; /* OBSOLETE */
917
918 int Allowed; /* OBSOLETE */
919
920 pblock *genericGlobals; /* OBSOLETE */
921
922 char *agentsACLFile; /* OBSOLETE */
923
924 int wait_for_cgi; /* OBSOLETE */
925 int cgiwatch_timeout; /* OBSOLETE */
926 int started_by_watchdog;
927 int restarted_by_watchdog;
928 int old_accel_cache_enabled; /* OBSOLETE */
929 int Vssl_cache_entries;
930 int blocking_listen_socket; /* OBSOLETE */
931 pblock **initfns;
932 char *vs_config_file; /* OBSOLETE */
933 };
934
935 /* Type used for Request rq_attr bit flags */
936 #ifdef AIX
937 #define RQATTR unsigned
938 #else
939 #define RQATTR unsigned long
940 #endif
941
942 struct Request {
943 /* Server working variables */
944 pblock *vars;
945
946 /* The method, URI, and protocol revision of this request */
947 pblock *reqpb;
948 /* Protocol specific headers */
949 int loadhdrs;
950 pblock *headers;
951
952 /* Server's response headers */
953 int senthdrs;
954 pblock *srvhdrs;
955
956 /* The object set constructed to fulfill this request */
957 httpd_objset *os;
958 /* Array of objects that were created from .nsconfig files */
959 httpd_objset *tmpos;
960
961 /* The stat last returned by request_stat_path */
962 char *statpath;
963 char *staterr;
964 struct stat *finfo;
965
966 /* access control state */
967 int aclstate; /* ACL decision state */
968 int acldirno; /* deciding ACL directive number */
969 char *aclname; /* name of deciding ACL */
970 pblock *aclpb; /* OBSOLETE */
971 /* 3.0 ACL list pointer */
972 ACLListHandle *acllist;
973
974 int request_is_cacheable; /* */
975 int directive_is_cacheable; /* set by SAFs with no external side effects that make decisions based solely on URI and path */
976
977 char *cached_headers; /* OBSOLETE */
978 int cached_headers_len; /* OBSOLETE */
979 char *unused;
980
981 /* HTTP/1.1 features */
982 #define REQ_TIME(x) (x)->req_start
983 time_t req_start; /* time request arrived - used for selecting weak or strong cache validation */
984 short protv_num; /* protocol version number */
985 short method_num; /* method number */
986 struct rq_attr {
987 RQATTR abs_uri:1; /* set if absolute URI was used */
988 RQATTR chunked:1; /* chunked transfer-coding */
989 RQATTR keep_alive:1; /* connection keep-alive */
990 RQATTR pipelined:1; /* request packet is pipelined */
991 RQATTR internal_req:1; /* this was an internal request */
992 RQATTR perm_req:1; /* don't FREE() this request */
993 RQATTR header_file_present:1; /* OBSOLETE */
994 RQATTR footer_file_present:1; /* OBSOLETE */
995 RQATTR jvm_attached:1; /* OBSOLETE */
996 RQATTR req_restarted:1; /* request was restarted */
997 RQATTR jvm_request_locked:1; /* used for first-request serialization on some platforms */
998 RQATTR default_type_set:1; /* set if default types were set using set-default-type objecttype function */
999 RQATTR is_web_app:1; /* OBSOLETE */
1000 RQATTR ssl_unclean_shutdown:1; /* set if browser requires unclean SSL shutdown */
1001 RQATTR vary_accept_language:1; /* set if request was restarted based on an accept-language header */
1002 RQATTR reserved:17; /* if you add a flag, make sure to subtract from this */
1003 } rq_attr;
1004 char *hostname; /* hostname used to access server (always non-NULL) */
1005 int allowed; /* OBSOLETE */
1006 int byterange; /* OBSOLETE */
1007 short status_num; /* HTTP status code */
1008
1009 int staterrno; /* used for rqstat */
1010 Request *orig_rq; /* original Request - used for internal redirects */
1011 };
1012
1013 /* Request attribute macros */
1014 #define ABS_URI(x) (x)->rq_attr.abs_uri
1015 #define CHUNKED(x) (x)->rq_attr.chunked
1016 #define KEEP_ALIVE(x) (x)->rq_attr.keep_alive
1017 #define PIPELINED(x) (x)->rq_attr.pipelined
1018 #define INTERNAL_REQUEST(x) (x)->rq_attr.internal_req
1019 #define RESTARTED_REQUEST(x) (x)->rq_attr.req_restarted
1020 #define PERM_REQUEST(x) (x)->rq_attr.perm_req
1021 #define JVM_REQUEST_LOCKED(x) (x)->rq_attr.jvm_request_locked
1022 #define SSL_UNCLEAN_SHUTDOWN(x) (x)->rq_attr.ssl_unclean_shutdown
1023 #define VARY_ACCEPT_LANGUAGE(x) (x)->rq_attr.vary_accept_language
1024
1025 /* Define methods for HTTP/1.1 */
1026 #define METHOD_HEAD 0
1027 #define METHOD_GET 1
1028 #define METHOD_PUT 2
1029 #define METHOD_POST 3
1030 #define METHOD_DELETE 4
1031 #define METHOD_TRACE 5
1032 #define METHOD_OPTIONS 6
1033 /* The following methods are Netscape method extensions */
1034 #define METHOD_MOVE 7
1035 #define METHOD_INDEX 8
1036 #define METHOD_MKDIR 9
1037 #define METHOD_RMDIR 10
1038 #define METHOD_COPY 11
1039 #define METHOD_MAX 12 /* Number of methods available on this server */
1040
1041 #define ISMGET(r) ((r)->method_num == METHOD_GET)
1042 #define ISMHEAD(r) ((r)->method_num == METHOD_HEAD)
1043 #define ISMPUT(r) ((r)->method_num == METHOD_PUT)
1044 #define ISMPOST(r) ((r)->method_num == METHOD_POST)
1045 #define ISMDELETE(r) ((r)->method_num == METHOD_DELETE)
1046 #define ISMMOVE(r) ((r)->method_num == METHOD_MOVE)
1047 #define ISMINDEX(r) ((r)->method_num == METHOD_INDEX)
1048 #define ISMMKDIR(r) ((r)->method_num == METHOD_MKDIR)
1049 #define ISMRMDIR(r) ((r)->method_num == METHOD_RMDIR)
1050 #define ISMCOPY(r) ((r)->method_num == METHOD_COPY)
1051 #define ISMTRACE(r) ((r)->method_num == METHOD_TRACE)
1052 #define ISMOPTIONS(r) ((r)->method_num == METHOD_OPTIONS)
1053
1054
1055 /* --- End type definitions --- */
1056
1057 /* --- Begin dispatch vector table definition --- */
1058
1059 typedef struct nsapi_dispatch_s nsapi_dispatch_t;
1060 struct nsapi_dispatch_s {
1061 char *(*f_system_version)();
1062 void *(*f_system_malloc)(int size);
1063 void *(*f_system_calloc)(int size);
1064 void *(*f_system_realloc)(void *ptr, int size);
1065 void (*f_system_free)(void *ptr);
1066 char *(*f_system_strdup)(const char *ptr);
1067 void *(*f_system_malloc_perm)(int size);
1068 void *(*f_system_calloc_perm)(int size);
1069 void *(*f_system_realloc_perm)(void *ptr, int size);
1070 void (*f_system_free_perm)(void *ptr);
1071 char *(*f_system_strdup_perm)(const char *ptr);
1072 int (*f_getThreadMallocKey)(void);
1073 void (*f_magnus_atrestart)(void (*fn)(void *), void *data);
1074 filebuf_t *(*f_filebuf_open)(SYS_FILE fd, int sz);
1075 netbuf *(*f_netbuf_open)(SYS_NETFD sd, int sz);
1076 filebuf_t *(*f_filebuf_create)(SYS_FILE fd, caddr_t mmap_ptr,
1077 int mmap_len, int bufsz);
1078 void (*f_filebuf_close_buffer)(filebuf_t *buf, int clean_mmap);
1079 filebuf_t *(*f_filebuf_open_nostat)(SYS_FILE fd, int sz,
1080 struct stat *finfo);
1081 #ifdef XP_WIN32
1082 filebuf_t *(*f_pipebuf_open)(SYS_FILE fd, int sz, struct stat *finfo);
1083 #else
1084 void *(*f_pipebuf_open)(void);
1085 #endif /* XP_WIN32 */
1086 int (*f_filebuf_next)(void);
1087 int (*f_netbuf_next)(netbuf *buf, int advance);
1088 #ifdef XP_WIN32
1089 int (*f_pipebuf_next)(filebuf_t *buf, int advance);
1090 #else
1091 int (*f_pipebuf_next)(void);
1092 #endif /* XP_WIN32 */
1093 void (*f_filebuf_close)(filebuf_t *buf);
1094 void (*f_netbuf_close)(netbuf *buf);
1095 #ifdef XP_WIN32
1096 void (*f_pipebuf_close)(filebuf_t *buf);
1097 #else
1098 void (*f_pipebuf_close)(void);
1099 #endif /* XP_WIN32 */
1100 int (*f_filebuf_grab)(filebuf_t *buf, int sz);
1101 int (*f_netbuf_grab)(netbuf *buf, int sz);
1102 #ifdef XP_WIN32
1103 int (*f_pipebuf_grab)(filebuf_t *buf, int sz);
1104 #else
1105 int (*f_pipebuf_grab)(void);
1106 #endif /* XP_WIN32 */
1107 int (*f_netbuf_buf2sd)(netbuf *buf, SYS_NETFD sd, int len);
1108 int (*f_filebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd);
1109 #ifdef XP_WIN32
1110 int (*f_pipebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd, int len);
1111 int (*f_pipebuf_netbuf2sd)(netbuf *buf, SYS_FILE sd, int len);
1112 int (*f_pipebuf_netbuf2pipe)(netbuf *buf, SYS_NETFD sd, int len);
1113 #else
1114 int (*f_pipebuf_buf2sd)(void);
1115 int (*f_pipebuf_netbuf2sd)(void);
1116 int (*f_pipebuf_netbuf2pipe)(void);
1117 #endif /* XP_WIN32 */
1118 void (*f_cinfo_init)(void);
1119 void (*f_cinfo_terminate)(void);
1120 char *(*f_cinfo_merge)(char *fn);
1121 cinfo *(*f_cinfo_find)(char *uri);
1122 cinfo *(*f_cinfo_lookup)(char *type);
1123 void (*f_cinfo_dump_database)(FILE *dump);
1124 CRITICAL (*f_crit_init)(void);
1125 void (*f_crit_enter)(CRITICAL id);
1126 void (*f_crit_exit)(CRITICAL id);
1127 void (*f_crit_terminate)(CRITICAL id);
1128 CONDVAR (*f_condvar_init)(CRITICAL id);
1129 void (*f_condvar_wait)(CONDVAR cv);
1130 void (*f_condvar_notify)(CONDVAR cv);
1131 void (*f_condvar_notifyAll)(CONDVAR cv);
1132 void (*f_condvar_terminate)(CONDVAR cv);
1133 COUNTING_SEMAPHORE (*f_cs_init)(int initial_count);
1134 void (*f_cs_terminate)(COUNTING_SEMAPHORE csp);
1135 int (*f_cs_wait)(COUNTING_SEMAPHORE csp);
1136 int (*f_cs_trywait)(COUNTING_SEMAPHORE csp);
1137 int (*f_cs_release)(COUNTING_SEMAPHORE csp);
1138 void (*f_daemon_atrestart)(void (*fn)(void *), void *data);
1139 /* Obsolete: servssl_init() */
1140 void (*f_servssl_init)(void);
1141 int (*f_ereport)(int degree, const char *fmt, ...);
1142 int (*f_ereport_v)(int degree, const char *fmt, va_list args);
1143 char *(*f_ereport_init)(const char *err_fn, const char *email,
1144 struct passwd *pwuser, const char *version,
1145 int restart);
1146 void (*f_ereport_terminate)(void);
1147 SYS_FILE (*f_ereport_getfd)(void);
1148 SYS_FILE (*f_system_fopenRO)(const char *path);
1149 SYS_FILE (*f_system_fopenWA)(const char *path);
1150 SYS_FILE (*f_system_fopenRW)(const char *path);
1151 SYS_FILE (*f_system_fopenWT)(const char *path);
1152 int (*f_system_fread)(SYS_FILE fd, void *buf, int sz);
1153 int (*f_system_fwrite)(SYS_FILE fd, const void *buf,int sz);
1154 int (*f_system_fwrite_atomic)(SYS_FILE fd, const void *buf, int sz);
1155 int (*f_system_lseek)(SYS_FILE fd, int off, int wh);
1156 int (*f_system_fclose)(SYS_FILE fd);
1157 int (*f_system_stat)(const char *name, struct stat *finfo);
1158 int (*f_system_rename)(const char *oldpath, const char *newpath);
1159 int (*f_system_unlink)(const char *path);
1160 int (*f_system_tlock)(SYS_FILE fd);
1161 int (*f_system_flock)(SYS_FILE fd);
1162 int (*f_system_ulock)(SYS_FILE fd);
1163 #ifdef XP_WIN32
1164 SYS_DIR (*f_dir_open)(const char *path);
1165 SYS_DIRENT *(*f_dir_read)(SYS_DIR ds);
1166 void (*f_dir_close)(SYS_DIR ds);
1167 #else
1168 void *(*f_dir_open)(void);
1169 void *(*f_dir_read)(void);
1170 void (*f_dir_close)(void);
1171 #endif /* XP_WIN32 */
1172 int (*f_dir_create_all)(char *dir);
1173 #ifdef XP_WIN32
1174 void *(*f_system_winsockerr)(void);
1175 void *(*f_system_winerr)(void);
1176 int (*f_system_pread)(SYS_FILE fd, void *buf, int sz);
1177 int (*f_system_pwrite)(SYS_FILE fd, const void *buf, int sz);
1178 void (*f_file_unix2local)(const char *path, char *p2);
1179 #else
1180 void *(*f_system_winsockerr)(void);
1181 void *(*f_system_winerr)(void);
1182 int (*f_system_pread)(void);
1183 int (*f_system_pwrite)(void);
1184 void (*f_file_unix2local)(void);
1185 #endif /* XP_WIN32 */
1186 int (*f_system_nocoredumps)(void);
1187 int (*f_file_setinherit)(SYS_FILE fd, int value);
1188 int (*f_file_notfound)(void);
1189 char *(*f_system_errmsg)(void);
1190 int (*f_system_errmsg_fn)(char **buff, size_t maxlen);
1191 SYS_NETFD (*f_net_socket)(int domain, int type, int protocol);
1192 int (*f_net_listen)(SYS_NETFD s, int backlog);
1193 SYS_NETFD (*f_net_create_listener)(const char *ipaddr, int port);
1194 int (*f_net_connect)(SYS_NETFD s, const void *sockaddr, int namelen);
1195 int (*f_net_getpeername)(SYS_NETFD s, struct sockaddr *name, int *namelen);
1196 int (*f_net_close)(SYS_NETFD s);
1197 int (*f_net_bind)(SYS_NETFD s, const struct sockaddr *name, int namelen);
1198 SYS_NETFD (*f_net_accept)(SYS_NETFD s, struct sockaddr *addr, int *addrlen);
1199 int (*f_net_read)(SYS_NETFD sd, void *buf, int sz, int timeout);
1200 int (*f_net_write)(SYS_NETFD sd, const void *buf, int sz);
1201 int (*f_net_writev)(SYS_NETFD sd, const NSAPIIOVec *iov, int iovlen);
1202 int (*f_net_isalive)(SYS_NETFD sd);
1203 char *(*f_net_ip2host)(const char *ip, int verify);
1204 int (*f_net_getsockopt)(SYS_NETFD s, int level, int optname,
1205 void *optval, int *optlen);
1206 int (*f_net_setsockopt)(SYS_NETFD s, int level, int optname,
1207 const void *optval, int optlen);
1208 int (*f_net_select)(int nfds, fd_set *r, fd_set *w, fd_set *e,
1209 struct timeval *timeout);
1210 int (*f_net_ioctl)(SYS_NETFD s, int tag, void *result);
1211 pb_param *(*f_param_create)(const char *name, const char *value);
1212 int (*f_param_free)(pb_param *pp);
1213 pblock *(*f_pblock_create)(int n);
1214 void (*f_pblock_free)(pblock *pb);
1215 char *(*f_pblock_findval)(const char *name, const pblock *pb);
1216 pb_param *(*f_pblock_nvinsert)(const char *name, const char *value, pblock *pb);
1217 pb_param *(*f_pblock_nninsert)(const char *name, int value, pblock *pb);
1218 void (*f_pblock_pinsert)(pb_param *pp, pblock *pb);
1219 int (*f_pblock_str2pblock)(const char *str, pblock *pb);
1220 char *(*f_pblock_pblock2str)(const pblock *pb, char *str);
1221 int (*f_pblock_copy)(const pblock *src, pblock *dst);
1222 pblock *(*f_pblock_dup)(const pblock *src);
1223 char **(*f_pblock_pb2env)(const pblock *pb, char **env);
1224 pb_param *(*f_pblock_fr)(const char *name, pblock *pb, int remove);
1225 char * (*f_pblock_replace)(const char *name,char * new_value,pblock *pb);
1226 pool_handle_t *(*f_pool_create)(void);
1227 void (*f_pool_destroy)(pool_handle_t *pool_handle);
1228 int (*f_pool_enabled)(void);
1229 void *(*f_pool_malloc)(pool_handle_t *pool_handle, size_t size );
1230 void (*f_pool_free)(pool_handle_t *pool_handle, void *ptr );
1231 void *(*f_pool_calloc)(pool_handle_t *pool_handle, size_t nelem, size_t elsize);
1232 void *(*f_pool_realloc)(pool_handle_t *pool_handle, void *ptr, size_t size );
1233 char *(*f_pool_strdup)(pool_handle_t *pool_handle, const char *orig_str );
1234 int (*f_regexp_valid)(const char *exp);
1235 int (*f_regexp_match)(const char *str, const char *exp);
1236 int (*f_regexp_cmp)(const char *str, const char *exp);
1237 int (*f_regexp_casecmp)(const char *str, const char *exp);
1238 SEMAPHORE (*f_sem_init)(char *name, int number);
1239 void (*f_sem_terminate)(SEMAPHORE id);
1240 int (*f_sem_grab)(SEMAPHORE id);
1241 int (*f_sem_tgrab)(SEMAPHORE id);
1242 int (*f_sem_release)(SEMAPHORE id);
1243 Session *(*f_session_alloc)(SYS_NETFD csd, struct sockaddr_in *sac); /* internal */
1244 Session *(*f_session_fill)(Session *sn); /* internal */
1245 Session *(*f_session_create)(SYS_NETFD csd, struct sockaddr_in *sac);
1246 void (*f_session_free)(Session *sn);
1247 char *(*f_session_dns_lookup)(Session *sn, int verify);
1248 int (*f_shexp_valid)(const char *exp);
1249 int (*f_shexp_match)(const char *str, const char *exp);
1250 int (*f_shexp_cmp)(const char *str, const char *exp);
1251 int (*f_shexp_casecmp)(const char *str, const char *exp);
1252 shmem_s *(*f_shmem_alloc)(char *name, int size, int expose);
1253 void (*f_shmem_free)(shmem_s *region);
1254 SYS_THREAD (*f_systhread_start)(int prio, int stksz, void (*fn)(void *), void *arg);
1255 SYS_THREAD (*f_systhread_current)(void);
1256 void (*f_systhread_yield)(void);
1257 SYS_THREAD (*f_systhread_attach)(void);
1258 void (*f_systhread_detach)(SYS_THREAD thr);
1259 void (*f_systhread_terminate)(SYS_THREAD thr);
1260 void (*f_systhread_sleep)(int milliseconds);
1261 void (*f_systhread_init)(char *name);
1262 void (*f_systhread_timerset)(int usec);
1263 int (*f_systhread_newkey)(void);
1264 void *(*f_systhread_getdata)(int key);
1265 void (*f_systhread_setdata)(int key, void *data);
1266 void (*f_systhread_set_default_stacksize)(unsigned long size);
1267 int (*f_util_getline)(filebuffer *buf, int lineno, int maxlen, char *l);
1268 char **(*f_util_env_create)(char **env, int n, int *pos);
1269 char *(*f_util_env_str)(const char *name, const char *value);
1270 void (*f_util_env_replace)(char **env, const char *name, const char *value);
1271 void (*f_util_env_free)(char **env);
1272 char **(*f_util_env_copy)(char **src, char **dst);
1273 char *(*f_util_env_find)(char **env, const char *name);
1274 char *(*f_util_hostname)(void);
1275 int (*f_util_chdir2path)(char *path);
1276 int (*f_util_is_mozilla)(char *ua, char *major, char *minor);
1277 int (*f_util_is_url)(const char *url);
1278 int (*f_util_later_than)(const struct tm *lms, const char *ims);
1279 int (*f_util_time_equal)(const struct tm *lms, const char *ims);
1280 int (*f_util_str_time_equal)(const char *t1, const char *t2);
1281 int (*f_util_uri_is_evil)(const char *t);
1282 void (*f_util_uri_parse)(char *uri);
1283 void (*f_util_uri_unescape)(char *s);
1284 char *(*f_util_uri_escape)(char *d, const char *s);
1285 char *(*f_util_url_escape)(char *d, const char *s);
1286 char *(*f_util_sh_escape)(char *s);
1287 int (*f_util_mime_separator)(char *sep);
1288 int (*f_util_itoa)(int i, char *a);
1289 int (*f_util_vsprintf)(char *s, register const char *fmt, va_list args);
1290 int (*f_util_sprintf)(char *s, const char *fmt, ...);
1291 int (*f_util_vsnprintf)(char *s, int n, register const char *fmt,
1292 va_list args);
1293 int (*f_util_snprintf)(char *s, int n, const char *fmt, ...);
1294 int (*f_util_strftime)(char *s, const char *format, const struct tm *t);
1295 char *(*f_util_strtok)(char *s1, const char *s2, char **lasts);
1296 struct tm *(*f_util_localtime)(const time_t *clock, struct tm *res);
1297 char *(*f_util_ctime)(const time_t *clock, char *buf, int buflen);
1298 char *(*f_util_strerror)(int errnum, char *msg, int buflen);
1299 struct tm *(*f_util_gmtime)(const time_t *clock, struct tm *res);
1300 char *(*f_util_asctime)(const struct tm *tm,char *buf, int buflen);
1301 #ifdef NEED_STRCASECMP
1302 int (*f_util_strcasecmp)(const char *one, const char *two);
1303 #else
1304 int (*f_util_strcasecmp)(void);
1305 #endif /* NEED_STRCASECMP */
1306 #ifdef NEED_STRNCASECMP
1307 int (*f_util_strncasecmp)(const char *one, const char *two, int n);
1308 #else
1309 int (*f_util_strncasecmp)(void);
1310 #endif /* NEED_STRNCASECMP */
1311 #ifdef XP_UNIX
1312 int (*f_util_can_exec)(struct stat *finfo, uid_t uid, gid_t gid);
1313 struct passwd *(*f_util_getpwnam)(const char *name, struct passwd
1314 *result, char *buffer, int buflen);
1315 pid_t (*f_util_waitpid)(pid_t pid, int *statptr, int options);
1316 #else
1317 int (*f_util_can_exec)(void);
1318 void *(*f_util_getpwnam)(void);
1319 int (*f_util_waitpid)(void);
1320 #endif /* XP_UNIX */
1321 #ifdef XP_WIN32
1322 VOID (*f_util_delete_directory)(char *FileName, BOOL delete_directory);
1323 #else
1324 void (*f_util_delete_directory)(void);
1325 #endif /* XP_WIN32 */
1326 void *(*f_conf_init)(void);
1327 void *(*f_conf_run_init_functions)(void);
1328 void (*f_conf_terminate)(void);
1329 conf_global_vars_s *(*f_conf_getglobals)(void);
1330 void (*f_func_init)(struct FuncStruct *func_standard);
1331 FuncPtr (*f_func_find)(char *name);
1332 int (*f_func_exec)(pblock *pb, Session *sn, Request *rq);
1333 struct FuncStruct *(*f_func_insert)(char *name, FuncPtr fn);
1334 int (*f_object_execute)(directive *inst, Session *sn, Request *rq);
1335 void *(*f_http_find_request)(void);
1336 int (*f_http_parse_request)(char *t, Request *rq, Session *sn);
1337 int (*f_http_scan_headers)(void);
1338 int (*f_http_start_response)(Session *sn, Request *rq);
1339 char **(*f_http_hdrs2env)(pblock *pb);
1340 void (*f_http_status)(Session *sn, Request *rq, int n, const char *r);
1341 int (*f_http_set_finfo)(Session *sn, Request *rq, struct stat *finfo);
1342 char *(*f_http_dump822)(pblock *pb, char *t, int *pos, int tsz);
1343 void (*f_http_finish_request)(Session *sn, Request *rq);
1344 void (*f_http_handle_session)(void);
1345 char *(*f_http_uri2url)(const char *prefix, const char *suffix);
1346 char *(*f_http_uri2url_dynamic)(const char *prefix, const char *suffix,
1347 Session *sn, Request *rq);
1348 void (*f_http_set_keepalive_timeout)(int secs);
1349 int (*f_log_error_v)(int degree, const char *func, Session *sn,
1350 Request *rq, const char *fmt, va_list args);
1351 int (*f_log_error)(int degree, const char *func, Session *sn, Request *rq,
1352 const char *fmt, ...);
1353 int (*f_log_ereport_v)(int degree, const char *fmt, va_list args);
1354 int (*f_log_ereport)(int degree, const char *fmt, ...);
1355 httpd_object *(*f_object_create)(int nd, pblock *name);
1356 void (*f_object_free)(httpd_object *obj);
1357 void (*f_object_add_directive)(int dc, pblock *p, pblock *c,
1358 httpd_object *obj);
1359 httpd_objset *(*f_objset_scan_buffer)(filebuffer *buf, char *errstr,
1360 httpd_objset *os);
1361 httpd_objset *(*f_objset_create)(void);
1362 void (*f_objset_free)(httpd_objset *os);
1363 void (*f_objset_free_setonly)(httpd_objset *os);
1364 httpd_object *(*f_objset_new_object)(pblock *name, httpd_objset *os);
1365 void (*f_objset_add_object)(httpd_object *obj, httpd_objset *os);
1366 void (*f_objset_add_init)(pblock *initfn, httpd_objset *os);
1367 httpd_object *(*f_objset_findbyname)(const char *name, httpd_objset *ign,
1368 httpd_objset *os);
1369 httpd_object *(*f_objset_findbyppath)(char *ppath, httpd_objset *ign,
1370 httpd_objset *os);
1371 Request *(*f_request_create)(void);
1372 void (*f_request_free)(Request *req);
1373 Request *(*f_request_restart_internal)(const char *uri, Request *rq);
1374 int (*f_request_header)(char *name, char **value, Session *sn,
1375 Request *rq);
1376 struct stat *(*f_request_stat_path)(const char *path, Request *rq);
1377 const char *(*f_conf_getServerString)(void);
1378 FuncPtr (*f_func_replace)(char *funcname, FuncPtr fn);
1379 int (*f_net_socketpair)(SYS_NETFD *pair);
1380 #ifdef XP_UNIX
1381 SYS_NETFD (*f_net_dup2)(SYS_NETFD prfd, int osfd);
1382 int (*f_net_is_STDOUT)(SYS_NETFD prfd);
1383 int (*f_net_is_STDIN)(SYS_NETFD prfd);
1384 #else
1385 void *(*f_net_dup2)(void);
1386 int (*f_net_is_STDOUT)(void);
1387 int (*f_net_is_STDIN)(void);
1388 #endif /* XP_UNIX */
1389 int (*f_func_set_native_thread_flag)(char *name, int flags);
1390 #ifdef NET_SSL
1391 void *(*f_random_create)(void);
1392 void (*f_random_update)(void *rctx, unsigned char *inbuf, int length);
1393 void (*f_random_generate)(void *rctx, unsigned char *outbuf, int length);
1394 void (*f_random_destroy)(void *rctx);
1395 void *(*f_md5hash_create)(void);
1396 void *(*f_md5hash_copy)(void *hctx);
1397 void (*f_md5hash_begin)(void *hctx);
1398 void (*f_md5hash_update)(void *hctx, unsigned char *inbuf, int length);
1399 void (*f_md5hash_end)(void *hctx, unsigned char *outbuf);
1400 void (*f_md5hash_destroy)(void *hctx);
1401 void (*f_md5hash_data)(unsigned char *outbuf, unsigned char *src, int length);
1402 #else
1403 void *(*f_random_create)(void);
1404 void (*f_random_update)(void);
1405 void (*f_random_generate)(void);
1406 void (*f_random_destroy)(void);
1407 void *(*f_md5hash_create)(void);
1408 void *(*f_md5hash_copy)(void);
1409 void (*f_md5hash_begin)(void);
1410 void (*f_md5hash_update)(void);
1411 void (*f_md5hash_end)(void);
1412 void (*f_md5hash_destroy)(void);
1413 void (*f_md5hash_data)(void);
1414 #endif
1415 int (*f_ACL_SetupEval)(struct ACLListHandle *acllist, Session *sn, Request *rq, char **rights, char **map_generic, const char *user);
1416 int (*f_netbuf_getbytes)(netbuf *buf, char *buffer, int size);
1417 char *(*f_servact_translate_uri)(char *uri, Session *sn);
1418 #ifdef NET_SSL
1419 int (*f_rsa_set_priv_fn)(void *);
1420 #else
1421 int (*f_rsa_set_priv_fn)(void);
1422 #endif
1423 #ifdef XP_UNIX
1424 int (*f_net_native_handle)(SYS_NETFD s);
1425 #else
1426 HANDLE (*f_net_native_handle)(SYS_NETFD s);
1427 #endif /* XP_UNIX */
1428 int (*f_internal_request)(Request *rq);
1429 char *(*f_util_cookie_find)(char *cookie, const char *name);
1430 char *(*f_util_cookie_next)(char *cookie, char **name, char **value);
1431 char *(*f_util_cookie_next_av_pair)(char *cookie, char **name, char **value);
1432 int (*f_objset_get_number_objects)(const httpd_objset *objset);
1433 const httpd_object *(*f_objset_get_object)(const httpd_objset *objset, int pos);
1434 const pblock * const *(*f_objset_get_initfns)(const httpd_objset *objset);
1435 const pblock *(*f_object_get_name)(const httpd_object *object);
1436 int (*f_object_get_num_directives)(const httpd_object *object);
1437 const dtable *(*f_object_get_directive_table)(const httpd_object *object, int n);
1438 int (*f_directive_table_get_num_directives)(const dtable *dt);
1439 const directive *(*f_directive_table_get_directive)(const dtable *dt, int pos);
1440 const pblock *(*f_directive_get_pblock)(const directive *);
1441 const FuncStruct *(*f_directive_get_funcstruct)(const directive *);
1442 const pblock *(*f_directive_get_client_pblock)(const directive *);
1443 #if NSAPI_VERSION >= 301
1444 int (*f_vs_register_cb)(VSInitFunc *vs_init_func, VSDestroyFunc *vs_destroy_func);
1445 const char* (*f_vs_get_id)(const VirtualServer *vs);
1446 const char* (*f_vs_lookup_config_var)(const VirtualServer *vs, const char *name);
1447 int (*f_vs_alloc_slot)(void);
1448 void* (*f_vs_set_data)(const VirtualServer *vs, int *slot, void *data);
1449 void* (*f_vs_get_data)(const VirtualServer *vs, int slot);
1450 const VirtualServer* (*f_request_get_vs)(Request *rq);
1451 httpd_objset* (*f_vs_get_httpd_objset)(VirtualServer *vs);
1452 httpd_object* (*f_vs_get_default_httpd_object)(VirtualServer *vs);
1453 char* (*f_vs_get_doc_root)(const VirtualServer *vs);
1454 char* (*f_vs_translate_uri)(const VirtualServer *vs, const char *uri);
1455 char* (*f_vs_get_mime_type)(const VirtualServer *vs, const char *uri);
1456 int (*f_vs_is_default_vs)(const VirtualServer *vs);
1457 void *(*f_vs_get_acllist)(const VirtualServer *vs);
1458 void (*f_vs_set_acllist)(VirtualServer *vs, void *acllist);
1459 int (*f_file_is_path_abs)(const char *path);
1460 char* (*f_file_canonicalize_path)(const char* path);
1461 int (*f_file_are_files_distinct)(SYS_FILE fd1, SYS_FILE fd2);
1462 int (*f_vs_directive_register_cb)(FuncPtr func, VSDirectiveInitFunc *vs_init_func, VSDirectiveDestroyFunc *vs_destroy_func);
1463 char* (*f_vs_substitute_vars)(const VirtualServer *vs, const char *string);
1464 const char *(*f_conf_getfilename)(void);
1465 const char *(*f_conf_getstring)(const char *name, const char *def);
1466 int (*f_conf_getboolean)(const char *name, int def);
1467 int (*f_conf_getinteger)(const char *name, int def);
1468 int (*f_conf_getboundedinteger)(const char *name, int min, int max, int def);
1469 void (*f_prepare_nsapi_thread)(Request *rq, Session *sn);
1470 #endif /* NSAPI_VERSION >= 301 */
1471 };
1472
1473 #if NSAPI_VERSION >= 302
1474 typedef struct nsapi302_dispatch_s nsapi302_dispatch_t;
1475 struct nsapi302_dispatch_s {
1476 int (*f_net_flush)(SYS_NETFD sd);
1477 int (*f_net_sendfile)(SYS_NETFD sd, sendfiledata *sfd);
1478 const Filter *(*f_filter_create)(const char *name, int order, const FilterMethods *methods);
1479 const char *(*f_filter_name)(const Filter *filter);
1480 const Filter *(*f_filter_find)(const char *name);
1481 FilterLayer *(*f_filter_layer)(SYS_NETFD sd, const Filter *filter);
1482 int (*f_filter_insert)(SYS_NETFD sd, pblock *pb, Session *sn, Request *rq, void *data, const Filter *filter);
1483 int (*f_filter_remove)(SYS_NETFD sd, const Filter *filter);
1484 SYS_NETFD (*f_filter_create_stack)(Session *sn);
1485 };
1486 #endif /* NSAPI_VERSION >= 302 */
1487
1488 #if NSAPI_VERSION >= 303
1489 typedef struct nsapi303_dispatch_s nsapi303_dispatch_t;
1490 struct hostent;
1491 struct nsapi303_dispatch_s {
1492 int (*f_dns_set_hostent)(struct hostent *he, Session *sn, Request *rq);
1493 };
1494 #endif /* NSAPI_VERSION >= 303 */
1495
1496 /* --- End dispatch vector table definition --- */
1497
1498 /* --- Begin API macro definitions --- */
1499
1500 #ifndef INTNSAPI
1501
1502 #if NSAPI_VERSION >= 301
1503
1504 /*
1505 * In Sun ONE Web Server 6.1 and higher, http_parse_request("", NULL, NULL)
1506 * returns the NSAPI version. In previous releases, it returns -1.
1507 */
1508 #define __NSAPI_RUNTIME_VERSION \
1509 ((*__nsapi30_table->f_http_parse_request)("", NULL, NULL))
1510
1511 /*
1512 * NSAPI_RUNTIME_VERSION returns the NSAPI version the server implements. The
1513 * returned NSAPI version number is reliable only in iPlanet Web Server 6.0,
1514 * Netscape Enterprise Server 6.0, and Sun ONE Web Server 6.0 and higher.
1515 */
1516 #define NSAPI_RUNTIME_VERSION \
1517 (__NSAPI_RUNTIME_VERSION > 0 ? __NSAPI_RUNTIME_VERSION : 301)
1518
1519 #endif /* NSAPI_VERSION >= 301 */
1520
1521 #define system_version (*__nsapi30_table->f_system_version)
1522
1523 /*
1524 * Depending on the system, memory allocated via these macros may come from
1525 * an arena. If these functions are called from within an Init function, they
1526 * will be allocated from permanent storage. Otherwise, they will be freed
1527 * when the current request is finished.
1528 */
1529
1530
1531
1532 #endif /* !INTNSAPI */
1533
1534 #ifdef XP_UNIX
1535 #define dir_open opendir
1536 #define dir_read readdir
1537 #define dir_close closedir
1538 #define dir_create(path) mkdir(path, 0755)
1539 #define dir_remove rmdir
1540 #define system_chdir chdir
1541 #define file_unix2local(path,p2) strcpy(p2,path)
1542 #endif /* XP_UNIX */
1543
1544 #ifdef XP_WIN32
1545 #define dir_create _mkdir
1546 #define dir_remove _rmdir
1547 #define system_chdir SetCurrentDirectory
1548 #endif /* XP_WIN32 */
1549
1550 /*
1551 * Thread-safe variants of localtime and gmtime
1552 */
1553 #define system_localtime(curtime, ret) util_localtime(curtime, ret)
1554 #define system_gmtime(curtime, ret) util_gmtime(curtime, ret)
1555
1556 /*
1557 * pblock_find finds the entry with the given name in pblock pb.
1558 *
1559 * If it is successful, it returns the param block. If not, it returns NULL.
1560 */
1561 #define pblock_find(name, pb) (pblock_fr(name,pb,0))
1562
1563 /*
1564 * pblock_remove behaves exactly like pblock_find, but removes the given
1565 * entry from pb.
1566 */
1567 #define pblock_remove(name, pb) (pblock_fr(name,pb,1))
1568
1569 /*
1570 * session_dns returns the DNS hostname of the client of this session,
1571 * and inserts it into the client pblock. Returns NULL if unavailable.
1572 */
1573 #define session_dns(sn) session_dns_lookup(sn, 0)
1574
1575 /*
1576 * session_maxdns looks up a hostname from an IP address, and then verifies
1577 * that the host is really who they claim to be.
1578 */
1579 #define session_maxdns(sn) session_dns_lookup(sn, 1)
1580
1581 #define protocol_start_response http_start_response
1582 #define protocol_status http_status
1583 #define protocol_set_finfo http_set_finfo
1584 #define protocol_finish_request http_finish_request
1585 #define protocol_uri2url http_uri2url
1586 #define protocol_uri2url_dynamic http_uri2url_dynamic
1587
1588 #define request_translate_uri servact_translate_uri
1589
1590 /* --- OBSOLETE ----------------------------------------------------------
1591 * The following macros/functions are obsolete and are only maintained for
1592 * compatibility. Do not use them.
1593 * -----------------------------------------------------------------------
1594 */
1595
1596 #define SYS_STDERR STDERR_FILENO
1597
1598 #ifdef XP_WIN32
1599
1600 typedef HANDLE pid_t;
1601
1602 #define ERROR_PIPE \
1603 (ERROR_BROKEN_PIPE | ERROR_BAD_PIPE | \
1604 ERROR_PIPE_BUSY | ERROR_PIPE_LISTENING | ERROR_PIPE_NOT_CONNECTED)
1605 #define CONVERT_TO_PRINTABLE_FORMAT(Filename) \
1606 { \
1607 register char *s; \
1608 if (Filename) \
1609 for (s = Filename; *s; s++) \
1610 if ( *s == '\\') \
1611 *s = '/'; \
1612 }
1613 #define CONVERT_TO_NATIVE_FS(Filename) \
1614 { \
1615 register char *s; \
1616 if (Filename) \
1617 for (s = Filename; *s; s++) \
1618 if ( *s == '/') \
1619 *s = '\\'; \
1620 }
1621
1622 #ifdef INTNSAPI
1623 NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
1624 #if NSAPI_VERSION >= 302
1625 NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table;
1626 #endif /* NSAPI_VERSION >= 302 */
1627 #if NSAPI_VERSION >= 303
1628 NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table;
1629 #endif /* NSAPI_VERSION >= 303 */
1630 #else
1631 __declspec(dllimport) nsapi_dispatch_t *__nsapi30_table;
1632 #if NSAPI_VERSION >= 302
1633 __declspec(dllimport) nsapi302_dispatch_t *__nsapi302_table;
1634 #endif /* NSAPI_VERSION >= 302 */
1635 #if NSAPI_VERSION >= 303
1636 __declspec(dllimport) nsapi303_dispatch_t *__nsapi303_table;
1637 #endif /* NSAPI_VERSION >= 303 */
1638 #endif /* INTNSAPI */
1639
1640 #else /* !XP_WIN32 */
1641
1642 NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
1643 #if NSAPI_VERSION >= 302
1644 NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table;
1645 #endif /* NSAPI_VERSION >= 302 */
1646 #if NSAPI_VERSION >= 303
1647 NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table;
1648 #endif /* NSAPI_VERSION >= 303 */
1649
1650 #endif /* XP_WIN32 */
1651
1652 #ifdef __cplusplus
1653 }
1654 #endif
1655
1656 #endif /* !PUBLIC_NSAPI_H */

mercurial