Repository: trafficserver Updated Branches: refs/heads/master e776c5fc2 -> 91e121ac7
TS-4035: simple plugin code documentation is wrong Remove in-line example code in favor of including plugin example code that builds. Fix API links. Update the plugin code to not use Traffic Server internal headers. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/91e121ac Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/91e121ac Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/91e121ac Branch: refs/heads/master Commit: 91e121ac74f1c7adc524f7d10cab23fa9d741d92 Parents: e776c5f Author: James Peach <[email protected]> Authored: Sun Nov 22 17:37:23 2015 -0800 Committer: James Peach <[email protected]> Committed: Sun Nov 22 17:37:23 2015 -0800 ---------------------------------------------------------------------- ...gin-registration-and-version-checking.en.rst | 69 +++----------------- example/version/version.c | 12 ++-- 2 files changed, 15 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/91e121ac/doc/developer-guide/plugins/getting-started/plugin-registration-and-version-checking.en.rst ---------------------------------------------------------------------- diff --git a/doc/developer-guide/plugins/getting-started/plugin-registration-and-version-checking.en.rst b/doc/developer-guide/plugins/getting-started/plugin-registration-and-version-checking.en.rst index dd4c287..6cbe5c8 100644 --- a/doc/developer-guide/plugins/getting-started/plugin-registration-and-version-checking.en.rst +++ b/doc/developer-guide/plugins/getting-started/plugin-registration-and-version-checking.en.rst @@ -22,68 +22,19 @@ Plugin Registration and Version Checking **************************************** -Make sure that the functions in your plugin are supported in your -version of Traffic Server. +If you need you make a plugin that will load against multiple +versions of Traffic Server, you can check the API version at both +compilation time and run time. Use the following interfaces: -- `TSPluginRegister <http://people.apache.org/~amc/ats/doc/html/ts_8h.html#a6d7f514e70abaf097c4a3f1ba01f6df8>`_ -- `TSTrafficServerVersionGet <http://people.apache.org/~amc/ats/doc/html/InkAPI_8cc.html#a3ef91e01612ffdce6dd040f836db08e8>`_ +- :c:func:`TSPluginRegister` +- :c:func:`TSTrafficServerVersionGet` -The following version of ``hello-world`` registers the plugin and -ensures it's running with a compatible version of Traffic Server. +The plugin registers the plugin and ensures it's running with a +compatible version of Traffic Server. -.. code-block:: c - - #include <stdio.h> - #include <ts/ts.h> - int - check_ts_version() - { - - 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; - } - - /* We need at least Traffic Server 2.0 */ - - if (major_ts_version >= 2) { - result = 1; - } - - } - - return result; - } - - void - TSPluginInit (int argc, const char *argv[]) - { - - TSPluginRegistrationInfo info; - - info.plugin_name = "hello-world"; - info.vendor_name = "MyCompany"; - info.support_email = "[email protected]"; - - if (!TSPluginRegister(&info)) { - TSError ("[plugin_name] Plugin registration failed."); - } - - if (!check_ts_version()) { - TSError ("[plugin_name] Plugin requires Traffic Server 2.0 or later"); - return; - } - - TSDebug ("debug-hello", "Hello World!\n"); - } +.. literalinclude:: ../../../../example/version/version.c + :language: c + :lines: 23- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/91e121ac/example/version/version.c ---------------------------------------------------------------------- diff --git a/example/version/version.c b/example/version/version.c index f5c8126..19e447d 100644 --- a/example/version/version.c +++ b/example/version/version.c @@ -22,18 +22,16 @@ */ #include <stdio.h> - -#include "ts/ts.h" -#include "ts/ink_defs.h" +#include <ts/ts.h> void -TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED) +TSPluginInit(int argc, const char *argv[]) { - TSPluginRegistrationInfo info; + (void)argc; // unused + (void)argv; // unused // Get the version: const char *ts_version = TSTrafficServerVersionGet(); - if (!ts_version) { TSError("[version] Can't get Traffic Server verion.\n"); return; @@ -49,11 +47,11 @@ TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED) return; } + TSPluginRegistrationInfo info; info.plugin_name = "version-plugin"; info.vendor_name = "MyCompany"; info.support_email = "[email protected]"; - // partial compilation #if (TS_VERSION_NUMBER < 3000000) if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS) {
