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/18 19:21:19 UTC
[trafficserver] branch master updated: TS-4976: Regularize plugins
- lifecycle
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 b46c403 TS-4976: Regularize plugins - lifecycle
b46c403 is described below
commit b46c403c9594b05de301e817134e4334f6dcf0ad
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Fri Mar 17 18:18:37 2017 -0500
TS-4976: Regularize plugins - lifecycle
---
example/Makefile.am | 4 +-
.../lifecycle_plugin.c} | 59 +++++-----------------
.../readme.txt | 0
3 files changed, 16 insertions(+), 47 deletions(-)
diff --git a/example/Makefile.am b/example/Makefile.am
index 55727b1..6faa134 100644
--- a/example/Makefile.am
+++ b/example/Makefile.am
@@ -33,7 +33,7 @@ example_Plugins = \
file_1.la \
hello.la \
intercept.la \
- lifecycle-plugin.la \
+ lifecycle_plugin.la \
null_transform.la \
output-header.la \
passthru.la \
@@ -97,7 +97,7 @@ cache_scan_la_SOURCES = cache_scan/cache_scan.cc
file_1_la_SOURCES = file_1/file_1.c
hello_la_SOURCES = hello/hello.c
intercept_la_SOURCES = intercept/intercept.cc
-lifecycle_plugin_la_SOURCES = lifecycle-plugin/lifecycle-plugin.c
+lifecycle_plugin_la_SOURCES = lifecycle_plugin/lifecycle_plugin.c
null_transform_la_SOURCES = null_transform/null_transform.c
output_header_la_SOURCES = output-header/output-header.c
passthru_la_SOURCES = passthru/passthru.cc
diff --git a/example/lifecycle-plugin/lifecycle-plugin.c b/example/lifecycle_plugin/lifecycle_plugin.c
similarity index 56%
rename from example/lifecycle-plugin/lifecycle-plugin.c
rename to example/lifecycle_plugin/lifecycle_plugin.c
index cae259c..a84e213 100644
--- a/example/lifecycle-plugin/lifecycle-plugin.c
+++ b/example/lifecycle_plugin/lifecycle_plugin.c
@@ -21,7 +21,7 @@
limitations under the License.
*/
-/* lifecycle-plugin.c: an example plugin to demonstrate the lifecycle hooks.
+/* lifecycle_plugin.c: an example plugin to demonstrate the lifecycle hooks.
* of response body content
*/
@@ -30,78 +30,47 @@
#include <inttypes.h>
#include <ts/ts.h>
+#define PLUGIN_NAME "lifecycle"
+
int
CallbackHandler(TSCont this, TSEvent id, void *data)
{
(void)this; // make compiler shut up about unused variable.
switch (id) {
case TS_EVENT_LIFECYCLE_PORTS_INITIALIZED:
- TSDebug("lifecycle-plugin", "Proxy ports initialized");
+ TSDebug(PLUGIN_NAME, "Proxy ports initialized");
break;
case TS_EVENT_LIFECYCLE_PORTS_READY:
- TSDebug("lifecycle-plugin", "Proxy ports active");
+ TSDebug(PLUGIN_NAME, "Proxy ports active");
break;
case TS_EVENT_LIFECYCLE_CACHE_READY:
- TSDebug("lifecycle-plugin", "Cache ready");
+ TSDebug(PLUGIN_NAME, "Cache ready");
break;
case TS_EVENT_LIFECYCLE_MSG: {
TSPluginMsg *msg = (TSPluginMsg *)data;
- TSDebug("lifecycle-plugin", "Message to '%s' - %zu bytes of data", msg->tag, msg->data_size);
+ TSDebug(PLUGIN_NAME, "Message to '%s' - %zu bytes of data", msg->tag, msg->data_size);
break;
}
default:
- TSDebug("lifecycle-plugin", "Unexpected event %d", id);
+ TSDebug(PLUGIN_NAME, "Unexpected event %d", id);
break;
}
return TS_EVENT_NONE;
}
-int
-CheckVersion()
-{
- const char *ts_version = TSTrafficServerVersionGet();
- int result = 0;
-
- if (ts_version) {
- int major_ts_version = 0;
- int minor_ts_version = 0;
- int patch_ts_version = 0;
-
- if (sscanf(ts_version, "%d.%d.%d", &major_ts_version, &minor_ts_version, &patch_ts_version) != 3) {
- return 0;
- }
-
- /* Need at least TS 3.3.5 */
- if (major_ts_version > 3 ||
- (major_ts_version == 3 && (minor_ts_version > 3 || (minor_ts_version == 3 && patch_ts_version >= 5)))) {
- result = 1;
- }
- }
- return result;
-}
-
void
TSPluginInit(int argc, const char *argv[])
{
TSPluginRegistrationInfo info;
TSCont cb;
- (void)argc;
- (void)argv;
-
- info.plugin_name = "lifecycle-plugin";
- info.vendor_name = "My Company";
- 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("[lifecycle-plugin] Plugin registration failed.");
-
- goto Lerror;
- }
+ TSError("[%s] Plugin registration failed.", PLUGIN_NAME);
- if (!CheckVersion()) {
- TSError("[lifecycle-plugin] Plugin requires Traffic Server 3.3.5 "
- "or later");
goto Lerror;
}
@@ -112,10 +81,10 @@ TSPluginInit(int argc, const char *argv[])
TSLifecycleHookAdd(TS_LIFECYCLE_CACHE_READY_HOOK, cb);
TSLifecycleHookAdd(TS_LIFECYCLE_MSG_HOOK, cb);
- TSDebug("lifecycle-plugin", "online");
+ TSDebug(PLUGIN_NAME, "online");
return;
Lerror:
- TSError("[lifecycle-plugin] Unable to initialize plugin (disabled).");
+ TSError("[%s] Unable to initialize plugin (disabled).", PLUGIN_NAME);
}
diff --git a/example/lifecycle-plugin/readme.txt b/example/lifecycle_plugin/readme.txt
similarity index 100%
rename from example/lifecycle-plugin/readme.txt
rename to example/lifecycle_plugin/readme.txt
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].