added TNC_TNCS_ReserveAdditionalIMVID() function
[strongswan.git] / src / libcharon / plugins / tnc_imv / tnc_imv.c
index 087780c..7d7b668 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2006 Mike McCauley
- * Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
+ * Copyright (C) 2010-2011 Andreas Steffen,
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -21,6 +22,7 @@
 
 #include <debug.h>
 #include <library.h>
+#include <utils/linked_list.h>
 #include <threading/mutex.h>
 
 typedef struct private_tnc_imv_t private_tnc_imv_t;
@@ -56,6 +58,11 @@ struct private_tnc_imv_t {
        TNC_IMVID id;
 
        /**
+        * List of additional IMV IDs
+        */
+       linked_list_t *additional_ids;
+
+       /**
         * List of message types supported by IMV - Vendor ID part
         */
        TNC_VendorIDList supported_vids;
@@ -88,6 +95,50 @@ METHOD(imv_t, get_id, TNC_IMVID,
        return this->id;
 }
 
+METHOD(imv_t, add_id, void,
+       private_tnc_imv_t *this, TNC_IMVID id)
+{
+       TNC_IMVID *new_id;
+
+       new_id = malloc_thing(TNC_IMVID);
+       *new_id = id;
+       this->additional_ids->insert_last(this->additional_ids, new_id);
+}
+
+METHOD(imv_t, has_id, bool,
+       private_tnc_imv_t *this, TNC_IMVID id)
+{
+       enumerator_t *enumerator;
+       TNC_IMVID *additional_id;
+       bool found = FALSE;
+
+       /* check primary IMV ID */
+       if (id == this->id)
+       {
+               return TRUE;
+       }
+
+       /* return if there are no additional IMV IDs */
+       if (this->additional_ids->get_count(this->additional_ids) == 0)
+       {
+               return FALSE;
+       }
+
+       /* check additional IMV IDs */
+       enumerator = this->additional_ids->create_enumerator(this->additional_ids);
+       while (enumerator->enumerate(enumerator, &additional_id))
+       {
+               if (id == *additional_id)
+               {
+                       found = TRUE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+
+       return found;
+}
+
 METHOD(imv_t, get_name, char*,
        private_tnc_imv_t *this)
 {
@@ -257,6 +308,7 @@ METHOD(imv_t, destroy, void,
 {
        dlclose(this->handle);
        this->mutex->destroy(this->mutex);
+       this->additional_ids->destroy_function(this->additional_ids, free);
        free(this->supported_vids);
        free(this->supported_subtypes);
        free(this->name);
@@ -275,6 +327,8 @@ imv_t* tnc_imv_create(char *name, char *path)
                .public = {
                        .set_id = _set_id,
                        .get_id = _get_id,
+                       .add_id = _add_id,
+                       .has_id = _has_id,
                        .get_name = _get_name,
                        .set_message_types = _set_message_types,
                        .set_message_types_long = _set_message_types_long,
@@ -283,6 +337,7 @@ imv_t* tnc_imv_create(char *name, char *path)
                },
                .name = name,
                .path = path,
+               .additional_ids = linked_list_create(),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );