A thought of new exception handling; add entrypoint for FireFox
authorMark Donnelly <mark@painless-security.com>
Wed, 26 Nov 2014 17:20:07 +0000 (12:20 -0500)
committerMark Donnelly <mark@painless-security.com>
Wed, 26 Nov 2014 17:20:07 +0000 (12:20 -0500)
json_gssapi/src/GSSException.cpp
json_gssapi/src/GSSException.h
json_gssapi/src/GSSRequest.cpp
json_gssapi/src/GSSRequest.h

index 61294e0..ccdfa50 100644 (file)
@@ -52,6 +52,9 @@ GSSException::GSSException(std::string message,
   /* Setup */
   
   /* Main */
+  this->major = major;
+  this->minor = minor;
+  
   output_stream << message << std::endl;
   output_stream << "GSS Error message:" << std::endl;
   output_stream << "  Major status:" << std::endl;
index 551d875..308a21c 100644 (file)
@@ -21,9 +21,13 @@ public:
       
     virtual const char* what(void) const throw() { return reason.c_str(); }
     
+    // Accessors
+    OM_uint32 getMajor() { return(major); }
+    OM_uint32 getMinor() { return(minor); }
     
 private:
     std::string reason;
+    OM_uint32 major, minor;
 };
 
 #endif // GSSEXCEPTION_H
index f38d78c..0517015 100644 (file)
@@ -13,6 +13,7 @@
 #include "commands/GSSImportName.h"
 #include "commands/GSSDisplayName.h"
 #include "GSSRequest.h"
+#include "GSSException.h"
 
 using std::bad_alloc;
 
@@ -32,18 +33,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());
+  }
 }
 
 
@@ -128,3 +140,32 @@ string GSSRequest::getResponse()
   /* Return */
   return(gssResponse);
 }
+
+
+
+char *gss_request(char *json_string)
+{
+  /* Variables */
+  char *retVal;
+  string output;
+  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();
+  output = req->getResponse();
+  retVal = new char[ output.length() + 1 ];
+  output.copy(retVal, output.length(), 0);
+  retVal[output.length()] = 0;
+  
+  return(retVal);
+}
+
+void deallocate_reply(char *reply)
+{
+  delete(reply);
+}
index 2d4297e..e0094f9 100644 (file)
 
 using std::string;
 
+/* An exportable function to be called by firefox
+ * to process a JSON string
+ */
+extern "C" {
+  char *gss_request(char *json_string);
+  void deallocate_reply(char *reply);
+}
+
 class GSSRequest
 {
 public: