]> granicus.if.org Git - apache/blob - include/httpd.h
CGIs work again on UNIX because ap_create_process() works again on UNIX.
[apache] / include / httpd.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #ifndef APACHE_HTTPD_H
60 #define APACHE_HTTPD_H
61
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65
66 /*
67  * httpd.h: header for simple (ha! not anymore) http daemon
68  */
69
70 /* XXX - We need to push more stuff to other .h files, or even .c files, to
71  * make this file smaller
72  */
73
74
75 /* Headers in which EVERYONE has an interest... */
76 #include "os.h"
77 #include "apr_general.h"
78 #include "apr_lib.h"
79 #include "apr_time.h"
80 #include "apr_network_io.h"
81 #include "buff.h"
82 #include "ap_mmn.h"
83
84 #ifdef HAVE_NETINET_IN_H
85 #include <netinet/in.h>
86 #endif
87
88 #ifdef CORE_PRIVATE
89
90 /* ----------------------------- config dir ------------------------------ */
91
92 /* Define this to be the default server home dir. Most things later in this
93  * file with a relative pathname will have this added.
94  */
95 #ifndef HTTPD_ROOT
96 #ifdef OS2
97 /* Set default for OS/2 file system */
98 #define HTTPD_ROOT "/os2httpd"
99 #elif defined(WIN32)
100 /* Set default for Windows file system */
101 #define HTTPD_ROOT "/apache"
102 #elif defined (BEOS)
103 /* Set the default for BeOS */
104 #define HTTPD_ROOT "/boot/home/apache"
105 #else
106 #define HTTPD_ROOT "/usr/local/apache"
107 #endif
108 #endif /* HTTPD_ROOT */
109
110 /* 
111  * --------- You shouldn't have to edit anything below this line ----------
112  *
113  * Any modifications to any defaults not defined above should be done in the 
114  * respective config. file. 
115  *
116  */
117
118 /* Default location of documents.  Can be overridden by the DocumentRoot
119  * directive.
120  */
121 #ifndef DOCUMENT_LOCATION
122 #ifdef OS2
123 /* Set default for OS/2 file system */
124 #define DOCUMENT_LOCATION  HTTPD_ROOT "/docs"
125 #else
126 #define DOCUMENT_LOCATION  HTTPD_ROOT "/htdocs"
127 #endif
128 #endif /* DOCUMENT_LOCATION */
129
130 /* Max. number of dynamically loaded modules */
131 #ifndef DYNAMIC_MODULE_LIMIT
132 #define DYNAMIC_MODULE_LIMIT 64
133 #endif
134
135 /* Default administrator's address */
136 #define DEFAULT_ADMIN "[no address given]"
137
138 /* The target name of the installed Apache */
139 #ifndef TARGET
140 #define TARGET "httpd"
141 #endif
142
143 /* --------- Default user name and group name ----------------------------- */
144 /* --- These may be specified as numbers by placing a # before a number --- */
145
146 #ifndef DEFAULT_USER
147 #define DEFAULT_USER "#-1"
148 #endif
149 #ifndef DEFAULT_GROUP
150 #define DEFAULT_GROUP "#-1"
151 #endif
152
153 /* The name of the log files */
154 #ifndef DEFAULT_XFERLOG
155 #if defined(OS2) || defined(WIN32)
156 #define DEFAULT_XFERLOG "logs/access.log"
157 #else
158 #define DEFAULT_XFERLOG "logs/access_log"
159 #endif
160 #endif /* DEFAULT_XFERLOG */
161
162 #ifndef DEFAULT_ERRORLOG
163 #if defined(OS2) || defined(WIN32)
164 #define DEFAULT_ERRORLOG "logs/error.log"
165 #else
166 #define DEFAULT_ERRORLOG "logs/error_log"
167 #endif
168 #endif /* DEFAULT_ERRORLOG */
169
170 /* Define this to be what your per-directory security files are called */
171 #ifndef DEFAULT_ACCESS_FNAME
172 #ifdef OS2
173 /* Set default for OS/2 file system */
174 #define DEFAULT_ACCESS_FNAME "htaccess"
175 #else
176 #define DEFAULT_ACCESS_FNAME ".htaccess"
177 #endif
178 #endif /* DEFAULT_ACCESS_FNAME */
179
180 /* The name of the server config file */
181 #ifndef SERVER_CONFIG_FILE
182 #define SERVER_CONFIG_FILE "conf/httpd.conf"
183 #endif
184
185 /* Whether we should enable rfc1413 identity checking */
186 #ifndef DEFAULT_RFC1413
187 #define DEFAULT_RFC1413 0
188 #endif
189
190 /* The default path for CGI scripts if none is currently set */
191 #ifndef DEFAULT_PATH
192 #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
193 #endif
194
195 /* The path to the suExec wrapper, can be overridden in Configuration */
196 #ifndef SUEXEC_BIN
197 #define SUEXEC_BIN  HTTPD_ROOT "/sbin/suexec"
198 #endif
199
200 /* The timeout for waiting for messages */
201 #ifndef DEFAULT_TIMEOUT
202 #define DEFAULT_TIMEOUT 120000 
203 #endif
204
205 /* The timeout for waiting for keepalive timeout until next request */
206 #ifndef DEFAULT_KEEPALIVE_TIMEOUT
207 #define DEFAULT_KEEPALIVE_TIMEOUT 300
208 #endif
209
210 /* The number of requests to entertain per connection */
211 #ifndef DEFAULT_KEEPALIVE
212 #define DEFAULT_KEEPALIVE 100
213 #endif
214
215 /* The maximum length of the queue of pending connections, as defined
216  * by listen(2).  Under some systems, it should be increased if you
217  * are experiencing a heavy TCP SYN flood attack.
218  *
219  * It defaults to 511 instead of 512 because some systems store it 
220  * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is 
221  * 255 when truncated.
222  */
223
224 #ifndef DEFAULT_LISTENBACKLOG
225 #define DEFAULT_LISTENBACKLOG 511
226 #endif
227
228 /* Limits on the size of various request items.  These limits primarily
229  * exist to prevent simple denial-of-service attacks on a server based
230  * on misuse of the protocol.  The recommended values will depend on the
231  * nature of the server resources -- CGI scripts and database backends
232  * might require large values, but most servers could get by with much
233  * smaller limits than we use below.  The request message body size can
234  * be limited by the per-dir config directive LimitRequestBody.
235  *
236  * Internal buffer sizes are two bytes more than the DEFAULT_LIMIT_REQUEST_LINE
237  * and DEFAULT_LIMIT_REQUEST_FIELDSIZE below, which explains the 8190.
238  * These two limits can be lowered (but not raised) by the server config
239  * directives LimitRequestLine and LimitRequestFieldsize, respectively.
240  *
241  * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
242  * the server config directive LimitRequestFields.
243  */
244 #ifndef DEFAULT_LIMIT_REQUEST_LINE
245 #define DEFAULT_LIMIT_REQUEST_LINE 8190
246 #endif /* default limit on bytes in Request-Line (Method+URI+HTTP-version) */
247 #ifndef DEFAULT_LIMIT_REQUEST_FIELDSIZE
248 #define DEFAULT_LIMIT_REQUEST_FIELDSIZE 8190
249 #endif /* default limit on bytes in any one header field  */
250 #ifndef DEFAULT_LIMIT_REQUEST_FIELDS
251 #define DEFAULT_LIMIT_REQUEST_FIELDS 100
252 #endif /* default limit on number of request header fields */
253
254
255 /*
256  * The default default character set name to add if AddDefaultCharset is
257  * enabled.  Overridden with AddDefaultCharsetName.
258  */
259 #define DEFAULT_ADD_DEFAULT_CHARSET_NAME "iso-8859-1"
260
261 /*
262  * The below defines the base string of the Server: header. Additional
263  * tokens can be added via the ap_add_version_component() API call.
264  *
265  * The tokens are listed in order of their significance for identifying the
266  * application.
267  *
268  * "Product tokens should be short and to the point -- use of them for 
269  * advertizing or other non-essential information is explicitly forbidden."
270  *
271  * Example: "Apache/1.1.0 MrWidget/0.1-alpha" 
272  */
273
274 /* Define this to 1 if you want fancy indexing, 0 otherwise */
275 #ifndef DEFAULT_INDEXING
276 #define DEFAULT_INDEXING 0
277 #endif
278 #endif /* CORE_PRIVATE */
279
280 #define AP_SERVER_BASEVERSION "Apache/2.0a3-dev"       /* SEE COMMENTS ABOVE */
281 #define AP_SERVER_VERSION  AP_SERVER_BASEVERSION
282
283 #define AP_SERVER_PROTOCOL "HTTP/1.1"
284
285
286 /* ------------------ stuff that modules are allowed to look at ----------- */
287
288 /* Define this to be what your HTML directory content files are called */
289 #ifndef AP_DEFAULT_INDEX
290 #define AP_DEFAULT_INDEX "index.html"
291 #endif
292
293
294 /* Define this to be what type you'd like returned for files with unknown */
295 /* suffixes.  MUST be all lower case. */
296 #ifndef DEFAULT_CONTENT_TYPE
297 #define DEFAULT_CONTENT_TYPE "text/plain"
298 #endif
299
300 /* The name of the MIME types file */
301 #ifndef AP_TYPES_CONFIG_FILE
302 #define AP_TYPES_CONFIG_FILE "conf/mime.types"
303 #endif
304
305 /*
306  * Define the HTML doctype strings centrally.
307  */
308 #define DOCTYPE_HTML_2_0  "<!DOCTYPE HTML PUBLIC \"-//IETF//" \
309                           "DTD HTML 2.0//EN\">\n"
310 #define DOCTYPE_HTML_3_2  "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
311                           "DTD HTML 3.2 Final//EN\">\n"
312 #define DOCTYPE_HTML_4_0S "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
313                           "DTD HTML 4.0//EN\"\n" \
314                           "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
315 #define DOCTYPE_HTML_4_0T "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
316                           "DTD HTML 4.0 Transitional//EN\"\n" \
317                           "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"
318 #define DOCTYPE_HTML_4_0F "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
319                           "DTD HTML 4.0 Frameset//EN\"\n" \
320                           "\"http://www.w3.org/TR/REC-html40/frameset.dtd\">\n"
321
322 /* -- Internal representation for a HTTP protocol number, e.g., HTTP/1.1 -- */
323
324 #define HTTP_VERSION(major,minor) (1000*(major)+(minor))
325 #define HTTP_VERSION_MAJOR(number) ((number)/1000)
326 #define HTTP_VERSION_MINOR(number) ((number)%1000)
327
328 /* -------------- Port number for server running standalone --------------- */
329
330 #define DEFAULT_HTTP_PORT       80
331 #define DEFAULT_HTTPS_PORT      443
332 #define ap_is_default_port(port,r)      ((port) == ap_default_port(r))
333 #define ap_http_method(r)       ap_run_http_method(r)
334 #define ap_default_port(r)      ap_run_default_port(r)
335
336 /* The default string lengths */
337 #define MAX_STRING_LEN HUGE_STRING_LEN
338 #define HUGE_STRING_LEN 8192
339
340 /* The size of the server's internal read-write buffers */
341 #define IOBUFSIZE 8192
342
343 /*
344  * Special Apache error codes. These are basically used
345  *  in http_main.c so we can keep track of various errors.
346  *
347  *   APEXIT_OK:
348  *     A normal exit
349  *   APEXIT_INIT:
350  *     A fatal error arising during the server's init sequence
351  *   APEXIT_CHILDINIT:
352  *     The child died during it's init sequence
353  *   APEXIT_CHILDFATAL:
354  *     A fatal error, resulting in the whole server aborting.
355  *     If a child exits with this error, the parent process
356  *     considers this a server-wide fatal error and aborts.
357  *                 
358  */
359 #define APEXIT_OK               0x0
360 #define APEXIT_INIT             0x2
361 #define APEXIT_CHILDINIT        0x3
362 #define APEXIT_CHILDFATAL       0xf
363
364 /* TODO: re-implement the server token/version stuff -- it's part of http_core
365  * it should be possible to do without touching http_main at all. (or else
366  * we haven't got enough module hooks)
367  */
368
369 enum server_token_type {
370     SrvTk_MIN,          /* eg: Apache/1.3.0 */
371     SrvTk_OS,           /* eg: Apache/1.3.0 (UNIX) */
372     SrvTk_FULL          /* eg: Apache/1.3.0 (UNIX) PHP/3.0 FooBar/1.2b */
373 };
374
375 #if 0
376 API_EXPORT(const char *) ap_get_server_version(void);
377 API_EXPORT(void) ap_add_version_component(const char *component);
378 #else
379 #define ap_get_server_version() (AP_SERVER_BASEVERSION)
380 #define ap_add_version_component(x) ((void)0)
381 #endif
382 API_EXPORT(const char *) ap_get_server_built(void);
383
384 /* Numeric release version identifier: MMNNFFRBB: major minor fix final beta
385  * Always increases along the same track as the source branch.
386  * For example, Apache 1.4.2 would be '10402100', 2.5b7 would be '20500007'.
387  */
388 #define APACHE_RELEASE 20000003
389
390 #define DECLINED -1             /* Module declines to handle */
391 #define DONE -2                 /* Module has served the response completely 
392                                  *  - it's safe to die() with no more output
393                                  */
394 #define OK 0                    /* Module has handled this stage. */
395
396
397 /* ----------------------- HTTP Status Codes  ------------------------- */
398
399 /* The size of the static array in http_protocol.c for storing
400  * all of the potential response status-lines (a sparse table).
401  * A future version should dynamically generate the ap_table_t at startup.
402  */
403 #define RESPONSE_CODES 55
404
405 #define HTTP_CONTINUE                      100
406 #define HTTP_SWITCHING_PROTOCOLS           101
407 #define HTTP_PROCESSING                    102
408 #define HTTP_OK                            200
409 #define HTTP_CREATED                       201
410 #define HTTP_ACCEPTED                      202
411 #define HTTP_NON_AUTHORITATIVE             203
412 #define HTTP_NO_CONTENT                    204
413 #define HTTP_RESET_CONTENT                 205
414 #define HTTP_PARTIAL_CONTENT               206
415 #define HTTP_MULTI_STATUS                  207
416 #define HTTP_MULTIPLE_CHOICES              300
417 #define HTTP_MOVED_PERMANENTLY             301
418 #define HTTP_MOVED_TEMPORARILY             302
419 #define HTTP_SEE_OTHER                     303
420 #define HTTP_NOT_MODIFIED                  304
421 #define HTTP_USE_PROXY                     305
422 #define HTTP_TEMPORARY_REDIRECT            307
423 #define HTTP_BAD_REQUEST                   400
424 #define HTTP_UNAUTHORIZED                  401
425 #define HTTP_PAYMENT_REQUIRED              402
426 #define HTTP_FORBIDDEN                     403
427 #define HTTP_NOT_FOUND                     404
428 #define HTTP_METHOD_NOT_ALLOWED            405
429 #define HTTP_NOT_ACCEPTABLE                406
430 #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407
431 #define HTTP_REQUEST_TIME_OUT              408
432 #define HTTP_CONFLICT                      409
433 #define HTTP_GONE                          410
434 #define HTTP_LENGTH_REQUIRED               411
435 #define HTTP_PRECONDITION_FAILED           412
436 #define HTTP_REQUEST_ENTITY_TOO_LARGE      413
437 #define HTTP_REQUEST_URI_TOO_LARGE         414
438 #define HTTP_UNSUPPORTED_MEDIA_TYPE        415
439 #define HTTP_RANGE_NOT_SATISFIABLE         416
440 #define HTTP_EXPECTATION_FAILED            417
441 #define HTTP_UNPROCESSABLE_ENTITY          422
442 #define HTTP_LOCKED                        423
443 #define HTTP_FAILED_DEPENDENCY             424
444 #define HTTP_INTERNAL_SERVER_ERROR         500
445 #define HTTP_NOT_IMPLEMENTED               501
446 #define HTTP_BAD_GATEWAY                   502
447 #define HTTP_SERVICE_UNAVAILABLE           503
448 #define HTTP_GATEWAY_TIME_OUT              504
449 #define HTTP_VERSION_NOT_SUPPORTED         505
450 #define HTTP_VARIANT_ALSO_VARIES           506
451 #define HTTP_INSUFFICIENT_STORAGE          507
452 #define HTTP_NOT_EXTENDED                  510
453
454 #define DOCUMENT_FOLLOWS    HTTP_OK
455 #define PARTIAL_CONTENT     HTTP_PARTIAL_CONTENT
456 #define MULTIPLE_CHOICES    HTTP_MULTIPLE_CHOICES
457 #define MOVED               HTTP_MOVED_PERMANENTLY
458 #define REDIRECT            HTTP_MOVED_TEMPORARILY
459 #define USE_LOCAL_COPY      HTTP_NOT_MODIFIED
460 #define BAD_REQUEST         HTTP_BAD_REQUEST
461 #define AUTH_REQUIRED       HTTP_UNAUTHORIZED
462 #define FORBIDDEN           HTTP_FORBIDDEN
463 #define NOT_FOUND           HTTP_NOT_FOUND
464 #define METHOD_NOT_ALLOWED  HTTP_METHOD_NOT_ALLOWED
465 #define NOT_ACCEPTABLE      HTTP_NOT_ACCEPTABLE
466 #define LENGTH_REQUIRED     HTTP_LENGTH_REQUIRED
467 #define PRECONDITION_FAILED HTTP_PRECONDITION_FAILED
468 #define SERVER_ERROR        HTTP_INTERNAL_SERVER_ERROR
469 #define NOT_IMPLEMENTED     HTTP_NOT_IMPLEMENTED
470 #define BAD_GATEWAY         HTTP_BAD_GATEWAY
471 #define VARIANT_ALSO_VARIES HTTP_VARIANT_ALSO_VARIES
472
473 #define ap_is_HTTP_INFO(x)         (((x) >= 100)&&((x) < 200))
474 #define ap_is_HTTP_SUCCESS(x)      (((x) >= 200)&&((x) < 300))
475 #define ap_is_HTTP_REDIRECT(x)     (((x) >= 300)&&((x) < 400))
476 #define ap_is_HTTP_ERROR(x)        (((x) >= 400)&&((x) < 600))
477 #define ap_is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500))
478 #define ap_is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600))
479
480 #define ap_status_drops_connection(x) \
481                                    (((x) == HTTP_BAD_REQUEST)           || \
482                                     ((x) == HTTP_REQUEST_TIME_OUT)      || \
483                                     ((x) == HTTP_LENGTH_REQUIRED)       || \
484                                     ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
485                                     ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
486                                     ((x) == HTTP_INTERNAL_SERVER_ERROR) || \
487                                     ((x) == HTTP_SERVICE_UNAVAILABLE) || \
488                                     ((x) == HTTP_NOT_IMPLEMENTED))
489
490 /* Methods recognized (but not necessarily handled) by the server.
491  * These constants are used in bit shifting masks of size int, so it is
492  * unsafe to have more methods than bits in an int.  HEAD == M_GET.
493  */
494 #define M_GET        0
495 #define M_PUT        1
496 #define M_POST       2
497 #define M_DELETE     3
498 #define M_CONNECT    4
499 #define M_OPTIONS    5
500 #define M_TRACE      6
501 #define M_PATCH      7
502 #define M_PROPFIND   8
503 #define M_PROPPATCH  9
504 #define M_MKCOL     10
505 #define M_COPY      11
506 #define M_MOVE      12
507 #define M_LOCK      13
508 #define M_UNLOCK    14
509 #define M_INVALID   15
510
511 #define METHODS     16
512
513 #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
514 #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
515 #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
516 #define DIR_MAGIC_TYPE "httpd/unix-directory"
517
518 #define LF 10
519 #define CR 13
520
521 /* Possible values for request_rec.read_body (set by handling module):
522  *    REQUEST_NO_BODY          Send 413 error if message has any body
523  *    REQUEST_CHUNKED_ERROR    Send 411 error if body without Content-Length
524  *    REQUEST_CHUNKED_DECHUNK  If chunked, remove the chunks for me.
525  *    REQUEST_CHUNKED_PASS     Pass the chunks to me without removal.
526  */
527 #define REQUEST_NO_BODY          0
528 #define REQUEST_CHUNKED_ERROR    1
529 #define REQUEST_CHUNKED_DECHUNK  2
530 #define REQUEST_CHUNKED_PASS     3
531
532 /* Things which may vary per file-lookup WITHIN a request ---
533  * e.g., state of MIME config.  Basically, the name of an object, info
534  * about the object, and any other info we may ahve which may need to
535  * change as we go poking around looking for it (e.g., overridden by
536  * .htaccess files).
537  *
538  * Note how the default state of almost all these things is properly
539  * zero, so that allocating it with pcalloc does the right thing without
540  * a whole lot of hairy initialization... so long as we are willing to
541  * make the (fairly) portable assumption that the bit pattern of a NULL
542  * pointer is, in fact, zero.
543  */
544
545 /* This represents the result of calling htaccess; these are cached for
546  * each request.
547  */
548 struct htaccess_result {
549     char *dir;                  /* the directory to which this applies */
550     int override;               /* the overrides allowed for the .htaccess file */
551     void *htaccess;             /* the configuration directives */
552 /* the next one, or NULL if no more; N.B. never change this */
553     const struct htaccess_result *next;
554 };
555
556 /* The following four types define a hierarchy of activities, so that
557  * given a request_rec r you can write r->connection->server->process
558  * to get to the process_rec.  While this reduces substantially the
559  * number of arguments that various hooks require beware that in
560  * threaded versions of the server you must consider multiplexing
561  * issues.  */
562
563 typedef struct process_rec process_rec;
564 typedef struct server_rec server_rec;
565 typedef struct conn_rec conn_rec;
566 typedef struct request_rec request_rec;
567
568 #include "util_uri.h"
569
570 struct process_rec {
571     ap_context_t *pool;  /* Global pool. Please try to cleared on _all_ exits */
572     ap_context_t *pconf; /* aka configuration pool, cleared on restarts */
573     int argc;
574     const char **argv;
575     const char *short_name;
576 };
577
578 struct request_rec {
579
580     ap_context_t *pool;
581     conn_rec *connection;
582     server_rec *server;
583
584     request_rec *next;          /* If we wind up getting redirected,
585                                  * pointer to the request we redirected to.
586                                  */
587     request_rec *prev;          /* If this is an internal redirect,
588                                  * pointer to where we redirected *from*.
589                                  */
590
591     request_rec *main;          /* If this is a sub_request (see request.h) 
592                                  * pointer back to the main request.
593                                  */
594
595     /* Info about the request itself... we begin with stuff that only
596      * protocol.c should ever touch...
597      */
598
599     char *the_request;          /* First line of request, so we can log it */
600     int assbackwards;           /* HTTP/0.9, "simple" request */
601     int proxyreq;               /* A proxy request (calculated during
602                                  * post_read_request or translate_name) */
603     int header_only;            /* HEAD request, as opposed to GET */
604     char *protocol;             /* Protocol, as given to us, or HTTP/0.9 */
605     int proto_num;              /* Number version of protocol; 1.1 = 1001 */
606     const char *hostname;       /* Host, as set by full URI or Host: */
607
608     ap_time_t request_time;     /* When the request started */
609
610     const char *status_line;    /* Status line, if set by script */
611     int status;                 /* In any case */
612
613     /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
614      * look, but don't touch.
615      */
616
617     const char *method;         /* GET, HEAD, POST, etc. */
618     int method_number;          /* M_GET, M_POST, etc. */
619
620     /*
621         allowed is a bitvector of the allowed methods.
622
623         A handler must ensure that the request method is one that
624         it is capable of handling.  Generally modules should DECLINE
625         any request methods they do not handle.  Prior to aborting the
626         handler like this the handler should set r->allowed to the list
627         of methods that it is willing to handle.  This bitvector is used
628         to construct the "Allow:" header required for OPTIONS requests,
629         and METHOD_NOT_ALLOWED and NOT_IMPLEMENTED status codes.
630
631         Since the default_handler deals with OPTIONS, all modules can
632         usually decline to deal with OPTIONS.  TRACE is always allowed,
633         modules don't need to set it explicitly.
634
635         Since the default_handler will always handle a GET, a
636         module which does *not* implement GET should probably return
637         METHOD_NOT_ALLOWED.  Unfortunately this means that a Script GET
638         handler can't be installed by mod_actions.
639     */
640     int allowed;                /* Allowed methods - for 405, OPTIONS, etc */
641
642     int sent_bodyct;            /* byte count in stream is for body */
643     long bytes_sent;            /* body byte count, for easy access */
644     ap_time_t mtime;            /* Time the resource was last modified */
645
646     /* HTTP/1.1 connection-level features */
647
648     int chunked;                /* sending chunked transfer-coding */
649     int byterange;              /* number of byte ranges */
650     char *boundary;             /* multipart/byteranges boundary */
651     const char *range;          /* The Range: header */
652     long clength;               /* The "real" content length */
653
654     long remaining;             /* bytes left to read */
655     long read_length;           /* bytes that have been read */
656     int read_body;              /* how the request body should be read */
657     int read_chunked;           /* reading chunked transfer-coding */
658     unsigned expecting_100;     /* is client waiting for a 100 response? */
659
660     /* MIME header environments, in and out.  Also, an array containing
661      * environment variables to be passed to subprocesses, so people can
662      * write modules to add to that environment.
663      *
664      * The difference between headers_out and err_headers_out is that the
665      * latter are printed even on error, and persist across internal redirects
666      * (so the headers printed for ErrorDocument handlers will have them).
667      *
668      * The 'notes' ap_table_t is for notes from one module to another, with no
669      * other set purpose in mind...
670      */
671
672     ap_table_t *headers_in;
673     ap_table_t *headers_out;
674     ap_table_t *err_headers_out;
675     ap_table_t *subprocess_env;
676     ap_table_t *notes;
677
678     /* content_type, handler, content_encoding, content_language, and all
679      * content_languages MUST be lowercased strings.  They may be pointers
680      * to static strings; they should not be modified in place.
681      */
682     const char *content_type;   /* Break these out --- we dispatch on 'em */
683     const char *handler;        /* What we *really* dispatch on           */
684
685     const char *content_encoding;
686     const char *content_language;       /* for back-compat. only -- do not use */
687     ap_array_header_t *content_languages;       /* array of (char*) */
688
689     char *vlist_validator;      /* variant list validator (if negotiated) */
690     
691     char *user;                 /* If an authentication check was made,
692                                  * this gets set to the user name.
693                                  */
694     char *ap_auth_type;         /* Ditto. */
695
696     int no_cache;
697     int no_local_copy;
698
699     /* What object is being requested (either directly, or via include
700      * or content-negotiation mapping).
701      */
702
703     char *unparsed_uri;         /* the uri without any parsing performed */
704     char *uri;                  /* the path portion of the URI */
705     char *filename;
706     char *path_info;
707     char *args;                 /* QUERY_ARGS, if any */
708     ap_finfo_t finfo;           /* ST_MODE set to zero if no such file */
709     uri_components parsed_uri;  /* components of uri, dismantled */
710
711     /* Various other config info which may change with .htaccess files
712      * These are config vectors, with one void* pointer for each module
713      * (the thing pointed to being the module's business).
714      */
715
716     void *per_dir_config;       /* Options set in config files, etc. */
717     void *request_config;       /* Notes on *this* request */
718
719 /*
720  * a linked list of the configuration directives in the .htaccess files
721  * accessed by this request.
722  * N.B. always add to the head of the list, _never_ to the end.
723  * that way, a sub request's list can (temporarily) point to a parent's list
724  */
725     const struct htaccess_result *htaccess;
726
727 /* Things placed at the end of the record to avoid breaking binary
728  * compatibility.  It would be nice to remember to reorder the entire
729  * record to improve 64bit alignment the next time we need to break
730  * binary compatibility for some other reason.
731  */
732 };
733
734
735 /* Things which are per connection
736  */
737
738 struct conn_rec {
739
740     ap_context_t *pool;
741     server_rec *base_server;    /* Physical vhost this conn come in on */
742     void *vhost_lookup_data;    /* used by http_vhost.c */
743
744     /* Information about the connection itself */
745
746     BUFF *client;               /* Connection to the guy */
747
748     /* Who is the client? */
749
750     struct sockaddr_in local_addr;      /* local address */
751     struct sockaddr_in remote_addr;     /* remote address */
752     char *remote_ip;            /* Client's IP address */
753     char *remote_host;          /* Client's DNS name, if known.
754                                  * NULL if DNS hasn't been checked,
755                                  * "" if it has and no address was found.
756                                  * N.B. Only access this though
757                                  * get_remote_host() */
758     char *remote_logname;       /* Only ever set if doing rfc1413 lookups.
759                                  * N.B. Only access this through
760                                  * get_remote_logname() */
761
762     unsigned aborted:1;         /* Are we still talking? */
763     signed int keepalive:2;     /* Are we using HTTP Keep-Alive?
764                                  * -1 fatal error, 0 undecided, 1 yes */
765     unsigned keptalive:1;       /* Did we use HTTP Keep-Alive? */
766     signed int double_reverse:2;/* have we done double-reverse DNS?
767                                  * -1 yes/failure, 0 not yet, 1 yes/success */
768     int keepalives;             /* How many times have we used it? */
769     char *local_ip;             /* server IP address */
770     char *local_host;           /* used for ap_get_server_name when
771                                  * UseCanonicalName is set to DNS
772                                  * (ignores setting of HostnameLookups) */
773     long id;                    /* ID of this connection; unique at any
774                                  * point in time */
775     void *conn_config;          /* Notes on *this* connection */
776 };
777
778 /* Per-vhost config... */
779
780 /* The address 255.255.255.255, when used as a virtualhost address,
781  * will become the "default" server when the ip doesn't match other vhosts.
782  */
783 #define DEFAULT_VHOST_ADDR 0xfffffffful
784
785 typedef struct server_addr_rec server_addr_rec;
786 struct server_addr_rec {
787     server_addr_rec *next;
788     ap_in_addr host_addr;       /* The bound address, for this server */
789     unsigned short host_port;   /* The bound port, for this server */
790     char *virthost;             /* The name given in <VirtualHost> */
791 };
792
793 struct server_rec {
794     process_rec *process;
795     server_rec *next;
796
797     /* description of where the definition came from */
798     const char *defn_name;
799     unsigned defn_line_number;
800
801     /* Contact information */
802
803     char *server_admin;
804     char *server_hostname;
805     unsigned short port;        /* for redirects, etc. */
806
807     /* Log files --- note that transfer log is now in the modules... */
808
809     char *error_fname;
810     ap_file_t *error_log;
811     int loglevel;
812
813     /* Module-specific configuration for server, and defaults... */
814
815     int is_virtual;             /* true if this is the virtual server */
816     void *module_config;        /* Config vector containing pointers to
817                                  * modules' per-server config structures.
818                                  */
819     void *lookup_defaults;      /* MIME type info, etc., before we start
820                                  * checking per-directory info.
821                                  */
822     /* Transaction handling */
823
824     server_addr_rec *addrs;
825     int timeout;                /* Timeout, in seconds, before we give up */
826     int keep_alive_timeout;     /* Seconds we'll wait for another request */
827     int keep_alive_max;         /* Maximum requests per connection */
828     int keep_alive;             /* Use persistent connections? */
829
830     char *path;                 /* Pathname for ServerPath */
831     int pathlen;                /* Length of path */
832
833     ap_array_header_t *names;   /* Normal names for ServerAlias servers */
834     ap_array_header_t *wild_names;      /* Wildcarded names for ServerAlias servers */
835
836     uid_t server_uid;        /* effective user id when calling exec wrapper */
837     gid_t server_gid;        /* effective group id when calling exec wrapper */
838
839     int limit_req_line;      /* limit on size of the HTTP request line    */
840     int limit_req_fieldsize; /* limit on size of any request header field */
841     int limit_req_fields;    /* limit on number of request header fields  */
842 };
843
844 /* stuff marked API_EXPORT is part of the API, and intended for use
845  * by modules
846  */
847 #ifndef API_EXPORT
848 #define API_EXPORT(type)    type
849 #endif
850
851 /* Stuff marked API_EXPORT_NONSTD is part of the API, and intended for
852  * use by modules.  The difference between API_EXPORT and
853  * API_EXPORT_NONSTD is that the latter is required for any functions
854  * which use varargs or are used via indirect function call.  This
855  * is to accomodate the two calling conventions in windows dlls.
856  */
857 #ifndef API_EXPORT_NONSTD
858 #define API_EXPORT_NONSTD(type)    type
859 #endif
860
861 #ifndef MODULE_VAR_EXPORT
862 #define MODULE_VAR_EXPORT
863 #endif
864 #ifndef API_VAR_EXPORT
865 #define API_VAR_EXPORT
866 #endif
867
868 /* modules should not used functions marked CORE_EXPORT
869  * or CORE_EXPORT_NONSTD */
870 #ifndef CORE_EXPORT
871 #define CORE_EXPORT     API_EXPORT
872 #endif
873 #ifndef CORE_EXPORT_NONSTD
874 #define CORE_EXPORT_NONSTD      API_EXPORT_NONSTD
875 #endif
876
877 /* On Mac OS X Server, symbols that conflict with loaded dylibs
878  * (eg. System framework) need to be declared as private symbols with
879  * __private_extern__.
880  * For other systems, make that a no-op.
881  */
882 #ifndef ap_private_extern
883 #if (defined(MAC_OS) || defined(MAC_OS_X_SERVER)) && defined(__DYNAMIC__)
884 #define ap_private_extern __private_extern__
885 #else
886 #define ap_private_extern
887 #endif
888 #endif
889
890 /* Time */
891
892 API_EXPORT(char *) ap_field_noparam(ap_context_t *p, const char *intype);
893 API_EXPORT(char *) ap_ht_time(ap_context_t *p, ap_time_t t, const char *fmt, int gmt);
894
895 /* String handling. The *_nc variants allow you to use non-const char **s as
896    arguments (unfortunately C won't automatically convert a char ** to a const
897    char **) */
898
899 API_EXPORT(char *) ap_getword(ap_context_t *p, const char **line, char stop);
900 API_EXPORT(char *) ap_getword_nc(ap_context_t *p, char **line, char stop);
901 API_EXPORT(char *) ap_getword_white(ap_context_t *p, const char **line);
902 API_EXPORT(char *) ap_getword_white_nc(ap_context_t *p, char **line);
903 API_EXPORT(char *) ap_getword_nulls(ap_context_t *p, const char **line, char stop);
904 API_EXPORT(char *) ap_getword_nulls_nc(ap_context_t *p, char **line, char stop);
905 API_EXPORT(char *) ap_getword_conf(ap_context_t *p, const char **line);
906 API_EXPORT(char *) ap_getword_conf_nc(ap_context_t *p, char **line);
907 API_EXPORT(char *) ap_resolve_env(ap_context_t *p, const char * word); 
908
909 API_EXPORT(const char *) ap_size_list_item(const char **field, int *len);
910 API_EXPORT(char *) ap_get_list_item(ap_context_t *p, const char **field);
911 API_EXPORT(int) ap_find_list_item(ap_context_t *p, const char *line, const char *tok);
912
913 API_EXPORT(char *) ap_get_token(ap_context_t *p, const char **accept_line, int accept_white);
914 API_EXPORT(int) ap_find_token(ap_context_t *p, const char *line, const char *tok);
915 API_EXPORT(int) ap_find_last_token(ap_context_t *p, const char *line, const char *tok);
916
917 API_EXPORT(int) ap_is_url(const char *u);
918 API_EXPORT(int) ap_unescape_url(char *url);
919 API_EXPORT(void) ap_no2slash(char *name);
920 API_EXPORT(void) ap_getparents(char *name);
921 API_EXPORT(char *) ap_escape_path_segment(ap_context_t *p, const char *s);
922 API_EXPORT(char *) ap_os_escape_path(ap_context_t *p, const char *path, int partial);
923 #define ap_escape_uri(ppool,path) ap_os_escape_path(ppool,path,1)
924 API_EXPORT(char *) ap_escape_html(ap_context_t *p, const char *s);
925 API_EXPORT(char *) ap_construct_server(ap_context_t *p, const char *hostname,
926                                     unsigned port, const request_rec *r);
927 API_EXPORT(char *) ap_escape_shell_cmd(ap_context_t *p, const char *s);
928
929 API_EXPORT(int) ap_count_dirs(const char *path);
930 API_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n);
931 API_EXPORT(char *) ap_make_dirstr_parent(ap_context_t *p, const char *s);
932 /* deprecated.  The previous two routines are preferred. */
933 API_EXPORT(char *) ap_make_dirstr(ap_context_t *a, const char *s, int n);
934 API_EXPORT(char *) ap_make_full_path(ap_context_t *a, const char *dir, const char *f);
935
936 API_EXPORT(int) ap_is_matchexp(const char *str);
937 API_EXPORT(int) ap_strcmp_match(const char *str, const char *exp);
938 API_EXPORT(int) ap_strcasecmp_match(const char *str, const char *exp);
939 API_EXPORT(char *) ap_strcasestr(const char *s1, const char *s2);
940 API_EXPORT(char *) ap_pbase64decode(ap_context_t *p, const char *bufcoded);
941 API_EXPORT(char *) ap_pbase64encode(ap_context_t *p, char *string); 
942 API_EXPORT(char *) ap_uudecode(ap_context_t *p, const char *bufcoded);
943 API_EXPORT(char *) ap_uuencode(ap_context_t *p, char *string); 
944
945 /* Regexes */
946 #if defined(AP_USE_HSREGEX) || defined(WIN32)
947 #include "hsregex.h"
948 #else
949 #include <regex.h>
950 #endif
951
952 API_EXPORT(regex_t *) ap_pregcomp(ap_context_t *p, const char *pattern,
953                                    int cflags);
954 API_EXPORT(void) ap_pregfree(ap_context_t *p, regex_t *reg);
955 API_EXPORT(int)    ap_regexec(const regex_t *preg, const char *string,
956                               size_t nmatch, regmatch_t pmatch[], int eflags);
957 API_EXPORT(size_t) ap_regerror(int errcode, const regex_t *preg, 
958                                char *errbuf, size_t errbuf_size);
959 API_EXPORT(char *) ap_pregsub(ap_context_t *p, const char *input, const char *source,
960                               size_t nmatch, regmatch_t pmatch[]);
961
962 API_EXPORT(void) ap_content_type_tolower(char *);
963 API_EXPORT(void) ap_str_tolower(char *);
964 API_EXPORT(int) ap_ind(const char *, char);     /* Sigh... */
965 API_EXPORT(int) ap_rind(const char *, char);
966
967 API_EXPORT(char *) ap_escape_quotes (ap_context_t *p, const char *instring);
968
969 /* Common structure for reading of config files / passwd files etc. */
970 typedef struct {
971     int (*getch) (void *param); /* a getc()-like function */
972     void *(*getstr) (void *buf, size_t bufsiz, void *param); /* a fgets()-like function */
973     int (*close) (void *param); /* a close hander function */
974     void *param;                /* the argument passed to getch/getstr/close */
975     const char *name;           /* the filename / description */
976     unsigned line_number;       /* current line number, starting at 1 */
977 } configfile_t;
978
979 /* Open a configfile_t as FILE, return open configfile_t struct pointer */
980 API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **, ap_context_t *p, const char *name);
981
982 /* Allocate a configfile_t handle with user defined functions and params */
983 API_EXPORT(configfile_t *) ap_pcfg_open_custom(ap_context_t *p, const char *descr,
984     void *param,
985     int(*getc_func)(void*),
986     void *(*gets_func) (void *buf, size_t bufsiz, void *param),
987     int(*close_func)(void *param));
988
989 /* Read one line from open configfile_t, strip LF, increase line number */
990 API_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp);
991
992 /* Read one char from open configfile_t, increase line number upon LF */
993 API_EXPORT(int) ap_cfg_getc(configfile_t *cfp);
994
995 /* Detach from open configfile_t, calling the close handler */
996 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp);
997
998 /* Misc system hackery */
999
1000 API_EXPORT(uid_t) ap_uname2id(const char *name);
1001 API_EXPORT(gid_t) ap_gname2id(const char *name);
1002 API_EXPORT(int) ap_is_directory(const char *name);
1003 API_EXPORT(void) ap_chdir_file(const char *file);
1004 API_EXPORT(int) ap_get_max_daemons(void);
1005 API_EXPORT(const server_rec *) ap_get_server_conf(void);
1006
1007 #ifdef _OSD_POSIX
1008 extern const char *os_set_account(ap_context_t *p, const char *account);
1009 extern int os_init_job_environment(server_rec *s, const char *user_name, int one_process);
1010 #endif /* _OSD_POSIX */
1011
1012 char *ap_get_local_host(ap_context_t *);
1013 unsigned long ap_get_virthost_addr(char *hostname, unsigned short *port);
1014
1015 API_EXPORT(char *) ap_escape_quotes(ap_context_t *p, const char *instr);
1016
1017 /*
1018  * Redefine assert() to something more useful for an Apache...
1019  */
1020 API_EXPORT(void) ap_log_assert(const char *szExp, const char *szFile, int nLine)
1021                             __attribute__((noreturn));
1022 #define ap_assert(exp) ((exp) ? (void)0 : ap_log_assert(#exp,__FILE__,__LINE__))
1023
1024 /* A set of flags which indicate places where the server should raise(SIGSTOP).
1025  * This is useful for debugging, because you can then attach to that process
1026  * with gdb and continue.  This is important in cases where one_process
1027  * debugging isn't possible.
1028  */
1029 #define SIGSTOP_DETACH                  1
1030 #define SIGSTOP_MAKE_CHILD              2
1031 #define SIGSTOP_SPAWN_CHILD             4
1032 #define SIGSTOP_PIPED_LOG_SPAWN         8
1033 #define SIGSTOP_CGI_CHILD               16
1034
1035 #ifdef DEBUG_SIGSTOP
1036 extern int raise_sigstop_flags;
1037 #define RAISE_SIGSTOP(x)        do { \
1038         if (raise_sigstop_flags & SIGSTOP_##x) raise(SIGSTOP);\
1039     } while (0)
1040 #else
1041 #define RAISE_SIGSTOP(x)
1042 #endif
1043
1044 API_EXPORT(extern const char *) ap_psignature(const char *prefix, request_rec *r);
1045
1046 /* strtoul does not exist on sunos4. */
1047 #ifdef strtoul
1048 #undef strtoul
1049 #endif
1050 #define strtoul strtoul_is_not_a_portable_function_use_strtol_instead
1051
1052 #define ap_is_aborted(abort) (abort->aborted ==1)
1053
1054 #ifdef __cplusplus
1055 }
1056 #endif
1057
1058 #endif  /* !APACHE_HTTPD_H */