Plugin Registration and Version Checking

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:

The plugin registers the plugin and ensures it’s running with a compatible version of Traffic Server.


#include <stdio.h>
#include <ts/ts.h>

#define PLUGIN_NAME "version"

void
TSPluginInit(int argc, const char *argv[])
{
  (void)argc; // unused
  (void)argv; // unused

  // Get the version:
  const char *ts_version = TSTrafficServerVersionGet();
  if (!ts_version) {
    TSError("[%s] Can't get Traffic Server version.", PLUGIN_NAME);
    return;
  }

  // Split it in major, minor, patch:
  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) {
    TSError("[%s] Can't extract versions.", PLUGIN_NAME);
    return;
  }

  TSPluginRegistrationInfo info;
  info.plugin_name   = PLUGIN_NAME;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "dev@trafficserver.apache.org";

  // partial compilation
  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[%s] Plugin registration failed.", PLUGIN_NAME);
  }

  TSDebug(PLUGIN_NAME, "Running in Apache Traffic Server: v%d.%d.%d", major_ts_version, minor_ts_version, patch_ts_version);
}