aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/lexparser.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2008-12-03 09:45:58 +0000
committerTobias Brunner <tobias@strongswan.org>2008-12-03 09:45:58 +0000
commit81736d7d243036220621a438e4d92528798fdc09 (patch)
tree74083f9cd5c2af13cfccca6848990148fb063873 /src/libstrongswan/utils/lexparser.c
parent0948edbbff1b7afe8d0a8040e2357f2ae227e642 (diff)
downloadstrongswan-81736d7d243036220621a438e4d92528798fdc09.tar.bz2
strongswan-81736d7d243036220621a438e4d92528798fdc09.tar.xz
added memstr and extract_token_str helper functions
Diffstat (limited to 'src/libstrongswan/utils/lexparser.c')
-rw-r--r--src/libstrongswan/utils/lexparser.c27
1 files changed, 27 insertions, 0 deletions
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
@@ -76,6 +76,33 @@ bool extract_token(chunk_t *token, const char termination, chunk_t *src)
}
/**
+ * 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
*/
bool extract_last_token(chunk_t *token, const char termination, chunk_t *src)