http_config.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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. * The central data structures around here...
  18. }
  19. { Command dispatch structures... }
  20. { Note that for all of these except RAW_ARGS, the config routine is
  21. * passed a freshly allocated string which can be modified or stored
  22. * or whatever... it's only necessary to do pstrdup() stuff with
  23. * RAW_ARGS.
  24. }
  25. type
  26. cmd_how = (
  27. RAW_ARGS, { cmd_func parses command line itself }
  28. TAKE1, { one argument only }
  29. TAKE2, { two arguments only }
  30. ITERATE, { one argument, occuring multiple times
  31. * (e.g., IndexIgnore)
  32. }
  33. ITERATE2, { two arguments, 2nd occurs multiple times
  34. * (e.g., AddIcon)
  35. }
  36. FLAG, { One of 'On' or 'Off' }
  37. NO_ARGS, { No args at all, e.g. </Directory> }
  38. TAKE12, { one or two arguments }
  39. TAKE3, { three arguments only }
  40. TAKE23, { two or three arguments }
  41. TAKE123, { one, two or three arguments }
  42. TAKE13 { one or three arguments }
  43. );
  44. cs_func_t = function (): PChar;
  45. command_struct = record
  46. name: PChar; { Name of this command }
  47. func: cs_func_t; { Function invoked }
  48. cmd_data: Pointer; { Extra data, for functions which
  49. * implement multiple commands...
  50. }
  51. req_override: cint; { What overrides need to be allowed to
  52. * enable this command.
  53. }
  54. args_how: cmd_how; { What the command expects as arguments }
  55. errmsg: PChar; { 'usage' message, in case of syntax errors }
  56. end;
  57. command_rec = command_struct;
  58. Pcommand_rec = ^command_rec;
  59. { The allowed locations for a configuration directive are the union of
  60. * those indicated by each set bit in the req_override mask.
  61. *
  62. * (req_override & RSRC_CONF) => *.conf outside <Directory> or <Location>
  63. * (req_override & ACCESS_CONF) => *.conf inside <Directory> or <Location>
  64. * (req_override & OR_AUTHCFG) => *.conf inside <Directory> or <Location>
  65. * and .htaccess when AllowOverride AuthConfig
  66. * (req_override & OR_LIMIT) => *.conf inside <Directory> or <Location>
  67. * and .htaccess when AllowOverride Limit
  68. * (req_override & OR_OPTIONS) => *.conf anywhere
  69. * and .htaccess when AllowOverride Options
  70. * (req_override & OR_FILEINFO) => *.conf anywhere
  71. * and .htaccess when AllowOverride FileInfo
  72. * (req_override & OR_INDEXES) => *.conf anywhere
  73. * and .htaccess when AllowOverride Indexes
  74. }
  75. const
  76. OR_NONE = 0;
  77. OR_LIMIT = 1;
  78. OR_OPTIONS = 2;
  79. OR_FILEINFO = 4;
  80. OR_AUTHCFG = 8;
  81. OR_INDEXES = 16;
  82. OR_UNSET = 32;
  83. ACCESS_CONF = 64;
  84. RSRC_CONF = 128;
  85. OR_ALL = (OR_LIMIT or OR_OPTIONS or OR_FILEINFO or OR_AUTHCFG or OR_INDEXES);
  86. { This can be returned by a function if they don't wish to handle
  87. * a command. Make it something not likely someone will actually use
  88. * as an error code.
  89. }
  90. DECLINE_CMD = '\a\b';
  91. {
  92. * This structure is passed to a command which is being invoked,
  93. * to carry a large variety of miscellaneous data which is all of
  94. * use to *somebody*...
  95. }
  96. type
  97. cmd_parms = record
  98. info: Pointer; { Argument to command from cmd_table }
  99. override: cint; { Which allow-override bits are set }
  100. limited: cint; { Which methods are <Limit>ed }
  101. config_file: Pconfigfile_t; { Config file structure from pcfg_openfile() }
  102. pool: Pap_pool; { Pool to allocate new storage in }
  103. temp_pool: Ppool; { Pool for scratch memory; persists during
  104. * configuration, but wiped before the first
  105. * request is served...
  106. }
  107. server: Pserver_rec; { Server_rec being configured for }
  108. path: PChar; { If configuring for a directory,
  109. * pathname of that directory.
  110. * NOPE! That's what it meant previous to the
  111. * existance of <Files>, <Location> and regex
  112. * matching. Now the only usefulness that can
  113. * be derived from this field is whether a command
  114. * is being called in a server context (path == NULL)
  115. * or being called in a dir context (path != NULL).
  116. }
  117. cmd: Pcommand_rec; { configuration command }
  118. end_token: PChar; { end token required to end a nested section }
  119. context: Pointer; { per_dir_config vector passed
  120. * to handle_command }
  121. end;
  122. { This structure records the existence of handlers in a module... }
  123. handler_t = function (param1: Prequest_rec): Integer; cdecl;
  124. Phandler_rec = ^handler_rec;
  125. handler_rec = record
  126. content_type: PChar; { MUST be all lower case }
  127. handler: handler_t;
  128. end;
  129. {
  130. * Module structures. Just about everything is dispatched through
  131. * these, directly or indirectly (through the command and handler
  132. * tables).
  133. }
  134. Pmodule_struct = ^module_struct;
  135. {$ifdef ULTRIX_BRAIN_DEATH}
  136. init_t = procedure (); cdecl;
  137. create_dir_config_t = function (): Pointer; cdecl;
  138. merge_dir_config_t = function (): Pointer; cdecl;
  139. create_server_config_t = function (): Pointer; cdecl;
  140. merge_server_config_t = function (): Pointer; cdecl;
  141. {$else}
  142. init_t = procedure (param1: Pserver_rec; param2: Ppool); cdecl;
  143. create_dir_config_t = function (p: Ppool; dir: PChar): Pointer; cdecl;
  144. merge_dir_config_t = function (p: PPool; base_conf, new_conf: Pointer): Pointer; cdecl;
  145. create_server_config_t = function (p: Ppool; s: Pserver_rec): Pointer; cdecl;
  146. merge_server_config_t = function (p: Ppool; base_conf, new_conf: Pointer): Pointer; cdecl;
  147. {$endif}
  148. hook_t = function (param1: Prequest_rec): cint; cdecl;
  149. {$ifdef ULTRIX_BRAIN_DEATH}
  150. child_init_t = procedure ();
  151. child_exit_t = procedure ();
  152. {$else}
  153. child_init_t = procedure (param1: Pserver_rec; param2: Ppool); cdecl;
  154. child_exit_t = procedure (param1: Pserver_rec; param2: Ppool); cdecl;
  155. {$endif}
  156. module_struct = record
  157. version: cint; { API version, *not* module version;
  158. * check that module is compatible with this
  159. * version of the server.
  160. }
  161. minor_version: cint; { API minor version. Provides API feature
  162. * milestones. Not checked during module init
  163. }
  164. module_index: cint; { Index to this modules structures in
  165. * config vectors.
  166. }
  167. name: PChar;
  168. dynamic_load_handle: Pointer;
  169. next: Pmodule_struct;
  170. magic: culong; { Magic Cookie to identify a module structure;
  171. * It's mainly important for the DSO facility
  172. * (see also mod_so).
  173. }
  174. { init() occurs after config parsing, but before any children are
  175. * forked.
  176. * Modules should not rely on the order in which create_server_config
  177. * and create_dir_config are called.
  178. }
  179. init: init_t;
  180. create_dir_config: create_dir_config_t;
  181. merge_dir_config: merge_dir_config_t;
  182. create_server_config: create_server_config_t;
  183. merge_server_config: merge_server_config_t;
  184. cmds: Pcommand_rec;
  185. handlers: Phandler_rec;
  186. { Hooks for getting into the middle of server ops...
  187. * translate_handler --- translate URI to filename
  188. * access_checker --- check access by host address, etc. All of these
  189. * run; if all decline, that's still OK.
  190. * check_user_id --- get and validate user id from the HTTP request
  191. * auth_checker --- see if the user (from check_user_id) is OK *here*.
  192. * If all of *these* decline, the request is rejected
  193. * (as a SERVER_ERROR, since the module which was
  194. * supposed to handle this was configured wrong).
  195. * type_checker --- Determine MIME type of the requested entity;
  196. * sets content_type, _encoding and _language fields.
  197. * logger --- log a transaction.
  198. * post_read_request --- run right after read_request or internal_redirect,
  199. * and not run during any subrequests.
  200. }
  201. translate_handler: hook_t;
  202. ap_check_user_id: hook_t;
  203. auth_checker: hook_t;
  204. access_checker: hook_t;
  205. type_checker: hook_t;
  206. fixer_upper: hook_t;
  207. logger: hook_t;
  208. header_parser: hook_t;
  209. { Regardless of the model the server uses for managing "units of
  210. * execution", i.e. multi-process, multi-threaded, hybrids of those,
  211. * there is the concept of a "heavy weight process". That is, a
  212. * process with its own memory space, file spaces, etc. This method,
  213. * child_init, is called once for each heavy-weight process before
  214. * any requests are served. Note that no provision is made yet for
  215. * initialization per light-weight process (i.e. thread). The
  216. * parameters passed here are the same as those passed to the global
  217. * init method above.
  218. }
  219. child_init: child_init_t;
  220. child_exit: child_exit_t;
  221. post_read_request: hook_t;
  222. end;
  223. module = module_struct;
  224. Pmodule = ^module;
  225. { Initializer for the first few module slots, which are only
  226. * really set up once we start running. Note that the first two slots
  227. * provide a version check; this should allow us to deal with changes to
  228. * the API. The major number should reflect changes to the API handler table
  229. * itself or removal of functionality. The minor number should reflect
  230. * additions of functionality to the existing API. (the server can detect
  231. * an old-format module, and either handle it back-compatibly, or at least
  232. * signal an error). See src/include/ap_mmn.h for MMN version history.
  233. }
  234. procedure STANDARD_MODULE_STUFF(var mod_: module);
  235. { Generic accessors for other modules to get at their own module-specific
  236. * data
  237. }
  238. {API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m);
  239. API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val);
  240. #define ap_get_module_config(v,m) \
  241. (((void **)(v))[(m)->module_index])
  242. #define ap_set_module_config(v,m,val) \
  243. ((((void **)(v))[(m)->module_index]) = (val))}
  244. { Generic command handling function... }
  245. {API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *);
  246. API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, char *);
  247. API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int);
  248. API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *);}
  249. { For modules which need to read config files, open logs, etc. ...
  250. * this returns the fname argument if it begins with '/'; otherwise
  251. * it relativizes it wrt server_root.
  252. }
  253. //API_EXPORT(char *) ap_server_root_relative(pool *p, char *fname);
  254. { Finally, the hook for dynamically loading modules in... }
  255. procedure ap_add_module(m: Pmodule);
  256. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  257. procedure ap_remove_module(m: Pmodule);
  258. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  259. procedure ap_add_loaded_module(m: Pmodule);
  260. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  261. function ap_add_named_module(const name: PChar): cint;
  262. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  263. procedure ap_clear_module_list();
  264. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  265. function ap_find_module_name(m: Pmodule): PChar;
  266. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  267. function ap_find_linked_module(const name: PChar): Pmodule;
  268. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF} external LibHTTPD;
  269. { for implementing subconfigs and customized config files }
  270. {API_EXPORT(const char *) ap_srm_command_loop(cmd_parms *parms, void *config);
  271. #ifdef CORE_PRIVATE
  272. extern API_VAR_EXPORT module *top_module;
  273. extern module *ap_prelinked_modules[];
  274. extern module *ap_preloaded_modules[];
  275. extern API_VAR_EXPORT module **ap_loaded_modules;}
  276. { For mod_so.c... }
  277. //API_EXPORT(void) ap_single_module_configure(pool *p, server_rec *s, module *m);
  278. { For http_main.c... }
  279. {API_EXPORT(server_rec *) ap_read_config(pool *conf_pool, pool *temp_pool, char *config_name);
  280. API_EXPORT(void) ap_init_modules(pool *p, server_rec *s);
  281. API_EXPORT(void) ap_child_init_modules(pool *p, server_rec *s);
  282. API_EXPORT(void) ap_child_exit_modules(pool *p, server_rec *s);
  283. API_EXPORT(void) ap_setup_prelinked_modules(void);
  284. API_EXPORT(void) ap_show_directives(void);
  285. API_EXPORT(void) ap_show_modules(void);
  286. void ap_cleanup_method_ptrs(void);}
  287. { For http_request.c... }
  288. {CORE_EXPORT(void *) ap_create_request_config(pool *p);
  289. CORE_EXPORT(void *) ap_create_per_dir_config(pool *p);
  290. CORE_EXPORT(void *) ap_merge_per_dir_configs(pool *p, void *base, void *new);}
  291. { For http_core.c... (<Directory> command and virtual hosts) }
  292. {CORE_EXPORT(int) ap_parse_htaccess(void **result, request_rec *r, int override,
  293. const char *path, const char *access_name);
  294. CORE_EXPORT(const char *) ap_init_virtual_host(pool *p, const char *hostname,
  295. server_rec *main_server, server_rec **);
  296. CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, pool *p, pool *ptemp);
  297. }
  298. { ap_check_cmd_context() definitions: }
  299. //API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);
  300. { ap_check_cmd_context(): Forbidden in: }
  301. const
  302. NOT_IN_VIRTUALHOST = $01; { <Virtualhost> }
  303. NOT_IN_LIMIT = $02; { <Limit> }
  304. NOT_IN_DIRECTORY = $04; { <Directory> }
  305. NOT_IN_LOCATION = $08; { <Location> }
  306. NOT_IN_FILES = $10; { <Files> }
  307. NOT_IN_DIR_LOC_FILE = (NOT_IN_DIRECTORY or NOT_IN_LOCATION or NOT_IN_FILES); { <Directory>/<Location>/<Files>}
  308. GLOBAL_ONLY = (NOT_IN_VIRTUALHOST or NOT_IN_LIMIT or NOT_IN_DIR_LOC_FILE);
  309. { Module-method dispatchers, also for http_request.c }
  310. //API_EXPORT(int) ap_translate_name(request_rec *);
  311. //API_EXPORT(int) ap_check_access(request_rec *); { check access on non-auth basis }
  312. //API_EXPORT(int) ap_check_user_id(request_rec *); { obtain valid username from client auth }
  313. //API_EXPORT(int) ap_check_auth(request_rec *); { check (validated) user is authorized here }
  314. //API_EXPORT(int) ap_find_types(request_rec *); { identify MIME type }
  315. //API_EXPORT(int) ap_run_fixups(request_rec *); { poke around for other metainfo, etc.... }
  316. //API_EXPORT(int) ap_invoke_handler(request_rec *);
  317. //API_EXPORT(int) ap_log_transaction(request_rec *r);
  318. //API_EXPORT(int) ap_header_parse(request_rec *);
  319. //API_EXPORT(int) ap_run_post_read_request(request_rec *);
  320. { for mod_perl }
  321. //CORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds);
  322. //CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod);
  323. //CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod);
  324. //CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l);
  325. //#endif