]> err.no Git - varnish/commitdiff
Move VCL compiler related stuff to mgt_vcc.c
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 4 Aug 2006 09:19:40 +0000 (09:19 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 4 Aug 2006 09:19:40 +0000 (09:19 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@636 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/mgt.h
varnish-cache/bin/varnishd/mgt_vcc.c [new file with mode: 0644]
varnish-cache/bin/varnishd/varnishd.c

index 2aaf58c3ff523b832e78d4b7c0e2477d43d64d2a..22340afd385aef6d5593ac3f1b9c220f39a76b67 100644 (file)
@@ -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 \
index ef2eeaa9e0688fae2c4d0a83f97c639054eabd5a..a20bf08ede47d4797bf4f812c58176b161058ce4 100644 (file)
@@ -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 (file)
index 0000000..2aa9d52
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * $Id$
+ *
+ * VCL compiler stuff
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/types.h>
+
+#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 <assert.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+#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
index d5679311202bae68fa7fecc35e7229185fc7cc75..eb0918393b406bb63eb74b0a83907e0bf072d8d9 100644 (file)
@@ -20,7 +20,6 @@
 #include "sbuf.h"
 
 #include "libvarnish.h"
-#include "libvcl.h"
 #include "cli.h"
 #include "cli_priv.h"
 #include "common_cli.h"
 #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);