summaryrefslogtreecommitdiff
path: root/pjsip-apps
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-06-28 03:20:17 +0000
committerBenny Prijono <bennylp@teluu.com>2007-06-28 03:20:17 +0000
commite1257e0d3173a651e5a0cdf24a4c66530c43d981 (patch)
tree7327099e6e463f29abc8e94fb6a6cdc8a72456d9 /pjsip-apps
parent4dadb8e1d7efb928aab416c79e8f1776455735a1 (diff)
Ticket #350: Support for parsing quoted arguments in pjsua config file (thanks Scott M Ober)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1399 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps')
-rw-r--r--pjsip-apps/src/pjsua/pjsua_app.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c
index 4fdd17cd..341ab5fd 100644
--- a/pjsip-apps/src/pjsua/pjsua_app.c
+++ b/pjsip-apps/src/pjsua/pjsua_app.c
@@ -264,24 +264,60 @@ static int read_config_file(pj_pool_t *pool, const char *filename,
/* Scan tokens in the file. */
while (argc < MAX_ARGS && !feof(fhnd)) {
- char *token, *p = line;
-
+ char *token;
+ char *p;
+ const char *whitespace = " \t\r\n";
+ char cDelimiter;
+ int len, token_len;
+
if (fgets(line, sizeof(line), fhnd) == NULL) break;
+
+ // Trim ending newlines
+ len = strlen(line);
+ if (line[len-1]=='\n')
+ line[--len] = '\0';
+ if (line[len-1]=='\r')
+ line[--len] = '\0';
- for (token = strtok(p, " \t\r\n"); argc < MAX_ARGS;
- token = strtok(NULL, " \t\r\n"))
- {
- int token_len;
+ if (len==0) continue;
+
+ for (p = line; *p != '\0' && argc < MAX_ARGS; p++) {
+ // first, scan whitespaces
+ while (*p != '\0' && strchr(whitespace, *p) != NULL) p++;
+
+ if (*p == '\0') // are we done yet?
+ break;
- if (!token) break;
- if (*token == '#') break;
+ if (*p == '"' || *p == '\'') { // is token a quoted string
+ cDelimiter = *p++; // save quote delimiter
+ token = p;
+
+ while (*p != '\0' && *p != cDelimiter) p++;
+
+ if (*p == '\0') // found end of the line, but,
+ cDelimiter = '\0'; // didn't find a matching quote
- token_len = strlen(token);
- if (!token_len)
- continue;
- argv[argc] = pj_pool_alloc(pool, token_len+1);
- pj_memcpy(argv[argc], token, token_len+1);
- ++argc;
+ } else { // token's not a quoted string
+ token = p;
+
+ while (*p != '\0' && strchr(whitespace, *p) == NULL) p++;
+
+ cDelimiter = *p;
+ }
+
+ *p = '\0';
+ token_len = p-token;
+
+ if (token_len > 0) {
+ if (*token == '#')
+ break; // ignore remainder of line
+
+ argv[argc] = pj_pool_alloc(pool, token_len + 1);
+ pj_memcpy(argv[argc], token, token_len + 1);
+ ++argc;
+ }
+
+ *p = cDelimiter;
}
}