mod_lua.c revision 001a44c352f89c9ec332ffd3e0a6927dcd19432c
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * the License. You may obtain a copy of the License at
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Unless required by applicable law or agreed to in writing, software
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * distributed under the License is distributed on an "AS IS" BASIS,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * See the License for the specific language governing permissions and
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * limitations under the License.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* getpid for *NIX */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* getpid for Windows */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_open,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_request,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *lua_ssl_val = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic APR_OPTIONAL_FN_TYPE(ssl_is_https) *lua_ssl_is_https = NULL;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantztypedef struct {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *name;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndtypedef struct
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * error reporting if lua has an error.
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Extracts the error from lua stack and prints
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic void report_lua_error(lua_State *L, request_rec *r)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *lua_response;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, APLOGNO(01471) "Lua error: %s",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic void lua_open_callback(lua_State *L, apr_pool_t *p, void *ctx)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrinstatic int lua_open_hook(lua_State *L, apr_pool_t *p)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrinstatic const char *scope_to_string(unsigned int scope)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin return "once";
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin return "request";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "conn";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "thread";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "server";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic void ap_lua_release_state(lua_State* L, ap_lua_vm_spec* spec, request_rec* r) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Lua.server_spec");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz sspec = (ap_lua_server_spec*) lua_touserdata(L, 1);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (apr_pool_userdata_get((void **)&reslist, hash,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic ap_lua_vm_spec *create_vm_spec(apr_pool_t **lifecycle_pool,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *what)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_lua_vm_spec *spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz spec->codecache = (cfg->codecache == AP_LUA_CACHE_UNSET) ? AP_LUA_CACHE_STAT : cfg->codecache;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, APLOGNO(02313)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin "%s details: scope: %s, file: %s, func: %s",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz pool = apr_thread_pool_get(r->connection->current_thread);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* string, const char** values)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char* ret;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin for (x=0; x < srclen; x++) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (string[x] == '$' && x != srclen-1 && string[x+1] >= '0' && string[x+1] <= '9') {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin if (x-y > 0) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ret = apr_pstrcat(pool, ret, stringBetween, values[v], NULL);
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if (x-y > 0 && y > 0) {
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin /* If no replacement was made, just return the original string */
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin else if (y == 0) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* Decline the request if the script does not exist (or is a directory),
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * rather than just returning internal server error */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(01472)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* XXX: This seems wrong because it may generate wrong headers for HEAD requests */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_lua_vm_spec *spec = create_vm_spec(&pool, r, cfg, NULL, NULL, NULL,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* TODO annotate spec with failure reason */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, APLOGNO(01474) "got a vm!");
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01475)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "lua: Unable to find function %s in %s",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* ------------------- Input/output content filters ------------------- */
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic apr_status_t lua_setup_filter_ctx(ap_filter_t* f, request_rec* r, lua_filter_ctx** c) {
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Find the filter that was called.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * XXX: If we were wired with mod_filter, the filter (mod_filters name)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * and the provider (our underlying filters name) need to have matched.
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ((ap_lua_filter_handler_spec **) cfg->mapped_filters->elts)[n];
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!strcasecmp(hook_spec->filter_name, f->frec->name)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz spec = create_vm_spec(&pool, r, cfg, server_cfg,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "filter");
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(02328)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "lua: Failed to obtain lua interpreter for %s %s",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(02329)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "lua: Unable to find function %s in %s",
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin /* If a Lua filter is interested in filtering a request, it must first do a yield,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * otherwise we'll assume that it's not interested and pretend we didn't find it.
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Not wired by mod_filter */
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade *pbbIn) {
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Set up the initial filter context and acquire the function.
5876f43a746f688a32b7201bced8591ddf19bd43minfrin * The corresponding Lua function should yield here.
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* No filter entry found (or the script declined to filter), just pass on the buckets */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* We've got a willing lua filter, setup and check for a prefix */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char* output = lua_tolstring(ctx->L, 1, &olen);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin pbktOut = apr_bucket_heap_create(output, olen, NULL, c->bucket_alloc);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* While the Lua function is still yielding, pass in buckets to the coroutine */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *data;
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* read the bucket */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Push the bucket onto the Lua stack as a global var */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* If Lua yielded, it means we have something to pass on */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin pbktOut = apr_bucket_heap_create(output, olen, NULL,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* If we've safely reached the end, do a final call to Lua to allow for any
5876f43a746f688a32b7201bced8591ddf19bd43minfrin finishing moves by the script, such as appending a tail. */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin pbktOut = apr_bucket_heap_create(output, olen, NULL,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Clean up */
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic apr_status_t lua_input_filter_handle(ap_filter_t *f,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* Set up the initial filter context and acquire the function.
5876f43a746f688a32b7201bced8591ddf19bd43minfrin * The corresponding Lua function should yield here.
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ctx->tmpBucket = apr_brigade_create(r->pool, c->bucket_alloc);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* If the Lua script broke or denied serving the request, just pass the buckets through */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return ap_get_brigade(f->next, pbbOut, eMode, eBlock, nBytes);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin ret = ap_get_brigade(f->next, ctx->tmpBucket, eMode, eBlock, nBytes);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin /* While the Lua function is still yielding, pass buckets to the coroutine */
5876f43a746f688a32b7201bced8591ddf19bd43minfrin apr_bucket *pbktIn = APR_BRIGADE_FIRST(ctx->tmpBucket);
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *data;
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* read the bucket */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* Push the bucket onto the Lua stack as a global var */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* If Lua yielded, it means we have something to pass on */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz pbktOut = apr_bucket_heap_create(output, olen, 0, c->bucket_alloc);
0ecc05d02d9ee3d110cb9e263080aaa2b77a12f9jim /* If we've safely reached the end, do a final call to Lua to allow for any
07d000c26f08bb7d590da25057748b28b8b59741jim finishing moves by the script, such as appending a tail. */
07d000c26f08bb7d590da25057748b28b8b59741jim if (lastCall == 0) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_bucket *pbktEOS = apr_bucket_eos_create(c->bucket_alloc);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd pbktOut = apr_bucket_heap_create(output, olen, 0, c->bucket_alloc);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/* ---------------- Configury stuff --------------- */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd/** harnesses for magic hooks **/
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic int lua_request_rec_hook_harness(request_rec *r, const char *name, int apr_hook_when)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *key = apr_psprintf(r->pool, "%s_%d", name, apr_hook_when);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, key,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "request hook");
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01477)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "lua: Failed to obtain lua interpreter for %s %s",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01478)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "lua: Unable to find function %s in %s",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_TRACE4, 0, r, "Lua hook %s:%s for phase %s returned %d",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd hook_spec->file_name, hook_spec->function_name, name, rc);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "Lua hook %s:%s for phase %s did not return a numeric value",
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd int rc, n = 0;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz for (n = 0; n < cfg->mapped_handlers->nelts; n++) {
7585f3892ce3057554a5bef740302dd479b223b2nd ((ap_lua_mapped_handler_spec **) cfg->mapped_handlers->elts)[n];
7585f3892ce3057554a5bef740302dd479b223b2nd if (!ap_regexec(hook_spec->uri_pattern, r->uri, 10, match, 0)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz for (i=0 ; i < 10; i++) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd values[i] = apr_pstrndup(r->pool, r->uri+match[i].rm_so, match[i].rm_eo - match[i].rm_so);
e8f95a682820a599fe41b22977010636be5c2717jim filename = ap_lua_interpolate_string(r->pool, hook_spec->file_name, values);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd function_name = ap_lua_interpolate_string(r->pool, hook_spec->function_name, values);
13be69a729c912bea7d0aa22596b92717df92551pquerna "mapped handler");
13be69a729c912bea7d0aa22596b92717df92551pquerna ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(02330)
13be69a729c912bea7d0aa22596b92717df92551pquerna "lua: Failed to obtain lua interpreter for %s %s",
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(02331)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "lua: Unable to find function %s in %s",
9de73d09e50d2daa2b0ba263d01cf6bf972a27fdrpluem ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(02483)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "lua: Lua handler %s in %s did not return a value, assuming apache2.OK",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic apr_size_t config_getstr(ap_configfile_t *cfg, char *buf,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_status_t rc = (cfg->getstr) (buf, bufsiz, cfg->param);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz while (i < bufsiz) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_status_t rc = (cfg->getch) (&ch, cfg->param);
13be69a729c912bea7d0aa22596b92717df92551pquernatypedef struct cr_ctx
be60e23cacdadb070a83d40086a6d689410acc38rpluem const char *endstr;
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin/* Okay, this deserves a little explaination -- in order for the errors that lua
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * generates to be 'accuarate', including line numbers, we basically inject
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin * N line number new lines into the 'top' of the chunk reader.....
be60e23cacdadb070a83d40086a6d689410acc38rpluem * be happy. this is cool.
13be69a729c912bea7d0aa22596b92717df92551pquernastatic const char *lf =
13be69a729c912bea7d0aa22596b92717df92551pquerna "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrinstatic const char *direct_chunkreader(lua_State *lvm, void *udata,
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin const char *p;
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin *plen = ctx->startline > N_LF ? N_LF : ctx->startline;
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin *plen = config_getstr(ctx->cfp, ctx->buf, HUGE_STRING_LEN);
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrin /*fprintf(stderr, "buf read: %s\n", ctx->buf); */
9ee5ae3a993134d40e9fb156b44b610ce261875cminfrinstatic int ldump_writer(lua_State *L, const void *b, size_t size, void *B)
13be69a729c912bea7d0aa22596b92717df92551pquerna luaL_addlstring((luaL_Buffer *) B, (const char *) b, size);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndtypedef struct hack_section_baton
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *name;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz/* You can be unhappy now.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * This is uncool.
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * When you create a <Section handler in httpd, the only 'easy' way to create
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * a directory context is to parse the section, and convert it into a 'normal'
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd * Configureation option, and then collapse the entire section, in memory,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * back into the parent section -- from which you can then get the new directive
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * invoked.... anyways. evil. Rici taught me how to do this hack :-)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *hack_section_handler(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *arg)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *key = apr_psprintf(cmd->pool, "%s_%d", baton->name, baton->apr_hook_when);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, key,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd *(ap_lua_mapped_handler_spec **) apr_array_push(hook_specs) = baton->spec;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_named_block_function_hook(const char *name,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *line)
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin line = apr_pstrndup(cmd->temp_pool, line, endp - line);
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *word;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "> 2nd argument must be 'early' or 'late'", NULL);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz tmp = apr_pstrdup(cmd->pool, cmd->err_directive->directive + 1);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* This lua State is used only to compile the input strings -> bytecode, so we don't need anything extra. */
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin rv = lua_load(lvm, direct_chunkreader, &ctx, spec->file_name);
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin if (rv != 0) {
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin const char *errstr = apr_pstrcat(cmd->pool, "Lua Error:",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz spec->bytecode = apr_pstrmemdup(cmd->pool, lua_tostring(lvm, -1),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz /* Here, we have to replace our current config node for the next pass */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *current = apr_pcalloc(cmd->pool, sizeof(**current));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz baton = apr_pcalloc(cmd->pool, sizeof(hack_section_baton));
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (*current)->line_num = cmd->config_file->line_number;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz (*current)->directive = apr_pstrdup(cmd->pool, "Lua_____ByteCodeHack");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_named_file_function_hook(const char *name,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *file,
9fe23388f983cb652b5d68e2bd92aa9f0568c574minfrin const char *function,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *key = apr_psprintf(cmd->pool, "%s_%d", name, apr_hook_when);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, key,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin apr_hash_set(cfg->hooks, key, APR_HASH_KEY_STRING, hook_specs);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec->function_name = apr_pstrdup(cmd->pool, function);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin *(ap_lua_mapped_handler_spec **) apr_array_push(hook_specs) = spec;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_mapped_file_function_hook(const char *pattern,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *function)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_regex_t *regex = apr_pcalloc(cmd->pool, sizeof(ap_regex_t));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return "Invalid regex pattern!";
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_mapped_handler_spec));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec->function_name = apr_pstrdup(cmd->pool, function);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin *(ap_lua_mapped_handler_spec **) apr_array_push(cfg->mapped_handlers) = spec;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_filter_function_hook(const char *filter,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *function,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec = apr_pcalloc(cmd->pool, sizeof(ap_lua_filter_handler_spec));
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin spec->function_name = apr_pstrdup(cmd->pool, function);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin *(ap_lua_filter_handler_spec **) apr_array_push(cfg->mapped_filters) = spec;
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /* TODO: Make it work on other types than just AP_FTYPE_RESOURCE? */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_register_output_filter_protocol(filter, lua_output_filter_handle, NULL, AP_FTYPE_RESOURCE,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin AP_FILTER_PROTO_CHANGE|AP_FILTER_PROTO_CHANGE_LENGTH);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_register_input_filter(filter, lua_input_filter_handle, NULL, AP_FTYPE_RESOURCE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_check_user_id_harness_first(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "check_user_id", AP_LUA_HOOK_FIRST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "check_user_id", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_check_user_id_harness_last(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "check_user_id", AP_LUA_HOOK_LAST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_translate_name_harness_first(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "translate_name", AP_LUA_HOOK_FIRST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_translate_name_harness(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "translate_name", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_translate_name_harness_last(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "translate_name", AP_LUA_HOOK_LAST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "fixups", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_map_to_storage_harness(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "map_to_storage", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "type_checker", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_access_checker_harness_first(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "access_checker", AP_LUA_HOOK_FIRST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_access_checker_harness(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "access_checker", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_access_checker_harness_last(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "access_checker", AP_LUA_HOOK_LAST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_auth_checker_harness_first(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "auth_checker", AP_LUA_HOOK_FIRST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "auth_checker", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_auth_checker_harness_last(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "auth_checker", AP_LUA_HOOK_LAST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic void lua_insert_filter_harness(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /* ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "LuaHookInsertFilter not yet implemented"); */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_log_transaction_harness(request_rec *r)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "log_transaction", APR_HOOK_FIRST);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic int lua_quick_harness(request_rec *r, int lookup)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return lua_request_rec_hook_harness(r, "quick", APR_HOOK_MIDDLE);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_translate_name_hook(cmd_parms *cmd, void *_cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *function,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *when)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return "Third argument must be 'early' or 'late'";
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return register_named_file_function_hook("translate_name", cmd, _cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_translate_name_block(cmd_parms *cmd, void *_cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *line)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return register_named_block_function_hook("translate_name", cmd, _cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_fixups_hook(cmd_parms *cmd, void *_cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *function)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return register_named_file_function_hook("fixups", cmd, _cfg, file,
2d728410bcf9e6e53698bb035f516e18efd76d8bndstatic const char *register_fixups_block(cmd_parms *cmd, void *_cfg,
1018201f5223624476334c6e23aead02db7c4040minfrin const char *line)
1018201f5223624476334c6e23aead02db7c4040minfrin return register_named_block_function_hook("fixups", cmd, _cfg, line);
9333012aa2af9e669db651f0ade3e044ccc3ec84rpluemstatic const char *register_map_to_storage_hook(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *file,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *function)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return register_named_file_function_hook("map_to_storage", cmd, _cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bndstatic const char *register_log_transaction_hook(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *file,
487d8b4e063696dd9698792a13c8e426635f1072nd const char *function)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return register_named_file_function_hook("log_transaction", cmd, _cfg,
487d8b4e063696dd9698792a13c8e426635f1072ndstatic const char *register_map_to_storage_block(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *line)
487d8b4e063696dd9698792a13c8e426635f1072nd return register_named_block_function_hook("map_to_storage", cmd, _cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bndstatic const char *register_check_user_id_hook(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *file,
487d8b4e063696dd9698792a13c8e426635f1072nd const char *function,
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantz const char *when)
487d8b4e063696dd9698792a13c8e426635f1072nd return "Third argument must be 'early' or 'late'";
2d728410bcf9e6e53698bb035f516e18efd76d8bnd return register_named_file_function_hook("check_user_id", cmd, _cfg, file,
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic const char *register_check_user_id_block(cmd_parms *cmd, void *_cfg,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *line)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin return register_named_block_function_hook("check_user_id", cmd, _cfg,
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic const char *register_type_checker_hook(cmd_parms *cmd, void *_cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *function)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return register_named_file_function_hook("type_checker", cmd, _cfg, file,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_type_checker_block(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *line)
2d728410bcf9e6e53698bb035f516e18efd76d8bnd return register_named_block_function_hook("type_checker", cmd, _cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_access_checker_hook(cmd_parms *cmd, void *_cfg,
2d728410bcf9e6e53698bb035f516e18efd76d8bnd const char *file,
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick const char *when)
5c345baea74f2eb2d74548bed271370b972499e5minfrin return "Third argument must be 'early' or 'late'";
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin return register_named_file_function_hook("access_checker", cmd, _cfg,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrinstatic const char *register_access_checker_block(cmd_parms *cmd, void *_cfg,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin const char *line)
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin return register_named_block_function_hook("access_checker", cmd, _cfg,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrinstatic const char *register_auth_checker_hook(cmd_parms *cmd, void *_cfg,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin const char *file,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *when)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "Third argument must be 'early' or 'late'";
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return register_named_file_function_hook("auth_checker", cmd, _cfg, file,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_auth_checker_block(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *line)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin return register_named_block_function_hook("auth_checker", cmd, _cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_insert_filter_hook(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *file,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return "LuaHookInsertFilter not yet implemented";
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrinstatic const char *register_quick_hook(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|
2d728410bcf9e6e53698bb035f516e18efd76d8bnd return register_named_file_function_hook("quick", cmd, _cfg, file,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_map_handler(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char* match, const char *file, const char *function)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return register_mapped_file_function_hook(match, cmd, _cfg, file,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *register_output_filter(cmd_parms *cmd, void *_cfg,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char* filter, const char *file, const char *function)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin return register_filter_function_hook(filter, cmd, _cfg, file,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic const char *register_input_filter(cmd_parms *cmd, void *_cfg,
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick const char* filter, const char *file, const char *function)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd return register_filter_function_hook(filter, cmd, _cfg, file,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic const char *register_quick_block(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *line)
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick return register_named_block_function_hook("quick", cmd, _cfg,
663c339c8a4663cf1977f890481f8b7e251d3221jerenkrantzstatic const char *register_package_helper(cmd_parms *cmd,
4e1b035de81cbd18cfaea3604d40209bc6919bd9trawick const char *arg,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_get_module_config(cmd->server->module_config, &lua_module);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz *(const char **) apr_array_push(dir_array) = fixed_filename;
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * Called for config directive which looks like
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz * LuaPackagePath /lua/package/path/mapped/thing/like/this/?.lua
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9ndstatic const char *register_package_dir(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *arg)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz return register_package_helper(cmd, arg, cfg->package_paths);
487d8b4e063696dd9698792a13c8e426635f1072nd * Called for config directive which looks like
487d8b4e063696dd9698792a13c8e426635f1072nd * LuaPackageCPath /lua/package/path/mapped/thing/like/this/?.so
487d8b4e063696dd9698792a13c8e426635f1072nd const char *arg)
15351ab1a34130c1f880daef4e5dc15407a75969colm return register_package_helper(cmd, arg, cfg->package_cpaths);
487d8b4e063696dd9698792a13c8e426635f1072nd const char *arg)
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "LuaInherit type of '%s' not recognized, valid "
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin "options are 'none', 'parent-first', and 'parent-last'",
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrinstatic const char *register_lua_codecache(cmd_parms *cmd,
f58bb3da705eb7ec926f4883597fc2eb1336a360minfrin const char *arg)
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "LuaCodeCache type of '%s' not recognized, valid "
5876f43a746f688a32b7201bced8591ddf19bd43minfrin "options are 'never', 'stat', and 'forever'",
5876f43a746f688a32b7201bced8591ddf19bd43minfrinstatic const char *register_lua_scope(cmd_parms *cmd,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *scope,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *min,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin const char *max)
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin "Scope type of '%s' cannot be used because this "
5dc4220fc22561537ce1421a03e11846a5b719ebminfrin "server does not have threading support "
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin "(APR_HAS_THREADS)"
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin "Scope type of '%s' cannot be used because this "
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin "server does not have threading support "
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin "(APR_HAS_THREADS)"
fac37c9794a18c24d187f4e0f97a9476c4344118minfrin if (vmin == 0) {
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "Invalid value for LuaScope, '%s', acceptable "
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "values are: 'once', 'request', 'conn'"
1018201f5223624476334c6e23aead02db7c4040minfrin ", 'thread', 'server'"
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *register_lua_root(cmd_parms *cmd, void *_cfg,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin const char *root)
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin /* ap_lua_dir_cfg* cfg = (ap_lua_dir_cfg*)_cfg; */
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin ap_lua_server_cfg *cfg = ap_get_module_config(cmd->server->module_config,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinconst char *ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c,
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin return (const char *)lua_ssl_val(p, s, c, r, (char *)var);
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrin/*******************************/
6fee4e2faa2e45fe2636d01e35d03c2cf0c9d431minfrinstatic const char *lua_authz_parse(cmd_parms *cmd, const char *require_line,
1018201f5223624476334c6e23aead02db7c4040minfrin apr_pool_userdata_get((void**)&provider_name, AUTHZ_PROVIDER_NAME_NOTE,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin spec = apr_hash_get(lua_authz_providers, provider_name, APR_HASH_KEY_STRING);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *arg;
1018201f5223624476334c6e23aead02db7c4040minfrin spec->args = apr_array_make(cmd->pool, 2, sizeof(const char *));
1018201f5223624476334c6e23aead02db7c4040minfrin while ((arg = ap_getword_conf(cmd->pool, &require_line)) && *arg) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic authz_status lua_authz_check(request_rec *r, const char *require_line,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin const lua_authz_provider_spec *prov_spec = parsed_require_line;
03ee592beedc99301c3c79838af79a333af47361minfrin spec = create_vm_spec(&pool, r, cfg, server_cfg, prov_spec->file_name,
5876f43a746f688a32b7201bced8591ddf19bd43minfrin NULL, 0, prov_spec->function_name, "authz provider");
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02314)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Unable to compile VM for authz provider %s", prov_spec->name);
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(02319)
fc1206972499ab73c4dfded43cef279d8bf01ad9minfrin "Unable to find function %s in %s",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz if (!lua_checkstack(L, prov_spec->args->nelts)) {
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02315)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Error: authz provider %s: too many arguments", prov_spec->name);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *arg = APR_ARRAY_IDX(prov_spec->args, i, const char *);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02316)
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "Error executing authz provider %s: %s", prov_spec->name, err);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02317)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Error: authz provider %s did not return integer", prov_spec->name);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02318)
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Error: authz provider %s: invalid return value %d",
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantzstatic const char *register_authz_provider(cmd_parms *cmd, void *_cfg,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd apr_hash_set(lua_authz_providers, name, APR_HASH_KEY_STRING, spec);
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz ap_register_auth_provider(cmd->pool, AUTHZ_PROVIDER_GROUP, name,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd AP_INIT_TAKE1("LuaRoot", register_lua_root, NULL, OR_ALL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Specify the base path for resolving relative paths for mod_lua directives"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE1("LuaPackagePath", register_package_dir, NULL, OR_ALL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Add a directory to lua's package.path"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE1("LuaPackageCPath", register_package_cdir, NULL, OR_ALL,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "Add a directory to lua's package.cpath"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE3("LuaAuthzProvider", register_authz_provider, NULL, RSRC_CONF|EXEC_ON_READ,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide an authorization provider"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE23("LuaHookTranslateName", register_translate_name_hook, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the translate name phase of request processing"),
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd AP_INIT_RAW_ARGS("<LuaHookTranslateName", register_translate_name_block,
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd "Provide a hook for the translate name phase of request processing"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE2("LuaHookFixups", register_fixups_hook, NULL, OR_ALL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the fixups phase of request processing"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_RAW_ARGS("<LuaHookFixups", register_fixups_block, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a inline hook for the fixups phase of request processing"),
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* todo: test */
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd AP_INIT_TAKE2("LuaHookMapToStorage", register_map_to_storage_hook, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the map_to_storage phase of request processing"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_RAW_ARGS("<LuaHookMapToStorage", register_map_to_storage_block,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the map_to_storage phase of request processing"),
03bdb4fb430b0d4e502ddfc75f7e9dbd91db72e9nd /* todo: test */
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_TAKE23("LuaHookCheckUserID", register_check_user_id_hook, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the check_user_id phase of request processing"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_RAW_ARGS("<LuaHookCheckUserID", register_check_user_id_block,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the check_user_id phase of request processing"),
a51acf58d9d82f52e0ee56106cd9282030f3f3bend /* todo: test */
a51acf58d9d82f52e0ee56106cd9282030f3f3bend AP_INIT_TAKE2("LuaHookTypeChecker", register_type_checker_hook, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the type_checker phase of request processing"),
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz AP_INIT_RAW_ARGS("<LuaHookTypeChecker", register_type_checker_block, NULL,
9fe74ffcdea85800f04a7222f716f78ae60cce51jerenkrantz "Provide a hook for the type_checker phase of request processing"),
NULL,
{NULL}
return cfg;
return OK;
return cfg;
ap_lua_push_request(L, r);
return OK;
return OK;
const char *tempdir;
return OK;
s, pconf, 0);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
(long int)getpid());
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
const void *key,
const void *overlay_val,
const void *base_val,
const void *data)
a->codecache = (overrides->codecache == AP_LUA_CACHE_UNSET) ? base->codecache : overrides->codecache;
/* http_request.h hooks */
#if APR_HAS_THREADS