From 25cada62234909a87658970d0066014b288a43d7 Mon Sep 17 00:00:00 2001 From: venaas Date: Thu, 24 May 2007 15:24:40 +0000 Subject: added strtokenquote() to replace strtok to enable quoting of values git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@107 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- radsecproxy.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/radsecproxy.c b/radsecproxy.c index 0410597..1eb84bb 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -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 -- cgit v1.1