include string.h for strdup
[gssweb.git] / json_gssapi / src / GSSRequest.cpp
index aa3de6e..05d189d 100644 (file)
@@ -7,11 +7,14 @@
 
 #include <cstddef>
 #include <stdexcept>
+#include <string.h>
 
 #include "commands/GSSAcquireCred.h"
 #include "commands/GSSInitSecContext.h"
 #include "commands/GSSImportName.h"
+#include "commands/GSSDisplayName.h"
 #include "GSSRequest.h"
+#include "GSSException.h"
 
 using std::bad_alloc;
 
@@ -31,18 +34,29 @@ GSSRequest::GSSRequest ( string jsonString )
 
 void GSSRequest::execute()
 {
-  /* variables */
-  /* Error checking */
-  /* Setup */
-  parseJSON();
-  getCommand();
-  
-  /* Main processing */
-  if (NULL != cmd)
-    cmd->execute();
-  
-  /* Cleanup */
-  /* Return */
+  try {
+    /* variables */
+    /* Error checking */
+    /* Setup */
+    parseJSON();
+    getCommand();
+    
+    /* Main processing */
+    if (NULL != cmd)
+      cmd->execute();
+    
+    /* Cleanup */
+    /* Return */
+  }
+  catch (GSSException e)
+  {
+    delete(cmd);
+    cmd = NULL;
+    JSONObject return_values;
+    return_values.set("major_status", e.getMajor());
+    return_values.set("minor_status", e.getMinor());
+//     response.set("error_message", e.what());
+  }
 }
 
 
@@ -60,7 +74,7 @@ void GSSRequest::parseJSON()
     response.set("method", request.get("method").string());
   }
   /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
-  catch ( bad_alloc& 
+  catch ( bad_alloc& ) 
   {
     // Top-level response
     response.set("error_message", "Could not parse the input JSON.");
@@ -85,7 +99,7 @@ void GSSRequest::getCommand()
   {
     cmd = new GSSImportName ( &arguments );
   } 
-  else if ( "gss_create_sec_context" == method ) 
+  else if ( "gss_init_sec_context" == method ) 
   {
     cmd = new GSSInitSecContext ( &arguments );
   } 
@@ -93,6 +107,10 @@ void GSSRequest::getCommand()
   {
     cmd = new GSSAcquireCred ( &arguments );
   } 
+  else if ( "gss_display_name" == method )
+  {
+    cmd = new GSSDisplayName ( &arguments );
+  }
   else 
   {
     string error_message = string("Unrecognized command: ") + method;
@@ -123,3 +141,25 @@ string GSSRequest::getResponse()
   /* Return */
   return(gssResponse);
 }
+
+
+
+char *gss_request(char *json_string)
+{
+  /* Variables */
+  GSSRequest *req = new GSSRequest(string(json_string));
+  
+  /* Error checking */
+  // An empty json_string could be an error, but GSSRequest does
+  // a good job of handling it.
+  
+  /* Setup */
+  /* Main processing */
+  req->execute();
+  return strdup(req->getResponse().c_str());
+}
+
+void deallocate_reply(char *reply)
+{
+  delete(reply);
+}