diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 92b55ebbd509eb9d62c975a3866c5aa67ce07534..b400f9acc51736fc43ebed4cb7a02ea6b03036af 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
*/
static sdb_store_matcher_t *
-name_matcher(const char *type_name, const char *cmp, sdb_store_expr_t *expr);
-
-static sdb_store_matcher_t *
-name_iter_matcher(int m_type, const char *type_name, const char *cmp,
+name_iter_matcher(int m_type, int type, const char *cmp,
sdb_store_expr_t *expr);
/*
%union {
const char *sstr; /* static string */
char *str;
+ int integer;
sdb_data_t data;
sdb_time_t datetime;
%token CMP_LT CMP_LE CMP_GE CMP_GT ALL ANY IN
%token CONCAT
+%token HOST_T HOSTS_T SERVICE_T SERVICES_T METRIC_T METRICS_T
+%token ATTRIBUTE_T ATTRIBUTES_T
+%token NAME_T LAST_UPDATE_T AGE_T INTERVAL_T BACKEND_T
+
%token START END
/* NULL token */
%type <expr> expression
+%type <integer> object_type_plural
+%type <integer> iterable
+%type <integer> field
+
%type <sstr> cmp
%type <data> data
* Retrieve detailed information about a single host.
*/
fetch_statement:
- FETCH IDENTIFIER STRING filter_clause
+ FETCH HOST_T 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($$)->type = SDB_HOST;
- CONN_FETCH($$)->name = $3;
+ CONN_FETCH($$)->host = $3;
+ CONN_FETCH($$)->name = NULL;
CONN_FETCH($$)->filter = CONN_MATCHER($4);
$$->cmd = CONNECTION_FETCH;
- free($2); $2 = NULL;
}
;
* Returns a list of all hosts in the store.
*/
list_statement:
- LIST IDENTIFIER filter_clause
+ LIST object_type_plural filter_clause
{
- int type = sdb_store_parse_object_type_plural($2);
- if ((type < 0) || (type == SDB_ATTRIBUTE)) {
- 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($$)->type = type;
+ CONN_LIST($$)->type = $2;
CONN_LIST($$)->filter = CONN_MATCHER($3);
$$->cmd = CONNECTION_LIST;
- free($2); $2 = NULL;
}
;
* Returns detailed information about <type> matching condition.
*/
lookup_statement:
- LOOKUP IDENTIFIER matching_clause filter_clause
+ LOOKUP HOSTS_T matching_clause 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));
- sdb_object_deref(SDB_OBJ($4));
- YYABORT;
- }
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_lookup_t, conn_lookup_destroy));
CONN_LOOKUP($$)->matcher = CONN_MATCHER($3);
CONN_LOOKUP($$)->filter = CONN_MATCHER($4);
$$->cmd = CONNECTION_LOOKUP;
- free($2); $2 = NULL;
}
;
sdb_object_deref(SDB_OBJ($3));
}
|
- IDENTIFIER cmp expression
- {
- $$ = name_matcher($1, $2, $3);
- free($1); $1 = NULL;
- sdb_object_deref(SDB_OBJ($3));
- }
- |
- ANY IDENTIFIER cmp expression
+ ANY iterable cmp expression
{
$$ = name_iter_matcher(MATCHER_ANY, $2, $3, $4);
- free($2); $2 = NULL;
sdb_object_deref(SDB_OBJ($4));
}
|
- ALL IDENTIFIER cmp expression
+ ALL iterable cmp expression
{
$$ = name_iter_matcher(MATCHER_ALL, $2, $3, $4);
- free($2); $2 = NULL;
sdb_object_deref(SDB_OBJ($4));
}
|
sdb_object_deref(SDB_OBJ($3)); $3 = NULL;
}
|
- '.' IDENTIFIER
+ HOST_T
{
- int field = sdb_store_parse_field_name($2);
- free($2); $2 = NULL;
- $$ = sdb_store_expr_fieldvalue(field);
+ /* TODO: this only works as long as queries
+ * are limited to hosts */
+ $$ = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
}
|
- IDENTIFIER '[' STRING ']'
+ field
+ {
+ $$ = sdb_store_expr_fieldvalue($1);
+ }
+ |
+ ATTRIBUTE_T '[' STRING ']'
{
- if (strcasecmp($1, "attribute")) {
- char errmsg[strlen($1) + strlen($3) + 32];
- snprintf(errmsg, sizeof(errmsg),
- YY_("unknown value %s[%s]"), $1, $3);
- sdb_fe_yyerror(&yylloc, scanner, errmsg);
- free($1); $1 = NULL;
- free($3); $3 = NULL;
- YYABORT;
- }
$$ = sdb_store_expr_attrvalue($3);
- free($1); $1 = NULL;
free($3); $3 = NULL;
}
|
}
;
+object_type_plural:
+ HOSTS_T { $$ = SDB_HOST; }
+ |
+ SERVICES_T { $$ = SDB_SERVICE; }
+ |
+ METRICS_T { $$ = SDB_METRIC; }
+ ;
+
+iterable:
+ SERVICE_T { $$ = SDB_SERVICE; }
+ |
+ METRIC_T { $$ = SDB_METRIC; }
+ |
+ ATTRIBUTE_T { $$ = SDB_ATTRIBUTE; }
+ ;
+
+field:
+ NAME_T { $$ = SDB_FIELD_NAME; }
+ |
+ LAST_UPDATE_T { $$ = SDB_FIELD_LAST_UPDATE; }
+ |
+ AGE_T { $$ = SDB_FIELD_AGE; }
+ |
+ INTERVAL_T { $$ = SDB_FIELD_INTERVAL; }
+ |
+ BACKEND_T { $$ = SDB_FIELD_BACKEND; }
+ ;
+
cmp:
CMP_EQUAL { $$ = "="; }
|
} /* sdb_fe_yyerror */
static sdb_store_matcher_t *
-name_matcher(const char *type_name, const char *cmp, sdb_store_expr_t *expr)
-{
- int type = sdb_store_parse_object_type(type_name);
- sdb_store_matcher_op_cb cb = sdb_store_parse_matcher_op(cmp);
- sdb_store_expr_t *e;
- sdb_store_matcher_t *m;
- assert(cb);
-
- /* TODO: this only works as long as queries
- * are limited to hosts */
- if (type != SDB_HOST)
- return NULL;
-
- e = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
- m = cb(e, expr);
- sdb_object_deref(SDB_OBJ(e));
- return m;
-} /* name_matcher */
-
-static sdb_store_matcher_t *
-name_iter_matcher(int m_type, const char *type_name, const char *cmp,
+name_iter_matcher(int m_type, int type, const char *cmp,
sdb_store_expr_t *expr)
{
- int type = sdb_store_parse_object_type(type_name);
sdb_store_matcher_op_cb cb = sdb_store_parse_matcher_op(cmp);
sdb_store_expr_t *e;
sdb_store_matcher_t *m, *tmp = NULL;