2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
11 #include "commands/GSSAcquireCred.h"
12 #include "commands/GSSInitSecContext.h"
13 #include "commands/GSSImportName.h"
14 #include "commands/GSSDisplayName.h"
15 #include "GSSRequest.h"
16 #include "GSSException.h"
20 GSSRequest::GSSRequest ( string jsonString )
26 response = JSONObject();
28 requestString = jsonString;
34 void GSSRequest::execute()
50 catch (GSSException e)
54 JSONObject return_values;
55 return_values.set("major_status", e.getMajor());
56 return_values.set("minor_status", e.getMinor());
57 // response.set("error_message", e.what());
63 void GSSRequest::parseJSON()
70 request = JSONObject::load(requestString.c_str(), 0, &jsonErr);
71 cookies = request.get("cookies");
72 response.set("cookies", cookies );
73 response.set("method", request.get("method").string());
75 /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
79 response.set("error_message", "Could not parse the input JSON.");
80 response.set("original_message", requestString.c_str());
85 void GSSRequest::getCommand()
88 JSONObject arguments = request.get("arguments");
92 if (request.get("method").isNull() )
95 method = string( request.get("method").string() );
97 if ( "gss_import_name" == method )
99 cmd = new GSSImportName ( &arguments );
101 else if ( "gss_init_sec_context" == method )
103 cmd = new GSSInitSecContext ( &arguments );
105 else if ( "gss_acquire_cred" == method )
107 cmd = new GSSAcquireCred ( &arguments );
109 else if ( "gss_display_name" == method )
111 cmd = new GSSDisplayName ( &arguments );
115 string error_message = string("Unrecognized command: ") + method;
116 response.set("error_message", error_message.c_str() );
117 response.set("original_message", requestString.c_str());
122 string GSSRequest::getResponse()
125 JSONObject *return_values;
128 /* Main processing */
129 // Put the return values into the response, assuming that the command
130 // was actually executed.
133 return_values = cmd->toJSON();
134 response.set("return_values", *return_values);
137 // Convert the response into a string to return.
138 gssResponse = string( response.dump() );
146 char *gss_request(char *json_string)
151 GSSRequest *req = new GSSRequest(string(json_string));
154 // An empty json_string could be an error, but GSSRequest does
155 // a good job of handling it.
158 /* Main processing */
160 output = req->getResponse();
161 retVal = new char[ output.length() + 1 ];
162 output.copy(retVal, output.length(), 0);
163 retVal[output.length()] = 0;
168 void deallocate_reply(char *reply)