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/10 13:20:17 UTC

[trafficserver] branch master updated: TS-4976: Regularize example plugins - blacklist

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  09ebcfc   TS-4976: Regularize example plugins - blacklist
09ebcfc is described below

commit 09ebcfc7bea7ebde594be676763b1bf24e6737db
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Mar 8 08:13:31 2017 -0600

    TS-4976: Regularize example plugins - blacklist
---
 .../plugins/example-plugins/blacklist/index.en.rst |  4 +--
 .../blacklist/setting-a-global-hook.en.rst         |  2 +-
 .../example-plugins/blacklist/source-code.en.rst   |  6 ++--
 .../plugins/example-plugins/index.en.rst           |  2 +-
 .../plugins/getting-started/index.en.rst           |  2 +-
 .../trafficserver-http-header-system.en.rst        |  2 +-
 doc/developer-guide/plugins/introduction.en.rst    |  2 +-
 .../plugins/plugin-management/logging-api.en.rst   |  4 +--
 example/Makefile.am                                |  8 ++---
 .../blacklist-0.c => blacklist_0/blacklist_0.c}    | 24 ++++++++-------
 example/{blacklist-1 => blacklist_1}/blacklist.txt |  0
 .../blacklist-1.c => blacklist_1/blacklist_1.c}    | 34 ++++++++++++----------
 example/{blacklist-1 => blacklist_1}/readme.txt    |  2 +-
 13 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/doc/developer-guide/plugins/example-plugins/blacklist/index.en.rst b/doc/developer-guide/plugins/example-plugins/blacklist/index.en.rst
index 65c02c7..b88c3f2 100644
--- a/doc/developer-guide/plugins/example-plugins/blacklist/index.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/blacklist/index.en.rst
@@ -23,7 +23,7 @@ Blacklist Plugin
 ****************
 
 The sample blacklisting plugin included in the Traffic Server SDK is
-``blacklist-1.c``. This plugin checks every incoming HTTP client request
+``blacklist_1.c``. This plugin checks every incoming HTTP client request
 against a list of blacklisted web sites. If the client requests a
 blacklisted site, then the plugin returns an ``Access forbidden``
 message to the client.
@@ -52,7 +52,7 @@ Traffic Server has a multi-threaded design, race conditions can occur if
 several threads try to access the same continuation's data.
 
 Here is how the static parent continuation is created in
-``blacklist-1.c``:
+``blacklist_1.c``:
 
 .. code-block:: c
 
diff --git a/doc/developer-guide/plugins/example-plugins/blacklist/setting-a-global-hook.en.rst b/doc/developer-guide/plugins/example-plugins/blacklist/setting-a-global-hook.en.rst
index 65bc059..e471b1c 100644
--- a/doc/developer-guide/plugins/example-plugins/blacklist/setting-a-global-hook.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/blacklist/setting-a-global-hook.en.rst
@@ -23,7 +23,7 @@ Setting a Global Hook
 Global hooks are always added in ``TSPluginInit`` using
 ``TSHttpHookAdd``. The two arguments of ``TSHttpHookAdd`` are the hook
 ID and the continuation to call when processing the event corresponding
-to the hook. In ``blacklist-1.c``, the global hook is added as follows:
+to the hook. In ``blacklist_1.c``, the global hook is added as follows:
 
 .. code-block:: c
 
diff --git a/doc/developer-guide/plugins/example-plugins/blacklist/source-code.en.rst b/doc/developer-guide/plugins/example-plugins/blacklist/source-code.en.rst
index af952a0..6e634a3 100644
--- a/doc/developer-guide/plugins/example-plugins/blacklist/source-code.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/blacklist/source-code.en.rst
@@ -24,11 +24,11 @@ Sample Source Code
 
 .. _blacklist-1.c:
 
-blacklist-1.c
+blacklist_1.c
 -------------
 
 The sample blacklisting plugin included in the Traffic Server SDK is
-``blacklist-1.c``. This plugin checks every incoming HTTP client request
+``blacklist_1.c``. This plugin checks every incoming HTTP client request
 against a list of blacklisted web sites. If the client requests a
 blacklisted site, then the plugin returns an ``Access forbidden``
 message to the client.
@@ -43,5 +43,5 @@ This plugin illustrates:
 
 -  How to use the plugin configuration management interface
 
-.. literalinclude:: ../../../../../example/blacklist-1/blacklist-1.c
+.. literalinclude:: ../../../../../example/blacklist_1/blacklist_1.c
    :language: c
diff --git a/doc/developer-guide/plugins/example-plugins/index.en.rst b/doc/developer-guide/plugins/example-plugins/index.en.rst
index 5a573a5..d805eb6 100644
--- a/doc/developer-guide/plugins/example-plugins/index.en.rst
+++ b/doc/developer-guide/plugins/example-plugins/index.en.rst
@@ -46,7 +46,7 @@ understand the following topics:
 
 -  Working with HTTP header functions
 
-The two sample plugins discussed in this chapter are ``blacklist-1.c``
+The two sample plugins discussed in this chapter are ``blacklist_1.c``
 and ``basic_auth.c``.
 
 Overview
diff --git a/doc/developer-guide/plugins/getting-started/index.en.rst b/doc/developer-guide/plugins/getting-started/index.en.rst
index 2a52ae4..b4a482f 100644
--- a/doc/developer-guide/plugins/getting-started/index.en.rst
+++ b/doc/developer-guide/plugins/getting-started/index.en.rst
@@ -151,7 +151,7 @@ You can find basic examples for many plugins in the SDK sample code:
 
 -  ``basic_auth.c`` performs basic HTTP proxy authorization.
 
--  ``blacklist-1.c`` reads blacklisted servers from a configuration file
+-  ``blacklist_1.c`` reads blacklisted servers from a configuration file
    and denies client access to these servers. This plugin is explained
    in :ref:`developer-plugins-examples-blacklist`.
 
diff --git a/doc/developer-guide/plugins/http-headers/trafficserver-http-header-system.en.rst b/doc/developer-guide/plugins/http-headers/trafficserver-http-header-system.en.rst
index fa84861..6af66bc 100644
--- a/doc/developer-guide/plugins/http-headers/trafficserver-http-header-system.en.rst
+++ b/doc/developer-guide/plugins/http-headers/trafficserver-http-header-system.en.rst
@@ -42,7 +42,7 @@ passed into the common ``str*()`` routines
    Values returned from a marshall buffer can be ``NULL``, which means the
    field or object requested does not exist.
 
-For example (from the ``blacklist-1`` sample)
+For example (from the ``blacklist_1`` sample)
 
 .. code-block:: c
 
diff --git a/doc/developer-guide/plugins/introduction.en.rst b/doc/developer-guide/plugins/introduction.en.rst
index 3b0d620..d051b68 100644
--- a/doc/developer-guide/plugins/introduction.en.rst
+++ b/doc/developer-guide/plugins/introduction.en.rst
@@ -173,7 +173,7 @@ them into activity.
 
 A plugin may consist of just one static continuation that is called
 whenever certain events happen. Examples of such plugins include
-``blacklist-1.c``, ``basic_auth.c``, and ``redirect-1.c``.
+``blacklist_1.c``, ``basic_auth.c``, and ``redirect-1.c``.
 Alternatively, a plugin might dynamically create other continuations as
 needed. Transform plugins are built in this manner: a static parent
 continuation checks all transactions to see if any are transformable;
diff --git a/doc/developer-guide/plugins/plugin-management/logging-api.en.rst b/doc/developer-guide/plugins/plugin-management/logging-api.en.rst
index 16867e0..0ce902b 100644
--- a/doc/developer-guide/plugins/plugin-management/logging-api.en.rst
+++ b/doc/developer-guide/plugins/plugin-management/logging-api.en.rst
@@ -58,7 +58,7 @@ The logging API enables you to:
    :c:func:`TSTextLogObjectDestroy`
 
 The steps below show how the logging API is used in the
-``blacklist-1.c`` sample plugin. For the complete source code, see the
+``blacklist_1.c`` sample plugin. For the complete source code, see the
 :ref:`developer-plugins-examples-blacklist-code` section.
 
 #. A new log file is defined as a global variable.
@@ -117,7 +117,7 @@ The steps below show how the logging API is used in the
        blacklisting site: sites[i]
 
    The log is not flushed or
-   destroyed in the ``blacklist-1`` plugin - it lives for the life of
+   destroyed in the ``blacklist_1`` plugin - it lives for the life of
    the plugin.
 
 
diff --git a/example/Makefile.am b/example/Makefile.am
index c26a9f9..db9eca0 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -26,8 +26,8 @@ example_Plugins = \
 	add_header.la \
 	append_transform.la \
 	basic_auth.la \
-	blacklist-0.la \
-	blacklist-1.la \
+	blacklist_0.la \
+	blacklist_1.la \
 	bnull-transform.la \
 	cache-scan.la \
 	file-1.la \
@@ -90,8 +90,8 @@ endif
 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
+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
diff --git a/example/blacklist-0/blacklist-0.c b/example/blacklist_0/blacklist_0.c
similarity index 85%
rename from example/blacklist-0/blacklist-0.c
rename to example/blacklist_0/blacklist_0.c
index d61cc83..432bdfd 100644
--- a/example/blacklist-0/blacklist-0.c
+++ b/example/blacklist_0/blacklist_0.c
@@ -22,7 +22,7 @@
  */
 
 /*
- *   blacklist-0.c:
+ *   blacklist_0.c:
  *	original version of blacklist-1, now used for internal testing
  *
  *
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <ts/ts.h>
 
+#define PLUGIN_NAME "blacklist_0"
+
 static char **sites;
 static int nsites;
 
@@ -48,19 +50,19 @@ handle_dns(TSHttpTxn txnp, TSCont contp)
   int host_length;
 
   if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-0] Couldn't retrieve client request header");
+    TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
     goto done;
   }
 
   if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
-    TSError("[blacklist-0] Couldn't retrieve request url");
+    TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
 
   host = TSUrlHostGet(bufp, url_loc, &host_length);
   if (!host) {
-    TSError("[blacklist-0] Couldn't retrieve request hostname");
+    TSError("[%s] Couldn't retrieve request hostname", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, hdr_loc, url_loc);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
@@ -93,7 +95,7 @@ handle_response(TSHttpTxn txnp)
   int url_length;
 
   if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-0] Couldn't retrieve client response header");
+    TSError("[%s] Couldn't retrieve client response header", PLUGIN_NAME);
     goto done;
   }
 
@@ -102,13 +104,13 @@ handle_response(TSHttpTxn txnp)
                      strlen(TSHttpHdrReasonLookup(TS_HTTP_STATUS_FORBIDDEN)));
 
   if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-0] Couldn't retrieve client request header");
+    TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
 
   if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
-    TSError("[blacklist-0] Couldn't retrieve request url");
+    TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
@@ -151,12 +153,12 @@ TSPluginInit(int argc, const char *argv[])
   int i;
   TSPluginRegistrationInfo info;
 
-  info.plugin_name   = "blacklist-0";
-  info.vendor_name   = "MyCompany";
-  info.support_email = "ts-api-support@MyCompany.com";
+  info.plugin_name   = PLUGIN_NAME;
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
 
   if (TSPluginRegister(&info) != TS_SUCCESS) {
-    TSError("[blacklist-0] Plugin registration failed.");
+    TSError("[%s] Plugin registration failed.", PLUGIN_NAME);
   }
 
   nsites = argc - 1;
diff --git a/example/blacklist-1/blacklist.txt b/example/blacklist_1/blacklist.txt
similarity index 100%
rename from example/blacklist-1/blacklist.txt
rename to example/blacklist_1/blacklist.txt
diff --git a/example/blacklist-1/blacklist-1.c b/example/blacklist_1/blacklist_1.c
similarity index 88%
rename from example/blacklist-1/blacklist-1.c
rename to example/blacklist_1/blacklist_1.c
index 5668721..a664173 100644
--- a/example/blacklist-1/blacklist-1.c
+++ b/example/blacklist_1/blacklist_1.c
@@ -27,6 +27,8 @@
 #include "ts/ts.h"
 #include "ts/ink_defs.h"
 
+#define PLUGIN_NAME "blacklist_1"
+
 #define MAX_NSITES 500
 #define RETRY_TIME 10
 
@@ -74,19 +76,19 @@ handle_dns(TSHttpTxn txnp, TSCont contp)
   int host_length;
 
   if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-1] Couldn't retrieve client request header");
+    TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
     goto done;
   }
 
   if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
-    TSError("[blacklist-1] Couldn't retrieve request url");
+    TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
 
   host = TSUrlHostGet(bufp, url_loc, &host_length);
   if (!host) {
-    TSError("[blacklist-1] Couldn't retrieve request hostname");
+    TSError("[%s] Couldn't retrieve request hostname", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, hdr_loc, url_loc);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
@@ -95,7 +97,7 @@ handle_dns(TSHttpTxn txnp, TSCont contp)
   /* We need to lock the sites_mutex as that is the mutex that is
      protecting the global list of all blacklisted sites. */
   if (TSMutexLockTry(sites_mutex) != TS_SUCCESS) {
-    TSDebug("blacklist-1", "Unable to get lock. Will retry after some time");
+    TSDebug(PLUGIN_NAME, "Unable to get lock. Will retry after some time");
     TSHandleMLocRelease(bufp, hdr_loc, url_loc);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     TSContSchedule(contp, RETRY_TIME, TS_THREAD_POOL_DEFAULT);
@@ -107,7 +109,7 @@ handle_dns(TSHttpTxn txnp, TSCont contp)
       if (log) {
         TSTextLogObjectWrite(log, "blacklisting site: %s", sites[i]);
       } else {
-        TSDebug("blacklist-1", "blacklisting site: %s", sites[i]);
+        TSDebug(PLUGIN_NAME, "blacklisting site: %s", sites[i]);
       }
       TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_RESPONSE_HDR_HOOK, contp);
       TSHandleMLocRelease(bufp, hdr_loc, url_loc);
@@ -137,7 +139,7 @@ handle_response(TSHttpTxn txnp, TSCont contp ATS_UNUSED)
   int url_length;
 
   if (TSHttpTxnClientRespGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-1] Couldn't retrieve client response header");
+    TSError("[%s] Couldn't retrieve client response header", PLUGIN_NAME);
     goto done;
   }
 
@@ -146,13 +148,13 @@ handle_response(TSHttpTxn txnp, TSCont contp ATS_UNUSED)
                      strlen(TSHttpHdrReasonLookup(TS_HTTP_STATUS_FORBIDDEN)));
 
   if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
-    TSError("[blacklist-1] Couldn't retrieve client request header");
+    TSError("[%s] Couldn't retrieve client request header", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
 
   if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
-    TSError("[blacklist-1] Couldn't retrieve request url");
+    TSError("[%s] Couldn't retrieve request url", PLUGIN_NAME);
     TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
     goto done;
   }
@@ -213,8 +215,8 @@ read_blacklist(TSCont contp)
 
     TSfclose(file);
   } else {
-    TSError("[blacklist-1] Unable to open %s", blacklist_file);
-    TSError("[blacklist-1] All sites will be allowed");
+    TSError("[%s] Unable to open %s", PLUGIN_NAME, blacklist_file);
+    TSError("[%s] All sites will be allowed", PLUGIN_NAME);
   }
 
   TSMutexUnlock(sites_mutex);
@@ -270,7 +272,7 @@ blacklist_plugin(TSCont contp, TSEvent event, void *edata)
         handle_response(cd->txnp, contp);
         return 0;
       default:
-        TSDebug("blacklist_plugin", "This event was unexpected: %d", event);
+        TSDebug(PLUGIN_NAME, "This event was unexpected: %d", event);
         break;
       }
     } else {
@@ -309,18 +311,18 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED)
   TSPluginRegistrationInfo info;
   TSReturnCode error;
 
-  info.plugin_name   = "blacklist-1";
-  info.vendor_name   = "MyCompany";
-  info.support_email = "ts-api-support@MyCompany.com";
+  info.plugin_name   = PLUGIN_NAME;
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
 
   if (TSPluginRegister(&info) != TS_SUCCESS) {
-    TSError("[blacklist-1] Plugin registration failed.");
+    TSError("[%s] Plugin registration failed.", PLUGIN_NAME);
   }
 
   /* create an TSTextLogObject to log blacklisted requests to */
   error = TSTextLogObjectCreate("blacklist", TS_LOG_MODE_ADD_TIMESTAMP, &log);
   if (!log || error == TS_ERROR) {
-    TSDebug("blacklist-1", "error while creating log");
+    TSDebug(PLUGIN_NAME, "error while creating log");
   }
 
   sites_mutex = TSMutexCreate();
diff --git a/example/blacklist-1/readme.txt b/example/blacklist_1/readme.txt
similarity index 89%
rename from example/blacklist-1/readme.txt
rename to example/blacklist_1/readme.txt
index b8241c5..0e7cf27 100644
--- a/example/blacklist-1/readme.txt
+++ b/example/blacklist_1/readme.txt
@@ -2,7 +2,7 @@ How to run the blacklist plugin
 ===============================
 
 1. Modify blacklist.cgi to specify the location of perl and traffic server.
-2. Copy blacklist.cgi, blacklist-1.so, PoweredByInktomi.gif to the directory
+2. Copy blacklist.cgi, blacklist_1.so, PoweredByInktomi.gif to the directory
    specified by the variable proxy.config.plugin.plugin_dir.
 3. Modify plugin.config to load the blacklist plugin.
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].