diff options
author | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-02-07 13:56:17 +0000 |
---|---|---|
committer | Rene Mayrhofer <rene@mayrhofer.eu.org> | 2008-02-07 13:56:17 +0000 |
commit | bcc8f7ca7fd8e8ff6e8a4d579251458313133598 (patch) | |
tree | a86b42b486c954937b32ffeaaa725804cb1458ec /src/libstrongswan/utils/lexparser.c | |
parent | 49104abddf3d71d5abf5cf75dc7f95fa6c55fa63 (diff) | |
download | vyos-strongswan-bcc8f7ca7fd8e8ff6e8a4d579251458313133598.tar.gz vyos-strongswan-bcc8f7ca7fd8e8ff6e8a4d579251458313133598.zip |
[svn-upgrade] Integrating new upstream version, strongswan (4.1.10)
Diffstat (limited to 'src/libstrongswan/utils/lexparser.c')
-rw-r--r-- | src/libstrongswan/utils/lexparser.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/libstrongswan/utils/lexparser.c b/src/libstrongswan/utils/lexparser.c index 9d3f06593..7cc89fc90 100644 --- a/src/libstrongswan/utils/lexparser.c +++ b/src/libstrongswan/utils/lexparser.c @@ -17,8 +17,12 @@ * 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: lexparser.c 3353 2007-11-19 12:27:08Z martin $ */ +/* memrchr is a GNU extension */ +#define _GNU_SOURCE #include <string.h> #include "lexparser.h" @@ -45,7 +49,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 +75,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) |