fastcgi++
request.hpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3 * Copyright (C) 2007 Eddie Carle [eddie@erctech.org] *
4 * *
5 * This file is part of fastcgi++. *
6 * *
7 * fastcgi++ is free software: you can redistribute it and/or modify it *
8 * under the terms of the GNU Lesser General Public License as published *
9 * by the Free Software Foundation, either version 3 of the License, or (at *
10 * your option) any later version. *
11 * *
12 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT *
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public *
15 * License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public License *
18 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
19 ****************************************************************************/
20 
21 
22 #ifndef REQUEST_HPP
23 #define REQUEST_HPP
24 
25 #include <queue>
26 #include <map>
27 #include <string>
28 #include <locale>
29 
30 #include <boost/shared_array.hpp>
31 #include <boost/thread.hpp>
32 #include <boost/function.hpp>
33 
35 #include <fastcgi++/protocol.hpp>
36 #include <fastcgi++/exceptions.hpp>
37 #include <fastcgi++/fcgistream.hpp>
38 #include <fastcgi++/http.hpp>
39 
41 namespace Fastcgipp
42 {
43  template<class T> class Manager;
44 
46 
61  template<class charT> class Request
62  {
63  public:
65 
70  Request(const size_t maxPostSize=0): m_maxPostSize(maxPostSize), state(Protocol::PARAMS) { setloc(std::locale::classic()); out.exceptions(std::ios_base::badbit | std::ios_base::failbit | std::ios_base::eofbit); m_environment.clearPostBuffer(); }
71 
74 
75  // To dump data into the stream without it being code converted and bypassing the stream buffer call Fcgistream::dump(char* data, size_t size)
76  // or Fcgistream::dump(std::basic_istream<char>& stream)
77 
79 
83 
85 
89 
91 
98  virtual void errorHandler(const std::exception& error);
99 
101  virtual void bigPostErrorHandler();
102 
104  Protocol::Role role() const { return m_role; }
105 
107 
118  const boost::function<void(Message)>& callback() const { return m_callback; }
119 
121 
130  void setloc(std::locale loc_){ out.imbue(loc_); err.imbue(loc_); }
131 
133 
136  const std::locale& getloc(){ return loc; }
137 
138  protected:
140 
148  virtual bool response() =0;
149 
151 
161  virtual void inHandler(int bytesReceived) { };
162 
164 
170  const Message& message() const { return m_message; }
171 
172  private:
173  template<class T> friend class Manager;
174 
176  std::locale loc;
177 
179 
186 
188 
199  boost::function<void(Message)> m_callback;
200 
203 
205 
209  class Messages: public std::queue<Message>, public boost::mutex {};
212 
214  const size_t m_maxPostSize;
215 
217 
224  bool handler();
232  bool killCon;
236  void complete();
238 
247  void set(Protocol::FullId id_, Transceiver& transceiver_, Protocol::Role role_, bool killCon_, boost::function<void(Message)> callback_)
248  {
249  killCon=killCon_;
250  id=id_;
251  transceiver=&transceiver_;
252  m_role=role_;
253  m_callback=callback_;
254 
255  err.set(id_, transceiver_, Protocol::ERR);
256  out.set(id_, transceiver_, Protocol::OUT);
257  }
258  };
259 
261  namespace Exceptions
262  {
266  struct RecordsOutOfOrder: public std::exception
267  {
268  const char* what() const throw() { return "FastCGI records received out of order from server."; }
269  };
270 
274  struct UnknownContentType: public std::exception
275  {
276  const char* what() const throw() { return "Client sent unknown content type."; }
277  };
278  }
279 }
280 
281 #endif