From 98daa21c39a8d4cf65fb32c03379da933386fe08 Mon Sep 17 00:00:00 2001 From: Mark Donnelly Date: Fri, 9 May 2014 12:43:40 -0400 Subject: [PATCH] Refactor some of the JSON generation into some of the data objects. --- json_gssapi/src/GSSAcquireCred.cpp | 24 +++++++++---------- json_gssapi/src/datamodel/GSSOIDSet.cpp | 42 +++++++++++++++++++++++++-------- json_gssapi/test/GSSAcquireCredTest.cpp | 2 +- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/json_gssapi/src/GSSAcquireCred.cpp b/json_gssapi/src/GSSAcquireCred.cpp index 4ac4897..2c76627 100644 --- a/json_gssapi/src/GSSAcquireCred.cpp +++ b/json_gssapi/src/GSSAcquireCred.cpp @@ -149,30 +149,28 @@ JSONObject *GSSAcquireCred::toJSON() /* Variables */ JSONObject *ret = new JSONObject(); JSONObject *values = new JSONObject(); - JSONObject mechs = JSONObject::array(); +// JSONObject mechs = JSONObject::array(); JSONObject *temp; - gss_OID_set gssMechs; - OM_uint32 i; /* Error checking */ /* Setup */ /* Main */ - gssMechs = actualMechs.toGss(); - for (i = 0; i < gssMechs->count; i++) - { - GSSOID m( gssMechs->elements + i ); - temp = m.toJSONValue(); - std::cout << "\nMech value: " << temp->string(); - mechs.append( *temp ); - } + // Return Values + // Easy stuff values->set("major_status", this->retVal); values->set("minor_status", this->minor_status); + values->set("time_rec", (int)this->time_rec ); + + // Objects that generate their own JSONObject temp = this->cred.toJSONValue(); values->set("output_cred_handle", *temp ); - values->set("actual_mechs", mechs); - values->set("time_rec", (int)this->time_rec ); + + temp = this->actualMechs.toJSONValue(); + values->set("actual_mechs", *temp); + + // Put it all together. ret->set("command", "gss_acquire_cred"); ret->set("return_values", *values); diff --git a/json_gssapi/src/datamodel/GSSOIDSet.cpp b/json_gssapi/src/datamodel/GSSOIDSet.cpp index 965069d..696cd06 100644 --- a/json_gssapi/src/datamodel/GSSOIDSet.cpp +++ b/json_gssapi/src/datamodel/GSSOIDSet.cpp @@ -120,16 +120,38 @@ bool GSSOIDSet::includes ( const GSSOID &oid ) const return(this->includes( oid.toGss() ) ); } -// JSONObject* GSSOIDSet::toJSONValue() const -// { -// /* Variables */ -// JSONObject x("hello"); -// /* Error checking */ -// /* Setup */ -// /* Main */ -// /* Cleanup */ -// /* return */ -// } +/* + * Desired JSON Output: + * + * [ + * "{ 1 2 3 4 }", + * "{ 5 6 7 8 }" + * ] + * + */ +JSONObject* GSSOIDSet::toJSONValue() const +{ + /* Variables */ + JSONObject jsonArray = JSONObject::array(); + JSONObject *ret, *temp; + OM_uint32 index; + /* Error checking */ + /* Setup */ + /* Main */ + + for (index = 0; index < set->count; index++) + { + GSSOID m( set->elements + index ); + temp = m.toJSONValue(); + jsonArray.append( *temp ); + } + + ret = new JSONObject(jsonArray); + + /* Cleanup */ + /* return */ + return(ret); +} /* Variables */ diff --git a/json_gssapi/test/GSSAcquireCredTest.cpp b/json_gssapi/test/GSSAcquireCredTest.cpp index 0c72757..f5d1f5d 100644 --- a/json_gssapi/test/GSSAcquireCredTest.cpp +++ b/json_gssapi/test/GSSAcquireCredTest.cpp @@ -249,7 +249,7 @@ void GSSAcquireCredTest::testJSONMarshal() cmd.execute(); result = cmd.toJSON(); - std::cout << "\n" << result->dump() << "\n"; +// std::cout << "\n" << result->dump() << "\n"; CPPUNIT_ASSERT_EQUAL_MESSAGE( "The command name is incorrect", -- 2.1.4