use OS type on IMV side
[strongswan.git] / src / libimcv / plugins / imv_os / imv_os_state.c
index 65160b4..49d2e56 100644 (file)
@@ -15,7 +15,7 @@
 
 #include "imv_os_state.h"
 
-#include <debug.h>
+#include <utils/debug.h>
 
 typedef struct private_imv_os_state_t private_imv_os_state_t;
 
@@ -65,9 +65,35 @@ struct private_imv_os_state_t {
        TNC_IMV_Evaluation_Result eval;
 
        /**
-        * OS Product Information
+        * OS Product Information (concatenation of OS Name and Version)
         */
        char *info;
+
+       /**
+        * OS Type
+        */
+       os_type_t type;
+
+       /**
+        * OS Name
+        */
+       chunk_t name;
+
+       /**
+        * OS Version
+        */
+       chunk_t version;
+
+       /**
+        * OS Installed Package request sent - mandatory response expected
+        */
+       bool package_request;
+
+       /**
+        * Angel count
+        */
+       int angel_count;
+
 };
 
 typedef struct entry_t entry_t;
@@ -81,7 +107,7 @@ struct entry_t {
 };
 
 /**
- * Table of multi-lingual reason string entries 
+ * Table of multi-lingual reason string entries
  */
 static entry_t reasons[] = {
        { "en", "" },
@@ -160,26 +186,75 @@ METHOD(imv_state_t, destroy, void,
        private_imv_os_state_t *this)
 {
        free(this->info);
+       free(this->name.ptr);
+       free(this->version.ptr);
        free(this);
 }
 
 METHOD(imv_os_state_t, set_info, void,
-       private_imv_os_state_t *this, char *name, chunk_t version)
+       private_imv_os_state_t *this, os_type_t type, chunk_t name, chunk_t version)
 {
-       int len = strlen(name) + 1 + version.len + 1;
+       int len = name.len + 1 + version.len + 1;
 
        /* OS info is a concatenation of OS name and OS version */
        free(this->info);
        this->info = malloc(len);
-       snprintf(this->info, len, "%s %.*s", name, version.len, version.ptr);
+       snprintf(this->info, len, "%.*s %.*s", name.len, name.ptr,
+                                                                                  version.len, version.ptr);
+       this->type = type;
+       this->name = chunk_clone(name);
+       this->version = chunk_clone(version);
 }
 
 METHOD(imv_os_state_t, get_info, char*,
-       private_imv_os_state_t *this)
+       private_imv_os_state_t *this, os_type_t *type, chunk_t *name,
+       chunk_t *version)
 {
+       if (type)
+       {
+               *type = this->type;
+       }
+       if (name)
+       {
+               *name = this->name;
+       }
+       if (version)
+       {
+               *version = this->version;
+       }
        return this->info;
 }
 
+METHOD(imv_os_state_t, get_type, os_type_t,
+       private_imv_os_state_t *this)
+{
+       return this->type;
+}
+
+METHOD(imv_os_state_t, set_package_request, void,
+       private_imv_os_state_t *this, bool set)
+{
+       this->package_request = set;
+}
+
+METHOD(imv_os_state_t, get_package_request, bool,
+       private_imv_os_state_t *this)
+{
+       return this->package_request;
+}
+
+METHOD(imv_os_state_t, set_angel_count, void,
+       private_imv_os_state_t *this, bool start)
+{
+       this->angel_count += start ? 1 : -1;
+}
+
+METHOD(imv_os_state_t, get_angel_count, int,
+       private_imv_os_state_t *this)
+{
+       return this->angel_count;
+}
+
 /**
  * Described in header.
  */
@@ -204,13 +279,17 @@ imv_state_t *imv_os_state_create(TNC_ConnectionID connection_id)
                        },
                        .set_info = _set_info,
                        .get_info = _get_info,
+                       .set_package_request = _set_package_request,
+                       .get_package_request = _get_package_request,
+                       .set_angel_count = _set_angel_count,
+                       .get_angel_count = _get_angel_count,
                },
                .state = TNC_CONNECTION_STATE_CREATE,
                .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
                .connection_id = connection_id,
        );
-       
+
        return &this->public.interface;
 }