ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/HostStatus.cpp
Revision: 34
Committed: 2003-11-15T01:06:43-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 1903 byte(s)
Log Message:
It should work, but it doesn't.

File Contents

# User Rev Content
1 Douglas Thrift 27 // Host Status
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "HostStatus.hpp"
8 Douglas Thrift 31 #include "Host.hpp"
9 Douglas Thrift 27
10     int main(int argc, char* argv[])
11     {
12     HostStatus status;
13    
14     return 0;
15     }
16    
17     HostStatus::HostStatus()
18     {
19 Douglas Thrift 32 sputenv("TZ=:America/Los_Angeles");
20    
21 Douglas Thrift 29 string method = sgetenv("REQUEST_METHOD");
22    
23     parse(method);
24    
25     multimap<string, string>::iterator itor = cgi.find("format");
26    
27     if (itor != cgi.end())
28     {
29     string format = itor->second;
30    
31     if (format == "t")
32     {
33     this->format = table;
34     }
35     else
36     {
37     this->format = page;
38     }
39     }
40    
41     display(method);
42 Douglas Thrift 27 }
43 Douglas Thrift 29
44     void HostStatus::parse(const string& method)
45     {
46     string query;
47    
48     if (method == "POST")
49     {
50     getline(cin, query);
51     }
52     else
53     {
54     query = sgetenv("QUERY_STRING");
55     }
56    
57     if (query == "") return;
58    
59     istringstream input(query);
60    
61     do
62     {
63     string name, value;
64    
65     getline(input, name, '=');
66     getline(input, value, '&');
67    
68     cgi.insert(pair<string, string>(name, value));
69     }
70     while (input.good());
71     }
72    
73     void HostStatus::display(const string& method)
74     {
75     cout << "Content-Type: text/html\n\n";
76    
77     if (method == "POST") sunsetenv("HTTP_USER_AGENT");
78    
79     pstream hostupdate("./hostupdate.cgi");
80    
81     if (method == "POST")
82     {
83     for (multimap<string, string>::iterator itor = cgi.begin(); itor !=
84     cgi.end(); itor++)
85     {
86     hostupdate << itor->first << '=' << itor->second << '&';
87     }
88    
89 Douglas Thrift 30 hostupdate << '\n' << flush;
90 Douglas Thrift 29 }
91    
92 Douglas Thrift 34 hostupdate.ignore(string::npos, '\n');
93     hostupdate.ignore(string::npos, '\n');
94    
95     list<Host> hosts;
96     bool done = false;
97    
98     do
99 Douglas Thrift 29 {
100 Douglas Thrift 34 Host host;
101 Douglas Thrift 29
102 Douglas Thrift 34 hostupdate >> host;
103 Douglas Thrift 29
104 Douglas Thrift 34 hosts.push_back(host);
105    
106     switch (hostupdate.peek())
107     {
108     case 'h':
109     case 'n':
110     case 'a':
111     case 'p':
112     case 's':
113     break;
114     default:
115     done = true;
116     break;
117     }
118 Douglas Thrift 29 }
119 Douglas Thrift 34 while (!done && hostupdate.good());
120    
121     if (format == page) header();
122    
123     for (list<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
124     {
125     Host host = *itor;
126    
127     cout << host << flush;
128     }
129    
130     if (format == page) footer();
131 Douglas Thrift 29 }

Properties

Name Value
svn:eol-style native
svn:keywords Id