From ae9df63aa9cb400e7c169b654f23a5b9e368aa7e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 28 Mar 2012 21:51:07 +0200 Subject: Config: allow escaping quotes in strings --- src/config.l | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/config.l') diff --git a/src/config.l b/src/config.l index 8a96b40..b1e61e6 100644 --- a/src/config.l +++ b/src/config.l @@ -26,6 +26,9 @@ secret { return TOK_SECRET; } key { return TOK_KEY; } include { return TOK_INCLUDE; } as { return TOK_AS; } +any { return TOK_ANY; } +tap { return TOK_TAP; } +tun { return TOK_TUN; } [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} { if (!inet_pton(AF_INET, yytext, &yylval->addr)) { @@ -36,19 +39,29 @@ as { return TOK_AS; } return TOK_ADDR; } -any { yylval->str = yytext; return TOK_ANY; } -tap { yylval->str = yytext; return TOK_TAP; } -tun { yylval->str = yytext; return TOK_TUN; } - [;:\{\}] { return yytext[0]; } [ \t\n] ; } -\"\" { yylval->str = strdup(""); return TOK_STRING; } \" BEGIN(STRING); -[^"]+ { yylval->str = strdup(yytext); return TOK_STRING; } -\" BEGIN(INITIAL); +[^"\\]* yymore(); +\\(.|\n) yymore(); +\" { + int i, esc = 0; + + for (i = 0; i < yyleng; i++) { + if (yytext[i] == '\\') + esc++; + else if(esc) + yytext[i-esc] = yytext[i]; + } + yytext[yyleng-esc-1] = 0; + yylval->str = strdup(yytext); + BEGIN(INITIAL); + return TOK_STRING; + + } \[ BEGIN(ADDR6); [^\]]+ { -- cgit v1.2.3