imc/imv->send_message() uses attr_list
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 11 Jul 2012 21:34:51 +0000 (23:34 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 11 Jul 2012 21:34:51 +0000 (23:34 +0200)
src/libimcv/imc/imc_agent.c
src/libimcv/imc/imc_agent.h
src/libimcv/imv/imv_agent.c
src/libimcv/imv/imv_agent.h
src/libimcv/plugins/imc_scanner/imc_scanner.c
src/libimcv/plugins/imc_test/imc_test.c
src/libimcv/plugins/imv_test/imv_test.c
src/libpts/plugins/imc_attestation/imc_attestation.c
src/libpts/plugins/imv_attestation/imv_attestation.c

index de2f959..4f9bb03 100644 (file)
@@ -18,7 +18,6 @@
 #include <tncif_names.h>
 
 #include <debug.h>
-#include <utils/linked_list.h>
 #include <threading/rwlock.h>
 
 typedef struct private_imc_agent_t private_imc_agent_t;
@@ -453,11 +452,14 @@ METHOD(imc_agent_t, get_state, bool,
 
 METHOD(imc_agent_t, send_message, TNC_Result,
        private_imc_agent_t *this, TNC_ConnectionID connection_id, bool excl,
-       TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id, chunk_t msg)
+       TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id, linked_list_t *attr_list)
 {
        TNC_MessageType type;
        TNC_UInt32 msg_flags;
        imc_state_t *state;
+       pa_tnc_attr_t *attr;
+       pa_tnc_msg_t *pa_tnc_msg;
+       chunk_t msg;
 
        state = find_connection(this, connection_id);
        if (!state)
@@ -467,6 +469,15 @@ METHOD(imc_agent_t, send_message, TNC_Result,
                return TNC_RESULT_FATAL;
        }
 
+       pa_tnc_msg = pa_tnc_msg_create();
+
+       while (attr_list->remove_first(attr_list, (void**)&attr) == SUCCESS)
+       {
+               pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
+       }
+       pa_tnc_msg->build(pa_tnc_msg);
+       msg = pa_tnc_msg->get_encoding(pa_tnc_msg);
+
        if (state->has_long(state) && this->send_message_long)
        {
                if (!src_imc_id)
index d1fef4d..33335d1 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <tncifimc.h>
 #include <pen/pen.h>
+#include <utils/linked_list.h>
 
 #include <library.h>
 
@@ -104,13 +105,13 @@ struct imc_agent_t {
         * @param excl                          exclusive flag
         * @param src_imc_id            IMC ID to be set as source
         * @param dst_imv_id            IMV ID to be set as destination
-        * @param msg                           message to send
+        * @param attr_list                     list of PA-TNC attributes to send
         * @return                                      TNC result code
         */
        TNC_Result (*send_message)(imc_agent_t *this,
                                                           TNC_ConnectionID connection_id, bool excl,
                                                           TNC_UInt32 src_imc_id, TNC_UInt32 dst_imv_id,
-                                                          chunk_t msg);
+                                                          linked_list_t *attr_list);
 
        /**
         * Call when a PA-TNC message was received
index 56131c5..888f01c 100644 (file)
@@ -18,7 +18,6 @@
 #include <tncif_names.h>
 
 #include <debug.h>
-#include <utils/linked_list.h>
 #include <threading/rwlock.h>
 
 typedef struct private_imv_agent_t private_imv_agent_t;
@@ -470,11 +469,14 @@ METHOD(imv_agent_t, get_state, bool,
 
 METHOD(imv_agent_t, send_message, TNC_Result,
        private_imv_agent_t *this, TNC_ConnectionID connection_id, bool excl,
-       TNC_UInt32 src_imv_id, TNC_UInt32 dst_imc_id, chunk_t msg)
+       TNC_UInt32 src_imv_id, TNC_UInt32 dst_imc_id, linked_list_t *attr_list)
 {
        TNC_MessageType type;
        TNC_UInt32 msg_flags;
        imv_state_t *state;
+       pa_tnc_attr_t *attr;
+       pa_tnc_msg_t *pa_tnc_msg;
+       chunk_t msg;
 
        state = find_connection(this, connection_id);
        if (!state)
@@ -484,6 +486,15 @@ METHOD(imv_agent_t, send_message, TNC_Result,
                return TNC_RESULT_FATAL;
        }
 
+       pa_tnc_msg = pa_tnc_msg_create();
+
+       while (attr_list->remove_first(attr_list, (void**)&attr) == SUCCESS)
+       {
+               pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
+       }
+       pa_tnc_msg->build(pa_tnc_msg);
+       msg = pa_tnc_msg->get_encoding(pa_tnc_msg);
+
        if (state->has_long(state) && this->send_message_long)
        {
                if (!src_imv_id)
index de70f3b..4178ae6 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <tncifimv.h>
 #include <pen/pen.h>
+#include <utils/linked_list.h>
 
 #include <library.h>
 
@@ -104,13 +105,13 @@ struct imv_agent_t {
         * @param excl                          exclusive flag
         * @param src_imv_id            IMV ID to be set as source
         * @param dst_imc_id            IMD ID to be set as destination
-        * @param msg                           message to send
+        * @param attr_list                     list of PA-TNC attributes to send
         * @return                                      TNC result code
         */
        TNC_Result (*send_message)(imv_agent_t *this,
                                                           TNC_ConnectionID connection_id, bool excl,
                                                           TNC_UInt32 src_imv_id, TNC_UInt32 dst_imc_id,
-                                                          chunk_t msg);
+                                                          linked_list_t *attr_list);
 
        /**
         * Call when a PA-TNC message was received
index b24c39c..7085e6c 100644 (file)
@@ -221,7 +221,7 @@ end:
 
 static TNC_Result send_message(TNC_ConnectionID connection_id)
 {
-       pa_tnc_msg_t *msg;
+       linked_list_t *attr_list;
        pa_tnc_attr_t *attr;
        ietf_attr_port_filter_t *attr_port_filter;
        TNC_Result result;
@@ -234,12 +234,11 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
                attr->destroy(attr);
                return TNC_RESULT_FATAL;
        }
-       msg = pa_tnc_msg_create();
-       msg->add_attribute(msg, attr);
-       msg->build(msg);
+       attr_list = linked_list_create();
+       attr_list->insert_last(attr_list, attr);
        result = imc_scanner->send_message(imc_scanner, connection_id, FALSE, 0,
-                                                                          TNC_IMVID_ANY, msg->get_encoding(msg));      
-       msg->destroy(msg);
+                                                                          TNC_IMVID_ANY, attr_list);
+       attr_list->destroy(attr_list);
 
        return result;
 }
index d71e7d7..93ef6b2 100644 (file)
@@ -162,30 +162,30 @@ static TNC_Result send_message(imc_state_t *state, TNC_UInt32 src_imc_id,
                                                                                                   TNC_UInt32 dst_imv_id)
 {
        imc_test_state_t *test_state;
-       pa_tnc_msg_t *msg;
+       linked_list_t *attr_list;
        pa_tnc_attr_t *attr;
        bool excl;
        TNC_ConnectionID connection_id;
        TNC_Result result;
 
+       attr_list = linked_list_create();
        connection_id = state->get_connection_id(state);
        test_state = (imc_test_state_t*)state;
 
-       msg = pa_tnc_msg_create();
        if (test_state->get_dummy_size(test_state))
        {
                attr = ita_attr_dummy_create(test_state->get_dummy_size(test_state));
                attr->set_noskip_flag(attr, TRUE);
-               msg->add_attribute(msg, attr);
+               attr_list->insert_last(attr_list, attr);
        }
        attr = ita_attr_command_create(test_state->get_command(test_state));
        attr->set_noskip_flag(attr, TRUE);
-       msg->add_attribute(msg, attr);
-       msg->build(msg);
+       attr_list->insert_last(attr_list, attr);
+
        excl = dst_imv_id != TNC_IMVID_ANY;
        result = imc_test->send_message(imc_test, connection_id, excl, src_imc_id,
-                                                                       dst_imv_id, msg->get_encoding(msg));    
-       msg->destroy(msg);
+                                                                       dst_imv_id, attr_list);
+       attr_list->destroy(attr_list);
 
        return result;
 }
index 4da499b..c2295e1 100644 (file)
@@ -102,6 +102,7 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
 {
        pa_tnc_msg_t *pa_tnc_msg;
        pa_tnc_attr_t *attr;
+       linked_list_t *attr_list;
        imv_state_t *state;
        imv_test_state_t *test_state;
        enumerator_t *enumerator;
@@ -217,13 +218,12 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
        /* repeat the measurement ? */
        if (test_state->another_round(test_state, src_imc_id))
        {
+               attr_list = linked_list_create();
                attr = ita_attr_command_create("repeat");
-               pa_tnc_msg = pa_tnc_msg_create();
-               pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
-               pa_tnc_msg->build(pa_tnc_msg);
+               attr_list->insert_last(attr_list, attr);
                result = imv_test->send_message(imv_test, connection_id, TRUE, imv_id,
-                                                       src_imc_id, pa_tnc_msg->get_encoding(pa_tnc_msg));      
-               pa_tnc_msg->destroy(pa_tnc_msg);
+                                                       src_imc_id, attr_list); 
+               attr_list->destroy(attr_list);
 
                return result;
        }
index 4f77ba0..9759737 100644 (file)
@@ -149,17 +149,15 @@ TNC_Result TNC_IMC_BeginHandshake(TNC_IMCID imc_id,
        platform_info = pts->get_platform_info(pts);
        if (platform_info)
        {
-               pa_tnc_msg_t *pa_tnc_msg;
+               linked_list_t *attr_list;
                pa_tnc_attr_t *attr;
 
-               pa_tnc_msg = pa_tnc_msg_create();
+               attr_list = linked_list_create();
                attr = ietf_attr_product_info_create(0, 0, platform_info);
-               pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
-               pa_tnc_msg->build(pa_tnc_msg);
+               attr_list->insert_last(attr_list, attr);
                result = imc_attestation->send_message(imc_attestation, connection_id,
-                                                                               FALSE, 0, TNC_IMVID_ANY,
-                                                                               pa_tnc_msg->get_encoding(pa_tnc_msg));
-               pa_tnc_msg->destroy(pa_tnc_msg);
+                                                                               FALSE, 0, TNC_IMVID_ANY, attr_list);
+               attr_list->destroy(attr_list);
        }
 
        return result;
@@ -253,23 +251,11 @@ static TNC_Result receive_message(TNC_IMCID imc_id,
 
        if (result == TNC_RESULT_SUCCESS && attr_list->get_count(attr_list))
        {
-               pa_tnc_msg = pa_tnc_msg_create();
-
-               enumerator = attr_list->create_enumerator(attr_list);
-               while (enumerator->enumerate(enumerator, &attr))
-               {
-                       pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
-               }
-               enumerator->destroy(enumerator);
-
-               pa_tnc_msg->build(pa_tnc_msg);
                result = imc_attestation->send_message(imc_attestation, connection_id,
-                                                                               FALSE, 0, TNC_IMVID_ANY,
-                                                                               pa_tnc_msg->get_encoding(pa_tnc_msg));
-               pa_tnc_msg->destroy(pa_tnc_msg);
+                                                                               FALSE, 0, TNC_IMVID_ANY, attr_list);
        }
-
        attr_list->destroy(attr_list);
+
        return result;
 }
 
index 6aaf6a6..d1136c1 100644 (file)
@@ -168,13 +168,10 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id,
 
 static TNC_Result send_message(TNC_ConnectionID connection_id)
 {
-       pa_tnc_msg_t *msg;
-       pa_tnc_attr_t *attr;
+       linked_list_t *attr_list;
        imv_state_t *state;
        imv_attestation_state_t *attestation_state;
        TNC_Result result;
-       linked_list_t *attr_list;
-       enumerator_t *enumerator;
 
        if (!imv_attestation->get_state(imv_attestation, connection_id, &state))
        {
@@ -188,21 +185,8 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
        {
                if (attr_list->get_count(attr_list))
                {
-                       msg = pa_tnc_msg_create();
-
-                       /* move PA-TNC attributes to PA-TNC message */
-                       enumerator = attr_list->create_enumerator(attr_list);
-                       while (enumerator->enumerate(enumerator, &attr))
-                       {
-                               msg->add_attribute(msg, attr);
-                       }
-                       enumerator->destroy(enumerator);
-
-                       msg->build(msg);
                        result = imv_attestation->send_message(imv_attestation,
-                                                       connection_id, FALSE, 0, TNC_IMCID_ANY,
-                                                       msg->get_encoding(msg));
-                       msg->destroy(msg);
+                                                       connection_id, FALSE, 0, TNC_IMCID_ANY, attr_list);
                }
                else
                {
@@ -330,24 +314,9 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
 
        if (attr_list->get_count(attr_list))
        {
-               pa_tnc_msg = pa_tnc_msg_create();
-
-               /* move PA-TNC attributes to PA-TNC message */
-               enumerator = attr_list->create_enumerator(attr_list);
-               while (enumerator->enumerate(enumerator, &attr))
-               {
-                       pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
-               }
-               enumerator->destroy(enumerator);
-
-               pa_tnc_msg->build(pa_tnc_msg);
                result = imv_attestation->send_message(imv_attestation, connection_id,
-                                                                               FALSE, 0, TNC_IMCID_ANY,
-                                                                               pa_tnc_msg->get_encoding(pa_tnc_msg));
-               
-               pa_tnc_msg->destroy(pa_tnc_msg);
+                                                                               FALSE, 0, TNC_IMCID_ANY, attr_list);
                attr_list->destroy(attr_list);
-               
                return result;
        }
        attr_list->destroy(attr_list);