From f98b02598095a78b0dac063c2288157d13b6b679 Mon Sep 17 00:00:00 2001 From: Mark Donnelly Date: Wed, 26 Nov 2014 12:20:07 -0500 Subject: [PATCH] A thought of new exception handling; add entrypoint for FireFox --- json_gssapi/src/GSSException.cpp | 3 ++ json_gssapi/src/GSSException.h | 4 +++ json_gssapi/src/GSSRequest.cpp | 65 ++++++++++++++++++++++++++++++++-------- json_gssapi/src/GSSRequest.h | 8 +++++ 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/json_gssapi/src/GSSException.cpp b/json_gssapi/src/GSSException.cpp index 61294e0..ccdfa50 100644 --- a/json_gssapi/src/GSSException.cpp +++ b/json_gssapi/src/GSSException.cpp @@ -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; diff --git a/json_gssapi/src/GSSException.h b/json_gssapi/src/GSSException.h index 551d875..308a21c 100644 --- a/json_gssapi/src/GSSException.h +++ b/json_gssapi/src/GSSException.h @@ -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 diff --git a/json_gssapi/src/GSSRequest.cpp b/json_gssapi/src/GSSRequest.cpp index f38d78c..0517015 100644 --- a/json_gssapi/src/GSSRequest.cpp +++ b/json_gssapi/src/GSSRequest.cpp @@ -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); +} diff --git a/json_gssapi/src/GSSRequest.h b/json_gssapi/src/GSSRequest.h index 2d4297e..e0094f9 100644 --- a/json_gssapi/src/GSSRequest.h +++ b/json_gssapi/src/GSSRequest.h @@ -15,6 +15,14 @@ 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: -- 2.1.4