5 |
|
// $Id$ |
6 |
|
|
7 |
|
#include <arpa/inet.h> |
8 |
+ |
#include <sys/utsname.h> |
9 |
|
|
10 |
|
#include "Daemon.hpp" |
11 |
|
|
83 |
|
void Daemon::response(ostream& sout, Status status) |
84 |
|
{ |
85 |
|
sout << "HTTP/1.1 " << status << ' ' << reason(status) << crlf << "Date: " |
86 |
< |
<< date() << crlf << "Server: Smersh/0.9" << crlf |
86 |
> |
<< date() << crlf << "Server: " << server() << crlf |
87 |
|
<< "Connection: close" << crlf; |
88 |
|
} |
89 |
|
|
90 |
+ |
string Daemon::server() |
91 |
+ |
{ |
92 |
+ |
utsname system; |
93 |
+ |
|
94 |
+ |
uname(&system); |
95 |
+ |
|
96 |
+ |
return string("Smersh/0.9 (") + system.sysname + ')'; |
97 |
+ |
} |
98 |
+ |
|
99 |
|
streamsize Daemon::error(ostream& sout, Status status) |
100 |
|
{ |
101 |
|
string reason(this->reason(status)); |
103 |
|
|
104 |
|
error << "<html><head><title>" << status << ' ' << reason << "</title></hea" |
105 |
|
<< "d><body><h1>" << reason << "</h1><p>Mistakes were made, deal with t" |
106 |
< |
<< "hem.</p><hr /><address>Smersh/0.9</address></body></html>\n"; |
106 |
> |
<< "hem.</p><hr /><address>" << server() + "</address></body></html>\n"; |
107 |
|
sout << "Content-Length: " << error.str().length() << crlf |
108 |
|
<< "Content-Type: text/html; charset=UTF-8\r\n\r\n" << error.str(); |
109 |
|
|
169 |
|
ofstream fout(this->log.c_str(), ios_base::app); |
170 |
|
|
171 |
|
fout << ip(*client) << " - - " << date(true) << ' ' << log.str() << '\n'; |
172 |
+ |
sio << flush; |
173 |
+ |
|
174 |
+ |
client->ShutdownWrite(); |
175 |
|
|
176 |
|
delete client; |
177 |
|
} |
189 |
|
istringstream input(line); |
190 |
|
string name, value; |
191 |
|
|
192 |
< |
::getline(input, name, ':'); |
192 |
> |
std::getline(input, name, ':'); |
193 |
|
getline(input, value); |
194 |
|
|
195 |
|
for (char next(sin.peek()); next == ' ' || next == '\t'; next = |