X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Ffrontend%2Fanalyzer.c;h=01e1ad357adec6502fc7efc74768bee7cdf03969;hp=c71d5ca078b5fbe9a3915013c183bb05ab6bd1f5;hb=5ced2b9eb4d4def7d3ad5b1172004293e7a68e0e;hpb=59947b2a42517a95b9c4451c8ebca0c0d8aadc11 diff --git a/src/frontend/analyzer.c b/src/frontend/analyzer.c index c71d5ca..01e1ad3 100644 --- a/src/frontend/analyzer.c +++ b/src/frontend/analyzer.c @@ -45,7 +45,7 @@ iter_error(sdb_strbuf_t *errbuf, int op, sdb_store_expr_t *iter, int context) sdb_strbuf_sprintf(errbuf, "Invalid %s iterator: %s %s " "not iterable in %s context", MATCHER_SYM(op), EXPR_TO_STRING(iter), SDB_STORE_TYPE_TO_NAME(iter->data_type), - SDB_STORE_TYPE_TO_NAME(context)); + context == -1 ? "generic" : SDB_STORE_TYPE_TO_NAME(context)); } /* iter_error */ static void @@ -95,19 +95,30 @@ analyze_expr(int context, sdb_store_expr_t *e, sdb_strbuf_t *errbuf) if (context == (int)e->data.data.integer) return 0; if ((e->data.data.integer == SDB_HOST) && - ((context == SDB_SERVICE) || (context == SDB_METRIC))) + ((context == SDB_SERVICE) || (context == SDB_METRIC) + || (context < 0))) return 0; sdb_strbuf_sprintf(errbuf, "Invalid expression %s.%s " "in %s context", SDB_STORE_TYPE_TO_NAME(e->data.data.integer), - EXPR_TO_STRING(e->left), SDB_STORE_TYPE_TO_NAME(context)); + EXPR_TO_STRING(e->left), + context == -1 ? "generic" : SDB_STORE_TYPE_TO_NAME(context)); return -1; case ATTR_VALUE: - case FIELD_VALUE: case 0: break; + case FIELD_VALUE: + if ((e->data.data.integer == SDB_FIELD_VALUE) + && (context != SDB_ATTRIBUTE)) { + sdb_strbuf_sprintf(errbuf, "Invalid expression %s.value " + "(only attributes have a value)", + SDB_STORE_TYPE_TO_NAME(context)); + return -1; + } + break; + default: if (analyze_expr(context, e->left, errbuf)) return -1; @@ -153,47 +164,50 @@ analyze_matcher(int context, int parent_type, case MATCHER_ANY: case MATCHER_ALL: { - int type = -1; + int child_context = -1; int left_type = -1; + int type = -1; assert(ITER_M(m)->m); - if (ITER_M(m)->iter->type == TYPED_EXPR) { - type = (int)ITER_M(m)->iter->data.data.integer; - left_type = ITER_M(m)->iter->data_type; - } - else if (ITER_M(m)->iter->type == FIELD_VALUE) { + if ((ITER_M(m)->iter->type == TYPED_EXPR) + || (ITER_M(m)->iter->type == FIELD_VALUE)) type = (int)ITER_M(m)->iter->data.data.integer; - /* element type of the field */ - left_type = ITER_M(m)->iter->data_type & 0xff; + + if (context == -1) { /* inside a filter */ + /* attributes are always iterable */ + if ((ITER_M(m)->iter->type == TYPED_EXPR) + && (type != SDB_ATTRIBUTE)) { + iter_error(errbuf, m->type, ITER_M(m)->iter, context); + return -1; + } + /* backends are always iterable */ + if ((ITER_M(m)->iter->type == FIELD_VALUE) + && (! (type != SDB_FIELD_BACKEND))) { + iter_error(errbuf, m->type, ITER_M(m)->iter, context); + return -1; + } } - else { + else if (! sdb_store_expr_iterable(ITER_M(m)->iter, context)) { iter_error(errbuf, m->type, ITER_M(m)->iter, context); return -1; } - if ((context != SDB_HOST) - && (context != SDB_SERVICE) - && (context != SDB_METRIC)) { - iter_error(errbuf, m->type, ITER_M(m)->iter, context); - return -1; - } - if (type == context) { - iter_error(errbuf, m->type, ITER_M(m)->iter, context); - return -1; + if (ITER_M(m)->iter->type == TYPED_EXPR) { + child_context = type; + left_type = ITER_M(m)->iter->data_type; } - if ((type != SDB_SERVICE) - && (type != SDB_METRIC) - && (type != SDB_ATTRIBUTE) - && (type != SDB_FIELD_BACKEND)) { - iter_error(errbuf, m->type, ITER_M(m)->iter, context); - return -1; + else if (ITER_M(m)->iter->type == FIELD_VALUE) { + child_context = context; + /* element type of the field */ + left_type = ITER_M(m)->iter->data_type & 0xff; } - if ((context == SDB_SERVICE) && (type == SDB_METRIC)) { - iter_error(errbuf, m->type, ITER_M(m)->iter, context); - return -1; + else if (! ITER_M(m)->iter->type) { + child_context = context; + /* elements of the array constant */ + left_type = ITER_M(m)->iter->data.type & 0xff; } - else if ((context == SDB_METRIC) && (type == SDB_SERVICE)) { + else { iter_error(errbuf, m->type, ITER_M(m)->iter, context); return -1; } @@ -222,7 +236,14 @@ analyze_matcher(int context, int parent_type, return -1; } } - if (analyze_matcher(type, m->type, ITER_M(m)->m, errbuf)) + if (child_context <= 0) { + sdb_strbuf_sprintf(errbuf, "Unable to determine the context " + "(object type) of iterator %s %s %s %s", + MATCHER_SYM(m->type), SDB_TYPE_TO_STRING(left_type), + MATCHER_SYM(ITER_M(m)->m->type), + SDB_TYPE_TO_STRING(CMP_M(ITER_M(m)->m)->right->data_type)); + } + if (analyze_matcher(child_context, m->type, ITER_M(m)->m, errbuf)) return -1; break; } @@ -382,10 +403,17 @@ sdb_fe_analyze(sdb_conn_node_t *node, sdb_strbuf_t *errbuf) } else { sdb_strbuf_sprintf(errbuf, - "Don't know how to analyze command %#x", node->cmd); + "Don't know how to analyze %s command (id=%#x)", + SDB_CONN_MSGTYPE_TO_STRING(node->cmd), node->cmd); return -1; } + if (context <= 0) { + sdb_strbuf_sprintf(errbuf, "Unable to determine the context " + "(object type) for %s command (id=%#x)", + SDB_CONN_MSGTYPE_TO_STRING(node->cmd), node->cmd); + return -1; + } if (analyze_matcher(context, -1, m, errbuf)) status = -1; if (analyze_matcher(-1, -1, filter, errbuf))