1 #include <commands/GSSImportName.h>
2 #include <commands/GSSCreateSecContextCommand.h>
3 #include <commands/GSSAcquireCred.h>
4 #include <datamodel/GSSBuffer.h>
18 int main(int argc, char **argv) {
20 string method, output;
28 ssize_t readTotal, readThisRound, readRemaining;
29 std::streamsize threeTwoBits = 32 / sizeof(string::size_type);
42 readThisRound = readTotal = 0;
45 readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
46 readTotal += readThisRound;
49 // Reads the number of bytes indicated by the above read
50 input = new char[len + 1];
51 readTotal = readThisRound = 0;
52 while (readTotal < len)
54 readRemaining = len - readTotal;
55 readThisRound = read( 0, &(input[readTotal]), readRemaining);
56 if (-1 == readThisRound)
59 readTotal += readThisRound;
61 // ... and null-terminate it
66 JSONObject json = JSONObject::load(input, 0, &jsonErr);
69 // Oh, how I wish I could simply use: switch(json.get("method"))
70 c_str = json.get("method").string();
72 if ("gss_import_name" == method)
74 cmd = new GSSImportName(&json);
76 else if ("gss_create_sec_context" == method)
78 cmd = new GSSCreateSecContextCommand(&json);
80 else if ("gss_acquire_cred" == method)
82 cmd = new GSSAcquireCred(&json);
87 response.set("method", "unknown");
88 response.set("error_message", "Did not find a valid method to execute.");
89 output = response.dump();
90 len = output.length();
91 cout.write((char *)&len, threeTwoBits);
92 cout << output << endl;
98 result = cmd->toJSON();
101 output = result->dump();
102 len = output.length();
104 cout.write((char *)&len, threeTwoBits);
109 catch ( std::bad_alloc& e )
113 response.set("method", "unknown");
114 response.set("error_message", "Could not parse the input JSON");
115 response.set("original message", input);
116 error.set("text", jsonErr.text);
117 error.set("source", jsonErr.source);
118 error.set("line", jsonErr.line);
119 error.set("column", jsonErr.column);
120 error.set("position", jsonErr.position);
121 response.set("error", error);
122 output = response.dump();
123 len = output.length();
124 cout.write((char *)&len, threeTwoBits);
125 cout << output << endl;