2 * Copyright (c) 2014 <copyright holder> <email>
4 * For license details, see the LICENSE file in the root of this project.
12 #include "commands/GSSAcquireCred.h"
13 #include "commands/GSSInitSecContext.h"
14 #include "commands/GSSImportName.h"
15 #include "commands/GSSDisplayName.h"
16 #include "GSSRequest.h"
17 #include "GSSException.h"
21 GSSRequest::GSSRequest ( string jsonString )
27 response = JSONObject();
29 requestString = jsonString;
35 void GSSRequest::execute()
51 catch (GSSException e)
55 JSONObject return_values;
56 return_values.set("major_status", e.getMajor());
57 return_values.set("minor_status", e.getMinor());
58 return_values.set("what", e.what());
59 response.set("return_values", return_values);
65 void GSSRequest::parseJSON()
72 request = JSONObject::load(requestString.c_str(), 0, &jsonErr);
73 cookies = request.get("cookies");
74 response.set("cookies", cookies );
75 response.set("method", request.get("method").string());
77 /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
81 response.set("error_message", "Could not parse the input JSON.");
82 response.set("original_message", requestString.c_str());
87 void GSSRequest::getCommand()
90 JSONObject arguments = request.get("arguments");
94 if (request.get("method").isNull() )
97 method = string( request.get("method").string() );
99 if ( "gss_import_name" == method )
101 cmd = new GSSImportName ( &arguments );
103 else if ( "gss_init_sec_context" == method )
105 cmd = new GSSInitSecContext ( &arguments );
107 else if ( "gss_acquire_cred" == method )
109 cmd = new GSSAcquireCred ( &arguments );
111 else if ( "gss_display_name" == method )
113 cmd = new GSSDisplayName ( &arguments );
117 string error_message = string("Unrecognized command: ") + method;
118 response.set("error_message", error_message.c_str() );
119 response.set("original_message", requestString.c_str());
124 string GSSRequest::getResponse()
127 JSONObject *return_values;
130 /* Main processing */
131 // Put the return values into the response, assuming that the command
132 // was actually executed.
135 return_values = cmd->toJSON();
136 response.set("return_values", *return_values);
139 // Convert the response into a string to return.
140 gssResponse = string( response.dump() );
148 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 return strdup(req->getResponse().c_str());
163 void deallocate_reply(char *reply)