]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Use a generic constructor to create PA-TNC error attributes
authorMartin Willi <martin@revosec.ch>
Mon, 28 Jan 2013 15:29:42 +0000 (16:29 +0100)
committerMartin Willi <martin@revosec.ch>
Thu, 14 Feb 2013 16:18:00 +0000 (17:18 +0100)
src/libimcv/ietf/ietf_attr_pa_tnc_error.c

index f92022fe0d7395efa5198eb551872d73406e7189..cc3ec28c5b8e3f5e923c356219c82a54fda31752 100644 (file)
@@ -325,22 +325,12 @@ METHOD(ietf_attr_pa_tnc_error_t, get_offset, u_int32_t,
 }
 
 /**
- * Described in header.
+ * Generic constructor
  */
-pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_type_t error_code,
-                                                                                        chunk_t msg_info)
+static private_ietf_attr_pa_tnc_error_t* create_generic()
 {
        private_ietf_attr_pa_tnc_error_t *this;
 
-       if (error_code.vendor_id == PEN_IETF)
-       {
-               msg_info.len = PA_ERROR_MSG_INFO_SIZE;
-       }
-       else if (msg_info.len > PA_ERROR_MSG_INFO_MAX_SIZE)
-       {
-               msg_info.len = PA_ERROR_MSG_INFO_MAX_SIZE;
-       }
-
        INIT(this,
                .public = {
                        .pa_tnc_attribute = {
@@ -360,11 +350,33 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_type_t error_code,
                        .get_offset = _get_offset,
                },
                .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR },
-               .error_code = error_code,
-               .msg_info = chunk_clone(msg_info),
                .ref = 1,
        );
 
+       return this;
+}
+
+/**
+ * Described in header.
+ */
+pa_tnc_attr_t *ietf_attr_pa_tnc_error_create(pen_type_t error_code,
+                                                                                        chunk_t msg_info)
+{
+       private_ietf_attr_pa_tnc_error_t *this;
+
+       if (error_code.vendor_id == PEN_IETF)
+       {
+               msg_info.len = PA_ERROR_MSG_INFO_SIZE;
+       }
+       else if (msg_info.len > PA_ERROR_MSG_INFO_MAX_SIZE)
+       {
+               msg_info.len = PA_ERROR_MSG_INFO_MAX_SIZE;
+       }
+
+       this = create_generic();
+       this->error_code = error_code;
+       this->msg_info = chunk_clone(msg_info);
+
        return &this->public.pa_tnc_attribute;
 }
 
@@ -380,30 +392,10 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_with_offset(pen_type_t error_code,
        /* the first 8 bytes of the erroneous PA-TNC message are sent back */
        msg_info.len = PA_ERROR_MSG_INFO_SIZE;
 
-       INIT(this,
-               .public = {
-                       .pa_tnc_attribute = {
-                               .get_type = _get_type,
-                               .get_value = _get_value,
-                               .get_noskip_flag = _get_noskip_flag,
-                               .set_noskip_flag = _set_noskip_flag,
-                               .build = _build,
-                               .process = _process,
-                               .get_ref = _get_ref,
-                               .destroy = _destroy,
-                       },
-                       .get_error_code = _get_error_code,
-                       .get_msg_info = _get_msg_info,
-                       .get_attr_info = _get_attr_info,
-                       .set_attr_info = _set_attr_info,
-                       .get_offset = _get_offset,
-               },
-               .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR },
-               .error_code = error_code,
-               .msg_info = chunk_clone(msg_info),
-               .error_offset = error_offset,
-               .ref = 1,
-       );
+       this = create_generic();
+       this->error_code = error_code;
+       this->msg_info = chunk_clone(msg_info);
+       this->error_offset = error_offset;
 
        return &this->public.pa_tnc_attribute;
 }
@@ -415,30 +407,8 @@ pa_tnc_attr_t *ietf_attr_pa_tnc_error_create_from_data(chunk_t data)
 {
        private_ietf_attr_pa_tnc_error_t *this;
 
-       INIT(this,
-               .public = {
-                       .pa_tnc_attribute = {
-                               .get_type = _get_type,
-                               .get_value = _get_value,
-                               .get_noskip_flag = _get_noskip_flag,
-                               .set_noskip_flag = _set_noskip_flag,
-                               .build = _build,
-                               .process = _process,
-                               .get_ref = _get_ref,
-                               .destroy = _destroy,
-                       },
-                       .get_error_code = _get_error_code,
-                       .get_msg_info = _get_msg_info,
-                       .get_attr_info = _get_attr_info,
-                       .set_attr_info = _set_attr_info,
-                       .get_offset = _get_offset,
-               },
-               .type = { PEN_IETF, IETF_ATTR_PA_TNC_ERROR },
-               .value = chunk_clone(data),
-               .ref = 1,
-       );
+       this = create_generic();
+       this->value = chunk_clone(data);
 
        return &this->public.pa_tnc_attribute;
 }
-
-