http_core.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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. * @file http_core.h
  18. * @brief CORE HTTP Daemon
  19. *
  20. * @defgroup APACHE_CORE_HTTPD Core HTTP Daemon
  21. * @ingroup APACHE_CORE
  22. * @{
  23. */
  24. #ifndef APACHE_HTTP_CORE_H
  25. #define APACHE_HTTP_CORE_H
  26. #include "apr.h"
  27. #include "apr_hash.h"
  28. #include "apr_optional.h"
  29. #include "util_filter.h"
  30. #include "ap_expr.h"
  31. #include "apr_tables.h"
  32. #include "http_config.h"
  33. #if APR_HAVE_STRUCT_RLIMIT
  34. #include <sys/time.h>
  35. #include <sys/resource.h>
  36. #endif
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* ****************************************************************
  41. *
  42. * The most basic server code is encapsulated in a single module
  43. * known as the core, which is just *barely* functional enough to
  44. * serve documents, though not terribly well.
  45. *
  46. * Largely for NCSA back-compatibility reasons, the core needs to
  47. * make pieces of its config structures available to other modules.
  48. * The accessors are declared here, along with the interpretation
  49. * of one of them (allow_options).
  50. */
  51. /**
  52. * @defgroup APACHE_CORE_HTTPD_ACESSORS Acessors
  53. *
  54. * @brief File/Directory Accessor directives
  55. *
  56. * @{
  57. */
  58. /** No directives */
  59. #define OPT_NONE 0
  60. /** Indexes directive */
  61. #define OPT_INDEXES 1
  62. /** SSI is enabled without exec= permission */
  63. #define OPT_INCLUDES 2
  64. /** FollowSymLinks directive */
  65. #define OPT_SYM_LINKS 4
  66. /** ExecCGI directive */
  67. #define OPT_EXECCGI 8
  68. /** directive unset */
  69. #define OPT_UNSET 16
  70. /** SSI exec= permission is permitted, iff OPT_INCLUDES is also set */
  71. #define OPT_INC_WITH_EXEC 32
  72. /** SymLinksIfOwnerMatch directive */
  73. #define OPT_SYM_OWNER 64
  74. /** MultiViews directive */
  75. #define OPT_MULTI 128
  76. /** All directives */
  77. #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_INC_WITH_EXEC|OPT_SYM_LINKS|OPT_EXECCGI)
  78. /** @} */
  79. /**
  80. * @defgroup get_remote_host Remote Host Resolution
  81. * @ingroup APACHE_CORE_HTTPD
  82. * @{
  83. */
  84. /** REMOTE_HOST returns the hostname, or NULL if the hostname
  85. * lookup fails. It will force a DNS lookup according to the
  86. * HostnameLookups setting.
  87. */
  88. #define REMOTE_HOST (0)
  89. /** REMOTE_NAME returns the hostname, or the dotted quad if the
  90. * hostname lookup fails. It will force a DNS lookup according
  91. * to the HostnameLookups setting.
  92. */
  93. #define REMOTE_NAME (1)
  94. /** REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
  95. * never forced.
  96. */
  97. #define REMOTE_NOLOOKUP (2)
  98. /** REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
  99. * a double reverse lookup, regardless of the HostnameLookups
  100. * setting. The result is the (double reverse checked) hostname,
  101. * or NULL if any of the lookups fail.
  102. */
  103. #define REMOTE_DOUBLE_REV (3)
  104. /** @} // get_remote_host */
  105. /** all of the requirements must be met */
  106. #define SATISFY_ALL 0
  107. /** any of the requirements must be met */
  108. #define SATISFY_ANY 1
  109. /** There are no applicable satisfy lines */
  110. #define SATISFY_NOSPEC 2
  111. /** Make sure we don't write less than 8000 bytes at any one time.
  112. */
  113. #define AP_MIN_BYTES_TO_WRITE 8000
  114. /** default maximum of internal redirects */
  115. # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 10
  116. /** default maximum subrequest nesting level */
  117. # define AP_DEFAULT_MAX_SUBREQ_DEPTH 10
  118. /**
  119. * Retrieve the value of Options for this request
  120. * @param r The current request
  121. * @return the Options bitmask
  122. */
  123. AP_DECLARE(int) ap_allow_options(request_rec *r);
  124. /**
  125. * Retrieve the value of the AllowOverride for this request
  126. * @param r The current request
  127. * @return the overrides bitmask
  128. */
  129. AP_DECLARE(int) ap_allow_overrides(request_rec *r);
  130. /**
  131. * Retrieve the document root for this server
  132. * @param r The current request
  133. * @warning Don't use this! If your request went through a Userdir, or
  134. * something like that, it'll screw you. But it's back-compatible...
  135. * @return The document root
  136. */
  137. AP_DECLARE(const char *) ap_document_root(request_rec *r);
  138. /**
  139. * Lookup the remote user agent's DNS name or IP address
  140. * @ingroup get_remote_hostname
  141. * @param req The current request
  142. * @param type The type of lookup to perform. One of:
  143. * <pre>
  144. * REMOTE_HOST returns the hostname, or NULL if the hostname
  145. * lookup fails. It will force a DNS lookup according to the
  146. * HostnameLookups setting.
  147. * REMOTE_NAME returns the hostname, or the dotted quad if the
  148. * hostname lookup fails. It will force a DNS lookup according
  149. * to the HostnameLookups setting.
  150. * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
  151. * never forced.
  152. * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
  153. * a double reverse lookup, regardless of the HostnameLookups
  154. * setting. The result is the (double reverse checked)
  155. * hostname, or NULL if any of the lookups fail.
  156. * </pre>
  157. * @param str_is_ip unless NULL is passed, this will be set to non-zero on
  158. * output when an IP address string is returned
  159. * @return The remote hostname (based on the request useragent_ip)
  160. */
  161. AP_DECLARE(const char *) ap_get_useragent_host(request_rec *req, int type,
  162. int *str_is_ip);
  163. /**
  164. * Lookup the remote client's DNS name or IP address
  165. * @ingroup get_remote_host
  166. * @param conn The current connection
  167. * @param dir_config The directory config vector from the request
  168. * @param type The type of lookup to perform. One of:
  169. * <pre>
  170. * REMOTE_HOST returns the hostname, or NULL if the hostname
  171. * lookup fails. It will force a DNS lookup according to the
  172. * HostnameLookups setting.
  173. * REMOTE_NAME returns the hostname, or the dotted quad if the
  174. * hostname lookup fails. It will force a DNS lookup according
  175. * to the HostnameLookups setting.
  176. * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
  177. * never forced.
  178. * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
  179. * a double reverse lookup, regardless of the HostnameLookups
  180. * setting. The result is the (double reverse checked)
  181. * hostname, or NULL if any of the lookups fail.
  182. * </pre>
  183. * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address
  184. * string is returned
  185. * @return The remote hostname (based on the connection client_ip)
  186. */
  187. AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);
  188. /**
  189. * Retrieve the login name of the remote user. Undef if it could not be
  190. * determined
  191. * @param r The current request
  192. * @return The user logged in to the client machine
  193. */
  194. AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
  195. /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
  196. * and SERVER_NAME.
  197. */
  198. /**
  199. * build a fully qualified URL from the uri and information in the request rec
  200. * @param p The pool to allocate the URL from
  201. * @param uri The path to the requested file
  202. * @param r The current request
  203. * @return A fully qualified URL
  204. */
  205. AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
  206. /**
  207. * Get the current server name from the request
  208. * @param r The current request
  209. * @return the server name
  210. */
  211. AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
  212. /**
  213. * Get the current server name from the request for the purposes
  214. * of using in a URL. If the server name is an IPv6 literal
  215. * address, it will be returned in URL format (e.g., "[fe80::1]").
  216. * @param r The current request
  217. * @return the server name
  218. */
  219. AP_DECLARE(const char *) ap_get_server_name_for_url(request_rec *r);
  220. /**
  221. * Get the current server port
  222. * @param r The current request
  223. * @return The server's port
  224. */
  225. AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
  226. /**
  227. * Return the limit on bytes in request msg body
  228. * @param r The current request
  229. * @return the maximum number of bytes in the request msg body
  230. */
  231. AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r);
  232. /**
  233. * Return the limit on bytes in XML request msg body
  234. * @param r The current request
  235. * @return the maximum number of bytes in XML request msg body
  236. */
  237. AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r);
  238. /**
  239. * Install a custom response handler for a given status
  240. * @param r The current request
  241. * @param status The status for which the custom response should be used
  242. * @param string The custom response. This can be a static string, a file
  243. * or a URL
  244. */
  245. AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);
  246. /**
  247. * Check if the current request is beyond the configured max. number of redirects or subrequests
  248. * @param r The current request
  249. * @return true (is exceeded) or false
  250. */
  251. AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r);
  252. /**
  253. * Check for a definition from the server command line
  254. * @param name The define to check for
  255. * @return 1 if defined, 0 otherwise
  256. */
  257. AP_DECLARE(int) ap_exists_config_define(const char *name);
  258. /* FIXME! See STATUS about how */
  259. AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
  260. /* Authentication stuff. This is one of the places where compatibility
  261. * with the old config files *really* hurts; they don't discriminate at
  262. * all between different authentication schemes, meaning that we need
  263. * to maintain common state for all of them in the core, and make it
  264. * available to the other modules through interfaces.
  265. */
  266. /** @see require_line */
  267. typedef struct require_line require_line;
  268. /**
  269. * @brief A structure to keep track of authorization requirements
  270. */
  271. struct require_line {
  272. /** Where the require line is in the config file. */
  273. apr_int64_t method_mask;
  274. /** The complete string from the command line */
  275. char *requirement;
  276. };
  277. /**
  278. * Return the type of authorization required for this request
  279. * @param r The current request
  280. * @return The authorization required
  281. */
  282. AP_DECLARE(const char *) ap_auth_type(request_rec *r);
  283. /**
  284. * Return the current Authorization realm
  285. * @param r The current request
  286. * @return The current authorization realm
  287. */
  288. AP_DECLARE(const char *) ap_auth_name(request_rec *r);
  289. /**
  290. * How the requires lines must be met.
  291. * @param r The current request
  292. * @return How the requirements must be met. One of:
  293. * <pre>
  294. * SATISFY_ANY -- any of the requirements must be met.
  295. * SATISFY_ALL -- all of the requirements must be met.
  296. * SATISFY_NOSPEC -- There are no applicable satisfy lines
  297. * </pre>
  298. */
  299. AP_DECLARE(int) ap_satisfies(request_rec *r);
  300. /**
  301. * Core is also unlike other modules in being implemented in more than
  302. * one file... so, data structures are declared here, even though most of
  303. * the code that cares really is in http_core.c. Also, another accessor.
  304. */
  305. AP_DECLARE_DATA extern module core_module;
  306. /**
  307. * Accessor for core_module's specific data. Equivalent to
  308. * ap_get_module_config(cv, &core_module) but more efficient.
  309. * @param cv The vector in which the modules configuration is stored.
  310. * usually r->per_dir_config or s->module_config
  311. * @return The module-specific data
  312. */
  313. AP_DECLARE(void *) ap_get_core_module_config(const ap_conf_vector_t *cv);
  314. /**
  315. * Accessor to set core_module's specific data. Equivalent to
  316. * ap_set_module_config(cv, &core_module, val) but more efficient.
  317. * @param cv The vector in which the modules configuration is stored.
  318. * usually r->per_dir_config or s->module_config
  319. * @param val The module-specific data to set
  320. */
  321. AP_DECLARE(void) ap_set_core_module_config(ap_conf_vector_t *cv, void *val);
  322. /** Get the socket from the core network filter. This should be used instead of
  323. * accessing the core connection config directly.
  324. * @param c The connection record
  325. * @return The socket
  326. */
  327. AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c);
  328. #ifndef AP_DEBUG
  329. #define AP_CORE_MODULE_INDEX 0
  330. #define ap_get_core_module_config(v) \
  331. (((void **)(v))[AP_CORE_MODULE_INDEX])
  332. #define ap_set_core_module_config(v, val) \
  333. ((((void **)(v))[AP_CORE_MODULE_INDEX]) = (val))
  334. #else
  335. #define AP_CORE_MODULE_INDEX (AP_DEBUG_ASSERT(core_module.module_index == 0), 0)
  336. #endif
  337. /**
  338. * @brief Per-request configuration
  339. */
  340. typedef struct {
  341. /** bucket brigade used by getline for look-ahead and
  342. * ap_get_client_block for holding left-over request body */
  343. struct apr_bucket_brigade *bb;
  344. /** an array of per-request working data elements, accessed
  345. * by ID using ap_get_request_note()
  346. * (Use ap_register_request_note() during initialization
  347. * to add elements)
  348. */
  349. void **notes;
  350. /** Custom response strings registered via ap_custom_response(),
  351. * or NULL; check per-dir config if nothing found here
  352. */
  353. char **response_code_strings; /* from ap_custom_response(), not from
  354. * ErrorDocument
  355. */
  356. /** per-request document root of the server. This allows mass vhosting
  357. * modules better compatibility with some scripts. Normally the
  358. * context_* info should be used instead */
  359. const char *document_root;
  360. /*
  361. * more fine-grained context information which is set by modules like
  362. * mod_alias and mod_userdir
  363. */
  364. /** the context root directory on disk for the current resource,
  365. * without trailing slash
  366. */
  367. const char *context_document_root;
  368. /** the URI prefix that corresponds to the context_document_root directory,
  369. * without trailing slash
  370. */
  371. const char *context_prefix;
  372. /** There is a script processor installed on the output filter chain,
  373. * so it needs the default_handler to deliver a (script) file into
  374. * the chain so it can process it. Normally, default_handler only
  375. * serves files on a GET request (assuming the file is actual content),
  376. * since other methods are not content-retrieval. This flag overrides
  377. * that behavior, stating that the "content" is actually a script and
  378. * won't actually be delivered as the response for the non-GET method.
  379. */
  380. int deliver_script;
  381. /** Should addition of charset= be suppressed for this request?
  382. */
  383. int suppress_charset;
  384. } core_request_config;
  385. /* Standard entries that are guaranteed to be accessible via
  386. * ap_get_request_note() for each request (additional entries
  387. * can be added with ap_register_request_note())
  388. */
  389. #define AP_NOTE_DIRECTORY_WALK 0
  390. #define AP_NOTE_LOCATION_WALK 1
  391. #define AP_NOTE_FILE_WALK 2
  392. #define AP_NOTE_IF_WALK 3
  393. #define AP_NUM_STD_NOTES 4
  394. /**
  395. * Reserve an element in the core_request_config->notes array
  396. * for some application-specific data
  397. * @return An integer key that can be passed to ap_get_request_note()
  398. * during request processing to access this element for the
  399. * current request.
  400. */
  401. AP_DECLARE(apr_size_t) ap_register_request_note(void);
  402. /**
  403. * Retrieve a pointer to an element in the core_request_config->notes array
  404. * @param r The request
  405. * @param note_num A key for the element: either a value obtained from
  406. * ap_register_request_note() or one of the predefined AP_NOTE_*
  407. * values.
  408. * @return NULL if the note_num is invalid, otherwise a pointer to the
  409. * requested note element.
  410. * @remark At the start of a request, each note element is NULL. The
  411. * handle provided by ap_get_request_note() is a pointer-to-pointer
  412. * so that the caller can point the element to some app-specific
  413. * data structure. The caller should guarantee that any such
  414. * structure will last as long as the request itself.
  415. */
  416. AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num);
  417. typedef unsigned char allow_options_t;
  418. typedef unsigned int overrides_t;
  419. /*
  420. * Bits of info that go into making an ETag for a file
  421. * document. Why a long? Because char historically
  422. * proved too short for Options, and int can be different
  423. * sizes on different platforms.
  424. */
  425. typedef unsigned long etag_components_t;
  426. #define ETAG_UNSET 0
  427. #define ETAG_NONE (1 << 0)
  428. #define ETAG_MTIME (1 << 1)
  429. #define ETAG_INODE (1 << 2)
  430. #define ETAG_SIZE (1 << 3)
  431. #define ETAG_ALL (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
  432. /* This is the default value used */
  433. #define ETAG_BACKWARD (ETAG_MTIME | ETAG_SIZE)
  434. /* Generic ON/OFF/UNSET for unsigned int foo :2 */
  435. #define AP_CORE_CONFIG_OFF (0)
  436. #define AP_CORE_CONFIG_ON (1)
  437. #define AP_CORE_CONFIG_UNSET (2)
  438. /* Generic merge of flag */
  439. #define AP_CORE_MERGE_FLAG(field, to, base, over) to->field = \
  440. over->field != AP_CORE_CONFIG_UNSET \
  441. ? over->field \
  442. : base->field
  443. /**
  444. * @brief Server Signature Enumeration
  445. */
  446. typedef enum {
  447. srv_sig_unset,
  448. srv_sig_off,
  449. srv_sig_on,
  450. srv_sig_withmail
  451. } server_signature_e;
  452. /**
  453. * @brief Per-directory configuration
  454. */
  455. typedef struct {
  456. /** path of the directory/regex/etc. see also d_is_fnmatch/absolute below */
  457. char *d;
  458. /** the number of slashes in d */
  459. unsigned d_components;
  460. /** If (opts & OPT_UNSET) then no absolute assignment to options has
  461. * been made.
  462. * invariant: (opts_add & opts_remove) == 0
  463. * Which said another way means that the last relative (options + or -)
  464. * assignment made to each bit is recorded in exactly one of opts_add
  465. * or opts_remove.
  466. */
  467. allow_options_t opts;
  468. allow_options_t opts_add;
  469. allow_options_t opts_remove;
  470. overrides_t override;
  471. allow_options_t override_opts;
  472. /* Used to be the custom response config. No longer used. */
  473. char **response_code_strings; /* from ErrorDocument, not from
  474. * ap_custom_response() */
  475. /* Hostname resolution etc */
  476. #define HOSTNAME_LOOKUP_OFF 0
  477. #define HOSTNAME_LOOKUP_ON 1
  478. #define HOSTNAME_LOOKUP_DOUBLE 2
  479. #define HOSTNAME_LOOKUP_UNSET 3
  480. unsigned int hostname_lookups : 4;
  481. unsigned int content_md5 : 2; /* calculate Content-MD5? */
  482. #define USE_CANONICAL_NAME_OFF (0)
  483. #define USE_CANONICAL_NAME_ON (1)
  484. #define USE_CANONICAL_NAME_DNS (2)
  485. #define USE_CANONICAL_NAME_UNSET (3)
  486. unsigned use_canonical_name : 2;
  487. /* since is_fnmatch(conf->d) was being called so frequently in
  488. * directory_walk() and its relatives, this field was created and
  489. * is set to the result of that call.
  490. */
  491. unsigned d_is_fnmatch : 1;
  492. /* should we force a charset on any outgoing parameterless content-type?
  493. * if so, which charset?
  494. */
  495. #define ADD_DEFAULT_CHARSET_OFF (0)
  496. #define ADD_DEFAULT_CHARSET_ON (1)
  497. #define ADD_DEFAULT_CHARSET_UNSET (2)
  498. unsigned add_default_charset : 2;
  499. const char *add_default_charset_name;
  500. /* System Resource Control */
  501. #ifdef RLIMIT_CPU
  502. struct rlimit *limit_cpu;
  503. #endif
  504. #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
  505. struct rlimit *limit_mem;
  506. #endif
  507. #ifdef RLIMIT_NPROC
  508. struct rlimit *limit_nproc;
  509. #endif
  510. apr_off_t limit_req_body; /* limit on bytes in request msg body */
  511. long limit_xml_body; /* limit on bytes in XML request msg body */
  512. /* logging options */
  513. server_signature_e server_signature;
  514. /* Access control */
  515. apr_array_header_t *sec_file;
  516. apr_array_header_t *sec_if;
  517. ap_regex_t *r;
  518. const char *mime_type; /* forced with ForceType */
  519. const char *handler; /* forced by something other than SetHandler */
  520. const char *output_filters; /* forced with SetOutputFilters */
  521. const char *input_filters; /* forced with SetInputFilters */
  522. int accept_path_info; /* forced with AcceptPathInfo */
  523. /*
  524. * What attributes/data should be included in ETag generation?
  525. */
  526. etag_components_t etag_bits;
  527. etag_components_t etag_add;
  528. etag_components_t etag_remove;
  529. /*
  530. * Run-time performance tuning
  531. */
  532. #define ENABLE_MMAP_OFF (0)
  533. #define ENABLE_MMAP_ON (1)
  534. #define ENABLE_MMAP_UNSET (2)
  535. unsigned int enable_mmap : 2; /* whether files in this dir can be mmap'ed */
  536. #define ENABLE_SENDFILE_OFF (0)
  537. #define ENABLE_SENDFILE_ON (1)
  538. #define ENABLE_SENDFILE_UNSET (2)
  539. unsigned int enable_sendfile : 2; /* files in this dir can be sendfile'ed */
  540. #define USE_CANONICAL_PHYS_PORT_OFF (0)
  541. #define USE_CANONICAL_PHYS_PORT_ON (1)
  542. #define USE_CANONICAL_PHYS_PORT_UNSET (2)
  543. unsigned int use_canonical_phys_port : 2;
  544. unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
  545. * pitched indiscriminately */
  546. unsigned int decode_encoded_slashes : 1; /* whether to decode encoded slashes in URLs */
  547. #define AP_CONDITION_IF 1
  548. #define AP_CONDITION_ELSE 2
  549. #define AP_CONDITION_ELSEIF (AP_CONDITION_ELSE|AP_CONDITION_IF)
  550. unsigned int condition_ifelse : 2; /* is this an <If>, <ElseIf>, or <Else> */
  551. ap_expr_info_t *condition; /* Conditionally merge <If> sections */
  552. /** per-dir log config */
  553. struct ap_logconf *log;
  554. /** Table of directives allowed per AllowOverrideList */
  555. apr_table_t *override_list;
  556. #define AP_MAXRANGES_UNSET -1
  557. #define AP_MAXRANGES_DEFAULT -2
  558. #define AP_MAXRANGES_UNLIMITED -3
  559. #define AP_MAXRANGES_NORANGES 0
  560. /** Number of Ranges before returning HTTP_OK. **/
  561. int max_ranges;
  562. /** Max number of Range overlaps (merges) allowed **/
  563. int max_overlaps;
  564. /** Max number of Range reversals (eg: 200-300, 100-125) allowed **/
  565. int max_reversals;
  566. /** Named back references */
  567. apr_array_header_t *refs;
  568. /** Custom response config with expression support. The hash table
  569. * contains compiled expressions keyed against the custom response
  570. * code.
  571. */
  572. apr_hash_t *response_code_exprs;
  573. #define AP_CGI_PASS_AUTH_OFF (0)
  574. #define AP_CGI_PASS_AUTH_ON (1)
  575. #define AP_CGI_PASS_AUTH_UNSET (2)
  576. /** CGIPassAuth: Whether HTTP authorization headers will be passed to
  577. * scripts as CGI variables; affects all modules calling
  578. * ap_add_common_vars(), as well as any others using this field as
  579. * advice
  580. */
  581. unsigned int cgi_pass_auth : 2;
  582. unsigned int qualify_redirect_url :2;
  583. ap_expr_info_t *expr_handler; /* forced with SetHandler */
  584. /** Table of rules for building CGI variables, NULL if none configured */
  585. apr_hash_t *cgi_var_rules;
  586. } core_dir_config;
  587. /* macro to implement off by default behaviour */
  588. #define AP_SENDFILE_ENABLED(x) \
  589. ((x) == ENABLE_SENDFILE_ON ? APR_SENDFILE_ENABLED : 0)
  590. /* Per-server core configuration */
  591. typedef struct {
  592. char *gprof_dir;
  593. /* Name translations --- we want the core to be able to do *something*
  594. * so it's at least a minimally functional web server on its own (and
  595. * can be tested that way). But let's keep it to the bare minimum:
  596. */
  597. const char *ap_document_root;
  598. /* Access control */
  599. char *access_name;
  600. apr_array_header_t *sec_dir;
  601. apr_array_header_t *sec_url;
  602. /* recursion backstopper */
  603. int redirect_limit; /* maximum number of internal redirects */
  604. int subreq_limit; /* maximum nesting level of subrequests */
  605. const char *protocol;
  606. apr_table_t *accf_map;
  607. /* array of ap_errorlog_format_item for error log format string */
  608. apr_array_header_t *error_log_format;
  609. /*
  610. * two arrays of arrays of ap_errorlog_format_item for additional information
  611. * logged to the error log once per connection/request
  612. */
  613. apr_array_header_t *error_log_conn;
  614. apr_array_header_t *error_log_req;
  615. /* TRACE control */
  616. #define AP_TRACE_UNSET -1
  617. #define AP_TRACE_DISABLE 0
  618. #define AP_TRACE_ENABLE 1
  619. #define AP_TRACE_EXTENDED 2
  620. int trace_enable;
  621. #define AP_MERGE_TRAILERS_UNSET 0
  622. #define AP_MERGE_TRAILERS_ENABLE 1
  623. #define AP_MERGE_TRAILERS_DISABLE 2
  624. int merge_trailers;
  625. apr_array_header_t *protocols;
  626. int protocols_honor_order;
  627. #define AP_HTTP09_UNSET 0
  628. #define AP_HTTP09_ENABLE 1
  629. #define AP_HTTP09_DISABLE 2
  630. char http09_enable;
  631. #define AP_HTTP_CONFORMANCE_UNSET 0
  632. #define AP_HTTP_CONFORMANCE_UNSAFE 1
  633. #define AP_HTTP_CONFORMANCE_STRICT 2
  634. char http_conformance;
  635. #define AP_HTTP_METHODS_UNSET 0
  636. #define AP_HTTP_METHODS_LENIENT 1
  637. #define AP_HTTP_METHODS_REGISTERED 2
  638. char http_methods;
  639. unsigned int merge_slashes;
  640. } core_server_config;
  641. /* for AddOutputFiltersByType in core.c */
  642. void ap_add_output_filters_by_type(request_rec *r);
  643. /* for http_config.c */
  644. void ap_core_reorder_directories(apr_pool_t *, server_rec *);
  645. /* for mod_perl */
  646. AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
  647. AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
  648. AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
  649. AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
  650. AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
  651. /* Core filters; not exported. */
  652. apr_status_t ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
  653. ap_input_mode_t mode, apr_read_type_e block,
  654. apr_off_t readbytes);
  655. apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *b);
  656. AP_DECLARE(const char*) ap_get_server_protocol(server_rec* s);
  657. AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto);
  658. typedef struct core_output_filter_ctx core_output_filter_ctx_t;
  659. typedef struct core_filter_ctx core_ctx_t;
  660. typedef struct core_net_rec {
  661. /** Connection to the client */
  662. apr_socket_t *client_socket;
  663. /** connection record */
  664. conn_rec *c;
  665. core_output_filter_ctx_t *out_ctx;
  666. core_ctx_t *in_ctx;
  667. } core_net_rec;
  668. /**
  669. * Insert the network bucket into the core input filter's input brigade.
  670. * This hook is intended for MPMs or protocol modules that need to do special
  671. * socket setup.
  672. * @param c The connection
  673. * @param bb The brigade to insert the bucket into
  674. * @param socket The socket to put into a bucket
  675. * @return AP_DECLINED if the current function does not handle this connection,
  676. * APR_SUCCESS or an error otherwise.
  677. */
  678. AP_DECLARE_HOOK(apr_status_t, insert_network_bucket,
  679. (conn_rec *c, apr_bucket_brigade *bb, apr_socket_t *socket))
  680. /* ----------------------------------------------------------------------
  681. *
  682. * Runtime status/management
  683. */
  684. typedef enum {
  685. ap_mgmt_type_string,
  686. ap_mgmt_type_long,
  687. ap_mgmt_type_hash
  688. } ap_mgmt_type_e;
  689. typedef union {
  690. const char *s_value;
  691. long i_value;
  692. apr_hash_t *h_value;
  693. } ap_mgmt_value;
  694. typedef struct {
  695. const char *description;
  696. const char *name;
  697. ap_mgmt_type_e vtype;
  698. ap_mgmt_value v;
  699. } ap_mgmt_item_t;
  700. /* Handles for core filters */
  701. AP_DECLARE_DATA extern ap_filter_rec_t *ap_subreq_core_filter_handle;
  702. AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_output_filter_handle;
  703. AP_DECLARE_DATA extern ap_filter_rec_t *ap_content_length_filter_handle;
  704. AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_input_filter_handle;
  705. /**
  706. * This hook provdes a way for modules to provide metrics/statistics about
  707. * their operational status.
  708. *
  709. * @param p A pool to use to create entries in the hash table
  710. * @param val The name of the parameter(s) that is wanted. This is
  711. * tree-structured would be in the form ('*' is all the tree,
  712. * 'module.*' all of the module , 'module.foo.*', or
  713. * 'module.foo.bar' )
  714. * @param ht The hash table to store the results. Keys are item names, and
  715. * the values point to ap_mgmt_item_t structures.
  716. * @ingroup hooks
  717. */
  718. AP_DECLARE_HOOK(int, get_mgmt_items,
  719. (apr_pool_t *p, const char * val, apr_hash_t *ht))
  720. /* ---------------------------------------------------------------------- */
  721. /* ----------------------------------------------------------------------
  722. *
  723. * I/O logging with mod_logio
  724. */
  725. APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out,
  726. (conn_rec *c, apr_off_t bytes));
  727. APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_in,
  728. (conn_rec *c, apr_off_t bytes));
  729. APR_DECLARE_OPTIONAL_FN(apr_off_t, ap_logio_get_last_bytes, (conn_rec *c));
  730. /* ----------------------------------------------------------------------
  731. *
  732. * Error log formats
  733. */
  734. /**
  735. * The info structure passed to callback functions of errorlog handlers.
  736. * Not all information is available in all contexts. In particular, all
  737. * pointers may be NULL.
  738. */
  739. typedef struct ap_errorlog_info {
  740. /** current server_rec.
  741. * Should be preferred over c->base_server and r->server
  742. */
  743. const server_rec *s;
  744. /** current conn_rec.
  745. * Should be preferred over r->connection
  746. */
  747. const conn_rec *c;
  748. /** current request_rec. */
  749. const request_rec *r;
  750. /** r->main if r is a subrequest, otherwise equal to r */
  751. const request_rec *rmain;
  752. /** pool passed to ap_log_perror, NULL otherwise */
  753. apr_pool_t *pool;
  754. /** name of source file where the log message was produced, NULL if N/A. */
  755. const char *file;
  756. /** line number in the source file, 0 if N/A */
  757. int line;
  758. /** module index of module that produced the log message, APLOG_NO_MODULE if N/A. */
  759. int module_index;
  760. /** log level of error message (flags like APLOG_STARTUP have been removed), -1 if N/A */
  761. int level;
  762. /** apr error status related to the log message, 0 if no error */
  763. apr_status_t status;
  764. /** 1 if logging to syslog, 0 otherwise */
  765. int using_syslog;
  766. /** 1 if APLOG_STARTUP was set for the log message, 0 otherwise */
  767. int startup;
  768. /** message format */
  769. const char *format;
  770. } ap_errorlog_info;
  771. /**
  772. * callback function prototype for a external errorlog handler
  773. * @note To avoid unbounded memory usage, these functions must not allocate
  774. * memory from the server, connection, or request pools. If an errorlog
  775. * handler absolutely needs a pool to pass to other functions, it must create
  776. * and destroy a sub-pool.
  777. */
  778. typedef int ap_errorlog_handler_fn_t(const ap_errorlog_info *info,
  779. const char *arg, char *buf, int buflen);
  780. /**
  781. * Register external errorlog handler
  782. * @param p config pool to use
  783. * @param tag the new format specifier (i.e. the letter after the %)
  784. * @param handler the handler function
  785. * @param flags flags (reserved, set to 0)
  786. */
  787. AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag,
  788. ap_errorlog_handler_fn_t *handler,
  789. int flags);
  790. typedef struct ap_errorlog_handler {
  791. ap_errorlog_handler_fn_t *func;
  792. int flags; /* for future extensions */
  793. } ap_errorlog_handler;
  794. /** item starts a new field */
  795. #define AP_ERRORLOG_FLAG_FIELD_SEP 1
  796. /** item is the actual error message */
  797. #define AP_ERRORLOG_FLAG_MESSAGE 2
  798. /** skip whole line if item is zero-length */
  799. #define AP_ERRORLOG_FLAG_REQUIRED 4
  800. /** log zero-length item as '-' */
  801. #define AP_ERRORLOG_FLAG_NULL_AS_HYPHEN 8
  802. typedef struct {
  803. /** ap_errorlog_handler function */
  804. ap_errorlog_handler_fn_t *func;
  805. /** argument passed to item in {} */
  806. const char *arg;
  807. /** a combination of the AP_ERRORLOG_* flags */
  808. unsigned int flags;
  809. /** only log item if the message's log level is higher than this */
  810. unsigned int min_loglevel;
  811. } ap_errorlog_format_item;
  812. /**
  813. * hook method to log error messages
  814. * @ingroup hooks
  815. * @param info pointer to ap_errorlog_info struct which contains all
  816. * the details
  817. * @param errstr the (unformatted) message to log
  818. * @warning Allocating from the usual pools (pool, info->c->pool, info->p->pool)
  819. * must be avoided because it can cause memory leaks.
  820. * Use a subpool if necessary.
  821. */
  822. AP_DECLARE_HOOK(void, error_log, (const ap_errorlog_info *info,
  823. const char *errstr))
  824. AP_CORE_DECLARE(void) ap_register_log_hooks(apr_pool_t *p);
  825. AP_CORE_DECLARE(void) ap_register_config_hooks(apr_pool_t *p);
  826. /* ----------------------------------------------------------------------
  827. *
  828. * ident lookups with mod_ident
  829. */
  830. APR_DECLARE_OPTIONAL_FN(const char *, ap_ident_lookup,
  831. (request_rec *r));
  832. /* ----------------------------------------------------------------------
  833. *
  834. * authorization values with mod_authz_core
  835. */
  836. APR_DECLARE_OPTIONAL_FN(int, authz_some_auth_required, (request_rec *r));
  837. APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_type, (request_rec *r));
  838. APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_name, (request_rec *r));
  839. /* ----------------------------------------------------------------------
  840. *
  841. * authorization values with mod_access_compat
  842. */
  843. APR_DECLARE_OPTIONAL_FN(int, access_compat_ap_satisfies, (request_rec *r));
  844. /* ---------------------------------------------------------------------- */
  845. /** Query the server for some state information
  846. * @param query_code Which information is requested
  847. * @return the requested state information
  848. */
  849. AP_DECLARE(int) ap_state_query(int query_code);
  850. /*
  851. * possible values for query_code in ap_state_query()
  852. */
  853. /** current status of the server */
  854. #define AP_SQ_MAIN_STATE 0
  855. /** are we going to serve requests or are we just testing/dumping config */
  856. #define AP_SQ_RUN_MODE 1
  857. /** generation of the top-level apache parent */
  858. #define AP_SQ_CONFIG_GEN 2
  859. /*
  860. * return values for ap_state_query()
  861. */
  862. /** return value for unknown query_code */
  863. #define AP_SQ_NOT_SUPPORTED -1
  864. /* values returned for AP_SQ_MAIN_STATE */
  865. /** before the config preflight */
  866. #define AP_SQ_MS_INITIAL_STARTUP 1
  867. /** initial configuration run for setting up log config, etc. */
  868. #define AP_SQ_MS_CREATE_PRE_CONFIG 2
  869. /** tearing down configuration */
  870. #define AP_SQ_MS_DESTROY_CONFIG 3
  871. /** normal configuration run */
  872. #define AP_SQ_MS_CREATE_CONFIG 4
  873. /** running the MPM */
  874. #define AP_SQ_MS_RUN_MPM 5
  875. /** cleaning up for exit */
  876. #define AP_SQ_MS_EXITING 6
  877. /* values returned for AP_SQ_RUN_MODE */
  878. /** command line not yet parsed */
  879. #define AP_SQ_RM_UNKNOWN 1
  880. /** normal operation (server requests or signal server) */
  881. #define AP_SQ_RM_NORMAL 2
  882. /** config test only */
  883. #define AP_SQ_RM_CONFIG_TEST 3
  884. /** only dump some parts of the config */
  885. #define AP_SQ_RM_CONFIG_DUMP 4
  886. #ifdef __cplusplus
  887. }
  888. #endif
  889. #endif /* !APACHE_HTTP_CORE_H */
  890. /** @} */