request.c revision cb1e20df951447249fd1344ae04a790219a16be5
842ae4bd224140319ae7feec1872b93dfd491143fielding/**
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the License. You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * http://www.apache.org/licenses/LICENSE-2.0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * limitations under the License.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "mod_wombat.h"
e8f95a682820a599fe41b22977010636be5c2717jim#include "util_script.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_lua.h"
e8f95a682820a599fe41b22977010636be5c2717jim
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fieldingtypedef char* (*req_field_string_f) (request_rec* r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholestypedef int (*req_field_int_f) (request_rec* r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesvoid rstack_dump(lua_State* L, request_rec* r, const char* msg) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Lua Stack Dump: [%s]", msg);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int i;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int top = lua_gettop(L);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (i = 1; i<= top; i++) {
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick int t = lua_type(L, i);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch(t) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case LUA_TSTRING: {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
5c0419d51818eb02045cf923a9fe456127a44c60wrowe "%d: '%s'", i, lua_tostring(L, i));
5c0419d51818eb02045cf923a9fe456127a44c60wrowe break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case LUA_TUSERDATA: {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d: userdata", i);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case LUA_TLIGHTUSERDATA: {
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d: lightuserdata", i);
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton break;
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes }
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes case LUA_TNIL: {
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes "%d: NIL", i);
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes break;
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes }
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes case LUA_TNONE: {
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "%d: None", i);
0f60998368b493f90120180a93fc2e1e74490872covener break;
0f60998368b493f90120180a93fc2e1e74490872covener }
0f60998368b493f90120180a93fc2e1e74490872covener case LUA_TBOOLEAN: {
0f60998368b493f90120180a93fc2e1e74490872covener ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
0f60998368b493f90120180a93fc2e1e74490872covener "%d: %s", i, lua_toboolean(L, i) ? "true" : "false");
0f60998368b493f90120180a93fc2e1e74490872covener break;
0f60998368b493f90120180a93fc2e1e74490872covener }
0f60998368b493f90120180a93fc2e1e74490872covener case LUA_TNUMBER: {
87587593f1a53030e840acc0dec6cc881022ea40covener ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
87587593f1a53030e840acc0dec6cc881022ea40covener "%d: %g", i, lua_tonumber(L, i));
87587593f1a53030e840acc0dec6cc881022ea40covener break;
87587593f1a53030e840acc0dec6cc881022ea40covener }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case LUA_TTABLE: {
43997561b2302d13dee973998e77743a3ddd2374trawick ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
fa123db15501821e36e513afa78e839775ad2800covener "%d: <table>", i);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
0568280364eb026393be492ebc732795c4934643jorton }
0568280364eb026393be492ebc732795c4934643jorton case LUA_TFUNCTION: {
0568280364eb026393be492ebc732795c4934643jorton ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
0568280364eb026393be492ebc732795c4934643jorton "%d: <function>", i);
0568280364eb026393be492ebc732795c4934643jorton break;
0568280364eb026393be492ebc732795c4934643jorton }
0568280364eb026393be492ebc732795c4934643jorton default: {
0568280364eb026393be492ebc732795c4934643jorton ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
0568280364eb026393be492ebc732795c4934643jorton "%d: unkown: -[%s]-", i, lua_typename(L, i));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/**
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Verify that the thing at index is a request_rec wrapping
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * userdata thingamajig and return it if it is. if it is not
796e4a7141265d8ed7036e4628161c6eafb2a789jorton * lua will enter its error handling routine.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic request_rec* apw_check_request_rec(lua_State* L, int index) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes luaL_checkudata(L, index, "Apache2.Request");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_rec* r = (request_rec*)lua_unboxpointer(L, index);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return r;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* ------------------ request methods -------------------- */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* helper callback for req_parseargs */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int req_aprtable2luatable_cb(void *l, const char *key, const char *value) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_State* L = (lua_State*)l; /* [table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* rstack_dump(L, RRR, "start of cb"); */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* L is [table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* build complex */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* rstack_dump(L, RRR, "after getfield"); */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin int t = lua_type(L, -1);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch(t) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case LUA_TNIL:
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin case LUA_TNONE: {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pop(L, 1); /* [table<s,t>, table<s,s>] */
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin lua_newtable(L); /* [array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pushnumber(L, 1); /* [1, array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pushstring(L, value); /* [string, 1, array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin }
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin case LUA_TTABLE: {
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin /* [array, table<s,t>, table<s,s>] */
a1790fb35c4b352dab721370985c623a9f8f5062rpluem int size = lua_objlen(L, -1);
713a2b68bac4aeb1e9c48785006c0732451039depquerna lua_pushnumber(L, size + 1); /* [#, array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pushstring(L, value); /* [string, #, array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe }
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* L is [table<s,t>, table<s,s>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* build simple */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_getfield(L, -2, key); /* [VALUE, table<s,s>, table<s,t>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (lua_isnoneornil(L, -1)) { /* only set if not already set */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pop(L, 1); /* [table<s,s>, table<s,t>]] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pushstring(L, value); /* [string, table<s,s>, table<s,t>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_setfield(L, -3, key); /* [table<s,s>, table<s,t>] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } else { lua_pop(L, 1); }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return 1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes/* r:parseargs() returning a lua table */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int req_parseargs(lua_State* L) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_rec* r = apw_check_request_rec(L, 1);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe lua_newtable(L);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_newtable(L); /* [table, table] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_table_t* form_table;
fa123db15501821e36e513afa78e839775ad2800covener ap_args_to_table(r, &form_table);
fa123db15501821e36e513afa78e839775ad2800covener apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
fa123db15501821e36e513afa78e839775ad2800covener return 2; /* [table<string, string>, table<string, array<string>>] */
fa123db15501821e36e513afa78e839775ad2800covener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
fa123db15501821e36e513afa78e839775ad2800covener/* wrap ap_rputs as r:puts(String) */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int req_puts(lua_State* L) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener request_rec* r = apw_check_request_rec(L, 1);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int argc = lua_gettop(L);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int i;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener for (i=2;i<=argc;i++) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rputs(luaL_checkstring(L, i), r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* wrap ap_rwrite as r:write(String) */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int req_write(lua_State* L) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_rec* r = apw_check_request_rec(L, 1);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe size_t n;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char* buf = luaL_checklstring(L, 2, &n);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_rwrite((void *)buf, n, r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* r:parsebody() */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int req_parsebody(lua_State* L) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_rec* r = apw_check_request_rec(L, 1);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_newtable(L);
fa123db15501821e36e513afa78e839775ad2800covener lua_newtable(L);
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener apr_table_t* form_table;
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener if (ap_body_to_table(r, &form_table) == APR_SUCCESS) {
fa123db15501821e36e513afa78e839775ad2800covener apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener }
f2be127030aa4190033084f0a6add531c9bc41desf return 2;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* r:addoutputfilter(name|function) */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int req_add_output_filter(lua_State *L) {
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener request_rec* r = apw_check_request_rec(L, 1);
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener const char *name = luaL_checkstring(L, 2);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "adding output filter %s", name);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_add_output_filter(name, L, r, r->connection);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return 0;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int req_document_root(lua_State* L) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener request_rec* r = apw_check_request_rec(L, 1);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char* doc_root = apr_pstrdup(r->pool, ap_document_root(r));
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener lua_pushstring(L, doc_root);
6683642c1e0032eeeed5f99e8c14880692ef84c5sf return 1;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* BEGIN dispatch mathods for request_rec fields */
6683642c1e0032eeeed5f99e8c14880692ef84c5sf
6683642c1e0032eeeed5f99e8c14880692ef84c5sfstatic char* req_uri_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->uri;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_method_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->method;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_hostname_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->hostname;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_args_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->args;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_path_info_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->path_info;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const char* req_canonical_filename_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->canonical_filename;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_filename_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->filename;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_user_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->user;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_unparsed_uri_field(request_rec* r) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return r->unparsed_uri;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic const char* req_ap_auth_type_field(request_rec* r) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return r->ap_auth_type;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const char* req_content_encoding_field(request_rec* r) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return r->content_encoding;
0e05808dc59a321566303084c84b9826a4353cefrederpj}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
b08925593f214f621161742925dcf074a8047e0acovenerstatic const char* req_content_type_field(request_rec* r) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return r->content_type;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfstatic const char* req_range_field(request_rec* r) {
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj return r->range;
e8f95a682820a599fe41b22977010636be5c2717jim}
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholesstatic const char* req_protocol_field(request_rec* r) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return r->protocol;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic const char* req_the_request_field(request_rec* r) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return r->the_request;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
ebe5305f8b22507374358f32b74d12fb50c05a25covenerstatic int req_status_field(request_rec* r) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return r->status;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic int req_assbackwards_field(request_rec* r) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return r->assbackwards;
513b324e774c559b579896df131fd7c8471ed529rederpj}
513b324e774c559b579896df131fd7c8471ed529rederpj
513b324e774c559b579896df131fd7c8471ed529rederpj/* END dispatch mathods for request_rec fields */
513b324e774c559b579896df131fd7c8471ed529rederpj
513b324e774c559b579896df131fd7c8471ed529rederpjstatic int req_dispatch(lua_State* L) {
513b324e774c559b579896df131fd7c8471ed529rederpj request_rec* r = apw_check_request_rec(L, 1);
513b324e774c559b579896df131fd7c8471ed529rederpj const char *name = luaL_checkstring(L, 2);
513b324e774c559b579896df131fd7c8471ed529rederpj lua_pop(L, 2);
513b324e774c559b579896df131fd7c8471ed529rederpj
513b324e774c559b579896df131fd7c8471ed529rederpj lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_t* dispatch = lua_touserdata(L, 1);
02fd88c85a9850109753b87612955ad372de1575sf lua_pop(L, 1);
02fd88c85a9850109753b87612955ad372de1575sf
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes req_fun_t* rft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (rft) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch(rft->type) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case APW_REQ_FUNTYPE_TABLE: {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "request_rec->dispatching %s -> apr table (NOT IMPLEMENTED YET)", name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case APW_REQ_FUNTYPE_LUACFUN: {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "request_rec->dispatching %s -> lua_CFunction", name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_CFunction func = rft->fun;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pushcfunction(L, func);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener return 1;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
fa123db15501821e36e513afa78e839775ad2800covener case APW_REQ_FUNTYPE_STRING: {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener "request_rec->dispatching %s -> string", name);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener req_field_string_f func = rft->fun;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener char* rs = (*func)(r);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_pushstring(L, rs);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener return 1;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
9ad7b260be233be7d7b5576979825cac72e15498rederpj case APW_REQ_FUNTYPE_INT: {
9ad7b260be233be7d7b5576979825cac72e15498rederpj ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "request_rec->dispatching %s -> int", name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes req_field_int_f func = rft->fun;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin int rs = (*func)(r);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushnumber(L, rs);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 1;
ebe5305f8b22507374358f32b74d12fb50c05a25covener }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes case APW_REQ_FUNTYPE_BOOLEAN: {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "request_rec->dispatching %s -> boolean", name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes req_field_int_f func = rft->fun;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes int rs = (*func)(r);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin lua_pushboolean(L, rs);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
ebe5305f8b22507374358f32b74d12fb50c05a25covener
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "nothing for %s", name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* helper function for the logging functions below */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic int req_log_at(lua_State* L, int level) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes request_rec* r = apw_check_request_rec(L, 1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_Debug dbg;
b08925593f214f621161742925dcf074a8047e0acovener
b08925593f214f621161742925dcf074a8047e0acovener lua_getstack(L, 1, &dbg);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_getinfo(L, "Sl", &dbg);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener const char* msg = luaL_checkstring(L, 2);
9ad7b260be233be7d7b5576979825cac72e15498rederpj ap_log_rerror(dbg.source, dbg.currentline, level, 0, r, msg);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener return 0;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener}
9ad7b260be233be7d7b5576979825cac72e15498rederpj
707f6d077f73cc948deead8df5b40ea42c1eaa78covener/* r:debug(String) and friends which use apache logging */
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_emerg(lua_State* L) { req_log_at(L, APLOG_EMERG); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_alert(lua_State* L) { req_log_at(L, APLOG_ALERT); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_crit(lua_State* L) { req_log_at(L, APLOG_CRIT); return 0; }
9ad7b260be233be7d7b5576979825cac72e15498rederpjstatic int req_err(lua_State* L) { req_log_at(L, APLOG_ERR); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_warn(lua_State* L) { req_log_at(L, APLOG_WARNING); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_notice(lua_State* L) { req_log_at(L, APLOG_NOTICE); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_info(lua_State* L) { req_log_at(L, APLOG_INFO); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_debug(lua_State* L) { req_log_at(L, APLOG_DEBUG); return 0; }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener/* handle r.status = 201 */
707f6d077f73cc948deead8df5b40ea42c1eaa78covenerstatic int req_newindex(lua_State* L) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /* request_rec* r = lua_touserdata(L, lua_upvalueindex(1)); */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /* const char* key = luaL_checkstring(L, -2); */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener request_rec* r = apw_check_request_rec(L, 1);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener rstack_dump(L, r, "req_newindex");
707f6d077f73cc948deead8df5b40ea42c1eaa78covener const char *key = luaL_checkstring(L, 2);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener rstack_dump(L, r, "req_newindex");
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (0 == apr_strnatcmp("status", key)) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener int code = luaL_checkinteger(L, 3);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener r->status = code;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener luaL_getmetatable(L, "Apache2.Request");
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_pushinteger(L, code);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_setfield(L, -2, "status");
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_pop(L, 1);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener return 0;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (0 == apr_strnatcmp("content_type", key)) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener const char* value = luaL_checkstring(L, 3);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener r->content_type = apr_pstrdup(r->pool, value);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener luaL_getmetatable(L, "Apache2.Request");
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_pushstring(L, value);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener lua_setfield(L, -2, "content_type");
9ad7b260be233be7d7b5576979825cac72e15498rederpj lua_pop(L, 1);
9ad7b260be233be7d7b5576979825cac72e15498rederpj return 0;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
7add8f7fb048534390571801b7794f71cd9e127abnicholes
7add8f7fb048534390571801b7794f71cd9e127abnicholes if (0 == apr_strnatcmp("filename", key)) {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem const char* value = luaL_checkstring(L, 3);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem r->filename = apr_pstrdup(r->pool, value);
7add8f7fb048534390571801b7794f71cd9e127abnicholes luaL_getmetatable(L, "Apache2.Request");
7add8f7fb048534390571801b7794f71cd9e127abnicholes lua_pushstring(L, value);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_setfield(L, -2, "filename");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pop(L, 1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (0 == apr_strnatcmp("uri", key)) {
7add8f7fb048534390571801b7794f71cd9e127abnicholes const char* value = luaL_checkstring(L, 3);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes r->uri = apr_pstrdup(r->pool, value);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes luaL_getmetatable(L, "Apache2.Request");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushstring(L, value);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_setfield(L, -2, "uri");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pop(L, 1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushstring(L, apr_psprintf(r->pool, "Property [%s] may not be set on a request_rec", key));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_error(L);
7add8f7fb048534390571801b7794f71cd9e127abnicholes return 0;
7add8f7fb048534390571801b7794f71cd9e127abnicholes}
141e1368614dc7564e1627671361b01b4869b491bnicholes
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholesstatic const struct luaL_Reg request_methods[] = {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes {"__index", req_dispatch},
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf {"__newindex", req_newindex},
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* {"__newindex", req_set_field}, */
e8f95a682820a599fe41b22977010636be5c2717jim {NULL, NULL}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes};
ebe5305f8b22507374358f32b74d12fb50c05a25covener
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic const struct luaL_Reg connection_methods[] = {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes {NULL, NULL}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes};
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholesstatic const struct luaL_Reg server_methods[] = {
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes {NULL, NULL}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf};
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfstatic req_fun_t* makefun(void* fun, int type, apr_pool_t* pool) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf req_fun_t* rft = apr_palloc(pool, sizeof(req_fun_t));
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf rft->fun = fun;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf rft->type = type;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf return rft;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfvoid apw_load_request_lmodule(lua_State *L, apr_pool_t *p) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_hash_t* dispatch = apr_hash_make(p);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf makefun(&req_puts, APW_REQ_FUNTYPE_LUACFUN, p));
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf makefun(&req_write, APW_REQ_FUNTYPE_LUACFUN, p));
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_document_root, APW_REQ_FUNTYPE_LUACFUN, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING,
e8f95a682820a599fe41b22977010636be5c2717jim makefun(&req_parseargs, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_parsebody, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_debug, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_info, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_notice, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(req_warn, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_err, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_crit, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_alert, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_emerg, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "add_output_filter", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_add_output_filter, APW_REQ_FUNTYPE_LUACFUN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_assbackwards_field, APW_REQ_FUNTYPE_BOOLEAN, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_status_field, APW_REQ_FUNTYPE_INT, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "protocol", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_protocol_field, APW_REQ_FUNTYPE_STRING, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "range", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_range_field, APW_REQ_FUNTYPE_STRING, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "content_type", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_content_type_field, APW_REQ_FUNTYPE_STRING, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "content_encoding", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_content_encoding_field, APW_REQ_FUNTYPE_STRING, p));
7dbf29be626018bc389ef94c1846aeac4b72633bsf apr_hash_set(dispatch, "ap_auth_type", APR_HASH_KEY_STRING,
7dbf29be626018bc389ef94c1846aeac4b72633bsf makefun(&req_ap_auth_type_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "unparsed_uri", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_unparsed_uri_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "user", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_user_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "filename", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_filename_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "canonical_filename", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_canonical_filename_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "path_info", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_path_info_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "args", APR_HASH_KEY_STRING,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf makefun(&req_args_field, APW_REQ_FUNTYPE_STRING, p));
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf apr_hash_set(dispatch, "hostname", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_hostname_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "uri", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_uri_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "the_request", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_the_request_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_hash_set(dispatch, "method", APR_HASH_KEY_STRING,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes makefun(&req_method_field, APW_REQ_FUNTYPE_STRING, p));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushlightuserdata(L, dispatch);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes luaL_newmetatable(L, "Apache2.Request"); /* [metatable] */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushvalue(L, -1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_setfield(L, -2, "__index");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes luaL_register(L, NULL, request_methods); /* [metatable] */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pop(L, 2);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes luaL_newmetatable(L, "Apache2.Connection"); /* [metatable] */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_pushvalue(L, -1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes lua_setfield(L, -2, "__index");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes luaL_register(L, NULL, connection_methods); /* [metatable] */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_pop(L, 2);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf luaL_newmetatable(L, "Apache2.Server"); /* [metatable] */
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf lua_pushvalue(L, -1);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_setfield(L, -2, "__index");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf luaL_register(L, NULL, server_methods); /* [metatable] */
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
7dbf29be626018bc389ef94c1846aeac4b72633bsf lua_pop(L, 2);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
e8f95a682820a599fe41b22977010636be5c2717jimvoid apw_push_connection(lua_State* L, conn_rec* c) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_boxpointer(L, c);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes luaL_getmetatable(L, "Apache2.Connection");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes lua_setmetatable(L, -2);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf luaL_getmetatable(L, "Apache2.Connection");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apw_push_apr_table(L, "notes", c->notes);
7dbf29be626018bc389ef94c1846aeac4b72633bsf
7dbf29be626018bc389ef94c1846aeac4b72633bsf lua_pushstring(L, c->remote_ip);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf lua_setfield(L, -2, "remote_ip");
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf lua_pop(L, 1);
9c63a05713cb83a44a1590b4af33edeebf39f118sf}
9c63a05713cb83a44a1590b4af33edeebf39f118sf
9c63a05713cb83a44a1590b4af33edeebf39f118sf
9c63a05713cb83a44a1590b4af33edeebf39f118sfvoid apw_push_server(lua_State* L, server_rec* s) {
9c63a05713cb83a44a1590b4af33edeebf39f118sf lua_boxpointer(L, s);
9c63a05713cb83a44a1590b4af33edeebf39f118sf luaL_getmetatable(L, "Apache2.Server");
9c63a05713cb83a44a1590b4af33edeebf39f118sf lua_setmetatable(L, -2);
9c63a05713cb83a44a1590b4af33edeebf39f118sf luaL_getmetatable(L, "Apache2.Server");
9c63a05713cb83a44a1590b4af33edeebf39f118sf
9c63a05713cb83a44a1590b4af33edeebf39f118sf lua_pushstring(L, s->server_hostname);
9c63a05713cb83a44a1590b4af33edeebf39f118sf lua_setfield(L, -2, "server_hostname");
9c63a05713cb83a44a1590b4af33edeebf39f118sf
9c63a05713cb83a44a1590b4af33edeebf39f118sf lua_pop(L, 1);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfvoid apw_push_request(lua_State* L, request_rec* r) {
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf lua_boxpointer(L, r);
9efd5708f6f0ab1992f6a5233eb622ad5e4eae18sf luaL_getmetatable(L, "Apache2.Request");
9efd5708f6f0ab1992f6a5233eb622ad5e4eae18sf lua_setmetatable(L, -2);
9efd5708f6f0ab1992f6a5233eb622ad5e4eae18sf}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes