• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

request.hpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003 * Copyright (C) 2007 Eddie Carle [eddie@erctech.org]                       *
00004 *                                                                          *
00005 * This file is part of fastcgi++.                                          *
00006 *                                                                          *
00007 * fastcgi++ is free software: you can redistribute it and/or modify it     *
00008 * under the terms of the GNU Lesser General Public License as  published   *
00009 * by the Free Software Foundation, either version 3 of the License, or (at *
00010 * your option) any later version.                                          *
00011 *                                                                          *
00012 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT *
00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    *
00014 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public     *
00015 * License for more details.                                                *
00016 *                                                                          *
00017 * You should have received a copy of the GNU Lesser General Public License *
00018 * along with fastcgi++.  If not, see <http://www.gnu.org/licenses/>.       *
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       // To dump data into the stream without it being code converted and bypassing the stream buffer call Fcgistream::dump(char* data, size_t size)
00070       // or Fcgistream::dump(std::basic_istream<char>& stream)
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

Generated on Fri Jan 21 2011 12:29:32 for fastcgi++ by  doxygen 1.7.2