Code

frontend: Let the parser run the analyzer.
authorSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 19:14:32 +0000 (20:14 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 19:14:32 +0000 (20:14 +0100)
… but only when parsing a full statement. Otherwise, the analyzer is missing
the context for verification.

src/frontend/parser.c
src/frontend/query.c

index 785b7e40b59caecc3f34d5e8660f7d04f918e397..f8c82d3e234b856506bb3461b0563ab1f38505fc 100644 (file)
@@ -72,6 +72,7 @@ sdb_fe_parse(const char *query, int len)
 {
        sdb_fe_yyscan_t scanner;
        sdb_fe_yyextra_t yyextra;
+       sdb_llist_iter_t *iter;
        int yyres;
 
        if (scanner_init(query, len, &scanner, &yyextra))
@@ -84,6 +85,18 @@ sdb_fe_parse(const char *query, int len)
                sdb_llist_destroy(yyextra.parsetree);
                return NULL;
        }
+
+       iter = sdb_llist_get_iter(yyextra.parsetree);
+       while (sdb_llist_iter_has_next(iter)) {
+               sdb_conn_node_t *node;
+               node = SDB_CONN_NODE(sdb_llist_iter_get_next(iter));
+               if (sdb_fe_analyze(node)) {
+                       sdb_llist_iter_destroy(iter);
+                       sdb_llist_destroy(yyextra.parsetree);
+                       return NULL;
+               }
+       }
+       sdb_llist_iter_destroy(iter);
        return yyextra.parsetree;
 } /* sdb_fe_parse */
 
index 7b105e731bf056af321611bc444a2a7287151d6a..e5a1fc43263b925653f71539ca369a5f677646b7 100644 (file)
@@ -107,16 +107,7 @@ sdb_fe_query(sdb_conn_t *conn)
        }
 
        if (node) {
-               if (sdb_fe_analyze(node)) {
-                       char query[conn->cmd_len + 1];
-                       strncpy(query, sdb_strbuf_string(conn->buf), conn->cmd_len);
-                       query[sizeof(query) - 1] = '\0';
-                       sdb_log(SDB_LOG_ERR, "frontend: Failed to verify query '%s'",
-                                       query);
-                       status = -1;
-               }
-               else
-                       status = sdb_fe_exec(conn, node);
+               status = sdb_fe_exec(conn, node);
                sdb_object_deref(SDB_OBJ(node));
        }
 
@@ -214,6 +205,8 @@ sdb_fe_lookup(sdb_conn_t *conn)
        node.type = type;
        m_node.matcher = m;
 
+       /* run analyzer separately; parse_matcher is missing
+        * the right context to do so */
        if (sdb_fe_analyze(SDB_CONN_NODE(&node))) {
                char expr[matcher_len + 1];
                strncpy(expr, matcher, sizeof(expr));