static void
free_request_info(RequestInfo *req_info)
{
  TSfree(req_info->effective_url);
  TSHandleMLocRelease(req_info->buf, TS_NULL_MLOC, req_info->http_hdr_loc);
  TSMBufferDestroy(req_info->buf);
  TSfree(req_info);
}
static void
free_response_info(ResponseInfo *resp_info)
{
  TSHandleMLocRelease(resp_info->buf, TS_NULL_MLOC, resp_info->http_hdr_loc);
  TSMBufferDestroy(resp_info->buf);
  TSHttpParserDestroy(resp_info->parser);
  TSfree(resp_info);
}
Ejemplo n.º 3
0
void
ts_http_fetcher_release(http_fetcher *fch)
{
    if (fch->http_vc) {
        TSVConnClose(fch->http_vc);
        fch->http_vc = NULL;
    }

    if (fch->http_parser)
        TSHttpParserDestroy(fch->http_parser);

    if (fch->hdr_loc) {
        TSMimeHdrDestroy(fch->hdr_bufp, fch->hdr_loc);
        TSHandleMLocRelease(fch->hdr_bufp, TS_NULL_MLOC, fch->hdr_loc);
    }

    if (fch->hdr_bufp)
        TSMBufferDestroy(fch->hdr_bufp);

    if (fch->hdr_reader)
        TSIOBufferReaderFree(fch->hdr_reader);
    if (fch->hdr_buffer)
        TSIOBufferDestroy(fch->hdr_buffer);

    if (fch->resp_reader)
        TSIOBufferReaderFree(fch->resp_reader);
    if (fch->resp_buffer)
        TSIOBufferDestroy(fch->resp_buffer);

    if (fch->body_reader)
        TSIOBufferReaderFree(fch->body_reader);
    if (fch->body_buffer)
        TSIOBufferDestroy(fch->body_buffer);

    if (fch->flow_reader)
        TSIOBufferReaderFree(fch->flow_reader);
    if (fch->flow_buffer)
        TSIOBufferDestroy(fch->flow_buffer);

    if (fch->req_reader)
        TSIOBufferReaderFree(fch->req_reader);
    if (fch->req_buffer)
        TSIOBufferDestroy(fch->req_buffer);

    TSContDestroy(fch->fetch_contp);

    TSfree(fch);
    fch = NULL;
}
Ejemplo n.º 4
0
static char *
get_effective_host(TSHttpTxn txn)
{
    char *effective_url, *tmp;
    const char *host;
    int len;
    TSMBuffer buf;
    TSMLoc url_loc;

    buf = TSMBufferCreate();
    if (TS_SUCCESS != TSUrlCreate(buf, &url_loc)) {
        TSDebug(DEBUG_TAG, "unable to create url");
        TSMBufferDestroy(buf);
        return NULL;
    }
    tmp = effective_url = TSHttpTxnEffectiveUrlStringGet(txn, &len);
    TSUrlParse(buf, url_loc, (const char **)(&tmp), (const char *)(effective_url + len));
    TSfree(effective_url);
    host = TSUrlHostGet(buf, url_loc, &len);
    tmp  = TSstrndup(host, len);
    TSHandleMLocRelease(buf, TS_NULL_MLOC, url_loc);
    TSMBufferDestroy(buf);
    return tmp;
}
Ejemplo n.º 5
0
static TSCacheKey
ts_lua_cache_key_create(const char *keystr, size_t key_len, const char *optstr, size_t opt_len)
{
    const char          *ptr, *end, *host;
    char                c;
    int                 host_len;
    TSCacheKey          key;
    TSMBuffer           urlBuf;
    TSMLoc              urlLoc;
    int                 url, http;

    ptr = optstr;
    end = optstr + opt_len;
    url = http = 0;

    while (ptr < end) {
        c = *ptr;

        switch (c) {
            case 'u':
                url = 1;
                break;

            case 'h':
                http = 1;
                break;

            default:
                break;
        }

        ptr++;
    }

    key = TSCacheKeyCreate();
    urlBuf = NULL;

    if (url == 0) {
        TSCacheKeyDigestSet(key, keystr, key_len);

    } else {
        end = keystr + key_len;
        ptr = memchr(keystr, ':', key_len);
        if (ptr == NULL)
            goto fail;

        ptr += 3;
        if (ptr >= end)
            goto fail;

        host = ptr;
        ptr = memchr(host, '/', end-host);
        if (ptr != NULL) {
            host_len = ptr - host;

        } else {
            host_len = end - host;
        }

        if (host_len <= 0)
            goto fail;

        ptr = memchr(host, ':', host_len);
        if (ptr != NULL) {
            host_len = ptr - host;
        }

        urlBuf = TSMBufferCreate();
        TSUrlCreate(urlBuf, &urlLoc);

        if (TSUrlParse(urlBuf, urlLoc, (const char **) &keystr, end) != TS_PARSE_DONE ||
                TSCacheKeyDigestFromUrlSet(key, urlLoc) != TS_SUCCESS) {
            goto fail;
        }

        TSHandleMLocRelease(urlBuf, NULL, urlLoc);
        TSMBufferDestroy(urlBuf);

        TSCacheKeyHostNameSet(key, host, host_len);
    }

    if (http) {
        TSCacheKeyDataTypeSet(key, TS_CACHE_DATA_TYPE_HTTP);
    }

    return key;

fail:

    TSCacheKeyDestroy(key);
    if (urlBuf) {
        TSHandleMLocRelease(urlBuf, NULL, urlLoc);
        TSMBufferDestroy(urlBuf);
    }

    return NULL;
}