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 "GSSRequest.h"
18 GSSRequest::GSSRequest ( string jsonString )
24 response = JSONObject();
26 requestString = jsonString;
32 void GSSRequest::execute()
50 void GSSRequest::parseJSON()
57 request = JSONObject::load(requestString.c_str(), 0, &jsonErr);
58 cookies = request.get("cookies");
59 response.set("cookies", cookies );
60 response.set("method", request.get("method").string());
62 /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
63 catch ( bad_alloc& e )
66 response.set("error_message", "Could not parse the input JSON.");
67 response.set("original_message", requestString.c_str());
72 void GSSRequest::getCommand()
75 JSONObject arguments = request.get("arguments");
79 if (request.get("method").isNull() )
82 method = string( request.get("method").string() );
84 if ( "gss_import_name" == method )
86 cmd = new GSSImportName ( &arguments );
88 else if ( "gss_init_sec_context" == method )
90 cmd = new GSSInitSecContext ( &arguments );
92 else if ( "gss_acquire_cred" == method )
94 cmd = new GSSAcquireCred ( &arguments );
98 string error_message = string("Unrecognized command: ") + method;
99 response.set("error_message", error_message.c_str() );
100 response.set("original_message", requestString.c_str());
105 string GSSRequest::getResponse()
108 JSONObject *return_values;
111 /* Main processing */
112 // Put the return values into the response, assuming that the command
113 // was actually executed.
116 return_values = cmd->toJSON();
117 response.set("return_values", *return_values);
120 // Convert the response into a string to return.
121 gssResponse = string( response.dump() );