Commit 23edde75 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Improve error messages in backend specifications



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2883 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 94f528da
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
flexelint \ flexelint \
-I/usr/include \ -I/usr/include \
-I. \ -I. \
-I../.. \
-I../../include \ -I../../include \
-I../../contrib/libevent \ -I../../contrib/libevent \
flint.lnt \ flint.lnt \
......
...@@ -187,15 +187,13 @@ vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) ...@@ -187,15 +187,13 @@ vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs)
return (ok); return (ok);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Parse and emit a backend host specification. * Parse and emit a backend host definition
* *
* The syntax is the following: * The syntax is the following:
* *
* backend_spec: * backend_host_def:
* name_of_backend # by reference * '{' be_elements '}'
* '{' be_elements '}' # by specification
* *
* be_elements: * be_elements:
* be_element * be_element
...@@ -208,38 +206,18 @@ vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) ...@@ -208,38 +206,18 @@ vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs)
*/ */
static void static void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial)
{ {
struct token *t_field; struct token *t_field;
struct token *t_first; struct token *t_first;
struct token *t_host = NULL; struct token *t_host = NULL;
struct token *t_port = NULL; struct token *t_port = NULL;
const char *ep; const char *ep;
struct host *h;
struct fld_spec *fs; struct fld_spec *fs;
fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL); fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL);
t_first = tl->t; t_first = tl->t;
if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) {
if (vcc_Teq(h->name, tl->t))
break;
}
if (h == NULL) {
vsb_printf(tl->sb, "Reference to unknown backend ");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
vcc_AddRef(tl, h->name, R_BACKEND);
vcc_NextToken(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
*nbh = h->hnum;
return;
}
ExpectErr(tl, '{'); ExpectErr(tl, '{');
vcc_NextToken(tl); vcc_NextToken(tl);
...@@ -332,6 +310,53 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, c ...@@ -332,6 +310,53 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, c
vcc_NextToken(tl); vcc_NextToken(tl);
} }
/*--------------------------------------------------------------------
* Parse and emit a backend host specification.
*
* The syntax is the following:
*
* backend_spec:
* name_of_backend # by reference
* '{' be_elements '}' # by specification
*
* The struct vrt_backend is emitted to Fh().
*/
static void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial)
{
struct host *h;
if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) {
if (vcc_Teq(h->name, tl->t))
break;
}
if (h == NULL) {
vsb_printf(tl->sb, "Reference to unknown backend ");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
vcc_AddRef(tl, h->name, R_BACKEND);
vcc_NextToken(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
*nbh = h->hnum;
} else if (tl->t->tok == '{') {
vcc_ParseHostDef(tl, nbh, name, qual, serial);
} else {
vsb_printf(tl->sb,
"Expected a backend specification here, either by name "
"or by {...}\n");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Parse a plain backend * Parse a plain backend
*/ */
...@@ -383,7 +408,7 @@ vcc_ParseBackend(struct tokenlist *tl) ...@@ -383,7 +408,7 @@ vcc_ParseBackend(struct tokenlist *tl)
static void static void
vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
{ {
struct token *t_field; struct token *t_field, *t_be;
int nbh, nelem; int nbh, nelem;
struct fld_spec *fs; struct fld_spec *fs;
unsigned u; unsigned u;
...@@ -404,6 +429,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) ...@@ -404,6 +429,7 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
PF(t_dir)); PF(t_dir));
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
t_be = tl->t;
vcc_ResetFldSpec(fs); vcc_ResetFldSpec(fs);
nbh = -1; nbh = -1;
...@@ -438,8 +464,12 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) ...@@ -438,8 +464,12 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
ErrInternal(tl); ErrInternal(tl);
} }
} }
vcc_FieldsOk(tl, fs); if (!vcc_FieldsOk(tl, fs)) {
ERRCHK(tl); vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
vcc_ErrWhere(tl, t_be);
return;
}
Fc(tl, 0, " },\n"); Fc(tl, 0, " },\n");
vcc_NextToken(tl); vcc_NextToken(tl);
} }
......
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