mirror of https://github.com/OpenVPN/openvpn-gui
Do not tokenize comments -- save it as a string
- Comments (whole line or trailing segment) are assigned as a single string to ce->comment. The comment character is preserved. - Also some bug fixes and error logging: Initialize status variable before use Do not parse escaped single quote (matches openvpn.exe) Log parsing error Remove leading "--" from first token Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/519/head
parent
170a9b9e76
commit
788a4c1f9e
|
@ -30,10 +30,17 @@
|
||||||
static int
|
static int
|
||||||
legal_escape(wchar_t c)
|
legal_escape(wchar_t c)
|
||||||
{
|
{
|
||||||
wchar_t *escapes = L"\"\' \\"; /* space, ", ' or backslash */
|
wchar_t *escapes = L"\" \\"; /* ", space, and backslash */
|
||||||
return (wcschr(escapes, c) != NULL);
|
return (wcschr(escapes, c) != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
is_comment(wchar_t *s)
|
||||||
|
{
|
||||||
|
wchar_t *comment_chars = L";#";
|
||||||
|
return (s && (wcschr(comment_chars, s[0]) != NULL));
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
copy_token(wchar_t **dest, wchar_t **src, wchar_t* delim)
|
copy_token(wchar_t **dest, wchar_t **src, wchar_t* delim)
|
||||||
{
|
{
|
||||||
|
@ -49,6 +56,7 @@ copy_token(wchar_t **dest, wchar_t **src, wchar_t* delim)
|
||||||
}
|
}
|
||||||
else if (*p == L'\\')
|
else if (*p == L'\\')
|
||||||
{
|
{
|
||||||
|
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"Parse error in copy_token: illegal backslash");
|
||||||
return -1; /* parse error -- illegal backslash in input */
|
return -1; /* parse error -- illegal backslash in input */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -68,7 +76,7 @@ tokenize(config_entry_t *ce)
|
||||||
p = ce->line;
|
p = ce->line;
|
||||||
s = ce->sline;
|
s = ce->sline;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
int status;
|
int status = 0;
|
||||||
|
|
||||||
for ( ; *p != L'\0'; p++, s++)
|
for ( ; *p != L'\0'; p++, s++)
|
||||||
{
|
{
|
||||||
|
@ -92,9 +100,23 @@ tokenize(config_entry_t *ce)
|
||||||
p++;
|
p++;
|
||||||
status = copy_token(&s, &p, L"\"");
|
status = copy_token(&s, &p, L"\"");
|
||||||
}
|
}
|
||||||
|
else if (is_comment(p))
|
||||||
|
{
|
||||||
|
/* store rest of the line as comment -- remove from tokens */
|
||||||
|
ce->comment = s;
|
||||||
|
wcsncpy(s, p, wcslen(p));
|
||||||
|
ce->tokens[--i] = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = copy_token(&s, &p, L" \t");
|
status = copy_token(&s, &p, L" \t");
|
||||||
if (status != 0) return status;
|
}
|
||||||
|
|
||||||
|
if (status != 0)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
if (*p == L'\0') break;
|
if (*p == L'\0') break;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +144,7 @@ config_readline(FILE *fd, int first)
|
||||||
config_entry_t *ce = calloc(sizeof(*ce), 1);
|
config_entry_t *ce = calloc(sizeof(*ce), 1);
|
||||||
if (!ce)
|
if (!ce)
|
||||||
{
|
{
|
||||||
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"Out of memory in tokenize");
|
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"Out of memory in config_readline");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +159,12 @@ config_readline(FILE *fd, int first)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* skip leading "--" in first token if any */
|
||||||
|
if (ce->ntokens > 0)
|
||||||
|
{
|
||||||
|
ce->tokens[0] += wcsspn(ce->tokens[0], L"--");
|
||||||
|
}
|
||||||
|
|
||||||
return ce;
|
return ce;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ struct config_entry {
|
||||||
wchar_t line[MAX_LINE_LENGTH];
|
wchar_t line[MAX_LINE_LENGTH];
|
||||||
wchar_t sline[MAX_LINE_LENGTH];
|
wchar_t sline[MAX_LINE_LENGTH];
|
||||||
wchar_t *tokens[16];
|
wchar_t *tokens[16];
|
||||||
|
wchar_t *comment;
|
||||||
int ntokens;
|
int ntokens;
|
||||||
config_entry_t *next;
|
config_entry_t *next;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue