You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2014/05/25 09:54:52 UTC

[2/2] git commit: TS-2555: update README.md and remove old lua plugin

TS-2555: update README.md and remove old lua plugin


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/9a3e5de5
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/9a3e5de5
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/9a3e5de5

Branch: refs/heads/master
Commit: 9a3e5de5f2009921436069b3393a133e0c23d5d1
Parents: 14c484b
Author: Kit Chan <ki...@apache.org>
Authored: Sun May 25 00:54:40 2014 -0700
Committer: Kit Chan <ki...@apache.org>
Committed: Sun May 25 00:54:40 2014 -0700

----------------------------------------------------------------------
 plugins/experimental/lua/Makefile.am            |  35 -
 plugins/experimental/lua/TODO                   |  51 --
 .../experimental/lua/examples/cachestatus.lua   |  48 --
 plugins/experimental/lua/examples/hooks.lua     |  90 ---
 plugins/experimental/lua/examples/remap.lua     |  73 ---
 plugins/experimental/lua/examples/test.lua      |  30 -
 plugins/experimental/lua/hook.cc                | 503 --------------
 plugins/experimental/lua/hook.h                 |  39 --
 plugins/experimental/lua/lapi.cc                | 651 -------------------
 plugins/experimental/lua/lapi.h                 |  63 --
 plugins/experimental/lua/lconfig.cc             | 151 -----
 plugins/experimental/lua/lutil.cc               | 139 ----
 plugins/experimental/lua/lutil.h                |  85 ---
 plugins/experimental/lua/plugin.cc              |  45 --
 plugins/experimental/lua/remap.cc               | 104 ---
 plugins/experimental/lua/state.cc               | 348 ----------
 plugins/experimental/lua/state.h                | 157 -----
 plugins/experimental/ts_lua/README.md           | 541 +--------------
 18 files changed, 2 insertions(+), 3151 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/Makefile.am b/plugins/experimental/lua/Makefile.am
deleted file mode 100644
index 0a41390..0000000
--- a/plugins/experimental/lua/Makefile.am
+++ /dev/null
@@ -1,35 +0,0 @@
-#  Licensed to the Apache Software Foundation (ASF) under one
-#  or more contributor license agreements.  See the NOTICE file
-#  distributed with this work for additional information
-#  regarding copyright ownership.  The ASF licenses this file
-#  to you under the Apache License, Version 2.0 (the
-#  "License"); you may not use this file except in compliance
-#  with the License.  You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-
-include $(top_srcdir)/build/plugins.mk
-
-if BUILD_LUA_SUPPORT
-
-# We have to use the per-target CPPFLAGS here to make sure that the Lua include
-# path comes first. If we have LuaJIT (/opt/local/include/luajit-2.0) and Lua
-# (/opt/local/include) headers, then we need to make sure that we don't end up
-# building with the Lua headers but linking LuaJIT.
-lua_la_CPPFLAGS = \
-  $(LUA_CFLAGS) \
-  $(AM_CPPFLAGS)
-
-pkglib_LTLIBRARIES = lua.la
-
-lua_la_LIBADD = $(LUA_LIBS)
-lua_la_SOURCES = remap.cc plugin.cc lapi.cc lutil.cc lconfig.cc hook.cc state.cc
-lua_la_LDFLAGS = $(TS_PLUGIN_LDFLAGS)
-
-endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/TODO
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/TODO b/plugins/experimental/lua/TODO
deleted file mode 100644
index e926771..0000000
--- a/plugins/experimental/lua/TODO
+++ /dev/null
@@ -1,51 +0,0 @@
-- Hook registration consistency
-
-  Per-object hooks register a hook table, but global hooks register
-  an individual function. We should make the register function
-  accept both calling conventions.
-
-- Transaction object parity
-
-  The transaction object that remap callbacks get is richer than
-  the one that hook callbacks get. They should both use the same
-  object and get the same API.
-
-- Richer TS API support
-
-  Flesh out API mappings. Humbedooh has a script that can generate
-  a lot of Lua binding. We should use that to make as much API as
-  we reasonably can.
-
-- HTTP client support
-
-  Wrap TSFetchURL (or its successor), such that Lua can fetch single
-  resources or multiple resources in parallel. For single resources,
-  use yield to make the call look synchronous; for multiple resources
-  consider a callback table.
-
-- HTTP server support
-
-  Reference stats_over_http to enabLe us server responses directly
-  from a Lua plugin. This would be useful for serving status, log
-  builder pages, admin tools, etc.
-
-- HTTP Alternate selection support
-
-  Enable support for HTTP_SELECT_ALT_HOOK. This probably just
-  requires plumbing an object for the TSHttpAltInfo edata argument.
-
-- Documentation
-
-  Document the Lua API in LuaDoc.
-
-- More examples
-
-  Add more Lua plugin examples. Take some of the header manipulation
-  C plugins and rewrite them in Lua. More examples will help us
-  figure out which Lua API is missing.
-
-- Transformation plugins
-
-  We don't support transforms yet. This probably warrants some
-  special purpose API rather than just using the existing hook
-  registration API.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/examples/cachestatus.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/examples/cachestatus.lua b/plugins/experimental/lua/examples/cachestatus.lua
deleted file mode 100644
index 36d60df..0000000
--- a/plugins/experimental/lua/examples/cachestatus.lua
+++ /dev/null
@@ -1,48 +0,0 @@
---  Licensed to the Apache Software Foundation (ASF) under one
---  or more contributor license agreements.  See the NOTICE file
---  distributed with this work for additional information
---  regarding copyright ownership.  The ASF licenses this file
---  to you under the Apache License, Version 2.0 (the
---  "License"); you may not use this file except in compliance
---  with the License.  You may obtain a copy of the License at
---
---  http://www.apache.org/licenses/LICENSE-2.0
---
---  Unless required by applicable law or agreed to in writing, software
---  distributed under the License is distributed on an "AS IS" BASIS,
---  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---  See the License for the specific language governing permissions and
---  limitations under the License.
-
--- Lua example to log the HTTP transaction cache lookup status.
-
-require 'string'
-require 'debug'
-
-ts = require 'ts'
-ts.hook = require 'ts.hook'
-
-ts.debug('cachestatus', string.format('loaded %s', debug.getinfo(1).source))
-
-do
-
-local strings = { }
-strings[ts.CACHE_LOOKUP_MISS]       = "TS_CACHE_LOOKUP_MISS"
-strings[ts.CACHE_LOOKUP_HIT_STALE]  = "TS_CACHE_LOOKUP_HIT_STALE"
-strings[ts.CACHE_LOOKUP_HIT_FRESH]  = "TS_CACHE_LOOKUP_HIT_FRESH"
-strings[ts.CACHE_LOOKUP_SKIPPED]    = "TS_CACHE_LOOKUP_SKIPPED"
-
-function cachestatus(status)
-    return strings[status]
-end
-end
-
-ts.hook.register(ts.hook.HTTP_CACHE_LOOKUP_COMPLETE_HOOK,
-    function(event, txn)
-        ts.debug('cachestatus',
-            string.format('cache lookup status is %s', cachestatus(txn:cachestatus())))
-        txn:continue()
-    end
-)
-
--- vim: set sw=4 ts=4 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/examples/hooks.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/examples/hooks.lua b/plugins/experimental/lua/examples/hooks.lua
deleted file mode 100644
index 931cd22..0000000
--- a/plugins/experimental/lua/examples/hooks.lua
+++ /dev/null
@@ -1,90 +0,0 @@
---  Licensed to the Apache Software Foundation (ASF) under one
---  or more contributor license agreements.  See the NOTICE file
---  distributed with this work for additional information
---  regarding copyright ownership.  The ASF licenses this file
---  to you under the Apache License, Version 2.0 (the
---  "License"); you may not use this file except in compliance
---  with the License.  You may obtain a copy of the License at
---
---  http://www.apache.org/licenses/LICENSE-2.0
---
---  Unless required by applicable law or agreed to in writing, software
---  distributed under the License is distributed on an "AS IS" BASIS,
---  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---  See the License for the specific language governing permissions and
---  limitations under the License.
-
--- Example Lua hooks plugin to demonstrate the use of global, per-session and per-transaction hooks.
-
-require 'string'
-require 'debug'
-
-ts = require 'ts'
-ts.hook = require 'ts.hook'
-
-function OnSession(event, ssn)
-    -- NOTE: the 'ssn' argument is either a session or a transaction object, depending on the event.
-    ts.debug('hooks', string.format('handling session event %d', event))
-    ssn:continue()
-end
-
--- Callback function for per-transaction hooks.
-function OnTransaction(event, txn)
-    ts.debug('hooks', string.format('handling transaction event %d', event))
-   txn:continue()
-end
-
-events = {
-    ssn = {},
-    txn = {}
-}
-
-events.txn[ts.hook.HTTP_OS_DNS_HOOK]                = OnTransaction
-events.txn[ts.hook.HTTP_READ_CACHE_HDR_HOOK]        = OnTransaction
-events.txn[ts.hook.HTTP_READ_REQUEST_HDR_HOOK]      = OnTransaction
-events.txn[ts.hook.HTTP_SEND_REQUEST_HDR_HOOK]      = OnTransaction
-events.txn[ts.hook.HTTP_READ_RESPONSE_HDR_HOOK]     = OnTransaction
-events.txn[ts.hook.HTTP_SEND_RESPONSE_HDR_HOOK]     = OnTransaction
-events.txn[ts.hook.HTTP_TXN_START_HOOK]             = OnTransaction
-events.txn[ts.hook.HTTP_TXN_CLOSE_HOOK]             = OnTransaction
-events.txn[ts.hook.HTTP_SSN_START_HOOK]             = OnTransaction
-events.txn[ts.hook.HTTP_SSN_CLOSE_HOOK]             = OnTransaction
-events.txn[ts.hook.HTTP_CACHE_LOOKUP_COMPLETE_HOOK] = OnTransaction
-events.txn[ts.hook.HTTP_PRE_REMAP_HOOK]             = OnTransaction
-events.txn[ts.hook.HTTP_POST_REMAP_HOOK]            = OnTransaction
-
-events.ssn[ts.hook.HTTP_READ_REQUEST_HDR_HOOK]      = OnSession
-events.ssn[ts.hook.HTTP_OS_DNS_HOOK]                = OnSession
-events.ssn[ts.hook.HTTP_SEND_REQUEST_HDR_HOOK]      = OnSession
-events.ssn[ts.hook.HTTP_READ_CACHE_HDR_HOOK]        = OnSession
-events.ssn[ts.hook.HTTP_READ_RESPONSE_HDR_HOOK]     = OnSession
-events.ssn[ts.hook.HTTP_SEND_RESPONSE_HDR_HOOK]     = OnSession
-events.ssn[ts.hook.HTTP_TXN_START_HOOK]             = OnSession
-events.ssn[ts.hook.HTTP_TXN_CLOSE_HOOK]             = OnSession
-events.ssn[ts.hook.HTTP_SSN_START_HOOK]             = OnSession
-events.ssn[ts.hook.HTTP_SSN_CLOSE_HOOK]             = OnSession
-events.ssn[ts.hook.HTTP_CACHE_LOOKUP_COMPLETE_HOOK] = OnSession
-events.ssn[ts.hook.HTTP_PRE_REMAP_HOOK]             = OnSession
-events.ssn[ts.hook.HTTP_POST_REMAP_HOOK]            = OnSession
-
-ts.debug('hooks', string.format('loaded %s', debug.getinfo(1).source))
-
--- Hook the global session start so we can register the per-session events.
-ts.hook.register(ts.hook.HTTP_SSN_START_HOOK,
-    function(event, ssn)
-        ts.debug('hooks', string.format('callback for HTTP_SSN_START event=%d', event))
-        ssn:register(events.ssn)
-        ssn:continue()
-    end
-)
-
--- Hook the global transaction start so we can register the per-transaction events.
-ts.hook.register(ts.hook.HTTP_TXN_START_HOOK,
-    function(event, txn)
-        ts.debug('hooks', string.format('callback for HTTP_TXN_START event=%d', event))
-        txn:register(events.txn)
-        txn:continue()
-    end
-)
-
--- vim: set sw=4 ts=4 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/examples/remap.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/examples/remap.lua b/plugins/experimental/lua/examples/remap.lua
deleted file mode 100644
index e360c76..0000000
--- a/plugins/experimental/lua/examples/remap.lua
+++ /dev/null
@@ -1,73 +0,0 @@
---  Licensed to the Apache Software Foundation (ASF) under one
---  or more contributor license agreements.  See the NOTICE file
---  distributed with this work for additional information
---  regarding copyright ownership.  The ASF licenses this file
---  to you under the Apache License, Version 2.0 (the
---  "License"); you may not use this file except in compliance
---  with the License.  You may obtain a copy of the License at
---
---  http://www.apache.org/licenses/LICENSE-2.0
---
---  Unless required by applicable law or agreed to in writing, software
---  distributed under the License is distributed on an "AS IS" BASIS,
---  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---  See the License for the specific language governing permissions and
---  limitations under the License.
-
--- Example Lua remap plugin. Load this with the following remap.comfig line:
---
--- map http://test.foo.com http://foo.foo.com @plugin=lua.so @pparam=/path/to/example.lua
-
--- Pull in the Traffic Server API.
-local TS = require 'ts'
-
-require 'string'
-require 'math'
-
--- Compulsory remap hook. We are given a request object that we can modify if necessary.
-function remap(request)
-  -- Get a copy of the current URL.
-  url = request:url()
-
-  TS.debug('example', string.format('remapping %s://%s', url.scheme, url.host))
-
-  -- Do some header manipulation, just to mess with the origin.
-  request.headers['added-bool'] = true
-  request.headers['added-int'] = 1
-  request.headers['added-string'] = 'ttt'
-  request.headers['added-table'] = {}
-  request.headers['deleted'] = nil
-
-  -- We can also print to stdout using Lua standard library.
-  print(string.format('request URL is %s://%s:%d/%s',
-        url.scheme, url.host, url.port, url.path and url.path or ''))
-
-  -- Modify components of the URL ... everybody loves slashdot.
-  url.host = 'www.slashdot.org'
-  url.port = 80
-  url.method = 'POST'
-
-  -- Plugin chain evaluation rules:
-  --    redirect: plugin chain terminates
-  --    reject: plugin chain terminates
-  --    rewrite: plugin chain continues
-
-  chance = math.random(4)
-  if chance == 1 then
-    -- Send a 301 redirect to the new URL.
-    request:redirect(url)
-  elseif chance == 2 then
-    -- Reject the request with an optional message.
-    request:reject(400, "Denied")
-  elseif chance == 3 then
-    -- Reject the request with a response body. We sniff the body to set the content type.
-    request:reject(500, [[
-      <HEAD></TITLE></HEAD>
-      <BODY>Internal error, sorry</BODY>
-      ]])
-  else
-    -- Rewrite the request URL. The remap plugin chain continues and other plugins
-    request:rewrite(url)
-  end
-
-end

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/examples/test.lua
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/examples/test.lua b/plugins/experimental/lua/examples/test.lua
deleted file mode 100644
index 3f9f450..0000000
--- a/plugins/experimental/lua/examples/test.lua
+++ /dev/null
@@ -1,30 +0,0 @@
---  Licensed to the Apache Software Foundation (ASF) under one
---  or more contributor license agreements.  See the NOTICE file
---  distributed with this work for additional information
---  regarding copyright ownership.  The ASF licenses this file
---  to you under the Apache License, Version 2.0 (the
---  "License"); you may not use this file except in compliance
---  with the License.  You may obtain a copy of the License at
---
---  http://www.apache.org/licenses/LICENSE-2.0
---
---  Unless required by applicable law or agreed to in writing, software
---  distributed under the License is distributed on an "AS IS" BASIS,
---  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
---  See the License for the specific language governing permissions and
---  limitations under the License.
-
-require 'string'
-require 'debug'
-ts = require 'ts'
-ts.hook = require 'ts.hook'
-
-ts.debug('lua', string.format('loaded %s', debug.getinfo(1).source))
-
-ts.hook.register(ts.hook.OS_DNS_HOOK,
-    function(event, txn)
-        ts.debug('lua', string.format('callback for event=%d', event))
-        txn:continue()
-    end
-)
--- vim: set sw=4 ts=4 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/hook.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/hook.cc b/plugins/experimental/lua/hook.cc
deleted file mode 100644
index 3f3f7cb..0000000
--- a/plugins/experimental/lua/hook.cc
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include <ts/ts.h>
-#include <ts/remap.h>
-#include <string.h>
-#include "lapi.h"
-#include "lutil.h"
-#include "hook.h"
-#include "state.h"
-
-#include <memory> // placement new
-
-#include "ink_config.h"
-#include "ink_defs.h"
-
-const char *
-HttpHookName(TSHttpHookID hookid)
-{
-  static const char * names[TS_HTTP_LAST_HOOK] = {
-    "HTTP_READ_REQUEST_HDR_HOOK",
-    "HTTP_OS_DNS_HOOK",
-    "HTTP_SEND_REQUEST_HDR_HOOK",
-    "HTTP_READ_CACHE_HDR_HOOK",
-    "HTTP_READ_RESPONSE_HDR_HOOK",
-    "HTTP_SEND_RESPONSE_HDR_HOOK",
-    NULL, // XXX TS_HTTP_REQUEST_TRANSFORM_HOOK
-    NULL, // XXX TS_HTTP_RESPONSE_TRANSFORM_HOOK
-    NULL, // XXX HTTP_SELECT_ALT_HOOK
-    "HTTP_TXN_START_HOOK",
-    "HTTP_TXN_CLOSE_HOOK",
-    "HTTP_SSN_START_HOOK",
-    "HTTP_SSN_CLOSE_HOOK",
-    "HTTP_CACHE_LOOKUP_COMPLETE_HOOK",
-    "HTTP_PRE_REMAP_HOOK",
-    "HTTP_POST_REMAP_HOOK",
-  };
-
-  if (hookid >= 0 && hookid < static_cast<TSHttpHookID>(countof(names))) {
-    return names[hookid];
-  }
-
-  return NULL;
-}
-
-static bool
-HookIsValid(int hookid)
-{
-  if (hookid == TS_HTTP_REQUEST_TRANSFORM_HOOK || hookid == TS_HTTP_RESPONSE_TRANSFORM_HOOK) {
-    return false;
-  }
-
-  return hookid >= 0 && hookid < TS_HTTP_LAST_HOOK;
-}
-
-static void
-LuaPushEventData(lua_State * lua, TSEvent event, void * edata)
-{
-  switch (event) {
-  case TS_EVENT_HTTP_READ_REQUEST_HDR:
-  case TS_EVENT_HTTP_OS_DNS:
-  case TS_EVENT_HTTP_SEND_REQUEST_HDR:
-  case TS_EVENT_HTTP_READ_CACHE_HDR:
-  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
-  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
-  case TS_EVENT_HTTP_SELECT_ALT:
-  case TS_EVENT_HTTP_TXN_START:
-  case TS_EVENT_HTTP_TXN_CLOSE:
-  case TS_EVENT_CACHE_LOOKUP_COMPLETE:
-  case TS_EVENT_HTTP_CACHE_LOOKUP_COMPLETE:
-  case TS_EVENT_HTTP_PRE_REMAP:
-  case TS_EVENT_HTTP_POST_REMAP:
-    LuaPushHttpTransaction(lua, (TSHttpTxn)edata);
-    break;
-  case TS_EVENT_HTTP_SSN_START:
-  case TS_EVENT_HTTP_SSN_CLOSE:
-    LuaPushHttpSession(lua, (TSHttpSsn)edata);
-    break;
-  default:
-    lua_pushnil(lua);
-  }
-}
-
-
-#if defined(INLINE_LUA_HOOK_REFERENCE)
-typedef char __size_check[sizeof(this_type) == sizeof(void *) ? 0 : -1];
-#endif
-
-// For 64-bit pointers, we can inline the LuaHookReference, otherwise we need an extra malloc.
-//
-#if SIZEOF_VOID_POINTER >= 8
-#define INLINE_LUA_HOOK_REFERENCE 1
-#else
-#undef INLINE_LUA_HOOK_REFERENCE
-#endif
-
-template <typename t1, typename t2>
-struct inline_tuple
-{
-  typedef t1 first_type;
-  typedef t2 second_type;
-  typedef inline_tuple<first_type, second_type> this_type;
-
-  union {
-    struct {
-      first_type first;
-      second_type second;
-    } s;
-    void * ptr;
-  } storage;
-
-  first_type& first() { return storage.s.first; }
-  second_type& second() { return storage.s.second; }
-
-  static void * allocate(const first_type first, const second_type second) {
-#if defined(INLINE_LUA_HOOK_REFERENCE)
-    this_type obj;
-    obj.first() = first;
-    obj.second() = second;
-    return obj.storage.ptr;
-#else
-    this_type * ptr = (this_type *)TSmalloc(sizeof(this_type));
-    ptr->first() = first;
-    ptr->second() = second;
-    return ptr;
-#endif
-  }
-
-  static void free(void *ptr ATS_UNUSED) {
-#if defined(INLINE_LUA_HOOK_REFERENCE)
-    // Nothing to do, because we never allocated.
-#else
-    TSfree(ptr);
-#endif
-  }
-
-  static this_type get(void * ptr) {
-#if defined(INLINE_LUA_HOOK_REFERENCE)
-    this_type obj;
-    obj.storage.ptr = ptr;
-    return obj;
-#else
-    return ptr ? *(this_type *)ptr : this_type();
-#endif
-  }
-
-};
-
-// The per-ssn and per-txn argument mechanism stores a pointer, so it's NULL when not set. Unfortunately, 0 is a
-// legitimate Lua reference value (all values except LUA_NOREF are legitimate), so we can't distinguish NULL from a 0
-// reference. In 64-bit mode we have some extra bits and we can maintain the state, but in 32-bit mode, we need to
-// allocate the LuaHookReference to have enough space to store the state.
-typedef inline_tuple<int, bool> LuaHookReference;
-
-static void *
-LuaHttpObjectArgGet(TSHttpSsn ssn)
-{
-  return TSHttpSsnArgGet(ssn, LuaHttpArgIndex);
-}
-
-static void *
-LuaHttpObjectArgGet(TSHttpTxn txn)
-{
-  return TSHttpTxnArgGet(txn, LuaHttpArgIndex);
-}
-
-static void
-LuaHttpObjectArgSet(TSHttpSsn ssn, void * ptr)
-{
-  return TSHttpSsnArgSet(ssn, LuaHttpArgIndex, ptr);
-}
-
-static void
-LuaHttpObjectArgSet(TSHttpTxn txn, void * ptr)
-{
-  return TSHttpTxnArgSet(txn, LuaHttpArgIndex, ptr);
-}
-
-template<typename T> static int
-LuaGetArgReference(T ptr)
-{
-  LuaHookReference href(LuaHookReference::get(LuaHttpObjectArgGet(ptr)));
-  // Only return the Lua ref if it was previously set.
-  return href.second() ? href.first() : LUA_NOREF;
-}
-
-template <typename T> void
-LuaSetArgReference(T ptr, int ref)
-{
-  LuaHookReference::free(LuaHttpObjectArgGet(ptr));
-  LuaHttpObjectArgSet(ptr, LuaHookReference::allocate(ref, true));
-}
-
-template <typename T> static void
-LuaClearArgReference(T ptr)
-{
-  LuaHookReference::free(LuaHttpObjectArgGet(ptr));
-  LuaHttpObjectArgSet(ptr, NULL);
-}
-
-// Force template instantiation of LuaSetArgReference().
-template void LuaSetArgReference<TSHttpSsn>(TSHttpSsn ssn, int ref);
-template void LuaSetArgReference<TSHttpTxn>(TSHttpTxn txn, int ref);
-
-static void
-LuaDemuxInvokeCallback(lua_State * lua, TSHttpHookID hookid, TSEvent event, void * edata, int ref)
-{
-  int nitems = lua_gettop(lua);
-
-  // Push the callback table onto the top of the stack.
-  lua_rawgeti(lua, LUA_REGISTRYINDEX, ref);
-
-  // XXX If this is a global hook, we have a function reference. If it's a ssn or txn hook then we
-  // have a callback table reference. We need to make these the same, but not rught now ...
-
-  switch (lua_type(lua, -1)) {
-    case LUA_TFUNCTION:
-      // Nothing to do, the function we want to invoke is already on top of the stack.
-      break;
-    case LUA_TTABLE:
-      // Push the hookid onto the stack so we can use it to index the table (that is now at -2).
-      lua_pushinteger(lua, hookid);
-
-      TSAssert(lua_isnumber(lua, -1));
-      TSAssert(lua_istable(lua, -2));
-
-      // Index the callback table with the hookid to get the callback function for this hook.
-      lua_gettable(lua, -2);
-
-      break;
-    default:
-      LuaLogError("invalid callback reference type %s", ltypeof(lua, -1));
-      TSReleaseAssert(0);
-  }
-
-  // The item on the top of the stack *ought* to be the callback function. However when we register a
-  // cleanup function to release the callback reference (because the ssn or txn closes), then we won't
-  // have a function because there's nothing to do here.
-  if (!lua_isnil(lua, -1)) {
-
-    TSAssert(lua_isfunction(lua, -1));
-
-    lua_pushinteger(lua, event);
-    LuaPushEventData(lua, event, edata);
-
-    if (lua_pcall(lua, 2 /* nargs */, 0, 0) != 0) {
-      LuaLogDebug("hook callback failed: %s", lua_tostring(lua, -1));
-      lua_pop(lua, 1); // pop the error message
-    }
-  }
-
-  // If we left anything on the stack, pop it.
-  lua_pop(lua, lua_gettop(lua) - nitems);
-}
-
-int
-LuaDemuxGlobalHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata)
-{
-  instanceid_t        instanceid = (uintptr_t)TSContDataGet(cont);
-  ScopedLuaState      lstate(instanceid);
-  int                 ref = lstate->hookrefs[hookid];
-
-  LuaLogDebug("%u/%p %s event=%d edata=%p, ref=%d",
-      instanceid, lstate->lua,
-      HttpHookName(hookid), event, edata, ref);
-
-  if (ref == LUA_NOREF) {
-    LuaLogError("no Lua callback for hook %s", HttpHookName(hookid));
-    return TS_EVENT_ERROR;
-  }
-
-  LuaDemuxInvokeCallback(lstate->lua, hookid, event, edata, ref);
-  return TS_EVENT_NONE;
-}
-
-int
-LuaDemuxTxnHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata)
-{
-  int                 ref = LuaGetArgReference((TSHttpTxn)edata);
-  instanceid_t        instanceid = (uintptr_t)TSContDataGet(cont);
-  ScopedLuaState      lstate(instanceid);
-
-  LuaLogDebug("%s(%s) instanceid=%u event=%d edata=%p",
-      __func__, HttpHookName(hookid), instanceid, event, edata);
-
-  if (ref == LUA_NOREF) {
-    LuaLogError("no Lua callback for hook %s", HttpHookName(hookid));
-    return TS_EVENT_ERROR;
-  }
-
-  LuaDemuxInvokeCallback(lstate->lua, hookid, event, edata, ref);
-
-  if (event == TS_EVENT_HTTP_TXN_CLOSE) {
-    LuaLogDebug("unref event handler %d", ref);
-    luaL_unref(lstate->lua, LUA_REGISTRYINDEX, ref);
-    LuaClearArgReference((TSHttpTxn)edata);
-  }
-
-  return TS_EVENT_NONE;
-}
-
-int
-LuaDemuxSsnHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata)
-{
-  instanceid_t        instanceid = (uintptr_t)TSContDataGet(cont);
-  ScopedLuaState      lstate(instanceid);
-  TSHttpSsn           ssn;
-  int                 ref;
-
-  // The edata might be a Txn or a Ssn, depending on the event type. If we get here, it's because we
-  // registered a callback on the Ssn, so we need to get back to the Ssn object in order to the the
-  // callback table reference ...
-  switch (event) {
-    case TS_EVENT_HTTP_SSN_START:
-    case TS_EVENT_HTTP_SSN_CLOSE:
-      ssn = (TSHttpSsn)edata;
-      break;
-    default:
-      ssn = TSHttpTxnSsnGet((TSHttpTxn)edata);
-  }
-
-  LuaLogDebug("%s(%s) instanceid=%u event=%d edata=%p",
-      __func__, HttpHookName(hookid), instanceid, event, edata);
-
-  ref = LuaGetArgReference(ssn);
-  if (ref == LUA_NOREF) {
-    LuaLogError("no Lua callback for hook %s", HttpHookName(hookid));
-    return TS_EVENT_ERROR;
-  }
-
-  LuaDemuxInvokeCallback(lstate->lua, hookid, event, edata, ref);
-
-  if (event == TS_EVENT_HTTP_SSN_CLOSE) {
-    LuaLogDebug("unref event handler %d", ref);
-    luaL_unref(lstate->lua, LUA_REGISTRYINDEX, ref);
-    LuaClearArgReference((TSHttpSsn)edata);
-  }
-
-  return TS_EVENT_NONE;
-}
-
-bool
-LuaRegisterHttpHooks(lua_State * lua, void * obj, LuaHookAddFunction add, int hooks)
-{
-  bool                hooked_close = false;
-  const TSHttpHookID  closehook = (add == LuaHttpSsnHookAdd ? TS_HTTP_SSN_CLOSE_HOOK : TS_HTTP_TXN_CLOSE_HOOK);
-
-  TSAssert(add == LuaHttpSsnHookAdd || add == LuaHttpTxnHookAdd);
-
-  // Push the hooks reference back onto the stack.
-  lua_rawgeti(lua, LUA_REGISTRYINDEX, hooks);
-
-  // The value on the top of the stack (index -1) MUST be the callback table.
-  TSAssert(lua_istable(lua, lua_gettop(lua)));
-
-  // Now we need our LuaThreadState to access the hook tables.
-  ScopedLuaState lstate(lua);
-
-  // Walk the table and register the hook for each entry.
-  lua_pushnil(lua);  // Push the first key, makes the callback table index -2.
-  while (lua_next(lua, -2) != 0) {
-    TSHttpHookID hookid;
-
-    // uses 'key' (at index -2) and 'value' (at index -1).
-    // LuaLogDebug("key=%s value=%s\n", ltypeof(lua, -2), ltypeof(lua, -1));
-
-    // Now the key (index -2) and value (index -1) got pushed onto the stack. The key must be a hook ID and
-    // the value must be a callback function.
-    luaL_checktype(lua, -1, LUA_TFUNCTION);
-    hookid = (TSHttpHookID)luaL_checkint(lua, -2);
-
-    if (!HookIsValid(hookid)) {
-      LuaLogError("invalid Hook ID %d", hookid);
-      goto next;
-    }
-
-    if (hookid == closehook) {
-      hooked_close = true;
-    }
-
-    // At demux time, we need the hook ID and the table (or function) ref.
-    add(obj, lstate.instance(), hookid);
-    LuaLogDebug("registered callback table %d for event %s on object %p",
-        hooks, HttpHookName(hookid), obj);
-
-next:
-    // Pop the value (index -1), leaving key as the new top (index -1).
-    lua_pop(lua, 1);
-  }
-
-  // we always need to hook the close because we keep a reference to the callback table and we need to
-  // release that reference when the object's lifetime ends.
-  if (!hooked_close) {
-    add(obj, lstate.instance(), closehook);
-  }
-
-  return true;
-}
-
-void
-LuaHttpSsnHookAdd(void * ssn, const LuaPluginInstance * instance, TSHttpHookID hookid)
-{
-  TSHttpSsnHookAdd((TSHttpSsn)ssn, hookid, instance->demux.ssn[hookid]);
-}
-
-void
-LuaHttpTxnHookAdd(void * txn, const LuaPluginInstance * instance, TSHttpHookID hookid)
-{
-  TSHttpTxnHookAdd((TSHttpTxn)txn, hookid, instance->demux.txn[hookid]);
-}
-
-static int
-TSLuaHttpHookRegister(lua_State * lua)
-{
-  TSHttpHookID      hookid;
-
-  hookid = (TSHttpHookID)luaL_checkint(lua, 1);
-  luaL_checktype(lua, 2, LUA_TFUNCTION);
-
-  LuaLogDebug("registering hook %s (%d)", HttpHookName(hookid), (int)hookid);
-  if (hookid < 0 || hookid >= TS_HTTP_LAST_HOOK) {
-    LuaLogDebug("hook ID %d out of range", hookid);
-    return -1;
-  }
-
-  ScopedLuaState lstate(lua);
-  TSReleaseAssert(lstate);
-
-  // The lstate must match the current Lua state or something is seriously wrong.
-  TSReleaseAssert(lstate->lua == lua);
-
-  // Global hooks can only be registered once, but we load the Lua scripts in every thread. Check whether
-  // the hook has already been registered and ignore any double-registrations.
-  if (lstate->hookrefs[hookid] != LUA_NOREF) {
-    LuaLogDebug("ignoring double registration for %s hook", HttpHookName(hookid));
-    return 0;
-  }
-
-  // The callback function for the hook should be on the top of the stack now. Keep a reference
-  // to the callback function in the registry so we can pop it out later.
-  TSAssert(lua_type(lua, lua_gettop(lua)) == LUA_TFUNCTION);
-  lstate->hookrefs[hookid] = luaL_ref(lua, LUA_REGISTRYINDEX);
-
-  LuaLogDebug("%u/%p added hook ref %d for %s",
-      lstate->instance->instanceid, lua, lstate->hookrefs[hookid], HttpHookName(hookid));
-
-  // We need to atomically install this global hook. We snaffle the high bit to mark whether or
-  // not it has been installed.
-  if (((uintptr_t)lstate->instance->demux.global[hookid] & 0x01u) == 0) {
-    TSCont cont = (TSCont)((uintptr_t)lstate->instance->demux.global[hookid] | 0x01u);
-
-    if (__sync_bool_compare_and_swap(&lstate->instance->demux.global[hookid],
-          lstate->instance->demux.global[hookid], cont)) {
-      LuaLogDebug("installed continuation for %s", HttpHookName(hookid));
-      TSHttpHookAdd(hookid, (TSCont)((uintptr_t)cont & ~0x01u));
-    } else {
-      LuaLogDebug("lost hook creation race for %s", HttpHookName(hookid));
-    }
-  }
-
-  return 0;
-}
-
-static const luaL_Reg LUAEXPORTS[] =
-{
-  { "register", TSLuaHttpHookRegister },
-  { NULL, NULL}
-};
-
-int
-LuaHookApiInit(lua_State * lua)
-{
-  LuaLogDebug("initializing TS Hook API");
-
-  lua_newtable(lua);
-
-  // Register functions in the "ts.hook" module.
-  luaL_register(lua, NULL, LUAEXPORTS);
-
-  for (unsigned i = 0; i < TS_HTTP_LAST_HOOK; ++i) {
-    if (HttpHookName((TSHttpHookID)i) != NULL) {
-      // Register named constants for each hook ID.
-      LuaSetConstantField(lua, HttpHookName((TSHttpHookID)i), i);
-    }
-  }
-
-  return 1;
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/hook.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/hook.h b/plugins/experimental/lua/hook.h
deleted file mode 100644
index 8c3f642..0000000
--- a/plugins/experimental/lua/hook.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#ifndef LUA_HOOK_H_
-#define LUA_HOOK_H_
-
-struct LuaPluginInstance;
-
-// Pointer to LuaHttpSsnHookAdd() or LuaHttpTxnsnHookAdd().
-typedef void (*LuaHookAddFunction)(void *, const LuaPluginInstance *, TSHttpHookID);
-
-void LuaHttpSsnHookAdd(void *, const LuaPluginInstance *, TSHttpHookID);
-void LuaHttpTxnHookAdd(void *, const LuaPluginInstance *, TSHttpHookID);
-
-// Set a LuaHookReference as the argument on the corresponding object. T can be either TSHttpSsn or TSHttpTxn.
-template <typename T> void LuaSetArgReference(T ptr, int ref);
-
-bool LuaRegisterHttpHooks(lua_State *, void *, LuaHookAddFunction, int);
-
-int LuaDemuxSsnHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata);
-int LuaDemuxTxnHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata);
-int LuaDemuxGlobalHook(TSHttpHookID hookid, TSCont cont, TSEvent event, void * edata);
-
-#endif // LUA_HOOK_H_

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/lapi.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/lapi.cc b/plugins/experimental/lua/lapi.cc
deleted file mode 100644
index 6121113..0000000
--- a/plugins/experimental/lua/lapi.cc
+++ /dev/null
@@ -1,651 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include "ts/ts.h"
-#include "ts/remap.h"
-#include "ink_defs.h"
-
-#include <string.h>
-#include "lapi.h"
-#include "lutil.h"
-#include "hook.h"
-
-template <typename LuaType, typename Param1> LuaType *
-push_userdata_object(lua_State * lua, Param1 p1)
-{
-  LuaType * ltype;
-  ltype = LuaType::alloc(lua, p1);
-  TSReleaseAssert(lua_isuserdata(lua, -1) == 1);
-  return ltype;
-}
-
-template <typename LuaType, typename Param1, typename Param2> LuaType *
-push_userdata_object(lua_State * lua, Param1 p1, Param2 p2)
-{
-  LuaType * ltype;
-  ltype = LuaType::alloc(lua, p1, p2);
-  TSReleaseAssert(lua_isuserdata(lua, -1) == 1);
-  return ltype;
-}
-
-struct LuaRemapHeaders
-{
-  TSMBuffer buffer;
-  TSMLoc    headers;
-
-  static LuaRemapHeaders * get(lua_State * lua, int index) {
-    return (LuaRemapHeaders *)luaL_checkudata(lua, index, "ts.meta.rri.headers");
-  }
-
-  static LuaRemapHeaders * alloc(lua_State * lua) {
-    LuaRemapHeaders * hdrs;
-
-    hdrs = LuaNewUserData<LuaRemapHeaders>(lua);
-    luaL_getmetatable(lua, "ts.meta.rri.headers");
-    lua_setmetatable(lua, -2);
-
-    return hdrs;
-  }
-};
-
-struct LuaHttpTransaction
-{
-  TSHttpTxn txn;
-
-  LuaHttpTransaction() : txn(NULL) {}
-
-  static LuaHttpTransaction * get(lua_State * lua, int index) {
-    return (LuaHttpTransaction *)luaL_checkudata(lua, index, "ts.meta.http.txn");
-  }
-
-  static LuaHttpTransaction * alloc(lua_State * lua, TSHttpTxn ptr) {
-    LuaHttpTransaction * txn;
-
-    txn = LuaNewUserData<LuaHttpTransaction>(lua);
-    txn->txn = ptr;
-    luaL_getmetatable(lua, "ts.meta.http.txn");
-    lua_setmetatable(lua, -2);
-
-    return txn;
-  }
-};
-
-struct LuaHttpSession
-{
-  TSHttpSsn ssn;      // session pointer
-
-  LuaHttpSession() : ssn(NULL) {}
-
-  static LuaHttpSession * get(lua_State * lua, int index) {
-    return (LuaHttpSession *)luaL_checkudata(lua, index, "ts.meta.http.ssn");
-  }
-
-  static LuaHttpSession * alloc(lua_State * lua, TSHttpSsn ptr) {
-    LuaHttpSession * ssn;
-
-    ssn = LuaNewUserData<LuaHttpSession>(lua);
-    ssn->ssn = ptr;
-    luaL_getmetatable(lua, "ts.meta.http.ssn");
-    lua_setmetatable(lua, -2);
-
-    return ssn;
-  }
-};
-
-LuaRemapRequest *
-LuaRemapRequest::get(lua_State * lua, int index)
-{
-  return (LuaRemapRequest *)luaL_checkudata(lua, index, "ts.meta.rri");
-}
-
-LuaRemapRequest *
-LuaRemapRequest::alloc(lua_State * lua, TSRemapRequestInfo * rri, TSHttpTxn txn)
-{
-  LuaRemapRequest * rq;
-
-  rq = new(lua_newuserdata(lua, sizeof(LuaRemapRequest))) LuaRemapRequest(rri, txn);
-  luaL_getmetatable(lua, "ts.meta.rri");
-  lua_setmetatable(lua, -2);
-
-  // Stash a new table as the environment for this object. We will use it later for __index.
-  lua_newtable(lua);
-  TSReleaseAssert(lua_setfenv(lua, -2));
-
-  return rq;
-}
-
-// Given a URL table on the top of the stack, pop it's values into the URL buffer.
-bool
-LuaPopUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url)
-{
-  const char *  strval;
-  size_t        len;
-
-#define SET_URL_COMPONENT(name, setter) do { \
-  lua_getfield(lua, -1, name); \
-  if (!lua_isnil(lua, -1)) { \
-    strval = luaL_checklstring(lua, -1, &len); \
-    if (strval) { \
-      setter(buffer, url, strval, len); \
-    } \
-  } \
-  lua_pop(lua, 1); \
-} while (0)
-
-  // We ignore the 'href' field. When constructing URL tables, it's convenient, but it doesn't seem
-  // necessary here. Callers can easily construct the URL table.
-  SET_URL_COMPONENT("scheme", TSUrlSchemeSet);
-  SET_URL_COMPONENT("user", TSUrlUserSet);
-  SET_URL_COMPONENT("password", TSUrlPasswordSet);
-  SET_URL_COMPONENT("host", TSUrlHostSet);
-  SET_URL_COMPONENT("path", TSUrlPathSet);
-  SET_URL_COMPONENT("query", TSUrlHttpQuerySet);
-  SET_URL_COMPONENT("fragment", TSUrlHttpFragmentSet);
-
-  lua_getfield(lua, -1, "port");
-  if (!lua_isnil(lua, -1)) {
-    TSUrlPortSet(buffer, url, luaL_checkint(lua, -1));
-  }
-  lua_pop(lua, 1);
-
-#undef SET_URL_COMPONENT
-  return true;
-}
-
-bool
-LuaPushUrl(lua_State * lua, TSMBuffer buffer, TSMLoc url)
-{
-  int len;
-  const char * str;
-
-#define PUSH_URL_COMPONENT(accessor, name) do { \
-  str = accessor(buffer, url, &len); \
-  if (str) { \
-    lua_pushlstring(lua, str, len); \
-  }  else { \
-    lua_pushnil(lua); \
-  } \
-  lua_setfield(lua, -2, name); \
-} while (0)
-
-  lua_newtable(lua);
-
-  // Set fundamental URL fields.
-  // XXX should we be luvit-compatible with these names?
-  PUSH_URL_COMPONENT(TSUrlSchemeGet, "scheme");       // luvit: protocol
-  PUSH_URL_COMPONENT(TSUrlUserGet, "user");
-  PUSH_URL_COMPONENT(TSUrlPasswordGet, "password");
-  PUSH_URL_COMPONENT(TSUrlHostGet, "host");
-  lua_pushinteger(lua, TSUrlPortGet(buffer, url));
-  lua_setfield(lua, -2, "port");
-  PUSH_URL_COMPONENT(TSUrlPathGet, "path");           // luvit: pathname
-  PUSH_URL_COMPONENT(TSUrlHttpQueryGet, "query");     // luvit: search
-  PUSH_URL_COMPONENT(TSUrlHttpFragmentGet, "fragment");
-
-  // It would be cleaner to add a __tostring metamethod, but to do that we would have to keep the
-  // buffer and url around indefinitely. Better to make a straight copy now; use the 'href' key
-  // just like luvit does.
-  str = TSUrlStringGet(buffer, url, &len);
-  if (str) {
-    lua_pushlstring(lua, str, len);
-    lua_setfield(lua, -2, "href");
-    TSfree((void *)str);
-  }
-
-  TSReleaseAssert(lua_istable(lua, -1) == 1);
-  return true;
-
-#undef PUSH_URL_COMPONENT
-}
-
-static int
-LuaRemapRedirect(lua_State * lua)
-{
-  LuaRemapRequest * rq;
-
-  rq = LuaRemapRequest::get(lua, 1);
-  luaL_checktype(lua, 2, LUA_TTABLE);
-
-  LuaLogDebug("redirecting request %p", rq->rri);
-
-  lua_pushvalue(lua, 2);
-  LuaPopUrl(lua, rq->rri->requestBufp, rq->rri->requestUrl);
-  lua_pop(lua, 1);
-
-  // A redirect always terminates plugin chain evaluation.
-  rq->rri->redirect = 1;
-  rq->status = TSREMAP_DID_REMAP_STOP;
-
-  // Return true back to Lua-space.
-  lua_pushboolean(lua, 1);
-  return 1;
-}
-
-static int
-LuaRemapRewrite(lua_State * lua)
-{
-  LuaRemapRequest * rq;
-
-  rq = LuaRemapRequest::get(lua, 1);
-  luaL_checktype(lua, 2, LUA_TTABLE);
-
-  LuaLogDebug("rewriting request %p", rq->rri);
-
-  lua_pushvalue(lua, 2);
-  LuaPopUrl(lua, rq->rri->requestBufp, rq->rri->requestUrl);
-  lua_pop(lua, 1);
-
-  // A rewrite updates the request URL but never terminates plugin chain evaluation.
-  rq->status = TSREMAP_DID_REMAP;
-
-  // Return true back to Lua-space.
-  lua_pushboolean(lua, 1);
-  return 1;
-}
-
-static int
-LuaRemapReject(lua_State * lua)
-{
-  LuaRemapRequest * rq;
-  int status;
-  size_t body_len;
-  const char * body = NULL;
-
-  rq = LuaRemapRequest::get(lua, 1);
-  status = luaL_checkint(lua, 2);
-  if (!lua_isnoneornil(lua, 3)) {
-    body = luaL_checklstring(lua, 3, &body_len);
-    // body = luaL_checkstring(lua, 3);
-  }
-
-  LuaLogDebug("rejecting request %p with status %d", rq->rri, status);
-
-  TSHttpTxnSetHttpRetStatus(rq->txn, (TSHttpStatus)status);
-  if (body && *body) {
-    TSHttpTxnErrorBodySet(rq->txn, TSstrdup(body), body_len, NULL); // Defaults to text/html
-  }
-
-  // A reject terminates plugin chain evaluation but does not update the request URL.
-  rq->status = TSREMAP_NO_REMAP_STOP;
-
-  return 1;
-}
-
-static int
-LuaRemapUrl(lua_State * lua)
-{
-  LuaRemapRequest * rq;
-
-  rq = LuaRemapRequest::get(lua, 1);
-  LuaPushUrl(lua, rq->rri->requestBufp, rq->rri->requestUrl);
-  return 1;
-}
-
-// Since we cannot add fields to userdata objects, we use the environment to store the fields. If the requested
-// field isn't in our metatable, try to find it in the environment. Populate keys in the environment on demand if
-// the request is for a key that we know about.
-//
-// XXX When we set __index in the metatable, Lua routes all method calls through here rather than checking for the
-// existing key first. That's a bit surprising and I wonder whether there's a better way to handle this.
-static int
-LuaRemapIndex(lua_State * lua)
-{
-  LuaRemapRequest * rq;
-  const char * index;
-
-  rq = LuaRemapRequest::get(lua, 1);
-  index = luaL_checkstring(lua, 2);
-
-  LuaLogDebug("%s[%s]", __func__, index);
-
-  // Get the userdata's metatable and look up the index in it.
-  lua_getmetatable(lua, 1);
-  lua_getfield(lua, -1, index);
-  if (!lua_isnoneornil(lua, -1)) {
-    // Pop the metatable, leaving the field value on top.
-    lua_remove(lua, -2);
-    return 1;
-  }
-
-  // Pop the field value and the metatable.
-  lua_pop(lua, 2);
-
-  lua_getfenv(lua, 1);
-
-  // Get the requested field from the environment table.
-  lua_getfield(lua, -1, index);
-
-  // If we have a value for that field, pop the environment table, leaving the value on top.
-  if (!lua_isnoneornil(lua, -1)) {
-    lua_remove(lua, -2);
-    return 1;
-  }
-
-  // Pop the nil field value.
-  lua_pop(lua, 1);
-
-  if (strcmp(index, "headers") == 0) {
-    LuaRemapHeaders * hdrs;
-
-    hdrs = LuaRemapHeaders::alloc(lua);
-    hdrs->buffer = rq->rri->requestBufp;
-    hdrs->headers = rq->rri->requestHdrp;
-
-    // Set it for the 'headers' index and then push it on the stack.
-    lua_setfield(lua, -2, index);
-    lua_getfield(lua, -1, index);
-
-    // Pop the environment table, leaving the field value on top.
-    lua_remove(lua, -2);
-    return 1;
-  }
-
-  return 0;
-}
-
-static const luaL_Reg RRI[] =
-{
-  { "redirect", LuaRemapRedirect },
-  { "rewrite", LuaRemapRewrite },
-  { "reject", LuaRemapReject },
-  { "url", LuaRemapUrl },
-  { "__index", LuaRemapIndex },
-  { NULL, NULL}
-};
-
-static int
-LuaRemapHeaderIndex(lua_State * lua)
-{
-  LuaRemapHeaders * hdrs;
-  const char *      index;
-  const char *      value;
-  int               vlen;
-  TSMLoc            field;
-
-  hdrs = LuaRemapHeaders::get(lua, 1);;
-  index = luaL_checkstring(lua, 2);
-
-  LuaLogDebug("%s[%s]", __func__, index);
-
-  field = TSMimeHdrFieldFind(hdrs->buffer, hdrs->headers, index, -1);
-  if (field == TS_NULL_MLOC) {
-    lua_pushnil(lua);
-    return 1;
-  }
-
-  value = TSMimeHdrFieldValueStringGet(hdrs->buffer, hdrs->headers, field, -1, &vlen);
-  lua_pushlstring(lua, value, vlen);
-  return 1;
-}
-
-static int
-LuaRemapHeaderNewIndex(lua_State * lua)
-{
-  LuaRemapHeaders * hdrs;
-  const char *      index;
-  const char *      value;
-  size_t            vlen;
-  TSMLoc            field;
-
-  hdrs = LuaRemapHeaders::get(lua, 1);
-  index = luaL_checkstring(lua, 2);
-
-  LuaLogDebug("%s[%s] = (%s)", __func__, index, ltypeof(lua, 3));
-  field = TSMimeHdrFieldFind(hdrs->buffer, hdrs->headers, index, -1);
-
-  // Setting a key to nil means to delete it.
-  if (lua_isnoneornil(lua, 3)) {
-    if (field != TS_NULL_MLOC) {
-      TSMimeHdrFieldDestroy(hdrs->buffer, hdrs->headers, field);
-      TSHandleMLocRelease(hdrs->buffer, hdrs->headers, field);
-    }
-
-    return 1;
-  }
-
-  // If the MIME field doesn't exist yet, we'd better make it.
-  if (field == TS_NULL_MLOC) {
-    TSMimeHdrFieldCreateNamed(hdrs->buffer, hdrs->headers, index, -1, &field);
-    TSMimeHdrFieldAppend(hdrs->buffer, hdrs->headers, field);
-  }
-
-  TSMimeHdrFieldValuesClear(hdrs->buffer, hdrs->headers, field);
-
-  // Finally, we can set it's value.
-  switch(lua_type(lua, 3)) {
-    case LUA_TBOOLEAN:
-      value = lua_toboolean(lua, 3) ? "1" : "0";
-      vlen = 1;
-      break;
-    default:
-      value = lua_tolstring(lua, 3, &vlen);
-      break;
-  }
-
-  if (value) {
-    TSMimeHdrFieldValueStringInsert(hdrs->buffer, hdrs->headers, field, -1, value, vlen);
-  }
-
-  TSHandleMLocRelease(hdrs->buffer, hdrs->headers, field);
-  return 1;
-}
-
-static const luaL_Reg HEADERS[] =
-{
-  { "__index", LuaRemapHeaderIndex },
-  { "__newindex", LuaRemapHeaderNewIndex },
-  { NULL, NULL }
-};
-
-static int
-LuaHttpTxnAbort(lua_State * lua)
-{
-  LuaHttpTransaction * txn;
-
-  txn = LuaHttpTransaction::get(lua, 1);
-  TSHttpTxnReenable(txn->txn, TS_EVENT_HTTP_ERROR);
-
-  return 1;
-}
-
-static int
-LuaHttpTxnContinue(lua_State * lua)
-{
-  LuaHttpTransaction * txn;
-
-  txn = LuaHttpTransaction::get(lua, 1);
-  TSHttpTxnReenable(txn->txn, TS_EVENT_HTTP_CONTINUE);
-
-  return 1;
-}
-
-static int
-LuaHttpTxnRegister(lua_State * lua)
-{
-  LuaHttpTransaction * txn;
-  int tableref;
-
-  txn = LuaHttpTransaction::get(lua, 1);
-  luaL_checktype(lua, 2, LUA_TTABLE);
-
-  // Keep a reference to the hooks table in ssn->hooks.
-  tableref = luaL_ref(lua, LUA_REGISTRYINDEX);
-
-  // On the other side of the denux, we need the hook, and the table.
-  if (LuaRegisterHttpHooks(lua, txn->txn, LuaHttpTxnHookAdd, tableref)) {
-    LuaSetArgReference(txn->txn, tableref);
-    return 1;
-  }
-
-  return 0;
-}
-
-static int
-LuaHttpTxnCacheLookupStatus(lua_State * lua)
-{
-  LuaHttpTransaction * txn;
-  int status;
-
-  txn = LuaHttpTransaction::get(lua, 1);
-  if (TSHttpTxnCacheLookupStatusGet(txn->txn, &status) == TS_SUCCESS) {
-    lua_pushinteger(lua, status);
-  } else {
-    lua_pushinteger(lua, -1);
-  }
-
-  return 1;
-}
-
-static const luaL_Reg HTTPTXN[] =
-{
-  { "abort", LuaHttpTxnAbort },
-  { "continue", LuaHttpTxnContinue },
-  { "register", LuaHttpTxnRegister },
-  { "cachestatus", LuaHttpTxnCacheLookupStatus },
-  { NULL, NULL }
-};
-
-static int
-LuaHttpSsnAbort(lua_State * lua)
-{
-  LuaHttpSession * ssn;
-
-  ssn = LuaHttpSession::get(lua, 1);
-  TSHttpSsnReenable(ssn->ssn, TS_EVENT_HTTP_ERROR);
-
-  return 1;
-}
-
-static int
-LuaHttpSsnContinue(lua_State * lua)
-{
-  LuaHttpSession * ssn;
-
-  ssn = LuaHttpSession::get(lua, 1);
-  TSHttpSsnReenable(ssn->ssn, TS_EVENT_HTTP_CONTINUE);
-
-  return 1;
-}
-
-static int
-LuaHttpSsnRegister(lua_State * lua)
-{
-  LuaHttpSession * ssn;
-  int tableref;
-
-  ssn = LuaHttpSession::get(lua, 1);
-  luaL_checktype(lua, 2, LUA_TTABLE);
-
-  // Keep a reference to the hooks table in ssn->hooks.
-  tableref = luaL_ref(lua, LUA_REGISTRYINDEX);
-
-  // On the other side of the denux, we need the hook, and the table.
-  if (LuaRegisterHttpHooks(lua, ssn->ssn, LuaHttpSsnHookAdd, tableref)) {
-    LuaSetArgReference(ssn->ssn, tableref);
-    return 1;
-  }
-
-  return 0;
-}
-
-static const luaL_Reg HTTPSSN[] =
-{
-  { "register", LuaHttpSsnRegister },
-  { "abort", LuaHttpSsnAbort },
-  { "continue", LuaHttpSsnContinue },
-  { NULL, NULL }
-};
-
-static int
-TSLuaDebug(lua_State * lua)
-{
-  const char * tag = luaL_checkstring(lua, 1);
-  const char * message = luaL_checkstring(lua, 2);
-
-  TSDebug(tag, "%s", message);
-  return 0;
-}
-
-static const luaL_Reg LUAEXPORTS[] =
-{
-  { "debug", TSLuaDebug },
-  { NULL, NULL}
-};
-
-LuaRemapRequest *
-LuaPushRemapRequestInfo(lua_State * lua, TSHttpTxn txn, TSRemapRequestInfo * rri)
-{
-  return push_userdata_object<LuaRemapRequest>(lua, rri, txn);
-}
-
-LuaHttpTransaction *
-LuaPushHttpTransaction(lua_State * lua, TSHttpTxn txn)
-{
-  return push_userdata_object<LuaHttpTransaction>(lua, txn);
-}
-
-LuaHttpSession *
-LuaPushHttpSession(lua_State * lua, TSHttpSsn ssn)
-{
-  return push_userdata_object<LuaHttpSession>(lua, ssn);
-}
-
-int
-LuaApiInit(lua_State * lua)
-{
-  LuaLogDebug("initializing TS API");
-
-  lua_newtable(lua);
-
-  // Register functions in the "ts" module.
-  luaL_register(lua, NULL, LUAEXPORTS);
-
-  // Push constants into the "ts" module.
-  LuaSetConstantField(lua, "VERSION", TSTrafficServerVersionGet());
-  LuaSetConstantField(lua, "MAJOR_VERSION", TSTrafficServerVersionGetMajor());
-  LuaSetConstantField(lua, "MINOR_VERSION", TSTrafficServerVersionGetMinor());
-  LuaSetConstantField(lua, "PATCH_VERSION", TSTrafficServerVersionGetPatch());
-
-  LuaSetConstantField(lua, "CACHE_LOOKUP_MISS", TS_CACHE_LOOKUP_MISS);
-  LuaSetConstantField(lua, "CACHE_LOOKUP_HIT_STALE", TS_CACHE_LOOKUP_HIT_STALE);
-  LuaSetConstantField(lua, "CACHE_LOOKUP_HIT_FRESH", TS_CACHE_LOOKUP_HIT_FRESH);
-  LuaSetConstantField(lua, "CACHE_LOOKUP_SKIPPED", TS_CACHE_LOOKUP_SKIPPED);
-
-  // Register TSRemapRequestInfo metatable.
-  LuaPushMetatable(lua, "ts.meta.rri", RRI);
-  // Pop the metatable.
-  lua_pop(lua, 1);
-
-  // Register the remap headers metatable.
-  LuaPushMetatable(lua, "ts.meta.rri.headers", HEADERS);
-  // Pop the metatable.
-  lua_pop(lua, 1);
-
-  // Register TSHttpTxn metatable.
-  LuaPushMetatable(lua, "ts.meta.http.txn", HTTPTXN);
-  // Pop the metatable.
-  lua_pop(lua, 1);
-
-  // Register TSHttpSsn metatable.
-  LuaPushMetatable(lua, "ts.meta.http.ssn", HTTPSSN);
-  // 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/9a3e5de5/plugins/experimental/lua/lapi.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/lapi.h b/plugins/experimental/lua/lapi.h
deleted file mode 100644
index 2218330..0000000
--- a/plugins/experimental/lua/lapi.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#ifndef LUA_LAPI_H_
-#define LUA_LAPI_H_
-
-#include <lua.hpp>
-
-struct LuaHttpTransaction;
-struct LuaHttpSession;
-
-struct LuaRemapRequest
-{
-  TSRemapRequestInfo *  rri;
-  TSHttpTxn             txn;
-  TSRemapStatus         status;
-
-  LuaRemapRequest(TSRemapRequestInfo * r, TSHttpTxn t) : rri(r), txn(t), status(TSREMAP_NO_REMAP) {}
-  LuaRemapRequest() : rri(NULL), txn(NULL), status(TSREMAP_NO_REMAP) {}
-  ~LuaRemapRequest() {}
-
-  static LuaRemapRequest * get(lua_State * lua, int index);
-  static LuaRemapRequest * alloc(lua_State *, TSRemapRequestInfo *, TSHttpTxn);
-};
-
-// Initialize the 'ts' module.
-int LuaApiInit(lua_State * lua);
-// Initialize the 'ts.config' module.
-int LuaConfigApiInit(lua_State * lua);
-// Initialize the 'ts.hook' module.
-int LuaHookApiInit(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.
-LuaRemapRequest *
-LuaPushRemapRequestInfo(lua_State * lua, TSHttpTxn txn, TSRemapRequestInfo * rri);
-
-// Push a TSHttpTxn userdata object.
-LuaHttpTransaction *
-LuaPushHttpTransaction(lua_State * lua, TSHttpTxn txn);
-
-// Push a TSHttpSsn userdata object.
-LuaHttpSession *
-LuaPushHttpSession(lua_State * lua, TSHttpSsn ssn);
-
-#endif // LUA_LAPI_H_

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/lconfig.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/lconfig.cc b/plugins/experimental/lua/lconfig.cc
deleted file mode 100644
index 292829a..0000000
--- a/plugins/experimental/lua/lconfig.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include "ts/ts.h"
-#include "ts/remap.h"
-#include "ink_defs.h"
-
-#include "lapi.h"
-#include "lutil.h"
-
-// ts.config.override(txn, key, value)
-//
-// Override a configuration entry for this transaction.
-static int
-TSLuaConfigOverride(lua_State * lua)
-{
-  LuaRemapRequest *       rq;
-  TSOverridableConfigKey  key;
-  union {
-    lua_Number  number;
-    lua_Integer integer;
-    struct { const char * str; size_t len; } lstring;
-  } value;
-
-
-  // XXX For now, this only works on remap request objects. When we expose a TSHttpTxn object in Lua, we should
-  // dynamically support passing one of those in as well.
-  rq = LuaRemapRequest::get(lua, 1);
-
-  key = (TSOverridableConfigKey)luaL_checkint(lua, 2);
-
-  switch(lua_type(lua, 3)) {
-    case LUA_TBOOLEAN:
-      TSHttpTxnConfigIntSet(rq->txn, key, lua_toboolean(lua, 3) ? 1 : 0);
-      break;
-    case LUA_TNUMBER:
-      // There's no API that will tell us the correct type to use for numberic override options. Let's try int first,
-      // since that's the common case. If that fails we can try float.
-      value.integer = luaL_checkinteger(lua, 3);
-      if (TSHttpTxnConfigIntSet(rq->txn, key, value.integer) == TS_ERROR) {
-        value.number = luaL_checknumber(lua, 3);
-        TSHttpTxnConfigFloatSet(rq->txn, key, value.number);
-      }
-
-      break;
-    case LUA_TSTRING:
-      value.lstring.str = lua_tolstring(lua, 3, &value.lstring.len);
-      TSHttpTxnConfigStringSet(rq->txn, key, value.lstring.str, value.lstring.len);
-      break;
-  }
-
-  return 0;
-}
-
-static const luaL_Reg LUAEXPORTS[] =
-{
-  { "override", TSLuaConfigOverride },
-  { NULL, NULL}
-};
-
-int
-LuaConfigApiInit(lua_State * lua)
-{
-  LuaLogDebug("initializing TS Config API");
-
-  lua_newtable(lua);
-
-  // Register functions in the "ts.config" module.
-  luaL_register(lua, NULL, LUAEXPORTS);
-
-#define DEFINE_CONFIG_KEY(NAME) LuaSetConstantField(lua, #NAME, TS_CONFIG_ ## NAME)
-  DEFINE_CONFIG_KEY(URL_REMAP_PRISTINE_HOST_HDR);
-  DEFINE_CONFIG_KEY(HTTP_CHUNKING_ENABLED);
-  DEFINE_CONFIG_KEY(HTTP_NEGATIVE_CACHING_ENABLED);
-  DEFINE_CONFIG_KEY(HTTP_NEGATIVE_CACHING_LIFETIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_WHEN_TO_REVALIDATE);
-  DEFINE_CONFIG_KEY(HTTP_KEEP_ALIVE_ENABLED_IN);
-  DEFINE_CONFIG_KEY(HTTP_KEEP_ALIVE_ENABLED_OUT);
-  DEFINE_CONFIG_KEY(HTTP_KEEP_ALIVE_POST_OUT);
-  DEFINE_CONFIG_KEY(HTTP_SHARE_SERVER_SESSIONS);
-  DEFINE_CONFIG_KEY(NET_SOCK_RECV_BUFFER_SIZE_OUT);
-  DEFINE_CONFIG_KEY(NET_SOCK_SEND_BUFFER_SIZE_OUT);
-  DEFINE_CONFIG_KEY(NET_SOCK_OPTION_FLAG_OUT);
-  DEFINE_CONFIG_KEY(HTTP_FORWARD_PROXY_AUTH_TO_PARENT);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_REMOVE_FROM);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_REMOVE_REFERER);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_REMOVE_USER_AGENT);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_REMOVE_COOKIE);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_REMOVE_CLIENT_IP);
-  DEFINE_CONFIG_KEY(HTTP_ANONYMIZE_INSERT_CLIENT_IP);
-  DEFINE_CONFIG_KEY(HTTP_RESPONSE_SERVER_ENABLED);
-  DEFINE_CONFIG_KEY(HTTP_INSERT_SQUID_X_FORWARDED_FOR);
-  DEFINE_CONFIG_KEY(HTTP_SERVER_TCP_INIT_CWND);
-  DEFINE_CONFIG_KEY(HTTP_SEND_HTTP11_REQUESTS);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_HTTP);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_IGNORE_CLIENT_NO_CACHE);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_IGNORE_CLIENT_CC_MAX_AGE);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_IMS_ON_CLIENT_NO_CACHE);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_IGNORE_SERVER_NO_CACHE);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_CACHE_RESPONSES_TO_COOKIES);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_IGNORE_AUTHENTICATION);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_CACHE_URLS_THAT_LOOK_DYNAMIC);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_REQUIRED_HEADERS);
-  DEFINE_CONFIG_KEY(HTTP_INSERT_REQUEST_VIA_STR);
-  DEFINE_CONFIG_KEY(HTTP_INSERT_RESPONSE_VIA_STR);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_HEURISTIC_MIN_LIFETIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_HEURISTIC_MAX_LIFETIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_GUARANTEED_MIN_LIFETIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_GUARANTEED_MAX_LIFETIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_MAX_STALE_AGE);
-  DEFINE_CONFIG_KEY(HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_IN);
-  DEFINE_CONFIG_KEY(HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_OUT);
-  DEFINE_CONFIG_KEY(HTTP_TRANSACTION_NO_ACTIVITY_TIMEOUT_IN);
-  DEFINE_CONFIG_KEY(HTTP_TRANSACTION_NO_ACTIVITY_TIMEOUT_OUT);
-  DEFINE_CONFIG_KEY(HTTP_TRANSACTION_ACTIVE_TIMEOUT_OUT);
-  DEFINE_CONFIG_KEY(HTTP_ORIGIN_MAX_CONNECTIONS);
-  DEFINE_CONFIG_KEY(HTTP_CONNECT_ATTEMPTS_MAX_RETRIES);
-  DEFINE_CONFIG_KEY(HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DEAD_SERVER);
-  DEFINE_CONFIG_KEY(HTTP_CONNECT_ATTEMPTS_RR_RETRIES);
-  DEFINE_CONFIG_KEY(HTTP_CONNECT_ATTEMPTS_TIMEOUT);
-  DEFINE_CONFIG_KEY(HTTP_POST_CONNECT_ATTEMPTS_TIMEOUT);
-  DEFINE_CONFIG_KEY(HTTP_DOWN_SERVER_CACHE_TIME);
-  DEFINE_CONFIG_KEY(HTTP_DOWN_SERVER_ABORT_THRESHOLD);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_FUZZ_TIME);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_FUZZ_MIN_TIME);
-  DEFINE_CONFIG_KEY(HTTP_DOC_IN_CACHE_SKIP_DNS);
-  DEFINE_CONFIG_KEY(HTTP_RESPONSE_SERVER_STR);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_HEURISTIC_LM_FACTOR);
-  DEFINE_CONFIG_KEY(HTTP_CACHE_FUZZ_PROBABILITY);
-  DEFINE_CONFIG_KEY(NET_SOCK_PACKET_MARK_OUT);
-  DEFINE_CONFIG_KEY(NET_SOCK_PACKET_TOS_OUT);
-  DEFINE_CONFIG_KEY(HTTP_INSERT_AGE_IN_RESPONSE);
-#undef DEFINE_CONFIG_KEY
-
-  return 1;
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/lutil.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/lutil.cc b/plugins/experimental/lua/lutil.cc
deleted file mode 100644
index 6971fb7..0000000
--- a/plugins/experimental/lua/lutil.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include "ts/ts.h"
-#include "ts/remap.h"
-#include "ink_defs.h"
-
-#include "lapi.h"
-#include "lutil.h"
-#include <pthread.h>
-#include <unistd.h>
-
-int LuaHttpArgIndex;
-
-#if !defined(LUAJIT_VERSION)
-static void *
-LuaAllocate(void * ud, void * ptr, size_t /* osize ATS_UNUSED */, size_t nsize)
-{
-  TSReleaseAssert(ud == NULL);
-
-  if (nsize == 0) {
-    TSfree(ptr);
-    return NULL;
-  }
-
-  return TSrealloc(ptr, nsize);
-}
-#endif
-
-lua_State *
-LuaNewState()
-{
-  return LuaPluginNewState();
-}
-
-lua_State *
-LuaPluginNewState(void)
-{
-  lua_State * lua;
-
-  // lua_newstate() is a stub in LuaJIT 64-bit.
-#if defined(LUAJIT_VERSION)
-  lua = luaL_newstate();
-#else
-  lua = lua_newstate(LuaAllocate, NULL);
-#endif
-  if (lua == NULL) {
-    return NULL;
-  }
-
-  LuaLoadLibraries(lua);
-  LuaRegisterLibrary(lua, "ts", LuaApiInit);
-  LuaRegisterLibrary(lua, "ts.config", LuaConfigApiInit);
-  LuaRegisterLibrary(lua, "ts.hook", LuaHookApiInit);
-
-  return lua;
-}
-
-void
-LuaPushMetatable(lua_State * lua, const char * name, const luaL_Reg * exports)
-{
-  luaL_newmetatable(lua, name);
-  lua_pushvalue(lua, -1);
-  lua_setfield(lua, -2, "__index");
-  luaL_register(lua, NULL, exports);
-}
-
-void
-LuaRegisterLibrary(lua_State * lua, const char * name, lua_CFunction loader)
-{
-  // Pull up the preload table.
-  lua_getglobal(lua, "package");
-  lua_getfield(lua, -1, "preload");
-
-  lua_pushcfunction(lua, loader);
-  lua_setfield(lua, -2, name);
-
-  // Pop the 'package' and 'preload' tables.
-  lua_pop(lua, 2);
-}
-
-void
-LuaLoadLibraries(lua_State * lua)
-{
-#define REGISTER_LIBRARY(name) LuaRegisterLibrary(lua, #name, luaopen_ ## name)
-
-    lua_cpcall(lua, luaopen_base, NULL);
-    lua_cpcall(lua, luaopen_package, NULL);
-
-    REGISTER_LIBRARY(io);
-    REGISTER_LIBRARY(os);
-    REGISTER_LIBRARY(table);
-    REGISTER_LIBRARY(string);
-    REGISTER_LIBRARY(math);
-    REGISTER_LIBRARY(debug);
-
-    // XXX LuaJIT recommends calling luaL_openlibs() here. No explanation of why.
-
-#undef REGISTER_LIBRARY
-}
-
-void
-LuaSetConstantField(lua_State * lua, const char * name, int value)
-{
-  lua_pushinteger(lua, value);
-  lua_setfield(lua, -2, name);
-}
-
-void
-LuaSetConstantField(lua_State * lua, const char * name, const char * value)
-{
-  lua_pushstring(lua, value);
-  lua_setfield(lua, -2, name);
-}
-
-void
-LuaDebugStack(lua_State * lua)
-{
-  int top = lua_gettop(lua);
-
-  for (int i = 1; i <= top; i++) {
-    LuaLogDebug("stack[%d] %s", i, ltypeof(lua, i));
-  }
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/lutil.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/lutil.h b/plugins/experimental/lua/lutil.h
deleted file mode 100644
index 90818d3..0000000
--- a/plugins/experimental/lua/lutil.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#ifndef LUA_LUTIL_H_
-#define LUA_LUTIL_H_
-
-#include <lua.hpp>
-#include <vector>
-#include <string>
-#include <memory>
-#include <pthread.h>
-#include "ink_defs.h"
-
-// Global argument index for TSHttpSsnArgGet and TSHttpTxnArgGet.
-extern int LuaHttpArgIndex;
-
-#define LuaLogDebug(fmt, ...) do { \
-    if (unlikely(TSIsDebugTagSet("lua"))) { \
-        TSDebug("lua", "%s: " fmt, __func__, ##__VA_ARGS__); \
-    } \
-} while (0)
-
-// In DEBUG mode, log errors to the debug channel. This is handy for making Lua runtime
-// errors show up on stdout along with the rest of the debug loggin.
-#if DEBUG
-#define LuaLogError(fmt, ...) LuaLogDebug(fmt, ##__VA_ARGS__)
-#else
-#define LuaLogError(fmt, ...) TSError(fmt, ##__VA_ARGS__)
-#endif
-
-// Debug log the Lua stack.
-void LuaDebugStack(lua_State *);
-
-// Return the type name string for the given index.
-static inline const char *
-ltypeof(lua_State * lua, int index) {
-  return lua_typename(lua, lua_type(lua, index));
-}
-
-template <typename T> T * tsnew() {
-  void * ptr = TSmalloc(sizeof(T));
-  return new(ptr) T();
-}
-
-template <typename T> void tsdelete(T * ptr) {
-  if (ptr) {
-    ptr->~T();
-    TSfree(ptr);
-  }
-}
-
-// Allocate an object with lua_newuserdata() and call the default constructor.
-template <typename T> T * LuaNewUserData(lua_State * lua) {
-  void * ptr = lua_newuserdata(lua, sizeof(T));
-  return new(ptr) T();
-}
-
-void LuaPushMetatable(lua_State * lua, const char * name, const luaL_Reg * exports);
-void LuaLoadLibraries(lua_State * lua);
-void LuaRegisterLibrary(lua_State * lua, const char * name, lua_CFunction loader);
-
-// Set the named field in the table on the top of the stack.
-void LuaSetConstantField(lua_State * lua, const char * name, int value);
-void LuaSetConstantField(lua_State * lua, const char * name, const char * value);
-
-// Allocate a new lua_State.
-lua_State * LuaNewState();
-lua_State * LuaPluginNewState(void);
-
-#endif // LUA_LUTIL_H_

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/plugin.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/plugin.cc b/plugins/experimental/lua/plugin.cc
deleted file mode 100644
index 1c96e3b..0000000
--- a/plugins/experimental/lua/plugin.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include <ts/ts.h>
-#include "lutil.h"
-#include "hook.h"
-#include "state.h"
-
-extern "C" void
-TSPluginInit(int argc, const char * argv[])
-{
-  TSPluginRegistrationInfo  info;
-  instanceid_t              instanceid;
-
-  info.plugin_name = (char *)"lua";
-  info.vendor_name = (char *)"Apache Software Foundation";
-  info.support_email = (char *)"dev@trafficserver.apache.org";
-
-  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
-      LuaLogError("Plugin registration failed");
-  }
-
-  // Allocate a TSHttpTxn argument index for handling per-transaction hooks.
-  TSReleaseAssert(TSHttpArgIndexReserve("lua", "lua", &LuaHttpArgIndex) == TS_SUCCESS);
-
-  // Register a new Lua plugin instance, skipping the first argument (which is the plugin name).
-  instanceid = LuaPluginRegister((unsigned)argc - 1, (const char **)argv + 1);
-  TSReleaseAssert(instanceid == 0);
-}
-

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/remap.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/remap.cc b/plugins/experimental/lua/remap.cc
deleted file mode 100644
index ac42075..0000000
--- a/plugins/experimental/lua/remap.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include "ts/ts.h"
-#include "ts/remap.h"
-#include "ink_defs.h"
-
-#include "lapi.h"
-#include "lutil.h"
-#include "state.h"
-#include <unistd.h>
-#include <pthread.h>
-
-static pthread_mutex_t PluginInstanceLock = PTHREAD_MUTEX_INITIALIZER;
-
-static TSRemapStatus
-LuaPluginRemap(lua_State * lua, TSHttpTxn txn, TSRemapRequestInfo * rri)
-{
-  LuaRemapRequest * rq;
-
-  lua_getglobal(lua, "remap");
-  if (lua_isnil(lua, -1)) {
-    // No "remap" callback, better continue.
-    return TSREMAP_NO_REMAP;
-  }
-
-  LuaLogDebug("handling request %p on thread 0x%llx", rri, (unsigned long long)pthread_self());
-
-  // XXX We can also cache the RemapRequestInfo in the Lua state. We we just need to reset
-  // the rri pointer and status.
-  rq = LuaPushRemapRequestInfo(lua, txn, rri);
-
-  if (lua_pcall(lua, 1, 0, 0) != 0) {
-    LuaLogDebug("remap failed: %s", lua_tostring(lua, -1));
-    lua_pop(lua, 1);
-    return TSREMAP_ERROR;
-  }
-
-  // XXX can we guarantee that rq has not been garbage collected?
-  return rq->status;
-}
-
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info ATS_UNUSED */, char * /* errbuf ATS_UNUSED */,
-            int /* errbuf_size ATS_UNUSED */)
-{
-  LuaLogDebug("loading lua plugin");
-
-  // Allocate a TSHttpTxn argument index for handling per-transaction hooks.
-  TSReleaseAssert(TSHttpArgIndexReserve("lua", "lua", &LuaHttpArgIndex) == TS_SUCCESS);
-
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char * argv[], void ** ih, char * /* errbuf ATS_UNUSED */, int /* errsz ATS_UNUSED */)
-{
-  instanceid_t instanceid;
-
-  pthread_mutex_lock(&PluginInstanceLock);
-
-  // Register a new Lua plugin instance, skipping the first two arguments (which are the remap URLs).
-  instanceid = LuaPluginRegister((unsigned)argc - 2, (const char **)argv + 2);
-  *ih = (void *)(intptr_t)instanceid;
-
-  pthread_mutex_unlock(&PluginInstanceLock);
-
-  LuaLogDebug("created Lua remap instance %u", instanceid);
-  return TS_SUCCESS;
-}
-
-void
-TSRemapDeleteInstance(void * ih)
-{
-  instanceid_t instanceid = (intptr_t)ih;
-
-  pthread_mutex_lock(&PluginInstanceLock);
-  LuaPluginUnregister(instanceid);
-  pthread_mutex_unlock(&PluginInstanceLock);
-}
-
-TSRemapStatus
-TSRemapDoRemap(void * ih, TSHttpTxn txn, TSRemapRequestInfo * rri)
-{
-  ScopedLuaState lstate((intptr_t)ih);
-
-  TSReleaseAssert(lstate);
-  return LuaPluginRemap(lstate->lua, txn, rri);
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/9a3e5de5/plugins/experimental/lua/state.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/lua/state.cc b/plugins/experimental/lua/state.cc
deleted file mode 100644
index 502e6fd..0000000
--- a/plugins/experimental/lua/state.cc
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
-  Licensed to the Apache Software Foundation (ASF) under one
-  or more contributor license agreements.  See the NOTICE file
-  distributed with this work for additional information
-  regarding copyright ownership.  The ASF licenses this file
-  to you under the Apache License, Version 2.0 (the
-  "License"); you may not use this file except in compliance
-  with the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-*/
-
-#include "ts/ts.h"
-#include "ts/remap.h"
-#include "ink_defs.h"
-
-#include "state.h"
-#include "hook.h"
-#include "lutil.h"
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-
-#define INVALID_INSTANCE_ID (instanceid_t)(-1)
-
-// InitDemuxTable() requires an initializer for every hook. Make sure that we don't
-// get out of sync with the number of hooks.
-extern void * __static_assert_hook_count[TS_HTTP_LAST_HOOK == 17 ? 0 : -1];
-
-typedef int (*LuaHookDemuxer)(TSHttpHookID, TSCont, TSEvent, void *);
-
-template <TSHttpHookID hookid, LuaHookDemuxer demuxer> int
-DemuxSpecificHook(TSCont cont, TSEvent event, void * edata) {
-  return demuxer(hookid, cont, event, edata);
-}
-
-template <LuaHookDemuxer demuxer> void
-InitDemuxTable(LuaPluginInstance::demux_table_t& table)
-{
-#define MakeLuaHook(demuxer, hookid) TSContCreate(DemuxSpecificHook<hookid, demuxer>, NULL)
-
-  table[TS_HTTP_READ_REQUEST_HDR_HOOK]  = MakeLuaHook(demuxer, TS_HTTP_READ_REQUEST_HDR_HOOK);
-  table[TS_HTTP_OS_DNS_HOOK]            = MakeLuaHook(demuxer, TS_HTTP_OS_DNS_HOOK);
-  table[TS_HTTP_SEND_REQUEST_HDR_HOOK]  = MakeLuaHook(demuxer, TS_HTTP_SEND_REQUEST_HDR_HOOK);
-  table[TS_HTTP_READ_CACHE_HDR_HOOK]    = MakeLuaHook(demuxer, TS_HTTP_READ_CACHE_HDR_HOOK);
-  table[TS_HTTP_READ_RESPONSE_HDR_HOOK] = MakeLuaHook(demuxer, TS_HTTP_READ_RESPONSE_HDR_HOOK);
-  table[TS_HTTP_SEND_RESPONSE_HDR_HOOK] = MakeLuaHook(demuxer, TS_HTTP_SEND_RESPONSE_HDR_HOOK);
-  table[TS_HTTP_REQUEST_TRANSFORM_HOOK] = MakeLuaHook(demuxer, TS_HTTP_REQUEST_TRANSFORM_HOOK);
-  table[TS_HTTP_RESPONSE_TRANSFORM_HOOK]= MakeLuaHook(demuxer, TS_HTTP_RESPONSE_TRANSFORM_HOOK);
-  table[TS_HTTP_SELECT_ALT_HOOK]        = MakeLuaHook(demuxer, TS_HTTP_SELECT_ALT_HOOK);
-  table[TS_HTTP_TXN_START_HOOK]         = MakeLuaHook(demuxer, TS_HTTP_TXN_START_HOOK);
-  table[TS_HTTP_TXN_CLOSE_HOOK]         = MakeLuaHook(demuxer, TS_HTTP_TXN_CLOSE_HOOK);
-  table[TS_HTTP_SSN_START_HOOK]         = MakeLuaHook(demuxer, TS_HTTP_SSN_START_HOOK);
-  table[TS_HTTP_SSN_CLOSE_HOOK]         = MakeLuaHook(demuxer, TS_HTTP_SSN_CLOSE_HOOK);
-  table[TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK] = MakeLuaHook(demuxer, TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK);
-  table[TS_HTTP_PRE_REMAP_HOOK]         = MakeLuaHook(demuxer, TS_HTTP_PRE_REMAP_HOOK);
-  table[TS_HTTP_POST_REMAP_HOOK]        = MakeLuaHook(demuxer, TS_HTTP_POST_REMAP_HOOK);
-  table[TS_HTTP_RESPONSE_CLIENT_HOOK]   = MakeLuaHook(demuxer, TS_HTTP_RESPONSE_CLIENT_HOOK);
-}
-
-// Global storage for Lua plugin instances. We vend instanceid_t's as an index into
-// this array.
-static std::vector<LuaPluginInstance *> LuaPluginStorage;
-
-template <typename T> struct is_integral_type {
-  enum { value = 0, is_pointer = 0 };
-};
-
-template <typename T> struct is_integral_type<T *> {
-  enum { value = 1, is_pointer = 1 };
-};
-
-template <> struct is_integral_type<int> { enum { value = 1, is_pointer = 0 }; };
-template <> struct is_integral_type<unsigned> { enum { value = 1, is_pointer = 0 }; };
-template <> struct is_integral_type<long> { enum { value = 1, is_pointer = 0 }; };
-template <> struct is_integral_type<unsigned long> { enum { value = 1, is_pointer = 0 }; };
-
-static unsigned
-nproc()
-{
-  long count;
-
-  count = sysconf(_SC_NPROCESSORS_ONLN);
-  return (unsigned)std::max(count, 1l);
-}
-
-static unsigned
-thread_id()
-{
-  pthread_t self = pthread_self();
-
-  if (is_integral_type<pthread_t>::value) {
-    // If it's a pointer, then the lower bits are probably zero because it's
-    // likely to be 8 or 16 byte aligned.
-    if (is_integral_type<pthread_t>::is_pointer) {
-      return (unsigned)((intptr_t)self >> 4);
-    }
-    return (unsigned)(intptr_t)self;
-  } else {
-    // XXX make this work on FreeBSD!
-    TSReleaseAssert(0 && "unsupported platform");
-    return 0;
-  }
-}
-
-LuaPluginInstance::LuaPluginInstance()
-  : instanceid(INVALID_INSTANCE_ID), paths(), states()
-{
-}
-
-LuaPluginInstance::~LuaPluginInstance()
-{
-  this->invalidate();
-}
-
-void
-LuaPluginInstance::invalidate()
-{
-  for (unsigned i = 0; i < this->states.size(); ++ i) {
-    tsdelete(this->states[i]);
-  }
-
-  this->states.clear();
-  this->paths.clear();
-  this->instanceid = INVALID_INSTANCE_ID;
-
-  for (unsigned i = 0; i < countof(this->demux.global); ++i) {
-    TSContDestroy(this->demux.global[i]);
-    TSContDestroy(this->demux.ssn[i]);
-    TSContDestroy(this->demux.txn[i]);
-    this->demux.global[i] = this->demux.ssn[i] = this->demux.txn[i] = NULL;
-  }
-
-}
-
-void
-LuaPluginInstance::init(unsigned argc, const char ** argv)
-{
-  for (unsigned i = 0; i < argc; ++i) {
-    this->paths.push_back(argv[i]);
-  }
-
-  // Make sure we have enough threads to make concurrent access to lua
-  // states unlikely.
-  this->states.resize(nproc() * 2);
-
-  InitDemuxTable<LuaDemuxGlobalHook>(this->demux.global);
-  InitDemuxTable<LuaDemuxSsnHook>(this->demux.ssn);
-  InitDemuxTable<LuaDemuxTxnHook>(this->demux.txn);
-
-  for (unsigned i = 0; i < countof(this->demux.global); ++i) {
-    TSContDataSet(this->demux.global[i], (void *)(uintptr_t)this->instanceid);
-    TSContDataSet(this->demux.ssn[i], (void *)(uintptr_t)this->instanceid);
-    TSContDataSet(this->demux.txn[i], (void *)(uintptr_t)this->instanceid);
-  }
-
-}
-
-instanceid_t
-LuaPluginRegister(unsigned argc, const char ** argv)
-{
-  instanceid_t instanceid = INVALID_INSTANCE_ID;
-  LuaPluginInstance * plugin;
-
-  LuaLogDebug("registering plugin");
-
-  // OK, first we try to find an unused instance slot.
-  for (unsigned i = 0; i < LuaPluginStorage.size(); ++i) {
-    if (LuaPluginStorage[i] == NULL) {
-      // This slot looks ok, let's try to claim it.
-      instanceid = i;
-      break;
-    }
-  }
-
-  // Take the current instanceid, incrementing it for next time.
-  if (instanceid == INVALID_INSTANCE_ID) {
-    instanceid = LuaPluginStorage.size();
-    LuaPluginStorage.resize(LuaPluginStorage.size() + 1);
-  }
-
-  // Mark this plugin instance as in use.
-  plugin = LuaPluginStorage[instanceid] = tsnew<LuaPluginInstance>();
-  plugin->instanceid = instanceid;
-
-  // The path list should be empty if we correctly released it last time this
-  // instance ID was used.
-  TSReleaseAssert(plugin->paths.empty());
-  LuaPluginStorage[instanceid]->init(argc, argv);
-
-  // Allocate the Lua states, then separately initialize by evaluating all the Lua files.
-  for (unsigned i = 0; i < plugin->states.size(); ++i) {
-    plugin->states[i] = tsnew<LuaThreadState>();
-    plugin->states[i]->alloc(plugin, i);
-  }
-
-  for (unsigned i = 0; i < LuaPluginStorage[instanceid]->states.size(); ++i) {
-    plugin->states[i]->init(plugin);
-  }
-
-  return instanceid;
-}
-
-void
-LuaPluginUnregister(instanceid_t instanceid)
-{
-  TSReleaseAssert(instanceid < LuaPluginStorage.size());
-  tsdelete(LuaPluginStorage[instanceid]);
-  LuaPluginStorage[instanceid] = NULL;
-}
-
-LuaThreadState::LuaThreadState()
-  : lua(NULL), instance(NULL)
-{
-  pthread_mutexattr_t attr;
-
-  // We need a recursive mutex so that we can safely reacquire it from Lua code.
-  TSReleaseAssert(pthread_mutexattr_init(&attr) == 0);
-  TSReleaseAssert(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);
-  TSReleaseAssert(pthread_mutex_init(&this->mutex, &attr) == 0);
-
-  for (unsigned i = 0; i < countof(this->hookrefs); ++i) {
-    this->hookrefs[i] = LUA_NOREF;
-  }
-
-  pthread_mutexattr_destroy(&attr);
-}
-
-LuaThreadState::~LuaThreadState()
-{
-  this->release();
-  pthread_mutex_destroy(&this->mutex);
-}
-
-bool
-LuaThreadState::alloc(LuaPluginInstance * plugin, unsigned threadid)
-{
-  this->lua = LuaNewState();
-  this->instance = plugin;
-
-  // Push the instanceid into a global integer. We will use this later to rendevous
-  // with the lthread from the lua_State. We have to set the instanceid global before
-  // executing any Lua code, because that will almost certainly call back into the plugin
-  // ad reguire the instance id to be set.
-  lua_pushinteger(this->lua, plugin->instanceid);
-  lua_setfield(this->lua, LUA_REGISTRYINDEX, "__instanceid");
-
-  lua_pushinteger(this->lua, threadid);
-  lua_setfield(this->lua, LUA_REGISTRYINDEX, "__threadid");
-
-  return true;
-}
-
-bool
-LuaThreadState::init(LuaPluginInstance * plugin)
-{
-  for (LuaPluginInstance::pathlist_t::const_iterator p = plugin->paths.begin(); p < plugin->paths.end(); ++p) {
-    LuaLogDebug("loading Lua program from %s", p->c_str());
-    if (access(p->c_str(), F_OK) != 0) {
-      LuaLogError("%s: %s", p->c_str(), strerror(errno));
-      continue;
-    }
-
-    if (luaL_dofile(this->lua, p->c_str()) != 0) {
-      // If the load failed, it should have pushed an error message.
-      LuaLogError("failed to load Lua file %s: %s", p->c_str(), lua_tostring(lua, -1));
-      return false;
-    }
-  }
-
-  return true;
-}
-
-void
-LuaThreadState::release()
-{
-  if (this->lua) {
-    lua_close(this->lua);
-    this->lua = NULL;
-  }
-}
-
-std::pair<LuaThreadState *, LuaPluginInstance *>
-LuaThreadStateAcquire(lua_State * lua)
-{
-  LuaThreadState * lthread;
-  LuaPluginInstance * instance;
-  instanceid_t instanceid;
-  unsigned threadid;
-
-  lua_getfield(lua, LUA_REGISTRYINDEX, "__instanceid");
-  instanceid = (instanceid_t)luaL_checkinteger(lua, -1);
-
-  lua_getfield(lua, LUA_REGISTRYINDEX, "__threadid");
-  threadid = (unsigned)luaL_checkinteger(lua, -1);
-
-  TSReleaseAssert(instanceid < LuaPluginStorage.size());
-
-  instance = LuaPluginStorage[instanceid];
-
-  TSReleaseAssert(threadid < instance->states.size());
-  lthread = instance->states[threadid];
-
-  LuaLogDebug("%u/%p acquired state %u from plugin instance %u on thread %u",
-      instanceid, lthread->lua, threadid, instanceid, thread_id());
-
-  lua_pop(lua, 2);
-
-  // Since we already hav a lua_State, we must already be holding the lock. But acquire
-  // and release come in matched pairs, so we need a recursive lock to release.
-  TSReleaseAssert(pthread_mutex_lock(&lthread->mutex) == 0);
-  return std::make_pair(lthread, instance);
-}
-
-std::pair<LuaThreadState *, LuaPluginInstance *>
-LuaThreadStateAcquire(instanceid_t instanceid)
-{
-  LuaThreadState * lthread;
-  LuaPluginInstance * instance;
-  unsigned which;
-
-  TSReleaseAssert(instanceid < LuaPluginStorage.size());
-
-  instance = LuaPluginStorage[instanceid];
-
-  // Index the set of LuaThreadStates with the thread ID. We might want to do a proper
-  // hash on this to prevent false sharing.
-  which = thread_id() % instance->states.size();
-  lthread = instance->states[which];
-
-  LuaLogDebug("%u/%p acquired state %u from plugin instance %u on thread %u",
-      instanceid, lthread->lua, which, instanceid, thread_id());
-
-  TSReleaseAssert(pthread_mutex_lock(&lthread->mutex) == 0);
-  return std::make_pair(lthread, instance);
-}
-
-void
-LuaThreadStateRelease(LuaThreadState * lthread)
-{
-  TSReleaseAssert(pthread_mutex_unlock(&lthread->mutex) == 0);
-}