mod_lua.h revision 7bf1401ef4bee095f2f6ce59519e0a6c1018324f
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak/**
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * Licensed to the Apache Software Foundation (ASF) under one or more
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * contributor license agreements. See the NOTICE file distributed with
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * this work for additional information regarding copyright ownership.
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * The ASF licenses this file to You under the Apache License, Version 2.0
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * (the "License"); you may not use this file except in compliance with
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * the License. You may obtain a copy of the License at
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak *
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * http://www.apache.org/licenses/LICENSE-2.0
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak *
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * Unless required by applicable law or agreed to in writing, software
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * distributed under the License is distributed on an "AS IS" BASIS,
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * See the License for the specific language governing permissions and
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * limitations under the License.
27e52281f1522522b170cafc76b08b58aa70ccaand */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#ifndef _MOD_LUA_H_
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define _MOD_LUA_H_
4b5981e276e93df97c34e4da05ca5cf8bbd937dand
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include <stdio.h>
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "httpd.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "http_core.h"
bc9d4698fce0238d2f6f2682e99423ebb1149976rbowen#include "http_config.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "http_request.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "http_log.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "http_protocol.h"
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#include "ap_regex.h"
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "ap_config.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "util_filter.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_thread_rwlock.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_strings.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_tables.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_hash.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_buckets.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_file_info.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_time.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "apr_hooks.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "lua.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "lauxlib.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "lualib.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak/* Create a set of AP_LUA_DECLARE(type), AP_LUA_DECLARE_NONSTD(type) and
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * AP_LUA_DECLARE_DATA with appropriate export and import tags for the platform
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#if !defined(WIN32)
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE(type) type
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_NONSTD(type) type
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_DATA
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#elif defined(AP_LUA_DECLARE_STATIC)
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE(type) type __stdcall
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_NONSTD(type) type
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_DATA
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#elif defined(AP_LUA_DECLARE_EXPORT)
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE(type) __declspec(dllexport) type __stdcall
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_NONSTD(type) __declspec(dllexport) type
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_DATA __declspec(dllexport)
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#else
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE(type) __declspec(dllimport) type __stdcall
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_NONSTD(type) __declspec(dllimport) type
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define AP_LUA_DECLARE_DATA __declspec(dllimport)
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#endif
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "lua_request.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#include "lua_vmprep.h"
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak/**
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * make a userdata out of a C pointer, and vice versa
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * instead of using lightuserdata
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#ifndef lua_boxpointer
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#define lua_unboxpointer(L,i) (*(void **)(lua_touserdata(L, i)))
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#endif
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniakvoid ap_lua_rstack_dump(lua_State *L, request_rec *r, const char *msg);
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniaktypedef struct
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak{
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_array_header_t *package_paths;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_array_header_t *package_cpaths;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak /**
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * mapped handlers
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_array_header_t *mapped_handlers;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_pool_t *pool;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak /**
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak * APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_SERVER
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak unsigned int vm_scope;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak unsigned int vm_server_pool_min;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak unsigned int vm_server_pool_max;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak /* info for the hook harnesses */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_hash_t *hooks; /* <wombat_hook_info> */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak /* the actual directory being configured */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak char *dir;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak} ap_lua_dir_cfg;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniaktypedef struct
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak{
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak ap_lua_code_cache *code_cache;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_hash_t *vm_reslists;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_thread_rwlock_t *vm_reslists_lock;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak /* value of the LuaRoot directive */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak const char *root_path;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak} ap_lua_server_cfg;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniaktypedef struct
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak{
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak char *function_name;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak ap_lua_vm_spec *spec;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak} mapped_request_details;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniaktypedef struct
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak{
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak mapped_request_details *mapped_request_details;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak apr_hash_t *request_scoped_vms;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak} ap_lua_request_cfg;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniaktypedef struct
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak{
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak lua_State *L;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak char *function;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak} ap_lua_filter_ctx;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniakextern module AP_MODULE_DECLARE_DATA lua_module;
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniakAPR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_open,
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak (lua_State *L, apr_pool_t *p))
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniakAPR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_request,
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak (lua_State *L, request_rec *r))
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniakAP_LUA_DECLARE(const char *) ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak#endif /* !_MOD_LUA_H_ */
f21bea4c0f58e17aa1d9a0fac2c219852f89944amaczniak