コード例 #1
0
static int
process_plugin(INKCont contp, INKEvent event, void *edata)
{
  LOG_SET_FUNCTION_NAME("process_plugin");

  INKHttpTxn txnp = (INKHttpTxn) edata;

  switch (event) {
  case INK_EVENT_HTTP_TXN_START:
    handle_txn_start(contp, txnp);
    break;
  case INK_EVENT_HTTP_READ_CACHE_HDR:
    handle_cache_hdr(txnp);
    break;
  case INK_EVENT_HTTP_READ_RESPONSE_HDR:
    handle_response_hdr(contp, txnp);
    break;
  default:
    break;
  }

  if (INKHttpTxnReenable(txnp, INK_EVENT_HTTP_CONTINUE) == INK_ERROR)
    LOG_ERROR("INKHttpTxnReenable");

  return 0;
}
コード例 #2
0
/************************************************************************************
 * getHdrInfo:
 *
 * DESCRIPTION: 
 *  Function to store httpHdrBuffer (pointed by hdrBuf) information into pHdrInfo
 *
 * RETURN:
 *  void
 ************************************************************************************/
static void
getHdrInfo(HdrInfo_T * pHdrInfo, INKMBuffer hdrBuf, INKMLoc hdrLoc)
{
  LOG_SET_FUNCTION_NAME("getHdrInfo");
  INKMLoc urlLoc = NULL;

  const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL;
  int iHttpHdrReasonLength, iHttpMethodLength, iHostLength;

  if ((pHdrInfo->httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }
  if ((pHdrInfo->hdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrLengthGet");
  }
  if ((pHdrInfo->httpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  if (pHdrInfo->httpType == INK_HTTP_TYPE_REQUEST) {
    if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else {
      pHdrInfo->httpMethod = INKstrndup(sHttpMethod, iHttpMethodLength);
    }

    if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrUrlGet");
    } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKUrlHostGet");
    } else {
      pHdrInfo->hostName = INKstrndup(sHostName, iHostLength);
    }

    /* Clean-up */
    STR_RELEASE(hdrBuf, urlLoc, sHostName);
    STR_RELEASE(hdrBuf, urlLoc, sHttpMethod);
    HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc);

  } else if (pHdrInfo->httpType == INK_HTTP_TYPE_RESPONSE) {
    if ((pHdrInfo->httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    }

    if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else if (sHttpHdrReason) {
      pHdrInfo->hdrReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
    }

    /* clean-up */
    STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason);
  } else {
    LOG_AUTO_ERROR("getHdrInfo", "httpType unknown");
  }
}
コード例 #3
0
static int
handle_txn_start(INKCont contp, INKHttpTxn txnp)
{
  LOG_SET_FUNCTION_NAME("handle_txn_start");

  if (INKHttpTxnHookAdd(txnp, INK_HTTP_READ_CACHE_HDR_HOOK, contp) == INK_ERROR)
    LOG_ERROR_AND_RETURN("INKHttpTxnHookAdd");
  if (INKHttpTxnHookAdd(txnp, INK_HTTP_READ_RESPONSE_HDR_HOOK, contp) == INK_ERROR)
    LOG_ERROR_AND_RETURN("INKHttpTxnHookAdd");

  return 0;
}
コード例 #4
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");
  }
}
コード例 #5
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;
}
コード例 #6
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");
  }

}
コード例 #7
0
static void
handleTxnStart(INKCont pCont, INKHttpTxn pTxn)
{
  LOG_SET_FUNCTION_NAME("handleTxnStart");

  if (INKHttpTxnHookAdd(pTxn, INK_HTTP_READ_REQUEST_HDR_HOOK, pCont) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHookAdd");
  }

  if (INKHttpTxnHookAdd(pTxn, INK_HTTP_SEND_RESPONSE_HDR_HOOK, pCont) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHookAdd");
  }

  if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpTxnReenable");
  }
}
コード例 #8
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");

}
コード例 #9
0
/************************************************************************************
 * identical_hdr:
 *
 * DESCRIPTION: 
 *  Function to check whether 2 hdrInfos are identical (member to member)
 *
 * RETURN:
 *  0: If not identical
 *  1: If identical
 ************************************************************************************/
int
identical_hdr(HdrInfo_T * pHdrInfo1, HdrInfo_T * pHdrInfo2)
{
  LOG_SET_FUNCTION_NAME("identical_hdr");

  if (pHdrInfo1->httpType != pHdrInfo2->httpType) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "httpType different");
    return 0;
  } else if (pHdrInfo1->hdrLength != pHdrInfo2->hdrLength) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "hdrLength different");
    return 0;
  } else if (pHdrInfo1->httpVersion != pHdrInfo2->httpVersion) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "httpVersion different");
    return 0;
  } else if (pHdrInfo1->httpType == INK_HTTP_TYPE_REQUEST) {
    if (strcmp(pHdrInfo1->httpMethod, pHdrInfo2->httpMethod)) {
      LOG_AUTO_ERROR("INKHttpHdrCopy", "httpMethod different");
      return 0;
    } else if (strcmp(pHdrInfo1->hostName, pHdrInfo2->hostName)) {
      LOG_AUTO_ERROR("INKHttpHdrCopy", "hostName different");
      return 0;
    }
  } else if (pHdrInfo1->httpType == INK_HTTP_TYPE_RESPONSE) {
    if (pHdrInfo1->httpStatus != pHdrInfo2->httpStatus) {
      LOG_AUTO_ERROR("INKHttpHdrCopy", "httpStatus different");
      return 0;
    } else if (pHdrInfo1->hdrReason && strcmp(pHdrInfo1->hdrReason, pHdrInfo2->hdrReason)) {
      LOG_AUTO_ERROR("INKHttpHdrCopy", "hdrReason different");
      return 0;
    }
  } else {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "httpType still INK_HTTP_TYPE_UNKNOWN");
    return 0;
  }

  return 1;                     /* Both the headers are exactly identical */
}
コード例 #10
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;
}
コード例 #11
0
static int
handle_cache_events(INKCont contp, INKEvent event, void *edata)
{
  CACHE_URL_DATA *url_data;
  INKVConn connp = (INKVConn) edata;
  char tempstr[32];

  LOG_SET_FUNCTION_NAME("handle_cache_events");

  url_data = (CACHE_URL_DATA *) INKContDataGet(contp);
  if (url_data == INK_ERROR_PTR) {
    LOG_ERROR_AND_RETURN("INKContDataGet");
  }

  if (event != INK_EVENT_HTTP_TXN_CLOSE) {
    INKReleaseAssert(url_data->magic == MAGIC_ALIVE);
  } else {
    INKReleaseAssert((url_data == NULL) || (url_data->magic == MAGIC_ALIVE));
  }

  switch (event) {
  case INK_EVENT_CACHE_OPEN_READ:
    /*handle_cache_read(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_OPEN_READ\n");

    if (url_data->pin_time != 0) {
      sprintf(tempstr, "PIN%d", url_data->pin_time);
    } else {
      sprintf(tempstr, "HIT");
    }
    insert_in_response(url_data->txnp, tempstr);

    if (url_data->pin_time != 0) {

      url_data->write_again_after_remove = 1;

      if (INKCacheRemove(contp, url_data->key) == INK_ERROR_PTR) {
        LOG_ERROR("INKCacheRemove");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }
#ifdef DEBUG
      if (INKCacheRemove(NULL, url_data->key) != INK_ERROR_PTR) {
        LOG_ERROR_NEG("INKCacheRemove(NULL, cache_key)");
      }

      if (INKCacheRemove(contp, NULL) != INK_ERROR_PTR) {
        LOG_ERROR_NEG("INKCacheRemove(contp, NULL)");
      }
#endif
      return 0;
    }
#ifdef DEBUG
    if (INKVConnRead(NULL, contp, url_data->bufp, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnRead(NULL, contp, bufp, url_len)");
    }

    if (INKVConnRead(connp, NULL, url_data->bufp, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnRead(connp, NULL, bufp, url_len)");
    }

    if (INKVConnRead(connp, contp, NULL, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnRead(connp, contp, NULL, url_len)");
    }

    if (INKVConnRead(connp, contp, url_data->bufp, -1) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnRead(connp, contp, bufp, -1)");
    }
#endif

    if (INKVConnRead(connp, contp, url_data->bufp, url_data->url_len) == INK_ERROR_PTR) {
      LOG_ERROR("INKVConnRead");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }

    break;

  case INK_EVENT_CACHE_OPEN_READ_FAILED:
    /*handle_cache_read_fail(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_OPEN_READ_FAILED(%d)\n", edata);

    if (url_data->pin_time != 0) {
      sprintf(tempstr, "PIN%d", url_data->pin_time);
    } else {
      sprintf(tempstr, "MISS");
    }
    insert_in_response(url_data->txnp, tempstr);

    if (url_data->pin_time != 0) {
      INKDebug(DEBUG_TAG, "url Pinned in cache for %d secs", url_data->pin_time);
      if (INKCacheKeyPinnedSet(url_data->key, url_data->pin_time) == INK_ERROR) {
        LOG_ERROR("INKCacheKeyPinnedSet");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }
#ifdef DEBUG
      if (INKCacheKeyPinnedSet(NULL, url_data->pin_time) != INK_ERROR) {
        LOG_ERROR_NEG("INKCacheKeyPinnedSet(NULL, pin_time)");
      }

      if (INKCacheKeyPinnedSet(url_data->key, -1) != INK_ERROR) {
        LOG_ERROR_NEG("INKCacheKeyPinnedSet(cache_key, -1)");
      }
#endif
    }

    if (INKCacheWrite(contp, url_data->key) == INK_ERROR_PTR) {
      LOG_ERROR("INKCacheWrite");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }
#ifdef DEBUG
    if (INKCacheWrite(contp, NULL) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKCacheWrite(contp, NULL)");
    }

    if (INKCacheWrite(NULL, url_data->key) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKCacheWrite(NULL, url_data->key)");
    }
#endif

    break;

  case INK_EVENT_CACHE_OPEN_WRITE:
    /*handle_cache_write(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_OPEN_WRITE\n");

    if (INKIOBufferWrite(url_data->bufp, url_data->url, url_data->url_len) == INK_ERROR) {
      LOG_ERROR("INKIOBufferWrite");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }

    url_data->bufp_reader = INKIOBufferReaderAlloc(url_data->bufp);
    if (url_data->bufp_reader == INK_ERROR_PTR) {
      LOG_ERROR("INKIOBufferReaderAlloc");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }
#ifdef DEBUG
    if (INKVConnWrite(NULL, contp, url_data->bufp_reader, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnWrite(NULL, contp, bufp_reader, url_len");
    }

    if (INKVConnWrite(connp, NULL, url_data->bufp_reader, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnWrite(connp, NULL, bufp_reader, url_len");
    }

    if (INKVConnWrite(connp, contp, NULL, url_data->url_len) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnWrite(connp, contp, NULL, url_len");
    }

    if (INKVConnWrite(connp, contp, url_data->bufp_reader, -1) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVConnWrite(connp, contp, bufp_reader, -1");
    }
#endif

    if (INKVConnWrite(connp, contp, url_data->bufp_reader, url_data->url_len) == INK_ERROR_PTR) {
      LOG_ERROR("INKVConnWrite");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }

    break;

  case INK_EVENT_CACHE_OPEN_WRITE_FAILED:
    /*handle_cache_write_fail(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_OPEN_WRITE_FAILED(%d)\n", edata);
    INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);

    break;

  case INK_EVENT_CACHE_REMOVE:
    /*handle_cache_remove(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_REMOVE\n");

    if (url_data->write_again_after_remove != 0) {

      INKDebug(DEBUG_TAG, "url Pinned in cache for %d secs", url_data->pin_time);
      if (url_data->pin_time != 0) {
        if (INKCacheKeyPinnedSet(url_data->key, url_data->pin_time) == INK_ERROR) {
          LOG_ERROR("INKCacheKeyPinnedSet");
          INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
          return -1;
        }
      }

      if (INKCacheWrite(contp, url_data->key) == INK_ERROR_PTR) {
        LOG_ERROR("INKCacheWrite");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }
    } else {
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
    }

    break;

  case INK_EVENT_CACHE_REMOVE_FAILED:
    /*handle_cache_remove_fail(); */
    INKDebug(DEBUG_TAG, "INK_EVENT_CACHE_REMOVE_FAILED(%d)\n", edata);
    INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
    break;

  case INK_EVENT_VCONN_READ_READY:
    INKDebug(DEBUG_TAG, "INK_EVENT_VCONN_READ_READY\n");

    if (INKVIOReenable(edata) == INK_ERROR) {
      LOG_ERROR("INKVIOReenable");
    }
#ifdef DEBUG
    if (INKVIOReenable(NULL) != INK_ERROR) {
      LOG_ERROR_NEG("INKVIOReenable");
    }
#endif

    break;

  case INK_EVENT_VCONN_WRITE_READY:
    INKDebug(DEBUG_TAG, "INK_EVENT_VCONN_WRITE_READY\n");

    if (INKVIOReenable(edata) == INK_ERROR) {
      LOG_ERROR("INKVIOReenable");
    }
#ifdef DEBUG
    if (INKVIOReenable(NULL) != INK_ERROR) {
      LOG_ERROR_NEG("INKVIOReenable");
    }
#endif

    break;

  case INK_EVENT_VCONN_READ_COMPLETE:
    INKDebug(DEBUG_TAG, "INK_EVENT_VCONN_READ_COMPLETE\n");
    {
      INKIOBufferBlock blk;
      char *src;
      char dst[MAX_URL_LEN];
      int avail;
      int url_len_from_cache;

      if ((connp = INKVIOVConnGet(edata)) == INK_ERROR_PTR) {
        LOG_ERROR("INKVIOVConnGet");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }
#ifdef DEBUG
      if (INKVConnCacheObjectSizeGet(NULL, &url_len_from_cache) != INK_ERROR) {
        LOG_ERROR_NEG("INKVConnCacheObjectSizeGet(NULL, &size)");
      }

      if (INKVConnCacheObjectSizeGet(connp, NULL) != INK_ERROR) {
        LOG_ERROR_NEG("INKVConnCacheObjectSizeGet(inkvconn, NULL)");
      }
#endif

      if (INKVConnCacheObjectSizeGet(connp, &url_len_from_cache) == INK_ERROR) {
        LOG_ERROR("INKVConnCacheObjectSizeGet");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }

      if (url_len_from_cache != url_data->url_len) {
        LOG_ERROR("INKVConnCacheObjectSizeGet-mismatch");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }

      if ((connp = INKVIOVConnGet(edata)) == INK_ERROR_PTR) {
        LOG_ERROR("INKVIOVConnGet");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }
#ifdef DEBUG
      if (INKVIOVConnGet(NULL) != INK_ERROR_PTR) {
        LOG_ERROR_NEG("INKVIOVConnGet(null)");
      }

      if (INKVConnClose(NULL) != INK_ERROR) {
        LOG_ERROR_NEG("INKVConnClose(NULL)");
      }
#endif

      if (INKVConnClose(connp) == INK_ERROR) {
        LOG_ERROR("INKVConnClose");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }

      url_data = (CACHE_URL_DATA *) INKContDataGet(contp);
      INKReleaseAssert(url_data->magic == MAGIC_ALIVE);

      url_data->bufp_reader = INKIOBufferReaderAlloc(url_data->bufp);
      blk = INKIOBufferReaderStart(url_data->bufp_reader);
      if (blk == INK_ERROR_PTR) {
        LOG_ERROR("INKIOBufferReaderStart");
        INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
        return -1;
      }

      src = (char *) INKIOBufferBlockReadStart(blk, url_data->bufp_reader, &avail);
      /* FC: make sure we do not copy more than MAX_URL_LEN-1 bytes into dst */
      if (avail < 0) {
        avail = 0;
      }
      avail = (avail < MAX_URL_LEN - 1) ? avail : (MAX_URL_LEN - 1);
      strncpy(dst, src, avail);
      dst[avail] = '\0';

      if (strcmp(dst, url_data->url) != 0) {
        INKDebug(DEBUG_TAG, "URL in cache NO_MATCH\ndst=[%s]\nurl=[%s]\n", dst, url_data->url);
      }
    }
    INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);

    break;

  case INK_EVENT_VCONN_WRITE_COMPLETE:
    INKDebug(DEBUG_TAG, "INK_EVENT_VCONN_WRITE_COMPLETE\n");

    if ((connp = INKVIOVConnGet(edata)) == INK_ERROR_PTR) {
      LOG_ERROR("INKVIOVConnGet");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }
#ifdef DEBUG
    if (INKVIOVConnGet(NULL) != INK_ERROR_PTR) {
      LOG_ERROR_NEG("INKVIOVConnGet(null)");
    }

    if (INKVConnClose(NULL) != INK_ERROR) {
      LOG_ERROR_NEG("INKVConnClose(NULL)");
    }
#endif

    if (INKVConnClose(connp) == INK_ERROR) {
      LOG_ERROR("INKVConnClose");
      INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
      return -1;
    }

    INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
    break;

  case INK_EVENT_VCONN_EOS:
    INKDebug(DEBUG_TAG, "INK_EVENT_VCONN_EOS\n");
    break;

  case INK_EVENT_ERROR:
    INKDebug(DEBUG_TAG, "INK_EVENT_ERROR\n");
    INKHttpTxnReenable(url_data->txnp, INK_EVENT_HTTP_CONTINUE);
    break;

  case INK_EVENT_HTTP_TXN_CLOSE:
    INKDebug(DEBUG_TAG, "INK_EVENT_HTTP_TXN_CLOSE\n");

    if (url_data == NULL) {
      INKHttpTxnReenable(edata, INK_EVENT_HTTP_CONTINUE);
      break;
    }

    if (url_data->url != NULL) {
      INKfree(url_data->url);
    }

    if (INKCacheKeyDestroy(url_data->key) == INK_ERROR) {
      LOG_ERROR("INKCacheKeyDestroy");
    }
#ifdef DEBUG
    if (INKCacheKeyDestroy(NULL) != INK_ERROR) {
      LOG_ERROR_NEG("INKCacheKeyDestroy(NULL)");
    }

    if (INKIOBufferDestroy(NULL) != INK_ERROR) {
      LOG_ERROR_NEG("INKIOBufferDestroy(NULL)");
    }
#endif

    if (INKIOBufferDestroy(url_data->bufp) == INK_ERROR) {
      LOG_ERROR("INKIOBufferDestroy");
    }

    url_data->magic = MAGIC_DEAD;
    INKfree(url_data);
    INKContDestroy(contp);
    INKHttpTxnReenable(edata, INK_EVENT_HTTP_CONTINUE);

    break;

  default:
    ;
  }
  return 0;
}
コード例 #12
0
/******************************************************************** 
 * When the client sends the same request the second time, get the
 * header field MY_HDR from the caches response header, print it out
 * and save it in a text file.
 ********************************************************************/
static int
handle_cache_hdr(INKHttpTxn txnp)
{
  LOG_SET_FUNCTION_NAME("handle_cache_hdr");

  INKMBuffer cache_bufp;
  INKMLoc cache_loc = NULL, field_loc = NULL;
  const char *my_hdr;
  int value_count, i, length;
  char output_file[1024], output_str[1024];
  INKFile file;

  output_str[0] = '\0';

  /* get the cached response header */
  if (!INKHttpTxnCachedRespGet(txnp, &cache_bufp, &cache_loc))
    LOG_ERROR_AND_RETURN("INKHttpTxnCachedRespGet");

  /* get the MY_HDR field in the header */
  if ((field_loc = INKMimeHdrFieldFind(cache_bufp, cache_loc, MY_HDR, strlen(MY_HDR))) == INK_ERROR_PTR ||
      field_loc == NULL)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldFind");

  if ((value_count = INKMimeHdrFieldValuesCount(cache_bufp, cache_loc, field_loc)) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValuesCount");
  for (i = 0; i <= value_count - 1; i++) {
    if (INKMimeHdrFieldValueStringGet(cache_bufp, cache_loc, field_loc, i, &my_hdr, &length) == INK_ERROR)
      LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueStringGet");

    /* concatenate the field to output_str */
    if (my_hdr) {
      snprintf(output_str, 1024, "%s MY_HDR(%d): %.*s \n", output_str, i, length, my_hdr);
      INKHandleStringRelease(cache_bufp, field_loc, my_hdr);
    }
  }

  snprintf(output_file, 1024, "%s/write_server_ip.txt", plugin_dir);
  INKDebug(DEBUG_TAG, "Writing record\n%s\nto file %s", output_str, output_file);

  /* append to the text file */
  if (INKMutexLock(file_mutex) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMutexLock");

  if ((file = INKfopen(output_file, "w")) == NULL)
    LOG_ERROR_AND_CLEANUP("INKfopen");
  INKfwrite(file, output_str, strlen(output_str));
  INKfflush(file);
  INKfclose(file);

  if (INKMutexUnlock(file_mutex) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMutexUnlock");

  /* cleanup */
Lcleanup:
  /* release mlocs */
  if (VALID_POINTER(field_loc))
    INKHandleMLocRelease(cache_bufp, cache_loc, field_loc);
  if (VALID_POINTER(cache_loc))
    INKHandleMLocRelease(cache_bufp, INK_NULL_MLOC, cache_loc);

  return 0;
}
コード例 #13
0
static void
handleReadRequest(INKCont pCont, INKHttpTxn pTxn)
{
  LOG_SET_FUNCTION_NAME("handleReadRequest");

  INKMBuffer reqHdrBuf = NULL, newHttpHdrBuf = NULL;
  INKMLoc reqHdrLoc = NULL, newHttpHdrLoc = NULL;

  INKHttpType httpType;

  int iOldHttpVersion, iHttpMethodLength, iHttpVersion;
  const char *sHttpMethod = NULL;
  char *outputString = NULL, *sOldHttpMethod = NULL;

  HdrInfo_T *pReqHdrInfo = NULL, *pNewReqHdrInfo = NULL;

#if 0
  const char *constant_request_header_str =
    "GET http://www.joes-hardware.com/ HTTP/1.0\r\nDate: Wed, 05 Jul 2000 22:12:26 GMT\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.51 [en] (X11; U; IRIX 6.2 IP22)\r\nHost: www.joes-hardware.com\r\nCache-Control: no-cache\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\nAccept-Charset: iso-8859-1,*,utf-8\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nX-Number-Header: 12345\r\nX-Silly-Header: frobnichek grobbledegook\r\nAccept-Charset: windows-1250, koi8-r\r\nX-Silly-Header: wawaaa\r\n\r\n";

#endif


  pReqHdrInfo = initHdr();
  pNewReqHdrInfo = initHdr();

  INKDebug(REQ, "\n>>>>>> handleReadRequest <<<<<<<\n");

  /* Get Request Marshall Buffer */
  if (!INKHttpTxnClientReqGet(pTxn, &reqHdrBuf, &reqHdrLoc)) {
    LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr");
    goto done;
  }


    /******* (1): Get every specifics from the HTTP header *********/

  INKDebug(REQ, "--------------------------------");

  getHdrInfo(pReqHdrInfo, reqHdrBuf, reqHdrLoc);
  printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 1);

#ifdef DEBUG
  negTesting(reqHdrBuf, reqHdrLoc);
#endif

    /*********** (2): Create/Copy/Destroy **********/
  /* For every request, create, copy and destroy a new HTTP header and 
   * print the details */

  INKDebug(REQ, "--------------------------------");
  if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section 3");
    goto section_3;             /* Skip to section (3) down the line directly; I hate GOTOs */
  }

    /*** INKHttpHdrCreate ***/
  if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "skipping to section 3");
    goto section_3;             /* Skip to section (3) down the line directly; I hate GOTOs */
  }

  /* Make sure the newly created HTTP header has INKHttpType value of INK_HTTP_TYPE_UNKNOWN */
  if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "but still continuing...");
  } else if (httpType != INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN");
  }

  /* set the HTTP header type: a new buffer has a type INK_HTTP_TYPE_UNKNOWN by default */
  if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_REQUEST) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeSet", "unable to set it to INK_HTTP_TYPE_REQUEST");
  } else if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKHttpHdrTypeGet", "still continuing");
  } else if (httpType != INK_HTTP_TYPE_REQUEST) {
    LOG_AUTO_ERROR("INKHttpHdrTypeSet", "Type not set to INK_HTTP_TYPE_REQUEST");
  }

    /*** INKHttpHdrCopy ***/
  if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, reqHdrBuf, reqHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }
  getHdrInfo(pNewReqHdrInfo, newHttpHdrBuf, newHttpHdrLoc);

  if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "New req buffer not identical to the original");
  }

  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, REQ, 2);

  FREE(pNewReqHdrInfo->httpMethod);
  FREE(pNewReqHdrInfo->hostName);

section_3:
    /********* (3): Excercise all the INK__Set on ReqBuf *********/
  INKDebug(REQ, "--------------------------------");

    /*** INKHttpHdrMethodSet ***/
  /* save the original method */
  if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrMethodGet");
  } else {
    sOldHttpMethod = INKstrndup(sHttpMethod, iHttpMethodLength);
  }
  /* change it to some unknown method */
  if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, "FOOBAR", strlen("FOOBAR")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrMethodSet");
  } else {
    if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else if (strncmp(sHttpMethod, "FOOBAR", iHttpMethodLength)) {
      LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method");
    }
  }

  outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
  INKDebug(REQ, "(3): new HTTP Header Method = %s", outputString);
  FREE(outputString);
  STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod);

  printHttpHeader(reqHdrBuf, reqHdrLoc, REQ, 3);

  /* set it back to the original method */
  /*INKHttpHdrMethodSet (reqHdrBuf, reqHdrLoc, sOldHttpMethod, iHttpMethodLength); */
  if (INKHttpHdrMethodSet(reqHdrBuf, reqHdrLoc, sOldHttpMethod, strlen(sOldHttpMethod)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrMethodSet");
  } else if ((sHttpMethod = INKHttpHdrMethodGet(reqHdrBuf, reqHdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrMethodGet");
  } else if (strncmp(sHttpMethod, sOldHttpMethod, iHttpMethodLength)) {
    LOG_AUTO_ERROR("INKHttpHdrMethodSet/Get", "GET method different from SET method");
  }

  outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
  INKDebug(REQ, "(3): original HTTP Header Method = %s", outputString);
  FREE(outputString);
  STR_RELEASE(reqHdrBuf, reqHdrLoc, sHttpMethod);


    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if ((INK_HTTP_MAJOR(iHttpVersion) != 10) || (INK_HTTP_MINOR(iHttpVersion) != 10)) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version");
  }

  INKDebug(REQ, "(3): new HTTP version; Major = %d   Minor = %d",
           INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion));

  /* change it back to the original version */
  if (INKHttpHdrVersionSet(reqHdrBuf, reqHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iHttpVersion = INKHttpHdrVersionGet(reqHdrBuf, reqHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (iHttpVersion != iOldHttpVersion) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet/Get", "SET HTTP version different from GET version");
  }

  getHdrInfo(pNewReqHdrInfo, reqHdrBuf, reqHdrLoc);
  if (!identical_hdr(pNewReqHdrInfo, pReqHdrInfo)) {
    LOG_AUTO_ERROR("INK..Set", "ReqBuf: Values not restored properly");
  }

  /* (3): clean-up */
  FREE(sOldHttpMethod);

done:
    /*************** Clean-up ***********************/
  /*
     FREE(pReqHdrInfo->httpMethod);
     FREE(pReqHdrInfo->hostName);

     FREE(pNewReqHdrInfo->httpMethod);
     FREE(pNewReqHdrInfo->hostName);

     FREE(pReqHdrInfo);
     FREE(pNewReqHdrInfo);
   */
  freeHdr(pReqHdrInfo);
  freeHdr(pNewReqHdrInfo);

  /* release hdrLoc */
  HANDLE_RELEASE(reqHdrBuf, INK_NULL_MLOC, reqHdrLoc);
  HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc);

  /* destroy hdr */
  HDR_DESTROY(newHttpHdrBuf, newHttpHdrLoc);

  /* destroy mbuffer */
  BUFFER_DESTROY(newHttpHdrBuf);


  if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpTxnReenable");
  }
  INKDebug(REQ, "..... exiting handleReadRequest ......\n");

}                               /* handleReadReadRequest */
コード例 #14
0
static void
handleSendResponse(INKCont pCont, INKHttpTxn pTxn)
{
  LOG_SET_FUNCTION_NAME("handleSendResponse");

  INKMBuffer respHdrBuf = NULL, newHttpHdrBuf = NULL, parseBuffer = NULL;
  INKMLoc respHttpHdrLoc = NULL, newHttpHdrLoc = NULL, parseHttpHdrLoc = NULL;

  INKHttpStatus oldHttpStatus, tmpHttpStatus;
  INKHttpType httpType;
  INKHttpParser httpRespParser = NULL;

  HdrInfo_T *pRespHdrInfo = NULL, *pNewRespHdrInfo = NULL;

  int iHttpHdrReasonLength, iOldHttpVersion, iTmpHttpVersion, iTmpHttpHdrReasonLength;
  const char *sHttpHdrReason = NULL, *sTmpHttpHdrReason = NULL, *pHttpParseStart = NULL, *pHttpParseEnd = NULL;
  char *sOldHttpReason = NULL;

  const char *sRespHdrStr1 =
    "HTTP/1.1 200 OK\r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun14 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";

  const char *sRespHdrStr2 =
    "HTTP/1.1 404 Not Found \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun24 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";

  const char *sRespHdrStr3 =
    "HTTP/1.1 505 HTTP Version Not Supported \r\nServer: Netscape-Enterprise/4.1\r\nDate: Tue, 31 Oct 2000 03:38:19 GMT\r\nContent-type: text/html\r\nAge: 3476\r\nContent-Length: 12440\r\nVia: HTTP/1.1 ts-sun34 (Traffic-Server/4.0.0 [cHs f ])\r\n\r\n";



  pRespHdrInfo = initHdr();
  pNewRespHdrInfo = initHdr();

  INKDebug(RESP, ">>> handleSendResponse <<<<\n");

  /* Get Response Marshall Buffer */
  if (!INKHttpTxnClientRespGet(pTxn, &respHdrBuf, &respHttpHdrLoc)) {
    LOG_API_ERROR_COMMENT("INKHttpTxnClientReqGet", "ERROR: Can't retrieve client req hdr");
    goto done;
  }

#ifdef DEBUG
  negTesting(respHdrBuf, respHttpHdrLoc);
#endif

    /******* (1): Exercise all possible INK*GET and print the values **********/

  INKDebug(RESP, "--------------------------------");
  getHdrInfo(pRespHdrInfo, respHdrBuf, respHttpHdrLoc);
  printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 1);

    /******* (2): Create a new header and check everything is copied correctly *********/

  INKDebug(RESP, "--------------------------------");

  if ((newHttpHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "skipping to section(4)");
    goto resp_4;
  }

    /*** INKHttpHdrCreate ***/
  if ((newHttpHdrLoc = INKHttpHdrCreate(newHttpHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR_COMMENT("INKMHTTPHdrCreate", "skipping to section(4)");
    goto resp_4;
  }

  /* Make sure the newly created HTTP header has INKHttpType value of INK_HTTP_TYPE_UNKNOWN */
  if ((httpType = INKHttpHdrTypeGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR_COMMENT("INKMHTTPHdrCreate", "continuing");
  } else if (httpType != INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrCreate", "Newly created hdr not of type INK_HTTP_TYPE_UNKNOWN");
  }


    /*** INKHttpHdrCopy ***/
  if (INKHttpHdrCopy(newHttpHdrBuf, newHttpHdrLoc, respHdrBuf, respHttpHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }

  getHdrInfo(pNewRespHdrInfo, newHttpHdrBuf, newHttpHdrLoc);
  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 2);

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INKHttpHdrCopy", "copy of the resp header not identical to the original");
  }

  /* Reuse:
   * newHttpHdrBuf, newHttHdrLoc */

    /******* (3): Now excercise some INK..SETs on the new header ********/
  INKDebug(RESP, "--------------------------------");

    /*** INKHttpHdrTypeSet ***/
  /* ERROR: 
   * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, 
   * INK_HTTP_TYPE_RESPONSE, and,
   * 2. Setting the type twice.  The hdr type has been already set during INKHttpHdrCopy 
   * above, so setting it again is incorrect */
  if (INKHttpHdrTypeSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeSet");
  }

    /*** INKHttpHdrReasonSet ***/
  /* save the original reason */
  if ((sHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
  }

  /* Note: 
   * INKHttpHdrReasonGet may return a NULL reason string (for e.g. I tried www.eyesong.8m.com).
   * Do NOT assume that INKstrndup always returns a null terminated string.  INKstrndup does 
   * not returns a NULL terminated string for a NULL ptr as i/p parameter.  It simply returns 
   * it backs. So functions like strlen() on the return value might cause TS to crash */


  if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(newHttpHdrBuf, newHttpHdrLoc, &iTmpHttpHdrReasonLength))
        == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) {
      LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason different from the SET reason");
    }
    STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sTmpHttpHdrReason);
  }

    /*** INKHttpStatusSet ***/
  /* save the original value */
  if ((oldHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  }

  /* change it to some unknown value */
  if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  } else if ((tmpHttpStatus = INKHttpHdrStatusGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  } else if (tmpHttpStatus != INK_HTTP_STATUS_NONE) {
    LOG_AUTO_ERROR("INKHttpHdrStatusGet/Set", "GET status different from the SET status");
  }


    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(newHttpHdrBuf, newHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) {
    LOG_AUTO_ERROR("INKHttpHdrVersionSet", "GET version different from SET version");
  }

  printHttpHeader(newHttpHdrBuf, newHttpHdrLoc, RESP, 3);

  /* Restore the original values */

  /* Here we can't use strlen(sOldHttpReason) to set the length.  This would crash TS if 
   * sOldHttpReason happens to be NULL */
  if (INKHttpHdrReasonSet(newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }
  /*INKHttpHdrReasonSet (newHttpHdrBuf, newHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */
  if (INKHttpHdrStatusSet(newHttpHdrBuf, newHttpHdrLoc, oldHttpStatus) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }
  if (INKHttpHdrVersionSet(newHttpHdrBuf, newHttpHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored");
  }

  /* (3): clean-up */
  STR_RELEASE(newHttpHdrBuf, newHttpHdrLoc, sHttpHdrReason);
  FREE(sOldHttpReason);

resp_4:
    /******* (4): Now excercise some SETs on the response header ********/
  INKDebug(RESP, "--------------------------------");

    /*** INKHttpHdrReasonSet ***/
  /* save the original reason */
  if ((sHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else {
    sOldHttpReason = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
  }

  /* change the reason phrase */
  if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, "dummy reason", strlen("dummy reason")) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }

  if ((sTmpHttpHdrReason = INKHttpHdrReasonGet(respHdrBuf, respHttpHdrLoc, &iTmpHttpHdrReasonLength))
      == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrReasonGet");
  } else if (sTmpHttpHdrReason && strncmp(sTmpHttpHdrReason, "dummy reason", iTmpHttpHdrReasonLength)) {
    LOG_AUTO_ERROR("INKHttpHdrReasonSet/Get", "GET reason string different from SET reason");
  }
  STR_RELEASE(respHdrBuf, respHttpHdrLoc, sTmpHttpHdrReason);

    /*** INKHttpStatusSet ***/
  /* save the original value */
  if ((oldHttpStatus = INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusGet");
  }

  /* change it to some unknown value */
  if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_STATUS_NONE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  } else if (INKHttpHdrStatusGet(respHdrBuf, respHttpHdrLoc) != INK_HTTP_STATUS_NONE) {
    LOG_AUTO_ERROR("INKHttpHdrStatusSet/GET", "GET status value different from SET status");
  }


    /*** INKHttpHdrTypeSet ***/
  /* ERROR: 
   * 1. Setting type other than INK_HTTP_TYPE_UNKNOWN, INK_HTTP_TYPE_REQUEST, 
   * INK_HTTP_TYPE_RESPONSE and,
   * 2. Setting the type twice.  The hdr type has been already set during INKHttpTxnClientRespGet
   * above, so setting it again should fail */
  if (INKHttpHdrTypeSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeGet(respHdrBuf, respHttpHdrLoc) == INK_HTTP_TYPE_UNKNOWN) {
    LOG_AUTO_ERROR("INKHttpHdrTypeSet/Get", "respHdrBuf CAN be set to INK_HTTP_TYPE_UNKNOWN");
  }

    /*** INKHttpHdrVersionSet ***/
  /* get the original version */
  if ((iOldHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }

  /* change it to some unknown version */
  if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, INK_HTTP_VERSION(10, 10)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  } else if ((iTmpHttpVersion = INKHttpHdrVersionGet(respHdrBuf, respHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  } else if (INK_HTTP_MAJOR(iTmpHttpVersion) != 10 && INK_HTTP_MINOR(iTmpHttpVersion) != 10) {
    LOG_AUTO_ERROR("INKHttpHdrVersionGet/Set", "GET HTTP version different from SET version");
  }

  printHttpHeader(respHdrBuf, respHttpHdrLoc, RESP, 4);

  /* restore the original values */

  /* For INKHttpHdrReasonSet, do NOT use strlen(sOldHttpReason) to set the length.  
   * This would crash TS if sOldHttpReason happened to be NULL */
  if (INKHttpHdrReasonSet(respHdrBuf, respHttpHdrLoc, sOldHttpReason, iHttpHdrReasonLength) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrReasonSet");
  }
  /*INKHttpHdrReasonSet (respHdrBuf, respHttpHdrLoc, sOldHttpReason, strlen(sOldHttpReason)); */
  if (INKHttpHdrStatusSet(respHdrBuf, respHttpHdrLoc, oldHttpStatus) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrStatusSet");
  }
  if (INKHttpHdrVersionSet(respHdrBuf, respHttpHdrLoc, iOldHttpVersion) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionSet");
  }

  FREE(pNewRespHdrInfo->hdrReason);
  getHdrInfo(pNewRespHdrInfo, respHdrBuf, respHttpHdrLoc);

  if (!identical_hdr(pRespHdrInfo, pNewRespHdrInfo)) {
    LOG_AUTO_ERROR("INK..SET", "Hdr values not properly restored");
  }

  /* (4): clean-up */
  STR_RELEASE(respHdrBuf, respHttpHdrLoc, sHttpHdrReason);
  FREE(sOldHttpReason);

    /********************************/
    /** (5): INKHttpHdrParseResp   **/
    /********************************/

  INKDebug(RESP, "--------------------------------");

  /* Create a parser Buffer and header location */
  if ((parseBuffer = INKMBufferCreate()) == INK_ERROR_PTR || parseBuffer == NULL) {
    LOG_API_ERROR_COMMENT("INKMBufferCreate", "abnormal exit");
    goto done;
  } else if ((parseHttpHdrLoc = INKHttpHdrCreate(parseBuffer)) == INK_ERROR_PTR || parseHttpHdrLoc == NULL) {
    LOG_API_ERROR_COMMENT("INKHttpHdrCreate", "abnormal exit");
    goto done;
  }

  pHttpParseStart = sRespHdrStr1;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  httpRespParser = INKHttpParserCreate();

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.1);

  if (INKHttpParserClear(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParseClear");
  }

  INKDebug(RESP, "--------------------------------");

  pHttpParseStart = sRespHdrStr2;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  /* httpRespParser = INKHttpParserCreate(); */

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.2);

  if (INKHttpParserClear(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParseClear");
  }

  INKDebug(RESP, "--------------------------------");

  pHttpParseStart = sRespHdrStr3;
  pHttpParseEnd = pHttpParseStart + strlen(pHttpParseStart);

  /* httpRespParser = INKHttpParserCreate(); */

  if (INKHttpHdrParseResp(httpRespParser, parseBuffer, parseHttpHdrLoc, &pHttpParseStart, pHttpParseEnd)
      == INK_PARSE_ERROR) {
    LOG_API_ERROR("INKHttpHdrParseResp");
  }

  printHttpHeader(parseBuffer, parseHttpHdrLoc, RESP, 5.3);


done:
  /* Clean-up */
  freeHdr(pRespHdrInfo);
  freeHdr(pNewRespHdrInfo);

  /* release hdrLoc */
  HANDLE_RELEASE(respHdrBuf, INK_NULL_MLOC, respHttpHdrLoc);
  HANDLE_RELEASE(newHttpHdrBuf, INK_NULL_MLOC, newHttpHdrLoc);
  HANDLE_RELEASE(parseBuffer, INK_NULL_MLOC, parseHttpHdrLoc);

  /* destroy hdrLoc */
  HDR_DESTROY(respHdrBuf, respHttpHdrLoc);
  HDR_DESTROY(parseBuffer, parseHttpHdrLoc);

  /* destroy mbuffer */
  BUFFER_DESTROY(newHttpHdrBuf);
  BUFFER_DESTROY(parseBuffer);

  /* destroy the parser */
  if (INKHttpParserDestroy(httpRespParser) == INK_ERROR) {
    LOG_API_ERROR("INKHttpParserDestroy");
  }

  if (INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE) == INK_ERROR) {
    LOG_API_ERROR("INKHttpTxnReenable");
  }

  INKDebug(RESP, "......... exiting handleRespResponse .............\n");

}                               /* handleSendResponse */
コード例 #15
0
static void
printHttpHeader(INKMBuffer hdrBuf, INKMLoc hdrLoc, char *debugTag, float section)
{
  LOG_SET_FUNCTION_NAME("printHttpHeader");

  INKMLoc urlLoc = NULL;

  INKHttpStatus httpStatus;
  INKHttpType httpType;

  int iHostLength, iHttpHdrLength, iHttpMethodLength, iHttpHdrReasonLength, iHttpVersion;
  const char *sHostName = NULL, *sHttpMethod = NULL, *sHttpHdrReason = NULL;
  char *outputString = NULL;


    /*** INKHttpHdrTypeGet ***/
  if ((httpType = INKHttpHdrTypeGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Type = %d", section, httpType);

    /*** INKHttpHdrLengthGet ***/
  if ((iHttpHdrLength = INKHttpHdrLengthGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrLengthGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Length = %d", section, iHttpHdrLength);

    /*** INKHttpVersionGet ***/
  if ((iHttpVersion = INKHttpHdrVersionGet(hdrBuf, hdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrVersionGet");
  }
  INKDebug(debugTag, "(%g) HTTP Header Version = %d", section, iHttpVersion);
  INKDebug(debugTag, "(%g) Major Version = %d, Minor Version = %d", section,
           INK_HTTP_MAJOR(iHttpVersion), INK_HTTP_MINOR(iHttpVersion));


  if (httpType == INK_HTTP_TYPE_REQUEST) {
        /*** INKHttpHdrMethodGet ***/
    if ((sHttpMethod = INKHttpHdrMethodGet(hdrBuf, hdrLoc, &iHttpMethodLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrMethodGet");
    } else {
      outputString = INKstrndup(sHttpMethod, iHttpMethodLength);
      INKDebug(debugTag, "(%g) HTTP Header Method = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, urlLoc, sHttpMethod);
    }

        /*** INKHttpHdrUrlGet ***/
    if ((urlLoc = INKHttpHdrUrlGet(hdrBuf, hdrLoc)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrUrlGet");
    } else if ((sHostName = INKUrlHostGet(hdrBuf, urlLoc, &iHostLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKUrlHostGet");
    } else if (sHostName) {
      outputString = INKstrndup(sHostName, iHostLength);
      INKDebug(debugTag, "(%g) HTTP Host = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, urlLoc, sHostName);
    }

    /* Clean-up */
    HANDLE_RELEASE(hdrBuf, hdrLoc, urlLoc);

  } else if (httpType == INK_HTTP_TYPE_RESPONSE) {

        /*** INKHttpHdrReasonGet ***/
    /* Try getting reason phrase from the request header - this is an error */
    if ((sHttpHdrReason = INKHttpHdrReasonGet(hdrBuf, hdrLoc, &iHttpHdrReasonLength)) == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    } else {
      outputString = INKstrndup(sHttpHdrReason, iHttpHdrReasonLength);
      INKDebug(debugTag, "(%g) HTTP Header Reason = %s", section, outputString);
      FREE(outputString);
      STR_RELEASE(hdrBuf, hdrLoc, sHttpHdrReason);
    }

        /*** INKHttpHdrStatusGet ***/
    /* Try getting status phrase from the request header - this is an error */
    if ((httpStatus = INKHttpHdrStatusGet(hdrBuf, hdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    } else {
      INKDebug(debugTag, "(%g) HTTP Header Status = %d", section, httpStatus);
    }
  }
}
コード例 #16
0
int
insert_in_response(INKHttpTxn txnp, char *result_val)
{
  INKMBuffer resp_bufp;
  INKMLoc resp_loc;
  INKMLoc field_loc;

  LOG_SET_FUNCTION_NAME("insert_in_response");

#ifdef DEBUG
  if (INKHttpTxnClientRespGet(NULL, &resp_bufp, &resp_loc) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientRespGet(null, buf, hdr_loc)");
  }

  if (INKHttpTxnClientRespGet(txnp, NULL, &resp_loc) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientRespGet(txnp, null, hdr_loc)");
  }

  if (INKHttpTxnClientRespGet(txnp, &resp_bufp, NULL) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientRespGet(txnp, buf, null)");
  }
#endif

  if (!INKHttpTxnClientRespGet(txnp, &resp_bufp, &resp_loc)) {
    LOG_ERROR_AND_RETURN("INKHttpTxnClientRespGet");
  }

  /* create a new field in the response header */
  if ((field_loc = INKMimeHdrFieldCreate(resp_bufp, resp_loc)) == INK_ERROR_PTR) {
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldCreate");
  }

  /* set its name */
  if (INKMimeHdrFieldNameSet(resp_bufp, resp_loc, field_loc, "CacheTester-Result", 18) == INK_ERROR) {
    INKHandleMLocRelease(resp_bufp, resp_loc, field_loc);
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldNameSet");
  }

  /* set its value */
  if (INKMimeHdrFieldValueStringInsert(resp_bufp, resp_loc, field_loc, -1, result_val, strlen(result_val)) == INK_ERROR) {
    INKHandleMLocRelease(resp_bufp, resp_loc, field_loc);
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldValueIntInsert");
  }

  /* insert it into the header */
  if (INKMimeHdrFieldAppend(resp_bufp, resp_loc, field_loc) == INK_ERROR) {
    INKHandleMLocRelease(resp_bufp, resp_loc, field_loc);
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldAppend");
  }

  if (INKHandleMLocRelease(resp_bufp, resp_loc, field_loc) == INK_ERROR) {
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);
    LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
  }

  if (INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc) == INK_ERROR) {
    LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
  }

  return 1;
}
コード例 #17
0
/***********************************************************************
 * Get the server ip and request method in the client request. Get the 
 * next hop ip from the server response. 
 * Create a new http header field MY_HDR in the server response and 
 * insert server ip, request method and next hop ip into the field as
 * field values.
 ***********************************************************************/
static int
handle_response_hdr(INKCont contp, INKHttpTxn txnp)
{
  LOG_SET_FUNCTION_NAME("handle_response_hdr");

  INKMBuffer resp_bufp;
  INKMLoc resp_loc = NULL;
  INKMLoc field_loc = NULL;
  unsigned int next_hop_ip = 0;
  unsigned int server_ip = 0;
  const char *request_method = NULL;
  char *r_method = NULL;
  int length;
  INKMBuffer req_bufp;
  INKMLoc req_loc = NULL;
  int incoming_port = 0, port = 0;
  char *hostname = NULL;
  int ret_value = -1;

  /* negative test */
#ifdef DEBUG
  if (INKHttpTxnServerIPGet(NULL) != 0)
    LOG_ERROR_NEG("INKHttpTxnServerIPGet");
  if (INKHttpTxnNextHopIPGet(NULL) != 0)
    LOG_ERROR_NEG("INKHttpTxnNextHopIPGet");
  if (INKHttpTxnParentProxyGet(NULL, &hostname, &port) != INK_ERROR)
    LOG_ERROR_NEG("INKHttpTxnParentProxyGet");
#endif

  /* get the server ip */
  if ((server_ip = INKHttpTxnServerIPGet(txnp)) == 0)
    LOG_ERROR_AND_RETURN("INKHttpTxnServerIPGet");

  /* get the request method */
  if (!INKHttpTxnServerReqGet(txnp, &req_bufp, &req_loc))
    LOG_ERROR_AND_RETURN("INKHttpTxnServerReqGet");

  if ((request_method = INKHttpHdrMethodGet(req_bufp, req_loc, &length)) == INK_ERROR_PTR || request_method == NULL)
    LOG_ERROR_AND_CLEANUP("INKHttpHdrMethodGet");

  r_method = INKstrndup(request_method, length);


  /* get the next hop ip */
  if ((next_hop_ip = INKHttpTxnNextHopIPGet(txnp)) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKHttpTxnNextHopIPGet");


  /* get the client incoming port */
  if ((incoming_port = INKHttpTxnClientIncomingPortGet(txnp)) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKHttpTxnClientIncomingPortGet");


  /* get the parent proxy */
  if (INKHttpTxnParentProxyGet(txnp, &hostname, &port) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKHttpTxnParentProxyGet");
  /* If no parent defined in records.config, set hostname to NULL and port to -1 */
  if (hostname == NULL) {
    hostname = "NULL";
    port = -1;
  }

  /* retrieve the server response header */
  if (!INKHttpTxnServerRespGet(txnp, &resp_bufp, &resp_loc))
    LOG_ERROR_AND_CLEANUP("INKHttpTxnServerRespGet");


  /* create and insert into hdr a new mime header field */
  if ((field_loc = INKMimeHdrFieldCreate(resp_bufp, resp_loc)) == INK_ERROR_PTR || field_loc == NULL)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldCreate");
  if (INKMimeHdrFieldAppend(resp_bufp, resp_loc, field_loc) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldAppend");
  if (INKMimeHdrFieldNameSet(resp_bufp, resp_loc, field_loc, MY_HDR, strlen(MY_HDR)) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldNameSet");

  /* Add value to the new mime header field */
  if (INKMimeHdrFieldValueStringInsert(resp_bufp, resp_loc, field_loc, -1, r_method, strlen(r_method)) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueStringInsert");
  if (INKMimeHdrFieldValueUintInsert(resp_bufp, resp_loc, field_loc, -1, server_ip) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueUintInsert");
  if (INKMimeHdrFieldValueUintInsert(resp_bufp, resp_loc, field_loc, -1, next_hop_ip) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueUintInsert");
  if (INKMimeHdrFieldValueIntInsert(resp_bufp, resp_loc, field_loc, -1, incoming_port) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueIntInsert");
  if (INKMimeHdrFieldValueIntInsert(resp_bufp, resp_loc, field_loc, -1, port) == INK_ERROR)
    LOG_ERROR_AND_CLEANUP("INKMimeHdrFieldValueIntInsert");

  /* success */
  ret_value = 0;

Lcleanup:
  if (VALID_POINTER(r_method))
    INKfree(r_method);

  /* negative test for INKHandleStringRelease */
#ifdef DEBUG
  if (INKHandleStringRelease(NULL, req_loc, request_method) != INK_ERROR) {
    LOG_ERROR_NEG("INKHandleStringRelease");
  }
#endif

  /* release the buffer handles */
  if (VALID_POINTER(request_method))
    INKHandleStringRelease(req_bufp, req_loc, request_method);
  if (VALID_POINTER(req_loc))
    INKHandleMLocRelease(req_bufp, INK_NULL_MLOC, req_loc);

  /* free the handles and continuation data */
  if (VALID_POINTER(field_loc))
    INKHandleMLocRelease(resp_bufp, resp_loc, field_loc);
  if (VALID_POINTER(resp_loc))
    INKHandleMLocRelease(resp_bufp, INK_NULL_MLOC, resp_loc);

  return ret_value;
}
コード例 #18
0
int
get_client_req(INKHttpTxn txnp, char **p_url_line, char **p_client_req, int *neg_test_val, int *pin_val)
{
  INKMBuffer bufp;
  INKReturnCode ret_code;
  INKMLoc hdr_loc;
  INKMLoc url_loc;
  INKMLoc neg_loc;
  INKMLoc pin_loc;

  INKIOBuffer output_buffer;
  INKIOBufferReader reader;
  int total_avail;

  INKIOBufferBlock block;
  const char *block_start;
  int block_avail;

  char *output_string;
  char *url_str;
  int url_len;
  int output_len;

  LOG_SET_FUNCTION_NAME("get_client_req");

  *p_url_line = NULL;
  *p_client_req = NULL;
  *neg_test_val = 0;
  *pin_val = 0;

#ifdef DEBUG
  if (INKHttpTxnClientReqGet(NULL, &bufp, &hdr_loc) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientReqGet(null, buf, hdr_loc)");
  }

  if (INKHttpTxnClientReqGet(txnp, NULL, &hdr_loc) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientReqGet(txnp, null, hdr_loc)");
  }

  if (INKHttpTxnClientReqGet(txnp, &bufp, NULL) != 0) {
    LOG_ERROR_NEG("INKHttpTxnClientReqGet(txnp, buf, null)");
  }
#endif

  if (!INKHttpTxnClientReqGet(txnp, &bufp, &hdr_loc)) {
    LOG_ERROR_AND_RETURN("INKHttpTxnClientReqGet");
  }

  if ((url_loc = INKHttpHdrUrlGet(bufp, hdr_loc)) == INK_ERROR_PTR) {
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    LOG_ERROR_AND_RETURN("INKHttpHdrUrlGet");
  }
#ifdef DEBUG
  if (INKUrlStringGet(NULL, url_loc, &url_len) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKUrlStringGet(NULL, url_loc, &int)");
  }

  if (INKUrlStringGet(bufp, NULL, &url_len) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKUrlStringGet(bufp, NULL, &int)");
  }
#endif

  if ((url_str = INKUrlStringGet(bufp, url_loc, &url_len)) == INK_ERROR_PTR) {
    INKHandleMLocRelease(bufp, hdr_loc, url_loc);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    LOG_ERROR_AND_RETURN("INKUrlStringGet");
  }

  if (INKHandleMLocRelease(bufp, hdr_loc, url_loc) == INK_ERROR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
  }

  url_str[url_len] = '\0';
  *p_url_line = url_str;

  if ((output_buffer = INKIOBufferCreate()) == INK_ERROR_PTR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    LOG_ERROR_AND_RETURN("INKIOBufferCreate");
  }
#ifdef DEBUG
  if (INKIOBufferReaderAlloc(NULL) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKIOBufferReaderAlloc(NULL)");
  }
#endif

  if ((reader = INKIOBufferReaderAlloc(output_buffer)) == INK_ERROR_PTR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKIOBufferReaderAlloc");
  }

  /* This will print  just MIMEFields and not
     the http request line */
  if (INKMimeHdrPrint(bufp, hdr_loc, output_buffer) == INK_ERROR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKMimeHdrPrint");
  }

  if ((neg_loc = INKMimeHdrFieldFind(bufp, hdr_loc, "CacheTester-HostNameSet", -1)) == INK_ERROR_PTR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldFind");
  }

  if (neg_loc != NULL) {

    ret_code = INKMimeHdrFieldValueIntGet(bufp, hdr_loc, neg_loc, 0, neg_test_val);
    if (ret_code == INK_ERROR) {
      INKfree(url_str);
      INKHandleMLocRelease(bufp, hdr_loc, neg_loc);
      INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
      INKIOBufferDestroy(output_buffer);
      LOG_ERROR_AND_RETURN("INKMimeHdrFieldValueIntGet");
    }

    if (INKHandleMLocRelease(bufp, hdr_loc, neg_loc) == INK_ERROR) {
      INKfree(url_str);
      INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
      INKIOBufferDestroy(output_buffer);
      LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
    }
  }

  if ((pin_loc = INKMimeHdrFieldFind(bufp, hdr_loc, "CacheTester-Pin", -1)) == INK_ERROR_PTR) {
    INKfree(url_str);
    INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKMimeHdrFieldFind");
  }

  if (pin_loc != NULL) {

    ret_code = INKMimeHdrFieldValueIntGet(bufp, hdr_loc, pin_loc, 0, pin_val);
    if (ret_code == INK_ERROR) {
      INKfree(url_str);
      INKHandleMLocRelease(bufp, hdr_loc, pin_loc);
      INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
      INKIOBufferDestroy(output_buffer);
      LOG_ERROR_AND_RETURN("INKMimeHdrFieldValueIntGet");
    }

    if (INKHandleMLocRelease(bufp, hdr_loc, pin_loc) == INK_ERROR) {
      INKfree(url_str);
      INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc);
      INKIOBufferDestroy(output_buffer);
      LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
    }
  }

  if (INKHandleMLocRelease(bufp, INK_NULL_MLOC, hdr_loc) == INK_ERROR) {
    INKfree(url_str);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKHandleMLocRelease");
  }

  /* Find out how the big the complete header is by
     seeing the total bytes in the buffer.  We need to
     look at the buffer rather than the first block to
     see the size of the entire header */
  if ((total_avail = INKIOBufferReaderAvail(reader)) == INK_ERROR) {
    INKfree(url_str);
    INKIOBufferDestroy(output_buffer);
    LOG_ERROR_AND_RETURN("INKIOBufferReaderAvail");
  }
#ifdef DEBUG
  if (INKIOBufferReaderAvail(NULL) != INK_ERROR) {
    LOG_ERROR_NEG("INKIOBufferReaderAvail(NULL)");
  }
#endif

  /* Allocate the string with an extra byte for the string
     terminator */
  output_string = (char *) INKmalloc(total_avail + 1);
  output_len = 0;

  /* We need to loop over all the buffer blocks to make
     sure we get the complete header since the header can
     be in multiple blocks */
  block = INKIOBufferReaderStart(reader);

  if (block == INK_ERROR_PTR) {
    INKfree(url_str);
    INKfree(output_string);
    LOG_ERROR_AND_RETURN("INKIOBufferReaderStart");
  }
#ifdef DEBUG
  if (INKIOBufferReaderStart(NULL) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKIOBufferReaderStart(NULL)");
  }

  if (INKIOBufferBlockReadStart(NULL, reader, &block_avail) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKIOBufferBlockReadStart(null, reader, &int)");
  }

  if (INKIOBufferBlockReadStart(block, NULL, &block_avail) != INK_ERROR_PTR) {
    LOG_ERROR_NEG("INKIOBufferBlockReadStart(block, null, &int)");
  }
#endif

  while (block) {

    block_start = INKIOBufferBlockReadStart(block, reader, &block_avail);

    if (block_start == INK_ERROR_PTR) {
      INKfree(url_str);
      INKfree(output_string);
      LOG_ERROR_AND_RETURN("INKIOBufferBlockReadStart");
    }

    /* FC paranoia: make sure we don't copy more bytes than buffer size can handle */
    if ((output_len + block_avail) > total_avail) {
      INKfree(url_str);
      INKfree(output_string);
      LOG_ERROR_AND_RETURN("More bytes than expected in IOBuffer");
    }

    /* We'll get a block pointer back even if there is no data
       left to read so check for this condition and break out of
       the loop. A block with no data to read means we've exhausted
       buffer of data since if there was more data on a later 
       block in the chain, this block would have been skipped over */
    if (block_avail == 0) {
      break;
    }

    memcpy(output_string + output_len, block_start, block_avail);
    output_len += block_avail;

    /* Consume the data so that we get to the next block */
    if (INKIOBufferReaderConsume(reader, block_avail) == INK_ERROR) {
      INKfree(url_str);
      INKfree(output_string);
      LOG_ERROR_AND_RETURN("INKIOBufferReaderConsume");
    }
#ifdef DEBUG
    if (INKIOBufferReaderConsume(NULL, block_avail) != INK_ERROR) {
      LOG_ERROR_NEG("INKIOBufferReaderConsume(null, int)");
    }

    if (INKIOBufferReaderConsume(reader, -1) != INK_ERROR) {
      LOG_ERROR_NEG("INKIOBufferReaderConsume(reader, -1)");
    }
#endif

    /* Get the next block now that we've consumed the
       data off the last block */
    if ((block = INKIOBufferReaderStart(reader)) == INK_ERROR_PTR) {
      INKfree(url_str);
      INKfree(output_string);
      LOG_ERROR_AND_RETURN("INKIOBufferReaderStart");
    }
  }

  /* Terminate the string */
  output_string[output_len] = '\0';
  /*output_len++; */

  /* Free up the INKIOBuffer that we used to print out the header */
  if (INKIOBufferReaderFree(reader) == INK_ERROR) {
    INKfree(url_str);
    INKfree(output_string);
    LOG_ERROR_AND_RETURN("INKIOBufferReaderFree");
  }
#ifdef DEBUG
  if (INKIOBufferReaderFree(NULL) != INK_ERROR) {
    LOG_ERROR_NEG("INKIOBufferReaderFree(NULL)");
  }
#endif

  if (INKIOBufferDestroy(output_buffer) == INK_ERROR) {
    INKfree(url_str);
    INKfree(output_string);
    LOG_ERROR_AND_RETURN("INKIOBufferDestroy");
  }

  *p_client_req = output_string;
  return 1;
}
コード例 #19
0
void
negTesting(INKMBuffer hdrBuf, INKMLoc httpHdrLoc)
{
  LOG_SET_FUNCTION_NAME("negTesting");

  INKMBuffer negHdrBuf = NULL;
  INKMLoc negHttpHdrLoc = NULL;

  INKHttpType negType, hdrHttpType;
  INKHttpStatus httpStatus;

  const char *sHttpReason = NULL;
  int iHttpMethodLength, iHttpHdrReasonLength;

  /* INKMBufferCreate: Nothing to neg test */

  /* INKMBufferDestroy */
  if (INKMBufferDestroy(NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKMBufferDestroy");
  }

  /* INKHttpHdrCreate */
  if (INKHttpHdrCreate(NULL) != INK_ERROR_PTR) {
    LOG_NEG_ERROR("INKHttpHdrCreate");
  }

  /* INKHttpHdrCopy */
  /* Copy w/o creating the hdrBuf and httpHdrLoc */
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }

  /* valid create */
  if ((negHdrBuf = INKMBufferCreate()) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKHttpHdrCreate");
  }
  if ((negHttpHdrLoc = INKHttpHdrCreate(negHdrBuf)) == INK_ERROR_PTR) {
    LOG_API_ERROR("INKMHttpHdrCreate");
  }

  if (INKHttpHdrCopy(NULL, negHttpHdrLoc, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, NULL, hdrBuf, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, NULL, httpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrCopy");
  }

  /* INKHttpHdrTypeSet */
  /* Docs - INKHttpHdrTypeSet should NOT be called after INKHttpHdrCopy */
  /* Try some incorrect (but valid int type) arguments */
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 10) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, -1) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }

  if (INKHttpHdrTypeSet(NULL, negHttpHdrLoc, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  if (INKHttpHdrTypeSet(negHdrBuf, NULL, INK_HTTP_TYPE_RESPONSE) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }
  /* INKqa12708 */
  if (INKHttpHdrTypeSet(negHdrBuf, negHttpHdrLoc, 100) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeSet");
  }


  /* INKHtttpHdrTypeGet */
  if ((negType = INKHttpHdrTypeGet(NULL, negHttpHdrLoc)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeGet");
  }
  if ((negType = INKHttpHdrTypeGet(negHdrBuf, NULL)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrTypeGet");
  }

  /* INKHttpHdrVersionGet */
  if (INKHttpHdrVersionGet(NULL, negHttpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionGet");
  }
  if (INKHttpHdrVersionGet(negHdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionGet");
  }

  /* INKHttpHdrVersionSet */
  if (INKHttpHdrVersionSet(NULL, negHttpHdrLoc, INK_HTTP_VERSION(1, 1)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  if (INKHttpHdrVersionSet(negHdrBuf, NULL, INK_HTTP_VERSION(1, 1)) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  /* Try some incorrect (but valid int type) arguments */
  if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, 0) == INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }
  if (INKHttpHdrVersionSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrVersionSet");
  }

  /* INKHttpHdrLengthGet */
  if (INKHttpHdrLengthGet(NULL, negHttpHdrLoc) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrLengthGet");
  }
  if (INKHttpHdrLengthGet(negHdrBuf, NULL) != INK_ERROR) {
    LOG_NEG_ERROR("INKHttpHdrLengthGet");
  }

  /* valid copy */
  if (INKHttpHdrCopy(negHdrBuf, negHttpHdrLoc, hdrBuf, httpHdrLoc) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrCopy");
  }

  if ((hdrHttpType = INKHttpHdrTypeGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) {
    LOG_API_ERROR("INKHttpHdrTypeGet");
  }

  if (hdrHttpType == INK_HTTP_TYPE_REQUEST) {
    /* INKHttpHdrUrlGet */
    if (INKHttpHdrUrlGet(NULL, negHttpHdrLoc) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrUrlGet");
    }
    if (INKHttpHdrUrlGet(negHdrBuf, NULL) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrUrlGet");
    }

    /* INKHttpHdrMethodGet */
    if (INKHttpHdrMethodGet(NULL, negHttpHdrLoc, &iHttpMethodLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }
    if (INKHttpHdrMethodGet(negHdrBuf, NULL, &iHttpMethodLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }
    if (INKHttpHdrMethodGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrMethodGet");
    }

    /* INKHttpHdrMethodSet */
    if (INKHttpHdrMethodSet(NULL, negHttpHdrLoc, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    if (INKHttpHdrMethodSet(negHdrBuf, NULL, "FOOBAR", strlen("FOOBAR")) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    /* INKqa12722 */
    if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }
    /* FIXME:  This neg test would crash TS */
    /* NOTE: This is a valid (corner) test case */
    if (INKHttpHdrMethodSet(negHdrBuf, negHttpHdrLoc, "", -1) == INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrMethodSet");
    }

  } else if (hdrHttpType == INK_HTTP_TYPE_RESPONSE) {

    /* INKHttpHdrStatusGet */
    if (INKHttpHdrStatusGet(NULL, negHttpHdrLoc) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusGet");
    }
    if (INKHttpHdrStatusGet(negHdrBuf, NULL) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusGet");
    }

    /* INKHttpHdrStatusSet */
    /* valid status get */
    if ((httpStatus = INKHttpHdrStatusGet(negHdrBuf, negHttpHdrLoc)) == INK_ERROR) {
      LOG_API_ERROR("INKHttpHdrStatusGet");
    }

    if (INKHttpHdrStatusSet(NULL, negHttpHdrLoc, httpStatus) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }
    if (INKHttpHdrStatusSet(negHdrBuf, NULL, httpStatus) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }
    /* setting status = NULL is NOT an error */
    if (INKHttpHdrStatusSet(negHdrBuf, negHttpHdrLoc, -1) == INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrStatusSet");
    }

    /* INKHttpHdrReasonGet */
    /* valid reason get */
    if ((sHttpReason = INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, &iHttpHdrReasonLength))
        == INK_ERROR_PTR) {
      LOG_API_ERROR("INKHttpHdrReasonGet");
    }

    if (INKHttpHdrReasonGet(NULL, negHttpHdrLoc, &iHttpHdrReasonLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }
    if (INKHttpHdrReasonGet(negHdrBuf, NULL, &iHttpHdrReasonLength) != INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }
    /* NULL is a valid length arg */
    if (INKHttpHdrReasonGet(negHdrBuf, negHttpHdrLoc, NULL) == INK_ERROR_PTR) {
      LOG_NEG_ERROR("INKHttpHdrReasonGet");
    }

    /* INKHttpHdrReasonSet */
    if (INKHttpHdrReasonSet(NULL, negHttpHdrLoc, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }
    if (INKHttpHdrReasonSet(negHdrBuf, NULL, sHttpReason, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }

    /* NOTE: INKqa12722: NULL reason arg fixed now */
    if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, iHttpHdrReasonLength) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }
    /* FIXME: INKqa12722 - This neg test would crash TS */
    if (INKHttpHdrReasonSet(negHdrBuf, negHttpHdrLoc, NULL, -1) != INK_ERROR) {
      LOG_NEG_ERROR("INKHttpHdrReasonSet");
    }

    STR_RELEASE(negHdrBuf, negHttpHdrLoc, sHttpReason);
  }

  /* Clean-up */
  HANDLE_RELEASE(negHdrBuf, INK_NULL_MLOC, negHttpHdrLoc);
  BUFFER_DESTROY(negHdrBuf);
}