Migrated proposal_t to INIT/METHOD macros

This commit is contained in:
Martin Willi
2010-10-28 13:06:20 +00:00
parent 806b69a467
commit d454c586ab
+53 -79
View File
@@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2008-2009 Tobias Brunner * Copyright (C) 2008-2009 Tobias Brunner
* Copyright (C) 2006 Martin Willi * Copyright (C) 2006-2010 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * 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); list->insert_last(list, (void*)algo_key);
} }
/** METHOD(proposal_t, add_algorithm, void,
* Implements proposal_t.add_algorithm private_proposal_t *this, transform_type_t type,
*/ u_int16_t algo, u_int16_t key_size)
static void add_algorithm(private_proposal_t *this, transform_type_t type,
u_int16_t algo, u_int16_t key_size)
{ {
switch (type) switch (type)
{ {
@@ -160,11 +158,8 @@ static bool alg_filter(void *null, algorithm_t **in, u_int16_t *alg,
return TRUE; return TRUE;
} }
/** METHOD(proposal_t, create_enumerator, enumerator_t*,
* Implements proposal_t.create_enumerator. private_proposal_t *this, transform_type_t type)
*/
static enumerator_t *create_enumerator(private_proposal_t *this,
transform_type_t type)
{ {
linked_list_t *list; linked_list_t *list;
@@ -192,11 +187,9 @@ static enumerator_t *create_enumerator(private_proposal_t *this,
(void*)alg_filter, NULL, NULL); (void*)alg_filter, NULL, NULL);
} }
/** METHOD(proposal_t, get_algorithm, bool,
* Implements proposal_t.get_algorithm. private_proposal_t *this, transform_type_t type,
*/ u_int16_t *alg, u_int16_t *key_size)
static bool get_algorithm(private_proposal_t *this, transform_type_t type,
u_int16_t *alg, u_int16_t *key_size)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
bool found = FALSE; bool found = FALSE;
@@ -210,10 +203,8 @@ static bool get_algorithm(private_proposal_t *this, transform_type_t type,
return found; return found;
} }
/** METHOD(proposal_t, has_dh_group, bool,
* Implements proposal_t.has_dh_group private_proposal_t *this, diffie_hellman_group_t group)
*/
static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
{ {
bool result = FALSE; bool result = FALSE;
@@ -240,10 +231,8 @@ static bool has_dh_group(private_proposal_t *this, diffie_hellman_group_t group)
return result; return result;
} }
/** METHOD(proposal_t, strip_dh, void,
* Implementation of proposal_t.strip_dh. private_proposal_t *this)
*/
static void strip_dh(private_proposal_t *this)
{ {
algorithm_t *alg; algorithm_t *alg;
@@ -304,12 +293,10 @@ static bool select_algo(linked_list_t *first, linked_list_t *second, bool priv,
return FALSE; return FALSE;
} }
/** METHOD(proposal_t, select_proposal, proposal_t*,
* Implements proposal_t.select. private_proposal_t *this, proposal_t *other_pub, bool private)
*/
static proposal_t *select_proposal(private_proposal_t *this,
private_proposal_t *other, bool private)
{ {
private_proposal_t *other = (private_proposal_t*)other_pub;
proposal_t *selected; proposal_t *selected;
u_int16_t algo; u_int16_t algo;
size_t key_size; size_t key_size;
@@ -420,26 +407,20 @@ static proposal_t *select_proposal(private_proposal_t *this,
return selected; return selected;
} }
/** METHOD(proposal_t, get_protocol, protocol_id_t,
* Implements proposal_t.get_protocols. private_proposal_t *this)
*/
static protocol_id_t get_protocol(private_proposal_t *this)
{ {
return this->protocol; return this->protocol;
} }
/** METHOD(proposal_t, set_spi, void,
* Implements proposal_t.set_spi. private_proposal_t *this, u_int64_t spi)
*/
static void set_spi(private_proposal_t *this, u_int64_t spi)
{ {
this->spi = spi; this->spi = spi;
} }
/** METHOD(proposal_t, get_spi, u_int64_t,
* Implements proposal_t.get_spi. private_proposal_t *this)
*/
static u_int64_t get_spi(private_proposal_t *this)
{ {
return this->spi; return this->spi;
} }
@@ -492,19 +473,15 @@ static bool algo_list_equals(linked_list_t *l1, linked_list_t *l2)
return equals; return equals;
} }
/** METHOD(proposal_t, equals, bool,
* Implementation of proposal_t.equals. private_proposal_t *this, proposal_t *other_pub)
*/
static bool equals(private_proposal_t *this, private_proposal_t *other)
{ {
private_proposal_t *other = (private_proposal_t*)other_pub;
if (this == other) if (this == other)
{ {
return TRUE; return TRUE;
} }
if (this->public.equals != other->public.equals)
{
return FALSE;
}
return ( return (
algo_list_equals(this->encryption_algos, other->encryption_algos) && algo_list_equals(this->encryption_algos, other->encryption_algos) &&
algo_list_equals(this->integrity_algos, other->integrity_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)); algo_list_equals(this->esns, other->esns));
} }
/** METHOD(proposal_t, clone_, proposal_t*,
* Implements proposal_t.clone private_proposal_t *this)
*/
static proposal_t *clone_(private_proposal_t *this)
{ {
private_proposal_t *clone = (private_proposal_t*)proposal_create(this->protocol); 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; return written;
} }
/** METHOD(proposal_t, destroy, void,
* Implements proposal_t.destroy. private_proposal_t *this)
*/
static void destroy(private_proposal_t *this)
{ {
this->encryption_algos->destroy_function(this->encryption_algos, free); this->encryption_algos->destroy_function(this->encryption_algos, free);
this->integrity_algos->destroy_function(this->integrity_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) 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; INIT(this,
this->public.create_enumerator = (enumerator_t* (*)(proposal_t*,transform_type_t))create_enumerator; .public = {
this->public.get_algorithm = (bool (*)(proposal_t*,transform_type_t,u_int16_t*,u_int16_t*))get_algorithm; .add_algorithm = _add_algorithm,
this->public.has_dh_group = (bool (*)(proposal_t*,diffie_hellman_group_t))has_dh_group; .create_enumerator = _create_enumerator,
this->public.strip_dh = (void(*)(proposal_t*))strip_dh; .get_algorithm = _get_algorithm,
this->public.select = (proposal_t* (*)(proposal_t*,proposal_t*,bool))select_proposal; .has_dh_group = _has_dh_group,
this->public.get_protocol = (protocol_id_t(*)(proposal_t*))get_protocol; .strip_dh = _strip_dh,
this->public.set_spi = (void(*)(proposal_t*,u_int64_t))set_spi; .select = _select_proposal,
this->public.get_spi = (u_int64_t(*)(proposal_t*))get_spi; .get_protocol = _get_protocol,
this->public.equals = (bool(*)(proposal_t*, proposal_t *other))equals; .set_spi = _set_spi,
this->public.clone = (proposal_t*(*)(proposal_t*))clone_; .get_spi = _get_spi,
this->public.destroy = (void(*)(proposal_t*))destroy; .equals = _equals,
.clone = _clone_,
this->spi = 0; .destroy = _destroy,
this->protocol = protocol; },
.protocol = protocol,
this->encryption_algos = linked_list_create(); .encryption_algos = linked_list_create(),
this->integrity_algos = linked_list_create(); .integrity_algos = linked_list_create(),
this->prf_algos = linked_list_create(); .prf_algos = linked_list_create(),
this->dh_groups = linked_list_create(); .dh_groups = linked_list_create(),
this->esns = linked_list_create(); .esns = linked_list_create(),
);
return &this->public; return &this->public;
} }