1 |
Douglas Thrift |
164 |
// Smersh |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _Daemon_hpp_ |
8 |
|
|
#define _Daemon_hpp_ |
9 |
|
|
|
10 |
Douglas Thrift |
172 |
#include <menes-api/socket.hpp> |
11 |
Douglas Thrift |
173 |
#include <menes-api/threads.hpp> |
12 |
Douglas Thrift |
174 |
#include <menes-etl/fnbind.hpp> |
13 |
|
|
#include <menes-ios/stdadapters.hpp> |
14 |
Douglas Thrift |
164 |
|
15 |
Douglas Thrift |
172 |
#include "Person.hpp" |
16 |
|
|
|
17 |
Douglas Thrift |
164 |
class Daemon |
18 |
|
|
{ |
19 |
|
|
private: |
20 |
Douglas Thrift |
174 |
virtual int handle(api::TcpSocket* client); |
21 |
Douglas Thrift |
176 |
void headers(istream& sin, Environment& env); |
22 |
Douglas Thrift |
164 |
protected: |
23 |
Douglas Thrift |
175 |
enum Status { ok = 200, found = 302, seeOther, bad = 400, notFound = 404, |
24 |
Douglas Thrift |
176 |
lengthRequired = 411, mediaType = 415, serverError = 500, |
25 |
|
|
notImplemented, version = 505 }; |
26 |
|
|
private: |
27 |
|
|
Status message(istream& sin, Environment& env, ostream& post); |
28 |
|
|
protected: |
29 |
Douglas Thrift |
175 |
static string crlf; |
30 |
Douglas Thrift |
173 |
Daemon() {} |
31 |
|
|
void serve(int port, bool fork, Daemon* self); |
32 |
Douglas Thrift |
175 |
istream& getline(istream& sin, string& line) { ::getline(sin, line, '\r'); |
33 |
|
|
sin.get(); return sin; } |
34 |
|
|
Status request(istream& sin, Environment& env, ostream& post, ostream& log); |
35 |
Douglas Thrift |
176 |
void response(ostream& sout, Status status); |
36 |
|
|
void error(ostream& sout, Status status); |
37 |
|
|
string date(bool log = false); |
38 |
Douglas Thrift |
164 |
public: |
39 |
Douglas Thrift |
173 |
Daemon(int port, bool fork) { Person::configure(); serve(port, fork, this); |
40 |
|
|
} |
41 |
Douglas Thrift |
172 |
virtual ~Daemon() {} |
42 |
Douglas Thrift |
164 |
}; |
43 |
|
|
|
44 |
|
|
#endif // _Daemon_hpp_ |