You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2013/03/09 01:48:36 UTC
[36/50] git commit: TS-1741: add plugins examples to the build
TS-1741: add plugins examples to the build
Add example plugins to the build. Simplify the automake configuration.
Rename files so that we consistently use '-' instead of '_'.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c6de4512
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c6de4512
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c6de4512
Branch: refs/heads/3.3.x
Commit: c6de45128e6bc142631e2772b78d3281fedadf34
Parents: deea8b0
Author: James Peach <jp...@apache.org>
Authored: Tue Mar 5 12:39:56 2013 -0800
Committer: James Peach <jp...@apache.org>
Committed: Tue Mar 5 13:00:21 2013 -0800
----------------------------------------------------------------------
CHANGES | 2 +
Makefile.am | 4 +-
configure.ac | 24 --
example/Makefile.am | 56 +++-
example/add-header/Makefile.am | 25 --
example/app-template/Makefile.am | 60 ----
example/append-transform/Makefile.am | 25 --
example/basic-auth/Makefile.am | 25 --
example/blacklist-0/Makefile.am | 25 --
example/blacklist-1/Makefile.am | 25 --
example/bnull-transform/Makefile.am | 25 --
example/cache-scan/cache-scan.cc | 498 ++++++++++++++++++++++++++++
example/cache_scan/Makefile.am | 25 --
example/cache_scan/cache_scan.cc | 498 ----------------------------
example/file-1/Makefile.am | 25 --
example/hello/Makefile.am | 25 --
example/null-transform/Makefile.am | 25 --
example/output-header/Makefile.am | 25 --
example/prefetch/Makefile.am | 25 --
example/protocol/Makefile.am | 25 --
example/query-remap/query-remap.c | 185 ++++++++++
example/query_remap/Makefile.am | 25 --
example/query_remap/query_remap.c | 185 ----------
example/redirect-1/Makefile.am | 25 --
example/remap/Makefile.am | 25 --
example/replace-header/Makefile.am | 25 --
example/response-header-1/Makefile.am | 25 --
example/server-transform/Makefile.am | 25 --
example/session-1/Makefile.am | 25 --
example/thread-1/Makefile.am | 25 --
example/thread-pool/Makefile.am | 25 --
31 files changed, 738 insertions(+), 1324 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index d4fb0bc..7ac4b24 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
Changes with Apache Traffic Server 3.3.1
+ *) [TS-1741] add plugins examples to the build
+
*) [TS-1058] add TSHttpTxnCloseAfterResponse experimental API
Author: Yakov Kopel <yk...@websense.com>
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index 8c90655..939f822 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,9 +27,9 @@ ACLOCAL_AMFLAGS = -I build
# proxy/api/ts has to be built first, since so much of libraries and "core
# depends on the generates ts/ts.h include file.
if STANDALONE_IOCORE
-SUBDIRS = proxy/api/ts iocore lib proxy/hdrs mgmt proxy cop plugins tools
+SUBDIRS = proxy/api/ts iocore lib proxy/hdrs mgmt proxy cop plugins tools example
else
-SUBDIRS = proxy/api/ts iocore lib proxy/hdrs mgmt proxy cop rc doc plugins tools
+SUBDIRS = proxy/api/ts iocore lib proxy/hdrs mgmt proxy cop rc doc plugins tools example
endif
DIST_BUILD_USER=`id -nu`
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 09ca9e7..6c56032 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1644,30 +1644,6 @@ AC_CONFIG_FILES([plugins/experimental/cacheurl/Makefile])
AC_CONFIG_FILES([tools/Makefile])
# example plugins
AC_CONFIG_FILES([example/Makefile])
-AC_CONFIG_FILES([example/add-header/Makefile])
-AC_CONFIG_FILES([example/append-transform/Makefile])
-AC_CONFIG_FILES([example/basic-auth/Makefile])
-AC_CONFIG_FILES([example/blacklist-0/Makefile])
-AC_CONFIG_FILES([example/blacklist-1/Makefile])
-AC_CONFIG_FILES([example/bnull-transform/Makefile])
-AC_CONFIG_FILES([example/cache_scan/Makefile])
-AC_CONFIG_FILES([example/file-1/Makefile])
-AC_CONFIG_FILES([example/hello/Makefile])
-AC_CONFIG_FILES([example/null-transform/Makefile])
-AC_CONFIG_FILES([example/output-header/Makefile])
-AC_CONFIG_FILES([example/prefetch/Makefile])
-AC_CONFIG_FILES([example/protocol/Makefile])
-AC_CONFIG_FILES([example/redirect-1/Makefile])
-AC_CONFIG_FILES([example/query_remap/Makefile])
-AC_CONFIG_FILES([example/remap/Makefile])
-AC_CONFIG_FILES([example/replace-header/Makefile])
-AC_CONFIG_FILES([example/response-header-1/Makefile])
-AC_CONFIG_FILES([example/server-transform/Makefile])
-AC_CONFIG_FILES([example/session-1/Makefile])
-AC_CONFIG_FILES([example/thread-1/Makefile])
-AC_CONFIG_FILES([example/thread-pool/Makefile])
-# example app w/ standalone iocore
-AC_CONFIG_FILES([example/app-template/Makefile example/app-template/records.config])
# -----------------------------------------------------------------------------
# 7. autoheader TEMPLATES
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/Makefile.am
----------------------------------------------------------------------
diff --git a/example/Makefile.am b/example/Makefile.am
index cc20f10..2504a98 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -14,8 +14,54 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-if STANDALONE_IOCORE
-SUBDIRS = app-template
-else
-SUBDIRS = . add-header append-transform basic-auth blacklist-0 blacklist-1 bnull-transform cache_scan file-1 hello null-transform output-header protocol query_remap redirect-1 remap replace-header response-header-1 server-transform session-1 thread-1 thread-pool
-endif
+pkglibdir = ${pkglibexecdir}
+
+AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
+AM_LDFLAGS = -module -avoid-version -shared
+
+noinst_LTLIBRARIES = \
+ add-header.la \
+ append-transform.la \
+ basic-auth.la \
+ blacklist-0.la \
+ blacklist-1.la \
+ bnull-transform.la \
+ cache-scan.la \
+ file-1.la \
+ hello.la \
+ null-transform.la \
+ output-header.la \
+ protocol.la \
+ psi.la \
+ query-remap.la \
+ remap.la \
+ replace-header.la \
+ response-header-1.la \
+ server-transform.la \
+ thread-1.la
+
+add_header_la_SOURCES = add-header/add-header.c
+append_transform_la_SOURCES = append-transform/append-transform.c
+basic_auth_la_SOURCES = basic-auth/basic-auth.c
+blacklist_0_la_SOURCES = blacklist-0/blacklist-0.c
+blacklist_1_la_SOURCES = blacklist-1/blacklist-1.c
+bnull_transform_la_SOURCES = bnull-transform/bnull-transform.c
+cache_scan_la_SOURCES = cache-scan/cache-scan.cc
+file_1_la_SOURCES = file-1/file-1.c
+hello_la_SOURCES = hello/hello.c
+null_transform_la_SOURCES = null-transform/null-transform.c
+output_header_la_SOURCES = output-header/output-header.c
+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
+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
+psi_la_SOURCES = thread-pool/psi.c thread-pool/thread.c
+
+# The following examples do not build:
+#
+# prefetch_eg1_la_SOURCES = prefetch/prefetch-plugin-eg1.c
+# redirect_1_la_SOURCES = redirect-1/redirect-1.c
+# session_1_la_SOURCES = session-1/session-1.c
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/add-header/Makefile.am
----------------------------------------------------------------------
diff --git a/example/add-header/Makefile.am b/example/add-header/Makefile.am
deleted file mode 100644
index b2e2b8f..0000000
--- a/example/add-header/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = add-header.la
-add_header_la_SOURCES = add-header.c
-add_header_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/add-header.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/app-template/Makefile.am
----------------------------------------------------------------------
diff --git a/example/app-template/Makefile.am b/example/app-template/Makefile.am
deleted file mode 100644
index fb21421..0000000
--- a/example/app-template/Makefile.am
+++ /dev/null
@@ -1,60 +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.
-
-AM_CPPFLAGS = -I$(iocore_include_dirs) \
- -I$(top_srcdir)/lib/records \
- -I$(top_srcdir)/proxy
-
-DEFS += @IOCORE_MODULARIZED_DEFS@
-
-bin_PROGRAMS = tsapp
-
-tsapp_SOURCES = app-template.cc
-
-tsapp_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
-tsapp_LDADD = \
- $(top_builddir)/proxy/libTrafficServerStandalone.a \
- $(top_builddir)/proxy/hdrs/libhdrs.a \
- $(top_builddir)/iocore/cache/libinkcache.a \
- $(top_builddir)/iocore/aio/libinkaio.a \
- $(top_builddir)/iocore/hostdb/libinkhostdb.a \
- $(top_builddir)/iocore/dns/libinkdns.a \
- $(top_builddir)/iocore/net/libinknet.a \
- $(top_builddir)/iocore/utils/libinkutils.a \
- $(top_builddir)/iocore/eventsystem/libinkevent.a \
- $(top_builddir)/lib/records/librecprocess.a \
- $(top_builddir)/lib/ts/libtsutil.la \
- @LIBTHREAD@ @LIBSOCKET@ @LIBNSL@ @LIBRESOLV@ @LIBRT@ \
- @LIBPCRE@ @LIBSSL@ @LIBTCL@ @LIBDL@ \
- @LIBEXPAT@ @LIBDEMANGLE@ \
- @LIBMLD@ @LIBEXC@ -lm @LIBPROFILER@ @LIBEXECINFO@
-
-EXTRA_DIST = records.config.in
-sysconfdir = $(pkgsysconfdir)
-nodist_sysconf_DATA = records.config
-
-install-data-local:
- $(INSTALL) -d -o $(pkgsysuser) -g $(pkgsysgroup) $(DESTDIR)$(pkglocalstatedir) $(DESTDIR)$(pkglogdir) $(DESTDIR)$(pkgsysconfdir) $(DESTDIR)$(pkgdatadir)
-
-install-data-hook:
- -chown -R $(pkgsysuser):$(pkgsysgroup) $(DESTDIR)$(pkgsysconfdir) $(DESTDIR)$(pkgdatadir)
-
-install-exec-local:
- $(INSTALL) -d -o $(pkgsysuser) -g $(pkgsysgroup) $(DESTDIR)$(pkglibexecdir)
-
-install-exec-hook:
- -chown -R $(pkgsysuser):$(pkgsysgroup) $(DESTDIR)$(pkglibexecdir)
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/append-transform/Makefile.am
----------------------------------------------------------------------
diff --git a/example/append-transform/Makefile.am b/example/append-transform/Makefile.am
deleted file mode 100644
index 31c6e0f..0000000
--- a/example/append-transform/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = append-transform.la
-append_transform_la_SOURCES = append-transform.c
-append_transform_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/append-transform.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/basic-auth/Makefile.am
----------------------------------------------------------------------
diff --git a/example/basic-auth/Makefile.am b/example/basic-auth/Makefile.am
deleted file mode 100644
index 9743385..0000000
--- a/example/basic-auth/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = basic-auth.la
-basic_auth_la_SOURCES = basic-auth.c
-basic_auth_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/basic-auth.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/blacklist-0/Makefile.am
----------------------------------------------------------------------
diff --git a/example/blacklist-0/Makefile.am b/example/blacklist-0/Makefile.am
deleted file mode 100644
index 2424d5d..0000000
--- a/example/blacklist-0/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = blacklist-0.la
-blacklist_0_la_SOURCES = blacklist-0.c
-blacklist_0_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/blacklist-0.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/blacklist-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/blacklist-1/Makefile.am b/example/blacklist-1/Makefile.am
deleted file mode 100644
index a00dff2..0000000
--- a/example/blacklist-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = blacklist-1.la
-blacklist_1_la_SOURCES = blacklist-1.c
-blacklist_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/blacklist-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/bnull-transform/Makefile.am
----------------------------------------------------------------------
diff --git a/example/bnull-transform/Makefile.am b/example/bnull-transform/Makefile.am
deleted file mode 100644
index 7a5929b..0000000
--- a/example/bnull-transform/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = bnull-transform.la
-bnull_transform_la_SOURCES = bnull-transform.c
-bnull_transform_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/bnull-transform.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/cache-scan/cache-scan.cc
----------------------------------------------------------------------
diff --git a/example/cache-scan/cache-scan.cc b/example/cache-scan/cache-scan.cc
new file mode 100644
index 0000000..0873a9f
--- /dev/null
+++ b/example/cache-scan/cache-scan.cc
@@ -0,0 +1,498 @@
+/** @file
+
+ A brief file description
+
+ @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.
+ */
+
+/*
+ * cache_scan.cc: use TSCacheScan to print URLs and headers for objects in
+ * the cache when endpoint /show-cache is requested
+ */
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#define __STDC_LIMIT_MACROS
+#include <ts/ts.h>
+#include <ts/experimental.h>
+
+// This gets the PRI*64 types
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
+static TSCont global_contp;
+
+struct cache_scan_state_t
+{
+ TSVConn net_vc;
+ TSVConn cache_vc;
+ TSVIO read_vio;
+ TSVIO write_vio;
+
+ TSIOBuffer req_buffer;
+ TSIOBuffer resp_buffer;
+ TSIOBufferReader resp_reader;
+
+ TSHttpTxn http_txnp;
+ TSAction pending_action;
+ TSCacheKey key_to_delete;
+
+ int64_t total_bytes;
+ int total_items;
+ int done;
+
+ bool write_pending;
+};
+
+typedef struct cache_scan_state_t cache_scan_state;
+
+
+//----------------------------------------------------------------------------
+static int
+handle_scan(TSCont contp, TSEvent event, void *edata)
+{
+ TSCacheHttpInfo cache_infop;
+ cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
+
+ if (event == TS_EVENT_CACHE_REMOVE) {
+ cstate->done = 1;
+ const char error[] = "Cache remove operation succeeded";
+ cstate->cache_vc = (TSVConn) edata;
+ cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
+ TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
+ TSVIOReenable(cstate->write_vio);
+ return 0;
+ }
+
+ if (event == TS_EVENT_CACHE_REMOVE_FAILED) {
+ cstate->done = 1;
+ const char error[] = "Cache remove operation failed error=";
+ char rc[12];
+ snprintf(rc, 12, "%p", edata);
+ cstate->cache_vc = (TSVConn) edata;
+ cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, rc, strlen(rc));
+
+ TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
+ TSVIOReenable(cstate->write_vio);
+ return 0;
+ }
+
+ //first scan event, save vc and start write
+ if (event == TS_EVENT_CACHE_SCAN) {
+ cstate->cache_vc = (TSVConn) edata;
+ cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
+ return TS_EVENT_CONTINUE;
+ }
+ //just stop scanning if blocked or failed
+ if (event == TS_EVENT_CACHE_SCAN_FAILED ||
+ event == TS_EVENT_CACHE_SCAN_OPERATION_BLOCKED || event == TS_EVENT_CACHE_SCAN_OPERATION_FAILED) {
+ cstate->done = 1;
+ if (cstate->resp_buffer) {
+ const char error[] = "Cache scan operation blocked or failed";
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
+ }
+ if (cstate->write_vio) {
+ TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
+ TSVIOReenable(cstate->write_vio);
+ }
+ return TS_CACHE_SCAN_RESULT_DONE;
+ }
+
+ //grab header and print url to outgoing vio
+ if (event == TS_EVENT_CACHE_SCAN_OBJECT) {
+ if (cstate->done) {
+ return TS_CACHE_SCAN_RESULT_DONE;
+ }
+ cache_infop = (TSCacheHttpInfo) edata;
+
+ TSMBuffer req_bufp, resp_bufp;
+ TSMLoc req_hdr_loc, resp_hdr_loc;
+ TSMLoc url_loc;
+
+ char *url;
+ int url_len;
+ const char s1[] = "URL: ", s2[] = "\n";
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s1, sizeof(s1) - 1);
+ TSCacheHttpInfoReqGet(cache_infop, &req_bufp, &req_hdr_loc);
+ TSHttpHdrUrlGet(req_bufp, req_hdr_loc, &url_loc);
+ url = TSUrlStringGet(req_bufp, url_loc, &url_len);
+
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, url, url_len);
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s2, sizeof(s2) - 1);
+
+ TSfree(url);
+ TSHandleMLocRelease(req_bufp, req_hdr_loc, url_loc);
+ TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_hdr_loc);
+
+
+ //print the response headers
+ TSCacheHttpInfoRespGet(cache_infop, &resp_bufp, &resp_hdr_loc);
+ cstate->total_bytes += TSMimeHdrLengthGet(resp_bufp, resp_hdr_loc);
+ TSMimeHdrPrint(resp_bufp, resp_hdr_loc, cstate->resp_buffer);
+ TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_hdr_loc);
+
+
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s2, sizeof(s2) - 1);
+ if (!cstate->write_pending) {
+ cstate->write_pending = 1;
+ TSVIOReenable(cstate->write_vio);
+ }
+
+ cstate->total_items++;
+ return TS_CACHE_SCAN_RESULT_CONTINUE;
+ }
+ //CACHE_SCAN_DONE: ready to close the vc on the next write reenable
+ if (event == TS_EVENT_CACHE_SCAN_DONE) {
+ cstate->done = 1;
+ char s[512];
+ int s_len = snprintf(s, sizeof(s),
+ "</pre></p>\n<p>%d total objects in cache</p>\n"
+ "<form method=\"GET\" action=\"/show-cache\">"
+ "Enter URL to delete: <input type=\"text\" size=\"40\" name=\"remove_url\">"
+ "<input type=\"submit\" value=\"Delete URL\">",
+ cstate->total_items);
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s, s_len);
+ TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
+ if (!cstate->write_pending) {
+ cstate->write_pending = 1;
+ TSVIOReenable(cstate->write_vio);
+ }
+ return TS_CACHE_SCAN_RESULT_DONE;
+ }
+
+ TSError("Unknown event in handle_scan: %d", event);
+ return -1;
+}
+
+//----------------------------------------------------------------------------
+static int
+handle_accept(TSCont contp, TSEvent event, TSVConn vc)
+{
+ cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
+
+ if (event == TS_EVENT_NET_ACCEPT) {
+ if (cstate) {
+ //setup vc, buffers
+ cstate->net_vc = vc;
+
+ cstate->req_buffer = TSIOBufferCreate();
+ cstate->resp_buffer = TSIOBufferCreate();
+ cstate->resp_reader = TSIOBufferReaderAlloc(cstate->resp_buffer);
+
+ cstate->read_vio = TSVConnRead(cstate->net_vc, contp, cstate->req_buffer, INT64_MAX);
+ } else {
+ TSVConnClose(vc);
+ TSContDestroy(contp);
+ }
+ } else {
+ //net_accept failed
+ if (cstate) {
+ TSfree(cstate);
+ }
+ TSContDestroy(contp);
+ }
+
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+static void
+cleanup(TSCont contp)
+{
+
+ //shutdown vc and free memory
+ cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
+
+ if (cstate) {
+ // cancel any pending cache scan actions, since we will be destroying the
+ // continuation
+ if (cstate->pending_action)
+ TSActionCancel(cstate->pending_action);
+
+ if (cstate->net_vc)
+ TSVConnShutdown(cstate->net_vc, 1, 1);
+
+ if (cstate->req_buffer) {
+ TSIOBufferDestroy(cstate->req_buffer);
+ cstate->req_buffer = NULL;
+ }
+
+ if (cstate->key_to_delete) {
+ if (TSCacheKeyDestroy(cstate->key_to_delete) == TS_ERROR) {
+ TSError("failed to destroy cache key");
+ }
+ cstate->key_to_delete = NULL;
+ }
+
+ if (cstate->resp_buffer) {
+ TSIOBufferDestroy(cstate->resp_buffer);
+ cstate->resp_buffer = NULL;
+ }
+
+ TSVConnClose(cstate->net_vc);
+ TSfree(cstate);
+ }
+ TSContDestroy(contp);
+}
+
+//----------------------------------------------------------------------------
+static int
+handle_io(TSCont contp, TSEvent event, void *edata)
+{
+ cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
+
+ switch (event) {
+ case TS_EVENT_VCONN_READ_READY:
+ case TS_EVENT_VCONN_READ_COMPLETE:
+ {
+ //we don't care about the request, so just shut down the read vc
+ TSVConnShutdown(cstate->net_vc, 1, 0);
+ //setup the response headers so we are ready to write body
+ char hdrs[] = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n";
+ cstate->total_bytes = TSIOBufferWrite(cstate->resp_buffer, hdrs, sizeof(hdrs) - 1);
+
+ if (cstate->key_to_delete) {
+ TSAction actionp = TSCacheRemove(contp, cstate->key_to_delete);
+ if (!TSActionDone(actionp)) {
+ cstate->pending_action = actionp;
+ }
+ } else {
+ char head[] = "<h3>Cache Contents:</h3>\n<p><pre>\n";
+ cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, head, sizeof(head) - 1);
+ //start scan
+ TSAction actionp = TSCacheScan(contp, 0, 512000);
+ if (!TSActionDone(actionp)) {
+ cstate->pending_action = actionp;
+ }
+ }
+
+ return 0;
+ }
+ case TS_EVENT_VCONN_WRITE_READY:
+ {
+ TSDebug("cache_iter", "ndone: %" PRId64 " total_bytes: % " PRId64, TSVIONDoneGet(cstate->write_vio), cstate->total_bytes);
+ cstate->write_pending = 0;
+ // the cache scan handler should call vio reenable when there is
+ // available data
+ //TSVIOReenable(cstate->write_vio);
+ return 0;
+ }
+ case TS_EVENT_VCONN_WRITE_COMPLETE:
+ TSDebug("cache_iter", "write complete");
+ case TS_EVENT_VCONN_EOS:
+ default:
+ cstate->done = 1;
+ cleanup(contp);
+ }
+
+ return 0;
+}
+
+
+//----------------------------------------------------------------------------
+// handler for VConnection and CacheScan events
+static int
+cache_intercept(TSCont contp, TSEvent event, void *edata)
+{
+ TSDebug("cache_iter", "cache_intercept event: %d", event);
+
+ switch (event) {
+ case TS_EVENT_NET_ACCEPT:
+ case TS_EVENT_NET_ACCEPT_FAILED:
+ return handle_accept(contp, event, (TSVConn) edata);
+ case TS_EVENT_VCONN_READ_READY:
+ case TS_EVENT_VCONN_READ_COMPLETE:
+ case TS_EVENT_VCONN_WRITE_READY:
+ case TS_EVENT_VCONN_WRITE_COMPLETE:
+ case TS_EVENT_VCONN_EOS:
+ return handle_io(contp, event, edata);
+ case TS_EVENT_CACHE_SCAN:
+ case TS_EVENT_CACHE_SCAN_FAILED:
+ case TS_EVENT_CACHE_SCAN_OBJECT:
+ case TS_EVENT_CACHE_SCAN_OPERATION_BLOCKED:
+ case TS_EVENT_CACHE_SCAN_OPERATION_FAILED:
+ case TS_EVENT_CACHE_SCAN_DONE:
+ case TS_EVENT_CACHE_REMOVE:
+ case TS_EVENT_CACHE_REMOVE_FAILED:
+ return handle_scan(contp, event, edata);
+ case TS_EVENT_ERROR:
+ cleanup(contp);
+ return 0;
+ default:
+ TSError("Unknown event in cache_intercept: %d", event);
+ cleanup(contp);
+ return 0;
+ }
+}
+
+// int unescapifyStr(char* buffer)
+//
+// Unescapifies a URL without a making a copy.
+// The passed in string is modified
+//
+int
+unescapifyStr(char *buffer)
+{
+ char *read = buffer;
+ char *write = buffer;
+ char subStr[3];
+
+ subStr[2] = '\0';
+ while (*read != '\0') {
+ if (*read == '%' && *(read + 1) != '\0' && *(read + 2) != '\0') {
+ subStr[0] = *(++read);
+ subStr[1] = *(++read);
+ *write = (char)strtol(subStr, (char **) NULL, 16);
+ read++;
+ write++;
+ } else if (*read == '+') {
+ *write = ' ';
+ write++;
+ read++;
+ } else {
+ *write = *read;
+ write++;
+ read++;
+ }
+ }
+ *write = '\0';
+
+ return (write - buffer);
+}
+
+//----------------------------------------------------------------------------
+static int
+setup_request(TSCont contp, TSHttpTxn txnp)
+{
+
+ TSMBuffer bufp;
+ TSMLoc hdr_loc;
+ TSMLoc url_loc;
+ TSCont scan_contp;
+ const char *path, *query;
+ cache_scan_state *cstate;
+ int path_len, query_len;
+
+ TSAssert(contp == global_contp);
+
+ if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
+ TSError("couldn't retrieve client request header");
+ TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+ return TS_SUCCESS;
+ }
+
+ if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
+ TSError("couldn't retrieve request url");
+ TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+ TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+ return TS_SUCCESS;
+ }
+
+ path = TSUrlPathGet(bufp, url_loc, &path_len);
+ if (!path) {
+ TSError("couldn't retrieve request path");
+ TSHandleMLocRelease(bufp, hdr_loc, url_loc);
+ TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+ TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+ return TS_SUCCESS;
+ }
+
+ query = TSUrlHttpQueryGet(bufp, url_loc, &query_len);
+
+ if (path_len == 10 && !strncmp(path, "show-cache", 10)) {
+ scan_contp = TSContCreate(cache_intercept, TSMutexCreate());
+ TSHttpTxnIntercept(scan_contp, txnp);
+ cstate = (cache_scan_state *) TSmalloc(sizeof(cache_scan_state));
+ memset(cstate, 0, sizeof(cache_scan_state));
+ cstate->http_txnp = txnp;
+
+ if (query && query_len > 11) {
+
+ char querybuf[2048];
+ query_len = (unsigned) query_len > sizeof(querybuf) - 1 ? sizeof(querybuf) - 1 : query_len;
+ char *start = querybuf, *end = querybuf + query_len;
+ size_t del_url_len;
+ memcpy(querybuf, query, query_len);
+ *end = '\0';
+ start = strstr(querybuf, "remove_url=");
+ if (start && (start == querybuf || *(start - 1) == '&')) {
+ start += 11;
+ if ((end = strstr(start, "&")) != NULL)
+ *end = '\0';
+ del_url_len = unescapifyStr(start);
+ end = start + del_url_len;
+
+ cstate->key_to_delete = TSCacheKeyCreate();
+ TSDebug("cache_iter", "deleting url: %s", start);
+
+ TSMBuffer urlBuf = TSMBufferCreate();
+ TSMLoc urlLoc;
+
+ TSUrlCreate(urlBuf, &urlLoc);
+ if (TSUrlParse(urlBuf, urlLoc, (const char **) &start, end) != TS_PARSE_DONE ||
+ TSCacheKeyDigestFromUrlSet(cstate->key_to_delete, urlLoc) != TS_SUCCESS) {
+ TSError("CacheKeyDigestFromUrlSet failed");
+ TSfree(cstate);
+ TSHandleMLocRelease(urlBuf, NULL, urlLoc);
+ TSCacheKeyDestroy(cstate->key_to_delete);
+ goto Ldone;
+ }
+ TSHandleMLocRelease(urlBuf, NULL, urlLoc);
+ }
+ }
+
+ TSContDataSet(scan_contp, cstate);
+ TSDebug("cache_iter", "setup cache intercept");
+ } else {
+ TSDebug("cache_iter", "not a cache iter request");
+ }
+
+Ldone:
+ TSHandleMLocRelease(bufp, hdr_loc, url_loc);
+ TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
+ TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
+ return TS_SUCCESS;
+}
+
+//----------------------------------------------------------------------------
+// handler for http txn events
+static int
+cache_print_plugin(TSCont contp, TSEvent event, void *edata)
+{
+ switch (event) {
+ case TS_EVENT_HTTP_READ_REQUEST_HDR:
+ return setup_request(contp, (TSHttpTxn) edata);
+ default:
+ break;
+ }
+ TSHttpTxnReenable((TSHttpTxn) edata, TS_EVENT_HTTP_CONTINUE);
+ return TS_SUCCESS;
+}
+
+//----------------------------------------------------------------------------
+void
+TSPluginInit(int argc, const char *argv[])
+{
+ global_contp = TSContCreate(cache_print_plugin, TSMutexCreate());
+ TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, global_contp);
+}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/cache_scan/Makefile.am
----------------------------------------------------------------------
diff --git a/example/cache_scan/Makefile.am b/example/cache_scan/Makefile.am
deleted file mode 100644
index 5b86a8a..0000000
--- a/example/cache_scan/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = cache_scan.la
-cache_scan_la_SOURCES = cache_scan.cc
-cache_scan_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/cache_scan.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/cache_scan/cache_scan.cc
----------------------------------------------------------------------
diff --git a/example/cache_scan/cache_scan.cc b/example/cache_scan/cache_scan.cc
deleted file mode 100644
index 0873a9f..0000000
--- a/example/cache_scan/cache_scan.cc
+++ /dev/null
@@ -1,498 +0,0 @@
-/** @file
-
- A brief file description
-
- @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.
- */
-
-/*
- * cache_scan.cc: use TSCacheScan to print URLs and headers for objects in
- * the cache when endpoint /show-cache is requested
- */
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-#include <stdlib.h>
-#define __STDC_LIMIT_MACROS
-#include <ts/ts.h>
-#include <ts/experimental.h>
-
-// This gets the PRI*64 types
-#define __STDC_FORMAT_MACROS 1
-#include <inttypes.h>
-
-static TSCont global_contp;
-
-struct cache_scan_state_t
-{
- TSVConn net_vc;
- TSVConn cache_vc;
- TSVIO read_vio;
- TSVIO write_vio;
-
- TSIOBuffer req_buffer;
- TSIOBuffer resp_buffer;
- TSIOBufferReader resp_reader;
-
- TSHttpTxn http_txnp;
- TSAction pending_action;
- TSCacheKey key_to_delete;
-
- int64_t total_bytes;
- int total_items;
- int done;
-
- bool write_pending;
-};
-
-typedef struct cache_scan_state_t cache_scan_state;
-
-
-//----------------------------------------------------------------------------
-static int
-handle_scan(TSCont contp, TSEvent event, void *edata)
-{
- TSCacheHttpInfo cache_infop;
- cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
-
- if (event == TS_EVENT_CACHE_REMOVE) {
- cstate->done = 1;
- const char error[] = "Cache remove operation succeeded";
- cstate->cache_vc = (TSVConn) edata;
- cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
- TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
- TSVIOReenable(cstate->write_vio);
- return 0;
- }
-
- if (event == TS_EVENT_CACHE_REMOVE_FAILED) {
- cstate->done = 1;
- const char error[] = "Cache remove operation failed error=";
- char rc[12];
- snprintf(rc, 12, "%p", edata);
- cstate->cache_vc = (TSVConn) edata;
- cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, rc, strlen(rc));
-
- TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
- TSVIOReenable(cstate->write_vio);
- return 0;
- }
-
- //first scan event, save vc and start write
- if (event == TS_EVENT_CACHE_SCAN) {
- cstate->cache_vc = (TSVConn) edata;
- cstate->write_vio = TSVConnWrite(cstate->net_vc, contp, cstate->resp_reader, INT64_MAX);
- return TS_EVENT_CONTINUE;
- }
- //just stop scanning if blocked or failed
- if (event == TS_EVENT_CACHE_SCAN_FAILED ||
- event == TS_EVENT_CACHE_SCAN_OPERATION_BLOCKED || event == TS_EVENT_CACHE_SCAN_OPERATION_FAILED) {
- cstate->done = 1;
- if (cstate->resp_buffer) {
- const char error[] = "Cache scan operation blocked or failed";
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, error, sizeof(error) - 1);
- }
- if (cstate->write_vio) {
- TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
- TSVIOReenable(cstate->write_vio);
- }
- return TS_CACHE_SCAN_RESULT_DONE;
- }
-
- //grab header and print url to outgoing vio
- if (event == TS_EVENT_CACHE_SCAN_OBJECT) {
- if (cstate->done) {
- return TS_CACHE_SCAN_RESULT_DONE;
- }
- cache_infop = (TSCacheHttpInfo) edata;
-
- TSMBuffer req_bufp, resp_bufp;
- TSMLoc req_hdr_loc, resp_hdr_loc;
- TSMLoc url_loc;
-
- char *url;
- int url_len;
- const char s1[] = "URL: ", s2[] = "\n";
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s1, sizeof(s1) - 1);
- TSCacheHttpInfoReqGet(cache_infop, &req_bufp, &req_hdr_loc);
- TSHttpHdrUrlGet(req_bufp, req_hdr_loc, &url_loc);
- url = TSUrlStringGet(req_bufp, url_loc, &url_len);
-
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, url, url_len);
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s2, sizeof(s2) - 1);
-
- TSfree(url);
- TSHandleMLocRelease(req_bufp, req_hdr_loc, url_loc);
- TSHandleMLocRelease(req_bufp, TS_NULL_MLOC, req_hdr_loc);
-
-
- //print the response headers
- TSCacheHttpInfoRespGet(cache_infop, &resp_bufp, &resp_hdr_loc);
- cstate->total_bytes += TSMimeHdrLengthGet(resp_bufp, resp_hdr_loc);
- TSMimeHdrPrint(resp_bufp, resp_hdr_loc, cstate->resp_buffer);
- TSHandleMLocRelease(resp_bufp, TS_NULL_MLOC, resp_hdr_loc);
-
-
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s2, sizeof(s2) - 1);
- if (!cstate->write_pending) {
- cstate->write_pending = 1;
- TSVIOReenable(cstate->write_vio);
- }
-
- cstate->total_items++;
- return TS_CACHE_SCAN_RESULT_CONTINUE;
- }
- //CACHE_SCAN_DONE: ready to close the vc on the next write reenable
- if (event == TS_EVENT_CACHE_SCAN_DONE) {
- cstate->done = 1;
- char s[512];
- int s_len = snprintf(s, sizeof(s),
- "</pre></p>\n<p>%d total objects in cache</p>\n"
- "<form method=\"GET\" action=\"/show-cache\">"
- "Enter URL to delete: <input type=\"text\" size=\"40\" name=\"remove_url\">"
- "<input type=\"submit\" value=\"Delete URL\">",
- cstate->total_items);
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, s, s_len);
- TSVIONBytesSet(cstate->write_vio, cstate->total_bytes);
- if (!cstate->write_pending) {
- cstate->write_pending = 1;
- TSVIOReenable(cstate->write_vio);
- }
- return TS_CACHE_SCAN_RESULT_DONE;
- }
-
- TSError("Unknown event in handle_scan: %d", event);
- return -1;
-}
-
-//----------------------------------------------------------------------------
-static int
-handle_accept(TSCont contp, TSEvent event, TSVConn vc)
-{
- cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
-
- if (event == TS_EVENT_NET_ACCEPT) {
- if (cstate) {
- //setup vc, buffers
- cstate->net_vc = vc;
-
- cstate->req_buffer = TSIOBufferCreate();
- cstate->resp_buffer = TSIOBufferCreate();
- cstate->resp_reader = TSIOBufferReaderAlloc(cstate->resp_buffer);
-
- cstate->read_vio = TSVConnRead(cstate->net_vc, contp, cstate->req_buffer, INT64_MAX);
- } else {
- TSVConnClose(vc);
- TSContDestroy(contp);
- }
- } else {
- //net_accept failed
- if (cstate) {
- TSfree(cstate);
- }
- TSContDestroy(contp);
- }
-
- return 0;
-}
-
-//----------------------------------------------------------------------------
-static void
-cleanup(TSCont contp)
-{
-
- //shutdown vc and free memory
- cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
-
- if (cstate) {
- // cancel any pending cache scan actions, since we will be destroying the
- // continuation
- if (cstate->pending_action)
- TSActionCancel(cstate->pending_action);
-
- if (cstate->net_vc)
- TSVConnShutdown(cstate->net_vc, 1, 1);
-
- if (cstate->req_buffer) {
- TSIOBufferDestroy(cstate->req_buffer);
- cstate->req_buffer = NULL;
- }
-
- if (cstate->key_to_delete) {
- if (TSCacheKeyDestroy(cstate->key_to_delete) == TS_ERROR) {
- TSError("failed to destroy cache key");
- }
- cstate->key_to_delete = NULL;
- }
-
- if (cstate->resp_buffer) {
- TSIOBufferDestroy(cstate->resp_buffer);
- cstate->resp_buffer = NULL;
- }
-
- TSVConnClose(cstate->net_vc);
- TSfree(cstate);
- }
- TSContDestroy(contp);
-}
-
-//----------------------------------------------------------------------------
-static int
-handle_io(TSCont contp, TSEvent event, void *edata)
-{
- cache_scan_state *cstate = (cache_scan_state *) TSContDataGet(contp);
-
- switch (event) {
- case TS_EVENT_VCONN_READ_READY:
- case TS_EVENT_VCONN_READ_COMPLETE:
- {
- //we don't care about the request, so just shut down the read vc
- TSVConnShutdown(cstate->net_vc, 1, 0);
- //setup the response headers so we are ready to write body
- char hdrs[] = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n";
- cstate->total_bytes = TSIOBufferWrite(cstate->resp_buffer, hdrs, sizeof(hdrs) - 1);
-
- if (cstate->key_to_delete) {
- TSAction actionp = TSCacheRemove(contp, cstate->key_to_delete);
- if (!TSActionDone(actionp)) {
- cstate->pending_action = actionp;
- }
- } else {
- char head[] = "<h3>Cache Contents:</h3>\n<p><pre>\n";
- cstate->total_bytes += TSIOBufferWrite(cstate->resp_buffer, head, sizeof(head) - 1);
- //start scan
- TSAction actionp = TSCacheScan(contp, 0, 512000);
- if (!TSActionDone(actionp)) {
- cstate->pending_action = actionp;
- }
- }
-
- return 0;
- }
- case TS_EVENT_VCONN_WRITE_READY:
- {
- TSDebug("cache_iter", "ndone: %" PRId64 " total_bytes: % " PRId64, TSVIONDoneGet(cstate->write_vio), cstate->total_bytes);
- cstate->write_pending = 0;
- // the cache scan handler should call vio reenable when there is
- // available data
- //TSVIOReenable(cstate->write_vio);
- return 0;
- }
- case TS_EVENT_VCONN_WRITE_COMPLETE:
- TSDebug("cache_iter", "write complete");
- case TS_EVENT_VCONN_EOS:
- default:
- cstate->done = 1;
- cleanup(contp);
- }
-
- return 0;
-}
-
-
-//----------------------------------------------------------------------------
-// handler for VConnection and CacheScan events
-static int
-cache_intercept(TSCont contp, TSEvent event, void *edata)
-{
- TSDebug("cache_iter", "cache_intercept event: %d", event);
-
- switch (event) {
- case TS_EVENT_NET_ACCEPT:
- case TS_EVENT_NET_ACCEPT_FAILED:
- return handle_accept(contp, event, (TSVConn) edata);
- case TS_EVENT_VCONN_READ_READY:
- case TS_EVENT_VCONN_READ_COMPLETE:
- case TS_EVENT_VCONN_WRITE_READY:
- case TS_EVENT_VCONN_WRITE_COMPLETE:
- case TS_EVENT_VCONN_EOS:
- return handle_io(contp, event, edata);
- case TS_EVENT_CACHE_SCAN:
- case TS_EVENT_CACHE_SCAN_FAILED:
- case TS_EVENT_CACHE_SCAN_OBJECT:
- case TS_EVENT_CACHE_SCAN_OPERATION_BLOCKED:
- case TS_EVENT_CACHE_SCAN_OPERATION_FAILED:
- case TS_EVENT_CACHE_SCAN_DONE:
- case TS_EVENT_CACHE_REMOVE:
- case TS_EVENT_CACHE_REMOVE_FAILED:
- return handle_scan(contp, event, edata);
- case TS_EVENT_ERROR:
- cleanup(contp);
- return 0;
- default:
- TSError("Unknown event in cache_intercept: %d", event);
- cleanup(contp);
- return 0;
- }
-}
-
-// int unescapifyStr(char* buffer)
-//
-// Unescapifies a URL without a making a copy.
-// The passed in string is modified
-//
-int
-unescapifyStr(char *buffer)
-{
- char *read = buffer;
- char *write = buffer;
- char subStr[3];
-
- subStr[2] = '\0';
- while (*read != '\0') {
- if (*read == '%' && *(read + 1) != '\0' && *(read + 2) != '\0') {
- subStr[0] = *(++read);
- subStr[1] = *(++read);
- *write = (char)strtol(subStr, (char **) NULL, 16);
- read++;
- write++;
- } else if (*read == '+') {
- *write = ' ';
- write++;
- read++;
- } else {
- *write = *read;
- write++;
- read++;
- }
- }
- *write = '\0';
-
- return (write - buffer);
-}
-
-//----------------------------------------------------------------------------
-static int
-setup_request(TSCont contp, TSHttpTxn txnp)
-{
-
- TSMBuffer bufp;
- TSMLoc hdr_loc;
- TSMLoc url_loc;
- TSCont scan_contp;
- const char *path, *query;
- cache_scan_state *cstate;
- int path_len, query_len;
-
- TSAssert(contp == global_contp);
-
- if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
- TSError("couldn't retrieve client request header");
- TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
- return TS_SUCCESS;
- }
-
- if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
- TSError("couldn't retrieve request url");
- TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
- TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
- return TS_SUCCESS;
- }
-
- path = TSUrlPathGet(bufp, url_loc, &path_len);
- if (!path) {
- TSError("couldn't retrieve request path");
- TSHandleMLocRelease(bufp, hdr_loc, url_loc);
- TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
- TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
- return TS_SUCCESS;
- }
-
- query = TSUrlHttpQueryGet(bufp, url_loc, &query_len);
-
- if (path_len == 10 && !strncmp(path, "show-cache", 10)) {
- scan_contp = TSContCreate(cache_intercept, TSMutexCreate());
- TSHttpTxnIntercept(scan_contp, txnp);
- cstate = (cache_scan_state *) TSmalloc(sizeof(cache_scan_state));
- memset(cstate, 0, sizeof(cache_scan_state));
- cstate->http_txnp = txnp;
-
- if (query && query_len > 11) {
-
- char querybuf[2048];
- query_len = (unsigned) query_len > sizeof(querybuf) - 1 ? sizeof(querybuf) - 1 : query_len;
- char *start = querybuf, *end = querybuf + query_len;
- size_t del_url_len;
- memcpy(querybuf, query, query_len);
- *end = '\0';
- start = strstr(querybuf, "remove_url=");
- if (start && (start == querybuf || *(start - 1) == '&')) {
- start += 11;
- if ((end = strstr(start, "&")) != NULL)
- *end = '\0';
- del_url_len = unescapifyStr(start);
- end = start + del_url_len;
-
- cstate->key_to_delete = TSCacheKeyCreate();
- TSDebug("cache_iter", "deleting url: %s", start);
-
- TSMBuffer urlBuf = TSMBufferCreate();
- TSMLoc urlLoc;
-
- TSUrlCreate(urlBuf, &urlLoc);
- if (TSUrlParse(urlBuf, urlLoc, (const char **) &start, end) != TS_PARSE_DONE ||
- TSCacheKeyDigestFromUrlSet(cstate->key_to_delete, urlLoc) != TS_SUCCESS) {
- TSError("CacheKeyDigestFromUrlSet failed");
- TSfree(cstate);
- TSHandleMLocRelease(urlBuf, NULL, urlLoc);
- TSCacheKeyDestroy(cstate->key_to_delete);
- goto Ldone;
- }
- TSHandleMLocRelease(urlBuf, NULL, urlLoc);
- }
- }
-
- TSContDataSet(scan_contp, cstate);
- TSDebug("cache_iter", "setup cache intercept");
- } else {
- TSDebug("cache_iter", "not a cache iter request");
- }
-
-Ldone:
- TSHandleMLocRelease(bufp, hdr_loc, url_loc);
- TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
- TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
- return TS_SUCCESS;
-}
-
-//----------------------------------------------------------------------------
-// handler for http txn events
-static int
-cache_print_plugin(TSCont contp, TSEvent event, void *edata)
-{
- switch (event) {
- case TS_EVENT_HTTP_READ_REQUEST_HDR:
- return setup_request(contp, (TSHttpTxn) edata);
- default:
- break;
- }
- TSHttpTxnReenable((TSHttpTxn) edata, TS_EVENT_HTTP_CONTINUE);
- return TS_SUCCESS;
-}
-
-//----------------------------------------------------------------------------
-void
-TSPluginInit(int argc, const char *argv[])
-{
- global_contp = TSContCreate(cache_print_plugin, TSMutexCreate());
- TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, global_contp);
-}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/file-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/file-1/Makefile.am b/example/file-1/Makefile.am
deleted file mode 100644
index 1cc11e7..0000000
--- a/example/file-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = file-1.la
-file_1_la_SOURCES = file-1.c
-file_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/file-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/hello/Makefile.am
----------------------------------------------------------------------
diff --git a/example/hello/Makefile.am b/example/hello/Makefile.am
deleted file mode 100644
index 7ac2302..0000000
--- a/example/hello/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = hello.la
-hello_la_SOURCES = hello.c
-hello_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/hello.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/null-transform/Makefile.am
----------------------------------------------------------------------
diff --git a/example/null-transform/Makefile.am b/example/null-transform/Makefile.am
deleted file mode 100644
index e9c19f3..0000000
--- a/example/null-transform/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = null-transform.la
-null_transform_la_SOURCES = null-transform.c
-null_transform_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/null-transform.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/output-header/Makefile.am
----------------------------------------------------------------------
diff --git a/example/output-header/Makefile.am b/example/output-header/Makefile.am
deleted file mode 100644
index d015b3f..0000000
--- a/example/output-header/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = output-header.la
-output_header_la_SOURCES = output-header.c
-output_header_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/output-header.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/prefetch/Makefile.am
----------------------------------------------------------------------
diff --git a/example/prefetch/Makefile.am b/example/prefetch/Makefile.am
deleted file mode 100644
index 3d2f110..0000000
--- a/example/prefetch/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = prefetch.la
-prefetch_la_SOURCES = prefetch.c
-prefetch_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/prefetch.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/protocol/Makefile.am
----------------------------------------------------------------------
diff --git a/example/protocol/Makefile.am b/example/protocol/Makefile.am
deleted file mode 100644
index cebee66..0000000
--- a/example/protocol/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = protocol.la
-protocol_la_SOURCES = Protocol.c TxnSM.c
-protocol_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/protocol.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/query-remap/query-remap.c
----------------------------------------------------------------------
diff --git a/example/query-remap/query-remap.c b/example/query-remap/query-remap.c
new file mode 100644
index 0000000..3e400ef
--- /dev/null
+++ b/example/query-remap/query-remap.c
@@ -0,0 +1,185 @@
+/** @file
+
+ A sample plugin to remap requests based on a query parameter
+
+ @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 <ts/ts.h>
+#include <ts/remap.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#define PLUGIN_NAME "query_remap"
+
+/* function prototypes */
+uint32_t hash_fnv32(char *buf, size_t len);
+
+typedef struct _query_remap_info {
+ char *param_name;
+ size_t param_len;
+ char **hosts;
+ int num_hosts;
+} query_remap_info;
+
+
+int
+TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
+{
+ /* Called at TS startup. Nothing needed for this plugin */
+ TSDebug(PLUGIN_NAME , "remap plugin initialized");
+ return 0;
+}
+
+
+int
+TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
+{
+ /* Called for each remap rule using this plugin. The parameters are parsed here */
+ int i;
+ TSDebug(PLUGIN_NAME, "new instance fromURL: %s toURL: %s", argv[0], argv[1]);
+
+ if (argc < 4) {
+ TSError("Missing parameters for " PLUGIN_NAME);
+ return -1;
+ }
+
+ /* initialize the struct to store info about this remap instance
+ the argv parameters are:
+ 0: fromURL
+ 1: toURL
+ 2: query param to hash
+ 3,4,... : server hostnames
+ */
+ query_remap_info *qri = (query_remap_info*) TSmalloc(sizeof(query_remap_info));
+
+ qri->param_name = TSstrdup(argv[2]);
+ qri->param_len = strlen(qri->param_name);
+ qri->num_hosts = argc - 3;
+ qri->hosts = (char**) TSmalloc(qri->num_hosts*sizeof(char*));
+
+ TSDebug(PLUGIN_NAME, " - Hash using query parameter [%s] with %d hosts",
+ qri->param_name, qri->num_hosts);
+
+ for (i=0; i < qri->num_hosts; ++i) {
+ qri->hosts[i] = TSstrdup(argv[i+3]);
+ TSDebug(PLUGIN_NAME, " - Host %d: %s", i, qri->hosts[i]);
+ }
+
+ *ih = (void*)qri;
+ TSDebug(PLUGIN_NAME, "created instance %p", *ih);
+ return 0;
+}
+
+void
+TSRemapDeleteInstance(void* ih)
+{
+ /* Release instance memory allocated in TSRemapNewInstance */
+ int i;
+ TSDebug(PLUGIN_NAME, "deleting instance %p", ih);
+
+ if (ih) {
+ query_remap_info *qri = (query_remap_info*)ih;
+ if (qri->param_name)
+ TSfree(qri->param_name);
+ if (qri->hosts) {
+ for (i=0; i < qri->num_hosts; ++i) {
+ TSfree(qri->hosts[i]);
+ }
+ TSfree(qri->hosts);
+ }
+ TSfree(qri);
+ }
+}
+
+
+TSRemapStatus
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+{
+ int hostidx = -1;
+ query_remap_info *qri = (query_remap_info*)ih;
+
+ if (!qri || !rri) {
+ TSError(PLUGIN_NAME "NULL private data or RRI");
+ return TSREMAP_NO_REMAP;
+ }
+
+ int req_query_len;
+ const char* req_query = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &req_query_len);
+
+ if (req_query && req_query_len > 0) {
+ char *q, *key;
+ char *s = NULL;
+
+ /* make a copy of the query, as it is read only */
+ q = (char*) TSstrndup(req_query, req_query_len+1);
+
+ /* parse query parameters */
+ for (key = strtok_r(q, "&", &s); key != NULL;) {
+ char *val = strchr(key, '=');
+ if (val && (size_t)(val-key) == qri->param_len &&
+ !strncmp(key, qri->param_name, qri->param_len)) {
+ ++val;
+ /* the param key matched the configured param_name
+ hash the param value to pick a host */
+ hostidx = hash_fnv32(val, strlen(val)) % (uint32_t)qri->num_hosts;
+ TSDebug(PLUGIN_NAME, "modifying host based on %s", key);
+ break;
+ }
+ key = strtok_r(NULL, "&", &s);
+ }
+
+ TSfree(q);
+
+ if (hostidx >= 0) {
+ int req_host_len;
+ /* TODO: Perhaps use TSIsDebugTagSet() before calling TSUrlHostGet()... */
+ const char* req_host = TSUrlHostGet(rri->requestBufp, rri->requestUrl, &req_host_len);
+
+ if (TSUrlHostSet(rri->requestBufp, rri->requestUrl, qri->hosts[hostidx], strlen(qri->hosts[hostidx])) != TS_SUCCESS) {
+ TSDebug(PLUGIN_NAME, "Failed to modify the Host in request URL");
+ return TSREMAP_NO_REMAP;
+ }
+ TSDebug(PLUGIN_NAME, "host changed from [%.*s] to [%s]", req_host_len, req_host, qri->hosts[hostidx]);
+ return TSREMAP_DID_REMAP; /* host has been modified */
+ }
+ }
+
+ /* the request was not modified, TS will use the toURL from the remap rule */
+ TSDebug(PLUGIN_NAME, "request not modified");
+ return TSREMAP_NO_REMAP;
+}
+
+
+/* FNV (Fowler/Noll/Vo) hash
+ (description: http://www.isthe.com/chongo/tech/comp/fnv/index.html) */
+uint32_t
+hash_fnv32(char *buf, size_t len)
+{
+ uint32_t hval = (uint32_t)0x811c9dc5; /* FNV1_32_INIT */
+
+ for (; len > 0; --len) {
+ hval *= (uint32_t)0x01000193; /* FNV_32_PRIME */
+ hval ^= (uint32_t)*buf++;
+ }
+
+ return hval;
+}
+
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/query_remap/Makefile.am
----------------------------------------------------------------------
diff --git a/example/query_remap/Makefile.am b/example/query_remap/Makefile.am
deleted file mode 100644
index 34073af..0000000
--- a/example/query_remap/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = query_remap.la
-query_remap_la_SOURCES = query_remap.c
-query_remap_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/query_remap.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/query_remap/query_remap.c
----------------------------------------------------------------------
diff --git a/example/query_remap/query_remap.c b/example/query_remap/query_remap.c
deleted file mode 100644
index 3e400ef..0000000
--- a/example/query_remap/query_remap.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/** @file
-
- A sample plugin to remap requests based on a query parameter
-
- @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 <ts/ts.h>
-#include <ts/remap.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-
-#define PLUGIN_NAME "query_remap"
-
-/* function prototypes */
-uint32_t hash_fnv32(char *buf, size_t len);
-
-typedef struct _query_remap_info {
- char *param_name;
- size_t param_len;
- char **hosts;
- int num_hosts;
-} query_remap_info;
-
-
-int
-TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
-{
- /* Called at TS startup. Nothing needed for this plugin */
- TSDebug(PLUGIN_NAME , "remap plugin initialized");
- return 0;
-}
-
-
-int
-TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
-{
- /* Called for each remap rule using this plugin. The parameters are parsed here */
- int i;
- TSDebug(PLUGIN_NAME, "new instance fromURL: %s toURL: %s", argv[0], argv[1]);
-
- if (argc < 4) {
- TSError("Missing parameters for " PLUGIN_NAME);
- return -1;
- }
-
- /* initialize the struct to store info about this remap instance
- the argv parameters are:
- 0: fromURL
- 1: toURL
- 2: query param to hash
- 3,4,... : server hostnames
- */
- query_remap_info *qri = (query_remap_info*) TSmalloc(sizeof(query_remap_info));
-
- qri->param_name = TSstrdup(argv[2]);
- qri->param_len = strlen(qri->param_name);
- qri->num_hosts = argc - 3;
- qri->hosts = (char**) TSmalloc(qri->num_hosts*sizeof(char*));
-
- TSDebug(PLUGIN_NAME, " - Hash using query parameter [%s] with %d hosts",
- qri->param_name, qri->num_hosts);
-
- for (i=0; i < qri->num_hosts; ++i) {
- qri->hosts[i] = TSstrdup(argv[i+3]);
- TSDebug(PLUGIN_NAME, " - Host %d: %s", i, qri->hosts[i]);
- }
-
- *ih = (void*)qri;
- TSDebug(PLUGIN_NAME, "created instance %p", *ih);
- return 0;
-}
-
-void
-TSRemapDeleteInstance(void* ih)
-{
- /* Release instance memory allocated in TSRemapNewInstance */
- int i;
- TSDebug(PLUGIN_NAME, "deleting instance %p", ih);
-
- if (ih) {
- query_remap_info *qri = (query_remap_info*)ih;
- if (qri->param_name)
- TSfree(qri->param_name);
- if (qri->hosts) {
- for (i=0; i < qri->num_hosts; ++i) {
- TSfree(qri->hosts[i]);
- }
- TSfree(qri->hosts);
- }
- TSfree(qri);
- }
-}
-
-
-TSRemapStatus
-TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
-{
- int hostidx = -1;
- query_remap_info *qri = (query_remap_info*)ih;
-
- if (!qri || !rri) {
- TSError(PLUGIN_NAME "NULL private data or RRI");
- return TSREMAP_NO_REMAP;
- }
-
- int req_query_len;
- const char* req_query = TSUrlHttpQueryGet(rri->requestBufp, rri->requestUrl, &req_query_len);
-
- if (req_query && req_query_len > 0) {
- char *q, *key;
- char *s = NULL;
-
- /* make a copy of the query, as it is read only */
- q = (char*) TSstrndup(req_query, req_query_len+1);
-
- /* parse query parameters */
- for (key = strtok_r(q, "&", &s); key != NULL;) {
- char *val = strchr(key, '=');
- if (val && (size_t)(val-key) == qri->param_len &&
- !strncmp(key, qri->param_name, qri->param_len)) {
- ++val;
- /* the param key matched the configured param_name
- hash the param value to pick a host */
- hostidx = hash_fnv32(val, strlen(val)) % (uint32_t)qri->num_hosts;
- TSDebug(PLUGIN_NAME, "modifying host based on %s", key);
- break;
- }
- key = strtok_r(NULL, "&", &s);
- }
-
- TSfree(q);
-
- if (hostidx >= 0) {
- int req_host_len;
- /* TODO: Perhaps use TSIsDebugTagSet() before calling TSUrlHostGet()... */
- const char* req_host = TSUrlHostGet(rri->requestBufp, rri->requestUrl, &req_host_len);
-
- if (TSUrlHostSet(rri->requestBufp, rri->requestUrl, qri->hosts[hostidx], strlen(qri->hosts[hostidx])) != TS_SUCCESS) {
- TSDebug(PLUGIN_NAME, "Failed to modify the Host in request URL");
- return TSREMAP_NO_REMAP;
- }
- TSDebug(PLUGIN_NAME, "host changed from [%.*s] to [%s]", req_host_len, req_host, qri->hosts[hostidx]);
- return TSREMAP_DID_REMAP; /* host has been modified */
- }
- }
-
- /* the request was not modified, TS will use the toURL from the remap rule */
- TSDebug(PLUGIN_NAME, "request not modified");
- return TSREMAP_NO_REMAP;
-}
-
-
-/* FNV (Fowler/Noll/Vo) hash
- (description: http://www.isthe.com/chongo/tech/comp/fnv/index.html) */
-uint32_t
-hash_fnv32(char *buf, size_t len)
-{
- uint32_t hval = (uint32_t)0x811c9dc5; /* FNV1_32_INIT */
-
- for (; len > 0; --len) {
- hval *= (uint32_t)0x01000193; /* FNV_32_PRIME */
- hval ^= (uint32_t)*buf++;
- }
-
- return hval;
-}
-
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/redirect-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/redirect-1/Makefile.am b/example/redirect-1/Makefile.am
deleted file mode 100644
index 9ba722f..0000000
--- a/example/redirect-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = redirect-1.la
-redirect_1_la_SOURCES = redirect-1.c
-redirect_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/redirect-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/remap/Makefile.am
----------------------------------------------------------------------
diff --git a/example/remap/Makefile.am b/example/remap/Makefile.am
deleted file mode 100644
index e1f95f6..0000000
--- a/example/remap/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = remap.la
-remap_la_SOURCES = remap.cc
-remap_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/remap.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/replace-header/Makefile.am
----------------------------------------------------------------------
diff --git a/example/replace-header/Makefile.am b/example/replace-header/Makefile.am
deleted file mode 100644
index b785eef..0000000
--- a/example/replace-header/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = replace-header.la
-replace_header_la_SOURCES = replace-header.c
-replace_header_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/replace-header.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/response-header-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/response-header-1/Makefile.am b/example/response-header-1/Makefile.am
deleted file mode 100644
index a28819a..0000000
--- a/example/response-header-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = response-header-1.la
-response_header_1_la_SOURCES = response-header-1.c
-response_header_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/response-header-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/server-transform/Makefile.am
----------------------------------------------------------------------
diff --git a/example/server-transform/Makefile.am b/example/server-transform/Makefile.am
deleted file mode 100644
index a2a873d..0000000
--- a/example/server-transform/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = server-transform.la
-server_transform_la_SOURCES = server-transform.c
-server_transform_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/server-transform.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/session-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/session-1/Makefile.am b/example/session-1/Makefile.am
deleted file mode 100644
index 68ac03a..0000000
--- a/example/session-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = session-1.la
-session_1_la_SOURCES = session-1.c
-session_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/session-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/thread-1/Makefile.am
----------------------------------------------------------------------
diff --git a/example/thread-1/Makefile.am b/example/thread-1/Makefile.am
deleted file mode 100644
index 65630a7..0000000
--- a/example/thread-1/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = thread-1.la
-thread_1_la_SOURCES = thread-1.c
-thread_1_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/thread-1.so
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c6de4512/example/thread-pool/Makefile.am
----------------------------------------------------------------------
diff --git a/example/thread-pool/Makefile.am b/example/thread-pool/Makefile.am
deleted file mode 100644
index 1e5af1c..0000000
--- a/example/thread-pool/Makefile.am
+++ /dev/null
@@ -1,25 +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.
-
-AM_CPPFLAGS = -I$(top_srcdir)/proxy/api
-
-pkglibdir = ${pkglibexecdir}
-pkglib_LTLIBRARIES = psi.la
-psi_la_SOURCES = psi.c thread.c
-psi_la_LDFLAGS = -module -avoid-version -shared
-
-all:
- ln -sf .libs/psi.so