Updated REST API
authorAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 6 Jun 2014 08:55:42 +0000 (10:55 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Fri, 6 Jun 2014 08:56:12 +0000 (10:56 +0200)
src/libpts/plugins/imv_swid/imv_swid_agent.c
src/libpts/plugins/imv_swid/imv_swid_state.c

index 4278fad..3053b26 100644 (file)
@@ -235,7 +235,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
                                tcg_swid_attr_tag_inv_t *attr_cast;
                                swid_tag_t *tag;
                                chunk_t tag_encoding;
-                               json_object *jarray, *jstring;
+                               json_object *jobj, *jarray, *jstring;
                                char *tag_str;
                                int tag_count;
                                enumerator_t *e;
@@ -260,7 +260,9 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
 
                                        if (this->rest_api)
                                        {
+                                               jobj = json_object_new_object();
                                                jarray = json_object_new_array();
+                                               json_object_object_add(jobj, "data", jarray);
 
                                                e = inventory->create_enumerator(inventory);
                                                while (e->enumerate(e, &tag))
@@ -275,11 +277,11 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
                                                e->destroy(e);
 
                                                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");
                                                }
-                                               json_object_put(jarray);
+                                               json_object_put(jobj);
                                        }
                                }
                                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 (asprintf(&command, "sessions/%d/swid_measurement/",
+                       if (asprintf(&command, "sessions/%d/swid-measurement/",
                                                 session->get_session_id(session, NULL, NULL)) < 0)
                        {
                                error_str = "allocation of command string failed";
@@ -491,7 +493,7 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
                                                                                          jrequest, &jresponse);
                                if (status == FAILED)
                                {
-                                       error_str = "error in REST API swid_measurement request";
+                                       error_str = "error in REST API swid-measurement request";
                                }
                                free(command);
                        }
index fa8a79c..c68b57e 100644 (file)
@@ -113,6 +113,11 @@ struct private_imv_swid_state_t {
        int tag_count;
 
        /**
+        * Top level JSON object
+        */
+       json_object *jobj;
+
+       /**
         * JSON array containing an inventory of SWID Tag IDs
         */
        json_object *jarray;
@@ -232,7 +237,7 @@ METHOD(imv_state_t, get_remediation_instructions, bool,
 METHOD(imv_state_t, destroy, void,
        private_imv_swid_state_t *this)
 {
-       json_object_put(this->jarray);
+       json_object_put(this->jobj);
        DESTROY_IF(this->session);
        DESTROY_IF(this->reason_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*,
        private_imv_swid_state_t *this)
 {
-       return this->jarray;
+       return this->jobj;
 }
 
 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,
                .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
                .connection_id = connection_id,
+               .jobj = json_object_new_object(),
                .jarray = json_object_new_array(),
        );
 
+       json_object_object_add(this->jobj, "data", this->jarray);
+
        return &this->public.interface;
 }