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