mod_example.pp 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. { Copyright 1999-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * 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. * Apache example module. Provide demonstrations of how modules do things.
  18. * It is not meant to be used in a production server. Since it participates
  19. * in all of the processing phases, it could conceivable interfere with
  20. * the proper operation of other modules -- particularly the ones related
  21. * to security.
  22. *
  23. * In the interest of brevity, all functions and structures internal to
  24. * this module, but which may have counterparts in *real* modules, are
  25. * prefixed with 'x_' instead of 'example_'.
  26. }
  27. library mod_example;
  28. {$i define.inc}
  29. uses
  30. Classes, SysUtils, httpd, apr, aprutil;
  31. var
  32. example_module: module; {$ifdef Unix} public name 'example_module'; {$endif}
  33. default_module_ptr: Pmodule;
  34. {$ifdef WINDOWS}
  35. exports
  36. example_module name 'example_module';
  37. {$endif}
  38. const
  39. MODULE_NAME = 'mod_example.so';
  40. {--------------------------------------------------------------------------}
  41. { }
  42. { Data declarations. }
  43. { }
  44. { Here are the static cells and structure declarations private to our }
  45. { module. }
  46. { }
  47. {--------------------------------------------------------------------------}
  48. {
  49. * Sample configuration record. Used for both per-directory and per-server
  50. * configuration data.
  51. *
  52. * It's perfectly reasonable to have two different structures for the two
  53. * different environments. The same command handlers will be called for
  54. * both, though, so the handlers need to be able to tell them apart. One
  55. * possibility is for both structures to start with an int which is 0 for
  56. * one and 1 for the other.
  57. *
  58. * Note that while the per-directory and per-server configuration records are
  59. * available to most of the module handlers, they should be treated as
  60. * READ-ONLY by all except the command and merge handlers. Sometimes handlers
  61. * are handed a record that applies to the current location by implication or
  62. * inheritance, and modifying it will change the rules for other locations.
  63. }
  64. const
  65. CONFIG_MODE_SERVER = 1;
  66. CONFIG_MODE_DIRECTORY = 2;
  67. CONFIG_MODE_COMBO = 3; { Shouldn't ever happen. }
  68. type
  69. x_cfg = record
  70. cmode: Integer; { Environment to which record applies
  71. * (directory, server, or combination).
  72. }
  73. local: Integer; { Boolean: "Example" directive declared
  74. * here?
  75. }
  76. congenital: Integer; { Boolean: did we inherit an "Example"? }
  77. trace: PChar; { Pointer to trace string. }
  78. loc: PChar; { Location to which this record applies. }
  79. end;
  80. Px_cfg = ^x_cfg;
  81. {
  82. * Let's set up a module-local static cell to point to the accreting callback
  83. * trace. As each API callback is made to us, we'll tack on the particulars
  84. * to whatever we've already recorded. To avoid massive memory bloat as
  85. * directories are walked again and again, we record the routine/environment
  86. * the first time (non-request context only), and ignore subsequent calls for
  87. * the same routine/environment.
  88. }
  89. var
  90. trace: PChar = nil;
  91. static_calls_made: Papr_table_t = nil;
  92. {
  93. * To avoid leaking memory from pools other than the per-request one, we
  94. * allocate a module-private pool, and then use a sub-pool of that which gets
  95. * freed each time we modify the trace. That way previous layers of trace
  96. * data don't get lost.
  97. }
  98. x_pool: Papr_pool_t = nil;
  99. x_subpool: Papr_pool_t = nil;
  100. {--------------------------------------------------------------------------}
  101. { }
  102. { The following pseudo-prototype declarations illustrate the parameters }
  103. { passed to command handlers for the different types of directive }
  104. { syntax. If an argument was specified in the directive definition }
  105. { (look for "command_rec" below), it's available to the command handler }
  106. { via the (void *) info field in the cmd_parms argument passed to the }
  107. { handler (cmd->info for the examples below). }
  108. { }
  109. {--------------------------------------------------------------------------}
  110. {
  111. * Command handler for a NO_ARGS directive. Declared in the command_rec
  112. * list with
  113. * AP_INIT_NO_ARGS("directive", function, mconfig, where, help)
  114. *
  115. * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig);
  116. }
  117. {
  118. * Command handler for a RAW_ARGS directive. The "args" argument is the text
  119. * of the commandline following the directive itself. Declared in the
  120. * command_rec list with
  121. * AP_INIT_RAW_ARGS("directive", function, mconfig, where, help)
  122. *
  123. * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig,
  124. * const char *args);
  125. }
  126. {
  127. * Command handler for a FLAG directive. The single parameter is passed in
  128. * "bool", which is either zero or not for Off or On respectively.
  129. * Declared in the command_rec list with
  130. * AP_INIT_FLAG("directive", function, mconfig, where, help)
  131. *
  132. * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool);
  133. }
  134. {
  135. * Command handler for a TAKE1 directive. The single parameter is passed in
  136. * "word1". Declared in the command_rec list with
  137. * AP_INIT_TAKE1("directive", function, mconfig, where, help)
  138. *
  139. * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig,
  140. * char *word1);
  141. }
  142. {
  143. * Command handler for a TAKE2 directive. TAKE2 commands must always have
  144. * exactly two arguments. Declared in the command_rec list with
  145. * AP_INIT_TAKE2("directive", function, mconfig, where, help)
  146. *
  147. * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig,
  148. * char *word1, char *word2);
  149. }
  150. {
  151. * Command handler for a TAKE3 directive. Like TAKE2, these must have exactly
  152. * three arguments, or the parser complains and doesn't bother calling us.
  153. * Declared in the command_rec list with
  154. * AP_INIT_TAKE3("directive", function, mconfig, where, help)
  155. *
  156. * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig,
  157. * char *word1, char *word2, char *word3);
  158. }
  159. {
  160. * Command handler for a TAKE12 directive. These can take either one or two
  161. * arguments.
  162. * - word2 is a NULL pointer if no second argument was specified.
  163. * Declared in the command_rec list with
  164. * AP_INIT_TAKE12("directive", function, mconfig, where, help)
  165. *
  166. * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig,
  167. * char *word1, char *word2);
  168. }
  169. {
  170. * Command handler for a TAKE123 directive. A TAKE123 directive can be given,
  171. * as might be expected, one, two, or three arguments.
  172. * - word2 is a NULL pointer if no second argument was specified.
  173. * - word3 is a NULL pointer if no third argument was specified.
  174. * Declared in the command_rec list with
  175. * AP_INIT_TAKE123("directive", function, mconfig, where, help)
  176. *
  177. * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig,
  178. * char *word1, char *word2, char *word3);
  179. }
  180. {
  181. * Command handler for a TAKE13 directive. Either one or three arguments are
  182. * permitted - no two-parameters-only syntax is allowed.
  183. * - word2 and word3 are NULL pointers if only one argument was specified.
  184. * Declared in the command_rec list with
  185. * AP_INIT_TAKE13("directive", function, mconfig, where, help)
  186. *
  187. * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig,
  188. * char *word1, char *word2, char *word3);
  189. }
  190. {
  191. * Command handler for a TAKE23 directive. At least two and as many as three
  192. * arguments must be specified.
  193. * - word3 is a NULL pointer if no third argument was specified.
  194. * Declared in the command_rec list with
  195. * AP_INIT_TAKE23("directive", function, mconfig, where, help)
  196. *
  197. * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig,
  198. * char *word1, char *word2, char *word3);
  199. }
  200. {
  201. * Command handler for a ITERATE directive.
  202. * - Handler is called once for each of n arguments given to the directive.
  203. * - word1 points to each argument in turn.
  204. * Declared in the command_rec list with
  205. * AP_INIT_ITERATE("directive", function, mconfig, where, help)
  206. *
  207. * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig,
  208. * char *word1);
  209. }
  210. {
  211. * Command handler for a ITERATE2 directive.
  212. * - Handler is called once for each of the second and subsequent arguments
  213. * given to the directive.
  214. * - word1 is the same for each call for a particular directive instance (the
  215. * first argument).
  216. * - word2 points to each of the second and subsequent arguments in turn.
  217. * Declared in the command_rec list with
  218. * AP_INIT_ITERATE2("directive", function, mconfig, where, help)
  219. *
  220. * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig,
  221. * char *word1, char *word2);
  222. }
  223. {--------------------------------------------------------------------------}
  224. { }
  225. { These routines are strictly internal to this module, and support its }
  226. { operation. They are not referenced by any external portion of the }
  227. { server. }
  228. { }
  229. {--------------------------------------------------------------------------}
  230. {
  231. * Locate our directory configuration record for the current request.
  232. }
  233. function our_dconfig(const r: Prequest_rec): Px_cfg; cdecl;
  234. begin
  235. Result := Px_cfg(ap_get_module_config(r^.per_dir_config, @example_module));
  236. end;
  237. //#if 0
  238. {
  239. * Locate our server configuration record for the specified server.
  240. }
  241. function our_sconfig(const s: Pserver_rec): Px_cfg; cdecl;
  242. begin
  243. Result := Px_cfg(ap_get_module_config(s^.module_config, @example_module));
  244. end;
  245. {
  246. * Likewise for our configuration record for the specified request.
  247. }
  248. function our_rconfig(const r: Prequest_rec): Px_cfg; cdecl;
  249. begin
  250. Result := Px_cfg(ap_get_module_config(r^.request_config, @example_module));
  251. end;
  252. //#endif
  253. {
  254. * Likewise for our configuration record for a connection.
  255. }
  256. function our_cconfig(const c: Pconn_rec): Px_cfg; cdecl;
  257. begin
  258. Result := Px_cfg(ap_get_module_config(c^.conn_config, @example_module));
  259. end;
  260. {
  261. * This routine sets up some module-wide cells if they haven't been already.
  262. }
  263. procedure setup_module_cells; cdecl;
  264. begin
  265. {
  266. * If we haven't already allocated our module-private pool, do so now.
  267. }
  268. if (x_pool = nil) then apr_pool_create(@x_pool, nil);
  269. {
  270. * Likewise for the table of routine/environment pairs we visit outside of
  271. * request context.
  272. }
  273. if (static_calls_made = nil) then static_calls_made := apr_table_make(x_pool, 16);
  274. end;
  275. {
  276. * This routine is used to add a trace of a callback to the list. We're
  277. * passed the server record (if available), the request record (if available),
  278. * a pointer to our private configuration record (if available) for the
  279. * environment to which the callback is supposed to apply, and some text. We
  280. * turn this into a textual representation and add it to the tail of the list.
  281. * The list can be displayed by the x_handler() routine.
  282. *
  283. * If the call occurs within a request context (i.e., we're passed a request
  284. * record), we put the trace into the request apr_pool_t and attach it to the
  285. * request via the notes mechanism. Otherwise, the trace gets added
  286. * to the static (non-request-specific) list.
  287. *
  288. * Note that the r^.notes table is only for storing strings; if you need to
  289. * maintain per-request data of any other type, you need to use another
  290. * mechanism.
  291. }
  292. const
  293. TRACE_NOTE = 'example-trace';
  294. EXAMPLE_LOG_EACH = 0;
  295. procedure trace_add(s: Pserver_rec; r: Prequest_rec; mconfig: Px_cfg; const note: PChar); cdecl;
  296. var
  297. sofar, addon, where, trace_copy, key: PChar;
  298. p: Papr_pool_t;
  299. begin
  300. {
  301. * Make sure our pools and tables are set up - we need 'em.
  302. }
  303. setup_module_cells();
  304. {
  305. * Now, if we're in request-context, we use the request pool.
  306. }
  307. if (r <> nil) then
  308. begin
  309. p := r^.pool;
  310. trace_copy := apr_table_get(r^.notes, TRACE_NOTE);
  311. if (trace_copy = nil) then trace_copy := '';
  312. end
  313. else
  314. begin
  315. {
  316. * We're not in request context, so the trace gets attached to our
  317. * module-wide pool. We do the create/destroy every time we're called
  318. * in non-request context; this avoids leaking memory in some of
  319. * the subsequent calls that allocate memory only once (such as the
  320. * key formation below).
  321. *
  322. * Make a new sub-pool and copy any existing trace to it. Point the
  323. * trace cell at the copied value.
  324. }
  325. apr_pool_create(@p, x_pool);
  326. if (trace <> nil) then trace := apr_pstrdup(p, trace);
  327. {
  328. * Now, if we have a sub-pool from before, nuke it and replace with
  329. * the one we just allocated.
  330. }
  331. if (x_subpool <> nil) then apr_pool_destroy(x_subpool);
  332. x_subpool := p;
  333. trace_copy := trace;
  334. end;
  335. {
  336. * If we weren't passed a configuration record, we can't figure out to
  337. * what location this call applies. This only happens for co-routines
  338. * that don't operate in a particular directory or server context. If we
  339. * got a valid record, extract the location (directory or server) to which
  340. * it applies.
  341. }
  342. {
  343. Translation note. The part bellow is commented because there is an unidentified
  344. problem with it.
  345. }
  346. {if (mconfig <> nil) then where := mconfig^.loc
  347. else} where := 'nowhere';
  348. if (where = nil) then where := '';
  349. {
  350. * Now, if we're not in request context, see if we've been called with
  351. * this particular combination before. The apr_table_t is allocated in the
  352. * module's private pool, which doesn't get destroyed.
  353. }
  354. if (r = nil) then
  355. begin
  356. key := apr_pstrcat(p, [note, PChar(':'), where, nil]);
  357. if (apr_table_get(static_calls_made, key) <> nil) then
  358. {
  359. * Been here, done this.
  360. }
  361. Exit
  362. else
  363. {
  364. * First time for this combination of routine and environment -
  365. * log it so we don't do it again.
  366. }
  367. apr_table_set(static_calls_made, key, 'been here');
  368. end;
  369. addon := apr_pstrcat(p, [
  370. PChar(' <li>' + LineEnding +
  371. ' <dl>' + LineEnding +
  372. ' <dt><samp>'), note, PChar('</samp></dt>' + LineEnding +
  373. ' <dd><samp>['), where, PChar(']</samp></dd>' + LineEnding +
  374. ' </dl>' + LineEnding +
  375. ' </li>' + LineEnding),
  376. nil]);
  377. if (trace_copy = nil) then sofar := '' else sofar := trace_copy;
  378. trace_copy := apr_pstrcat(p, [sofar, addon, nil]);
  379. if (r <> nil) then apr_table_set(r^.notes, TRACE_NOTE, trace_copy)
  380. else trace := trace_copy;
  381. {
  382. * You *could* change the following if you wanted to see the calling
  383. * sequence reported in the server's error_log, but beware - almost all of
  384. * these co-routines are called for every single request, and the impact
  385. * on the size (and readability) of the error_log is considerable.
  386. }
  387. if ((EXAMPLE_LOG_EACH = 0) and (s <> nil)) then
  388. ap_log_error(MODULE_NAME, 438, APLOG_DEBUG, 0, s, 'mod_example: ', [note]);
  389. end;
  390. {--------------------------------------------------------------------------}
  391. { We prototyped the various syntax for command handlers (routines that }
  392. { are called when the configuration parser detects a directive declared }
  393. { by our module) earlier. Now we actually declare a "real" routine that }
  394. { will be invoked by the parser when our "real" directive is }
  395. { encountered. }
  396. { }
  397. { If a command handler encounters a problem processing the directive, it }
  398. { signals this fact by returning a non-NULL pointer to a string }
  399. { describing the problem. }
  400. { }
  401. { The magic return value DECLINE_CMD is used to deal with directives }
  402. { that might be declared by multiple modules. If the command handler }
  403. { returns NULL, the directive was processed; if it returns DECLINE_CMD, }
  404. { the next module (if any) that declares the directive is given a chance }
  405. { at it. If it returns any other value, it's treated as the text of an }
  406. { error message. }
  407. {--------------------------------------------------------------------------}
  408. {
  409. * Command handler for the NO_ARGS "Example" directive. All we do is mark the
  410. * call in the trace log, and flag the applicability of the directive to the
  411. * current location in that location's configuration record.
  412. }
  413. function cmd_example(cmd: Pcmd_parms; mconfig: Pointer): PChar; cdecl;
  414. var
  415. cfg: Px_cfg;
  416. begin
  417. cfg := Px_cfg(mconfig);
  418. { "Example Wuz Here" }
  419. cfg^.local := 1;
  420. trace_add(cmd^.server, nil, cfg, 'cmd_example()');
  421. Result := nil;
  422. end;
  423. {--------------------------------------------------------------------------}
  424. { }
  425. { Now we declare our content handlers, which are invoked when the server }
  426. { encounters a document which our module is supposed to have a chance to }
  427. { see. (See mod_mime's SetHandler and AddHandler directives, and the }
  428. { mod_info and mod_status examples, for more details.) }
  429. { }
  430. { Since content handlers are dumping data directly into the connection }
  431. { (using the r*() routines, such as rputs() and rprintf()) without }
  432. { intervention by other parts of the server, they need to make }
  433. { sure any accumulated HTTP headers are sent first. This is done by }
  434. { calling send_http_header(). Otherwise, no header will be sent at all, }
  435. { and the output sent to the client will actually be HTTP-uncompliant. }
  436. {--------------------------------------------------------------------------}
  437. {
  438. * Sample content handler. All this does is display the call list that has
  439. * been built up so far.
  440. *
  441. * The return value instructs the caller concerning what happened and what to
  442. * do next:
  443. * OK ("we did our thing")
  444. * DECLINED ("this isn't something with which we want to get involved")
  445. * HTTP_mumble ("an error status should be reported")
  446. }
  447. function x_handler(r: Prequest_rec): Integer; cdecl;
  448. var
  449. dcfg: Px_cfg;
  450. tempstr: PChar;
  451. begin
  452. tempstr := 'Undefined';
  453. if not SameText(r^.handler, 'example-handler') then
  454. begin
  455. Result := DECLINED;
  456. Exit;
  457. end;
  458. dcfg := our_dconfig(r);
  459. // trace_add(r^.server, r, dcfg, 'x_handler()');
  460. {
  461. * We're about to start sending content, so we need to force the HTTP
  462. * headers to be sent at this point. Otherwise, no headers will be sent
  463. * at all. We can set any we like first, of course. **NOTE** Here's
  464. * where you set the "Content-type" header, and you do so by putting it in
  465. * r^.content_type, *not* r^.headers_out("Content-type"). If you don't
  466. * set it, it will be filled in with the server's default type (typically
  467. * "text/plain"). You *must* also ensure that r^.content_type is lower
  468. * case.
  469. *
  470. * We also need to start a timer so the server can know if the connexion
  471. * is broken.
  472. }
  473. ap_set_content_type(r, 'text/html');
  474. {
  475. * If we're only supposed to send header information (HEAD request), we're
  476. * already there.
  477. }
  478. if (r^.header_only <> 0) then
  479. begin
  480. Result := OK;
  481. Exit;
  482. end;
  483. {
  484. * Now send our actual output. Since we tagged this as being
  485. * "text/html", we need to embed any HTML.
  486. }
  487. ap_rputs(DOCTYPE_HTML_3_2, r);
  488. ap_rputs('<HTML>' + LineEnding, r);
  489. ap_rputs(' <HEAD>' + LineEnding, r);
  490. ap_rputs(' <TITLE>mod_example Module Content-Handler Output' + LineEnding, r);
  491. ap_rputs(' </TITLE>' + LineEnding, r);
  492. ap_rputs(' </HEAD>' + LineEnding, r);
  493. ap_rputs(' <BODY>' + LineEnding, r);
  494. ap_rputs(' <H1><SAMP>mod_example</SAMP> Module Content-Handler Output' + LineEnding, r);
  495. ap_rputs(' </H1>' + LineEnding, r);
  496. ap_rputs(' <P>' + LineEnding, r);
  497. ap_rprintf(r, ' Apache HTTP Server version: "%s"' + LineEnding, [ap_get_server_version()]);
  498. ap_rputs(' <BR>' + LineEnding, r);
  499. ap_rprintf(r, ' Server built: "%s"' + LineEnding, [ap_get_server_built()]);
  500. ap_rputs(' </P>' + LineEnding, r);;
  501. ap_rputs(' <P>' + LineEnding, r);
  502. ap_rputs(' The format for the callback trace is:' + LineEnding, r);
  503. ap_rputs(' </P>' + LineEnding, r);
  504. ap_rputs(' <DL>' + LineEnding, r);
  505. ap_rputs(' <DT><EM>n</EM>.<SAMP>&lt;routine-name&gt;', r);
  506. ap_rputs('(&lt;routine-data&gt;)</SAMP>' + LineEnding, r);
  507. ap_rputs(' </DT>' + LineEnding, r);
  508. ap_rputs(' <DD><SAMP>[&lt;applies-to&gt;]</SAMP>' + LineEnding, r);
  509. ap_rputs(' </DD>' + LineEnding, r);
  510. ap_rputs(' </DL>' + LineEnding, r);
  511. ap_rputs(' <P>' + LineEnding, r);
  512. ap_rputs(' The <SAMP>&lt;routine-data&gt;</SAMP> is supplied by' + LineEnding, r);
  513. ap_rputs(' the routine when it requests the trace,' + LineEnding, r);
  514. ap_rputs(' and the <SAMP>&lt;applies-to&gt;</SAMP> is extracted' + LineEnding, r);
  515. ap_rputs(' from the configuration record at the time of the trace.' + LineEnding, r);
  516. ap_rputs(' <STRONG>SVR()</STRONG> indicates a server environment' + LineEnding, r);
  517. ap_rputs(' (blank means the main or default server, otherwise it''s' + LineEnding, r);
  518. ap_rputs(' the name of the VirtualHost); <STRONG>DIR()</STRONG>' + LineEnding, r);
  519. ap_rputs(' indicates a location in the URL or filesystem' + LineEnding, r);
  520. ap_rputs(' namespace.' + LineEnding, r);
  521. ap_rputs(' </P>' + LineEnding, r);
  522. ap_rprintf(r, ' <H2>Static callbacks so far:</H2>' + LineEnding +
  523. ' <OL>' + LineEnding + '%s </OL>' + LineEnding, [trace]);
  524. ap_rputs(' <H2>Request-specific callbacks so far:</H2>' + LineEnding, r);
  525. ap_rprintf(r, ' <OL>' + LineEnding + '%s </OL>' + LineEnding, [apr_table_get(r^.notes, TRACE_NOTE)]);
  526. ap_rputs(' <H2>Environment for <EM>this</EM> call:</H2>' + LineEnding, r);
  527. ap_rputs(' <UL>' + LineEnding, r);
  528. // ap_rprintf(r, ' <LI>Applies-to: <SAMP>%s</SAMP>' + LineEnding + ' </LI>' + LineEnding, [dcfg^.loc]);
  529. // if dcfg^.local = 0 then tempstr := 'NO' else tempstr := 'Yes';
  530. ap_rprintf(r, ' <LI>"Example" directive declared here: %s' + LineEnding + ' </LI>' + LineEnding,
  531. [tempstr]);
  532. // if dcfg^.congenital = 0 then tempstr := 'NO' else tempstr := 'Yes';
  533. ap_rprintf(r, ' <LI>"Example" inherited: %s' + LineEnding + ' </LI>' + LineEnding, [tempstr]);
  534. ap_rputs(' </UL>' + LineEnding, r);
  535. ap_rputs(' </BODY>' + LineEnding, r);
  536. ap_rputs('</HTML>' + LineEnding, r);
  537. {
  538. * We're all done, so cancel the timeout we set. Since this is probably
  539. * the end of the request we *could* assume this would be done during
  540. * post-processing - but it's possible that another handler might be
  541. * called and inherit our outstanding timer. Not good; to each its own.
  542. }
  543. {
  544. * We did what we wanted to do, so tell the rest of the server we
  545. * succeeded.
  546. }
  547. Result := OK;
  548. end;
  549. {--------------------------------------------------------------------------}
  550. { }
  551. { Now let's declare routines for each of the callback phase in order. }
  552. { (That's the order in which they're listed in the callback list, *not }
  553. { the order in which the server calls them! See the command_rec }
  554. { declaration near the bottom of this file.) Note that these may be }
  555. { called for situations that don't relate primarily to our function - in }
  556. { other words, the fixup handler shouldn't assume that the request has }
  557. { to do with "example" stuff. }
  558. { }
  559. { With the exception of the content handler, all of our routines will be }
  560. { called for each request, unless an earlier handler from another module }
  561. { aborted the sequence. }
  562. { }
  563. { Handlers that are declared as "int" can return the following: }
  564. { }
  565. { OK Handler accepted the request and did its thing with it. }
  566. { DECLINED Handler took no action. }
  567. { HTTP_mumble Handler looked at request and found it wanting. }
  568. { }
  569. { What the server does after calling a module handler depends upon the }
  570. { handler's return value. In all cases, if the handler returns }
  571. { DECLINED, the server will continue to the next module with an handler }
  572. { for the current phase. However, if the handler return a non-OK, }
  573. { non-DECLINED status, the server aborts the request right there. If }
  574. { the handler returns OK, the server's next action is phase-specific; }
  575. { see the individual handler comments below for details. }
  576. { }
  577. {--------------------------------------------------------------------------}
  578. {
  579. * This function is called during server initialisation. Any information
  580. * that needs to be recorded must be in static cells, since there's no
  581. * configuration record.
  582. *
  583. * There is no return value.
  584. }
  585. {
  586. * This function is called when an heavy-weight process (such as a child) is
  587. * being run down or destroyed. As with the child initialisation function,
  588. * any information that needs to be recorded must be in static cells, since
  589. * there's no configuration record.
  590. *
  591. * There is no return value.
  592. }
  593. {
  594. * This function is called during server initialisation when an heavy-weight
  595. * process (such as a child) is being initialised. As with the
  596. * module initialisation function, any information that needs to be recorded
  597. * must be in static cells, since there's no configuration record.
  598. *
  599. * There is no return value.
  600. }
  601. {
  602. * This function gets called to create a per-directory configuration
  603. * record. This will be called for the "default" server environment, and for
  604. * each directory for which the parser finds any of our directives applicable.
  605. * If a directory doesn't have any of our directives involved (i.e., they
  606. * aren't in the .htaccess file, or a <Location>, <Directory>, or related
  607. * block), this routine will *not* be called - the configuration for the
  608. * closest ancestor is used.
  609. *
  610. * The return value is a pointer to the created module-specific
  611. * structure.
  612. }
  613. function x_create_dir_config(p: Papr_pool_t; dirspec: PChar): Pointer; cdecl;
  614. var
  615. cfg: Px_cfg;
  616. dname: PChar;
  617. begin
  618. dname := dirspec;
  619. {
  620. * Allocate the space for our record from the pool supplied.
  621. }
  622. cfg := Px_cfg(apr_pcalloc(p, sizeof(x_cfg)));
  623. {
  624. * Now fill in the defaults. If there are any `parent' configuration
  625. * records, they'll get merged as part of a separate callback.
  626. }
  627. cfg^.local := 0;
  628. cfg^.congenital := 0;
  629. cfg^.cmode := CONFIG_MODE_DIRECTORY;
  630. {
  631. * Finally, add our trace to the callback list.
  632. }
  633. if dname = nil then dname := '';
  634. cfg^.loc := apr_pstrcat(p, [PChar('DIR('), dname, PChar(')'), nil]);
  635. trace_add(nil, nil, cfg, 'x_create_dir_config()');
  636. Result := Pointer(cfg);
  637. end;
  638. {
  639. * This function gets called to merge two per-directory configuration
  640. * records. This is typically done to cope with things like .htaccess files
  641. * or <Location> directives for directories that are beneath one for which a
  642. * configuration record was already created. The routine has the
  643. * responsibility of creating a new record and merging the contents of the
  644. * other two into it appropriately. If the module doesn't declare a merge
  645. * routine, the record for the closest ancestor location (that has one) is
  646. * used exclusively.
  647. *
  648. * The routine MUST NOT modify any of its arguments!
  649. *
  650. * The return value is a pointer to the created module-specific structure
  651. * containing the merged values.
  652. }
  653. function x_merge_dir_config(p: Papr_pool_t;
  654. parent_conf, newloc_conf: Pointer): Pointer; cdecl;
  655. var
  656. merged_config, pconf, nconf: Px_cfg;
  657. note: PChar;
  658. begin
  659. merged_config := Px_cfg(apr_pcalloc(p, sizeof(x_cfg)));
  660. pconf := Px_cfg(parent_conf);
  661. nconf := Px_cfg(newloc_conf);
  662. {
  663. * Some things get copied directly from the more-specific record, rather
  664. * than getting merged.
  665. }
  666. merged_config^.local := nconf^.local;
  667. merged_config^.loc := apr_pstrdup(p, nconf^.loc);
  668. {
  669. * Others, like the setting of the `congenital' flag, get ORed in. The
  670. * setting of that particular flag, for instance, is TRUE if it was ever
  671. * true anywhere in the upstream configuration.
  672. }
  673. merged_config^.congenital := (pconf^.congenital or pconf^.local);
  674. {
  675. * If we're merging records for two different types of environment (server
  676. * and directory), mark the new record appropriately. Otherwise, inherit
  677. * the current value.
  678. }
  679. if pconf^.cmode = nconf^.cmode then
  680. merged_config^.cmode := pconf^.cmode
  681. else merged_config^.cmode := CONFIG_MODE_COMBO;
  682. {
  683. * Now just record our being called in the trace list. Include the
  684. * locations we were asked to merge.
  685. }
  686. note := apr_pstrcat(p, [PChar('x_merge_dir_config("'), pconf^.loc, PChar('","'),
  687. nconf^.loc, PChar('")'), nil]);
  688. trace_add(nil, nil, merged_config, note);
  689. Result := Pointer(merged_config);
  690. end;
  691. {
  692. * This function gets called to create a per-server configuration
  693. * record. It will always be called for the "default" server.
  694. *
  695. * The return value is a pointer to the created module-specific
  696. * structure.
  697. }
  698. function x_create_server_config(p: Papr_pool_t; s: Pserver_rec): Pointer; cdecl;
  699. var
  700. cfg: Px_cfg;
  701. sname: PChar;
  702. begin
  703. sname := s^.server_hostname;
  704. {
  705. * As with the x_create_dir_config() reoutine, we allocate and fill
  706. * in an empty record.
  707. }
  708. cfg := Px_cfg(apr_pcalloc(p, sizeof(x_cfg)));
  709. cfg^.local := 0;
  710. cfg^.congenital := 0;
  711. cfg^.cmode := CONFIG_MODE_SERVER;
  712. {
  713. * Note that we were called in the trace list.
  714. }
  715. if sname = nil then sname := '';
  716. cfg^.loc := apr_pstrcat(p, [PChar('SVR('), sname, PChar(')'), nil]);
  717. trace_add(s, nil, cfg, 'x_create_server_config()');
  718. Result := Pointer(cfg);
  719. end;
  720. {
  721. * This function gets called to merge two per-server configuration
  722. * records. This is typically done to cope with things like virtual hosts and
  723. * the default server configuration The routine has the responsibility of
  724. * creating a new record and merging the contents of the other two into it
  725. * appropriately. If the module doesn't declare a merge routine, the more
  726. * specific existing record is used exclusively.
  727. *
  728. * The routine MUST NOT modify any of its arguments!
  729. *
  730. * The return value is a pointer to the created module-specific structure
  731. * containing the merged values.
  732. }
  733. function x_merge_server_config(p: Papr_pool_t;
  734. server1_conf, server2_conf: Pointer): Pointer; cdecl;
  735. var
  736. merged_config, s1conf, s2conf: Px_cfg;
  737. note: PChar;
  738. begin
  739. merged_config := Px_cfg(apr_pcalloc(p, sizeof(x_cfg)));
  740. s1conf := Px_cfg(server1_conf);
  741. s2conf := Px_cfg(server2_conf);
  742. {
  743. * Our inheritance rules are our own, and part of our module's semantics.
  744. * Basically, just note whence we came.
  745. }
  746. if s1conf^.cmode = s2conf^.cmode then
  747. merged_config^.cmode := s1conf^.cmode
  748. else merged_config^.cmode := CONFIG_MODE_COMBO;
  749. merged_config^.local := s2conf^.local;
  750. merged_config^.congenital := (s1conf^.congenital or s1conf^.local);
  751. merged_config^.loc := apr_pstrdup(p, s2conf^.loc);
  752. {
  753. * Trace our call, including what we were asked to merge.
  754. }
  755. note := apr_pstrcat(p, [PChar('x_merge_server_config("'), s1conf^.loc, PChar('","'),
  756. s2conf^.loc, PChar('")'), nil]);
  757. trace_add(nil, nil, merged_config, note);
  758. Result := Pointer(merged_config);
  759. end;
  760. {
  761. * This routine is called before the server processes the configuration
  762. * files. There is no return value.
  763. }
  764. function x_pre_config(pconf, plog, ptemp: Papr_pool_t): Integer; cdecl;
  765. begin
  766. {
  767. * Log the call and exit.
  768. }
  769. trace_add(nil, nil, nil, 'x_pre_config()');
  770. Result := OK;
  771. end;
  772. {
  773. * This routine is called to perform any module-specific fixing of header
  774. * fields, et cetera. It is invoked just before any content-handler.
  775. *
  776. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  777. * server will still call any remaining modules with an handler for this
  778. * phase.
  779. }
  780. function x_post_config(pconf, plog, ptemp: Papr_pool_t; s: Pserver_rec): Integer; cdecl;
  781. begin
  782. {
  783. * Log the call and exit.
  784. }
  785. trace_add(nil, nil, nil, 'x_post_config()');
  786. Result := OK;
  787. end;
  788. {
  789. * This routine is called to perform any module-specific log file
  790. * openings. It is invoked just before the post_config phase
  791. *
  792. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  793. * server will still call any remaining modules with an handler for this
  794. * phase.
  795. }
  796. function x_open_logs(pconf, plog, ptemp: Papr_pool_t; s: Pserver_rec): Integer; cdecl;
  797. begin
  798. {
  799. * Log the call and exit.
  800. }
  801. trace_add(s, nil, nil, 'x_open_logs()');
  802. Result := OK;
  803. end;
  804. {
  805. * All our process-death routine does is add its trace to the log.
  806. }
  807. function x_child_exit(data: Pointer): apr_status_t; cdecl;
  808. var
  809. note, sname: PChar;
  810. s: Pserver_rec;
  811. begin
  812. s := data;
  813. sname := s^.server_hostname;
  814. {
  815. * The arbitrary text we add to our trace entry indicates for which server
  816. * we're being called.
  817. }
  818. if sname = nil then sname := '';
  819. note := apr_pstrcat(s^.process^.pool, [PChar('x_child_exit('), sname, PChar(')'), nil]);
  820. trace_add(s, nil, nil, note);
  821. Result := APR_SUCCESS;
  822. end;
  823. {
  824. * All our process initialiser does is add its trace to the log.
  825. }
  826. procedure x_child_init(p: Papr_pool_t; s: Pserver_rec); cdecl;
  827. var
  828. note, sname: PChar;
  829. begin
  830. sname := s^.server_hostname;
  831. {
  832. * Set up any module cells that ought to be initialised.
  833. }
  834. setup_module_cells();
  835. {
  836. * The arbitrary text we add to our trace entry indicates for which server
  837. * we're being called.
  838. }
  839. if sname = nil then sname := '';
  840. note := apr_pstrcat(p, [PChar('x_child_init('), sname, PChar(')'), nil]);
  841. trace_add(s, nil, nil, note);
  842. apr_pool_cleanup_register(p, s, @x_child_exit, @x_child_exit);
  843. end;
  844. {
  845. * XXX: This routine is called XXX
  846. *
  847. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  848. * server will still call any remaining modules with an handler for this
  849. * phase.
  850. }
  851. //#if 0
  852. function x_http_method(const r: Prequest_rec): PChar; cdecl;
  853. var
  854. cfg: Px_cfg;
  855. begin
  856. cfg := our_dconfig(r);
  857. // Log the call and exit.
  858. trace_add(r^.server, nil, cfg, 'x_http_method()');
  859. Result := 'foo';
  860. end;
  861. {
  862. * XXX: This routine is called XXX
  863. *
  864. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  865. * server will still call any remaining modules with an handler for this
  866. * phase.
  867. }
  868. function x_default_port(const r: Prequest_rec): apr_port_t; cdecl;
  869. var
  870. cfg: Px_cfg;
  871. begin
  872. cfg := our_dconfig(r);
  873. {
  874. * Log the call and exit.
  875. }
  876. trace_add(r^.server, nil, cfg, 'x_default_port()');
  877. Result := 80;
  878. end;
  879. //#endif {0}
  880. {
  881. * XXX: This routine is called XXX
  882. *
  883. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  884. * server will still call any remaining modules with an handler for this
  885. * phase.
  886. }
  887. procedure x_insert_filter(r: Prequest_rec); cdecl;
  888. var
  889. cfg: Px_cfg;
  890. begin
  891. cfg := our_dconfig(r);
  892. {
  893. * Log the call and exit.
  894. }
  895. trace_add(r^.server, nil, cfg, 'x_insert_filter()');
  896. end;
  897. {
  898. * XXX: This routine is called XXX
  899. *
  900. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  901. * server will still call any remaining modules with an handler for this
  902. * phase.
  903. }
  904. function x_quick_handler(r: Prequest_rec; lookup_uri: Integer): Integer; cdecl;
  905. var
  906. cfg: Px_cfg;
  907. begin
  908. cfg := our_dconfig(r);
  909. { Log the call and exit. }
  910. trace_add(r^.server, nil, cfg, 'x_post_config()');
  911. Result := DECLINED;
  912. end;
  913. {
  914. * This routine is called just after the server accepts the connection,
  915. * but before it is handed off to a protocol module to be served. The point
  916. * of this hook is to allow modules an opportunity to modify the connection
  917. * as soon as possible. The core server uses this phase to setup the
  918. * connection record based on the type of connection that is being used.
  919. *
  920. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  921. * server will still call any remaining modules with an handler for this
  922. * phase.
  923. }
  924. function x_pre_connection(c: Pconn_rec; csd: Pointer): Integer; cdecl;
  925. var
  926. cfg: Px_cfg;
  927. begin
  928. cfg := our_cconfig(c);
  929. {$ifdef 0}
  930. {
  931. * Log the call and exit.
  932. }
  933. trace_add(r^.server, nil, cfg, 'x_post_config()');
  934. {$endif}
  935. Result := OK;
  936. end;
  937. { This routine is used to actually process the connection that was received.
  938. * Only protocol modules should implement this hook, as it gives them an
  939. * opportunity to replace the standard HTTP processing with processing for
  940. * some other protocol. Both echo and POP3 modules are available as
  941. * examples.
  942. *
  943. * The return VALUE is OK, DECLINED, or HTTP_mumble. If we return OK, no
  944. * further modules are called for this phase.
  945. }
  946. function x_process_connection(c: Pconn_rec): Integer; cdecl;
  947. begin
  948. Result := DECLINED;
  949. end;
  950. {
  951. * This routine is called after the request has been read but before any other
  952. * phases have been processed. This allows us to make decisions based upon
  953. * the input header fields.
  954. *
  955. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
  956. * further modules are called for this phase.
  957. }
  958. function x_post_read_request(r: Prequest_rec): Integer; cdecl;
  959. var
  960. cfg: Px_cfg;
  961. begin
  962. cfg := our_dconfig(r);
  963. {
  964. * We don't actually *do* anything here, except note the fact that we were
  965. * called.
  966. }
  967. trace_add(r^.server, r, cfg, 'x_post_read_request()');
  968. Result := DECLINED;
  969. end;
  970. {
  971. * This routine gives our module an opportunity to translate the URI into an
  972. * actual filename. If we don't do anything special, the server's default
  973. * rules (Alias directives and the like) will continue to be followed.
  974. *
  975. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
  976. * further modules are called for this phase.
  977. }
  978. function x_translate_handler(r: Prequest_rec): Integer; cdecl;
  979. var
  980. cfg: Px_cfg;
  981. begin
  982. cfg := our_dconfig(r);
  983. {
  984. * We don't actually *do* anything here, except note the fact that we were
  985. * called.
  986. }
  987. trace_add(r^.server, r, cfg, 'x_translate_handler()');
  988. Result := DECLINED;
  989. end;
  990. {
  991. * this routine gives our module another chance to examine the request
  992. * headers and to take special action. This is the first phase whose
  993. * hooks' configuration directives can appear inside the <Directory>
  994. * and similar sections, because at this stage the URI has been mapped
  995. * to the filename. For example this phase can be used to block evil
  996. * clients, while little resources were wasted on these.
  997. *
  998. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK,
  999. * the server will still call any remaining modules with an handler
  1000. * for this phase.
  1001. }
  1002. function x_header_parser_handler(r: Prequest_rec): Integer; cdecl;
  1003. var
  1004. cfg: Px_cfg;
  1005. begin
  1006. cfg := our_dconfig(r);
  1007. {
  1008. * We don't actually *do* anything here, except note the fact that we were
  1009. * called.
  1010. }
  1011. trace_add(r^.server, r, cfg, 'header_parser_handler()');
  1012. Result := DECLINED;
  1013. end;
  1014. {
  1015. * This routine is called to check the authentication information sent with
  1016. * the request (such as looking up the user in a database and verifying that
  1017. * the [encrypted] password sent matches the one in the database).
  1018. *
  1019. * The return value is OK, DECLINED, or some HTTP_mumble error (typically
  1020. * HTTP_UNAUTHORIZED). If we return OK, no other modules are given a chance
  1021. * at the request during this phase.
  1022. }
  1023. function x_check_user_id(r: Prequest_rec): Integer; cdecl;
  1024. var
  1025. cfg: Px_cfg;
  1026. begin
  1027. cfg := our_dconfig(r);
  1028. { Don't do anything except log the call. }
  1029. trace_add(r^.server, r, cfg, 'x_check_user_id()');
  1030. Result := DECLINED;
  1031. end;
  1032. {
  1033. * This routine is called to check to see if the resource being requested
  1034. * requires authorisation.
  1035. *
  1036. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
  1037. * other modules are called during this phase.
  1038. *
  1039. * If *all* modules return DECLINED, the request is aborted with a server
  1040. * error.
  1041. }
  1042. function x_auth_checker(r: Prequest_rec): Integer; cdecl;
  1043. var
  1044. cfg: Px_cfg;
  1045. begin
  1046. cfg := our_dconfig(r);
  1047. { * Log the call and return OK, or access will be denied (even though we
  1048. * didn't actually do anything). }
  1049. trace_add(r^.server, r, cfg, 'x_auth_checker()');
  1050. Result := DECLINED;
  1051. end;
  1052. {
  1053. * This routine is called to check for any module-specific restrictions placed
  1054. * upon the requested resource. (See the mod_access module for an example.)
  1055. *
  1056. * The return value is OK, DECLINED, or HTTP_mumble. All modules with an
  1057. * handler for this phase are called regardless of whether their predecessors
  1058. * return OK or DECLINED. The first one to return any other status, however,
  1059. * will abort the sequence (and the request) as usual.
  1060. }
  1061. function x_access_checker(r: Prequest_rec): Integer; cdecl;
  1062. var
  1063. cfg: Px_cfg;
  1064. begin
  1065. cfg := our_dconfig(r);
  1066. trace_add(r^.server, r, cfg, 'x_access_checker()');
  1067. Result := DECLINED;
  1068. end;
  1069. {
  1070. * This routine is called to determine and/or set the various document type
  1071. * information bits, like Content-type (via r^.content_type), language, et
  1072. * cetera.
  1073. *
  1074. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
  1075. * further modules are given a chance at the request for this phase.
  1076. }
  1077. function x_type_checker(r: Prequest_rec): Integer; cdecl;
  1078. var
  1079. cfg: Px_cfg;
  1080. begin
  1081. cfg := our_dconfig(r);
  1082. { * Log the call, but don't do anything else - and report truthfully that
  1083. * we didn't do anything. }
  1084. trace_add(r^.server, r, cfg, 'x_type_checker()');
  1085. Result := DECLINED;
  1086. end;
  1087. {
  1088. * This routine is called to perform any module-specific fixing of header
  1089. * fields, et cetera. It is invoked just before any content-handler.
  1090. *
  1091. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
  1092. * server will still call any remaining modules with an handler for this
  1093. * phase.
  1094. }
  1095. function x_fixer_upper(r: Prequest_rec): Integer; cdecl;
  1096. var
  1097. cfg: Px_cfg;
  1098. begin
  1099. cfg := our_dconfig(r);
  1100. { Log the call and exit. }
  1101. trace_add(r^.server, r, cfg, 'x_fixer_upper()');
  1102. Result := OK;
  1103. end;
  1104. {
  1105. * This routine is called to perform any module-specific logging activities
  1106. * over and above the normal server things.
  1107. *
  1108. * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any
  1109. * remaining modules with an handler for this phase will still be called.
  1110. }
  1111. function x_logger(r: Prequest_rec): Integer; cdecl;
  1112. var
  1113. cfg: Px_cfg;
  1114. begin
  1115. cfg := our_dconfig(r);
  1116. trace_add(r^.server, r, cfg, 'x_logger()');
  1117. Result := DECLINED;
  1118. end;
  1119. {--------------------------------------------------------------------------}
  1120. { }
  1121. { Which functions are responsible for which hooks in the server. }
  1122. { }
  1123. {--------------------------------------------------------------------------}
  1124. {
  1125. * Each function our module provides to handle a particular hook is
  1126. * specified here. The functions are registered using
  1127. * ap_hook_foo(name, predecessors, successors, position)
  1128. * where foo is the name of the hook.
  1129. *
  1130. * The args are as follows:
  1131. * name ^. the name of the function to call.
  1132. * predecessors ^. a list of modules whose calls to this hook must be
  1133. * invoked before this module.
  1134. * successors ^. a list of modules whose calls to this hook must be
  1135. * invoked after this module.
  1136. * position ^. The relative position of this module. One of
  1137. * APR_HOOK_FIRST, APR_HOOK_MIDDLE, or APR_HOOK_LAST.
  1138. * Most modules will use APR_HOOK_MIDDLE. If multiple
  1139. * modules use the same relative position, Apache will
  1140. * determine which to call first.
  1141. * If your module relies on another module to run first,
  1142. * or another module running after yours, use the
  1143. * predecessors and/or successors.
  1144. *
  1145. * The number in brackets indicates the order in which the routine is called
  1146. * during request processing. Note that not all routines are necessarily
  1147. * called (such as if a resource doesn't have access restrictions).
  1148. * The actual delivery of content to the browser [9] is not handled by
  1149. * a hook; see the handler declarations below.
  1150. }
  1151. procedure x_register_hooks(p: Papr_pool_t); cdecl;
  1152. begin
  1153. ap_hook_pre_config(@x_pre_config, nil, nil, APR_HOOK_MIDDLE);
  1154. ap_hook_post_config(@x_post_config, nil, nil, APR_HOOK_MIDDLE);
  1155. ap_hook_open_logs(@x_open_logs, nil, nil, APR_HOOK_MIDDLE);
  1156. ap_hook_child_init(@x_child_init, nil, nil, APR_HOOK_MIDDLE);
  1157. ap_hook_handler(@x_handler, nil, nil, APR_HOOK_MIDDLE);
  1158. ap_hook_quick_handler(@x_quick_handler, nil, nil, APR_HOOK_MIDDLE);
  1159. ap_hook_pre_connection(@x_pre_connection, nil, nil, APR_HOOK_MIDDLE);
  1160. ap_hook_process_connection(@x_process_connection, nil, nil, APR_HOOK_MIDDLE);
  1161. { [1] post read_request handling }
  1162. ap_hook_post_read_request(@x_post_read_request, nil, nil, APR_HOOK_MIDDLE);
  1163. ap_hook_log_transaction(@x_logger, nil, nil, APR_HOOK_MIDDLE);
  1164. {$ifdef 0}
  1165. ap_hook_http_method(x_http_method, nil, nil, APR_HOOK_MIDDLE);
  1166. ap_hook_default_port(x_default_port, nil, nil, APR_HOOK_MIDDLE);
  1167. {$endif}
  1168. ap_hook_translate_name(@x_translate_handler, nil, nil, APR_HOOK_MIDDLE);
  1169. ap_hook_header_parser(@x_header_parser_handler, nil, nil, APR_HOOK_MIDDLE);
  1170. ap_hook_check_user_id(@x_check_user_id, nil, nil, APR_HOOK_MIDDLE);
  1171. ap_hook_fixups(@x_fixer_upper, nil, nil, APR_HOOK_MIDDLE);
  1172. ap_hook_type_checker(@x_type_checker, nil, nil, APR_HOOK_MIDDLE);
  1173. ap_hook_access_checker(@x_access_checker, nil, nil, APR_HOOK_MIDDLE);
  1174. ap_hook_auth_checker(@x_auth_checker, nil, nil, APR_HOOK_MIDDLE);
  1175. ap_hook_insert_filter(@x_insert_filter, nil, nil, APR_HOOK_MIDDLE);
  1176. end;
  1177. {--------------------------------------------------------------------------}
  1178. { }
  1179. { All of the routines have been declared now. Here's the list of }
  1180. { directives specific to our module, and information about where they }
  1181. { may appear and how the command parser should pass them to us for }
  1182. { processing. Note that care must be taken to ensure that there are NO }
  1183. { collisions of directive names between modules. }
  1184. { }
  1185. {--------------------------------------------------------------------------}
  1186. var
  1187. x_cmds: command_rec;
  1188. {--------------------------------------------------------------------------}
  1189. { }
  1190. { Finally, the list of callback routines and data structures that provide }
  1191. { the static hooks into our module from the other parts of the server. }
  1192. { }
  1193. {--------------------------------------------------------------------------}
  1194. {
  1195. * Module definition for configuration. If a particular callback is not
  1196. * needed, replace its routine name below with the word NULL.
  1197. }
  1198. begin
  1199. default_module_ptr := @example_module;
  1200. FillChar(default_module_ptr^, SizeOf(default_module_ptr^), 0);
  1201. STANDARD20_MODULE_STUFF(default_module_ptr^);
  1202. { List of directives specific to our module. }
  1203. with x_cmds do
  1204. begin
  1205. name := 'Example';
  1206. func.func_no_args := @cmd_example;
  1207. cmd_data := nil;
  1208. req_override := OR_OPTIONS;
  1209. args_how := NO_ARGS; // Or RAW_ARGS ?
  1210. errmsg := 'Example directive - no arguments';
  1211. end;
  1212. with example_module do
  1213. begin
  1214. name := MODULE_NAME;
  1215. magic := MODULE_MAGIC_COOKIE;
  1216. create_dir_config := @x_create_dir_config; { per-directory config creator }
  1217. merge_dir_config := @x_merge_dir_config; { dir config merger }
  1218. create_server_config := @x_create_server_config;{ server config creator }
  1219. merge_server_config := @x_merge_server_config; { server config merger }
  1220. cmds := @x_cmds; { command table }
  1221. register_hooks := @x_register_hooks; { set up other request processing hooks }
  1222. end;
  1223. end.