]> source.dussan.org Git - rspamd.git/commitdiff
Fixes to rcl parser found by tests.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Aug 2013 00:44:10 +0000 (01:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 13 Aug 2013 00:44:10 +0000 (01:44 +0100)
src/rcl/rcl_parser.c
test/rspamd_rcl_test.c

index 16552d325068bb64f9ea68c691584f046635fce6..b1e64d1cb3bc0f5f174119e55b64433c22b5300f 100644 (file)
@@ -300,6 +300,7 @@ rspamd_cl_lex_number (struct rspamd_cl_parser *parser,
        }
        if (errno == ERANGE) {
                rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "numeric value is out of range", err);
+               parser->prev_state = parser->state;
                parser->state = RSPAMD_RCL_STATE_ERROR;
                return FALSE;
        }
@@ -572,7 +573,6 @@ rspamd_cl_parse_key (struct rspamd_cl_parser *parser,
                        }
                        else {
                                /* Invalid identifier */
-                               parser->state = RSPAMD_RCL_STATE_ERROR;
                                rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "key must begin with a letter", err);
                                return FALSE;
                        }
@@ -731,6 +731,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
 
        p = chunk->pos;
        while (chunk->pos < chunk->end) {
+               parser->prev_state = parser->state;
                switch (parser->state) {
                case RSPAMD_RCL_STATE_INIT:
                        /*
@@ -739,6 +740,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                         * a key of newly created object
                         */
                        if (!rspamd_cl_skip_comments (parser, err)) {
+                               parser->prev_state = parser->state;
                                parser->state = RSPAMD_RCL_STATE_ERROR;
                                return FALSE;
                        }
@@ -773,6 +775,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                continue;
                        }
                        if (!rspamd_cl_parse_key (parser, chunk, err)) {
+                               parser->prev_state = parser->state;
                                parser->state = RSPAMD_RCL_STATE_ERROR;
                                return FALSE;
                        }
@@ -798,6 +801,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                rspamd_cl_chunk_skipc (chunk, *p);
                                p ++;
                                if (!rspamd_cl_lex_json_string (parser, chunk, err)) {
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -837,15 +841,17 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                break;
                        default:
                                /* Skip any spaces and comments */
-                               while (p < chunk->end && g_ascii_isspace (*p)) {
-                                       rspamd_cl_chunk_skipc (chunk, *p);
-                                       p ++;
-                               }
-                               if ((p[0] == '/' && p[1] == '/') || *p == '#') {
+                               if (g_ascii_isspace (*p) ||
+                                               (p[0] == '/' && p[1] == '/') || *p == '#') {
+                                       while (p < chunk->end && g_ascii_isspace (*p)) {
+                                               rspamd_cl_chunk_skipc (chunk, *p);
+                                               p ++;
+                                       }
                                        if (!rspamd_cl_skip_comments (parser, err)) {
                                                return FALSE;
                                        }
                                        p = chunk->pos;
+                                       continue;
                                }
                                /* Parse atom */
                                if (g_ascii_isdigit (*p) || *p == '-') {
@@ -869,6 +875,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                }
                                else {
                                        if (!rspamd_cl_parse_string_value (parser, chunk, err)) {
+                                               parser->prev_state = parser->state;
                                                parser->state = RSPAMD_RCL_STATE_ERROR;
                                                return FALSE;
                                        }
@@ -891,6 +898,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                        else if ((p[0] == '/' && p[1] == '/') || *p == '#') {
                                /* Skip comment */
                                if (!rspamd_cl_skip_comments (parser, err)) {
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -900,7 +908,8 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                /* Got a separator */
                                got_sep = TRUE;
                                if (got_comma || got_semicolon) {
-                                       rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "uexpected comma detected", err);
+                                       rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "unexpected comma detected", err);
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -913,6 +922,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                got_sep = TRUE;
                                if (got_comma || got_semicolon) {
                                        rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "unexpected semicolon detected", err);
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -928,6 +938,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                        else if (*p == '}' || *p == ']') {
                                if (parser->stack == NULL) {
                                        rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "unexpected } detected", err);
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -941,6 +952,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                }
                                else {
                                        rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "unexpected terminating symbol detected", err);
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
@@ -959,6 +971,7 @@ rspamd_cl_state_machine (struct rspamd_cl_parser *parser, GError **err)
                                /* Anything else */
                                if (!got_sep) {
                                        rspamd_cl_set_err (chunk, RSPAMD_CL_ESYNTAX, "delimiter is missing", err);
+                                       parser->prev_state = parser->state;
                                        parser->state = RSPAMD_RCL_STATE_ERROR;
                                        return FALSE;
                                }
index 8271530778c02bcc1decfe97b21ed13636626e28..0c338035f24c13ef0e4521f1a4ada9ea8a5e4961 100644 (file)
@@ -72,7 +72,7 @@ rspamd_rcl_test_func (void)
                /* Test config emitting */
                emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_CONFIG);
                g_assert (emitted != NULL);
-               msg_info ("got config output: %s", emitted);
+               msg_debug ("got config output: %s", emitted);
                parser2 = rspamd_cl_parser_new ();
                g_assert (parser2 != NULL);
                rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err);
@@ -82,7 +82,7 @@ rspamd_rcl_test_func (void)
                /* Test json emitted */
                emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_JSON);
                g_assert (emitted != NULL);
-               msg_info ("got json output: %s", emitted);
+               msg_debug ("got json output: %s", emitted);
                parser2 = rspamd_cl_parser_new ();
                g_assert (parser2 != NULL);
                rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err);
@@ -92,7 +92,7 @@ rspamd_rcl_test_func (void)
                /* Compact json */
                emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_JSON_COMPACT);
                g_assert (emitted != NULL);
-               msg_info ("got json compacted output: %s", emitted);
+               msg_debug ("got json compacted output: %s", emitted);
                parser2 = rspamd_cl_parser_new ();
                g_assert (parser2 != NULL);
                rspamd_cl_parser_add_chunk (parser2, emitted, strlen (emitted), &err);