Migrated ike_cfg_t to METHOD/INIT macros

This commit is contained in:
Martin Willi
2010-02-26 11:44:32 +01:00
parent 147dd96376
commit deac3a0a5d
+52 -72
View File
@@ -64,71 +64,57 @@ struct private_ike_cfg_t {
linked_list_t *proposals; linked_list_t *proposals;
}; };
/** METHOD(ike_cfg_t, send_certreq, bool,
* Implementation of ike_cfg_t.certreq. private_ike_cfg_t *this)
*/
static bool send_certreq(private_ike_cfg_t *this)
{ {
return this->certreq; return this->certreq;
} }
/** METHOD(ike_cfg_t, force_encap_, bool,
* Implementation of ike_cfg_t.force_encap. private_ike_cfg_t *this)
*/
static bool force_encap_meth(private_ike_cfg_t *this)
{ {
return this->force_encap; return this->force_encap;
} }
/** METHOD(ike_cfg_t, get_my_addr, char*,
* Implementation of ike_cfg_t.get_my_addr. private_ike_cfg_t *this)
*/
static char *get_my_addr(private_ike_cfg_t *this)
{ {
return this->me; return this->me;
} }
/** METHOD(ike_cfg_t, get_other_addr, char*,
* Implementation of ike_cfg_t.get_other_addr. private_ike_cfg_t *this)
*/
static char *get_other_addr(private_ike_cfg_t *this)
{ {
return this->other; return this->other;
} }
/** METHOD(ike_cfg_t, add_proposal, void,
* Implementation of ike_cfg_t.add_proposal. private_ike_cfg_t *this, proposal_t *proposal)
*/
static void add_proposal(private_ike_cfg_t *this, proposal_t *proposal)
{ {
this->proposals->insert_last(this->proposals, proposal); this->proposals->insert_last(this->proposals, proposal);
} }
/** METHOD(ike_cfg_t, get_proposals, linked_list_t*,
* Implementation of ike_cfg_t.get_proposals. private_ike_cfg_t *this)
*/
static linked_list_t* get_proposals(private_ike_cfg_t *this)
{ {
iterator_t *iterator; enumerator_t *enumerator;
proposal_t *current; proposal_t *current;
linked_list_t *proposals = linked_list_create(); linked_list_t *proposals;
iterator = this->proposals->create_iterator(this->proposals, TRUE); proposals = linked_list_create();
while (iterator->iterate(iterator, (void**)&current)) enumerator = this->proposals->create_enumerator(this->proposals);
while (enumerator->enumerate(enumerator, &current))
{ {
current = current->clone(current); current = current->clone(current);
proposals->insert_last(proposals, (void*)current); proposals->insert_last(proposals, current);
} }
iterator->destroy(iterator); enumerator->destroy(enumerator);
return proposals; return proposals;
} }
/** METHOD(ike_cfg_t, select_proposal, proposal_t*,
* Implementation of ike_cfg_t.select_proposal. private_ike_cfg_t *this, linked_list_t *proposals, bool private)
*/
static proposal_t *select_proposal(private_ike_cfg_t *this,
linked_list_t *proposals, bool private)
{ {
iterator_t *stored_iter, *supplied_iter; iterator_t *stored_iter, *supplied_iter;
proposal_t *stored, *supplied, *selected; proposal_t *stored, *supplied, *selected;
@@ -166,10 +152,8 @@ static proposal_t *select_proposal(private_ike_cfg_t *this,
return NULL; return NULL;
} }
/** METHOD(ike_cfg_t, get_dh_group, diffie_hellman_group_t,
* Implementation of ike_cfg_t.get_dh_group. private_ike_cfg_t *this)
*/
static diffie_hellman_group_t get_dh_group(private_ike_cfg_t *this)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
proposal_t *proposal; proposal_t *proposal;
@@ -187,11 +171,10 @@ static diffie_hellman_group_t get_dh_group(private_ike_cfg_t *this)
return dh_group; return dh_group;
} }
/** METHOD(ike_cfg_t, equals, bool,
* Implementation of ike_cfg_t.equals. private_ike_cfg_t *this, ike_cfg_t *other_public)
*/
static bool equals(private_ike_cfg_t *this, private_ike_cfg_t *other)
{ {
private_ike_cfg_t *other = (private_ike_cfg_t*)other_public;
enumerator_t *e1, *e2; enumerator_t *e1, *e2;
proposal_t *p1, *p2; proposal_t *p1, *p2;
bool eq = TRUE; bool eq = TRUE;
@@ -229,19 +212,15 @@ static bool equals(private_ike_cfg_t *this, private_ike_cfg_t *other)
streq(this->other, other->other)); streq(this->other, other->other));
} }
/** METHOD(ike_cfg_t, get_ref, ike_cfg_t*,
* Implementation of ike_cfg_t.get_ref. private_ike_cfg_t *this)
*/
static ike_cfg_t* get_ref(private_ike_cfg_t *this)
{ {
ref_get(&this->refcount); ref_get(&this->refcount);
return &this->public; return &this->public;
} }
/** METHOD(ike_cfg_t, destroy, void,
* Implementation of ike_cfg_t.destroy. private_ike_cfg_t *this)
*/
static void destroy(private_ike_cfg_t *this)
{ {
if (ref_put(&this->refcount)) if (ref_put(&this->refcount))
{ {
@@ -259,28 +238,29 @@ static void destroy(private_ike_cfg_t *this)
ike_cfg_t *ike_cfg_create(bool certreq, bool force_encap, ike_cfg_t *ike_cfg_create(bool certreq, bool force_encap,
char *me, char *other) char *me, char *other)
{ {
private_ike_cfg_t *this = malloc_thing(private_ike_cfg_t); private_ike_cfg_t *this;
/* public functions */ INIT(this,
this->public.send_certreq = (bool(*)(ike_cfg_t*))send_certreq; .public = {
this->public.force_encap = (bool (*) (ike_cfg_t *))force_encap_meth; .send_certreq = _send_certreq,
this->public.get_my_addr = (char*(*)(ike_cfg_t*))get_my_addr; .force_encap = _force_encap_,
this->public.get_other_addr = (char*(*)(ike_cfg_t*))get_other_addr; .get_my_addr = _get_my_addr,
this->public.add_proposal = (void(*)(ike_cfg_t*, proposal_t*)) add_proposal; .get_other_addr = _get_other_addr,
this->public.get_proposals = (linked_list_t*(*)(ike_cfg_t*))get_proposals; .add_proposal = _add_proposal,
this->public.select_proposal = (proposal_t*(*)(ike_cfg_t*,linked_list_t*,bool))select_proposal; .get_proposals = _get_proposals,
this->public.get_dh_group = (diffie_hellman_group_t(*)(ike_cfg_t*)) get_dh_group; .select_proposal = _select_proposal,
this->public.equals = (bool(*)(ike_cfg_t*,ike_cfg_t*)) equals; .get_dh_group = _get_dh_group,
this->public.get_ref = (ike_cfg_t*(*)(ike_cfg_t*))get_ref; .equals = _equals,
this->public.destroy = (void(*)(ike_cfg_t*))destroy; .get_ref = _get_ref,
.destroy = _destroy,
/* private variables */ },
this->refcount = 1; .refcount = 1,
this->certreq = certreq; .certreq = certreq,
this->force_encap = force_encap; .force_encap = force_encap,
this->me = strdup(me); .me = strdup(me),
this->other = strdup(other); .other = strdup(other),
this->proposals = linked_list_create(); .proposals = linked_list_create(),
);
return &this->public; return &this->public;
} }