From bce1ab5da7f9d73b529fb16d8786dd12b9205336 Mon Sep 17 00:00:00 2001 From: Gancho Tenev Date: Wed, 17 Aug 2016 16:33:15 -0700 Subject: [PATCH] TS-4362 Removed cacheurl plugin --- NOTICE | 5 - configure.ac | 1 - doc/.tx/config | 5 - doc/admin-guide/plugins/cacheurl.en.rst | 149 ------ doc/admin-guide/plugins/index.en.rst | 5 - .../admin-guide/plugins/cacheurl.en.po | 268 ---------- .../admin-guide/plugins/index.en.po | 4 - plugins/Makefile.am | 1 - plugins/cacheurl/Makefile.am | 26 - plugins/cacheurl/cacheurl.cc | 467 ------------------ plugins/cacheurl/cacheurl.config.example | 39 -- 11 files changed, 970 deletions(-) delete mode 100644 doc/admin-guide/plugins/cacheurl.en.rst delete mode 100644 doc/locale/ja/LC_MESSAGES/admin-guide/plugins/cacheurl.en.po delete mode 100644 plugins/cacheurl/Makefile.am delete mode 100644 plugins/cacheurl/cacheurl.cc delete mode 100644 plugins/cacheurl/cacheurl.config.example diff --git a/NOTICE b/NOTICE index 7ee263f0dab..3e8ae3d09e7 100644 --- a/NOTICE +++ b/NOTICE @@ -35,11 +35,6 @@ Copyright (C) 2014 LinkedIn ~~~ -Cacheurl Plugin developed by OmniTI on behalf of Google. -Copyright (C) 2011 Google Inc. - -~~~ - stale_while_revalidate Plugin developed by OmniTI on behalf of Oregon Health & Science University Copyright (C) 2012 Oregon Health & Science University diff --git a/configure.ac b/configure.ac index ab388a0f115..f96681bc837 100644 --- a/configure.ac +++ b/configure.ac @@ -1956,7 +1956,6 @@ AC_CONFIG_FILES([ plugins/Makefile plugins/authproxy/Makefile plugins/background_fetch/Makefile - plugins/cacheurl/Makefile plugins/conf_remap/Makefile plugins/esi/Makefile plugins/generator/Makefile diff --git a/doc/.tx/config b/doc/.tx/config index a5e4d8fcbd0..48e4411b5f1 100644 --- a/doc/.tx/config +++ b/doc/.tx/config @@ -397,11 +397,6 @@ file_filter = locale//LC_MESSAGES/admin-guide/plugins/cachekey.en.po source_file = _build/locale/pot/admin-guide/plugins/cachekey.en.pot source_lang = en -[apache-traffic-server-6x.admin-guide--plugins--cacheurl_en] -file_filter = locale//LC_MESSAGES/admin-guide/plugins/cacheurl.en.po -source_file = _build/locale/pot/admin-guide/plugins/cacheurl.en.pot -source_lang = en - [apache-traffic-server-6x.admin-guide--plugins--combo_handler_en] file_filter = locale//LC_MESSAGES/admin-guide/plugins/combo_handler.en.po source_file = _build/locale/pot/admin-guide/plugins/combo_handler.en.pot diff --git a/doc/admin-guide/plugins/cacheurl.en.rst b/doc/admin-guide/plugins/cacheurl.en.rst deleted file mode 100644 index 01085a9de81..00000000000 --- a/doc/admin-guide/plugins/cacheurl.en.rst +++ /dev/null @@ -1,149 +0,0 @@ -.. Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - -.. include:: ../../common.defs - -.. _admin-plugins-cacheurl: - -Cache URL Plugin -**************** - -.. note:: - - This plugin is deprecated as of v6.2.0 and will be removed as of v7.0.0. - It is replaced by a new :ref:`admin-plugins-cachekey` and you should change your configurations to use the new plugin instead. - Please find some examples below. - -This plugin allows you to change the :term:`cache key` that is used for caching -a request by using any portion of the URL via regular expressions. - -Purpose -======= - -By default |TS| generates keys for cache objects from the full request URL. -Future requests will only be able to use the existing cache object if they -result in the same cache key. It can be the case, however, that the same -content is accessible through more than one request URL. Without any special -configuration, that same content will result in multiple cache objects based on -the differing URLs. - -In this scenario, it can be very beneficial to allow |TS| to reuse a cache -object for multiple URLs. This plugin enables that behavior, by allowing the -administrator to define custom patterns for generating cache keys for some, or -all, of their site's URLs. Uninteresting or irrelevant portions of request URLs -may be removed, or altered, before the cache key is created using the full -power of regular expressions. - -Installation -============ - -This plugin is considered stable and is included with |TS| by default. There -are no special steps necessary for its installation. - -.. configfile:: cacheurl.config - -Configuration -============= - -#. Enable the plugin by modifying :file:`plugin.config` to include the plugin:: - - cacheurl.so - -#. Create a ``cacheurl.config`` file in the plugin directory with the url regex - patterns you wish to match, using the following format:: - - - - The ```` is a regular expression (PCRE) applied against the - incoming request URL. The ```` may contain ``$1``, ``$2``, and - so on, which will be replaced with the appropriate matching group from - ````. - -#. Reload your |TS| configuration with :option:`traffic_ctl config reload`. - -Logging -======= - -A new log file will be generated by this plugin, containing entries for each -incident of an incoming URL's cache key being altered, located in the |TS| -log directory and named ``cacheurl.log``. - -Examples -======== - -While many possibilities exist, limited really only by your site's URL scheme -and the capabililties of PCRE regular expressions, the following are examples -of a few situations |TS| administrators may encounter. - -Multiple Domains, One Cache Object ----------------------------------- - -If you have multiple subdomains which serve the same file content, there may be -no reason to duplicate their storage (leading to higher churn and faster -potential eviction of still-fresh objects) in your |TS| cache. By default, -however, the differing subdomains will lead to differing cache keys. To work -around this, a pattern like the following can be used to create a single cache -key which will be valid for all subdomains:: - - http://s[123].example.com/(.*) http://s.example.com.TSINTERNAL/$1 - -Now, the domains ``s1.example.com``, ``s2.example.com``, and ``s3.example.com`` -will effectively share cache objects. Adding a unique suffix (``TSINTERNAL`` in -this example) to the cache key guarantees that it won't clash with a real URL -should s.example.com exist. - -Converting to :ref:`admin-plugins-cachekey` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -You could do the same with :ref:`admin-plugins-cachekey` by adding the following to the mapping rules:: - - @plugin=cachekey.so @pparam=--capture-prefix=/s[123].example.com:.*/s.example.com.TSINTERNAL/ - - -Ignoring Some Query Parameters ------------------------------- - -If your site attaches, for example, session information to URLs, even on pages -which do not include session-specific content and may be safely cached, you can -add a pattern which strips this unnecessary information from the URL before -generating a cache key, while still retaining important query parameters:: - - http://www.example.com/video\?.*?\&?(id=[0-9a-f]*).*?\&(format=[a-z]*) http://video-srv.example.com.ATSINTERNAL/$1&$2 - -Converting to :ref:`admin-plugins-cachekey` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -You could do the same with :ref:`admin-plugins-cachekey` by adding the following to the mapping rules:: - - @plugin=cachekey.so @pparam=--include-params=id,format - - -Ignore Query String on Specific Pages -------------------------------------- - -To completely ignore a query string for a specific page, it's quite easy to -simply match and drop everything from the ``?`` query string opener to the end -of the URL:: - - http://www.example.com/some/page(?:\?|$) http://www.example.com/some/page - -Converting to :ref:`admin-plugins-cachekey` -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -You could do the same with :ref:`admin-plugins-cachekey` by adding the following to the mapping rules:: - - @plugin=cachekey.so @pparam=--remove-all-params diff --git a/doc/admin-guide/plugins/index.en.rst b/doc/admin-guide/plugins/index.en.rst index acd4f221ff1..51999863934 100644 --- a/doc/admin-guide/plugins/index.en.rst +++ b/doc/admin-guide/plugins/index.en.rst @@ -48,7 +48,6 @@ Plugins that are considered stable are installed by default in |TS| releases. AuthProxy AWS S3 Authentication Background Fetch - Cache URL Configuration Remap ESI Generator @@ -70,10 +69,6 @@ Plugins that are considered stable are installed by default in |TS| releases. :doc:`Background Fetch ` Proactively fetch content from Origin in a way that it will fill the object into cache. -:doc:`Cache URL ` - Modify the :term:`cache key` used for requests by applying a regular - expression to the URL. - :doc:`Configuration Remap ` Override configuration directives on a per-rule basis. diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/cacheurl.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/cacheurl.en.po deleted file mode 100644 index 1f1cc1e32c8..00000000000 --- a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/cacheurl.en.po +++ /dev/null @@ -1,268 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) 2015, dev@trafficserver.apache.org -# This file is distributed under the same license as the Apache Traffic -# Server package. -# FIRST AUTHOR , 2016. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: Apache Traffic Server 6.2\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2016-06-30 14:07+0900\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.2.0\n" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:23 -#, fuzzy -msgid "Cache URL Plugin" -msgstr "CacheURL プラグイン" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:27 -msgid "" -"This plugin is deprecated as of v6.2.0 and will be removed as of v7.0.0. It " -"is replaced by a new :ref:`admin-plugins-cachekey` and you should change " -"your configurations to use the new plugin instead. Please find some " -"examples below." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:31 -#, fuzzy -msgid "" -"This plugin allows you to change the :term:`cache key` that is used for " -"caching a request by using any portion of the URL via regular expressions." -msgstr "" -"このプラグインは正規表現により URL の一部を使用することでリクエストをキャッ" -"シュする際に用いられるキーを変更することを可能にします。異なる URL で同じコ" -"ンテンツ ( 例えばミラーサイト ) のリクエストが一度だけキャッシュされるように" -"設計されています。" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:35 -msgid "Purpose" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:37 -msgid "" -"By default |TS| generates keys for cache objects from the full request URL. " -"Future requests will only be able to use the existing cache object if they " -"result in the same cache key. It can be the case, however, that the same " -"content is accessible through more than one request URL. Without any " -"special configuration, that same content will result in multiple cache " -"objects based on the differing URLs." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:44 -msgid "" -"In this scenario, it can be very beneficial to allow |TS| to reuse a cache " -"object for multiple URLs. This plugin enables that behavior, by allowing " -"the administrator to define custom patterns for generating cache keys for " -"some, or all, of their site's URLs. Uninteresting or irrelevant portions of " -"request URLs may be removed, or altered, before the cache key is created " -"using the full power of regular expressions." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:52 -msgid "Installation" -msgstr "インストール" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:54 -msgid "" -"This plugin is considered stable and is included with |TS| by default. " -"There are no special steps necessary for its installation." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:60 -msgid "Configuration" -msgstr "設定" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:62 -#, fuzzy -msgid "" -"Enable the plugin by modifying :file:`plugin.config` to include the plugin::" -msgstr ":file:`plugin.config` ファイルにプラグインを追加する。" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:66 -#, fuzzy -msgid "" -"Create a ``cacheurl.config`` file in the plugin directory with the url " -"regex patterns you wish to match, using the following format::" -msgstr "" -"プラグインディレクトリにマッチさせる URL 正規表現パターンを記載した " -"``cacheurl.config`` ファイルを作成する。" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:71 -msgid "" -"The ```` is a regular expression (PCRE) applied against the " -"incoming request URL. The ```` may contain ``$1``, ``$2``, and " -"so on, which will be replaced with the appropriate matching group from " -"````." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:76 -msgid "" -"Reload your |TS| configuration with :option:`traffic_ctl config reload`." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:79 -msgid "Logging" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:81 -msgid "" -"A new log file will be generated by this plugin, containing entries for " -"each incident of an incoming URL's cache key being altered, located in the |" -"TS| log directory and named ``cacheurl.log``." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:86 -msgid "Examples" -msgstr "例" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:88 -msgid "" -"While many possibilities exist, limited really only by your site's URL " -"scheme and the capabililties of PCRE regular expressions, the following are " -"examples of a few situations |TS| administrators may encounter." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:93 -msgid "Multiple Domains, One Cache Object" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:95 -msgid "" -"If you have multiple subdomains which serve the same file content, there " -"may be no reason to duplicate their storage (leading to higher churn and " -"faster potential eviction of still-fresh objects) in your |TS| cache. By " -"default, however, the differing subdomains will lead to differing cache " -"keys. To work around this, a pattern like the following can be used to " -"create a single cache key which will be valid for all subdomains::" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:104 -msgid "" -"Now, the domains ``s1.example.com``, ``s2.example.com``, and ``s3.example." -"com`` will effectively share cache objects. Adding a unique suffix " -"(``TSINTERNAL`` in this example) to the cache key guarantees that it won't " -"clash with a real URL should s.example.com exist." -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:110 -#: ../../../admin-guide/plugins/cacheurl.en.rst:128 -#: ../../../admin-guide/plugins/cacheurl.en.rst:145 -msgid "Converting to :ref:`admin-plugins-cachekey`" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:112 -#: ../../../admin-guide/plugins/cacheurl.en.rst:130 -#: ../../../admin-guide/plugins/cacheurl.en.rst:147 -msgid "" -"You could do the same with :ref:`admin-plugins-cachekey` by adding the " -"following to the mapping rules::" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:118 -msgid "Ignoring Some Query Parameters" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:120 -msgid "" -"If your site attaches, for example, session information to URLs, even on " -"pages which do not include session-specific content and may be safely " -"cached, you can add a pattern which strips this unnecessary information " -"from the URL before generating a cache key, while still retaining important " -"query parameters::" -msgstr "" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:136 -#, fuzzy -msgid "Ignore Query String on Specific Pages" -msgstr "特定のページでクエリー文字列を完全に無視する。" - -#: ../../../admin-guide/plugins/cacheurl.en.rst:138 -msgid "" -"To completely ignore a query string for a specific page, it's quite easy to " -"simply match and drop everything from the ``?`` query string opener to the " -"end of the URL::" -msgstr "" - -#~ msgid "This plugin is only built if the configure option ::" -#~ msgstr "このプラグインはビルド時の設定オプションに ::" - -#~ msgid "is given at build time." -#~ msgstr "が与えられている場合にのみビルドされます。" - -#~ msgid "" -#~ "Cache based on only some parts of a query string (e.g. ignore session " -#~ "information). This plucks out the id and format query string variables " -#~ "and only considers those when making the cache key." -#~ msgstr "" -#~ "クエリー文字列の一部のみをもとにキャッシュする ( 例 セッション情報を無視" -#~ "する ) 。これは id と format クエリー文字列変数を抜き取り、キャッシュキー" -#~ "を生成する際にはそれらだけを考慮します。" - -#~ msgid "More docs" -#~ msgstr "参考文献" - -#~ msgid "" -#~ "Start traffic server. Any rewritten URLs will be written to ``cacheurl." -#~ "log`` in the log directory by default." -#~ msgstr "" -#~ "Traffic Server を起動。書き換えられた URL はデフォルトではログディレクト" -#~ "リの ``cacheurl.log`` に書かれます。" - -#~ msgid "" -#~ "The url_pattern is a regular expression (pcre). The replacement can " -#~ "contain $1, $2 and so on, which will be replaced with the appropriate " -#~ "matching group from the pattern." -#~ msgstr "" -#~ "url_pattern は正規表現 (pcre) です。replacement は $1 、$2 などを含むこと" -#~ "ができ、パターンの適切なマッチンググループと置き換えられます。" - -#~ msgid "" -#~ "There are some docs on cacheurl in Chinese, please find them in the " -#~ "following:" -#~ msgstr "" -#~ "cacheurl についていくつかの中国語のドキュメントがあります。以下から探して" -#~ "ください。" - -#~ msgid "" -#~ "To make files from s1.example.com, s2.example.com and s3.example.com all " -#~ "be cached with the same key. Adding a unique suffix (TSINTERNAL in this " -#~ "example) to the cache key guarantees that it won't clash with a real URL " -#~ "should s.example.com exist." -#~ msgstr "" -#~ "s1.example.com 、s2.example.com そして s3.example.com からのファイルすべ" -#~ "てが同じキーでキャッシュされるようにする。キャッシュキーが実在する URL s." -#~ "example.com と衝突しないことを保証するために一意なサフィックス ( この例で" -#~ "は TSINTERNAL ) を追加します。" - -#~ msgid "" -#~ "``http://s[123].example.com/(.*) http://s.example.com.TSINTERNAL/$1``" -#~ msgstr "" -#~ "``http://s[123].example.com/(.*) http://s.example.com.TSINTERNAL/$1``" - -#~ msgid "" -#~ "``http://www.example.com/some/page.html(?:\\?|$) http://www.example.com/" -#~ "some/page.html``" -#~ msgstr "" -#~ "``http://www.example.com/some/page.html(?:\\?|$) http://www.example.com/" -#~ "some/page.html``" - -#~ msgid "" -#~ "``http://www.example.com/video\\?.*?\\&?(id=[0-9a-f]*).*?\\&(format=[a-" -#~ "z]*) http://video-srv.example.com.ATSINTERNAL/$1&$2``" -#~ msgstr "" -#~ "``http://www.example.com/video\\?.*?\\&?(id=[0-9a-f]*).*?\\&(format=[a-" -#~ "z]*) http://video-srv.example.com.ATSINTERNAL/$1&$2``" - -#~ msgid "``url_pattern cache_key_replacement``" -#~ msgstr "``url_pattern cache_key_replacement``" - -#~ msgid "https://blog.zymlinux.net/index.php/archives/195" -#~ msgstr "https://blog.zymlinux.net/index.php/archives/195" diff --git a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po index 25c705410b6..c5f3022e9a0 100644 --- a/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po +++ b/doc/locale/ja/LC_MESSAGES/admin-guide/plugins/index.en.po @@ -57,10 +57,6 @@ msgstr "" "安定的なプラグインです。これらは |TS| のリリースにデフォルトでインストールさ" "れれています。" -#: ../../../admin-guide/plugins/index.en.rst:59 -msgid ":doc:`Cache URL `" -msgstr "" - #: ../../../admin-guide/plugins/index.en.rst:58 msgid "" "Modify the :term:`cache key` used for requests by applying a regular " diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 43de8213a88..0eb7980243c 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -19,7 +19,6 @@ SUBDIRS = \ authproxy \ background_fetch \ - cacheurl \ conf_remap \ esi \ generator \ diff --git a/plugins/cacheurl/Makefile.am b/plugins/cacheurl/Makefile.am deleted file mode 100644 index 65d521a3163..00000000000 --- a/plugins/cacheurl/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -include $(top_srcdir)/build/plugins.mk - -pkglib_LTLIBRARIES = cacheurl.la -cacheurl_la_SOURCES = cacheurl.cc -cacheurl_la_LDFLAGS = $(TS_PLUGIN_LDFLAGS) - -include $(top_srcdir)/build/tidy.mk - -tidy-local: $(DIST_SOURCES) - $(CXX_Clang_Tidy) diff --git a/plugins/cacheurl/cacheurl.cc b/plugins/cacheurl/cacheurl.cc deleted file mode 100644 index 75ea8fc13af..00000000000 --- a/plugins/cacheurl/cacheurl.cc +++ /dev/null @@ -1,467 +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. - */ - -/* cacheurl.cc - Plugin to modify the URL used as a cache key for certain - * requests, without modifying the URL used for actually fetching data from - * the origin server. - */ - -#include -#include - -#include "ts/ts.h" -#include "ts/remap.h" - -#include "ts/ink_defs.h" -#include "ts/ink_memory.h" - -#include -#include - -#ifdef HAVE_PCRE_PCRE_H -#include -#else -#include -#endif - -#define TOKENCOUNT 10 -#define OVECOUNT 30 -#define PLUGIN_NAME "cacheurl" -#define DEFAULT_CONFIG "cacheurl.config" - -struct regex_info { - pcre *re; /* Compiled regular expression */ - int tokcount; /* Token count */ - char *pattern; /* Pattern string */ - char *replacement; /* Replacement string */ - int *tokens; /* Array of $x token values */ - int *tokenoffset; /* Array of $x token offsets */ -}; - -struct pr_list { - std::vector pr; - - pr_list() {} - ~pr_list() - { - for (std::vector::iterator info = this->pr.begin(); info != this->pr.end(); ++info) { - TSfree((*info)->tokens); - TSfree((*info)->tokenoffset); - pcre_free((*info)->re); - TSfree(*info); - } - } -}; - -static int -regex_substitute(char **buf, char *str, regex_info *info) -{ - int matchcount; - int ovector[OVECOUNT]; /* Locations of matches in regex */ - - int replacelen; /* length of replacement string */ - int i; - int offset; - int prev; - - /* Perform the regex matching */ - matchcount = pcre_exec(info->re, NULL, str, strlen(str), 0, 0, ovector, OVECOUNT); - if (matchcount < 0) { - switch (matchcount) { - case PCRE_ERROR_NOMATCH: - break; - default: - TSError("[%s] Matching error: %d", PLUGIN_NAME, matchcount); - break; - } - return 0; - } - - /* Verify the replacement has the right number of matching groups */ - for (i = 0; i < info->tokcount; i++) { - if (info->tokens[i] >= matchcount) { - TSError("[%s] Invalid reference int replacement: $%d", PLUGIN_NAME, info->tokens[i]); - return 0; - } - } - - /* malloc the replacement string */ - replacelen = strlen(info->replacement); - replacelen -= info->tokcount * 2; /* Subtract $1, $2 etc... */ - for (i = 0; i < info->tokcount; i++) { - replacelen += (ovector[info->tokens[i] * 2 + 1] - ovector[info->tokens[i] * 2]); - } - replacelen++; /* Null terminator */ - *buf = (char *)TSmalloc(replacelen); - - /* perform string replacement */ - offset = 0; /* Where we are adding new data in the string */ - prev = 0; - for (i = 0; i < info->tokcount; i++) { - memcpy(*buf + offset, info->replacement + prev, info->tokenoffset[i] - prev); - offset += (info->tokenoffset[i] - prev); - prev = info->tokenoffset[i] + 2; - - memcpy(*buf + offset, str + ovector[info->tokens[i] * 2], ovector[info->tokens[i] * 2 + 1] - ovector[info->tokens[i] * 2]); - offset += (ovector[info->tokens[i] * 2 + 1] - ovector[info->tokens[i] * 2]); - } - memcpy(*buf + offset, info->replacement + prev, strlen(info->replacement) - prev); - offset += strlen(info->replacement) - prev; - (*buf)[offset] = 0; /* Null termination */ - return 1; -} - -static int -regex_compile(regex_info **buf, char *pattern, char *replacement) -{ - const char *reerror; /* Error string from pcre */ - int reerroffset; /* Offset where any pcre error occured */ - - int tokcount; - int *tokens = NULL; - int *tokenoffset = NULL; - - int status = 1; /* Status (return value) of the function */ - regex_info *info = (regex_info *)TSmalloc(sizeof(regex_info)); - - /* Precompile the regular expression */ - info->re = pcre_compile(pattern, 0, &reerror, &reerroffset, NULL); - if (!info->re) { - TSError("[%s] Compilation of regex '%s' failed at char %d: %s", PLUGIN_NAME, pattern, reerroffset, reerror); - status = 0; - } - - /* Precalculate the location of $X tokens in the replacement */ - tokcount = 0; - if (status) { - tokens = (int *)TSmalloc(sizeof(int) * TOKENCOUNT); - tokenoffset = (int *)TSmalloc(sizeof(int) * TOKENCOUNT); - for (unsigned i = 0; i < strlen(replacement); i++) { - if (replacement[i] == '$') { - if (tokcount >= TOKENCOUNT) { - TSError("[%s] Error: too many tokens in replacement " - "string: %s", - PLUGIN_NAME, replacement); - status = 0; - break; - } else if (replacement[i + 1] < '0' || replacement[i + 1] > '9') { - TSError("[%s] Error: Invalid replacement token $%c in %s: should be $0 - $9", PLUGIN_NAME, replacement[i + 1], - replacement); - status = 0; - break; - } else { - /* Store the location of the replacement */ - /* Convert '0' to 0 */ - tokens[tokcount] = replacement[i + 1] - '0'; - tokenoffset[tokcount] = i; - tokcount++; - /* Skip the next char */ - i++; - } - } - } - } - - if (status) { - /* Everything went OK */ - info->tokcount = tokcount; - info->tokens = tokens; - info->tokenoffset = tokenoffset; - - info->pattern = TSstrdup(pattern); - info->replacement = TSstrdup(replacement); - - *buf = info; - } else { - /* Something went wrong, clean up */ - TSfree(tokens); - TSfree(tokenoffset); - if (info->re) { - pcre_free(info->re); - } - TSfree(info); - } - return status; -} - -static pr_list * -load_config_file(const char *config_file) -{ - char buffer[1024]; - std::string path; - TSFile fh; - ats_scoped_obj prl(new pr_list()); - - /* locations in a config file line, end of line, split start, split end */ - char *eol, *spstart, *spend; - int lineno = 0; - int retval; - regex_info *info = 0; - - if (config_file == NULL) { - config_file = DEFAULT_CONFIG; - } - - if (*config_file != '/') { - // Relative paths are relative to the config directory - path = TSConfigDirGet(); - path += "/"; - path += config_file; - } else { - // Absolute path ... - path = config_file; - } - - TSDebug(PLUGIN_NAME, "Opening config file: %s", path.c_str()); - fh = TSfopen(path.c_str(), "r"); - - if (!fh) { - TSError("[%s] Unable to open %s. No patterns will be loaded", PLUGIN_NAME, path.c_str()); - return NULL; - } - - while (TSfgets(fh, buffer, sizeof(buffer) - 1)) { - lineno++; - - // make sure line was not bigger than buffer - if ((eol = strchr(buffer, '\n')) == NULL && (eol = strstr(buffer, "\r\n")) == NULL) { - // Malformed line - skip - TSError("%s: config line too long, did not get a good line in cfg, skipping, line: %s", PLUGIN_NAME, buffer); - memset(buffer, 0, sizeof(buffer)); - continue; - } else { - *eol = 0; - } - // make sure line has something useful on it - // or allow # Comments, only at line beginning - if (eol - buffer < 2 || buffer[0] == '#') { - memset(buffer, 0, sizeof(buffer)); - continue; - } - - /* Split line into two parts based on whitespace */ - /* Find first whitespace */ - spstart = strstr(buffer, " "); - if (!spstart) { - spstart = strstr(buffer, "\t"); - } - if (!spstart) { - TSError("[%s] ERROR: Invalid format on line %d. Skipping", PLUGIN_NAME, lineno); - TSfclose(fh); - return NULL; - } - /* Find part of the line after any whitespace */ - spend = spstart + 1; - while (*spend == ' ' || *spend == '\t') { - spend++; - } - if (*spend == 0) { - /* We reached the end of the string without any non-whitepace */ - TSError("[%s] ERROR: Invalid format on line %d. Skipping", PLUGIN_NAME, lineno); - TSfclose(fh); - return NULL; - } - - *spstart = 0; - /* We have the pattern/replacement, now do precompilation. - * buffer is the first part of the line. spend is the second part just - * after the whitespace */ - TSDebug(PLUGIN_NAME, "Adding pattern/replacement pair: '%s' -> '%s'", buffer, spend); - retval = regex_compile(&info, buffer, spend); - if (!retval) { - TSError("[%s] Error precompiling regex/replacement. Skipping.", PLUGIN_NAME); - TSfclose(fh); - return NULL; - } - - prl->pr.push_back(info); - } - TSfclose(fh); - - if (prl->pr.empty()) { - TSError("[%s] No regular expressions loaded.", PLUGIN_NAME); - } - - TSDebug(PLUGIN_NAME, "loaded %u regexes", (unsigned)prl->pr.size()); - return prl.release(); -} - -static int -rewrite_cacheurl(pr_list *prl, TSHttpTxn txnp) -{ - int ok = 1; - char *newurl = 0; - int retval; - char *url; - int url_length; - - url = TSHttpTxnEffectiveUrlStringGet(txnp, &url_length); - if (!url) { - TSError("[%s] couldn't retrieve request url", PLUGIN_NAME); - ok = 0; - } - - if (ok) { - for (std::vector::iterator info = prl->pr.begin(); info != prl->pr.end(); ++info) { - retval = regex_substitute(&newurl, url, *info); - if (retval) { - /* Successful match/substitution */ - break; - } - } - if (newurl) { - TSDebug(PLUGIN_NAME, "Rewriting cache URL for %s to %s", url, newurl); - if (TSCacheUrlSet(txnp, newurl, strlen(newurl)) != TS_SUCCESS) { - TSError("[%s] Unable to modify cache url from " - "%s to %s", - PLUGIN_NAME, url, newurl); - ok = 0; - } - } - } - - /* Clean up */ - if (url) { - TSfree(url); - } - if (newurl) { - TSfree(newurl); - } - - return ok; -} - -static int -handle_hook(TSCont contp, TSEvent event, void *edata) -{ - TSHttpTxn txnp = (TSHttpTxn)edata; - pr_list *prl; - int ok = 1; - - prl = (pr_list *)TSContDataGet(contp); - - switch (event) { - case TS_EVENT_HTTP_READ_REQUEST_HDR: - ok = rewrite_cacheurl(prl, txnp); - TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE); - break; - default: - TSAssert(!"Unexpected event"); - ok = 0; - break; - } - - return ok; -} - -/* Generic error message function for errors in plugin initialization */ -static void -initialization_error(const char *msg) -{ - TSError("[%s] %s", PLUGIN_NAME, msg); - TSError("[%s] Unable to initialize plugin (disabled).", PLUGIN_NAME); -} - -TSReturnCode -TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size) -{ - if (!api_info) { - strncpy(errbuf, "[tsremap_init] Invalid TSRemapInterface argument", errbuf_size - 1); - return TS_ERROR; - } - - if (api_info->size < sizeof(TSRemapInterface)) { - strncpy(errbuf, "[tsremap_init] Incorrect size of TSRemapInterface structure", errbuf_size - 1); - return TS_ERROR; - } - - if (api_info->tsremap_version < TSREMAP_VERSION) { - snprintf(errbuf, errbuf_size - 1, "[tsremap_init] Incorrect API version %ld.%ld", api_info->tsremap_version >> 16, - (api_info->tsremap_version & 0xffff)); - return TS_ERROR; - } - - TSDebug(PLUGIN_NAME, "remap plugin is successfully initialized"); - - TSError("[%s] is deprecated and will be removed as of v7.0.0", PLUGIN_NAME); - - return TS_SUCCESS; -} - -TSReturnCode -TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf ATS_UNUSED, int errbuf_size ATS_UNUSED) -{ - *ih = load_config_file(argc > 2 ? argv[2] : NULL); - return (NULL == *ih) ? TS_ERROR : TS_SUCCESS; -} - -void -TSRemapDeleteInstance(void *ih) -{ - pr_list *prl = (pr_list *)ih; - - TSDebug(PLUGIN_NAME, "Deleting remap instance"); - - delete prl; -} - -TSRemapStatus -TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri ATS_UNUSED) -{ - int ok; - - ok = rewrite_cacheurl((pr_list *)ih, rh); - if (ok) { - return TSREMAP_NO_REMAP; - } else { - return TSREMAP_ERROR; - } -} - -void -TSPluginInit(int argc, const char *argv[]) -{ - TSPluginRegistrationInfo info; - TSCont contp; - pr_list *prl; - - info.plugin_name = (char *)PLUGIN_NAME; - info.vendor_name = (char *)"Apache Software Foundation"; - info.support_email = (char *)"dev@trafficserver.apache.org"; - - if (TSPluginRegister(&info) != TS_SUCCESS) { - TSDebug(PLUGIN_NAME, "ERROR, Plugin registration failed"); - initialization_error("Plugin registration failed."); - return; - } - - prl = load_config_file(argc > 1 ? argv[1] : NULL); - if (prl) { - contp = TSContCreate((TSEventFunc)handle_hook, NULL); - /* Store the pattern replacement list in the continuation */ - TSContDataSet(contp, prl); - TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, contp); - } else { - TSDebug(PLUGIN_NAME, "ERROR, Plugin config load failed."); - initialization_error("Plugin config load failed."); - return; - } - - TSError("[%s] is deprecated and will be removed as of v7.0.0", PLUGIN_NAME); -} diff --git a/plugins/cacheurl/cacheurl.config.example b/plugins/cacheurl/cacheurl.config.example deleted file mode 100644 index 67a91a76075..00000000000 --- a/plugins/cacheurl/cacheurl.config.example +++ /dev/null @@ -1,39 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Configuration file format: -# -# url_pattern cache_key_replacement -# -# The url_pattern is a regular expression (pcre). The replacement can contain -# $1, $2 and so on, which will be replaced with the appropriate matching group -# from the pattern. - -# Make files from s1.example.com, s2.example.com and s3.example.com all -# be cached with the same key. -# Adding a unique suffix (TSINTERNAL in this example) to the cache key -# guarantees that it won't clash with a real URL should s.example.com exist. -http://s[123].example.com/(.*) http://s.example.com.TSINTERNAL/$1 - -# Cache based on only some parts of a query string (e.g. ignore session -# information). This plucks out the id and format query string variables and -# only considers those when making the cache key. -http://www.example.com/video\?.*?\&?(id=[0-9a-f]*).*?\&(format=[a-z]*) http://video-srv.example.com.ATSINTERNAL/$1&$2 - -# Completely ignore a query string for a specific page -http://www.example.com/some/page.html(?:\?|$) http://www.example.com/some/page.html