Removed len argument from proposal_get_token()

Also use enumerators instead of lexparser.h to parse proposal strings.
This commit is contained in:
Tobias Brunner
2012-09-13 15:44:01 +02:00
parent 1962e12fd3
commit 995875210a
6 changed files with 30 additions and 32 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
limit = atoi(argv[2]); limit = atoi(argv[2]);
} }
token = proposal_get_token(argv[1], strlen(argv[1])); token = proposal_get_token(argv[1]);
if (!token) if (!token)
{ {
fprintf(stderr, "algorithm '%s' unknown!\n", argv[1]); fprintf(stderr, "algorithm '%s' unknown!\n", argv[1]);
+1 -1
View File
@@ -91,7 +91,7 @@ static linked_list_t* load_proposals(private_custom_proposal_t *this,
alg = strtoul(value, &end, 10); alg = strtoul(value, &end, 10);
if (end == value || errno) if (end == value || errno)
{ {
token = proposal_get_token(value, strlen(value)); token = proposal_get_token(value);
if (!token) if (!token)
{ {
DBG1(DBG_CFG, "unknown algorithm: '%s', skipped", value); DBG1(DBG_CFG, "unknown algorithm: '%s', skipped", value);
+23 -24
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2009 Tobias Brunner * Copyright (C) 2008-2012 Tobias Brunner
* Copyright (C) 2006-2010 Martin Willi * Copyright (C) 2006-2010 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -21,7 +21,7 @@
#include <daemon.h> #include <daemon.h>
#include <utils/linked_list.h> #include <utils/linked_list.h>
#include <utils/identification.h> #include <utils/identification.h>
#include <utils/lexparser.h>
#include <crypto/transform.h> #include <crypto/transform.h>
#include <crypto/prfs/prf.h> #include <crypto/prfs/prf.h>
#include <crypto/crypters/crypter.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. * 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) if (token == NULL)
{ {
DBG1(DBG_CFG, "algorithm '%.*s' not recognized", alg.len, alg.ptr); DBG1(DBG_CFG, "algorithm '%s' not recognized", alg);
return FAILED; return FALSE;
} }
add_algorithm(this, token->type, token->algorithm, token->keysize); 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); 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) proposal_t *proposal_create_from_string(protocol_id_t protocol, const char *algs)
{ {
private_proposal_t *this = (private_proposal_t*)proposal_create(protocol, 0); private_proposal_t *this;
chunk_t string = {(void*)algs, strlen(algs)}; enumerator_t *enumerator;
chunk_t alg; bool failed = TRUE;
status_t status = SUCCESS; char *alg;
eat_whitespace(&string); this = (private_proposal_t*)proposal_create(protocol, 0);
if (string.len < 1)
{
destroy(this);
return NULL;
}
/* get all tokens, separated by '-' */ /* get all tokens, separated by '-' */
while (extract_token(&alg, '-', &string)) enumerator = enumerator_create_token(algs, "-", " ");
while (enumerator->enumerate(enumerator, &alg))
{ {
status |= add_string_algo(this, alg); if (!add_string_algo(this, alg))
{
failed = TRUE;
break;
}
failed = FALSE;
} }
if (string.len) enumerator->destroy(enumerator);
{
status |= add_string_algo(this, string); if (failed)
}
if (status != SUCCESS)
{ {
destroy(this); destroy(this);
return NULL; return NULL;
@@ -26,7 +26,7 @@
/* /*
* see header file * see header file
*/ */
const proposal_token_t* proposal_get_token(const char *str, u_int len) const proposal_token_t* proposal_get_token(const char *str)
{ {
return proposal_get_token_static(str, len); return proposal_get_token_static(str, strlen(str));
} }
@@ -62,9 +62,8 @@ struct proposal_token {
* Returns a proposal token for the specified string if a token exists. * Returns a proposal token for the specified string if a token exists.
* *
* @param str the string containing the name of the token * @param str the string containing the name of the token
* @param len the length of the string
* @return proposal_tolen if found otherwise NULL * @return proposal_tolen if found otherwise NULL
*/ */
const proposal_token_t* proposal_get_token(const char *str, u_int len); const proposal_token_t* proposal_get_token(const char *str);
#endif /** PROPOSAL_KEYWORDS_H_ @}*/ #endif /** PROPOSAL_KEYWORDS_H_ @}*/
+2 -2
View File
@@ -828,7 +828,7 @@ int main(int argc, char **argv)
if (strcaseeq("enc", type)) if (strcaseeq("enc", type))
{ {
token = proposal_get_token(algo, strlen(algo)); token = proposal_get_token(algo);
if (token == NULL || token->type != ENCRYPTION_ALGORITHM) if (token == NULL || token->type != ENCRYPTION_ALGORITHM)
{ {
usage("invalid algorithm specified"); usage("invalid algorithm specified");
@@ -846,7 +846,7 @@ int main(int argc, char **argv)
{ {
hash_algorithm_t hash; hash_algorithm_t hash;
token = proposal_get_token(algo, strlen(algo)); token = proposal_get_token(algo);
if (token == NULL || token->type != INTEGRITY_ALGORITHM) if (token == NULL || token->type != INTEGRITY_ALGORITHM)
{ {
usage("invalid algorithm specified"); usage("invalid algorithm specified");