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

Move VCL compiler related stuff to mgt_vcc.c



git-svn-id: http://www.varnish-cache.org/svn/trunk@636 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8b6f733e
......@@ -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 \
......
......@@ -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);
......
/*
* $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
......@@ -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);
......
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