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(): status(PARAMETERS), loc(std::locale::classic()) { out.imbue(loc); err.imbue(loc); out.exceptions(std::ios_base::badbit | std::ios_base::failbit | std::ios_base::eofbit); session.clearPostBuffer(); }
00064
00065 protected:
00067 Http::Session<charT> session;
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 std::locale loc;
00110
00112
00118 Message message;
00119
00121
00129 void setloc(std::locale loc_) { loc=loc_; out.imbue(loc); }
00130
00132
00143 boost::function<void(Message)> callback;
00144 private:
00146
00150 class Messages: public std::queue<Message>, public boost::mutex {};
00152 Messages messages;
00153
00155
00162 bool handler();
00163 template <typename T> friend class Manager;
00165 Transceiver* transceiver;
00167 Protocol::Role role;
00169 Protocol::FullId id;
00171 bool killCon;
00173 enum Status { PARAMETERS, POST, RESPONSE } status;
00175 void complete();
00177
00186 void set(Protocol::FullId id_, Transceiver& transceiver_, Protocol::Role role_, bool killCon_, boost::function<void(Message)> callback_)
00187 {
00188 killCon=killCon_;
00189 id=id_;
00190 transceiver=&transceiver_;
00191 role=role_;
00192 callback=callback_;
00193
00194 err.set(id_, transceiver_, Protocol::ERR);
00195 out.set(id_, transceiver_, Protocol::OUT);
00196 }
00197 };
00198 }
00199
00200 #endif