trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: TS-4976: Regularize plugins - session_hooks (nee session-1).
Date Wed, 16 Aug 2017 15:55:23 GMT
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 90d8eee  TS-4976: Regularize plugins - session_hooks (nee session-1).
90d8eee is described below

commit 90d8eeeef22ceaa3e319aba3a85741451a751ea4
Author: Alan M. Carroll <amc@apache.org>
AuthorDate: Sat Aug 5 13:47:08 2017 -0500

    TS-4976: Regularize plugins - session_hooks (nee session-1).
---
 example/Makefile.am                                |  6 +--
 .../session-1.c => session_hooks/session_hooks.c}  | 50 +++++++++-------------
 2 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/example/Makefile.am b/example/Makefile.am
index 29b4a0b..becc50b 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -50,6 +50,7 @@ example_Plugins = \
 	secure_link.la \
 	server_push.la \
 	server_transform.la \
+	session_hooks.la \
 	ssl-preaccept.la \
 	ssl-sni-whitelist.la \
 	ssl-sni.la \
@@ -127,10 +128,7 @@ thread_1_la_SOURCES = thread-1/thread-1.c
 txn_data_sink_la_SOURCES = txn-data-sink/txn-data-sink.c
 version_la_SOURCES = version/version.c
 redirect_1_la_SOURCES = redirect_1/redirect_1.c
-
-# The following examples do not build:
-#
-# session_1_la_SOURCES = session-1/session-1.c
+session_hooks_la_SOURCES = session_hooks/session_hooks.c
 
 cppapi_AsyncHttpFetchStreaming_la_SOURCES = cppapi/async_http_fetch_streaming/AsyncHttpFetchStreaming.cc
 cppapi_AsyncHttpFetch_la_SOURCES = cppapi/async_http_fetch/AsyncHttpFetch.cc
diff --git a/example/session-1/session-1.c b/example/session_hooks/session_hooks.c
similarity index 61%
rename from example/session-1/session-1.c
rename to example/session_hooks/session_hooks.c
index 0166aa2..bd62b98 100644
--- a/example/session-1/session-1.c
+++ b/example/session_hooks/session_hooks.c
@@ -1,6 +1,6 @@
 /** @file
 
-  A brief file description
+  An example plugin that demonstrates session hook usage.
 
   @section license License
 
@@ -21,40 +21,33 @@
   limitations under the License.
  */
 
-/* session-1.c: a plugin that illustrates how to use
- *                session hooks
- *
- *
- *  Usage: session-1.so
- *
- */
-
 #include <stdio.h>
 #include "ts/ts.h"
 #include "ts/ink_defs.h"
 
-static INKStat transaction_count;
-static INKStat session_count;
-static INKStat av_transaction;
+#define PLUGIN_NAME "session_hooks"
+
+static int transaction_count_stat;
+static int session_count_stat;
 
 static void
 txn_handler(TSHttpTxn txnp, TSCont contp)
 {
-  int64_t num_txns = 0;
+  TSMgmtInt num_txns = 0;
 
-  INKStatIncrement(transaction_count);
-  num_txns = INKStatIntGet(transaction_count);
-  TSDebug("tag_session", "The number of transactions is %" PRId64, num_txns);
+  TSStatIntIncrement(transaction_count_stat, 1);
+  num_txns = TSStatIntGet(transaction_count_stat);
+  TSDebug(PLUGIN_NAME, "The number of transactions is %" PRId64, num_txns);
 }
 
 static void
 handle_session(TSHttpSsn ssnp, TSCont contp)
 {
-  int64_t num_ssn = 0;
+  TSMgmtInt num_ssn = 0;
 
-  INKStatIncrement(session_count);
-  num_ssn = INKStatIntGet(session_count);
-  TSDebug("tag_session", "The number of sessions is %" PRId64, num_ssn);
+  TSStatIntIncrement(session_count_stat, 1);
+  num_ssn = TSStatIntGet(session_count_stat);
+  TSDebug(PLUGIN_NAME, "The number of sessions is %" PRId64, num_ssn);
   TSHttpSsnHookAdd(ssnp, TS_HTTP_TXN_START_HOOK, contp);
 }
 
@@ -79,7 +72,7 @@ ssn_handler(TSCont contp, TSEvent event, void *edata)
     return 0;
 
   default:
-    TSDebug("tag_session", "In the default case: event = %d", event);
+    TSDebug(PLUGIN_NAME, "In the default case: event = %d", event);
     break;
   }
   return 0;
@@ -91,23 +84,22 @@ TSPluginInit(int argc, const char *argv[])
   TSCont contp;
   TSPluginRegistrationInfo info;
 
-  info.plugin_name   = "session-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("[session-1] Plugin registration failed.\n");
+    TSError("[%s] Plugin registration failed.\n", PLUGIN_NAME);
 
     goto error;
   }
 
-  transaction_count = INKStatCreate("transaction.count", INKSTAT_TYPE_INT64);
-  session_count     = INKStatCreate("session.count", INKSTAT_TYPE_INT64);
-  av_transaction    = INKStatCreate("avg.transactions", INKSTAT_TYPE_FLOAT);
+  transaction_count_stat = TSStatCreate("transaction.count", TS_RECORDDATATYPE_INT, TS_STAT_NON_PERSISTENT,
TS_STAT_SYNC_SUM);
+  session_count_stat     = TSStatCreate("session.count", TS_RECORDDATATYPE_INT, TS_STAT_NON_PERSISTENT,
TS_STAT_SYNC_SUM);
 
   contp = TSContCreate(ssn_handler, NULL);
   TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, contp);
 
 error:
-  TSError("[session-1] Plugin not initialized");
+  TSError("[%s] Plugin not initialized", PLUGIN_NAME);
 }

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

Mime
View raw message