diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2011-06-03 16:39:27 +0200 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2011-06-03 16:39:27 +0200 |
commit | 2f7f248f1108aeb2d5fe5a7592329b1c1e41ad47 (patch) | |
tree | d9202457d92523a7450b60e84402638e372e2b0a /src | |
parent | bc20bc192720e4f41979165ff10e1a4880779fb4 (diff) | |
download | strongswan-2f7f248f1108aeb2d5fe5a7592329b1c1e41ad47.tar.bz2 strongswan-2f7f248f1108aeb2d5fe5a7592329b1c1e41ad47.tar.xz |
added a reference count for PA-TNC attributes
Diffstat (limited to 'src')
-rw-r--r-- | src/libimcv/ietf/ietf_attr_pa_tnc_error.c | 23 | ||||
-rw-r--r-- | src/libimcv/ita/ita_attr_command.c | 25 | ||||
-rw-r--r-- | src/libimcv/pa_tnc/pa_tnc_attr.h | 7 |
3 files changed, 50 insertions, 5 deletions
diff --git a/src/libimcv/ietf/ietf_attr_pa_tnc_error.c b/src/libimcv/ietf/ietf_attr_pa_tnc_error.c index 2fa0f4127..5d0f9a278 100644 --- a/src/libimcv/ietf/ietf_attr_pa_tnc_error.c +++ b/src/libimcv/ietf/ietf_attr_pa_tnc_error.c @@ -89,6 +89,11 @@ struct private_ietf_attr_pa_tnc_error_t { * PA-TNC message header */ chunk_t header; + + /** + * Reference count + */ + refcount_t ref; }; METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, @@ -141,11 +146,21 @@ METHOD(pa_tnc_attr_t, process, status_t, return SUCCESS; } +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ietf_attr_pa_tnc_error_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + METHOD(pa_tnc_attr_t, destroy, void, private_ietf_attr_pa_tnc_error_t *this) { - free(this->header.ptr); - free(this); + if (ref_put(&this->ref)) + { + free(this->header.ptr); + free(this); + } } METHOD(ietf_attr_pa_tnc_error_t, get_error_vendor_id, pen_t, @@ -181,6 +196,7 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, .set_noskip_flag = _set_noskip_flag, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_vendor_id = _get_error_vendor_id, @@ -191,6 +207,7 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_t vendor_id, .error_vendor_id = vendor_id, .error_code = error_code, .header = chunk_clone(header), + .ref = 1, ); return &this->public.pa_tnc_attribute; @@ -211,6 +228,7 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data) .get_value = _get_value, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_vendor_id = _get_error_vendor_id, @@ -219,6 +237,7 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data) .vendor_id = PEN_IETF, .type = IETF_ATTR_PA_TNC_ERROR, .value = chunk_clone(data), + .ref = 1, ); return &this->public.pa_tnc_attribute; diff --git a/src/libimcv/ita/ita_attr_command.c b/src/libimcv/ita/ita_attr_command.c index d8c18b55c..69eb7b055 100644 --- a/src/libimcv/ita/ita_attr_command.c +++ b/src/libimcv/ita/ita_attr_command.c @@ -54,6 +54,11 @@ struct private_ita_attr_command_t { * Command string */ char *command; + + /** + * Reference count + */ + refcount_t ref; }; METHOD(pa_tnc_attr_t, get_vendor_id, pen_t, @@ -103,12 +108,22 @@ METHOD(pa_tnc_attr_t, process, status_t, return SUCCESS; } +METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*, + private_ita_attr_command_t *this) +{ + ref_get(&this->ref); + return &this->public.pa_tnc_attribute; +} + METHOD(pa_tnc_attr_t, destroy, void, private_ita_attr_command_t *this) { - free(this->value.ptr); - free(this->command); - free(this); + if (ref_put(&this->ref)) + { + free(this->value.ptr); + free(this->command); + free(this); + } } METHOD(ita_attr_command_t, get_command, char*, @@ -134,6 +149,7 @@ pa_tnc_attr_t *ita_attr_command_create(char *command) .set_noskip_flag = _set_noskip_flag, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_command = _get_command, @@ -141,6 +157,7 @@ pa_tnc_attr_t *ita_attr_command_create(char *command) .vendor_id = PEN_ITA, .type = ITA_ATTR_COMMAND, .command = strdup(command), + .ref = 1, ); return &this->public.pa_tnc_attribute; @@ -161,6 +178,7 @@ pa_tnc_attr_t *ita_attr_command_create_from_data(chunk_t data) .get_value = _get_value, .build = _build, .process = _process, + .get_ref = _get_ref, .destroy = _destroy, }, .get_command = _get_command, @@ -168,6 +186,7 @@ pa_tnc_attr_t *ita_attr_command_create_from_data(chunk_t data) .vendor_id = PEN_ITA, .type = ITA_ATTR_COMMAND, .value = chunk_clone(data), + .ref = 1, ); return &this->public.pa_tnc_attribute; diff --git a/src/libimcv/pa_tnc/pa_tnc_attr.h b/src/libimcv/pa_tnc/pa_tnc_attr.h index c1ef6d52a..95a596ce0 100644 --- a/src/libimcv/pa_tnc/pa_tnc_attr.h +++ b/src/libimcv/pa_tnc/pa_tnc_attr.h @@ -80,6 +80,13 @@ struct pa_tnc_attr_t { status_t (*process)(pa_tnc_attr_t *this); /** + * Get a new reference to the PA-TNC attribute + * + * @return this, with an increased refcount + */ + pa_tnc_attr_t* (*get_ref)(pa_tnc_attr_t *this); + + /** * Destroys a pa_tnc_attr_t object. */ void (*destroy)(pa_tnc_attr_t *this); |