Refactor some of the JSON generation into some of the data objects.
authorMark Donnelly <mark@painless-security.com>
Fri, 9 May 2014 16:43:40 +0000 (12:43 -0400)
committerMark Donnelly <mark@painless-security.com>
Fri, 9 May 2014 16:43:40 +0000 (12:43 -0400)
json_gssapi/src/GSSAcquireCred.cpp
json_gssapi/src/datamodel/GSSOIDSet.cpp
json_gssapi/test/GSSAcquireCredTest.cpp

index 4ac4897..2c76627 100644 (file)
@@ -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);
   
index 965069d..696cd06 100644 (file)
@@ -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 */
index 0c72757..f5d1f5d 100644 (file)
@@ -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",