コード例 #1
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;
}
コード例 #2
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);
}
コード例 #3
0
/* Verification code for: INKqa06643 */
static int
EventHandler(INKCont contp, INKEvent event, void *eData)
{
  INKHttpTxn txn = (INKHttpTxn) eData;
  int iVal;
  time_t tVal;

  if (time(&tVal) != (time_t) (-1)) {
    INKDebug("tag_sched6643", "INKContSchedule: EventHandler: called at %s\n", ctime(&tVal));
  }

  iVal = (int) INKContDataGet(contp);

  INKDebug("tag_sched6643", "INKContSchedule: handler called with value %d\n", iVal);

  switch (event) {

  case INK_EVENT_HTTP_OS_DNS:
    INKDebug("tag_sched6643", "INKContSchedule: Seed event %s\n", "INK_EVENT_HTTP_OS_DNS");
    break;

  case INK_EVENT_TIMEOUT:
    INKDebug("tag_sched6643", "INKContSchedule: TIMEOUT event\n");
    break;

  default:
    INKDebug("tag_sched6643", "INKContSchedule: Error: default event\n");
    break;
  }

  iVal += 100;                  /* seed + timeout val */
  INKContDataSet(contp, (void *) iVal);
  INKContSchedule(contp, iVal);

  /* INKHttpTxnReenable(txn, INK_EVENT_HTTP_CONTINUE); */
}
コード例 #4
0
void
cache_exercise(INKHttpTxn txnp, char *url, int pin_val, int hostname_set, INKCont cache_handler_cont)
{
  INKCacheKey cache_key;
  CACHE_URL_DATA *url_data;
  int cache_ready;
  char *pchar;
  char hostname[MAX_URL_LEN];

  LOG_SET_FUNCTION_NAME("cache_exercise");

  pchar = strstr(url, "://");
  if (pchar == NULL) {
    pchar = url;
  } else {
    pchar += 3;
  }

  strncpy(hostname, pchar, MAX_URL_LEN - 1);

  pchar = strstr(hostname, "/");
  if (pchar != NULL) {
    *pchar = '\0';
  }

  if (INKCacheReady(&cache_ready) == INK_ERROR) {
    LOG_ERROR_AND_REENABLE("INKCacheReady");
    return;
  }
#ifdef DEBUG
  /*INKDebug(DEBUG_TAG, "Starting Negative Test for INKCacheReady"); */
  if (INKCacheReady(NULL) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheReady(NULL)");
  }
  /*INKDebug(DEBUG_TAG, "Done Negative Test for INKCacheReady"); */
#endif

  if (cache_ready == 0) {
    INKDebug(DEBUG_TAG, "%s: ERROR!! Cache Not Ready\n", PLUGIN_NAME);
    insert_in_response(txnp, "MISS");
    INKHttpTxnReenable(txnp, INK_EVENT_HTTP_CONTINUE);
    return;
  }

  if (INKCacheKeyCreate(&cache_key) == INK_ERROR) {
    LOG_ERROR_AND_REENABLE("INKCacheKeyCreate");
    return;
  }
#ifdef DEBUG
  /*INKDebug(DEBUG_TAG, "Starting Negative Test for INKCacheKeyCreate"); */
  if (INKCacheKeyCreate(NULL) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyCreate(NULL)");
  }
  /*INKDebug(DEBUG_TAG, "Done Negative Test for INKCacheKeyCreate"); */
#endif

#ifdef DEBUG
  /*INKDebug(DEBUG_TAG, "Starting Negative Test for INKCacheKeyDigestSet"); */
  if (INKCacheKeyDigestSet(NULL, (unsigned char *) url, strlen(url)) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyDigestSet(NULL, string, len)");
  }

  if (INKCacheKeyDigestSet(cache_key, NULL, strlen(url)) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyDigestSet(cache_key, NULL, len)");
  }

  if (INKCacheKeyDigestSet(cache_key, (unsigned char *) url, -1) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyDigestSet(cache_key, string, -1)");
  }
  /*INKDebug(DEBUG_TAG, "Done Negative Test for INKCacheKeyDigestSet"); */
#endif

  if (INKCacheKeyDigestSet(cache_key, (unsigned char *) url, strlen(url)) == INK_ERROR) {
    INKCacheKeyDestroy(cache_key);
    LOG_ERROR_AND_REENABLE("INKCacheKeyDigestSet");
    return;
  }

  url_data = INKmalloc(sizeof(CACHE_URL_DATA));
  if (url_data == NULL) {
    INKCacheKeyDestroy(cache_key);
    LOG_ERROR_AND_REENABLE("INKmalloc");
    return;
  }

  url_data->magic = MAGIC_ALIVE;
  url_data->url = url;
  url_data->url_len = strlen(url);
  url_data->key = cache_key;
  url_data->pin_time = pin_val;
  url_data->write_again_after_remove = 0;
  url_data->txnp = txnp;

  url_data->bufp = INKIOBufferCreate();
  if (url_data->bufp == INK_ERROR_PTR) {
    INKCacheKeyDestroy(cache_key);
    INKfree(url_data);
    LOG_ERROR_AND_REENABLE("INKIOBufferCreate");
    return;
  }

  if (INKContDataSet(cache_handler_cont, url_data) == INK_ERROR) {
    INKCacheKeyDestroy(cache_key);
    INKfree(url_data);
    LOG_ERROR_AND_REENABLE("INKContDataSet");
    return;
  }
#ifdef DEBUG
  /*INKDebug(DEBUG_TAG, "Starting Negative Test for INKCacheKeyHostNameSet"); */
  if (INKCacheKeyHostNameSet(NULL, (unsigned char *) hostname, strlen(hostname)) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyHostNameSet(NULL, string, len)");
  }

  if (INKCacheKeyHostNameSet(url_data->key, NULL, strlen(hostname)) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyHostNameSet(cache_key, NULL, len)");
  }

  if (INKCacheKeyHostNameSet(url_data->key, (unsigned char *) hostname, -1) != INK_ERROR) {
    LOG_ERROR_NEG("INKCacheKeyHostNameSet(cache_key, string, -1)");
  }
  /*INKDebug(DEBUG_TAG, "Done Negative Test for INKCacheKeyHostNameSet"); */
#endif

  if (hostname_set > 0) {
    INKDebug(DEBUG_TAG, "HostName set for cache_key to %s", hostname);
    if (INKCacheKeyHostNameSet(url_data->key, (unsigned char *) hostname, strlen(hostname)) == INK_ERROR) {
      INKCacheKeyDestroy(cache_key);
      INKfree(url_data);
      LOG_ERROR_AND_REENABLE("INKCacheKeyHostNameSet");
      return;
    }
  }

  /* try to read from the cache */
  if (INKCacheRead(cache_handler_cont, cache_key) == INK_ERROR_PTR) {
    INKCacheKeyDestroy(cache_key);
    INKfree(url_data);
    LOG_ERROR_AND_REENABLE("INKCacheRead");
    return;
  }
#ifdef DEBUG
  /*INKDebug(DEBUG_TAG, "Starting Negative Test for INKCacheRead"); */
  if (INKCacheRead(cache_handler_cont, NULL) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKCacheRead(cache_handler_cont, NULL)");
  }

  if (INKCacheRead(NULL, cache_key) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKCacheRead(NULL, cache_key)");
  }
  /*INKDebug(DEBUG_TAG, "Done Negative Test for INKCacheRead"); */
#endif

  return;
}