Commit 4993ea0d authored by Daniel Salzman's avatar Daniel Salzman

yparser: improve invalid indentation check

parent 2398655d
......@@ -120,12 +120,13 @@ static const struct error errors[] = {
{ KNOT_DNSSEC_EMISSINGKEYTYPE, "missing active KSK or ZSK" },
/* Yparser errors. */
{ KNOT_YP_EINVAL_ITEM, "invalid item" },
{ KNOT_YP_EINVAL_DATA, "invalid value" },
{ KNOT_YP_ENOTSUP_DATA, "value not supported" },
{ KNOT_YP_ENOTSUP_ID, "identifier not supported" },
{ KNOT_YP_ENODATA, "missing value" },
{ KNOT_YP_ENOID, "missing identifier" },
{ KNOT_YP_EINVAL_ITEM, "invalid item" },
{ KNOT_YP_EINVAL_DATA, "invalid value" },
{ KNOT_YP_EINVAL_INDENT, "invalid indentation" },
{ KNOT_YP_ENOTSUP_DATA, "value not supported" },
{ KNOT_YP_ENOTSUP_ID, "identifier not supported" },
{ KNOT_YP_ENODATA, "missing value" },
{ KNOT_YP_ENOID, "missing identifier" },
/* Configuration errors. */
{ KNOT_CONF_EMPTY, "empty configuration database" },
......
......@@ -126,6 +126,7 @@ enum knot_error {
/* Yparser errors. */
KNOT_YP_EINVAL_ITEM,
KNOT_YP_EINVAL_DATA,
KNOT_YP_EINVAL_INDENT,
KNOT_YP_ENOTSUP_DATA,
KNOT_YP_ENOTSUP_ID,
KNOT_YP_ENODATA,
......
......@@ -301,7 +301,7 @@ _match:
{
if (indent > 0 && parser->indent > 0 &&
indent != parser->indent) {
return KNOT_EPARSEFAIL;
return KNOT_YP_EINVAL_INDENT;
}
parser->processed = false;
parser->key_len = 0;
......@@ -321,6 +321,7 @@ _match:
{
parser->key[parser->key_len] = '\0';
parser->indent = 0;
parser->id_pos = 0;
parser->event = YP_EKEY0;
}
break;
......@@ -353,7 +354,7 @@ _match:
{
if (id_pos > 0 && parser->id_pos > 0 &&
id_pos != parser->id_pos) {
return KNOT_EPARSEFAIL;
return KNOT_YP_EINVAL_INDENT;
}
parser->indent = 0;
}
......
......@@ -91,7 +91,7 @@
action _key_init {
if (indent > 0 && parser->indent > 0 &&
indent != parser->indent) {
return KNOT_EPARSEFAIL;
return KNOT_YP_EINVAL_INDENT;
}
parser->processed = false;
parser->key_len = 0;
......@@ -107,6 +107,7 @@
action _key0_exit {
parser->key[parser->key_len] = '\0';
parser->indent = 0;
parser->id_pos = 0;
parser->event = YP_EKEY0;
}
action _key1_exit {
......@@ -129,7 +130,7 @@
action _dash_init {
if (id_pos > 0 && parser->id_pos > 0 &&
id_pos != parser->id_pos) {
return KNOT_EPARSEFAIL;
return KNOT_YP_EINVAL_INDENT;
}
parser->indent = 0;
}
......
......@@ -60,7 +60,9 @@ const char *syntax_ok =
" - domain: example. # comment\n"
" master: bind\n"
" - domain: example.\n"
" master: bind\n";
" master: bind\n"
"zone2:\n"
" - a: b # different indentation";
const char *syntax_error1 =
"f:\n"
......@@ -180,6 +182,20 @@ int main(int argc, char *argv[])
"compare key1");
}
line = 39;
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key0");
ok(yp->key_len == 5 && strcmp(yp->key, "zone2") == 0 &&
yp->data_len == 0 &&
yp->event == YP_EKEY0 && yp->line_count == line,
"compare key0 value");
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key1");
ok(yp->key_len == 1 && strcmp(yp->key, "a") == 0 &&
yp->data_len == 1 && strcmp(yp->data, "b") == 0 &&
yp->event == YP_EID && yp->line_count == line + 1,
"compare key1 value");
ret = yp_parse(yp);
ok(ret == KNOT_EOF, "parse EOF");
......@@ -191,7 +207,7 @@ int main(int argc, char *argv[])
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key1");
ret = yp_parse(yp);
ok(ret == KNOT_EPARSEFAIL, "parse invalid key1");
ok(ret == KNOT_YP_EINVAL_INDENT, "parse key1 - invalid indentation");
// Error input 2.
ret = yp_set_input_string(yp, syntax_error2, strlen(syntax_error2));
......@@ -201,7 +217,7 @@ int main(int argc, char *argv[])
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key1");
ret = yp_parse(yp);
ok(ret == KNOT_EPARSEFAIL, "parse invalid key1");
ok(ret == KNOT_YP_EINVAL_INDENT, "parse key1 - invalid indentation");
// Error input 3.
ret = yp_set_input_string(yp, syntax_error3, strlen(syntax_error3));
......@@ -211,7 +227,7 @@ int main(int argc, char *argv[])
ret = yp_parse(yp);
ok(ret == KNOT_EOK, "parse key1");
ret = yp_parse(yp);
ok(ret == KNOT_EPARSEFAIL, "parse invalid key1");
ok(ret == KNOT_YP_EINVAL_INDENT, "parse key1 - invalid indentation");
yp_deinit(yp);
......
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