diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-09-13 13:39:33 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-09-13 15:44:01 +0200 |
commit | 995875210acb70ba2b12c9368ce892325abb64f2 (patch) | |
tree | e8bc8ce7dcb96885c98fbe89b2797cf245e2de06 /src/libcharon/config/proposal.c | |
parent | 1962e12fd3a0d80c56facf508ec8ee9ea2c92dc8 (diff) | |
download | strongswan-995875210acb70ba2b12c9368ce892325abb64f2.tar.bz2 strongswan-995875210acb70ba2b12c9368ce892325abb64f2.tar.xz |
Removed len argument from proposal_get_token()
Also use enumerators instead of lexparser.h to parse proposal strings.
Diffstat (limited to 'src/libcharon/config/proposal.c')
-rw-r--r-- | src/libcharon/config/proposal.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/libcharon/config/proposal.c b/src/libcharon/config/proposal.c index 6523fd351..bf2bcd031 100644 --- a/src/libcharon/config/proposal.c +++ b/src/libcharon/config/proposal.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2009 Tobias Brunner + * Copyright (C) 2008-2012 Tobias Brunner * Copyright (C) 2006-2010 Martin Willi * Hochschule fuer Technik Rapperswil * @@ -21,7 +21,7 @@ #include <daemon.h> #include <utils/linked_list.h> #include <utils/identification.h> -#include <utils/lexparser.h> + #include <crypto/transform.h> #include <crypto/prfs/prf.h> #include <crypto/crypters/crypter.h> @@ -560,14 +560,14 @@ static void check_proposal(private_proposal_t *this) /** * add a algorithm identified by a string to the proposal. */ -static status_t add_string_algo(private_proposal_t *this, chunk_t alg) +static bool add_string_algo(private_proposal_t *this, const char *alg) { - const proposal_token_t *token = proposal_get_token(alg.ptr, alg.len); + const proposal_token_t *token = proposal_get_token(alg); if (token == NULL) { - DBG1(DBG_CFG, "algorithm '%.*s' not recognized", alg.len, alg.ptr); - return FAILED; + DBG1(DBG_CFG, "algorithm '%s' not recognized", alg); + return FALSE; } add_algorithm(this, token->type, token->algorithm, token->keysize); @@ -610,7 +610,7 @@ static status_t add_string_algo(private_proposal_t *this, chunk_t alg) add_algorithm(this, PSEUDO_RANDOM_FUNCTION, prf, 0); } } - return SUCCESS; + return TRUE; } /** @@ -901,28 +901,27 @@ proposal_t *proposal_create_default(protocol_id_t protocol) */ proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs) { - private_proposal_t *this = (private_proposal_t*)proposal_create(protocol, 0); - chunk_t string = {(void*)algs, strlen(algs)}; - chunk_t alg; - status_t status = SUCCESS; + private_proposal_t *this; + enumerator_t *enumerator; + bool failed = TRUE; + char *alg; - eat_whitespace(&string); - if (string.len < 1) - { - destroy(this); - return NULL; - } + this = (private_proposal_t*)proposal_create(protocol, 0); /* get all tokens, separated by '-' */ - while (extract_token(&alg, '-', &string)) - { - status |= add_string_algo(this, alg); - } - if (string.len) + enumerator = enumerator_create_token(algs, "-", " "); + while (enumerator->enumerate(enumerator, &alg)) { - status |= add_string_algo(this, string); + if (!add_string_algo(this, alg)) + { + failed = TRUE; + break; + } + failed = FALSE; } - if (status != SUCCESS) + enumerator->destroy(enumerator); + + if (failed) { destroy(this); return NULL; |