SingleHostClientHttpSession.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #ifndef PROTOCOLS__HTTP__SINGLE_HOST_CLIENT_HTTP_SESSION_H
00024 #define PROTOCOLS__HTTP__SINGLE_HOST_CLIENT_HTTP_SESSION_H
00025 
00026 #include "Imports.h"
00027 #include "ClientHttpSession.h"
00028 #include "RequestHeader.h"
00029 #include "ResponseHeader.h"
00030 
00031 namespace Protocols {
00032 namespace Http {
00033 
00034 class ClientHttpSessionStatus;
00035 class BodyEnd; // Needed for the receive() overload.
00036 
00038 
00061 class SingleHostClientHttpSession : public ClientHttpSession,
00062                                     public SessionStatus
00063 {
00064     CALITKO_TESTABLE
00065     REFERENCE_OBJECT (SingleHostClientHttpSession)
00066 
00067 public:
00068                         SingleHostClientHttpSession (ClientHttpSessionStatus *,
00069                                                      Session *);
00070                         ~SingleHostClientHttpSession();
00071 
00072     // Implementation of the ClientHttpSession interface:
00073     void                open();
00074     void                close();
00075     void                abort();
00076     void                get (const Uri &uri, File *outFile);
00077 
00078     // Implementation of the SessionStatus interface:
00079     void                sessionReceivedData (Session *, const Data &);
00080     void                sessionSendingData (Session *, const Data &);
00081     void                sessionClosing (Session *);
00082     void                sessionClosed (Session *);
00083 
00084     static RequestHeader    createRequestHeader (const QByteArray &method,
00085                                                  const Uri &uri);
00086 
00087 private:
00088     static QByteArray   requestUri (const Uri &uri);
00089     static QByteArray   host (const Uri &uri);
00090     void                received (const ResponseHeader &);
00091     void                received (const RawData &);
00092     void                received (const BodyEnd &);
00093     void                received (const DataBase &);
00094 
00095     ClientHttpSessionStatus         *status_;
00096     Session                         *session_;
00097     ObjectDispatcher <DataBase>     receivedDataDispatcher_;
00098     File                            *outFile_;
00099 };
00100 
00101 } // namespace Http
00102 } // namespace Protocols
00103 
00104 #endif // PROTOCOLS__HTTP__SINGLE_HOST_CLIENT_HTTP_SESSION_H