implement set_attribute() callback function
This commit is contained in:
@@ -39,12 +39,22 @@ struct recommendation_entry_t {
|
|||||||
/**
|
/**
|
||||||
* Action Recommendation provided by IMV instance
|
* Action Recommendation provided by IMV instance
|
||||||
*/
|
*/
|
||||||
TNC_IMV_Action_Recommendation rec;
|
TNC_IMV_Action_Recommendation rec;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluation Result provided by IMV instance
|
* 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);
|
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,
|
METHOD(recommendations_t, destroy, void,
|
||||||
private_tnc_imv_recommendations_t *this)
|
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->preferred_language.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@@ -293,6 +355,9 @@ recommendations_t* tnc_imv_recommendations_create(linked_list_t *imv_list)
|
|||||||
.have_recommendation = _have_recommendation,
|
.have_recommendation = _have_recommendation,
|
||||||
.get_preferred_language = _get_preferred_language,
|
.get_preferred_language = _get_preferred_language,
|
||||||
.set_preferred_language = _set_preferred_language,
|
.set_preferred_language = _set_preferred_language,
|
||||||
|
.set_reason_string = _set_reason_string,
|
||||||
|
.set_reason_language = _set_reason_language,
|
||||||
|
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.recs = linked_list_create(),
|
.recs = linked_list_create(),
|
||||||
|
|||||||
@@ -81,6 +81,26 @@ struct recommendations_t {
|
|||||||
*/
|
*/
|
||||||
void (*set_preferred_language)(recommendations_t *this, chunk_t pref_lang);
|
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.
|
* Destroys an imv_t object.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -352,6 +352,42 @@ METHOD(tnccs_manager_t, set_attribute, TNC_Result,
|
|||||||
TNC_UInt32 buffer_len,
|
TNC_UInt32 buffer_len,
|
||||||
TNC_BufferReference buffer)
|
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;
|
return TNC_RESULT_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user