trunk 20080912
[gitenigma.git] / include / lib / system / httpd.h
blob8cdeb754893e9087e851c150ac9f3eec4de39f15
1 #ifndef __httpd_h
2 #define __httpd_h
4 #include <asm/types.h>
5 #include <map>
7 #include <lib/base/eptrlist.h>
8 #include <lib/base/ebase.h>
9 #include <lib/base/estring.h>
10 #include <lib/base/eerror.h>
11 #include <lib/socket/socket.h>
12 #include <lib/socket/serversocket.h>
14 class eHTTPConnection;
15 class eHTTPDataSource;
16 class eHTTPD;
18 class eHTTPPathResolver
20 public:
21 virtual ~eHTTPPathResolver() {};
22 virtual eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn)=0;
25 class eHTTPLogResolver: public eHTTPPathResolver
27 public:
28 eHTTPLogResolver();
29 eHTTPDataSource *getDataSource(eString request, eString path, eHTTPConnection *conn);
32 class eHTTPDataSource
34 protected:
35 eHTTPConnection *connection;
36 public:
37 eHTTPDataSource(eHTTPConnection *c);
38 virtual ~eHTTPDataSource();
39 virtual void haveData(void *data, int len);
40 virtual int doWrite(int bytes); // number of written bytes, -1 for "no more"
43 class eHTTPError: public eHTTPDataSource
45 int errcode;
46 public:
47 eHTTPError(eHTTPConnection *c, int errcode);
48 ~eHTTPError() { }
49 void haveData();
50 int doWrite(int bytes);
53 class eHTTPD: public eServerSocket
55 friend class eHTTPConnection;
56 ePtrList<eHTTPPathResolver> resolver;
57 eMainloop *ml;
58 public:
59 eHTTPD(int port, eMainloop *ml);
60 void newConnection(int socket);
62 void addResolver(eHTTPPathResolver *r) { resolver.push_back(r); }
63 void removeResolver(eHTTPPathResolver *r) { resolver.remove(r); }
67 class eHTTPConnection: public eSocket
69 void doError(int error);
71 int getLine(eString &line);
73 int processLocalState();
74 int processRemoteState();
75 void writeString(const char *data);
77 eHTTPDataSource *data;
78 eHTTPD *parent;
80 int buffersize;
81 private:
82 void readData();
83 void gotError(int);
84 void bytesWritten(int);
85 void hostConnected();
86 void destruct();
87 public:
88 Signal1<void,int> transferDone;
89 Signal1<eHTTPDataSource*,eHTTPConnection*> createDataSource;
90 enum
94 < GET / HTTP/1.0
95 < If-modified-since: bla
97 < Data
98 > 200 OK HTTP/1.0
99 > Content-Type: text/html
101 > Data
104 stateWait, stateRequest, stateResponse, stateHeader, stateData, stateDone, stateClose
106 int localstate, remotestate;
107 int persistent;
109 eHTTPConnection(int socket, int issocket, eHTTPD *parent, int persistent=0);
110 eHTTPConnection(eMainloop *ml); // ready to do "connectToHost"
111 static eHTTPConnection *doRequest(const char *uri, eMainloop *ml, int *error=0);
112 void start();
113 void gotHangup();
114 ~eHTTPConnection();
116 // stateRequest
117 eString request, requestpath, httpversion;
118 int is09;
120 // stateResponse
122 int code;
123 eString code_descr;
125 std::map<eString,eString> remote_header, local_header;
127 // stateData
128 int content_length, content_length_remaining;
130 eString RemoteHost() { return parent->RemoteHost(); }
133 #endif