-#include <commands/GSSImportName.h>
-#include <commands/GSSCreateSecContextCommand.h>
-#include <commands/GSSAcquireCred.h>
-#include <datamodel/GSSBuffer.h>
-#include <exception>
+//
#include <iostream>
-#include <string>
-#include <util_json.h>
+#ifdef WIN32
+#include <stdio.h>
+#include <fcntl.h>
+#include <io.h>
+#else
+#include <unistd.h>
+#include <string.h>
+#endif
+#include <GSSRequest.h>
+
using std::cin;
using std::cout;
using std::endl;
using std::getline;
-using std::string;
int main(int argc, char **argv) {
/* Variables */
- string input, method;
- const char* c_str;
- JSONObject json;
- JSONObject *result;
- json_error_t jsonErr;
- GSSCommand *cmd;
+ char *input;
+ char *output;
+ int32_t len;
/* Error checking */
/* Setup */
/* Main processing */
+#ifdef WIN32
+ _setmode(_fileno(stdin), _O_BINARY);
+#endif
+ int readThisRound, readTotal, readRemaining;
do
{
- try
+ // Read 32 bit length
+ len = 0;
+ readThisRound = readTotal = 0;
+ while(4 != readTotal)
{
- cout << "Give me some JSON: ";
- getline(cin, input);
-
- c_str = input.c_str();
- JSONObject json = JSONObject::load(c_str, 0, &jsonErr);
-
- // Oh, how I wish I could simply use: switch(json.get("method"))
- c_str = json.get("method").string();
- method = c_str;
- if ("gss_import_name" == method)
- {
- cmd = new GSSImportName(&json);
- }
- else if ("gss_create_sec_context" == method)
- {
- cmd = new GSSCreateSecContextCommand(&json);
- }
- else if ("gss_acquire_cred" == method)
- {
- cmd = new GSSAcquireCred(&json);
- }
- else
- {
- JSONObject response;
- response.set("method", "unknown");
- response.set("error_message", "Did not find a valid method to execute.");
- cout << response.dump() << endl;
-
- continue;
- }
-
- cmd->execute();
- result = cmd->toJSON();
- delete cmd;
-
- cout << result->dump( JSON_INDENT(4) ) << endl;
-
+ readThisRound = _read(0, ((&len) + readTotal), 4 - readTotal);
+ readTotal += readThisRound;
}
- catch ( std::bad_alloc )
+
+ // Reads the number of bytes indicated by the above read
+ input = new char[len + 1];
+ readTotal = readThisRound = 0;
+ while (readTotal < len)
{
- JSONObject response;
- JSONObject error;
- response.set("method", "unknown");
- response.set("error_message", "Could not parse the input JSON");
- error.set("text", jsonErr.text);
- error.set("source", jsonErr.source);
- error.set("line", jsonErr.line);
- error.set("column", jsonErr.column);
- error.set("position", jsonErr.position);
- response.set("error", error);
- cout << response.dump() << endl;
+ readRemaining = len - readTotal;
+ readThisRound = _read( 0, &(input[readTotal]), readRemaining);
+ if (-1 == readThisRound)
+ break;
+ else
+ readTotal += readThisRound;
}
+ // ... and null-terminate it
+ input[len] = '\0';
+
+ output = gss_request(input);
+ len = (int32_t )strlen(output);
+
+ cout.write((char *)&len, 4);
+ cout << output;
+ deallocate_reply(output);
+ cout.flush();
} while(1);
-
return 0;
}