Commit 16c934f5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rename HTC_* to HTTP1_*

Add a read-method to http_conn, and use it from all VFPs, which
should be protocol agnostic.
parent 6cdf30ed
......@@ -112,6 +112,7 @@ struct busyobj;
struct cli;
struct cli_proto;
struct director;
struct http_conn;
struct iovec;
struct mempool;
struct objcore;
......@@ -207,11 +208,18 @@ struct http {
/*--------------------------------------------------------------------
* HTTP Protocol connection structure
*
* This is the protocol independent object for a HTTP connection, used
* both for backend and client sides.
*
*/
typedef ssize_t htc_read(struct http_conn *, void *, size_t);
struct http_conn {
unsigned magic;
#define HTTP_CONN_MAGIC 0x3e19edd1
htc_read *read;
int fd;
struct vsl_log *vsl;
......@@ -876,21 +884,21 @@ void http_VSLH(const struct http *hp, unsigned hdr);
/* cache_http1_proto.c */
enum htc_status_e {
HTC_ALL_WHITESPACE = -3,
HTC_OVERFLOW = -2,
HTC_ERROR_EOF = -1,
HTC_NEED_MORE = 0,
HTC_COMPLETE = 1
HTTP1_ALL_WHITESPACE = -3,
HTTP1_OVERFLOW = -2,
HTTP1_ERROR_EOF = -1,
HTTP1_NEED_MORE = 0,
HTTP1_COMPLETE = 1
};
void HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *,
void HTTP1_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *,
unsigned maxbytes, unsigned maxhdr);
enum htc_status_e HTC_Reinit(struct http_conn *htc);
enum htc_status_e HTC_Rx(struct http_conn *htc);
ssize_t HTC_Read(struct http_conn *htc, void *d, size_t len);
enum htc_status_e HTC_Complete(struct http_conn *htc);
uint16_t HTC_DissectRequest(struct req *);
uint16_t HTC_DissectResponse(struct http *sp, const struct http_conn *htc);
enum htc_status_e HTTP1_Reinit(struct http_conn *htc);
enum htc_status_e HTTP1_Rx(struct http_conn *htc);
ssize_t HTTP1_Read(struct http_conn *htc, void *d, size_t len);
enum htc_status_e HTTP1_Complete(struct http_conn *htc);
uint16_t HTTP1_DissectRequest(struct req *);
uint16_t HTTP1_DissectResponse(struct http *sp, const struct http_conn *htc);
#define HTTPH(a, b, c) extern char b[];
#include "tbl/http_headers.h"
......
......@@ -64,8 +64,7 @@ struct vef_priv {
*/
static ssize_t
vef_read(struct http_conn *htc, void *buf, ssize_t buflen,
ssize_t bytes)
vef_read(struct http_conn *htc, void *buf, ssize_t buflen, ssize_t bytes)
{
ssize_t d;
......@@ -76,7 +75,7 @@ vef_read(struct http_conn *htc, void *buf, ssize_t buflen,
if (d < bytes)
bytes = d;
}
return (HTC_Read(htc, buf, bytes));
return (htc->read(htc, buf, bytes));
}
/*---------------------------------------------------------------------
......
......@@ -166,7 +166,7 @@ vfp_nop_bytes(void *priv, struct http_conn *htc, ssize_t bytes)
l = st->space - st->len;
if (l > bytes)
l = bytes;
wl = HTC_Read(htc, st->ptr + st->len, l);
wl = HTTP1_Read(htc, st->ptr + st->len, l);
if (wl <= 0)
return (wl);
st->len += wl;
......@@ -307,7 +307,7 @@ fetch_chunked(struct busyobj *bo, struct http_conn *htc)
do {
/* Skip leading whitespace */
do {
if (HTC_Read(htc, buf, 1) <= 0)
if (HTTP1_Read(htc, buf, 1) <= 0)
return (FetchError(bo, "chunked read err"));
} while (vct_islws(buf[0]));
......@@ -317,7 +317,7 @@ fetch_chunked(struct busyobj *bo, struct http_conn *htc)
/* Collect hex digits, skipping leading zeros */
for (u = 1; u < sizeof buf; u++) {
do {
if (HTC_Read(htc, buf + u, 1) <= 0)
if (HTTP1_Read(htc, buf + u, 1) <= 0)
return (FetchError(bo,
"chunked read err"));
} while (u == 1 && buf[0] == '0' && buf[u] == '0');
......@@ -330,7 +330,7 @@ fetch_chunked(struct busyobj *bo, struct http_conn *htc)
/* Skip trailing white space */
while(vct_islws(buf[u]) && buf[u] != '\n')
if (HTC_Read(htc, buf + u, 1) <= 0)
if (HTTP1_Read(htc, buf + u, 1) <= 0)
return (FetchError(bo, "chunked read err"));
if (buf[u] != '\n')
......@@ -344,10 +344,10 @@ fetch_chunked(struct busyobj *bo, struct http_conn *htc)
if (cl > 0 && VFP_Bytes(bo, htc, cl) <= 0)
return (FetchError(bo, "chunked read err"));
i = HTC_Read(htc, buf, 1);
i = HTTP1_Read(htc, buf, 1);
if (i <= 0)
return (FetchError(bo, "chunked read err"));
if (buf[0] == '\r' && HTC_Read( htc, buf, 1) <= 0)
if (buf[0] == '\r' && HTTP1_Read( htc, buf, 1) <= 0)
return (FetchError(bo, "chunked read err"));
if (buf[0] != '\n')
return (FetchError(bo,"chunked tail no NL"));
......@@ -469,7 +469,7 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
/* Receive response */
HTC_Init(htc, bo->ws, vc->fd, vc->vsl,
HTTP1_Init(htc, bo->ws, vc->fd, vc->vsl,
cache_param->http_resp_size,
cache_param->http_resp_hdr_len);
......@@ -477,8 +477,8 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
first = 1;
do {
hs = HTC_Rx(htc);
if (hs == HTC_OVERFLOW) {
hs = HTTP1_Rx(htc);
if (hs == HTTP1_OVERFLOW) {
VSLb(req->vsl, SLT_FetchError,
"http %sread error: overflow",
first ? "first " : "");
......@@ -486,7 +486,7 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
/* XXX: other cleanup ? */
return (-1);
}
if (hs == HTC_ERROR_EOF) {
if (hs == HTTP1_ERROR_EOF) {
VSLb(req->vsl, SLT_FetchError,
"http %sread error: EOF",
first ? "first " : "");
......@@ -500,11 +500,11 @@ FetchHdr(struct req *req, int need_host_hdr, int sendbody)
VTCP_set_read_timeout(vc->fd,
vc->between_bytes_timeout);
}
} while (hs != HTC_COMPLETE);
} while (hs != HTTP1_COMPLETE);
hp = bo->beresp;
if (HTC_DissectResponse(hp, htc)) {
if (HTTP1_DissectResponse(hp, htc)) {
VSLb(req->vsl, SLT_FetchError, "http format error");
VDI_CloseFd(&bo->vbc);
/* XXX: other cleanup ? */
......
......@@ -471,7 +471,7 @@ vfp_gunzip_bytes(void *priv, struct http_conn *htc, ssize_t bytes)
l = vg->m_sz;
if (l > bytes)
l = bytes;
wl = HTC_Read(htc, vg->m_buf, l);
wl = htc->read(htc, vg->m_buf, l);
if (wl <= 0)
return (wl);
VGZ_Ibuf(vg, vg->m_buf, wl);
......@@ -551,7 +551,7 @@ vfp_gzip_bytes(void *priv, struct http_conn *htc, ssize_t bytes)
l = vg->m_sz;
if (l > bytes)
l = bytes;
wl = HTC_Read(htc, vg->m_buf, l);
wl = htc->read(htc, vg->m_buf, l);
if (wl <= 0)
return (wl);
VGZ_Ibuf(vg, vg->m_buf, wl);
......@@ -643,7 +643,7 @@ vfp_testgzip_bytes(void *priv, struct http_conn *htc, ssize_t bytes)
l = st->space - st->len;
if (l > bytes)
l = bytes;
wl = HTC_Read(htc, st->ptr + st->len, l);
wl = htc->read(htc, st->ptr + st->len, l);
if (wl <= 0)
return (wl);
bytes -= wl;
......
......@@ -114,20 +114,20 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
assert(j >= 0);
now = VTIM_real();
if (j != 0)
hs = HTC_Rx(req->htc);
hs = HTTP1_Rx(req->htc);
else
hs = HTC_Complete(req->htc);
if (hs == HTC_COMPLETE) {
hs = HTTP1_Complete(req->htc);
if (hs == HTTP1_COMPLETE) {
/* Got it, run with it */
req->t_req = now;
return (REQ_FSM_MORE);
} else if (hs == HTC_ERROR_EOF) {
} else if (hs == HTTP1_ERROR_EOF) {
why = SC_REM_CLOSE;
break;
} else if (hs == HTC_OVERFLOW) {
} else if (hs == HTTP1_OVERFLOW) {
why = SC_RX_OVERFLOW;
break;
} else if (hs == HTC_ALL_WHITESPACE) {
} else if (hs == HTTP1_ALL_WHITESPACE) {
/* Nothing but whitespace */
when = sp->t_idle + cache_param->timeout_idle;
if (when < now) {
......@@ -224,7 +224,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
WS_Reset(req->ws, NULL);
WS_Reset(wrk->aws, NULL);
if (HTC_Reinit(req->htc) == HTC_COMPLETE) {
if (HTTP1_Reinit(req->htc) == HTTP1_COMPLETE) {
req->t_req = sp->t_idle;
wrk->stats.sess_pipeline++;
return (SESS_DONE_RET_START);
......@@ -260,7 +260,7 @@ http1_dissect(struct worker *wrk, struct req *req)
wrk->vcl = NULL;
HTTP_Setup(req->http, req->ws, req->vsl, HTTP_Method);
req->err_code = HTC_DissectRequest(req);
req->err_code = HTTP1_DissectRequest(req);
/* If we could not even parse the request, just close */
if (req->err_code == 400) {
......@@ -330,7 +330,7 @@ HTTP1_Session(struct worker *wrk, struct req *req)
}
if (sp->sess_step == S_STP_NEWREQ) {
HTC_Init(req->htc, req->ws, sp->fd, req->vsl,
HTTP1_Init(req->htc, req->ws, sp->fd, req->vsl,
cache_param->http_req_size,
cache_param->http_req_hdr_len);
}
......@@ -442,7 +442,7 @@ http1_iter_req_body(struct req *req, struct http1_r_b_s *rbs, void *buf,
req->req_body_status = REQ_BODY_DONE;
return (0);
}
len = HTC_Read(req->htc, buf, len);
len = HTTP1_Read(req->htc, buf, len);
if (len <= 0) {
req->req_body_status = REQ_BODY_FAIL;
return (-1);
......
......@@ -46,11 +46,10 @@
#include "vct.h"
/*--------------------------------------------------------------------*/
void
HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
HTTP1_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
unsigned maxbytes, unsigned maxhdr)
{
......@@ -60,6 +59,7 @@ HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
htc->vsl = vsl;
htc->maxbytes = maxbytes;
htc->maxhdr = maxhdr;
htc->read = HTTP1_Read;
(void)WS_Reserve(htc->ws, htc->maxbytes);
htc->rxbuf.b = ws->f;
......@@ -76,7 +76,7 @@ HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
*/
enum htc_status_e
HTC_Reinit(struct http_conn *htc)
HTTP1_Reinit(struct http_conn *htc)
{
unsigned l;
......@@ -92,7 +92,7 @@ HTC_Reinit(struct http_conn *htc)
htc->pipeline.e = NULL;
}
*htc->rxbuf.e = '\0';
return (HTC_Complete(htc));
return (HTTP1_Complete(htc));
}
/*--------------------------------------------------------------------
......@@ -101,7 +101,7 @@ HTC_Reinit(struct http_conn *htc)
*/
enum htc_status_e
HTC_Complete(struct http_conn *htc)
HTTP1_Complete(struct http_conn *htc)
{
int i;
const char *p;
......@@ -120,12 +120,12 @@ HTC_Complete(struct http_conn *htc)
/* All white space */
t->e = t->b;
*t->e = '\0';
return (HTC_ALL_WHITESPACE);
return (HTTP1_ALL_WHITESPACE);
}
while (1) {
p = strchr(p, '\n');
if (p == NULL)
return (HTC_NEED_MORE);
return (HTTP1_NEED_MORE);
p++;
if (*p == '\r')
p++;
......@@ -142,7 +142,7 @@ HTC_Complete(struct http_conn *htc)
htc->pipeline.e = htc->rxbuf.e;
htc->rxbuf.e = htc->pipeline.b;
}
return (HTC_COMPLETE);
return (HTTP1_COMPLETE);
}
/*--------------------------------------------------------------------
......@@ -150,7 +150,7 @@ HTC_Complete(struct http_conn *htc)
*/
enum htc_status_e
HTC_Rx(struct http_conn *htc)
HTTP1_Rx(struct http_conn *htc)
{
int i;
......@@ -159,7 +159,7 @@ HTC_Rx(struct http_conn *htc)
i = (htc->ws->r - htc->rxbuf.e) - 1; /* space for NUL */
if (i <= 0) {
WS_ReleaseP(htc->ws, htc->rxbuf.b);
return (HTC_OVERFLOW);
return (HTTP1_OVERFLOW);
}
i = read(htc->fd, htc->rxbuf.e, i);
if (i <= 0) {
......@@ -168,11 +168,11 @@ HTC_Rx(struct http_conn *htc)
* so consequently an EOF can not be OK
*/
WS_ReleaseP(htc->ws, htc->rxbuf.b);
return (HTC_ERROR_EOF);
return (HTTP1_ERROR_EOF);
}
htc->rxbuf.e += i;
*htc->rxbuf.e = '\0';
return (HTC_Complete(htc));
return (HTTP1_Complete(htc));
}
/*--------------------------------------------------------------------
......@@ -180,7 +180,7 @@ HTC_Rx(struct http_conn *htc)
*/
ssize_t
HTC_Read(struct http_conn *htc, void *d, size_t len)
HTTP1_Read(struct http_conn *htc, void *d, size_t len)
{
size_t l;
unsigned char *p;
......@@ -390,7 +390,7 @@ htc_proto_ver(struct http *hp)
/*--------------------------------------------------------------------*/
uint16_t
HTC_DissectRequest(struct req *req)
HTTP1_DissectRequest(struct req *req)
{
struct http_conn *htc;
struct http *hp;
......@@ -413,7 +413,7 @@ HTC_DissectRequest(struct req *req)
/*--------------------------------------------------------------------*/
uint16_t
HTC_DissectResponse(struct http *hp, const struct http_conn *htc)
HTTP1_DissectResponse(struct http *hp, const struct http_conn *htc)
{
int j;
uint16_t retval = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment