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