*/
#include "GSSException.h"
+#include "datamodel/GSSBuffer.h"
#include <sstream>
-#include <ios>
-#include <iostream>
+#include <string>
-static void disp_status(OM_uint32 status, int status_type, gss_OID mech, std::ostream &output_stream)
+static std::string disp_status(OM_uint32 status, int status_type, gss_OID mech)
{
+ /* Error checking */
+ /* Variables */
+ GSSBuffer disp_buf;
+ std::string disp_status;
+
OM_uint32 disp_major, disp_minor, disp_context;
- gss_buffer_desc disp_buf;
disp_context = 0;
do
status_type,
mech,
&disp_context,
- &disp_buf);
+ disp_buf.toGss() );
if (GSS_ERROR(disp_major))
- {
- disp_context = 0; // Get out of this loop.
- output_stream << " An error occurred, and then another error" << std::endl <<
- " occurred in creating a message to describe the first one. " << std::endl <<
- " How embarrassing. It's time to quit before it gets any worse." << std::endl <<
- " For now, the error code itself was 0x" << std::hex << status << std::dec;
- std::cout << "\n -------------------------\n Something wonky happened in displaying status:\n";
- std::cout << " gss_display_status(&disp_minor, " << status << ", " << (int)status_type << ", " << (long int)mech << ", " << disp_context << ", &buf);\n";
- disp_status(disp_major, GSS_C_GSS_CODE, mech, std::cout);
- disp_status(disp_minor, GSS_C_MECH_CODE, mech, std::cout);
- } else
- output_stream << " " << (char *)disp_buf.value << std::endl;
+ throw GSSException("An error occurred while dealing with another error.", disp_major, disp_minor, mech);
+ else
+ disp_status += disp_buf.toString();
} while (disp_context != 0);
+
+ return(disp_status);
}
GSSException::GSSException(std::string message,
/* Error checking */
/* Variables */
- std::stringstream output_stream;
/* 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;
- disp_status(major, GSS_C_GSS_CODE, mech, output_stream);
- output_stream << std::endl;
- output_stream << " Minor status details: " << std::endl;
- disp_status(minor, GSS_C_MECH_CODE, mech, output_stream);
- reason = output_stream.str();
-
+ this->mech = mech;
+ this->message = message;
+
+ this->major_msg = disp_status(major, GSS_C_GSS_CODE, mech);
+ this->minor_msg = disp_status(minor, GSS_C_MECH_CODE, mech);
/* Cleanup */
/* Return */
}
+
+const char* GSSException::what(void) const throw()
+{
+ /* Variables */
+ return(this->message.c_str());
+}
+
GSSException(std::string msg, OM_uint32 major = 0, OM_uint32 minor = 0 , gss_OID mech = GSS_C_NO_OID);
~GSSException(void) throw() { }
- virtual const char* what(void) const throw() { return reason.c_str(); }
+ const char* what(void) const throw();
// Accessors
OM_uint32 getMajor() { return(major); }
OM_uint32 getMinor() { return(minor); }
+
+ std::string major_status_message() const throw() {return(major_msg);};
+ std::string minor_status_message() const throw() {return(minor_msg);};
private:
- std::string reason;
+ std::string reason, message, major_msg, minor_msg;
OM_uint32 major, minor;
+ gss_OID mech;
};
#endif // GSSEXCEPTION_H
cmd = NULL;
}
- JSONObject return_values;
+ JSONObject return_values, errors;
+ errors.set("major_status_message", e.major_status_message().c_str());
+ errors.set("minor_status_message", e.minor_status_message().c_str());
+ errors.set("what", e.what());
+ return_values.set("errors", errors);
return_values.set("major_status", e.getMajor());
return_values.set("minor_status", e.getMinor());
- return_values.set("what", e.what());
response.set("return_values", return_values);
}
catch (std::invalid_argument e)