ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdate/HostUpdate.cpp
(Generate patch)

Comparing HostUpdate/HostUpdate.cpp (file contents):
Revision 21 by Douglas Thrift, 2003-11-10T20:16:12-08:00 vs.
Revision 22 by Douglas Thrift, 2003-11-10T23:58:38-08:00

# Line 33 | Line 33 | HostUpdate::HostUpdate()
33          string method = sgetenv("REQUEST_METHOD");
34  
35          parse(method);
36 +        mode();
37  
38          if (agent.find("Host Update/") == 0 && method == "POST" && agent.find(" (")
39                  != string::npos && agent.find(") libwww-perl/") != string::npos)
# Line 74 | Line 75 | void HostUpdate::parse(const string& met
75          while (input.good());
76   }
77  
78 + void HostUpdate::mode()
79 + {
80 +        host = false, name = false, address = false, platform = false, since =
81 +                false;
82 +
83 +        for (multimap<string, string>::iterator itor = cgi.find("mode"); itor !=
84 +                cgi.upper_bound("mode"); itor++)
85 +        {
86 +                string mode = itor->second;
87 +
88 +                for (string::iterator itor = mode.begin(); itor != mode.end(); itor++)
89 +                {
90 +                        char mode = *itor;
91 +
92 +                        switch (mode)
93 +                        {
94 +                        case 'h':
95 +                                if (!host) host = true;
96 +                                break;
97 +                        case 'n':
98 +                                if (!name) name = true;
99 +                                break;
100 +                        case 'a':
101 +                                if (!address) address = true;
102 +                                break;
103 +                        case 'p':
104 +                                if (!platform) platform = true;
105 +                                break;
106 +                        case 's':
107 +                                if (!since) since = true;
108 +                                break;
109 +                        default:
110 +                                break;
111 +                        }
112 +                }
113 +        }
114 +
115 +        if (!host && !name && !address && !platform && !since) host = true, name =
116 +                true, address = true, platform = true, since = true;
117 + }
118 +
119   void HostUpdate::update(const string& agent)
120   {
121          cout << "Content-Type: text/plain\n\n";
# Line 92 | Line 134 | void HostUpdate::update(const string& ag
134  
135          Host client(host, name, address, platform), saved(host);
136  
95        cout << "host=" << client.getHost() << '\n'
96                << "name=" << client.getName() << '\n'
97                << "address=" << client.getAddress() << '\n'
98                << "platform=" << client.getPlatform() << '\n';
99
137          if (client != ++saved) client--;
138 +
139 +        display(client);
140   }
141  
142   void HostUpdate::display()
143   {
144          cout << "Content-Type: text/plain\n\n";
145  
146 +        {
147 +                bool request = false;
148 +
149 +                for (multimap<string, string>::iterator itor = cgi.find("host"); itor !=
150 +                        cgi.upper_bound("host"); itor++)
151 +                {
152 +                        if (itor->second != "")
153 +                        {
154 +                                Host host(itor->second);
155 +
156 +                                display(++host);
157 +
158 +                                if (!request) request = true;
159 +                        }
160 +                }
161 +
162 +                if (request) return;
163 +        }
164 +
165          set<Host> hosts;
166  
167   #ifndef _WIN32
# Line 149 | Line 207 | void HostUpdate::display()
207  
208   void HostUpdate::display(const Host& host)
209   {
210 <        cout << "host=" << host.getHost() << '\n'
211 <                << "name=" << host.getName() << '\n'
212 <                << "address=" << host.getAddress() << '\n'
213 <                << "platform=" << host.getPlatform() << '\n';
210 >        if (this->host) cout << "host=" << host.getHost() << '\n';
211 >        if (name) cout << "name=" << host.getName() << '\n';
212 >        if (address) cout << "address=" << host.getAddress() << '\n';
213 >        if (platform) cout << "platform=" << host.getPlatform() << '\n';
214  
215          string name = string("hosts") + slash + host.getHost();
216          struct stat file;
217  
218 <        if (stat(name.c_str(), &file) == 0)
218 >        if (since && stat(name.c_str(), &file) == 0)
219          {
220                  char since[20];
221  
# Line 165 | Line 223 | void HostUpdate::display(const Host& hos
223  
224                  cout << "since=" << since << " GMT\n";
225          }
226 +        else if (since)
227 +        {
228 +                char since[20];
229 +                time_t* now = new time_t;
230 +
231 +                time(now);
232 +                strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(now));
233 +
234 +                delete now;
235 +
236 +                cout << "since=" << since << " GMT\n";
237 +        }
238   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines