You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2008/11/05 19:03:42 UTC

svn commit: r711639 - in /httpd/mod_wombat/trunk: request.c request.h

Author: brianm
Date: Wed Nov  5 10:03:42 2008
New Revision: 711639

URL: http://svn.apache.org/viewvc?rev=711639&view=rev
Log:
still broken, but getting way better!

Modified:
    httpd/mod_wombat/trunk/request.c
    httpd/mod_wombat/trunk/request.h

Modified: httpd/mod_wombat/trunk/request.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.c?rev=711639&r1=711638&r2=711639&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.c (original)
+++ httpd/mod_wombat/trunk/request.c Wed Nov  5 10:03:42 2008
@@ -18,6 +18,8 @@
 #include "mod_wombat.h"
 #include "apr_lua.h"
 
+typedef char* (*req_field_string_f) (request_rec* r);
+
 void rstack_dump(lua_State* L, request_rec* r, const char* msg) {
     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Lua Stack Dump: [%s]", msg);
 
@@ -64,9 +66,14 @@
                               "%d:  <table>", i);
                 break;
             }
+            case LUA_TFUNCTION: {
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+                              "%d:  <function>", i);
+                break;
+            }
             default: {
                 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
-                              "%d:  unkown: [%s]", i, lua_typename(L, i));
+                              "%d:  unkown: -[%s]-", i, lua_typename(L, i));
                 break;                
             }
         }
@@ -193,23 +200,42 @@
   return 1;
 }
 
+static char* req_uri_field(request_rec* r) {
+    return r->uri;
+}
+
+static const char* req_method_field(request_rec* r) {
+    return r->method;
+}
+
 static int req_dispatch(lua_State* L) {
-  request_rec* r = check_request_rec(L, 1);
-  const char *name = luaL_checkstring(L, 2);
-  ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "dispatching %s", name);
-  lua_pop(L, 2);
+    request_rec* r = check_request_rec(L, 1);
+    const char *name = luaL_checkstring(L, 2);
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "dispatching %s", name);
+    lua_pop(L, 2);
  
-  lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
-  apr_hash_t* dispatch = lua_touserdata(L, 1);
-  lua_pop(L, 1);
-  lua_CFunction* func = (lua_CFunction*) apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
-  if (!func) {
-      ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "no function for %s", name);
-      
-      return 0;
-  }
-  lua_pushcfunction(L, func);
-  return 1;
+    lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.functions");
+    apr_hash_t* dispatch = lua_touserdata(L, 1);
+    lua_pop(L, 1);
+    lua_CFunction* func = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
+    if (func) {
+        lua_pushcfunction(L, func);      
+        return 1;
+    }
+    
+    lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.string_fields");
+    apr_hash_t* fields = lua_touserdata(L, 1);
+    lua_pop(L, 1);
+    req_field_string_f rf_func = apr_hash_get(fields, name, APR_HASH_KEY_STRING);
+    if (rf_func) {
+        char* rs = (*rf_func)(r);
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got field %s -> %s", name, rs);
+        lua_pushstring(L, rs);
+        return 1;
+    }
+    
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "nothing for %s", name);  
+    return 0;
 }
 
 // helper function for the logging functions below
@@ -237,11 +263,14 @@
 
 // handle r.status = 201
 static int req_newindex(lua_State* L) {
-    request_rec* r = lua_touserdata(L, lua_upvalueindex(1));    
-    const char* key = luaL_checkstring(L, -2);
-    
+    // request_rec* r = lua_touserdata(L, lua_upvalueindex(1));    
+    // const char* key = luaL_checkstring(L, -2);
+    request_rec* r = check_request_rec(L, 1);
+    rstack_dump(L, r, "req_newindex");
+    const char *key = luaL_checkstring(L, 2);
+    rstack_dump(L, r, "req_newindex");
     if (0 == apr_strnatcmp("status", key)) {
-        int code = luaL_checkinteger(L, -1);
+        int code = luaL_checkinteger(L, 3);
         r->status = code;
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushinteger(L, code);
@@ -251,7 +280,7 @@
     }
     
     if (0 == apr_strnatcmp("content_type", key)) {
-        const char* value = luaL_checkstring(L, -1);
+        const char* value = luaL_checkstring(L, 3);
         r->content_type = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -261,7 +290,7 @@
     }
     
     if (0 == apr_strnatcmp("filename", key)) {
-        const char* value = luaL_checkstring(L, -1);
+        const char* value = luaL_checkstring(L, 3);
         r->filename = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -271,7 +300,7 @@
     }
 
     if (0 == apr_strnatcmp("uri", key)) {
-        const char* value = luaL_checkstring(L, -1);
+        const char* value = luaL_checkstring(L, 3);
         r->uri = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -287,6 +316,7 @@
 
 static const struct luaL_Reg request_methods[] = {
     {"__index", req_dispatch},
+    {"__newindex", req_newindex},
     //   {"__newindex", req_set_field},    
     {NULL, NULL}
 };
@@ -309,8 +339,6 @@
     apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING, &req_document_root);
     apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING, &req_parseargs);
     apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING, &req_parsebody);
-    
-    
     apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING, &req_debug);
     apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING, &req_info);
     apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING, &req_notice);
@@ -319,9 +347,18 @@
     apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING, &req_crit);
     apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING, &req_alert);
     apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING, &req_emerg);
-    
     lua_pushlightuserdata(L, dispatch);
-    lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
+    lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.functions");
+    
+    
+    apr_hash_t* string_fields = apr_hash_make(p);
+    apr_hash_set(string_fields, "uri", APR_HASH_KEY_STRING, &req_uri_field);
+    apr_hash_set(string_fields, "method", APR_HASH_KEY_STRING, &req_method_field);
+    lua_pushlightuserdata(L, string_fields);
+    lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.string_fields");
+    
+    
+    
     
     luaL_newmetatable(L, "Apache2.Request"); // [metatable]
     lua_pushvalue(L, -1); 
@@ -381,9 +418,9 @@
     luaL_getmetatable(L, "Apache2.Request");
     lua_setmetatable(L, -2);
     luaL_getmetatable(L, "Apache2.Request");
-    rstack_dump(L, r, "apw_push_request pre pop");
+//    rstack_dump(L, r, "apw_push_request pre pop");
     lua_pop(L, 1);
-    rstack_dump(L, r, "apw_push_request post pop");
+//    rstack_dump(L, r, "apw_push_request post pop");
     // lua_pushinteger(L, r->status);
     // lua_setfield(L, -2, "status");
         

Modified: httpd/mod_wombat/trunk/request.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.h?rev=711639&r1=711638&r2=711639&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.h (original)
+++ httpd/mod_wombat/trunk/request.h Wed Nov  5 10:03:42 2008
@@ -21,5 +21,15 @@
 APR_DECLARE(void) apw_push_request(lua_State* L, request_rec* r);
 APR_DECLARE(void) apw_load_request_lmodule(lua_State *L, apr_pool_t *p);
 
+#define APW_REQ_FUNTYPE_STRING      1
+#define APW_REQ_FUNTYPE_INT         2
+#define APW_REQ_FUNTYPE_TABLE       3
+
+typedef struct {
+    void *fun;
+    int type;
+} req_funt;
+
+
 #endif