You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2017/03/29 00:26:34 UTC
[trafficserver] branch master updated: TS-4976: Regularize plugins
- query_remap
This is an automated email from the ASF dual-hosted git repository.
amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ed748b7 TS-4976: Regularize plugins - query_remap
ed748b7 is described below
commit ed748b7f7d53d9b4353adae8b32463c6274200f4
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Tue Mar 28 09:43:46 2017 -0500
TS-4976: Regularize plugins - query_remap
---
.../plugins/example-plugins/index.en.rst | 2 +-
.../example-query-remap.en.rst | 96 ++++------------------
.../{query-remap => query_remap}/index.en.rst | 11 +--
example/Makefile.am | 4 +-
.../query-remap.c => query_remap/query_remap.c} | 4 +-
5 files changed, 25 insertions(+), 92 deletions(-)
diff --git a/doc/developer-guide/plugins/example-plugins/index.en.rst b/doc/developer-guide/plugins/example-plugins/index.en.rst
index d805eb6..9ab3492 100644
--- a/doc/developer-guide/plugins/example-plugins/index.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/index.en.rst
@@ -27,7 +27,7 @@ Example Plugins
basic-authorization/index.en
blacklist/index.en
- query-remap/index.en
+ query_remap/index.en
.. _developer-plugins-header-based-examples:
diff --git a/doc/developer-guide/plugins/example-plugins/query-remap/example-query-remap.en.rst b/doc/developer-guide/plugins/example-plugins/query_remap/example-query-remap.en.rst
similarity index 57%
rename from doc/developer-guide/plugins/example-plugins/query-remap/example-query-remap.en.rst
rename to doc/developer-guide/plugins/example-plugins/query_remap/example-query-remap.en.rst
index 09e72eb..33a4c77 100644
--- a/doc/developer-guide/plugins/example-plugins/query-remap/example-query-remap.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/query_remap/example-query-remap.en.rst
@@ -33,14 +33,12 @@ Configuration of query\_remap
The query remap plugin will allow the query parameter name to be
specified, along with the hostnames of the servers to hash across.
-Sample ``remap.config`` rules using ``query_remap`` will look like:
-
-::
+Sample :file:`remap.config` rules using ``query_remap`` will look like::
map http://www.example.com/search http://srch1.example.com/search @plugin=query_remap.so @pparam=q @pparam=srch1.example.com @pparam=srch2.example.com @pparam=srch3.example.com
map http://www.example.com/profiles http://prof1.example.com/profiles @plugin=query_remap.so @pparam=user_id @pparam=prof1.example.com @pparam=prof2.example.com
-The first ``@pparam`` specifies the query param key for which the value
+The first :code:`@pparam` specifies the query param key for which the value
will be hashed. The remaining parameters list the hostnames of the
servers. A request for ``http://www.example.com/search?q=apache`` will
match the first rule. The plugin will look for the *``q``* parameter and
@@ -54,36 +52,19 @@ decides not to modify the request, the default toURL
The parameters are passed to the plugin's ``tsremap_new_instance``
function. In ``query_remap``, ``tsremap_new_instance`` creates a
plugin-defined ``query_remap_info`` struct to store its configuration
-parameters. The ihandle, an opaque pointer that can be used to pass
-per-instance data, is set to this struct pointer and will be passed to
-the ``tsremap_remap`` function when it is triggered for a request.
-
-.. code-block:: c
-
- typedef struct _query_remap_info {
- char *param_name;
- size_t param_len;
- char **hosts;
- int num_hosts;
- } query_remap_info;
+parameters.
+.. literalinclude:: ../../../../../example/query_remap/query_remap.c
+ :language: c
+ :lines: 37-42
- int tsremap_new_instance(int argc,char *argv[],ihandle *ih,char *errbuf,int errbuf_size)
- {
- int i;
-
- if (argc param_name = strdup(argv[2]);
- qri->param_len = strlen(qri->param_name);
- qri->num_hosts = argc - 3;
- qri->hosts = (char**) TSmalloc(qri->num_hosts*sizeof(char*));
-
- for (i=0; i num_hosts; ++i) {
- qri->hosts[i] = strdup(argv[i+3]);
- }
+The :code:`ihandle`, an opaque pointer that can be used to pass
+per-instance data, is set to this struct pointer and will be passed to
+the :code:`TSRemapDoRemap` function when it is triggered for a request.
- *ih = (ihandle)qri;
- return 0;
- }
+.. literalinclude:: ../../../../../example/query_remap/query_remap.c
+ :language: c
+ :lines: 53-88
Another way remap plugins may want handle more complex configuration is
to specify a configuration filename as a ``pparam`` and parse the
@@ -98,55 +79,10 @@ to a remap rule configured for the plugin. The ``TSRemapRequestInfo``
struct contains input and output members for the remap operation.
``tsremap_remap`` uses the configuration information passed via the
-``ihandle`` and checks the ``request_query`` for the configured query
+:code:`ihandle` and checks the ``request_query`` for the configured query
parameter. If the parameter is found, the plugin sets a ``new_host`` to
modify the request host:
-.. code-block:: c
-
- int tsremap_remap(ihandle ih, rhandle rh, TSRemapRequestInfo *rri)
- {
- int hostidx = -1;
- query_remap_info *qri = (query_remap_info*)ih;
-
- if (!qri) {
- TSError("[remap] NULL ihandle");
- return 0;
- }
-
- if (rri && rri->request_query && rri->request_query_size > 0) {
- char *q, *s, *key;
-
- //make a copy of the query, as it is read only
- q = (char*) TSmalloc(rri->request_query_size+1);
- strncpy(q, rri->request_query, rri->request_query_size);
- q[rri->request_query_size] = '\0';
-
- s = q;
- //parse query parameters
- for (key = strsep(&s, "&"); key != NULL; key = strsep(&s, "&")) {
- 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;
- break;
- }
- }
-
- TSfree(q);
-
- if (hostidx >= 0) {
- rri->new_host_size = strlen(qri->hosts[hostidx]);
- if (rri->new_host_size new_host, qri->hosts[hostidx], rri->new_host_size);
- return 1; //host has been modified
- }
- }
- }
-
- //the request was not modified, TS will use the toURL from the remap rule
- return 0;
- }
-
+.. literalinclude:: ../../../../../example/query_remap/query_remap.c
+ :language: c
+ :lines: 112-166
diff --git a/doc/developer-guide/plugins/example-plugins/query-remap/index.en.rst b/doc/developer-guide/plugins/example-plugins/query_remap/index.en.rst
similarity index 88%
rename from doc/developer-guide/plugins/example-plugins/query-remap/index.en.rst
rename to doc/developer-guide/plugins/example-plugins/query_remap/index.en.rst
index 4c8a3e2..c2a31d6 100644
--- a/doc/developer-guide/plugins/example-plugins/query-remap/index.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/query_remap/index.en.rst
@@ -32,16 +32,15 @@ remap rules. It is not built on top of the Traffic Server APIs and
exists solely for the purpose of URL remapping. The remap plugin is not
global --it is configured on a per-remap rule basis, which enables you
to customize how URLs are redirected based on individual rules in the
-``remap.config`` file.
+:file:`remap.config` file.
The Traffic Server Remap API enables a plugin to dynamically map a
client request to a target URL. Each plugin is associated with one or
-more remap rules in ``remap.config`` (an "instance"). If a request URL
+more remap rules in :file:`remap.config` (an "instance"). If a request URL
matches a remap rule's "fromURL", then Traffic Server calls the
plugin-defined remap function for that request.
-((Editor's note: additional text TBD; text in this chapter is still
-under development))
+.. note:: Additional text TBD; text in this chapter is still under development
Remap Header File
=================
@@ -70,6 +69,4 @@ A remap plugin is required to implement the following functions:
Configuration
~~~~~~~~~~~~~
-To associate a remap plugin with a remap rule, use the ``@plugin``
-parameter. See the Admin Guide section (?TBD?) for details on
-configuring remap plugins
+To associate a remap plugin with a remap rule, use the :code:`@plugin` parameter (see :ref:`remap-config-plugin-chaining`).
diff --git a/example/Makefile.am b/example/Makefile.am
index ecf272f..6c85bc5 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -40,7 +40,7 @@ example_Plugins = \
protocol_stack.la \
protocol.la \
psi.la \
- query-remap.la \
+ query_remap.la \
remap.la \
remap_header_add.la \
replace-header.la \
@@ -105,7 +105,7 @@ passthru_la_SOURCES = passthru/passthru.cc
protocol_la_SOURCES = protocol/Protocol.c protocol/TxnSM.c
protocol_stack_la_SOURCES = protocol_stack/protocol_stack.cc
psi_la_SOURCES = thread-pool/psi.c thread-pool/thread.c
-query_remap_la_SOURCES = query-remap/query-remap.c
+query_remap_la_SOURCES = query_remap/query_remap.c
remap_header_add_la_SOURCES = remap_header_add/remap_header_add.cc
remap_la_SOURCES = remap/remap.cc
replace_header_la_SOURCES = replace-header/replace-header.c
diff --git a/example/query-remap/query-remap.c b/example/query_remap/query_remap.c
similarity index 97%
rename from example/query-remap/query-remap.c
rename to example/query_remap/query_remap.c
index 2c4796d..558f4fd 100644
--- a/example/query-remap/query-remap.c
+++ b/example/query_remap/query_remap.c
@@ -57,7 +57,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf ATS_UNUSED, i
TSDebug(PLUGIN_NAME, "new instance fromURL: %s toURL: %s", argv[0], argv[1]);
if (argc < 4) {
- TSError("[query_remap] Missing parameters");
+ TSError("[%s] Missing parameters", PLUGIN_NAME);
return -1;
}
@@ -116,7 +116,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh ATS_UNUSED, TSRemapRequestInfo *rri)
query_remap_info *qri = (query_remap_info *)ih;
if (!qri || !rri) {
- TSError("[query_remap] NULL private data or RRI");
+ TSError("[%s] NULL private data or RRI", PLUGIN_NAME);
return TSREMAP_NO_REMAP;
}
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].