httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r711665 - in /httpd/mod_wombat/trunk: request.c request.h
Date Wed, 05 Nov 2008 19:13:26 GMT
Author: brianm
Date: Wed Nov  5 11:13:25 2008
New Revision: 711665

URL: http://svn.apache.org/viewvc?rev=711665&view=rev
Log:
new request dispatch in and tests pass again!

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=711665&r1=711664&r2=711665&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.c (original)
+++ httpd/mod_wombat/trunk/request.c Wed Nov  5 11:13:25 2008
@@ -19,6 +19,7 @@
 #include "apr_lua.h"
 
 typedef char* (*req_field_string_f) (request_rec* r);
+typedef int (*req_field_int_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);
@@ -185,13 +186,13 @@
 }
 
 // r:addoutputfilter(name|function)
-static int req_add_output_filter(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, "adding output filter %s", name);
-    ap_add_output_filter(name, L, r, r->connection);
-    return 0;
-}
+// static int req_add_output_filter(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, "adding output filter %s", name);
+//     ap_add_output_filter(name, L, r, r->connection);
+//     return 0;
+// }
 
 static int req_document_root(lua_State* L) {
   request_rec* r = check_request_rec(L, 1);
@@ -208,30 +209,109 @@
     return r->method;
 }
 
+static const char* req_hostname_field(request_rec* r) {
+    return r->hostname;
+}
+
+static const char* req_args_field(request_rec* r) {
+    return r->args;
+}
+
+static const char* req_path_info_field(request_rec* r) {
+    return r->path_info;
+}
+
+static const char* req_canonical_filename_field(request_rec* r) {
+    return r->canonical_filename;
+}
+
+static const char* req_filename_field(request_rec* r) {
+    return r->filename;
+}
+
+static const char* req_user_field(request_rec* r) {
+    return r->user;
+}
+
+static const char* req_unparsed_uri_field(request_rec* r) {
+    return r->unparsed_uri;
+}
+
+static const char* req_ap_auth_type_field(request_rec* r) {
+    return r->ap_auth_type;
+}
+
+static const char* req_content_encoding_field(request_rec* r) {
+    return r->content_encoding;
+}
+
+static const char* req_content_type_field(request_rec* r) {
+    return r->content_type;
+}
+
+static const char* req_range_field(request_rec* r) {
+    return r->range;
+}
+
+static const char* req_protocol_field(request_rec* r) {
+    return r->protocol;
+}
+
+static const char* req_the_request_field(request_rec* r) {
+    return r->the_request;
+}
+
+static int req_status_field(request_rec* r) {
+    return r->status;
+}
+
+static int req_assbackwards_field(request_rec* r) {
+    return r->assbackwards;
+}
+
+
 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);
  
-    lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.functions");
+    lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
     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;
+    req_fun_t* rft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
+    if (rft) {
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "rft -> %d, type -> %d", (int)rft,
rft->type);
+        switch(rft->type) {
+            case APW_REQ_FUNTYPE_LUACFUN: {
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> lua_CFunction", name);
+                lua_CFunction func = rft->fun;
+                lua_pushcfunction(L, func);      
+                return 1;                
+            }
+            case APW_REQ_FUNTYPE_STRING: {
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> string", name);
+                req_field_string_f func = rft->fun;
+                char* rs = (*func)(r);
+                lua_pushstring(L, rs);
+                return 1;                
+            }
+            case APW_REQ_FUNTYPE_INT: {
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> int", name);
+                req_field_int_f func = rft->fun;
+                int rs = (*func)(r);
+                lua_pushnumber(L, rs);
+                return 1;                
+            }
+            case APW_REQ_FUNTYPE_BOOLEAN: {
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> boolean", name);
+                req_field_int_f func = rft->fun;
+                int rs = (*func)(r);
+                lua_pushboolean(L, rs);
+                return 1;                
+            }
+        }
     }
     
     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "nothing for %s", name);  
@@ -331,33 +411,58 @@
     {NULL, NULL}
 };
 
+
+static req_fun_t* makefun(void* fun, int type, apr_pool_t* pool) {
+    req_fun_t* rft = apr_palloc(pool, sizeof(req_fun_t));
+    rft->fun = fun;
+    rft->type = type;
+    return rft;
+}
+
 void apw_load_request_lmodule(lua_State *L, apr_pool_t *p) {
     
     apr_hash_t* dispatch = apr_hash_make(p);
-    apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING, &req_puts);
-    apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING, &req_write);
-    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);
-    apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING, &req_warn);
-    apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING, &req_err);
-    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.functions");
+    
+    apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING, makefun(&req_puts, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING, makefun(&req_write, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING, makefun(&req_document_root,
APW_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING, makefun(&req_parseargs,
APW_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING, makefun(&req_parsebody,
APW_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING, makefun(&req_debug, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING, makefun(&req_info, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING, makefun(&req_notice, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING, makefun(req_warn, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING, makefun(&req_err, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING, makefun(&req_crit, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING, makefun(&req_alert, APW_REQ_FUNTYPE_LUACFUN,
p));
+    apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING, makefun(&req_emerg, APW_REQ_FUNTYPE_LUACFUN,
p));
     
     
-    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");
+    // lua_pushinteger(L, r->status);
+    // lua_setfield(L, -2, "status");
     
+    apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING, makefun(&req_assbackwards_field,
APW_REQ_FUNTYPE_BOOLEAN, p));
+    apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING, makefun(&req_status_field,
APW_REQ_FUNTYPE_INT, p));
+    apr_hash_set(dispatch, "protocol", APR_HASH_KEY_STRING, makefun(&req_protocol_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "range", APR_HASH_KEY_STRING, makefun(&req_range_field, APW_REQ_FUNTYPE_STRING,
p));
+    apr_hash_set(dispatch, "content_type", APR_HASH_KEY_STRING, makefun(&req_content_type_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "content_encoding", APR_HASH_KEY_STRING, 
+                 makefun(&req_content_encoding_field, APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "ap_auth_type", APR_HASH_KEY_STRING, makefun(&req_ap_auth_type_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "unparsed_uri", APR_HASH_KEY_STRING, makefun(&req_unparsed_uri_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "user", APR_HASH_KEY_STRING, makefun(&req_user_field, APW_REQ_FUNTYPE_STRING,
p));
+    apr_hash_set(dispatch, "filename", APR_HASH_KEY_STRING, makefun(&req_filename_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "canonical_filename", 
+                APR_HASH_KEY_STRING, makefun(&req_canonical_filename_field, APW_REQ_FUNTYPE_STRING,
p));
+    apr_hash_set(dispatch, "path_info", APR_HASH_KEY_STRING, makefun(&req_path_info_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "args", APR_HASH_KEY_STRING, makefun(&req_args_field, APW_REQ_FUNTYPE_STRING,
p));
+    apr_hash_set(dispatch, "hostname", APR_HASH_KEY_STRING, makefun(&req_hostname_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "uri", APR_HASH_KEY_STRING, makefun(&req_uri_field, APW_REQ_FUNTYPE_STRING,
p));
+    apr_hash_set(dispatch, "the_request", APR_HASH_KEY_STRING, makefun(&req_the_request_field,
APW_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "method", APR_HASH_KEY_STRING, makefun(&req_method_field,
APW_REQ_FUNTYPE_STRING, p));
     
+    lua_pushlightuserdata(L, dispatch);
+    lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
     
     
     luaL_newmetatable(L, "Apache2.Request"); // [metatable]

Modified: httpd/mod_wombat/trunk/request.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.h?rev=711665&r1=711664&r2=711665&view=diff
==============================================================================
--- httpd/mod_wombat/trunk/request.h (original)
+++ httpd/mod_wombat/trunk/request.h Wed Nov  5 11:13:25 2008
@@ -24,11 +24,13 @@
 #define APW_REQ_FUNTYPE_STRING      1
 #define APW_REQ_FUNTYPE_INT         2
 #define APW_REQ_FUNTYPE_TABLE       3
+#define APW_REQ_FUNTYPE_LUACFUN     4
+#define APW_REQ_FUNTYPE_BOOLEAN     5
 
 typedef struct {
     void *fun;
     int type;
-} req_funt;
+} req_fun_t;
 
 
 #endif



Mime
View raw message