1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @brief HTTP Daemon routines
21 * @defgroup APACHE Apache
23 * Top level group of which all other groups are a member
26 * @defgroup APACHE_MODS Apache Modules
27 * Top level group for Apache Modules
28 * @defgroup APACHE_OS Operating System Specific
29 * @defgroup APACHE_CORE Apache Core
31 * @defgroup APACHE_CORE_DAEMON HTTP Daemon Routine
35 #ifndef APACHE_HTTPD_H
36 #define APACHE_HTTPD_H
38 /* XXX - We need to push more stuff to other .h files, or even .c files, to
39 * make this file smaller
42 /* Headers in which EVERYONE has an interest... */
43 #include "ap_config.h"
46 #include "ap_release.h"
49 #include "apr_general.h"
50 #include "apr_tables.h"
51 #include "apr_pools.h"
53 #include "apr_network_io.h"
54 #include "apr_buckets.h"
56 #include "apr_thread_proc.h"
66 /* Note: apr_uri.h is also included, see below */
72 /* ----------------------------- config dir ------------------------------ */
74 /** Define this to be the default server home dir. Most things later in this
75 * file with a relative pathname will have this added.
79 /** Set default for OS/2 file system */
80 #define HTTPD_ROOT "/os2httpd"
82 /** Set default for Windows file system */
83 #define HTTPD_ROOT "/apache"
85 /** Set the default for BeOS */
86 #define HTTPD_ROOT "/boot/home/apache"
87 #elif defined (NETWARE)
88 /** Set the default for NetWare */
89 #define HTTPD_ROOT "/apache"
91 /** Set for all other OSs */
92 #define HTTPD_ROOT "/usr/local/apache"
94 #endif /* HTTPD_ROOT */
97 * --------- You shouldn't have to edit anything below this line ----------
99 * Any modifications to any defaults not defined above should be done in the
100 * respective configuration file.
105 * Default location of documents. Can be overridden by the DocumentRoot
108 #ifndef DOCUMENT_LOCATION
110 /* Set default for OS/2 file system */
111 #define DOCUMENT_LOCATION HTTPD_ROOT "/docs"
113 /* Set default for non OS/2 file system */
114 #define DOCUMENT_LOCATION HTTPD_ROOT "/htdocs"
116 #endif /* DOCUMENT_LOCATION */
118 /** Maximum number of dynamically loaded modules */
119 #ifndef DYNAMIC_MODULE_LIMIT
120 #define DYNAMIC_MODULE_LIMIT 128
123 /** Default administrator's address */
124 #define DEFAULT_ADMIN "[no address given]"
126 /** The name of the log files */
127 #ifndef DEFAULT_ERRORLOG
128 #if defined(OS2) || defined(WIN32)
129 #define DEFAULT_ERRORLOG "logs/error.log"
131 #define DEFAULT_ERRORLOG "logs/error_log"
133 #endif /* DEFAULT_ERRORLOG */
135 /** Define this to be what your per-directory security files are called */
136 #ifndef DEFAULT_ACCESS_FNAME
138 /* Set default for OS/2 file system */
139 #define DEFAULT_ACCESS_FNAME "htaccess"
141 #define DEFAULT_ACCESS_FNAME ".htaccess"
143 #endif /* DEFAULT_ACCESS_FNAME */
145 /** The name of the server config file */
146 #ifndef SERVER_CONFIG_FILE
147 #define SERVER_CONFIG_FILE "conf/httpd.conf"
150 /** The default path for CGI scripts if none is currently set */
152 #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
155 /** The path to the suExec wrapper, can be overridden in Configuration */
157 #define SUEXEC_BIN HTTPD_ROOT "/bin/suexec"
160 /** The timeout for waiting for messages */
161 #ifndef DEFAULT_TIMEOUT
162 #define DEFAULT_TIMEOUT 300
165 /** The timeout for waiting for keepalive timeout until next request */
166 #ifndef DEFAULT_KEEPALIVE_TIMEOUT
167 #define DEFAULT_KEEPALIVE_TIMEOUT 5
170 /** The number of requests to entertain per connection */
171 #ifndef DEFAULT_KEEPALIVE
172 #define DEFAULT_KEEPALIVE 100
176 * Limits on the size of various request items. These limits primarily
177 * exist to prevent simple denial-of-service attacks on a server based
178 * on misuse of the protocol. The recommended values will depend on the
179 * nature of the server resources -- CGI scripts and database backends
180 * might require large values, but most servers could get by with much
181 * smaller limits than we use below. The request message body size can
182 * be limited by the per-dir config directive LimitRequestBody.
184 * Internal buffer sizes are two bytes more than the DEFAULT_LIMIT_REQUEST_LINE
185 * and DEFAULT_LIMIT_REQUEST_FIELDSIZE below, which explains the 8190.
186 * These two limits can be lowered (but not raised) by the server config
187 * directives LimitRequestLine and LimitRequestFieldsize, respectively.
189 * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
190 * the server config directive LimitRequestFields.
193 /** default limit on bytes in Request-Line (Method+URI+HTTP-version) */
194 #ifndef DEFAULT_LIMIT_REQUEST_LINE
195 #define DEFAULT_LIMIT_REQUEST_LINE 8190
197 /** default limit on bytes in any one header field */
198 #ifndef DEFAULT_LIMIT_REQUEST_FIELDSIZE
199 #define DEFAULT_LIMIT_REQUEST_FIELDSIZE 8190
201 /** default limit on number of request header fields */
202 #ifndef DEFAULT_LIMIT_REQUEST_FIELDS
203 #define DEFAULT_LIMIT_REQUEST_FIELDS 100
207 * The default default character set name to add if AddDefaultCharset is
208 * enabled. Overridden with AddDefaultCharsetName.
210 #define DEFAULT_ADD_DEFAULT_CHARSET_NAME "iso-8859-1"
212 /** default HTTP Server protocol */
213 #define AP_SERVER_PROTOCOL "HTTP/1.1"
216 /* ------------------ stuff that modules are allowed to look at ----------- */
218 /** Define this to be what your HTML directory content files are called */
219 #ifndef AP_DEFAULT_INDEX
220 #define AP_DEFAULT_INDEX "index.html"
223 /** The name of the MIME types file */
224 #ifndef AP_TYPES_CONFIG_FILE
225 #define AP_TYPES_CONFIG_FILE "conf/mime.types"
229 * Define the HTML doctype strings centrally.
231 /** HTML 2.0 Doctype */
232 #define DOCTYPE_HTML_2_0 "<!DOCTYPE HTML PUBLIC \"-//IETF//" \
233 "DTD HTML 2.0//EN\">\n"
234 /** HTML 3.2 Doctype */
235 #define DOCTYPE_HTML_3_2 "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
236 "DTD HTML 3.2 Final//EN\">\n"
237 /** HTML 4.0 Strict Doctype */
238 #define DOCTYPE_HTML_4_0S "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
239 "DTD HTML 4.0//EN\"\n" \
240 "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
241 /** HTML 4.0 Transitional Doctype */
242 #define DOCTYPE_HTML_4_0T "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
243 "DTD HTML 4.0 Transitional//EN\"\n" \
244 "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"
245 /** HTML 4.0 Frameset Doctype */
246 #define DOCTYPE_HTML_4_0F "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
247 "DTD HTML 4.0 Frameset//EN\"\n" \
248 "\"http://www.w3.org/TR/REC-html40/frameset.dtd\">\n"
249 /** XHTML 1.0 Strict Doctype */
250 #define DOCTYPE_XHTML_1_0S "<!DOCTYPE html PUBLIC \"-//W3C//" \
251 "DTD XHTML 1.0 Strict//EN\"\n" \
252 "\"http://www.w3.org/TR/xhtml1/DTD/" \
253 "xhtml1-strict.dtd\">\n"
254 /** XHTML 1.0 Transitional Doctype */
255 #define DOCTYPE_XHTML_1_0T "<!DOCTYPE html PUBLIC \"-//W3C//" \
256 "DTD XHTML 1.0 Transitional//EN\"\n" \
257 "\"http://www.w3.org/TR/xhtml1/DTD/" \
258 "xhtml1-transitional.dtd\">\n"
259 /** XHTML 1.0 Frameset Doctype */
260 #define DOCTYPE_XHTML_1_0F "<!DOCTYPE html PUBLIC \"-//W3C//" \
261 "DTD XHTML 1.0 Frameset//EN\"\n" \
262 "\"http://www.w3.org/TR/xhtml1/DTD/" \
263 "xhtml1-frameset.dtd\">"
265 /** Internal representation for a HTTP protocol number, e.g., HTTP/1.1 */
266 #define HTTP_VERSION(major,minor) (1000*(major)+(minor))
267 /** Major part of HTTP protocol */
268 #define HTTP_VERSION_MAJOR(number) ((number)/1000)
269 /** Minor part of HTTP protocol */
270 #define HTTP_VERSION_MINOR(number) ((number)%1000)
272 /* -------------- Port number for server running standalone --------------- */
274 /** default HTTP Port */
275 #define DEFAULT_HTTP_PORT 80
276 /** default HTTPS Port */
277 #define DEFAULT_HTTPS_PORT 443
279 * Check whether @a port is the default port for the request @a r.
280 * @param port The port number
281 * @param r The request
282 * @see #ap_default_port
284 #define ap_is_default_port(port,r) ((port) == ap_default_port(r))
286 * Get the default port for a request (which depends on the scheme).
287 * @param r The request
289 #define ap_default_port(r) ap_run_default_port(r)
291 * Get the scheme for a request.
292 * @param r The request
294 #define ap_http_scheme(r) ap_run_http_scheme(r)
296 /** The default string length */
297 #define MAX_STRING_LEN HUGE_STRING_LEN
299 /** The length of a Huge string */
300 #define HUGE_STRING_LEN 8192
302 /** The size of the server's internal read-write buffers */
303 #define AP_IOBUFSIZE 8192
305 /** The max number of regex captures that can be expanded by ap_pregsub */
306 #define AP_MAX_REG_MATCH 10
309 * APR_HAS_LARGE_FILES introduces the problem of spliting sendfile into
310 * mutiple buckets, no greater than MAX(apr_size_t), and more granular
311 * than that in case the brigade code/filters attempt to read it directly.
312 * ### 16mb is an invention, no idea if it is reasonable.
314 #define AP_MAX_SENDFILE 16777216 /* 2^24 */
317 * Special Apache error codes. These are basically used
318 * in http_main.c so we can keep track of various errors.
322 #define APEXIT_OK 0x0
323 /** A fatal error arising during the server's init sequence */
324 #define APEXIT_INIT 0x2
325 /** The child died during its init sequence */
326 #define APEXIT_CHILDINIT 0x3
328 * The child exited due to a resource shortage.
329 * The parent should limit the rate of forking until
330 * the situation is resolved.
332 #define APEXIT_CHILDSICK 0x7
334 * A fatal error, resulting in the whole server aborting.
335 * If a child exits with this error, the parent process
336 * considers this a server-wide fatal error and aborts.
338 #define APEXIT_CHILDFATAL 0xf
342 * Stuff marked #AP_DECLARE is part of the API, and intended for use
343 * by modules. Its purpose is to allow us to add attributes that
344 * particular platforms or compilers require to every exported function.
346 # define AP_DECLARE(type) type
349 #ifndef AP_DECLARE_NONSTD
351 * Stuff marked #AP_DECLARE_NONSTD is part of the API, and intended for
352 * use by modules. The difference between #AP_DECLARE and
353 * #AP_DECLARE_NONSTD is that the latter is required for any functions
354 * which use varargs or are used via indirect function call. This
355 * is to accomodate the two calling conventions in windows dlls.
357 # define AP_DECLARE_NONSTD(type) type
359 #ifndef AP_DECLARE_DATA
360 # define AP_DECLARE_DATA
363 #ifndef AP_MODULE_DECLARE
364 # define AP_MODULE_DECLARE(type) type
366 #ifndef AP_MODULE_DECLARE_NONSTD
367 # define AP_MODULE_DECLARE_NONSTD(type) type
369 #ifndef AP_MODULE_DECLARE_DATA
370 # define AP_MODULE_DECLARE_DATA
375 * modules should not use functions marked AP_CORE_DECLARE
377 #ifndef AP_CORE_DECLARE
378 # define AP_CORE_DECLARE AP_DECLARE
383 * modules should not use functions marked AP_CORE_DECLARE_NONSTD
386 #ifndef AP_CORE_DECLARE_NONSTD
387 # define AP_CORE_DECLARE_NONSTD AP_DECLARE_NONSTD
391 * @brief The numeric version information is broken out into fields within this
395 int major
; /**< major number */
396 int minor
; /**< minor number */
397 int patch
; /**< patch number */
398 const char *add_string
; /**< additional string like "-dev" */
402 * Return httpd's version information in a numeric form.
404 * @param version Pointer to a version structure for returning the version
407 AP_DECLARE(void) ap_get_server_revision(ap_version_t
*version
);
410 * Get the server banner in a form suitable for sending over the
411 * network, with the level of information controlled by the
412 * ServerTokens directive.
413 * @return The server banner
415 AP_DECLARE(const char *) ap_get_server_banner(void);
418 * Get the server description in a form suitable for local displays,
419 * status reports, or logging. This includes the detailed server
420 * version and information about some modules. It is not affected
421 * by the ServerTokens directive.
422 * @return The server description
424 AP_DECLARE(const char *) ap_get_server_description(void);
427 * Add a component to the server description and banner strings
428 * @param pconf The pool to allocate the component from
429 * @param component The string to add
431 AP_DECLARE(void) ap_add_version_component(apr_pool_t
*pconf
, const char *component
);
434 * Get the date a time that the server was built
435 * @return The server build time string
437 AP_DECLARE(const char *) ap_get_server_built(void);
439 /* non-HTTP status codes retuned by hooks */
441 #define OK 0 /**< Module has handled this stage. */
442 #define DECLINED -1 /**< Module declines to handle */
443 #define DONE -2 /**< Module has served the response completely
444 * - it's safe to die() with no more output
446 #define SUSPENDED -3 /**< Module will handle the remainder of the request.
447 * The core will never invoke the request again, */
449 /** Returned by the bottom-most filter if no data was written.
450 * @see ap_pass_brigade(). */
451 #define AP_NOBODY_WROTE -100
452 /** Returned by the bottom-most filter if no data was read.
453 * @see ap_get_brigade(). */
454 #define AP_NOBODY_READ -101
455 /** Returned by any filter if the filter chain encounters an error
456 * and has already dealt with the error response.
458 #define AP_FILTER_ERROR -102
461 * @defgroup HTTP_Status HTTP Status Codes
465 * The size of the static array in http_protocol.c for storing
466 * all of the potential response status-lines (a sparse table).
467 * A future version should dynamically generate the apr_table_t at startup.
469 #define RESPONSE_CODES 57
471 #define HTTP_CONTINUE 100
472 #define HTTP_SWITCHING_PROTOCOLS 101
473 #define HTTP_PROCESSING 102
475 #define HTTP_CREATED 201
476 #define HTTP_ACCEPTED 202
477 #define HTTP_NON_AUTHORITATIVE 203
478 #define HTTP_NO_CONTENT 204
479 #define HTTP_RESET_CONTENT 205
480 #define HTTP_PARTIAL_CONTENT 206
481 #define HTTP_MULTI_STATUS 207
482 #define HTTP_MULTIPLE_CHOICES 300
483 #define HTTP_MOVED_PERMANENTLY 301
484 #define HTTP_MOVED_TEMPORARILY 302
485 #define HTTP_SEE_OTHER 303
486 #define HTTP_NOT_MODIFIED 304
487 #define HTTP_USE_PROXY 305
488 #define HTTP_TEMPORARY_REDIRECT 307
489 #define HTTP_BAD_REQUEST 400
490 #define HTTP_UNAUTHORIZED 401
491 #define HTTP_PAYMENT_REQUIRED 402
492 #define HTTP_FORBIDDEN 403
493 #define HTTP_NOT_FOUND 404
494 #define HTTP_METHOD_NOT_ALLOWED 405
495 #define HTTP_NOT_ACCEPTABLE 406
496 #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407
497 #define HTTP_REQUEST_TIME_OUT 408
498 #define HTTP_CONFLICT 409
499 #define HTTP_GONE 410
500 #define HTTP_LENGTH_REQUIRED 411
501 #define HTTP_PRECONDITION_FAILED 412
502 #define HTTP_REQUEST_ENTITY_TOO_LARGE 413
503 #define HTTP_REQUEST_URI_TOO_LARGE 414
504 #define HTTP_UNSUPPORTED_MEDIA_TYPE 415
505 #define HTTP_RANGE_NOT_SATISFIABLE 416
506 #define HTTP_EXPECTATION_FAILED 417
507 #define HTTP_UNPROCESSABLE_ENTITY 422
508 #define HTTP_LOCKED 423
509 #define HTTP_FAILED_DEPENDENCY 424
510 #define HTTP_UPGRADE_REQUIRED 426
511 #define HTTP_INTERNAL_SERVER_ERROR 500
512 #define HTTP_NOT_IMPLEMENTED 501
513 #define HTTP_BAD_GATEWAY 502
514 #define HTTP_SERVICE_UNAVAILABLE 503
515 #define HTTP_GATEWAY_TIME_OUT 504
516 #define HTTP_VERSION_NOT_SUPPORTED 505
517 #define HTTP_VARIANT_ALSO_VARIES 506
518 #define HTTP_INSUFFICIENT_STORAGE 507
519 #define HTTP_NOT_EXTENDED 510
521 /** is the status code informational */
522 #define ap_is_HTTP_INFO(x) (((x) >= 100)&&((x) < 200))
523 /** is the status code OK ?*/
524 #define ap_is_HTTP_SUCCESS(x) (((x) >= 200)&&((x) < 300))
525 /** is the status code a redirect */
526 #define ap_is_HTTP_REDIRECT(x) (((x) >= 300)&&((x) < 400))
527 /** is the status code a error (client or server) */
528 #define ap_is_HTTP_ERROR(x) (((x) >= 400)&&((x) < 600))
529 /** is the status code a client error */
530 #define ap_is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500))
531 /** is the status code a server error */
532 #define ap_is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600))
533 /** is the status code a (potentially) valid response code? */
534 #define ap_is_HTTP_VALID_RESPONSE(x) (((x) >= 100)&&((x) < 600))
536 /** should the status code drop the connection */
537 #define ap_status_drops_connection(x) \
538 (((x) == HTTP_BAD_REQUEST) || \
539 ((x) == HTTP_REQUEST_TIME_OUT) || \
540 ((x) == HTTP_LENGTH_REQUIRED) || \
541 ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
542 ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
543 ((x) == HTTP_INTERNAL_SERVER_ERROR) || \
544 ((x) == HTTP_SERVICE_UNAVAILABLE) || \
545 ((x) == HTTP_NOT_IMPLEMENTED))
549 * @defgroup Methods List of Methods recognized by the server
550 * @ingroup APACHE_CORE_DAEMON
553 * @brief Methods recognized (but not necessarily handled) by the server.
555 * These constants are used in bit shifting masks of size int, so it is
556 * unsafe to have more methods than bits in an int. HEAD == M_GET.
557 * This list must be tracked by the list in http_protocol.c in routine
558 * ap_method_name_of().
562 #define M_GET 0 /** RFC 2616: HTTP */
563 #define M_PUT 1 /* : */
568 #define M_TRACE 6 /** RFC 2616: HTTP */
569 #define M_PATCH 7 /** no rfc(!) ### remove this one? */
570 #define M_PROPFIND 8 /** RFC 2518: WebDAV */
571 #define M_PROPPATCH 9 /* : */
576 #define M_UNLOCK 14 /** RFC 2518: WebDAV */
577 #define M_VERSION_CONTROL 15 /** RFC 3253: WebDAV Versioning */
578 #define M_CHECKOUT 16 /* : */
579 #define M_UNCHECKOUT 17
584 #define M_MKWORKSPACE 22
585 #define M_MKACTIVITY 23
586 #define M_BASELINE_CONTROL 24
588 #define M_INVALID 26 /** RFC 3253: WebDAV Versioning */
591 * METHODS needs to be equal to the number of bits
592 * we are using for limit masks.
597 * The method mask bit to shift for anding with a bitmask.
599 #define AP_METHOD_BIT ((apr_int64_t)1)
603 /** @see ap_method_list_t */
604 typedef struct ap_method_list_t ap_method_list_t
;
607 * @struct ap_method_list_t
608 * @brief Structure for handling HTTP methods.
610 * Methods known to the server are accessed via a bitmask shortcut;
611 * extension methods are handled by an array.
613 struct ap_method_list_t
{
614 /** The bitmask used for known methods */
615 apr_int64_t method_mask
;
616 /** the array used for extension methods */
617 apr_array_header_t
*method_list
;
621 * @defgroup module_magic Module Magic mime types
624 /** Magic for mod_cgi[d] */
625 #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
626 /** Magic for mod_include */
627 #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
628 /** Magic for mod_include */
629 #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
630 /** Magic for mod_dir */
631 #define DIR_MAGIC_TYPE "httpd/unix-directory"
634 /* Just in case your linefeed isn't the one the other end is expecting. */
635 #if !APR_CHARSET_EBCDIC
638 /** carrige return */
640 /** carrige return /Line Feed Combo */
641 #define CRLF "\015\012"
642 #else /* APR_CHARSET_EBCDIC */
643 /* For platforms using the EBCDIC charset, the transition ASCII->EBCDIC is done
644 * in the buff package (bread/bputs/bwrite). Everywhere else, we use
645 * "native EBCDIC" CR and NL characters. These are therefore
652 #endif /* APR_CHARSET_EBCDIC */
653 /** Useful for common code with either platform charset. */
654 #define CRLF_ASCII "\015\012"
657 * @defgroup values_request_rec_body Possible values for request_rec.read_body
659 * Possible values for request_rec.read_body (set by handling module):
662 /** Send 413 error if message has any body */
663 #define REQUEST_NO_BODY 0
664 /** Send 411 error if body without Content-Length */
665 #define REQUEST_CHUNKED_ERROR 1
666 /** If chunked, remove the chunks for me. */
667 #define REQUEST_CHUNKED_DECHUNK 2
668 /** @} // values_request_rec_body */
671 * @defgroup values_request_rec_used_path_info Possible values for request_rec.used_path_info
672 * @ingroup APACHE_CORE_DAEMON
674 * Possible values for request_rec.used_path_info:
677 /** Accept the path_info from the request */
678 #define AP_REQ_ACCEPT_PATH_INFO 0
679 /** Return a 404 error if path_info was given */
680 #define AP_REQ_REJECT_PATH_INFO 1
681 /** Module may chose to use the given path_info */
682 #define AP_REQ_DEFAULT_PATH_INFO 2
684 /** @} // values_request_rec_used_path_info */
688 * Things which may vary per file-lookup WITHIN a request ---
689 * e.g., state of MIME config. Basically, the name of an object, info
690 * about the object, and any other info we may ahve which may need to
691 * change as we go poking around looking for it (e.g., overridden by
694 * Note how the default state of almost all these things is properly
695 * zero, so that allocating it with pcalloc does the right thing without
696 * a whole lot of hairy initialization... so long as we are willing to
697 * make the (fairly) portable assumption that the bit pattern of a NULL
698 * pointer is, in fact, zero.
702 * @brief This represents the result of calling htaccess; these are cached for
705 struct htaccess_result
{
706 /** the directory to which this applies */
708 /** the overrides allowed for the .htaccess file */
710 /** the override options allowed for the .htaccess file */
712 /** the configuration directives */
713 struct ap_conf_vector_t
*htaccess
;
714 /** the next one, or NULL if no more; N.B. never change this */
715 const struct htaccess_result
*next
;
718 /* The following four types define a hierarchy of activities, so that
719 * given a request_rec r you can write r->connection->server->process
720 * to get to the process_rec. While this reduces substantially the
721 * number of arguments that various hooks require beware that in
722 * threaded versions of the server you must consider multiplexing
726 /** A structure that represents one process */
727 typedef struct process_rec process_rec
;
728 /** A structure that represents a virtual server */
729 typedef struct server_rec server_rec
;
730 /** A structure that represents one connection */
731 typedef struct conn_rec conn_rec
;
732 /** A structure that represents the current request */
733 typedef struct request_rec request_rec
;
734 /** A structure that represents the status of the current connection */
735 typedef struct conn_state_t conn_state_t
;
737 /* ### would be nice to not include this from httpd.h ... */
738 /* This comes after we have defined the request_rec type */
742 * @brief A structure that represents one process
745 /** Global pool. Cleared upon normal exit */
747 /** Configuration pool. Cleared upon restart */
749 /** Number of command line arguments passed to the program */
751 /** The command line arguments */
752 const char * const *argv
;
753 /** The program name used to execute the program */
754 const char *short_name
;
758 * @brief A structure that represents the current request
761 /** The pool associated with the request */
763 /** The connection to the client */
764 conn_rec
*connection
;
765 /** The virtual host for this request */
768 /** Pointer to the redirected request if this is an external redirect */
770 /** Pointer to the previous request if this is an internal redirect */
773 /** Pointer to the main request if this is a sub-request
774 * (see http_request.h) */
777 /* Info about the request itself... we begin with stuff that only
778 * protocol.c should ever touch...
780 /** First line of request */
782 /** HTTP/0.9, "simple" request (e.g. GET /foo\n w/no headers) */
784 /** A proxy request (calculated during post_read_request/translate_name)
785 * possible values PROXYREQ_NONE, PROXYREQ_PROXY, PROXYREQ_REVERSE,
789 /** HEAD request, as opposed to GET */
791 /** Protocol string, as given to us, or HTTP/0.9 */
793 /** Protocol version number of protocol; 1.1 = 1001 */
795 /** Host, as set by full URI or Host: */
796 const char *hostname
;
798 /** Time when the request started */
799 apr_time_t request_time
;
801 /** Status line, if set by script */
802 const char *status_line
;
806 /* Request method, two ways; also, protocol, etc.. Outside of protocol.c,
807 * look, but don't touch.
810 /** Request method (eg. GET, HEAD, POST, etc.) */
812 /** M_GET, M_POST, etc. */
816 * 'allowed' is a bitvector of the allowed methods.
818 * A handler must ensure that the request method is one that
819 * it is capable of handling. Generally modules should DECLINE
820 * any request methods they do not handle. Prior to aborting the
821 * handler like this the handler should set r->allowed to the list
822 * of methods that it is willing to handle. This bitvector is used
823 * to construct the "Allow:" header required for OPTIONS requests,
824 * and HTTP_METHOD_NOT_ALLOWED and HTTP_NOT_IMPLEMENTED status codes.
826 * Since the default_handler deals with OPTIONS, all modules can
827 * usually decline to deal with OPTIONS. TRACE is always allowed,
828 * modules don't need to set it explicitly.
830 * Since the default_handler will always handle a GET, a
831 * module which does *not* implement GET should probably return
832 * HTTP_METHOD_NOT_ALLOWED. Unfortunately this means that a Script GET
833 * handler can't be installed by mod_actions.
836 /** Array of extension methods */
837 apr_array_header_t
*allowed_xmethods
;
838 /** List of allowed methods */
839 ap_method_list_t
*allowed_methods
;
841 /** byte count in stream is for body */
842 apr_off_t sent_bodyct
;
843 /** body byte count, for easy access */
844 apr_off_t bytes_sent
;
845 /** Last modified time of the requested resource */
848 /* HTTP/1.1 connection-level features */
850 /** sending chunked transfer-coding */
852 /** The Range: header */
854 /** The "real" content length */
857 /** Remaining bytes left to read from the request body */
859 /** Number of bytes that have been read from the request body */
860 apr_off_t read_length
;
861 /** Method for reading the request body
862 * (eg. REQUEST_CHUNKED_ERROR, REQUEST_NO_BODY,
863 * REQUEST_CHUNKED_DECHUNK, etc...) */
865 /** reading chunked transfer-coding */
867 /** is client waiting for a 100 response? */
868 unsigned expecting_100
;
870 /* MIME header environments, in and out. Also, an array containing
871 * environment variables to be passed to subprocesses, so people can
872 * write modules to add to that environment.
874 * The difference between headers_out and err_headers_out is that the
875 * latter are printed even on error, and persist across internal redirects
876 * (so the headers printed for ErrorDocument handlers will have them).
878 * The 'notes' apr_table_t is for notes from one module to another, with no
879 * other set purpose in mind...
882 /** MIME header environment from the request */
883 apr_table_t
*headers_in
;
884 /** MIME header environment for the response */
885 apr_table_t
*headers_out
;
886 /** MIME header environment for the response, printed even on errors and
887 * persist across internal redirects */
888 apr_table_t
*err_headers_out
;
889 /** Array of environment variables to be used for sub processes */
890 apr_table_t
*subprocess_env
;
891 /** Notes from one module to another */
894 /* content_type, handler, content_encoding, and all content_languages
895 * MUST be lowercased strings. They may be pointers to static strings;
896 * they should not be modified in place.
898 /** The content-type for the current request */
899 const char *content_type
; /* Break these out --- we dispatch on 'em */
900 /** The handler string that we use to call a handler function */
901 const char *handler
; /* What we *really* dispatch on */
903 /** How to encode the data */
904 const char *content_encoding
;
905 /** Array of strings representing the content languages */
906 apr_array_header_t
*content_languages
;
908 /** variant list validator (if negotiated) */
909 char *vlist_validator
;
911 /** If an authentication check was made, this gets set to the user name. */
913 /** If an authentication check was made, this gets set to the auth type. */
916 /** This response can not be cached */
918 /** There is no local copy of this response */
921 /* What object is being requested (either directly, or via include
922 * or content-negotiation mapping).
925 /** The URI without any parsing performed */
927 /** The path portion of the URI */
929 /** The filename on disk corresponding to this response */
931 /* XXX: What does this mean? Please define "canonicalize" -aaron */
932 /** The true filename, we canonicalize r->filename if these don't match */
933 char *canonical_filename
;
934 /** The PATH_INFO extracted from this request */
936 /** The QUERY_ARGS extracted from this request */
938 /** finfo.protection (st_mode) set to zero if no such file */
940 /** A struct containing the components of URI */
941 apr_uri_t parsed_uri
;
944 * Flag for the handler to accept or reject path_info on
945 * the current request. All modules should respect the
946 * AP_REQ_ACCEPT_PATH_INFO and AP_REQ_REJECT_PATH_INFO
947 * values, while AP_REQ_DEFAULT_PATH_INFO indicates they
948 * may follow existing conventions. This is set to the
949 * user's preference upon HOOK_VERY_FIRST of the fixups.
953 /* Various other config info which may change with .htaccess files
954 * These are config vectors, with one void* pointer for each module
955 * (the thing pointed to being the module's business).
958 /** Options set in config files, etc. */
959 struct ap_conf_vector_t
*per_dir_config
;
960 /** Notes on *this* request */
961 struct ap_conf_vector_t
*request_config
;
964 * A linked list of the .htaccess configuration directives
965 * accessed by this request.
966 * N.B. always add to the head of the list, _never_ to the end.
967 * that way, a sub request's list can (temporarily) point to a parent's list
969 const struct htaccess_result
*htaccess
;
971 /** A list of output filters to be used for this request */
972 struct ap_filter_t
*output_filters
;
973 /** A list of input filters to be used for this request */
974 struct ap_filter_t
*input_filters
;
976 /** A list of protocol level output filters to be used for this
978 struct ap_filter_t
*proto_output_filters
;
979 /** A list of protocol level input filters to be used for this
981 struct ap_filter_t
*proto_input_filters
;
983 /** A flag to determine if the eos bucket has been sent yet */
986 /** The optional kept body of the request. */
987 apr_bucket_brigade
*kept_body
;
989 apr_thread_mutex_t
*invoke_mtx
;
991 apr_table_t
*body_table
;
993 /* Things placed at the end of the record to avoid breaking binary
994 * compatibility. It would be nice to remember to reorder the entire
995 * record to improve 64bit alignment the next time we need to break
996 * binary compatibility for some other reason.
1001 * @defgroup ProxyReq Proxy request types
1003 * Possible values of request_rec->proxyreq. A request could be normal,
1004 * proxied or reverse proxied. Normally proxied and reverse proxied are
1005 * grouped together as just "proxied", but sometimes it's necessary to
1006 * tell the difference between the two, such as for authentication.
1010 #define PROXYREQ_NONE 0 /**< No proxy */
1011 #define PROXYREQ_PROXY 1 /**< Standard proxy */
1012 #define PROXYREQ_REVERSE 2 /**< Reverse proxy */
1013 #define PROXYREQ_RESPONSE 3 /**< Origin response */
1018 * @brief Enumeration of connection keepalive options
1024 } ap_conn_keepalive_e
;
1027 * @brief Structure to store things which are per connection
1030 /** Pool associated with this connection */
1032 /** Physical vhost this conn came in on */
1033 server_rec
*base_server
;
1034 /** used by http_vhost.c */
1035 void *vhost_lookup_data
;
1037 /* Information about the connection itself */
1038 /** local address */
1039 apr_sockaddr_t
*local_addr
;
1040 /** remote address */
1041 apr_sockaddr_t
*remote_addr
;
1043 /** Client's IP address */
1045 /** Client's DNS name, if known. NULL if DNS hasn't been checked,
1046 * "" if it has and no address was found. N.B. Only access this though
1047 * get_remote_host() */
1049 /** Only ever set if doing rfc1413 lookups. N.B. Only access this through
1050 * get_remote_logname() */
1051 char *remote_logname
;
1053 /** Are we still talking? */
1056 /** Are we going to keep the connection alive for another request?
1057 * @see ap_conn_keepalive_e */
1058 ap_conn_keepalive_e keepalive
;
1060 /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
1062 signed int double_reverse
:2;
1064 /** How many times have we used it? */
1066 /** server IP address */
1068 /** used for ap_get_server_name when UseCanonicalName is set to DNS
1069 * (ignores setting of HostnameLookups) */
1072 /** ID of this connection; unique at any point in time */
1074 /** Config vector containing pointers to connections per-server
1075 * config structures. */
1076 struct ap_conf_vector_t
*conn_config
;
1077 /** Notes on *this* connection: send note from one module to
1078 * another. must remain valid for all requests on this conn */
1080 /** A list of input filters to be used for this connection */
1081 struct ap_filter_t
*input_filters
;
1082 /** A list of output filters to be used for this connection */
1083 struct ap_filter_t
*output_filters
;
1084 /** handle to scoreboard information for this connection */
1086 /** The bucket allocator to use for all bucket/brigade creations */
1087 struct apr_bucket_alloc_t
*bucket_alloc
;
1088 /** The current state of this connection */
1090 /** Is there data pending in the input filters? */
1091 int data_in_input_filters
;
1092 /** Is there data pending in the output filters? */
1093 int data_in_output_filters
;
1095 /** Are there any filters that clogg/buffer the input stream, breaking
1098 int clogging_input_filters
;
1100 /** This points to the current thread being used to process this request,
1101 * over the lifetime of a request, the value may change. Users of the connection
1102 * record should not rely upon it staying the same between calls that invole
1106 apr_thread_t
*current_thread
;
1111 * Enumeration of connection states
1114 CONN_STATE_CHECK_REQUEST_LINE_READABLE
,
1115 CONN_STATE_READ_REQUEST_LINE
,
1117 CONN_STATE_WRITE_COMPLETION
,
1118 CONN_STATE_SUSPENDED
,
1123 * @brief A structure to contain connection state information
1125 struct conn_state_t
{
1126 /** APR_RING of expiration timeouts */
1127 APR_RING_ENTRY(conn_state_t
) timeout_list
;
1128 /** the expiration time of the next keepalive timeout */
1129 apr_time_t expiration_time
;
1130 /** Current state of the connection */
1132 /** connection record this struct refers to */
1134 /** memory pool to allocate from */
1136 /** bucket allocator */
1137 apr_bucket_alloc_t
*bucket_alloc
;
1138 /** poll file decriptor information */
1142 /* Per-vhost config... */
1145 * The address 255.255.255.255, when used as a virtualhost address,
1146 * will become the "default" server when the ip doesn't match other vhosts.
1148 #define DEFAULT_VHOST_ADDR 0xfffffffful
1152 * @struct server_addr_rec
1153 * @brief A structure to be used for Per-vhost config
1155 typedef struct server_addr_rec server_addr_rec
;
1156 struct server_addr_rec
{
1157 /** The next server in the list */
1158 server_addr_rec
*next
;
1159 /** The bound address, for this server */
1160 apr_sockaddr_t
*host_addr
;
1161 /** The bound port, for this server */
1162 apr_port_t host_port
;
1163 /** The name given in "<VirtualHost>" */
1168 * @brief A structure to store information for each virtual server
1171 /** The process this server is running in */
1172 process_rec
*process
;
1173 /** The next server in the list */
1176 /** The name of the server */
1177 const char *defn_name
;
1178 /** The line of the config file that the server was defined on */
1179 unsigned defn_line_number
;
1181 /* Contact information */
1183 /** The admin's contact information */
1185 /** The server hostname */
1186 char *server_hostname
;
1187 /** for redirects, etc. */
1190 /* Log files --- note that transfer log is now in the modules... */
1192 /** The name of the error log */
1194 /** A file descriptor that references the error log */
1195 apr_file_t
*error_log
;
1196 /** The log level for this server */
1199 /* Module-specific configuration for server, and defaults... */
1201 /** true if this is the virtual server */
1203 /** Config vector containing pointers to modules' per-server config
1205 struct ap_conf_vector_t
*module_config
;
1206 /** MIME type info, etc., before we start checking per-directory info */
1207 struct ap_conf_vector_t
*lookup_defaults
;
1209 /* Transaction handling */
1211 /** I haven't got a clue */
1212 server_addr_rec
*addrs
;
1213 /** Timeout, as an apr interval, before we give up */
1214 apr_interval_time_t timeout
;
1215 /** The apr interval we will wait for another request */
1216 apr_interval_time_t keep_alive_timeout
;
1217 /** Maximum requests per connection */
1219 /** Use persistent connections? */
1222 /** Pathname for ServerPath */
1224 /** Length of path */
1227 /** Normal names for ServerAlias servers */
1228 apr_array_header_t
*names
;
1229 /** Wildcarded names for ServerAlias servers */
1230 apr_array_header_t
*wild_names
;
1232 /** limit on size of the HTTP request line */
1234 /** limit on size of any request header field */
1235 int limit_req_fieldsize
;
1236 /** limit on number of request header fields */
1237 int limit_req_fields
;
1239 /** The server request scheme for redirect responses */
1240 const char *server_scheme
;
1243 typedef struct core_output_filter_ctx
{
1244 apr_bucket_brigade
*buffered_bb
;
1245 apr_size_t bytes_in
;
1246 apr_size_t bytes_written
;
1247 } core_output_filter_ctx_t
;
1249 typedef struct core_filter_ctx
{
1250 apr_bucket_brigade
*b
;
1251 apr_bucket_brigade
*tmpbb
;
1254 typedef struct core_net_rec
{
1255 /** Connection to the client */
1256 apr_socket_t
*client_socket
;
1258 /** connection record */
1261 core_output_filter_ctx_t
*out_ctx
;
1266 * Examine a field value (such as a media-/content-type) string and return
1267 * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
1268 * @param p Pool to allocate memory from
1269 * @param intype The field to examine
1270 * @return A copy of the field minus any parameters
1272 AP_DECLARE(char *) ap_field_noparam(apr_pool_t
*p
, const char *intype
);
1275 * Convert a time from an integer into a string in a specified format
1276 * @param p The pool to allocate memory from
1277 * @param t The time to convert
1278 * @param fmt The format to use for the conversion
1279 * @param gmt Convert the time for GMT?
1280 * @return The string that represents the specified time
1282 AP_DECLARE(char *) ap_ht_time(apr_pool_t
*p
, apr_time_t t
, const char *fmt
, int gmt
);
1284 /* String handling. The *_nc variants allow you to use non-const char **s as
1285 arguments (unfortunately C won't automatically convert a char ** to a const
1289 * Get the characters until the first occurance of a specified character
1290 * @param p The pool to allocate memory from
1291 * @param line The string to get the characters from
1292 * @param stop The character to stop at
1293 * @return A copy of the characters up to the first stop character
1295 AP_DECLARE(char *) ap_getword(apr_pool_t
*p
, const char **line
, char stop
);
1298 * Get the characters until the first occurance of a specified character
1299 * @param p The pool to allocate memory from
1300 * @param line The string to get the characters from
1301 * @param stop The character to stop at
1302 * @return A copy of the characters up to the first stop character
1303 * @note This is the same as ap_getword(), except it doesn't use const char **.
1305 AP_DECLARE(char *) ap_getword_nc(apr_pool_t
*p
, char **line
, char stop
);
1308 * Get the first word from a given string. A word is defined as all characters
1309 * up to the first whitespace.
1310 * @param p The pool to allocate memory from
1311 * @param line The string to traverse
1312 * @return The first word in the line
1314 AP_DECLARE(char *) ap_getword_white(apr_pool_t
*p
, const char **line
);
1317 * Get the first word from a given string. A word is defined as all characters
1318 * up to the first whitespace.
1319 * @param p The pool to allocate memory from
1320 * @param line The string to traverse
1321 * @return The first word in the line
1322 * @note The same as ap_getword_white(), except it doesn't use const char**
1324 AP_DECLARE(char *) ap_getword_white_nc(apr_pool_t
*p
, char **line
);
1327 * Get all characters from the first occurance of @a stop to the first "\0"
1328 * @param p The pool to allocate memory from
1329 * @param line The line to traverse
1330 * @param stop The character to start at
1331 * @return A copy of all caracters after the first occurance of the specified
1334 AP_DECLARE(char *) ap_getword_nulls(apr_pool_t
*p
, const char **line
,
1338 * Get all characters from the first occurance of @a stop to the first "\0"
1339 * @param p The pool to allocate memory from
1340 * @param line The line to traverse
1341 * @param stop The character to start at
1342 * @return A copy of all caracters after the first occurance of the specified
1344 * @note The same as ap_getword_nulls(), except it doesn't use const char **.
1346 AP_DECLARE(char *) ap_getword_nulls_nc(apr_pool_t
*p
, char **line
, char stop
);
1349 * Get the second word in the string paying attention to quoting
1350 * @param p The pool to allocate from
1351 * @param line The line to traverse
1352 * @return A copy of the string
1354 AP_DECLARE(char *) ap_getword_conf(apr_pool_t
*p
, const char **line
);
1357 * Get the second word in the string paying attention to quoting
1358 * @param p The pool to allocate from
1359 * @param line The line to traverse
1360 * @return A copy of the string
1361 * @note The same as ap_getword_conf(), except it doesn't use const char **.
1363 AP_DECLARE(char *) ap_getword_conf_nc(apr_pool_t
*p
, char **line
);
1366 * Check a string for any ${ENV} environment variable construct and replace
1367 * each them by the value of that environment variable, if it exists. If the
1368 * environment value does not exist, leave the ${ENV} construct alone; it
1369 * means something else.
1370 * @param p The pool to allocate from
1371 * @param word The string to check
1372 * @return The string with the replaced environment variables
1374 AP_DECLARE(const char *) ap_resolve_env(apr_pool_t
*p
, const char * word
);
1377 * Size an HTTP header field list item, as separated by a comma.
1378 * @param field The field to size
1379 * @param len The length of the field
1380 * @return The return value is a pointer to the beginning of the non-empty
1381 * list item within the original string (or NULL if there is none) and the
1382 * address of field is shifted to the next non-comma, non-whitespace
1383 * character. len is the length of the item excluding any beginning whitespace.
1385 AP_DECLARE(const char *) ap_size_list_item(const char **field
, int *len
);
1388 * Retrieve an HTTP header field list item, as separated by a comma,
1389 * while stripping insignificant whitespace and lowercasing anything not in
1390 * a quoted string or comment.
1391 * @param p The pool to allocate from
1392 * @param field The field to retrieve
1393 * @return The return value is a new string containing the converted list
1394 * item (or NULL if none) and the address pointed to by field is
1395 * shifted to the next non-comma, non-whitespace.
1397 AP_DECLARE(char *) ap_get_list_item(apr_pool_t
*p
, const char **field
);
1400 * Find an item in canonical form (lowercase, no extra spaces) within
1401 * an HTTP field value list.
1402 * @param p The pool to allocate from
1403 * @param line The field value list to search
1404 * @param tok The token to search for
1405 * @return 1 if found, 0 if not found.
1407 AP_DECLARE(int) ap_find_list_item(apr_pool_t
*p
, const char *line
, const char *tok
);
1410 * Retrieve a token, spacing over it and adjusting the pointer to
1411 * the first non-white byte afterwards. Note that these tokens
1412 * are delimited by semis and commas and can also be delimited
1413 * by whitespace at the caller's option.
1414 * @param p The pool to allocate from
1415 * @param accept_line The line to retrieve the token from (adjusted afterwards)
1416 * @param accept_white Is it delimited by whitespace
1419 AP_DECLARE(char *) ap_get_token(apr_pool_t
*p
, const char **accept_line
, int accept_white
);
1422 * Find http tokens, see the definition of token from RFC2068
1423 * @param p The pool to allocate from
1424 * @param line The line to find the token
1425 * @param tok The token to find
1426 * @return 1 if the token is found, 0 otherwise
1428 AP_DECLARE(int) ap_find_token(apr_pool_t
*p
, const char *line
, const char *tok
);
1431 * find http tokens from the end of the line
1432 * @param p The pool to allocate from
1433 * @param line The line to find the token
1434 * @param tok The token to find
1435 * @return 1 if the token is found, 0 otherwise
1437 AP_DECLARE(int) ap_find_last_token(apr_pool_t
*p
, const char *line
, const char *tok
);
1440 * Check for an Absolute URI syntax
1441 * @param u The string to check
1442 * @return 1 if URI, 0 otherwise
1444 AP_DECLARE(int) ap_is_url(const char *u
);
1448 * @param url The string to unescape
1449 * @return 0 on success, non-zero otherwise
1451 AP_DECLARE(int) ap_unescape_all(char *url
);
1455 * @param url The url to unescape
1456 * @return 0 on success, non-zero otherwise
1458 AP_DECLARE(int) ap_unescape_url(char *url
);
1461 * Unescape a URL, but leaving %2f (slashes) escaped
1462 * @param url The url to unescape
1463 * @return 0 on success, non-zero otherwise
1465 AP_DECLARE(int) ap_unescape_url_keep2f(char *url
);
1468 * Convert all double slashes to single slashes
1469 * @param name The string to convert
1471 AP_DECLARE(void) ap_no2slash(char *name
);
1474 * Remove all ./ and xx/../ substrings from a file name. Also remove
1475 * any leading ../ or /../ substrings.
1476 * @param name the file name to parse
1478 AP_DECLARE(void) ap_getparents(char *name
);
1481 * Escape a path segment, as defined in RFC 1808
1482 * @param p The pool to allocate from
1483 * @param s The path to convert
1484 * @return The converted URL
1486 AP_DECLARE(char *) ap_escape_path_segment(apr_pool_t
*p
, const char *s
);
1489 * Escape a path segment, as defined in RFC 1808, to a preallocated buffer.
1490 * @param c The preallocated buffer to write to
1491 * @param s The path to convert
1492 * @return The converted URL (c)
1494 AP_DECLARE(char *) ap_escape_path_segment_buffer(char *c
, const char *s
);
1497 * convert an OS path to a URL in an OS dependant way.
1498 * @param p The pool to allocate from
1499 * @param path The path to convert
1500 * @param partial if set, assume that the path will be appended to something
1501 * with a '/' in it (and thus does not prefix "./")
1502 * @return The converted URL
1504 AP_DECLARE(char *) ap_os_escape_path(apr_pool_t
*p
, const char *path
, int partial
);
1506 /** @see ap_os_escape_path */
1507 #define ap_escape_uri(ppool,path) ap_os_escape_path(ppool,path,1)
1510 * Escape an html string
1511 * @param p The pool to allocate from
1512 * @param s The html to escape
1513 * @return The escaped string
1515 #define ap_escape_html(p,s) ap_escape_html2(p,s,0)
1517 * Escape an html string
1518 * @param p The pool to allocate from
1519 * @param s The html to escape
1520 * @param toasc Whether to escape all non-ASCII chars to &#nnn;
1521 * @return The escaped string
1523 AP_DECLARE(char *) ap_escape_html2(apr_pool_t
*p
, const char *s
, int toasc
);
1526 * Escape a string for logging
1527 * @param p The pool to allocate from
1528 * @param str The string to escape
1529 * @return The escaped string
1531 AP_DECLARE(char *) ap_escape_logitem(apr_pool_t
*p
, const char *str
);
1534 * Escape a string for logging into the error log (without a pool)
1535 * @param dest The buffer to write to
1536 * @param source The string to escape
1537 * @param buflen The buffer size for the escaped string (including "\0")
1538 * @return The len of the escaped string (always < maxlen)
1540 AP_DECLARE(apr_size_t
) ap_escape_errorlog_item(char *dest
, const char *source
,
1544 * Construct a full hostname
1545 * @param p The pool to allocate from
1546 * @param hostname The hostname of the server
1547 * @param port The port the server is running on
1548 * @param r The current request
1549 * @return The server's hostname
1551 AP_DECLARE(char *) ap_construct_server(apr_pool_t
*p
, const char *hostname
,
1552 apr_port_t port
, const request_rec
*r
);
1555 * Escape a shell command
1556 * @param p The pool to allocate from
1557 * @param s The command to escape
1558 * @return The escaped shell command
1560 AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t
*p
, const char *s
);
1563 * Count the number of directories in a path
1564 * @param path The path to count
1565 * @return The number of directories
1567 AP_DECLARE(int) ap_count_dirs(const char *path
);
1570 * Copy at most @a n leading directories of @a s into @a d. @a d
1571 * should be at least as large as @a s plus 1 extra byte
1573 * @param d The location to copy to
1574 * @param s The location to copy from
1575 * @param n The number of directories to copy
1576 * @return value is the ever useful pointer to the trailing "\0" of d
1577 * @note on platforms with drive letters, n = 0 returns the "/" root,
1578 * whereas n = 1 returns the "d:/" root. On all other platforms, n = 0
1579 * returns the empty string. */
1580 AP_DECLARE(char *) ap_make_dirstr_prefix(char *d
, const char *s
, int n
);
1583 * Return the parent directory name (including trailing /) of the file
1585 * @param p The pool to allocate from
1586 * @param s The file to get the parent of
1587 * @return A copy of the file's parent directory
1589 AP_DECLARE(char *) ap_make_dirstr_parent(apr_pool_t
*p
, const char *s
);
1592 * Given a directory and filename, create a single path from them. This
1593 * function is smart enough to ensure that there is a sinlge '/' between the
1594 * directory and file names
1595 * @param a The pool to allocate from
1596 * @param dir The directory name
1597 * @param f The filename
1598 * @return A copy of the full path
1599 * @note Never consider using this function if you are dealing with filesystem
1600 * names that need to remain canonical, unless you are merging an apr_dir_read
1601 * path and returned filename. Otherwise, the result is not canonical.
1603 AP_DECLARE(char *) ap_make_full_path(apr_pool_t
*a
, const char *dir
, const char *f
);
1606 * Test if the given path has an an absolute path.
1607 * @param p The pool to allocate from
1608 * @param dir The directory name
1609 * @note The converse is not necessarily true, some OS's (Win32/OS2/Netware) have
1610 * multiple forms of absolute paths. This only reports if the path is absolute
1611 * in a canonical sense.
1613 AP_DECLARE(int) ap_os_is_path_absolute(apr_pool_t
*p
, const char *dir
);
1616 * Does the provided string contain wildcard characters? This is useful
1617 * for determining if the string should be passed to strcmp_match or to strcmp.
1618 * The only wildcard characters recognized are '?' and '*'
1619 * @param str The string to check
1620 * @return 1 if the string has wildcards, 0 otherwise
1622 AP_DECLARE(int) ap_is_matchexp(const char *str
);
1625 * Determine if a string matches a patterm containing the wildcards '?' or '*'
1626 * @param str The string to check
1627 * @param expected The pattern to match against
1628 * @return 1 if the two strings match, 0 otherwise
1630 AP_DECLARE(int) ap_strcmp_match(const char *str
, const char *expected
);
1633 * Determine if a string matches a patterm containing the wildcards '?' or '*',
1635 * @param str The string to check
1636 * @param expected The pattern to match against
1637 * @return 1 if the two strings match, 0 otherwise
1639 AP_DECLARE(int) ap_strcasecmp_match(const char *str
, const char *expected
);
1642 * Find the first occurrence of the substring s2 in s1, regardless of case
1643 * @param s1 The string to search
1644 * @param s2 The substring to search for
1645 * @return A pointer to the beginning of the substring
1646 * @remark See apr_strmatch() for a faster alternative
1648 AP_DECLARE(char *) ap_strcasestr(const char *s1
, const char *s2
);
1651 * Return a pointer to the location inside of bigstring immediately after prefix
1652 * @param bigstring The input string
1653 * @param prefix The prefix to strip away
1654 * @return A pointer relative to bigstring after prefix
1656 AP_DECLARE(const char *) ap_stripprefix(const char *bigstring
,
1657 const char *prefix
);
1660 * Decode a base64 encoded string into memory allocated from a pool
1661 * @param p The pool to allocate from
1662 * @param bufcoded The encoded string
1663 * @return The decoded string
1665 AP_DECLARE(char *) ap_pbase64decode(apr_pool_t
*p
, const char *bufcoded
);
1668 * Encode a string into memory allocated from a pool in base 64 format
1669 * @param p The pool to allocate from
1670 * @param string The plaintext string
1671 * @return The encoded string
1673 AP_DECLARE(char *) ap_pbase64encode(apr_pool_t
*p
, char *string
);
1676 * Compile a regular expression to be used later
1677 * @param p The pool to allocate from
1678 * @param pattern the regular expression to compile
1679 * @param cflags The bitwise or of one or more of the following:
1680 * @li REG_EXTENDED - Use POSIX extended Regular Expressions
1681 * @li REG_ICASE - Ignore case
1682 * @li REG_NOSUB - Support for substring addressing of matches
1684 * @li REG_NEWLINE - Match-any-character operators don't match new-line
1685 * @return The compiled regular expression
1687 AP_DECLARE(ap_regex_t
*) ap_pregcomp(apr_pool_t
*p
, const char *pattern
,
1691 * Free the memory associated with a compiled regular expression
1692 * @param p The pool the regex was allocated from
1693 * @param reg The regular expression to free
1695 AP_DECLARE(void) ap_pregfree(apr_pool_t
*p
, ap_regex_t
*reg
);
1698 * After performing a successful regex match, you may use this function to
1699 * perform a series of string substitutions based on subexpressions that were
1700 * matched during the call to ap_regexec
1701 * @param p The pool to allocate from
1702 * @param input An arbitrary string containing $1 through $9. These are
1703 * replaced with the corresponding matched sub-expressions
1704 * @param source The string that was originally matched to the regex
1705 * @param nmatch the nmatch returned from ap_pregex
1706 * @param pmatch the pmatch array returned from ap_pregex
1708 AP_DECLARE(char *) ap_pregsub(apr_pool_t
*p
, const char *input
, const char *source
,
1709 size_t nmatch
, ap_regmatch_t pmatch
[]);
1712 * We want to downcase the type/subtype for comparison purposes
1713 * but nothing else because ;parameter=foo values are case sensitive.
1714 * @param s The content-type to convert to lowercase
1716 AP_DECLARE(void) ap_content_type_tolower(char *s
);
1719 * convert a string to all lowercase
1720 * @param s The string to convert to lowercase
1722 AP_DECLARE(void) ap_str_tolower(char *s
);
1725 * Search a string from left to right for the first occurrence of a
1726 * specific character
1727 * @param str The string to search
1728 * @param c The character to search for
1729 * @return The index of the first occurrence of c in str
1731 AP_DECLARE(int) ap_ind(const char *str
, char c
); /* Sigh... */
1734 * Search a string from right to left for the first occurrence of a
1735 * specific character
1736 * @param str The string to search
1737 * @param c The character to search for
1738 * @return The index of the first occurrence of c in str
1740 AP_DECLARE(int) ap_rind(const char *str
, char c
);
1743 * Given a string, replace any bare " with \" .
1744 * @param p The pool to allocate memory from
1745 * @param instring The string to search for "
1746 * @return A copy of the string with escaped quotes
1748 AP_DECLARE(char *) ap_escape_quotes(apr_pool_t
*p
, const char *instring
);
1751 * Given a string, append the PID deliminated by delim.
1752 * Usually used to create a pid-appended filepath name
1753 * (eg: /a/b/foo -> /a/b/foo.6726). A function, and not
1754 * a macro, to avoid unistd.h dependency
1755 * @param p The pool to allocate memory from
1756 * @param string The string to append the PID to
1757 * @param delim The string to use to deliminate the string from the PID
1758 * @return A copy of the string with the PID appended
1760 AP_DECLARE(char *) ap_append_pid(apr_pool_t
*p
, const char *string
,
1764 * Parse a given timeout parameter string into an apr_interval_time_t value.
1765 * The unit of the time interval is given as postfix string to the numeric
1766 * string. Currently the following units are understood:
1773 * If no unit is contained in the given timeout parameter the default_time_unit
1774 * will be used instead.
1775 * @param timeout_parameter The string containing the timeout parameter.
1776 * @param timeout The timeout value to be returned.
1777 * @param default_time_unit The default time unit to use if none is specified
1778 * in timeout_parameter.
1779 * @return Status value indicating whether the parsing was successful or not.
1781 AP_DECLARE(apr_status_t
) ap_timeout_parameter_parse(
1782 const char *timeout_parameter
,
1783 apr_interval_time_t
*timeout
,
1784 const char *default_time_unit
);
1786 /* Misc system hackery */
1788 * Given the name of an object in the file system determine if it is a directory
1789 * @param p The pool to allocate from
1790 * @param name The name of the object to check
1791 * @return 1 if it is a directory, 0 otherwise
1793 AP_DECLARE(int) ap_is_rdirectory(apr_pool_t
*p
, const char *name
);
1796 * Given the name of an object in the file system determine if it is a directory - this version is symlink aware
1797 * @param p The pool to allocate from
1798 * @param name The name of the object to check
1799 * @return 1 if it is a directory, 0 otherwise
1801 AP_DECLARE(int) ap_is_directory(apr_pool_t
*p
, const char *name
);
1804 extern int os_init_job_environment(server_rec
*s
, const char *user_name
, int one_process
);
1805 #endif /* _OSD_POSIX */
1808 * Determine the local host name for the current machine
1809 * @param p The pool to allocate from
1810 * @return A copy of the local host name
1812 char *ap_get_local_host(apr_pool_t
*p
);
1815 * Log an assertion to the error log
1816 * @param szExp The assertion that failed
1817 * @param szFile The file the assertion is in
1818 * @param nLine The line the assertion is defined on
1820 AP_DECLARE(void) ap_log_assert(const char *szExp
, const char *szFile
, int nLine
)
1821 __attribute__((noreturn
));
1824 * @internal Internal Assert function
1826 #define ap_assert(exp) ((exp) ? (void)0 : ap_log_assert(#exp,__FILE__,__LINE__))
1829 * Redefine assert() to something more useful for an Apache...
1831 * Use ap_assert() if the condition should always be checked.
1832 * Use AP_DEBUG_ASSERT() if the condition should only be checked when AP_DEBUG
1836 #define AP_DEBUG_ASSERT(exp) ap_assert(exp)
1838 #define AP_DEBUG_ASSERT(exp) ((void)0)
1842 * @defgroup stopsignal Flags which indicate places where the sever should stop for debugging.
1844 * A set of flags which indicate places where the server should raise(SIGSTOP).
1845 * This is useful for debugging, because you can then attach to that process
1846 * with gdb and continue. This is important in cases where one_process
1847 * debugging isn't possible.
1849 /** stop on a Detach */
1850 #define SIGSTOP_DETACH 1
1851 /** stop making a child process */
1852 #define SIGSTOP_MAKE_CHILD 2
1853 /** stop spawning a child process */
1854 #define SIGSTOP_SPAWN_CHILD 4
1855 /** stop spawning a child process with a piped log */
1856 #define SIGSTOP_PIPED_LOG_SPAWN 8
1857 /** stop spawning a CGI child process */
1858 #define SIGSTOP_CGI_CHILD 16
1860 /** Macro to get GDB started */
1861 #ifdef DEBUG_SIGSTOP
1862 extern int raise_sigstop_flags
;
1863 #define RAISE_SIGSTOP(x) do { \
1864 if (raise_sigstop_flags & SIGSTOP_##x) raise(SIGSTOP);\
1867 #define RAISE_SIGSTOP(x)
1871 * Get HTML describing the address and (optionally) admin of the server.
1872 * @param prefix Text which is prepended to the return value
1873 * @param r The request_rec
1874 * @return HTML describing the server, allocated in @a r's pool.
1876 AP_DECLARE(const char *) ap_psignature(const char *prefix
, request_rec
*r
);
1878 /** strtoul does not exist on sunos4. */
1882 #define strtoul strtoul_is_not_a_portable_function_use_strtol_instead
1884 /* The C library has functions that allow const to be silently dropped ...
1885 these macros detect the drop in maintainer mode, but use the native
1886 methods for normal builds
1888 Note that on some platforms (e.g., AIX with gcc, Solaris with gcc), string.h needs
1889 to be included before the macros are defined or compilation will fail.
1893 AP_DECLARE(char *) ap_strchr(char *s
, int c
);
1894 AP_DECLARE(const char *) ap_strchr_c(const char *s
, int c
);
1895 AP_DECLARE(char *) ap_strrchr(char *s
, int c
);
1896 AP_DECLARE(const char *) ap_strrchr_c(const char *s
, int c
);
1897 AP_DECLARE(char *) ap_strstr(char *s
, const char *c
);
1898 AP_DECLARE(const char *) ap_strstr_c(const char *s
, const char *c
);
1903 # define strchr(s, c) ap_strchr(s,c)
1905 # define strrchr(s, c) ap_strrchr(s,c)
1907 # define strstr(s, c) ap_strstr(s,c)
1911 /** use this instead of strchr */
1912 # define ap_strchr(s, c) strchr(s, c)
1913 /** use this instead of strchr */
1914 # define ap_strchr_c(s, c) strchr(s, c)
1915 /** use this instead of strrchr */
1916 # define ap_strrchr(s, c) strrchr(s, c)
1917 /** use this instead of strrchr */
1918 # define ap_strrchr_c(s, c) strrchr(s, c)
1919 /** use this instead of strrstr*/
1920 # define ap_strstr(s, c) strstr(s, c)
1921 /** use this instead of strrstr*/
1922 # define ap_strstr_c(s, c) strstr(s, c)
1926 #define AP_NORESTART APR_OS_START_USEERR + 1
1932 #endif /* !APACHE_HTTPD_H */
1934 /** @} //APACHE Daemon */
1935 /** @} //APACHE Core */
1936 /** @} //APACHE super group */