mod_lua.c revision e0e7a4768845d518c21ce98d359d2ba8314832ba
/**
* 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 "config.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "lua_apr.h"
(lua_State *L, apr_pool_t *p),
(L, p),
(lua_State *L, request_rec *r),
(L, 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;
}
if (!r->header_only) {
if (!d) {
d->function_name = "handle";
}
d->spec->code_cache_style);
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) {
int i;
const apl_mapped_handler_spec *cnd = ((const apl_mapped_handler_spec**)cfg->mapped_handlers->elts)[i];
r->handler = "lua-script";
}
/* now do replacement on method name where? */
rcfg->mapped_request_details = d;
return OK;
}
}
return DECLINED;
}
/* ---------------- Configury stuff --------------- */
/** harnesses for magic hooks **/
char *fixed_filename;
&lua_module);
if (hook_specs) {
int i;
for (i=0; i < hook_specs->nelts; i++) {
/*
const apl_dir_cfg* cfg = ap_get_module_config(r->per_dir_config, &lua_module);
lua_State *L = apl_get_lua_state(r->pool,
d->spec->file,
cfg->package_paths,
cfg->package_cpaths,
&lua_open_callback, NULL);
*/
apr_filepath_merge(&fixed_filename, server_cfg->root_path, spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
if (!L) {
return 500;
}
if (!lua_isfunction(L, -1)) {
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) {
}
else {
buf[0] = '\0';
i = 0;
}
}
else {
while (i < bufsiz) {
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 :-)
*/
{
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;
}
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) {
return errstr;
}
else {
luaL_Buffer b;
luaL_buffinit(lvm, &b);
luaL_pushresult(&b);
}
/* 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;
}
int lua_check_user_id_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "check_user_id");
}
int lua_translate_name_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "translate_name");
}
int lua_fixup_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "fixups");
}
int lua_map_to_storage_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "map_to_storage");
}
int lua_type_checker_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "type_checker");
}
int lua_access_checker_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "access_checker");
}
int lua_auth_checker_harness(request_rec *r) {
return lua_request_rec_hook_harness(r, "auth_checker");
}
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");
}
static const char* register_translate_name_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
{
}
static const char* register_fixups_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_map_to_storage_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_check_user_id_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_type_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_access_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_auth_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
}
static const char* register_insert_filter_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
return "LuaHookInsertFilter not yet implemented";
}
static const char* register_quick_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
}
return "LuaQuickHook in an inline block not yet implemented";
}
static const char* register_package_helper(cmd_parms *cmd, const char *arg, apr_array_header_t *dir_array) {
char *fixed_filename;
rv = apr_filepath_merge(&fixed_filename, server_cfg->root_path, arg, APR_FILEPATH_NOTRELATIVE, cmd->pool);
if (rv != APR_SUCCESS) {
}
return NULL;
}
/**
* Called for config directive which looks like
*/
}
/**
* Called for config directive which looks like
*/
}
/**
* Called for config directive which looks like
* LuaCodeCache
*/
}
}
}
else {
"Invalid value for LuaCodeCache, '%s', acceptable values are %s",
arg, "'stat', 'forever', and 'never'");
}
return NULL;
}
const char *min,
const char *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
*/
static const char* lua_map_handler(cmd_parms *cmd, void *_cfg, const char *path, const char *file, const char *function) {
const char *function_name;
if (rv != APR_SUCCESS) {
}
return NULL;
}
/* 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"),
"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"),
"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"),
"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"),
"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 */
};