ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Daemon.hpp
Revision: 253
Committed: 2004-09-13T23:31:24-07:00 (20 years, 9 months ago) by Douglas Thrift
File size: 1511 byte(s)
Log Message:
This is a bit futzy!?

File Contents

# User Rev Content
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 180 #include <arpa/inet.h>
11     #include <sys/utsname.h>
12 Douglas Thrift 172 #include <menes-api/socket.hpp>
13 Douglas Thrift 173 #include <menes-api/threads.hpp>
14 Douglas Thrift 174 #include <menes-etl/fnbind.hpp>
15     #include <menes-ios/stdadapters.hpp>
16 Douglas Thrift 164
17 Douglas Thrift 179 #include "Matcher.hpp"
18 Douglas Thrift 172 #include "Person.hpp"
19    
20 Douglas Thrift 164 class Daemon
21     {
22 Douglas Thrift 179 protected:
23 Douglas Thrift 184 struct Client
24     {
25     api::InternetAddress ip;
26 Douglas Thrift 253 ext::StackReference<api::Socket> socket;
27 Douglas Thrift 184 Client(api::TcpSocket& server) : socket(server, &ip) {}
28     };
29 Douglas Thrift 175 enum Status { ok = 200, found = 302, seeOther, bad = 400, notFound = 404,
30 Douglas Thrift 176 lengthRequired = 411, mediaType = 415, serverError = 500,
31     notImplemented, version = 505 };
32     private:
33 Douglas Thrift 181 int port;
34 Douglas Thrift 180 virtual int handle(Client* client);
35     void headers(istream& sin, Environment& env);
36 Douglas Thrift 176 Status message(istream& sin, Environment& env, ostream& post);
37     protected:
38 Douglas Thrift 175 static string crlf;
39 Douglas Thrift 177 string log;
40 Douglas Thrift 253 void serve(Daemon* self);
41 Douglas Thrift 178 istream& getline(istream& sin, string& line) { std::getline(sin, line,
42     '\r'); sin.get(); return sin; }
43 Douglas Thrift 175 Status request(istream& sin, Environment& env, ostream& post, ostream& log);
44 Douglas Thrift 176 void response(ostream& sout, Status status);
45 Douglas Thrift 180 string reason(Status status);
46 Douglas Thrift 178 string server();
47 Douglas Thrift 181 string server(const Environment& env);
48     streamsize error(ostream& sout, Status status, const Environment& env);
49 Douglas Thrift 176 string date(bool log = false);
50 Douglas Thrift 164 public:
51 Douglas Thrift 253 Daemon(int port, const string& log, bool run = true) : port(port), log(log)
52     { if (run) { Person::configure(); serve(this); } }
53 Douglas Thrift 172 virtual ~Daemon() {}
54 Douglas Thrift 164 };
55    
56     #endif // _Daemon_hpp_

Properties

Name Value
svn:eol-style native
svn:keywords Id