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 2007/05/02 20:34:00 UTC
svn commit: r534582 - in /httpd/mod_wombat/trunk: Makefile.in mod_wombat.c
mod_wombat.h request.c request.h vmprep.c
Author: brianm
Date: Wed May 2 11:33:59 2007
New Revision: 534582
URL: http://svn.apache.org/viewvc?view=rev&rev=534582
Log:
Patch from Brian Akins
- use hooks for:
-- wombat_open - called by create_vm
-- wombat_request - called instead of apw_request_push
- added apr_lua.c and .h - only handles tables for now. Can be extended to do
more in future.
Modified:
httpd/mod_wombat/trunk/Makefile.in
httpd/mod_wombat/trunk/mod_wombat.c
httpd/mod_wombat/trunk/mod_wombat.h
httpd/mod_wombat/trunk/request.c
httpd/mod_wombat/trunk/request.h
httpd/mod_wombat/trunk/vmprep.c
Modified: httpd/mod_wombat/trunk/Makefile.in
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/Makefile.in?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/Makefile.in (original)
+++ httpd/mod_wombat/trunk/Makefile.in Wed May 2 11:33:59 2007
@@ -25,7 +25,7 @@
dist-clean: maintainer-clean
mod_wombat.la: mod_wombat.c
- $(COMPILE_APACHE_MOD) mod_wombat.c request.c vmprep.c config.c
+ $(COMPILE_APACHE_MOD) mod_wombat.c request.c vmprep.c config.c apr_lua.c
install-mods: mod_wombat.la
$(INSTALL_MOD_SHARED) -n wombat mod_wombat.la
Modified: httpd/mod_wombat/trunk/mod_wombat.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.c?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/mod_wombat.c (original)
+++ httpd/mod_wombat/trunk/mod_wombat.c Wed May 2 11:33:59 2007
@@ -20,6 +20,18 @@
#include <string.h>
#include <stdlib.h>
+#include "apr_lua.h"
+
+APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apw, WOMBAT, int, wombat_open,
+ (lua_State *L, apr_pool_t *p),
+ (L, p),
+ OK, DECLINED)
+
+APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apw, WOMBAT, int, wombat_request,
+ (lua_State *L, request_rec *r),
+ (L, r),
+ OK, DECLINED)
+
module AP_MODULE_DECLARE_DATA wombat_module;
/**
@@ -98,7 +110,7 @@
ap_rputs("Unable to compile VM, see logs", r);
}
lua_getglobal(L, d->function_name);
- apw_push_request(L, r);
+ apw_run_wombat_request(L, r);
if (lua_pcall(L, 1, 0, 0)) {
report_lua_error(L, r);
}
@@ -167,7 +179,7 @@
lua_State* L = apw_rgetvm(r, spec);
lua_getglobal(L, hook_spec->function_name);
- apw_push_request(L, r);
+ apw_run_wombat_request(L, r);
if (lua_pcall(L, 1, 1, 0)) {
report_lua_error(L, r);
return 500;
@@ -244,6 +256,12 @@
// ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "LuaHookInsertFilter not yet implemented");
}
+int wombat_quick_harness(request_rec *r, int lookup) {
+ if(lookup) {
+ return DECLINED;
+ }
+ return wombat_request_rec_hook_harness(r, "quick");
+}
static const char* register_translate_name_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
return register_named_file_function_hook("translate_name", cmd, _cfg, file, function);
@@ -277,6 +295,10 @@
return "LuaHookInsertFilter not yet implemented";
}
+static const char* register_quick_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
+ return register_named_file_function_hook("quick", cmd, _cfg, file, function);
+}
+
/**
* Called for config directive which looks like
* LuaPackagePath /lua/package/path/mapped/thing/like/this/?.lua
@@ -400,6 +422,9 @@
AP_INIT_TAKE1("LuaCodeCache", register_code_cache, NULL, OR_ALL,
"Configure the compiled code cache. \
Default is to stat the file each time, options are stat|forever|never"),
+
+ AP_INIT_TAKE2("LuaQuickHandler", register_quick_hook, NULL, OR_ALL,
+ "Provide a hook for the quick handler of request processing"),
{ NULL }
};
@@ -437,6 +462,19 @@
return cfg;
}
+static int wombat_open_hook(lua_State *L, apr_pool_t *p) {
+ apr_lua_init(L, p);
+ apw_load_apache2_lmodule(L);
+ apw_load_request_lmodule(L);
+ apw_load_config_lmodule(L);
+ return OK;
+}
+
+static int wombat_request_hook(lua_State *L, request_rec *r) {
+ apw_request_init(L, r);
+ return OK;
+}
+
static void wombat_register_hooks(apr_pool_t *p) {
// ap_register_output_filter("wombathood", wombathood, NULL, AP_FTYPE_RESOURCE);
ap_hook_handler(wombat_handler, NULL, NULL, APR_HOOK_MIDDLE);
@@ -451,9 +489,16 @@
ap_hook_access_checker(wombat_access_checker_harness, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_auth_checker(wombat_auth_checker_harness, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_insert_filter(wombat_insert_filter_harness, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_quick_handler(wombat_quick_harness, NULL, NULL, APR_HOOK_FIRST);
// ap_hook_translate_name(wombat_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_translate_name(apw_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_translate_name(apw_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
+
+ APR_OPTIONAL_HOOK(apw, wombat_open, wombat_open_hook, NULL, NULL,
+ APR_HOOK_REALLY_FIRST);
+
+ APR_OPTIONAL_HOOK(apw, wombat_request, wombat_request_hook, NULL, NULL,
+ APR_HOOK_REALLY_FIRST);
}
module AP_MODULE_DECLARE_DATA wombat_module = {
Modified: httpd/mod_wombat/trunk/mod_wombat.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/mod_wombat.h?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/mod_wombat.h (original)
+++ httpd/mod_wombat/trunk/mod_wombat.h Wed May 2 11:33:59 2007
@@ -1,3 +1,6 @@
+#ifndef MOD_WOMBAT_H
+#define MOD_WOMBAT_H
+
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -35,6 +38,7 @@
#include "apr_buckets.h"
#include "apr_file_info.h"
#include "apr_time.h"
+#include "apr_hooks.h"
#include "apreq_parser.h"
#include "apreq_param.h"
@@ -47,9 +51,6 @@
#include "request.h"
#include "vmprep.h"
-#ifndef MOD_WOMBAT_H
-#define MOD_WOMBAT_H
-
/**
* make a userdata out of a C pointer, and vice versa
@@ -110,6 +111,30 @@
extern module AP_MODULE_DECLARE_DATA wombat_module;
// module wombat_module;
+
+#if !defined(WIN32)
+#define WOMBAT_DECLARE(type) type
+#define WOMBAT_DECLARE_NONSTD(type) type
+#define WOMBAT_DECLARE_DATA
+#elif defined(WOMBAT_DECLARE_STATIC)
+#define WOMBAT_DECLARE(type) type __stdcall
+#define WOMBAT_DECLARE_NONSTD(type) type
+#define WOMBAT_DECLARE_DATA
+#elif defined(WOMBAT_DECLARE_EXPORT)
+#define WOMBAT_DECLARE(type) __declspec(dllexport) type __stdcall
+#define WOMBAT_DECLARE_NONSTD(type) __declspec(dllexport) type
+#define WOMBAT_DECLARE_DATA __declspec(dllexport)
+#else
+#define WOMBAT_DECLARE(type) __declspec(dllimport) type __stdcall
+#define WOMBAT_DECLARE_NONSTD(type) __declspec(dllimport) type
+#define WOMBAT_DECLARE_DATA __declspec(dllimport)
+#endif
+
+APR_DECLARE_EXTERNAL_HOOK(apw, WOMBAT, int, wombat_open,
+ (lua_State *L, apr_pool_t *p));
+
+APR_DECLARE_EXTERNAL_HOOK(apw, WOMBAT, int, wombat_request,
+ (lua_State *L, request_rec *r));
#endif /* !MOD_WOMBAT_H */
Modified: httpd/mod_wombat/trunk/request.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.c?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/request.c (original)
+++ httpd/mod_wombat/trunk/request.c Wed May 2 11:33:59 2007
@@ -266,21 +266,30 @@
{NULL, NULL}
};
+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);
+}
+
+
void apw_load_request_lmodule(lua_State *L) {
luaL_newmetatable(L, "Apache2.Request"); // [metatable]
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaL_register(L, NULL, request_methods); // [metatable]
+
lua_pop(L, 2);
}
-void apw_push_request(lua_State* L, request_rec* r) {
+void apw_request_init(lua_State* L, request_rec* r) {
lua_boxpointer(L, r);
luaL_getmetatable(L, "Apache2.Request");
lua_setmetatable(L, -2);
luaL_getmetatable(L, "Apache2.Request");
-
+
lua_pushinteger(L, r->status);
lua_setfield(L, -2, "status");
@@ -331,6 +340,9 @@
lua_pushcfunction(L, &req_add_output_filter);
lua_setfield(L, -2, "addoutputfilter");
+
+ apw_push_apr_table(L, "headers_out", r->headers_out);
+ apw_push_apr_table(L, "headers_in", r->headers_in);
lua_pushlightuserdata(L, r);
lua_pushcclosure(L, &req_newindex, 1);
Modified: httpd/mod_wombat/trunk/request.h
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/request.h?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/request.h (original)
+++ httpd/mod_wombat/trunk/request.h Wed May 2 11:33:59 2007
@@ -18,7 +18,7 @@
#ifndef REQUEST_H
#define REQUEST_H
-APR_DECLARE(void) apw_push_request(lua_State* L, request_rec* r);
+APR_DECLARE(void) apw_request_init(lua_State* L, request_rec* r);
APR_DECLARE(void) apw_load_request_lmodule(lua_State *L);
#endif
Modified: httpd/mod_wombat/trunk/vmprep.c
URL: http://svn.apache.org/viewvc/httpd/mod_wombat/trunk/vmprep.c?view=diff&rev=534582&r1=534581&r2=534582
==============================================================================
--- httpd/mod_wombat/trunk/vmprep.c (original)
+++ httpd/mod_wombat/trunk/vmprep.c Wed May 2 11:33:59 2007
@@ -124,6 +124,108 @@
lua_pushstring(L, ap_get_server_version());
lua_setfield(L, -2, "version");
+
+ lua_pushinteger(L, HTTP_MOVED_TEMPORARILY);
+ lua_setfield(L, -2, "HTTP_MOVED_TEMPORARILY");
+
+ /*
+ lua_pushinteger(L, HTTP_CONTINUE);
+ lua_setfield(L, -2, "HTTP_CONTINUE");
+ lua_pushinteger(L, HTTP_SWITCHING_PROTOCOLS);
+ lua_setfield(L, -2, "HTTP_SWITCHING_PROTOCOLS");
+ lua_pushinteger(L, HTTP_PROCESSING);
+ lua_setfield(L, -2, "HTTP_PROCESSING");
+ lua_pushinteger(L, HTTP_OK);
+ lua_setfield(L, -2, "HTTP_OK");
+ lua_pushinteger(L, HTTP_CREATED);
+ lua_setfield(L, -2, "HTTP_CREATED");
+ lua_pushinteger(L, HTTP_ACCEPTED);
+ lua_setfield(L, -2, "HTTP_ACCEPTED");
+ lua_pushinteger(L, HTTP_NON_AUTHORITATIVE);
+ lua_setfield(L, -2, "HTTP_NON_AUTHORITATIVE");
+ lua_pushinteger(L, HTTP_NO_CONTENT);
+ lua_setfield(L, -2, "HTTP_NO_CONTENT");
+ lua_pushinteger(L, HTTP_RESET_CONTENT);
+ lua_setfield(L, -2, "HTTP_RESET_CONTENT");
+ lua_pushinteger(L, HTTP_PARTIAL_CONTENT);
+ lua_setfield(L, -2, "HTTP_PARTIAL_CONTENT");
+ lua_pushinteger(L, HTTP_MULTI_STATUS);
+ lua_setfield(L, -2, "HTTP_MULTI_STATUS");
+ lua_pushinteger(L, HTTP_MULTIPLE_CHOICES);
+ lua_setfield(L, -2, "HTTP_MULTIPLE_CHOICES");
+ lua_pushinteger(L, HTTP_MOVED_PERMANENTLY);
+ lua_setfield(L, -2, "HTTP_MOVED_PERMANENTLY");
+ lua_pushinteger(L, HTTP_SEE_OTHER);
+ lua_setfield(L, -2, "HTTP_SEE_OTHER");
+ lua_pushinteger(L, HTTP_NOT_MODIFIED);
+ lua_setfield(L, -2, "HTTP_NOT_MODIFIED");
+ lua_pushinteger(L, HTTP_USE_PROXY);
+ lua_setfield(L, -2, "HTTP_USE_PROXY");
+ lua_pushinteger(L, HTTP_TEMPORARY_REDIRECT);
+ lua_setfield(L, -2, "HTTP_TEMPORARY_REDIRECT");
+ lua_pushinteger(L, HTTP_BAD_REQUEST);
+ lua_setfield(L, -2, "HTTP_BAD_REQUEST");
+ lua_pushinteger(L, HTTP_UNAUTHORIZED);
+ lua_setfield(L, -2, "HTTP_UNAUTHORIZED");
+ lua_pushinteger(L, HTTP_PAYMENT_REQUIRED);
+ lua_setfield(L, -2, "HTTP_PAYMENT_REQUIRED");
+ lua_pushinteger(L, HTTP_FORBIDDEN);
+ lua_setfield(L, -2, "HTTP_FORBIDDEN");
+ lua_pushinteger(L, HTTP_NOT_FOUND);
+ lua_setfield(L, -2, "HTTP_NOT_FOUND");
+ lua_pushinteger(L, HTTP_METHOD_NOT_ALLOWED);
+ lua_setfield(L, -2, "HTTP_METHOD_NOT_ALLOWED");
+ lua_pushinteger(L, HTTP_NOT_ACCEPTABLE);
+ lua_setfield(L, -2, "HTTP_NOT_ACCEPTABLE");
+ lua_pushinteger(L, HTTP_PROXY_AUTHENTICATION_REQUIRED);
+ lua_setfield(L, -2, "HTTP_PROXY_AUTHENTICATION_REQUIRED");
+ lua_pushinteger(L, HTTP_REQUEST_TIME_OUT);
+ lua_setfield(L, -2, "HTTP_REQUEST_TIME_OUT");
+ lua_pushinteger(L, HTTP_CONFLICT);
+ lua_setfield(L, -2, "HTTP_CONFLICT");
+ lua_pushinteger(L, HTTP_GONE);
+ lua_setfield(L, -2, "HTTP_GONE");
+ lua_pushinteger(L, HTTP_LENGTH_REQUIRED);
+ lua_setfield(L, -2, "HTTP_LENGTH_REQUIRED");
+ lua_pushinteger(L, HTTP_PRECONDITION_FAILED);
+ lua_setfield(L, -2, "HTTP_PRECONDITION_FAILED");
+ lua_pushinteger(L, HTTP_REQUEST_ENTITY_TOO_LARGE);
+ lua_setfield(L, -2, "HTTP_REQUEST_ENTITY_TOO_LARGE");
+ lua_pushinteger(L, HTTP_REQUEST_URI_TOO_LARGE);
+ lua_setfield(L, -2, "HTTP_REQUEST_URI_TOO_LARGE");
+ lua_pushinteger(L, HTTP_UNSUPPORTED_MEDIA_TYPE);
+ lua_setfield(L, -2, "HTTP_UNSUPPORTED_MEDIA_TYPE");
+ lua_pushinteger(L, HTTP_RANGE_NOT_SATISFIABLE);
+ lua_setfield(L, -2, "HTTP_RANGE_NOT_SATISFIABLE");
+ lua_pushinteger(L, HTTP_EXPECTATION_FAILED);
+ lua_setfield(L, -2, "HTTP_EXPECTATION_FAILED");
+ lua_pushinteger(L, HTTP_UNPROCESSABLE_ENTITY);
+ lua_setfield(L, -2, "HTTP_UNPROCESSABLE_ENTITY");
+ lua_pushinteger(L, HTTP_LOCKED);
+ lua_setfield(L, -2, "HTTP_LOCKED");
+ lua_pushinteger(L, HTTP_FAILED_DEPENDENCY);
+ lua_setfield(L, -2, "HTTP_FAILED_DEPENDENCY");
+ lua_pushinteger(L, HTTP_UPGRADE_REQUIRED);
+ lua_setfield(L, -2, "HTTP_UPGRADE_REQUIRED");
+ lua_pushinteger(L, HTTP_INTERNAL_SERVER_ERROR);
+ lua_setfield(L, -2, "HTTP_INTERNAL_SERVER_ERROR");
+ lua_pushinteger(L, HTTP_NOT_IMPLEMENTED);
+ lua_setfield(L, -2, "HTTP_NOT_IMPLEMENTED");
+ lua_pushinteger(L, HTTP_BAD_GATEWAY);
+ lua_setfield(L, -2, "HTTP_BAD_GATEWAY");
+ lua_pushinteger(L, HTTP_SERVICE_UNAVAILABLE);
+ lua_setfield(L, -2, "HTTP_SERVICE_UNAVAILABLE");
+ lua_pushinteger(L, HTTP_GATEWAY_TIME_OUT);
+ lua_setfield(L, -2, "HTTP_GATEWAY_TIME_OUT");
+ lua_pushinteger(L, HTTP_VERSION_NOT_SUPPORTED);
+ lua_setfield(L, -2, "HTTP_VERSION_NOT_SUPPORTED");
+ lua_pushinteger(L, HTTP_VARIANT_ALSO_VARIES);
+ lua_setfield(L, -2, "HTTP_VARIANT_ALSO_VARIES");
+ lua_pushinteger(L, HTTP_INSUFFICIENT_STORAGE);
+ lua_setfield(L, -2, "HTTP_INSUFFICIENT_STORAGE");
+ lua_pushinteger(L, HTTP_NOT_EXTENDED);
+ lua_setfield(L, -2, "HTTP_NOT_EXTENDED");
+ */
}
/* END apache2 lmodule */
@@ -144,10 +246,7 @@
apr_pool_t *pool) {
lua_State* L = luaL_newstate();
open_lualibs(L);
- apw_load_apache2_lmodule(L);
- apw_load_request_lmodule(L);
- apw_load_config_lmodule(L);
-
+ apw_run_wombat_open(L, pool);
lua_getglobal(L, "package");
lua_getfield(L, -1, "path");
const char* current = lua_tostring(L, -1);