Beispiel #1
0
void
INKPluginInit(int argc, const char *argv[])
{
  INKPluginRegistrationInfo info;

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

  if (!INKPluginRegister(INK_SDK_VERSION_5_2, &info)) {
    INKError("[PluginInit] Plugin registration failed.\n");
    goto error;
  }

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


  INKHttpHookAdd(INK_HTTP_OS_DNS_HOOK, INKContCreate(hdr_plugin, NULL));

error:
  INKError("[PluginInit] Plugin not initialized");
}
Beispiel #2
0
static void
clusterRPC_init()
{
  int ret;

    /***********************************************************************
     *  Create plugin mutex
     ***********************************************************************/
  node_status_mutex = INKMutexCreate();
  if (!node_status_mutex) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexCreate for node_status failed\n");
    return;
  }
  if (!INKMutexTryLock(node_status_mutex)) {
    /* Should never fail */
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKMutexTryLock failed\n");
  }
    /***********************************************************************
     *  Register our RPC handler.
     ***********************************************************************/
  ret = INKAddClusterRPCFunction(RPC_API_WIRELESS_F10, rpc_wireless_f10_func, &rpc_wireless_f10_handle);
  if (ret) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterRPCFunction failed\n");
    return;
  }
    /***********************************************************************
     *  Subscribe to cluster node status callouts.
     ***********************************************************************/
  ret = INKAddClusterStatusFunction(status_callout, node_status_mutex, &status_callout_handle);
  if (ret) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKAddClusterStatusFunction failed\n");
    return;
  }
    /***********************************************************************
     *  Perform node status initializations.
     ***********************************************************************/
  INKGetMyNodeHandle(&my_node_handle);

    /***********************************************************************
     *  Enable cluster node status callouts.
     ***********************************************************************/
  INKEnableClusterStatusCallout(&status_callout_handle);

    /***********************************************************************
     *  Establish the periodic event.
     ***********************************************************************/
  periodic_event_cont = INKContCreate(periodic_event, node_status_mutex);
  if (!periodic_event_cont) {
    INKDebug(PLUGIN_DEBUG_ERR_TAG, "INKContCreate for periodic_event failed\n");
    return;
  }
  periodic_event_action = INKContSchedule(periodic_event_cont, (1 * 1000) /* 1 sec */ );
  INKMutexUnlock(node_status_mutex);
}
Beispiel #3
0
void
INKPluginInit(int argc, const char *argv[])
{
  INKCont pCont;

  LOG_SET_FUNCTION_NAME("INKPluginInit");

  if ((pCont = INKContCreate(contHandler, NULL)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKContCreate")
  } else if (INKHttpHookAdd(INK_HTTP_TXN_START_HOOK, pCont) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHookAdd");
  }
}
Beispiel #4
0
static int
event_mux(INKCont contp, INKEvent event, void *edata)
{
  INKHttpTxn txnp = (INKHttpTxn) edata;
  INKCont newcont;
  char *client_req;
  char *url_line;
  int ret_status;
  int neg_test_val;
  int pin_val;

  LOG_SET_FUNCTION_NAME("event_mux");

  switch (event) {

  case INK_EVENT_HTTP_SEND_RESPONSE_HDR:
    if ((newcont = INKContCreate(handle_cache_events, INKMutexCreate())) == INK_ERROR_PTR) {
      LOG_ERROR_AND_REENABLE("INKContCreate");
      return 0;
    }

    /* FC When called back for txn close, the plugins test if the value of the
       continuation data ptr is null or not. Initialize it here to null. */
    INKContDataSet(newcont, NULL);

    if (INKHttpTxnHookAdd(edata, INK_HTTP_TXN_CLOSE_HOOK, newcont) == INK_ERROR) {
      LOG_ERROR_AND_REENABLE("INKHttpTxnHookAdd");
      return 0;
    }

    ret_status = get_client_req(txnp, &url_line, &client_req, &neg_test_val, &pin_val);

    /* FC: added test on url and client req too */
    if ((ret_status == -1) || (url_line == NULL) || (client_req == NULL)) {
      INKDebug(DEBUG_TAG, "Unable to get client request header\n");
      INKHttpTxnReenable(txnp, INK_EVENT_HTTP_CONTINUE);
      return 0;
    }

    INKDebug(DEBUG_TAG, "\n%s\n%s", url_line, client_req);
    INKfree(client_req);

    cache_exercise(txnp, url_line, pin_val, neg_test_val, newcont);

    break;

  default:
    ;
  }
  return 0;
}
Beispiel #5
0
void
INKPluginInit(int argc, const char *argv[])
{
  LOG_SET_FUNCTION_NAME("INKPluginInit");
  INKCont contp;

  INKDebug(DEBUG_TAG, "INKPluginInit");
  if ((contp = INKContCreate(event_mux, NULL)) == INK_ERROR_PTR) {
    LOG_ERROR("INKContCreate");
  } else if (INKHttpHookAdd(INK_HTTP_SEND_RESPONSE_HDR_HOOK, contp) == INK_ERROR) {
    LOG_ERROR("INKHttpHookAdd");
  }

}
Beispiel #6
0
void
INKPluginInit(int argc, const char *argv[])
{
  INKCont contp, contp2;
  int timeOut = 10;

  INKDebug("tag_sched6643", "INKContSchedule: Initial data value for contp is %d\n", timeOut);

  /* contp = INKContCreate(EventHandler, INKMutexCreate() ); */

  contp = INKContCreate(EventHandler, NULL);
  INKContDataSet(contp, (void *) timeOut);

  INKHttpHookAdd(INK_HTTP_OS_DNS_HOOK, contp);
}
Beispiel #7
0
static int
attach_test(INKCont contp, INKEvent event, void *edata)
{
  INKHttpTxn txnp = (INKHttpTxn) edata;
  INKCont new_cont;

  switch (event) {
  case INK_EVENT_HTTP_READ_REQUEST_HDR:
    new_cont = INKContCreate(test_destroy_plugin, INKMutexCreate());
    INKHttpTxnHookAdd(txnp, INK_HTTP_TXN_CLOSE_HOOK, new_cont);
    INKHttpTxnReenable(txnp, INK_EVENT_HTTP_CONTINUE);
    break;
  default:
    INKAssert(0);
  }
  return 0;
}
Beispiel #8
0
void
INKPluginInit(int argc, const char *argv[])
{


  INKMutex lock1 = INKMutexCreate();

  INKCont contp = INKContCreate(startplugin, lock1);

  value = 0;

  INKHttpHookAdd(INK_HTTP_READ_REQUEST_HDR_HOOK, contp);
  INKHttpHookAdd(INK_HTTP_OS_DNS_HOOK, contp);
  INKHttpHookAdd(INK_HTTP_SEND_REQUEST_HDR_HOOK, contp);
  INKHttpHookAdd(INK_HTTP_READ_CACHE_HDR_HOOK, contp);
  INKHttpHookAdd(INK_HTTP_READ_RESPONSE_HDR_HOOK, contp);
  INKHttpHookAdd(INK_HTTP_SEND_RESPONSE_HDR_HOOK, contp);
}
Beispiel #9
0
void
INKPluginInit(int argc, const char *argv[])
{
  INKPluginRegistrationInfo info;

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

  if (!INKPluginRegister(INK_SDK_VERSION_5_2, &info)) {
    INKError("Plugin registration failed. \n");
  }

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

  INKHttpHookAdd(INK_HTTP_READ_RESPONSE_HDR_HOOK, INKContCreate(replace_header_plugin, NULL));
}
Beispiel #10
0
void
INKPluginInit(int argc, const char *argv[])
{
  LOG_SET_FUNCTION_NAME("INKPluginInit");

  INKCont contp;

  plugin_dir = INKPluginDirGet();
  if ((file_mutex = INKMutexCreate()) == INK_ERROR_PTR) {
    LOG_ERROR("INKMutexCreate");
    return;
  }

  if ((contp = INKContCreate(process_plugin, INKMutexCreate())) == INK_ERROR_PTR) {
    LOG_ERROR("INKContCreate");
    return;
  }

  if (INKHttpHookAdd(INK_HTTP_TXN_START_HOOK, contp) == INK_ERROR)
    LOG_ERROR("INKHttpHookAdd");

}
Beispiel #11
0
void
INKPluginInit(int argc, const char *argv[])
{

  INKHttpHookAdd(INK_HTTP_READ_REQUEST_HDR_HOOK, INKContCreate(attach_test, NULL));
}
Beispiel #12
0
void
INKPluginInit(int argc, const char *argv[])
{
  INKMLoc field_loc;
  const char *p;
  int i, retval;
  INKPluginRegistrationInfo info;

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

  if (!INKPluginRegister(INK_SDK_VERSION_5_2, &info)) {
    INKError("[PluginInit] Plugin registration failed.\n");
    goto error;
  }

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

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

  hdr_bufp = INKMBufferCreate();
  if (hdr_bufp == INK_ERROR_PTR) {
    INKError("[PluginInit] Can not create mbuffer");
    goto error;
  }

  hdr_loc = INKMimeHdrCreate(hdr_bufp);
  if (hdr_loc == INK_ERROR_PTR) {
    INKError("[PluginInit] Can not create mime header");
    goto error;
  }

  for (i = 1; i < argc; i++) {
    field_loc = INKMimeHdrFieldCreate(hdr_bufp, hdr_loc);
    if (field_loc == INK_ERROR_PTR) {
      INKError("[PluginInit] Error while creating field");
      goto error;
    }

    retval = INKMimeHdrFieldAppend(hdr_bufp, hdr_loc, field_loc);
    if (retval == INK_ERROR) {
      INKError("[PluginInit] Error while adding field");
      goto error;
    }

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

      p += 1;
      while (isspace(*p)) {
        p += 1;
      }
      retval = INKMimeHdrFieldValueInsert(hdr_bufp, hdr_loc, field_loc, p, strlen(p), -1);
      if (retval == INK_ERROR) {
        INKError("[PluginInit] Error while inserting field value");
        goto error;
      }
    } else {
      retval = INKMimeHdrFieldNameSet(hdr_bufp, hdr_loc, field_loc, argv[i], strlen(argv[i]));
      if (retval == INK_ERROR) {
        INKError("[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 */
  retval = INKHttpHookAdd(INK_HTTP_READ_REQUEST_HDR_HOOK, INKContCreate(add_header_plugin, INKMutexCreate()));
  if (retval == INK_ERROR) {
    INKError("[PluginInit] Error while registering to hook");
    goto error;
  }

  goto done;

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

done:
  return;
}