modguide.xml revision f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55db
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<?xml version='1.0' encoding='UTF-8' ?>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
28fed5323a564c1aacad7af660c2359268b44570nd<!-- $LastChangedRevision$ -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!--
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh Licensed to the Apache Software Foundation (ASF) under one or more
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh contributor license agreements. See the NOTICE file distributed with
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh this work for additional information regarding copyright ownership.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh The ASF licenses this file to You under the Apache License, Version 2.0
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh (the "License"); you may not use this file except in compliance with
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh the License. You may obtain a copy of the License at
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh http://www.apache.org/licenses/LICENSE-2.0
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh Unless required by applicable law or agreed to in writing, software
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh distributed under the License is distributed on an "AS IS" BASIS,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh See the License for the specific language governing permissions and
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh limitations under the License.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh-->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<manualpage metafile="modguide.xml.meta">
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<parentdocument href="./">Developer</parentdocument>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <title>Developing modules for the Apache HTTP Server 2.4</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<summary>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<p>This document explains how you can develop modules for the Apache HTTP
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohServer 2.4</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</summary>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<seealso><a href="request.html">Request Processing in Apache 2.4</a></seealso>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<seealso><a href="hooks.html">Apache 2.x Hook Functions</a></seealso>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="introduction"><title>Introduction</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="what"><title>What we will be discussing in this document</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThis document will discuss how you can easily create modules for the Apache
5408def46d326118d1a65a93a86b646008ed01e1humbedoohHTTP Server 2.4, by exploring an example module called
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<code>mod_example</code>. In the first part of this document, the purpose
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohof this module will be to calculate and print out various digest values for
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohexisting files on your web server, whenever we access the URL <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhttp://hostname/filename.sum</code>. For instance, if we want to know the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohMD5 digest value of the file located at <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhttp://www.example.com/index.html</code>, we would visit <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhttp://www.example.com/index.html.sum</code>.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn the second part of this document, which deals with configuration
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohdirective and context awareness, we will be looking at a module that simply
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwrite out its own configuration to the client.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="prerequisites"><title>Prerequisites</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohFirst and foremost, you are expected to have a basic knowledge of how the C
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohprogramming language works. In most cases, we will try to be as pedagogical
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohas possible and link to documents describing the functions used in the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohexamples, but there are also many cases where it is necessary to either
05664b3e454b2686379515dc6775bfbc51d3dc6ahumbedoohjust assume that "it works" or do some digging yourself into what the hows
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohand whys of various function calls.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohLastly, you will need to have a basic understanding of how modules are
5408def46d326118d1a65a93a86b646008ed01e1humbedoohloaded and configured in the Apache HTTP Server, as well as how to get the headers for
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohApache if you do not have them already, as these are needed for compiling
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohnew modules.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="compiling"><title>Compiling your module</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohTo compile the source code we are building in this document, we will be
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohusing <a href="/programs/apxs.html">APXS</a>. Assuming your source file
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohis called mod_example.c, compiling, installing and activating the module is
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohas simple as:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohapxs -i -a -c mod_example.c
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="basics"><title>Defining a module</title>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<img src="/images/build_a_mod_3.png" alt="Module name tags"/><br/>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<p>Every module starts with the same declaration, or name tag if you will,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthat defines a module as <em>a separate entity within Apache</em>:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF<code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh create_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh merge_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh create_svr_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh merge_svr_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh directives<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedoohThis bit of code lets the server know that we have now registered a new module
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohin the system, and that its name is <code>example_module</code>. The name
05664b3e454b2686379515dc6775bfbc51d3dc6ahumbedoohof the module is used primarily for two things:<br/>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li>Letting the server know how to load the module using the LoadModule</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Setting up a namespace for the module to use in configurations</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohFor now, we're only concerned with the first purpose of the module name,
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedoohwhich comes into play when we need to load the module:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre><a href="/mod/mod_so.html#LoadModule">LoadModule</a> example_module modules/mod_example.so</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohIn essence, this tells the server to open up <code>mod_example.so</code> and look for a module
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohcalled <code>example_module</code>.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohWithin this name tag of ours is also a bunch of references to how we would
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohlike to handle things: Which directives do we respond to in a configuration
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohfile or .htaccess, how do we operate within specific contexts, and what
5408def46d326118d1a65a93a86b646008ed01e1humbedoohhandlers are we interested in registering with the Apache HTTP service. We'll
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohreturn to all these elements later in this document.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<section id="hooking"><title>Getting started: Hooking into the server</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="hook_intro"><title>An introduction to hooks</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohWhen handling requests in Apache HTTP Server 2.4, the first thing you will need to do is
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcreate a hook into the request handling process. A hook is essentially a
5408def46d326118d1a65a93a86b646008ed01e1humbedoohmessage telling the server that you are willing to either serve or at least
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohtake a glance at certain requests given by clients. All handlers, whether
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohit's mod_rewrite, mod_authn_*, mod_proxy and so on, are hooked into
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohspecific parts of the request process. As you are probably aware, modules
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohserve different purposes; Some are authentication/authorization handlers,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohothers are file or script handlers while some third modules rewrite URIs or
5408def46d326118d1a65a93a86b646008ed01e1humbedoohproxies content. Furthermore, in the end, it is up to the user of the server
5408def46d326118d1a65a93a86b646008ed01e1humbedoohhow and when each module will come into place. Thus, the server itself does not
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohpresume to know which module is responsible for handling a specific
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrequest, and will ask each module whether they have an interest in a given
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrequest or not. It is then up to each module to either gently decline
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohserving a request, accept serving it or flat out deny the request from
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohbeing served, as authentication/authorization modules do: <br/>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<img src="/images/build_a_mod_2.png" alt="Hook handling in httpd"/><br/>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohTo make it a bit easier for handlers such as our mod_example to know
5408def46d326118d1a65a93a86b646008ed01e1humbedoohwhether the client is requesting content we should handle or not, the server
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhas directives for hinting to modules whether their assistance is needed or
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohnot. Two of these are <directive module="mod_mime">AddHandler</directive>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohand <directive module="core">SetHandler</directive>. Let's take a look at
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohan example using <directive module="mod_mime">AddHandler</directive>. In
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour example case, we want every request ending with .sum to be served by
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<code>mod_example</code>, so we'll add a configuration directive that tells
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthe server to do just that:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohAddHandler example-handler .sum
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohWhat this tells the server is the following: <em>Whenever we receive a request
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohfor a URI ending in .sum, we are to let all modules know that we are
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohlooking for whoever goes by the name of &quot;example-handler&quot; </em>.
5408def46d326118d1a65a93a86b646008ed01e1humbedoohThus, when a request is being served that ends in .sum, the server will let all
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmodules know, that this request should be served by &quot;example-handler
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh&quot;. As you will see later, when we start building mod_example, we will
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcheck for this handler tag relayed by <code>AddHandler</code> and reply to
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthe server based on the value of this tag.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="hook_declaration"><title>Hooking into httpd</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohTo begin with, we only want to create a simple handler, that replies to the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohclient browser when a specific URL is requested, so we won't bother setting
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohup configuration handlers and directives just yet. Our initial module
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohdefinition will look like this:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module =
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh{
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>register_hooks</code> <code style='color:#c34e00; '><code style='color:#c34e00; '>/* Our hook registering function */</code></code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh};
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedoohThis lets the server know that we are not interesting in anything fancy, we
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohjust want to hook onto the requests and possibly handle some of them. </p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<p> The reference in our example declaration, <code>register_hooks</code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohis the name of a function we will create to manage how we hook onto the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrequest process. In this example module, the function has just one purpose;
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohTo create a simple hook that gets called after all the rewrites, access
5408def46d326118d1a65a93a86b646008ed01e1humbedoohcontrol etc has been handled. Thus, we will let the server know, that we want
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohto hook into its process as one of the last modules:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Create a hook in the request handler, so we get called when a request arrives */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>ap_hook_handler</code><code style='color:#806030; '>(</code>example_handler<code style='color:#806030; '>,</code> <code style='color:#7f0055; font-weight:bold; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#7f0055; font-weight:bold; '>NULL</code><code style='color:#806030; '>,</code> APR_HOOK_LAST<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThe <code>example_handler</code> reference is the function that will handle
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthe request. We will discuss how to create a handler in the next chapter.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="hook_others"><title>Other useful hooks</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohHooking into the request handling phase is but one of many hooks that you
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcan create. Some other ways of hooking are:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li><code>ap_hook_child_init</code>: Place a hook that executes when a child process is spawned (commonly used for initializing modules after the server has forked)</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>ap_hook_pre_config</code>: Place a hook that executes before any configuration data has been read (very early hook)</li>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li><code>ap_hook_post_config</code>: Place a hook that executes after configuration has been parsed, but before the server has forked</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>ap_hook_translate_name</code>: Place a hook that executes when a URI needs to be translated into a filename on the server (think <code>mod_rewrite</code>)</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="handling"><title>Building a handler</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohA handler is essentially a function that receives a callback when a request
5408def46d326118d1a65a93a86b646008ed01e1humbedoohto the server is made. It is passed a record of the current request (how it was
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmade, which headers and requests were passed along, who's giving the
5408def46d326118d1a65a93a86b646008ed01e1humbedoohrequest and so on), and is put in charge of either telling the server that it's
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohnot interested in the request or handle the request with the tools provided.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<section id="simple_handler"><title>A simple &quot;Hello, world!&quot;
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhandler</title> Let's start off by making a very simple request handler
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthat does the following: <br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ol>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Check that this is a request that should be served by &quot;example-handler&quot;</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Set the content type of our output to <code>text/html</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Write &quot;Hello, world!&quot; back to the client browser</li>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li>Let the server know that we took care of this request and everything went fine</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ol>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohIn C code, our example handler will now look like this:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* First off, we need to check if this is a call for the "example-handler" handler.</code>
b0f3904bd0a4fd47ac0f508c88379b39dd912d0dhumbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;* If it is, we accept it and do our things, if not, we simply return DECLINED,</code>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;* and the server will try somewhere else.</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Now that we are handling this request, we'll write out "Hello, world!" to the client.</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;* To do so, we must first set the appropriate content type, followed by our output.</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#gaa2f8412c400197338ec509f4a45e4579">ap_set_content_type</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/html</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#ga5e91eb6ca777c9a427b2e82bf1eeb81d">ap_rprintf</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Hello, world!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedooh <code style='color:#c34e00; '>/* Lastly, we must tell the server that we took care of this request and everything went fine.</code>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;* We do so by simply returning the value OK to the server.</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohNow, we put all we have learned together and end up with a program that
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohlooks like
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<a href="http://people.apache.org/~humbedooh/mods/examples/mod_example_1.c">mod_example_1.c</a>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh. The functions used in this example will be explained later in the section
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<a href= "#functions">&quot;Some useful functions you should know&quot;</a>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh. </section> <section id="request_rec"><title>The request_rec structure
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh</title> <p>The most essential part of any request is the <em>request record
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh</em>. In a call to a handler function, this is represented by the <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrequest_req* </code> structure passed along with every call that is made.
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThis struct, typically just refered to as <code>r</code> in modules,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcontains all the information you need for your module to fully process any
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohHTTP request and respond accordingly.</p> <p>Some key elements of the <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrequest_req </code> structure are:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li><code><code style='color:#008833'>r-&gt;handler</code> (char*)</code>: Contains the name of the handler the server is currently asking to do the handling of this request</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;method</code> (char*)</code>: Contains the HTTP method being used, f.x. GET or POST</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;filename</code> (char*)</code>: Contains the translated filename the client is requesting</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;args</code> (char*)</code>: Contains the query string of the request, if any</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;headers_in</code> (apr_table_t*)</code>: Contains all the headers sent by the client</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;connection</code> (conn_rec*)</code>: A record containing information about the current connection</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;useragent_ip</code> (char*)</code>: The IP address of the client connecting to us</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code><code style='color:#008833'>r-&gt;pool</code> (apr_pool_t*)</code>: The memory pool of this request. We'll discuss this in the &quot;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<a href="#memory">Memory management</a>&quot; chapter.</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohA complete list of all the values contained with in the <code>request_req</code> structure can be found in
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohthe <a href="http://svn.apache.org/repos/asf/httpd/httpd/trunk/include/httpd.h"><code>httpd.h</code></a> header
1784f96e3c9d47bf36a4d973d47e3857f260fc7dhumbedoohfile or at <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/structrequest__rec.html">http://ci.apache.org/projects/httpd/trunk/doxygen/structrequest__rec.html</a>.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohLet's try out some of these variables in another example handler:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Set the appropriate content type */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#gaa2f8412c400197338ec509f4a45e4579">ap_set_content_type</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/html</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print out the IP address of the client connecting to us: */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#ga5e91eb6ca777c9a427b2e82bf1eeb81d">ap_rprintf</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;h2>Hello, </code><code style='color:#0f6900; '>%s</code><code style='color:#e60000; '>!&lt;/h2></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>useragent_ip</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* If we were reached through a GET or a POST request, be happy, else sad. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code> <code style='color:#806030; '>!</code><code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>method</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>POST</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#806030; '>!</code><code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>method</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>GET</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>You used a GET or a POST method, that makes us happy!&lt;br></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>You did not use POST or GET, that makes us sad :(&lt;br></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Lastly, if there was a query string, let's print that too! */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>args</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#ga5e91eb6ca777c9a427b2e82bf1eeb81d">ap_rprintf</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Your query string was: </code><code style='color:#0f6900; '>%s</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>args</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="return_value"><title>Return values</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohApache relies on return values from handlers to signify whether a request
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwas handled or not, and if so, whether the request went well or not. If a
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmodule is not interested in handling a specific request, it should always
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohreturn the value <code>DECLINED</code>. If it is handling a request, it
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohshould either return the generic value <code>OK</code>, or a specific HTTP
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohstatus code, for example:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Return 404: Not found */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> HTTP_NOT_FOUND<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
05664b3e454b2686379515dc6775bfbc51d3dc6ahumbedoohReturning <code>OK</code> or a HTTP status code does not necessarily mean
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthat the request will end. The server may still have other handlers that are
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohinterested in this request, for instance the logging modules which, upon a
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohsuccessful request, will write down a summary of what was requested and how
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohit went. To do a full stop and prevent any further processing after your
5408def46d326118d1a65a93a86b646008ed01e1humbedoohmodule is done, you can return the value <code>DONE</code> to let the server
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohknow that it should cease all activity on this request and carry on with
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthe next, without informing other handlers.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<strong>General response codes:</strong>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>DECLINED</code>: We are not handling this request</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>OK</code>: We handled this request and it went well</li>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li><code>DONE</code>: We handled this request and the server should just close this thread without further processing</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul><br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<strong>HTTP specific return codes (excerpt):</strong>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_OK (200)</code>: Request was okay</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_MOVED_PERMANENTLY (301)</code>: The resource has moved to a new URL</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_UNAUTHORIZED (401)</code>: Client is not authorized to visit this page</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_FORBIDDEN (403)</code>: Permission denied</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_NOT_FOUND (404)</code>: File not found</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>HTTP_INTERNAL_SERVER_ERROR (500)</code>: Internal server error (self explanatory)</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="functions"><title>Some useful functions you should know</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code>ap_rputs(const char *string, request_req *r)</code>: <br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh Sends a string of text to the client. This is a shorthand version of <a
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#gac827cd0537d2b6213a7c06d7c26cc36e">
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rwrite</a>.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Hello, world!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code></pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#ga5e91eb6ca777c9a427b2e82bf1eeb81d">ap_rprintf</a></code>: <br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh This function works just like <code>printf</code>, except it sends the result to the client.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'><code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#ga5e91eb6ca777c9a427b2e82bf1eeb81d">ap_rprintf</a></code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Hello, </code><code style='color:#0f6900; '>%s</code><code style='color:#e60000; '>!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>useragent_ip</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code></pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#gaa2f8412c400197338ec509f4a45e4579">ap_set_content_type</a>(request_req *r, const char *type)</code>: <br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh Sets the content type of the output you are sending.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'><code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__PROTO.html#gaa2f8412c400197338ec509f4a45e4579">ap_set_content_type</a></code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/plain</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* force a raw text output */</code></pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="memory"><title>Memory management</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohManaging your resources in Apache HTTP Server 2.4 is quite easy, thanks to the memory pool
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohsystem. In essence, each server, connection and request have their own
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmemory pool that gets cleaned up when its scope ends, e.g. when a request
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohis done or when a server process shuts down. All your module needs to do is
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohlatch onto this memory pool, and you won't have to worry about having to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohclean up after yourself - pretty neat, huh?
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
05664b3e454b2686379515dc6775bfbc51d3dc6ahumbedoohIn our module, we will primarily be allocating memory for each request, so
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohit's appropriate to use the <code style='color:#008833'>r-&gt;pool</code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohreference when creating new objects. A few of the functions for allocating
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmemory within a pool are:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ul>
2012d5e61d7a0648e2831321bad89085ea4718d3humbedooh<li><code>void* <a href="http://apr.apache.org/docs/apr/1.4/group__apr__pools.html#ga85f1e193c31d109affda72f9a92c6915">apr_palloc</a>(
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohapr_pool_t *p, apr_size_t size)</code>: Allocates <code>size</code> number of bytes in the pool for you</li>
2012d5e61d7a0648e2831321bad89085ea4718d3humbedooh<li><code>void* <a href="http://apr.apache.org/docs/apr/1.4/group__apr__pools.html#gaf61c098ad258069d64cdf8c0a9369f9e">apr_pcalloc</a>(
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohapr_pool_t *p, apr_size_t size)</code>: Allocates <code>size</code> number of bytes in the pool for you and sets all bytes to 0</li>
2012d5e61d7a0648e2831321bad89085ea4718d3humbedooh<li><code>char* <a href="http://apr.apache.org/docs/apr/1.4/group__apr__strings.html#gabc79e99ff19abbd7cfd18308c5f85d47">apr_pstrdup</a>(
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohapr_pool_t *p, const char *s)</code>: Creates a duplicate of the string <code>s</code>. This is useful for copying constant values so you can edit them</li>
2012d5e61d7a0648e2831321bad89085ea4718d3humbedooh<li><code>char* <a href="http://apr.apache.org/docs/apr/1.4/group__apr__strings.html#ga3eca76b8d293c5c3f8021e45eda813d8">apr_psprintf</a>(
5408def46d326118d1a65a93a86b646008ed01e1humbedoohapr_pool_t *p, const char *fmt, ...)</code>: Similar to <code>sprintf</code>, except the server supplies you with an appropriately allocated target variable</li>
2012d5e61d7a0648e2831321bad89085ea4718d3humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ul>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohLet's put these functions into an example handler:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '>*</code> original <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>You can't edit this!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
afcfeaafe0f4332a9abc222501b8528d5afdbe36humbedooh <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '>*</code> copy<code style='color:#806030; '>;</code>
afcfeaafe0f4332a9abc222501b8528d5afdbe36humbedooh <code style='color:#400000; font-weight:bold; '>int</code><code style='color:#806030; '>*</code> integers<code style='color:#806030; '>;</code>
afcfeaafe0f4332a9abc222501b8528d5afdbe36humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Allocate space for 10 integer values and set them all to zero. */</code>
afcfeaafe0f4332a9abc222501b8528d5afdbe36humbedooh integers <code style='color:#806030; '>=</code> apr_pcalloc<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>sizeof</code><code style='color:#806030; '>(</code><code style='color:#400000; font-weight:bold; '>int</code><code style='color:#806030; '>)</code><code style='color:#806030; '>*</code><code style='color:#c00000; '>10</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Create a copy of the 'original' variable that we can edit. */</code>
afcfeaafe0f4332a9abc222501b8528d5afdbe36humbedooh copy <code style='color:#806030; '>=</code> apr_pstrdup<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>pool<code style='color:#806030; '>,</code> original<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThis is all well and good for our module, which won't need any
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohpre-initialized variables or structures. However, if we wanted to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohinitialize something early on, before the requests come rolling in, we
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcould simply add a call to a function in our <code>register_hooks</code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohfunction to sort it out:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Call a function that initializes some stuff */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>example_init_function</code><code style='color:#806030; '>(</code>pool<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Create a hook in the request handler, so we get called when a request arrives */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>ap_hook_handler</code><code style='color:#806030; '>(</code>example_handler<code style='color:#806030; '>,</code> <code style='color:#7f0055; font-weight:bold; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#7f0055; font-weight:bold; '>NULL</code><code style='color:#806030; '>,</code> APR_HOOK_LAST<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn this pre-request initialization function we would not be using the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohsame pool as we did when allocating resources for request-based functions.
5408def46d326118d1a65a93a86b646008ed01e1humbedoohInstead, we would use the pool given to us by the server for allocating memory
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohon a per-process based level.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="parsing"><title>Parsing request data</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn our example module, we would like to add a feature, that checks which
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohtype of digest, MD5 or SHA1 the client would like to see. This could be
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohsolved by adding a query string to the request. A query string is typically
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcomprised of several keys and values put together in a string, for instance
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<code>valueA=yes&amp;valueB=no&amp;valueC=maybe</code>. It is up to the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmodule itself to parse these and get the data it requires. In our example,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwe'll be looking for a key called <code>digest</code>, and if set to <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmd5</code>, we'll produce an MD5 digest, otherwise we'll produce a SHA1
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohdigest.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohSince the introduction of Apache HTTP Server 2.4, parsing request data from GET and
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohPOST requests have never been easier. All we require to parse both GET and
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohPOST data is four simple lines:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__apr__tables.html#gad7ea82d6608a4a633fc3775694ab71e4">apr_table_t</a> *GET;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<a href="http://ci.apache.org/projects/httpd/trunk/doxygen/structapr__array__header__t.html">apr_array_header_t</a> *POST;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__SCRIPT.html#gaed25877b529623a4d8f99f819ba1b7bd">ap_args_to_table</a>(r, &amp;GET);
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__DAEMON.html#ga9d426b6382b49754d4f87c55f65af202">ap_parse_form_data</a>(r, <code style='color:#7f0055; font-weight:bold; '>NULL</code>, &amp;POST, -1, 8192);
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn our specific example module, we're looking for the <code>digest</code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohvalue from the query string, which now resides inside a table called <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohGET</code>. To extract this value, we need only perform a simple operation:
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Get the "digest" key from the query string, if any. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>digestType <code style='color:#806030; '>=</code> <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__apr__tables.html#ga4db13e3915c6b9a3142b175d4c15d915">apr_table_get</a><code style='color:#806030; '>(</code>GET<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>digest</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* If no key was returned, we will set a default value instead. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>digestType<code style='color:#806030; '>)</code> digestType <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>sha1</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThe structures used for the POST and GET data are not exactly the same, so
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohif we were to fetch a value from POST data instead of the query string, we
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwould have to resort to a few more lines, as outlined in <a href="#get_post"
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh>this example</a> in the last chapter of this document.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="advanced_handler"><title>Making an advanced handler</title>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohNow that we have learned how to parse form data and manage our resources,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwe can move on to creating an advanced version of our module, that spits
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohout the MD5 or SHA1 digest of files:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> rc<code style='color:#806030; '>,</code> exists<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_finfo_t finfo<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_file_t<code style='color:#806030; '> *</code>file<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>filename<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> buffer<code style='color:#806030; '>[</code><code style='color:#c00000; '>256</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_size_t readBytes<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> n<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_table_t<code style='color:#806030; '> *</code>GET<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_array_header_t<code style='color:#806030; '> *</code>POST<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>digestType<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Check that the "example-handler" handler is being called. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Figure out which file is being requested by removing the .sum from it */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh filename <code style='color:#806030; '>=</code> apr_pstrdup<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>pool</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>filename</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh filename<code style='color:#806030; '>[</code><code style='color:#800040; '>strlen</code><code style='color:#806030; '>(</code>filename<code style='color:#806030; '>)</code><code style='color:#806030; '>-</code><code style='color:#c00000; '>4</code><code style='color:#806030; '>]</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Cut off the last 4 characters. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Figure out if the file we request a sum on exists and isn't a directory */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh rc <code style='color:#806030; '>=</code> apr_stat<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>finfo<code style='color:#806030; '>,</code> filename<code style='color:#806030; '>,</code> APR_FINFO_MIN<code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>pool</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code>rc <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> APR_SUCCESS<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh exists <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>(</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>(</code>finfo<code style='color:#806030; '>.</code>filetype <code style='color:#806030; '>!</code><code style='color:#806030; '>=</code> APR_NOFILE<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>&amp;</code><code style='color:#806030; '>&amp;</code> <code style='color:#806030; '>!</code><code style='color:#806030; '>(</code>finfo<code style='color:#806030; '>.</code>filetype <code style='color:#806030; '>&amp;</code> APR_DIR<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>exists<code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code> HTTP_NOT_FOUND<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Return a 404 if not found. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* If apr_stat failed, we're probably not allowed to check this file. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> <code style='color:#400000; font-weight:bold; '>return</code> HTTP_FORBIDDEN<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Parse the GET and, optionally, the POST data sent to us */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_args_to_table<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>GET<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_parse_form_data<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>POST<code style='color:#806030; '>,</code> <code style='color:#806030; '>-</code><code style='color:#c00000; '>1</code><code style='color:#806030; '>,</code> <code style='color:#c00000; '>8192</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Set the appropriate content type */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_set_content_type<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/html</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print a title and some general information */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;h2>Information on </code><code style='color:#0f6900; '>%s</code><code style='color:#e60000; '>:&lt;/h2></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> filename<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;b>Size:&lt;/b> </code><code style='color:#0f6900; '>%u</code><code style='color:#e60000; '> bytes&lt;br/></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> finfo<code style='color:#806030; '>.</code>size<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Get the digest type the client wants to see */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh digestType <code style='color:#806030; '>=</code> apr_table_get<code style='color:#806030; '>(</code>GET<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>digest</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>digestType<code style='color:#806030; '>)</code> digestType <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>MD5</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh rc <code style='color:#806030; '>=</code> apr_file_open<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>file<code style='color:#806030; '>,</code> filename<code style='color:#806030; '>,</code> APR_READ<code style='color:#806030; '>,</code> APR_OS_DEFAULT<code style='color:#806030; '>,</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>pool</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code>rc <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> APR_SUCCESS<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Are we trying to calculate the MD5 or the SHA1 digest? */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>digestType<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>md5</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Calculate the MD5 sum of the file */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>union</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> chr<code style='color:#806030; '>[</code><code style='color:#c00000; '>16</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh uint32_t num<code style='color:#806030; '>[</code><code style='color:#c00000; '>4</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code> digest<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_md5_ctx_t md5<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_md5_init<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>md5<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh readBytes <code style='color:#806030; '>=</code> <code style='color:#c00000; '>256</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>while</code> <code style='color:#806030; '>(</code> apr_file_read<code style='color:#806030; '>(</code>file<code style='color:#806030; '>,</code> buffer<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>readBytes<code style='color:#806030; '>)</code> <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> APR_SUCCESS <code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_md5_update<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>md5<code style='color:#806030; '>,</code> buffer<code style='color:#806030; '>,</code> readBytes<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_md5_final<code style='color:#806030; '>(</code>digest<code style='color:#806030; '>.</code>chr<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>md5<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print out the MD5 digest */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;b>MD5: &lt;/b>&lt;code></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>for</code> <code style='color:#806030; '>(</code>n <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code> n <code style='color:#806030; '>&lt;</code> APR_MD5_DIGESTSIZE<code style='color:#806030; '>/</code><code style='color:#c00000; '>4</code><code style='color:#806030; '>;</code> n<code style='color:#806030; '>+</code><code style='color:#806030; '>+</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#0f6900; '>%08x</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> digest<code style='color:#806030; '>.</code>num<code style='color:#806030; '>[</code>n<code style='color:#806030; '>]</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;/code></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print a link to the SHA1 version */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;br/>&lt;a href='?digest=sha1'>View the SHA1 hash instead&lt;/a></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Calculate the SHA1 sum of the file */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>union</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> chr<code style='color:#806030; '>[</code><code style='color:#c00000; '>20</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh uint32_t num<code style='color:#806030; '>[</code><code style='color:#c00000; '>5</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code> digest<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_sha1_ctx_t sha1<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_sha1_init<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>sha1<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh readBytes <code style='color:#806030; '>=</code> <code style='color:#c00000; '>256</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>while</code> <code style='color:#806030; '>(</code> apr_file_read<code style='color:#806030; '>(</code>file<code style='color:#806030; '>,</code> buffer<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>readBytes<code style='color:#806030; '>)</code> <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> APR_SUCCESS <code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_sha1_update<code style='color:#806030; '>(</code><code style='color:#806030; '>&amp;</code>sha1<code style='color:#806030; '>,</code> buffer<code style='color:#806030; '>,</code> readBytes<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_sha1_final<code style='color:#806030; '>(</code>digest<code style='color:#806030; '>.</code>chr<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>sha1<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print out the SHA1 digest */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;b>SHA1: &lt;/b>&lt;code></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>for</code> <code style='color:#806030; '>(</code>n <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code> n <code style='color:#806030; '>&lt;</code> APR_SHA1_DIGESTSIZE<code style='color:#806030; '>/</code><code style='color:#c00000; '>4</code><code style='color:#806030; '>;</code> n<code style='color:#806030; '>+</code><code style='color:#806030; '>+</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#0f6900; '>%08x</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> digest<code style='color:#806030; '>.</code>num<code style='color:#806030; '>[</code>n<code style='color:#806030; '>]</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;/code></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Print a link to the MD5 version */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rputs<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;br/>&lt;a href='?digest=md5'>View the MD5 hash instead&lt;/a></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_file_close<code style='color:#806030; '>(</code>file<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedooh <code style='color:#c34e00; '>/* Let the server know that we responded to this request. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThis version in its entirity can be found here:
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<a href="http://people.apache.org/~humbedooh/mods/examples/mod_example_2.c">mod_example_2.c</a>.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="configuration"><title>Adding configuration options</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn this next segment of this document, we will turn our eyes away from the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohdigest module and create a new example module, whose only function is to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwrite out its own configuration. The purpose of this is to examine how
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthe server works with configuration, and what happens when you start writing
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohadvanced configurations
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohfor your modules.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<section id="config_intro"><title>An introduction to configuration
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedoohdirectives</title>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedoohIf you are reading this, then you probably already know
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwhat a configuration directive is. Simply put, a directive is a way of
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohtelling an individual module (or a set of modules) how to behave, such as
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthese directives control how <code>mod_rewrite</code> works:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohRewriteEngine On
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohRewriteCond %{REQUEST_URI} ^/foo/bar
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohRewriteRule ^/foo/bar/(.*)$ /foobar?page=$1
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohEach of these configuration directives are handled by a separate function,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthat parses the parameters given and sets up a configuration accordingly.
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="config_simple"><title>Making an example configuration</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohTo begin with, we'll create a basic configuration in C-space:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>typedef</code> <code style='color:#400000; font-weight:bold; '>struct</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> enabled<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Enable or disable our module */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>path<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Some path to...something */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> typeOfAction<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* 1 means action A, 2 means action B and so on */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code> example_config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohNow, let's put this into perspective by creating a very small module that
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohjust prints out a hard-coded configuration. You'll notice that we use the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<code>register_hooks</code> function for initializing the configuration
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohvalues to their defaults:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>typedef</code> <code style='color:#400000; font-weight:bold; '>struct</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> enabled<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Enable or disable our module */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>path<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Some path to...something */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> typeOfAction<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* 1 means action A, 2 means action B and so on */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code> example_config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> example_config config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_set_content_type<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/plain</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(r, </code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Enabled: </code><code style='color:#0f6900; '>%u</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>enabled<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(r, </code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Path: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>path<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(r, </code><code style='color:#800000; '>"</code><code style='color:#e60000; '>TypeOfAction: </code><code style='color:#0f6900; '>%x</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>typeOfAction<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>path <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>/foo/bar</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x00</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_hook_handler<code style='color:#806030; '>(</code>example_handler<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> APR_HOOK_LAST<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Define our module as an entity and assign a function for registering hooks */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF<code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohSo far so good. To access our new handler, we could add the following to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour configuration:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Location /example&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh SetHandler example-handler
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Location&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohWhen we visit, we'll see our current configuration being spit out by our
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmodule.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<section id="register_directive"><title>Registering directives with the server</title>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohWhat if we want to change our configuration, not by hard-coding new values
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohinto the module, but by using either the httpd.conf file or possibly a
5408def46d326118d1a65a93a86b646008ed01e1humbedooh.htaccess file? It's time to let the server know that we want this to be
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohpossible. To do so, we must first change our <em>name tag</em> to include a
5408def46d326118d1a65a93a86b646008ed01e1humbedoohreference to the configuration directives we want to register with the server:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module =
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh{
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF,
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>, <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>, <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>, <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#7f0055; font-weight:bold; '>NULL</code>, <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_directives, <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh};
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedoohThis will tell the server that we are now accepting directives from the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguration files, and that the structure called <code>example_directives
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh</code> holds information on what our directives are and how they work.
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohSince we have three different variables in our module configuration, we
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwill add a structure with three directives and a NULL at the end:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohstatic const command_rec example_directives[] =
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh{
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a></code>("exampleEnabled", example_set_enabled, <code style='color:#7f0055; font-weight:bold; '>NULL</code>, RSRC_CONF, "Enable or disable mod_example"),
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a></code>("examplePath", example_set_path, <code style='color:#7f0055; font-weight:bold; '>NULL</code>, RSRC_CONF, "The path to whatever"),
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#gafaec43534fcf200f37d9fecbf9247c21">AP_INIT_TAKE2</a></code>("exampleAction", example_set_action, <code style='color:#7f0055; font-weight:bold; '>NULL</code>, RSRC_CONF, "Special action value!"),
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh { <code style='color:#7f0055; font-weight:bold; '>NULL</code> }
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh};
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<img src="/images/build_a_mod_4.png" border="1" alt="Directives structure"/><br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohAs you can see, each directive needs at least 5 parameters set:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ol>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<li><code><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a></code>: This is a macro that tells the server that this directive takes one and only one argument.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohIf we required two arguments, we could use the macro <code><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#gafaec43534fcf200f37d9fecbf9247c21">AP_INIT_TAKE2</a></code> and so on (refer to httpd_conf.h
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohfor more macros).</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>exampleEnabled</code>: This is the name of our directive. More precisely, it is what the user must put in his/her
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohconfiguration in order to invoke a configuration change in our module.</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>example_set_enabled</code>: This is a reference to a C function that parses the directive and sets the configuration
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohaccordingly. We will discuss how to make this in the following paragraph.</li>
05664b3e454b2686379515dc6775bfbc51d3dc6ahumbedooh<li><code>RSRC_CONF</code>: This tells the server where the directive is permitted. We'll go into details on this value in the
5408def46d326118d1a65a93a86b646008ed01e1humbedoohlater chapters, but for now, <code>RSRC_CONF</code> means that the server will only accept these directives in a server context.</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><code>"Enable or disable...."</code>: This is simply a brief description of what the directive does.</li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ol>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh(<em>The "missing" parameter in our definition, which is usually set to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<code>NULL</code>, is an optional function that can be run after the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohinitial function to parse the arguments have been run. This is usually
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohomitted, as the function for verifying arguments might as well be used to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohset them.</em>)
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="directive_handler"><title>The directive handler function</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohNow that we've told the server to expect some directives for our module, it's
5408def46d326118d1a65a93a86b646008ed01e1humbedoohtime to make a few functions for handling these. What the server reads in the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguration file(s) is text, and so naturally, what it passes along to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour directive handler is one or more strings, that we ourselves need to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohrecognize and act upon. You'll notice, that since we set our <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohexampleAction</code> directive to accept two arguments, its C function also
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhas an additional parameter defined:<br/>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "exambleEnabled" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_enabled<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>on</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "examplePath" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_path<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>path <code style='color:#806030; '>=</code> arg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "exampleAction" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* and we store it in a bit-wise manner. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_action<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg1<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '>*</code> arg2<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg1<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>file</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x01</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x02</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg2<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>deny</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x10</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x20</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="directive_complete"><title>Putting it all together</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohNow that we have our directives set up, and handlers configured for them,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwe can assemble our module into one big file:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* mod_example_config_simple.c: */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>&lt;</code><code style='color:#40015a; '>stdio.h</code><code style='color:#800000; '>></code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>apr_hash.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>ap_config.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>ap_provider.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>httpd.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_core.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_config.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_log.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_protocol.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_request.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;Our configuration prototype and declaration:</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>typedef</code> <code style='color:#400000; font-weight:bold; '>struct</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> enabled<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Enable or disable our module */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>path<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* Some path to...something */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> typeOfAction<code style='color:#806030; '>;</code> <code style='color:#c34e00; '>/* 1 means action A, 2 means action B and so on */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code> example_config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> example_config config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;Our directive handlers:</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "exambleEnabled" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_enabled<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>on</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "examplePath" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_path<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>path <code style='color:#806030; '>=</code> arg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Handler for the "exampleAction" directive */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/* and we store it in a bit-wise manner. */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '> *</code>example_set_action<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg1<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '>*</code> arg2<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg1<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>file</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x01</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x02</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg2<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>deny</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x10</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x20</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;The directive structure for our name tag:</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>const</code> command_rec example_directives<code style='color:#806030; '>[</code><code style='color:#806030; '>]</code> <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>exampleEnabled</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_enabled<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> RSRC_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Enable or disable mod_example</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>examplePath</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_path<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> RSRC_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>The path to whatever</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#gafaec43534fcf200f37d9fecbf9247c21">AP_INIT_TAKE2</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>exampleAction</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_action<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> RSRC_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Special action value!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code> <code style='color:#007d45; '>NULL</code> <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;Our module handler:</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_set_content_type<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/plain</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Enabled: </code><code style='color:#0f6900; '>%u</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>enabled<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Path: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>path<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>TypeOfAction: </code><code style='color:#0f6900; '>%x</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>.</code>typeOfAction<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;The hook registration function (also initializes the default config values):</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>enabled <code style='color:#806030; '>=</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>path <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>/foo/bar</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh config<code style='color:#806030; '>.</code>typeOfAction <code style='color:#806030; '>=</code> <code style='color:#c00000; '>3</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_hook_handler<code style='color:#806030; '>(</code>example_handler<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> APR_HOOK_LAST<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;Our module name tag:</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;==============================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF<code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_directives<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn our httpd.conf file, we can now change the hard-coded configuration by
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohadding a few lines:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohExampleEnabled On
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohExamplePath "/usr/bin/foo"
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohExampleAction file allow
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohAnd thus we apply the configuration, visit <code>/example</code> on our
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohweb site, and we see the configuration has adapted to what we wrote in our
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguration file.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="context"><title>Context aware configurations</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="context_intro"><title>Introduction to context aware configurations</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohIn Apache HTTP Server 2.4, different URLs, virtual hosts, directories etc can have very
5408def46d326118d1a65a93a86b646008ed01e1humbedoohdifferent meanings to the user of the server, and thus different contexts
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwithin which modules must operate. For example, let's assume you have this
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguration set up for mod_rewrite:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Directory &quot;/var/www&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh RewriteCond %{HTTP_HOST} ^example.com$
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh RewriteRule (.*) http://www.example.com/$1
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Directory&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Directory &quot;/var/www/sub&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh RewriteRule ^foobar$ index.php?foobar=true
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Directory&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn this example, you will have set up two different contexts for
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmod_rewrite:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ol>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Inside <code>/var/www</code>, all requests for <code>http://example.com</code> must go to <code>http://www.example.com</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Inside <code>/var/www/sub</code>, all requests for <code>foobar</code> must go to <code>index.php?foobar=true</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ol>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohIf mod_rewrite (or the entire server for that matter) wasn't context aware, then
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthese rewrite rules would just apply to every and any request made,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohregardless of where and how they were made, but since the module can pull
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthe context specific configuration straight from the server, it does not need
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohto know itself, which of the directives are valid in this context, since
5408def46d326118d1a65a93a86b646008ed01e1humbedoohthe server takes care of this.</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohSo how does a module get the specific configuration for the server,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohdirectory or location in question? It does so by making one simple call:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohexample_config *config = (example_config*) <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga1093a5908a384eacc929b028c79f2a02">ap_get_module_config</a>(<code style='color:#008833'>r-&gt;per_dir_config</code>, &amp;example_module);
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThat's it! Of course, a whole lot goes on behind the scenes, which we will
5408def46d326118d1a65a93a86b646008ed01e1humbedoohdiscuss in this chapter, starting with how the server came to know what our
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguration looks like, and how it came to be set up as it is in the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohspecific context.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="context_base"><title>Our basic configuration setup</title>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh<p>In this chapter, we will be working with a slightly modified version of
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour previous context structure. We will set a <code>context</code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohvariable that we can use to track which context configuration is being
5408def46d326118d1a65a93a86b646008ed01e1humbedoohused by the server in various places:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>typedef</code> <code style='color:#400000; font-weight:bold; '>struct</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> context<code style='color:#806030; '>[</code><code style='color:#c00000; '>256</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> path<code style='color:#806030; '>[</code><code style='color:#c00000; '>256</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> typeOfAction<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> enabled<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code> example_config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>Our handler for requests will also be modified, yet still very simple:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config<code style='color:#806030; '> *</code>config <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config<code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> ap_get_module_config<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>per_dir_config</code><code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>example_module<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_set_content_type<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/plain</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Enabled: </code><code style='color:#0f6900; '>%u</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Path: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>TypeOfAction: </code><code style='color:#0f6900; '>%x</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>Context: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>context</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="context_which"><title>Choosing a context</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohBefore we can start making our module context aware, we must first define,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwhich contexts we will accept. As we saw in the previous chapter, defining
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooha directive required five elements be set:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#2e8800; '><a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a></code>(&quot;exampleEnabled&quot;, example_set_enabled, <code style='color:#7f0055; font-weight:bold; '>NULL</code>, RSRC_CONF, &quot;Enable or disable mod_example&quot;),
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedoohThe <code>RSRC_CONF</code> definition told the server that we would only allow
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthis directive in a global server context, but since we are now trying out
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooha context aware version of our module, we should set this to something
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohmore lenient, namely the value <code>ACCESS_CONF</code>, which lets us use
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohthe directive inside &lt;Directory&gt; and &lt;Location&gt; blocks.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<section id="context_pool"><title>Using the server to allocate configuration slots</title>
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<p> A much smarter way to manage your configurations is by letting the server
d5f549d9022aee3727a1278486dc80124198ac26humbedoohhelp you create them. To do so, we must first start off by changing our
5408def46d326118d1a65a93a86b646008ed01e1humbedooh<em>name tag</em> to let the server know, that it should assist us in creating
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohand managing our configurations. Since we have chosen the per-directory
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh(or per-location) context for our module configurations, we'll add a
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohper-directory creator and merger function reference in our tag:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF<code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh create_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh merge_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh directives<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<section id="context_new"><title>Creating new context configurations</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohNow that we have told the server to help us create and manage configurations,
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour first step is to make a function for creating new, blank
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfigurations. We do so by creating the function we just referenced in
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohour name tag as the Per-directory configuration handler:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code><code style='color:#806030; '>*</code> example_create_dir_conf<code style='color:#806030; '>(</code>apr_pool_t<code style='color:#806030; '>*</code> pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>char</code><code style='color:#806030; '>*</code> context<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh context <code style='color:#806030; '>=</code> context <code style='color:#806030; '>?</code> context <code style='color:#806030; '>:</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>(undefined context)</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config<code style='color:#806030; '> *</code>cfg <code style='color:#806030; '>=</code> apr_pcalloc<code style='color:#806030; '>(</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>sizeof</code><code style='color:#806030; '>(</code>example_config<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>cfg<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Set some default values */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>strcpy</code><code style='color:#806030; '>(</code>cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>context</code><code style='color:#806030; '>,</code> x<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code> <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>/foo/bar</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x11</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c10b2604e59ba7d8fe42fb5eefbdc0ba4180c929humbedooh <code style='color:#400000; font-weight:bold; '>return</code> cfg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<section id="context_merge"><title>Merging configurations</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohOur next step in creating a context aware configuration is merging
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfigurations. This part of the process particularly apply to scenarios
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohwhere you have a parent configuration and a child, such as the following:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Directory &quot;/var/www&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleEnable On
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExamplePath /foo/bar
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleAction file allow
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Directory&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Directory &quot;/var/www/subdir&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleAction file deny
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Directory&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIn this example, it is natural to assume that the directory <code>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh/var/www/subdir</code> should inherit the value set for the <code>/var/www
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedooh</code> directory, as we did not specify a <code>ExampleEnable</code> nor
5408def46d326118d1a65a93a86b646008ed01e1humbedoohan <code>ExamplePath</code> for this directory. The server does not presume to
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohknow if this is true, but cleverly does the following:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<ol>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Creates a new configuration for <code>/var/www</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Sets the configuration values according to the directives given for <code>/var/www</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Creates a new configuration for <code>/var/www/subdir</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li>Sets the configuration values according to the directives given for <code>/var/www/subdir</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<li><strong>Proposes a merge</strong> of the two configurations into a new configuration for <code>/var/www/subdir</code></li>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</ol>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThis proposal is handled by the <code>merge_dir_conf</code> function we
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohreferenced in our name tag. The purpose of this function is to assess the
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohtwo configurations and decide how they are to be merged:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code><code style='color:#806030; '>*</code> merge_dir_conf<code style='color:#806030; '>(</code>apr_pool_t<code style='color:#806030; '>*</code> pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code><code style='color:#806030; '>*</code> BASE<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code><code style='color:#806030; '>*</code> ADD<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config<code style='color:#806030; '>*</code> base <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> BASE <code style='color:#806030; '>;</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config<code style='color:#806030; '>*</code> add <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> ADD <code style='color:#806030; '>;</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config<code style='color:#806030; '>*</code> conf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> create_dir_conf<code style='color:#806030; '>(</code>pool<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Merged configuration</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code> <code style='color:#806030; '>)</code> <code style='color:#806030; '>?</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>:</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>?</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>:</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>strcpy</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>,</code> <code style='color:#800040; '>strlen</code><code style='color:#806030; '>(</code>add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>?</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code> <code style='color:#806030; '>:</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> conf <code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<section id="context_example"><title>Trying out our new context aware configurations</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
d5f549d9022aee3727a1278486dc80124198ac26humbedoohNow, let's try putting it all together to create a new module that is
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohcontext aware. First off, we'll create a configuration that lets us test
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhow the module works:
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<example><pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Location &quot;/a&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh SetHandler example-handler
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleEnabled on
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExamplePath &quot;/foo/bar&quot;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleAction file allow
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Location&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Location &quot;/a/b&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleAction file deny
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleEnabled off
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Location&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;Location &quot;/a/b/c&quot;&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleAction db deny
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExamplePath &quot;/foo/bar/baz&quot;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ExampleEnabled on
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh&lt;/Location&gt;
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre></example>
f0e7dbf8fc52d4a9fdf8e1cd5dd2d2da16bd55dbhumbedooh<p>
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohThen we'll assemble our module code. Note, that since we are now using our
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohname tag as reference when fetching configurations in our handler, I have
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohadded some prototypes to keep the compiler happy:
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*$6</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;* mod_example_config.c</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>&lt;</code><code style='color:#40015a; '>stdio.h</code><code style='color:#800000; '>></code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>apr_hash.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>ap_config.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>ap_provider.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>httpd.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_core.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_config.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_log.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_protocol.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#004a43; '>#</code><code style='color:#004a43; '>include </code><code style='color:#800000; '>"</code><code style='color:#40015a; '>http_request.h</code><code style='color:#800000; '>"</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*$1</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Configuration structure</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>typedef</code> <code style='color:#400000; font-weight:bold; '>struct</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> context<code style='color:#806030; '>[</code><code style='color:#c00000; '>256</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> path<code style='color:#806030; '>[</code><code style='color:#c00000; '>256</code><code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> typeOfAction<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> enabled<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code> example_config<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*$1</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Prototypes</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_enabled<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_path<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_action<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg1<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg2<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>create_dir_conf<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>context<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>merge_dir_conf<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>BASE<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>ADD<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*$1</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Configuration directives</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>const</code> command_rec directives<code style='color:#806030; '>[</code><code style='color:#806030; '>]</code> <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>exampleEnabled</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_enabled<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> ACCESS_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Enable or disable mod_example</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#ga07c7d22ae17805e61204463326cf9c34">AP_INIT_TAKE1</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>examplePath</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_path<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> ACCESS_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>The path to whatever</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <a href="http://ci.apache.org/projects/httpd/trunk/doxygen/group__APACHE__CORE__CONFIG.html#gafaec43534fcf200f37d9fecbf9247c21">AP_INIT_TAKE2</a><code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>exampleAction</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> example_set_action<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> ACCESS_CONF<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Special action value!</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code> <code style='color:#007d45; '>NULL</code> <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*$1</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Our name tag</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohmodule AP_MODULE_DECLARE_DATA example_module <code style='color:#806030; '>=</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh STANDARD20_MODULE_STUFF<code style='color:#806030; '>,</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh create_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-directory configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh merge_dir_conf<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-directory configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Per-server configuration handler */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Merge handler for per-server configurations */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh directives<code style='color:#806030; '>,</code> <code style='color:#c34e00; '>/* Any directives we may have for httpd */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh register_hooks <code style='color:#c34e00; '>/* Our hook registering function */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Hook registration function</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>void</code> register_hooks<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_hook_handler<code style='color:#806030; '>(</code>example_handler<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> APR_HOOK_LAST<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Our example web service handler</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code> <code style='color:#806030; '>|</code><code style='color:#806030; '>|</code> <code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>handler</code><code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>example-handler</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>DECLINED<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config <code style='color:#806030; '>*</code>config <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> ap_get_module_config<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>per_dir_config</code><code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>example_module<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_set_content_type<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>text/plain</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Enabled: </code><code style='color:#0f6900; '>%u</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Path: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>TypeOfAction: </code><code style='color:#0f6900; '>%x</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Context: </code><code style='color:#0f6900; '>%s</code><code style='color:#0f6900; '>\n</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> config<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>context</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Handler for the "exambleEnabled" directive</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_enabled<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config <code style='color:#806030; '>*</code>conf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> cfg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>on</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Handler for the "examplePath" directive</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_path<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config <code style='color:#806030; '>*</code>conf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> cfg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>strcpy</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>,</code> arg<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Handler for the "exampleAction" directive ;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Let's pretend this one takes one argument (file or db), and a second (deny or allow), ;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;and we store it in a bit-wise manner.</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>example_set_action<code style='color:#806030; '>(</code>cmd_parms <code style='color:#806030; '>*</code>cmd<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>cfg<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg1<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>arg2<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config <code style='color:#806030; '>*</code>conf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> cfg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg1<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>file</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x01</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x02</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>strcasecmp<code style='color:#806030; '>(</code>arg2<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>deny</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x10</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x20</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Function for creating new configurations for per-directory contexts</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>create_dir_conf<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>context<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh context <code style='color:#806030; '>=</code> context <code style='color:#806030; '>?</code> context <code style='color:#806030; '>:</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Newly created configuration</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh example_config <code style='color:#806030; '>*</code>cfg <code style='color:#806030; '>=</code> apr_pcalloc<code style='color:#806030; '>(</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>sizeof</code><code style='color:#806030; '>(</code>example_config<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>cfg<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/* Set some default values */</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>strcpy</code><code style='color:#806030; '>(</code>cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>context</code><code style='color:#806030; '>,</code> context<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>memset</code><code style='color:#806030; '>(</code>cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>,</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>,</code> <code style='color:#c00000; '>256</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh cfg<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0x00</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> cfg<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>/*</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;&#xa0;&#xa0;&#xa0;Merging function for configurations</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;=======================================================================================================================</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#c34e00; '>&#xa0;*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>merge_dir_conf<code style='color:#806030; '>(</code>apr_pool_t <code style='color:#806030; '>*</code>pool<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>BASE<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>void</code> <code style='color:#806030; '>*</code>ADD<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config <code style='color:#806030; '>*</code>base <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> BASE<code style='color:#806030; '>;</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config <code style='color:#806030; '>*</code>add <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> ADD<code style='color:#806030; '>;</code>
9f82a7343f0a2f0721e0e0e1e881b06739003506humbedooh example_config <code style='color:#806030; '>*</code>conf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>example_config <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> create_dir_conf<code style='color:#806030; '>(</code>pool<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>Merged configuration</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>?</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code> <code style='color:#806030; '>:</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>enabled</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>=</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>?</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code> <code style='color:#806030; '>:</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>typeOfAction</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>strcpy</code><code style='color:#806030; '>(</code>conf<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>,</code> <code style='color:#800040; '>strlen</code><code style='color:#806030; '>(</code>add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>?</code> add<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code> <code style='color:#806030; '>:</code> base<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>path</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> conf<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="summary"><title>Summing up</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<p>
5408def46d326118d1a65a93a86b646008ed01e1humbedoohWe have now looked at how to create simple modules for Apache HTTP Server 2.4 and
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohconfiguring them. What you do next is entirely up to you, but it is my
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohhope that something valuable has come out of reading this documentation.
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohIf you have questions on how to further develop modules, you are welcome
9a76f548bf4b14aaf2e6cbf886851a630e3e2fefhumbedoohto join our <a href="http://httpd.apache.org/lists.html">mailing lists</a>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedoohor check out the rest of our documentation for further tips.
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</p>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="snippets"><title>Some useful snippets of code</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<section id="get_post"><title>Retrieve a variable from POST form data</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
7c46931efadad26fbfbf0698d8091f34852086aahumbedooh<code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>read_post_value<code style='color:#806030; '>(</code><code style='color:#400000; font-weight:bold; '>const</code> apr_array_header_t <code style='color:#806030; '>*</code>fields<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>key<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
7c46931efadad26fbfbf0698d8091f34852086aahumbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> i<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_table_entry_t <code style='color:#806030; '>*</code>e <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
7c46931efadad26fbfbf0698d8091f34852086aahumbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh e <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>apr_table_entry_t <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> fields<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>elts<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>for</code><code style='color:#806030; '>(</code>i <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code> i <code style='color:#806030; '>&lt;</code> fields<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>nelts<code style='color:#806030; '>;</code> i<code style='color:#806030; '>+</code><code style='color:#806030; '>+</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>!</code><code style='color:#800040; '>strcmp</code><code style='color:#806030; '>(</code>e<code style='color:#806030; '>[</code>i<code style='color:#806030; '>]</code><code style='color:#806030; '>.</code>key<code style='color:#806030; '>,</code> key<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#400000; font-weight:bold; '>return</code> e<code style='color:#806030; '>[</code>i<code style='color:#806030; '>]</code><code style='color:#806030; '>.</code>val<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_req <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_array_header_t <code style='color:#806030; '>*</code>POST<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>value<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_parse_form_data<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#007d45; '>NULL</code><code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>POST<code style='color:#806030; '>,</code> <code style='color:#806030; '>-</code><code style='color:#c00000; '>1</code><code style='color:#806030; '>,</code> <code style='color:#c00000; '>8192</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh value <code style='color:#806030; '>=</code> read_post_value<code style='color:#806030; '>(</code>POST<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>valueA</code><code style='color:#800000; '>"</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code> <code style='color:#806030; '>(</code><code style='color:#806030; '>!</code>value<code style='color:#806030; '>)</code> value <code style='color:#806030; '>=</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>(undefined)</code><code style='color:#800000; '>"</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>The value of valueA is: </code><code style='color:#0f6900; '>%s</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> value<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <section id="headers_out"><title>Printing out every HTTP header received</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_req <code style='color:#806030; '>*</code>r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> apr_array_header_t <code style='color:#806030; '>*</code>fields<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> i<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_table_entry_t <code style='color:#806030; '>*</code>e <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh fields <code style='color:#806030; '>=</code> <a href="http://apr.apache.org/docs/apr/1.4/group__apr__tables.html#gaea3005541cce67481f48ab201b5c0cf3">apr_table_elts</a><code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>headers_in<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh e <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code>apr_table_entry_t <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> fields<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>elts<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>for</code><code style='color:#806030; '>(</code>i <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code> i <code style='color:#806030; '>&lt;</code> fields<code style='color:#806030; '>-</code><code style='color:#806030; '>></code>nelts<code style='color:#806030; '>;</code> i<code style='color:#806030; '>+</code><code style='color:#806030; '>+</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#800000; '>"</code><code style='color:#e60000; '>&lt;b></code><code style='color:#0f6900; '>%s</code><code style='color:#e60000; '>&lt;/b>: </code><code style='color:#0f6900; '>%s</code><code style='color:#e60000; '>&lt;br/></code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> e<code style='color:#806030; '>[</code>i<code style='color:#806030; '>]</code><code style='color:#806030; '>.</code>key<code style='color:#806030; '>,</code> e<code style='color:#806030; '>[</code>i<code style='color:#806030; '>]</code><code style='color:#806030; '>.</code>val<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <section id="request_body"><title>Reading the request body into memory</title>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- BEGIN EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<pre style='color:#000000;background:#ffffef;border: 1px dashed #333; padding: 0.5em; margin: 1em 2em 1em 1em;'>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> util_read<code style='color:#806030; '>(</code>request_rec <code style='color:#806030; '>*</code>r<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code><code style='color:#806030; '>*</code>rbuf<code style='color:#806030; '>,</code> apr_off_t <code style='color:#806030; '>*</code>size<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>int</code> rc <code style='color:#806030; '>=</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>(</code>rc <code style='color:#806030; '>=</code> ap_setup_client_block<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> REQUEST_CHUNKED_ERROR<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>rc<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>ap_should_client_block<code style='color:#806030; '>(</code>r<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>char</code> argsbuffer<code style='color:#806030; '>[</code>HUGE_STRING_LEN<code style='color:#806030; '>]</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_off_t rsize<code style='color:#806030; '>,</code> len_read<code style='color:#806030; '>,</code> rpos <code style='color:#806030; '>=</code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_off_t length <code style='color:#806030; '>=</code> r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>remaining</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>*</code>rbuf <code style='color:#806030; '>=</code> <code style='color:#806030; '>(</code><code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> apr_pcalloc<code style='color:#806030; '>(</code>r<code style='color:#806030; '>-</code><code style='color:#806030; '>></code><code style='color:#008833'>pool</code><code style='color:#806030; '>,</code> <code style='color:#806030; '>(</code>apr_size_t<code style='color:#806030; '>)</code> <code style='color:#806030; '>(</code>length <code style='color:#806030; '>+</code> <code style='color:#c00000; '>1</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>*</code>size <code style='color:#806030; '>=</code> length<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>while</code><code style='color:#806030; '>(</code><code style='color:#806030; '>(</code>len_read <code style='color:#806030; '>=</code> ap_get_client_block<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> argsbuffer<code style='color:#806030; '>,</code> <code style='color:#400000; font-weight:bold; '>sizeof</code><code style='color:#806030; '>(</code>argsbuffer<code style='color:#806030; '>)</code><code style='color:#806030; '>)</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>></code> <code style='color:#c00000; '>0</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code><code style='color:#806030; '>(</code>rpos <code style='color:#806030; '>+</code> len_read<code style='color:#806030; '>)</code> <code style='color:#806030; '>></code> length<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh rsize <code style='color:#806030; '>=</code> length <code style='color:#806030; '>-</code> rpos<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>else</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh rsize <code style='color:#806030; '>=</code> len_read<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#800040; '>memcpy</code><code style='color:#806030; '>(</code><code style='color:#806030; '>(</code><code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code><code style='color:#806030; '>)</code> <code style='color:#806030; '>*</code>rbuf <code style='color:#806030; '>+</code> rpos<code style='color:#806030; '>,</code> argsbuffer<code style='color:#806030; '>,</code> <code style='color:#806030; '>(</code><code style='color:#800040; '>size_t</code><code style='color:#806030; '>)</code> rsize<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh rpos <code style='color:#806030; '>+</code><code style='color:#806030; '>=</code> rsize<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code><code style='color:#806030; '>(</code>rc<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#400000; font-weight:bold; '>static</code> <code style='color:#400000; font-weight:bold; '>int</code> example_handler<code style='color:#806030; '>(</code>request_req<code style='color:#806030; '>*</code> r<code style='color:#806030; '>)</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh apr_off_t size<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>const</code> <code style='color:#400000; font-weight:bold; '>char</code> <code style='color:#806030; '>*</code>buffer<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#c34e00; '>/*~~~~~~~~~~~~~~~~*/</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>if</code><code style='color:#806030; '>(</code>util_read<code style='color:#806030; '>(</code>r<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>data<code style='color:#806030; '>,</code> <code style='color:#806030; '>&amp;</code>size<code style='color:#806030; '>)</code> <code style='color:#806030; '>=</code><code style='color:#806030; '>=</code> OK<code style='color:#806030; '>)</code> <code style='color:#806030; '>{</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh ap_rprintf<code style='color:#806030; '>(</code><code style='color:#800000; '>"</code><code style='color:#e60000; '>We read a request body that was </code><code style='color:#0f6900; '>%u</code><code style='color:#e60000; '> bytes long</code><code style='color:#800000; '>"</code><code style='color:#806030; '>,</code> size<code style='color:#806030; '>)</code><code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh <code style='color:#400000; font-weight:bold; '>return</code> OK<code style='color:#806030; '>;</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<code style='color:#806030; '>}</code>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </pre>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh<!-- END EXAMPLE CODE -->
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh </section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</section>
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh
c955b5a85313893f7bf55aaa5aacbd946cb41570humbedooh</manualpage>