diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-11-16 20:23:29 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-11-16 20:23:29 +0000 |
commit | b073aada2336f891de117520fc92df106f92924c (patch) | |
tree | 985bbcb1ff2b2840a215dedfd11a9331192e162a /src/libstrongswan/utils/lexparser.c | |
parent | e101f162abba82d4713d68721d911d5cbd772201 (diff) | |
download | strongswan-b073aada2336f891de117520fc92df106f92924c.tar.bz2 strongswan-b073aada2336f891de117520fc92df106f92924c.tar.xz |
search : delimiter in ipsec.secrets entries from the rear
Diffstat (limited to 'src/libstrongswan/utils/lexparser.c')
-rw-r--r-- | src/libstrongswan/utils/lexparser.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/libstrongswan/utils/lexparser.c b/src/libstrongswan/utils/lexparser.c index 9d3f06593..52a0e1617 100644 --- a/src/libstrongswan/utils/lexparser.c +++ b/src/libstrongswan/utils/lexparser.c @@ -17,6 +17,8 @@ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. + * + * RCSID $Id$ */ #include <string.h> @@ -45,7 +47,7 @@ bool match(const char *pattern, const chunk_t *ch) } /** - * extracts a token ending with a given termination symbol + * extracts a token ending with the first occurrence of a given termination symbol */ bool extract_token(chunk_t *token, const char termination, chunk_t *src) { @@ -71,6 +73,32 @@ bool extract_token(chunk_t *token, const char termination, chunk_t *src) } /** + * 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) +{ + u_char *eot = memrchr(src->ptr, termination, src->len); + + /* initialize empty token */ + *token = chunk_empty; + + if (eot == NULL) /* termination symbol not found */ + { + return FALSE; + } + + /* extract token */ + token->ptr = src->ptr; + token->len = (u_int)(eot - src->ptr); + + /* advance src pointer after termination symbol */ + src->ptr = eot + 1; + src->len -= (token->len + 1); + + return TRUE; +} + +/** * fetches a new line terminated by \n or \r\n */ bool fetchline(chunk_t *src, chunk_t *line) |