summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ea9e77c)
raw | patch | inline | side by side (parent: ea9e77c)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 21 Jul 2014 16:51:48 +0000 (18:51 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 21 Jul 2014 16:51:48 +0000 (18:51 +0200) |
This feels a bit more natural and no longer shadows attributes called "name".
index da9f55076f6d5a1fc33969bee7012d3fb6ea6856..a3efb4669c182ee66938ac3554ba79c10d577d84 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
sdb_store_cond_t *cond;
_Bool inv = 0;
- /* TODO: this will reject any attributes called "name";
- * use a different syntax for querying objects by name */
- if (! strcasecmp(attr, "name"))
+ if (! attr)
return NULL;
if (! strcasecmp(op, "IS")) {
return NULL;
}
- if (! strcasecmp(attr, "name"))
+ if (! attr)
m = sdb_store_name_matcher(type, value->data.string, re);
else if (type == SDB_ATTRIBUTE)
m = sdb_store_attr_matcher(attr, value->data.string, re);
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 2173e6df1b383f1ce2ce58f849cb70c37aa021c2..d5054854c3153a1298a238ad1bee2026a965cd51 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
* Parse matchers comparing object attributes with a value.
*/
compare_matcher:
+ IDENTIFIER op data
+ {
+ $$ = sdb_store_matcher_parse_cmp($1, NULL, $2, &$3);
+ free($1); $1 = NULL;
+ sdb_data_free_datum(&$3);
+ }
+ |
IDENTIFIER '.' IDENTIFIER op data
{
$$ = sdb_store_matcher_parse_cmp($1, $3, $4, &$5);
index a474a524367eb213b1e8f614c3ea085b25a0fa64..ef12bf8f2dbf1a735ff284c7cfb8b084b19098c9 100755 (executable)
echo "$output" | grep -F 'some.host.name' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE attribute.name != 'architecture'" )"
+ -c "LOOKUP hosts WHERE attribute != 'architecture'" )"
echo "$output" \
| grep -F '"some.host.name"' \
| grep -F '"localhost"'
echo "$output" | grep -F 'host2.example.com' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE service.name = 'sysdbd'" )"
+ -c "LOOKUP hosts WHERE service = 'sysdbd'" )"
echo "$output" | grep -F '"localhost"'
echo "$output" | grep -F 'some.host.name' && exit 1
echo "$output" | grep -F 'other.host.name' && exit 1
echo "$output" | grep -F 'host2.example.com' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts WHERE host.name =~ 'example.com'" )"
+ -c "LOOKUP hosts WHERE host =~ 'example.com'" )"
echo "$output" \
| grep -F '"host1.example.com"' \
| grep -F '"host2.example.com"'
index 7536f390bc96cfe9b556326271925c367ff6d0a7..7ecaaf0c3706fb535909cf8488c23dc158234e99 100644 (file)
const sdb_data_t *value;
int expected;
} golden_data[] = {
- { "host", "name", "=", &hostname, MATCHER_NAME },
- { "host", "name", "!=", &hostname, MATCHER_NOT },
- { "host", "name", "=~", &hostname, MATCHER_NAME },
- { "host", "name", "!~", &hostname, MATCHER_NOT },
+ { "host", NULL, "=", &hostname, MATCHER_NAME },
+ { "host", NULL, "!=", &hostname, MATCHER_NOT },
+ { "host", NULL, "=~", &hostname, MATCHER_NAME },
+ { "host", NULL, "!~", &hostname, MATCHER_NOT },
{ "host", "attr", "=", &hostname, -1 },
{ "host", "attr", "!=", &hostname, -1 },
- { "host", "name", "&^", &hostname, -1 },
- { "host", "name", "<", &hostname, -1 },
- { "host", "name", "<=", &hostname, -1 },
- { "host", "name", ">=", &hostname, -1 },
- { "host", "name", ">", &hostname, -1 },
- { "service", "name", "=", &srvname, MATCHER_NAME },
- { "service", "name", "!=", &srvname, MATCHER_NOT },
- { "service", "name", "=~", &srvname, MATCHER_NAME },
- { "service", "name", "!~", &srvname, MATCHER_NOT },
+ { "host", NULL, "&^", &hostname, -1 },
+ { "host", NULL, "<", &hostname, -1 },
+ { "host", NULL, "<=", &hostname, -1 },
+ { "host", NULL, ">=", &hostname, -1 },
+ { "host", NULL, ">", &hostname, -1 },
+ { "service", NULL, "=", &srvname, MATCHER_NAME },
+ { "service", NULL, "!=", &srvname, MATCHER_NOT },
+ { "service", NULL, "=~", &srvname, MATCHER_NAME },
+ { "service", NULL, "!~", &srvname, MATCHER_NOT },
{ "service", "attr", "=", &srvname, -1 },
{ "service", "attr", "!=", &srvname, -1 },
- { "service", "name", "&^", &srvname, -1 },
- { "service", "name", "<", &srvname, -1 },
- { "service", "name", "<=", &srvname, -1 },
- { "service", "name", ">=", &srvname, -1 },
- { "service", "name", ">", &srvname, -1 },
- { "attribute", "name", "=", &attrname, MATCHER_NAME },
- { "attribute", "name", "!=", &attrname, MATCHER_NOT },
- { "attribute", "name", "=~", &attrname, MATCHER_NAME },
- { "attribute", "name", "!~", &attrname, MATCHER_NOT },
- { "attribute", "name", "<", &attrname, -1 },
- { "attribute", "name", "<=", &attrname, -1 },
- { "attribute", "name", ">=", &attrname, -1 },
- { "attribute", "name", ">", &attrname, -1 },
+ { "service", NULL, "&^", &srvname, -1 },
+ { "service", NULL, "<", &srvname, -1 },
+ { "service", NULL, "<=", &srvname, -1 },
+ { "service", NULL, ">=", &srvname, -1 },
+ { "service", NULL, ">", &srvname, -1 },
+ { "attribute", NULL, "=", &attrname, MATCHER_NAME },
+ { "attribute", NULL, "!=", &attrname, MATCHER_NOT },
+ { "attribute", NULL, "=~", &attrname, MATCHER_NAME },
+ { "attribute", NULL, "!~", &attrname, MATCHER_NOT },
+ { "attribute", NULL, "<", &attrname, -1 },
+ { "attribute", NULL, "<=", &attrname, -1 },
+ { "attribute", NULL, ">=", &attrname, -1 },
+ { "attribute", NULL, ">", &attrname, -1 },
{ "attribute", "attr", "=", &attrname, MATCHER_ATTR },
{ "attribute", "attr", "!=", &attrname, MATCHER_NOT },
{ "attribute", "attr", "=~", &attrname, MATCHER_ATTR },
{ "attribute", "attr", ">", &attrname, MATCHER_GT },
{ "attribute", "attr", "IS", NULL, MATCHER_ISNULL },
{ "attribute", "attr", "IS", &attrname, -1 },
- { "foo", "name", "=", &attrname, -1 },
+ { "foo", NULL, "=", &attrname, -1 },
{ "foo", "attr", "=", &attrname, -1 },
};
int expected;
const char *tostring_re;
} golden_data[] = {
- { "host.name = 'a'", 1,
+ { "host = 'a'", 1,
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
- { "host.name =~ 'a|b'", 2,
+ { "host =~ 'a|b'", 2,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ 'host'", 0,
+ { "host =~ 'host'", 0,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host.name =~ '.'", 3,
+ { "host =~ '.'", 3,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "service.name = 's1'", 2,
+ { "service = 's1'", 2,
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
- { "service.name =~ 's'", 2,
+ { "service =~ 's'", 2,
"OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "service.name !~ 's'", 1,
+ { "service !~ 's'", 1,
"\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
- { "attribute.name = 'k1'", 1,
+ { "attribute = 'k1'", 1,
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
- { "attribute.name = 'x'", 0,
+ { "attribute = 'x'", 0,
"OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
{ "attribute.k1 = 'v1'", 1,
"ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
{ "attribute.k1 != 'v2'", 3,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
- { "attribute.name != 'x' "
+ { "attribute != 'x' "
"AND attribute.y !~ 'x'", 3,
"\\(AND, "
"\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
index 4b9b6728d00ebb7bece003f7dc47de1f4ad3c236..f1e656982cbb21de211fd850b64e456da68ee84f 100644 (file)
{ "LIST; INVALID", 5, 1, CONNECTION_LIST },
{ "LOOKUP hosts WHERE "
- "host.name = 'host'", -1, 1, CONNECTION_LOOKUP },
+ "host = 'host'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE NOT "
- "host.name = 'host'", -1, 1, CONNECTION_LOOKUP },
+ "host = 'host'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE "
- "host.name =~ 'p' AND "
- "service.name =~ 'p'", -1, 1, CONNECTION_LOOKUP },
+ "host =~ 'p' AND "
+ "service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE NOT "
- "host.name =~ 'p' AND "
- "service.name =~ 'p'", -1, 1, CONNECTION_LOOKUP },
+ "host =~ 'p' AND "
+ "service =~ 'p'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE "
- "host.name =~ 'p' AND "
- "service.name =~ 'p' OR "
- "service.name =~ 'r'", -1, 1, CONNECTION_LOOKUP },
+ "host =~ 'p' AND "
+ "service =~ 'p' OR "
+ "service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE NOT "
- "host.name =~ 'p' AND "
- "service.name =~ 'p' OR "
- "service.name =~ 'r'", -1, 1, CONNECTION_LOOKUP },
+ "host =~ 'p' AND "
+ "service =~ 'p' OR "
+ "service =~ 'r'", -1, 1, CONNECTION_LOOKUP },
/* numeric constants */
{ "LOOKUP hosts WHERE "
"NOT attribute.foo "
"IS NULL", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts WHERE "
- "host.name IS NULL", -1, -1, 0 },
+ "host IS NULL", -1, -1, 0 },
{ "LOOKUP hosts WHERE "
- "service.name "
- "IS NULL", -1, -1, 0 },
+ "service IS NULL", -1, -1, 0 },
/* invalid numeric constants */
{ "LOOKUP hosts WHERE "
{ "LOOKUP hosts", -1, -1, 0 },
{ "LOOKUP foo WHERE "
- "host.name = 'host'", -1, -1, 0 },
+ "host = 'host'", -1, -1, 0 },
};
size_t i;
int expected;
} golden_data[] = {
/* empty expressions */
- { NULL, -1, -1 },
- { "", -1, -1 },
+ { NULL, -1, -1 },
+ { "", -1, -1 },
/* valid expressions */
- { "host.name = 'localhost'", -1, MATCHER_NAME },
- { "host.name != 'localhost'", -1, MATCHER_NOT },
- { "host.name =~ 'host'", -1, MATCHER_NAME },
- { "host.name !~ 'host'", -1, MATCHER_NOT },
- { "host.name = 'localhost' -- foo", -1, MATCHER_NAME },
- { "host.name = 'host' <garbage>", 18, MATCHER_NAME },
+ { "host = 'localhost'", -1, MATCHER_NAME },
+ { "host != 'localhost'", -1, MATCHER_NOT },
+ { "host =~ 'host'", -1, MATCHER_NAME },
+ { "host !~ 'host'", -1, MATCHER_NOT },
+ { "host = 'localhost' -- foo", -1, MATCHER_NAME },
+ { "host = 'host' <garbage>", 13, MATCHER_NAME },
/* match hosts by service */
- { "service.name = 'name'", -1, MATCHER_NAME },
- { "service.name != 'name'", -1, MATCHER_NOT },
- { "service.name =~ 'pattern'", -1, MATCHER_NAME },
- { "service.name !~ 'pattern'", -1, MATCHER_NOT },
+ { "service = 'name'", -1, MATCHER_NAME },
+ { "service != 'name'", -1, MATCHER_NOT },
+ { "service =~ 'pattern'", -1, MATCHER_NAME },
+ { "service !~ 'pattern'", -1, MATCHER_NOT },
/* match hosts by attribute */
- { "attribute.name = 'name'", -1, MATCHER_NAME },
- { "attribute.name != 'name'", -1, MATCHER_NOT },
- { "attribute.name =~ 'pattern'", -1, MATCHER_NAME },
- { "attribute.name !~ 'pattern'", -1, MATCHER_NOT },
+ { "attribute = 'name'", -1, MATCHER_NAME },
+ { "attribute != 'name'", -1, MATCHER_NOT },
+ { "attribute =~ 'pattern'", -1, MATCHER_NAME },
+ { "attribute !~ 'pattern'", -1, MATCHER_NOT },
/* composite expressions */
- { "host.name =~ 'pattern' AND "
- "service.name =~ 'pattern'", -1, MATCHER_AND },
- { "host.name =~ 'pattern' OR "
- "service.name =~ 'pattern'", -1, MATCHER_OR },
- { "NOT host.name = 'host'", -1, MATCHER_NOT },
+ { "host =~ 'pattern' AND "
+ "service =~ 'pattern'", -1, MATCHER_AND },
+ { "host =~ 'pattern' OR "
+ "service =~ 'pattern'", -1, MATCHER_OR },
+ { "NOT host = 'host'", -1, MATCHER_NOT },
/* numeric expressions */
- { "attribute.foo < 123", -1, MATCHER_LT },
- { "attribute.foo <= 123", -1, MATCHER_LE },
- { "attribute.foo = 123", -1, MATCHER_EQ },
- { "attribute.foo >= 123", -1, MATCHER_GE },
- { "attribute.foo > 123", -1, MATCHER_GT },
+ { "attribute.foo < 123", -1, MATCHER_LT },
+ { "attribute.foo <= 123", -1, MATCHER_LE },
+ { "attribute.foo = 123", -1, MATCHER_EQ },
+ { "attribute.foo >= 123", -1, MATCHER_GE },
+ { "attribute.foo > 123", -1, MATCHER_GT },
/* NULL; while this is an implementation detail,
* IS NULL currently maps to an equality matcher */
- { "attribute.foo IS NULL", -1, MATCHER_ISNULL },
- { "attribute.foo IS NOT NULL", -1, MATCHER_NOT },
+ { "attribute.foo IS NULL", -1, MATCHER_ISNULL },
+ { "attribute.foo IS NOT NULL", -1, MATCHER_NOT },
/* check operator precedence */
- { "host.name = 'name' OR "
- "service.name = 'name' AND "
- "attribute.name = 'name' OR "
- "attribute.foo = 'bar'", -1, MATCHER_OR },
- { "host.name = 'name' AND "
- "service.name = 'name' AND "
- "attribute.name = 'name' OR "
- "attribute.foo = 'bar'", -1, MATCHER_OR },
- { "host.name = 'name' AND "
- "service.name = 'name' OR "
- "attribute.name = 'name' AND "
- "attribute.foo = 'bar'", -1, MATCHER_OR },
- { "(host.name = 'name' OR "
- "service.name = 'name') AND "
- "(attribute.name = 'name' OR "
- "attribute.foo = 'bar')", -1, MATCHER_AND },
- { "NOT host.name = 'name' OR "
- "service.name = 'name'", -1, MATCHER_OR },
- { "NOT host.name = 'name' OR "
- "NOT service.name = 'name'", -1, MATCHER_OR },
- { "NOT (host.name = 'name' OR "
- "NOT service.name = 'name')", -1, MATCHER_NOT },
+ { "host = 'name' OR "
+ "service = 'name' AND "
+ "attribute = 'name' OR "
+ "attribute.foo = 'bar'", -1, MATCHER_OR },
+ { "host = 'name' AND "
+ "service = 'name' AND "
+ "attribute = 'name' OR "
+ "attribute.foo = 'bar'", -1, MATCHER_OR },
+ { "host = 'name' AND "
+ "service = 'name' OR "
+ "attribute = 'name' AND "
+ "attribute.foo = 'bar'", -1, MATCHER_OR },
+ { "(host = 'name' OR "
+ "service = 'name') AND "
+ "(attribute = 'name' OR "
+ "attribute.foo = 'bar')", -1, MATCHER_AND },
+ { "NOT host = 'name' OR "
+ "service = 'name'", -1, MATCHER_OR },
+ { "NOT host = 'name' OR "
+ "NOT service = 'name'", -1, MATCHER_OR },
+ { "NOT (host = 'name' OR "
+ "NOT service = 'name')", -1, MATCHER_NOT },
/* syntax errors */
- { "LIST", -1, -1 },
- { "foo &^ bar", -1, -1 },
+ { "LIST", -1, -1 },
+ { "foo &^ bar", -1, -1 },
};
size_t i;