if (i>1)
{
/* should not happen, but who knows */
- return;
+ break;
}
}
+ iterator->destroy(iterator);
}
/**
/* delete proposals */
- while(this->proposals->get_count(this->proposals) > 0)
+ while(this->proposals->remove_last(this->proposals, (void**)&proposal) == SUCCESS)
{
- this->proposals->remove_last(this->proposals, (void**)&proposal);
proposal->destroy(proposal);
}
this->proposals->destroy(this->proposals);
/* delete traffic selectors */
- while(this->ts_initiator->get_count(this->ts_initiator) > 0)
+ while(this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector) == SUCCESS)
{
- this->ts_initiator->remove_last(this->ts_initiator, (void**)&traffic_selector);
traffic_selector->destroy(traffic_selector);
}
this->ts_initiator->destroy(this->ts_initiator);
/* delete traffic selectors */
- while(this->ts_responder->get_count(this->ts_responder) > 0)
+ while(this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector) == SUCCESS)
{
- this->ts_responder->remove_last(this->ts_responder, (void**)&traffic_selector);
traffic_selector->destroy(traffic_selector);
}
this->ts_responder->destroy(this->ts_responder);
iterator->current(iterator, (void**)&proposal);
add_child_proposal((private_sa_payload_t*)sa_payload, proposal);
}
+ iterator->destroy(iterator);
return sa_payload;
}
*/
static status_t process_sa_payload(private_ike_auth_requested_t *this, sa_payload_t *sa_payload)
{
- child_proposal_t *proposal;
+ child_proposal_t *proposal, *proposal_tmp;
linked_list_t *proposal_list;
protocol_id_t proto;
- /* TODO fix mem allocation */
- /* TODO child sa stuff */
-
- /* get selected proposal */
+ /* get his selected proposal */
proposal_list = sa_payload->get_child_proposals(sa_payload);
/* check count of proposals */
if (proposal_list->get_count(proposal_list) == 0)
{
- /* no proposal? we accept this, no child sa is built */
+ /* no proposal? we accept this, but no child sa is built */
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD didn't contain any proposals. No CHILD_SA created",
proposal_list->get_count(proposal_list));
+ proposal_list->destroy(proposal_list);
return SUCCESS;
}
if (proposal_list->get_count(proposal_list) > 1)
{
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply's SA_PAYLOAD contained %d proposal. Deleting IKE_SA",
proposal_list->get_count(proposal_list));
+ while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
+ {
+ proposal->destroy(proposal);
+ }
+ proposal_list->destroy(proposal_list);
return DELETE_ME;
}
/* we have to re-check here if other's selection is valid */
proposal = this->sa_config->select_proposal(this->sa_config, proposal_list);
+ /* list not needed anymore */
+ while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS)
+ {
+ proposal_tmp->destroy(proposal_tmp);
+ }
+ proposal_list->destroy(proposal_list);
+ /* got a match? */
if (proposal == NULL)
{
this->logger->log(this->logger, AUDIT, "IKE_AUTH reply contained a not offered proposal. Deleting IKE_SA");
}
}
+ /* TODO: Proposal? child_sa */
+ proposal->destroy(proposal);
+
return SUCCESS;
}
sa_payload_t *sa_payload;
sa_config_t *sa_config;
+ /* get proposals form config, add to payload */
sa_config = this->ike_sa->get_sa_config(this->ike_sa);
proposal_list = sa_config->get_proposals(sa_config);
sa_payload = sa_payload_create_from_child_proposal_list(proposal_list);
- /* TODO: fix mem allocation */
+
/* TODO child sa stuff */
this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
*/
static status_t build_sa_payload(private_ike_sa_init_responded_t *this, sa_payload_t *request, message_t *response)
{
- child_proposal_t *proposal;
+ child_proposal_t *proposal, *proposal_tmp;
linked_list_t *proposal_list;
sa_payload_t *sa_response;
protocol_id_t proto;
- /* TODO: fix mem */
/* TODO: child sa stuff */
/* get proposals from request */
this->logger->log(this->logger, AUDIT, "IKE_AUH request did not contain any proposals. No CHILD_SA created");
sa_response = sa_payload_create();
response->add_payload(response, (payload_t*)sa_response);
+ proposal_list->destroy(proposal_list);
return SUCCESS;
}
/* now select a proposal */
this->logger->log(this->logger, CONTROL|LEVEL1, "Selecting proposals:");
proposal = this->sa_config->select_proposal(this->sa_config, proposal_list);
+ /* list is not needed anymore */
+ while (proposal_list->remove_last(proposal_list, (void**)&proposal_tmp) == SUCCESS)
+ {
+ proposal_tmp->destroy(proposal_tmp);
+ }
+ proposal_list->destroy(proposal_list);
+ /* do we have a proposal */
if (proposal == NULL)
{
this->logger->log(this->logger, AUDIT, "IKE_AUTH request did not contain any proposals we accept. Deleting IKE_SA");
/* create payload with selected propsal */
sa_response = sa_payload_create_from_child_proposal(proposal);
response->add_payload(response, (payload_t*)sa_response);
+ proposal->destroy(proposal);
return SUCCESS;
}
*/
struct iterator_t {
+ /**
+ * @brief Iterate over all items.
+ *
+ * The easy way to iterate over items.
+ *
+ * @param this calling object
+ * @param[out] value item
+ * @return
+ * - TRUE, if more elements are avaiable,
+ * - FALSE otherwise
+ */
+ bool (*iterate) (iterator_t *this, void** value);
+
/**
* @brief Moves to the next element, if available.
*
/**
* Implementation of iterator_t.has_next.
*/
-bool iterator_has_next(private_iterator_t *this)
+static bool iterate(private_iterator_t *this, void** value)
+{
+ if (this->list->count == 0)
+ {
+ return FALSE;
+ }
+ if (this->current == NULL)
+ {
+ this->current = (this->forward) ? this->list->first : this->list->last;
+ *value = this->current->value;
+ return TRUE;
+ }
+ if (this->forward)
+ {
+ if (this->current->next == NULL)
+ {
+ return FALSE;
+ }
+ this->current = this->current->next;
+ *value = this->current->value;
+ return TRUE;
+ }
+ /* backward */
+ if (this->current->previous == NULL)
+ {
+ return FALSE;
+ }
+ this->current = this->current->previous;
+ *value = this->current->value;
+ return TRUE;
+}
+
+/**
+ * Implementation of iterator_t.has_next.
+ */
+static bool iterator_has_next(private_iterator_t *this)
{
if (this->list->count == 0)
{
{
private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
+ this->public.iterate = (bool (*) (iterator_t *this, void **value)) iterate;
this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current;
this->public.insert_before = (void (*) (iterator_t *this, void *item)) insert_before;