starter: Add support for multi-line strings in ipsec.conf
authorTobias Brunner <tobias@strongswan.org>
Mon, 8 Jun 2015 15:49:02 +0000 (17:49 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 28 Jul 2015 11:27:32 +0000 (13:27 +0200)
src/starter/parser/lexer.l
src/starter/parser/parser.y
src/starter/tests/suites/test_parser.c

index d9f469c..f70658e 100644 (file)
@@ -123,16 +123,11 @@ static void include_files(parser_helper_t *ctx);
 <str>{
        "\""                            |
        <<EOF>>                         |
-       \n                                      |
        \\                                      {
                if (!streq(yytext, "\""))
                {
-                       if (streq(yytext, "\n"))
-                       {       /* put the newline back to fix the line numbers */
-                               unput('\n');
-                               yy_set_bol(0);
-                       }
                        PARSER_DBG1(yyextra, "unterminated string detected");
+                       return STRING_ERROR;
                }
                if (yy_top_state(yyscanner) == inc)
                {       /* string include */
@@ -152,7 +147,7 @@ static void include_files(parser_helper_t *ctx);
        \\t     yyextra->string_add(yyextra, "\t");
        \\\r?\n /* merge lines that end with EOL characters */
        \\.     yyextra->string_add(yyextra, yytext+1);
-       [^\\\n"]+                       {
+       [^\\"]+                 {
                yyextra->string_add(yyextra, yytext);
        }
 }
index 54dedc1..0b2b3b0 100644 (file)
@@ -73,7 +73,7 @@ static int yylex(YYSTYPE *lvalp, parser_helper_t *ctx)
        conf_parser_section_t t;
 }
 %token <s> STRING
-%token EQ SPACES NEWLINE CONFIG_SETUP CONN CA
+%token EQ SPACES NEWLINE CONFIG_SETUP CONN CA STRING_ERROR
 
 /* ...and other symbols */
 %type <t> section_type
index 26a41ba..4ae7b22 100644 (file)
@@ -328,6 +328,9 @@ static struct {
        { TRUE, "conn foo\n\tkey=val     ue", "foo", "val ue" },
        { TRUE, "conn foo\n\tkey=\"val   ue\"", "foo", "val   ue" },
        { TRUE, "conn foo\n\tkey=\"val\\nue\"", "foo", "val\nue" },
+       { TRUE, "conn foo\n\tkey=\"val\nue\"", "foo", "val\nue" },
+       { TRUE, "conn foo\n\tkey=\"val\\\nue\"", "foo", "value" },
+       { FALSE, "conn foo\n\tkey=\"unterminated", "foo", NULL },
 };
 
 START_TEST(test_strings)