Coverage Report

Created: 2025-08-26 06:24

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