Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef REQUEST_HPP
00023 #define REQUEST_HPP
00024
00025 #include <queue>
00026 #include <map>
00027 #include <string>
00028 #include <locale>
00029
00030 #include <boost/shared_array.hpp>
00031 #include <boost/thread.hpp>
00032 #include <boost/function.hpp>
00033
00034 #include <fastcgi++/protocol.hpp>
00035 #include <fastcgi++/exceptions.hpp>
00036 #include <fastcgi++/transceiver.hpp>
00037 #include <fastcgi++/fcgistream.hpp>
00038 #include <fastcgi++/http.hpp>
00039
00041 namespace Fastcgipp
00042 {
00044
00059 template<class charT> class Request
00060 {
00061 public:
00063 Request(): state(Protocol::PARAMS) { setloc(std::locale::classic()); out.exceptions(std::ios_base::badbit | std::ios_base::failbit | std::ios_base::eofbit); m_environment.clearPostBuffer(); }
00064
00065 protected:
00067 const Http::Environment<charT>& environment() const { return m_environment; }
00068
00069
00070
00071
00073
00076 Fcgistream<charT, std::char_traits<charT> > out;
00077
00079
00082 Fcgistream<charT, std::char_traits<charT> > err;
00083
00085
00093 virtual bool response() =0;
00094
00096
00106 virtual void inHandler(int bytesReceived) { };
00107
00109
00116 virtual void errorHandler(const std::exception& error);
00117
00119 std::locale loc;
00120
00122
00128 const Message& message() const { return m_message; }
00129
00131
00140 void setloc(std::locale loc_);
00141
00143
00154 const boost::function<void(Message)>& callback() const { return m_callback; }
00155
00157 Protocol::Role role() const { return m_role; }
00158
00159 private:
00161
00167 Message m_message;
00168
00170
00181 boost::function<void(Message)> m_callback;
00182
00184 Http::Environment<charT> m_environment;
00185
00187
00191 class Messages: public std::queue<Message>, public boost::mutex {};
00193 Messages messages;
00194
00196
00203 bool handler();
00204 template <class T> friend class Manager;
00206 Transceiver* transceiver;
00208 Protocol::Role m_role;
00210 Protocol::FullId id;
00212 bool killCon;
00214 Protocol::RecordType state;
00216 void complete();
00218
00227 void set(Protocol::FullId id_, Transceiver& transceiver_, Protocol::Role role_, bool killCon_, boost::function<void(Message)> callback_)
00228 {
00229 killCon=killCon_;
00230 id=id_;
00231 transceiver=&transceiver_;
00232 m_role=role_;
00233 m_callback=callback_;
00234
00235 err.set(id_, transceiver_, Protocol::ERR);
00236 out.set(id_, transceiver_, Protocol::OUT);
00237 }
00238 };
00239
00241 namespace Exceptions
00242 {
00246 struct RecordsOutOfOrder: public std::exception
00247 {
00248 const char* what() const throw() { return "FastCGI records received out of order from server."; }
00249 };
00250
00254 struct UnknownContentType: public std::exception
00255 {
00256 const char* what() const throw() { return "Client sent unknown content type."; }
00257 };
00258 }
00259 }
00260
00261 #endif