d16d09fb681b0b57f34dd3be2cb5a432d9b0c982
[gssweb.git] / json_gssapi / main.cpp
1 #include <commands/GSSImportName.h>
2 #include <commands/GSSInitSecContext.h>
3 #include <commands/GSSAcquireCred.h>
4 #include <datamodel/GSSBuffer.h>
5 #include <exception>
6 #include <iostream>
7 #include <string>
8 #include <unistd.h>
9 #include <util_json.h>
10 #include <GSSRequest.h>
11
12
13 using std::cin;
14 using std::cout;
15 using std::endl;
16 using std::getline;
17 using std::string;
18
19 int main(int argc, char **argv) {
20   /* Variables */
21   string output;
22   char *input;
23   int len;
24   ssize_t readTotal, readThisRound, readRemaining;
25   
26   /* Error checking */
27   
28   /* Setup */
29   
30   /* Main processing */
31   do 
32   {
33     // Read 32 bit length
34     len = 0;
35     readThisRound = readTotal = 0;
36     while(4 != readTotal)
37     {
38       readThisRound = read(0, ((&len) + readTotal), 4 - readTotal);
39       readTotal += readThisRound;
40     }
41     
42     // Reads the number of bytes indicated by the above read
43     input = new char[len + 1];
44     readTotal = readThisRound = 0;
45     while (readTotal < len)
46     {
47       readRemaining = len - readTotal;
48       readThisRound = read( 0, &(input[readTotal]), readRemaining);
49       if (-1 == readThisRound)
50         break;
51       else
52         readTotal += readThisRound;
53     }
54     // ... and null-terminate it
55     input[len] = '\0';
56     
57     
58     GSSRequest *req = new GSSRequest(string(input));
59     req->execute();
60     output = req->getResponse();
61     len = output.length();
62     
63     cout.write((char *)&len, 4);
64     cout << output;
65     cout.flush();
66     
67   } while(1);
68   
69   return 0;
70 }