Commit 165371df authored by Paul Querna's avatar Paul Querna
Browse files

Merge mod_wombat from the wombat branch:

parent f235fb05
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1005,6 +1005,7 @@ struct request_rec {

    apr_thread_mutex_t *invoke_mtx;

    apr_table_t *body_table;
/* Things placed at the end of the record to avoid breaking binary
 * compatibility.  It would be nice to remember to reorder the entire
 * record to improve 64bit alignment the next time we need to break
+4 −0
Original line number Diff line number Diff line
@@ -140,6 +140,10 @@ AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
				       int (*getsfunc) (char *, int, void *),
				       void *getsfunc_data);

AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table);

AP_DECLARE(apr_status_t) ap_body_to_table(request_rec *r, apr_table_t **table);
    
#ifdef __cplusplus
}
#endif
+3 −0
Original line number Diff line number Diff line
# a modules Makefile has no explicit targets -- they will be defined by
# whatever modules are enabled. just grab special.mk to deal with this.
include $(top_srcdir)/build/special.mk

modules/wombat/README

0 → 100644
+77 −0
Original line number Diff line number Diff line
-*- mode:org -*-
* Requirements:
** lua 5.1 ( http://www.lua.org/ )
** libapreq2 ( http://httpd.apache.org/apreq/download.cgi )
** Apache HTTPD 2.2 ( http://httpd.apache.org/ )

* Documentation
  See docs/README

* Building
  For now, see docs/building-from-subversion.txt

* To Consider
  Allow definition of lua_State instances associated with arbitrary
  pool using the pool's user_data constuct. There would, here, be two
  types, pooled and singleton. On the other hand, singleton would work
  fine for almost all cases -- the exception being a process or server
  pool, and then we could stay singleton anyway and lock around it.

  The current "server scope" behavior could, instead, fall into
  connection scope, for long-lived connections, really we want thread
  scope (which Brian Akins knows how to do). Is there a pool
  associated with a thread? Contention on the pool is a pain in a
  highly concurrent environment.

  Could use apr_thread_data_(get|set) if I can find a way to hook into
  thread destruction. Looks like apr threads let you use the standard
  APR_POOL_DECLARE_ACCESSOR(thread); defined method, just need to look
  up what form that takes. -- apr_thread_pool_get -- just attach to
  that pool.

  Given that, we can associate a hash of lua_State instances with
  arbitrary pools, such as the request pool, thread pool, server pool,
  etc. We then use the file as key into the hash. Users, able to
  specify the handler function, can then make use of the same file
  with different handlers to reuse states.

  

* Task List
** TODO Use r->file to determine file, doing rewriting in translate_name   
** TODO Change to controlling lifecycle by passing in a pool?
   Need to determine how to handle server scoped then!
** TODO Provide means to get useful output from lua errors in response body
   Probably have to put it on the vm spec for pre-handler errors, as
   it is pre-handler, will prolly be on the request_config somewhere,
   but sometimes cannot put there, so... fun
** TODO Filters
** TODO Mapping in the server_rec
** TODO Connection scoped vms
** TODO Figure out how reentrancy works regarding filter chain stuff. 
   Do we need new "threads"?
** TODO Flesh out apw_*getvm for each flavor we allow
** TODO Rework apw_sgetvm to use the create_vm stuff like apw_rgetvm
** TODO apw_rgetvm needs to handle connection scoped vms     
** TODO options in server scoped vms (ie, min and max vm counts)
    
* License
  Apache License, Version 2.0,
  
  http://www.apache.org/licenses/LICENSE-2.0 

  See NOTICE file for more information
        
* Problems and Patches:
  Please use dev@httpd.apache.org for discussing mod_wombat development
  To subscribe send email to dev-subscribe@httpd.apache.org  
  Note that this is for development discussion, not user support :-)
   
* Contributors Include
** Brian McCallister
** Paul Querna
** Garrett Rooney
** Martin Traverso
** Brian Akins
** Justin Erenkrantz
** Philip M. Gollucci
+71 −0
Original line number Diff line number Diff line
#include "apr.h"
#include "apr_tables.h"

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

/**
 * make a userdata out of a C pointer, and vice versa
 * instead of using lightuserdata
 */
#ifndef lua_boxpointer
#define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))
#define lua_unboxpointer(L,i)	(*(void **)(lua_touserdata(L, i)))
#endif


apr_table_t* check_apr_table(lua_State* L, int index) {
    luaL_checkudata(L, index, "Apr.Table");
    apr_table_t* t = (apr_table_t*)lua_unboxpointer(L, index);
    return t;
}


void apw_push_apr_table(lua_State* L, const char *name, apr_table_t *t) {
    lua_boxpointer(L, t);    
    luaL_getmetatable(L, "Apr.Table");
    lua_setmetatable(L, -2);
    lua_setfield(L, -2, name);
}

static int lua_table_set(lua_State* L) {
    apr_table_t *t = check_apr_table(L, 1);
    const char* key = luaL_checkstring(L, 2);
    const char* val = luaL_checkstring(L, 3);

    apr_table_set(t, key, val);
    return 0;
}

static int lua_table_get(lua_State* L) {
    apr_table_t *t = check_apr_table(L, 1);
    const char* key = luaL_checkstring(L, 2);
    const char *val = apr_table_get(t, key);
    lua_pushstring(L, val);
    return 1;
}

static const luaL_reg lua_table_methods[] = {
    {"set", lua_table_set},
    {"get", lua_table_get},
    {0, 0}
};


int apr_lua_init(lua_State *L, apr_pool_t *p) {
    luaL_newmetatable(L, "Apr.Table");
    luaL_openlib(L, "apr_table", lua_table_methods, 0);
    lua_pushstring(L, "__index");
    lua_pushstring(L, "get");
    lua_gettable(L, 2);
    lua_settable(L, 1);

    lua_pushstring(L, "__newindex");
    lua_pushstring(L, "set");
    lua_gettable(L, 2);
    lua_settable(L, 1);
    
    return 0;
}
Loading