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