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;
41 readThisRound = readTotal = 0;
44 readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
45 readTotal += readThisRound;
48 // Reads the number of bytes indicated by the above read
49 input = new char[len + 1];
50 readTotal = readThisRound = 0;
51 while (readTotal < len)
53 readRemaining = len - readTotal;
54 readThisRound = read( 0, &(input[readTotal]), readRemaining);
55 if (-1 == readThisRound)
58 readTotal += readThisRound;
60 // ... and null-terminate it
65 JSONObject json = JSONObject::load(input, 0, &jsonErr);
68 if ( json.get("method").isNull() )
71 response.set("method", "unknown");
72 response.set("error_message", "Did not find a valid method to execute.");
73 output = response.dump();
74 len = output.length();
75 cout.write((char *)&len, 4);
76 cout << output << endl;
80 // Oh, how I wish I could simply use: switch(json.get("method"))
81 c_str = json.get("method").string();
83 if ("gss_import_name" == method)
85 cmd = new GSSImportName(&json);
87 else if ("gss_create_sec_context" == method)
89 cmd = new GSSCreateSecContextCommand(&json);
91 else if ("gss_acquire_cred" == method)
93 cmd = new GSSAcquireCred(&json);
98 response.set("method", "unknown");
99 response.set("error_message", "Did not find a valid method to execute.");
100 output = response.dump();
101 len = output.length();
102 cout.write((char *)&len, 4);
103 cout << output << endl;
109 result = cmd->toJSON();
112 output = result->dump();
113 len = output.length();
115 cout.write((char *)&len, 4);
120 catch ( std::bad_alloc& e )
124 response.set("method", "unknown");
125 response.set("error_message", "Could not parse the input JSON");
126 response.set("original message", input);
127 error.set("text", jsonErr.text);
128 error.set("source", jsonErr.source);
129 error.set("line", jsonErr.line);
130 error.set("column", jsonErr.column);
131 error.set("position", jsonErr.position);
132 response.set("error", error);
133 output = response.dump();
134 len = output.length();
135 cout.write((char *)&len, 4);
136 cout << output << endl;