/*--------------------------------------------------------------------*/
static char *
-mgt_VccCompile(struct vsb *sb, const char *b, const char *e, int C_flag)
+mgt_VccCompile(struct vsb **sb, const char *b, int C_flag)
{
char *csrc, *vf = NULL;
- csrc = VCC_Compile(sb, b, e);
- if (csrc != NULL) {
- if (C_flag)
- (void)fputs(csrc, stdout);
- vf = mgt_run_cc(csrc, sb);
- if (C_flag && vf != NULL)
- AZ(unlink(vf));
- free(csrc);
- }
- return (vf);
-}
+ *sb = vsb_newauto();
+ XXXAN(*sb);
+ csrc = VCC_Compile(*sb, b, NULL);
-static char *
-mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag, int fd)
-{
- char *csrc, *vf = NULL;
-
- csrc = VCC_CompileFile(sb, fn, fd);
if (csrc != NULL) {
if (C_flag)
(void)fputs(csrc, stdout);
- vf = mgt_run_cc(csrc, sb);
+ vf = mgt_run_cc(csrc, *sb);
if (C_flag && vf != NULL)
AZ(unlink(vf));
free(csrc);
}
+ vsb_finish(*sb);
+ AZ(vsb_overflowed(*sb));
return (vf);
}
-
/*--------------------------------------------------------------------*/
static struct vclprog *
/*--------------------------------------------------------------------*/
int
-mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag)
+mgt_vcc_default(const char *b_arg, char *vcl, int C_flag)
{
char *addr, *port;
- char *buf, *vf;
+ char *vf;
struct vsb *sb;
struct vclprog *vp;
- sb = vsb_newauto();
- XXXAN(sb);
if (b_arg != NULL) {
+ AZ(vcl);
/*
* XXX: should do a "HEAD /" on the -b argument to see that
* XXX: it even works. On the other hand, we should do that
*/
free(port);
fprintf(stderr, "invalid backend address\n");
- vsb_delete(sb);
return (1);
}
- buf = NULL;
- asprintf(&buf,
+ asprintf(&vcl,
"backend default {\n"
" .host = \"%s\";\n"
" .port = \"%s\";\n"
"}\n", addr, port ? port : "http");
free(addr);
free(port);
- AN(buf);
- vf = mgt_VccCompile(sb, buf, NULL, C_flag);
- free(buf);
- } else {
- vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd);
+ AN(vcl);
}
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+
+ vf = mgt_VccCompile(&sb, vcl, C_flag);
+ free(vcl);
if (vsb_len(sb) > 0)
fprintf(stderr, "%s", vsb_data(sb));
vsb_delete(sb);
return;
}
- sb = vsb_newauto();
- XXXAN(sb);
- vf = mgt_VccCompile(sb, av[3], NULL, 0);
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+ vf = mgt_VccCompile(&sb, av[3], 0);
if (vsb_len(sb) > 0)
cli_out(cli, "%s", vsb_data(sb));
vsb_delete(sb);
void
mcf_config_load(struct cli *cli, const char * const *av, void *priv)
{
- char *vf;
+ char *vf, *vcl;
struct vsb *sb;
unsigned status;
char *p = NULL;
return;
}
- sb = vsb_newauto();
- XXXAN(sb);
- vf = mgt_VccCompileFile(sb, av[3], 0, -1);
- vsb_finish(sb);
- AZ(vsb_overflowed(sb));
+ vcl = vreadfile(av[3]);
+ if (vcl == NULL) {
+ cli_out(cli, "Cannot open '%s'", av[3]);
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
+
+ vf = mgt_VccCompile(&sb, vcl, 0);
+ free(vcl);
+
if (vsb_len(sb) > 0)
cli_out(cli, "%s", vsb_data(sb));
vsb_delete(sb);
const char *l_arg = "80m";
uintmax_t l_size;
const char *q;
- int f_fd = -1;
const char *h_arg = "classic";
const char *n_arg = NULL;
const char *P_arg = NULL;
const char *s_arg = "file";
int s_arg_given = 0;
const char *T_arg = NULL;
- char *p;
+ char *p, *vcl = NULL;
struct cli cli[1];
struct pidfh *pfh = NULL;
char dirname[1024];
}
if (f_arg != NULL) {
- f_fd = open(f_arg, O_RDONLY);
- if (f_fd < 0) {
- fprintf(stderr, "Cannot open '%s': %s\n",
+ vcl = vreadfile(f_arg);
+ if (vcl == NULL) {
+ fprintf(stderr, "Cannot read '%s': %s\n",
f_arg, strerror(errno));
exit(1);
}
}
if (b_arg != NULL || f_arg != NULL)
- if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag))
+ if (mgt_vcc_default(b_arg, vcl, C_flag))
exit (2);
if (C_flag)
/*--------------------------------------------------------------------*/
static struct source *
-vcc_file_source(struct vsb *sb, const char *fn, int fd)
+vcc_file_source(struct vsb *sb, const char *fn)
{
char *f;
struct source *sp;
- if (fd < 0) {
- fd = open(fn, O_RDONLY);
- if (fd < 0) {
- vsb_printf(sb, "Cannot open file '%s': %s\n",
- fn, strerror(errno));
- return (NULL);
- }
+ f = vreadfile(fn);
+ if (f == NULL) {
+ vsb_printf(sb, "Cannot read file '%s': %s\n",
+ fn, strerror(errno));
+ return (NULL);
}
- f = vreadfile(fd);
- AN(f);
- AZ(close(fd));
sp = vcc_new_source(f, NULL, fn);
sp->freeit = f;
return (sp);
}
assert(t2 != NULL);
- sp = vcc_file_source(tl->sb, t1->dec, -1);
+ sp = vcc_file_source(tl->sb, t1->dec);
if (sp == NULL) {
vcc_ErrWhere(tl, t1);
return;
return (r);
}
-/*--------------------------------------------------------------------
- * Compile the VCL code from the file named. Error messages, if any
- * are formatted into the vsb.
- */
-
-char *
-VCC_CompileFile(struct vsb *sb, const char *fn, int fd)
-{
- struct source *sp;
- char *r;
-
- sp = vcc_file_source(sb, fn, fd);
- if (sp == NULL)
- return (NULL);
- r = vcc_CompileSource(sb, sp);
- return (r);
-}
-
/*--------------------------------------------------------------------
* Initialize the compiler and register the default VCL code for later
* compilation runs.