added strtokenquote() to replace strtok to enable quoting of values
authorvenaas <venaas>
Thu, 24 May 2007 15:24:40 +0000 (15:24 +0000)
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>
Thu, 24 May 2007 15:24:40 +0000 (15:24 +0000)
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@107 e88ac4ed-0b26-0410-9574-a7f39faa03bf

radsecproxy.c

index 0410597..1eb84bb 100644 (file)
@@ -1977,6 +1977,38 @@ struct peer *server_create(char type) {
     return server;
 }
 
+/* returns 0 on error, 1 if ok. E.g. "" will return token with empty string */
+int strtokenquote(char *s, char **token, char *del, char *quote, char *comment) {
+    char *t = s, *q;
+
+    if (!t || !token || !del)
+       return 0;
+    while (strchr(del, *t))
+       t++;
+    if (!*t || comment && strchr(comment, *t)) {
+       *token = NULL;
+       return 1;
+    }
+    if (quote && (q = strchr(quote, *t))) {
+       t++;
+       while (*t && *t != *q)
+           t++;
+       if (!*t)
+           return 0;
+       if (t[1] && !strchr(del, t[1]))
+           return 0;
+       *t = '\0';
+       *token = q + 1;
+       return 1;
+    }
+    *token = t;
+    t++;
+    while (*t && !strchr(del, *t))
+       t++;
+    *t = '\0';
+    return 1;
+}
+
 /* Parses config with following syntax:
  * One of these:
  * option-name value