2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-15 14:59:47 +00:00
|
|
|
* @file sa_payload.c
|
2005-11-14 10:14:22 +00:00
|
|
|
*
|
2005-11-28 18:24:10 +00:00
|
|
|
* @brief Implementation of sa_payload_t.
|
2005-11-14 10:14:22 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005-2006 Martin Willi
|
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2005-11-14 10:14:22 +00:00
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-10 08:07:38 +00:00
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "sa_payload.h"
|
|
|
|
|
2005-11-23 09:57:18 +00:00
|
|
|
#include <encoding/payloads/encodings.h>
|
2005-11-23 09:08:45 +00:00
|
|
|
#include <utils/linked_list.h>
|
2006-06-15 11:09:11 +00:00
|
|
|
#include <utils/logger_manager.h>
|
2005-11-14 10:14:22 +00:00
|
|
|
|
|
|
|
|
2005-11-24 09:17:51 +00:00
|
|
|
typedef struct private_sa_payload_t private_sa_payload_t;
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Private data of an sa_payload_t object.
|
2005-11-14 10:14:22 +00:00
|
|
|
*
|
|
|
|
*/
|
2005-11-24 09:17:51 +00:00
|
|
|
struct private_sa_payload_t {
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Public sa_payload_t interface.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
sa_payload_t public;
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Next payload type.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
u_int8_t next_payload;
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Critical flag.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
bool critical;
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Length of this payload.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
u_int16_t payload_length;
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Proposals in this payload are stored in a linked_list_t.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
linked_list_t * proposals;
|
2005-11-15 09:14:45 +00:00
|
|
|
|
2006-06-15 11:09:11 +00:00
|
|
|
/**
|
|
|
|
* Logger for error handling
|
|
|
|
*/
|
|
|
|
logger_t *logger;
|
|
|
|
|
2005-11-15 09:14:45 +00:00
|
|
|
/**
|
|
|
|
* @brief Computes the length of this payload.
|
|
|
|
*
|
|
|
|
* @param this calling private_sa_payload_t object
|
|
|
|
*/
|
2005-11-28 18:24:10 +00:00
|
|
|
void (*compute_length) (private_sa_payload_t *this);
|
2005-11-14 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2005-11-15 14:59:47 +00:00
|
|
|
* Encoding rules to parse or generate a IKEv2-SA Payload
|
2005-11-14 10:14:22 +00:00
|
|
|
*
|
|
|
|
* The defined offsets are the positions in a object of type
|
|
|
|
* private_sa_payload_t.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
encoding_rule_t sa_payload_encodings[] = {
|
|
|
|
/* 1 Byte next payload type, stored in the field next_payload */
|
|
|
|
{ U_INT_8, offsetof(private_sa_payload_t, next_payload) },
|
|
|
|
/* the critical bit */
|
|
|
|
{ FLAG, offsetof(private_sa_payload_t, critical) },
|
|
|
|
/* 7 Bit reserved bits, nowhere stored */
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
{ RESERVED_BIT, 0 },
|
|
|
|
/* Length of the whole SA payload*/
|
|
|
|
{ PAYLOAD_LENGTH, offsetof(private_sa_payload_t, payload_length) },
|
|
|
|
/* Proposals are stored in a proposal substructure,
|
|
|
|
offset points to a linked_list_t pointer */
|
|
|
|
{ PROPOSALS, offsetof(private_sa_payload_t, proposals) }
|
|
|
|
};
|
|
|
|
|
2005-11-17 12:49:35 +00:00
|
|
|
/*
|
|
|
|
1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
! Next Payload !C! RESERVED ! Payload Length !
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
! !
|
|
|
|
~ <Proposals> ~
|
|
|
|
! !
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.verify.
|
2005-11-17 12:49:35 +00:00
|
|
|
*/
|
|
|
|
static status_t verify(private_sa_payload_t *this)
|
|
|
|
{
|
2006-06-15 11:09:11 +00:00
|
|
|
int expected_number = 1, current_number;
|
2005-11-29 12:23:40 +00:00
|
|
|
status_t status = SUCCESS;
|
2005-11-24 14:22:29 +00:00
|
|
|
iterator_t *iterator;
|
2005-11-17 12:49:35 +00:00
|
|
|
bool first = TRUE;
|
|
|
|
|
|
|
|
/* check proposal numbering */
|
2005-11-29 08:54:48 +00:00
|
|
|
iterator = this->proposals->create_iterator(this->proposals,TRUE);
|
2005-11-17 12:49:35 +00:00
|
|
|
|
|
|
|
while(iterator->has_next(iterator))
|
|
|
|
{
|
|
|
|
proposal_substructure_t *current_proposal;
|
2005-11-29 12:23:40 +00:00
|
|
|
iterator->current(iterator,(void **)¤t_proposal);
|
2006-06-15 11:09:11 +00:00
|
|
|
current_number = current_proposal->get_proposal_number(current_proposal);
|
|
|
|
if (current_number > expected_number)
|
2005-11-17 12:49:35 +00:00
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
{
|
2006-06-15 11:09:11 +00:00
|
|
|
this->logger->log(this->logger, ERROR, "first proposal is not proposal #1");
|
2005-11-17 12:49:35 +00:00
|
|
|
status = FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-15 11:09:11 +00:00
|
|
|
if (current_number != (expected_number + 1))
|
2005-11-17 12:49:35 +00:00
|
|
|
{
|
2006-06-15 11:09:11 +00:00
|
|
|
this->logger->log(this->logger, ERROR, "proposal number is %d, excepted %d or %d",
|
|
|
|
current_number, expected_number, expected_number + 1);
|
2005-11-17 12:49:35 +00:00
|
|
|
status = FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 11:09:11 +00:00
|
|
|
else if (current_number < expected_number)
|
2005-11-17 12:49:35 +00:00
|
|
|
{
|
|
|
|
/* must not be smaller then proceeding one */
|
2006-06-15 11:09:11 +00:00
|
|
|
this->logger->log(this->logger, ERROR, "proposal number smaller than that of previous proposal");
|
2005-11-17 12:49:35 +00:00
|
|
|
status = FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-29 12:23:40 +00:00
|
|
|
|
|
|
|
status = current_proposal->payload_interface.verify(&(current_proposal->payload_interface));
|
|
|
|
if (status != SUCCESS)
|
|
|
|
{
|
2006-07-13 12:49:35 +00:00
|
|
|
this->logger->log(this->logger, ERROR, "PROPOSAL_SUBSTRUCTURE verification failed");
|
2005-11-29 12:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-17 12:49:35 +00:00
|
|
|
first = FALSE;
|
2006-06-15 11:09:11 +00:00
|
|
|
expected_number = current_number;
|
2005-11-17 12:49:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.destroy and sa_payload_t.destroy.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
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;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->proposals->remove_last(this->proposals,(void **)¤t_proposal);
|
2005-11-14 10:14:22 +00:00
|
|
|
current_proposal->destroy(current_proposal);
|
|
|
|
}
|
|
|
|
this->proposals->destroy(this->proposals);
|
|
|
|
|
2006-04-10 08:07:38 +00:00
|
|
|
free(this);
|
2005-11-14 10:14:22 +00:00
|
|
|
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.get_encoding_rules.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
2005-11-28 18:24:10 +00:00
|
|
|
static void get_encoding_rules(private_sa_payload_t *this, encoding_rule_t **rules, size_t *rule_count)
|
2005-11-14 10:14:22 +00:00
|
|
|
{
|
|
|
|
*rules = sa_payload_encodings;
|
|
|
|
*rule_count = sizeof(sa_payload_encodings) / sizeof(encoding_rule_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.get_type.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
static payload_type_t get_type(private_sa_payload_t *this)
|
|
|
|
{
|
|
|
|
return SECURITY_ASSOCIATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.get_next_type.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
static payload_type_t get_next_type(private_sa_payload_t *this)
|
|
|
|
{
|
|
|
|
return (this->next_payload);
|
|
|
|
}
|
|
|
|
|
2005-11-15 09:14:45 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.set_next_type.
|
2005-11-15 09:14:45 +00:00
|
|
|
*/
|
2005-11-28 18:24:10 +00:00
|
|
|
static void set_next_type(private_sa_payload_t *this,payload_type_t type)
|
2005-11-15 09:14:45 +00:00
|
|
|
{
|
|
|
|
this->next_payload = type;
|
|
|
|
}
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of payload_t.get_length.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
static size_t get_length(private_sa_payload_t *this)
|
|
|
|
{
|
2005-11-15 09:14:45 +00:00
|
|
|
this->compute_length(this);
|
2005-11-14 10:14:22 +00:00
|
|
|
return this->payload_length;
|
|
|
|
}
|
|
|
|
|
2005-11-14 12:04:06 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of sa_payload_t.create_proposal_substructure_iterator.
|
2005-11-14 12:04:06 +00:00
|
|
|
*/
|
2005-11-29 08:54:48 +00:00
|
|
|
static iterator_t *create_proposal_substructure_iterator (private_sa_payload_t *this,bool forward)
|
2005-11-14 12:04:06 +00:00
|
|
|
{
|
2005-11-29 08:54:48 +00:00
|
|
|
return this->proposals->create_iterator(this->proposals,forward);
|
2005-11-14 12:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of sa_payload_t.add_proposal_substructure.
|
2005-11-14 12:04:06 +00:00
|
|
|
*/
|
2006-06-07 13:26:23 +00:00
|
|
|
static void add_proposal_substructure(private_sa_payload_t *this,proposal_substructure_t *proposal)
|
2005-11-14 12:04:06 +00:00
|
|
|
{
|
2005-12-01 08:48:57 +00:00
|
|
|
status_t status;
|
2006-06-07 13:26:23 +00:00
|
|
|
u_int proposal_count = this->proposals->get_count(this->proposals);
|
|
|
|
|
|
|
|
if (proposal_count > 0)
|
2005-12-01 08:48:57 +00:00
|
|
|
{
|
|
|
|
proposal_substructure_t *last_proposal;
|
|
|
|
status = this->proposals->get_last(this->proposals,(void **) &last_proposal);
|
|
|
|
/* last transform is now not anymore last one */
|
2006-06-07 13:26:23 +00:00
|
|
|
last_proposal->set_is_last_proposal(last_proposal, FALSE);
|
2005-12-01 08:48:57 +00:00
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
proposal->set_is_last_proposal(proposal, TRUE);
|
|
|
|
proposal->set_proposal_number(proposal, proposal_count + 1);
|
2005-11-28 18:24:10 +00:00
|
|
|
this->proposals->insert_last(this->proposals,(void *) proposal);
|
2005-11-15 09:14:45 +00:00
|
|
|
this->compute_length(this);
|
|
|
|
}
|
|
|
|
|
2006-02-06 14:05:35 +00:00
|
|
|
/**
|
2006-02-14 14:52:00 +00:00
|
|
|
* Implementation of sa_payload_t.add_proposal.
|
2006-02-06 14:05:35 +00:00
|
|
|
*/
|
2006-02-14 14:52:00 +00:00
|
|
|
static void add_proposal(private_sa_payload_t *this, proposal_t *proposal)
|
2006-02-06 14:05:35 +00:00
|
|
|
{
|
|
|
|
proposal_substructure_t *substructure;
|
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
substructure = proposal_substructure_create_from_proposal(proposal);
|
|
|
|
add_proposal_substructure(this, substructure);
|
2006-02-06 14:05:35 +00:00
|
|
|
}
|
|
|
|
|
2005-12-01 08:48:57 +00:00
|
|
|
/**
|
2006-02-14 14:52:00 +00:00
|
|
|
* Implementation of sa_payload_t.get_proposals.
|
2005-12-01 08:48:57 +00:00
|
|
|
*/
|
2006-02-14 14:52:00 +00:00
|
|
|
static linked_list_t *get_proposals(private_sa_payload_t *this)
|
2005-12-01 12:18:20 +00:00
|
|
|
{
|
2006-06-07 13:26:23 +00:00
|
|
|
int struct_number = 0;
|
|
|
|
int ignore_struct_number = 0;
|
2005-12-01 12:18:20 +00:00
|
|
|
iterator_t *iterator;
|
2006-02-08 15:25:34 +00:00
|
|
|
linked_list_t *proposal_list;
|
2005-12-01 12:18:20 +00:00
|
|
|
|
2006-02-08 15:25:34 +00:00
|
|
|
/* this list will hold our proposals */
|
|
|
|
proposal_list = linked_list_create();
|
2005-12-12 08:44:35 +00:00
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
/* we do not support proposals split up to two proposal substructures, as
|
|
|
|
* AH+ESP bundles are not supported in RFC4301 anymore.
|
|
|
|
* To handle such structures safely, we just skip proposals with multiple
|
|
|
|
* protocols.
|
|
|
|
*/
|
|
|
|
iterator = this->proposals->create_iterator(this->proposals, TRUE);
|
2005-12-01 12:18:20 +00:00
|
|
|
while (iterator->has_next(iterator))
|
|
|
|
{
|
2006-06-07 13:26:23 +00:00
|
|
|
proposal_t *proposal;
|
2006-02-08 15:25:34 +00:00
|
|
|
proposal_substructure_t *proposal_struct;
|
2005-12-01 12:18:20 +00:00
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
iterator->current(iterator, (void **)&proposal_struct);
|
|
|
|
/* check if a proposal has a single protocol */
|
|
|
|
if (proposal_struct->get_proposal_number(proposal_struct) == struct_number)
|
|
|
|
{
|
|
|
|
if (ignore_struct_number < struct_number)
|
|
|
|
{
|
|
|
|
/* remova an already added, if first of series */
|
2006-07-05 10:53:20 +00:00
|
|
|
proposal_list->remove_last(proposal_list, (void**)&proposal);
|
2006-06-07 13:26:23 +00:00
|
|
|
proposal->destroy(proposal);
|
|
|
|
ignore_struct_number = struct_number;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
struct_number++;
|
|
|
|
proposal = proposal_struct->get_proposal(proposal_struct);
|
|
|
|
if (proposal)
|
2005-12-01 12:18:20 +00:00
|
|
|
{
|
2006-02-08 15:25:34 +00:00
|
|
|
proposal_list->insert_last(proposal_list, proposal);
|
2005-12-01 12:18:20 +00:00
|
|
|
}
|
|
|
|
}
|
2006-02-08 15:25:34 +00:00
|
|
|
iterator->destroy(iterator);
|
|
|
|
return proposal_list;
|
2005-12-01 12:18:20 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 09:14:45 +00:00
|
|
|
/**
|
2005-11-28 18:24:10 +00:00
|
|
|
* Implementation of private_sa_payload_t.compute_length.
|
2005-11-15 09:14:45 +00:00
|
|
|
*/
|
2005-11-28 18:24:10 +00:00
|
|
|
static void compute_length (private_sa_payload_t *this)
|
2005-11-15 09:14:45 +00:00
|
|
|
{
|
2005-11-24 14:22:29 +00:00
|
|
|
iterator_t *iterator;
|
2005-11-15 09:14:45 +00:00
|
|
|
size_t length = SA_PAYLOAD_HEADER_LENGTH;
|
2005-11-29 08:54:48 +00:00
|
|
|
iterator = this->proposals->create_iterator(this->proposals,TRUE);
|
2005-11-15 09:14:45 +00:00
|
|
|
while (iterator->has_next(iterator))
|
|
|
|
{
|
|
|
|
payload_t *current_proposal;
|
|
|
|
iterator->current(iterator,(void **) ¤t_proposal);
|
|
|
|
length += current_proposal->get_length(current_proposal);
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
|
|
|
|
this->payload_length = length;
|
2005-11-14 12:04:06 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/*
|
2005-11-28 18:24:10 +00:00
|
|
|
* Described in header.
|
2005-11-14 10:14:22 +00:00
|
|
|
*/
|
|
|
|
sa_payload_t *sa_payload_create()
|
|
|
|
{
|
2006-04-10 08:07:38 +00:00
|
|
|
private_sa_payload_t *this = malloc_thing(private_sa_payload_t);
|
2005-11-14 10:14:22 +00:00
|
|
|
|
2005-11-17 12:49:35 +00:00
|
|
|
/* public interface */
|
|
|
|
this->public.payload_interface.verify = (status_t (*) (payload_t *))verify;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->public.payload_interface.get_encoding_rules = (void (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules;
|
2005-11-14 10:14:22 +00:00
|
|
|
this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length;
|
|
|
|
this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type;
|
2005-11-14 10:14:22 +00:00
|
|
|
this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->public.payload_interface.destroy = (void (*) (payload_t *))destroy;
|
2005-11-17 12:49:35 +00:00
|
|
|
|
|
|
|
/* public functions */
|
2005-11-29 08:54:48 +00:00
|
|
|
this->public.create_proposal_substructure_iterator = (iterator_t* (*) (sa_payload_t *,bool)) create_proposal_substructure_iterator;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->public.add_proposal_substructure = (void (*) (sa_payload_t *,proposal_substructure_t *)) add_proposal_substructure;
|
2006-05-24 09:05:21 +00:00
|
|
|
this->public.add_proposal = (void (*) (sa_payload_t*,proposal_t*))add_proposal;
|
2006-02-14 14:52:00 +00:00
|
|
|
this->public.get_proposals = (linked_list_t* (*) (sa_payload_t *)) get_proposals;
|
2005-11-28 18:24:10 +00:00
|
|
|
this->public.destroy = (void (*) (sa_payload_t *)) destroy;
|
2005-11-14 10:14:22 +00:00
|
|
|
|
2005-11-15 09:14:45 +00:00
|
|
|
/* private functions */
|
|
|
|
this->compute_length = compute_length;
|
|
|
|
|
2005-11-14 10:14:22 +00:00
|
|
|
/* set default values of the fields */
|
2006-03-23 15:25:43 +00:00
|
|
|
this->critical = FALSE;
|
2005-11-14 10:14:22 +00:00
|
|
|
this->next_payload = NO_PAYLOAD;
|
|
|
|
this->payload_length = SA_PAYLOAD_HEADER_LENGTH;
|
2006-06-15 11:09:11 +00:00
|
|
|
this->logger = logger_manager->get_logger(logger_manager, PARSER);
|
2005-11-14 10:14:22 +00:00
|
|
|
|
|
|
|
this->proposals = linked_list_create();
|
2006-06-07 13:26:23 +00:00
|
|
|
return &this->public;
|
2005-11-14 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
2005-12-01 08:48:57 +00:00
|
|
|
/*
|
|
|
|
* Described in header.
|
|
|
|
*/
|
2006-02-14 14:52:00 +00:00
|
|
|
sa_payload_t *sa_payload_create_from_proposal_list(linked_list_t *proposals)
|
2006-02-08 15:25:34 +00:00
|
|
|
{
|
|
|
|
iterator_t *iterator;
|
2006-02-14 14:52:00 +00:00
|
|
|
proposal_t *proposal;
|
2006-02-08 15:25:34 +00:00
|
|
|
sa_payload_t *sa_payload = sa_payload_create();
|
2005-12-01 12:18:20 +00:00
|
|
|
|
2006-02-08 15:25:34 +00:00
|
|
|
/* add every payload from the list */
|
|
|
|
iterator = proposals->create_iterator(proposals, TRUE);
|
|
|
|
while (iterator->has_next(iterator))
|
2005-12-01 12:18:20 +00:00
|
|
|
{
|
2006-02-08 15:25:34 +00:00
|
|
|
iterator->current(iterator, (void**)&proposal);
|
2006-02-14 14:52:00 +00:00
|
|
|
add_proposal((private_sa_payload_t*)sa_payload, proposal);
|
2005-12-01 12:18:20 +00:00
|
|
|
}
|
2006-02-09 11:56:24 +00:00
|
|
|
iterator->destroy(iterator);
|
2005-12-01 12:18:20 +00:00
|
|
|
|
|
|
|
return sa_payload;
|
|
|
|
}
|
2006-02-09 10:16:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Described in header.
|
|
|
|
*/
|
2006-02-14 14:52:00 +00:00
|
|
|
sa_payload_t *sa_payload_create_from_proposal(proposal_t *proposal)
|
2006-02-09 10:16:20 +00:00
|
|
|
{
|
|
|
|
sa_payload_t *sa_payload = sa_payload_create();
|
|
|
|
|
2006-02-14 14:52:00 +00:00
|
|
|
add_proposal((private_sa_payload_t*)sa_payload, proposal);
|
2006-02-09 10:16:20 +00:00
|
|
|
|
|
|
|
return sa_payload;
|
|
|
|
}
|