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