Removed strayed code fragment
[strongswan.git] / src / charon / encoding / payloads / ts_payload.c
index c026f7e..6bf3e42 100644 (file)
@@ -1,10 +1,3 @@
-/**
- * @file ts_payload.c
- * 
- * @brief Implementation of ts_payload_t.
- * 
- */
-
 /*
  * Copyright (C) 2005-2006 Martin Willi
  * Copyright (C) 2005 Jan Hutter
@@ -32,19 +25,19 @@ typedef struct private_ts_payload_t private_ts_payload_t;
 
 /**
  * Private data of an ts_payload_t object.
- * 
+ *
  */
 struct private_ts_payload_t {
        /**
         * Public ts_payload_t interface.
         */
        ts_payload_t public;
-       
+
        /**
         * TRUE if this TS payload is of type TSi, FALSE for TSr.
         */
        bool is_initiator;
-       
+
        /**
         * Next payload type.
         */
@@ -54,43 +47,36 @@ struct private_ts_payload_t {
         * Critical flag.
         */
        bool critical;
-       
+
        /**
         * Length of this payload.
         */
        u_int16_t payload_length;
-       
+
        /**
         * Number of traffic selectors
         */
        u_int8_t number_of_traffic_selectors;
-       
+
        /**
         * Contains the traffic selectors of type traffic_selector_substructure_t.
         */
        linked_list_t *traffic_selectors;
-       
-       /**
-        * @brief Computes the length of this payload.
-        *
-        * @param this  calling private_ts_payload_t object
-        */
-       void (*compute_length) (private_ts_payload_t *this);
 };
 
 /**
  * Encoding rules to parse or generate a TS payload
- * 
- * The defined offsets are the positions in a object of type 
+ *
+ * The defined offsets are the positions in a object of type
  * private_ts_payload_t.
- * 
+ *
  */
 encoding_rule_t ts_payload_encodings[] = {
-       /* 1 Byte next payload type, stored in the field next_payload */
+       /* 1 Byte next payload type, stored in the field next_payload */
        { U_INT_8,                      offsetof(private_ts_payload_t, next_payload)                            },
        /* the critical bit */
        { FLAG,                         offsetof(private_ts_payload_t, critical)                                        },
-       /* 7 Bit reserved bits, nowhere stored */
+       /* 7 Bit reserved bits, nowhere stored */
        { RESERVED_BIT, 0                                                                                                                               },
        { RESERVED_BIT, 0                                                                                                                               },
        { RESERVED_BIT, 0                                                                                                                               },
@@ -98,9 +84,9 @@ encoding_rule_t ts_payload_encodings[] = {
        { RESERVED_BIT, 0                                                                                                                               },
        { RESERVED_BIT, 0                                                                                                                               },
        { RESERVED_BIT, 0                                                                                                                               },
-       /* Length of the whole payload*/        
+       /* Length of the whole payload*/
        { PAYLOAD_LENGTH,       offsetof(private_ts_payload_t, payload_length)},
-       /* 1 Byte TS type*/
+       /* 1 Byte TS type*/
        { U_INT_8,                      offsetof(private_ts_payload_t, number_of_traffic_selectors)     },
        /* 3 reserved bytes */
        { RESERVED_BYTE,        0                                                                                                                       },
@@ -130,20 +116,18 @@ encoding_rule_t ts_payload_encodings[] = {
 static status_t verify(private_ts_payload_t *this)
 {
        iterator_t *iterator;
+       payload_t *current_traffic_selector;
        status_t status = SUCCESS;
-       
+
        if (this->number_of_traffic_selectors != (this->traffic_selectors->get_count(this->traffic_selectors)))
        {
                /* must be the same */
                return FAILED;
        }
-       
+
        iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
-       while(iterator->has_next(iterator))
+       while(iterator->iterate(iterator, (void**)&current_traffic_selector))
        {
-               payload_t *current_traffic_selector;
-               iterator->current(iterator,(void **)&current_traffic_selector);
-
                status = current_traffic_selector->verify(current_traffic_selector);
                if (status != SUCCESS)
                {
@@ -151,7 +135,7 @@ static status_t verify(private_ts_payload_t *this)
                }
        }
        iterator->destroy(iterator);
-       
+
        return status;
 }
 
@@ -196,11 +180,33 @@ static void set_next_type(private_ts_payload_t *this,payload_type_t type)
 }
 
 /**
+ * recompute the length of the payload.
+ */
+static void compute_length (private_ts_payload_t *this)
+{
+       iterator_t *iterator;
+       size_t ts_count = 0;
+       size_t length = TS_PAYLOAD_HEADER_LENGTH;
+       payload_t *current_traffic_selector;
+
+       iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
+       while (iterator->iterate(iterator, (void**)&current_traffic_selector))
+       {
+               length += current_traffic_selector->get_length(current_traffic_selector);
+               ts_count++;
+       }
+       iterator->destroy(iterator);
+
+       this->number_of_traffic_selectors= ts_count;
+       this->payload_length = length;
+}
+
+/**
  * Implementation of payload_t.get_length.
  */
 static size_t get_length(private_ts_payload_t *this)
 {
-       this->compute_length(this);
+       compute_length(this);
        return this->payload_length;
 }
 
@@ -244,62 +250,28 @@ static linked_list_t *get_traffic_selectors(private_ts_payload_t *this)
 {
        traffic_selector_t *ts;
        iterator_t *iterator;
+       traffic_selector_substructure_t *ts_substructure;
        linked_list_t *ts_list = linked_list_create();
-       
+
        iterator = this->traffic_selectors->create_iterator(this->traffic_selectors, TRUE);
-       while (iterator->has_next(iterator))
+       while (iterator->iterate(iterator, (void**)&ts_substructure))
        {
-               traffic_selector_substructure_t *ts_substructure;
-               iterator->current(iterator, (void**)&ts_substructure);
                ts = ts_substructure->get_traffic_selector(ts_substructure);
                ts_list->insert_last(ts_list, (void*)ts);
        }
        iterator->destroy(iterator);
-       
-       return ts_list;
-}
-
-/**
- * Implementation of private_ts_payload_t.compute_length.
- */
-static void compute_length (private_ts_payload_t *this)
-{
-       iterator_t *iterator;
-       size_t ts_count = 0;
-       size_t length = TS_PAYLOAD_HEADER_LENGTH;
-       iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
-       while (iterator->has_next(iterator))
-       {
-               payload_t * current_traffic_selector;
-               iterator->current(iterator,(void **) &current_traffic_selector);
-               length += current_traffic_selector->get_length(current_traffic_selector);
-               ts_count++;
-       }
-       iterator->destroy(iterator);
-       
-       this->number_of_traffic_selectors= ts_count;
-       this->payload_length = length;  
 
+       return ts_list;
 }
 
-
 /**
  * Implementation of payload_t.destroy and ts_payload_t.destroy.
  */
 static void destroy(private_ts_payload_t *this)
 {
-       while (this->traffic_selectors->get_count(this->traffic_selectors) > 0)
-       {
-               payload_t *current_traffic_selector;
-               
-               this->traffic_selectors->remove_last(this->traffic_selectors,(void **) &current_traffic_selector);
-               
-               current_traffic_selector->destroy(current_traffic_selector);
-       }
-       
-       this->traffic_selectors->destroy(this->traffic_selectors);
-               
-       free(this);     
+       this->traffic_selectors->destroy_offset(this->traffic_selectors,
+                                                                                       offsetof(payload_t, destroy));
+       free(this);
 }
 
 /*
@@ -317,7 +289,7 @@ ts_payload_t *ts_payload_create(bool is_initiator)
        this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type;
        this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_payload_type;
        this->public.payload_interface.destroy = (void (*) (payload_t *))destroy;
-       
+
        /* public functions */
        this->public.destroy = (void (*) (ts_payload_t *)) destroy;
        this->public.get_initiator = (bool (*) (ts_payload_t *)) get_initiator;
@@ -325,17 +297,14 @@ ts_payload_t *ts_payload_create(bool is_initiator)
        this->public.add_traffic_selector_substructure = (void (*) (ts_payload_t *,traffic_selector_substructure_t *)) add_traffic_selector_substructure;
        this->public.create_traffic_selector_substructure_iterator = (iterator_t* (*) (ts_payload_t *,bool)) create_traffic_selector_substructure_iterator;
        this->public.get_traffic_selectors = (linked_list_t *(*) (ts_payload_t *)) get_traffic_selectors;
-       
-       /* private functions */
-       this->compute_length = compute_length;
-       
+
        /* private variables */
        this->critical = FALSE;
        this->next_payload = NO_PAYLOAD;
        this->payload_length =TS_PAYLOAD_HEADER_LENGTH;
        this->is_initiator = is_initiator;
        this->number_of_traffic_selectors = 0;
-       this->traffic_selectors = linked_list_create();  
+       this->traffic_selectors = linked_list_create();
 
        return &(this->public);
 }
@@ -349,18 +318,17 @@ ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, linked
        traffic_selector_t *ts;
        traffic_selector_substructure_t *ts_substructure;
        private_ts_payload_t *this;
-       
+
        this = (private_ts_payload_t*)ts_payload_create(is_initiator);
-       
+
        iterator = traffic_selectors->create_iterator(traffic_selectors, TRUE);
-       while (iterator->has_next(iterator))
+       while (iterator->iterate(iterator, (void**)&ts))
        {
-               iterator->current(iterator, (void**)&ts);
                ts_substructure = traffic_selector_substructure_create_from_traffic_selector(ts);
                this->public.add_traffic_selector_substructure(&(this->public), ts_substructure);
        }
        iterator->destroy(iterator);
-       
+
        return &(this->public);
 }