Migrated proposal_t to INIT/METHOD macros
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2009 Tobias Brunner
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* Copyright (C) 2006-2010 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -117,11 +117,9 @@ static void add_algo(linked_list_t *list, u_int16_t algo, u_int16_t key_size)
|
||||
list->insert_last(list, (void*)algo_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.add_algorithm
|
||||
*/
|
||||
static void add_algorithm(private_proposal_t *this, transform_type_t type,
|
||||
u_int16_t algo, u_int16_t key_size)
|
||||
METHOD(proposal_t, add_algorithm, void,
|
||||
private_proposal_t *this, transform_type_t type,
|
||||
u_int16_t algo, u_int16_t key_size)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -160,11 +158,8 @@ static bool alg_filter(void *null, algorithm_t **in, u_int16_t *alg,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.create_enumerator.
|
||||
*/
|
||||
static enumerator_t *create_enumerator(private_proposal_t *this,
|
||||
transform_type_t type)
|
||||
METHOD(proposal_t, create_enumerator, enumerator_t*,
|
||||
private_proposal_t *this, transform_type_t type)
|
||||
{
|
||||
linked_list_t *list;
|
||||
|
||||
@@ -192,11 +187,9 @@ static enumerator_t *create_enumerator(private_proposal_t *this,
|
||||
(void*)alg_filter, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.get_algorithm.
|
||||
*/
|
||||
static bool get_algorithm(private_proposal_t *this, transform_type_t type,
|
||||
u_int16_t *alg, u_int16_t *key_size)
|
||||
METHOD(proposal_t, get_algorithm, bool,
|
||||
private_proposal_t *this, transform_type_t type,
|
||||
u_int16_t *alg, u_int16_t *key_size)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
bool found = FALSE;
|
||||
@@ -210,10 +203,8 @@ static bool get_algorithm(private_proposal_t *this, transform_type_t type,
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.has_dh_group
|
||||
*/
|
||||
static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
|
||||
METHOD(proposal_t, has_dh_group, bool,
|
||||
private_proposal_t *this, diffie_hellman_group_t group)
|
||||
{
|
||||
bool result = FALSE;
|
||||
|
||||
@@ -240,10 +231,8 @@ static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of proposal_t.strip_dh.
|
||||
*/
|
||||
static void strip_dh(private_proposal_t *this)
|
||||
METHOD(proposal_t, strip_dh, void,
|
||||
private_proposal_t *this)
|
||||
{
|
||||
algorithm_t *alg;
|
||||
|
||||
@@ -304,12 +293,10 @@ static bool select_algo(linked_list_t *first, linked_list_t *second, bool priv,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.select.
|
||||
*/
|
||||
static proposal_t *select_proposal(private_proposal_t *this,
|
||||
private_proposal_t *other, bool private)
|
||||
METHOD(proposal_t, select_proposal, proposal_t*,
|
||||
private_proposal_t *this, proposal_t *other_pub, bool private)
|
||||
{
|
||||
private_proposal_t *other = (private_proposal_t*)other_pub;
|
||||
proposal_t *selected;
|
||||
u_int16_t algo;
|
||||
size_t key_size;
|
||||
@@ -420,26 +407,20 @@ static proposal_t *select_proposal(private_proposal_t *this,
|
||||
return selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.get_protocols.
|
||||
*/
|
||||
static protocol_id_t get_protocol(private_proposal_t *this)
|
||||
METHOD(proposal_t, get_protocol, protocol_id_t,
|
||||
private_proposal_t *this)
|
||||
{
|
||||
return this->protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.set_spi.
|
||||
*/
|
||||
static void set_spi(private_proposal_t *this, u_int64_t spi)
|
||||
METHOD(proposal_t, set_spi, void,
|
||||
private_proposal_t *this, u_int64_t spi)
|
||||
{
|
||||
this->spi = spi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.get_spi.
|
||||
*/
|
||||
static u_int64_t get_spi(private_proposal_t *this)
|
||||
METHOD(proposal_t, get_spi, u_int64_t,
|
||||
private_proposal_t *this)
|
||||
{
|
||||
return this->spi;
|
||||
}
|
||||
@@ -492,19 +473,15 @@ static bool algo_list_equals(linked_list_t *l1, linked_list_t *l2)
|
||||
return equals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of proposal_t.equals.
|
||||
*/
|
||||
static bool equals(private_proposal_t *this, private_proposal_t *other)
|
||||
METHOD(proposal_t, equals, bool,
|
||||
private_proposal_t *this, proposal_t *other_pub)
|
||||
{
|
||||
private_proposal_t *other = (private_proposal_t*)other_pub;
|
||||
|
||||
if (this == other)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
if (this->public.equals != other->public.equals)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return (
|
||||
algo_list_equals(this->encryption_algos, other->encryption_algos) &&
|
||||
algo_list_equals(this->integrity_algos, other->integrity_algos) &&
|
||||
@@ -513,10 +490,8 @@ static bool equals(private_proposal_t *this, private_proposal_t *other)
|
||||
algo_list_equals(this->esns, other->esns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.clone
|
||||
*/
|
||||
static proposal_t *clone_(private_proposal_t *this)
|
||||
METHOD(proposal_t, clone_, proposal_t*,
|
||||
private_proposal_t *this)
|
||||
{
|
||||
private_proposal_t *clone = (private_proposal_t*)proposal_create(this->protocol);
|
||||
|
||||
@@ -696,10 +671,8 @@ int proposal_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec,
|
||||
return written;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_t.destroy.
|
||||
*/
|
||||
static void destroy(private_proposal_t *this)
|
||||
METHOD(proposal_t, destroy, void,
|
||||
private_proposal_t *this)
|
||||
{
|
||||
this->encryption_algos->destroy_function(this->encryption_algos, free);
|
||||
this->integrity_algos->destroy_function(this->integrity_algos, free);
|
||||
@@ -714,29 +687,30 @@ static void destroy(private_proposal_t *this)
|
||||
*/
|
||||
proposal_t *proposal_create(protocol_id_t protocol)
|
||||
{
|
||||
private_proposal_t *this = malloc_thing(private_proposal_t);
|
||||
private_proposal_t *this;
|
||||
|
||||
this->public.add_algorithm = (void (*)(proposal_t*,transform_type_t,u_int16_t,u_int16_t))add_algorithm;
|
||||
this->public.create_enumerator = (enumerator_t* (*)(proposal_t*,transform_type_t))create_enumerator;
|
||||
this->public.get_algorithm = (bool (*)(proposal_t*,transform_type_t,u_int16_t*,u_int16_t*))get_algorithm;
|
||||
this->public.has_dh_group = (bool (*)(proposal_t*,diffie_hellman_group_t))has_dh_group;
|
||||
this->public.strip_dh = (void(*)(proposal_t*))strip_dh;
|
||||
this->public.select = (proposal_t* (*)(proposal_t*,proposal_t*,bool))select_proposal;
|
||||
this->public.get_protocol = (protocol_id_t(*)(proposal_t*))get_protocol;
|
||||
this->public.set_spi = (void(*)(proposal_t*,u_int64_t))set_spi;
|
||||
this->public.get_spi = (u_int64_t(*)(proposal_t*))get_spi;
|
||||
this->public.equals = (bool(*)(proposal_t*, proposal_t *other))equals;
|
||||
this->public.clone = (proposal_t*(*)(proposal_t*))clone_;
|
||||
this->public.destroy = (void(*)(proposal_t*))destroy;
|
||||
|
||||
this->spi = 0;
|
||||
this->protocol = protocol;
|
||||
|
||||
this->encryption_algos = linked_list_create();
|
||||
this->integrity_algos = linked_list_create();
|
||||
this->prf_algos = linked_list_create();
|
||||
this->dh_groups = linked_list_create();
|
||||
this->esns = linked_list_create();
|
||||
INIT(this,
|
||||
.public = {
|
||||
.add_algorithm = _add_algorithm,
|
||||
.create_enumerator = _create_enumerator,
|
||||
.get_algorithm = _get_algorithm,
|
||||
.has_dh_group = _has_dh_group,
|
||||
.strip_dh = _strip_dh,
|
||||
.select = _select_proposal,
|
||||
.get_protocol = _get_protocol,
|
||||
.set_spi = _set_spi,
|
||||
.get_spi = _get_spi,
|
||||
.equals = _equals,
|
||||
.clone = _clone_,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.protocol = protocol,
|
||||
.encryption_algos = linked_list_create(),
|
||||
.integrity_algos = linked_list_create(),
|
||||
.prf_algos = linked_list_create(),
|
||||
.dh_groups = linked_list_create(),
|
||||
.esns = linked_list_create(),
|
||||
);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user