Ejemplo n.º 1
0
void TSPluginInit(int argc, const char *argv[]) {
	TSPluginRegistrationInfo info;
	TSCont main_cont, config_cont;
	config_holder_t *config_holder;

	info.plugin_name = PLUGIN_TAG;
	info.vendor_name = "Comcast";
	info.support_email = "*****@*****.**";
	astatsLoad = time(NULL);

	if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS)
		TSError("Plugin registration failed. \n");

	if (!check_ts_version()) {
		TSError("Plugin requires Traffic Server 2.0 or later\n");
		return;
	}

	config_holder = new_config_holder(argc > 1 ? argv[1] : NULL);

	main_cont = TSContCreate(astats_origin, NULL);
	TSContDataSet(main_cont, (void *) config_holder);
	TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, main_cont);

	config_cont = TSContCreate(config_handler, TSMutexCreate());
	TSContDataSet(config_cont, (void *) config_holder);
	TSMgmtUpdateRegister(config_cont, PLUGIN_TAG);
	/* Create a continuation with a mutex as there is a shared global structure
       containing the headers to add */
	TSDebug(PLUGIN_TAG, "astats module registered, path: '%s'", config_holder->config->stats_path);
}
Ejemplo n.º 2
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  info.plugin_name = "null-transform";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[null-transform] Plugin registration failed.\n");
    goto Lerror;
  }

  if (!check_ts_version()) {
    TSError("[null-transform] Plugin requires Traffic Server 3.0 " "or later\n");
    goto Lerror;
  }

  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(transform_plugin, NULL));
  return;

Lerror:
  TSError("[null-tranform] Unable to initialize plugin (disabled).\n");
}
Ejemplo n.º 3
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSFile filep;
  char buf[4096];
  int i;
  TSPluginRegistrationInfo info;

  info.plugin_name = "file_plugin";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("Plugin registration failed.\n");
  }

  if (!check_ts_version()) {
    TSError("Plugin requires Traffic Server 3.0 or later\n");
    return;
  }

  for (i = 1; i < argc; i++) {
    filep = TSfopen(argv[i], "r");
    if (!filep) {
      continue;
    }

    while (TSfgets(filep, buf, 4096)) {
      TSDebug("debug-file", "%s", buf);
    }

    TSfclose(filep);
  }
}
Ejemplo n.º 4
0
void
TSPluginInit(int argc, const char *argv[])
{
  int i;
  TSPluginRegistrationInfo info;

  info.plugin_name = "blacklist-0";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[blacklist-0] Plugin registration failed.");
  }

  nsites = argc - 1;
  if (nsites > 0) {
    sites = (char **)TSmalloc(sizeof(char *) * nsites);

    for (i = 0; i < nsites; i++) {
      sites[i] = TSstrdup(argv[i + 1]);
    }

    TSHttpHookAdd(TS_HTTP_OS_DNS_HOOK, TSContCreate(blacklist_plugin, NULL));
  }
}
Ejemplo n.º 5
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSCont contp;
  TSPluginRegistrationInfo info;

  info.plugin_name = "session-1";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[session-1] Plugin registration failed.\n");

    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);

  contp = TSContCreate(ssn_handler, NULL);
  TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, contp);

error:
  TSError("[session-1] Plugin not initialized");
}
Ejemplo n.º 6
0
void
TSPluginInit(int argc, const char *argv[])
{
  const char prefix[] = "http://";
  int uri_len;
  TSPluginRegistrationInfo info;

  info.plugin_name = "redirect-1";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("Plugin registration failed.\n");
  }

  if (!check_ts_version()) {
    TSError("Plugin requires Traffic Server 3.0 or later\n");
    return;
  }

  if (argc == 3) {
    block_ip = TSstrdup(argv[1]);

    /*
     *   The Location header must contain an absolute URI:
     */

    url_redirect = TSstrdup(argv[2]);
    uri_len = strlen(prefix) + strlen(url_redirect) + 1;
    uri_redirect = TSmalloc(uri_len);
    TSstrlcpy(uri_redirect, prefix, uri_len);
    TSstrlcat(uri_redirect, url_redirect, uri_len);

  } else {
    TSError("Incorrect syntax in plugin.conf:  correct usage is" "redirect-1.so ip_deny url_redirect");
    return;
  }

  ip_deny = inet_addr(block_ip);

  TSDebug("redirect_init", "initializing stats...");
  init_stats();
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL));

  TSDebug("redirect_init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s",
           block_ip, url_redirect, uri_redirect);
  // ToDo: Should figure out how to print IPs which are IPv4 / v6.
  // TSDebug("redirect_init", "ip_deny is %ld\n", ip_deny);

  /*
   *  Demonstrate another tracing function.  This can be used to
   *  enable debug calculations and other work that should only
   *  be done in debug mode.
   */

  if (TSIsDebugTagSet("redirect_demo"))
    TSDebug("redirect_init", "The redirect_demo tag is set");
  else
    TSDebug("redirect_init", "The redirect_demo tag is not set");
}
Ejemplo n.º 7
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  TSCont cont;

  info.plugin_name = "server-transform";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("Plugin registration failed.\n");
  }

  if (!check_ts_version()) {
    TSError("Plugin requires Traffic Server 3.0 or later\n");
    return;
  }

  /* connect to the echo port on localhost */
  server_ip = (127 << 24) | (0 << 16) | (0 << 8) | (1);
  server_ip = htonl(server_ip);
  server_port = 7;

  cont = TSContCreate(transform_plugin, NULL);
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
}
Ejemplo n.º 8
0
void TSPluginInit(int argc, const char *argv[])
{
    TSPluginRegistrationInfo info;
    TSThread init_thread;
    TSCont cont;

    info.plugin_name = (char *)"ironbee";
    info.vendor_name = (char *)"Qualys, Inc";
    info.support_email = (char *)"*****@*****.**";

    if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
        TSError("[ironbee] Plugin registration failed.  IronBee disabled");
        return;
    }

    if (!check_ts_version()) {
        TSError("[ironbee] Plugin requires Traffic Server 3.0 or later.  IronBee disabled");
        return;
    }

    if (read_ibconf(&module_data, argc, argv) != IB_OK) {
        TSError("[ironbee] Bad Ironbee options.  IronBee disabled");
        return;
    }

    if (tsib_pre_init(&cont) != IB_OK) {
        TSError("[ironbee] Pre-config failed.  IronBee disabled");
        return;
    }

    /* Launch potentially-slow config in its own thread */
    init_thread = TSThreadCreate(ibinit, cont);
    assert(init_thread != NULL);
}
Ejemplo n.º 9
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  TSMutex mutex = TS_NULL_MUTEX;

  info.plugin_name = "buffered-null-transform";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[bnull-transform] Plugin registration failed.\n");
    goto Lerror;
  }

  if (!check_ts_version()) {
    TSError("[bnull-transform] Plugin requires Traffic Server 3.0" " or later\n");
    goto Lerror;
  }

  /* This is call we could use if we need to protect global data */
  /* TSReleaseAssert ((mutex = TSMutexCreate()) != TS_NULL_MUTEX); */

  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(transform_plugin, mutex));
  return;

Lerror:
  TSError("[bnull-transform] Plugin disabled\n");
}
Ejemplo n.º 10
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSFile filep;
  char buf[4096];
  int i;
  TSPluginRegistrationInfo info;

  info.plugin_name = "file_plugin";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[file-1] Plugin registration failed.");
  }

  for (i = 1; i < argc; i++) {
    filep = TSfopen(argv[i], "r");
    if (!filep) {
      continue;
    }

    while (TSfgets(filep, buf, 4096)) {
      TSDebug("debug-file", "%s", buf);
    }

    TSfclose(filep);
  }
}
Ejemplo n.º 11
0
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("[version] Can't get Traffic Server verion.\n");
    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("[version] Can't extract verions.\n");
    return;
  }

  TSPluginRegistrationInfo info;
  info.plugin_name   = "version-plugin";
  info.vendor_name   = "MyCompany";
  info.support_email = "*****@*****.**";

// partial compilation
#if (TS_VERSION_NUMBER < 3000000)
  if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS) {
#elif (TS_VERSION_NUMBER < 6000000)
  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
#else
  if (TSPluginRegister(&info) != TS_SUCCESS) {
#endif
    TSError("[version] Plugin registration failed. \n");
  }

  TSDebug("debug-version-plugin", "Running in Apache Traffic Server: v%d.%d.%d", major_ts_version, minor_ts_version,
          patch_ts_version);
}
Ejemplo n.º 12
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  char *end;
  int tmp;

  info.plugin_name = "output-header";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[protocol] Plugin registration failed.");

    goto error;
  }


  /* default value */
  accept_port = 4666;
  server_port = 4666;

  if (argc < 3) {
    TSDebug("protocol", "Usage: protocol.so accept_port server_port");
    printf("[protocol_plugin] Usage: protocol.so accept_port server_port\n");
    printf("[protocol_plugin] Wrong arguments. Using deafult ports.\n");
  } else {
    tmp = strtol(argv[1], &end, 10);
    if (*end == '\0') {
      accept_port = tmp;
      TSDebug("protocol", "using accept_port %d", accept_port);
      printf("[protocol_plugin] using accept_port %d\n", accept_port);
    } else {
      printf("[protocol_plugin] Wrong argument for accept_port.");
      printf("Using deafult port %d\n", accept_port);
    }

    tmp = strtol(argv[2], &end, 10);
    if (*end == '\0') {
      server_port = tmp;
      TSDebug("protocol", "using server_port %d", server_port);
      printf("[protocol_plugin] using server_port %d\n", server_port);
    } else {
      printf("[protocol_plugin] Wrong argument for server_port.");
      printf("Using deafult port %d\n", server_port);
    }
  }

  protocol_init(accept_port, server_port);

error:
  TSError("[protocol] Plugin not initialized");
}
Ejemplo n.º 13
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  info.plugin_name = "output-header";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[PluginInit] Plugin registration failed.\n");
    goto error;
  }

  if (!check_ts_version()) {
    TSError("[PluginInit] Plugin requires Traffic Server 3.0 or later\n");
    goto error;
  }


  /* default value */
  accept_port = 4666;
  server_port = 4666;

  if (argc < 3) {
    TSDebug("protocol", "Usage: protocol.so accept_port server_port");
    printf("[protocol_plugin] Usage: protocol.so accept_port server_port\n");
    printf("[protocol_plugin] Wrong arguments. Using deafult ports.\n");
  } else {
    if (!isnan(atoi(argv[1]))) {
      accept_port = atoi(argv[1]);
      TSDebug("protocol", "using accept_port %d", accept_port);
      printf("[protocol_plugin] using accept_port %d\n", accept_port);
    } else {
      printf("[protocol_plugin] Wrong argument for accept_port.");
      printf("Using deafult port %d\n", accept_port);
    }

    if (!isnan(atoi(argv[2]))) {
      server_port = atoi(argv[2]);
      TSDebug("protocol", "using server_port %d", server_port);
      printf("[protocol_plugin] using server_port %d\n", server_port);
    } else {
      printf("[protocol_plugin] Wrong argument for server_port.");
      printf("Using deafult port %d\n", server_port);
    }
  }

  protocol_init(accept_port, server_port);

error:
  TSError("[PluginInit] Plugin not initialized");
}
Ejemplo n.º 14
0
void
TSPluginInit(int argc, const char *argv[])
{
  const char prefix[] = "http://";
  int uri_len;
  TSPluginRegistrationInfo info;

  info.plugin_name   = PLUGIN_NAME;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

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

  if (argc == 3) {
    block_ip = TSstrdup(argv[1]);

    /*
     *   The Location header must contain an absolute URI:
     */

    url_redirect = TSstrdup(argv[2]);
    uri_len      = strlen(prefix) + strlen(url_redirect) + 1;
    uri_redirect = TSmalloc(uri_len);
    TSstrlcpy(uri_redirect, prefix, uri_len);
    TSstrlcat(uri_redirect, url_redirect, uri_len);

  } else {
    TSError("[%s] Incorrect syntax in plugin.conf:  correct usage is", PLUGIN_NAME "redirect_1.so ip_deny url_redirect");
    return;
  }

  ip_deny = inet_addr(block_ip);

  TSDebug(PLUGIN_NAME, "initializing stats");
  init_stats();
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(redirect_plugin, NULL));

  TSDebug(PLUGIN_NAME ".init", "block_ip is %s, url_redirect is %s, and uri_redirect is %s", block_ip, url_redirect, uri_redirect);

  /*
   *  Demonstrate another tracing function.  This can be used to
   *  enable debug calculations and other work that should only
   *  be done in debug mode.
   */

  if (TSIsDebugTagSet(PLUGIN_NAME ".demo")) {
    TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is set");
  } else {
    TSDebug(PLUGIN_NAME ".init", "The redirect_demo tag is not set");
  }
}
Ejemplo n.º 15
0
/* Initialize the plugin / global continuation hook */
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  const char *proof = "acme";

  static const struct option longopt[] = {
    {(char *)"proof-directory", optional_argument, NULL, 'p'},
    {NULL, no_argument, NULL, '\0'},
  };

  memset(&gConfig, 0, sizeof(gConfig));
  while (true) {
    int opt = getopt_long(argc, (char *const *)argv, "", longopt, NULL);

    switch (opt) {
    case 'p':
      proof = optarg;
      break;
    }

    if (opt == -1) {
      break;
    }
  }

  if ('/' != *proof) {
    const char *confdir = TSConfigDirGet();
    int len             = strlen(proof) + strlen(confdir) + 8;

    gConfig.proof = TSmalloc(len);
    snprintf(gConfig.proof, len, "%s/%s", confdir, proof);
    TSDebug(PLUGIN_NAME, "base directory for proof-types is %s", gConfig.proof);
  } else {
    gConfig.proof = TSstrdup(proof);
  }

  info.plugin_name   = "acme";
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

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

  TSDebug(PLUGIN_NAME, "Started the %s plugin", PLUGIN_NAME);
  TSDebug(PLUGIN_NAME, "\tproof-type dir = %s", gConfig.proof);

  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(acme_hook, NULL));
}
Ejemplo n.º 16
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  char *end;
  int tmp;

  info.plugin_name   = PLUGIN_NAME;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

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

    goto error;
  }

  /* default value */
  accept_port = 4666;
  server_port = 4666;

  if (argc < 3) {
    TSDebug(PLUGIN_NAME, "Usage: protocol.so <accept_port> <server_port>. Using default ports accept=%d server=%d", accept_port,
            server_port);
  } else {
    tmp = strtol(argv[1], &end, 10);
    if (*end == '\0') {
      accept_port = tmp;
      TSDebug(PLUGIN_NAME, "using accept_port %d", accept_port);
    } else {
      TSError("[%s] Wrong argument for accept_port, using default port %d", PLUGIN_NAME, accept_port);
    }

    tmp = strtol(argv[2], &end, 10);
    if (*end == '\0') {
      server_port = tmp;
      TSDebug(PLUGIN_NAME, "using server_port %d", server_port);
    } else {
      TSError("[%s] Wrong argument for server_port, using default port %d", PLUGIN_NAME, server_port);
    }
  }

  protocol_init(accept_port, server_port);

error:
  TSError("[%s] Plugin not initialized", PLUGIN_NAME);
}
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  static const char usage[]             = PLUGIN_NAME ".so [--integer-counters] [PATH]";
  static const struct option longopts[] = {{(char *)("integer-counters"), no_argument, NULL, 'i'},
                                           {(char *)("wrap-counters"), no_argument, NULL, 'w'},
                                           {NULL, 0, NULL, 0}};

  info.plugin_name   = PLUGIN_NAME;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

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

  for (;;) {
    switch (getopt_long(argc, (char *const *)argv, "iw", longopts, NULL)) {
    case 'i':
      integer_counters = true;
      break;
    case 'w':
      wrap_counters = true;
      break;
    case -1:
      goto init;
    default:
      TSError("[%s] usage: %s", PLUGIN_NAME, usage);
    }
  }

init:
  argc -= optind;
  argv += optind;

  if (argc > 0) {
    url_path = TSstrdup(argv[0] + ('/' == argv[0][0] ? 1 : 0)); /* Skip leading / */
  }
  url_path_len = strlen(url_path);

  /* Create a continuation with a mutex as there is a shared global structure
     containing the headers to add */
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(stats_origin, NULL));
  TSDebug(PLUGIN_NAME, "stats module registered");
}
Ejemplo n.º 18
0
/*-------------------------------------------------------------------------
  TSPluginInit
  Function called at plugin init time

  Input:
    argc  number of args
    argv  list vof args
  Output :
  Return Value:
  -------------------------------------------------------------------------*/
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  int i;
  TSReturnCode retval;

  info.plugin_name = "psi";
  info.vendor_name = "Apache";
  info.support_email = "";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("Plugin registration failed.\n");
  }

  if (!check_ts_version()) {
    TSError("Plugin requires Traffic Server 3.0 or later\n");
    return;
  }

  /* Initialize the psi directory = <plugin_path>/include */
  sprintf(psi_directory, "%s/%s", TSPluginDirGet(), PSI_PATH);

  /* create an TSTextLogObject to log any psi include */
  retval = TSTextLogObjectCreate("psi", TS_LOG_MODE_ADD_TIMESTAMP, &log);
  if (retval == TS_ERROR) {
    TSError("Failed creating log for psi plugin");
    log = NULL;
  }

  /* Create working threads */
  thread_init();
  init_queue(&job_queue);

  for (i = 0; i < NB_THREADS; i++) {
    char *thread_name = (char *) TSmalloc(64);
    sprintf(thread_name, "Thread[%d]", i);
    if (!TSThreadCreate((TSThreadFunc) thread_loop, thread_name)) {
      TSError("[TSPluginInit] Error while creating threads");
      return;
    }
  }

  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(read_response_handler, TSMutexCreate()));
  TSDebug(DBG_TAG, "Plugin started");
}
Ejemplo n.º 19
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  info.plugin_name   = PLUGIN_NAME;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError(PCP "Plugin registration failed.\n");
    return;
  }

  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(main_hook, NULL));
  return;
}
/* Initialize the plugin / global continuation hook */
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  if (2 != argc) {
    TSError("Must specify a configuration file.\n");
    return;
  }

  info.plugin_name = "health_checks";
  info.vendor_name = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

  if (TS_SUCCESS != TSPluginRegister(TS_SDK_VERSION_3_0, &info)) {
    TSError("Plugin registration failed. \n");
    return;
  }

  if (!check_ts_version()) {
    TSError("Plugin requires Traffic Server 3.0 or later\n");
    return;
  }

  /* This will update the global configuration file, and is not reloaded at run time */
  /* ToDo: Support reloading with traffic_line -x  ? */
  if (NULL == (g_config = parse_configs(argv[1]))) {
    TSError("Unable to read / parse %s config file", argv[1]);
    return;
  }

  /* Setup the background thread */
  if (!TSThreadCreate(hc_thread, NULL)) {
    TSError("Failure in thread creation");
    return;
  }

  /* Create a continuation with a mutex as there is a shared global structure
     containing the headers to add */
  TSDebug(PLUGIN_NAME, "Started %s plugin", PLUGIN_NAME);
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(health_check_origin, NULL));
}
Ejemplo n.º 21
0
void TSPluginInit(int argc, const char *argv[])
{
  int rv;
  TSPluginRegistrationInfo info;
  TSCont cont;

  /* FIXME - check why these are char*, not const char* */
  info.plugin_name = (char *)"ironbee";
  info.vendor_name = (char *)"Qualys, Inc";
  info.support_email = (char *)"*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[ironbee] Plugin registration failed.\n");
    goto Lerror;
  }

  if (!check_ts_version()) {
    TSError("[ironbee] Plugin requires Traffic Server 3.0 or later\n");
    goto Lerror;
  }

  cont = TSContCreate(ironbee_plugin, NULL);

  /* connection initialisation & cleanup */
  TSHttpHookAdd(TS_HTTP_SSN_START_HOOK, cont);


  if (argc < 2) {
    TSError("[ironbee] configuration file name required\n");
    goto Lerror;
  }
  rv = ironbee_init(argv[1], argc >= 3 ? argv[2] : DEFAULT_LOG);
  if (rv != IB_OK) {
    TSError("[ironbee] initialisation failed with %d\n", rv);
  }
  return;

Lerror:
  TSError("[ironbee] Unable to initialize plugin (disabled).\n");
}
Ejemplo n.º 22
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  info.plugin_name = "stats";
  info.vendor_name = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS)
    TSError("Plugin registration failed. \n");

  if (argc > 1) {
    url_path = TSstrdup(argv[1] + ('/' == argv[1][0] ? 1 : 0)); /* Skip leading / */
  }
  url_path_len = strlen(url_path);

  /* Create a continuation with a mutex as there is a shared global structure
     containing the headers to add */
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(stats_origin, NULL));
  TSDebug("istats", "stats module registered");
}
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;

  info.plugin_name   = (char *)PLUGIN_NAME;
  info.vendor_name   = (char *)"Apache Software Foundation";
  info.support_email = (char *)"*****@*****.**";

  if (argc > 1) {
    TSstrlcpy(genid_kyoto_db, argv[1], sizeof(genid_kyoto_db));
  } else {
    TSError("[%s] plugin registration failed. check argv[1] for db path", PLUGIN_NAME);
    return;
  }

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[%s] plugin registration failed, check version", PLUGIN_NAME);
    return;
  }

  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate((TSEventFunc)handle_hook, NULL));
}
Ejemplo n.º 24
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSMLoc chk_field_loc;

  TSPluginRegistrationInfo info;

  info.plugin_name = "response-header-1";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("Plugin registration failed.\n");
  }

  init_buffer_status = 0;
  if (argc > 1) {
    TSError("usage: %s \n", argv[0]);
    TSError("warning: too many args %d\n", argc);
    TSError("warning: ignoring unused arguments beginning with %s\n", argv[1]);
  }

  /*
   *  The following code sets up an "init buffer" containing an extension header
   *  and its initial value.  This will be the same for all requests, so we try
   *  to be efficient and do all of the work here rather than on a per-transaction
   *  basis.
   */


  hdr_bufp = TSMBufferCreate();
  TSMimeHdrCreate(hdr_bufp, &hdr_loc);

  mimehdr1_name = TSstrdup("x-num-served-from-cache");
  mimehdr1_value = TSstrdup("0");

  /* Create name here and set DateTime value when o.s.
   * response 200 is received
   */
  mimehdr2_name = TSstrdup("x-date-200-recvd");

  TSDebug("resphdr", "Inserting header %s with value %s into init buffer", mimehdr1_name, mimehdr1_value);

  TSMimeHdrFieldCreate(hdr_bufp, hdr_loc, &field_loc); /* Probably should check for errors */
  TSMimeHdrFieldAppend(hdr_bufp, hdr_loc, field_loc);
  TSMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, mimehdr1_name, strlen(mimehdr1_name));
  TSMimeHdrFieldValueStringInsert(hdr_bufp, hdr_loc, field_loc, -1, mimehdr1_value, strlen(mimehdr1_value));
  TSDebug("resphdr", "init buffer hdr, field and value locs are %p, %p and %p", hdr_loc, field_loc, value_loc);
  init_buffer_status = 1;


  TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, TSContCreate(modify_response_header_plugin, NULL));

  /*
   *  The following code demonstrates how to extract the field_loc from the header.
   *  In this plugin, the init buffer and thus field_loc never changes.  Code
   *  similar to this may be used to extract header fields from any buffer.
   */

  if (TS_NULL_MLOC == (chk_field_loc = TSMimeHdrFieldGet(hdr_bufp, hdr_loc, 0))) {
    TSError("couldn't retrieve header field from init buffer");
    TSError("marking init buffer as corrupt; no more plugin processing");
    init_buffer_status = 0;
    /* bail out here and reenable transaction */
  } else {
    if (field_loc != chk_field_loc)
      TSError("retrieved buffer field loc is %p when it should be %p", chk_field_loc, field_loc);
  }
}
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  TSCont main_cont, config_cont;
  plugin_state_t *pstate;
  invalidate_t *iptr        = NULL;
  bool disable_timed_reload = false;

  TSDebug(LOG_PREFIX, "Starting plugin init");

  pstate = (plugin_state_t *)TSmalloc(sizeof(plugin_state_t));
  init_plugin_state_t(pstate);

  int c;
  static const struct option longopts[] = {{"config", required_argument, NULL, 'c'},
                                           {"log", required_argument, NULL, 'l'},
                                           {"disable-timed-reload", no_argument, NULL, 'd'},
                                           {NULL, 0, NULL, 0}};

  while ((c = getopt_long(argc, (char *const *)argv, "c:l:", longopts, NULL)) != -1) {
    switch (c) {
    case 'c':
      pstate->config_file = TSstrdup(optarg);
      break;
    case 'l':
      if (TS_SUCCESS == TSTextLogObjectCreate(optarg, TS_LOG_MODE_ADD_TIMESTAMP, &pstate->log)) {
        TSTextLogObjectRollingEnabledSet(pstate->log, 1);
        TSTextLogObjectRollingIntervalSecSet(pstate->log, LOG_ROLL_INTERVAL);
        TSTextLogObjectRollingOffsetHrSet(pstate->log, LOG_ROLL_OFFSET);
      }
      break;
    case 'd':
      disable_timed_reload = true;
      break;
    default:
      break;
    }
  }

  if (!pstate->config_file) {
    TSError("[regex_revalidate] Plugin requires a --config option along with a config file name");
    free_plugin_state_t(pstate);
    return;
  }

  if (!load_config(pstate, &iptr)) {
    TSDebug(LOG_PREFIX, "Problem loading config from file %s", pstate->config_file);
  } else {
    pstate->invalidate_list = iptr;
    list_config(pstate, iptr);
  }

  info.plugin_name   = LOG_PREFIX;
  info.vendor_name   = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(&info) != TS_SUCCESS) {
    TSError("[regex_revalidate] Plugin registration failed");

    free_plugin_state_t(pstate);
    return;
  } else {
    TSDebug(LOG_PREFIX, "Plugin registration succeeded");
  }

  if (!check_ts_version()) {
    TSError("[regex_revalidate] Plugin requires Traffic Server %d.%d.%d", TS_VERSION_MAJOR, TS_VERSION_MINOR, TS_VERSION_MICRO);
    free_plugin_state_t(pstate);
    return;
  }

  pcre_malloc = &ts_malloc;
  pcre_free   = &ts_free;

  main_cont = TSContCreate(main_handler, NULL);
  TSContDataSet(main_cont, (void *)pstate);
  TSHttpHookAdd(TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, main_cont);

  config_cont = TSContCreate(config_handler, TSMutexCreate());
  TSContDataSet(config_cont, (void *)pstate);

  TSMgmtUpdateRegister(config_cont, LOG_PREFIX);

  if (!disable_timed_reload) {
    TSContScheduleOnPool(config_cont, CONFIG_TMOUT, TS_THREAD_POOL_TASK);
  }

  TSDebug(LOG_PREFIX, "Plugin Init Complete");
}
Ejemplo n.º 26
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSPluginRegistrationInfo info;
  TSCont pre_remap_cont, post_remap_cont, global_cont;
  config_t *config;

  info.plugin_name = PLUGIN_NAME;
  info.vendor_name = "Apache Software Foundation";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("Plugin registration failed.");
    return;
  } else
    TSDebug(DEBUG_TAG, "Plugin registration succeeded.");

  config = TSmalloc(sizeof(config_t));
  config->post_remap_host = false;
  config->persist_type = TS_STAT_NON_PERSISTENT;
  config->stat_creation_mutex = TSMutexCreate();

  if (argc > 1) {
    int c;
    optind = 1;
    static const struct option longopts[] = {
      {"post-remap-host", no_argument, NULL, 'P'},
      {"persistent", no_argument, NULL, 'p'},
      {NULL, 0, NULL, 0}
    };

    while ((c = getopt_long(argc, (char *const *) argv, "Pp", longopts, NULL)) != -1) {
      switch (c) {
      case 'P':
        config->post_remap_host = true;
        TSDebug(DEBUG_TAG, "Using post remap hostname");
        break;
      case 'p':
        config->persist_type = TS_STAT_PERSISTENT;
        TSDebug(DEBUG_TAG, "Using persistent stats");
        break;
      default:
        break;
      }
    }
  }

  TSHttpArgIndexReserve(PLUGIN_NAME, "txn data", &(config->txn_slot));

  if (!config->post_remap_host) {
    pre_remap_cont = TSContCreate(handle_read_req_hdr, NULL);
    TSContDataSet(pre_remap_cont, (void *) config);
    TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, pre_remap_cont);
  }

  post_remap_cont = TSContCreate(handle_post_remap, NULL);
  TSContDataSet(post_remap_cont, (void *) config);
  TSHttpHookAdd(TS_HTTP_POST_REMAP_HOOK, post_remap_cont);

  global_cont = TSContCreate(handle_txn_close, NULL);
  TSContDataSet(global_cont, (void *) config);
  TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, global_cont);

  TSDebug(DEBUG_TAG, "Init complete");
}
Ejemplo n.º 27
0
void
TSPluginInit(int argc, const char *argv[])
{
    TSPluginRegistrationInfo info;

    info.plugin_name   = "ts_lua";
    info.vendor_name   = "Apache Software Foundation";
    info.support_email = "*****@*****.**";

    if (TSPluginRegister(&info) != TS_SUCCESS) {
        TSError("[ts_lua] Plugin registration failed.");
    }

    int ret                 = 0;
    ts_lua_g_main_ctx_array = TSmalloc(sizeof(ts_lua_main_ctx) * TS_LUA_MAX_STATE_COUNT);
    memset(ts_lua_g_main_ctx_array, 0, sizeof(ts_lua_main_ctx) * TS_LUA_MAX_STATE_COUNT);

    ret = ts_lua_create_vm(ts_lua_g_main_ctx_array, TS_LUA_MAX_STATE_COUNT);

    if (ret) {
        ts_lua_destroy_vm(ts_lua_g_main_ctx_array, TS_LUA_MAX_STATE_COUNT);
        TSfree(ts_lua_g_main_ctx_array);
        return;
    }

    if (argc < 2) {
        TSError("[ts_lua][%s] lua script file required !!", __FUNCTION__);
        return;
    }

    if (strlen(argv[1]) >= TS_LUA_MAX_SCRIPT_FNAME_LENGTH - 16) {
        TSError("[ts_lua][%s] lua script file name too long !!", __FUNCTION__);
        return;
    }

    ts_lua_instance_conf *conf = TSmalloc(sizeof(ts_lua_instance_conf));
    if (!conf) {
        TSError("[ts_lua][%s] TSmalloc failed !!", __FUNCTION__);
        return;
    }
    memset(conf, 0, sizeof(ts_lua_instance_conf));
    conf->remap = 0;

    snprintf(conf->script, TS_LUA_MAX_SCRIPT_FNAME_LENGTH, "%s", argv[1]);

    ts_lua_init_instance(conf);

    char errbuf[TS_LUA_MAX_STR_LENGTH];
    int errbuf_len = sizeof(errbuf);
    ret = ts_lua_add_module(conf, ts_lua_g_main_ctx_array, TS_LUA_MAX_STATE_COUNT, argc - 1, (char **)&argv[1], errbuf, errbuf_len);

    if (ret != 0) {
        TSError(errbuf, NULL);
        TSError("[ts_lua][%s] ts_lua_add_module failed", __FUNCTION__);
        return;
    }

    TSCont global_contp = TSContCreate(globalHookHandler, NULL);
    if (!global_contp) {
        TSError("[ts_lua][%s] could not create transaction start continuation", __FUNCTION__);
        return;
    }
    TSContDataSet(global_contp, conf);

    // adding hook based on whether the lua global function exists.
    ts_lua_main_ctx *main_ctx = &ts_lua_g_main_ctx_array[0];
    ts_lua_http_ctx *http_ctx = ts_lua_create_http_ctx(main_ctx, conf);
    lua_State *l              = http_ctx->cinfo.routine.lua;

    lua_getglobal(l, TS_LUA_FUNCTION_G_SEND_REQUEST);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_SEND_REQUEST_HDR_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "send_request_hdr_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_READ_RESPONSE);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "read_response_hdr_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_SEND_RESPONSE);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_SEND_RESPONSE_HDR_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "send_response_hdr_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_CACHE_LOOKUP_COMPLETE);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "cache_lookup_complete_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_READ_REQUEST);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "read_request_hdr_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_TXN_START);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_TXN_START_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "txn_start_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_PRE_REMAP);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_PRE_REMAP_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "pre_remap_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_POST_REMAP);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_POST_REMAP_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "post_remap_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_SELECT_ALT);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_SELECT_ALT_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "select_alt_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_OS_DNS);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_OS_DNS_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "os_dns_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_READ_CACHE);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_READ_CACHE_HDR_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "read_cache_hdr_hook added");
    }
    lua_pop(l, 1);

    lua_getglobal(l, TS_LUA_FUNCTION_G_TXN_CLOSE);
    if (lua_type(l, -1) == LUA_TFUNCTION) {
        TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, global_contp);
        TSDebug(TS_LUA_DEBUG_TAG, "txn_close_hook added");
    }
    lua_pop(l, 1);

    ts_lua_destroy_http_ctx(http_ctx);
}
Ejemplo n.º 28
0
void
TSPluginInit(int argc, const char *argv[])
{
  TSMLoc field_loc;
  const char *p;
  int i, retval;
  TSPluginRegistrationInfo info;

  info.plugin_name = "add-header";
  info.vendor_name = "MyCompany";
  info.support_email = "*****@*****.**";

  if (TSPluginRegister(TS_SDK_VERSION_3_0, &info) != TS_SUCCESS) {
    TSError("[PluginInit] Plugin registration failed.\n");
    goto error;
  }

  if (!check_ts_version()) {
    TSError("[PluginInit] Plugin requires Traffic Server 3.0 or later\n");
    goto error;
  }

  if (argc < 2) {
    TSError("[PluginInit] Usage: %s \"name1: value1\" \"name2: value2\" ...>\n", argv[0]);
    goto error;
  }

  hdr_bufp = TSMBufferCreate();
  if (TSMimeHdrCreate(hdr_bufp, &hdr_loc) != TS_SUCCESS) {
    TSError("[PluginInit] Can not create mime header");
    goto error;
  }

  for (i = 1; i < argc; i++) {
    if (TSMimeHdrFieldCreate(hdr_bufp, hdr_loc, &field_loc) != TS_SUCCESS) {
      TSError("[PluginInit] Error while creating field");
      goto error;
    }

    retval = TSMimeHdrFieldAppend(hdr_bufp, hdr_loc, field_loc);
    if (retval != TS_SUCCESS) {
      TSError("[PluginInit] Error while adding field");
      goto error;
    }

    p = strchr(argv[i], ':');
    if (p) {
      retval = TSMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, argv[i], p - argv[i]);
      if (retval == TS_ERROR) {
        TSError("[PluginInit] Error while naming field");
        goto error;
      }

      p += 1;
      while (isspace(*p)) {
        p += 1;
      }
      retval = TSMimeHdrFieldValueStringInsert(hdr_bufp, hdr_loc, field_loc, -1, p, strlen(p));
      if (retval == TS_ERROR) {
        TSError("[PluginInit] Error while inserting field value");
        goto error;
      }
    } else {
      retval = TSMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, argv[i], strlen(argv[i]));
      if (retval == TS_ERROR) {
        TSError("[PluginInit] Error while inserting field value");
        goto error;
      }
    }
  }

  /* Create a continuation with a mutex as there is a shared global structure
     containing the headers to add */
  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(add_header_plugin, TSMutexCreate()));
  goto done;

error:
  TSError("[PluginInit] Plugin not initialized");

done:
  return;
}