12 |
|
#include <menes-etl/fnbind.hpp> |
13 |
|
#include <menes-ios/stdadapters.hpp> |
14 |
|
|
15 |
+ |
#include "Matcher.hpp" |
16 |
|
#include "Person.hpp" |
17 |
|
|
18 |
|
class Daemon |
19 |
|
{ |
20 |
+ |
protected: |
21 |
+ |
struct Client { api::TcpSocket socket; api::InternetAddress ip; Client() : |
22 |
+ |
ip(api::InternetAddress::Any) {} }; |
23 |
|
private: |
24 |
< |
virtual int handle(api::TcpSocket* client); |
24 |
> |
virtual int handle(Client* client); |
25 |
|
void headers(istream& sin, Environment& env); |
26 |
|
protected: |
27 |
|
enum Status { ok = 200, found = 302, seeOther, bad = 400, notFound = 404, |
29 |
|
notImplemented, version = 505 }; |
30 |
|
private: |
31 |
|
Status message(istream& sin, Environment& env, ostream& post); |
32 |
+ |
string reason(Status status); |
33 |
|
protected: |
34 |
|
static string crlf; |
35 |
< |
Daemon() {} |
35 |
> |
string log; |
36 |
> |
Daemon(const string& log) : log(log) {} |
37 |
|
void serve(int port, bool fork, Daemon* self); |
38 |
< |
istream& getline(istream& sin, string& line) { ::getline(sin, line, '\r'); |
39 |
< |
sin.get(); return sin; } |
38 |
> |
istream& getline(istream& sin, string& line) { std::getline(sin, line, |
39 |
> |
'\r'); sin.get(); return sin; } |
40 |
|
Status request(istream& sin, Environment& env, ostream& post, ostream& log); |
41 |
|
void response(ostream& sout, Status status); |
42 |
< |
void error(ostream& sout, Status status); |
42 |
> |
string server(); |
43 |
> |
streamsize error(ostream& sout, Status status); |
44 |
|
string date(bool log = false); |
45 |
|
public: |
46 |
< |
Daemon(int port, bool fork) { Person::configure(); serve(port, fork, this); |
47 |
< |
} |
46 |
> |
Daemon(int port, bool fork, const string& log) : log(log) { |
47 |
> |
Person::configure(); serve(port, fork, this); } |
48 |
|
virtual ~Daemon() {} |
49 |
|
}; |
50 |
|
|