1 |
// Host Update |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "Host.hpp" |
8 |
|
9 |
void Host::setSince(const string& since) |
10 |
{ |
11 |
struct tm when; |
12 |
|
13 |
strptime(since.c_str(), "%m/%d/%Y %H:%M:%S %Z", &when); |
14 |
|
15 |
time_t time = timegm(&when); |
16 |
|
17 |
memcpy(&when, localtime(&time), sizeof(struct tm)); |
18 |
|
19 |
char then[61]; |
20 |
|
21 |
strftime(then, 61, "%A, %B %e, %Y %l:%M:%S %p %Z", &when); |
22 |
|
23 |
this->since = then; |
24 |
} |
25 |
|
26 |
ostream& operator<<(ostream& output, Host& host) |
27 |
{ |
28 |
output << "<tr>\n"; |
29 |
|
30 |
if (host.host != "") output << "<td>" << host.host << "</td>\n"; |
31 |
if (host.name != "") output << "<td>" << host.name << "</td>\n"; |
32 |
if (host.address != "") output << "<td>" << host.address << "</td>\n"; |
33 |
if (host.platform != "") output << "<td>" << host.platform << "</td>\n"; |
34 |
if (host.since != "") output << "<td>" << host.since << "</td>\n"; |
35 |
|
36 |
output << "</tr>\n"; |
37 |
|
38 |
return output; |
39 |
} |
40 |
|
41 |
istream& operator>>(istream& input, Host& host) |
42 |
{ |
43 |
bool done = false; |
44 |
|
45 |
do |
46 |
{ |
47 |
switch (input.peek()) |
48 |
{ |
49 |
case 'h': |
50 |
if (host.host != "") |
51 |
{ |
52 |
done = true; |
53 |
|
54 |
continue; |
55 |
} |
56 |
break; |
57 |
case 'n': |
58 |
if (host.name != "") |
59 |
{ |
60 |
done = true; |
61 |
|
62 |
continue; |
63 |
} |
64 |
break; |
65 |
case 'a': |
66 |
if (host.address != "") |
67 |
{ |
68 |
done = true; |
69 |
|
70 |
continue; |
71 |
} |
72 |
break; |
73 |
case 'p': |
74 |
if (host.platform != "") |
75 |
{ |
76 |
done = true; |
77 |
|
78 |
continue; |
79 |
} |
80 |
break; |
81 |
case 's': |
82 |
if (host.since != "") |
83 |
{ |
84 |
done = true; |
85 |
|
86 |
continue; |
87 |
} |
88 |
break; |
89 |
default: |
90 |
done = true; |
91 |
continue; |
92 |
} |
93 |
|
94 |
string name, value; |
95 |
|
96 |
getline(input, name, '='); |
97 |
getline(input, value); |
98 |
|
99 |
if (name == "host") |
100 |
{ |
101 |
host.host = value; |
102 |
} |
103 |
else if (name == "name") |
104 |
{ |
105 |
host.name = value != "" ? value : " "; |
106 |
} |
107 |
else if (name == "address") |
108 |
{ |
109 |
host.address = value; |
110 |
} |
111 |
else if (name == "platform") |
112 |
{ |
113 |
host.platform = value; |
114 |
} |
115 |
else if (name == "since") |
116 |
{ |
117 |
host.setSince(value); |
118 |
} |
119 |
} |
120 |
while (!done && input.good()); |
121 |
|
122 |
return input; |
123 |
} |