From 81736d7d243036220621a438e4d92528798fdc09 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 3 Dec 2008 09:45:58 +0000 Subject: added memstr and extract_token_str helper functions --- src/libstrongswan/utils/lexparser.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/libstrongswan/utils/lexparser.c') diff --git a/src/libstrongswan/utils/lexparser.c b/src/libstrongswan/utils/lexparser.c index 9019c2602..34eb340a5 100644 --- a/src/libstrongswan/utils/lexparser.c +++ b/src/libstrongswan/utils/lexparser.c @@ -75,6 +75,33 @@ bool extract_token(chunk_t *token, const char termination, chunk_t *src) return TRUE; } +/** + * extracts a token ending with the first occurrence of a given null-terminated string + */ +bool extract_token_str(chunk_t *token, const char *termination, chunk_t *src) +{ + u_char *eot = memstr(src->ptr, termination, src->len); + size_t l = strlen(termination); + + /* initialize empty token */ + *token = chunk_empty; + + if (eot == NULL) /* termination string not found */ + { + return FALSE; + } + + /* extract token */ + token->ptr = src->ptr; + token->len = (u_int)(eot - src->ptr); + + /* advance src pointer after termination string */ + src->ptr = eot + l; + src->len -= (token->len + l); + + return TRUE; +} + /** * extracts a token ending with the last occurrence of a given termination symbol */ -- cgit v1.2.3