summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-09-16 16:36:22 +0200
committerJakub Jelen <jjelen@redhat.com>2019-10-01 10:24:01 +0200
commit349abe5942908dd46b2b15070fe29166585820e8 (patch)
treea282434968656f485aa8ee84cbf95e094a359634
parenta3a0529b41e5ce4789cc8a5bd5e09b4ed15efe32 (diff)
downloadlibssh-349abe5942908dd46b2b15070fe29166585820e8.tar.gz
libssh-349abe5942908dd46b2b15070fe29166585820e8.tar.xz
libssh-349abe5942908dd46b2b15070fe29166585820e8.zip
config_parser: Implement more useful variant of get_token()
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
-rw-r--r--src/config_parser.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/config_parser.c b/src/config_parser.c
index ae2aa2c8..354ed35c 100644
--- a/src/config_parser.c
+++ b/src/config_parser.c
@@ -31,6 +31,11 @@
#include "libssh/config_parser.h"
#include "libssh/priv.h"
+/* Returns the original string after skipping the leading whitespace
+ * and optional quotes.
+ * This is useful in case we need to get the rest of the line (for example
+ * external command).
+ */
char *ssh_config_get_cmd(char **str)
{
register char *c;
@@ -65,15 +70,34 @@ out:
return r;
}
+/* Returns the next token delimited by whitespace or equal sign (=)
+ * respecting the quotes creating separate token (including whitespaces).
+ */
char *ssh_config_get_token(char **str)
{
register char *c;
char *r;
- c = ssh_config_get_cmd(str);
+ /* Ignore leading spaces */
+ for (c = *str; *c; c++) {
+ if (! isblank(*c)) {
+ break;
+ }
+ }
+
+ /* If we start with quote, return the whole quoted block */
+ if (*c == '\"') {
+ for (r = ++c; *c; c++) {
+ if (*c == '\"') {
+ *c = '\0';
+ goto out;
+ }
+ }
+ }
+ /* Otherwise terminate on space, equal or newline */
for (r = c; *c; c++) {
- if (isblank(*c) || *c == '=') {
+ if (isblank(*c) || *c == '=' || *c == '\n') {
*c = '\0';
goto out;
}