From 8014e0bb085059cc026a129fc9f09de8435f17ed Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sat, 2 Aug 2014 22:52:25 +0200 Subject: [PATCH] =?utf8?q?frontend/grammar:=20Changed=20=E2=80=98LIST=20?= =?utf8?q?=E2=80=A6=E2=80=99=20to=20=E2=80=98LIST=20hosts=20=E2=80=A6?= =?utf8?q?=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This seems more consistent. --- src/frontend/grammar.y | 20 ++++++++++++++++---- t/integration/simple_query.sh | 6 +++--- t/unit/frontend/parser_test.c | 11 ++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index a2ae448..3ece01a 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -201,7 +201,7 @@ statement: ; /* - * FETCH ; + * FETCH [FILTER ]; * * Retrieve detailed information about a single host. */ @@ -218,17 +218,29 @@ fetch_statement: ; /* - * LIST; + * LIST [FILTER ]; * * Returns a list of all hosts in the store. */ list_statement: - LIST filter_clause + LIST IDENTIFIER filter_clause { + /* TODO: support other types as well */ + if (strcasecmp($2, "hosts")) { + 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; + sdb_object_deref(SDB_OBJ($3)); + YYABORT; + } + $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_list_t, conn_list_destroy)); - CONN_LIST($$)->filter = CONN_MATCHER($2); + CONN_LIST($$)->filter = CONN_MATCHER($3); $$->cmd = CONNECTION_LIST; + free($2); $2 = NULL; } ; diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index 86ac03f..942b77c 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -54,7 +54,7 @@ echo "$output" | grep "Failed to parse query 'INVALID'" echo "$output" | grep "parse error: syntax error" # Simple, successful commands. -output="$( run_sysdb -H "$SOCKET_FILE" -c LIST )" +output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST hosts' )" echo "$output" \ | grep -F '"host1.example.com"' \ | grep -F '"host2.example.com"' \ @@ -62,7 +62,7 @@ echo "$output" \ | grep -F '"other.host.name"' \ | grep -F '"some.host.name"' -output="$( echo 'LIST;' | run_sysdb -H "$SOCKET_FILE" )" || echo $? +output="$( echo 'LIST hosts;' | run_sysdb -H "$SOCKET_FILE" )" || echo $? echo "$output" \ | grep -F '"host1.example.com"' \ | grep -F '"host2.example.com"' \ @@ -80,7 +80,7 @@ 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;'; sleep 1; echo "FETCH 'host1.example.com'") \ +(echo 'LIST hosts;'; sleep 1; echo "FETCH 'host1.example.com'") \ | run_sysdb -H "$SOCKET_FILE" # When requesting information for unknown hosts, expect a non-zero exit code. diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index bca8645..16f61af 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -56,11 +56,11 @@ START_TEST(test_parse) { "FETCH 'host' FILTER " "host = 'host'", -1, 1, CONNECTION_FETCH }, - { "LIST", -1, 1, CONNECTION_LIST }, - { "LIST -- comment", -1, 1, CONNECTION_LIST }, - { "LIST;", -1, 1, CONNECTION_LIST }, - { "LIST; INVALID", 5, 1, CONNECTION_LIST }, - { "LIST FILTER " + { "LIST hosts", -1, 1, CONNECTION_LIST }, + { "LIST hosts -- foo", -1, 1, CONNECTION_LIST }, + { "LIST hosts;", -1, 1, CONNECTION_LIST }, + { "LIST hosts; INVALID", 11, 1, CONNECTION_LIST }, + { "LIST hosts FILTER " "host = 'host'", -1, 1, CONNECTION_LIST }, { "LOOKUP hosts", -1, 1, CONNECTION_LOOKUP }, @@ -190,6 +190,7 @@ START_TEST(test_parse) { "LIST; INVALID", 8, -1, 0 }, { "/* some incomplete", -1, -1, 0 }, + { "LIST", -1, -1, 0 }, { "LIST MATCHING " "host = 'host'", -1, -1, 0 }, { "FETCH 'host' MATCHING " -- 2.30.2