cvs20080628 - trunk
[gitenigma.git] / boot / chttpd / request.h
blob7ad40e766f6d0e532926fa012812baa59bce6490
1 /*
2 * $Id: request.h,v 1.2 2005/10/18 11:30:19 digi_casi Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
5 * based on nhttpd (C) 2001/2002 Dirk Szymanski
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef __chttpd_request_h__
24 #define __chttpd_request_h__
26 #include <string>
27 #include <map>
28 #include "webserver.h"
30 typedef std::map<std::string, std::string> CStringList;
32 enum Method_Typ
34 M_UNKNOWN = 0,
35 M_POST = 1,
36 M_GET = 2,
37 M_PUT = 3,
38 M_HEAD = 4
41 class CWebserverRequest
43 protected:
44 bool RequestCanceled;
45 std::string rawbuffer;
46 int rawbuffer_len;
47 char *outbuf;
48 std::string Boundary;
50 long tmplong;
51 int tmpint;
52 std::string tmpstring;
54 bool CheckAuth(void);
55 std::string GetContentType(std::string ext);
56 std::string GetFileName(std::string path, std::string filename);
57 void SplitParameter(char *param_str);
58 void RewriteURL(void);
59 int OpenFile(std::string path, std::string filename);
61 public:
62 std::string Client_Addr;
63 int Socket;
64 unsigned long RequestNumber;
66 void printf(const char *fmt, ...);
68 bool SocketWrite(char const *text);
69 bool SocketWriteLn(char const *text);
70 bool SocketWriteData(char const *data, long length);
71 bool SocketWrite(const std::string text) { return SocketWrite(text.c_str()); }
72 bool SocketWriteLn(const std::string text) { return SocketWriteLn(text.c_str()); }
73 bool SendFile(const std::string path, const std::string filename);
75 void SendHTMLFooter(void);
76 void SendHTMLHeader(std::string Titel);
77 void SendPlainHeader(std::string contenttype = "text/plain");
78 void Send302(char const *URI);
79 void Send404Error(void);
80 void Send500Error(void);
82 bool Authenticate(void);
84 long ParseBuffer(char *file_buffer, long file_length, char *out_buffer, long out_buffer_size, CStringList &params);
85 bool ParseFile(const std::string filename, CStringList &params);
87 int Method;
88 int HttpStatus;
90 std::string Host;
91 std::string URL;
92 std::string Path;
93 std::string Filename;
94 std::string FileExt;
95 std::string Param_String;
97 CStringList ParameterList;
98 CStringList HeaderList;
100 std::map<int, std::string> boundaries;
102 class CWebserver *Parent;
104 CWebserverRequest(CWebserver *server);
105 ~CWebserverRequest(void);
107 bool GetRawRequest(void);
108 bool ParseRequest(void);
109 bool ParseParams(std::string param_string);
110 bool ParseFirstLine(std::string zeile);
111 bool ParseHeader(std::string header);
112 bool ParseBoundaries(std::string bounds);
113 static void URLDecode(std::string &encodedString);
114 bool HandleUpload(void);
115 bool HandleUpload(char *Name);
116 void PrintRequest(void);
117 bool SendResponse(void);
118 bool EndRequest(void);
119 void SendOk(void);
120 void SendError(void);
123 #endif /* __chttpd_request_h__ */