1 /* ====================================================================
2 * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
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
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/)."
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
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.
30 * 6. Redistributions of any form whatsoever must retain the following
32 * "This product includes software developed by the Apache Group
33 * for use in the Apache HTTP server project (http://www.apache.org/)."
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 * ====================================================================
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/>.
58 #ifndef APACHE_HTTPD_H
59 #define APACHE_HTTPD_H
66 * httpd.h: header for simple (ha! not anymore) http daemon
69 /* Headers in which EVERYONE has an interest... */
71 #include "ap_config.h"
76 /* ----------------------------- config dir ------------------------------ */
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.
83 /* Set default for OS/2 file system */
84 #define HTTPD_ROOT "/os2httpd"
86 /* Set default for Windows file system */
87 #define HTTPD_ROOT "/apache"
89 #define HTTPD_ROOT "/usr/local/apache"
91 #endif /* HTTPD_ROOT */
93 /* Default location of documents. Can be overridden by the DocumentRoot
96 #ifndef DOCUMENT_LOCATION
98 /* Set default for OS/2 file system */
99 #define DOCUMENT_LOCATION HTTPD_ROOT "/docs"
101 #define DOCUMENT_LOCATION HTTPD_ROOT "/htdocs"
103 #endif /* DOCUMENT_LOCATION */
105 /* Max. number of dynamically loaded modules */
106 #ifndef DYNAMIC_MODULE_LIMIT
107 #define DYNAMIC_MODULE_LIMIT 64
110 /* Default administrator's address */
111 #define DEFAULT_ADMIN "[no address given]"
113 /* The target name of the installed Apache */
115 #define TARGET "httpd"
119 * --------- You shouldn't have to edit anything below this line ----------
121 * Any modifications to any defaults not defined above should be done in the
122 * respective config. file.
127 /* -- Internal representation for a HTTP protocol number, e.g., HTTP/1.1 -- */
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)
134 /* -------------- Port number for server running standalone --------------- */
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
142 /* --------- Default user name and group name running standalone ---------- */
143 /* --- These may be specified as numbers by placing a # before a number --- */
146 #define DEFAULT_USER "#-1"
148 #ifndef DEFAULT_GROUP
149 #define DEFAULT_GROUP "#-1"
152 /* The name of the log files */
153 #ifndef DEFAULT_XFERLOG
154 #if defined(OS2) || defined(WIN32)
155 #define DEFAULT_XFERLOG "logs/access.log"
157 #define DEFAULT_XFERLOG "logs/access_log"
159 #endif /* DEFAULT_XFERLOG */
161 #ifndef DEFAULT_ERRORLOG
162 #if defined(OS2) || defined(WIN32)
163 #define DEFAULT_ERRORLOG "logs/error.log"
165 #define DEFAULT_ERRORLOG "logs/error_log"
167 #endif /* DEFAULT_ERRORLOG */
169 #ifndef DEFAULT_PIDLOG
170 #define DEFAULT_PIDLOG "logs/httpd.pid"
172 #ifndef DEFAULT_SCOREBOARD
173 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
175 #ifndef DEFAULT_LOCKFILE
176 #define DEFAULT_LOCKFILE "logs/accept.lock"
179 /* Define this to be what your HTML directory content files are called */
180 #ifndef DEFAULT_INDEX
181 #define DEFAULT_INDEX "index.html"
184 /* Define this to 1 if you want fancy indexing, 0 otherwise */
185 #ifndef DEFAULT_INDEXING
186 #define DEFAULT_INDEXING 0
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"
195 /* Define this to be what your per-directory security files are called */
196 #ifndef DEFAULT_ACCESS_FNAME
198 /* Set default for OS/2 file system */
199 #define DEFAULT_ACCESS_FNAME "htaccess"
201 #define DEFAULT_ACCESS_FNAME ".htaccess"
203 #endif /* DEFAULT_ACCESS_FNAME */
205 /* The name of the server config file */
206 #ifndef SERVER_CONFIG_FILE
207 #define SERVER_CONFIG_FILE "conf/httpd.conf"
210 /* The name of the document config file */
211 #ifndef RESOURCE_CONFIG_FILE
212 #define RESOURCE_CONFIG_FILE "conf/srm.conf"
215 /* The name of the MIME types file */
216 #ifndef TYPES_CONFIG_FILE
217 #define TYPES_CONFIG_FILE "conf/mime.types"
220 /* The name of the access file */
221 #ifndef ACCESS_CONFIG_FILE
222 #define ACCESS_CONFIG_FILE "conf/access.conf"
225 /* Whether we should enable rfc1413 identity checking */
226 #ifndef DEFAULT_RFC1413
227 #define DEFAULT_RFC1413 0
229 /* The default directory in user's home dir */
230 #ifndef DEFAULT_USER_DIR
231 #define DEFAULT_USER_DIR "public_html"
234 /* The default path for CGI scripts if none is currently set */
236 #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
239 /* The path to the shell interpreter, for parsed docs */
241 #if defined(OS2) || defined(WIN32)
242 /* Set default for OS/2 and Windows file system */
243 #define SHELL_PATH "CMD.EXE"
245 #define SHELL_PATH "/bin/sh"
247 #endif /* SHELL_PATH */
249 /* The path to the suExec wrapper, can be overridden in Configuration */
251 #define SUEXEC_BIN HTTPD_ROOT "/sbin/suexec"
254 /* The default string lengths */
255 #define MAX_STRING_LEN HUGE_STRING_LEN
256 #define HUGE_STRING_LEN 8192
258 /* The timeout for waiting for messages */
259 #ifndef DEFAULT_TIMEOUT
260 #define DEFAULT_TIMEOUT 300
263 /* The timeout for waiting for keepalive timeout until next request */
264 #ifndef DEFAULT_KEEPALIVE_TIMEOUT
265 #define DEFAULT_KEEPALIVE_TIMEOUT 15
268 /* The number of requests to entertain per connection */
269 #ifndef DEFAULT_KEEPALIVE
270 #define DEFAULT_KEEPALIVE 100
273 /* The size of the server's internal read-write buffers */
274 #define IOBUFSIZE 8192
276 /* Number of servers to spawn off by default --- also, if fewer than
277 * this free when the caretaker checks, it will spawn more.
279 #ifndef DEFAULT_START_DAEMON
280 #define DEFAULT_START_DAEMON 5
283 /* Maximum number of *free* server processes --- more than this, and
287 #ifndef DEFAULT_MAX_FREE_DAEMON
288 #define DEFAULT_MAX_FREE_DAEMON 10
291 /* Minimum --- fewer than this, and more will be created */
293 #ifndef DEFAULT_MIN_FREE_DAEMON
294 #define DEFAULT_MIN_FREE_DAEMON 5
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.
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
308 #ifndef HARD_SERVER_LIMIT
309 #define HARD_SERVER_LIMIT 256
313 * Special Apache error codes. These are basically used
314 * in http_main.c so we can keep track of various errors.
319 * A fatal error arising during the server's init sequence
321 * The child died during it's init sequence
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.
328 #define APEXIT_OK 0x0
329 #define APEXIT_INIT 0x2
330 #define APEXIT_CHILDINIT 0x3
331 #define APEXIT_CHILDFATAL 0xf
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.
344 #ifndef SCOREBOARD_MAINTENANCE_INTERVAL
345 #define SCOREBOARD_MAINTENANCE_INTERVAL 1000000
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.
353 #ifndef DEFAULT_MAX_REQUESTS_PER_CHILD
354 #define DEFAULT_MAX_REQUESTS_PER_CHILD 0
357 #ifndef DEFAULT_THREADS_PER_CHILD
358 #define DEFAULT_THREADS_PER_CHILD 50
360 #ifndef DEFAULT_EXCESS_REQUESTS_PER_CHILD
361 #define DEFAULT_EXCESS_REQUESTS_PER_CHILD 0
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.
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.
373 #ifndef DEFAULT_LISTENBACKLOG
374 #define DEFAULT_LISTENBACKLOG 511
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.
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.
390 * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
391 * the server config directive LimitRequestFields.
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 */
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.
407 * The tokens are listed in order of their significance for identifying the
410 * "Product tokens should be short and to the point -- use of them for
411 * advertizing or other non-essential information is explicitly forbidden."
413 * Example: "Apache/1.1.0 MrWidget/0.1-alpha"
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 */
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);
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'.
432 #define APACHE_RELEASE 10306100
434 #define SERVER_PROTOCOL "HTTP/1.1"
435 #ifndef SERVER_SUPPORT
436 #define SERVER_SUPPORT "http://www.apache.org/"
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
443 #define OK 0 /* Module has handled this stage. */
446 /* ----------------------- HTTP Status Codes ------------------------- */
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.
452 #define RESPONSE_CODES 55
454 #define HTTP_CONTINUE 100
455 #define HTTP_SWITCHING_PROTOCOLS 101
456 #define HTTP_PROCESSING 102
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
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
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))
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))
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.
552 #define M_PROPPATCH 9
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"
573 /* Just in case your linefeed isn't the one the other end is expecting. */
574 #ifndef CHARSET_EBCDIC
577 #else /* CHARSET_EBCDIC */
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
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.
588 #endif /* CHARSET_EBCDIC */
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.
596 #define REQUEST_NO_BODY 0
597 #define REQUEST_CHUNKED_ERROR 1
598 #define REQUEST_CHUNKED_DECHUNK 2
599 #define REQUEST_CHUNKED_PASS 3
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
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.
614 /* This represents the result of calling htaccess; these are cached for
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;
625 typedef struct 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;
630 #include "util_uri.h"
635 conn_rec *connection;
638 request_rec *next; /* If we wind up getting redirected,
639 * pointer to the request we redirected to.
641 request_rec *prev; /* If this is an internal redirect,
642 * pointer to where we redirected *from*.
645 request_rec *main; /* If this is a sub_request (see request.h)
646 * pointer back to the main request.
649 /* Info about the request itself... we begin with stuff that only
650 * protocol.c should ever touch...
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: */
662 time_t request_time; /* When the request started */
664 const char *status_line; /* Status line, if set by script */
665 int status; /* In any case */
667 /* Request method, two ways; also, protocol, etc.. Outside of protocol.c,
668 * look, but don't touch.
671 const char *method; /* GET, HEAD, POST, etc. */
672 int method_number; /* M_GET, M_POST, etc. */
675 * allowed is a bitvector of the allowed methods.
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.
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.
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.
694 int allowed; /* Allowed methods - for 405, OPTIONS, etc */
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 */
700 /* HTTP/1.1 connection-level features */
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 */
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? */
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.
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).
722 * The 'notes' table is for notes from one module to another, with no
723 * other set purpose in mind...
728 table *err_headers_out;
729 table *subprocess_env;
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.
736 const char *content_type; /* Break these out --- we dispatch on 'em */
737 const char *handler; /* What we *really* dispatch on */
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*) */
743 char *vlist_validator; /* variant list validator (if negotiated) */
748 /* What object is being requested (either directly, or via include
749 * or content-negotiation mapping).
752 char *unparsed_uri; /* the uri without any parsing performed */
753 char *uri; /* the path portion of the URI */
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 */
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).
765 void *per_dir_config; /* Options set in config files, etc. */
766 void *request_config; /* Notes on *this* request */
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
774 const struct htaccess_result *htaccess;
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.
784 /* Things which are per connection
791 server_rec *base_server; /* Physical vhost this conn come in on */
792 void *vhost_lookup_data; /* used by http_vhost.c */
794 /* Information about the connection itself */
796 int child_num; /* The number of the child handling conn_rec */
797 BUFF *client; /* Connection to the guy */
799 /* Who is the client? */
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(!)
816 char *ap_auth_type; /* Ditto. */
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? */
827 /* Per-vhost config... */
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.
832 #define DEFAULT_VHOST_ADDR 0xfffffffful
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> */
846 /* description of where the definition came from */
847 const char *defn_name;
848 unsigned defn_line_number;
850 /* Full locations of server config info */
853 char *access_confname;
855 /* Contact information */
858 char *server_hostname;
859 unsigned short port; /* for redirects, etc. */
861 /* Log files --- note that transfer log is now in the modules... */
867 /* Module-specific configuration for server, and defaults... */
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.
873 void *lookup_defaults; /* MIME type info, etc., before we start
874 * checking per-directory info.
876 /* Transaction handling */
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) */
885 char *path; /* Pathname for ServerPath */
886 int pathlen; /* Length of path */
888 array_header *names; /* Normal names for ServerAlias servers */
889 array_header *wild_names; /* Wildcarded names for ServerAlias servers */
891 uid_t server_uid; /* effective user id when calling exec wrapper */
892 gid_t server_gid; /* effective group id when calling exec wrapper */
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 */
899 /* These are more like real hosts than virtual hosts */
902 struct sockaddr_in local_addr; /* local IP address and port */
904 int used; /* Only used during restart */
905 /* more stuff here, like which protocol is bound to the port */
908 /* Prototypes for utilities... util.c.
911 extern void ap_util_init(void);
914 extern API_VAR_EXPORT const char ap_month_snames[12][4];
915 extern API_VAR_EXPORT const char ap_day_snames[7][4];
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,
921 API_EXPORT(char *) ap_gm_timestr_822(pool * p, time_t t);
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
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,
933 API_EXPORT(char *) ap_getword_nulls_nc(pool * p, char **line,
935 API_EXPORT(char *) ap_getword_conf(pool * p, const char **line);
936 API_EXPORT(char *) ap_getword_conf_nc(pool * p, char **line);
938 API_EXPORT(const char *) ap_size_list_item(const char **field,
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,
944 API_EXPORT(char *) ap_get_token(pool * p, const char **accept_line,
946 API_EXPORT(int) ap_find_token(pool * p, const char *line,
948 API_EXPORT(int) ap_find_last_token(pool * p, const char *line,
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,
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,
962 const request_rec * r);
963 API_EXPORT(char *) ap_escape_shell_cmd(pool * p, const char *s);
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,
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);
979 void os2pathname(char *path);
982 API_EXPORT(char *) ap_pregsub(pool * p, const char *input,
983 const char *source, size_t nmatch,
984 regmatch_t pmatch[]);
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);
991 API_EXPORT(char *) ap_escape_quotes(pool * p, const char *instring);
993 /* Common structure for reading of config files / passwd files etc. */
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 */
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);
1006 /* Allocate a configfile_t handle with user defined functions and params */
1007 API_EXPORT(configfile_t *) ap_pcfg_open_custom(pool * p,
1010 int (*getc_func) (void
1012 void *(*gets_func) (void
1018 int (*close_func) (void
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);
1025 /* Read one char from open configfile_t, increase line number upon LF */
1026 API_EXPORT(int) ap_cfg_getc(configfile_t * cfp);
1028 /* Detach from open configfile_t, calling the close handler */
1029 API_EXPORT(int) ap_cfg_closefile(configfile_t * cfp);
1031 #ifdef NEED_STRERROR
1032 char *strerror(int err);
1035 /* Misc system hackery */
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);
1043 #ifndef HAVE_CANONICAL_FILENAME
1045 * We can't define these in os.h because of dependence on pool pointer.
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)
1051 API_EXPORT(char *) ap_os_canonical_filename(pool * p, const char *file);
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);
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)
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,
1067 #endif /* _OSD_POSIX */
1069 char *ap_get_local_host(pool *);
1070 unsigned long ap_get_virthost_addr(char *hostname, unsigned short *port);
1072 extern API_VAR_EXPORT time_t ap_restart_time;
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"
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.
1087 #ifndef LOW_SLACK_LINE
1088 #define LOW_SLACK_LINE 15
1090 /* #define HIGH_SLACK_LINE 255 */
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
1099 #define ap_slack(fd,line) (fd)
1101 int ap_slack(int fd, int line);
1102 #define AP_SLACK_LOW 1
1103 #define AP_SLACK_HIGH 2
1106 API_EXPORT(char *) ap_escape_quotes(pool * p, const char *instr);
1109 * Redefine assert() to something more useful for an Apache...
1111 API_EXPORT(void) ap_log_assert(const char *szExp, const char *szFile,
1113 __attribute__ ((noreturn));
1114 #define ap_assert(exp) ((exp) ? (void)0 : ap_log_assert(#exp,__FILE__,__LINE__))
1116 /* The optimized timeout code only works if we're not MULTITHREAD and we're
1117 * also not using a scoreboard file
1119 #if !defined (MULTITHREAD) && \
1120 (defined (USE_MMAP_SCOREBOARD) || defined (USE_SHMGET_SCOREBOARD))
1121 #define OPTIMIZE_TIMEOUTS
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.
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
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);\
1141 #define RAISE_SIGSTOP(x)
1144 API_EXPORT(extern const char *) ap_psignature(const char *prefix,
1147 /* strtoul does not exist on sunos4. */
1151 #define strtoul strtoul_is_not_a_portable_function_use_strtol_instead
1156 #endif /* !APACHE_HTTPD_H */