A thought of new exception handling; add entrypoint for FireFox
[gssweb.git] / json_gssapi / src / GSSException.cpp
1 /*
2  * Copyright (c) 2014 <copyright holder> <email>
3  * 
4  * For license details, see the LICENSE file in the root of this project.
5  * 
6  */
7
8 #include "GSSException.h"
9 #include <sstream>
10 #include <ios>
11 #include <iostream>
12
13 static void disp_status(OM_uint32 status, int status_type, gss_OID mech, std::ostream &output_stream)
14 {
15   OM_uint32 disp_major, disp_minor, disp_context;
16   gss_buffer_desc disp_buf;
17
18   disp_context = 0;
19   do
20   {
21     disp_major = gss_display_status(&disp_minor, 
22                                     status, 
23                                     status_type,
24                                     mech, 
25                                     &disp_context, 
26                                     &disp_buf);
27     if (GSS_ERROR(disp_major))
28     {
29       disp_context = 0; // Get out of this loop.
30       output_stream << "    An error occurred, and then another error" << std::endl <<
31          "    occurred in creating a message to describe the first one. " << std::endl <<
32          "    How embarrassing. It's time to quit before it gets any worse." <<  std::endl <<
33          "    For now, the error code itself was 0x" << std::hex << status << std::dec;
34       std::cout << "\n     -------------------------\n    Something wonky happened in displaying status:\n";
35       std::cout << "     gss_display_status(&disp_minor, " << status << ", " << (int)status_type << ", " << (long int)mech << ", " << disp_context << ", &buf);\n";
36       disp_status(disp_major, GSS_C_GSS_CODE, mech, std::cout);
37       disp_status(disp_minor, GSS_C_MECH_CODE, mech, std::cout);
38     } else
39       output_stream << "    " << (char *)disp_buf.value << std::endl;
40   } while (disp_context != 0);
41 }
42
43 GSSException::GSSException(std::string message, 
44                            OM_uint32 major, 
45                            OM_uint32 minor, 
46                            gss_OID mech)
47 {
48   /* Error checking */
49   
50   /* Variables */
51   std::stringstream output_stream;
52   /* Setup */
53   
54   /* Main */
55   this->major = major;
56   this->minor = minor;
57   
58   output_stream << message << std::endl;
59   output_stream << "GSS Error message:" << std::endl;
60   output_stream << "  Major status:" << std::endl;
61   disp_status(major, GSS_C_GSS_CODE, mech, output_stream);
62   output_stream << std::endl;
63   output_stream << "  Minor status details: " << std::endl;
64   disp_status(minor, GSS_C_MECH_CODE, mech, output_stream);
65   reason = output_stream.str();
66   
67   
68   /* Cleanup */
69   /* Return */
70 }