diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2011-12-18 17:20:13 +0100 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2011-12-18 17:20:13 +0100 |
commit | 8982b702984a08bdcc568fa63402b3d012e440aa (patch) | |
tree | 903a1f454f6b9aed6fd1d10de39fa2d9b7d8fe51 /src/libimcv | |
parent | 4f9134270214412c69e1c100c3ff9ac35a4522b6 (diff) | |
download | strongswan-8982b702984a08bdcc568fa63402b3d012e440aa.tar.bz2 strongswan-8982b702984a08bdcc568fa63402b3d012e440aa.tar.xz |
added reference counts to all PA-TNC attribute classes
Diffstat (limited to 'src/libimcv')
-rw-r--r-- | src/libimcv/ietf/ietf_attr_port_filter.c | 25 | ||||
-rw-r--r-- | src/libimcv/ietf/ietf_attr_product_info.c | 24 |
2 files changed, 43 insertions, 6 deletions
diff --git a/src/libimcv/ietf/ietf_attr_port_filter.c b/src/libimcv/ietf/ietf_attr_port_filter.c index c9b76dde5..b53019657 100644 --- a/src/libimcv/ietf/ietf_attr_port_filter.c +++ b/src/libimcv/ietf/ietf_attr_port_filter.c @@ -81,6 +81,11 @@ struct private_ietf_attr_port_filter_t { * List of Port Filter entries */ linked_list_t *ports; + + /** + * Reference count + */ + refcount_t ref; }; METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, @@ -166,12 +171,22 @@ METHOD(pa_tnc_attr_t, process, status_t, return SUCCESS; } +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ietf_attr_port_filter_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + METHOD(pa_tnc_attr_t, destroy, void, private_ietf_attr_port_filter_t *this) { - this->ports->destroy_function(this->ports, free); - free(this->value.ptr); - free(this); + if (ref_put(&this->ref)) + { + this->ports->destroy_function(this->ports, free); + free(this->value.ptr); + free(this); + } } METHOD(ietf_attr_port_filter_t, add_port, void, @@ -224,6 +239,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create(void) .set_noskip_flag = _set_noskip_flag, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .add_port = _add_port, @@ -232,6 +248,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create(void) .vendor_id = PEN_IETF, .type = IETF_ATTR_PORT_FILTER, .ports = linked_list_create(), + .ref = 1, ); return &this->public.pa_tnc_attribute; @@ -252,6 +269,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create_from_data(chunk_t data) .get_value = _get_value, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .add_port = _add_port, @@ -261,6 +279,7 @@ pa_tnc_attr_t *ietf_attr_port_filter_create_from_data(chunk_t data) .type = IETF_ATTR_PORT_FILTER, .value = chunk_clone(data), .ports = linked_list_create(), + .ref = 1, ); return &this->public.pa_tnc_attribute; diff --git a/src/libimcv/ietf/ietf_attr_product_info.c b/src/libimcv/ietf/ietf_attr_product_info.c index 222fef0bf..548793547 100644 --- a/src/libimcv/ietf/ietf_attr_product_info.c +++ b/src/libimcv/ietf/ietf_attr_product_info.c @@ -80,6 +80,10 @@ struct private_ietf_attr_product_info_t { */ char *product_name; + /** + * Reference count + */ + refcount_t ref; }; METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, @@ -154,12 +158,22 @@ METHOD(pa_tnc_attr_t, process, status_t, return SUCCESS; } +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ietf_attr_product_info_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + METHOD(pa_tnc_attr_t, destroy, void, private_ietf_attr_product_info_t *this) { - free(this->product_name); - free(this->value.ptr); - free(this); + if (ref_put(&this->ref)) + { + free(this->product_name); + free(this->value.ptr); + free(this); + } } METHOD(ietf_attr_product_info_t, get_info, char*, @@ -194,6 +208,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create(pen_t vendor_id, u_int16_t id, .set_noskip_flag = _set_noskip_flag, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_info = _get_info, @@ -203,6 +218,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create(pen_t vendor_id, u_int16_t id, .product_vendor_id = vendor_id, .product_id = id, .product_name = strdup(name), + .ref = 1, ); return &this->public.pa_tnc_attribute; @@ -223,6 +239,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create_from_data(chunk_t data) .get_value = _get_value, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_info = _get_info, @@ -230,6 +247,7 @@ pa_tnc_attr_t *ietf_attr_product_info_create_from_data(chunk_t data) .vendor_id = PEN_IETF, .type = IETF_ATTR_PRODUCT_INFORMATION, .value = chunk_clone(data), + .ref = 1, ); return &this->public.pa_tnc_attribute; |