You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by br...@apache.org on 2015/02/10 01:22:56 UTC

[1/2] trafficserver git commit: Adding example remap plugin for adding headers on remap

Repository: trafficserver
Updated Branches:
  refs/heads/master 2dbdd9c26 -> ce74235e3


Adding example remap plugin for adding headers on remap


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

Branch: refs/heads/master
Commit: 1c1a72a69d82cc4d5ac264c54ae825a6db3b03cf
Parents: d777303
Author: Brian Geffon <br...@apache.org>
Authored: Mon Feb 9 16:16:32 2015 -0800
Committer: Brian Geffon <br...@apache.org>
Committed: Mon Feb 9 16:16:32 2015 -0800

----------------------------------------------------------------------
 example/Makefile.am                          |   2 +
 example/remap_header_add/build.txt           |  17 +++
 example/remap_header_add/remap_header_add.cc | 163 ++++++++++++++++++++++
 3 files changed, 182 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1c1a72a6/example/Makefile.am
----------------------------------------------------------------------
diff --git a/example/Makefile.am b/example/Makefile.am
index 47c1d90..db09497 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -41,6 +41,7 @@ plugins = \
   secure-link.la \
   server-transform.la \
   ssl-preaccept.la \
+  remap_header_add.la \
   ssl-sni.la \
   ssl-sni-whitelist.la \
   thread-1.la \
@@ -69,6 +70,7 @@ protocol_la_SOURCES = protocol/Protocol.c protocol/TxnSM.c
 query_remap_la_SOURCES = query-remap/query-remap.c
 remap_la_SOURCES = remap/remap.cc
 replace_header_la_SOURCES = replace-header/replace-header.c
+remap_header_add_la_SOURCES = remap_header_add/remap_header_add.cc
 response_header_1_la_SOURCES = response-header-1/response-header-1.c
 server_transform_la_SOURCES = server-transform/server-transform.c
 thread_1_la_SOURCES = thread-1/thread-1.c

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1c1a72a6/example/remap_header_add/build.txt
----------------------------------------------------------------------
diff --git a/example/remap_header_add/build.txt b/example/remap_header_add/build.txt
new file mode 100755
index 0000000..c9a87ad
--- /dev/null
+++ b/example/remap_header_add/build.txt
@@ -0,0 +1,17 @@
+#  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.
+
+gcc -D_FILE_OFFSET_BITS=64 -fPIC -shared -I../../include -I../../.. -I./ -g -o remap_header_add.so remap_header_add.cc

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1c1a72a6/example/remap_header_add/remap_header_add.cc
----------------------------------------------------------------------
diff --git a/example/remap_header_add/remap_header_add.cc b/example/remap_header_add/remap_header_add.cc
new file mode 100644
index 0000000..1fad637
--- /dev/null
+++ b/example/remap_header_add/remap_header_add.cc
@@ -0,0 +1,163 @@
+/** @file
+
+  A simple remap plugin for ATS
+
+  @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.
+
+  @section description
+    This is a very simple plugin: it will add headers that are specified on a remap line
+
+    Example usage:
+    map /foo http://127.0.0.1/ @plugin=remap_header_add.so @pparam=foo:"x" @pparam=@test:"c" @pparam=a:"b"
+
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ts/ts.h"
+#include "ts/remap.h"
+
+struct remap_line {
+  int argc;
+  char **argv; // store the originals
+
+  int nvc; // the number of name value pairs, should be argc - 2.
+  char **name; // at load we will parse out the name and values.
+  char **val;
+};
+
+#define TAG "headeradd_remap"
+#define NOWARN_UNUSED __attribute__ ((unused))
+#define EXTERN extern "C"
+
+EXTERN void ParseArgIntoNv(const char *arg, char **n, char **v) {
+  const char *colon_pos = strchr(arg, ':');
+  if (colon_pos == NULL) {
+    *n = NULL;
+    *v = NULL;
+    TSDebug(TAG, "No name value pair since it was malformed");
+    return;
+  }
+
+  size_t name_len = colon_pos - arg;
+  *n = (char *) TSmalloc(name_len + 1);
+  memcpy(*n, arg, colon_pos - arg);
+  (*n)[name_len] = '\0';
+
+  size_t val_len = strlen(colon_pos + 1); // skip past the ':'
+
+  // check to see if the value is quoted.
+  if (val_len > 1 && colon_pos[1] == '"' && colon_pos[val_len] == '"') {
+    colon_pos++; // advance past the first quote
+    val_len -= 2; // don't include the trailing quote
+  }
+
+  *v = (char *) TSmalloc(val_len + 1);
+  memcpy(*v, colon_pos + 1, val_len);
+  (*v)[val_len] = '\0';
+
+  TSDebug(TAG, "\t name_len=%d, val_len=%d, %s=%s", name_len, val_len, *n, *v);
+}
+
+TSReturnCode TSRemapInit(NOWARN_UNUSED TSRemapInterface *api_info, NOWARN_UNUSED char *errbuf, NOWARN_UNUSED int errbuf_size) {
+  return TS_SUCCESS;
+}
+
+TSReturnCode TSRemapNewInstance(int argc, char* argv[], void** ih, char* errbuf, int errbuf_size) {
+  remap_line *rl = NULL;
+
+  TSDebug(TAG, "TSRemapNewInstance()");
+
+  if (!argv || !ih) {
+    TSError(TAG ": Unable to load plugin because missing argv or ih.");
+    return TS_ERROR;
+  }
+
+  // print all arguments for this particular remapping
+
+  rl = (remap_line*) TSmalloc(sizeof(remap_line));
+  rl->argc = argc;
+  rl->argv = argv;
+  rl->nvc = argc - 2; // the first two are the remap from and to
+  if (rl->nvc) {
+    rl->name = (char**) TSmalloc(sizeof(char *) * rl->nvc);
+    rl->val = (char**) TSmalloc(sizeof(char *) * rl->nvc);
+  }
+
+  TSDebug(TAG, "NewInstance:");
+  for (int i = 2; i < argc; i++) {
+    ParseArgIntoNv(argv[i], &rl->name[i-2], &rl->val[i-2]);
+  }
+
+  *ih = (void *) rl;
+
+  return TS_SUCCESS;
+}
+
+void TSRemapDeleteInstance(void* ih)
+{
+  TSDebug(TAG, "deleting instance %p", ih);
+
+  if (ih) {
+    remap_line *rl = (remap_line*)ih;
+    for (int i = 0; i < rl->nvc; ++i)
+    {
+      TSfree(rl->name[i]);
+      TSfree(rl->val[i]);
+    }
+
+    TSfree(rl->name);
+    TSfree(rl->val);
+  }
+}
+
+TSRemapStatus TSRemapDoRemap(void* ih, NOWARN_UNUSED TSHttpTxn txn, NOWARN_UNUSED TSRemapRequestInfo *rri) {
+  remap_line *rl = (remap_line *) ih;
+
+  if (!rl || !rri) {
+    TSError(TAG ": rl or rri is null.");
+    return TSREMAP_NO_REMAP;
+  }
+
+  TSDebug(TAG, "TSRemapDoRemap:");
+
+  TSMBuffer req_bufp;
+  TSMLoc req_loc;
+  if (TSHttpTxnClientReqGet(txn, &req_bufp, &req_loc) != TS_SUCCESS) {
+    TSError(TAG ": Error while retrieving client request header");
+    return TSREMAP_NO_REMAP;
+  }
+
+  for (int i = 0; i < rl->nvc; ++i) {
+    TSDebug(TAG, "Attaching header \"%s\" with value \"%s\".", rl->name[i], rl->val[i]);
+
+    TSMLoc field_loc;
+    if (TSMimeHdrFieldCreate(req_bufp, req_loc, &field_loc) == TS_SUCCESS) {
+        TSMimeHdrFieldNameSet(req_bufp, req_loc, field_loc, rl->name[i], strlen(rl->name[i]));
+        TSMimeHdrFieldAppend(req_bufp, req_loc, field_loc);
+        TSMimeHdrFieldValueStringInsert(req_bufp, req_loc, field_loc, 0,  rl->val[i], strlen(rl->val[i]));
+    } else {
+      TSError(TAG ": Failure on TSMimeHdrFieldCreate");
+    }
+  }
+  return TSREMAP_NO_REMAP;
+}


[2/2] trafficserver git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/trafficserver

Posted by br...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/trafficserver


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

Branch: refs/heads/master
Commit: ce74235e3c2b8c7ac88bc9c3c6c19ce359885f68
Parents: 1c1a72a 2dbdd9c
Author: Brian Geffon <br...@apache.org>
Authored: Mon Feb 9 16:22:14 2015 -0800
Committer: Brian Geffon <br...@apache.org>
Committed: Mon Feb 9 16:22:14 2015 -0800

----------------------------------------------------------------------
 CHANGES                                     |  7 ++
 build/crypto.m4                             | 83 +++++++++++++++++++++++-
 ci/new_tsqa/tests/helpers.py                |  2 +-
 cmd/traffic_cop/Makefile.am                 |  9 ++-
 cmd/traffic_crashlog/Makefile.am            |  9 +--
 cmd/traffic_layout/Makefile.am              |  5 ++
 cmd/traffic_line/Makefile.am                |  8 ++-
 cmd/traffic_manager/Makefile.am             | 10 +--
 cmd/traffic_top/Makefile.am                 | 11 +++-
 cmd/traffic_via/Makefile.am                 |  6 +-
 cmd/traffic_wccp/Makefile.am                | 17 +++--
 configure.ac                                | 18 +++--
 doc/admin/event-logging-formats.en.rst      | 22 +++++++
 iocore/aio/Makefile.am                      | 15 +++--
 iocore/cache/Cache.cc                       |  2 +-
 iocore/cache/CacheDir.cc                    |  2 +-
 iocore/eventsystem/Makefile.am              | 28 ++++----
 iocore/net/Makefile.am                      | 15 +++--
 iocore/net/P_SSLConfig.h                    |  4 +-
 iocore/net/SSLConfig.cc                     | 10 ++-
 iocore/net/SSLInternal.cc                   |  7 ++
 iocore/net/SSLNetProcessor.cc               |  2 +-
 iocore/net/SSLUtils.cc                      |  4 +-
 lib/ts/ink_config.h.in                      |  2 +
 mgmt/Makefile.am                            |  6 +-
 mgmt/utils/Makefile.am                      | 12 ++--
 mgmt/web2/WebUtils.cc                       |  2 +-
 plugins/experimental/esi/lib/FailureInfo.cc |  1 +
 proxy/Main.cc                               | 68 ++++++++++++++++++-
 proxy/Makefile.am                           | 44 +++++--------
 proxy/Plugin.cc                             | 26 +++++---
 proxy/Plugin.h                              |  2 +-
 proxy/ReverseProxy.cc                       |  6 +-
 proxy/ReverseProxy.h                        |  2 +-
 proxy/http/HttpProxyServerMain.cc           | 10 +--
 35 files changed, 357 insertions(+), 120 deletions(-)
----------------------------------------------------------------------