Main Page | Modules | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

httpd.h

Go to the documentation of this file.
00001 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
00002  * applicable.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APACHE_HTTPD_H
00018 #define APACHE_HTTPD_H
00019 
00020 /**
00021  * @file httpd.h
00022  * @brief HTTP Daemon routines
00023  */
00024 
00025 /* XXX - We need to push more stuff to other .h files, or even .c files, to
00026  * make this file smaller
00027  */
00028 
00029 /* Headers in which EVERYONE has an interest... */
00030 #include "ap_config.h"
00031 #include "ap_mmn.h"
00032 
00033 #include "ap_release.h"
00034 
00035 #include "apr_general.h"
00036 #include "apr_tables.h"
00037 #include "apr_pools.h"
00038 #include "apr_time.h"
00039 #include "apr_network_io.h"
00040 #include "apr_buckets.h"
00041 
00042 #include "os.h"
00043 
00044 #include "pcreposix.h"
00045 
00046 /* Note: util_uri.h is also included, see below */
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 #ifdef CORE_PRIVATE
00053 
00054 /* ----------------------------- config dir ------------------------------ */
00055 
00056 /* Define this to be the default server home dir. Most things later in this
00057  * file with a relative pathname will have this added.
00058  */
00059 #ifndef HTTPD_ROOT
00060 #ifdef OS2
00061 /* Set default for OS/2 file system */
00062 #define HTTPD_ROOT "/os2httpd"
00063 #elif defined(WIN32)
00064 /* Set default for Windows file system */
00065 #define HTTPD_ROOT "/apache"
00066 #elif defined (BEOS)
00067 /* Set the default for BeOS */
00068 #define HTTPD_ROOT "/boot/home/apache"
00069 #elif defined (NETWARE)
00070 /* Set the default for NetWare */
00071 #define HTTPD_ROOT "/apache"
00072 #else
00073 #define HTTPD_ROOT "/usr/local/apache"
00074 #endif
00075 #endif /* HTTPD_ROOT */
00076 
00077 /* 
00078  * --------- You shouldn't have to edit anything below this line ----------
00079  *
00080  * Any modifications to any defaults not defined above should be done in the 
00081  * respective configuration file. 
00082  *
00083  */
00084 
00085 /* Default location of documents.  Can be overridden by the DocumentRoot
00086  * directive.
00087  */
00088 #ifndef DOCUMENT_LOCATION
00089 #ifdef OS2
00090 /* Set default for OS/2 file system */
00091 #define DOCUMENT_LOCATION  HTTPD_ROOT "/docs"
00092 #else
00093 #define DOCUMENT_LOCATION  HTTPD_ROOT "/htdocs"
00094 #endif
00095 #endif /* DOCUMENT_LOCATION */
00096 
00097 /* Maximum number of dynamically loaded modules */
00098 #ifndef DYNAMIC_MODULE_LIMIT
00099 #define DYNAMIC_MODULE_LIMIT 64
00100 #endif
00101 
00102 /* Default administrator's address */
00103 #define DEFAULT_ADMIN "[no address given]"
00104 
00105 /* The name of the log files */
00106 #ifndef DEFAULT_ERRORLOG
00107 #if defined(OS2) || defined(WIN32)
00108 #define DEFAULT_ERRORLOG "logs/error.log"
00109 #else
00110 #define DEFAULT_ERRORLOG "logs/error_log"
00111 #endif
00112 #endif /* DEFAULT_ERRORLOG */
00113 
00114 /* Define this to be what your per-directory security files are called */
00115 #ifndef DEFAULT_ACCESS_FNAME
00116 #ifdef OS2
00117 /* Set default for OS/2 file system */
00118 #define DEFAULT_ACCESS_FNAME "htaccess"
00119 #else
00120 #define DEFAULT_ACCESS_FNAME ".htaccess"
00121 #endif
00122 #endif /* DEFAULT_ACCESS_FNAME */
00123 
00124 /* The name of the server config file */
00125 #ifndef SERVER_CONFIG_FILE
00126 #define SERVER_CONFIG_FILE "conf/httpd.conf"
00127 #endif
00128 
00129 /* Whether we should enable rfc1413 identity checking */
00130 #ifndef DEFAULT_RFC1413
00131 #define DEFAULT_RFC1413 0
00132 #endif
00133 
00134 /* The default path for CGI scripts if none is currently set */
00135 #ifndef DEFAULT_PATH
00136 #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
00137 #endif
00138 
00139 /* The path to the suExec wrapper, can be overridden in Configuration */
00140 #ifndef SUEXEC_BIN
00141 #define SUEXEC_BIN  HTTPD_ROOT "/bin/suexec"
00142 #endif
00143 
00144 /* The timeout for waiting for messages */
00145 #ifndef DEFAULT_TIMEOUT
00146 #define DEFAULT_TIMEOUT 300 
00147 #endif
00148 
00149 /* The timeout for waiting for keepalive timeout until next request */
00150 #ifndef DEFAULT_KEEPALIVE_TIMEOUT
00151 #define DEFAULT_KEEPALIVE_TIMEOUT 15
00152 #endif
00153 
00154 /* The number of requests to entertain per connection */
00155 #ifndef DEFAULT_KEEPALIVE
00156 #define DEFAULT_KEEPALIVE 100
00157 #endif
00158 
00159 /* Limits on the size of various request items.  These limits primarily
00160  * exist to prevent simple denial-of-service attacks on a server based
00161  * on misuse of the protocol.  The recommended values will depend on the
00162  * nature of the server resources -- CGI scripts and database backends
00163  * might require large values, but most servers could get by with much
00164  * smaller limits than we use below.  The request message body size can
00165  * be limited by the per-dir config directive LimitRequestBody.
00166  *
00167  * Internal buffer sizes are two bytes more than the DEFAULT_LIMIT_REQUEST_LINE
00168  * and DEFAULT_LIMIT_REQUEST_FIELDSIZE below, which explains the 8190.
00169  * These two limits can be lowered (but not raised) by the server config
00170  * directives LimitRequestLine and LimitRequestFieldsize, respectively.
00171  *
00172  * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
00173  * the server config directive LimitRequestFields.
00174  */
00175 #ifndef DEFAULT_LIMIT_REQUEST_LINE
00176 #define DEFAULT_LIMIT_REQUEST_LINE 8190
00177 #endif /* default limit on bytes in Request-Line (Method+URI+HTTP-version) */
00178 #ifndef DEFAULT_LIMIT_REQUEST_FIELDSIZE
00179 #define DEFAULT_LIMIT_REQUEST_FIELDSIZE 8190
00180 #endif /* default limit on bytes in any one header field  */
00181 #ifndef DEFAULT_LIMIT_REQUEST_FIELDS
00182 #define DEFAULT_LIMIT_REQUEST_FIELDS 100
00183 #endif /* default limit on number of request header fields */
00184 
00185 
00186 /**
00187  * The default default character set name to add if AddDefaultCharset is
00188  * enabled.  Overridden with AddDefaultCharsetName.
00189  */
00190 #define DEFAULT_ADD_DEFAULT_CHARSET_NAME "iso-8859-1"
00191 
00192 #endif /* CORE_PRIVATE */
00193 
00194 /** default HTTP Server protocol */
00195 #define AP_SERVER_PROTOCOL "HTTP/1.1"
00196 
00197 
00198 /* ------------------ stuff that modules are allowed to look at ----------- */
00199 
00200 /** Define this to be what your HTML directory content files are called */
00201 #ifndef AP_DEFAULT_INDEX
00202 #define AP_DEFAULT_INDEX "index.html"
00203 #endif
00204 
00205 
00206 /** 
00207  * Define this to be what type you'd like returned for files with unknown 
00208  * suffixes.  
00209  * @warning MUST be all lower case. 
00210  */
00211 #ifndef DEFAULT_CONTENT_TYPE
00212 #define DEFAULT_CONTENT_TYPE "text/plain"
00213 #endif
00214 
00215 /** The name of the MIME types file */
00216 #ifndef AP_TYPES_CONFIG_FILE
00217 #define AP_TYPES_CONFIG_FILE "conf/mime.types"
00218 #endif
00219 
00220 /*
00221  * Define the HTML doctype strings centrally.
00222  */
00223 /** HTML 2.0 Doctype */
00224 #define DOCTYPE_HTML_2_0  "<!DOCTYPE HTML PUBLIC \"-//IETF//" \
00225                           "DTD HTML 2.0//EN\">\n"
00226 /** HTML 3.2 Doctype */
00227 #define DOCTYPE_HTML_3_2  "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
00228                           "DTD HTML 3.2 Final//EN\">\n"
00229 /** HTML 4.0 Strict Doctype */
00230 #define DOCTYPE_HTML_4_0S "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
00231                           "DTD HTML 4.0//EN\"\n" \
00232                           "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
00233 /** HTML 4.0 Transitional Doctype */
00234 #define DOCTYPE_HTML_4_0T "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
00235                           "DTD HTML 4.0 Transitional//EN\"\n" \
00236                           "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"
00237 /** HTML 4.0 Frameset Doctype */
00238 #define DOCTYPE_HTML_4_0F "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
00239                           "DTD HTML 4.0 Frameset//EN\"\n" \
00240                           "\"http://www.w3.org/TR/REC-html40/frameset.dtd\">\n"
00241 /** XHTML 1.0 Strict Doctype */
00242 #define DOCTYPE_XHTML_1_0S "<!DOCTYPE html PUBLIC \"-//W3C//" \
00243                            "DTD XHTML 1.0 Strict//EN\"\n" \
00244                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
00245                            "xhtml1-strict.dtd\">\n"
00246 /** XHTML 1.0 Transitional Doctype */
00247 #define DOCTYPE_XHTML_1_0T "<!DOCTYPE html PUBLIC \"-//W3C//" \
00248                            "DTD XHTML 1.0 Transitional//EN\"\n" \
00249                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
00250                            "xhtml1-transitional.dtd\">\n"
00251 /** XHTML 1.0 Frameset Doctype */
00252 #define DOCTYPE_XHTML_1_0F "<!DOCTYPE html PUBLIC \"-//W3C//" \
00253                            "DTD XHTML 1.0 Frameset//EN\"\n" \
00254                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
00255                            "xhtml1-frameset.dtd\">"
00256 
00257 /** Internal representation for a HTTP protocol number, e.g., HTTP/1.1 */
00258 
00259 #define HTTP_VERSION(major,minor) (1000*(major)+(minor))
00260 /** Major part of HTTP protocol */
00261 #define HTTP_VERSION_MAJOR(number) ((number)/1000)
00262 /** Minor part of HTTP protocol */
00263 #define HTTP_VERSION_MINOR(number) ((number)%1000)
00264 
00265 /* -------------- Port number for server running standalone --------------- */
00266 
00267 /** default HTTP Port */
00268 #define DEFAULT_HTTP_PORT       80
00269 /** default HTTPS Port */
00270 #define DEFAULT_HTTPS_PORT      443
00271 /**
00272  * Check whether @a port is the default port for the request @a r.
00273  * @param port The port number
00274  * @param r The request
00275  * @see #ap_default_port
00276  */
00277 #define ap_is_default_port(port,r)      ((port) == ap_default_port(r))
00278 /**
00279  * Get the default port for a request (which depends on the scheme).
00280  * @param r The request
00281  */
00282 #define ap_default_port(r)      ap_run_default_port(r)
00283 /**
00284  * Get the scheme for a request.
00285  * @param r The request
00286  * @bug This should be called ap_http_scheme!
00287  */
00288 #define ap_http_method(r)       ap_run_http_method(r)
00289 
00290 /** The default string lengths */
00291 #define MAX_STRING_LEN HUGE_STRING_LEN
00292 #define HUGE_STRING_LEN 8192
00293 
00294 /** The size of the server's internal read-write buffers */
00295 #define AP_IOBUFSIZE 8192
00296 
00297 /** The max number of regex captures that can be expanded by ap_pregsub */
00298 #define AP_MAX_REG_MATCH 10
00299 
00300 /**
00301  * APR_HAS_LARGE_FILES introduces the problem of spliting sendfile into 
00302  * mutiple buckets, no greater than MAX(apr_size_t), and more granular 
00303  * than that in case the brigade code/filters attempt to read it directly.
00304  * ### 16mb is an invention, no idea if it is reasonable.
00305  */
00306 #define AP_MAX_SENDFILE 16777216  /* 2^24 */
00307 
00308 /**
00309  * Special Apache error codes. These are basically used
00310  *  in http_main.c so we can keep track of various errors.
00311  *        
00312  */
00313 /** a normal exit */
00314 #define APEXIT_OK               0x0
00315 /** A fatal error arising during the server's init sequence */
00316 #define APEXIT_INIT             0x2
00317 /**  The child died during its init sequence */
00318 #define APEXIT_CHILDINIT        0x3
00319 /**  
00320  *   The child exited due to a resource shortage.
00321  *   The parent should limit the rate of forking until
00322  *   the situation is resolved.
00323  */
00324 #define APEXIT_CHILDSICK        0x7
00325 /** 
00326  *     A fatal error, resulting in the whole server aborting.
00327  *     If a child exits with this error, the parent process
00328  *     considers this a server-wide fatal error and aborts.
00329  */
00330 #define APEXIT_CHILDFATAL       0xf
00331 
00332 #ifndef AP_DECLARE
00333 /**
00334  * Stuff marked #AP_DECLARE is part of the API, and intended for use
00335  * by modules. Its purpose is to allow us to add attributes that
00336  * particular platforms or compilers require to every exported function.
00337  */
00338 # define AP_DECLARE(type)    type
00339 #endif
00340 
00341 #ifndef AP_DECLARE_NONSTD
00342 /**
00343  * Stuff marked #AP_DECLARE_NONSTD is part of the API, and intended for
00344  * use by modules.  The difference between #AP_DECLARE and
00345  * #AP_DECLARE_NONSTD is that the latter is required for any functions
00346  * which use varargs or are used via indirect function call.  This
00347  * is to accomodate the two calling conventions in windows dlls.
00348  */
00349 # define AP_DECLARE_NONSTD(type)    type
00350 #endif
00351 #ifndef AP_DECLARE_DATA
00352 # define AP_DECLARE_DATA
00353 #endif
00354 
00355 #ifndef AP_MODULE_DECLARE
00356 # define AP_MODULE_DECLARE(type)    type
00357 #endif
00358 #ifndef AP_MODULE_DECLARE_NONSTD
00359 # define AP_MODULE_DECLARE_NONSTD(type)  type
00360 #endif
00361 #ifndef AP_MODULE_DECLARE_DATA
00362 # define AP_MODULE_DECLARE_DATA
00363 #endif
00364 
00365 /**
00366  * @internal
00367  * modules should not used functions marked AP_CORE_DECLARE
00368  */
00369 #ifndef AP_CORE_DECLARE
00370 # define AP_CORE_DECLARE        AP_DECLARE
00371 #endif
00372 /**
00373  * @internal
00374  * modules should not used functions marked AP_CORE_DECLARE_NONSTD
00375  */
00376 
00377 #ifndef AP_CORE_DECLARE_NONSTD
00378 # define AP_CORE_DECLARE_NONSTD AP_DECLARE_NONSTD
00379 #endif
00380 
00381 /**
00382  * Get the server version string
00383  * @return The server version string
00384  */
00385 AP_DECLARE(const char *) ap_get_server_version(void);
00386 
00387 /**
00388  * Add a component to the version string
00389  * @param pconf The pool to allocate the component from
00390  * @param component The string to add
00391  */
00392 AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char *component);
00393 
00394 /**
00395  * Get the date a time that the server was built
00396  * @return The server build time string
00397  */
00398 AP_DECLARE(const char *) ap_get_server_built(void);
00399 
00400 #define DECLINED -1             /**< Module declines to handle */
00401 #define DONE -2                 /**< Module has served the response completely 
00402                                  *  - it's safe to die() with no more output
00403                                  */
00404 #define OK 0                    /**< Module has handled this stage. */
00405 
00406 
00407 /**
00408  * @defgroup HTTP_Status HTTP Status Codes
00409  * @{
00410  */
00411 /**
00412  * The size of the static array in http_protocol.c for storing
00413  * all of the potential response status-lines (a sparse table).
00414  * A future version should dynamically generate the apr_table_t at startup.
00415  */
00416 #define RESPONSE_CODES 57
00417 
00418 #define HTTP_CONTINUE                      100
00419 #define HTTP_SWITCHING_PROTOCOLS           101
00420 #define HTTP_PROCESSING                    102
00421 #define HTTP_OK                            200
00422 #define HTTP_CREATED                       201
00423 #define HTTP_ACCEPTED                      202
00424 #define HTTP_NON_AUTHORITATIVE             203
00425 #define HTTP_NO_CONTENT                    204
00426 #define HTTP_RESET_CONTENT                 205
00427 #define HTTP_PARTIAL_CONTENT               206
00428 #define HTTP_MULTI_STATUS                  207
00429 #define HTTP_MULTIPLE_CHOICES              300
00430 #define HTTP_MOVED_PERMANENTLY             301
00431 #define HTTP_MOVED_TEMPORARILY             302
00432 #define HTTP_SEE_OTHER                     303
00433 #define HTTP_NOT_MODIFIED                  304
00434 #define HTTP_USE_PROXY                     305
00435 #define HTTP_TEMPORARY_REDIRECT            307
00436 #define HTTP_BAD_REQUEST                   400
00437 #define HTTP_UNAUTHORIZED                  401
00438 #define HTTP_PAYMENT_REQUIRED              402
00439 #define HTTP_FORBIDDEN                     403
00440 #define HTTP_NOT_FOUND                     404
00441 #define HTTP_METHOD_NOT_ALLOWED            405
00442 #define HTTP_NOT_ACCEPTABLE                406
00443 #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407
00444 #define HTTP_REQUEST_TIME_OUT              408
00445 #define HTTP_CONFLICT                      409
00446 #define HTTP_GONE                          410
00447 #define HTTP_LENGTH_REQUIRED               411
00448 #define HTTP_PRECONDITION_FAILED           412
00449 #define HTTP_REQUEST_ENTITY_TOO_LARGE      413
00450 #define HTTP_REQUEST_URI_TOO_LARGE         414
00451 #define HTTP_UNSUPPORTED_MEDIA_TYPE        415
00452 #define HTTP_RANGE_NOT_SATISFIABLE         416
00453 #define HTTP_EXPECTATION_FAILED            417
00454 #define HTTP_UNPROCESSABLE_ENTITY          422
00455 #define HTTP_LOCKED                        423
00456 #define HTTP_FAILED_DEPENDENCY             424
00457 #define HTTP_UPGRADE_REQUIRED              426
00458 #define HTTP_INTERNAL_SERVER_ERROR         500
00459 #define HTTP_NOT_IMPLEMENTED               501
00460 #define HTTP_BAD_GATEWAY                   502
00461 #define HTTP_SERVICE_UNAVAILABLE           503
00462 #define HTTP_GATEWAY_TIME_OUT              504
00463 #define HTTP_VERSION_NOT_SUPPORTED         505
00464 #define HTTP_VARIANT_ALSO_VARIES           506
00465 #define HTTP_INSUFFICIENT_STORAGE          507
00466 #define HTTP_NOT_EXTENDED                  510
00467 
00468 /** is the status code informational */
00469 #define ap_is_HTTP_INFO(x)         (((x) >= 100)&&((x) < 200))
00470 /** is the status code OK ?*/
00471 #define ap_is_HTTP_SUCCESS(x)      (((x) >= 200)&&((x) < 300))
00472 /** is the status code a redirect */
00473 #define ap_is_HTTP_REDIRECT(x)     (((x) >= 300)&&((x) < 400))
00474 /** is the status code a error (client or server) */
00475 #define ap_is_HTTP_ERROR(x)        (((x) >= 400)&&((x) < 600))
00476 /** is the status code a client error  */
00477 #define ap_is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500))
00478 /** is the status code a server error  */
00479 #define ap_is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600))
00480 
00481 /** should the status code drop the connection */
00482 #define ap_status_drops_connection(x) \
00483                                    (((x) == HTTP_BAD_REQUEST)           || \
00484                                     ((x) == HTTP_REQUEST_TIME_OUT)      || \
00485                                     ((x) == HTTP_LENGTH_REQUIRED)       || \
00486                                     ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
00487                                     ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
00488                                     ((x) == HTTP_INTERNAL_SERVER_ERROR) || \
00489                                     ((x) == HTTP_SERVICE_UNAVAILABLE) || \
00490                                     ((x) == HTTP_NOT_IMPLEMENTED))
00491 /** @} */
00492 /**
00493  * @defgroup Methods List of Methods recognized by the server
00494  * @{
00495  */
00496 /**
00497  * Methods recognized (but not necessarily handled) by the server.
00498  * These constants are used in bit shifting masks of size int, so it is
00499  * unsafe to have more methods than bits in an int.  HEAD == M_GET.
00500  * This list must be tracked by the list in http_protocol.c in routine
00501  * ap_method_name_of().
00502  */
00503 #define M_GET                   0       /* RFC 2616: HTTP */
00504 #define M_PUT                   1       /*  :             */
00505 #define M_POST                  2
00506 #define M_DELETE                3
00507 #define M_CONNECT               4
00508 #define M_OPTIONS               5
00509 #define M_TRACE                 6       /* RFC 2616: HTTP */
00510 #define M_PATCH                 7       /* no rfc(!)  ### remove this one? */
00511 #define M_PROPFIND              8       /* RFC 2518: WebDAV */
00512 #define M_PROPPATCH             9       /*  :               */
00513 #define M_MKCOL                 10
00514 #define M_COPY                  11
00515 #define M_MOVE                  12
00516 #define M_LOCK                  13
00517 #define M_UNLOCK                14      /* RFC 2518: WebDAV */
00518 #define M_VERSION_CONTROL       15      /* RFC 3253: WebDAV Versioning */
00519 #define M_CHECKOUT              16      /*  :                          */
00520 #define M_UNCHECKOUT            17
00521 #define M_CHECKIN               18
00522 #define M_UPDATE                19
00523 #define M_LABEL                 20
00524 #define M_REPORT                21
00525 #define M_MKWORKSPACE           22
00526 #define M_MKACTIVITY            23
00527 #define M_BASELINE_CONTROL      24
00528 #define M_MERGE                 25
00529 #define M_INVALID               26      /* RFC 3253: WebDAV Versioning */
00530 
00531 /**
00532  * METHODS needs to be equal to the number of bits
00533  * we are using for limit masks.
00534  */
00535 #define METHODS     64
00536 
00537 /**
00538  * The method mask bit to shift for anding with a bitmask.
00539  */
00540 #define AP_METHOD_BIT ((apr_int64_t)1)
00541 /** @} */
00542 
00543 
00544 /**
00545  * Structure for handling HTTP methods.  Methods known to the server are
00546  * accessed via a bitmask shortcut; extension methods are handled by
00547  * an array.
00548  */
00549 typedef struct ap_method_list_t ap_method_list_t;
00550 struct ap_method_list_t {
00551     /* The bitmask used for known methods */
00552     apr_int64_t method_mask;
00553     /* the array used for extension methods */
00554     apr_array_header_t *method_list;
00555 };
00556 /**
00557  * @defgroup module_magic Module Magic mime types
00558  * @{
00559  */
00560 /** Magic for mod_cgi[d] */
00561 #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
00562 /** Magic for mod_include */
00563 #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
00564 /** Magic for mod_include */
00565 #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
00566 /** Magic for mod_dir */
00567 #define DIR_MAGIC_TYPE "httpd/unix-directory"
00568 
00569 /** @} */
00570 /* Just in case your linefeed isn't the one the other end is expecting. */
00571 #if !APR_CHARSET_EBCDIC
00572 /** linefeed */
00573 #define LF 10
00574 /** carrige return */
00575 #define CR 13
00576 /** carrige return /Line Feed Combo */
00577 #define CRLF "\015\012"
00578 #else /* APR_CHARSET_EBCDIC */
00579 /* For platforms using the EBCDIC charset, the transition ASCII->EBCDIC is done
00580  * in the buff package (bread/bputs/bwrite).  Everywhere else, we use
00581  * "native EBCDIC" CR and NL characters. These are therefore
00582  * defined as
00583  * '\r' and '\n'.
00584  */
00585 #define CR '\r'
00586 #define LF '\n'
00587 #define CRLF "\r\n"
00588 #endif /* APR_CHARSET_EBCDIC */                                   
00589 
00590 /**
00591  * @defgroup values_request_rec_body Possible values for request_rec.read_body 
00592  * @{
00593  * Possible values for request_rec.read_body (set by handling module):
00594  */
00595 
00596 /** Send 413 error if message has any body */
00597 #define REQUEST_NO_BODY          0
00598 /** Send 411 error if body without Content-Length */
00599 #define REQUEST_CHUNKED_ERROR    1
00600 /** If chunked, remove the chunks for me. */
00601 #define REQUEST_CHUNKED_DECHUNK  2
00602 /** @} */
00603 
00604 /**
00605  * @defgroup values_request_rec_used_path_info Possible values for request_rec.used_path_info 
00606  * @{
00607  * Possible values for request_rec.used_path_info:
00608  */
00609 
00610 /** Accept the path_info from the request */
00611 #define AP_REQ_ACCEPT_PATH_INFO    0
00612 /** Return a 404 error if path_info was given */
00613 #define AP_REQ_REJECT_PATH_INFO    1
00614 /** Module may chose to use the given path_info */
00615 #define AP_REQ_DEFAULT_PATH_INFO   2
00616 /** @} */
00617 
00618 /*
00619  * Things which may vary per file-lookup WITHIN a request ---
00620  * e.g., state of MIME config.  Basically, the name of an object, info
00621  * about the object, and any other info we may ahve which may need to
00622  * change as we go poking around looking for it (e.g., overridden by
00623  * .htaccess files).
00624  *
00625  * Note how the default state of almost all these things is properly
00626  * zero, so that allocating it with pcalloc does the right thing without
00627  * a whole lot of hairy initialization... so long as we are willing to
00628  * make the (fairly) portable assumption that the bit pattern of a NULL
00629  * pointer is, in fact, zero.
00630  */
00631 
00632 /**
00633  * This represents the result of calling htaccess; these are cached for
00634  * each request.
00635  */
00636 struct htaccess_result {
00637     /** the directory to which this applies */
00638     const char *dir;
00639     /** the overrides allowed for the .htaccess file */
00640     int override;
00641     /** the configuration directives */
00642     struct ap_conf_vector_t *htaccess;
00643     /** the next one, or NULL if no more; N.B. never change this */
00644     const struct htaccess_result *next;
00645 };
00646 
00647 /* The following four types define a hierarchy of activities, so that
00648  * given a request_rec r you can write r->connection->server->process
00649  * to get to the process_rec.  While this reduces substantially the
00650  * number of arguments that various hooks require beware that in
00651  * threaded versions of the server you must consider multiplexing
00652  * issues.  */
00653 
00654 
00655 /** A structure that represents one process */
00656 typedef struct process_rec process_rec;
00657 /** A structure that represents a virtual server */
00658 typedef struct server_rec server_rec;
00659 /** A structure that represents one connection */
00660 typedef struct conn_rec conn_rec;
00661 /** A structure that represents the current request */
00662 typedef struct request_rec request_rec;
00663 
00664 /* ### would be nice to not include this from httpd.h ... */
00665 /* This comes after we have defined the request_rec type */
00666 #include "apr_uri.h"
00667 
00668 /** A structure that represents one process */
00669 struct process_rec {
00670     /** Global pool. Cleared upon normal exit */
00671     apr_pool_t *pool;
00672     /** Configuration pool. Cleared upon restart */
00673     apr_pool_t *pconf;
00674     /** Number of command line arguments passed to the program */
00675     int argc;
00676     /** The command line arguments */
00677     const char * const *argv;
00678     /** The program name used to execute the program */
00679     const char *short_name;
00680 };
00681 
00682 /** A structure that represents the current request */
00683 struct request_rec {
00684     /** The pool associated with the request */
00685     apr_pool_t *pool;
00686     /** The connection to the client */
00687     conn_rec *connection;
00688     /** The virtual host for this request */
00689     server_rec *server;
00690 
00691     /** Pointer to the redirected request if this is an external redirect */
00692     request_rec *next;
00693     /** Pointer to the previous request if this is an internal redirect */
00694     request_rec *prev;
00695 
00696     /** Pointer to the main request if this is a sub-request
00697      * (see http_request.h) */
00698     request_rec *main;
00699 
00700     /* Info about the request itself... we begin with stuff that only
00701      * protocol.c should ever touch...
00702      */
00703     /** First line of request */
00704     char *the_request;
00705     /** HTTP/0.9, "simple" request (e.g. GET /foo\n w/no headers) */
00706     int assbackwards;
00707     /** A proxy request (calculated during post_read_request/translate_name)
00708      *  possible values PROXYREQ_NONE, PROXYREQ_PROXY, PROXYREQ_REVERSE,
00709      *                  PROXYREQ_RESPONSE
00710      */
00711     int proxyreq;
00712     /** HEAD request, as opposed to GET */
00713     int header_only;
00714     /** Protocol string, as given to us, or HTTP/0.9 */
00715     char *protocol;
00716     /** Protocol version number of protocol; 1.1 = 1001 */
00717     int proto_num;
00718     /** Host, as set by full URI or Host: */
00719     const char *hostname;
00720 
00721     /** Time when the request started */
00722     apr_time_t request_time;
00723 
00724     /** Status line, if set by script */
00725     const char *status_line;
00726     /** Status line */
00727     int status;
00728 
00729     /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
00730      * look, but don't touch.
00731      */
00732 
00733     /** Request method (eg. GET, HEAD, POST, etc.) */
00734     const char *method;
00735     /** M_GET, M_POST, etc. */
00736     int method_number;
00737 
00738     /**
00739      *  'allowed' is a bitvector of the allowed methods.
00740      *
00741      *  A handler must ensure that the request method is one that
00742      *  it is capable of handling.  Generally modules should DECLINE
00743      *  any request methods they do not handle.  Prior to aborting the
00744      *  handler like this the handler should set r->allowed to the list
00745      *  of methods that it is willing to handle.  This bitvector is used
00746      *  to construct the "Allow:" header required for OPTIONS requests,
00747      *  and HTTP_METHOD_NOT_ALLOWED and HTTP_NOT_IMPLEMENTED status codes.
00748      *
00749      *  Since the default_handler deals with OPTIONS, all modules can
00750      *  usually decline to deal with OPTIONS.  TRACE is always allowed,
00751      *  modules don't need to set it explicitly.
00752      *
00753      *  Since the default_handler will always handle a GET, a
00754      *  module which does *not* implement GET should probably return
00755      *  HTTP_METHOD_NOT_ALLOWED.  Unfortunately this means that a Script GET
00756      *  handler can't be installed by mod_actions.
00757      */
00758     apr_int64_t allowed;
00759     /** Array of extension methods */
00760     apr_array_header_t *allowed_xmethods; 
00761     /** List of allowed methods */
00762     ap_method_list_t *allowed_methods; 
00763 
00764     /** byte count in stream is for body */
00765     apr_off_t sent_bodyct;
00766     /** body byte count, for easy access */
00767     apr_off_t bytes_sent;
00768     /** Last modified time of the requested resource */
00769     apr_time_t mtime;
00770 
00771     /* HTTP/1.1 connection-level features */
00772 
00773     /** sending chunked transfer-coding */
00774     int chunked;
00775     /** The Range: header */
00776     const char *range;
00777     /** The "real" content length */
00778     apr_off_t clength;
00779 
00780     /** Remaining bytes left to read from the request body */
00781     apr_off_t remaining;
00782     /** Number of bytes that have been read  from the request body */
00783     apr_off_t read_length;
00784     /** Method for reading the request body
00785      * (eg. REQUEST_CHUNKED_ERROR, REQUEST_NO_BODY,
00786      *  REQUEST_CHUNKED_DECHUNK, etc...) */
00787     int read_body;
00788     /** reading chunked transfer-coding */
00789     int read_chunked;
00790     /** is client waiting for a 100 response? */
00791     unsigned expecting_100;
00792 
00793     /* MIME header environments, in and out.  Also, an array containing
00794      * environment variables to be passed to subprocesses, so people can
00795      * write modules to add to that environment.
00796      *
00797      * The difference between headers_out and err_headers_out is that the
00798      * latter are printed even on error, and persist across internal redirects
00799      * (so the headers printed for ErrorDocument handlers will have them).
00800      *
00801      * The 'notes' apr_table_t is for notes from one module to another, with no
00802      * other set purpose in mind...
00803      */
00804 
00805     /** MIME header environment from the request */
00806     apr_table_t *headers_in;
00807     /** MIME header environment for the response */
00808     apr_table_t *headers_out;
00809     /** MIME header environment for the response, printed even on errors and
00810      * persist across internal redirects */
00811     apr_table_t *err_headers_out;
00812     /** Array of environment variables to be used for sub processes */
00813     apr_table_t *subprocess_env;
00814     /** Notes from one module to another */
00815     apr_table_t *notes;
00816 
00817     /* content_type, handler, content_encoding, and all content_languages 
00818      * MUST be lowercased strings.  They may be pointers to static strings;
00819      * they should not be modified in place.
00820      */
00821     /** The content-type for the current request */
00822     const char *content_type;   /* Break these out --- we dispatch on 'em */
00823     /** The handler string that we use to call a handler function */
00824     const char *handler;        /* What we *really* dispatch on */
00825 
00826     /** How to encode the data */
00827     const char *content_encoding;
00828     /** Array of strings representing the content languages */
00829     apr_array_header_t *content_languages;
00830 
00831     /** variant list validator (if negotiated) */
00832     char *vlist_validator;
00833     
00834     /** If an authentication check was made, this gets set to the user name. */
00835     char *user; 
00836     /** If an authentication check was made, this gets set to the auth type. */
00837     char *ap_auth_type;
00838 
00839     /** This response can not be cached */
00840     int no_cache;
00841     /** There is no local copy of this response */
00842     int no_local_copy;
00843 
00844     /* What object is being requested (either directly, or via include
00845      * or content-negotiation mapping).
00846      */
00847 
00848     /** The URI without any parsing performed */
00849     char *unparsed_uri; 
00850     /** The path portion of the URI */
00851     char *uri;
00852     /** The filename on disk corresponding to this response */
00853     char *filename;
00854     /* XXX: What does this mean? Please define "canonicalize" -aaron */
00855     /** The true filename, we canonicalize r->filename if these don't match */
00856     char *canonical_filename;
00857     /** The PATH_INFO extracted from this request */
00858     char *path_info;
00859     /** The QUERY_ARGS extracted from this request */
00860     char *args; 
00861     /**  finfo.protection (st_mode) set to zero if no such file */
00862     apr_finfo_t finfo;
00863     /** A struct containing the components of URI */
00864     apr_uri_t parsed_uri;
00865 
00866     /**
00867      * Flag for the handler to accept or reject path_info on 
00868      * the current request.  All modules should respect the
00869      * AP_REQ_ACCEPT_PATH_INFO and AP_REQ_REJECT_PATH_INFO 
00870      * values, while AP_REQ_DEFAULT_PATH_INFO indicates they
00871      * may follow existing conventions.  This is set to the
00872      * user's preference upon HOOK_VERY_FIRST of the fixups.
00873      */
00874     int used_path_info;
00875 
00876     /* Various other config info which may change with .htaccess files
00877      * These are config vectors, with one void* pointer for each module
00878      * (the thing pointed to being the module's business).
00879      */
00880 
00881     /** Options set in config files, etc. */
00882     struct ap_conf_vector_t *per_dir_config;
00883     /** Notes on *this* request */
00884     struct ap_conf_vector_t *request_config;
00885 
00886     /**
00887      * A linked list of the .htaccess configuration directives
00888      * accessed by this request.
00889      * N.B. always add to the head of the list, _never_ to the end.
00890      * that way, a sub request's list can (temporarily) point to a parent's list
00891      */
00892     const struct htaccess_result *htaccess;
00893 
00894     /** A list of output filters to be used for this request */
00895     struct ap_filter_t *output_filters;
00896     /** A list of input filters to be used for this request */
00897     struct ap_filter_t *input_filters;
00898 
00899     /** A list of protocol level output filters to be used for this
00900      *  request */
00901     struct ap_filter_t *proto_output_filters;
00902     /** A list of protocol level input filters to be used for this
00903      *  request */
00904     struct ap_filter_t *proto_input_filters;
00905 
00906     /** A flag to determine if the eos bucket has been sent yet */
00907     int eos_sent;
00908 
00909 /* Things placed at the end of the record to avoid breaking binary
00910  * compatibility.  It would be nice to remember to reorder the entire
00911  * record to improve 64bit alignment the next time we need to break
00912  * binary compatibility for some other reason.
00913  */
00914 };
00915 
00916 /**
00917  * @defgroup ProxyReq Proxy request types
00918  *
00919  * Possible values of request_rec->proxyreq. A request could be normal,
00920  *  proxied or reverse proxied. Normally proxied and reverse proxied are
00921  *  grouped together as just "proxied", but sometimes it's necessary to
00922  *  tell the difference between the two, such as for authentication.
00923  * @{
00924  */
00925 
00926 #define PROXYREQ_NONE 0         /**< No proxy */
00927 #define PROXYREQ_PROXY 1        /**< Standard proxy */
00928 #define PROXYREQ_REVERSE 2      /**< Reverse proxy */
00929 #define PROXYREQ_RESPONSE 3 /**< Origin response */
00930 
00931 /* @} */
00932 
00933 typedef enum {
00934     AP_CONN_UNKNOWN,
00935     AP_CONN_CLOSE,
00936     AP_CONN_KEEPALIVE
00937 } ap_conn_keepalive_e;
00938 
00939 /** Structure to store things which are per connection */
00940 struct conn_rec {
00941     /** Pool associated with this connection */
00942     apr_pool_t *pool;
00943     /** Physical vhost this conn came in on */
00944     server_rec *base_server;
00945     /** used by http_vhost.c */
00946     void *vhost_lookup_data;
00947 
00948     /* Information about the connection itself */
00949     /** local address */
00950     apr_sockaddr_t *local_addr;
00951     /** remote address */
00952     apr_sockaddr_t *remote_addr;
00953 
00954     /** Client's IP address */
00955     char *remote_ip;
00956     /** Client's DNS name, if known.  NULL if DNS hasn't been checked,
00957      *  "" if it has and no address was found.  N.B. Only access this though
00958      * get_remote_host() */
00959     char *remote_host;
00960     /** Only ever set if doing rfc1413 lookups.  N.B. Only access this through
00961      *  get_remote_logname() */
00962     char *remote_logname;
00963 
00964     /** Are we still talking? */
00965     unsigned aborted:1;
00966 
00967     /** Are we going to keep the connection alive for another request?
00968      * @see ap_conn_keepalive_e */
00969     ap_conn_keepalive_e keepalive;
00970 
00971     /** have we done double-reverse DNS? -1 yes/failure, 0 not yet, 
00972      *  1 yes/success */
00973     signed int double_reverse:2;
00974 
00975     /** How many times have we used it? */
00976     int keepalives;
00977     /** server IP address */
00978     char *local_ip;
00979     /** used for ap_get_server_name when UseCanonicalName is set to DNS
00980      *  (ignores setting of HostnameLookups) */
00981     char *local_host;
00982 
00983     /** ID of this connection; unique at any point in time */
00984     long id; 
00985     /** Config vector containing pointers to connections per-server
00986      *  config structures. */
00987     struct ap_conf_vector_t *conn_config;
00988     /** Notes on *this* connection: send note from one module to
00989      *  another. must remain valid for all requests on this conn */
00990     apr_table_t *notes;
00991     /** A list of input filters to be used for this connection */
00992     struct ap_filter_t *input_filters;
00993     /** A list of output filters to be used for this connection */
00994     struct ap_filter_t *output_filters;
00995     /** handle to scoreboard information for this connection */
00996     void *sbh;
00997     /** The bucket allocator to use for all bucket/brigade creations */
00998     struct apr_bucket_alloc_t *bucket_alloc;
00999 };
01000 
01001 /* Per-vhost config... */
01002 
01003 /**
01004  * The address 255.255.255.255, when used as a virtualhost address,
01005  * will become the "default" server when the ip doesn't match other vhosts.
01006  */
01007 #define DEFAULT_VHOST_ADDR 0xfffffffful
01008 
01009 
01010 /** A structure to be used for Per-vhost config */
01011 typedef struct server_addr_rec server_addr_rec;
01012 struct server_addr_rec {
01013     /** The next server in the list */
01014     server_addr_rec *next;
01015     /** The bound address, for this server */
01016     apr_sockaddr_t *host_addr;
01017     /** The bound port, for this server */
01018     apr_port_t host_port;
01019     /** The name given in <VirtualHost> */
01020     char *virthost;
01021 };
01022 
01023 /** A structure to store information for each virtual server */
01024 struct server_rec {
01025     /** The process this server is running in */
01026     process_rec *process;
01027     /** The next server in the list */
01028     server_rec *next;
01029 
01030     /** The name of the server */
01031     const char *defn_name;
01032     /** The line of the config file that the server was defined on */
01033     unsigned defn_line_number;
01034 
01035     /* Contact information */
01036 
01037     /** The admin's contact information */
01038     char *server_admin;
01039     /** The server hostname */
01040     char *server_hostname;
01041     /** for redirects, etc. */
01042     apr_port_t port;
01043 
01044     /* Log files --- note that transfer log is now in the modules... */
01045 
01046     /** The name of the error log */
01047     char *error_fname;
01048     /** A file descriptor that references the error log */
01049     apr_file_t *error_log;
01050     /** The log level for this server */
01051     int loglevel;
01052 
01053     /* Module-specific configuration for server, and defaults... */
01054 
01055     /** true if this is the virtual server */
01056     int is_virtual;
01057     /** Config vector containing pointers to modules' per-server config 
01058      *  structures. */
01059     struct ap_conf_vector_t *module_config; 
01060     /** MIME type info, etc., before we start checking per-directory info */
01061     struct ap_conf_vector_t *lookup_defaults;
01062 
01063     /* Transaction handling */
01064 
01065     /** I haven't got a clue */
01066     server_addr_rec *addrs;
01067     /** Timeout, as an apr interval, before we give up */
01068     apr_interval_time_t timeout;
01069     /** The apr interval we will wait for another request */
01070     apr_interval_time_t keep_alive_timeout;
01071     /** Maximum requests per connection */
01072     int keep_alive_max;
01073     /** Use persistent connections? */
01074     int keep_alive;
01075 
01076     /** Pathname for ServerPath */
01077     const char *path;
01078     /** Length of path */
01079     int pathlen;
01080 
01081     /** Normal names for ServerAlias servers */
01082     apr_array_header_t *names;
01083     /** Wildcarded names for ServerAlias servers */
01084     apr_array_header_t *wild_names;
01085 
01086     /** limit on size of the HTTP request line    */
01087     int limit_req_line;
01088     /** limit on size of any request header field */
01089     int limit_req_fieldsize;
01090     /** limit on number of request header fields  */
01091     int limit_req_fields; 
01092 };
01093 
01094 typedef struct core_output_filter_ctx {
01095     apr_bucket_brigade *b;
01096     apr_pool_t *deferred_write_pool; /* subpool of c->pool used for resources 
01097                                       * which may outlive the request
01098                                       */
01099 } core_output_filter_ctx_t;
01100  
01101 typedef struct core_filter_ctx {
01102     apr_bucket_brigade *b;
01103     apr_bucket_brigade *tmpbb;
01104 } core_ctx_t;
01105  
01106 typedef struct core_net_rec {
01107     /** Connection to the client */
01108     apr_socket_t *client_socket;
01109 
01110     /** connection record */
01111     conn_rec *c;
01112  
01113     core_output_filter_ctx_t *out_ctx;
01114     core_ctx_t *in_ctx;
01115 } core_net_rec;
01116 
01117 /**
01118  * Examine a field value (such as a media-/content-type) string and return
01119  * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
01120  * @param p Pool to allocate memory from
01121  * @param intype The field to examine
01122  * @return A copy of the field minus any parameters
01123  */
01124 AP_DECLARE(char *) ap_field_noparam(apr_pool_t *p, const char *intype);
01125 
01126 /**
01127  * Convert a time from an integer into a string in a specified format
01128  * @param p The pool to allocate memory from
01129  * @param t The time to convert
01130  * @param fmt The format to use for the conversion
01131  * @param gmt Convert the time for GMT?
01132  * @return The string that represents the specified time
01133  */
01134 AP_DECLARE(char *) ap_ht_time(apr_pool_t *p, apr_time_t t, const char *fmt, int gmt);
01135 
01136 /* String handling. The *_nc variants allow you to use non-const char **s as
01137    arguments (unfortunately C won't automatically convert a char ** to a const
01138    char **) */
01139 
01140 /**
01141  * Get the characters until the first occurance of a specified character
01142  * @param p The pool to allocate memory from
01143  * @param line The string to get the characters from
01144  * @param stop The character to stop at
01145  * @return A copy of the characters up to the first stop character
01146  */
01147 AP_DECLARE(char *) ap_getword(apr_pool_t *p, const char **line, char stop);
01148 /**
01149  * Get the characters until the first occurance of a specified character
01150  * @param p The pool to allocate memory from
01151  * @param line The string to get the characters from
01152  * @param stop The character to stop at
01153  * @return A copy of the characters up to the first stop character
01154  * @note This is the same as ap_getword(), except it doesn't use const char **.
01155  */
01156 AP_DECLARE(char *) ap_getword_nc(apr_pool_t *p, char **line, char stop);
01157 
01158