Moved apache code into a folder to help prepare for packaging where we dont want...
[httpd-crcsyncproxy.git] / apache / modules / lua / lua_vmprep.h
bloba0c37259bcb3a3c20e083a8cba85aebda7108359
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
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.
18 #include "lua.h"
19 #include "lauxlib.h"
20 #include "lualib.h"
22 #include "httpd.h"
24 #include "apr_thread_rwlock.h"
25 #include "apr_strings.h"
26 #include "apr_tables.h"
27 #include "apr_hash.h"
28 #include "apr_buckets.h"
29 #include "apr_file_info.h"
30 #include "apr_time.h"
31 #include "apr_pools.h"
34 #ifndef VMPREP_H
35 #define VMPREP_H
37 #define APL_CODE_CACHE_STAT 1
38 #define APL_CODE_CACHE_FOREVER 2
39 #define APL_CODE_CACHE_NEVER 3
41 #define APL_SCOPE_ONCE 1
42 #define APL_SCOPE_REQUEST 2
43 #define APL_SCOPE_CONN 3
44 #define APL_SCOPE_SERVER 4
46 /**
47 * Specification for a lua virtual machine
49 typedef struct
52 /* NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG */
53 apr_array_header_t *package_paths;
54 apr_array_header_t *package_cpaths;
56 /* name of base file to load in the vm */
57 char *file;
59 /* APL_CODE_CACHE_STAT | APL_CODE_CACHE_FOREVER | APL_CODE_CACHE_NEVER */
60 int code_cache_style;
62 /* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_SERVER */
63 int scope;
65 /* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
66 apr_pool_t *pool;
68 /* Pre-compiled Lua Byte code to load directly. If bytecode_len is >0,
69 * the file part of this structure is ignored for loading purposes, but
70 * it is used for error messages.
72 const char *bytecode;
73 apr_size_t bytecode_len;
74 } apl_vm_spec;
76 typedef struct
78 int code_cache_style;
79 char *function_name;
80 char *file_name;
81 int scope;
82 ap_regex_t *uri_pattern;
83 const char *bytecode;
84 apr_size_t bytecode_len;
85 } apl_mapped_handler_spec;
87 typedef struct
89 apr_pool_t *pool;
90 apr_hash_t *compiled_files;
91 apr_thread_rwlock_t *compiled_files_lock;
92 } apl_code_cache;
94 /* remove and make static once out of mod_wombat.c */
95 void apl_openlibs(lua_State *L);
97 /* remove and make static once out of mod_wombat.c */
98 void apl_registerlib(lua_State *L, char *name, lua_CFunction f);
101 * Fake out addition of the "apache2" module
103 void apl_load_apache2_lmodule(lua_State *L);
106 * the apl_?getvm family of functions is used to create and/or obtain
107 * a handle to a lua state. If there is not an extant vm matching the
108 * spec then a new one is created.
110 /* lua_State* apl_rgetvm(request_rec *r, apl_vm_spec *spec); */
112 /* returns NULL if the spec requires a request scope */
113 /* lua_State* apl_cgetvm(conn_rec *r, apl_vm_spec *spec);*/
115 /* returns NULL if the spec requires a request scope or conn scope */
116 /* lua_State* apl_sgetvm(server_rec *r, apl_vm_spec *spec); */
118 typedef void (*apl_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
119 void *ctx);
122 * alternate means of getting lua_State (preferred eventually)
123 * Obtain a lua_State which has loaded file and is associated with lifecycle_pool
124 * If one exists, will return extant one, otherwise will create, attach, and return
125 * This does no locking around the lua_State, so if the pool is shared between
126 * threads, locking is up the client.
128 * @lifecycle_pool -> pool whose lifeycle controls the lua_State
129 * @file file to be opened, also used as a key for uniquing lua_States
130 * @cb callback for vm initialization called *before* the file is opened
131 * @ctx a baton passed to cb
133 lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
134 apl_vm_spec *spec,
135 apr_array_header_t *package_paths,
136 apr_array_header_t *package_cpaths,
137 apl_lua_state_open_callback cb, void *btn);
141 #endif