implemented provide_recommendation callback function

This commit is contained in:
Andreas Steffen
2010-11-09 20:43:51 +01:00
parent 1dc7b22c53
commit 213245cca9
5 changed files with 95 additions and 13 deletions
+18 -3
View File
@@ -22,6 +22,7 @@
#define TNCCS_H_
#include <tnc/tncif.h>
#include <tnc/tncifimv.h>
#include <library.h>
typedef enum tnccs_type_t tnccs_type_t;
@@ -53,13 +54,27 @@ typedef tnccs_t* (*tnccs_constructor_t)(bool is_server);
/**
* Callback function adding a message to a TNCCS batch
*
* @param message message to be added
* @param message_len message length
* @param message_type message type
* @param message message to be added
* @param message_len message length
* @param message_type message type
*/
typedef void (*tnccs_send_message_t)(tnccs_t* tncss,
TNC_BufferReference message,
TNC_UInt32 message_len,
TNC_MessageType message_type);
/**
* Callback function delivering an IMV Action Recommendation and
* IMV Evaluation Result to the TNCS
*
* @param imv_id ID of the IMV providing the recommendation
* @param recommendation action recommendation
* @param evaluation evaluation result
*/
typedef void (*tnccs_provide_recommendation_t)(tnccs_t* tncss,
TNC_IMVID imv_id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation);
#endif /** TNCCS_H_ @}*/
+41 -2
View File
@@ -58,6 +58,11 @@ struct tnccs_connection_entry_t {
*
*/
tnccs_send_message_t send_message;
/** TNCS provide recommendation function
*
*/
tnccs_provide_recommendation_t provide_recommendation;
};
/**
@@ -198,7 +203,7 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
{
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
tnccs_send_message_t send_message;
tnccs_send_message_t send_message = NULL;
tnccs_t *tnccs = NULL;
this->lock->write_lock(this->lock);
@@ -215,7 +220,7 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
if (tnccs)
if (tnccs && send_message)
{
send_message(tnccs, message, message_len, message_type);
return TNC_RESULT_SUCCESS;
@@ -223,6 +228,39 @@ METHOD(tnccs_manager_t, send_message, TNC_Result,
return TNC_RESULT_FATAL;
}
METHOD(tnccs_manager_t, provide_recommendation, TNC_Result,
private_tnccs_manager_t *this, TNC_IMVID imv_id,
TNC_ConnectionID id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation)
{
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
tnccs_provide_recommendation_t provide_recommendation = NULL;
tnccs_t *tnccs = NULL;
this->lock->write_lock(this->lock);
enumerator = this->connections->create_enumerator(this->connections);
while (enumerator->enumerate(enumerator, &entry))
{
if (id == entry->id)
{
tnccs = entry->tnccs;
provide_recommendation = entry->provide_recommendation;
break;
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
if (tnccs && provide_recommendation)
{
provide_recommendation(tnccs, imv_id, recommendation, evaluation);
return TNC_RESULT_SUCCESS;
}
return TNC_RESULT_FATAL;
}
METHOD(tnccs_manager_t, destroy, void,
private_tnccs_manager_t *this)
{
@@ -247,6 +285,7 @@ tnccs_manager_t *tnccs_manager_create()
.create_connection = _create_connection,
.remove_connection = _remove_connection,
.send_message = _send_message,
.provide_recommendation = _provide_recommendation,
.destroy = _destroy,
},
.protocols = linked_list_create(),
+23 -5
View File
@@ -61,14 +61,18 @@ struct tnccs_manager_t {
bool is_server);
/**
* Create a TNCCS connection and assign a unique connection ID
* Create a TNCCS connection and assign a unique connection ID as well as
* callback functions for adding a message to a TNCCS batch and delivering
* an IMV recommendation, respectively
*
* @param tnccs TNCCS connection instance
* @param send_message callback function adding a message to a TNCCS batch
* @return assigned connection ID
* @param tnccs TNCCS connection instance
* @param send_message TNCCS callback function
* @param provide_recommendation TNCS callback function
* @return assigned connection ID
*/
TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs,
tnccs_send_message_t send_message);
tnccs_send_message_t send_message,
tnccs_provide_recommendation_t provide_recommendation);
/**
* Remove a TNCCS connection using its connection ID.
@@ -92,6 +96,20 @@ struct tnccs_manager_t {
TNC_UInt32 message_len,
TNC_MessageType message_type);
/**
* Deliver an IMV Action Recommendation and IMV Evaluation Result to the TNCS
*
* @param imv_id ID of the IMV providing the recommendation
* @param connection_id target connection ID
* @param recommendation action recommendation
* @param evaluation evaluation result
*/
TNC_Result (*provide_recommendation)(tnccs_manager_t *this,
TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation);
/**
* Destroy a tnccs_manager instance.
*/