1/** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#ifndef _MOD_LUA_H_ 19#define _MOD_LUA_H_ 20 21#include <stdio.h> 22 23#include "httpd.h" 24#include "http_core.h" 25#include "http_config.h" 26#include "http_request.h" 27#include "http_log.h" 28#include "http_protocol.h" 29#include "ap_regex.h" 30 31#include "ap_config.h" 32#include "util_filter.h" 33 34#include "apr_thread_rwlock.h" 35#include "apr_strings.h" 36#include "apr_tables.h" 37#include "apr_hash.h" 38#include "apr_buckets.h" 39#include "apr_file_info.h" 40#include "apr_time.h" 41#include "apr_hooks.h" 42#include "apr_reslist.h" 43 44/* Allow for Lua 5.2 backwards compatibility */ 45#define LUA_COMPAT_ALL 46 47#include "lua.h" 48#include "lauxlib.h" 49#include "lualib.h" 50 51#if LUA_VERSION_NUM > 501 52/* Load mode for lua_load() */ 53#define lua_load(a,b,c,d) lua_load(a,b,c,d,NULL) 54#define lua_resume(a,b) lua_resume(a, NULL, b) 55#endif 56 57/* Create a set of AP_LUA_DECLARE(type), AP_LUA_DECLARE_NONSTD(type) and 58 * AP_LUA_DECLARE_DATA with appropriate export and import tags for the platform 59 */ 60#if !defined(WIN32) 61#define AP_LUA_DECLARE(type) type 62#define AP_LUA_DECLARE_NONSTD(type) type 63#define AP_LUA_DECLARE_DATA 64#elif defined(AP_LUA_DECLARE_STATIC) 65#define AP_LUA_DECLARE(type) type __stdcall 66#define AP_LUA_DECLARE_NONSTD(type) type 67#define AP_LUA_DECLARE_DATA 68#elif defined(AP_LUA_DECLARE_EXPORT) 69#define AP_LUA_DECLARE(type) __declspec(dllexport) type __stdcall 70#define AP_LUA_DECLARE_NONSTD(type) __declspec(dllexport) type 71#define AP_LUA_DECLARE_DATA __declspec(dllexport) 72#else 73#define AP_LUA_DECLARE(type) __declspec(dllimport) type __stdcall 74#define AP_LUA_DECLARE_NONSTD(type) __declspec(dllimport) type 75#define AP_LUA_DECLARE_DATA __declspec(dllimport) 76#endif 77 78 79#include "lua_request.h" 80#include "lua_vmprep.h" 81 82typedef enum { 83 AP_LUA_INHERIT_UNSET = -1, 84 AP_LUA_INHERIT_NONE = 0, 85 AP_LUA_INHERIT_PARENT_FIRST = 1, 86 AP_LUA_INHERIT_PARENT_LAST = 2 87} ap_lua_inherit_t; 88 89/** 90 * make a userdata out of a C pointer, and vice versa 91 * instead of using lightuserdata 92 */ 93#ifndef lua_boxpointer 94#define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) 95#define lua_unboxpointer(L,i) (*(void **)(lua_touserdata(L, i))) 96#endif 97 98void ap_lua_rstack_dump(lua_State *L, request_rec *r, const char *msg); 99 100typedef struct 101{ 102 apr_array_header_t *package_paths; 103 apr_array_header_t *package_cpaths; 104 105 /** 106 * mapped handlers/filters 107 */ 108 apr_array_header_t *mapped_handlers; 109 apr_array_header_t *mapped_filters; 110 111 apr_pool_t *pool; 112 113 /** 114 * AP_LUA_SCOPE_ONCE | AP_LUA_SCOPE_REQUEST | AP_LUA_SCOPE_CONN | AP_LUA_SCOPE_SERVER 115 */ 116 unsigned int vm_scope; 117 unsigned int vm_min; 118 unsigned int vm_max; 119 120 /* info for the hook harnesses */ 121 apr_hash_t *hooks; /* <wombat_hook_info> */ 122 123 /* the actual directory being configured */ 124 const char *dir; 125 126 /* Whether Lua scripts in a sub-dir are run before parents */ 127 ap_lua_inherit_t inherit; 128 129 /** 130 * AP_LUA_CACHE_NEVER | AP_LUA_CACHE_STAT | AP_LUA_CACHE_FOREVER 131 */ 132 unsigned int codecache; 133 134} ap_lua_dir_cfg; 135 136typedef struct 137{ 138 apr_hash_t *vm_reslists; 139 apr_thread_rwlock_t *vm_reslists_lock; 140 141 /* value of the LuaRoot directive */ 142 const char *root_path; 143} ap_lua_server_cfg; 144 145typedef struct 146{ 147 const char *function_name; 148 ap_lua_vm_spec *spec; 149} mapped_request_details; 150 151typedef struct 152{ 153 mapped_request_details *mapped_request_details; 154 apr_hash_t *request_scoped_vms; 155} ap_lua_request_cfg; 156 157typedef struct 158{ 159 lua_State *L; 160 const char *function; 161} ap_lua_filter_ctx; 162 163extern module AP_MODULE_DECLARE_DATA lua_module; 164 165APR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_open, 166 (lua_State *L, apr_pool_t *p)) 167 168APR_DECLARE_EXTERNAL_HOOK(ap_lua, AP_LUA, int, lua_request, 169 (lua_State *L, request_rec *r)) 170 171const char *ap_lua_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, 172 request_rec *r, const char *var); 173 174int ap_lua_ssl_is_https(conn_rec *c); 175 176#endif /* !_MOD_LUA_H_ */ 177