]> granicus.if.org Git - apache/blob - docs/manual/developer/new_api_2_4.xml
Document the unfortunate side effect of converting ap_log_*error into macros
[apache] / docs / manual / developer / new_api_2_4.xml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="new_api_2_4.xml.meta">
24
25 <title>API Changes in Apache HTTP Server 2.4 since 2.2</title>
26
27 <summary>
28   <p>This document describes changes to the Apache HTTPD API from
29      version 2.2 to 2.4, that may be of interest to module/application
30      developers and core hacks.  At the time of writing, the 2.4 API
31      is not finalised, and this document may serve to highlight
32      points that call for further review.</p>
33   <p>API changes fall into two categories: APIs that are altogether new,
34      and existing APIs that are expanded or changed.  The latter are
35      further divided into those where all changes are back-compatible
36      (so existing modules can ignore them), and those that might
37      require attention by maintainers.  As with the transition from
38      HTTPD 2.0 to 2.2, existing modules and applications will require
39      recompiling and may call for some attention, but most should not
40      require any substantial updating (although some may be able to
41      take advantage of API changes to offer significant improvements).</p>
42   <p>For the purpose of this document, the API is split according
43      to the public header files.  These headers are themselves the
44      reference documentation, and can be used to generate a browsable
45      HTML reference with <code>make docs</code>.</p>
46 </summary>
47
48 <section id="api_changes">
49   <title>Changed APIs</title>
50
51   <section id="ap_expr">
52     <title>ap_expr (NEW!)</title>
53     <p>Introduces a new API to parse and evaluate boolean and algebraic
54        expressions, including provision for a standard syntax and
55        customised variants.</p>
56   </section>
57
58   <section id="ap_listen">
59     <title>ap_listen (changed; back-compatible)</title>
60     <p>Introduces new API to enable apache child processes to serve different purposes.</p>
61   </section>
62
63   <section id="ap_mpm">
64     <title>ap_mpm (changed)</title>
65   <p><code>ap_mpm_run</code> is replaced by a new <code>mpm</code> hook.
66   Also <code>ap_graceful_stop_signalled</code> is lost, and
67   <code>ap_mpm_register_timed_callback</code> is new.</p>
68   </section>
69
70   <section id="ap_regex">
71     <title>ap_regex (changed)</title>
72   <p>In addition to the existing regexp wrapper, a new higher-level API
73   <code>ap_rxplus</code> is now provided.  This provides the capability to
74   compile Perl-style expressions like <code>s/regexp/replacement/flags</code>
75   and to execute them against arbitrary strings. Support for regexp
76   backreference.</p>
77   </section>
78
79   <section id="ap_slotmem">
80     <title>ap_slotmem (NEW!)</title>
81     <p>Introduces an API for modules to allocate and manage memory slots
82     (normally) for shared memory.</p>
83   </section>
84
85   <section id="ap_socache">
86     <title>ap_socache (NEW!)</title>
87     <p>API to manage a shared object cache.</p>
88   </section>
89
90   <section id="heartbeat">
91     <title>heartbeat (NEW!)</title>
92     <p>common structures for heartbeat modules (should this be public API?)</p>
93   </section>
94
95   <section id="ap_parse_htaccess">
96     <title>ap_parse_htaccess (changed)</title>
97     <p>The function signature for <code>ap_parse_htaccess</code> has been
98     changed. A <code>apr_table_t</code> of individual directives allowed
99     for override must now be passed (override remains).</p>
100   </section>
101
102   <section id="http_config">
103     <title>http_config (changed)</title>
104     <ul>
105       <li>Introduces per-module, per-directory loglevels, including macro wrappers.</li>
106       <li>New AP_DECLARE_MODULE macro to declare all modules.</li>
107       <li>New APLOG_USE_MODULE macro necessary for per-module loglevels in
108           multi-file modules.</li>
109       <li>New API to retain data across module unload/load</li>
110       <li>New check_config hook</li>
111       <li>New ap_process_fnmatch_configs() to process wildcards</li>
112       <li>Change ap_configfile_t, ap_cfg_getline(), ap_cfg_getc() to return error
113           code, new ap_pcfg_strerror().</li>
114       <li>Any config directive permitted in ACCESS_CONF context must now
115           correctly handle being called from an .htaccess file via the new
116           <directive module="core">AllowOverrideList</directive> directive.
117           ap_check_cmd_context() accepts a new flag NOT_IN_HTACCESS to detect
118           this case.</li>
119     </ul>
120   </section>
121
122   <section id="http_core">
123     <title>http_core (changed)</title>
124     <ul>
125       <li>REMOVED ap_default_type, ap_requires, all 2.2 authnz API</li>
126       <li>Introduces Optional Functions for logio and authnz</li>
127       <li>New function ap_get_server_name_for_url to support ipv6 literals.</li>
128       <li>New function ap_register_errorlog_handler to register errorlog
129           format string handlers.</li>
130       <li>Arguments of error_log hook have changed. Declaration has moved to
131           <code>http_core.h</code>.</li>
132       <li>New function ap_state_query to determine if the server is in the
133           initial configuration preflight phase or not. This is both easier to
134           use and more correct than the old method of creating a pool userdata
135           entry in the process pool.</li>
136       <li>New function ap_get_conn_socket to get the socket descriptor for a
137           connection. This should be used instead of accessing the core
138           connection config directly.</li>
139     </ul>
140   </section>
141
142   <section id="httpd">
143     <title>httpd (changed)</title>
144     <ul>
145       <li>Introduce per-directory, per-module loglevel</li>
146       <li>New loglevels APLOG_TRACEn</li>
147       <li>Introduce errorlog ids for requests and connections</li>
148       <li>Support for mod_request kept_body</li>
149       <li>Support buffering filter data for async requests</li>
150       <li>New CONN_STATE values</li>
151       <li>Function changes: ap_escape_html updated; ap_unescape_all,
152           ap_escape_path_segment_buffer</li>
153       <li>Modules that load other modules later than the EXEC_ON_READ config
154           reading stage need to call ap_reserve_module_slots() or
155           ap_reserve_module_slots_directive() in their pre_config hook.</li>
156       <li>The useragent IP address per request can now be specified
157           independently of the client IP address of the connection for
158           the benefit of load balancers</li>
159     </ul>
160   </section>
161
162   <section id="http_log">
163     <title>http_log (changed)</title>
164     <ul>
165       <li>Introduce per-directory, per-module loglevel</li>
166       <li>New loglevels APLOG_TRACEn</li>
167       <li>ap_log_*error become macro wrappers (back-compatible if
168           APLOG_MARK macro is used, except that is no longer possible to
169           use #ifdef inside the argument list)</li>
170       <li>piped logging revamped</li>
171       <li>module_index added to error_log hook</li>
172       <li>new function: ap_log_command_line</li>
173     </ul>
174   </section>
175
176   <section id="http_request">
177     <title>http_request (changed)</title>
178     <ul>
179       <li>New auth_internal API and auth_provider API</li>
180       <li>New EOR bucket type</li>
181       <li>New function ap_process_async_request</li>
182       <li>New flags AP_AUTH_INTERNAL_PER_CONF and AP_AUTH_INTERNAL_PER_URI</li>
183       <li>New access_checker_ex hook to apply additional access control and/or
184           bypass authentication.</li>
185       <li>New functions ap_hook_check_access_ex, ap_hook_check_access,
186           ap_hook_check_authn, ap_hook_check_authz which accept
187           AP_AUTH_INTERNAL_PER_* flags</li>
188       <li>DEPRECATED direct use of ap_hook_access_checker, access_checker_ex,
189           ap_hook_check_user_id, ap_hook_auth_checker</li>
190     </ul>
191     <p>When possible, registering all access control hooks (including
192        authentication and authorization hooks) using AP_AUTH_INTERNAL_PER_CONF
193        is recommended.  If all modules' access control hooks are registered
194        with this flag, then whenever the server handles an internal
195        sub-request that matches the same set of access control configuration
196        directives as the initial request (which is the common case), it can
197        avoid invoking the access control hooks another time.</p>
198     <p>If your module requires the old behavior and must perform access
199        control checks on every sub-request with a different URI from the
200        initial request, even if that URI matches the same set of access
201        control configuration directives, then use AP_AUTH_INTERNAL_PER_URI.</p>
202   </section>
203
204   <section id="mod_auth">
205     <title>mod_auth (NEW!)</title>
206     <p>Introduces the new provider framework for authn and authz</p>
207   </section>
208
209   <section id="mod_cache">
210     <title>mod_cache (changed)</title>
211     <p>Introduces a commit_entity() function to the cache provider interface,
212     allowing atomic writes to cache. Add a cache_status() hook to report
213     the cache decision. Remove all private structures and functions from the
214     public mod_cache.h header file.</p>
215   </section>
216
217   <section id="mod_core">
218     <title>mod_core (NEW!)</title>
219     <p>This introduces low-level APIs to send arbitrary headers,
220     and exposes functions to handle HTTP OPTIONS and TRACE.</p>
221   </section>
222
223   <section id="mod_cache_disk">
224     <title>mod_cache_disk (changed)</title>
225     <p>Changes the disk format of the disk cache to support atomic cache
226     updates without locking. The device/inode pair of the body file is
227     embedded in the header file, allowing confirmation that the header
228     and body belong to one another.</p>
229   </section>
230
231   <section id="mod_disk_cache">
232     <title>mod_disk_cache (renamed)</title>
233     <p>The mod_disk_cache module has been renamed to mod_cache_disk in
234     order to be consistent with the naming of other modules within the
235     server.</p>
236   </section>
237
238   <section id="mod_request">
239     <title>mod_request (NEW!)</title>
240     <p>The API for <module>mod_request</module>, to make input data
241     available to multiple application/handler modules where required,
242     and to parse HTML form data.</p>
243   </section>
244
245   <section id="mpm_common">
246     <title>mpm_common (changed)</title>
247     <ul>
248       <li>REMOVES: accept, lockfile, lock_mech, set_scoreboard (locking uses the new ap_mutex API)</li>
249       <li>NEW API to drop privileges (delegates this platform-dependent
250           function to modules)</li>
251       <li>NEW Hooks: mpm_query, timed_callback, and get_name</li>
252       <li>CHANGED interfaces: monitor hook,
253       ap_reclaim_child_processes, ap_relieve_child_processes</li>
254     </ul>
255   </section>
256
257   <section id="scoreboard">
258     <title>scoreboard (changed)</title>
259     <p>ap_get_scoreboard_worker is gratuitously made non-back-compatible
260     as an alternative version is introduced.  Additional proxy_balancer
261     support.  Child status stuff revamped.</p>
262   </section>
263
264   <section id="util_cookies">
265     <title>util_cookies (NEW!)</title>
266     <p>Introduces a new API for managing HTTP Cookies.</p>
267   </section>
268
269   <section id="util_ldap">
270     <title>util_ldap (changed)</title>
271     <p>I have yet to get a handle on this update.</p>
272   </section>
273
274   <section id="util_mutex">
275     <title>util_mutex (NEW!)</title>
276     <p>A wrapper for APR proc and global mutexes in httpd.</p>
277   </section>
278
279   <section id="util_script">
280     <title>util_script (changed)</title>
281     <p>NEW: ap_args_to_table</p>
282   </section>
283
284   <section id="util_time">
285     <title>util_time (changed)</title>
286     <p>NEW: ap_recent_ctime_ex</p>
287   </section>
288
289 </section>
290
291 <section id="upgrading">
292   <title>Specific information on upgrading modules from 2.2</title>
293
294   <section id="upgrading_logging">
295     <title>Logging</title>
296     <p>In order to take advantage of per-module loglevel configuration, any
297        source file that calls the <code>ap_log_*</code> functions should declare
298        which module it belongs to. If the module's module_struct is called
299        <code>foo_module</code>, the following code can be used to remain
300        backward compatible with HTTPD 2.0 and 2.2:</p>
301     <example>
302         #include &lt;http_log.h&gt;<br/>
303         <br/>
304         #ifdef APLOG_USE_MODULE<br/>
305         APLOG_USE_MODULE(foo);<br/>
306         #endif
307     </example>
308     <p>Note: This is absolutely required for C++-language modules.  It
309     can be skipped for C-language modules, though that breaks
310     module-specific log level support for files without it.</p>
311     <p>The number of parameters of the <code>ap_log_*</code> functions and the
312        definition of <code>APLOG_MARK</code> has changed. Normally, the change
313        is completely transparent. However, changes are required if a
314        module uses <code>APLOG_MARK</code> as a parameter to its own functions
315        or if a module calls <code>ap_log_*</code> without passing
316        <code>APLOG_MARK</code>.  A module which uses wrappers
317        around <code>ap_log_*</code> typically uses both of these constructs.</p>
318
319     <p>The easiest way to change code which passes <code>APLOG_MARK</code> to
320        its own functions is to define and use a different macro that expands to
321        the parameters required by those functions, as <code>APLOG_MARK</code>
322        should only be used when calling <code>ap_log_*</code>
323        directly.  In this way, the code will remain compatible with HTTPD 2.0
324        and 2.2.</p>
325
326     <p>Code which calls <code>ap_log_*</code> without passing
327        <code>APLOG_MARK</code> will necessarily differ between 2.4 and earlier
328        releases, as 2.4 requires a new third argument,
329        <code>APLOG_MODULE_INDEX</code>.</p>
330
331     <example>
332        /* code for httpd 2.0/2.2 */<br />
333        ap_log_perror(file, line, APLOG_ERR, 0, p, "Failed to allocate dynamic lock structure");<br />
334        <br />
335        /* code for httpd 2.4 */<br />
336        ap_log_perror(file, line, APLOG_MODULE_INDEX, APLOG_ERR, 0, p, "Failed to allocate dynamic lock structure");<br />
337        <br />
338     </example>
339
340     <p><code>ap_log_*error</code> are now implemented as macros. This means
341        that it is no longer possible to use <code>#ifdef</code> inside the
342        argument list of <code>ap_log_*error</code>, as this would cause
343        undefined behavor according to C99.</p>
344
345     <p>A <code>server_rec</code> pointer must be passed to
346        <code>ap_log_error()</code> when called after startup.  This
347        was always appropriate, but there are even more limitations with
348        a <code>NULL</code> <code>server_rec</code> in 2.4 than in
349        previous releases.  Beginning with 2.3.12, the global variable
350        <code>ap_server_conf</code> can always be used as
351        the <code>server_rec</code> parameter, as it will be
352        <code>NULL</code> only when it is valid to pass <code>NULL</code>
353        to <code>ap_log_error()</code>.  <code>ap_server_conf</code>
354        should be used only when a more appropriate <code>server_rec</code>
355        is not available.</p>
356
357     <p>Consider the following changes to take advantage of the new
358        <code>APLOG_TRACE1..8</code> log levels:</p>
359        <ul>
360          <li>Check current use of <code>APLOG_DEBUG</code> and
361          consider if one of the <code>APLOG_TRACEn</code> levels is
362          more appropriate.</li>
363          <li>If your module currently has a mechanism for configuring
364          the amount of debug logging which is performed, consider
365          eliminating that mechanism and relying on the use of
366          different <code>APLOG_TRACEn</code> levels.  If expensive
367          trace processing needs to be bypassed depending on the
368          configured log level, use the <code>APLOGtrace<em>n</em></code>
369          and <code>APLOGrtrace<em>n</em></code> macros to first check
370          if tracing is enabled.</li>
371        </ul>
372
373     <p>Modules sometimes add process id and/or thread id to their log
374        messages.  These ids are now logged by default, so it may not
375        be necessary for the module to log them explicitly.  (Users may
376        remove them from the error log format, but they can be
377        instructed to add it back if necessary for problem diagnosis.)</p>
378   </section>
379
380   <section id="upgrading_byfunction">
381     <title>If your module uses these existing APIs...</title>
382
383     <dl>
384       <dt><code>ap_default_type()</code></dt>
385       <dd>This is no longer available; Content-Type must be configured
386           explicitly or added by the application.</dd>
387
388       <dt><code>ap_get_server_name()</code></dt>
389       <dd>If the returned server name is used in a URL,
390       use <code>ap_get_server_name_for_url()</code> instead.  This new
391       function handles the odd case where the server name is an IPv6
392       literal address.</dd>
393
394       <dt><code>ap_get_server_version()</code></dt>
395       <dd>For logging purposes, where detailed information is
396           appropriate, use <code>ap_get_server_description()</code>.
397           When generating output, where the amount of information
398           should be configurable by ServerTokens, use
399           <code>ap_get_server_banner()</code>.</dd>
400
401       <dt><code>ap_graceful_stop_signalled()</code></dt>
402       <dd>Replace with a call
403       to <code>ap_mpm_query(AP_MPMQ_MPM_STATE)</code> and checking for
404       state <code>AP_MPMQ_STOPPING</code>.</dd>
405
406       <dt><code>ap_max_daemons_limit</code>, <code>ap_my_generation</code>,
407           and <code>ap_threads_per_child</code></dt>
408       <dd>Use <code>ap_mpm_query()</code> query codes
409           <code>AP_MPMQ_MAX_DAEMON_USED</code>, <code>AP_MPMQ_GENERATION</code>,
410           and <code>AP_MPMQ_MAX_THREADS</code>, respectively.</dd>
411
412       <dt><code>ap_mpm_query()</code></dt>
413       <dd>Ensure that it is not used until after the register-hooks
414           hook has completed.  Otherwise, an MPM built as a DSO
415           would not have had a chance to enable support for this
416           function.</dd>
417
418       <dt><code>ap_server_conf->process->pool</code>
419       userdata</dt>
420       <dd>
421         Optional:
422         <ul>
423           <li>If your module uses this to determine which pass of the
424           startup hooks is being run,
425           use <code>ap_state_query(AP_SQ_MAIN_STATE)</code>.</li>
426           <li>If your module uses this to maintain data across the
427           unloading and reloading of your module, use
428           <code>ap_retained_data_create()</code> and
429           <code>ap_retained_data_get()</code>.</li>
430         </ul>
431       </dd>
432
433       <dt><code>apr_global_mutex_create()</code>,
434           <code>apr_proc_mutex_create()</code></dt>
435       <dd>Optional: See <code>ap_mutex_register()</code>,
436           <code>ap_global_mutex_create()</code>, and
437           <code>ap_proc_mutex_create()</code>; these allow your
438           mutexes to be configurable with
439           the <directive module="core">Mutex</directive> directive;
440           you can also remove any configuration mechanisms in your
441           module for such mutexes
442       </dd>
443
444       <dt><code>CORE_PRIVATE</code></dt>
445       <dd>This is now unnecessary and ignored.</dd>
446
447       <dt><code>dav_new_error()</code>
448       and <code>dav_new_error_tag()</code></dt>
449       <dd>Previously, these assumed that <code>errno</code> contained
450       information describing the failure.  Now,
451       an <code>apr_status_t</code> parameter must be provided.  Pass
452       0/APR_SUCCESS if there is no such error information, or a valid
453       <code>apr_status_t</code> value otherwise.</dd>
454
455       <dt><code>mpm_default.h</code>, <code>DEFAULT_LOCKFILE</code>,
456       <code>DEFAULT_THREAD_LIMIT</code>, <code>DEFAULT_PIDLOG</code>,
457       etc.</dt>
458       <dd>The header file and most of the default configuration
459       values set in it are no longer visible to modules.  (Most can
460       still be overridden at build time.)  <code>DEFAULT_PIDLOG</code>
461       and <code>DEFAULT_REL_RUNTIMEDIR</code> are now universally
462       available via <code>ap_config.h</code>.</dd>
463
464       <dt><code>unixd_config</code></dt>
465       <dd>This has been renamed to ap_unixd_config.</dd>
466
467       <dt><code>conn_rec->remote_ip and conn_rec->remote_addr</code></dt>
468       <dd>In order to distinguish between the client IP address of the
469       connection, and the useragent IP address of the request potentially
470       overridden by a load balancer or proxy, the above variables have
471       been renamed. If a module makes reference to either of the above
472       variables, they need to be replaced with one of the following two
473       options as appropriate for the module:
474       <ul>
475         <li>When you require the IP address of the user agent, which
476         might be connected directly to the server, or might optionally be
477         separated from the server by a transparent load balancer or
478         proxy, use request_rec->useragent_ip and
479         request_rec->useragent_addr.</li>
480         <li>When you require the IP address of the client that is
481         connected directly to the server, which might be the useragent or
482         might be the load balancer or proxy itself, use
483         conn_rec->client_ip and conn_rec->client_addr.</li>
484       </ul>
485       </dd>
486     </dl>
487   </section>
488
489   <section id="upgrading_byfeature">
490     <title>If your module interfaces with this feature...</title>
491     <dl>
492       <dt>suEXEC</dt>
493       <dd>Optional: If your module logs an error
494           when <code>ap_unixd_config.suexec_enabled</code> is 0,
495           also log the value of the new
496           field <code>suexec_disabled_reason</code>, which contains an
497           explanation of why it is not available.</dd>
498
499       <dt>Extended status data in the scoreboard</dt>
500       <dd>In previous releases, <code>ExtendedStatus</code> had to be
501           set to <code>On</code>, which in turn required that
502           mod_status was loaded.  In 2.4, just
503           set <code>ap_extended_status</code> to <code>1</code> in a
504           pre-config hook and the extended status data will be
505           available.</dd>
506
507     </dl>
508   </section>
509
510   <section id="upgrading_newfeatures">
511     <title>Does your module...</title>
512     <dl>
513     <dt>Parse query args</dt>
514     <dd>Consider if <code>ap_args_to_table()</code> would be
515     helpful.</dd>
516
517     <dt>Parse form data...</dt>
518     <dd>Use <code>ap_parse_form_data()</code>.</dd>
519
520     <dt>Check for request header fields <code>Content-Length</code>
521     and <code>Transfer-Encoding</code> to see if a body was
522     specified</dt>
523     <dd>Use <code>ap_request_has_body()</code>.</dd>
524
525     <dt>Implement cleanups which clear pointer variables</dt>
526     <dd>Use <code>ap_pool_cleanup_set_null()</code>.</dd>
527     </dl>
528   </section>
529
530 </section>
531
532 </manualpage>