Migrated ietf_attributes to INIT/METHOD macros

This commit is contained in:
Andreas Steffen
2011-09-29 22:46:43 +02:00
parent a6e3eabfa6
commit 3cd78d98b7
@@ -102,15 +102,14 @@ static void ietf_attr_destroy(ietf_attr_t *this)
*/ */
static ietf_attr_t* ietf_attr_create(ietf_attribute_type_t type, chunk_t value) static ietf_attr_t* ietf_attr_create(ietf_attribute_type_t type, chunk_t value)
{ {
ietf_attr_t *this = malloc_thing(ietf_attr_t); ietf_attr_t *this;
/* initialize */ INIT(this,
this->type = type; .compare = ietf_attr_compare,
this->value = chunk_clone(value); .destroy = ietf_attr_destroy,
.type = type,
/* function */ .value = chunk_clone(value),
this->compare = ietf_attr_compare; );
this->destroy = ietf_attr_destroy;
return this; return this;
} }
@@ -142,10 +141,8 @@ struct private_ietf_attributes_t {
refcount_t ref; refcount_t ref;
}; };
/** METHOD(ietf_attributes_t, get_string, char*,
* Implementation of ietf_attributes_t.get_string. private_ietf_attributes_t *this)
*/
static char* get_string(private_ietf_attributes_t *this)
{ {
if (this->string == NULL) if (this->string == NULL)
{ {
@@ -217,10 +214,8 @@ static char* get_string(private_ietf_attributes_t *this)
return this->string; return this->string;
} }
/** METHOD(ietf_attributes_t, get_encoding, chunk_t,
* Implementation of ietf_attributes_t.get_encoding. private_ietf_attributes_t *this)
*/
static chunk_t get_encoding(private_ietf_attributes_t *this)
{ {
chunk_t values; chunk_t values;
size_t size = 0; size_t size = 0;
@@ -270,7 +265,11 @@ static chunk_t get_encoding(private_ietf_attributes_t *this)
return asn1_wrap(ASN1_SEQUENCE, "m", values); return asn1_wrap(ASN1_SEQUENCE, "m", values);
} }
static bool equals(private_ietf_attributes_t *this, private_ietf_attributes_t *other) /**
* Implementation of ietf_attributes_t.equals.
*/
static bool equals(private_ietf_attributes_t *this,
private_ietf_attributes_t *other)
{ {
bool result = TRUE; bool result = TRUE;
@@ -304,7 +303,11 @@ static bool equals(private_ietf_attributes_t *this, private_ietf_attributes_t *o
return result; return result;
} }
static bool matches(private_ietf_attributes_t *this, private_ietf_attributes_t *other) /**
* Implementation of ietf_attributes_t.matches.
*/
static bool matches(private_ietf_attributes_t *this,
private_ietf_attributes_t *other)
{ {
bool result = FALSE; bool result = FALSE;
ietf_attr_t *attr_a, *attr_b; ietf_attr_t *attr_a, *attr_b;
@@ -364,19 +367,15 @@ static bool matches(private_ietf_attributes_t *this, private_ietf_attributes_t *
return result; return result;
} }
/** METHOD(ietf_attributes_t, get_ref, ietf_attributes_t*,
* Implementation of ietf_attributes_t.get_ref private_ietf_attributes_t *this)
*/
static private_ietf_attributes_t* get_ref(private_ietf_attributes_t *this)
{ {
ref_get(&this->ref); ref_get(&this->ref);
return this; return &this->public;
} }
/** METHOD(ietf_attributes_t, destroy, void,
* Implementation of ietf_attributes_t.destroy. private_ietf_attributes_t *this)
*/
static void destroy(private_ietf_attributes_t *this)
{ {
if (ref_put(&this->ref)) if (ref_put(&this->ref))
{ {
@@ -388,18 +387,21 @@ static void destroy(private_ietf_attributes_t *this)
static private_ietf_attributes_t* create_empty(void) static private_ietf_attributes_t* create_empty(void)
{ {
private_ietf_attributes_t *this = malloc_thing(private_ietf_attributes_t); private_ietf_attributes_t *this;
this->public.get_string = (char* (*)(ietf_attributes_t*))get_string; INIT(this,
this->public.get_encoding = (chunk_t (*)(ietf_attributes_t*))get_encoding; .public = {
this->public.equals = (bool (*)(ietf_attributes_t*,ietf_attributes_t*))equals; .get_string = _get_string,
this->public.matches = (bool (*)(ietf_attributes_t*,ietf_attributes_t*))matches; .get_encoding = _get_encoding,
this->public.get_ref = (ietf_attributes_t* (*)(ietf_attributes_t*))get_ref; .equals = (bool (*)(ietf_attributes_t*,ietf_attributes_t*))equals,
this->public.destroy = (void (*)(ietf_attributes_t*))destroy; .matches = (bool (*)(ietf_attributes_t*,ietf_attributes_t*))matches,
.get_ref = _get_ref,
.destroy = _destroy,
},
.list = linked_list_create(),
.ref = 1,
);
this->list = linked_list_create();
this->string = NULL;
this->ref = 1;
return this; return this;
} }
@@ -517,7 +519,7 @@ ietf_attributes_t *ietf_attributes_create_from_encoding(chunk_t encoded)
ietf_attr_t *attr; ietf_attr_t *attr;
type = (objectID - IETF_ATTR_OCTETS) / 2; type = (objectID - IETF_ATTR_OCTETS) / 2;
attr = ietf_attr_create(type, object); attr = ietf_attr_create(type, object);
ietf_attributes_add(this, attr); ietf_attributes_add(this, attr);
} }
break; break;