mod_lua.c revision 185aa71728867671e105178b4c66fbc22b65ae26
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mod_lua.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "lua_apr.h"
#include "lua_config.h"
#include "apr_optional.h"
#include "mod_ssl.h"
#ifdef APR_HAS_THREADS
#include "apr_thread_proc.h"
#endif
(lua_State *L, apr_pool_t *p),
(lua_State *L, request_rec *r),
/**
* error reporting if lua has an error.
* Extracts the error from lua stack and prints
*/
{
const char *lua_response;
r->content_type = "text/html";
ap_rputs("<b>Error!</b>\n", r);
ap_rputs("<p>", r);
ap_rputs(lua_response, r);
ap_rputs("</p>\n", r);
}
{
ap_lua_init(L, p);
ap_lua_load_request_lmodule(L, p);
}
{
lua_open_callback(L, p, NULL);
return OK;
}
/**
* "main"
*/
static int lua_handler(request_rec *r)
{
return DECLINED;
}
r->filename);
if (!r->header_only) {
lua_State *L;
&lua_module);
"request details scope:%u, filename:%s, function:%s",
"handle");
case AP_LUA_SCOPE_ONCE:
case AP_LUA_SCOPE_UNSET:
break;
case AP_LUA_SCOPE_REQUEST:
break;
case AP_LUA_SCOPE_CONN:
break;
case AP_LUA_SCOPE_THREAD:
#if APR_HAS_THREADS
break;
#endif
}
L = ap_lua_get_lua_state(pool,
spec);
if (!L) {
/* TODO annotate spec with failure reason */
ap_rputs("Unable to compile VM, see logs", r);
return HTTP_INTERNAL_SERVER_ERROR;
}
lua_getglobal(L, "handle");
if (!lua_isfunction(L, -1)) {
"lua: Unable to find function %s in %s",
"handle",
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_lua_run_lua_request(L, r);
if (lua_pcall(L, 1, 0, 0)) {
report_lua_error(L, r);
}
}
return OK;
}
/* ---------------- Configury stuff --------------- */
/** harnesses for magic hooks **/
{
int rc;
lua_State *L;
&lua_module);
&lua_module);
if (hook_specs) {
int i;
for (i = 0; i < hook_specs->nelts; i++) {
continue;
}
"request details scope:%u, filename:%s, function:%s",
case AP_LUA_SCOPE_ONCE:
case AP_LUA_SCOPE_UNSET:
break;
case AP_LUA_SCOPE_REQUEST:
break;
case AP_LUA_SCOPE_CONN:
break;
case AP_LUA_SCOPE_THREAD:
#if APR_HAS_THREADS
break;
#endif
}
if (!L) {
"lua: Failed to obtain lua interpreter for %s %s",
return HTTP_INTERNAL_SERVER_ERROR;
}
if (!lua_isfunction(L, -1)) {
"lua: Unable to find function %s in %s",
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_lua_run_lua_request(L, r);
}
else {
int t;
ap_lua_run_lua_request(L, r);
t = lua_gettop(L);
lua_setglobal(L, "r");
lua_settop(L, t);
}
report_lua_error(L, r);
return HTTP_INTERNAL_SERVER_ERROR;
}
if (lua_isnumber(L, -1)) {
}
return rc;
}
}
}
return DECLINED;
}
{
apr_size_t i = 0;
if (rc == APR_SUCCESS) {
++cfg->line_number;
}
else {
buf[0] = '\0';
i = 0;
}
}
else {
while (i < bufsiz) {
char ch;
if (rc != APR_SUCCESS)
break;
if (ch == '\n') {
++cfg->line_number;
break;
}
}
}
return i;
}
typedef struct cr_ctx
{
const char *endstr;
char buf[HUGE_STRING_LEN];
} cr_ctx;
/* Okay, this deserves a little explaination -- in order for the errors that lua
* generates to be 'accuarate', including line numbers, we basically inject
* N line number new lines into the 'top' of the chunk reader.....
*
* be happy. this is cool.
*
*/
static const char *lf =
"\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";
#define N_LF 32
{
const char *p;
return lf;
}
if (p[0] == '<' && p[1] == '/') {
apr_size_t i = 0;
++i;
}
*plen = 0;
return NULL;
}
/*fprintf(stderr, "buf read: %s\n", ctx->buf); */
}
{
(void) L;
return 0;
}
typedef struct hack_section_baton
{
const char *name;
int apr_hook_when;
/* You can be unhappy now.
*
* This is uncool.
*
* When you create a <Section handler in httpd, the only 'easy' way to create
* a directory context is to parse the section, and convert it into a 'normal'
* Configureation option, and then collapse the entire section, in memory,
* back into the parent section -- from which you can then get the new directive
* invoked.... anyways. evil. Rici taught me how to do this hack :-)
*/
const char *arg)
{
if (!hook_specs) {
sizeof(ap_lua_mapped_handler_spec *));
}
return NULL;
}
static const char *register_named_block_function_hook(const char *name,
void *mconfig,
const char *line)
{
int when = APR_HOOK_MIDDLE;
"> directive missing closing '>'", NULL);
}
if (line[0]) {
const char *word;
}
}
}
else {
"> 2nd argument must be 'early' or 'late'", NULL);
}
}
}
{
char buf[32];
char *tmp;
int rv;
if (function) {
}
else {
}
/* This lua State is used only to compile the input strings -> bytecode, so we don't need anything extra. */
lvm = luaL_newstate();
lua_settop(lvm, 0);
if (rv != 0) {
return errstr;
}
else {
luaL_Buffer b;
luaL_buffinit(lvm, &b);
luaL_pushresult(&b);
spec->bytecode_len);
}
/* Here, we have to replace our current config node for the next pass */
if (!*current) {
}
}
return NULL;
}
static const char *register_named_file_function_hook(const char *name,
void *_cfg,
const char *file,
const char *function,
int apr_hook_when)
{
if (!hook_specs) {
sizeof(ap_lua_mapped_handler_spec *));
}
return NULL;
}
static int lua_check_user_id_harness_first(request_rec *r)
{
}
static int lua_check_user_id_harness(request_rec *r)
{
}
static int lua_check_user_id_harness_last(request_rec *r)
{
}
static int lua_translate_name_harness_first(request_rec *r)
{
}
static int lua_translate_name_harness(request_rec *r)
{
}
static int lua_translate_name_harness_last(request_rec *r)
{
}
static int lua_fixup_harness(request_rec *r)
{
}
static int lua_map_to_storage_harness(request_rec *r)
{
}
static int lua_type_checker_harness(request_rec *r)
{
}
static int lua_access_checker_harness_first(request_rec *r)
{
}
static int lua_access_checker_harness(request_rec *r)
{
}
static int lua_access_checker_harness_last(request_rec *r)
{
}
static int lua_auth_checker_harness_first(request_rec *r)
{
}
static int lua_auth_checker_harness(request_rec *r)
{
}
static int lua_auth_checker_harness_last(request_rec *r)
{
}
static void lua_insert_filter_harness(request_rec *r)
{
/* ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "LuaHookInsertFilter not yet implemented"); */
}
{
if (lookup) {
return DECLINED;
}
}
const char *file,
const char *function,
const char *when)
{
int apr_hook_when = APR_HOOK_MIDDLE;
if (err) {
return err;
}
if (when) {
}
}
else {
return "Third argument must be 'early' or 'late'";
}
}
}
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)
{
int apr_hook_when = APR_HOOK_MIDDLE;
if (when) {
}
}
else {
return "Third argument must be 'early' or 'late'";
}
}
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
}
const char *line)
{
line);
}
const char *file,
const char *function,
const char *when)
{
int apr_hook_when = APR_HOOK_MIDDLE;
if (when) {
}
}
else {
return "Third argument must be 'early' or 'late'";
}
}
}
const char *line)
{
line);
}
const char *file,
const char *function,
const char *when)
{
int apr_hook_when = APR_HOOK_MIDDLE;
if (when) {
}
}
else {
return "Third argument must be 'early' or 'late'";
}
}
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
return "LuaHookInsertFilter not yet implemented";
}
{
if (err) {
return err;
}
}
const char *line)
{
line);
}
const char *arg,
{
char *fixed_filename;
arg,
if (rv != APR_SUCCESS) {
"Unable to build full path to file, %s", arg);
}
return NULL;
}
/**
* Called for config directive which looks like
*/
const char *arg)
{
}
/**
* Called for config directive which looks like
*/
void *_cfg,
const char *arg)
{
}
void *_cfg,
const char *arg)
{
}
}
}
else {
"LuaInherit type of '%s' not recognized, valid "
"options are 'none', 'parent-first', and 'parent-last'",
arg);
}
return NULL;
}
void *_cfg,
const char *scope,
const char *min,
const char *max)
{
}
}
}
#if !APR_HAS_THREADS
"Scope type of '%s' cannot be used because this "
"server does not have threading support "
"(APR_HAS_THREADS)"
scope);
#endif
}
else {
"Invalid value for LuaScope, '%s', acceptable "
"values are: 'once', 'request', 'conn', 'server'"
#if APR_HAS_THREADS
", 'thread'"
#endif
,scope);
}
return NULL;
}
const char *root)
{
/* ap_lua_dir_cfg* cfg = (ap_lua_dir_cfg*)_cfg; */
&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 (const char *)lua_ssl_val(p, s, c, r, (char *)var);
}
return NULL;
}
{
return lua_ssl_is_https ? lua_ssl_is_https(c) : 0;
}
/*******************************/
command_rec lua_commands[] = {
"Specify the base path for resolving relative paths for mod_lua directives"),
"Add a directory to lua's package.path"),
"Add a directory to lua's package.cpath"),
"Provide a hook for the translate name phase of request processing"),
NULL,
"Provide a hook for the translate name phase of request processing"),
"Provide a hook for the fixups phase of request processing"),
"Provide a inline hook for the fixups phase of request processing"),
/* todo: test */
"Provide a hook for the map_to_storage phase of request processing"),
NULL,
"Provide a hook for the map_to_storage phase of request processing"),
/* todo: test */
"Provide a hook for the check_user_id phase of request processing"),
NULL,
"Provide a hook for the check_user_id phase of request processing"),
/* todo: test */
"Provide a hook for the type_checker phase of request processing"),
"Provide a hook for the type_checker phase of request processing"),
/* todo: test */
"Provide a hook for the access_checker phase of request processing"),
NULL,
"Provide a hook for the access_checker phase of request processing"),
/* todo: test */
"Provide a hook for the auth_checker phase of request processing"),
"Provide a hook for the auth_checker phase of request processing"),
/* todo: test */
"Provide a hook for the insert_filter phase of request processing"),
"One of once, request, conn, server -- default is once"),
"Controls how Lua scripts in parent contexts are merged with the current "
" context: none|parent-last|parent-first (default: parent-first) "),
"Provide a hook for the quick handler of request processing"),
"Provide a hook for the quick handler of request processing"),
"(internal) Byte code handler"),
{NULL}
};
{
return cfg;
}
static int create_request_config(request_rec *r)
{
return OK;
}
{
return cfg;
}
{
ap_lua_push_request(L, r);
return OK;
}
{
return OK;
}
static void *overlay_hook_specs(apr_pool_t *p,
const void *key,
const void *overlay_val,
const void *base_val,
const void *data)
{
sizeof(ap_lua_mapped_handler_spec *));
return newspecs;
}
{
}
else if (a->inherit == AP_LUA_INHERIT_PARENT_LAST) {
}
else {
}
return a;
}
static void lua_register_hooks(apr_pool_t *p)
{
/* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */
/* http_request.h hooks */
}
AP_DECLARE_MODULE(lua) = {
create_dir_config, /* create per-dir config structures */
merge_dir_config, /* merge per-dir config structures */
create_server_config, /* create per-server config structures */
NULL, /* merge per-server config structures */
lua_commands, /* table of config file commands */
lua_register_hooks /* register hooks */
};