]> granicus.if.org Git - apache/blob - include/httpd.h
core: Extend support for asynchronous write completion from the
[apache] / include / httpd.h
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file httpd.h
19  * @brief HTTP Daemon routines
20  *
21  * @defgroup APACHE Apache HTTP Server
22  *
23  * Top level group of which all other groups are a member
24  * @{
25  *
26  * @defgroup APACHE_MODS Loadable modules
27  *           Top level group for modules
28  * @defgroup APACHE_OS Operating System Specific
29  * @defgroup APACHE_INTERNAL Internal interfaces
30  * @defgroup APACHE_CORE Core routines
31  * @{
32  * @defgroup APACHE_CORE_DAEMON HTTP Daemon Routine
33  * @{
34  */
35
36 #ifndef APACHE_HTTPD_H
37 #define APACHE_HTTPD_H
38
39 /* XXX - We need to push more stuff to other .h files, or even .c files, to
40  * make this file smaller
41  */
42
43 /* Headers in which EVERYONE has an interest... */
44 #include "ap_config.h"
45 #include "ap_mmn.h"
46
47 #include "ap_release.h"
48
49 #include "apr.h"
50 #include "apr_general.h"
51 #include "apr_tables.h"
52 #include "apr_pools.h"
53 #include "apr_time.h"
54 #include "apr_network_io.h"
55 #include "apr_buckets.h"
56 #include "apr_poll.h"
57 #include "apr_thread_proc.h"
58 #include "apr_hash.h"
59
60 #include "os.h"
61
62 #include "ap_regex.h"
63
64 #if APR_HAVE_STDLIB_H
65 #include <stdlib.h>
66 #endif
67
68 /* Note: apr_uri.h is also included, see below */
69
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
74 /* ----------------------------- config dir ------------------------------ */
75
76 /** Define this to be the default server home dir. Most things later in this
77  * file with a relative pathname will have this added.
78  */
79 #ifndef HTTPD_ROOT
80 #ifdef OS2
81 /** Set default for OS/2 file system */
82 #define HTTPD_ROOT "/os2httpd"
83 #elif defined(WIN32)
84 /** Set default for Windows file system */
85 #define HTTPD_ROOT "/apache"
86 #elif defined (NETWARE)
87 /** Set the default for NetWare */
88 #define HTTPD_ROOT "/apache"
89 #else
90 /** Set for all other OSs */
91 #define HTTPD_ROOT "/usr/local/apache"
92 #endif
93 #endif /* HTTPD_ROOT */
94
95 /*
96  * --------- You shouldn't have to edit anything below this line ----------
97  *
98  * Any modifications to any defaults not defined above should be done in the
99  * respective configuration file.
100  *
101  */
102
103 /**
104  * Default location of documents.  Can be overridden by the DocumentRoot
105  * directive.
106  */
107 #ifndef DOCUMENT_LOCATION
108 #ifdef OS2
109 /* Set default for OS/2 file system */
110 #define DOCUMENT_LOCATION  HTTPD_ROOT "/docs"
111 #else
112 /* Set default for non OS/2 file system */
113 #define DOCUMENT_LOCATION  HTTPD_ROOT "/htdocs"
114 #endif
115 #endif /* DOCUMENT_LOCATION */
116
117 /** Maximum number of dynamically loaded modules */
118 #ifndef DYNAMIC_MODULE_LIMIT
119 #define DYNAMIC_MODULE_LIMIT 256
120 #endif
121
122 /** Default administrator's address */
123 #define DEFAULT_ADMIN "[no address given]"
124
125 /** The name of the log files */
126 #ifndef DEFAULT_ERRORLOG
127 #if defined(OS2) || defined(WIN32)
128 #define DEFAULT_ERRORLOG "logs/error.log"
129 #else
130 #define DEFAULT_ERRORLOG "logs/error_log"
131 #endif
132 #endif /* DEFAULT_ERRORLOG */
133
134 /** Define this to be what your per-directory security files are called */
135 #ifndef DEFAULT_ACCESS_FNAME
136 #ifdef OS2
137 /* Set default for OS/2 file system */
138 #define DEFAULT_ACCESS_FNAME "htaccess"
139 #else
140 #define DEFAULT_ACCESS_FNAME ".htaccess"
141 #endif
142 #endif /* DEFAULT_ACCESS_FNAME */
143
144 /** The name of the server config file */
145 #ifndef SERVER_CONFIG_FILE
146 #define SERVER_CONFIG_FILE "conf/httpd.conf"
147 #endif
148
149 /** The default path for CGI scripts if none is currently set */
150 #ifndef DEFAULT_PATH
151 #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
152 #endif
153
154 /** The path to the suExec wrapper, can be overridden in Configuration */
155 #ifndef SUEXEC_BIN
156 #define SUEXEC_BIN  HTTPD_ROOT "/bin/suexec"
157 #endif
158
159 /** The timeout for waiting for messages */
160 #ifndef DEFAULT_TIMEOUT
161 #define DEFAULT_TIMEOUT 60
162 #endif
163
164 /** The timeout for waiting for keepalive timeout until next request */
165 #ifndef DEFAULT_KEEPALIVE_TIMEOUT
166 #define DEFAULT_KEEPALIVE_TIMEOUT 5
167 #endif
168
169 /** The number of requests to entertain per connection */
170 #ifndef DEFAULT_KEEPALIVE
171 #define DEFAULT_KEEPALIVE 100
172 #endif
173
174 /*
175  * Limits on the size of various request items.  These limits primarily
176  * exist to prevent simple denial-of-service attacks on a server based
177  * on misuse of the protocol.  The recommended values will depend on the
178  * nature of the server resources -- CGI scripts and database backends
179  * might require large values, but most servers could get by with much
180  * smaller limits than we use below.  The request message body size can
181  * be limited by the per-dir config directive LimitRequestBody.
182  *
183  * Internal buffer sizes are two bytes more than the DEFAULT_LIMIT_REQUEST_LINE
184  * and DEFAULT_LIMIT_REQUEST_FIELDSIZE below, which explains the 8190.
185  * These two limits can be lowered or raised by the server config
186  * directives LimitRequestLine and LimitRequestFieldsize, respectively.
187  *
188  * DEFAULT_LIMIT_REQUEST_FIELDS can be modified or disabled (set = 0) by
189  * the server config directive LimitRequestFields.
190  */
191
192 /** default limit on bytes in Request-Line (Method+URI+HTTP-version) */
193 #ifndef DEFAULT_LIMIT_REQUEST_LINE
194 #define DEFAULT_LIMIT_REQUEST_LINE 8190
195 #endif
196 /** default limit on bytes in any one header field  */
197 #ifndef DEFAULT_LIMIT_REQUEST_FIELDSIZE
198 #define DEFAULT_LIMIT_REQUEST_FIELDSIZE 8190
199 #endif
200 /** default limit on number of request header fields */
201 #ifndef DEFAULT_LIMIT_REQUEST_FIELDS
202 #define DEFAULT_LIMIT_REQUEST_FIELDS 100
203 #endif
204
205 /**
206  * The default default character set name to add if AddDefaultCharset is
207  * enabled.  Overridden with AddDefaultCharsetName.
208  */
209 #define DEFAULT_ADD_DEFAULT_CHARSET_NAME "iso-8859-1"
210
211 /** default HTTP Server protocol */
212 #define AP_SERVER_PROTOCOL "HTTP/1.1"
213
214
215 /* ------------------ stuff that modules are allowed to look at ----------- */
216
217 /** Define this to be what your HTML directory content files are called */
218 #ifndef AP_DEFAULT_INDEX
219 #define AP_DEFAULT_INDEX "index.html"
220 #endif
221
222 /** The name of the MIME types file */
223 #ifndef AP_TYPES_CONFIG_FILE
224 #define AP_TYPES_CONFIG_FILE "conf/mime.types"
225 #endif
226
227 /*
228  * Define the HTML doctype strings centrally.
229  */
230 /** HTML 2.0 Doctype */
231 #define DOCTYPE_HTML_2_0  "<!DOCTYPE HTML PUBLIC \"-//IETF//" \
232                           "DTD HTML 2.0//EN\">\n"
233 /** HTML 3.2 Doctype */
234 #define DOCTYPE_HTML_3_2  "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
235                           "DTD HTML 3.2 Final//EN\">\n"
236 /** HTML 4.0 Strict Doctype */
237 #define DOCTYPE_HTML_4_0S "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
238                           "DTD HTML 4.0//EN\"\n" \
239                           "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
240 /** HTML 4.0 Transitional Doctype */
241 #define DOCTYPE_HTML_4_0T "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
242                           "DTD HTML 4.0 Transitional//EN\"\n" \
243                           "\"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"
244 /** HTML 4.0 Frameset Doctype */
245 #define DOCTYPE_HTML_4_0F "<!DOCTYPE HTML PUBLIC \"-//W3C//" \
246                           "DTD HTML 4.0 Frameset//EN\"\n" \
247                           "\"http://www.w3.org/TR/REC-html40/frameset.dtd\">\n"
248 /** XHTML 1.0 Strict Doctype */
249 #define DOCTYPE_XHTML_1_0S "<!DOCTYPE html PUBLIC \"-//W3C//" \
250                            "DTD XHTML 1.0 Strict//EN\"\n" \
251                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
252                            "xhtml1-strict.dtd\">\n"
253 /** XHTML 1.0 Transitional Doctype */
254 #define DOCTYPE_XHTML_1_0T "<!DOCTYPE html PUBLIC \"-//W3C//" \
255                            "DTD XHTML 1.0 Transitional//EN\"\n" \
256                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
257                            "xhtml1-transitional.dtd\">\n"
258 /** XHTML 1.0 Frameset Doctype */
259 #define DOCTYPE_XHTML_1_0F "<!DOCTYPE html PUBLIC \"-//W3C//" \
260                            "DTD XHTML 1.0 Frameset//EN\"\n" \
261                            "\"http://www.w3.org/TR/xhtml1/DTD/" \
262                            "xhtml1-frameset.dtd\">"
263
264 /** Internal representation for a HTTP protocol number, e.g., HTTP/1.1 */
265 #define HTTP_VERSION(major,minor) (1000*(major)+(minor))
266 /** Major part of HTTP protocol */
267 #define HTTP_VERSION_MAJOR(number) ((number)/1000)
268 /** Minor part of HTTP protocol */
269 #define HTTP_VERSION_MINOR(number) ((number)%1000)
270
271 /* -------------- Port number for server running standalone --------------- */
272
273 /** default HTTP Port */
274 #define DEFAULT_HTTP_PORT       80
275 /** default HTTPS Port */
276 #define DEFAULT_HTTPS_PORT      443
277 /**
278  * Check whether @a port is the default port for the request @a r.
279  * @param port The port number
280  * @param r The request
281  * @see #ap_default_port
282  */
283 #define ap_is_default_port(port,r)      ((port) == ap_default_port(r))
284 /**
285  * Get the default port for a request (which depends on the scheme).
286  * @param r The request
287  */
288 #define ap_default_port(r)      ap_run_default_port(r)
289 /**
290  * Get the scheme for a request.
291  * @param r The request
292  */
293 #define ap_http_scheme(r)       ap_run_http_scheme(r)
294
295 /** The default string length */
296 #define MAX_STRING_LEN HUGE_STRING_LEN
297
298 /** The length of a Huge string */
299 #define HUGE_STRING_LEN 8192
300
301 /** The size of the server's internal read-write buffers */
302 #define AP_IOBUFSIZE 8192
303
304 /** The max number of regex captures that can be expanded by ap_pregsub */
305 #define AP_MAX_REG_MATCH 10
306
307 /**
308  * APR_HAS_LARGE_FILES introduces the problem of spliting sendfile into
309  * mutiple buckets, no greater than MAX(apr_size_t), and more granular
310  * than that in case the brigade code/filters attempt to read it directly.
311  * ### 16mb is an invention, no idea if it is reasonable.
312  */
313 #define AP_MAX_SENDFILE 16777216  /* 2^24 */
314
315 /**
316  * MPM child process exit status values
317  * The MPM parent process may check the status to see if special
318  * error handling is required.
319  */
320 /** a normal exit */
321 #define APEXIT_OK               0x0
322 /** A fatal error arising during the server's init sequence */
323 #define APEXIT_INIT             0x2
324 /**  The child died during its init sequence */
325 #define APEXIT_CHILDINIT        0x3
326 /**
327  *   The child exited due to a resource shortage.
328  *   The parent should limit the rate of forking until
329  *   the situation is resolved.
330  */
331 #define APEXIT_CHILDSICK        0x7
332 /**
333  *     A fatal error, resulting in the whole server aborting.
334  *     If a child exits with this error, the parent process
335  *     considers this a server-wide fatal error and aborts.
336  */
337 #define APEXIT_CHILDFATAL       0xf
338
339 #ifndef AP_DECLARE
340 /**
341  * Stuff marked #AP_DECLARE is part of the API, and intended for use
342  * by modules. Its purpose is to allow us to add attributes that
343  * particular platforms or compilers require to every exported function.
344  */
345 # define AP_DECLARE(type)    type
346 #endif
347
348 #ifndef AP_DECLARE_NONSTD
349 /**
350  * Stuff marked #AP_DECLARE_NONSTD is part of the API, and intended for
351  * use by modules.  The difference between #AP_DECLARE and
352  * #AP_DECLARE_NONSTD is that the latter is required for any functions
353  * which use varargs or are used via indirect function call.  This
354  * is to accomodate the two calling conventions in windows dlls.
355  */
356 # define AP_DECLARE_NONSTD(type)    type
357 #endif
358 #ifndef AP_DECLARE_DATA
359 # define AP_DECLARE_DATA
360 #endif
361
362 #ifndef AP_MODULE_DECLARE
363 # define AP_MODULE_DECLARE(type)    type
364 #endif
365 #ifndef AP_MODULE_DECLARE_NONSTD
366 # define AP_MODULE_DECLARE_NONSTD(type)  type
367 #endif
368 #ifndef AP_MODULE_DECLARE_DATA
369 # define AP_MODULE_DECLARE_DATA
370 #endif
371
372 /**
373  * @internal
374  * modules should not use functions marked AP_CORE_DECLARE
375  */
376 #ifndef AP_CORE_DECLARE
377 # define AP_CORE_DECLARE        AP_DECLARE
378 #endif
379
380 /**
381  * @internal
382  * modules should not use functions marked AP_CORE_DECLARE_NONSTD
383  */
384
385 #ifndef AP_CORE_DECLARE_NONSTD
386 # define AP_CORE_DECLARE_NONSTD AP_DECLARE_NONSTD
387 #endif
388
389 /**
390  * @defgroup APACHE_APR_STATUS_T HTTPD specific values of apr_status_t
391  * @{
392  */
393 #define AP_START_USERERR            (APR_OS_START_USERERR + 2000)
394 #define AP_USERERR_LEN              1000
395
396 /** The function declines to handle the request */
397 #define AP_DECLINED                 (AP_START_USERERR + 0)
398
399 /** @} */
400
401 /**
402  * @brief The numeric version information is broken out into fields within this
403  * structure.
404  */
405 typedef struct {
406     int major;              /**< major number */
407     int minor;              /**< minor number */
408     int patch;              /**< patch number */
409     const char *add_string; /**< additional string like "-dev" */
410 } ap_version_t;
411
412 /**
413  * Return httpd's version information in a numeric form.
414  *
415  *  @param version Pointer to a version structure for returning the version
416  *                 information.
417  */
418 AP_DECLARE(void) ap_get_server_revision(ap_version_t *version);
419
420 /**
421  * Get the server banner in a form suitable for sending over the
422  * network, with the level of information controlled by the
423  * ServerTokens directive.
424  * @return The server banner
425  */
426 AP_DECLARE(const char *) ap_get_server_banner(void);
427
428 /**
429  * Get the server description in a form suitable for local displays,
430  * status reports, or logging.  This includes the detailed server
431  * version and information about some modules.  It is not affected
432  * by the ServerTokens directive.
433  * @return The server description
434  */
435 AP_DECLARE(const char *) ap_get_server_description(void);
436
437 /**
438  * Add a component to the server description and banner strings
439  * @param pconf The pool to allocate the component from
440  * @param component The string to add
441  */
442 AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char *component);
443
444 /**
445  * Get the date a time that the server was built
446  * @return The server build time string
447  */
448 AP_DECLARE(const char *) ap_get_server_built(void);
449
450 /* non-HTTP status codes returned by hooks */
451
452 #define OK 0                    /**< Module has handled this stage. */
453 #define DECLINED -1             /**< Module declines to handle */
454 #define DONE -2                 /**< Module has served the response completely
455                                  *  - it's safe to die() with no more output
456                                  */
457 #define SUSPENDED -3 /**< Module will handle the remainder of the request.
458                       * The core will never invoke the request again, */
459
460 /** Returned by the bottom-most filter if no data was written.
461  *  @see ap_pass_brigade(). */
462 #define AP_NOBODY_WROTE         -100
463 /** Returned by the bottom-most filter if no data was read.
464  *  @see ap_get_brigade(). */
465 #define AP_NOBODY_READ          -101
466 /** Returned by any filter if the filter chain encounters an error
467  *  and has already dealt with the error response.
468  */
469 #define AP_FILTER_ERROR         -102
470
471 /**
472  * @defgroup HTTP_Status HTTP Status Codes
473  * @{
474  */
475 /**
476  * The size of the static status_lines array in http_protocol.c for
477  * storing all of the potential response status-lines (a sparse table).
478  * When adding a new code here add it to status_lines as well.
479  * A future version should dynamically generate the apr_table_t at startup.
480  */
481 #define RESPONSE_CODES 83
482
483 #define HTTP_CONTINUE                        100
484 #define HTTP_SWITCHING_PROTOCOLS             101
485 #define HTTP_PROCESSING                      102
486 #define HTTP_OK                              200
487 #define HTTP_CREATED                         201
488 #define HTTP_ACCEPTED                        202
489 #define HTTP_NON_AUTHORITATIVE               203
490 #define HTTP_NO_CONTENT                      204
491 #define HTTP_RESET_CONTENT                   205
492 #define HTTP_PARTIAL_CONTENT                 206
493 #define HTTP_MULTI_STATUS                    207
494 #define HTTP_ALREADY_REPORTED                208
495 #define HTTP_IM_USED                         226
496 #define HTTP_MULTIPLE_CHOICES                300
497 #define HTTP_MOVED_PERMANENTLY               301
498 #define HTTP_MOVED_TEMPORARILY               302
499 #define HTTP_SEE_OTHER                       303
500 #define HTTP_NOT_MODIFIED                    304
501 #define HTTP_USE_PROXY                       305
502 #define HTTP_TEMPORARY_REDIRECT              307
503 #define HTTP_PERMANENT_REDIRECT              308
504 #define HTTP_BAD_REQUEST                     400
505 #define HTTP_UNAUTHORIZED                    401
506 #define HTTP_PAYMENT_REQUIRED                402
507 #define HTTP_FORBIDDEN                       403
508 #define HTTP_NOT_FOUND                       404
509 #define HTTP_METHOD_NOT_ALLOWED              405
510 #define HTTP_NOT_ACCEPTABLE                  406
511 #define HTTP_PROXY_AUTHENTICATION_REQUIRED   407
512 #define HTTP_REQUEST_TIME_OUT                408
513 #define HTTP_CONFLICT                        409
514 #define HTTP_GONE                            410
515 #define HTTP_LENGTH_REQUIRED                 411
516 #define HTTP_PRECONDITION_FAILED             412
517 #define HTTP_REQUEST_ENTITY_TOO_LARGE        413
518 #define HTTP_REQUEST_URI_TOO_LARGE           414
519 #define HTTP_UNSUPPORTED_MEDIA_TYPE          415
520 #define HTTP_RANGE_NOT_SATISFIABLE           416
521 #define HTTP_EXPECTATION_FAILED              417
522 #define HTTP_IM_A_TEAPOT                     418
523 #define HTTP_MISDIRECTED_REQUEST             421
524 #define HTTP_UNPROCESSABLE_ENTITY            422
525 #define HTTP_LOCKED                          423
526 #define HTTP_FAILED_DEPENDENCY               424
527 #define HTTP_UPGRADE_REQUIRED                426
528 #define HTTP_PRECONDITION_REQUIRED           428
529 #define HTTP_TOO_MANY_REQUESTS               429
530 #define HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE 431
531 #define HTTP_INTERNAL_SERVER_ERROR           500
532 #define HTTP_NOT_IMPLEMENTED                 501
533 #define HTTP_BAD_GATEWAY                     502
534 #define HTTP_SERVICE_UNAVAILABLE             503
535 #define HTTP_GATEWAY_TIME_OUT                504
536 #define HTTP_VERSION_NOT_SUPPORTED           505
537 #define HTTP_VARIANT_ALSO_VARIES             506
538 #define HTTP_INSUFFICIENT_STORAGE            507
539 #define HTTP_LOOP_DETECTED                   508
540 #define HTTP_NOT_EXTENDED                    510
541 #define HTTP_NETWORK_AUTHENTICATION_REQUIRED 511
542
543 /** is the status code informational */
544 #define ap_is_HTTP_INFO(x)         (((x) >= 100)&&((x) < 200))
545 /** is the status code OK ?*/
546 #define ap_is_HTTP_SUCCESS(x)      (((x) >= 200)&&((x) < 300))
547 /** is the status code a redirect */
548 #define ap_is_HTTP_REDIRECT(x)     (((x) >= 300)&&((x) < 400))
549 /** is the status code a error (client or server) */
550 #define ap_is_HTTP_ERROR(x)        (((x) >= 400)&&((x) < 600))
551 /** is the status code a client error  */
552 #define ap_is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500))
553 /** is the status code a server error  */
554 #define ap_is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600))
555 /** is the status code a (potentially) valid response code?  */
556 #define ap_is_HTTP_VALID_RESPONSE(x) (((x) >= 100)&&((x) < 600))
557
558 /** should the status code drop the connection */
559 #define ap_status_drops_connection(x) \
560                                    (((x) == HTTP_BAD_REQUEST)           || \
561                                     ((x) == HTTP_REQUEST_TIME_OUT)      || \
562                                     ((x) == HTTP_LENGTH_REQUIRED)       || \
563                                     ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \
564                                     ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \
565                                     ((x) == HTTP_INTERNAL_SERVER_ERROR) || \
566                                     ((x) == HTTP_SERVICE_UNAVAILABLE) || \
567                                     ((x) == HTTP_NOT_IMPLEMENTED))
568 /** @} */
569
570 /**
571  * @defgroup Methods List of Methods recognized by the server
572  * @ingroup APACHE_CORE_DAEMON
573  * @{
574  *
575  * @brief Methods recognized (but not necessarily handled) by the server.
576  *
577  * These constants are used in bit shifting masks of size int, so it is
578  * unsafe to have more methods than bits in an int.  HEAD == M_GET.
579  * This list must be tracked by the list in http_protocol.c in routine
580  * ap_method_name_of().
581  *
582  */
583
584 #define M_GET                   0       /** RFC 2616: HTTP */
585 #define M_PUT                   1       /*  :             */
586 #define M_POST                  2
587 #define M_DELETE                3
588 #define M_CONNECT               4
589 #define M_OPTIONS               5
590 #define M_TRACE                 6       /** RFC 2616: HTTP */
591 #define M_PATCH                 7       /** no rfc(!)  ### remove this one? */
592 #define M_PROPFIND              8       /** RFC 2518: WebDAV */
593 #define M_PROPPATCH             9       /*  :               */
594 #define M_MKCOL                 10
595 #define M_COPY                  11
596 #define M_MOVE                  12
597 #define M_LOCK                  13
598 #define M_UNLOCK                14      /** RFC 2518: WebDAV */
599 #define M_VERSION_CONTROL       15      /** RFC 3253: WebDAV Versioning */
600 #define M_CHECKOUT              16      /*  :                          */
601 #define M_UNCHECKOUT            17
602 #define M_CHECKIN               18
603 #define M_UPDATE                19
604 #define M_LABEL                 20
605 #define M_REPORT                21
606 #define M_MKWORKSPACE           22
607 #define M_MKACTIVITY            23
608 #define M_BASELINE_CONTROL      24
609 #define M_MERGE                 25
610 #define M_INVALID               26      /** no valid method */
611 #define M_BREW                  27      /** RFC 2324: HTCPCP/1.0 */
612 #define M_WHEN                  28      /** RFC 2324: HTCPCP/1.0 */
613
614 /**
615  * METHODS needs to be equal to the number of bits
616  * we are using for limit masks.
617  */
618 #define METHODS     64
619
620 /**
621  * The method mask bit to shift for anding with a bitmask.
622  */
623 #define AP_METHOD_BIT ((apr_int64_t)1)
624 /** @} */
625
626
627 /** @see ap_method_list_t */
628 typedef struct ap_method_list_t ap_method_list_t;
629
630 /**
631  * @struct ap_method_list_t
632  * @brief  Structure for handling HTTP methods.
633  *
634  * Methods known to the server are accessed via a bitmask shortcut;
635  * extension methods are handled by an array.
636  */
637 struct ap_method_list_t {
638     /** The bitmask used for known methods */
639     apr_int64_t method_mask;
640     /** the array used for extension methods */
641     apr_array_header_t *method_list;
642 };
643
644 /**
645  * @defgroup module_magic Module Magic mime types
646  * @{
647  */
648 /** Magic for mod_cgi[d] */
649 #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
650 /** Magic for mod_include */
651 #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
652 /** Magic for mod_include */
653 #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3"
654 /** Magic for mod_dir */
655 #define DIR_MAGIC_TYPE "httpd/unix-directory"
656 /** Default for r->handler if no content-type set by type_checker */
657 #define AP_DEFAULT_HANDLER_NAME ""
658 #define AP_IS_DEFAULT_HANDLER_NAME(x) (*x == '\0')
659
660 /** @} */
661 /* Just in case your linefeed isn't the one the other end is expecting. */
662 #if !APR_CHARSET_EBCDIC
663 /** linefeed */
664 #define LF 10
665 /** carrige return */
666 #define CR 13
667 /** carrige return /Line Feed Combo */
668 #define CRLF "\015\012"
669 #else /* APR_CHARSET_EBCDIC */
670 /* For platforms using the EBCDIC charset, the transition ASCII->EBCDIC is done
671  * in the buff package (bread/bputs/bwrite).  Everywhere else, we use
672  * "native EBCDIC" CR and NL characters. These are therefore
673  * defined as
674  * '\r' and '\n'.
675  */
676 #define CR '\r'
677 #define LF '\n'
678 #define CRLF "\r\n"
679 #endif /* APR_CHARSET_EBCDIC */
680 /** Useful for common code with either platform charset. */
681 #define CRLF_ASCII "\015\012"
682
683 /**
684  * @defgroup values_request_rec_body Possible values for request_rec.read_body
685  * @{
686  * Possible values for request_rec.read_body (set by handling module):
687  */
688
689 /** Send 413 error if message has any body */
690 #define REQUEST_NO_BODY          0
691 /** Send 411 error if body without Content-Length */
692 #define REQUEST_CHUNKED_ERROR    1
693 /** If chunked, remove the chunks for me. */
694 #define REQUEST_CHUNKED_DECHUNK  2
695 /** @} // values_request_rec_body */
696
697 /**
698  * @defgroup values_request_rec_used_path_info Possible values for request_rec.used_path_info
699  * @ingroup APACHE_CORE_DAEMON
700  * @{
701  * Possible values for request_rec.used_path_info:
702  */
703
704 /** Accept the path_info from the request */
705 #define AP_REQ_ACCEPT_PATH_INFO    0
706 /** Return a 404 error if path_info was given */
707 #define AP_REQ_REJECT_PATH_INFO    1
708 /** Module may chose to use the given path_info */
709 #define AP_REQ_DEFAULT_PATH_INFO   2
710
711 /** @} // values_request_rec_used_path_info */
712
713
714 /*
715  * Things which may vary per file-lookup WITHIN a request ---
716  * e.g., state of MIME config.  Basically, the name of an object, info
717  * about the object, and any other info we may ahve which may need to
718  * change as we go poking around looking for it (e.g., overridden by
719  * .htaccess files).
720  *
721  * Note how the default state of almost all these things is properly
722  * zero, so that allocating it with pcalloc does the right thing without
723  * a whole lot of hairy initialization... so long as we are willing to
724  * make the (fairly) portable assumption that the bit pattern of a NULL
725  * pointer is, in fact, zero.
726  */
727
728 /**
729  * @brief This represents the result of calling htaccess; these are cached for
730  * each request.
731  */
732 struct htaccess_result {
733     /** the directory to which this applies */
734     const char *dir;
735     /** the overrides allowed for the .htaccess file */
736     int override;
737     /** the override options allowed for the .htaccess file */
738     int override_opts;
739     /** Table of allowed directives for override */
740     apr_table_t *override_list;
741     /** the configuration directives */
742     struct ap_conf_vector_t *htaccess;
743     /** the next one, or NULL if no more; N.B. never change this */
744     const struct htaccess_result *next;
745 };
746
747 /* The following four types define a hierarchy of activities, so that
748  * given a request_rec r you can write r->connection->server->process
749  * to get to the process_rec.  While this reduces substantially the
750  * number of arguments that various hooks require beware that in
751  * threaded versions of the server you must consider multiplexing
752  * issues.  */
753
754
755 /** A structure that represents one process */
756 typedef struct process_rec process_rec;
757 /** A structure that represents a virtual server */
758 typedef struct server_rec server_rec;
759 /** A structure that represents one connection */
760 typedef struct conn_rec conn_rec;
761 /** A structure that represents one slave connection */
762 typedef struct conn_slave_rec conn_slave_rec;
763 /** A structure that represents the current request */
764 typedef struct request_rec request_rec;
765 /** A structure that represents the status of the current connection */
766 typedef struct conn_state_t conn_state_t;
767
768 /* ### would be nice to not include this from httpd.h ... */
769 /* This comes after we have defined the request_rec type */
770 #include "apr_uri.h"
771
772 /**
773  * @brief A structure that represents one process
774  */
775 struct process_rec {
776     /** Global pool. Cleared upon normal exit */
777     apr_pool_t *pool;
778     /** Configuration pool. Cleared upon restart */
779     apr_pool_t *pconf;
780     /** The program name used to execute the program */
781     const char *short_name;
782     /** The command line arguments */
783     const char * const *argv;
784     /** Number of command line arguments passed to the program */
785     int argc;
786 };
787
788 /**
789  * @brief A structure that represents the current request
790  */
791 struct request_rec {
792     /** The pool associated with the request */
793     apr_pool_t *pool;
794     /** The connection to the client */
795     conn_rec *connection;
796     /** The virtual host for this request */
797     server_rec *server;
798
799     /** Pointer to the redirected request if this is an external redirect */
800     request_rec *next;
801     /** Pointer to the previous request if this is an internal redirect */
802     request_rec *prev;
803
804     /** Pointer to the main request if this is a sub-request
805      * (see http_request.h) */
806     request_rec *main;
807
808     /* Info about the request itself... we begin with stuff that only
809      * protocol.c should ever touch...
810      */
811     /** First line of request */
812     char *the_request;
813     /** HTTP/0.9, "simple" request (e.g. GET /foo\n w/no headers) */
814     int assbackwards;
815     /** A proxy request (calculated during post_read_request/translate_name)
816      *  possible values PROXYREQ_NONE, PROXYREQ_PROXY, PROXYREQ_REVERSE,
817      *                  PROXYREQ_RESPONSE
818      */
819     int proxyreq;
820     /** HEAD request, as opposed to GET */
821     int header_only;
822     /** Protocol version number of protocol; 1.1 = 1001 */
823     int proto_num;
824     /** Protocol string, as given to us, or HTTP/0.9 */
825     char *protocol;
826     /** Host, as set by full URI or Host: header.
827      *  For literal IPv6 addresses, this does NOT include the surrounding [ ]
828      */
829     const char *hostname;
830
831     /** Time when the request started */
832     apr_time_t request_time;
833
834     /** Status line, if set by script */
835     const char *status_line;
836     /** Status line */
837     int status;
838
839     /* Request method, two ways; also, protocol, etc..  Outside of protocol.c,
840      * look, but don't touch.
841      */
842
843     /** M_GET, M_POST, etc. */
844     int method_number;
845     /** Request method (eg. GET, HEAD, POST, etc.) */
846     const char *method;
847
848     /**
849      *  'allowed' is a bitvector of the allowed methods.
850      *
851      *  A handler must ensure that the request method is one that
852      *  it is capable of handling.  Generally modules should DECLINE
853      *  any request methods they do not handle.  Prior to aborting the
854      *  handler like this the handler should set r->allowed to the list
855      *  of methods that it is willing to handle.  This bitvector is used
856      *  to construct the "Allow:" header required for OPTIONS requests,
857      *  and HTTP_METHOD_NOT_ALLOWED and HTTP_NOT_IMPLEMENTED status codes.
858      *
859      *  Since the default_handler deals with OPTIONS, all modules can
860      *  usually decline to deal with OPTIONS.  TRACE is always allowed,
861      *  modules don't need to set it explicitly.
862      *
863      *  Since the default_handler will always handle a GET, a
864      *  module which does *not* implement GET should probably return
865      *  HTTP_METHOD_NOT_ALLOWED.  Unfortunately this means that a Script GET
866      *  handler can't be installed by mod_actions.
867      */
868     apr_int64_t allowed;
869     /** Array of extension methods */
870     apr_array_header_t *allowed_xmethods;
871     /** List of allowed methods */
872     ap_method_list_t *allowed_methods;
873
874     /** byte count in stream is for body */
875     apr_off_t sent_bodyct;
876     /** body byte count, for easy access */
877     apr_off_t bytes_sent;
878     /** Last modified time of the requested resource */
879     apr_time_t mtime;
880
881     /* HTTP/1.1 connection-level features */
882
883     /** The Range: header */
884     const char *range;
885     /** The "real" content length */
886     apr_off_t clength;
887     /** sending chunked transfer-coding */
888     int chunked;
889
890     /** Method for reading the request body
891      * (eg. REQUEST_CHUNKED_ERROR, REQUEST_NO_BODY,
892      *  REQUEST_CHUNKED_DECHUNK, etc...) */
893     int read_body;
894     /** reading chunked transfer-coding */
895     int read_chunked;
896     /** is client waiting for a 100 response? */
897     unsigned expecting_100;
898     /** The optional kept body of the request. */
899     apr_bucket_brigade *kept_body;
900     /** For ap_body_to_table(): parsed body */
901     /* XXX: ap_body_to_table has been removed. Remove body_table too or
902      * XXX: keep it to reintroduce ap_body_to_table without major bump? */
903     apr_table_t *body_table;
904     /** Remaining bytes left to read from the request body */
905     apr_off_t remaining;
906     /** Number of bytes that have been read  from the request body */
907     apr_off_t read_length;
908
909     /* MIME header environments, in and out.  Also, an array containing
910      * environment variables to be passed to subprocesses, so people can
911      * write modules to add to that environment.
912      *
913      * The difference between headers_out and err_headers_out is that the
914      * latter are printed even on error, and persist across internal redirects
915      * (so the headers printed for ErrorDocument handlers will have them).
916      *
917      * The 'notes' apr_table_t is for notes from one module to another, with no
918      * other set purpose in mind...
919      */
920
921     /** MIME header environment from the request */
922     apr_table_t *headers_in;
923     /** MIME header environment for the response */
924     apr_table_t *headers_out;
925     /** MIME header environment for the response, printed even on errors and
926      * persist across internal redirects */
927     apr_table_t *err_headers_out;
928     /** Array of environment variables to be used for sub processes */
929     apr_table_t *subprocess_env;
930     /** Notes from one module to another */
931     apr_table_t *notes;
932
933     /* content_type, handler, content_encoding, and all content_languages
934      * MUST be lowercased strings.  They may be pointers to static strings;
935      * they should not be modified in place.
936      */
937     /** The content-type for the current request */
938     const char *content_type;   /* Break these out --- we dispatch on 'em */
939     /** The handler string that we use to call a handler function */
940     const char *handler;        /* What we *really* dispatch on */
941
942     /** How to encode the data */
943     const char *content_encoding;
944     /** Array of strings representing the content languages */
945     apr_array_header_t *content_languages;
946
947     /** variant list validator (if negotiated) */
948     char *vlist_validator;
949
950     /** If an authentication check was made, this gets set to the user name. */
951     char *user;
952     /** If an authentication check was made, this gets set to the auth type. */
953     char *ap_auth_type;
954
955     /* What object is being requested (either directly, or via include
956      * or content-negotiation mapping).
957      */
958
959     /** The URI without any parsing performed */
960     char *unparsed_uri;
961     /** The path portion of the URI, or "/" if no path provided */
962     char *uri;
963     /** The filename on disk corresponding to this response */
964     char *filename;
965     /** The true filename stored in the filesystem, as in the true alpha case
966      *  and alias correction, e.g. "Image.jpeg" not "IMAGE$1.JPE" on Windows.
967      *  The core map_to_storage canonicalizes r->filename when they mismatch */
968     char *canonical_filename;
969     /** The PATH_INFO extracted from this request */
970     char *path_info;
971     /** The QUERY_ARGS extracted from this request */
972     char *args;
973
974     /**
975      * Flag for the handler to accept or reject path_info on
976      * the current request.  All modules should respect the
977      * AP_REQ_ACCEPT_PATH_INFO and AP_REQ_REJECT_PATH_INFO
978      * values, while AP_REQ_DEFAULT_PATH_INFO indicates they
979      * may follow existing conventions.  This is set to the
980      * user's preference upon HOOK_VERY_FIRST of the fixups.
981      */
982     int used_path_info;
983
984     /** A flag to determine if the eos bucket has been sent yet */
985     int eos_sent;
986
987     /* Various other config info which may change with .htaccess files
988      * These are config vectors, with one void* pointer for each module
989      * (the thing pointed to being the module's business).
990      */
991
992     /** Options set in config files, etc. */
993     struct ap_conf_vector_t *per_dir_config;
994     /** Notes on *this* request */
995     struct ap_conf_vector_t *request_config;
996
997     /** Optional request log level configuration. Will usually point
998      *  to a server or per_dir config, i.e. must be copied before
999      *  modifying */
1000     const struct ap_logconf *log;
1001
1002     /** Id to identify request in access and error log. Set when the first
1003      *  error log entry for this request is generated.
1004      */
1005     const char *log_id;
1006
1007     /**
1008      * A linked list of the .htaccess configuration directives
1009      * accessed by this request.
1010      * N.B. always add to the head of the list, _never_ to the end.
1011      * that way, a sub request's list can (temporarily) point to a parent's list
1012      */
1013     const struct htaccess_result *htaccess;
1014
1015     /** A list of output filters to be used for this request */
1016     struct ap_filter_t *output_filters;
1017     /** A list of input filters to be used for this request */
1018     struct ap_filter_t *input_filters;
1019
1020     /** A list of protocol level output filters to be used for this
1021      *  request */
1022     struct ap_filter_t *proto_output_filters;
1023     /** A list of protocol level input filters to be used for this
1024      *  request */
1025     struct ap_filter_t *proto_input_filters;
1026
1027     /** This response can not be cached */
1028     int no_cache;
1029     /** There is no local copy of this response */
1030     int no_local_copy;
1031
1032     /** Mutex protect callbacks registered with ap_mpm_register_timed_callback
1033      * from being run before the original handler finishes running
1034      */
1035 #if APR_HAS_THREADS
1036     apr_thread_mutex_t *invoke_mtx;
1037 #endif
1038
1039     /** A struct containing the components of URI */
1040     apr_uri_t parsed_uri;
1041     /**  finfo.protection (st_mode) set to zero if no such file */
1042     apr_finfo_t finfo;
1043
1044     /** remote address information from conn_rec, can be overridden if
1045      * necessary by a module.
1046      * This is the address that originated the request.
1047      */
1048     apr_sockaddr_t *useragent_addr;
1049     char *useragent_ip;
1050
1051     /** MIME trailer environment from the request */
1052     apr_table_t *trailers_in;
1053     /** MIME trailer environment from the response */
1054     apr_table_t *trailers_out;
1055 };
1056
1057 /**
1058  * @defgroup ProxyReq Proxy request types
1059  *
1060  * Possible values of request_rec->proxyreq. A request could be normal,
1061  *  proxied or reverse proxied. Normally proxied and reverse proxied are
1062  *  grouped together as just "proxied", but sometimes it's necessary to
1063  *  tell the difference between the two, such as for authentication.
1064  * @{
1065  */
1066
1067 #define PROXYREQ_NONE     0     /**< No proxy */
1068 #define PROXYREQ_PROXY    1     /**< Standard proxy */
1069 #define PROXYREQ_REVERSE  2     /**< Reverse proxy */
1070 #define PROXYREQ_RESPONSE 3     /**< Origin response */
1071
1072 /* @} */
1073
1074 /**
1075  * @brief Enumeration of connection keepalive options
1076  */
1077 typedef enum {
1078     AP_CONN_UNKNOWN,
1079     AP_CONN_CLOSE,
1080     AP_CONN_KEEPALIVE
1081 } ap_conn_keepalive_e;
1082
1083 /**
1084  * @brief Structure to store things which are per connection
1085  */
1086 struct conn_rec {
1087     /** Pool associated with this connection */
1088     apr_pool_t *pool;
1089     /** Physical vhost this conn came in on */
1090     server_rec *base_server;
1091     /** used by http_vhost.c */
1092     void *vhost_lookup_data;
1093
1094     /* Information about the connection itself */
1095     /** local address */
1096     apr_sockaddr_t *local_addr;
1097     /** remote address; this is the end-point of the next hop, for the address
1098      *  of the request creator, see useragent_addr in request_rec
1099      */
1100     apr_sockaddr_t *client_addr;
1101
1102     /** Client's IP address; this is the end-point of the next hop, for the
1103      *  IP of the request creator, see useragent_ip in request_rec
1104      */
1105     char *client_ip;
1106     /** Client's DNS name, if known.  NULL if DNS hasn't been checked,
1107      *  "" if it has and no address was found.  N.B. Only access this though
1108      * get_remote_host() */
1109     char *remote_host;
1110     /** Only ever set if doing rfc1413 lookups.  N.B. Only access this through
1111      *  get_remote_logname() */
1112     char *remote_logname;
1113
1114     /** server IP address */
1115     char *local_ip;
1116     /** used for ap_get_server_name when UseCanonicalName is set to DNS
1117      *  (ignores setting of HostnameLookups) */
1118     char *local_host;
1119
1120     /** ID of this connection; unique at any point in time */
1121     long id;
1122     /** Config vector containing pointers to connections per-server
1123      *  config structures. */
1124     struct ap_conf_vector_t *conn_config;
1125     /** Notes on *this* connection: send note from one module to
1126      *  another. must remain valid for all requests on this conn */
1127     apr_table_t *notes;
1128     /** A list of input filters to be used for this connection */
1129     struct ap_filter_t *input_filters;
1130     /** A list of output filters to be used for this connection */
1131     struct ap_filter_t *output_filters;
1132     /** handle to scoreboard information for this connection */
1133     void *sbh;
1134     /** The bucket allocator to use for all bucket/brigade creations */
1135     struct apr_bucket_alloc_t *bucket_alloc;
1136     /** The current state of this connection; may be NULL if not used by MPM */
1137     conn_state_t *cs;
1138     /** Is there data pending in the input filters? */
1139     int data_in_input_filters;
1140     /** No longer used, replaced with ap_filter_should_yield() */
1141     int data_in_output_filters;
1142
1143     /** Are there any filters that clogg/buffer the input stream, breaking
1144      *  the event mpm.
1145      */
1146     unsigned int clogging_input_filters:1;
1147
1148     /** have we done double-reverse DNS? -1 yes/failure, 0 not yet,
1149      *  1 yes/success */
1150     signed int double_reverse:2;
1151
1152     /** Are we still talking? */
1153     unsigned aborted;
1154
1155     /** Are we going to keep the connection alive for another request?
1156      * @see ap_conn_keepalive_e */
1157     ap_conn_keepalive_e keepalive;
1158
1159     /** How many times have we used it? */
1160     int keepalives;
1161
1162     /** Optional connection log level configuration. May point to a server or
1163      *  per_dir config, i.e. must be copied before modifying */
1164     const struct ap_logconf *log;
1165
1166     /** Id to identify this connection in error log. Set when the first
1167      *  error log entry for this connection is generated.
1168      */
1169     const char *log_id;
1170
1171
1172     /** This points to the current thread being used to process this request,
1173      * over the lifetime of a request, the value may change. Users of the connection
1174      * record should not rely upon it staying the same between calls that involve
1175      * the MPM.
1176      */
1177 #if APR_HAS_THREADS
1178     apr_thread_t *current_thread;
1179 #endif
1180
1181     /** Array of slave connections (conn_slave_rec *) for this connection. */
1182     apr_array_header_t *slaves;
1183
1184     /** The "real" master connection. NULL if I am the master. */
1185     conn_rec *master;
1186
1187     /** context of this connection */
1188     void *ctx;
1189
1190     /** Context under which this connection was suspended */
1191     void *suspended_baton;
1192
1193     /** Array of requests being handled under this connection. */
1194     apr_array_header_t *requests;
1195
1196     /** Empty bucket brigade */
1197     apr_bucket_brigade *empty;
1198
1199     /** Hashtable of filters with setaside buckets for write completion */
1200     apr_hash_t *filters;
1201 };
1202
1203 struct conn_slave_rec {
1204   conn_rec *c;
1205 };
1206
1207 /**
1208  * Enumeration of connection states
1209  * The two states CONN_STATE_LINGER_NORMAL and CONN_STATE_LINGER_SHORT may
1210  * only be set by the MPM. Use CONN_STATE_LINGER outside of the MPM.
1211  */
1212 typedef enum  {
1213     CONN_STATE_CHECK_REQUEST_LINE_READABLE,
1214     CONN_STATE_READ_REQUEST_LINE,
1215     CONN_STATE_HANDLER,
1216     CONN_STATE_WRITE_COMPLETION,
1217     CONN_STATE_SUSPENDED,
1218     CONN_STATE_LINGER,          /* connection may be closed with lingering */
1219     CONN_STATE_LINGER_NORMAL,   /* MPM has started lingering close with normal timeout */
1220     CONN_STATE_LINGER_SHORT     /* MPM has started lingering close with short timeout */
1221 } conn_state_e;
1222
1223 typedef enum  {
1224     CONN_SENSE_DEFAULT,
1225     CONN_SENSE_WANT_READ,       /* next event must be read */
1226     CONN_SENSE_WANT_WRITE       /* next event must be write */
1227 } conn_sense_e;
1228
1229 /**
1230  * @brief A structure to contain connection state information
1231  */
1232 struct conn_state_t {
1233     /** Current state of the connection */
1234     conn_state_e state;
1235     /** Whether to read instead of write, or write instead of read */
1236     conn_sense_e sense;
1237 };
1238
1239 /* Per-vhost config... */
1240
1241 /**
1242  * The address 255.255.255.255, when used as a virtualhost address,
1243  * will become the "default" server when the ip doesn't match other vhosts.
1244  */
1245 #define DEFAULT_VHOST_ADDR 0xfffffffful
1246
1247
1248 /**
1249  * @struct server_addr_rec
1250  * @brief  A structure to be used for Per-vhost config
1251  */
1252 typedef struct server_addr_rec server_addr_rec;
1253 struct server_addr_rec {
1254     /** The next server in the list */
1255     server_addr_rec *next;
1256     /** The name given in "<VirtualHost>" */
1257     char *virthost;
1258     /** The bound address, for this server */
1259     apr_sockaddr_t *host_addr;
1260     /** The bound port, for this server */
1261     apr_port_t host_port;
1262 };
1263
1264 struct ap_logconf {
1265     /** The per-module log levels */
1266     signed char *module_levels;
1267
1268     /** The log level for this server */
1269     int level;
1270 };
1271 /**
1272  * @brief A structure to store information for each virtual server
1273  */
1274 struct server_rec {
1275     /** The process this server is running in */
1276     process_rec *process;
1277     /** The next server in the list */
1278     server_rec *next;
1279
1280     /* Log files --- note that transfer log is now in the modules... */
1281
1282     /** The name of the error log */
1283     char *error_fname;
1284     /** A file descriptor that references the error log */
1285     apr_file_t *error_log;
1286     /** The log level configuration */
1287     struct ap_logconf log;
1288     /** External error log writer provider */
1289     struct ap_errorlog_provider *errorlog_provider;
1290     /** Handle to be passed to external log provider's logging method */
1291     void *errorlog_provider_handle;
1292
1293     /* Module-specific configuration for server, and defaults... */
1294
1295     /** Config vector containing pointers to modules' per-server config
1296      *  structures. */
1297     struct ap_conf_vector_t *module_config;
1298     /** MIME type info, etc., before we start checking per-directory info */
1299     struct ap_conf_vector_t *lookup_defaults;
1300
1301     /** The name of the server */
1302     const char *defn_name;
1303     /** The line of the config file that the server was defined on */
1304     unsigned defn_line_number;
1305     /** true if this is the virtual server */
1306     char is_virtual;
1307
1308
1309     /* Information for redirects */
1310
1311     /** for redirects, etc. */
1312     apr_port_t port;
1313     /** The server request scheme for redirect responses */
1314     const char *server_scheme;
1315
1316     /* Contact information */
1317
1318     /** The admin's contact information */
1319     char *server_admin;
1320     /** The server hostname */
1321     char *server_hostname;
1322
1323     /* Transaction handling */
1324
1325     /** I haven't got a clue */
1326     server_addr_rec *addrs;
1327     /** Timeout, as an apr interval, before we give up */
1328     apr_interval_time_t timeout;
1329     /** The apr interval we will wait for another request */
1330     apr_interval_time_t keep_alive_timeout;
1331     /** Maximum requests per connection */
1332     int keep_alive_max;
1333     /** Use persistent connections? */
1334     int keep_alive;
1335
1336     /** Normal names for ServerAlias servers */
1337     apr_array_header_t *names;
1338     /** Wildcarded names for ServerAlias servers */
1339     apr_array_header_t *wild_names;
1340
1341     /** Pathname for ServerPath */
1342     const char *path;
1343     /** Length of path */
1344     int pathlen;
1345
1346     /** limit on size of the HTTP request line    */
1347     int limit_req_line;
1348     /** limit on size of any request header field */
1349     int limit_req_fieldsize;
1350     /** limit on number of request header fields  */
1351     int limit_req_fields;
1352
1353     /** Opaque storage location */
1354     void *context;
1355
1356     /** Whether the keepalive timeout is explicit (1) or
1357      *  inherited (0) from the base server (either first
1358      *  server on the same IP:port or main server) */
1359     unsigned int keep_alive_timeout_set:1;
1360 };
1361
1362 /**
1363  * @struct ap_sload_t
1364  * @brief  A structure to hold server load params
1365  */
1366 typedef struct ap_sload_t ap_sload_t;
1367 struct ap_sload_t {
1368     /* percentage of process/threads ready/idle (0->100)*/
1369     int idle;
1370     /* percentage of process/threads busy (0->100) */
1371     int busy;
1372     /* total bytes served */
1373     apr_off_t bytes_served;
1374     /* total access count */
1375     unsigned long access_count;
1376 };
1377
1378 /**
1379  * @struct ap_loadavg_t
1380  * @brief  A structure to hold various server loadavg
1381  */
1382 typedef struct ap_loadavg_t ap_loadavg_t;
1383 struct ap_loadavg_t {
1384     /* current loadavg, ala getloadavg() */
1385     float loadavg;
1386     /* 5 min loadavg */
1387     float loadavg5;
1388     /* 15 min loadavg */
1389     float loadavg15;
1390 };
1391
1392 /**
1393  * Get the context_document_root for a request. This is a generalization of
1394  * the document root, which is too limited in the presence of mappers like
1395  * mod_userdir and mod_alias. The context_document_root is the directory
1396  * on disk that maps to the context_prefix URI prefix.
1397  * @param r The request
1398  * @note For resources that do not map to the file system or for very complex
1399  * mappings, this information may still be wrong.
1400  */
1401 AP_DECLARE(const char *) ap_context_document_root(request_rec *r);
1402
1403 /**
1404  * Get the context_prefix for a request. The context_prefix URI prefix
1405  * maps to the context_document_root on disk.
1406  * @param r The request
1407  */
1408 AP_DECLARE(const char *) ap_context_prefix(request_rec *r);
1409
1410 /** Set context_prefix and context_document_root for a request.
1411  * @param r The request
1412  * @param prefix the URI prefix, without trailing slash
1413  * @param document_root the corresponding directory on disk, without trailing
1414  * slash
1415  * @note If one of prefix of document_root is NULL, the corrsponding
1416  * property will not be changed.
1417  */
1418 AP_DECLARE(void) ap_set_context_info(request_rec *r, const char *prefix,
1419                                      const char *document_root);
1420
1421 /** Set per-request document root. This is for mass virtual hosting modules
1422  * that want to provide the correct DOCUMENT_ROOT value to scripts.
1423  * @param r The request
1424  * @param document_root the document root for the request.
1425  */
1426 AP_DECLARE(void) ap_set_document_root(request_rec *r, const char *document_root);
1427
1428 /**
1429  * Examine a field value (such as a media-/content-type) string and return
1430  * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
1431  * @param p Pool to allocate memory from
1432  * @param intype The field to examine
1433  * @return A copy of the field minus any parameters
1434  */
1435 AP_DECLARE(char *) ap_field_noparam(apr_pool_t *p, const char *intype);
1436
1437 /**
1438  * Convert a time from an integer into a string in a specified format
1439  * @param p The pool to allocate memory from
1440  * @param t The time to convert
1441  * @param fmt The format to use for the conversion
1442  * @param gmt Convert the time for GMT?
1443  * @return The string that represents the specified time
1444  */
1445 AP_DECLARE(char *) ap_ht_time(apr_pool_t *p, apr_time_t t, const char *fmt, int gmt);
1446
1447 /* String handling. The *_nc variants allow you to use non-const char **s as
1448    arguments (unfortunately C won't automatically convert a char ** to a const
1449    char **) */
1450
1451 /**
1452  * Get the characters until the first occurrence of a specified character
1453  * @param p The pool to allocate memory from
1454  * @param line The string to get the characters from
1455  * @param stop The character to stop at
1456  * @return A copy of the characters up to the first stop character
1457  */
1458 AP_DECLARE(char *) ap_getword(apr_pool_t *p, const char **line, char stop);
1459
1460 /**
1461  * Get the characters until the first occurrence of a specified character
1462  * @param p The pool to allocate memory from
1463  * @param line The string to get the characters from
1464  * @param stop The character to stop at
1465  * @return A copy of the characters up to the first stop character
1466  * @note This is the same as ap_getword(), except it doesn't use const char **.
1467  */
1468 AP_DECLARE(char *) ap_getword_nc(apr_pool_t *p, char **line, char stop);
1469
1470 /**
1471  * Get the first word from a given string.  A word is defined as all characters
1472  * up to the first whitespace.
1473  * @param p The pool to allocate memory from
1474  * @param line The string to traverse
1475  * @return The first word in the line
1476  */
1477 AP_DECLARE(char *) ap_getword_white(apr_pool_t *p, const char **line);
1478
1479 /**
1480  * Get the first word from a given string.  A word is defined as all characters
1481  * up to the first whitespace.
1482  * @param p The pool to allocate memory from
1483  * @param line The string to traverse
1484  * @return The first word in the line
1485  * @note The same as ap_getword_white(), except it doesn't use const char**
1486  */
1487 AP_DECLARE(char *) ap_getword_white_nc(apr_pool_t *p, char **line);
1488
1489 /**
1490  * Get all characters from the first occurrence of @a stop to the first "\0"
1491  * @param p The pool to allocate memory from
1492  * @param line The line to traverse
1493  * @param stop The character to start at
1494  * @return A copy of all characters after the first occurrence of the specified
1495  *         character
1496  */
1497 AP_DECLARE(char *) ap_getword_nulls(apr_pool_t *p, const char **line,
1498                                     char stop);
1499
1500 /**
1501  * Get all characters from the first occurrence of @a stop to the first "\0"
1502  * @param p The pool to allocate memory from
1503  * @param line The line to traverse
1504  * @param stop The character to start at
1505  * @return A copy of all characters after the first occurrence of the specified
1506  *         character
1507  * @note The same as ap_getword_nulls(), except it doesn't use const char **.
1508  */
1509 AP_DECLARE(char *) ap_getword_nulls_nc(apr_pool_t *p, char **line, char stop);
1510
1511 /**
1512  * Get the second word in the string paying attention to quoting
1513  * @param p The pool to allocate from
1514  * @param line The line to traverse
1515  * @return A copy of the string
1516  */
1517 AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line);
1518
1519 /**
1520  * Get the second word in the string paying attention to quoting
1521  * @param p The pool to allocate from
1522  * @param line The line to traverse
1523  * @return A copy of the string
1524  * @note The same as ap_getword_conf(), except it doesn't use const char **.
1525  */
1526 AP_DECLARE(char *) ap_getword_conf_nc(apr_pool_t *p, char **line);
1527
1528 /**
1529  * Check a string for any config define or environment variable construct
1530  * and replace each of them by the value of that variable, if it exists.
1531  * The default syntax of the constructs is ${ENV} but can be changed by
1532  * setting the define::* config defines. If the variable does not exist,
1533  * leave the ${ENV} construct alone but print a warning.
1534  * @param p The pool to allocate from
1535  * @param word The string to check
1536  * @return The string with the replaced environment variables
1537  */
1538 AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word);
1539
1540 /**
1541  * Size an HTTP header field list item, as separated by a comma.
1542  * @param field The field to size
1543  * @param len The length of the field
1544  * @return The return value is a pointer to the beginning of the non-empty
1545  * list item within the original string (or NULL if there is none) and the
1546  * address of field is shifted to the next non-comma, non-whitespace
1547  * character.  len is the length of the item excluding any beginning whitespace.
1548  */
1549 AP_DECLARE(const char *) ap_size_list_item(const char **field, int *len);
1550
1551 /**
1552  * Retrieve an HTTP header field list item, as separated by a comma,
1553  * while stripping insignificant whitespace and lowercasing anything not in
1554  * a quoted string or comment.
1555  * @param p The pool to allocate from
1556  * @param field The field to retrieve
1557  * @return The return value is a new string containing the converted list
1558  *         item (or NULL if none) and the address pointed to by field is
1559  *         shifted to the next non-comma, non-whitespace.
1560  */
1561 AP_DECLARE(char *) ap_get_list_item(apr_pool_t *p, const char **field);
1562
1563 /**
1564  * Find an item in canonical form (lowercase, no extra spaces) within
1565  * an HTTP field value list.
1566  * @param p The pool to allocate from
1567  * @param line The field value list to search
1568  * @param tok The token to search for
1569  * @return 1 if found, 0 if not found.
1570  */
1571 AP_DECLARE(int) ap_find_list_item(apr_pool_t *p, const char *line, const char *tok);
1572
1573 /**
1574  * Do a weak ETag comparison within an HTTP field value list.
1575  * @param p The pool to allocate from
1576  * @param line The field value list to search
1577  * @param tok The token to search for
1578  * @return 1 if found, 0 if not found.
1579  */
1580 AP_DECLARE(int) ap_find_etag_weak(apr_pool_t *p, const char *line, const char *tok);
1581
1582 /**
1583  * Do a strong ETag comparison within an HTTP field value list.
1584  * @param p The pool to allocate from
1585  * @param line The field value list to search
1586  * @param tok The token to search for
1587  * @return 1 if found, 0 if not found.
1588  */
1589 AP_DECLARE(int) ap_find_etag_strong(apr_pool_t *p, const char *line, const char *tok);
1590
1591 /**
1592  * Retrieve an array of tokens in the format "1#token" defined in RFC2616. Only
1593  * accepts ',' as a delimiter, does not accept quoted strings, and errors on
1594  * any separator.
1595  * @param p The pool to allocate from
1596  * @param tok The line to read tokens from
1597  * @param tokens Pointer to an array of tokens. If not NULL, must be an array
1598  *    of char*, otherwise it will be allocated on @a p when a token is found
1599  * @param skip_invalid If true, when an invalid separator is encountered, it
1600  *    will be ignored.
1601  * @return NULL on success, an error string otherwise.
1602  * @remark *tokens may be NULL on output if NULL in input and no token is found
1603  */
1604 AP_DECLARE(const char *) ap_parse_token_list_strict(apr_pool_t *p, const char *tok,
1605                                                     apr_array_header_t **tokens,
1606                                                     int skip_invalid);
1607
1608 /**
1609  * Retrieve a token, spacing over it and adjusting the pointer to
1610  * the first non-white byte afterwards.  Note that these tokens
1611  * are delimited by semis and commas and can also be delimited
1612  * by whitespace at the caller's option.
1613  * @param p The pool to allocate from
1614  * @param accept_line The line to retrieve the token from (adjusted afterwards)
1615  * @param accept_white Is it delimited by whitespace
1616  * @return the token
1617  */
1618 AP_DECLARE(char *) ap_get_token(apr_pool_t *p, const char **accept_line, int accept_white);
1619
1620 /**
1621  * Find http tokens, see the definition of token from RFC2068
1622  * @param p The pool to allocate from
1623  * @param line The line to find the token
1624  * @param tok The token to find
1625  * @return 1 if the token is found, 0 otherwise
1626  */
1627 AP_DECLARE(int) ap_find_token(apr_pool_t *p, const char *line, const char *tok);
1628
1629 /**
1630  * find http tokens from the end of the line
1631  * @param p The pool to allocate from
1632  * @param line The line to find the token
1633  * @param tok The token to find
1634  * @return 1 if the token is found, 0 otherwise
1635  */
1636 AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line, const char *tok);
1637
1638 /**
1639  * Check for an Absolute URI syntax
1640  * @param u The string to check
1641  * @return 1 if URI, 0 otherwise
1642  */
1643 AP_DECLARE(int) ap_is_url(const char *u);
1644
1645 /**
1646  * Unescape a string
1647  * @param url The string to unescape
1648  * @return 0 on success, non-zero otherwise
1649  */
1650 AP_DECLARE(int) ap_unescape_all(char *url);
1651
1652 /**
1653  * Unescape a URL
1654  * @param url The url to unescape
1655  * @return 0 on success, non-zero otherwise
1656  * @deprecated Replaced by apr_unescape_url() in APR
1657  */
1658 AP_DECLARE(int) ap_unescape_url(char *url);
1659
1660 /**
1661  * Unescape a URL, but leaving %2f (slashes) escaped
1662  * @param url The url to unescape
1663  * @param decode_slashes Whether or not slashes should be decoded
1664  * @return 0 on success, non-zero otherwise
1665  * @deprecated Replaced by apr_unescape_url() in APR
1666  */
1667 AP_DECLARE(int) ap_unescape_url_keep2f(char *url, int decode_slashes);
1668
1669 /**
1670  * Unescape an application/x-www-form-urlencoded string
1671  * @param query The query to unescape
1672  * @return 0 on success, non-zero otherwise
1673  * @deprecated Replaced by apr_unescape_url() in APR
1674  */
1675 AP_DECLARE(int) ap_unescape_urlencoded(char *query);
1676
1677 /**
1678  * Convert all double slashes to single slashes
1679  * @param name The string to convert
1680  */
1681 AP_DECLARE(void) ap_no2slash(char *name)
1682                  AP_FN_ATTR_NONNULL_ALL;
1683
1684 /**
1685  * Remove all ./ and xx/../ substrings from a file name. Also remove
1686  * any leading ../ or /../ substrings.
1687  * @param name the file name to parse
1688  */
1689 AP_DECLARE(void) ap_getparents(char *name)
1690                  AP_FN_ATTR_NONNULL_ALL;
1691
1692 /**
1693  * Escape a path segment, as defined in RFC 1808
1694  * @param p The pool to allocate from
1695  * @param s The path to convert
1696  * @return The converted URL
1697  * @deprecated Replaced by apr_pescape_path_segment() in APR
1698  */
1699 AP_DECLARE(char *) ap_escape_path_segment(apr_pool_t *p, const char *s)
1700                    AP_FN_ATTR_NONNULL_ALL;
1701
1702 /**
1703  * Escape a path segment, as defined in RFC 1808, to a preallocated buffer.
1704  * @param c The preallocated buffer to write to
1705  * @param s The path to convert
1706  * @return The converted URL (c)
1707  * @deprecated Replaced by apr_escape_path_segment() in APR
1708  */
1709 AP_DECLARE(char *) ap_escape_path_segment_buffer(char *c, const char *s)
1710                    AP_FN_ATTR_NONNULL_ALL;
1711
1712 /**
1713  * convert an OS path to a URL in an OS dependent way.
1714  * @param p The pool to allocate from
1715  * @param path The path to convert
1716  * @param partial if set, assume that the path will be appended to something
1717  *        with a '/' in it (and thus does not prefix "./").
1718  * @return The converted URL, with one byte of extra space after the NUL
1719  *         to allow the caller to add a trailing '/'. 
1720  * @deprecated Replaced by apr_pescape_path() in APR
1721  */
1722 AP_DECLARE(char *) ap_os_escape_path(apr_pool_t *p, const char *path, int partial)
1723                    AP_FN_ATTR_NONNULL_ALL;
1724
1725 /** @see ap_os_escape_path */
1726 #define ap_escape_uri(ppool,path) ap_os_escape_path(ppool,path,1)
1727
1728 /**
1729  * Escape a string as application/x-www-form-urlencoded
1730  * @param p The pool to allocate from
1731  * @param s The path to convert
1732  * @return The converted URL
1733  * @deprecated Replaced by apr_pescape_url() in APR
1734  */
1735 AP_DECLARE(char *) ap_escape_urlencoded(apr_pool_t *p, const char *s)
1736                    AP_FN_ATTR_NONNULL_ALL;
1737
1738 /**
1739  * Escape a string as application/x-www-form-urlencoded, to a preallocated buffer
1740  * @param c The preallocated buffer to write to
1741  * @param s The path to convert
1742  * @return The converted URL (c)
1743  * @deprecated Replaced by apr_escape_url() in APR
1744  */
1745 AP_DECLARE(char *) ap_escape_urlencoded_buffer(char *c, const char *s)
1746                    AP_FN_ATTR_NONNULL_ALL;
1747
1748 /**
1749  * Escape an html string
1750  * @param p The pool to allocate from
1751  * @param s The html to escape
1752  * @return The escaped string
1753  * @deprecated Replaced by apr_pescape_entity() in APR
1754  */
1755 #define ap_escape_html(p,s) ap_escape_html2(p,s,0)
1756 /**
1757  * Escape an html string
1758  * @param p The pool to allocate from
1759  * @param s The html to escape
1760  * @param toasc Whether to escape all non-ASCII chars to \&\#nnn;
1761  * @return The escaped string
1762  * @deprecated Replaced by apr_pescape_entity() in APR
1763  */
1764 AP_DECLARE(char *) ap_escape_html2(apr_pool_t *p, const char *s, int toasc)
1765                    AP_FN_ATTR_NONNULL_ALL;
1766
1767 /**
1768  * Escape a string for logging
1769  * @param p The pool to allocate from
1770  * @param str The string to escape
1771  * @return The escaped string
1772  * @deprecated Replaced by apr_pescape_echo() in APR
1773  */
1774 AP_DECLARE(char *) ap_escape_logitem(apr_pool_t *p, const char *str)
1775                    AP_FN_ATTR_NONNULL((1));
1776
1777 /**
1778  * Escape a string for logging into the error log (without a pool)
1779  * @param dest The buffer to write to
1780  * @param source The string to escape
1781  * @param buflen The buffer size for the escaped string (including "\0")
1782  * @return The len of the escaped string (always < maxlen)
1783  * @deprecated Replaced by apr_escape_echo() in APR
1784  */
1785 AP_DECLARE(apr_size_t) ap_escape_errorlog_item(char *dest, const char *source,
1786                                                apr_size_t buflen)
1787                        AP_FN_ATTR_NONNULL((1));
1788
1789 /**
1790  * Construct a full hostname
1791  * @param p The pool to allocate from
1792  * @param hostname The hostname of the server
1793  * @param port The port the server is running on
1794  * @param r The current request
1795  * @return The server's hostname
1796  */
1797 AP_DECLARE(char *) ap_construct_server(apr_pool_t *p, const char *hostname,
1798                                     apr_port_t port, const request_rec *r)
1799                    AP_FN_ATTR_NONNULL((1,4));
1800
1801 /**
1802  * Escape a shell command
1803  * @param p The pool to allocate from
1804  * @param s The command to escape
1805  * @return The escaped shell command
1806  * @deprecated Replaced with apr_escape_shell() in APR
1807  */
1808 AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *s)
1809                    AP_FN_ATTR_NONNULL_ALL;
1810
1811 /**
1812  * Count the number of directories in a path
1813  * @param path The path to count
1814  * @return The number of directories
1815  */
1816 AP_DECLARE(int) ap_count_dirs(const char *path)
1817                 AP_FN_ATTR_NONNULL_ALL;
1818
1819 /**
1820  * Copy at most @a n leading directories of @a s into @a d. @a d
1821  * should be at least as large as @a s plus 1 extra byte
1822  *
1823  * @param d The location to copy to
1824  * @param s The location to copy from
1825  * @param n The number of directories to copy
1826  * @return value is the ever useful pointer to the trailing "\0" of d
1827  * @note on platforms with drive letters, n = 0 returns the "/" root,
1828  * whereas n = 1 returns the "d:/" root.  On all other platforms, n = 0
1829  * returns the empty string.  */
1830 AP_DECLARE(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
1831                    AP_FN_ATTR_NONNULL_ALL;
1832
1833 /**
1834  * Return the parent directory name (including trailing /) of the file
1835  * @a s
1836  * @param p The pool to allocate from
1837  * @param s The file to get the parent of
1838  * @return A copy of the file's parent directory
1839  */
1840 AP_DECLARE(char *) ap_make_dirstr_parent(apr_pool_t *p, const char *s)
1841                    AP_FN_ATTR_NONNULL_ALL;
1842
1843 /**
1844  * Given a directory and filename, create a single path from them.  This
1845  * function is smart enough to ensure that there is a single '/' between the
1846  * directory and file names
1847  * @param a The pool to allocate from
1848  * @param dir The directory name
1849  * @param f The filename
1850  * @return A copy of the full path, with one byte of extra space after the NUL
1851  *         to allow the caller to add a trailing '/'.
1852  * @note Never consider using this function if you are dealing with filesystem
1853  * names that need to remain canonical, unless you are merging an apr_dir_read
1854  * path and returned filename.  Otherwise, the result is not canonical.
1855  */
1856 AP_DECLARE(char *) ap_make_full_path(apr_pool_t *a, const char *dir, const char *f)
1857                    AP_FN_ATTR_NONNULL_ALL;
1858
1859 /**
1860  * Test if the given path has an absolute path.
1861  * @param p The pool to allocate from
1862  * @param dir The directory name
1863  * @note The converse is not necessarily true, some OS's (Win32/OS2/Netware) have
1864  * multiple forms of absolute paths.  This only reports if the path is absolute
1865  * in a canonical sense.
1866  */
1867 AP_DECLARE(int) ap_os_is_path_absolute(apr_pool_t *p, const char *dir)
1868                 AP_FN_ATTR_NONNULL_ALL;
1869
1870 /**
1871  * Does the provided string contain wildcard characters?  This is useful
1872  * for determining if the string should be passed to strcmp_match or to strcmp.
1873  * The only wildcard characters recognized are '?' and '*'
1874  * @param str The string to check
1875  * @return 1 if the string has wildcards, 0 otherwise
1876  */
1877 AP_DECLARE(int) ap_is_matchexp(const char *str)
1878                 AP_FN_ATTR_NONNULL_ALL;
1879
1880 /**
1881  * Determine if a string matches a patterm containing the wildcards '?' or '*'
1882  * @param str The string to check
1883  * @param expected The pattern to match against
1884  * @return 0 if the two strings match, 1 otherwise
1885  */
1886 AP_DECLARE(int) ap_strcmp_match(const char *str, const char *expected)
1887                 AP_FN_ATTR_NONNULL_ALL;
1888
1889 /**
1890  * Determine if a string matches a patterm containing the wildcards '?' or '*',
1891  * ignoring case
1892  * @param str The string to check
1893  * @param expected The pattern to match against
1894  * @return 0 if the two strings match, 1 otherwise
1895  */
1896 AP_DECLARE(int) ap_strcasecmp_match(const char *str, const char *expected)
1897                 AP_FN_ATTR_NONNULL_ALL;
1898
1899 /**
1900  * Find the first occurrence of the substring s2 in s1, regardless of case
1901  * @param s1 The string to search
1902  * @param s2 The substring to search for
1903  * @return A pointer to the beginning of the substring
1904  * @remark See apr_strmatch() for a faster alternative
1905  */
1906 AP_DECLARE(char *) ap_strcasestr(const char *s1, const char *s2)
1907                    AP_FN_ATTR_NONNULL_ALL;
1908
1909 /**
1910  * Return a pointer to the location inside of bigstring immediately after prefix
1911  * @param bigstring The input string
1912  * @param prefix The prefix to strip away
1913  * @return A pointer relative to bigstring after prefix
1914  */
1915 AP_DECLARE(const char *) ap_stripprefix(const char *bigstring,
1916                                         const char *prefix)
1917                          AP_FN_ATTR_NONNULL_ALL;
1918
1919 /**
1920  * Decode a base64 encoded string into memory allocated from a pool
1921  * @param p The pool to allocate from
1922  * @param bufcoded The encoded string
1923  * @return The decoded string
1924  * @deprecated Replaced by apr_pbase64_decode() in APR.
1925  */
1926 AP_DECLARE(char *) ap_pbase64decode(apr_pool_t *p, const char *bufcoded);
1927
1928 /**
1929  * Encode a string into memory allocated from a pool in base 64 format
1930  * @param p The pool to allocate from
1931  * @param string The plaintext string
1932  * @return The encoded string
1933  * @deprecated Replaced by apr_pbase64_encode() in APR.
1934  */
1935 AP_DECLARE(char *) ap_pbase64encode(apr_pool_t *p, char *string);
1936
1937 /**
1938  * Compile a regular expression to be used later. The regex is freed when
1939  * the pool is destroyed.
1940  * @param p The pool to allocate from
1941  * @param pattern the regular expression to compile
1942  * @param cflags The bitwise or of one or more of the following:
1943  *   @li REG_EXTENDED - Use POSIX extended Regular Expressions
1944  *   @li REG_ICASE    - Ignore case
1945  *   @li REG_NOSUB    - Support for substring addressing of matches
1946  *       not required
1947  *   @li REG_NEWLINE  - Match-any-character operators don't match new-line
1948  * @return The compiled regular expression
1949  */
1950 AP_DECLARE(ap_regex_t *) ap_pregcomp(apr_pool_t *p, const char *pattern,
1951                                      int cflags);
1952
1953 /**
1954  * Free the memory associated with a compiled regular expression
1955  * @param p The pool the regex was allocated from
1956  * @param reg The regular expression to free
1957  * @note This function is only necessary if the regex should be cleaned
1958  * up before the pool
1959  */
1960 AP_DECLARE(void) ap_pregfree(apr_pool_t *p, ap_regex_t *reg);
1961
1962 /**
1963  * After performing a successful regex match, you may use this function to
1964  * perform a series of string substitutions based on subexpressions that were
1965  * matched during the call to ap_regexec. This function is limited to
1966  * result strings of 64K. Consider using ap_pregsub_ex() instead.
1967  * @param p The pool to allocate from
1968  * @param input An arbitrary string containing $1 through $9.  These are
1969  *              replaced with the corresponding matched sub-expressions
1970  * @param source The string that was originally matched to the regex
1971  * @param nmatch the nmatch returned from ap_pregex
1972  * @param pmatch the pmatch array returned from ap_pregex
1973  * @return The substituted string, or NULL on error
1974  */
1975 AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input,
1976                               const char *source, apr_size_t nmatch,
1977                               ap_regmatch_t pmatch[]);
1978
1979 /**
1980  * After performing a successful regex match, you may use this function to
1981  * perform a series of string substitutions based on subexpressions that were
1982  * matched during the call to ap_regexec
1983  * @param p The pool to allocate from
1984  * @param result where to store the result, will be set to NULL on error
1985  * @param input An arbitrary string containing $1 through $9.  These are
1986  *              replaced with the corresponding matched sub-expressions
1987  * @param source The string that was originally matched to the regex
1988  * @param nmatch the nmatch returned from ap_pregex
1989  * @param pmatch the pmatch array returned from ap_pregex
1990  * @param maxlen the maximum string length to return, 0 for unlimited
1991  * @return APR_SUCCESS if successful, APR_ENOMEM or other error code otherwise.
1992  */
1993 AP_DECLARE(apr_status_t) ap_pregsub_ex(apr_pool_t *p, char **result,
1994                                        const char *input, const char *source,
1995                                        apr_size_t nmatch,
1996                                        ap_regmatch_t pmatch[],
1997                                        apr_size_t maxlen);
1998
1999 /**
2000  * We want to downcase the type/subtype for comparison purposes
2001  * but nothing else because ;parameter=foo values are case sensitive.
2002  * @param s The content-type to convert to lowercase
2003  */
2004 AP_DECLARE(void) ap_content_type_tolower(char *s);
2005
2006 /**
2007  * convert a string to all lowercase
2008  * @param s The string to convert to lowercase
2009  */
2010 AP_DECLARE(void) ap_str_tolower(char *s);
2011
2012 /**
2013  * convert a string to all uppercase
2014  * @param s The string to convert to uppercase
2015  */
2016 AP_DECLARE(void) ap_str_toupper(char *s);
2017
2018 /**
2019  * Search a string from left to right for the first occurrence of a
2020  * specific character
2021  * @param str The string to search
2022  * @param c The character to search for
2023  * @return The index of the first occurrence of c in str
2024  */
2025 AP_DECLARE(int) ap_ind(const char *str, char c);        /* Sigh... */
2026
2027 /**
2028  * Search a string from right to left for the first occurrence of a
2029  * specific character
2030  * @param str The string to search
2031  * @param c The character to search for
2032  * @return The index of the first occurrence of c in str
2033  */
2034 AP_DECLARE(int) ap_rind(const char *str, char c);
2035
2036 /**
2037  * Given a string, replace any bare &quot; with \\&quot; .
2038  * @param p The pool to allocate memory from
2039  * @param instring The string to search for &quot;
2040  * @return A copy of the string with escaped quotes
2041  * @deprecated Replaced by apr_pescape_echo() in APR
2042  */
2043 AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring);
2044
2045 /**
2046  * Given a string, append the PID deliminated by delim.
2047  * Usually used to create a pid-appended filepath name
2048  * (eg: /a/b/foo -> /a/b/foo.6726). A function, and not
2049  * a macro, to avoid unistd.h dependency
2050  * @param p The pool to allocate memory from
2051  * @param string The string to append the PID to
2052  * @param delim The string to use to deliminate the string from the PID
2053  * @return A copy of the string with the PID appended
2054  */
2055 AP_DECLARE(char *) ap_append_pid(apr_pool_t *p, const char *string,
2056                                  const char *delim);
2057
2058 /**
2059  * Parse a given timeout parameter string into an apr_interval_time_t value.
2060  * The unit of the time interval is given as postfix string to the numeric
2061  * string. Currently the following units are understood:
2062  *
2063  * ms    : milliseconds
2064  * s     : seconds
2065  * mi[n] : minutes
2066  * h     : hours
2067  *
2068  * If no unit is contained in the given timeout parameter the default_time_unit
2069  * will be used instead.
2070  * @param timeout_parameter The string containing the timeout parameter.
2071  * @param timeout The timeout value to be returned.
2072  * @param default_time_unit The default time unit to use if none is specified
2073  * in timeout_parameter.
2074  * @return Status value indicating whether the parsing was successful or not.
2075  */
2076 AP_DECLARE(apr_status_t) ap_timeout_parameter_parse(
2077                                                const char *timeout_parameter,
2078                                                apr_interval_time_t *timeout,
2079                                                const char *default_time_unit);
2080
2081 /**
2082  * Determine if a request has a request body or not.
2083  *
2084  * @param r the request_rec of the request
2085  * @return truth value
2086  */
2087 AP_DECLARE(int) ap_request_has_body(request_rec *r);
2088
2089 /**
2090  * Cleanup a string (mainly to be filesystem safe)
2091  * We only allow '_' and alphanumeric chars. Non-printable
2092  * map to 'x' and all others map to '_'
2093  *
2094  * @param  p pool to use to allocate dest
2095  * @param  src string to clean up
2096  * @param  dest cleaned up, allocated string
2097  * @return Status value indicating whether the cleaning was successful or not.
2098  */
2099 AP_DECLARE(apr_status_t) ap_pstr2_alnum(apr_pool_t *p, const char *src,
2100                                         const char **dest);
2101
2102 /**
2103  * Cleanup a string (mainly to be filesystem safe)
2104  * We only allow '_' and alphanumeric chars. Non-printable
2105  * map to 'x' and all others map to '_'
2106  *
2107  * @param  src string to clean up
2108  * @param  dest cleaned up, pre-allocated string
2109  * @return Status value indicating whether the cleaning was successful or not.
2110  */
2111 AP_DECLARE(apr_status_t) ap_str2_alnum(const char *src, char *dest);
2112
2113 /**
2114  * Structure to store the contents of an HTTP form of the type
2115  * application/x-www-form-urlencoded.
2116  *
2117  * Currently it contains the name as a char* of maximum length
2118  * HUGE_STRING_LEN, and a value in the form of a bucket brigade
2119  * of arbitrary length.
2120  */
2121 typedef struct {
2122     const char *name;
2123     apr_bucket_brigade *value;
2124 } ap_form_pair_t;
2125
2126 /**
2127  * Read the body and parse any form found, which must be of the
2128  * type application/x-www-form-urlencoded.
2129  * @param r request containing POSTed form data
2130  * @param f filter
2131  * @param ptr returned array of ap_form_pair_t
2132  * @param num max num of params or -1 for unlimited
2133  * @param size max size allowed for parsed data
2134  * @return OK or HTTP error
2135  */
2136 AP_DECLARE(int) ap_parse_form_data(request_rec *r, struct ap_filter_t *f,
2137                                    apr_array_header_t **ptr,
2138                                    apr_size_t num, apr_size_t size);
2139
2140 /* Misc system hackery */
2141 /**
2142  * Given the name of an object in the file system determine if it is a directory
2143  * @param p The pool to allocate from
2144  * @param name The name of the object to check
2145  * @return 1 if it is a directory, 0 otherwise
2146  */
2147 AP_DECLARE(int) ap_is_rdirectory(apr_pool_t *p, const char *name);
2148
2149 /**
2150  * Given the name of an object in the file system determine if it is a directory - this version is symlink aware
2151  * @param p The pool to allocate from
2152  * @param name The name of the object to check
2153  * @return 1 if it is a directory, 0 otherwise
2154  */
2155 AP_DECLARE(int) ap_is_directory(apr_pool_t *p, const char *name);
2156
2157 #ifdef _OSD_POSIX
2158 extern int os_init_job_environment(server_rec *s, const char *user_name, int one_process);
2159 #endif /* _OSD_POSIX */
2160
2161 /**
2162  * Determine the local host name for the current machine
2163  * @param p The pool to allocate from
2164  * @return A copy of the local host name
2165  */
2166 char *ap_get_local_host(apr_pool_t *p);
2167
2168 /**
2169  * Log an assertion to the error log
2170  * @param szExp The assertion that failed
2171  * @param szFile The file the assertion is in
2172  * @param nLine The line the assertion is defined on
2173  */
2174 AP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile, int nLine)
2175                             __attribute__((noreturn));
2176
2177 /**
2178  * @internal Internal Assert function
2179  */
2180 #define ap_assert(exp) ((exp) ? (void)0 : ap_log_assert(#exp,__FILE__,__LINE__))
2181
2182 /**
2183  * Redefine assert() to something more useful for an Apache...
2184  *
2185  * Use ap_assert() if the condition should always be checked.
2186  * Use AP_DEBUG_ASSERT() if the condition should only be checked when AP_DEBUG
2187  * is defined.
2188  */
2189 #ifdef AP_DEBUG
2190 #define AP_DEBUG_ASSERT(exp) ap_assert(exp)
2191 #else
2192 #define AP_DEBUG_ASSERT(exp) ((void)0)
2193 #endif
2194
2195 /**
2196  * @defgroup stopsignal Flags which indicate places where the server should stop for debugging.
2197  * @{
2198  * A set of flags which indicate places where the server should raise(SIGSTOP).
2199  * This is useful for debugging, because you can then attach to that process
2200  * with gdb and continue.  This is important in cases where one_process
2201  * debugging isn't possible.
2202  */
2203 /** stop on a Detach */
2204 #define SIGSTOP_DETACH                  1
2205 /** stop making a child process */
2206 #define SIGSTOP_MAKE_CHILD              2
2207 /** stop spawning a child process */
2208 #define SIGSTOP_SPAWN_CHILD             4
2209 /** stop spawning a child process with a piped log */
2210 #define SIGSTOP_PIPED_LOG_SPAWN         8
2211 /** stop spawning a CGI child process */
2212 #define SIGSTOP_CGI_CHILD               16
2213
2214 /** Macro to get GDB started */
2215 #ifdef DEBUG_SIGSTOP
2216 extern int raise_sigstop_flags;
2217 #define RAISE_SIGSTOP(x)        do { \
2218         if (raise_sigstop_flags & SIGSTOP_##x) raise(SIGSTOP);\
2219     } while (0)
2220 #else
2221 #define RAISE_SIGSTOP(x)
2222 #endif
2223 /** @} */
2224 /**
2225  * Get HTML describing the address and (optionally) admin of the server.
2226  * @param prefix Text which is prepended to the return value
2227  * @param r The request_rec
2228  * @return HTML describing the server, allocated in @a r's pool.
2229  */
2230 AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r);
2231
2232   /* The C library has functions that allow const to be silently dropped ...
2233      these macros detect the drop in maintainer mode, but use the native
2234      methods for normal builds
2235
2236      Note that on some platforms (e.g., AIX with gcc, Solaris with gcc), string.h needs
2237      to be included before the macros are defined or compilation will fail.
2238   */
2239 #include <string.h>
2240
2241 AP_DECLARE(char *) ap_strchr(char *s, int c);
2242 AP_DECLARE(const char *) ap_strchr_c(const char *s, int c);
2243 AP_DECLARE(char *) ap_strrchr(char *s, int c);
2244 AP_DECLARE(const char *) ap_strrchr_c(const char *s, int c);
2245 AP_DECLARE(char *) ap_strstr(char *s, const char *c);
2246 AP_DECLARE(const char *) ap_strstr_c(const char *s, const char *c);
2247 AP_DECLARE(void *) ap_palloc_debug(apr_pool_t *p, apr_size_t size);
2248 AP_DECLARE(void *) ap_pcalloc_debug(apr_pool_t *p, apr_size_t size);
2249
2250 #ifdef AP_DEBUG
2251
2252 #undef strchr
2253 # define strchr(s, c)  ap_strchr(s,c)
2254 #undef strrchr
2255 # define strrchr(s, c) ap_strrchr(s,c)
2256 #undef strstr
2257 # define strstr(s, c)  ap_strstr(s,c)
2258
2259 #if !defined(AP_DEBUG_NO_ALLOC_POISON) && !APR_POOL_DEBUG
2260 /*
2261  * ap_palloc_debug initializes allocated memory to non-zero
2262  */
2263 #define apr_palloc     ap_palloc_debug
2264 /*
2265  * this is necessary to avoid useless double memset of memory
2266  * with ap_palloc_debug
2267  */
2268 #ifdef apr_pcalloc
2269 #undef apr_pcalloc
2270 #endif
2271 #define apr_pcalloc    ap_pcalloc_debug
2272 #endif
2273
2274 #else
2275
2276 /** use this instead of strchr */
2277 # define ap_strchr(s, c)     strchr(s, c)
2278 /** use this instead of strchr */
2279 # define ap_strchr_c(s, c)   strchr(s, c)
2280 /** use this instead of strrchr */
2281 # define ap_strrchr(s, c)    strrchr(s, c)
2282 /** use this instead of strrchr */
2283 # define ap_strrchr_c(s, c)  strrchr(s, c)
2284 /** use this instead of strrstr*/
2285 # define ap_strstr(s, c)     strstr(s, c)
2286 /** use this instead of strrstr*/
2287 # define ap_strstr_c(s, c)   strstr(s, c)
2288
2289 #endif
2290
2291 /**
2292  * Generate pseudo random bytes.
2293  * This is a convenience interface to apr_random. It is cheaper but less
2294  * secure than apr_generate_random_bytes().
2295  * @param buf where to store the bytes
2296  * @param size number of bytes to generate
2297  * @note ap_random_insecure_bytes() is thread-safe, it uses a mutex on
2298  *       threaded MPMs.
2299  */
2300 AP_DECLARE(void) ap_random_insecure_bytes(void *buf, apr_size_t size);
2301
2302 /**
2303  * Get a pseudo random number in a range.
2304  * @param min low end of range
2305  * @param max high end of range
2306  * @return a number in the range
2307  */
2308 AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max);
2309
2310 /**
2311  * Abort with a error message signifying out of memory
2312  */
2313 AP_DECLARE(void) ap_abort_on_oom(void) __attribute__((noreturn));
2314
2315 /**
2316  * Wrapper for malloc() that calls ap_abort_on_oom() if out of memory
2317  * @param size size of the memory block
2318  * @return pointer to the allocated memory
2319  * @note ap_malloc may be implemented as a macro
2320  */
2321 AP_DECLARE(void *) ap_malloc(size_t size)
2322                     __attribute__((malloc))
2323                     AP_FN_ATTR_ALLOC_SIZE(1);
2324
2325 /**
2326  * Wrapper for calloc() that calls ap_abort_on_oom() if out of memory
2327  * @param nelem number of elements to allocate memory for
2328  * @param size size of a single element
2329  * @return pointer to the allocated memory
2330  * @note ap_calloc may be implemented as a macro
2331  */
2332 AP_DECLARE(void *) ap_calloc(size_t nelem, size_t size)
2333                    __attribute__((malloc))
2334                    AP_FN_ATTR_ALLOC_SIZE2(1,2);
2335
2336 /**
2337  * Wrapper for realloc() that calls ap_abort_on_oom() if out of memory
2338  * @param ptr pointer to the old memory block (or NULL)
2339  * @param size new size of the memory block
2340  * @return pointer to the reallocated memory
2341  * @note ap_realloc may be implemented as a macro
2342  */
2343 AP_DECLARE(void *) ap_realloc(void *ptr, size_t size)
2344                    AP_FN_ATTR_WARN_UNUSED_RESULT
2345                    AP_FN_ATTR_ALLOC_SIZE(2);
2346
2347 /**
2348  * Get server load params
2349  * @param ld struct to populate: -1 in fields means error
2350  */
2351 AP_DECLARE(void) ap_get_sload(ap_sload_t *ld)
2352                  AP_FN_ATTR_NONNULL_ALL;
2353
2354 /**
2355  * Get server load averages (ala getloadavg)
2356  * @param ld struct to populate: -1 in fields means error
2357  */
2358 AP_DECLARE(void) ap_get_loadavg(ap_loadavg_t *ld)
2359                  AP_FN_ATTR_NONNULL_ALL;
2360
2361 /**
2362  * Convert binary data into a hex string
2363  * @param src pointer to the data
2364  * @param srclen length of the data
2365  * @param dest pointer to buffer of length (2 * srclen + 1). The resulting
2366  *        string will be NUL-terminated.
2367  * @deprecated Replaced by apr_escape_hex() in APR
2368  */
2369 AP_DECLARE(void) ap_bin2hex(const void *src, apr_size_t srclen, char *dest)
2370                  AP_FN_ATTR_NONNULL_ALL;
2371
2372 /**
2373  * Check if string contains a control character
2374  * @param str the string to check
2375  * @return 1 if yes, 0 if no control characters
2376  */
2377 AP_DECLARE(int) ap_has_cntrl(const char *str)
2378                 AP_FN_ATTR_NONNULL_ALL;
2379
2380 /**
2381  * Wrapper for @a apr_password_validate() to cache expensive calculations
2382  * @param r the current request
2383  * @param username username of the user
2384  * @param passwd password string
2385  * @param hash hash string to be passwd to @a apr_password_validate()
2386  * @return APR_SUCCESS if passwords match, APR_EMISMATCH or error otherwise
2387  * @note Currently, ap_password_validate() only caches the result of the
2388  *       most recent call with the same connection as @a r.
2389  *       In the future, it may also do rate-limiting against brute-force
2390  *       attacks.
2391  */
2392 AP_DECLARE(apr_status_t) ap_password_validate(request_rec *r,
2393                                               const char *username,
2394                                               const char *passwd,
2395                                               const char *hash);
2396
2397 /**
2398  * Short function to execute a command and return the first line of
2399  * output minus \\r \\n. Useful for "obscuring" passwords via exec calls
2400  * @param p the pool to allocate from
2401  * @param cmd the command to execute
2402  * @param argv the arguments to pass to the cmd
2403  * @return ptr to characters or NULL on any error
2404  */
2405 AP_DECLARE(char *) ap_get_exec_line(apr_pool_t *p,
2406                                     const char *cmd,
2407                                     const char * const *argv);
2408
2409
2410 #define AP_NORESTART APR_OS_START_USEERR + 1
2411
2412 /**
2413  * Get the first index of the string in the array or -1 if not found. Start
2414  * searching a start. 
2415  * @param array The array the check
2416  * @param s The string to find
2417  * @param start Start index for search. If start is out of bounds (negative or  
2418                 equal to array length or greater), -1 will be returned.
2419  * @return index of string in array or -1
2420  */
2421 AP_DECLARE(int) ap_array_str_index(const apr_array_header_t *array, 
2422                                    const char *s,
2423                                    int start);
2424
2425 /**
2426  * Check if the string is member of the given array by strcmp.
2427  * @param array The array the check
2428  * @param s The string to find
2429  * @return !=0 iff string is member of array (via strcmp)
2430  */
2431 AP_DECLARE(int) ap_array_str_contains(const apr_array_header_t *array, 
2432                                       const char *s);
2433
2434 #ifdef __cplusplus
2435 }
2436 #endif
2437
2438 #endif  /* !APACHE_HTTPD_H */
2439
2440 /** @} //APACHE Daemon      */
2441 /** @} //APACHE Core        */
2442 /** @} //APACHE super group */
2443