diff options
author | Gregor Beck <gbeck@sernet.de> | 2011-03-17 10:22:25 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-04-04 15:57:36 +0200 |
commit | 8fc8c880074d01af5a2d92fbd9b2fb042bdd59f3 (patch) | |
tree | ef9bd3449bcdf7300ea3908d30b9df0e0dd36d7c /source3 | |
parent | 9272614d9dad501ad95ac76b40f53e433a4878bc (diff) | |
download | samba-8fc8c880074d01af5a2d92fbd9b2fb042bdd59f3.tar.gz samba-8fc8c880074d01af5a2d92fbd9b2fb042bdd59f3.tar.bz2 samba-8fc8c880074d01af5a2d92fbd9b2fb042bdd59f3.zip |
s3: add function srprs_quoted to parse strings written with cbuf_print_quoted
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/srprs.c | 40 | ||||
-rw-r--r-- | source3/lib/srprs.h | 13 |
2 files changed, 52 insertions, 1 deletions
diff --git a/source3/lib/srprs.c b/source3/lib/srprs.c index 77464f5f3a..5a032d27b6 100644 --- a/source3/lib/srprs.c +++ b/source3/lib/srprs.c @@ -183,3 +183,43 @@ bool srprs_line(const char** ptr, cbuf* str) ; return true; } + +bool srprs_quoted(const char** ptr, cbuf* str) +{ + const char* pos = *ptr; + const size_t spos = cbuf_getpos(str); + + if (!srprs_char(&pos, '"')) { + goto fail; + } + + while (true) { + while (srprs_charsetinv(&pos, "\\\"", str)) + ; + + switch (*pos) { + case '\0': + goto fail; + case '"': + *ptr = pos+1; + return true; + + case '\\': + pos++; + if (!srprs_charset(&pos, "\\\"", str)) { + unsigned u; + if (!srprs_hex(&pos, 2, &u)) { + goto fail; + } + cbuf_putc(str, u); + } + break; + default: + assert(false); + } + } + +fail: + cbuf_setpos(str, spos); + return false; +} diff --git a/source3/lib/srprs.h b/source3/lib/srprs.h index bbbcdc776a..350e08c2c1 100644 --- a/source3/lib/srprs.h +++ b/source3/lib/srprs.h @@ -113,9 +113,10 @@ bool srprs_charsetinv(const char** ptr, const char* set, struct cbuf* oss); * assert(*cont == false); * assert(strcmp(cbuf_gets(out, 0), "start...continued...end")==0); * @endcode + * @see cbuf_print_quoted_string * * @param[in,out] ptr parse position - * @param[out] str output buffer where to put the match, may be NULL + * @param[out] str output buffer where to put the match * @param[in,out] cont * * @return true if matched @@ -177,5 +178,15 @@ bool srprs_eol(const char** ptr, struct cbuf* nl); */ bool srprs_line(const char** ptr, struct cbuf* str); +/** + * Match a quoted string with escaped characters. + * @see cbuf_print_quoted + * + * @param[in,out] ptr parse position + * @param[out] str output buffer where to put the match + * + * @return true if matched + */ +bool srprs_quoted(const char** ptr, struct cbuf* str); #endif /* __SRPRS_H */ |