Removed len argument from proposal_get_token()
authorTobias Brunner <tobias@strongswan.org>
Thu, 13 Sep 2012 11:39:33 +0000 (13:39 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 13 Sep 2012 13:44:01 +0000 (15:44 +0200)
Also use enumerators instead of lexparser.h to parse proposal strings.

scripts/crypt_burn.c
src/conftest/hooks/custom_proposal.c
src/libcharon/config/proposal.c
src/libstrongswan/crypto/proposal/proposal_keywords.c
src/libstrongswan/crypto/proposal/proposal_keywords.h
src/scepclient/scepclient.c

index 1f1536a..c7990ed 100644 (file)
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
                limit = atoi(argv[2]);
        }
 
-       token = proposal_get_token(argv[1], strlen(argv[1]));
+       token = proposal_get_token(argv[1]);
        if (!token)
        {
                fprintf(stderr, "algorithm '%s' unknown!\n", argv[1]);
index 958bc10..b09fe6e 100644 (file)
@@ -91,7 +91,7 @@ static linked_list_t* load_proposals(private_custom_proposal_t *this,
                        alg = strtoul(value, &end, 10);
                        if (end == value || errno)
                        {
-                               token = proposal_get_token(value, strlen(value));
+                               token = proposal_get_token(value);
                                if (!token)
                                {
                                        DBG1(DBG_CFG, "unknown algorithm: '%s', skipped", value);
index 6523fd3..bf2bcd0 100644 (file)
@@ -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;
index 9e16dd2..bb6353d 100644 (file)
@@ -26,7 +26,7 @@
 /*
  * 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));
 }
index 1abd10f..ad9e82a 100644 (file)
@@ -62,9 +62,8 @@ struct proposal_token {
  * Returns a proposal token for the specified string if a token exists.
  *
  * @param str          the string containing the name of the token
- * @param len          the length of the string
  * @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_ @}*/
index 76d639a..2444080 100644 (file)
@@ -828,7 +828,7 @@ int main(int argc, char **argv)
 
                                if (strcaseeq("enc", type))
                                {
-                                       token = proposal_get_token(algo, strlen(algo));
+                                       token = proposal_get_token(algo);
                                        if (token == NULL || token->type != ENCRYPTION_ALGORITHM)
                                        {
                                                usage("invalid algorithm specified");
@@ -846,7 +846,7 @@ int main(int argc, char **argv)
                                {
                                        hash_algorithm_t hash;
 
-                                       token = proposal_get_token(algo, strlen(algo));
+                                       token = proposal_get_token(algo);
                                        if (token == NULL || token->type != INTEGRITY_ALGORITHM)
                                        {
                                                usage("invalid algorithm specified");