Commit 716a307a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

We will have to maintain the filter list per VCL, so move the

stuff there.
parent 48a57371
......@@ -223,81 +223,6 @@ VFP_Push(struct vfp_ctx *vc, const struct vfp *vfp)
return (vfe);
}
/*--------------------------------------------------------------------
*/
struct vfp_filter {
unsigned magic;
#define VFP_FILTER_MAGIC 0xd40894e9
const struct vfp *filter;
int nlen;
VTAILQ_ENTRY(vfp_filter) list;
};
static VTAILQ_HEAD(,vfp_filter) vfp_filters =
VTAILQ_HEAD_INITIALIZER(vfp_filters);
void
VFP_AddFilter(const struct vfp *filter)
{
struct vfp_filter *vp;
VTAILQ_FOREACH(vp, &vfp_filters, list) {
assert(vp->filter != filter);
assert(strcasecmp(vp->filter->name, filter->name));
}
ALLOC_OBJ(vp, VFP_FILTER_MAGIC);
AN(vp);
vp->filter = filter;
vp->nlen = strlen(filter->name);
VTAILQ_INSERT_TAIL(&vfp_filters, vp, list);
}
void
VFP_RemoveFilter(const struct vfp *filter)
{
struct vfp_filter *vp;
VTAILQ_FOREACH(vp, &vfp_filters, list) {
if (vp->filter == filter)
break;
}
AN(vp);
VTAILQ_REMOVE(&vfp_filters, vp, list);
FREE_OBJ(vp);
}
int
VFP_FilterList(struct vfp_ctx *vc, const char *fl)
{
const char *p, *q;
const struct vfp_filter *vp;
VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
for (p = fl; *p; p = q) {
if (vct_isspace(*p)) {
q = p + 1;
continue;
}
for (q = p; *q; q++)
if (vct_isspace(*q))
break;
VTAILQ_FOREACH(vp, &vfp_filters, list) {
if (vp->nlen != q - p)
continue;
if (!memcmp(p, vp->filter->name, vp->nlen))
break;
}
if (vp == NULL)
return (VFP_Error(vc,
"Filter '%.*s' not found", (int)(q-p), p));
if (VFP_Push(vc, vp->filter) == NULL)
return (-1);
}
return (0);
}
/*--------------------------------------------------------------------
* Debugging aids
*/
......@@ -324,9 +249,4 @@ VFP_Init(void)
{
CLI_AddFuncs(debug_cmds);
VFP_AddFilter(&VFP_testgunzip);
VFP_AddFilter(&VFP_gunzip);
VFP_AddFilter(&VFP_gzip);
VFP_AddFilter(&VFP_esi);
VFP_AddFilter(&VFP_esi_gzip);
}
......@@ -89,8 +89,8 @@ enum vfp_status VFP_Suck(struct vfp_ctx *, void *p, ssize_t *lp);
enum vfp_status VFP_Error(struct vfp_ctx *, const char *fmt, ...)
v_printflike_(2, 3);
int VFP_FilterList(struct vfp_ctx *, const char *);
void VFP_AddFilter(const struct vfp *);
void VFP_RemoveFilter(const struct vfp *);
void VFP_AddFilter(struct vcl *, const struct vfp *);
void VFP_RemoveFilter(struct vcl *, const struct vfp *);
/* Deliver processors ------------------------------------------------*/
......
......@@ -351,6 +351,7 @@ child_main(int sigmagic, size_t altstksz)
ObjInit();
VCL_Init();
VCL_VRT_Init();
HTTP_Init();
......
......@@ -405,6 +405,9 @@ typedef int vcl_be_func(struct cli *, struct director *, void *);
int VCL_IterDirector(struct cli *, const char *, vcl_be_func *, void *);
/* cache_vcl_vrt.c */
void VCL_VRT_Init(void);
/* cache_vrt.c */
void VRTPRIV_init(struct vrt_privs *privs);
void VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id);
......
......@@ -526,6 +526,7 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
XXXAN(vcl->loaded_name);
VTAILQ_INIT(&vcl->director_list);
VTAILQ_INIT(&vcl->ref_list);
VTAILQ_INIT(&vcl->vfps);
vcl->temp = VCL_TEMP_INIT;
......
......@@ -26,8 +26,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* NB: This is a private .h file for cache_vcl*.c
* NB: No other code should include this file.
*
*/
struct vfp_filter;
VTAILQ_HEAD(vfp_filter_head, vfp_filter);
struct vcl {
unsigned magic;
#define VCL_MAGIC 0x214188f2
......@@ -45,6 +52,7 @@ struct vcl {
int nrefs;
struct vcl *label;
int nlabels;
struct vfp_filter_head vfps;
};
struct vclref {
......
......@@ -37,9 +37,11 @@
#include "cache_varnishd.h"
#include "vcl.h"
#include "vct.h"
#include "cache_director.h"
#include "cache_vcl.h"
#include "cache_filter.h"
/*--------------------------------------------------------------------*/
......@@ -413,3 +415,98 @@ VCL_##func##_method(struct vcl *vcl, struct worker *wrk, \
}
#include "tbl/vcl_returns.h"
/*--------------------------------------------------------------------
*/
struct vfp_filter {
unsigned magic;
#define VFP_FILTER_MAGIC 0xd40894e9
const struct vfp *filter;
int nlen;
VTAILQ_ENTRY(vfp_filter) list;
};
static struct vfp_filter_head vfp_filters =
VTAILQ_HEAD_INITIALIZER(vfp_filters);
void
VFP_AddFilter(struct vcl *vcl, const struct vfp *filter)
{
struct vfp_filter *vp;
struct vfp_filter_head *hd = &vfp_filters;
VTAILQ_FOREACH(vp, hd, list) {
xxxassert(vp->filter != filter);
xxxassert(strcasecmp(vp->filter->name, filter->name));
}
if (vcl != NULL) {
hd = &vcl->vfps;
VTAILQ_FOREACH(vp, hd, list) {
xxxassert(vp->filter != filter);
xxxassert(strcasecmp(vp->filter->name, filter->name));
}
}
ALLOC_OBJ(vp, VFP_FILTER_MAGIC);
AN(vp);
vp->filter = filter;
vp->nlen = strlen(filter->name);
VTAILQ_INSERT_TAIL(hd, vp, list);
}
void
VFP_RemoveFilter(struct vcl *vcl, const struct vfp *filter)
{
struct vfp_filter *vp;
struct vfp_filter_head *hd = &vcl->vfps;
AN(vcl);
VTAILQ_FOREACH(vp, hd, list) {
if (vp->filter == filter)
break;
}
XXXAN(vp);
VTAILQ_REMOVE(hd, vp, list);
FREE_OBJ(vp);
}
int
VFP_FilterList(struct vfp_ctx *vc, const char *fl)
{
const char *p, *q;
const struct vfp_filter *vp;
VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
for (p = fl; *p; p = q) {
if (vct_isspace(*p)) {
q = p + 1;
continue;
}
for (q = p; *q; q++)
if (vct_isspace(*q))
break;
VTAILQ_FOREACH(vp, &vfp_filters, list) {
if (vp->nlen != q - p)
continue;
if (!memcmp(p, vp->filter->name, vp->nlen))
break;
}
if (vp == NULL)
return (VFP_Error(vc,
"Filter '%.*s' not found", (int)(q-p), p));
if (VFP_Push(vc, vp->filter) == NULL)
return (-1);
}
return (0);
}
void
VCL_VRT_Init(void)
{
VFP_AddFilter(NULL, &VFP_testgunzip);
VFP_AddFilter(NULL, &VFP_gunzip);
VFP_AddFilter(NULL, &VFP_gzip);
VFP_AddFilter(NULL, &VFP_esi);
VFP_AddFilter(NULL, &VFP_esi_gzip);
}
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