| 1 | /* ==================================================================== |
| 2 | * Copyright (c) 1995-1997 The Apache Group. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in |
| 13 | * the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * |
| 16 | * 3. All advertising materials mentioning features or use of this |
| 17 | * software must display the following acknowledgment: |
| 18 | * "This product includes software developed by the Apache Group |
| 19 | * for use in the Apache HTTP server project (http://www.apache.org/)." |
| 20 | * |
| 21 | * 4. The names "Apache Server" and "Apache Group" must not be used to |
| 22 | * endorse or promote products derived from this software without |
| 23 | * prior written permission. |
| 24 | * |
| 25 | * 5. Redistributions of any form whatsoever must retain the following |
| 26 | * acknowledgment: |
| 27 | * "This product includes software developed by the Apache Group |
| 28 | * for use in the Apache HTTP server project (http://www.apache.org/)." |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY |
| 31 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 33 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR |
| 34 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 36 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 41 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 | * ==================================================================== |
| 43 | * |
| 44 | * This software consists of voluntary contributions made by many |
| 45 | * individuals on behalf of the Apache Group and was originally based |
| 46 | * on public domain software written at the National Center for |
| 47 | * Supercomputing Applications, University of Illinois, Urbana-Champaign. |
| 48 | * For more information on the Apache Group and the Apache HTTP server |
| 49 | * project, please see <http://www.apache.org/>. |
| 50 | * |
| 51 | */ |
| 52 | |
| 53 | /* |
| 54 | * httpd.h: header for simple (ha! not anymore) http daemon |
| 55 | */ |
| 56 | |
| 57 | /* Headers in which EVERYONE has an interest... */ |
| 58 | |
| 59 | #include "conf.h" |
| 60 | #include "alloc.h" |
| 61 | #include "buff.h" |
| 62 | |
| 63 | /* ----------------------------- config dir ------------------------------ */ |
| 64 | |
| 65 | /* Define this to be the default server home dir. Anything later in this |
| 66 | * file with a relative pathname will have this added. |
| 67 | */ |
| 68 | #ifndef HTTPD_ROOT |
| 69 | #ifdef __EMX__ |
| 70 | /* Set default for OS/2 file system */ |
| 71 | #define HTTPD_ROOT "/os2httpd" |
| 72 | #else |
| 73 | #define HTTPD_ROOT "/usr/local/etc/httpd" |
| 74 | #endif |
| 75 | #endif |
| 76 | |
| 77 | #ifndef DOCUMENT_LOCATION |
| 78 | /* Root of server */ |
| 79 | #ifdef __EMX__ |
| 80 | /* Set default for OS/2 file system */ |
| 81 | #define DOCUMENT_LOCATION "/os2httpd/docs" |
| 82 | #else |
| 83 | #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs" |
| 84 | #endif |
| 85 | #endif |
| 86 | |
| 87 | /* Max. number of dynamically loaded modules */ |
| 88 | #define DYNAMIC_MODULE_LIMIT 64 |
| 89 | |
| 90 | /* Default administrator's address */ |
| 91 | #define DEFAULT_ADMIN "[no address given]" |
| 92 | |
| 93 | /* |
| 94 | * --------- You shouldn't have to edit anything below this line ---------- |
| 95 | * |
| 96 | * Any modifications to any defaults not defined above should be done in the |
| 97 | * respective config. file. |
| 98 | * |
| 99 | */ |
| 100 | |
| 101 | |
| 102 | /* -------------- Port number for server running standalone --------------- */ |
| 103 | |
| 104 | #define DEFAULT_PORT 80 |
| 105 | |
| 106 | /* --------- Default user name and group name running standalone ---------- */ |
| 107 | /* --- These may be specified as numbers by placing a # before a number --- */ |
| 108 | |
| 109 | #ifndef DEFAULT_USER |
| 110 | #define DEFAULT_USER "#-1" |
| 111 | #endif |
| 112 | #ifndef DEFAULT_GROUP |
| 113 | #define DEFAULT_GROUP "#-1" |
| 114 | #endif |
| 115 | |
| 116 | /* The name of the log files */ |
| 117 | #ifndef DEFAULT_XFERLOG |
| 118 | #ifdef __EMX__ |
| 119 | /* Set default for OS/2 file system */ |
| 120 | #define DEFAULT_XFERLOG "logs/access.log" |
| 121 | #else |
| 122 | #define DEFAULT_XFERLOG "logs/access_log" |
| 123 | #endif |
| 124 | #endif /* DEFAULT_XFERLOG */ |
| 125 | #ifndef DEFAULT_ERRORLOG |
| 126 | #ifdef __EMX__ |
| 127 | /* Set default for OS/2 file system */ |
| 128 | #define DEFAULT_ERRORLOG "logs/error.log" |
| 129 | #else |
| 130 | #define DEFAULT_ERRORLOG "logs/error_log" |
| 131 | #endif |
| 132 | #endif /* DEFAULT_ERRORLOG */ |
| 133 | #ifndef DEFAULT_PIDLOG |
| 134 | #define DEFAULT_PIDLOG "logs/httpd.pid" |
| 135 | #endif |
| 136 | #ifndef DEFAULT_SCOREBOARD |
| 137 | #define DEFAULT_SCOREBOARD "logs/apache_runtime_status" |
| 138 | #endif |
| 139 | #ifndef DEFAULT_LOCKFILE |
| 140 | #define DEFAULT_LOCKFILE "logs/accept.lock" |
| 141 | #endif |
| 142 | |
| 143 | /* Define this to be what your HTML directory content files are called */ |
| 144 | #define DEFAULT_INDEX "index.html" |
| 145 | |
| 146 | /* Define this to 1 if you want fancy indexing, 0 otherwise */ |
| 147 | #define DEFAULT_INDEXING 0 |
| 148 | |
| 149 | /* Define this to be what type you'd like returned for files with unknown */ |
| 150 | /* suffixes */ |
| 151 | #define DEFAULT_TYPE "text/plain" |
| 152 | |
| 153 | /* Define this to be what your per-directory security files are called */ |
| 154 | #ifdef __EMX__ |
| 155 | /* Set default for OS/2 file system */ |
| 156 | #define DEFAULT_ACCESS_FNAME "htaccess" |
| 157 | #else |
| 158 | #define DEFAULT_ACCESS_FNAME ".htaccess" |
| 159 | #endif |
| 160 | |
| 161 | /* The name of the server config file */ |
| 162 | #ifndef SERVER_CONFIG_FILE |
| 163 | #define SERVER_CONFIG_FILE "conf/httpd.conf" |
| 164 | #endif |
| 165 | |
| 166 | #ifndef RESOURCE_CONFIG_FILE |
| 167 | /* The name of the document config file */ |
| 168 | #define RESOURCE_CONFIG_FILE "conf/srm.conf" |
| 169 | #endif |
| 170 | |
| 171 | #ifndef TYPES_CONFIG_FILE |
| 172 | /* The name of the MIME types file */ |
| 173 | #define TYPES_CONFIG_FILE "conf/mime.types" |
| 174 | #endif |
| 175 | |
| 176 | #ifndef ACCESS_CONFIG_FILE |
| 177 | /* The name of the access file */ |
| 178 | #define ACCESS_CONFIG_FILE "conf/access.conf" |
| 179 | #endif |
| 180 | |
| 181 | /* Whether we should enable rfc1413 identity checking */ |
| 182 | #define DEFAULT_RFC1413 0 |
| 183 | /* The default directory in user's home dir */ |
| 184 | #define DEFAULT_USER_DIR "public_html" |
| 185 | |
| 186 | /* The default path for CGI scripts if none is currently set */ |
| 187 | #ifndef DEFAULT_PATH |
| 188 | #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin" |
| 189 | #endif |
| 190 | |
| 191 | /* The path to the Bourne shell, for parsed docs */ |
| 192 | #ifndef SHELL_PATH |
| 193 | #ifdef __EMX__ |
| 194 | /* Set default for OS/2 file system */ |
| 195 | #define SHELL_PATH "CMD.EXE" |
| 196 | #else |
| 197 | #define SHELL_PATH "/bin/sh" |
| 198 | #endif |
| 199 | #endif |
| 200 | |
| 201 | /* The path to the suExec wrapper, can be overridden in Configuration */ |
| 202 | #ifndef SUEXEC_BIN |
| 203 | #define SUEXEC_BIN "/usr/local/etc/httpd/sbin/suexec" |
| 204 | #endif |
| 205 | |
| 206 | /* The default string lengths */ |
| 207 | #define MAX_STRING_LEN HUGE_STRING_LEN |
| 208 | #define HUGE_STRING_LEN 8192 |
| 209 | |
| 210 | /* The timeout for waiting for messages */ |
| 211 | #define DEFAULT_TIMEOUT 300 |
| 212 | |
| 213 | /* The timeout for waiting for keepalive timeout until next request */ |
| 214 | #define DEFAULT_KEEPALIVE_TIMEOUT 15 |
| 215 | |
| 216 | /* The number of requests to entertain per connection */ |
| 217 | #define DEFAULT_KEEPALIVE 100 |
| 218 | |
| 219 | /* The size of the server's internal read-write buffers */ |
| 220 | #define IOBUFSIZE 8192 |
| 221 | |
| 222 | /* Number of servers to spawn off by default --- also, if fewer than |
| 223 | * this free when the caretaker checks, it will spawn more. |
| 224 | */ |
| 225 | #define DEFAULT_START_DAEMON 5 |
| 226 | |
| 227 | /* Maximum number of *free* server processes --- more than this, and |
| 228 | * they will die off. |
| 229 | */ |
| 230 | |
| 231 | #define DEFAULT_MAX_FREE_DAEMON 10 |
| 232 | |
| 233 | /* Minimum --- fewer than this, and more will be created */ |
| 234 | |
| 235 | #define DEFAULT_MIN_FREE_DAEMON 5 |
| 236 | |
| 237 | /* Limit on the total --- clients will be locked out if more servers than |
| 238 | * this are needed. It is intended solely to keep the server from crashing |
| 239 | * when things get out of hand. |
| 240 | * |
| 241 | * We keep a hard maximum number of servers, for two reasons --- first off, |
| 242 | * in case something goes seriously wrong, we want to stop the fork bomb |
| 243 | * short of actually crashing the machine we're running on by filling some |
| 244 | * kernel table. Secondly, it keeps the size of the scoreboard file small |
| 245 | * enough that we can read the whole thing without worrying too much about |
| 246 | * the overhead. |
| 247 | */ |
| 248 | #ifndef HARD_SERVER_LIMIT |
| 249 | #define HARD_SERVER_LIMIT 256 |
| 250 | #endif |
| 251 | |
| 252 | /* Number of requests to try to handle in a single process. If <= 0, |
| 253 | * the children don't die off. That's the default here, since I'm still |
| 254 | * interested in finding and stanching leaks. |
| 255 | */ |
| 256 | |
| 257 | #define DEFAULT_MAX_REQUESTS_PER_CHILD 0 |
| 258 | |
| 259 | /* If you have altered Apache and wish to change the SERVER_VERSION |
| 260 | * identifier below, please keep to the HTTP specification. This states that |
| 261 | * the identification string should consist of product tokens with an optional |
| 262 | * slash and version designator. Sub-products which form a significant part |
| 263 | * of the application can be listed, separated by whitespace, by adding |
| 264 | * their product tokens to EXTRA_CFLAGS in the Configuration file like so. |
| 265 | * |
| 266 | * EXTRA_CFLAGS="-DSERVER_SUBVERSION="MrWidget/0.1-alpha" |
| 267 | * |
| 268 | * The tokens are listed in order of their significance for identifying the |
| 269 | * application. |
| 270 | * |
| 271 | * "Product tokens should be short and to the point -- use of them for |
| 272 | * advertizing or other non-essential information is explicitly forbidden." |
| 273 | * |
| 274 | * Example: "Apache/1.1.0 MrWidget/0.1-alpha" |
| 275 | */ |
| 276 | |
| 277 | #define SERVER_BASEVERSION "Apache/1.2.6" /* SEE COMMENTS ABOVE */ |
| 278 | #ifdef SERVER_SUBVERSION |
| 279 | #define SERVER_VERSION SERVER_BASEVERSION " " SERVER_SUBVERSION |
| 280 | #else |
| 281 | #define SERVER_VERSION SERVER_BASEVERSION |
| 282 | #endif |
| 283 | |
| 284 | /* Numeric release version identifier: major minor bugfix betaseq |
| 285 | * Always increases along the same track as the source branch. |
| 286 | */ |
| 287 | #define APACHE_RELEASE 1020600 |
| 288 | |
| 289 | #define SERVER_PROTOCOL "HTTP/1.1" |
| 290 | #define SERVER_SUPPORT "http://www.apache.org/" |
| 291 | |
| 292 | #define DECLINED -1 /* Module declines to handle */ |
| 293 | #define OK 0 /* Module has handled this stage. */ |
| 294 | |
| 295 | |
| 296 | /* ----------------------- HTTP Status Codes ------------------------- */ |
| 297 | |
| 298 | #define RESPONSE_CODES 38 |
| 299 | |
| 300 | #define HTTP_CONTINUE 100 |
| 301 | #define HTTP_SWITCHING_PROTOCOLS 101 |
| 302 | #define HTTP_OK 200 |
| 303 | #define HTTP_CREATED 201 |
| 304 | #define HTTP_ACCEPTED 202 |
| 305 | #define HTTP_NON_AUTHORITATIVE 203 |
| 306 | #define HTTP_NO_CONTENT 204 |
| 307 | #define HTTP_RESET_CONTENT 205 |
| 308 | #define HTTP_PARTIAL_CONTENT 206 |
| 309 | #define HTTP_MULTIPLE_CHOICES 300 |
| 310 | #define HTTP_MOVED_PERMANENTLY 301 |
| 311 | #define HTTP_MOVED_TEMPORARILY 302 |
| 312 | #define HTTP_SEE_OTHER 303 |
| 313 | #define HTTP_NOT_MODIFIED 304 |
| 314 | #define HTTP_USE_PROXY 305 |
| 315 | #define HTTP_BAD_REQUEST 400 |
| 316 | #define HTTP_UNAUTHORIZED 401 |
| 317 | #define HTTP_PAYMENT_REQUIRED 402 |
| 318 | #define HTTP_FORBIDDEN 403 |
| 319 | #define HTTP_NOT_FOUND 404 |
| 320 | #define HTTP_METHOD_NOT_ALLOWED 405 |
| 321 | #define HTTP_NOT_ACCEPTABLE 406 |
| 322 | #define HTTP_PROXY_AUTHENTICATION_REQUIRED 407 |
| 323 | #define HTTP_REQUEST_TIME_OUT 408 |
| 324 | #define HTTP_CONFLICT 409 |
| 325 | #define HTTP_GONE 410 |
| 326 | #define HTTP_LENGTH_REQUIRED 411 |
| 327 | #define HTTP_PRECONDITION_FAILED 412 |
| 328 | #define HTTP_REQUEST_ENTITY_TOO_LARGE 413 |
| 329 | #define HTTP_REQUEST_URI_TOO_LARGE 414 |
| 330 | #define HTTP_UNSUPPORTED_MEDIA_TYPE 415 |
| 331 | #define HTTP_INTERNAL_SERVER_ERROR 500 |
| 332 | #define HTTP_NOT_IMPLEMENTED 501 |
| 333 | #define HTTP_BAD_GATEWAY 502 |
| 334 | #define HTTP_SERVICE_UNAVAILABLE 503 |
| 335 | #define HTTP_GATEWAY_TIME_OUT 504 |
| 336 | #define HTTP_VERSION_NOT_SUPPORTED 505 |
| 337 | #define HTTP_VARIANT_ALSO_VARIES 506 |
| 338 | |
| 339 | #define DOCUMENT_FOLLOWS HTTP_OK |
| 340 | #define PARTIAL_CONTENT HTTP_PARTIAL_CONTENT |
| 341 | #define MULTIPLE_CHOICES HTTP_MULTIPLE_CHOICES |
| 342 | #define MOVED HTTP_MOVED_PERMANENTLY |
| 343 | #define REDIRECT HTTP_MOVED_TEMPORARILY |
| 344 | #define USE_LOCAL_COPY HTTP_NOT_MODIFIED |
| 345 | #define BAD_REQUEST HTTP_BAD_REQUEST |
| 346 | #define AUTH_REQUIRED HTTP_UNAUTHORIZED |
| 347 | #define FORBIDDEN HTTP_FORBIDDEN |
| 348 | #define NOT_FOUND HTTP_NOT_FOUND |
| 349 | #define METHOD_NOT_ALLOWED HTTP_METHOD_NOT_ALLOWED |
| 350 | #define NOT_ACCEPTABLE HTTP_NOT_ACCEPTABLE |
| 351 | #define LENGTH_REQUIRED HTTP_LENGTH_REQUIRED |
| 352 | #define PRECONDITION_FAILED HTTP_PRECONDITION_FAILED |
| 353 | #define SERVER_ERROR HTTP_INTERNAL_SERVER_ERROR |
| 354 | #define NOT_IMPLEMENTED HTTP_NOT_IMPLEMENTED |
| 355 | #define BAD_GATEWAY HTTP_BAD_GATEWAY |
| 356 | #define VARIANT_ALSO_VARIES HTTP_VARIANT_ALSO_VARIES |
| 357 | |
| 358 | #define is_HTTP_INFO(x) (((x) >= 100)&&((x) < 200)) |
| 359 | #define is_HTTP_SUCCESS(x) (((x) >= 200)&&((x) < 300)) |
| 360 | #define is_HTTP_REDIRECT(x) (((x) >= 300)&&((x) < 400)) |
| 361 | #define is_HTTP_ERROR(x) (((x) >= 400)&&((x) < 600)) |
| 362 | #define is_HTTP_CLIENT_ERROR(x) (((x) >= 400)&&((x) < 500)) |
| 363 | #define is_HTTP_SERVER_ERROR(x) (((x) >= 500)&&((x) < 600)) |
| 364 | |
| 365 | #define status_drops_connection(x) (((x) == HTTP_BAD_REQUEST) || \ |
| 366 | ((x) == HTTP_REQUEST_TIME_OUT) || \ |
| 367 | ((x) == HTTP_LENGTH_REQUIRED) || \ |
| 368 | ((x) == HTTP_REQUEST_ENTITY_TOO_LARGE) || \ |
| 369 | ((x) == HTTP_REQUEST_URI_TOO_LARGE) || \ |
| 370 | ((x) == HTTP_INTERNAL_SERVER_ERROR) || \ |
| 371 | ((x) == HTTP_SERVICE_UNAVAILABLE)) |
| 372 | |
| 373 | |
| 374 | #define METHODS 8 |
| 375 | #define M_GET 0 |
| 376 | #define M_PUT 1 |
| 377 | #define M_POST 2 |
| 378 | #define M_DELETE 3 |
| 379 | #define M_CONNECT 4 |
| 380 | #define M_OPTIONS 5 |
| 381 | #define M_TRACE 6 |
| 382 | #define M_INVALID 7 |
| 383 | |
| 384 | #define CGI_MAGIC_TYPE "application/x-httpd-cgi" |
| 385 | #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html" |
| 386 | #define INCLUDES_MAGIC_TYPE3 "text/x-server-parsed-html3" |
| 387 | #define MAP_FILE_MAGIC_TYPE "application/x-type-map" |
| 388 | #define ASIS_MAGIC_TYPE "httpd/send-as-is" |
| 389 | #define DIR_MAGIC_TYPE "httpd/unix-directory" |
| 390 | #define STATUS_MAGIC_TYPE "application/x-httpd-status" |
| 391 | |
| 392 | /* Just in case your linefeed isn't the one the other end is expecting. */ |
| 393 | #define LF 10 |
| 394 | #define CR 13 |
| 395 | |
| 396 | /* Possible values for request_rec.read_body (set by handling module): |
| 397 | * REQUEST_NO_BODY Send 413 error if message has any body |
| 398 | * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length |
| 399 | * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me. |
| 400 | * REQUEST_CHUNKED_PASS Pass the chunks to me without removal. |
| 401 | */ |
| 402 | #define REQUEST_NO_BODY 0 |
| 403 | #define REQUEST_CHUNKED_ERROR 1 |
| 404 | #define REQUEST_CHUNKED_DECHUNK 2 |
| 405 | #define REQUEST_CHUNKED_PASS 3 |
| 406 | |
| 407 | /* Things which may vary per file-lookup WITHIN a request --- |
| 408 | * e.g., state of MIME config. Basically, the name of an object, info |
| 409 | * about the object, and any other info we may ahve which may need to |
| 410 | * change as we go poking around looking for it (e.g., overridden by |
| 411 | * .htaccess files). |
| 412 | * |
| 413 | * Note how the default state of almost all these things is properly |
| 414 | * zero, so that allocating it with pcalloc does the right thing without |
| 415 | * a whole lot of hairy initialization... so long as we are willing to |
| 416 | * make the (fairly) portable assumption that the bit pattern of a NULL |
| 417 | * pointer is, in fact, zero. |
| 418 | */ |
| 419 | |
| 420 | /* This represents the result of calling htaccess; these are cached for |
| 421 | * each request. |
| 422 | */ |
| 423 | struct htaccess_result { |
| 424 | char *dir; /* the directory to which this applies */ |
| 425 | int override; /* the overrides allowed for the .htaccess file */ |
| 426 | void *htaccess; /* the configuration directives */ |
| 427 | /* the next one, or NULL if no more; N.B. never change this */ |
| 428 | const struct htaccess_result *next; |
| 429 | }; |
| 430 | |
| 431 | |
| 432 | typedef struct conn_rec conn_rec; |
| 433 | typedef struct server_rec server_rec; |
| 434 | typedef struct request_rec request_rec; |
| 435 | typedef struct listen_rec listen_rec; |
| 436 | |
| 437 | struct request_rec { |
| 438 | |
| 439 | pool *pool; |
| 440 | conn_rec *connection; |
| 441 | server_rec *server; |
| 442 | |
| 443 | request_rec *next; /* If we wind up getting redirected, |
| 444 | * pointer to the request we redirected to. |
| 445 | */ |
| 446 | request_rec *prev; /* If this is an internal redirect, |
| 447 | * pointer to where we redirected *from*. |
| 448 | */ |
| 449 | |
| 450 | request_rec *main; /* If this is a sub_request (see request.h) |
| 451 | * pointer back to the main request. |
| 452 | */ |
| 453 | |
| 454 | /* Info about the request itself... we begin with stuff that only |
| 455 | * protocol.c should ever touch... |
| 456 | */ |
| 457 | |
| 458 | char *the_request; /* First line of request, so we can log it */ |
| 459 | int assbackwards; /* HTTP/0.9, "simple" request */ |
| 460 | int proxyreq; /* A proxy request */ |
| 461 | int header_only; /* HEAD request, as opposed to GET */ |
| 462 | char *protocol; /* Protocol, as given to us, or HTTP/0.9 */ |
| 463 | int proto_num; /* Number version of protocol; 1.1 = 1001 */ |
| 464 | char *hostname; /* Host, as set by full URI or Host: */ |
| 465 | int hostlen; /* Length of http://host:port in full URI */ |
| 466 | |
| 467 | time_t request_time; /* When the request started */ |
| 468 | |
| 469 | char *status_line; /* Status line, if set by script */ |
| 470 | int status; /* In any case */ |
| 471 | |
| 472 | /* Request method, two ways; also, protocol, etc.. Outside of protocol.c, |
| 473 | * look, but don't touch. |
| 474 | */ |
| 475 | |
| 476 | char *method; /* GET, HEAD, POST, etc. */ |
| 477 | int method_number; /* M_GET, M_POST, etc. */ |
| 478 | int allowed; /* Allowed methods - for 405, OPTIONS, etc */ |
| 479 | |
| 480 | int sent_bodyct; /* byte count in stream is for body */ |
| 481 | long bytes_sent; /* body byte count, for easy access */ |
| 482 | |
| 483 | /* HTTP/1.1 connection-level features */ |
| 484 | |
| 485 | int chunked; /* sending chunked transfer-coding */ |
| 486 | int byterange; /* number of byte ranges */ |
| 487 | char *boundary; /* multipart/byteranges boundary */ |
| 488 | char *range; /* The Range: header */ |
| 489 | long clength; /* The "real" content length */ |
| 490 | |
| 491 | long remaining; /* bytes left to read */ |
| 492 | long read_length; /* bytes that have been read */ |
| 493 | int read_body; /* how the request body should be read */ |
| 494 | int read_chunked; /* reading chunked transfer-coding */ |
| 495 | |
| 496 | /* MIME header environments, in and out. Also, an array containing |
| 497 | * environment variables to be passed to subprocesses, so people can |
| 498 | * write modules to add to that environment. |
| 499 | * |
| 500 | * The difference between headers_out and err_headers_out is that the |
| 501 | * latter are printed even on error, and persist across internal redirects |
| 502 | * (so the headers printed for ErrorDocument handlers will have them). |
| 503 | * |
| 504 | * The 'notes' table is for notes from one module to another, with no |
| 505 | * other set purpose in mind... |
| 506 | */ |
| 507 | |
| 508 | table *headers_in; |
| 509 | table *headers_out; |
| 510 | table *err_headers_out; |
| 511 | table *subprocess_env; |
| 512 | table *notes; |
| 513 | |
| 514 | char *content_type; /* Break these out --- we dispatch on 'em */ |
| 515 | char *handler; /* What we *really* dispatch on */ |
| 516 | |
| 517 | char *content_encoding; |
| 518 | char *content_language; /* for back-compat. only -- do not use */ |
| 519 | array_header *content_languages; /* array of (char*) */ |
| 520 | |
| 521 | int no_cache; |
| 522 | int no_local_copy; |
| 523 | |
| 524 | /* What object is being requested (either directly, or via include |
| 525 | * or content-negotiation mapping). |
| 526 | */ |
| 527 | |
| 528 | char *uri; /* complete URI for a proxy req, or |
| 529 | * URL path for a non-proxy req */ |
| 530 | char *filename; |
| 531 | char *path_info; |
| 532 | char *args; /* QUERY_ARGS, if any */ |
| 533 | struct stat finfo; /* ST_MODE set to zero if no such file */ |
| 534 | |
| 535 | /* Various other config info which may change with .htaccess files |
| 536 | * These are config vectors, with one void* pointer for each module |
| 537 | * (the thing pointed to being the module's business). |
| 538 | */ |
| 539 | |
| 540 | void *per_dir_config; /* Options set in config files, etc. */ |
| 541 | void *request_config; /* Notes on *this* request */ |
| 542 | |
| 543 | /* |
| 544 | * a linked list of the configuration directives in the .htaccess files |
| 545 | * accessed by this request. |
| 546 | * N.B. always add to the head of the list, _never_ to the end. |
| 547 | * that way, a sub request's list can (temporarily) point to a parent's list |
| 548 | */ |
| 549 | const struct htaccess_result *htaccess; |
| 550 | }; |
| 551 | |
| 552 | |
| 553 | /* Things which are per connection |
| 554 | */ |
| 555 | |
| 556 | struct conn_rec { |
| 557 | |
| 558 | pool *pool; |
| 559 | server_rec *server; |
| 560 | server_rec *base_server; /* Physical vhost this conn come in on */ |
| 561 | |
| 562 | /* Information about the connection itself */ |
| 563 | |
| 564 | int child_num; /* The number of the child handling conn_rec */ |
| 565 | BUFF *client; /* Connetion to the guy */ |
| 566 | int aborted; /* Are we still talking? */ |
| 567 | |
| 568 | /* Who is the client? */ |
| 569 | |
| 570 | struct sockaddr_in local_addr; /* local address */ |
| 571 | struct sockaddr_in remote_addr; /* remote address */ |
| 572 | char *remote_ip; /* Client's IP address */ |
| 573 | char *remote_host; /* Client's DNS name, if known. |
| 574 | * NULL if DNS hasn't been checked, |
| 575 | * "" if it has and no address was found. |
| 576 | * N.B. Only access this though |
| 577 | * get_remote_host() */ |
| 578 | char *remote_logname; /* Only ever set if doing rfc1413 lookups. |
| 579 | * N.B. Only access this through |
| 580 | * get_remote_logname() */ |
| 581 | char *user; /* If an authentication check was made, |
| 582 | * this gets set to the user name. We assume |
| 583 | * that there's only one user per connection(!) |
| 584 | */ |
| 585 | char *auth_type; /* Ditto. */ |
| 586 | |
| 587 | int keepalive; /* Are we using HTTP Keep-Alive? */ |
| 588 | int keptalive; /* Did we use HTTP Keep-Alive? */ |
| 589 | int keepalives; /* How many times have we used it? */ |
| 590 | }; |
| 591 | |
| 592 | /* Per-vhost config... */ |
| 593 | |
| 594 | /* The address 255.255.255.255, when used as a virtualhost address, |
| 595 | * will become the "default" server when the ip doesn't match other vhosts. |
| 596 | */ |
| 597 | #define DEFAULT_VHOST_ADDR 0xfffffffful |
| 598 | |
| 599 | typedef struct server_addr_rec server_addr_rec; |
| 600 | struct server_addr_rec { |
| 601 | server_addr_rec *next; |
| 602 | struct in_addr host_addr; /* The bound address, for this server */ |
| 603 | unsigned short host_port; /* The bound port, for this server */ |
| 604 | char *virthost; /* The name given in <VirtualHost> */ |
| 605 | }; |
| 606 | |
| 607 | |
| 608 | struct server_rec { |
| 609 | |
| 610 | server_rec *next; |
| 611 | |
| 612 | /* Full locations of server config info */ |
| 613 | |
| 614 | char *srm_confname; |
| 615 | char *access_confname; |
| 616 | |
| 617 | /* Contact information */ |
| 618 | |
| 619 | char *server_admin; |
| 620 | char *server_hostname; |
| 621 | unsigned short port; /* for redirects, etc. */ |
| 622 | |
| 623 | /* Log files --- note that transfer log is now in the modules... */ |
| 624 | |
| 625 | char *error_fname; |
| 626 | FILE *error_log; |
| 627 | |
| 628 | /* Module-specific configuration for server, and defaults... */ |
| 629 | |
| 630 | int is_virtual; /* true if this is the virtual server */ |
| 631 | void *module_config; /* Config vector containing pointers to |
| 632 | * modules' per-server config structures. |
| 633 | */ |
| 634 | void *lookup_defaults; /* MIME type info, etc., before we start |
| 635 | * checking per-directory info. |
| 636 | */ |
| 637 | /* Transaction handling */ |
| 638 | |
| 639 | server_addr_rec *addrs; |
| 640 | int timeout; /* Timeout, in seconds, before we give up */ |
| 641 | int keep_alive_timeout; /* Seconds we'll wait for another request */ |
| 642 | int keep_alive_max; /* Maximum requests per connection */ |
| 643 | int keep_alive; /* Use persistent connections? */ |
| 644 | int send_buffer_size; /* size of TCP send buffer (in bytes) */ |
| 645 | |
| 646 | char *path; /* Pathname for ServerPath */ |
| 647 | int pathlen; /* Length of path */ |
| 648 | |
| 649 | char *names; /* Wildcarded names for ServerAlias servers */ |
| 650 | |
| 651 | uid_t server_uid; /* effective user id when calling exec wrapper */ |
| 652 | gid_t server_gid; /* effective group id when calling exec wrapper */ |
| 653 | }; |
| 654 | |
| 655 | /* These are more like real hosts than virtual hosts */ |
| 656 | struct listen_rec { |
| 657 | listen_rec *next; |
| 658 | struct sockaddr_in local_addr; /* local IP address and port */ |
| 659 | int fd; |
| 660 | int used; /* Only used during restart */ |
| 661 | /* more stuff here, like which protocol is bound to the port */ |
| 662 | }; |
| 663 | |
| 664 | /* Prototypes for utilities... util.c. |
| 665 | */ |
| 666 | |
| 667 | /* Time */ |
| 668 | extern const char month_snames[12][4]; |
| 669 | |
| 670 | struct tm *get_gmtoff(int *tz); |
| 671 | char *get_time(); |
| 672 | char *ht_time(pool * p, time_t t, const char *fmt, int gmt); |
| 673 | char *gm_timestr_822(pool * p, time_t t); |
| 674 | |
| 675 | /* String handling. The *_nc variants allow you to use non-const char **s as |
| 676 | arguments (unfortunately C won't automatically convert a char ** to a const |
| 677 | char **) */ |
| 678 | |
| 679 | char *getword(pool * p, const char **line, char stop); |
| 680 | char *getword_nc(pool * p, char **line, char stop); |
| 681 | char *getword_white(pool * p, const char **line); |
| 682 | char *getword_white_nc(pool * p, char **line); |
| 683 | char *getword_nulls(pool * p, const char **line, char stop); |
| 684 | char *getword_nulls_nc(pool * p, char **line, char stop); |
| 685 | char *getword_conf(pool * p, const char **line); |
| 686 | char *getword_conf_nc(pool * p, char **line); |
| 687 | |
| 688 | char *get_token(pool * p, char **accept_line, int accept_white); |
| 689 | int find_token(pool * p, const char *line, const char *tok); |
| 690 | int find_last_token(pool * p, const char *line, const char *tok); |
| 691 | |
| 692 | int is_url(const char *u); |
| 693 | extern int unescape_url(char *url); |
| 694 | void no2slash(char *name); |
| 695 | void getparents(char *name); |
| 696 | char *escape_path_segment(pool * p, const char *s); |
| 697 | char *os_escape_path(pool * p, const char *path, int partial); |
| 698 | #define escape_uri(ppool,path) os_escape_path(ppool,path,1) |
| 699 | extern char *escape_html(pool * p, const char *s); |
| 700 | char *construct_server(pool * p, const char *hostname, unsigned port); |
| 701 | char *construct_url(pool * p, const char *path, const server_rec * s); |
| 702 | char *escape_shell_cmd(pool * p, const char *s); |
| 703 | |
| 704 | int count_dirs(const char *path); |
| 705 | char *make_dirstr(pool * a, const char *s, int n); |
| 706 | char *make_full_path(pool * a, const char *dir, const char *f); |
| 707 | |
| 708 | int is_matchexp(const char *str); |
| 709 | int strcmp_match(const char *str, const char *exp); |
| 710 | int strcasecmp_match(const char *str, const char *exp); |
| 711 | char *uudecode(pool *, const char *); |
| 712 | |
| 713 | char *pregsub(pool * p, const char *input, const char *source, size_t nmatch, |
| 714 | regmatch_t pmatch[]); |
| 715 | |
| 716 | void str_tolower(char *); |
| 717 | int ind(const char *, char); /* Sigh... */ |
| 718 | int rind(const char *, char); |
| 719 | |
| 720 | int cfg_getline(char *s, int n, FILE * f); |
| 721 | |
| 722 | #ifdef NEED_STRERROR |
| 723 | char *strerror(int err); |
| 724 | #endif |
| 725 | |
| 726 | /* Misc system hackery */ |
| 727 | |
| 728 | uid_t uname2id(const char *name); |
| 729 | gid_t gname2id(const char *name); |
| 730 | int is_directory(const char *name); |
| 731 | int can_exec(const struct stat *); |
| 732 | void chdir_file(const char *file); |
| 733 | |
| 734 | char *get_local_host(pool *); |
| 735 | unsigned long get_virthost_addr(const char *hostname, unsigned short *port); |
| 736 | |
| 737 | extern time_t restart_time; |
| 738 | |
| 739 | /* |
| 740 | * Apache tries to keep all of its long term filehandles (such as log files, |
| 741 | * and sockets) above this number. This is to workaround problems in many |
| 742 | * third party libraries that are compiled with a small FD_SETSIZE. There |
| 743 | * should be no reason to lower this, because it's only advisory. If a file |
| 744 | * can't be allocated above this number then it will remain in the "slack" |
| 745 | * area. |
| 746 | * |
| 747 | * Only the low slack line is used by default. If HIGH_SLACK_LINE is defined |
| 748 | * then an attempt is also made to keep all non-FILE * files above the high |
| 749 | * slack line. This is to work around a Solaris C library limitation, where it |
| 750 | * uses an unsigned char to store the file descriptor. |
| 751 | */ |
| 752 | #ifndef LOW_SLACK_LINE |
| 753 | #define LOW_SLACK_LINE 15 |
| 754 | #endif |
| 755 | /* #define HIGH_SLACK_LINE 255 */ |
| 756 | |
| 757 | /* |
| 758 | * The ap_slack() function takes a fd, and tries to move it above the indicated |
| 759 | * line. It returns an fd which may or may not have moved above the line, and |
| 760 | * never fails. If the high line was requested and it fails it will also try |
| 761 | * the low line. |
| 762 | */ |
| 763 | int ap_slack(int fd, int line); |
| 764 | #define AP_SLACK_LOW 1 |
| 765 | #define AP_SLACK_HIGH 2 |