ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Daemon.hpp
(Generate patch)

Comparing Smersh/Daemon.hpp (file contents):
Revision 172 by Douglas Thrift, 2004-06-20T22:47:13-07:00 vs.
Revision 181 by Douglas Thrift, 2004-07-03T05:41:00-07:00

# Line 7 | Line 7
7   #ifndef _Daemon_hpp_
8   #define _Daemon_hpp_
9  
10 + #include <arpa/inet.h>
11 + #include <sys/utsname.h>
12   #include <menes-api/socket.hpp>
13 + #include <menes-api/threads.hpp>
14 + #include <menes-etl/fnbind.hpp>
15 + #include <menes-ios/stdadapters.hpp>
16  
17 + #include "Matcher.hpp"
18   #include "Person.hpp"
19  
20   class Daemon
21   {
22 + protected:
23 +        struct Client { api::TcpSocket socket; api::InternetAddress ip; Client() :
24 +                ip(api::InternetAddress::Any) {} };
25 +        enum Status { ok = 200, found = 302, seeOther, bad = 400, notFound = 404,
26 +                lengthRequired = 411, mediaType = 415, serverError = 500,
27 +                notImplemented, version = 505 };
28   private:
29          int port;
30 <        virtual void handle();
30 >        virtual int handle(Client* client);
31 >        void headers(istream& sin, Environment& env);
32 >        Status message(istream& sin, Environment& env, ostream& post);
33   protected:
34 <        Daemon(int port) : port(port) {}
34 >        static string crlf;
35 >        string log;
36 >        Daemon(int port, const string& log) : port(port), log(log) {}
37          void serve(bool fork, Daemon* self);
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 +        string reason(Status status);
43 +        string server();
44 +        string server(const Environment& env);
45 +        streamsize error(ostream& sout, Status status, const Environment& env);
46 +        string date(bool log = false);
47   public:
48 <        Daemon(int port, bool fork) : port(port) { serve(fork, this); }
48 >        Daemon(int port, bool fork, const string& log) : port(port), log(log) {
49 >                Person::configure(); serve(fork, this); }
50          virtual ~Daemon() {}
51   };
52  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines