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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include "apr_thread_rwlock.h"
25 #include "apr_strings.h"
26 #include "apr_tables.h"
28 #include "apr_buckets.h"
29 #include "apr_file_info.h"
31 #include "apr_pools.h"
32 #include "apr_reslist.h"
38 #define AP_LUA_SCOPE_UNSET 0
39 #define AP_LUA_SCOPE_ONCE 1
40 #define AP_LUA_SCOPE_REQUEST 2
41 #define AP_LUA_SCOPE_CONN 3
42 #define AP_LUA_SCOPE_THREAD 4
43 #define AP_LUA_SCOPE_SERVER 5
45 #define AP_LUA_CACHE_UNSET 0
46 #define AP_LUA_CACHE_NEVER 1
47 #define AP_LUA_CACHE_STAT 2
48 #define AP_LUA_CACHE_FOREVER 3
50 #define AP_LUA_FILTER_INPUT 1
51 #define AP_LUA_FILTER_OUTPUT 2
53 typedef void (*ap_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
56 * Specification for a lua virtual machine
60 /* NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG */
61 apr_array_header_t *package_paths;
62 apr_array_header_t *package_cpaths;
64 /* name of base file to load in the vm */
67 /* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_THREAD | APL_SCOPE_SERVER */
72 ap_lua_state_open_callback cb;
75 /* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
78 /* Pre-compiled Lua Byte code to load directly. If bytecode_len is >0,
79 * the file part of this structure is ignored for loading purposes, but
80 * it is used for error messages.
83 apr_size_t bytecode_len;
90 const char *function_name;
91 const char *file_name;
93 ap_regex_t *uri_pattern;
95 apr_size_t bytecode_len;
97 } ap_lua_mapped_handler_spec;
101 const char *function_name;
102 const char *file_name;
103 const char* filter_name;
104 int direction; /* AP_LUA_FILTER_INPUT | AP_LUA_FILTER_OUTPUT */
105 } ap_lua_filter_handler_spec;
116 } ap_lua_server_spec;
119 * Fake out addition of the "apache2" module
121 void ap_lua_load_apache2_lmodule(lua_State *L);
124 * alternate means of getting lua_State (preferred eventually)
125 * Obtain a lua_State which has loaded file and is associated with lifecycle_pool
126 * If one exists, will return extant one, otherwise will create, attach, and return
127 * This does no locking around the lua_State, so if the pool is shared between
128 * threads, locking is up the client.
130 * @lifecycle_pool -> pool whose lifeycle controls the lua_State
131 * @file file to be opened, also used as a key for uniquing lua_States
132 * @cb callback for vm initialization called *before* the file is opened
133 * @ctx a baton passed to cb
135 lua_State *ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
136 ap_lua_vm_spec *spec, request_rec* r);
138 #if APR_HAS_THREADS || defined(DOXYGEN)
140 * Initialize mod_lua mutex.
141 * @pool pool for mutex
142 * @s server_rec for logging
144 void ap_lua_init_mutex(apr_pool_t *pool, server_rec *s);