Go to the documentation of this file. 1 #ifndef WIBBLE_NET_HTTP_H
2 #define WIBBLE_NET_HTTP_H
37 struct error :
public std::exception
49 virtual const char*
what()
const throw ();
89 std::map<std::string, std::string>
headers;
120 bool read_buf(std::string& res,
size_t size);
140 void send(
const std::string& buf);
143 void send_status_line(
int code,
const std::string&
msg,
const std::string& version =
"HTTP/1.0");
146 void send_server_header();
149 void send_date_header();
152 void send_extra_response_headers();
155 void send_result(
const std::string& content,
const std::string& content_type=
"text/html; charset=utf-8",
const std::string& filename=std::string());
158 void discard_input();
166 std::string pop_path_info();
173 std::string path_info_head();
187 virtual void parse(
const std::string& str) = 0;
193 virtual void parse(
const std::string& str);
199 virtual void parse(
const std::string& str);
219 std::map<std::string, std::string> headers,
220 const std::string& outdir,
221 const std::string& fname_blacklist,
222 const std::string& client_fname,
224 const std::string& boundary,
235 std::map<std::string, std::string> headers,
236 const std::string& outdir,
237 const std::string& fname_blacklist,
238 const std::string& client_fname,
240 const std::string& boundary,
241 size_t inputsize) = 0;
259 std::map<std::string, std::string> headers,
260 const std::string& outdir,
261 const std::string& fname_blacklist,
262 const std::string& client_fname,
264 const std::string& boundary,
277 std::map<std::string, std::string> headers,
278 const std::string& outdir,
279 const std::string& fname_blacklist,
280 const std::string& client_fname,
282 const std::string& boundary,
295 std::map<std::string, FileParam*>
files;
342 template<
typename TYPE>
343 TYPE*
add(
const std::string& name)
345 TYPE* res =
new TYPE;
351 void add(
const std::string& name,
Param* param);
354 void add(
const std::string& name,
FileParam* param);
361 Param* obtain_field(
const std::string& name);
368 FileParam* obtain_file_field(
const std::string& name);
371 Param* field(
const std::string& name);
374 FileParam* file_field(
const std::string& name);
380 void parse_urlencoded(
const std::string& qstring);
383 void parse_multipart(
net::http::Request& req,
size_t inputsize,
const std::string& content_type);
Single file upload field.
Definition: http.h:247
Iterator< typename I::value_type > iterator(I i)
Definition: iterator.h:123
bool read_until_boundary(int sock, const std::string &boundary, std::ostream &out, size_t max=0)
Read until boundary is found, sending data to the given ostream.
Definition: mime.cpp:159
File upload parameter.
Definition: http.h:205
wibble::Splitter space_splitter
Definition: http.h:90
const_iterator end() const
Definition: string.h:402
std::string joinpath(const std::string &path1, const std::string &path2)
Join two paths, adding slashes when appropriate.
Definition: string.h:257
virtual const char * what() const
Definition: http.cpp:38
bool read_buf(std::string &res, size_t size)
Read a fixed amount of data from the file descriptor.
Definition: http.cpp:159
FileParam * file_field(const std::string &name)
Get a file field by name.
Definition: http.cpp:564
FileParam * obtain_file_field(const std::string &name)
Get a normal fileld during form parsing.
Definition: http.cpp:544
error404()
Definition: http.h:62
Param * field(const std::string &name)
Get a field by name.
Definition: http.cpp:556
const_iterator begin() const
Split the string and iterate the resulting tokens.
Definition: string.h:401
bool read_headers(int sock, std::map< std::string, std::string > &headers)
Read MIME headers.
Definition: mime.cpp:68
int code
Definition: http.h:39
std::string toupper(const std::string &str)
Convert a string to uppercase.
Definition: string.h:228
bool match(const std::string &str, int flags=0)
Definition: regexp.cpp:74
std::string server_name
Definition: http.h:76
bool read_request()
Read request method and headers from sock.
Definition: http.cpp:83
std::string path_info_head()
Return the first component from path_info.
Definition: http.cpp:116
Params()
Definition: http.cpp:495
std::string method
Definition: http.h:86
size_t conf_max_input_size
Maximum size of POST input data.
Definition: http.h:298
size_t conf_max_field_size
Maximum size of field data for one non-file field.
Definition: http.h:301
void set_cgi_env()
Set the CGI environment variables for the current process using this request.
Definition: http.cpp:224
std::string peer_port
Definition: http.h:75
std::string desc
Definition: http.h:40
bool conf_accept_unknown_fields
Whether to accept unknown fields.
Definition: http.h:310
bool read(net::mime::Reader &mime_reader, std::map< std::string, std::string > headers, const std::string &outdir, const std::string &fname_blacklist, const std::string &client_fname, int sock, const std::string &boundary, size_t inputsize)
Handle a file upload from a multipart/form-data file upload part.
Definition: http.cpp:406
std::string version
Definition: http.h:88
~Params()
Definition: http.cpp:503
void send(const std::string &buf)
Send the content of buf, verbatim, to the client.
Definition: http.cpp:295
error(int code, const std::string &desc, const std::string &msg)
Definition: http.h:45
TYPE * add(const std::string &name)
Universal, automatic add method.
Definition: http.h:343
error400(const std::string &msg)
Definition: http.h:57
Multiple file uploads with the same name.
Definition: http.h:271
std::string urldecode(const std::string &str)
Decode an urlencoded string.
Definition: string.cpp:178
std::string fname
File pathname on the local file system.
Definition: http.h:211
virtual bool read(net::mime::Reader &mime_reader, std::map< std::string, std::string > headers, const std::string &outdir, const std::string &fname_blacklist, const std::string &client_fname, int sock, const std::string &boundary, size_t inputsize)
Handle a file upload from a multipart/form-data file upload part.
Definition: http.cpp:468
std::string url
Definition: http.h:87
int sock
Definition: http.h:72
virtual bool read(net::mime::Reader &mime_reader, std::map< std::string, std::string > headers, const std::string &outdir, const std::string &fname_blacklist, const std::string &client_fname, int sock, const std::string &boundary, size_t inputsize)
Handle a file upload from a multipart/form-data file upload part.
Definition: http.cpp:481
bool response_started
true if some response has already been sent to the client
Definition: http.h:84
std::string server_port
Definition: http.h:77
std::string conf_outdir
Directory where we write uploaded files.
Definition: http.h:326
std::string basename(const std::string &pathname)
Given a pathname, return the file name without its path.
Definition: string.h:124
error400()
Definition: http.h:56
ListIterator< List > end(List)
Definition: list.h:425
std::map< std::string, FileParam * > files
File parameters.
Definition: http.h:295
std::string script_name
Definition: http.h:78
Map< List, F > map(const List &l, const F &f)
Definition: list.h:381
std::string peer_hostname
Definition: http.h:73
virtual void parse(const std::string &str)=0
Parse the value of this parameter from the given unescaped string value.
void send_server_header()
Send the HTTP server header.
Definition: http.cpp:315
Base interface for GET or POST parameters.
Definition: http.h:177
std::map< std::string, std::string > extra_response_headers
Definition: http.h:94
wibble::net::mime::Reader mime_reader
Definition: http.h:92
std::string query_string
Definition: http.h:80
bool read_line(int sock, std::string &res)
Read a line from the file descriptor.
Definition: mime.cpp:37
Parse and store HTTP query parameters.
Definition: http.h:292
std::string path_info
Definition: http.h:79
void send_status_line(int code, const std::string &msg, const std::string &version="HTTP/1.0")
Send the HTTP status line.
Definition: http.cpp:307
std::string msg
Definition: http.h:41
error(int code, const std::string &desc)
Definition: http.h:43
Base class for system exceptions.
Definition: exception.h:396
void send_extra_response_headers()
Send headers in extra_response_headers.
Definition: http.cpp:341
void parse_post(net::http::Request &req)
Parse parameters from HTTP POST input.
Definition: http.cpp:687
std::vector< FileInfo > files
Definition: http.h:273
FileParamSingle(const std::string &fname=std::string())
If a file name is given, use its base name for storing the file; else, use the file name given by the...
Definition: http.cpp:463
std::string pop_path_info()
Remove the first component from path_info, append it to script_name and return it.
Definition: http.cpp:131
const_iterator end()
Definition: regexp.h:201
bool conf_accept_unknown_file_fields
Whether to accept unknown file upload fields.
Definition: http.h:319
Warning: the various iterators reuse the Regexps and therefore only one iteration of a Splitter can b...
Definition: regexp.h:155
bool read_headers()
Read HTTP headers.
Definition: http.cpp:217
FileInfo info
Definition: http.h:249
Split a string where a given substring is found.
Definition: string.h:314
ListIterator< List > begin(List l)
Definition: list.h:420
error404(const std::string &msg)
Definition: http.h:63
Infomation about one uploaded file.
Definition: http.h:208
size_t size(const std::string &file)
File size.
Definition: fs.cpp:287
virtual void parse(const std::string &str)
Parse the value of this parameter from the given unescaped string value.
Definition: http.cpp:399
void parse_urlencoded(const std::string &qstring)
Parse parameters from urlencoded form data.
Definition: http.cpp:586
const_iterator begin(const std::string &str)
Split the string and iterate the resulting tokens.
Definition: regexp.h:200
Split a string using a regular expression to match the token separators.
Definition: regexp.h:145
bool discard_until_boundary(int sock, const std::string &boundary)
Read until boundary is found, sending data to the given ostream.
Definition: mime.cpp:192
std::string server_software
String to use as server software "NAME/version".
Definition: http.h:82
virtual void send(Request &req)
Definition: http.cpp:44
void parse_multipart(net::http::Request &req, size_t inputsize, const std::string &content_type)
Parse parameters from multipart/form-data.
Definition: http.cpp:614
Param * obtain_field(const std::string &name)
Get a normal fileld during form parsing.
Definition: http.cpp:533
std::string fmtf(const char *f,...)
Definition: string.cpp:113
std::string peer_hostaddr
Definition: http.h:74
virtual ~error()
Definition: http.h:47
std::string client_fname
File pathname provided by the client.
Definition: http.h:213
virtual void parse(const std::string &str)
Parse the value of this parameter from the given unescaped string value.
Definition: http.cpp:394
std::string conf_fname_blacklist
String containing blacklist characters that are replaced with "_" in the file name.
Definition: http.h:335
std::map< std::string, std::string > headers
Definition: http.h:89
Multi-valued parameter.
Definition: http.h:197
void parse_get_or_post(net::http::Request &req)
Parse parameters as GET or POST according to request method.
Definition: http.cpp:572
virtual ~Param()
Definition: http.cpp:392
void send_date_header()
Send the HTTP date header.
Definition: http.cpp:322
virtual bool read(net::mime::Reader &mime_reader, std::map< std::string, std::string > headers, const std::string &outdir, const std::string &fname_blacklist, const std::string &client_fname, int sock, const std::string &boundary, size_t inputsize)=0
Handle a file upload from a multipart/form-data file upload part.
bool read_method()
Definition: http.cpp:183
void discard_input()
Discard all input from the socket.
Definition: http.cpp:375
Exception thrown when some consistency check fails.
Definition: exception.h:254
Single-valued parameter.
Definition: http.h:191
void send_result(const std::string &content, const std::string &content_type="text/html; charset=utf-8", const std::string &filename=std::string())
Send a string as result.
Definition: http.cpp:361
virtual ~FileParam()
Definition: http.cpp:404
void now(int *dst)
Fill in an int[6] with the UTC values for now.
Base class for exceptions for file I/O.
Definition: exception.h:420