httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r737293 - in /httpd/httpd/trunk/modules/lua: lua_apr.c lua_apr.h lua_request.c test/htdocs/headers.lua
Date Sat, 24 Jan 2009 03:10:40 GMT
Author: brianm
Date: Sat Jan 24 03:10:40 2009
New Revision: 737293

URL: http://svn.apache.org/viewvc?rev=737293&view=rev
Log:
changes headers_in and headers_out handling in mod_lua to map apr_table_t instances as boxed
pointers

Added:
    httpd/httpd/trunk/modules/lua/test/htdocs/headers.lua
Modified:
    httpd/httpd/trunk/modules/lua/lua_apr.c
    httpd/httpd/trunk/modules/lua/lua_apr.h
    httpd/httpd/trunk/modules/lua/lua_request.c

Modified: httpd/httpd/trunk/modules/lua/lua_apr.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_apr.c?rev=737293&r1=737292&r2=737293&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_apr.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_apr.c Sat Jan 24 03:10:40 2009
@@ -41,12 +41,11 @@
 }
 
 
-void apl_push_apr_table(lua_State *L, const char *name, apr_table_t *t)
+void apl_push_apr_table(lua_State *L, 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)

Modified: httpd/httpd/trunk/modules/lua/lua_apr.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_apr.h?rev=737293&r1=737292&r2=737293&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_apr.h (original)
+++ httpd/httpd/trunk/modules/lua/lua_apr.h Sat Jan 24 03:10:40 2009
@@ -20,6 +20,6 @@
 
 int apr_lua_init(lua_State *L, apr_pool_t * p);
 apr_table_t *check_apr_table(lua_State *L, int index);
-void apl_push_apr_table(lua_State *L, const char *name, apr_table_t *t);
+void apl_push_apr_table(lua_State *L, apr_table_t *t);
 
 #endif /* !_LUA_APR_H_ */

Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=737293&r1=737292&r2=737293&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Sat Jan 24 03:10:40 2009
@@ -21,6 +21,7 @@
 
 typedef char *(*req_field_string_f) (request_rec * r);
 typedef int (*req_field_int_f) (request_rec * r);
+typedef apr_table_t *(*req_field_apr_table_f) (request_rec * r);
 
 void apl_rstack_dump(lua_State *L, request_rec *r, const char *msg)
 {
@@ -213,8 +214,7 @@
 static int req_document_root(lua_State *L)
 {
     request_rec *r = apl_check_request_rec(L, 1);
-    char *doc_root = apr_pstrdup(r->pool, ap_document_root(r));
-    lua_pushstring(L, doc_root);
+    lua_pushstring(L, ap_document_root(r));
     return 1;
 }
 
@@ -305,6 +305,17 @@
     return r->assbackwards;
 }
 
+static apr_table_t* req_headers_in(request_rec *r)
+{
+    return r->headers_in;
+}
+
+static apr_table_t* req_headers_out(request_rec *r)
+{
+    return r->headers_out;
+}
+
+
 /* END dispatch mathods for request_rec fields */
 
 static int req_dispatch(lua_State *L)
@@ -323,10 +334,14 @@
     if (rft) {
         switch (rft->type) {
         case APL_REQ_FUNTYPE_TABLE:{
+                req_field_apr_table_f func = rft->fun;
                 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
-                              "request_rec->dispatching %s -> apr table (NOT IMPLEMENTED
YET)",
+                              "request_rec->dispatching %s -> apr table",
                               name);
-                return 0;
+                apr_table_t *rs;
+                rs = (*func)(r);
+                apl_push_apr_table(L, rs);          
+                return 1;
             }
 
         case APL_REQ_FUNTYPE_LUACFUN:{
@@ -428,25 +443,6 @@
     return 0;
 }
 
-static int req_headers_in(lua_State *L)
-{
-    const char *key;
-    const char *value;
-    request_rec *r = apl_check_request_rec(L, 1);
-
-    key = luaL_checkstring(L, 2);
-
-    value = apr_table_get(r->headers_in, key);
-    if (value) {
-        lua_pushstring(L, value);
-    }
-    else {
-        lua_pushnil(L);
-    }
-
-    return 1;
-}
-
 /* handle r.status = 201 */
 static int req_newindex(lua_State *L)
 {
@@ -603,7 +599,11 @@
                  makefun(&req_method_field, APL_REQ_FUNTYPE_STRING, p));
 
     apr_hash_set(dispatch, "headers_in", APR_HASH_KEY_STRING,
-                 makefun(&req_headers_in, APL_REQ_FUNTYPE_LUACFUN, p));
+                 makefun(&req_headers_in, APL_REQ_FUNTYPE_TABLE, p));
+
+    apr_hash_set(dispatch, "headers_out", APR_HASH_KEY_STRING,
+                 makefun(&req_headers_out, APL_REQ_FUNTYPE_TABLE, p));
+
 
     lua_pushlightuserdata(L, dispatch);
     lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
@@ -641,7 +641,8 @@
     lua_setmetatable(L, -2);
     luaL_getmetatable(L, "Apache2.Connection");
 
-    apl_push_apr_table(L, "notes", c->notes);
+    apl_push_apr_table(L, c->notes);
+    lua_setfield(L, -2, "notes");
 
     lua_pushstring(L, c->remote_ip);
     lua_setfield(L, -2, "remote_ip");

Added: httpd/httpd/trunk/modules/lua/test/htdocs/headers.lua
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/test/htdocs/headers.lua?rev=737293&view=auto
==============================================================================
--- httpd/httpd/trunk/modules/lua/test/htdocs/headers.lua (added)
+++ httpd/httpd/trunk/modules/lua/test/htdocs/headers.lua Sat Jan 24 03:10:40 2009
@@ -0,0 +1,6 @@
+function handle(r)
+   local host = r.headers_in['host']
+   r:debug(host)
+   r:puts(host)
+   r.headers_out['wombat'] = 'lua'
+end



Mime
View raw message