/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mod_lua.h"
#include "lua_apr.h"
#include "lua_dbd.h"
#include "lua_passwd.h"
#include "scoreboard.h"
#include "util_md5.h"
#include "util_script.h"
#include "util_varbuf.h"
#include "apr_date.h"
#include "apr_pools.h"
#include "apr_thread_mutex.h"
#include "apr_tables.h"
#include "util_cookies.h"
#define APR_WANT_BYTEFUNC
#include "apr_want.h"
extern apr_global_mutex_t* lua_ivm_mutex;
extern apr_shm_t *lua_ivm_shm;
#ifndef MODLUA_MAX_REG_MATCH
#endif
{
int i;
for (i = 1; i <= top; i++) {
int t = lua_type(L, i);
switch (t) {
case LUA_TSTRING:{
"%d: '%s'", i, lua_tostring(L, i));
break;
}
case LUA_TUSERDATA:{
i);
break;
}
case LUA_TLIGHTUSERDATA:{
"%d: lightuserdata", i);
break;
}
case LUA_TNIL:{
break;
}
case LUA_TNONE:{
break;
}
case LUA_TBOOLEAN:{
"%d: %s", i, lua_toboolean(L,
i) ? "true" :
"false");
break;
}
case LUA_TNUMBER:{
"%d: %g", i, lua_tonumber(L, i));
break;
}
case LUA_TTABLE:{
"%d: <table>", i);
break;
}
case LUA_TFUNCTION:{
"%d: <function>", i);
break;
}
default:{
"%d: unknown: -[%s]-", i, lua_typename(L, i));
break;
}
}
}
}
/**
* Verify that the thing at index is a request_rec wrapping
* userdata thingamajig and return it if it is. if it is not
* lua will enter its error handling routine.
*/
{
request_rec *r;
return r;
}
/* ------------------ request methods -------------------- */
/* helper callback for req_parseargs */
const char *value)
{
int t;
/* rstack_dump(L, RRR, "start of cb"); */
/* L is [table<s,t>, table<s,s>] */
/* build complex */
/* rstack_dump(L, RRR, "after getfield"); */
t = lua_type(L, -1);
switch (t) {
case LUA_TNIL:
case LUA_TNONE:{
lua_newtable(L); /* [array, table<s,t>, table<s,s>] */
break;
}
case LUA_TTABLE:{
/* [array, table<s,t>, table<s,s>] */
break;
}
}
/* L is [table<s,t>, table<s,s>] */
/* build simple */
}
else {
lua_pop(L, 1);
}
return 1;
}
/* helper callback for req_parseargs */
{
int t;
/* rstack_dump(L, RRR, "start of cb"); */
/* L is [table<s,t>, table<s,s>] */
/* build complex */
/* rstack_dump(L, RRR, "after getfield"); */
t = lua_type(L, -1);
switch (t) {
case LUA_TNIL:
case LUA_TNONE:{
lua_newtable(L); /* [array, table<s,t>, table<s,s>] */
break;
}
case LUA_TTABLE:{
/* [array, table<s,t>, table<s,s>] */
break;
}
}
/* L is [table<s,t>, table<s,s>] */
/* build simple */
}
else {
lua_pop(L, 1);
}
return 1;
}
/*
=======================================================================================================================
lua_read_body(request_rec *r, const char **rbuf, apr_off_t *size): Reads any additional form data sent in POST/PUT
requests. Used for multipart POST data.
=======================================================================================================================
*/
{
return (rc);
}
if (ap_should_client_block(r)) {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
return APR_EINCOMPLETE; /* Only room for incomplete data chunk :( */
}
}
else {
}
}
}
return (rc);
}
/*
* =======================================================================================================================
* and writes to a file.
* =======================================================================================================================
*/
{
return rc;
if (ap_should_client_block(r)) {
rpos = 0;
while ((len_read =
sizeof(argsbuffer))) > 0) {
else
NULL);
if (rc != APR_SUCCESS)
return rc;
}
}
return rc;
}
/* r:parseargs() returning a lua table */
{
lua_newtable(L);
lua_newtable(L); /* [table, table] */
ap_args_to_table(r, &form_table);
return 2; /* [table<string, string>, table<string, array<string>>] */
}
/* ap_lua_binstrstr: Binary strstr function for uploaded data with NULL bytes */
static char* ap_lua_binstrstr (const char * haystack, size_t hsize, const char* needle, size_t nsize)
{
size_t p;
return (char*) (haystack + p);
}
}
return NULL;
}
/* r:parsebody(): Parses regular (url-enocded) or multipart POST data and returns two tables*/
{
int res;
char *multipart;
const char *contentType;
lua_newtable(L);
lua_newtable(L); /* [table, table] */
if (contentType != NULL && (sscanf(contentType, "multipart/form-data; boundary=%250c", multipart) == 1)) {
const char *data;
int i;
return 2;
}
i = 0;
for
(
) {
i++;
if (i == POST_MAX_VARS) break;
if (!crlf) break;
"Content-Disposition: form-data; name=\"%255[^\"]\"; filename=\"%255[^\"]\"",
}
}
}
else {
char *buffer;
}
}
}
return 2; /* [table<string, string>, table<string, array<string>>] */
}
/*
* lua_ap_requestbody; r:requestbody([filename]) - Reads or stores the request
* body
*/
{
const char *filename;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
if (r) {
lua_pushnil(L);
lua_pushliteral(L, "Request body was larger than the permitted size.");
return 2;
}
return (0);
if (!filename) {
const char *data;
return (0);
return (2);
} else {
APR_FPROT_OS_DEFAULT, r->pool);
lua_settop(L, 0);
if (rc == APR_SUCCESS) {
lua_pushboolean(L, 0);
return 1;
}
return (1);
} else
lua_pushboolean(L, 0);
return (1);
}
}
return (0);
}
/* wrap ap_rputs as r:puts(String) */
{
int i;
for (i = 2; i <= argc; i++) {
ap_rputs(luaL_checkstring(L, i), r);
}
return 0;
}
/* wrap ap_rwrite as r:write(String) */
{
size_t n;
int rv;
lua_pushinteger(L, rv);
return 1;
}
/* r:addoutputfilter(name|function) */
{
name);
return 0;
}
/* wrap ap_construct_url as r:construct_url(String) */
{
return 1;
}
/* wrap ap_escape_html r:escape_html(String) */
{
const char *s = luaL_checkstring(L, 2);
return 1;
}
/* wrap optional ssl_var_lookup as r:ssl_var_lookup(String) */
{
const char *s = luaL_checkstring(L, 2);
(char *)s);
lua_pushstring(L, res);
return 1;
}
/* BEGIN dispatch mathods for request_rec fields */
/* not really a field, but we treat it like one */
{
return ap_document_root(r);
}
{
return ap_context_prefix(r);
}
{
return ap_context_document_root(r);
}
{
return r->uri;
}
{
return r->method;
}
{
return r->handler;
}
{
switch (r->proxyreq) {
case PROXYREQ_NONE: return "PROXYREQ_NONE";
case PROXYREQ_PROXY: return "PROXYREQ_PROXY";
case PROXYREQ_REVERSE: return "PROXYREQ_REVERSE";
case PROXYREQ_RESPONSE: return "PROXYREQ_RESPONSE";
default: return NULL;
}
}
{
return r->hostname;
}
{
return r->args;
}
{
return r->path_info;
}
{
return r->canonical_filename;
}
{
return r->filename;
}
{
return r->user;
}
{
return r->unparsed_uri;
}
{
return r->ap_auth_type;
}
{
return r->content_encoding;
}
{
return r->content_type;
}
{
return r->range;
}
{
return r->protocol;
}
{
return r->the_request;
}
{
return r->log_id;
}
{
return r->useragent_ip;
}
{
return r->remaining;
}
{
return r->status;
}
{
return r->assbackwards;
}
{
t->r = r;
t->t = r->headers_in;
t->n = "headers_in";
return t;
}
{
t->r = r;
t->t = r->headers_out;
t->n = "headers_out";
return t;
}
{
t->r = r;
t->t = r->err_headers_out;
t->n = "err_headers_out";
return t;
}
{
t->r = r;
t->t = r->subprocess_env;
t->n = "subprocess_env";
return t;
}
{
t->r = r;
t->t = r->notes;
t->n = "notes";
return t;
}
{
return ap_lua_ssl_is_https(r->connection);
}
{
return (int) ap_get_server_port(r);
}
int returnValue;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
returnValue = ap_rflush(r);
lua_pushboolean(L, (returnValue == 0));
return 1;
}
{
int opts;
opts = ap_allow_options(r);
return apr_psprintf(r->pool, "%s %s %s %s %s %s", (opts&OPT_INDEXES) ? "Indexes" : "", (opts&OPT_INCLUDES) ? "Includes" : "", (opts&OPT_SYM_LINKS) ? "FollowSymLinks" : "", (opts&OPT_EXECCGI) ? "ExecCGI" : "", (opts&OPT_MULTI) ? "MultiViews" : "", (opts&OPT_ALL) == OPT_ALL ? "All" : "" );
}
{
int opts;
opts = ap_allow_overrides(r);
return "All";
}
return "None";
}
return apr_psprintf(r->pool, "%s %s %s %s %s", (opts & OR_LIMIT) ? "Limit" : "", (opts & OR_OPTIONS) ? "Options" : "", (opts & OR_FILEINFO) ? "FileInfo" : "", (opts & OR_AUTHCFG) ? "AuthCfg" : "", (opts & OR_INDEXES) ? "Indexes" : "" );
}
{
}
{
ap_get_basic_auth_pw(r, &pw);
}
{
return (int) ap_get_limit_req_body(r);
}
{
return ap_is_initial_req(r);
}
{
return ap_some_auth_required(r);
}
{
const char *filename;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
lua_pushboolean(L, 0);
}
else {
r->pool);
if (rc == APR_SUCCESS) {
lua_pushinteger(L, sent);
}
else {
lua_pushboolean(L, 0);
}
}
return (1);
}
/*
* lua_apr_b64encode; r:encode_base64(string) - encodes a string to Base64
* format
*/
{
const char *plain;
char *encoded;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
if (encoded_len) {
encoded_len--;
return 1;
}
return 0;
}
/*
* lua_apr_b64decode; r:decode_base64(string) - decodes a Base64 string
*/
{
const char *encoded;
char *plain;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
if (decoded_len) {
decoded_len--;
return 1;
}
return 0;
}
/*
* lua_ap_unescape; r:unescape(string) - Unescapes an URL-encoded string
*/
{
const char *escaped;
char *plain;
size_t x,
y;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
y = ap_unescape_urlencoded(plain);
if (!y) {
lua_pushstring(L, plain);
return 1;
}
return 0;
}
/*
* lua_ap_escape; r:escape(string) - URL-escapes a string
*/
{
const char *plain;
char *escaped;
size_t x;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
lua_pushstring(L, escaped);
return 1;
}
/*
* lua_apr_md5; r:md5(string) - Calculates an MD5 digest of a string
*/
{
const char *buffer;
char *result;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
lua_pushstring(L, result);
return 1;
}
/*
* lua_apr_sha1; r:sha1(string) - Calculates the SHA1 digest of a string
*/
{
const char *buffer;
char *result;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
lua_pushstring(L, result);
return 1;
}
/*
* lua_apr_htpassword; r:htpassword(string [, algorithm [, cost]]) - Creates
* a htpassword hash from a string
*/
{
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
if (mk_password_hash(&ctx)) {
lua_pushboolean(L, 0);
return 2;
} else {
}
return 1;
}
/*
* lua_apr_touch; r:touch(string [, time]) - Sets mtime of a file
*/
{
request_rec *r;
const char *path;
r = ap_lua_check_request_rec(L, 1);
lua_pushboolean(L, (status == 0));
return 1;
}
/*
* lua_apr_mkdir; r:mkdir(string [, permissions]) - Creates a directory
*/
{
request_rec *r;
const char *path;
r = ap_lua_check_request_rec(L, 1);
lua_pushboolean(L, (status == 0));
return 1;
}
/*
* lua_apr_mkrdir; r:mkrdir(string [, permissions]) - Creates directories
* recursive
*/
{
request_rec *r;
const char *path;
r = ap_lua_check_request_rec(L, 1);
lua_pushboolean(L, (status == 0));
return 1;
}
/*
* lua_apr_rmdir; r:rmdir(string) - Removes a directory
*/
{
request_rec *r;
const char *path;
r = ap_lua_check_request_rec(L, 1);
lua_pushboolean(L, (status == 0));
return 1;
}
/*
* lua_apr_date_parse_rfc; r.date_parse_rfc(string) - Parses a DateTime string
*/
{
const char *input;
if (result == 0)
return 0;
return 1;
}
/*
* lua_ap_mpm_query; r:mpm_query(info) - Queries for MPM info
*/
{
int x,
y;
x = lua_tointeger(L, 1);
ap_mpm_query(x, &y);
lua_pushinteger(L, y);
return 1;
}
/*
* lua_ap_expr; r:expr(string) - Evaluates an expr statement.
*/
{
request_rec *r;
int x = 0;
const char *expr,
*err;
r = ap_lua_check_request_rec(L, 1);
res.line_number = 0;
if (!err) {
lua_pushboolean(L, x);
if (x < 0) {
lua_pushstring(L, err);
return 2;
}
return 1;
} else {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 0);
return 1;
}
/*
* lua_ap_regex; r:regex(string, pattern [, flags])
* - Evaluates a regex and returns captures if matched
*/
{
request_rec *r;
int i,
rv,
const char *pattern,
*source;
char *err;
r = ap_lua_check_request_rec(L, 1);
if (rv) {
lua_pushboolean(L, 0);
lua_pushstring(L, err);
return 2;
}
lua_pushboolean(L, 0);
"regcomp found %d matches; only %d allowed.",
lua_pushstring(L, err);
return 2;
}
if (rv == AP_REG_NOMATCH) {
lua_pushboolean(L, 0);
return 1;
}
lua_newtable(L);
lua_pushinteger(L, i);
else
lua_pushnil(L);
lua_settable(L, -3);
}
return 1;
}
/*
* lua_ap_scoreboard_process; r:scoreboard_process(a) - returns scoreboard info
*/
{
int i;
i = lua_tointeger(L, 2);
if (ps_record) {
lua_newtable(L);
lua_pushstring(L, "connections");
lua_settable(L, -3);
lua_pushstring(L, "keepalive");
lua_settable(L, -3);
lua_pushstring(L, "lingering_close");
lua_settable(L, -3);
lua_pushstring(L, "pid");
lua_settable(L, -3);
lua_pushstring(L, "suspended");
lua_settable(L, -3);
lua_pushstring(L, "write_completion");
lua_settable(L, -3);
lua_pushstring(L, "not_accepting");
lua_settable(L, -3);
lua_pushstring(L, "quiescing");
lua_settable(L, -3);
return 1;
}
return 0;
}
/*
* lua_ap_scoreboard_worker; r:scoreboard_worker(proc, thread) - Returns thread
* info
*/
{
int i, j;
request_rec *r = NULL;
r = ap_lua_check_request_rec(L, 1);
if (!r) return 0;
i = lua_tointeger(L, 2);
j = lua_tointeger(L, 3);
ap_copy_scoreboard_worker(ws_record, i, j);
if (ws_record) {
lua_newtable(L);
lua_pushstring(L, "access_count");
lua_settable(L, -3);
lua_pushstring(L, "bytes_served");
lua_settable(L, -3);
lua_pushstring(L, "client");
lua_settable(L, -3);
lua_pushstring(L, "conn_bytes");
lua_settable(L, -3);
lua_pushstring(L, "conn_count");
lua_settable(L, -3);
lua_pushstring(L, "generation");
lua_settable(L, -3);
lua_pushstring(L, "last_used");
lua_settable(L, -3);
lua_pushstring(L, "pid");
lua_settable(L, -3);
lua_pushstring(L, "request");
lua_settable(L, -3);
lua_pushstring(L, "start_time");
lua_settable(L, -3);
lua_pushstring(L, "status");
lua_settable(L, -3);
lua_pushstring(L, "stop_time");
lua_settable(L, -3);
lua_pushstring(L, "tid");
lua_settable(L, -3);
lua_pushstring(L, "vhost");
lua_settable(L, -3);
#ifdef HAVE_TIMES
lua_pushstring(L, "stimes");
lua_settable(L, -3);
lua_pushstring(L, "utimes");
lua_settable(L, -3);
#endif
return 1;
}
return 0;
}
/*
* lua_ap_clock; r:clock() - Returns timestamp with microsecond precision
*/
{
now = apr_time_now();
return 1;
}
/*
* lua_ap_add_input_filter; r:add_input_filter(name) - Adds an input filter to
* the chain
*/
{
request_rec *r;
const char *filterName;
r = ap_lua_check_request_rec(L, 1);
if (filter) {
lua_pushboolean(L, 1);
} else
lua_pushboolean(L, 0);
return 1;
}
/*
* lua_ap_module_info; r:module_info(mod_name) - Returns information about a
* loaded module
*/
{
const char *moduleName;
lua_newtable(L);
lua_pushstring(L, "commands");
lua_newtable(L);
lua_settable(L, -3);
}
lua_settable(L, -3);
return 1;
}
return 0;
}
/*
* lua_ap_runtime_dir_relative: r:runtime_dir_relative(file): Returns the
* filename as relative to the runtime dir
*/
{
request_rec *r;
const char *file;
r = ap_lua_check_request_rec(L, 1);
return 1;
}
/*
* lua_ap_set_document_root; r:set_document_root(path) - sets the current doc
* root for the request
*/
{
request_rec *r;
const char *root;
r = ap_lua_check_request_rec(L, 1);
ap_set_document_root(r, root);
return 0;
}
/*
* lua_ap_getdir; r:get_direntries(directory) - Gets all entries of a
* directory and returns the directory info as a table
*/
{
request_rec *r;
const char *directory;
r = ap_lua_check_request_rec(L, 1);
int i = 0;
lua_newtable(L);
do {
if (APR_STATUS_IS_INCOMPLETE(status)) {
continue; /* ignore un-stat()able files */
}
else if (status != APR_SUCCESS) {
break;
}
lua_pushinteger(L, ++i);
lua_settable(L, -3);
} while (1);
return 1;
}
else {
return 0;
}
}
/*
* lua_ap_stat; r:stat(filename [, wanted]) - Runs stat on a file and
* returns the file info as a table
*/
{
request_rec *r;
const char *filename;
r = ap_lua_check_request_rec(L, 1);
lua_newtable(L);
if (wanted & APR_FINFO_MTIME) {
lua_pushstring(L, "mtime");
lua_settable(L, -3);
}
if (wanted & APR_FINFO_ATIME) {
lua_pushstring(L, "atime");
lua_settable(L, -3);
}
if (wanted & APR_FINFO_CTIME) {
lua_pushstring(L, "ctime");
lua_settable(L, -3);
}
if (wanted & APR_FINFO_SIZE) {
lua_pushstring(L, "size");
lua_settable(L, -3);
}
if (wanted & APR_FINFO_TYPE) {
lua_pushstring(L, "filetype");
lua_settable(L, -3);
}
if (wanted & APR_FINFO_PROT) {
lua_pushstring(L, "protection");
lua_settable(L, -3);
}
return 1;
}
else {
return 0;
}
}
/*
* lua_ap_loaded_modules; r:loaded_modules() - Returns a list of loaded modules
*/
{
int i;
lua_newtable(L);
lua_pushinteger(L, i + 1);
lua_settable(L, -3);
}
return 1;
}
/*
* lua_ap_server_info; r:server_info() - Returns server info, such as the
* executable filename, server root, mpm etc
*/
{
lua_newtable(L);
lua_pushstring(L, "server_executable");
lua_settable(L, -3);
lua_pushstring(L, "server_root");
lua_settable(L, -3);
lua_pushstring(L, "scoreboard_fname");
lua_settable(L, -3);
lua_pushstring(L, "server_mpm");
lua_pushstring(L, ap_show_mpm());
lua_settable(L, -3);
return 1;
}
/*
* === Auto-scraped functions ===
*/
/**
* ap_set_context_info: Set context_prefix and context_document_root.
* @param r The request
* @param prefix the URI prefix, without trailing slash
* @param document_root the corresponding directory on disk, without trailing
* slash
* @note If one of prefix of document_root is NULL, the corrsponding
* property will not be changed.
*/
{
request_rec *r;
const char *prefix;
const char *document_root;
r = ap_lua_check_request_rec(L, 1);
return 0;
}
/**
* ap_os_escape_path (apr_pool_t *p, const char *path, int partial)
* convert an OS path to a URL in an OS dependant way.
* @param p The pool to allocate from
* @param path The path to convert
* @param partial if set, assume that the path will be appended to something
* with a '/' in it (and thus does not prefix "./")
* @return The converted URL
*/
{
char *returnValue;
request_rec *r;
const char *path;
int partial = 0;
r = ap_lua_check_request_rec(L, 1);
if (lua_isboolean(L, 3))
return 1;
}
/**
* ap_escape_logitem (apr_pool_t *p, const char *str)
* Escape a string for logging
* @param p The pool to allocate from
* @param str The string to escape
* @return The escaped string
*/
{
char *returnValue;
request_rec *r;
const char *str;
r = ap_lua_check_request_rec(L, 1);
return 1;
}
/**
* ap_strcmp_match (const char *str, const char *expected)
* Determine if a string matches a patterm containing the wildcards '?' or '*'
* @param str The string to check
* @param expected The pattern to match against
* @param ignoreCase Whether to ignore case when matching
* @return 1 if the two strings match, 0 otherwise
*/
{
int returnValue;
const char *str;
const char *expected;
int ignoreCase = 0;
if (lua_isboolean(L, 3))
if (!ignoreCase)
else
lua_pushboolean(L, (!returnValue));
return 1;
}
/**
* ap_set_keepalive (request_rec *r)
* Set the keepalive status for this request
* @param r The current request
* @return 1 if keepalive can be set, 0 otherwise
*/
{
int returnValue;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
returnValue = ap_set_keepalive(r);
return 1;
}
/**
* ap_make_etag (request_rec *r, int force_weak)
* Construct an entity tag from the resource information. If it's a real
* file, build in some of the file characteristics.
* @param r The current request
* @param force_weak Force the entity tag to be weak - it could be modified
* again in as short an interval.
* @return The entity tag
*/
{
char *returnValue;
request_rec *r;
int force_weak;
r = ap_lua_check_request_rec(L, 1);
return 1;
}
/**
* ap_send_interim_response (request_rec *r, int send_headers)
* Send an interim (HTTP 1xx) response immediately.
* @param r The request
* @param send_headers Whether to send&clear headers in r->headers_out
*/
{
request_rec *r;
int send_headers = 0;
r = ap_lua_check_request_rec(L, 1);
if (lua_isboolean(L, 2))
return 0;
}
/**
* ap_custom_response (request_rec *r, int status, const char *string)
* Install a custom response handler for a given status
* @param r The current request
* @param status The status for which the custom response should be used
* @param string The custom response. This can be a static string, a file
* or a URL
*/
{
request_rec *r;
int status;
const char *string;
r = ap_lua_check_request_rec(L, 1);
return 0;
}
/**
* ap_exists_config_define (const char *name)
* Check for a definition from the server command line
* @param name The define to check for
* @return 1 if defined, 0 otherwise
*/
{
int returnValue;
const char *name;
return 1;
}
{
const char *servername;
request_rec *r;
r = ap_lua_check_request_rec(L, 1);
lua_pushstring(L, servername);
return 1;
}
/* ap_state_query (int query_code) item starts a new field */
{
int returnValue;
int query_code;
return 1;
}
/*
* lua_ap_usleep; r:usleep(microseconds)
* - Sleep for the specified number of microseconds.
*/
{
return 0;
}
/* END dispatch methods for request_rec fields */
{
lua_pop(L, 2);
lua_pop(L, 1);
if (rft) {
case APL_REQ_FUNTYPE_TABLE:{
"request_rec->dispatching %s -> apr table",
name);
ap_lua_push_apr_table(L, rs);
return 1;
}
case APL_REQ_FUNTYPE_LUACFUN:{
"request_rec->dispatching %s -> lua_CFunction",
name);
lua_pushcfunction(L, func);
return 1;
}
case APL_REQ_FUNTYPE_STRING:{
char *rs;
"request_rec->dispatching %s -> string", name);
lua_pushstring(L, rs);
return 1;
}
case APL_REQ_FUNTYPE_INT:{
int rs;
"request_rec->dispatching %s -> int", name);
lua_pushinteger(L, rs);
return 1;
}
case APL_REQ_FUNTYPE_BOOLEAN:{
int rs;
"request_rec->dispatching %s -> boolean", name);
lua_pushboolean(L, rs);
return 1;
}
}
}
return 0;
}
/* helper function for the logging functions below */
{
const char *msg;
r, "%s", msg);
return 0;
}
/* r:debug(String) and friends which use apache logging */
{
return req_log_at(L, APLOG_EMERG);
}
{
return req_log_at(L, APLOG_ALERT);
}
{
return req_log_at(L, APLOG_CRIT);
}
{
return req_log_at(L, APLOG_ERR);
}
{
return req_log_at(L, APLOG_WARNING);
}
{
return req_log_at(L, APLOG_NOTICE);
}
{
return req_log_at(L, APLOG_INFO);
}
{
return req_log_at(L, APLOG_DEBUG);
}
{
if (object) {
return 1;
}
else {
return 0;
}
}
{
luaL_checkany(L, 3);
if (!object) {
}
str_len++; /* add trailing \0 */
}
}
return 0;
}
{
lua_pushstring(L, cookie);
return 1;
}
return 0;
}
{
/* New >= 2.4.8 method: */
if (lua_istable(L, 2)) {
/* key */
lua_pushstring(L, "key");
lua_gettable(L, -2);
lua_pop(L, 1);
/* value */
lua_pushstring(L, "value");
lua_gettable(L, -2);
lua_pop(L, 1);
/* expiry */
lua_pushstring(L, "expires");
lua_gettable(L, -2);
lua_pop(L, 1);
/* secure */
lua_pushstring(L, "secure");
lua_gettable(L, -2);
if (lua_isboolean(L, -1)) {
}
lua_pop(L, 1);
/* httponly */
lua_pushstring(L, "httponly");
lua_gettable(L, -2);
if (lua_isboolean(L, -1)) {
}
lua_pop(L, 1);
/* path */
lua_pushstring(L, "path");
lua_gettable(L, -2);
lua_pop(L, 1);
/* domain */
lua_pushstring(L, "domain");
lua_gettable(L, -2);
lua_pop(L, 1);
}
/* Old <= 2.4.7 method: */
else {
secure = 0;
if (lua_isboolean(L, 4)) {
}
}
/* Calculate expiry if set */
if (expires > 0) {
if (rv == APR_SUCCESS) {
}
}
/* Create path segment */
}
/* Create domain segment */
/* Domain does NOT like quotes in most browsers, so let's avoid that */
}
/* Create the header */
return 0;
}
{
if (APR_IS_BIGENDIAN) {
return *input;
}
return rval;
}
{
char *encoded;
int encoded_len;
"Websocket: Got websocket key: %s", key);
NULL);
if (encoded_len) {
r->status = 101;
/* Trick httpd into NOT using the chunked filter, IMPORTANT!!!111*/
r->clength = 0;
r->bytes_sent = 0;
r->read_chunked = 0;
ap_rflush(r);
"Websocket: Upgraded from HTTP to Websocket");
lua_pushboolean(L, 1);
return 1;
}
}
"Websocket: Upgrade from HTTP to Websocket failed");
return 0;
}
{
if (rv == APR_SUCCESS) {
if (!APR_BRIGADE_EMPTY(brigade)) {
if (rv == APR_SUCCESS) {
}
}
}
return rv;
}
{
r->connection->bucket_alloc);
if (rv == APR_SUCCESS) {
lua_pushboolean(L, 1);
}
else {
lua_pushboolean(L, 0);
}
return 1;
}
{
int n = 0;
unsigned short payload_short = 0;
unsigned char *mask_bytes;
char byte;
int plaintext;
while (do_read) {
do_read = 0;
/* Get opcode and FIN bit */
if (plaintext) {
}
else {
}
if (rv == APR_SUCCESS) {
/* fin bit is the first bit */
/* opcode is the last four bits (there's 3 reserved bits we don't care about) */
/* Get the payload length and mask bit */
if (plaintext) {
}
else {
}
if (rv == APR_SUCCESS) {
/* Mask is the first bit */
/* Payload is the last 7 bits */
/* Extended payload? */
if (payload == 126) {
len = 2;
if (plaintext) {
/* XXX: apr_socket_recv does not receive len bits, only up to len bits! */
}
else {
(char*) &payload_short, 2);
}
if (rv == APR_SUCCESS) {
}
else {
return 0;
}
}
/* Super duper extended payload? */
if (payload == 127) {
len = 8;
if (plaintext) {
}
else {
(char*) &payload_long, 8);
}
if (rv == APR_SUCCESS) {
}
else {
return 0;
}
}
plen,
if (mask) {
len = 4;
if (plaintext) {
}
else {
(char*) mask_bytes, 4);
}
if (rv != APR_SUCCESS) {
return 0;
}
}
if (plaintext) {
while (remaining > 0) {
if (received > 0 ) {
}
}
at);
}
else {
"pushed to Lua stack",
}
if (mask) {
for (n = 0; n < plen; n++) {
}
}
return 2;
}
/* Decide if we need to react to the opcode or not */
plen = 2;
frame[0] = 0x8A;
frame[1] = 0;
do_read = 1;
}
}
}
}
return 0;
}
{
const char *string;
int raw = 0;
char prelude;
if (lua_isboolean(L, 3)) {
}
if (raw != 1) {
"Websocket: Writing framed message to client");
if (len < 126) {
}
else if (len < 65535) {
ap_rputc(126, r);
}
else {
ap_rputc(127, r);
}
}
else {
"Websocket: Writing raw message to client");
}
if (rv == APR_SUCCESS) {
lua_pushboolean(L, 1);
}
else {
lua_pushboolean(L, 0);
}
return 1;
}
{
/* Send a header that says: socket is closing. */
/* Close up tell the MPM and filters to back off */
r->output_filters = NULL;
return 0;
}
{
/* Send a header that says: PING. */
prelude[1] = 0;
plen = 2;
/* Get opcode and FIN bit from pong */
plen = 2;
if (rv == APR_SUCCESS) {
"Websocket: Got PONG opcode: %x", opcode);
if (opcode == 0x8A) {
lua_pushboolean(L, 1);
}
else {
lua_pushboolean(L, 0);
}
if (plen > 0) {
return 1;
}
if (mask) {
plen = 2;
plen = 2;
}
}
else {
lua_pushboolean(L, 0);
}
return 1;
}
{ \
}
/* handle r.status = 201 */
{
const char *key;
/* request_rec* r = lua_touserdata(L, lua_upvalueindex(1)); */
/* const char* key = luaL_checkstring(L, -2); */
return 0;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
apr_psprintf(r->pool,
"Property [%s] may not be set on a request_rec",
key));
lua_error(L);
return 0;
}
/* helper function for walking config trees */
int x = 0;
const char* value;
lua_newtable(L);
x++;
lua_pushnumber(L, x);
lua_newtable(L);
lua_pushstring(L, "directive");
lua_pushstring(L, value);
lua_settable(L, -3);
lua_pushstring(L, "file");
lua_settable(L, -3);
lua_pushstring(L, "line");
lua_settable(L, -3);
if (cfg->first_child) {
lua_pushstring(L, "children");
lua_settable(L, -3);
}
lua_settable(L, -3);
}
}
read_cfg_tree(L, r, ap_conftree);
return 1;
}
/* Hack, hack, hack...! TODO: Make this actually work properly */
return 1;
}
return 1;
}
}
}
}
return 0;
}
{"__index", req_dispatch},
{"__newindex", req_newindex},
/* {"__newindex", req_set_field}, */
};
};
{
const char *name;
name = ap_auth_name(r);
}
{
const char *name;
name = ap_get_server_name(r);
}
};
{
return rft;
}
{
p));
APL_REQ_FUNTYPE_STRING, p));
lua_pushvalue(L, -1);
lua_pop(L, 2);
lua_pushvalue(L, -1);
lua_pop(L, 2);
lua_pushvalue(L, -1);
lua_pop(L, 2);
}
{
req_table_t* t;
lua_boxpointer(L, c);
luaL_getmetatable(L, "Apache2.Connection");
lua_setmetatable(L, -2);
luaL_getmetatable(L, "Apache2.Connection");
t->t = c->notes;
t->r = NULL;
t->n = "notes";
ap_lua_push_apr_table(L, t);
lua_pushstring(L, c->client_ip);
lua_pop(L, 1);
}
{
lua_boxpointer(L, s);
luaL_getmetatable(L, "Apache2.Server");
lua_setmetatable(L, -2);
luaL_getmetatable(L, "Apache2.Server");
lua_pushstring(L, s->server_hostname);
lua_pop(L, 1);
}
{
lua_boxpointer(L, r);
luaL_getmetatable(L, "Apache2.Request");
lua_setmetatable(L, -2);
}