Updated REST API

This commit is contained in:
Andreas Steffen 2014-06-06 10:55:42 +02:00
parent 35e08cde3c
commit b23c7d6a38
2 changed files with 17 additions and 7 deletions

View File

@ -235,7 +235,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
tcg_swid_attr_tag_inv_t *attr_cast; tcg_swid_attr_tag_inv_t *attr_cast;
swid_tag_t *tag; swid_tag_t *tag;
chunk_t tag_encoding; chunk_t tag_encoding;
json_object *jarray, *jstring; json_object *jobj, *jarray, *jstring;
char *tag_str; char *tag_str;
int tag_count; int tag_count;
enumerator_t *e; enumerator_t *e;
@ -260,7 +260,9 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
if (this->rest_api) if (this->rest_api)
{ {
jobj = json_object_new_object();
jarray = json_object_new_array(); jarray = json_object_new_array();
json_object_object_add(jobj, "data", jarray);
e = inventory->create_enumerator(inventory); e = inventory->create_enumerator(inventory);
while (e->enumerate(e, &tag)) while (e->enumerate(e, &tag))
@ -275,11 +277,11 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
e->destroy(e); e->destroy(e);
if (this->rest_api->post(this->rest_api, if (this->rest_api->post(this->rest_api,
"swid/add-tags/", jarray, NULL) != SUCCESS) "swid/add-tags/", jobj, NULL) != SUCCESS)
{ {
DBG1(DBG_IMV, "error in REST API add-tags request"); DBG1(DBG_IMV, "error in REST API add-tags request");
} }
json_object_put(jarray); json_object_put(jobj);
} }
} }
else else
@ -478,7 +480,7 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
if (this->rest_api && (received & IMV_SWID_ATTR_TAG_ID_INV)) if (this->rest_api && (received & IMV_SWID_ATTR_TAG_ID_INV))
{ {
if (asprintf(&command, "sessions/%d/swid_measurement/", if (asprintf(&command, "sessions/%d/swid-measurement/",
session->get_session_id(session, NULL, NULL)) < 0) session->get_session_id(session, NULL, NULL)) < 0)
{ {
error_str = "allocation of command string failed"; error_str = "allocation of command string failed";
@ -491,7 +493,7 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
jrequest, &jresponse); jrequest, &jresponse);
if (status == FAILED) if (status == FAILED)
{ {
error_str = "error in REST API swid_measurement request"; error_str = "error in REST API swid-measurement request";
} }
free(command); free(command);
} }

View File

@ -112,6 +112,11 @@ struct private_imv_swid_state_t {
*/ */
int tag_count; int tag_count;
/**
* Top level JSON object
*/
json_object *jobj;
/** /**
* JSON array containing an inventory of SWID Tag IDs * JSON array containing an inventory of SWID Tag IDs
*/ */
@ -232,7 +237,7 @@ METHOD(imv_state_t, get_remediation_instructions, bool,
METHOD(imv_state_t, destroy, void, METHOD(imv_state_t, destroy, void,
private_imv_swid_state_t *this) private_imv_swid_state_t *this)
{ {
json_object_put(this->jarray); json_object_put(this->jobj);
DESTROY_IF(this->session); DESTROY_IF(this->session);
DESTROY_IF(this->reason_string); DESTROY_IF(this->reason_string);
DESTROY_IF(this->remediation_string); DESTROY_IF(this->remediation_string);
@ -293,7 +298,7 @@ METHOD(imv_swid_state_t, set_swid_inventory, void,
METHOD(imv_swid_state_t, get_swid_inventory, json_object*, METHOD(imv_swid_state_t, get_swid_inventory, json_object*,
private_imv_swid_state_t *this) private_imv_swid_state_t *this)
{ {
return this->jarray; return this->jobj;
} }
METHOD(imv_swid_state_t, set_count, void, METHOD(imv_swid_state_t, set_count, void,
@ -371,9 +376,12 @@ imv_state_t *imv_swid_state_create(TNC_ConnectionID connection_id)
.rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION, .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
.eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW, .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
.connection_id = connection_id, .connection_id = connection_id,
.jobj = json_object_new_object(),
.jarray = json_object_new_array(), .jarray = json_object_new_array(),
); );
json_object_object_add(this->jobj, "data", this->jarray);
return &this->public.interface; return &this->public.interface;
} }