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"
19 GSSRequest::GSSRequest ( string jsonString )
25 response = JSONObject();
27 requestString = jsonString;
33 void GSSRequest::execute()
51 void GSSRequest::parseJSON()
58 request = JSONObject::load(requestString.c_str(), 0, &jsonErr);
59 cookies = request.get("cookies");
60 response.set("cookies", cookies );
61 response.set("method", request.get("method").string());
63 /* bad_alloc is thrown when JSONObject can't parse the input string as JSON */
67 response.set("error_message", "Could not parse the input JSON.");
68 response.set("original_message", requestString.c_str());
73 void GSSRequest::getCommand()
76 JSONObject arguments = request.get("arguments");
80 if (request.get("method").isNull() )
83 method = string( request.get("method").string() );
85 if ( "gss_import_name" == method )
87 cmd = new GSSImportName ( &arguments );
89 else if ( "gss_init_sec_context" == method )
91 cmd = new GSSInitSecContext ( &arguments );
93 else if ( "gss_acquire_cred" == method )
95 cmd = new GSSAcquireCred ( &arguments );
97 else if ( "gss_display_name" == method )
99 cmd = new GSSDisplayName ( &arguments );
103 string error_message = string("Unrecognized command: ") + method;
104 response.set("error_message", error_message.c_str() );
105 response.set("original_message", requestString.c_str());
110 string GSSRequest::getResponse()
113 JSONObject *return_values;
116 /* Main processing */
117 // Put the return values into the response, assuming that the command
118 // was actually executed.
121 return_values = cmd->toJSON();
122 response.set("return_values", *return_values);
125 // Convert the response into a string to return.
126 gssResponse = string( response.dump() );