libmultipath: config parser: Allow '"' in strings
[multipath-tools/.git] / libmultipath / parser.c
index 3d9656f..21151a1 100644 (file)
@@ -219,11 +219,13 @@ alloc_strvec(char *string)
 
        in_string = 0;
        while (1) {
+               int two_quotes = 0;
+
                if (!vector_alloc_slot(strvec))
                        goto out;
 
                start = cp;
-               if (*cp == '"') {
+               if (*cp == '"' && !(in_string && *(cp + 1) == '"')) {
                        cp++;
                        token = MALLOC(2);
 
@@ -246,11 +248,23 @@ alloc_strvec(char *string)
                        *(token + 1) = '\0';
                        cp++;
                } else {
+
+               move_on:
                        while ((in_string ||
                                (!isspace((int) *cp) && isascii((int) *cp) &&
                                 *cp != '!' && *cp != '#' && *cp != '{' &&
                                 *cp != '}')) && *cp != '\0' && *cp != '"')
                                cp++;
+
+                       /* Two consecutive double quotes - don't end string */
+                       if (in_string && *cp == '"') {
+                               if (*(cp + 1) == '"') {
+                                       two_quotes = 1;
+                                       cp += 2;
+                                       goto move_on;
+                               }
+                       }
+
                        strlen = cp - start;
                        token = MALLOC(strlen + 1);
 
@@ -259,6 +273,16 @@ alloc_strvec(char *string)
 
                        memcpy(token, start, strlen);
                        *(token + strlen) = '\0';
+
+                       /* Replace "" by " */
+                       if (two_quotes) {
+                               char *qq = strstr(token, "\"\"");
+                               while (qq != NULL) {
+                                       memmove(qq + 1, qq + 2,
+                                               strlen + 1 - (qq + 2 - token));
+                                       qq = strstr(qq + 1, "\"\"");
+                               }
+                       }
                }
                vector_set_slot(strvec, token);