mod_lua.c revision 39bfc06718264cb819a2646ec4cd1e9c421549b9
/**
* 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"
(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
*/
{
r->status = 500;
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);
}
{
apr_lua_init(L, p);
apl_load_request_lmodule(L, p);
}
{
lua_open_callback(L, p, NULL);
return OK;
}
/*
static apr_status_t luahood(ap_filter_t *f, apr_bucket_brigade *bb) {
apr_bucket* b;
apr_status_t rs;
for ( b = APR_BRIGADE_FIRST(bb);
b != APR_BRIGADE_SENTINEL(bb);
b = APR_BUCKET_NEXT(b))
{
if (APR_BUCKET_IS_EOS(b)) {kl
break;
}
const char *buffer;
size_t bytes;
if (( rs = apr_bucket_read(b, &buffer, &bytes, APR_BLOCK_READ))) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, rs, f->r, "read failure in luahood");
return rs;
}
char *mine = apr_pstrmemdup(f->r->pool, buffer, bytes);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, "sending '%s'", mine);
}
ap_pass_brigade(f->next, bb);
return OK;
}
*/
/**
* "main"
*/
static int lua_handler(request_rec *r)
{
return DECLINED;
}
r->filename);
if (!r->header_only) {
if (!d) {
d->function_name = "handle";
}
d->spec->code_cache_style);
const apl_dir_cfg *cfg =
d->spec,
if (!L) {
/* TODO annotate spec with failure reason */
r->status = 500;
ap_rputs("Unable to compile VM, see logs", r);
}
lua_getglobal(L, d->function_name);
apl_run_lua_request(L, r);
if (lua_pcall(L, 1, 0, 0)) {
report_lua_error(L, r);
}
}
return OK;
}
/**
* Like mod_alias except for lua handler fun :-)
*/
static int apl_alias_munger(request_rec *r)
{
const apl_dir_cfg *cfg =
int i;
const apl_mapped_handler_spec *cnd =
elts)[i];
if (OK ==
0)) {
r->handler = "lua-script";
matches);
}
d->function_name =
/* now do replacement on method name where? */
rcfg->mapped_request_details = d;
return OK;
}
}
return DECLINED;
}
/* ---------------- Configury stuff --------------- */
/** harnesses for magic hooks **/
{
&lua_module);
const apl_dir_cfg *cfg =
&lua_module);
if (hook_specs) {
int i;
for (i = 0; i < hook_specs->nelts; i++) {
char *fixed_filename = NULL;
continue;
}
spec,
if (!L) {
"lua: Failed to obtain lua interpreter for %s %s",
return 500;
}
if (!lua_isfunction(L, -1)) {
"lua: Unable to find function %s in %s",
return 500;
}
apl_run_lua_request(L, r);
}
else {
apl_run_lua_request(L, r);
int t = lua_gettop(L);
lua_setglobal(L, "r");
lua_settop(L, t);
}
report_lua_error(L, r);
return 500;
}
if (lua_isnumber(L, -1)) {
}
return rv;
}
}
}
return DECLINED;
}
{
apr_size_t i = 0;
if (res) {
++cfg->line_number;
}
else {
buf[0] = '\0';
i = 0;
}
}
else {
while (i < bufsiz) {
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] == '/') {
int 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;
/* 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) {
}
return NULL;
}
static const char *register_named_block_function_hook(const char *name,
void *mconfig,
const char *line)
{
const char *function;
}
else {
const char *word;
"> takes exactly one argument", NULL);
}
else {
}
}
{
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) {
const char *errstr =
NULL);
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)
{
if (!hook_specs) {
}
/*
int code_cache_style;
char *function_name;
char *file_name;
int scope;
*/
return NULL;
}
static int lua_check_user_id_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "check_user_id");
}
static int lua_translate_name_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "translate_name");
}
static int lua_fixup_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "fixups");
}
static int lua_map_to_storage_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "map_to_storage");
}
static int lua_type_checker_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "type_checker");
}
static int lua_access_checker_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "access_checker");
}
static int lua_auth_checker_harness(request_rec *r)
{
return lua_request_rec_hook_harness(r, "auth_checker");
}
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;
}
return lua_request_rec_hook_harness(r, "quick");
}
const char *file,
const char *function)
{
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
function);
}
const char *line)
{
}
const char *file,
const char *function)
{
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
function);
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
function);
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
function);
}
const char *line)
{
line);
}
const char *file,
const char *function)
{
return "LuaHookInsertFilter not yet implemented";
}
{
function);
}
const char *line)
{
return "LuaQuickHook in an inline block not yet implemented";
}
{
char *fixed_filename;
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
*/
const char *arg)
{
}
/**
* Called for config directive which looks like
* LuaCodeCache
*/
const char *arg)
{
}
}
}
else {
"Invalid value for LuaCodeCache, '%s', acceptable values are %s",
arg, "'stat', 'forever', and 'never'");
}
return NULL;
}
const char *max)
{
}
}
}
if (min)
if (max)
}
else {
"Invalid value for LuaScope, '%s', acceptable values are %s",
scope, "'once', 'request', 'conn', and 'server'");
}
return NULL;
}
/**
* Called for config directive which looks like
*/
const char *function)
{
const char *function_name;
if (rv != APR_SUCCESS) {
"Unable to configure a lua handler for path '%s', handler %s#%s",
}
return NULL;
}
const char *root)
{
/* apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg; */
return NULL;
}
/*******************************/
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"),
"Map a path to a lua handler"),
"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"),
"Configure the compiled code cache. \
Default is to stat the file each time, options are stat|forever|never"),
"One of once, request, conn, server -- default is once"),
"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;
}
{
apl_push_request(L, r);
return OK;
}
static void lua_register_hooks(apr_pool_t *p)
{
/* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */
/* http_request.h hooks */
/* ap_hook_translate_name(lua_alias_munger, NULL, NULL, APR_HOOK_MIDDLE); */
}
create_dir_config, /* create per-dir config structures */
NULL, /* 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 */
};