implement set_attribute() callback function
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 16 Nov 2010 20:07:02 +0000 (21:07 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 16 Nov 2010 20:07:02 +0000 (21:07 +0100)
src/libcharon/plugins/tnc_imv/tnc_imv_recommendations.c
src/libcharon/tnc/imv/imv_recommendations.h
src/libcharon/tnc/tnccs/tnccs_manager.c

index 0219830..fb76d00 100644 (file)
@@ -39,12 +39,22 @@ struct recommendation_entry_t {
        /**
         * Action Recommendation provided by IMV instance
         */
-  TNC_IMV_Action_Recommendation rec;
+       TNC_IMV_Action_Recommendation rec;
 
        /**
         * Evaluation Result provided by IMV instance
         */
-  TNC_IMV_Evaluation_Result eval;
+       TNC_IMV_Evaluation_Result eval;
+
+       /**
+        * Reason string provided by IMV instance
+        */
+       chunk_t reason;
+
+       /**
+        * Reason language provided by IMV instance
+        */
+       chunk_t reason_language;        
 };
 
 /**
@@ -269,10 +279,62 @@ METHOD(recommendations_t, set_preferred_language, void,
        this->preferred_language = chunk_clone(pref_lang);
 }
 
+METHOD(recommendations_t, set_reason_string, TNC_Result,
+       private_tnc_imv_recommendations_t *this, TNC_IMVID id, chunk_t reason)
+{
+       enumerator_t *enumerator;
+       recommendation_entry_t *entry;
+       bool found = FALSE;
+
+       enumerator = this->recs->create_enumerator(this->recs);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->id == id)
+               {
+                       found = TRUE;
+                       free(entry->reason.ptr);
+                       entry->reason = chunk_clone(reason);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return found ? TNC_RESULT_SUCCESS : TNC_RESULT_INVALID_PARAMETER;
+}
+
+METHOD(recommendations_t, set_reason_language, TNC_Result,
+       private_tnc_imv_recommendations_t *this, TNC_IMVID id, chunk_t reason_lang)
+{
+       enumerator_t *enumerator;
+       recommendation_entry_t *entry;
+       bool found = FALSE;
+
+       enumerator = this->recs->create_enumerator(this->recs);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (entry->id == id)
+               {
+                       found = TRUE;
+                       free(entry->reason_language.ptr);
+                       entry->reason_language = chunk_clone(reason_lang);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return found ? TNC_RESULT_SUCCESS : TNC_RESULT_INVALID_PARAMETER;
+}
+
 METHOD(recommendations_t, destroy, void,
        private_tnc_imv_recommendations_t *this)
 {
-       this->recs->destroy_function(this->recs, free);
+       recommendation_entry_t *entry;
+
+       while (this->recs->remove_last(this->recs, (void**)&entry))
+       {
+               free(entry->reason.ptr);
+               free(entry->reason_language.ptr);
+               free(entry);
+       }
+       this->recs->destroy(this->recs);
        free(this->preferred_language.ptr);
        free(this);
 }
@@ -293,6 +355,9 @@ recommendations_t* tnc_imv_recommendations_create(linked_list_t *imv_list)
                        .have_recommendation = _have_recommendation,
                        .get_preferred_language = _get_preferred_language,
                        .set_preferred_language = _set_preferred_language,
+                       .set_reason_string = _set_reason_string,
+                       .set_reason_language = _set_reason_language,
+
                        .destroy = _destroy,
         },
                .recs = linked_list_create(),
index f96f53e..434f00b 100644 (file)
@@ -82,6 +82,26 @@ struct recommendations_t {
        void (*set_preferred_language)(recommendations_t *this, chunk_t pref_lang);
 
        /**
+        * Set the reason string
+        *
+        * @param id                    ID of IMV setting the reason string
+        * @param reason                reason string
+        * @result                              return code
+        */
+       TNC_Result (*set_reason_string)(recommendations_t *this, TNC_IMVID id,
+                                                                       chunk_t reason);
+
+       /**
+        * Set the language for reason strings
+        *
+        * @param id                    ID of IMV setting the reason language
+        * @param reason_lang   reason language
+        * @result                              return code
+        */
+       TNC_Result (*set_reason_language)(recommendations_t *this, TNC_IMVID id,
+                                                                         chunk_t reason_lang);
+
+       /**
         * Destroys an imv_t object.
         */
        void (*destroy)(recommendations_t *this);
index d99ed85..c1ba452 100644 (file)
@@ -352,6 +352,42 @@ METHOD(tnccs_manager_t, set_attribute, TNC_Result,
                                                                   TNC_UInt32 buffer_len,
                                                                   TNC_BufferReference buffer)
 {
+       enumerator_t *enumerator;
+       tnccs_connection_entry_t *entry;
+       recommendations_t *recs = NULL;
+
+       if (attribute_id != TNC_ATTRIBUTEID_REASON_STRING &&
+               attribute_id != TNC_ATTRIBUTEID_REASON_LANGUAGE)
+       {
+               return TNC_RESULT_INVALID_PARAMETER;
+       }
+
+       this->connection_lock->read_lock(this->connection_lock);
+       enumerator = this->connections->create_enumerator(this->connections);
+       while (enumerator->enumerate(enumerator, &entry))
+       {
+               if (id == entry->id)
+               {
+                       recs = entry->recs;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       this->connection_lock->unlock(this->connection_lock);
+
+       if (recs)
+       {
+               chunk_t attribute = { buffer, buffer_len };
+
+               if (attribute_id == TNC_ATTRIBUTEID_REASON_STRING)
+               {
+                       return recs->set_reason_string(recs, imv_id, attribute);
+               }
+               else
+               {
+                       return recs->set_reason_language(recs, imv_id, attribute);
+               }
+       }
        return TNC_RESULT_INVALID_PARAMETER;
 }