-- Function for querying the database for saved vhost entries
function query_vhosts(host)
if not cached_vhosts[host] or (cached_vhosts[host] and cached_vhosts[host].updated < os.time() - timeout) then
- local db = apache2.dbopen("mod_dbd")
+ local db = apache2.dbopen(r,"mod_dbd")
local _host = db:escape(_host)
local res, err = db:query( ("SELECT `destination` FROM `vhosts` WHERE `hostname` = '%s' LIMIT 1"):format(_host) )
if res and #res == 1 then
-- Function for querying the database for the account's password (stored as a salted SHA-1 hash)
function fetch_password(user)
if not accounts[user] or (accounts[user] and accounts[user].updated < os.time() - timeout) then
- local db = apache2.dbopen("mod_dbd")
+ local db = apache2.dbopen(r, "mod_dbd")
local usr = db:escape(user)
local res, err = db:query( ("SELECT `password` FROM `accounts` WHERE `user` = '%s' LIMIT 1"):format(usr) )
if res and #res == 1 then
</section>
-<section id="map_handler"><title>Example 4: Authorization using LuaAuthzProvider</title>
+<section id="authz"><title>Example 4: Authorization using LuaAuthzProvider</title>
<highlight language="config">
LuaAuthzProvider rights /path/to/lua/script.lua rights_handler
+
+
+
<section id="String_manipulation">
<title>HTTPd bindings: String manipulation</title>
+<p>
<a href="#apache2.base64_encode">apache2.base64_encode</a>
<br/>
<a href="#apache2.base64_decode">apache2.base64_decode</a>
<br/>
<a href="#apache2.escape_logitem">apache2.escape_logitem</a>
<br/>
+</p>
<section id="apache2.base64_decode">
<title>apache2.base64_decode(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The string to decode</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local str = "This is a test"
local encoded = apache2.base64_encode(str)
local decoded = apache2.base64_decode(encoded)
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.base64_encode">
<title>apache2.base64_encode(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The string to encode</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local str = "This is a test"
local encoded = apache2.base64_encode(str)
local decoded = apache2.base64_decode(encoded)
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.escape">
<title>apache2.escape(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The string to escape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local str = "This is a test"
local escaped = apache2.escape(str)
print(escaped) -- prints "This+is+a+test"
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.escape_logitem">
<title>apache2.escape_logitem(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The string to escape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The converted string
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.escapehtml">
<title>apache2.escapehtml(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>Whether to escape all non-ASCI characters as &#nnn;</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local html = "<b>Testing!</b>"
local escaped = apache2.escapehtml(html)
r:puts(escaped) -- prints "&lt;b&gt;Testing!&lt;/b&gt;"
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.md5">
<title>apache2.md5(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The (binary) string to digest</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local text = "The quick brown fox jumps over the lazy dog"
local md5 = apache2.md51(text)
r:puts(md5) -- prints out "9e107d9d372bb6826bd81d3542a419d6"
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.os_escape_path">
<title>apache2.os_escape_path(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>partial if set, assume that the path will be appended to something with a '/' in it (and thus does not prefix "./")</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local path = ap_os_escape_path("C:/foo/bar.txt")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.sha1">
<title>apache2.sha1(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The (binary) string to digest</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local text = "The quick brown fox jumps over the lazy dog"
local sha1 = apache2.sha1(text)
r:puts(sha1) -- prints out "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.unescape">
<title>apache2.unescape(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The string to unescape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local str = "This+is+a+test"
local unescaped = apache2.unescape(str)
print(unescaped) -- prints "This is a test"
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
</section>
<section id="Request_handling">
<title>HTTPd bindings: Request handling</title>
+<p>
<a href="#apache2.sendfile">apache2.sendfile</a>
<br/>
<a href="#apache2.port">apache2.port</a>
<br/>
<a href="#apache2.satisfies">apache2.satisfies</a>
<br/>
+</p>
<section id="apache2.add_input_filter">
<title>apache2.add_input_filter(
request_rec<em> r</em>, string<em> filter</em>
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The name of the filter handler to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.add_input_filter(r, "SPAM_FILTER") -- Check input for spam..?
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.add_output_filter">
<title>apache2.add_output_filter(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The name of the filter handler to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.add_input_filter(r, "INCLUDES") -- Turn out output into an SSI-enabled document.
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.allowoverrides">
<title>apache2.allowoverrides(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local ctx = apache2.allowoverrides(r)
if ctx:match("AuthCfg") then
r:puts("You are allowed to override AuthCfg stuff in your .htaccess")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.auth_name">
<title>apache2.auth_name(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The current authorization realm
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.auth_type">
<title>apache2.auth_type(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The current Authorization type used in the request
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.context_document_root">
<title>apache2.context_document_root(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.context_prefix">
<title>apache2.context_prefix(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.flush">
<title>apache2.flush(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
r:puts("This is buffered")
apache2.flush(r) -- now it's written to the client.
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.get_basic_auth_pw">
<title>apache2.get_basic_auth_pw(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The password from a basic authorization request or nil if none was supplied
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.get_limit_req_body">
<title>apache2.get_limit_req_body(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local limit = apache2.get_limit_req_body(r)
r:puts("You can't upload files bigger than ", limit, " bytes!")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.get_server_name">
<title>apache2.get_server_name(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local name = apache2.get_server_name(r)
r:puts("The ServerName is set to: ", name)
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.getenv">
<title>apache2.getenv(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>key</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local env = apache2.getenv("HTTP_HOST")
if env and env:len() > 0 then
r:puts("HTTP_HOST equals ", env)
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.make_etag">
<title>apache2.make_etag(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>force_weak Force the entity tag to be weak - it could be modified again in as short an interval.</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The entity tag
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.options">
<title>apache2.options(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local ctx = apache2.options(r)
if ctx:match("MultiViews") then
r:puts("MultiViews is enabled!")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.port">
<title>apache2.port(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local port = apache2.port(r)
r:puts("We are listening on port ", port)
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.request_has_body">
<title>apache2.request_has_body(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if apache2.request_has_body(r) then
-- do stuff with the req body
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.requestbody">
<title>apache2.requestbody(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>filename</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if tonumber(r.headers_in['Content-Length'] or 0) < 10000 then
local smallfile = apache2.requestbody(r) -- fetch a small file into memory
r:puts("I saved the uploaded file in a temp directory. Total bytes written was: ", read)
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.satisfies">
<title>apache2.satisfies(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local how = apache2.satisfies(r)
if how == "SATISFY_ANY" then
-- ...
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.send_interim_response">
<title>apache2.send_interim_response(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>send_headers Whether to send&clear headers in r->headers_out</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.send_interim_response(r, false)
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.sendfile">
<title>apache2.sendfile(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The file to send</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.sendfile(r, "/foo/bar/test.png") -- sends /foo/bar/test.png via sendfile
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.set_context_prefix">
<title>apache2.set_context_prefix(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The corresponding directory on disk, without trailing slash</td>
</tr>
</table>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.set_document_root">
<title>apache2.set_document_root(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>root</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
-- Suppose our real document root is /var/bar, then...
if r.hostname == "www.foo.com" then
apache2.set_document_root(r, "/www/foo") -- change document root on the fly
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.set_keepalive">
<title>apache2.set_keepalive(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
True if keepalive can be set, false otherwise
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.setenv">
<title>apache2.setenv(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>val</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.setenv("FOO_VAL", "bar and stuff")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.some_auth_required">
<title>apache2.some_auth_required(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if apache2.some_auth_required(r) then
print("debug: auth is required for this request\n")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
</section>
<section id="Parser_functions">
<title>HTTPd bindings: Parser functions</title>
+<p>
<a href="#apache2.expr">apache2.expr</a>
<br/>
<a href="#apache2.regex">apache2.regex</a>
<br/>
<a href="#apache2.strcmp_match">apache2.strcmp_match</a>
<br/>
+</p>
<section id="apache2.expr">
<title>apache2.expr(
request_rec<em> r</em>, string<em> expression</em>
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>expression</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if apache2.expr("%{REQUEST_URI} =~ /force-gzip") then
apache2.add_output_filter(r, "DEFLATE")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.regex">
<title>apache2.regex(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>the source string to capture from</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local matches = apache2.regex(r, [[(\S+) kitty]], "Hello kitty")
if matches and matches[1] then
r:puts("You said ", matches[1], " to kitty")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.strcmp_match">
<title>apache2.strcmp_match(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>Whether to ignore case when matching</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if apache2.strcmp_match("foo.bar", "foo.*") then
r:puts("It matches!")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
</section>
<section id="Server_settings">
<title>HTTPd bindings: Server settings</title>
+<p>
<a href="#apache2.add_version_component">apache2.add_version_component</a>
<br/>
<a href="#apache2.banner">apache2.banner</a>
<br/>
<a href="#apache2.exists_config_define">apache2.exists_config_define</a>
<br/>
+</p>
<section id="apache2.add_version_component">
<title>apache2.add_version_component(
request_rec<em> r</em>, string<em> component</em>
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The component to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if not apache2.banner():match("FooModule") then -- Make sure we haven't added it already
apache2.add_version_component(r, "FooModule/1.0")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.banner">
<title>apache2.banner(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
The server banner
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.custom_response">
<title>apache2.custom_response(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The custom response. This can be a static string, a file or a URL</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
apache2.custom_response(r, 404, "Not found!!")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.exists_config_define">
<title>apache2.exists_config_define(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The define to check for</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
if apache2.exists_config_define("FOO") then
r:puts("This server was started with -DFOO")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.get_server_built">
<title>apache2.get_server_built(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
The date the server was built
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.is_initial_req">
<title>apache2.is_initial_req(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
True if this is the main request, false if it is a sub-request
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.loaded_modules">
<title>apache2.loaded_modules(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
A table containing the name (c filename) of all loaded modules
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.module_info">
<title>apache2.module_info(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>file</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The various commands available to this module as a table, or nil if the module wasn't found.
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.mpm_query">
<title>apache2.mpm_query(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>i</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The queried value
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.runtime_dir_relative">
<title>apache2.runtime_dir_relative(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>file</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The path of a file relative to the default runtime directory
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.scoreboard_process">
<title>apache2.scoreboard_process(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The server child to query</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The scoreboard for a server daemon as a table
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.scoreboard_worker">
<title>apache2.scoreboard_worker(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The thread to query</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The scoreboard for a single thread as a table
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.server_info">
<title>apache2.server_info(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
A table with information about the server program
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.started">
<title>apache2.started(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
The time when the server was (re)started
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.state_query">
<title>apache2.state_query(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>Which information is requested</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local gen = apache2.state_query(2)
r:puts("This is generation no. " .. gen .. " of the top-level parent")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.terminate">
<title>apache2.terminate(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
-<br/>
-<br/>
+<p>None</p>
+<p> </p>
</section>
</section>
<section id="Database_connectivity">
<title>HTTPd bindings: Database connectivity</title>
+<p>
<a href="#apache2.dbopen">apache2.dbopen</a>
<br/>
<a href="#db:query">db:query</a>
<br/>
<a href="#db:close">db:close</a>
<br/>
+</p>
<section id="apache2.dbopen">
<title>apache2.dbopen(
request_rec<em> r</em>, string<em> dbtype</em>, string<em> conn_string</em>
)
</title>
<p>
-Opens up a new database connection. See the DB functions for mod_pLua for more info on this.
+Opens up a new database connection.
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>connection string</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local db, error = apache2.dbopen(r, "mod_dbd")
if error then
-- DB stuff here
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="db:close">
<title>db:close(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local db = apache2.dbopen(r, "mod_dbd") -- open a db connection
db:close() -- close it down
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="db:do">
<title>db:do(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The SQL statement to execute</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local db = apache2.dbopen(r, "mod_dbd")
local affected = db:do("DELETE FROM `table` WHERE 1")
r:puts("Affected ", affected, " rows")
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="db:query">
<title>db:query(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The SQL statement to execute</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br/>
</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
local db = apache2.dbopen(r, "mod_dbd")
local result, error = db:query("SELECT * FROM `table` WHERE 1")
end
end
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
</section>
<section id="Miscellaneous">
<title>HTTPd bindings: Miscellaneous</title>
+<p>
<a href="#apache2.clock">apache2.clock</a>
<br/>
<a href="#apache2.sleep">apache2.sleep</a>
<br/>
+</p>
<section id="apache2.clock">
<title>apache2.clock(
</p>
<p>
<em>Arguments:</em>
-<br/>
- None<br/>
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br/>
The current time in microseconds.
</p>
-<br/>
-<br/>
+<p> </p>
</section>
<section id="apache2.sleep">
<title>apache2.sleep(
</p>
<p>
<em>Arguments:</em>
-<br/>
+</p>
<table border="1">
<tr>
<th>Argument</th>
<td>The number of seconds to sleep.</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br/>
+</p>
<highlight language="lua">
r:puts("this is ")
apache2.flush(r)
apache2.sleep(0.25) -- sleep for a quarter second.
r:puts("delayed")
</highlight>
-</p>
-<br/>
-<br/>
+<p> </p>
</section>
</section>