From: phk Date: Fri, 4 Aug 2006 09:19:40 +0000 (+0000) Subject: Move VCL compiler related stuff to mgt_vcc.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6ef90f1d013fc362e5e9ff00d9a4d881512c591;p=varnish Move VCL compiler related stuff to mgt_vcc.c git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@636 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 2aaf58c3..22340afd 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -38,6 +38,7 @@ varnishd_SOURCES = \ hash_classic.c \ mgt_child.c \ mgt_cli.c \ + mgt_vcc.c \ rfc2616.c \ shmlog.c \ storage_file.c \ diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index ef2eeaa9..a20bf08e 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -17,6 +17,10 @@ void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); int mgt_cli_askchild(int *status, char **resp, const char *fmt, ...); +/* mgt_vcc.c */ +void mgt_vcc_init(void); +char *mgt_vcc_default(const char *bflag); +char *mgt_vcc_file(const char *fflag); /* tcp.c */ int open_tcp(const char *port); diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c new file mode 100644 index 00000000..2aa9d525 --- /dev/null +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -0,0 +1,205 @@ +/* + * $Id$ + * + * VCL compiler stuff + */ + +#include +#include +#include +#include +#include + +#include "sbuf.h" + +#include "libvarnish.h" +#include "libvcl.h" +#include "cli.h" +#include "cli_priv.h" +#include "common_cli.h" + +#include "mgt.h" + +/*--------------------------------------------------------------------*/ + +static const char *default_vcl = + "sub default_vcl_recv {\n" + " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" + " pipe;\n" + " }\n" + " if (req.http.Expect) {\n" + " pipe;\n" + " }\n" + " if (req.http.Authenticate || req.http.Cookie) {\n" + " pass;\n" + " }\n" + " lookup;\n" + "}\n" + "\n" + "sub default_vcl_hit {\n" + " if (!obj.cacheable) {\n" + " pass;\n" + " }\n" + " deliver;\n" + "}\n" + "\n" + "sub default_vcl_miss {\n" + " fetch;\n" + "}\n" + "\n" + "sub default_vcl_fetch {\n" + " if (!obj.valid) {\n" + " error;\n" + " }\n" + " if (!obj.cacheable) {\n" + " insert_pass;\n" + " }\n" + " insert;\n" + "}\n" + "sub default_vcl_timeout {\n" + " discard;\n" + "}\n"; + +/*--------------------------------------------------------------------*/ + +char * +mgt_vcc_default(const char *bflag) +{ + char *buf, *vf; + const char *p, *q; + struct sbuf *sb; + + /* + * XXX: should do a "HEAD /" on the -b argument to see that + * XXX: it even works. On the other hand, we should do that + * XXX: for all backends in the cache process whenever we + * XXX: change config, but for a complex VCL, it might not be + * XXX: a bug for a backend to not reply at that time, so then + * XXX: again: we should check it here in the "trivial" case. + */ + p = strchr(bflag, ' '); + if (p != NULL) { + q = p + 1; + } else { + p = strchr(bflag, '\0'); + assert(p != NULL); + q = "http"; + } + + buf = NULL; + asprintf(&buf, + "backend default {\n" + " set backend.host = \"%*.*s\";\n" + " set backend.port = \"%s\";\n" + "}\n", (int)(p - bflag), (int)(p - bflag), bflag, q); + assert(buf != NULL); + sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(sb != NULL); + vf = VCC_Compile(sb, buf, NULL); + sbuf_finish(sb); + if (sbuf_len(sb) > 0) { + fprintf(stderr, "%s", sbuf_data(sb)); + free(buf); + sbuf_delete(sb); + return (NULL); + } + sbuf_delete(sb); + free(buf); + return (vf); +} + +/*--------------------------------------------------------------------*/ + +char * +mgt_vcc_file(const char *fflag) +{ + char *vf; + struct sbuf *sb; + + sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(sb != NULL); + vf = VCC_CompileFile(sb, fflag); + sbuf_finish(sb); + if (sbuf_len(sb) > 0) { + fprintf(stderr, "%s", sbuf_data(sb)); + sbuf_delete(sb); + return (NULL); + } + sbuf_delete(sb); + return (vf); +} + +/*--------------------------------------------------------------------*/ + +void +mgt_vcc_init(void) +{ + + VCC_InitCompile(default_vcl); +} + + +#if 0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mgt.h" + +static void +m_cli_func_config_inline(struct cli *cli, char **av, void *priv) +{ + char *vf; + struct sbuf *sb; + + (void)priv; + + sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(sb != NULL); + vf = VCC_Compile(sb, av[3], NULL); + sbuf_finish(sb); + if (sbuf_len(sb) > 0) { + cli_out(cli, "%s", sbuf_data(sb)); + sbuf_delete(sb); + return; + } + sbuf_delete(sb); + cli_suspend(cli); + mgt_child_request(cli_passthrough_cb, cli, NULL, + "config.load %s %s", av[2], vf); +} + +/* XXX: m prefix to avoid name clash */ +static void +m_cli_func_config_load(struct cli *cli, char **av, void *priv) +{ + char *vf; + struct sbuf *sb; + + (void)priv; + + sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(sb != NULL); + vf = VCC_CompileFile(sb, av[3]); + sbuf_finish(sb); + if (sbuf_len(sb) > 0) { + cli_out(cli, "%s", sbuf_data(sb)); + sbuf_delete(sb); + return; + } + sbuf_delete(sb); + cli_suspend(cli); + mgt_child_request(cli_passthrough_cb, cli, NULL, + "config.load %s %s", av[2], vf); +} + +#endif diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index d5679311..eb091839 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -20,7 +20,6 @@ #include "sbuf.h" #include "libvarnish.h" -#include "libvcl.h" #include "cli.h" #include "cli_priv.h" #include "common_cli.h" @@ -29,167 +28,10 @@ #include "heritage.h" #include "shmlog.h" -/*--------------------------------------------------------------------*/ - -static const char *default_vcl = - "sub default_vcl_recv {\n" - " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" - " pipe;\n" - " }\n" - " if (req.http.Expect) {\n" - " pipe;\n" - " }\n" - " if (req.http.Authenticate || req.http.Cookie) {\n" - " pass;\n" - " }\n" - " lookup;\n" - "}\n" - "\n" - "sub default_vcl_hit {\n" - " if (!obj.cacheable) {\n" - " pass;\n" - " }\n" - " deliver;\n" - "}\n" - "\n" - "sub default_vcl_miss {\n" - " fetch;\n" - "}\n" - "\n" - "sub default_vcl_fetch {\n" - " if (!obj.valid) {\n" - " error;\n" - " }\n" - " if (!obj.cacheable) {\n" - " insert_pass;\n" - " }\n" - " insert;\n" - "}\n" - "sub default_vcl_timeout {\n" - " discard;\n" - "}\n"; - -/*--------------------------------------------------------------------*/ - struct heritage heritage; /*--------------------------------------------------------------------*/ -static char * -vcl_default(const char *bflag) -{ - char *buf, *vf; - const char *p, *q; - struct sbuf *sb; - - /* - * XXX: should do a "HEAD /" on the -b argument to see that - * XXX: it even works. On the other hand, we should do that - * XXX: for all backends in the cache process whenever we - * XXX: change config, but for a complex VCL, it might not be - * XXX: a bug for a backend to not reply at that time, so then - * XXX: again: we should check it here in the "trivial" case. - */ - p = strchr(bflag, ' '); - if (p != NULL) { - q = p + 1; - } else { - p = strchr(bflag, '\0'); - assert(p != NULL); - q = "http"; - } - - buf = NULL; - asprintf(&buf, - "backend default {\n" - " set backend.host = \"%*.*s\";\n" - " set backend.port = \"%s\";\n" - "}\n", (int)(p - bflag), (int)(p - bflag), bflag, q); - assert(buf != NULL); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - vf = VCC_Compile(sb, buf, NULL); - sbuf_finish(sb); - if (sbuf_len(sb) > 0) { - fprintf(stderr, "%s", sbuf_data(sb)); - free(buf); - sbuf_delete(sb); - return (NULL); - } - sbuf_delete(sb); - free(buf); - return (vf); -} -#if 0 -static void -m_cli_func_config_inline(struct cli *cli, char **av, void *priv) -{ - char *vf; - struct sbuf *sb; - - (void)priv; - - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - vf = VCC_Compile(sb, av[3], NULL); - sbuf_finish(sb); - if (sbuf_len(sb) > 0) { - cli_out(cli, "%s", sbuf_data(sb)); - sbuf_delete(sb); - return; - } - sbuf_delete(sb); - cli_suspend(cli); - mgt_child_request(cli_passthrough_cb, cli, NULL, - "config.load %s %s", av[2], vf); -} - -/* XXX: m prefix to avoid name clash */ -static void -m_cli_func_config_load(struct cli *cli, char **av, void *priv) -{ - char *vf; - struct sbuf *sb; - - (void)priv; - - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - vf = VCC_CompileFile(sb, av[3]); - sbuf_finish(sb); - if (sbuf_len(sb) > 0) { - cli_out(cli, "%s", sbuf_data(sb)); - sbuf_delete(sb); - return; - } - sbuf_delete(sb); - cli_suspend(cli); - mgt_child_request(cli_passthrough_cb, cli, NULL, - "config.load %s %s", av[2], vf); -} -#endif - -static char * -vcl_file(const char *fflag) -{ - char *vf; - struct sbuf *sb; - - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - vf = VCC_CompileFile(sb, fflag); - sbuf_finish(sb); - if (sbuf_len(sb) > 0) { - fprintf(stderr, "%s", sbuf_data(sb)); - sbuf_delete(sb); - return (NULL); - } - sbuf_delete(sb); - return (vf); -} - -/*--------------------------------------------------------------------*/ - static int cmp_hash(struct hash_slinger *s, const char *p, const char *q) { @@ -465,8 +307,8 @@ main(int argc, char *argv[]) setbuf(stdout, NULL); setbuf(stderr, NULL); - - VCC_InitCompile(default_vcl); + + mgt_vcc_init(); heritage.default_ttl = 120; heritage.wthread_min = 1; @@ -522,9 +364,9 @@ main(int argc, char *argv[]) } if (bflag != NULL) - heritage.vcl_file = vcl_default(bflag); + heritage.vcl_file = mgt_vcc_default(bflag); else - heritage.vcl_file = vcl_file(fflag); + heritage.vcl_file = mgt_vcc_file(fflag); if (heritage.vcl_file == NULL) exit (1);