libimcv: Add generic constructor for PA-TNC attributes
authorTobias Brunner <tobias@strongswan.org>
Mon, 13 Oct 2014 16:17:30 +0000 (18:17 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 15 Oct 2014 11:55:13 +0000 (13:55 +0200)
src/libimcv/pa_tnc/pa_tnc_attr_manager.c
src/libimcv/pa_tnc/pa_tnc_attr_manager.h

index 2d914f4..522213b 100644 (file)
@@ -236,6 +236,45 @@ METHOD(pa_tnc_attr_manager_t, create, pa_tnc_attr_t*,
        return attr;
 }
 
+METHOD(pa_tnc_attr_manager_t, construct, pa_tnc_attr_t*,
+       private_pa_tnc_attr_manager_t *this, pen_t vendor_id, uint32_t type,
+       chunk_t value)
+{
+       enum_name_t *pa_attr_names;
+       pa_tnc_attr_t *attr = NULL;
+       enumerator_t *enumerator;
+       entry_t *entry;
+
+       pa_attr_names = imcv_pa_tnc_attributes->get_names(imcv_pa_tnc_attributes,
+                                                                                                         vendor_id);
+       if (pa_attr_names)
+       {
+               DBG2(DBG_TNC, "generating PA-TNC attribute type '%N/%N' "
+                                         "0x%06x/0x%08x", pen_names, vendor_id,
+                                          pa_attr_names, type, vendor_id, type);
+       }
+       else
+       {
+               DBG2(DBG_TNC, "generating PA-TNC attribute type '%N' "
+                                         "0x%06x/0x%08x", pen_names, vendor_id,
+                                          vendor_id, type);
+       }
+       enumerator = this->list->create_enumerator(this->list);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->vendor_id == vendor_id)
+               {
+                       if (entry->attr_create)
+                       {
+                               attr = entry->attr_create(type, value.len, value);
+                       }
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return attr;
+}
+
 METHOD(pa_tnc_attr_manager_t, destroy, void,
        private_pa_tnc_attr_manager_t *this)
 {
@@ -256,6 +295,7 @@ pa_tnc_attr_manager_t *pa_tnc_attr_manager_create(void)
                        .remove_vendor = _remove_vendor,
                        .get_names = _get_names,
                        .create = _create,
+                       .construct = _construct,
                        .destroy = _destroy,
                },
                .list = linked_list_create(),
index 048ad19..8607fee 100644 (file)
@@ -77,6 +77,17 @@ struct pa_tnc_attr_manager_t {
                                                         pa_tnc_attr_t **error);
 
        /**
+        * Generically construct a PA-TNC attribute from type and data
+        *
+        * @param vendor_id             Private Enterprise Number (PEN)
+        * @param type                  PA-TNC attribute type
+        * @param value                 PA-TNC attribute value as encoded data
+        * @return                              PA-TNC attribute object if supported, NULL else
+        */
+       pa_tnc_attr_t* (*construct)(pa_tnc_attr_manager_t *this, pen_t vendor_id,
+                                                               uint32_t type, chunk_t value);
+
+       /**
         * Destroys a pa_tnc_attr_manager_t object.
         */
        void (*destroy)(pa_tnc_attr_manager_t *this);