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 15 by Douglas Thrift, 2003-11-09T16:51:42-08:00 vs.
Revision 20 by Douglas Thrift, 2003-11-10T20:11:13-08:00

# Line 6 | Line 6
6  
7   #include "HostUpdate.hpp"
8   #include "Host.hpp"
9 + #include <windows.h>
10  
11   int main(int argc, char* argv[])
12   {
# Line 41 | Line 42 | HostUpdate::HostUpdate()
42          }
43   }
44  
44 HostUpdate::~HostUpdate()
45 {
46        //
47 }
48
45   void HostUpdate::parse(const string& method)
46   {
47          string query;
# Line 80 | Line 76 | void HostUpdate::update(const string& ag
76          cout << "Content-Type: text/plain\n\n";
77  
78          multimap<string, string>::iterator itor = cgi.find("host");
79 <        
79 >
80          if (itor == cgi.end()) return;
81          if (itor->second == "") return;
82  
# Line 106 | Line 102 | void HostUpdate::display()
102          cout << "Content-Type: text/plain\n\n";
103  
104          set<Host> hosts;
105 +
106 + #ifndef _WIN32
107          DIR* dir = opendir("hosts");
108          struct dirent* ent;
109  
# Line 114 | Line 112 | void HostUpdate::display()
112                  string file = ent->d_name;
113  
114                  if (file == "." || file == "..") continue;
115 <                
115 >
116                  Host host(file);
117  
118                  hosts.insert(++host);
119          }
120  
121          closedir(dir);
122 + #else
123 +        WIN32_FIND_DATA found;
124 +        HANDLE find = FindFirstFile("hosts\\*", &found);
125 +
126 +        do
127 +        {
128 +                string file = found.cFileName;
129 +
130 +                if (file == "." || file == "..") continue;
131 +
132 +                Host host(file);
133 +
134 +                hosts.insert(++host);
135 +        }
136 +        while (FindNextFile(find, &found) != 0);
137 +
138 +        FindClose(find);
139 + #endif
140  
141          for (set<Host>::iterator itor = hosts.begin(); itor != hosts.end(); itor++)
142          {
143 <                Host host = *itor;
143 >                display(*itor);
144 >        }
145 > }
146 >
147 > void HostUpdate::display(const Host& host)
148 > {
149 >        cout << "host=" << host.getHost() << '\n'
150 >                << "name=" << host.getName() << '\n'
151 >                << "address=" << host.getAddress() << '\n'
152 >                << "platform=" << host.getPlatform() << '\n';
153 >
154 >        string name = string("hosts") + slash + host.getHost();
155 >        struct stat file;
156 >
157 >        if (stat(name.c_str(), &file) == 0)
158 >        {
159 >                char since[20];
160 >
161 >                strftime(since, 20, "%m/%d/%Y %H:%M:%S", gmtime(&file.st_mtime));
162  
163 <                cout << "host=" << host.getHost() << '\n'
130 <                        << "name=" << host.getName() << '\n'
131 <                        << "address=" << host.getAddress() << '\n'
132 <                        << "platform=" << host.getPlatform() << "\n\n";
163 >                cout << "since=" << since << " GMT\n";
164          }
165   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines