updated Doxyfile
[strongswan.git] / src / charon / encoding / payloads / sa_payload.c
index e03770d..950e16d 100644 (file)
@@ -1,10 +1,3 @@
-/**
- * @file sa_payload.c
- * 
- * @brief Implementation of sa_payload_t.
- * 
- */
-
 /*
  * Copyright (C) 2005-2006 Martin Willi
  * Copyright (C) 2005 Jan Hutter
@@ -19,6 +12,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.
+ *
+ * $Id$
  */
 
 #include <stddef.h>
@@ -110,28 +105,20 @@ static status_t verify(private_sa_payload_t *this)
        int expected_number = 1, current_number;
        status_t status = SUCCESS;
        iterator_t *iterator;
+       proposal_substructure_t *current_proposal;
        bool first = TRUE;
 
-       /* check proposal numbering */          
+       /* check proposal numbering */
        iterator = this->proposals->create_iterator(this->proposals,TRUE);
        
-       while(iterator->has_next(iterator))
+       while(iterator->iterate(iterator, (void**)&current_proposal))
        {
-               proposal_substructure_t *current_proposal;
-               iterator->current(iterator,(void **)&current_proposal);
                current_number = current_proposal->get_proposal_number(current_proposal);
-               if (current_number > expected_number)
-               {
-                       if (first) 
-                       {
-                               DBG1(SIG_DBG_ENC, "first proposal is not proposal #1");
-                               status = FAILED;
-                               break;
-                       }
-                       
+               if (current_number < expected_number)
+               {                       
                        if (current_number != (expected_number + 1))
                        {
-                               DBG1(SIG_DBG_ENC, "proposal number is %d, excepted %d or %d",
+                               DBG1(DBG_ENC, "proposal number is %d, expected %d or %d",
                                         current_number, expected_number, expected_number + 1);
                                status = FAILED;
                                break;
@@ -140,7 +127,7 @@ static status_t verify(private_sa_payload_t *this)
                else if (current_number < expected_number)
                {
                        /* must not be smaller then proceeding one */
-                       DBG1(SIG_DBG_ENC, "proposal number smaller than that of previous proposal");
+                       DBG1(DBG_ENC, "proposal number smaller than that of previous proposal");
                        status = FAILED;
                        break;
                }
@@ -148,7 +135,7 @@ static status_t verify(private_sa_payload_t *this)
                status = current_proposal->payload_interface.verify(&(current_proposal->payload_interface));
                if (status != SUCCESS)
                {
-                       DBG1(SIG_DBG_ENC, "PROPOSAL_SUBSTRUCTURE verification failed");
+                       DBG1(DBG_ENC, "PROPOSAL_SUBSTRUCTURE verification failed");
                        break;
                }
                first = FALSE;
@@ -165,17 +152,9 @@ static status_t verify(private_sa_payload_t *this)
  */
 static status_t destroy(private_sa_payload_t *this)
 {
-       /* all proposals are getting destroyed */ 
-       while (this->proposals->get_count(this->proposals) > 0)
-       {
-               proposal_substructure_t *current_proposal;
-               this->proposals->remove_last(this->proposals,(void **)&current_proposal);
-               current_proposal->destroy(current_proposal);
-       }
-       this->proposals->destroy(this->proposals);
-       
+       this->proposals->destroy_offset(this->proposals,
+                                                                       offsetof(proposal_substructure_t, destroy));
        free(this);
-       
        return SUCCESS;
 }
 
@@ -218,12 +197,12 @@ static void set_next_type(private_sa_payload_t *this,payload_type_t type)
 static void compute_length (private_sa_payload_t *this)
 {
        iterator_t *iterator;
+       payload_t *current_proposal;
        size_t length = SA_PAYLOAD_HEADER_LENGTH;
+       
        iterator = this->proposals->create_iterator(this->proposals,TRUE);
-       while (iterator->has_next(iterator))
+       while (iterator->iterate(iterator, (void **)&current_proposal))
        {
-               payload_t *current_proposal;
-               iterator->current(iterator,(void **) &current_proposal);
                length += current_proposal->get_length(current_proposal);
        }
        iterator->destroy(iterator);
@@ -288,6 +267,7 @@ static linked_list_t *get_proposals(private_sa_payload_t *this)
        int struct_number = 0;
        int ignore_struct_number = 0;
        iterator_t *iterator;
+       proposal_substructure_t *proposal_struct;
        linked_list_t *proposal_list;
        
        /* this list will hold our proposals */
@@ -299,12 +279,10 @@ static linked_list_t *get_proposals(private_sa_payload_t *this)
         * protocols.
         */
        iterator = this->proposals->create_iterator(this->proposals, TRUE);
-       while (iterator->has_next(iterator))
+       while (iterator->iterate(iterator, (void **)&proposal_struct))
        {
                proposal_t *proposal;
-               proposal_substructure_t *proposal_struct;
                
-               iterator->current(iterator, (void **)&proposal_struct);
                /* check if a proposal has a single protocol */
                if (proposal_struct->get_proposal_number(proposal_struct) == struct_number)
                {
@@ -370,9 +348,8 @@ sa_payload_t *sa_payload_create_from_proposal_list(linked_list_t *proposals)
        
        /* add every payload from the list */
        iterator = proposals->create_iterator(proposals, TRUE);
-       while (iterator->has_next(iterator))
+       while (iterator->iterate(iterator, (void**)&proposal))
        {
-               iterator->current(iterator, (void**)&proposal);
                add_proposal((private_sa_payload_t*)sa_payload, proposal);
        }
        iterator->destroy(iterator);