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 23 by Douglas Thrift, 2003-11-11T00:36:02-08:00 vs.
Revision 192 by Douglas Thrift, 2004-08-22T21:23:29-07:00

# Line 7 | Line 7
7   #include "HostUpdate.hpp"
8   #include "Host.hpp"
9  
10 < #ifdef _WIN32
10 > #ifndef _WIN32
11 >
12 > extern "C"
13 > {
14 > #include <resolv.h>
15 > }
16 >
17 > #else
18 >
19   #include <windows.h>
20 +
21   #endif
22  
23   int main(int argc, char* argv[])
24   {
25 + #ifndef _WIN32
26 +        res_init();
27 +
28 +        for (short index(0); index < MAXNS; ++index)
29 +        {
30 +                if (index + 1 < MAXNS)
31 +                {
32 +                        memcpy(&_res.nsaddr_list[index].sin_addr,
33 +                                &_res.nsaddr_list[index + 1].sin_addr, sizeof(in_addr_t));
34 +                }
35 +                else
36 +                {
37 +                        memset(&_res.nsaddr_list[index].sin_addr, 0, sizeof(in_addr_t));
38 +                }
39 +        }
40 + #endif
41 +        
42          HostUpdate update;
43  
44          return 0;
45   }
46  
47 < HostUpdate::HostUpdate()
47 > HostUpdate::HostUpdate() : host(false), name(false), address(false),
48 >        platform(false), since(false)
49   {
50          struct stat* hosts = new struct stat;
51  
# Line 40 | Line 67 | HostUpdate::HostUpdate()
67          {
68                  update(agent);
69          }
70 +        else if (agent.find("Host Update Sharp/") == 0 && method == "POST" &&
71 +                agent.find(" (") != string::npos && agent.find(')') != string::npos)
72 +        {
73 +                update(agent);
74 +        }
75          else
76          {
77                  display();
# Line 77 | Line 109 | void HostUpdate::parse(const string& met
109  
110   void HostUpdate::mode()
111   {
112 <        host = false, name = false, address = false, platform = false, since =
113 <                false;
82 <
83 <        for (multimap<string, string>::iterator itor = cgi.find("mode"); itor !=
84 <                cgi.upper_bound("mode"); itor++)
112 >        for (multimap<string, string>::iterator itor(cgi.find("mode"));
113 >                itor != cgi.upper_bound("mode") && itor != cgi.end(); itor++)
114          {
115 <                string mode = itor->second;
115 >                string mode(itor->second);
116  
117 <                for (string::iterator itor = mode.begin(); itor != mode.end(); itor++)
117 >                for (string::iterator itor(mode.begin()); itor != mode.end(); itor++)
118                  {
119 <                        char mode = *itor;
119 >                        char mode(*itor);
120  
121                          switch (mode)
122                          {
# Line 125 | Line 154 | void HostUpdate::update(const string& ag
154          if (itor == cgi.end()) return;
155          if (itor->second == "") return;
156  
157 <        string host = itor->second, name = sgetenv("REMOTE_HOST"), address =
158 <           sgetenv("REMOTE_ADDR");
157 >        string host(itor->second), name(sgetenv("REMOTE_HOST")),
158 >                address(sgetenv("REMOTE_ADDR"));
159  
160 <        string::size_type begin = agent.find('(') + 1, end = agent.rfind(')');
160 >        string::size_type begin(agent.find('(') + 1), end(agent.rfind(')'));
161  
162          if (begin >= end) return;
163  
164 <        string platform = agent.substr(begin, end - begin);
164 >        string platform(agent.substr(begin, end - begin));
165  
166          Host client(host, name, address, platform), saved(host);
167  
# Line 146 | Line 175 | void HostUpdate::display()
175          cout << "Content-Type: text/plain\n\n";
176  
177          {
178 <                bool request = false;
178 >                bool request(false);
179  
180 <                for (multimap<string, string>::iterator itor = cgi.find("host"); itor !=
181 <                        cgi.upper_bound("host"); itor++)
180 >                for (multimap<string, string>::iterator itor(cgi.find("host"));
181 >                        itor != cgi.upper_bound("host") && itor != cgi.end(); itor++)
182                  {
183 <                        if (itor->second != "")
183 >                        if (!itor->second.empty())
184                          {
185                                  Host host(itor->second);
186  
# Line 167 | Line 196 | void HostUpdate::display()
196          set<Host> hosts;
197  
198   #ifndef _WIN32
199 <        DIR* dir = opendir("hosts");
199 >        DIR* dir(opendir("hosts"));
200          struct dirent* ent;
201  
202          while ((ent = readdir(dir)) != NULL)
203          {
204 <                string file = ent->d_name;
204 >                string file(ent->d_name);
205  
206                  if (file == "." || file == "..") continue;
207  
# Line 184 | Line 213 | void HostUpdate::display()
213          closedir(dir);
214   #else
215          WIN32_FIND_DATA found;
216 <        HANDLE find = FindFirstFile("hosts\\*", &found);
216 >        HANDLE find(FindFirstFile("hosts\\*", &found));
217  
218          do
219          {
220 <                string file = found.cFileName;
220 >                string file(found.cFileName);
221  
222                  if (file == "." || file == "..") continue;
223  
# Line 201 | Line 230 | void HostUpdate::display()
230          FindClose(find);
231   #endif
232  
233 <        for (set<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
233 >        for (set<Host>::iterator itor(hosts.begin()); itor != hosts.end(); itor++)
234          {
235                  display(*itor);
236          }
# Line 214 | Line 243 | void HostUpdate::display(const Host& hos
243          if (address) cout << "address=" << host.getAddress() << '\n';
244          if (platform) cout << "platform=" << host.getPlatform() << '\n';
245  
246 <        string name = string("hosts") + slash + host.getHost();
246 >        string name(string("hosts") + slash + host.getHost());
247          struct stat file;
248  
249          if (since && stat(name.c_str(), &file) == 0)
# Line 228 | Line 257 | void HostUpdate::display(const Host& hos
257          else if (since)
258          {
259                  char since[20];
260 <                time_t* now = new time_t;
232 <
233 <                time(now);
234 <                strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(now));
260 >                time_t now(time(NULL));
261  
262 <                delete now;
262 >                strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(&now));
263  
264                  cout << "since=" << since << " GMT\n";
265          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines