implement GetAttribute() callback function

This commit is contained in:
Andreas Steffen
2010-11-16 20:14:48 +01:00
parent 4d178affbb
commit 92477a0625
5 changed files with 205 additions and 25 deletions
@@ -67,6 +67,35 @@ TNC_Result TNC_TNCS_ProvideRecommendation(TNC_IMVID imv_id,
connection_id, recommendation, evaluation);
}
/**
* Called by the IMV to get the value of an attribute associated with a
* connection or with the TNCS as a whole.
*/
TNC_Result TNC_TNCS_GetAttribute(TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer,
TNC_UInt32 *out_value_len)
{
return charon->tnccs->get_attribute(charon->tnccs, imv_id, connection_id,
attribute_id, buffer_len, buffer, out_value_len);
}
/**
* Called by the IMV to set the value of an attribute associated with a
* connection or with the TNCS as a whole.
*/
TNC_Result TNC_TNCS_SetAttribute(TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer)
{
return charon->tnccs->set_attribute(charon->tnccs, imv_id, connection_id,
attribute_id, buffer_len, buffer);
}
/**
* Called by the IMV when it needs a function pointer
*/
@@ -90,6 +119,14 @@ TNC_Result TNC_TNCS_BindFunction(TNC_IMVID id,
{
*function_pointer = (void*)TNC_TNCS_ProvideRecommendation;
}
else if (streq(function_name, "TNC_TNCS_GetAttribute"))
{
*function_pointer = (void*)TNC_TNCS_GetAttribute;
}
else if (streq(function_name, "TNC_TNCS_SetAttribute"))
{
*function_pointer = (void*)TNC_TNCS_SetAttribute;
}
else
{
return TNC_RESULT_INVALID_PARAMETER;
@@ -61,6 +61,11 @@ struct private_tnc_imv_recommendations_t {
* list of recommendations and evaluations provided by IMVs
*/
linked_list_t *recs;
/**
* Preferred language for remediation messages
*/
chunk_t preferred_language;
};
METHOD(recommendations_t, provide_recommendation, TNC_Result,
@@ -251,11 +256,24 @@ METHOD(recommendations_t, have_recommendation, bool,
return TRUE;
}
METHOD(recommendations_t, get_preferred_language, chunk_t,
private_tnc_imv_recommendations_t *this)
{
return this->preferred_language;
}
METHOD(recommendations_t, set_preferred_language, void,
private_tnc_imv_recommendations_t *this, chunk_t pref_lang)
{
chunk_free(&this->preferred_language);
this->preferred_language = chunk_clone(pref_lang);
}
METHOD(recommendations_t, destroy, void,
private_tnc_imv_recommendations_t *this)
{
this->recs->destroy_function(this->recs, free);
free(this->preferred_language.ptr);
free(this);
}
@@ -273,6 +291,8 @@ recommendations_t* tnc_imv_recommendations_create(linked_list_t *imv_list)
.public = {
.provide_recommendation = _provide_recommendation,
.have_recommendation = _have_recommendation,
.get_preferred_language = _get_preferred_language,
.set_preferred_language = _set_preferred_language,
.destroy = _destroy,
},
.recs = linked_list_create(),
+26 -3
View File
@@ -45,19 +45,42 @@ struct recommendations_t {
/**
* Deliver 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
* @param imv_id ID of the IMV providing the recommendation
* @param rec action recommendation
* @param eval evaluation result
* @return return code
*/
TNC_Result (*provide_recommendation)(recommendations_t *this,
TNC_IMVID imv_id,
TNC_IMV_Action_Recommendation rec,
TNC_IMV_Evaluation_Result eval);
/**
* If all IMVs provided a recommendation, derive a consolidated action
* recommendation and evaluation result based on a configured policy
*
* @param rec action recommendation
* @param eval evaluation result
* @return TRUE if all IMVs provided a recommendation
*/
bool (*have_recommendation)(recommendations_t *this,
TNC_IMV_Action_Recommendation *rec,
TNC_IMV_Evaluation_Result *eval);
/**
* Get the preferred language for remediation messages
*
* @return preferred language
*/
chunk_t (*get_preferred_language)(recommendations_t *this);
/**
* Set the preferred language for remediation messages
*
* @param pref_lang preferred language
*/
void (*set_preferred_language)(recommendations_t *this, chunk_t pref_lang);
/**
* Destroys an imv_t object.
*/
+65 -4
View File
@@ -57,13 +57,13 @@ struct tnccs_connection_entry_t {
*/
tnccs_t *tnccs;
/** TNCCS send message function
*
/**
* TNCCS send message function
*/
tnccs_send_message_t send_message;
/** collection of IMV recommendations
*
/**
* collection of IMV recommendations
*/
recommendations_t *recs;
};
@@ -296,6 +296,65 @@ METHOD(tnccs_manager_t, provide_recommendation, TNC_Result,
return TNC_RESULT_FATAL;
}
METHOD(tnccs_manager_t, get_attribute, TNC_Result,
private_tnccs_manager_t *this, TNC_IMVID imv_id,
TNC_ConnectionID id,
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer,
TNC_UInt32 *out_value_len)
{
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
recommendations_t *recs = NULL;
if (attribute_id != TNC_ATTRIBUTEID_PREFERRED_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 pref_lang;
pref_lang = recs->get_preferred_language(recs);
if (pref_lang.len == 0)
{
return TNC_RESULT_INVALID_PARAMETER;
}
*out_value_len = pref_lang.len;
if (buffer && buffer_len <= pref_lang.len)
{
memcpy(buffer, pref_lang.ptr, pref_lang.len);
}
return TNC_RESULT_SUCCESS;
}
return TNC_RESULT_INVALID_PARAMETER;
}
METHOD(tnccs_manager_t, set_attribute, TNC_Result,
private_tnccs_manager_t *this, TNC_IMVID imv_id,
TNC_ConnectionID id,
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer)
{
return TNC_RESULT_INVALID_PARAMETER;
}
METHOD(tnccs_manager_t, destroy, void,
private_tnccs_manager_t *this)
{
@@ -322,6 +381,8 @@ tnccs_manager_t *tnccs_manager_create()
.remove_connection = _remove_connection,
.send_message = _send_message,
.provide_recommendation = _provide_recommendation,
.get_attribute = _get_attribute,
.set_attribute = _set_attribute,
.destroy = _destroy,
},
.protocols = linked_list_create(),
+57 -18
View File
@@ -67,10 +67,10 @@ struct tnccs_manager_t {
* callback function for adding a message to a TNCCS batch and create
* an empty set for collecting IMV recommendations
*
* @param tnccs TNCCS connection instance
* @param send_message TNCCS callback function
* @param recs pointer to IMV recommendation set
* @return assigned connection ID
* @param tnccs TNCCS connection instance
* @param send_message TNCCS callback function
* @param recs pointer to IMV recommendation set
* @return assigned connection ID
*/
TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs,
tnccs_send_message_t send_message,
@@ -79,38 +79,77 @@ struct tnccs_manager_t {
/**
* Remove a TNCCS connection using its connection ID.
*
* @param id connection ID of the connection to be removed
* @param id connection ID of the connection to be removed
*/
void (*remove_connection)(tnccs_manager_t *this, TNC_ConnectionID id);
/**
* Add an IMC/IMV message to the batch of a given connection ID.
*
* @param id target connection ID
* @param message message to be added
* @param message_len message length
* @param message_type message type
* @return return code
* @param id target connection ID
* @param msg message to be added
* @param msg_len message length
* @param msg_type message type
* @return return code
*/
TNC_Result (*send_message)(tnccs_manager_t *this,
TNC_ConnectionID id,
TNC_BufferReference message,
TNC_UInt32 message_len,
TNC_MessageType message_type);
TNC_BufferReference msg,
TNC_UInt32 msg_len,
TNC_MessageType msg_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
* @param connection_id ID of target connection
* @param rec action recommendation
* @param eval evaluation result
* @return return code
*/
TNC_Result (*provide_recommendation)(tnccs_manager_t *this,
TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_IMV_Action_Recommendation rec,
TNC_IMV_Evaluation_Result eval);
/**
* Get the value of an attribute associated with a connection or with the
* TNCS as a whole.
*
* @param imv_id ID of the IMV requesting the attribute
* @param connection_id ID of target connection
* @param attribute_id ID of the requested attribute
* @param buffer_len length of the buffer in bytes
* @param buffer pointer to the buffer
* @param out_value_len actual length of the returned attribute
* @return return code
*/
TNC_Result (*get_attribute)(tnccs_manager_t *this,
TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer,
TNC_UInt32 *out_value_len);
/**
* Set the value of an attribute associated with a connection or with the
* TNCS as a whole.
*
* @param imv_id ID of the IMV setting the attribute
* @param connection_id ID of target connection
* @param attribute_id ID of the attribute to be set
* @param buffer_len length of the buffer in bytes
* @param buffer pointer to the buffer
* @return return code
*/
TNC_Result (*set_attribute)(tnccs_manager_t *this,
TNC_IMVID imv_id,
TNC_ConnectionID connection_id,
TNC_IMV_Action_Recommendation recommendation,
TNC_IMV_Evaluation_Result evaluation);
TNC_AttributeID attribute_id,
TNC_UInt32 buffer_len,
TNC_BufferReference buffer);
/**
* Destroy a tnccs_manager instance.