You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/05/11 06:01:19 UTC
[17/32] git commit: Initial TSRemapRequestInfo object wrapping
Initial TSRemapRequestInfo object wrapping
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/ddd35e76
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/ddd35e76
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/ddd35e76
Branch: refs/heads/jpeach/lua
Commit: ddd35e7647a626656723c3496a35c3d79e06ecbe
Parents: 2c0436b
Author: James Peach <jp...@apache.org>
Authored: Sat Apr 14 22:41:25 2012 -0700
Committer: James Peach <jp...@apache.org>
Committed: Thu May 10 20:23:42 2012 -0700
----------------------------------------------------------------------
plugins/lua/lapi.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++-
plugins/lua/lapi.h | 2 +
plugins/lua/lua.cc | 3 +-
3 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ddd35e76/plugins/lua/lapi.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lapi.cc b/plugins/lua/lapi.cc
index 6d1ac55..947f81d 100644
--- a/plugins/lua/lapi.cc
+++ b/plugins/lua/lapi.cc
@@ -67,6 +67,46 @@ LuaPushUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url)
}
static int
+LuaRemapRedirect(lua_State * lua)
+{
+ TSRemapRequestInfo * rri;
+
+ rri = *(TSRemapRequestInfo **)luaL_checkudata(lua, 1, "ts.meta.rri");
+ luaL_checktype(lua, 2, LUA_TTABLE);
+
+ TSDebug("lua", "redirecting request %p", rri);
+
+ // XXX take the URL table argument and use it to rewrite rri->requestUrl ...
+
+ rri->redirect = 1;
+
+ // Return true back to Lua-space.
+ lua_pushboolean(lua, 1);
+ return 1;
+}
+
+static const luaL_Reg RRI[] =
+{
+ { "redirect", LuaRemapRedirect },
+ { NULL, NULL}
+};
+
+bool
+LuaPushRemapRequestInfo(lua_State * lua, TSRemapRequestInfo * rri)
+{
+ TSRemapRequestInfo ** ptr;
+
+ ptr = (TSRemapRequestInfo **)lua_newuserdata(lua, sizeof(TSRemapRequestInfo *));
+ *ptr = rri;
+
+ luaL_getmetatable(lua, "ts.meta.rri");
+ lua_setmetatable(lua, -2);
+
+ TSReleaseAssert(lua_isuserdata(lua, -1) == 1);
+ return true;
+}
+
+static int
TSLuaDebug(lua_State * lua)
{
const char * tag = luaL_checkstring(lua, 1);
@@ -93,7 +133,6 @@ LuaApiInit(lua_State * lua)
luaL_register(lua, NULL, LUAEXPORTS);
// Push constants into the "ts" module.
-
lua_pushstring(lua, TSTrafficServerVersionGet());
lua_setfield(lua, -2, "VERSION");
@@ -112,6 +151,16 @@ LuaApiInit(lua_State * lua)
lua_pushinteger(lua, TSREMAP_DID_REMAP);
lua_setfield(lua, -2, "REMAP_CONTINUE");
+ // Register TSRemapRequestInfo metatable.
+ luaL_newmetatable(lua, "ts.meta.rri");
+ lua_pushvalue(lua, -1);
+ lua_setfield(lua, -2, "__index");
+
+ luaL_register(lua, NULL, RRI);
+
+ // Pop the metatable.
+ lua_pop(lua, 1);
+
TSReleaseAssert(lua_istable(lua, -1) == 1);
return 1;
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ddd35e76/plugins/lua/lapi.h
----------------------------------------------------------------------
diff --git a/plugins/lua/lapi.h b/plugins/lua/lapi.h
index 03f9fc7..aff426c 100644
--- a/plugins/lua/lapi.h
+++ b/plugins/lua/lapi.h
@@ -28,3 +28,5 @@ int LuaApiInit(lua_State * lua);
// Push a copy of the given URL.
bool LuaPushUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url);
+// Push a wrapper object for the given TSRemapRequestInfo.
+bool LuaPushRemapRequestInfo(lua_State * lua, TSRemapRequestInfo * rri);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ddd35e76/plugins/lua/lua.cc
----------------------------------------------------------------------
diff --git a/plugins/lua/lua.cc b/plugins/lua/lua.cc
index c48c328..4758763 100644
--- a/plugins/lua/lua.cc
+++ b/plugins/lua/lua.cc
@@ -91,8 +91,9 @@ LuaPluginRemap(lua_State * lua, TSHttpTxn txn, TSRemapRequestInfo * rri)
// XXX we should cache these ...
LuaPushUrl(lua, rri->requestBufp, rri->mapFromUrl);
LuaPushUrl(lua, rri->requestBufp, rri->mapToUrl);
+ LuaPushRemapRequestInfo(lua, rri);
- if (lua_pcall(lua, 2, 1, 0) != 0) {
+ if (lua_pcall(lua, 3, 1, 0) != 0) {
TSDebug("lua", "remap failed: %s", lua_tostring(lua, -1));
lua_pop(lua, 1);
return TSREMAP_ERROR;