From 7e793f3944a35ead8d767d297e9b80651d648dc4 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 2 Aug 2014 23:05:44 +0200 Subject: [PATCH] =?utf8?q?frontend/grammar:=20Changes=20=E2=80=98FETCH=20'?= =?utf8?q?name'=E2=80=99=20to=20=E2=80=98FETCH=20host=20'name'=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This also seems more consistent. --- src/frontend/grammar.y | 20 ++++++++++++++++---- t/integration/simple_query.sh | 6 +++--- t/unit/frontend/parser_test.c | 17 ++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 3ece01a..a297714 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -201,17 +201,29 @@ statement: ; /* - * FETCH [FILTER ]; + * FETCH [FILTER ]; * * Retrieve detailed information about a single host. */ fetch_statement: - FETCH STRING filter_clause + FETCH IDENTIFIER STRING filter_clause { + /* TODO: support other types as well */ + if (strcasecmp($2, "host")) { + char errmsg[strlen($2) + 32]; + snprintf(errmsg, sizeof(errmsg), + YY_("unknown data-source %s"), $2); + sdb_fe_yyerror(&yylloc, scanner, errmsg); + free($2); $2 = NULL; + free($3); $3 = NULL; + sdb_object_deref(SDB_OBJ($4)); + YYABORT; + } + $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_fetch_t, conn_fetch_destroy)); - CONN_FETCH($$)->name = strdup($2); - CONN_FETCH($$)->filter = CONN_MATCHER($3); + CONN_FETCH($$)->name = $3; + CONN_FETCH($$)->filter = CONN_MATCHER($4); $$->cmd = CONNECTION_FETCH; free($2); $2 = NULL; } diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index 942b77c..f191d65 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -70,7 +70,7 @@ echo "$output" \ | grep -F '"other.host.name"' \ | grep -F '"some.host.name"' -output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH 'host1.example.com'" )" +output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'host1.example.com'" )" echo "$output" \ | grep -F '"host1.example.com"' \ | grep -F '"mock service"' \ @@ -80,11 +80,11 @@ echo "$output" | grep -F 'localhost' && exit 1 echo "$output" | grep -F 'other.host.name' && exit 1 echo "$output" | grep -F 'some.host.name' && exit 1 -(echo 'LIST hosts;'; sleep 1; echo "FETCH 'host1.example.com'") \ +(echo 'LIST hosts;'; sleep 1; echo "FETCH host 'host1.example.com'") \ | run_sysdb -H "$SOCKET_FILE" # When requesting information for unknown hosts, expect a non-zero exit code. -output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH 'does.not.exist'" )" \ +output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'does.not.exist'" )" \ && exit 1 echo "$output" | grep -F 'not found' diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index 16f61af..e6b3063 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -52,8 +52,8 @@ START_TEST(test_parse) { ";;", -1, 0, 0 }, /* valid commands */ - { "FETCH 'host'", -1, 1, CONNECTION_FETCH }, - { "FETCH 'host' FILTER " + { "FETCH host 'host'", -1, 1, CONNECTION_FETCH }, + { "FETCH host 'host' FILTER " "host = 'host'", -1, 1, CONNECTION_FETCH }, { "LIST hosts", -1, 1, CONNECTION_LIST }, @@ -187,13 +187,20 @@ START_TEST(test_parse) /* syntax errors */ { "INVALID", -1, -1, 0 }, { "FETCH host", -1, -1, 0 }, - { "LIST; INVALID", 8, -1, 0 }, + { "FETCH 'host'", -1, -1, 0 }, + { "LIST hosts; INVALID", -1, -1, 0 }, { "/* some incomplete", -1, -1, 0 }, { "LIST", -1, -1, 0 }, - { "LIST MATCHING " + { "LIST foo", -1, -1, 0 }, + { "LIST hosts MATCHING " "host = 'host'", -1, -1, 0 }, - { "FETCH 'host' MATCHING " + { "LIST foo FILTER " + "host = 'host'", -1, -1, 0 }, + { "FETCH host 'host' MATCHING " + "host = 'host'", -1, -1, 0 }, + { "FETCH foo 'host'", -1, -1, 0 }, + { "FETCH foo 'host' FILTER " "host = 'host'", -1, -1, 0 }, { "LOOKUP foo", -1, -1, 0 }, -- 2.30.2