trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject [1/5] initial atscppapi commit
Date Fri, 18 Oct 2013 21:51:08 GMT
Updated Branches:
  refs/heads/master cc25667ca -> 7b2ea5f89


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/include/atscppapi/noncopyable.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/atscppapi/noncopyable.h b/lib/atscppapi/src/include/atscppapi/noncopyable.h
new file mode 100644
index 0000000..6c1c5f4
--- /dev/null
+++ b/lib/atscppapi/src/include/atscppapi/noncopyable.h
@@ -0,0 +1,64 @@
+/**
+  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.
+ */
+
+/**
+ * @file noncopyable.h
+ * @brief A base class used to prevent dervied classes from being copyable, this effectively
+ * eliminates the copy constructor and assignment operator.
+ */
+
+#pragma once
+#ifndef ATSCPPAPI_NONCOPYABLE_H_
+#define ATSCPPAPI_NONCOPYABLE_H_
+
+namespace atscppapi {
+
+/**
+ * @brief noncopyable is a base class that will prevent derived classes from being copied.
+ *
+ * @private Prevent Doxygen from showing this class in the inheritance diagrams.
+ *
+ * To use noncopyable you only need to inherit from this class and you're derived class
+ * will become uncopyable
+ *
+ * \code
+ * class myClass : uncopyable {
+ * public:
+ *  int test_;
+ * }
+ *
+ * // The following will fail:
+ * myClass a;
+ * myClass b(a); // fails
+ * myClass c = a; // fails
+ * \endcode
+ */
+class noncopyable
+{
+protected:
+  noncopyable() {}
+  ~noncopyable() {}
+private:
+  noncopyable(const noncopyable&);
+  const noncopyable& operator=(const noncopyable&);
+};
+
+} /* atscppapi */
+
+
+#endif /* ATSCPPAPI_NONCOPYABLE_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/include/atscppapi/shared_ptr.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/atscppapi/shared_ptr.h b/lib/atscppapi/src/include/atscppapi/shared_ptr.h
new file mode 100644
index 0000000..3207405
--- /dev/null
+++ b/lib/atscppapi/src/include/atscppapi/shared_ptr.h
@@ -0,0 +1,41 @@
+/**
+  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.
+ */
+/**
+ * @file shared_ptr.h
+ *
+ * Shared pointer declaration.
+ */
+
+#pragma once
+#ifndef ASTCPPAPI_SHARED_PTR_H_
+#define ASTCPPAPI_SHARED_PTR_H_
+
+#include <tr1/memory>
+
+namespace atscppapi {
+
+/**
+ * Force the use of std::tr1::shared_ptr
+ * \todo Consider adding a simple macro to check if c++0x/11 is enabled
+ * and if so change it to std::shared_ptr and #include <memory>s
+ */
+using std::tr1::shared_ptr;
+
+} /* atscppapi */
+
+#endif /* SHARED_PTR_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/include/atscppapi/utils.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/atscppapi/utils.h b/lib/atscppapi/src/include/atscppapi/utils.h
new file mode 100644
index 0000000..85b8c9e
--- /dev/null
+++ b/lib/atscppapi/src/include/atscppapi/utils.h
@@ -0,0 +1,69 @@
+/**
+  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.
+ */
+
+/**
+ * @file utils.h
+ * @brief Contains utility functions available to users of the api.
+ *
+ */
+
+#pragma once
+#ifndef ATSCPPAPI_UTILS_H_
+#define ATSCPPAPI_UTILS_H_
+
+#include <string>
+#include <arpa/inet.h>
+#include <stdint.h>
+
+namespace atscppapi {
+namespace utils {
+
+/**
+ * @brief Returns a pretty printed string of a sockaddr *
+ *
+ * @param sockaddr* A pointer to a sockaddr *
+ * @return a string which is the pretty printed address
+ */
+std::string getIpString(const sockaddr *);
+
+/**
+ * @brief Returns just the port portion of the sockaddr *
+ *
+ * @param sockaddr* A pointer to a sockaddr *
+ * @return a uint16_t which is the port from the sockaddr *
+ */
+uint16_t getPort(const sockaddr *);
+
+/**
+ * @brief Returns a pretty printed string of a sockaddr * including port
+ *
+ * @param sockaddr* A pointer to a sockaddr *
+ * @return a string which is the pretty printed address including port
+ */
+std::string getIpPortString(const sockaddr *);
+
+/**
+ * @brief This is the environment variable that disables caching in all
+ * types including InitializableValue.
+ */
+extern const std::string DISABLE_DATA_CACHING_ENV_FLAG;
+
+}
+}
+
+#endif /* ATSCPPAPI_UTILS_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/include/logging_internal.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/logging_internal.h b/lib/atscppapi/src/include/logging_internal.h
new file mode 100644
index 0000000..7a6ac27
--- /dev/null
+++ b/lib/atscppapi/src/include/logging_internal.h
@@ -0,0 +1,44 @@
+/**
+  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.
+ */
+
+/**
+ * @file logging_internal.h
+ *
+ *
+ * @brief logging used inside the atscppapi library.
+ */
+
+#pragma once
+#ifndef ATSCPPAPI_LOGGING_INTERNAL_H_
+#define ATSCPPAPI_LOGGING_INTERNAL_H_
+
+#include "atscppapi/Logger.h"
+
+// Because we have the helper in Logger.h with the same name.
+#ifdef LOG_DEBUG
+#undef LOG_DEBUG
+#endif
+
+#ifdef LOG_ERROR
+#undef LOG_ERROR
+#endif
+
+#define LOG_DEBUG(fmt, ...) TS_DEBUG("atscppapi", fmt, ## __VA_ARGS__)
+#define LOG_ERROR(fmt, ...) TS_ERROR("atscppapi", fmt, ## __VA_ARGS__)
+
+#endif /* ATSCPPAPI_LOGGING_INTERNAL_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/include/utils_internal.h
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/include/utils_internal.h b/lib/atscppapi/src/include/utils_internal.h
new file mode 100644
index 0000000..0eb499e
--- /dev/null
+++ b/lib/atscppapi/src/include/utils_internal.h
@@ -0,0 +1,89 @@
+/**
+  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.
+ */
+
+/**
+ * @file atsutils.h
+ *
+ *
+ * @brief internal utilities for atscppapi
+ */
+
+#pragma once
+#ifndef ATSCPPAPI_ATSUTILS_H_
+#define ATSCPPAPI_ATSUTILS_H_
+
+#include <ts/ts.h>
+#include <string>
+#include "atscppapi/GlobalPlugin.h"
+#include "atscppapi/TransactionPlugin.h"
+#include "atscppapi/TransformationPlugin.h"
+#include "atscppapi/Plugin.h"
+#include "atscppapi/HttpVersion.h"
+#include "atscppapi/utils.h"
+#include "atscppapi/AsyncHttpFetch.h"
+#include "atscppapi/Transaction.h"
+
+namespace atscppapi {
+
+namespace utils {
+
+/**
+ * @private
+ */
+class internal {
+public:
+  static TSHttpHookID convertInternalHookToTsHook(Plugin::HookType);
+  static TSHttpHookID convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type);
+  static void invokePluginForEvent(TransactionPlugin *, TSHttpTxn, TSEvent);
+  static void invokePluginForEvent(GlobalPlugin *, TSHttpTxn, TSEvent);
+  static HttpVersion getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc);
+  static void initTransactionManagement();
+  static std::string consumeFromTSIOBufferReader(TSIOBufferReader);
+  static shared_ptr<Mutex> getTransactionPluginMutex(TransactionPlugin &);
+  static Transaction &getTransaction(TSHttpTxn);
+
+  static AsyncHttpFetchState *getAsyncHttpFetchState(AsyncHttpFetch &async_http_fetch) {
+    return async_http_fetch.state_;
+  }
+
+  static void initResponse(Response &response, TSMBuffer hdr_buf, TSMLoc hdr_loc) {
+    response.init(hdr_buf, hdr_loc);
+  }
+
+  static void initTransactionServerRequest(Transaction &transaction) {
+    transaction.initServerRequest();
+  }
+
+  static void initTransactionServerResponse(Transaction &transaction) {
+    transaction.initServerResponse();
+  }
+
+  static void initTransactionClientResponse(Transaction &transaction) {
+    transaction.initClientResponse();
+  }
+
+  static const std::list<TransactionPlugin *> &getTransactionPlugins(const Transaction &transaction) {
+    return transaction.getPlugins();
+  }
+}; /* internal */
+
+} /* utils */
+
+}
+
+#endif /* ATSCPPAPI_ATSUTILS_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/utils.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/utils.cc b/lib/atscppapi/src/utils.cc
new file mode 100644
index 0000000..d547bb2
--- /dev/null
+++ b/lib/atscppapi/src/utils.cc
@@ -0,0 +1,79 @@
+/**
+  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.
+ */
+
+/**
+ * @file utils.cc
+ */
+
+#include "atscppapi/utils.h"
+#include <sstream>
+#include <arpa/inet.h>
+#include <ts/ts.h>
+#include "logging_internal.h"
+
+const std::string atscppapi::utils::DISABLE_DATA_CACHING_ENV_FLAG("ATSCPPAPI_DISABLE_TRANSACTION_DATA_CACHING");
+
+std::string atscppapi::utils::getIpString(const sockaddr *sockaddress) {
+  if (sockaddress == NULL) {
+    LOG_ERROR("Cannot work on NULL sockaddress");
+   return std::string();
+  }
+
+  char buf[INET6_ADDRSTRLEN];
+
+  switch (sockaddress->sa_family) {
+  case AF_INET:
+    inet_ntop(AF_INET, &(((struct sockaddr_in *) sockaddress)->sin_addr), buf, INET_ADDRSTRLEN);
+    return std::string(buf);
+  case AF_INET6:
+    inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN);
+    return std::string(buf);
+  default:
+    LOG_ERROR("Unknown Address Family %d", static_cast<int>(sockaddress->sa_family));
+    return std::string();
+  }
+}
+
+uint16_t atscppapi::utils::getPort(const sockaddr *sockaddress) {
+  if (sockaddress == NULL) {
+    LOG_ERROR("Cannot work on NULL sockaddress");
+    return 0;
+  }
+
+  if (sockaddress->sa_family == AF_INET) {
+    return ntohs((((struct sockaddr_in*) sockaddress)->sin_port));
+  } else if (sockaddress->sa_family == AF_INET6) {
+    return ntohs((((struct sockaddr_in6*) sockaddress)->sin6_port));
+  } else {
+    LOG_ERROR("Unknown Address Family %d", static_cast<int>(sockaddress->sa_family));
+    return 0;
+  }
+}
+
+std::string atscppapi::utils::getIpPortString(const sockaddr *sockaddress) {
+  if (sockaddress == NULL) {
+    LOG_ERROR("Cannot work on NULL sockaddress");
+    return std::string();
+  }
+
+  std::ostringstream oss;
+  oss << getIpString(sockaddress);
+  oss << ":";
+  oss << getPort(sockaddress);
+  return oss.str();
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/atscppapi/src/utils_internal.cc
----------------------------------------------------------------------
diff --git a/lib/atscppapi/src/utils_internal.cc b/lib/atscppapi/src/utils_internal.cc
new file mode 100644
index 0000000..b153a49
--- /dev/null
+++ b/lib/atscppapi/src/utils_internal.cc
@@ -0,0 +1,246 @@
+/**
+  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.
+ */
+
+/**
+ * @file utils_internal.cc
+ */
+#include "utils_internal.h"
+#include <cassert>
+#include <ts/ts.h>
+#include <pthread.h>
+#include <cstdlib>
+#include <cassert>
+#include <cstddef>
+#include "atscppapi/Plugin.h"
+#include "atscppapi/GlobalPlugin.h"
+#include "atscppapi/Transaction.h"
+#include "atscppapi/TransactionPlugin.h"
+#include "atscppapi/TransformationPlugin.h"
+#include "InitializableValue.h"
+#include "atscppapi/utils.h"
+#include "logging_internal.h"
+
+using namespace atscppapi;
+
+namespace {
+
+// This is the highest txn arg that can be used, we choose this
+// value to minimize the likelihood of it causing any problems.
+const int MAX_TXN_ARG = 15;
+const int TRANSACTION_STORAGE_INDEX = MAX_TXN_ARG;
+
+int handleTransactionEvents(TSCont cont, TSEvent event, void *edata) {
+  // This function is only here to clean up Transaction objects
+  TSHttpTxn ats_txn_handle = static_cast<TSHttpTxn>(edata);
+  Transaction &transaction = utils::internal::getTransaction(ats_txn_handle);
+  LOG_DEBUG("Got event %d on continuation %p for transaction (ats pointer %p, object %p)", event, cont,
+            ats_txn_handle, &transaction);
+  TSMBuffer hdr_buf;
+  TSMLoc hdr_loc;
+  switch (event) {
+  case TS_EVENT_HTTP_POST_REMAP:
+    transaction.getClientRequest().getUrl().reset();
+    break;
+  case TS_EVENT_HTTP_SEND_REQUEST_HDR:
+    utils::internal::initTransactionServerRequest(transaction);
+    break;
+  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
+    utils::internal::initTransactionServerResponse(transaction);
+    break;
+  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
+    utils::internal::initTransactionClientResponse(transaction);
+    break;
+  case TS_EVENT_HTTP_TXN_CLOSE:
+    { // opening scope to declare plugins variable below 
+      const std::list<TransactionPlugin *> &plugins = utils::internal::getTransactionPlugins(transaction);
+      for (std::list<TransactionPlugin *>::const_iterator iter = plugins.begin(), end = plugins.end();
+           iter != end; ++iter) {
+        shared_ptr<Mutex> trans_mutex = utils::internal::getTransactionPluginMutex(**iter);
+        LOG_DEBUG("Locking TransacitonPlugin mutex to delete transaction plugin at %p", *iter);
+        trans_mutex->lock();
+        LOG_DEBUG("Locked Mutex...Deleting transaction plugin at %p", *iter);
+        delete *iter;
+        trans_mutex->unlock();
+      }
+      delete &transaction;
+    }
+    break;
+  default:
+    assert(false); /* we should never get here */
+    break;
+  }    
+  TSHttpTxnReenable(ats_txn_handle, TS_EVENT_HTTP_CONTINUE);
+  return 0;
+}
+
+void setupTransactionManagement() {
+  // We must always have a cleanup handler available
+  TSMutex mutex = NULL;
+  TSCont cont = TSContCreate(handleTransactionEvents, mutex);
+  TSHttpHookAdd(TS_HTTP_POST_REMAP_HOOK, cont);
+  TSHttpHookAdd(TS_HTTP_SEND_REQUEST_HDR_HOOK, cont);
+  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, cont);
+  TSHttpHookAdd(TS_HTTP_SEND_RESPONSE_HDR_HOOK, cont);
+  TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, cont);
+#ifndef DISABLE_TRANSACTION_DATA_CACHING
+  transaction_data_caching_enabled = (getenv(utils::DISABLE_DATA_CACHING_ENV_FLAG.c_str()) == NULL);
+#endif
+  LOG_DEBUG("Initialized transaction management with data caching %s",
+            (transaction_data_caching_enabled ? "enabled" : "disabled"));
+  // TODO is existence of env variable enough or should we expect a specific value?
+}
+
+void inline invokePluginForEvent(Plugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) {
+  Transaction &transaction = utils::internal::getTransaction(ats_txn_handle);
+  switch (event) {
+  case TS_EVENT_HTTP_PRE_REMAP:
+    plugin->handleReadRequestHeadersPreRemap(transaction);
+    break;
+  case TS_EVENT_HTTP_POST_REMAP:
+    plugin->handleReadRequestHeadersPostRemap(transaction);
+    break;
+  case TS_EVENT_HTTP_SEND_REQUEST_HDR:
+    plugin->handleSendRequestHeaders(transaction);
+    break;
+  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
+    plugin->handleReadResponseHeaders(transaction);
+    break;
+  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
+    plugin->handleSendResponseHeaders(transaction);
+    break;
+  case TS_EVENT_HTTP_OS_DNS:
+    plugin->handleOsDns(transaction);
+    break;
+  default:
+    assert(false); /* we should never get here */
+    break;
+  }
+}
+
+} /* anonymous namespace */
+
+Transaction &utils::internal::getTransaction(TSHttpTxn ats_txn_handle) {
+  Transaction *transaction = static_cast<Transaction *>(TSHttpTxnArgGet(ats_txn_handle, TRANSACTION_STORAGE_INDEX));
+  if (!transaction) {
+    transaction = new Transaction(static_cast<void *>(ats_txn_handle));
+    LOG_DEBUG("Created new transaction object at %p for ats pointer %p", transaction, ats_txn_handle);
+    TSHttpTxnArgSet(ats_txn_handle, TRANSACTION_STORAGE_INDEX, transaction);
+  }
+  return *transaction;
+}
+
+shared_ptr<Mutex> utils::internal::getTransactionPluginMutex(TransactionPlugin &transaction_plugin) {
+  return transaction_plugin.getMutex();
+}
+
+TSHttpHookID utils::internal::convertInternalHookToTsHook(Plugin::HookType hooktype) {
+  switch (hooktype) {
+  case Plugin::HOOK_READ_REQUEST_HEADERS_POST_REMAP:
+    return TS_HTTP_POST_REMAP_HOOK;
+  case Plugin::HOOK_READ_REQUEST_HEADERS_PRE_REMAP:
+    return TS_HTTP_PRE_REMAP_HOOK;
+  case Plugin::HOOK_READ_RESPONSE_HEADERS:
+    return TS_HTTP_READ_RESPONSE_HDR_HOOK;
+  case Plugin::HOOK_SEND_REQUEST_HEADERS:
+    return TS_HTTP_SEND_REQUEST_HDR_HOOK;
+  case Plugin::HOOK_SEND_RESPONSE_HEADERS:
+    return TS_HTTP_SEND_RESPONSE_HDR_HOOK;
+  case Plugin::HOOK_OS_DNS:
+    return TS_HTTP_OS_DNS_HOOK;
+  default:
+    assert(false); // shouldn't happen, let's catch it early
+    break;
+  }
+  return static_cast<TSHttpHookID>(-1);
+}
+
+TSHttpHookID utils::internal::convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type) {
+  TSHttpHookID hook_id;
+  switch (type) {
+    case TransformationPlugin::RESPONSE_TRANSFORMATION:
+      return TS_HTTP_RESPONSE_TRANSFORM_HOOK;
+    case TransformationPlugin::REQUEST_TRANSFORMATION:
+      return TS_HTTP_REQUEST_TRANSFORM_HOOK;
+    default:
+      assert(false); // shouldn't happen, let's catch it early
+      break;
+  }
+  return static_cast<TSHttpHookID>(-1);
+}
+
+void utils::internal::invokePluginForEvent(TransactionPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) {
+  ScopedSharedMutexLock scopedLock(plugin->getMutex());
+  ::invokePluginForEvent(static_cast<Plugin *>(plugin), ats_txn_handle, event);
+}
+
+void utils::internal::invokePluginForEvent(GlobalPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) {
+  ::invokePluginForEvent(static_cast<Plugin *>(plugin), ats_txn_handle, event);
+}
+
+std::string utils::internal::consumeFromTSIOBufferReader(TSIOBufferReader reader) {
+  std::string str;
+  int avail = TSIOBufferReaderAvail(reader);
+
+  if (avail != TS_ERROR) {
+    int consumed = 0;
+    if (avail > 0) {
+      str.reserve(avail + 1);
+
+      int64_t data_len;
+      const char *char_data;
+      TSIOBufferBlock block = TSIOBufferReaderStart(reader);
+      while (block != NULL) {
+        char_data = TSIOBufferBlockReadStart(block, reader, &data_len);
+        str.append(char_data, data_len);
+        consumed += data_len;
+        block = TSIOBufferBlockNext(block);
+      }
+    }
+    TSIOBufferReaderConsume(reader, consumed);
+  } else {
+    LOG_ERROR("TSIOBufferReaderAvail returned error code %d for reader %p", avail, reader);
+  }
+
+  return str;
+}
+
+
+HttpVersion utils::internal::getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc) {
+  int version = TSHttpHdrVersionGet(hdr_buf, hdr_loc);
+  if (version != TS_ERROR) {
+    if ((TS_HTTP_MAJOR(version) == 0) && (TS_HTTP_MINOR(version) == 0)) {
+      return HTTP_VERSION_0_9;
+    }
+    if ((TS_HTTP_MAJOR(version) == 1) && (TS_HTTP_MINOR(version) == 0)) {
+      return HTTP_VERSION_1_0;
+    }
+    if ((TS_HTTP_MAJOR(version) == 1) && (TS_HTTP_MINOR(version) == 1)) {
+      return HTTP_VERSION_1_1;
+    } else {
+      LOG_ERROR("Unrecognized version %d", version);
+    }
+  } else {
+    LOG_ERROR("Could not get version; hdr_buf %p, hdr_loc %p", hdr_buf, hdr_loc);
+  }
+  return HTTP_VERSION_UNKNOWN;
+}
+
+void utils::internal::initTransactionManagement() {
+  static pthread_once_t setup_pthread_once_control = PTHREAD_ONCE_INIT;
+  pthread_once(&setup_pthread_once_control, setupTransactionManagement);
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/cpp11api/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/cpp11api/Makefile.am b/lib/cpp11api/Makefile.am
deleted file mode 100644
index 0aab9ed..0000000
--- a/lib/cpp11api/Makefile.am
+++ /dev/null
@@ -1,37 +0,0 @@
-# Makefile.am for C++11 API
-#
-#  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.
-
-includedir=$(prefix)/include/ts
-
-AM_CPPFLAGS = -I$(top_builddir)/proxy/api/ts
-  
-if BUILD_HAVE_CXX_11
-
-if BUILD_HAVE_LIBCXX
-AM_CXXFLAGS += -stdlib=libc++
-endif
-
-lib_LTLIBRARIES = libatscpp11api.la
-
-libatscpp11api_la_SOURCES = \
-  cpp11api.cc
-  
-include_HEADERS = \
-  ts-cpp11.h ts-cpp11-headers.h
-
-endif # BUILD_HAVE_CXX_11

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/cpp11api/cpp11api.cc
----------------------------------------------------------------------
diff --git a/lib/cpp11api/cpp11api.cc b/lib/cpp11api/cpp11api.cc
deleted file mode 100644
index e29fea2..0000000
--- a/lib/cpp11api/cpp11api.cc
+++ /dev/null
@@ -1,880 +0,0 @@
-/** @file
- @section license License
-
- 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 <arpa/inet.h>
-#include <ts.h>
-#include <algorithm>
-#include "ts-cpp11.h"
-#include "ts-cpp11-headers.h"
-
-using namespace ats::api;
-
-TSHttpHookID TSHookIDFromHookType(HookType hook);
-
-class HookContinuationData {
-public:
-  GlobalHookCallback callback;
-  HookType hooktype;
-  TSHttpHookID ts_hook_id;
-};
-
-class ats::api::Transaction {
-public:
-  TSHttpTxn ts_http_txn_ = NULL;
-  TSCont ts_contp_ = NULL;
-};
-
-extern "C" void TSPluginInit(int argc, const char *argv[]) {
-
-  TSPluginRegistrationInfo registration_info;
-
-  const char *api_version_string = "cpp11api";
-
-  registration_info.plugin_name = const_cast<char*>(api_version_string);
-  registration_info.vendor_name = const_cast<char*>(api_version_string);
-  registration_info.support_email = const_cast<char*>(api_version_string);
-
-  if (TSPluginRegister(TS_SDK_VERSION_3_0, &registration_info) != TS_SUCCESS) {
-    return;
-  }
-
-  StringVector arguments;
-  for (int i = 0; i < argc; ++i) {
-    arguments.push_back(std::string(argv[i]));
-  }
-
-  // Finally we will call the wrapper API registration point
-  PluginRegister(arguments);
-}
-
-TSHttpHookID TSHookIDFromHookType(HookType hook) {
-  switch (hook) {
-  case ats::api::HookType::HOOK_PRE_REMAP:
-    return TS_HTTP_PRE_REMAP_HOOK;
-    break;
-  case ats::api::HookType::HOOK_POST_REMAP:
-    return TS_HTTP_POST_REMAP_HOOK;
-    break;
-  case ats::api::HookType::HOOK_READ_REQUEST_HEADERS:
-    return TS_HTTP_READ_REQUEST_HDR_HOOK;
-    break;
-  case ats::api::HookType::HOOK_READ_RESPONSE_HEADERS:
-    return TS_HTTP_READ_RESPONSE_HDR_HOOK;
-    break;
-  case ats::api::HookType::HOOK_SEND_RESPONSE_HEADERS:
-    return TS_HTTP_SEND_RESPONSE_HDR_HOOK;
-    break;
-  case ats::api::HookType::HOOK_TRANSACTION_START:
-    return TS_HTTP_TXN_START_HOOK;
-    break;
-  case ats::api::HookType::HOOK_TRANSACTION_END:
-    return TS_HTTP_TXN_CLOSE_HOOK;
-    break;
-  }
-
-  return TS_HTTP_PRE_REMAP_HOOK;
-}
-
-void inline ReenableBasedOnNextState(TSHttpTxn txnp, NextState ns) {
-  switch (ns) {
-  case NextState::HTTP_DONT_CONTINUE:
-    return;
-    break;
-  case NextState::HTTP_ERROR:
-    TSHttpTxnReenable(txnp, static_cast<TSEvent>(TS_EVENT_HTTP_ERROR));
-    break;
-  case NextState::HTTP_CONTINUE:
-  default:
-    TSHttpTxnReenable(txnp, static_cast<TSEvent>(TS_EVENT_HTTP_CONTINUE));
-    break;
-  }
-}
-
-std::string printable_sockaddr_ip(sockaddr const * s_sockaddr) {
-  const struct sockaddr_in * s_sockaddr_in =
-      reinterpret_cast<const struct sockaddr_in *>(s_sockaddr);
-
-  char res[INET_ADDRSTRLEN];
-  inet_ntop(AF_INET, &s_sockaddr_in->sin_addr, res, INET_ADDRSTRLEN);
-
-  return std::string(res);
-}
-
-std::string ats::api::GetPristineRequestUrl(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc) != TS_SUCCESS)
-    return std::string();
-
-  int url_len;
-  char *urlp = TSUrlStringGet(bufp, url_loc, &url_len);
-  std::string url(urlp, url_len);
-
-  TSfree(urlp);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
-
-  return url;
-}
-
-std::string ats::api::GetRequestUrl(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return std::string();
-
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  int url_len;
-  char *urlp = TSUrlStringGet(bufp, url_loc, &url_len);
-  std::string url(urlp, url_len);
-
-  TSfree(urlp);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return url;
-}
-
-std::string ats::api::GetRequestUrlScheme(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return std::string();
-
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  int scheme_length;
-  const char *scheme = TSUrlSchemeGet(bufp, url_loc, &scheme_length);
-
-  std::string ret(scheme, scheme_length);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return ret;
-}
-
-
-std::string ats::api::GetPristineRequestUrlScheme(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc);
-
-  int length;
-  const char *scheme = TSUrlHostGet(bufp, url_loc, &length);
-
-  std::string ret(scheme, length);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
-
-  return ret;
-}
-
-void ats::api::SetRequestUrlScheme(Transaction &t, const std::string &scheme) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  TSUrlHostSet(bufp, url_loc, scheme.c_str(), scheme.length());
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-
-std::string ats::api::GetRequestUrlQuery(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return std::string();
-
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  int query_length;
-  const char *query = TSUrlHttpQueryGet(bufp, url_loc, &query_length);
-
-  std::string ret(query, query_length);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return ret;
-}
-
-std::string ats::api::GetPristineRequestUrlQuery(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc);
-
-  int query_length;
-  const char *query = TSUrlHostGet(bufp, url_loc, &query_length);
-
-  std::string ret(query, query_length);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
-
-  return ret;
-}
-
-void ats::api::SetRequestUrlQuery(Transaction &t, const std::string &query) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  TSUrlHostSet(bufp, url_loc, query.c_str(), query.length());
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-std::string ats::api::GetRequestUrlHost(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return std::string();
-
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  int host_length;
-  const char *host = TSUrlHostGet(bufp, url_loc, &host_length);
-
-  std::string ret(host, host_length);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return ret;
-}
-
-std::string ats::api::GetPristineRequestUrlHost(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc);
-
-  int host_length;
-  const char *host = TSUrlHostGet(bufp, url_loc, &host_length);
-
-  std::string ret(host, host_length);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
-
-  return ret;
-}
-
-void ats::api::SetRequestUrlHost(Transaction &t, const std::string &host) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  TSUrlHostSet(bufp, url_loc, host.c_str(), host.length());
-
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-std::string ats::api::GetRequestUrlPath(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return std::string();
-
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  int path_length;
-  const char *path = TSUrlPathGet(bufp, url_loc, &path_length);
-
-  std::string ret(path, path_length);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return ret;
-}
-
-unsigned int ats::api::GetRequestUrlPort(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-  int port = TSUrlPortGet(bufp, url_loc);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return port;
-}
-
-unsigned int ats::api::GetPristineRequestUrlPort(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc);
-  int port = TSUrlPortGet(bufp, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc); // TODO: is this wrong?
-
-  return port;
-}
-
-void ats::api::SetRequestUrlPort(Transaction &t, unsigned int port) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  TSUrlPortSet(bufp, url_loc, port);
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-std::string ats::api::GetPristineRequestUrlPath(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc url_loc;
-
-  TSHttpTxnPristineUrlGet(t.ts_http_txn_, &bufp, &url_loc);
-
-  int path_length;
-  const char *path = TSUrlPathGet(bufp, url_loc, &path_length);
-
-  std::string ret(path, path_length);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, url_loc);
-
-  return ret;
-}
-
-void ats::api::SetRequestUrlPath(Transaction &t, const std::string &path) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-  TSMLoc url_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc);
-
-  TSUrlPathSet(bufp, url_loc, path.c_str(), path.length());
-
-  TSHandleMLocRelease(bufp, hdr_loc, url_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-static int GlobalContinuationHandler(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) {
-  TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
-
-  Transaction transaction;
-  transaction.ts_http_txn_ = txnp;
-  transaction.ts_contp_ = contp;
-
-  HookContinuationData *data = static_cast<HookContinuationData*>(TSContDataGet(
-      contp));
-
-  ats::api::NextState ns = data->callback(transaction);
-  ReenableBasedOnNextState(txnp, ns);
-
-  return 0;
-}
-
-std::string ats::api::GetClientIP(Transaction &t) {
-  return printable_sockaddr_ip(TSHttpTxnClientAddrGet(t.ts_http_txn_));
-}
-
-unsigned int ats::api::GetClientPort(Transaction &t) {
-  const struct sockaddr_in * client_sockaddr =
-      reinterpret_cast<const struct sockaddr_in *>(TSHttpTxnClientAddrGet(
-          t.ts_http_txn_));
-
-  return static_cast<unsigned int>(ntohs(client_sockaddr->sin_port));
-}
-
-std::string ats::api::GetServerIncomingIP(Transaction &t) {
-  return printable_sockaddr_ip(TSHttpTxnIncomingAddrGet(t.ts_http_txn_));
-}
-
-unsigned int ats::api::GetServerIncomingPort(Transaction &t) {
-  const struct sockaddr_in * client_sockaddr =
-      reinterpret_cast<const struct sockaddr_in *>(TSHttpTxnIncomingAddrGet(
-          t.ts_http_txn_));
-
-  return static_cast<unsigned int>(ntohs(client_sockaddr->sin_port));
-}
-
-bool ats::api::IsInternalRequest(Transaction &t) {
-  return TSHttpIsInternalRequest(t.ts_http_txn_) == TS_SUCCESS;
-}
-
-int ats::api::GetServerResponseStatusCode(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  TSHttpTxnServerRespGet(t.ts_http_txn_, &bufp, &hdr_loc);
-  int status = TSHttpHdrStatusGet(bufp, hdr_loc);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return status;
-}
-
-std::string ats::api::GetRequestMethod(Transaction &t) {
-
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-
-  int method_len;
-  const char *methodp = TSHttpHdrMethodGet(bufp, hdr_loc, &method_len);
-  std::string method(methodp, method_len);
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return method;
-}
-
-void ats::api::SetRequestMethod(Transaction &t, const std::string &method) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc);
-
-  TSHttpHdrMethodSet(bufp, hdr_loc, method.c_str(), method.length());
-
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::ReenableTransaction(Transaction &t, NextState ns) {
-  ReenableBasedOnNextState(t.ts_http_txn_, ns);
-}
-
-static int TransactionContinuationHandler(TSCont contp, TSEvent event,
-    void *edata) {
-  TSHttpTxn txnp = static_cast<TSHttpTxn>(edata);
-
-  Transaction transaction;
-  transaction.ts_http_txn_ = txnp;
-  transaction.ts_contp_ = contp;
-
-  NextState ns = NextState::HTTP_CONTINUE;
-  HookContinuationData *data = static_cast<HookContinuationData*>(TSContDataGet(
-      contp));
-  if (event != TS_EVENT_HTTP_TXN_CLOSE
-      || (event == TS_EVENT_HTTP_TXN_CLOSE
-          && data->ts_hook_id == TS_HTTP_TXN_CLOSE_HOOK)) {
-    ns = data->callback(transaction);
-  }
-
-  // We must free the HookContinuationData structure and continuation
-  // If this transaction is complete
-  if (event == TS_EVENT_HTTP_TXN_CLOSE) {
-    delete data;
-    TSContDestroy(contp);
-  }
-
-  ReenableBasedOnNextState(txnp, ns);
-  return 0;
-}
-
-void* ats::api::GetTransactionIdentifier(Transaction &t) {
-  return reinterpret_cast<void *>(t.ts_http_txn_);
-}
-
-void ats::api::CreateTransactionHook(Transaction &txn,HookType hook,
-    GlobalHookCallback callback) {
-  TSHttpHookID ts_hook_id = TSHookIDFromHookType(hook);
-  TSCont contp = TSContCreate(TransactionContinuationHandler, NULL);
-
-  HookContinuationData *data = new HookContinuationData();
-  data->callback = callback;
-  data->hooktype = hook;
-  data->ts_hook_id = ts_hook_id;
-
-  TSContDataSet(contp, static_cast<void*>(data));
-  TSHttpTxnHookAdd(txn.ts_http_txn_, ts_hook_id, contp);
-
-  if (ts_hook_id != TS_HTTP_TXN_CLOSE_HOOK) {
-    TSHttpTxnHookAdd(txn.ts_http_txn_, TS_HTTP_TXN_CLOSE_HOOK, contp);
-  }
-}
-
-void ats::api::CreateGlobalHook(HookType hook, GlobalHookCallback callback) {
-
-  TSHttpHookID ts_hook_id = TSHookIDFromHookType(hook);
-  TSCont contp = TSContCreate(GlobalContinuationHandler, NULL);
-
-  HookContinuationData *data = new HookContinuationData();
-  data->callback = callback;
-  data->hooktype = hook;
-
-  TSContDataSet(contp, static_cast<void*>(data));
-  TSHttpHookAdd(ts_hook_id, contp);
-}
-
-/*
- * Header code
- */
-
-void SetHeader(TSMBuffer bufp, TSMLoc hdr_loc, const std::string &name,
-    const std::vector<std::string> &values) {
-
-  TSMLoc field_loc;
-
-  field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, name.c_str(), name.length());
-
-  // if the field already existed, let's just blow it away.
-  if (field_loc) {
-    TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
-    TSHandleMLocRelease(bufp, hdr_loc, field_loc);
-  }
-
-  // Now it definitely doesn't exist, so add it.
-  TSMimeHdrFieldCreate(bufp, hdr_loc, &field_loc);
-  TSMimeHdrFieldNameSet(bufp, hdr_loc, field_loc, name.c_str(), name.length());
-
-  for (unsigned int i = 0; i < values.size(); ++i) {
-    TSMimeHdrFieldValueStringInsert(bufp, hdr_loc, field_loc, 0, values[i].c_str(),
-        values[i].length());
-    TSMimeHdrFieldAppend(bufp, hdr_loc, field_loc);
-  }
-
-  TSHandleMLocRelease(bufp, hdr_loc, field_loc);
-}
-
-void AppendHeader(TSMBuffer bufp, TSMLoc hdr_loc, const std::string &name,
-    const std::vector<std::string> &values) {
-
-  TSMLoc field_loc;
-
-  TSMimeHdrFieldCreate(bufp, hdr_loc, &field_loc);
-  TSMimeHdrFieldNameSet(bufp, hdr_loc, field_loc, name.c_str(), name.length());
-
-  for (unsigned int i = 0; i < values.size(); ++i) {
-    TSMimeHdrFieldValueStringInsert(bufp, hdr_loc, field_loc, 0, values[i].c_str(),
-        values[i].length());
-    TSMimeHdrFieldAppend(bufp, hdr_loc, field_loc);
-  }
-
-  TSHandleMLocRelease(bufp, hdr_loc, field_loc);
-}
-
-void DeleteHeader(TSMBuffer bufp, TSMLoc hdr_loc, const std::string &name) {
-  TSMLoc field_loc;
-
-  field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, name.c_str(), name.length());
-
-  if (field_loc) {
-    TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
-    TSHandleMLocRelease(bufp, hdr_loc, field_loc);
-  }
-}
-
-/*
- * Obviously this should be optimized to either fill in a passed vector
- * or just returned a shared_ptr to the build vector, this is an exercise
- * left to the reader.
- */
-ats::api::headers::HeaderVector GetHeaders(TSMBuffer bufp, TSMLoc hdr_loc) {
-
-  TSMLoc field_loc;
-
-  ats::api::headers::HeaderVector hv;
-
-  field_loc = TSMimeHdrFieldGet(bufp, hdr_loc, 0);
-  while (field_loc) {
-    /* copy the header to a more friedly data structure */
-    int name_length;
-    const char *fieldName = TSMimeHdrFieldNameGet(bufp, hdr_loc, field_loc, &name_length);
-
-    ats::api::headers::Header hdr;
-    hdr.assignName(fieldName, name_length);
-
-    /* now we have to walk all the values and add them */
-    int numValues = TSMimeHdrFieldValuesCount(bufp, hdr_loc, field_loc);
-    for (int indx = 0; indx < numValues; ++indx) {
-      int val_length;
-      const char *value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, indx, &val_length);
-      hdr.addNewValue(value, val_length);
-    }
-
-    hv.push_back(hdr);
-
-    /* Get the next field and release the current one */
-    TSMLoc next_field_loc = TSMimeHdrFieldNext(bufp, hdr_loc, field_loc);
-    TSHandleMLocRelease(bufp, hdr_loc, field_loc);
-    field_loc = next_field_loc;
-  }
-
-  return hv;
-}
-
-/*
- * TODO: All of these can be improved by caching and then invalidating the
- * header cache when a delete, append, or set occurs.
- */
-
-void ats::api::headers::DeleteClientRequestHeader(Transaction &t, const std::string &name) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  DeleteHeader(bufp, hdr_loc, name);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::DeleteClientResponseHeader(Transaction &t, const std::string &name) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  DeleteHeader(bufp, hdr_loc, name);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::DeleteServerResponseHeader(Transaction &t, const std::string &name) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnServerRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  DeleteHeader(bufp, hdr_loc, name);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::SetClientRequestHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  SetHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::SetClientRequestHeader(Transaction &t, const std::string &name, const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  SetClientRequestHeader(t, name, vals);
-}
-
-void ats::api::headers::SetClientResponseHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  SetHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::SetClientResponseHeader(Transaction &t, const std::string &name, const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  SetClientResponseHeader(t, name, vals);
-}
-
-void ats::api::headers::SetServerResponseHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnServerRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  SetHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::SetServerResponseHeader(Transaction &t, const std::string &name, const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  SetServerResponseHeader(t, name, vals);
-}
-
-void ats::api::headers::AppendServerResponseHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnServerRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  AppendHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::AppendServerResponseHeader(Transaction &t, const std::string &name,
-    const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  AppendServerResponseHeader(t, name, vals);
-}
-
-void ats::api::headers::AppendClientRequestHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  AppendHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::AppendClientRequestHeader(Transaction &t, const std::string &name,
-    const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  AppendClientRequestHeader(t, name, vals);
-}
-
-void ats::api::headers::AppendClientResponseHeader(Transaction &t, const std::string &name,
-    const std::vector<std::string> &vals) {
-
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  if (TSHttpTxnClientRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return;
-
-  AppendHeader(bufp, hdr_loc, name, vals);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-}
-
-void ats::api::headers::AppendClientResponseHeader(Transaction &t, const std::string &name,
-    const std::string &val) {
-
-  std::vector<std::string> vals;
-  vals.push_back(val);
-  AppendClientResponseHeader(t, name, vals);
-}
-
-ats::api::headers::HeaderVector ats::api::headers::GetClientRequestHeaders(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  HeaderVector hv;
-
-  if (TSHttpTxnClientReqGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return hv;
-
-  hv = GetHeaders(bufp, hdr_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return hv;
-}
-
-ats::api::headers::HeaderVector ats::api::headers::GetClientResponseHeaders(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  HeaderVector hv;
-
-  if (TSHttpTxnClientRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return hv;
-
-  hv = GetHeaders(bufp, hdr_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return hv;
-}
-
-ats::api::headers::HeaderVector ats::api::headers::GetServerResponseHeaders(Transaction &t) {
-  TSMBuffer bufp;
-  TSMLoc hdr_loc;
-
-  HeaderVector hv;
-
-  if (TSHttpTxnServerRespGet(t.ts_http_txn_, &bufp, &hdr_loc) != TS_SUCCESS)
-    return hv;
-
-  hv = GetHeaders(bufp, hdr_loc);
-  TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
-
-  return hv;
-}
-
-inline ats::api::headers::Header GetHeader(Transaction & /* t ATS_UNUSED */, const std::string& hdr_name,
-                                           const ats::api::headers::HeaderVector &hdrs) {
-
-  ats::api::headers::Header hdr;
-  ats::api::headers::HeaderVector::const_iterator ii = std::find_if(hdrs.begin(), hdrs.end(),
-                                                                    ats::api::headers::HeaderName(hdr_name));
-
-  if (ii != hdrs.end()) {
-    hdr = *ii;
-  }
-
-  return hdr;
-}
-
-ats::api::headers::Header ats::api::headers::GetClientRequestHeader(Transaction &t, const std::string& hdr_name) {
-  return GetHeader(t, hdr_name, GetClientRequestHeaders(t));
-}
-
-ats::api::headers::Header ats::api::headers::GetClientResponseHeader(Transaction &t, const std::string& hdr_name) {
-  return GetHeader(t, hdr_name, GetClientResponseHeaders(t));
-}
-
-ats::api::headers::Header ats::api::headers::GetServerResponseHeader(Transaction &t, const std::string& hdr_name) {
-  return GetHeader(t, hdr_name, GetServerResponseHeaders(t));
-}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/cpp11api/ts-cpp11-headers.h
----------------------------------------------------------------------
diff --git a/lib/cpp11api/ts-cpp11-headers.h b/lib/cpp11api/ts-cpp11-headers.h
deleted file mode 100644
index cfe94bc..0000000
--- a/lib/cpp11api/ts-cpp11-headers.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/** @file
- @section license License
-
- 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 TS_CPP11_HEADERS_H_
-#define TS_CPP11_HEADERS_H_
-#include <functional>
-#include <string>
-#include <vector>
-#include <memory>
-
-namespace ats {
-namespace api {
-namespace headers {
-
-class Header;
-typedef typename std::vector<Header> HeaderVector;
-
-class Header {
-private:
-  std::string name_;
-  std::vector<std::string> field_values_;
-public:
-  Header() {
-  }
-  Header(const std::string &name, const std::string &value) {
-    name_ = name;
-    addNewValue(value);
-  }
-
-  Header(std::string name, const std::vector<std::string> & values) {
-    name_ = name;
-    field_values_ = values;
-  }
-
-  void assignName(const std::string & name) {
-    name_ = name;
-  }
-
-  void assignName(const char *buf, size_t len) {
-    name_.assign(buf, len);
-  }
-
-  void addNewValue(const char *buf, size_t len) {
-    std::string newVal(buf, len);
-    field_values_.push_back(newVal);
-  }
-
-  void addNewValue(std::string value) {
-    field_values_.push_back(value);
-  }
-
-  int getNumValues() const {
-    return field_values_.size();
-  }
-
-  std::string getValue(int valueindx) const{
-    return field_values_[valueindx];
-  }
-
-  std::string getName() const {
-    return name_;
-  }
-
-  std::string getJoinedValues() const {
-    std::string ret;
-
-    for (std::vector<std::string>::size_type i = 0; i < field_values_.size();
-        ++i) {
-      if (i > 0)
-        ret.append(",");
-      ret.append(field_values_[i]);
-    }
-    return ret;
-  }
-
-  std::vector<std::string> getValues() const {
-    return field_values_;
-  }
-};
-
-
-
-/*
- *  predicates
- */
-class HeaderName: public std::unary_function<Header, bool> { // could probably be replaced with mem_ptr_fun()..
-private:
-  std::string name_;
-public:
-  HeaderName(std::string name) :
-      name_(name) {
-  }
-
-  bool operator()(const Header &field) const {
-    return (field.getName() == name_);
-  }
-};
-
-}
-}
-}
-
-#endif /* TS_CPP11_HEADERS_H_ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7b2ea5f8/lib/cpp11api/ts-cpp11.h
----------------------------------------------------------------------
diff --git a/lib/cpp11api/ts-cpp11.h b/lib/cpp11api/ts-cpp11.h
deleted file mode 100644
index b1e2a48..0000000
--- a/lib/cpp11api/ts-cpp11.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/** @file
- @section license License
-
- 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 TS_CPP11_H_
-#define TS_CPP11_H_
-
-#ifndef __GXX_EXPERIMENTAL_CXX0X__
-#error The C++ Apache Traffic Server API wrapper requires C++11 support.
-#endif
-
-#include <functional>
-#include <string>
-#include <vector>
-#include "ts-cpp11-headers.h"
-
-namespace ats {
-namespace api {
-typedef std::vector<std::string> StringVector;
-
-enum class HookType {
-  HOOK_PRE_REMAP = 100,
-  HOOK_POST_REMAP,
-  HOOK_READ_RESPONSE_HEADERS,
-  HOOK_READ_REQUEST_HEADERS,
-  HOOK_SEND_RESPONSE_HEADERS,
-  HOOK_TRANSACTION_START,
-  HOOK_TRANSACTION_END
-};
-
-enum class NextState {
-  HTTP_CONTINUE = 200, HTTP_ERROR, HTTP_DONT_CONTINUE
-};
-
-class Transaction;
-
-/*
- * This is the type our global hook callbacks will take
- */
-typedef std::function<NextState(Transaction &)> GlobalHookCallback;
-
-/*
- * Create a new hook
- */
-void CreateGlobalHook(HookType, GlobalHookCallback);
-void CreateTransactionHook(Transaction &, HookType, GlobalHookCallback);
-
-std::string GetRequestUrl(Transaction &);
-std::string GetPristineRequestUrl(Transaction &);
-std::string GetRequestUrlPath(Transaction &);
-std::string GetPristineRequestUrlPath(Transaction &);
-void SetRequestUrlPath(Transaction &, const std::string &);
-std::string GetRequestUrlQuery(Transaction &);
-std::string GetPristineRequestUrlQuery(Transaction &);
-void SetRequestUrlQuery(Transaction &, const std::string &);
-std::string GetRequestUrlHost(Transaction &);
-std::string GetPristineRequestUrlHost(Transaction &);
-void SetRequestUrlHost(Transaction &, const std::string &);
-std::string GetRequestUrlScheme(Transaction &);
-std::string GetPristineRequestUrlScheme(Transaction &);
-void SetRequestUrlScheme(Transaction &, const std::string &);
-unsigned int GetRequestUrlPort(Transaction &);
-unsigned int GetPristineRequestUrlPort(Transaction &);
-void SetRequestUrlPort(Transaction &, unsigned int);
-std::string GetClientIP(Transaction &);
-unsigned int GetClientPort(Transaction &);
-std::string GetServerIncomingIP(Transaction &);
-unsigned int GetServerIncomingPort(Transaction &);
-std::string GetRequestMethod(Transaction &t);
-void SetRequestMethod(Transaction &t, const std::string &);
-int GetServerResponseStatusCode(Transaction &t);
-bool IsInternalRequest(Transaction &);
-void* GetTransactionIdentifier(Transaction &);
-void ReenableTransaction(Transaction &, NextState);
-
-/* headers */
-// TODO: Switch these out to deal with shared_ptrs to a HeaderVector
-namespace headers {
-HeaderVector GetClientRequestHeaders(Transaction &);
-HeaderVector GetClientResponseHeaders(Transaction &);
-HeaderVector GetServerResponseHeaders(Transaction &);
-Header GetClientRequestHeader(Transaction &, const std::string &);
-Header GetClientResponseHeader(Transaction &, const std::string &);
-Header GetServerResponseHeader(Transaction &, const std::string &);
-void DeleteClientRequestHeader(Transaction &, const std::string &);
-void DeleteClientResponseHeader(Transaction &, const std::string &);
-void DeleteServerResponseHeader(Transaction &, const std::string &);
-void SetClientRequestHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void SetClientResponseHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void SetServerResponseHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void SetClientRequestHeader(Transaction &, const std::string &, const std::string &);
-void SetClientResponseHeader(Transaction &, const std::string &, const std::string &);
-void SetServerResponseHeader(Transaction &, const std::string &, const std::string &);
-void AppendClientRequestHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void AppendClientResponseHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void AppendServerResponseHeader(Transaction &, const std::string &, const std::vector<std::string> &);
-void AppendClientRequestHeader(Transaction &, const std::string &, const std::string &);
-void AppendClientResponseHeader(Transaction &, const std::string &, const std::string &);
-void AppendServerResponseHeader(Transaction &, const std::string &, const std::string &);
-} /* headers */
-
-} /* api */
-} /* ats */
-
-/*
- * Every plugin must have a simple entry point
- */
-void PluginRegister(const ats::api::StringVector &);
-
-#endif /* TS_CPP11_H_ */


Mime
View raw message