Commit a9d4a497 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Wrap a structure around fetch filters, and move the filter

API to a separate #include file.
parent b2b6e329
......@@ -103,6 +103,7 @@ noinst_HEADERS = \
pkgdataincludedir = $(pkgdatadir)/include
nobase_pkgdatainclude_HEADERS = \
cache/cache.h \
cache/cache_filter.h \
cache/cache_backend.h \
common/common.h \
common/params.h
......
......@@ -36,6 +36,7 @@
#include "common/common.h"
#include "cache/cache_filter.h"
#include "vapi/vsl_int.h"
#include <sys/socket.h>
......@@ -253,32 +254,6 @@ struct dstat {
#undef L0
#undef L1
/* Fetch processors --------------------------------------------------*/
enum vfp_status {
VFP_ERROR = -1,
VFP_OK = 0,
VFP_END = 1,
};
typedef enum vfp_status
vfp_pull_f(struct busyobj *bo, void *p, ssize_t *len, intptr_t *priv);
extern vfp_pull_f vfp_gunzip_pull;
extern vfp_pull_f vfp_gzip_pull;
extern vfp_pull_f vfp_testgunzip_pull;
extern vfp_pull_f vfp_esi_pull;
extern vfp_pull_f vfp_esi_gzip_pull;
/* Deliver processors ------------------------------------------------*/
enum vdp_action {
VDP_NULL,
VDP_FLUSH,
VDP_FINISH,
};
typedef int vdp_bytes(struct req *, enum vdp_action, const void *ptr,
ssize_t len);
/*--------------------------------------------------------------------*/
struct exp {
......@@ -487,7 +462,7 @@ struct busyobj {
uint8_t *vary;
#define N_VFPS 5
vfp_pull_f *vfps[N_VFPS];
const struct vfp *vfps[N_VFPS];
intptr_t vfps_priv[N_VFPS];
int vfp_nxt;
......@@ -901,7 +876,7 @@ enum vfp_status VFP_Error(struct busyobj *, const char *fmt, ...)
__printflike(2, 3);
void VFP_Init(void);
void VFP_Fetch_Body(struct busyobj *bo, ssize_t est);
void VFP_Push(struct busyobj *, vfp_pull_f *func, intptr_t priv);
void VFP_Push(struct busyobj *, const struct vfp *, intptr_t priv);
enum vfp_status VFP_Suck(struct busyobj *, void *p, ssize_t *lp);
extern char vfp_init[];
extern char vfp_fini[];
......
......@@ -141,7 +141,7 @@ vfp_esi_end(struct busyobj *bo, struct vef_priv *vef, enum vfp_status retval)
return (retval);
}
enum vfp_status __match_proto__(vfp_pull_f)
static enum vfp_status __match_proto__(vfp_pull_f)
vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
{
enum vfp_status vp;
......@@ -202,7 +202,7 @@ vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
return (vp);
}
enum vfp_status __match_proto__(vfp_pull_f)
static enum vfp_status __match_proto__(vfp_pull_f)
vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
{
enum vfp_status vp;
......@@ -241,3 +241,11 @@ vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
}
return (vp);
}
const struct vfp vfp_esi = {
.pull = vfp_esi_pull,
};
const struct vfp vfp_esi_gzip = {
.pull = vfp_esi_gzip_pull,
};
......@@ -468,22 +468,22 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
if (bo->do_gunzip || (bo->is_gzip && bo->do_esi)) {
RFC2616_Weaken_Etag(bo->beresp);
VFP_Push(bo, vfp_gunzip_pull, 0);
VFP_Push(bo, &vfp_gunzip, 0);
}
if (bo->do_esi && bo->do_gzip) {
VFP_Push(bo, vfp_esi_gzip_pull, 0);
VFP_Push(bo, &vfp_esi_gzip, 0);
RFC2616_Weaken_Etag(bo->beresp);
} else if (bo->do_esi && bo->is_gzip && !bo->do_gunzip) {
VFP_Push(bo, vfp_esi_gzip_pull, 0);
VFP_Push(bo, &vfp_esi_gzip, 0);
RFC2616_Weaken_Etag(bo->beresp);
} else if (bo->do_esi) {
VFP_Push(bo, vfp_esi_pull, 0);
VFP_Push(bo, &vfp_esi, 0);
} else if (bo->do_gzip) {
VFP_Push(bo, vfp_gzip_pull, 0);
VFP_Push(bo, &vfp_gzip, 0);
RFC2616_Weaken_Etag(bo->beresp);
} else if (bo->is_gzip && !bo->do_gunzip) {
VFP_Push(bo, vfp_testgunzip_pull, 0);
VFP_Push(bo, &vfp_testgunzip, 0);
}
if (bo->fetch_objcore->flags & OC_F_PRIVATE)
......
......@@ -114,8 +114,8 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
static enum vfp_status
vfp_call(struct busyobj *bo, int nbr, void *p, ssize_t *lp)
{
AN(bo->vfps[nbr]);
return (bo->vfps[nbr](bo, p, lp, &bo->vfps_priv[nbr]));
AN(bo->vfps[nbr]->pull);
return (bo->vfps[nbr]->pull(bo, p, lp, &bo->vfps_priv[nbr]));
}
static void
......@@ -250,12 +250,12 @@ VFP_Fetch_Body(struct busyobj *bo, ssize_t est)
}
void
VFP_Push(struct busyobj *bo, vfp_pull_f *func, intptr_t priv)
VFP_Push(struct busyobj *bo, const struct vfp *vfp, intptr_t priv)
{
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
bo->vfps_priv[bo->vfp_nxt] = priv;
bo->vfps[bo->vfp_nxt] = func;
bo->vfps[bo->vfp_nxt] = vfp;
bo->vfp_nxt++;
}
......
/*-
* Copyright (c) 2013-2014 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
struct busyobj;
struct req;
/* Fetch processors --------------------------------------------------*/
enum vfp_status {
VFP_ERROR = -1,
VFP_OK = 0,
VFP_END = 1,
};
typedef enum vfp_status
vfp_pull_f(struct busyobj *bo, void *p, ssize_t *len, intptr_t *priv);
struct vfp {
vfp_pull_f *pull;
};
extern const struct vfp vfp_gunzip;
extern const struct vfp vfp_gzip;
extern const struct vfp vfp_testgunzip;
extern const struct vfp vfp_esi;
extern const struct vfp vfp_esi_gzip;
/* Deliver processors ------------------------------------------------*/
enum vdp_action {
VDP_NULL,
VDP_FLUSH,
VDP_FINISH,
};
typedef int vdp_bytes(struct req *, enum vdp_action, const void *ptr,
ssize_t len);
......@@ -450,7 +450,7 @@ VGZ_Destroy(struct vgz **vgp)
* A VFP for gunzip'ing an object as we receive it from the backend
*/
enum vfp_status __match_proto__(vfp_pull_f)
static enum vfp_status __match_proto__(vfp_pull_f)
vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
{
ssize_t l;
......@@ -513,13 +513,18 @@ vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
return (vp);
}
const struct vfp vfp_gunzip = {
.pull = vfp_gunzip_pull,
};
/*--------------------------------------------------------------------
* VFP_GZIP
*
* A VFP for gzip'ing an object as we receive it from the backend
*/
enum vfp_status __match_proto__(vfp_pull_f)
static enum vfp_status __match_proto__(vfp_pull_f)
vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
{
ssize_t l;
......@@ -583,6 +588,10 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
return (VFP_END);
}
const struct vfp vfp_gzip = {
.pull = vfp_gzip_pull,
};
/*--------------------------------------------------------------------
* VFP_TESTGZIP
*
......@@ -590,7 +599,7 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
* collecting the magic bits while we're at it.
*/
enum vfp_status __match_proto__(vfp_pull_f)
static enum vfp_status __match_proto__(vfp_pull_f)
vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
{
struct vgz *vg;
......@@ -641,3 +650,7 @@ vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
}
return (vp);
}
const struct vfp vfp_testgunzip = {
.pull = vfp_testgunzip_pull,
};
......@@ -100,6 +100,10 @@ v1f_pull_straight(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
return (VFP_OK);
}
static const struct vfp v1f_straight = {
.pull = v1f_pull_straight,
};
/*--------------------------------------------------------------------
* Read a chunked HTTP object.
*
......@@ -133,6 +137,10 @@ v1f_pull_chunked(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
}
}
static const struct vfp v1f_chunked = {
.pull = v1f_pull_chunked,
};
/*--------------------------------------------------------------------*/
static enum vfp_status __match_proto__(vfp_pull_f)
......@@ -160,6 +168,11 @@ v1f_pull_eof(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
return (VFP_OK);
}
static const struct vfp v1f_eof = {
.pull = v1f_pull_eof,
};
/*--------------------------------------------------------------------
*/
......@@ -176,14 +189,14 @@ V1F_Setup_Fetch(struct busyobj *bo)
switch(htc->body_status) {
case BS_EOF:
VFP_Push(bo, v1f_pull_eof, 0);
VFP_Push(bo, &v1f_eof, 0);
return(-1);
case BS_LENGTH:
cl = vbf_fetch_number(bo->h_content_length, 10);
VFP_Push(bo, v1f_pull_straight, cl);
VFP_Push(bo, &v1f_straight, cl);
return (cl);
case BS_CHUNKED:
VFP_Push(bo, v1f_pull_chunked, -1);
VFP_Push(bo, &v1f_chunked, -1);
return (-1);
default:
break;
......
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