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__
28 #include "webserver.h"
30 typedef std::map
<std::string
, std::string
> CStringList
;
41 class CWebserverRequest
45 std::string rawbuffer
;
52 std::string tmpstring
;
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
);
62 std::string Client_Addr
;
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
¶ms
);
85 bool ParseFile(const std::string filename
, CStringList
¶ms
);
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);
120 void SendError(void);
123 #endif /* __chttpd_request_h__ */