mod_lua.c revision db38a4275fe8e2e76b0de82b52019f2ec5fda32c
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Licensed to the Apache Software Foundation (ASF) under one or more
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * (the "License"); you may not use this file except in compliance with
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * the License. You may obtain a copy of the License at
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * Unless required by applicable law or agreed to in writing, software
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2e545ce2450a9953665f701bb05350f0d3f26275nd * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
4a56677aad9b66a36f3dc9fddbca8dc1230ad471rbowenAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_open,
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap_lua, AP_LUA, int, lua_request,
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *lua_ssl_val = NULL;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic APR_OPTIONAL_FN_TYPE(ssl_is_https) *lua_ssl_is_https = NULL;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzortypedef struct {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh const char *name;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor const char *file_name;
4aa603e6448b99f9371397d439795c91a93637eand * error reporting if lua has an error.
727872d18412fc021f03969b8641810d8896820bhumbedooh * Extracts the error from lua stack and prints
3c13a815670b54d1c17bf02954f7d2b066cde95cndstatic void report_lua_error(lua_State *L, request_rec *r)
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, APLOGNO(01471) "Lua error: %s",
727872d18412fc021f03969b8641810d8896820bhumbedoohstatic void lua_open_callback(lua_State *L, apr_pool_t *p, void *ctx)
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalicstatic const char *scope_to_string(unsigned int scope)
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor return "once";
727872d18412fc021f03969b8641810d8896820bhumbedooh return "request";
727872d18412fc021f03969b8641810d8896820bhumbedooh return "conn";
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor return "thread";
4aa603e6448b99f9371397d439795c91a93637eandstatic ap_lua_vm_spec *create_vm_spec(apr_pool_t **lifecycle_pool,
4aa603e6448b99f9371397d439795c91a93637eand const char *function,
727872d18412fc021f03969b8641810d8896820bhumbedooh const char *what)
70f5253b24dd333c67fb6502d557a8b48ad3ba87igalic ap_lua_vm_spec *spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
cd8142d105a47b208d863bea7cdb540727a5f02digalic spec->codecache = (cfg->codecache == AP_LUA_CACHE_UNSET) ? AP_LUA_CACHE_STAT : cfg->codecache;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, APLOGNO(02313)
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor "%s details: scope: %s, file: %s, func: %s",
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor pool = apr_thread_pool_get(r->connection->current_thread);
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzorstatic const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* string, const char** values)
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor const char* ret;
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor for (x=0; x < srclen; x++) {
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor if (string[x] == '$' && x != srclen-1 && string[x+1] >= '0' && string[x+1] <= '9') {
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor if (x-y > 0) {
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor ret = apr_psprintf(pool, "%s%s%s", ret, stringBetween, values[v]);
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor if (x-y > 0 && y > 0) {
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor ret = apr_psprintf(pool, "%s%s", ret, stringBetween);
cac3c497ee99fac7d83f6e8bd05cb72eaaf95d8fgryzor else if (y==0) return string; /* If no replacement was made, just return the original str. */
0d0ba3a410038e179b695446bb149cce6264e0abnd ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(01472)
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh /* XXX: This seems wrong because it may generate wrong headers for HEAD requests */
727872d18412fc021f03969b8641810d8896820bhumbedooh const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
0d0ba3a410038e179b695446bb149cce6264e0abnd ap_lua_vm_spec *spec = create_vm_spec(&pool, r, cfg, NULL, NULL, NULL,
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd /* TODO annotate spec with failure reason */
return HTTP_INTERNAL_SERVER_ERROR;
ap_lua_run_lua_request(L, r);
report_lua_error(L, r);
return OK;
int rc;
lua_State *L;
&lua_module);
&lua_module);
if (hook_specs) {
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
ap_lua_run_lua_request(L, r);
ap_lua_run_lua_request(L, r);
t = lua_gettop(L);
lua_settop(L, t);
report_lua_error(L, r);
return HTTP_INTERNAL_SERVER_ERROR;
return rc;
return DECLINED;
int rc, n = 0;
lua_State *L;
&lua_module);
&lua_module);
return HTTP_INTERNAL_SERVER_ERROR;
filename);
return HTTP_INTERNAL_SERVER_ERROR;
ap_lua_run_lua_request(L, r);
ap_lua_run_lua_request(L, r);
t = lua_gettop(L);
lua_settop(L, t);
report_lua_error(L, r);
return HTTP_INTERNAL_SERVER_ERROR;
return rc;
return DECLINED;
apr_size_t i = 0;
while (i < bufsiz) {
char ch;
typedef struct cr_ctx
const char *endstr;
} cr_ctx;
static const char *lf =
return lf;
apr_size_t i = 0;
*plen = 0;
return NULL;
typedef struct hack_section_baton
const char *name;
int apr_hook_when;
const char *arg)
if (!hook_specs) {
sizeof(ap_lua_mapped_handler_spec *));
return NULL;
void *mconfig,
const char *line)
if (line[0]) {
const char *word;
char *tmp;
int rv;
if (function) {
/* This lua State is used only to compile the input strings -> bytecode, so we don't need anything extra. */
if (rv != 0) {
return errstr;
luaL_Buffer b;
luaL_pushresult(&b);
if (!*current) {
return NULL;
void *_cfg,
const char *file,
const char *function,
int apr_hook_when)
if (!hook_specs) {
sizeof(ap_lua_mapped_handler_spec *));
return NULL;
void *_cfg,
const char *file,
const char *function)
return NULL;
if (lookup) {
return DECLINED;
const char *file,
const char *function,
const char *when)
if (err) {
return err;
if (when) {
const char *line)
line);
const char *file,
const char *function)
const char *line)
const char *file,
const char *function)
const char *line)
line);
const char *file,
const char *function,
const char *when)
if (when) {
const char *line)
line);
const char *file,
const char *function)
const char *line)
line);
const char *file,
const char *function,
const char *when)
if (when) {
const char *line)
line);
const char *file,
const char *function,
const char *when)
if (when) {
const char *line)
line);
const char *file,
const char *function)
if (err) {
return err;
if (err) {
return err;
function);
const char *line)
line);
const char *arg,
char *fixed_filename;
arg,
return NULL;
const char *arg)
void *_cfg,
const char *arg)
void *_cfg,
const char *arg)
arg);
return NULL;
void *_cfg,
const char *arg)
arg);
return NULL;
void *_cfg,
const char *scope,
const char *min,
const char *max)
#if !APR_HAS_THREADS
scope);
#if APR_HAS_THREADS
,scope);
return NULL;
const char *root)
&lua_module);
return NULL;
AP_LUA_DECLARE(const char *) ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var)
if (lua_ssl_val) {
return NULL;
const void **parsed_require_line)
const char *provider_name;
const char *arg;
return NULL;
const void *parsed_require_line)
lua_State *L;
&lua_module);
&lua_module);
int result;
int nargs = 0;
if (L == NULL) {
return AUTHZ_GENERAL_ERROR;
return AUTHZ_GENERAL_ERROR;
ap_lua_run_lua_request(L, r);
return AUTHZ_GENERAL_ERROR;
return AUTHZ_GENERAL_ERROR;
return AUTHZ_GENERAL_ERROR;
switch (result) {
case AUTHZ_DENIED:
case AUTHZ_GRANTED:
case AUTHZ_NEUTRAL:
case AUTHZ_GENERAL_ERROR:
case AUTHZ_DENIED_NO_USER:
return result;
return AUTHZ_GENERAL_ERROR;
const char *function)
if (err)
return err;
return NULL;
"Add a directory to lua's package.cpath"),
NULL,
NULL,
NULL,
NULL,
{NULL}
return cfg;
return OK;
return cfg;
ap_lua_push_request(L, r);
return OK;
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 */