|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "lua.h"
|
|
Packit |
90a5c9 |
#include "lauxlib.h"
|
|
Packit |
90a5c9 |
#include "lualib.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_thread_rwlock.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_tables.h"
|
|
Packit |
90a5c9 |
#include "apr_hash.h"
|
|
Packit |
90a5c9 |
#include "apr_buckets.h"
|
|
Packit |
90a5c9 |
#include "apr_file_info.h"
|
|
Packit |
90a5c9 |
#include "apr_time.h"
|
|
Packit |
90a5c9 |
#include "apr_pools.h"
|
|
Packit |
90a5c9 |
#include "apr_reslist.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef VMPREP_H
|
|
Packit |
90a5c9 |
#define VMPREP_H
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_UNSET 0
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_ONCE 1
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_REQUEST 2
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_CONN 3
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_THREAD 4
|
|
Packit |
90a5c9 |
#define AP_LUA_SCOPE_SERVER 5
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define AP_LUA_CACHE_UNSET 0
|
|
Packit |
90a5c9 |
#define AP_LUA_CACHE_NEVER 1
|
|
Packit |
90a5c9 |
#define AP_LUA_CACHE_STAT 2
|
|
Packit |
90a5c9 |
#define AP_LUA_CACHE_FOREVER 3
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define AP_LUA_FILTER_INPUT 1
|
|
Packit |
90a5c9 |
#define AP_LUA_FILTER_OUTPUT 2
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef void (*ap_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
|
|
Packit |
90a5c9 |
void *ctx);
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Specification for a lua virtual machine
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
typedef struct
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG */
|
|
Packit |
90a5c9 |
apr_array_header_t *package_paths;
|
|
Packit |
90a5c9 |
apr_array_header_t *package_cpaths;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* name of base file to load in the vm */
|
|
Packit |
90a5c9 |
const char *file;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_THREAD | APL_SCOPE_SERVER */
|
|
Packit |
90a5c9 |
int scope;
|
|
Packit |
90a5c9 |
unsigned int vm_min;
|
|
Packit |
90a5c9 |
unsigned int vm_max;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_lua_state_open_callback cb;
|
|
Packit |
90a5c9 |
void* cb_arg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
|
|
Packit |
90a5c9 |
apr_pool_t *pool;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Pre-compiled Lua Byte code to load directly. If bytecode_len is >0,
|
|
Packit |
90a5c9 |
* the file part of this structure is ignored for loading purposes, but
|
|
Packit |
90a5c9 |
* it is used for error messages.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
const char *bytecode;
|
|
Packit |
90a5c9 |
apr_size_t bytecode_len;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int codecache;
|
|
Packit |
90a5c9 |
} ap_lua_vm_spec;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *function_name;
|
|
Packit |
90a5c9 |
const char *file_name;
|
|
Packit |
90a5c9 |
int scope;
|
|
Packit |
90a5c9 |
ap_regex_t *uri_pattern;
|
|
Packit |
90a5c9 |
const char *bytecode;
|
|
Packit |
90a5c9 |
apr_size_t bytecode_len;
|
|
Packit |
90a5c9 |
int codecache;
|
|
Packit |
90a5c9 |
} ap_lua_mapped_handler_spec;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *function_name;
|
|
Packit |
90a5c9 |
const char *file_name;
|
|
Packit |
90a5c9 |
const char* filter_name;
|
|
Packit |
90a5c9 |
int direction; /* AP_LUA_FILTER_INPUT | AP_LUA_FILTER_OUTPUT */
|
|
Packit |
90a5c9 |
} ap_lua_filter_handler_spec;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
apr_size_t runs;
|
|
Packit |
90a5c9 |
apr_time_t modified;
|
|
Packit |
90a5c9 |
apr_off_t size;
|
|
Packit |
90a5c9 |
} ap_lua_finfo;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
lua_State* L;
|
|
Packit |
90a5c9 |
ap_lua_finfo* finfo;
|
|
Packit |
90a5c9 |
} ap_lua_server_spec;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Fake out addition of the "apache2" module
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
void ap_lua_load_apache2_lmodule(lua_State *L);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* alternate means of getting lua_State (preferred eventually)
|
|
Packit |
90a5c9 |
* Obtain a lua_State which has loaded file and is associated with lifecycle_pool
|
|
Packit |
90a5c9 |
* If one exists, will return extant one, otherwise will create, attach, and return
|
|
Packit |
90a5c9 |
* This does no locking around the lua_State, so if the pool is shared between
|
|
Packit |
90a5c9 |
* threads, locking is up the client.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @lifecycle_pool -> pool whose lifeycle controls the lua_State
|
|
Packit |
90a5c9 |
* @file file to be opened, also used as a key for uniquing lua_States
|
|
Packit |
90a5c9 |
* @cb callback for vm initialization called *before* the file is opened
|
|
Packit |
90a5c9 |
* @ctx a baton passed to cb
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
lua_State *ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
|
|
Packit |
90a5c9 |
ap_lua_vm_spec *spec, request_rec* r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if APR_HAS_THREADS || defined(DOXYGEN)
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Initialize mod_lua mutex.
|
|
Packit |
90a5c9 |
* @pool pool for mutex
|
|
Packit |
90a5c9 |
* @s server_rec for logging
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
void ap_lua_init_mutex(apr_pool_t *pool, server_rec *s);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif
|