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>
Этот коммит содержится в:
родитель
a3a0529b41
Коммит
349abe5942
@ -31,6 +31,11 @@
|
|||||||
#include "libssh/config_parser.h"
|
#include "libssh/config_parser.h"
|
||||||
#include "libssh/priv.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)
|
char *ssh_config_get_cmd(char **str)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *c;
|
||||||
@ -65,15 +70,34 @@ out:
|
|||||||
return r;
|
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)
|
char *ssh_config_get_token(char **str)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *c;
|
||||||
char *r;
|
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++) {
|
for (r = c; *c; c++) {
|
||||||
if (isblank(*c) || *c == '=') {
|
if (isblank(*c) || *c == '=' || *c == '\n') {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user