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 21 by Douglas Thrift, 2003-11-10T20:16:12-08:00

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines