]> granicus.if.org Git - apache/blob - docs/manual/developer/modules.html.en
xforms
[apache] / docs / manual / developer / modules.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>Converting Modules from Apache 1.3 to Apache 2.0 - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
12 <script src="../style/scripts/prettify.js" type="text/javascript">
13 </script>
14
15 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
16 <body id="manual-page"><div id="page-header">
17 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
18 <p class="apache">Apache HTTP Server Version 2.5</p>
19 <img alt="" src="../images/feather.gif" /></div>
20 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
21 <div id="path">
22 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Developer Documentation</a></div><div id="page-content"><div id="preamble"><h1>Converting Modules from Apache 1.3 to Apache 2.0</h1>
23 <div class="toplang">
24 <p><span>Available Languages: </span><a href="../en/developer/modules.html" title="English">&nbsp;en&nbsp;</a> |
25 <a href="../ja/developer/modules.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
26 </div>
27
28     <p>This is a first attempt at writing the lessons I learned
29     when trying to convert the <code>mod_mmap_static</code> module to Apache
30     2.0. It's by no means definitive and probably won't even be
31     correct in some ways, but it's a start.</p>
32 </div>
33 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#easy">The easier changes ...</a></li>
34 <li><img alt="" src="../images/down.gif" /> <a href="#messy">The messier changes...</a></li>
35 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
36 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
37 <div class="section">
38 <h2><a name="easy" id="easy">The easier changes ...</a></h2>
39
40     <h3><a name="cleanup" id="cleanup">Cleanup Routines</a></h3>
41       <p>These now need to be of type <code>apr_status_t</code> and return a
42       value of that type. Normally the return value will be
43       <code>APR_SUCCESS</code> unless there is some need to signal an error in
44       the cleanup. Be aware that even though you signal an error not all code
45       yet checks and acts upon the error.</p>
46     
47
48     <h3><a name="init" id="init">Initialisation Routines</a></h3>
49       <p>These should now be renamed to better signify where they sit
50       in the overall process. So the name gets a small change from
51       <code>mmap_init</code> to <code>mmap_post_config</code>. The arguments
52       passed have undergone a radical change and now look like</p>
53
54       <ul>
55         <li><code>apr_pool_t *p</code></li>
56         <li><code>apr_pool_t *plog</code></li>
57         <li><code>apr_pool_t *ptemp</code></li>
58         <li><code>server_rec *s</code></li>
59       </ul>
60     
61
62     <h3><a name="datatypes" id="datatypes">Data Types</a></h3>
63       <p>A lot of the data types have been moved into the <a href="http://apr.apache.org/">APR</a>. This means that some have had
64       a name change, such as the one shown above. The following is a brief
65       list of some of the changes that you are likely to have to make.</p>
66
67       <ul>
68         <li><code>pool</code> becomes <code>apr_pool_t</code></li>
69         <li><code>table</code> becomes <code>apr_table_t</code></li>
70       </ul>
71     
72 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
73 <div class="section">
74 <h2><a name="messy" id="messy">The messier changes...</a></h2>
75
76     <h3><a name="register-hooks" id="register-hooks">Register Hooks</a></h3>
77       <p>The new architecture uses a series of hooks to provide for
78       calling your functions. These you'll need to add to your module
79       by way of a new function, <code>static void register_hooks(void)</code>.
80       The function is really reasonably straightforward once you
81       understand what needs to be done. Each function that needs
82       calling at some stage in the processing of a request needs to
83       be registered, handlers do not. There are a number of phases
84       where functions can be added, and for each you can specify with
85       a high degree of control the relative order that the function
86       will be called in.</p>
87
88       <p>This is the code that was added to <code>mod_mmap_static</code>:</p>
89       <div class="example"><pre>
90 static void register_hooks(void)
91 {
92     static const char * const aszPre[]={ "http_core.c",NULL };
93     ap_hook_post_config(mmap_post_config,NULL,NULL,HOOK_MIDDLE);
94     ap_hook_translate_name(mmap_static_xlat,aszPre,NULL,HOOK_LAST);
95 };</pre></div>
96
97       <p>This registers 2 functions that need to be called, one in
98       the <code>post_config</code> stage (virtually every module will need this
99       one) and one for the <code>translate_name</code> phase. note that while
100       there are different function names the format of each is
101       identical. So what is the format?</p>
102
103       <div class="example"><p><code>
104         ap_hook_<var>phase_name</var>(<var>function_name</var>,
105         <var>predecessors</var>, <var>successors</var>, <var>position</var>);
106       </code></p></div>
107
108       <p>There are 3 hook positions defined...</p>
109
110       <ul>
111         <li><code>HOOK_FIRST</code></li>
112         <li><code>HOOK_MIDDLE</code></li>
113         <li><code>HOOK_LAST</code></li>
114       </ul>
115
116       <p>To define the position you use the position and then modify
117       it with the predecessors and successors. Each of the modifiers
118       can be a list of functions that should be called, either before
119       the function is run (predecessors) or after the function has
120       run (successors).</p>
121
122       <p>In the <code>mod_mmap_static</code> case I didn't care about the
123       <code>post_config</code> stage, but the <code>mmap_static_xlat</code>
124       <strong>must</strong> be called after the core module had done it's name
125       translation, hence the use of the aszPre to define a modifier to the
126       position <code>HOOK_LAST</code>.</p>
127     
128
129     <h3><a name="moddef" id="moddef">Module Definition</a></h3>
130       <p>There are now a lot fewer stages to worry about when
131       creating your module definition. The old definition looked
132       like</p>
133
134       <div class="example"><pre>
135 module MODULE_VAR_EXPORT <var>module_name</var>_module =
136 {
137     STANDARD_MODULE_STUFF,
138     /* initializer */
139     /* dir config creater */
140     /* dir merger --- default is to override */
141     /* server config */
142     /* merge server config */
143     /* command handlers */
144     /* handlers */
145     /* filename translation */
146     /* check_user_id */
147     /* check auth */
148     /* check access */
149     /* type_checker */
150     /* fixups */
151     /* logger */
152     /* header parser */
153     /* child_init */
154     /* child_exit */
155     /* post read-request */
156 };</pre></div>
157
158       <p>The new structure is a great deal simpler...</p>
159       <div class="example"><pre>
160 module MODULE_VAR_EXPORT <var>module_name</var>_module =
161 {
162     STANDARD20_MODULE_STUFF,
163     /* create per-directory config structures */
164     /* merge per-directory config structures  */
165     /* create per-server config structures    */
166     /* merge per-server config structures     */
167     /* command handlers */
168     /* handlers */
169     /* register hooks */
170 };</pre></div>
171
172       <p>Some of these read directly across, some don't. I'll try to
173       summarise what should be done below.</p>
174
175       <p>The stages that read directly across :</p>
176
177       <dl>
178         <dt><code>/* dir config creater */</code></dt>
179         <dd><code>/* create per-directory config structures */</code></dd>
180
181         <dt><code>/* server config */</code></dt>
182         <dd><code>/* create per-server config structures */</code></dd>
183
184         <dt><code>/* dir merger */</code></dt>
185         <dd><code>/* merge per-directory config structures */</code></dd>
186
187         <dt><code>/* merge server config */</code></dt>
188         <dd><code>/* merge per-server config structures */</code></dd>
189
190         <dt><code>/* command table */</code></dt>
191         <dd><code>/* command apr_table_t */</code></dd>
192
193         <dt><code>/* handlers */</code></dt>
194         <dd><code>/* handlers */</code></dd>
195       </dl>
196
197       <p>The remainder of the old functions should be registered as
198       hooks. There are the following hook stages defined so
199       far...</p>
200
201       <dl>
202         <dt><code>ap_hook_pre_config</code></dt>
203         <dd>do any setup required prior to processing configuration
204         directives</dd>
205
206         <dt><code>ap_hook_check_config</code></dt>
207         <dd>review configuration directive interdependencies</dd>
208
209         <dt><code>ap_hook_test_config</code></dt>
210         <dd>executes only with <code>-t</code> option</dd>
211
212         <dt><code>ap_hook_open_logs</code></dt>
213         <dd>open any specified logs</dd>
214
215         <dt><code>ap_hook_post_config</code></dt>
216         <dd>this is where the old <code>_init</code> routines get
217         registered</dd>
218
219         <dt><code>ap_hook_http_method</code></dt>
220         <dd>retrieve the http method from a request. (legacy)</dd>
221
222         <dt><code>ap_hook_auth_checker</code></dt>
223         <dd>check if the resource requires authorization</dd>
224
225         <dt><code>ap_hook_access_checker</code></dt>
226         <dd>check for module-specific restrictions</dd>
227
228         <dt><code>ap_hook_check_user_id</code></dt>
229         <dd>check the user-id and password</dd>
230
231         <dt><code>ap_hook_default_port</code></dt>
232         <dd>retrieve the default port for the server</dd>
233
234         <dt><code>ap_hook_pre_connection</code></dt>
235         <dd>do any setup required just before processing, but after
236         accepting</dd>
237
238         <dt><code>ap_hook_process_connection</code></dt>
239         <dd>run the correct protocol</dd>
240
241         <dt><code>ap_hook_child_init</code></dt>
242         <dd>call as soon as the child is started</dd>
243
244         <dt><code>ap_hook_create_request</code></dt>
245         <dd>??</dd>
246
247         <dt><code>ap_hook_fixups</code></dt>
248         <dd>last chance to modify things before generating content</dd>
249
250         <dt><code>ap_hook_handler</code></dt>
251         <dd>generate the content</dd>
252
253         <dt><code>ap_hook_header_parser</code></dt>
254         <dd>lets modules look at the headers, not used by most modules, because
255         they use <code>post_read_request</code> for this</dd>
256
257         <dt><code>ap_hook_insert_filter</code></dt>
258         <dd>to insert filters into the filter chain</dd>
259
260         <dt><code>ap_hook_log_transaction</code></dt>
261         <dd>log information about the request</dd>
262
263         <dt><code>ap_hook_optional_fn_retrieve</code></dt>
264         <dd>retrieve any functions registered as optional</dd>
265
266         <dt><code>ap_hook_post_read_request</code></dt>
267         <dd>called after reading the request, before any other phase</dd>
268
269         <dt><code>ap_hook_quick_handler</code></dt>
270         <dd>called before any request processing, used by cache modules.</dd>
271
272         <dt><code>ap_hook_translate_name</code></dt>
273         <dd>translate the URI into a filename</dd>
274
275         <dt><code>ap_hook_type_checker</code></dt>
276         <dd>determine and/or set the doc type</dd>
277       </dl>
278     
279 </div></div>
280 <div class="bottomlang">
281 <p><span>Available Languages: </span><a href="../en/developer/modules.html" title="English">&nbsp;en&nbsp;</a> |
282 <a href="../ja/developer/modules.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
283 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
284 <script type="text/javascript"><!--//--><![CDATA[//><!--
285 var comments_shortname = 'httpd';
286 var comments_identifier = 'http://httpd.apache.org/docs/trunk/developer/modules.html';
287 (function(w, d) {
288     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
289         d.write('<div id="comments_thread"><\/div>');
290         var s = d.createElement('script');
291         s.type = 'text/javascript';
292         s.async = true;
293         s.src = 'https://c.apaste.info/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
294         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
295     }
296     else {
297         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
298     }
299 })(window, document);
300 //--><!]]></script></div><div id="footer">
301 <p class="apache">Copyright 2012 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
302 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
303 if (typeof(prettyPrint) !== 'undefined') {
304     prettyPrint();
305 }
306 //--><!]]></script>
307 </body></html>