~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to docs/manual/developer/modules.html.en

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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" />
 
12
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
 
13
<body id="manual-page"><div id="page-header">
 
14
<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
 
15
<p class="apache">Apache HTTP Server Version 2.2</p>
 
16
<img alt="" src="../images/feather.gif" /></div>
 
17
<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
 
18
<div id="path">
 
19
<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.2</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>
 
20
<div class="toplang">
 
21
<p><span>Available Languages: </span><a href="../en/developer/modules.html" title="English">&nbsp;en&nbsp;</a> |
 
22
<a href="../ja/developer/modules.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
 
23
</div>
 
24
 
 
25
    <p>This is a first attempt at writing the lessons I learned
 
26
    when trying to convert the <code>mod_mmap_static</code> module to Apache
 
27
    2.0. It's by no means definitive and probably won't even be
 
28
    correct in some ways, but it's a start.</p>
 
29
</div>
 
30
<div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#easy">The easier changes ...</a></li>
 
31
<li><img alt="" src="../images/down.gif" /> <a href="#messy">The messier changes...</a></li>
 
32
</ul></div>
 
33
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 
34
<div class="section">
 
35
<h2><a name="easy" id="easy">The easier changes ...</a></h2>
 
36
 
 
37
    <h3><a name="cleanup" id="cleanup">Cleanup Routines</a></h3>
 
38
      <p>These now need to be of type <code>apr_status_t</code> and return a
 
39
      value of that type. Normally the return value will be
 
40
      <code>APR_SUCCESS</code> unless there is some need to signal an error in
 
41
      the cleanup. Be aware that even though you signal an error not all code
 
42
      yet checks and acts upon the error.</p>
 
43
    
 
44
 
 
45
    <h3><a name="init" id="init">Initialisation Routines</a></h3>
 
46
      <p>These should now be renamed to better signify where they sit
 
47
      in the overall process. So the name gets a small change from
 
48
      <code>mmap_init</code> to <code>mmap_post_config</code>. The arguments
 
49
      passed have undergone a radical change and now look like</p>
 
50
 
 
51
      <ul>
 
52
        <li><code>apr_pool_t *p</code></li>
 
53
        <li><code>apr_pool_t *plog</code></li>
 
54
        <li><code>apr_pool_t *ptemp</code></li>
 
55
        <li><code>server_rec *s</code></li>
 
56
      </ul>
 
57
    
 
58
 
 
59
    <h3><a name="datatypes" id="datatypes">Data Types</a></h3>
 
60
      <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
 
61
      a name change, such as the one shown above. The following is a brief
 
62
      list of some of the changes that you are likely to have to make.</p>
 
63
 
 
64
      <ul>
 
65
        <li><code>pool</code> becomes <code>apr_pool_t</code></li>
 
66
        <li><code>table</code> becomes <code>apr_table_t</code></li>
 
67
      </ul>
 
68
    
 
69
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 
70
<div class="section">
 
71
<h2><a name="messy" id="messy">The messier changes...</a></h2>
 
72
 
 
73
    <h3><a name="register-hooks" id="register-hooks">Register Hooks</a></h3>
 
74
      <p>The new architecture uses a series of hooks to provide for
 
75
      calling your functions. These you'll need to add to your module
 
76
      by way of a new function, <code>static void register_hooks(void)</code>.
 
77
      The function is really reasonably straightforward once you
 
78
      understand what needs to be done. Each function that needs
 
79
      calling at some stage in the processing of a request needs to
 
80
      be registered, handlers do not. There are a number of phases
 
81
      where functions can be added, and for each you can specify with
 
82
      a high degree of control the relative order that the function
 
83
      will be called in.</p>
 
84
 
 
85
      <p>This is the code that was added to <code>mod_mmap_static</code>:</p>
 
86
      <div class="example"><pre>
 
87
static void register_hooks(void)
 
88
{
 
89
    static const char * const aszPre[]={ "http_core.c",NULL };
 
90
    ap_hook_post_config(mmap_post_config,NULL,NULL,HOOK_MIDDLE);
 
91
    ap_hook_translate_name(mmap_static_xlat,aszPre,NULL,HOOK_LAST);
 
92
};</pre></div>
 
93
 
 
94
      <p>This registers 2 functions that need to be called, one in
 
95
      the <code>post_config</code> stage (virtually every module will need this
 
96
      one) and one for the <code>translate_name</code> phase. note that while
 
97
      there are different function names the format of each is
 
98
      identical. So what is the format?</p>
 
99
 
 
100
      <div class="example"><p><code>
 
101
        ap_hook_<var>phase_name</var>(<var>function_name</var>,
 
102
        <var>predecessors</var>, <var>successors</var>, <var>position</var>);
 
103
      </code></p></div>
 
104
 
 
105
      <p>There are 3 hook positions defined...</p>
 
106
 
 
107
      <ul>
 
108
        <li><code>HOOK_FIRST</code></li>
 
109
        <li><code>HOOK_MIDDLE</code></li>
 
110
        <li><code>HOOK_LAST</code></li>
 
111
      </ul>
 
112
 
 
113
      <p>To define the position you use the position and then modify
 
114
      it with the predecessors and successors. Each of the modifiers
 
115
      can be a list of functions that should be called, either before
 
116
      the function is run (predecessors) or after the function has
 
117
      run (successors).</p>
 
118
 
 
119
      <p>In the <code>mod_mmap_static</code> case I didn't care about the
 
120
      <code>post_config</code> stage, but the <code>mmap_static_xlat</code>
 
121
      <strong>must</strong> be called after the core module had done it's name
 
122
      translation, hence the use of the aszPre to define a modifier to the
 
123
      position <code>HOOK_LAST</code>.</p>
 
124
    
 
125
 
 
126
    <h3><a name="moddef" id="moddef">Module Definition</a></h3>
 
127
      <p>There are now a lot fewer stages to worry about when
 
128
      creating your module definition. The old defintion looked
 
129
      like</p>
 
130
 
 
131
      <div class="example"><pre>
 
132
module MODULE_VAR_EXPORT <var>module_name</var>_module =
 
133
{
 
134
    STANDARD_MODULE_STUFF,
 
135
    /* initializer */
 
136
    /* dir config creater */
 
137
    /* dir merger --- default is to override */
 
138
    /* server config */
 
139
    /* merge server config */
 
140
    /* command handlers */
 
141
    /* handlers */
 
142
    /* filename translation */
 
143
    /* check_user_id */
 
144
    /* check auth */
 
145
    /* check access */
 
146
    /* type_checker */
 
147
    /* fixups */
 
148
    /* logger */
 
149
    /* header parser */
 
150
    /* child_init */
 
151
    /* child_exit */
 
152
    /* post read-request */
 
153
};</pre></div>
 
154
 
 
155
      <p>The new structure is a great deal simpler...</p>
 
156
      <div class="example"><pre>
 
157
module MODULE_VAR_EXPORT <var>module_name</var>_module =
 
158
{
 
159
    STANDARD20_MODULE_STUFF,
 
160
    /* create per-directory config structures */
 
161
    /* merge per-directory config structures  */
 
162
    /* create per-server config structures    */
 
163
    /* merge per-server config structures     */
 
164
    /* command handlers */
 
165
    /* handlers */
 
166
    /* register hooks */
 
167
};</pre></div>
 
168
 
 
169
      <p>Some of these read directly across, some don't. I'll try to
 
170
      summarise what should be done below.</p>
 
171
 
 
172
      <p>The stages that read directly across :</p>
 
173
 
 
174
      <dl>
 
175
        <dt><code>/* dir config creater */</code></dt>
 
176
        <dd><code>/* create per-directory config structures */</code></dd>
 
177
 
 
178
        <dt><code>/* server config */</code></dt>
 
179
        <dd><code>/* create per-server config structures */</code></dd>
 
180
 
 
181
        <dt><code>/* dir merger */</code></dt>
 
182
        <dd><code>/* merge per-directory config structures */</code></dd>
 
183
 
 
184
        <dt><code>/* merge server config */</code></dt>
 
185
        <dd><code>/* merge per-server config structures */</code></dd>
 
186
 
 
187
        <dt><code>/* command table */</code></dt>
 
188
        <dd><code>/* command apr_table_t */</code></dd>
 
189
 
 
190
        <dt><code>/* handlers */</code></dt>
 
191
        <dd><code>/* handlers */</code></dd>
 
192
      </dl>
 
193
 
 
194
      <p>The remainder of the old functions should be registered as
 
195
      hooks. There are the following hook stages defined so
 
196
      far...</p>
 
197
 
 
198
      <dl>
 
199
        <dt><code>ap_hook_post_config</code></dt>
 
200
        <dd>this is where the old <code>_init</code> routines get
 
201
        registered</dd>
 
202
 
 
203
        <dt><code>ap_hook_http_method</code></dt>
 
204
        <dd>retrieve the http method from a request. (legacy)</dd>
 
205
 
 
206
        <dt><code>ap_hook_open_logs</code></dt>
 
207
        <dd>open any specified logs</dd>
 
208
 
 
209
        <dt><code>ap_hook_auth_checker</code></dt>
 
210
        <dd>check if the resource requires authorization</dd>
 
211
 
 
212
        <dt><code>ap_hook_access_checker</code></dt>
 
213
        <dd>check for module-specific restrictions</dd>
 
214
 
 
215
        <dt><code>ap_hook_check_user_id</code></dt>
 
216
        <dd>check the user-id and password</dd>
 
217
 
 
218
        <dt><code>ap_hook_default_port</code></dt>
 
219
        <dd>retrieve the default port for the server</dd>
 
220
 
 
221
        <dt><code>ap_hook_pre_connection</code></dt>
 
222
        <dd>do any setup required just before processing, but after
 
223
        accepting</dd>
 
224
 
 
225
        <dt><code>ap_hook_process_connection</code></dt>
 
226
        <dd>run the correct protocol</dd>
 
227
 
 
228
        <dt><code>ap_hook_child_init</code></dt>
 
229
        <dd>call as soon as the child is started</dd>
 
230
 
 
231
        <dt><code>ap_hook_create_request</code></dt>
 
232
        <dd>??</dd>
 
233
 
 
234
        <dt><code>ap_hook_fixups</code></dt>
 
235
        <dd>last chance to modify things before generating content</dd>
 
236
 
 
237
        <dt><code>ap_hook_handler</code></dt>
 
238
        <dd>generate the content</dd>
 
239
 
 
240
        <dt><code>ap_hook_header_parser</code></dt>
 
241
        <dd>lets modules look at the headers, not used by most modules, because
 
242
        they use <code>post_read_request</code> for this</dd>
 
243
 
 
244
        <dt><code>ap_hook_insert_filter</code></dt>
 
245
        <dd>to insert filters into the filter chain</dd>
 
246
 
 
247
        <dt><code>ap_hook_log_transaction</code></dt>
 
248
        <dd>log information about the request</dd>
 
249
 
 
250
        <dt><code>ap_hook_optional_fn_retrieve</code></dt>
 
251
        <dd>retrieve any functions registered as optional</dd>
 
252
 
 
253
        <dt><code>ap_hook_post_read_request</code></dt>
 
254
        <dd>called after reading the request, before any other phase</dd>
 
255
 
 
256
        <dt><code>ap_hook_quick_handler</code></dt>
 
257
        <dd>called before any request processing, used by cache modules.</dd>
 
258
 
 
259
        <dt><code>ap_hook_translate_name</code></dt>
 
260
        <dd>translate the URI into a filename</dd>
 
261
 
 
262
        <dt><code>ap_hook_type_checker</code></dt>
 
263
        <dd>determine and/or set the doc type</dd>
 
264
      </dl>
 
265
    
 
266
</div></div>
 
267
<div class="bottomlang">
 
268
<p><span>Available Languages: </span><a href="../en/developer/modules.html" title="English">&nbsp;en&nbsp;</a> |
 
269
<a href="../ja/developer/modules.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a></p>
 
270
</div><div id="footer">
 
271
<p class="apache">Copyright 2006 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>
 
272
<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
 
273
</body></html>
 
 
b'\\ No newline at end of file'