ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

383 lines
10 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_HTTP_REQUEST_H
  9. #define CPPCMS_HTTP_REQUEST_H
  10. #include <cppcms/defs.h>
  11. #include <booster/noncopyable.h>
  12. #include <booster/hold_ptr.h>
  13. #include <booster/shared_ptr.h>
  14. #include <cppcms/http_content_type.h>
  15. #include <string>
  16. #include <map>
  17. #include <vector>
  18. namespace cppcms {
  19. namespace impl { namespace cgi { class connection; } }
  20. namespace http {
  21. class cookie;
  22. class file;
  23. class content_limits;
  24. class content_filter;
  25. class basic_content_filter;
  26. ///
  27. /// \brief This class represents all information related to the HTTP/CGI request.
  28. ///
  29. /// It is usually accessed via http::context or application class
  30. ///
  31. class CPPCMS_API request : public booster::noncopyable {
  32. public:
  33. // RFC 3875
  34. ///
  35. /// CGI AUTH_TYPE environment variable
  36. ///
  37. std::string auth_type();
  38. ///
  39. /// CGI CONTENT_LENGTH environment variable
  40. ///
  41. unsigned long long content_length();
  42. ///
  43. /// CGI CONTENT_TYPE environment variable
  44. ///
  45. std::string content_type();
  46. ///
  47. /// Parsed CGI CONTENT_TYPE environment variable
  48. ///
  49. cppcms::http::content_type content_type_parsed();
  50. ///
  51. /// CGI GATEWAY_INTERFACE environment variable
  52. ///
  53. std::string gateway_interface();
  54. ///
  55. /// CGI PATH_INFO environment variable
  56. ///
  57. std::string path_info();
  58. ///
  59. /// CGI PATH_TRANSLATED environment variable
  60. ///
  61. std::string path_translated();
  62. ///
  63. /// CGI QUERY_STRING environment variable
  64. ///
  65. std::string query_string();
  66. ///
  67. /// CGI REMOTE_ADDR environment variable
  68. ///
  69. std::string remote_addr();
  70. ///
  71. /// CGI REMOTE_HOST environment variable
  72. ///
  73. std::string remote_host();
  74. ///
  75. /// CGI REMOTE_IDENT environment variable
  76. ///
  77. std::string remote_ident();
  78. ///
  79. /// CGI REMOTE_USER environment variable
  80. ///
  81. std::string remote_user();
  82. ///
  83. /// CGI REQUEST_METHOD environment variable
  84. ///
  85. std::string request_method();
  86. ///
  87. /// CGI SCRIPT_NAME environment variable
  88. ///
  89. std::string script_name();
  90. ///
  91. /// CGI SERVER_NAME environment variable
  92. ///
  93. std::string server_name();
  94. ///
  95. /// CGI SERVER_PORT environment variable
  96. ///
  97. unsigned server_port();
  98. ///
  99. /// CGI SERVER_PROTOCOL environment variable
  100. ///
  101. std::string server_protocol();
  102. ///
  103. /// CGI SERVER_SOFTWARE environment variable
  104. ///
  105. std::string server_software();
  106. // RFC 2616 request headers
  107. ///
  108. /// CGI HTTP_ACCEPT variable representing Accept HTTP header
  109. ///
  110. std::string http_accept();
  111. ///
  112. /// CGI HTTP_ACCEPT_CHARSET variable representing Accept-Charset HTTP header
  113. ///
  114. std::string http_accept_charset();
  115. ///
  116. /// CGI HTTP_ACCEPT_ENCODING variable representing Accept-Encoding HTTP header
  117. ///
  118. std::string http_accept_encoding();
  119. ///
  120. /// CGI HTTP_ACCEPT_LANGUAGE variable representing Accept-Language HTTP header
  121. ///
  122. std::string http_accept_language();
  123. ///
  124. /// CGI HTTP_ACCEPT_RANGES variable representing Accept-Ranges HTTP header
  125. ///
  126. std::string http_accept_ranges();
  127. ///
  128. /// CGI HTTP_AUTHORIZATION variable representing Authorization HTTP header
  129. ///
  130. std::string http_authorization();
  131. ///
  132. /// CGI HTTP_CACHE_CONTROL variable representing Cache-Control HTTP header
  133. ///
  134. std::string http_cache_control();
  135. ///
  136. /// CGI HTTP_CONNECTION variable representing Connection HTTP header
  137. ///
  138. std::string http_connection();
  139. ///
  140. /// CGI HTTP_COOKIE variable representing Cookie HTTP header
  141. ///
  142. std::string http_cookie();
  143. ///
  144. /// CGI HTTP_EXPECT variable representing Expect HTTP header
  145. ///
  146. std::string http_expect();
  147. ///
  148. /// CGI HTTP_FORM variable representing Form HTTP header
  149. ///
  150. std::string http_form();
  151. ///
  152. /// CGI HTTP_HOST variable representing Host HTTP header
  153. ///
  154. std::string http_host();
  155. ///
  156. /// CGI HTTP_IF_MATCH variable representing If-Match HTTP header
  157. ///
  158. std::string http_if_match();
  159. ///
  160. /// CGI HTTP_IF_NONE_MATCH variable representing If-None-Match HTTP header
  161. ///
  162. std::string http_if_none_match();
  163. ///
  164. /// GGI HTTP_MAX_FORWARDS variable representing Http-Max-Forwards
  165. ///
  166. /// Returns a pair of {true,HTTP_MAX_FORWARDS} if set or {false,0} otherwise
  167. ///
  168. std::pair<bool,unsigned> http_max_forwards();
  169. ///
  170. /// CGI HTTP_PRAGMA variable representing Pragma HTTP header
  171. ///
  172. std::string http_pragma();
  173. ///
  174. /// CGI HTTP_PROXY_AUTHORIZATION variable representing Proxy-Authorization HTTP header
  175. ///
  176. std::string http_proxy_authorization();
  177. ///
  178. /// CGI HTTP_RANGE variable representing Range HTTP header
  179. ///
  180. std::string http_range();
  181. ///
  182. /// CGI HTTP_REFERER variable representing Referer HTTP header
  183. ///
  184. std::string http_referer();
  185. ///
  186. /// CGI HTTP_TE variable representing Te HTTP header
  187. ///
  188. std::string http_te();
  189. ///
  190. /// CGI HTTP_UPGRADE variable representing Upgrade HTTP header
  191. ///
  192. std::string http_upgrade();
  193. ///
  194. /// CGI HTTP_USER_AGENT variable representing User-Agent HTTP header
  195. ///
  196. std::string http_user_agent();
  197. ///
  198. /// CGI HTTP_VIA variable representing Via HTTP header
  199. ///
  200. std::string http_via();
  201. ///
  202. /// CGI HTTP_WARN variable representing Warn HTTP header
  203. ///
  204. std::string http_warn();
  205. ///
  206. /// Get CGI environment variable by name. Returns empty string if the variable is not set
  207. ///
  208. std::string getenv(std::string const &);
  209. ///
  210. /// Get CGI environment variable by name. Returns empty string if the variable is not set
  211. ///
  212. std::string getenv(char const *);
  213. ///
  214. /// Get CGI environment variable by name. Returns empty string if the variable is not set
  215. ///
  216. char const *cgetenv(char const *);
  217. ///
  218. /// Get map of all CGI environment variable as key-value pairs.
  219. ///
  220. std::map<std::string,std::string> getenv();
  221. ///
  222. /// Type that represents from-data key-value pairs
  223. ///
  224. typedef std::multimap<std::string,std::string> form_type;
  225. ///
  226. /// Type of a map of cookie name to the cookie value
  227. ///
  228. typedef std::map<std::string,cookie> cookies_type;
  229. ///
  230. /// Type that represents all files uploaded in this request
  231. ///
  232. typedef std::vector<booster::shared_ptr<file> > files_type;
  233. ///
  234. /// Get all cookies sent with this request
  235. ///
  236. cookies_type const &cookies();
  237. ///
  238. /// Get cookie by its name, if not assigned returns empty cookie
  239. ///
  240. cookie const &cookie_by_name(std::string const &name);
  241. ///
  242. /// Fetch GET value by name, if name not exists or more then one
  243. /// entry with same name exists, empty string is returned
  244. ///
  245. std::string get(std::string const &name);
  246. ///
  247. /// Fetch POST value by name, if name not exists or more then one
  248. /// entry with same name exists, empty string is returned
  249. ///
  250. std::string post(std::string const &name);
  251. ///
  252. /// form-data GET part of request
  253. ///
  254. form_type const &get();
  255. ///
  256. /// form-data POST part of request
  257. ///
  258. form_type const &post();
  259. ///
  260. /// form-data POST or GET according to reuqest_method()
  261. ///
  262. form_type const &post_or_get();
  263. ///
  264. /// Get all uploaded files
  265. ///
  266. files_type files();
  267. ///
  268. /// Access to raw bits of POST (content) data. If the content is empty if raw_content_filter is installed
  269. /// or multipart/form-data is handled the read_post_data().second will be 0;
  270. ///
  271. /// Note: when processing multipart/form-data returns chunk of zero size as
  272. /// such requests maybe huge (file uploads of multiple hundreds of MB or even GB) that are would be stored in
  273. /// temporary files instead of memory. In order to get access to POST data you'll have to use post(), get(), or files()
  274. /// member functions.
  275. ///
  276. std::pair<void *,size_t> raw_post_data();
  277. ///
  278. /// Get content limits for incoming data processing
  279. ///
  280. /// \ver{v1_2}
  281. content_limits &limits();
  282. ///
  283. /// Get installed content filter, returns 0 if it is not installed, no ownership is transfered
  284. ///
  285. /// \ver{v1_2}
  286. basic_content_filter *content_filter();
  287. ///
  288. /// Installs content filter. If another filter installed it is removed
  289. ///
  290. /// \ver{v1_2}
  291. void set_content_filter(basic_content_filter &flt);
  292. ///
  293. /// Installs new content filter (or removes existing), the ownership of new filter is transfered to the request object
  294. ///
  295. /// \ver{v1_2}
  296. void reset_content_filter(basic_content_filter *flt = 0);
  297. ///
  298. /// Release existing content filter owned by request
  299. ///
  300. /// \ver{v1_2}
  301. basic_content_filter *release_content_filter();
  302. ///
  303. /// Returns true when full request content is ready
  304. ///
  305. /// \ver{v1_2}
  306. bool is_ready();
  307. ///
  308. /// Set the size of the buffer for content that isn't loaded to memory directly,
  309. /// like for example multipart/form-data, default is defined in configuration as
  310. /// service.input_buffer_size and defaults to 65536
  311. ///
  312. /// \ver{v1_2}
  313. void setbuf(int size);
  314. public:
  315. /// \cond INTERNAL
  316. request(impl::cgi::connection &);
  317. ~request();
  318. /// \endcond
  319. private:
  320. friend class context;
  321. friend class impl::cgi::connection;
  322. void set_filter(basic_content_filter *ptr,bool owns);
  323. int on_content_start();
  324. void on_error();
  325. int on_content_progress(size_t n);
  326. std::pair<char *,size_t > get_buffer();
  327. bool size_ok(file &f,long long size);
  328. std::pair<char *,size_t> get_content_buffer();
  329. bool prepare();
  330. bool parse_cookies();
  331. std::string urlencoded_decode(char const *,char const *);
  332. bool parse_form_urlencoded(char const *begin,char const *end,form_type &out);
  333. bool read_key_value(
  334. std::string::const_iterator &p,
  335. std::string::const_iterator e,
  336. std::string &key,
  337. std::string &value);
  338. struct _data;
  339. form_type get_;
  340. form_type post_;
  341. files_type files_;
  342. cookies_type cookies_;
  343. cppcms::http::content_type content_type_;
  344. booster::hold_ptr<_data> d;
  345. impl::cgi::connection *conn_;
  346. };
  347. } // namespace http
  348. } // namespace cppcms
  349. #endif