PixelLightAPI  .
HttpHandle.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: HttpHandle.h                                   *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_FILE_HTTPHANDLE_H__
00024 #define __PLCORE_FILE_HTTPHANDLE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/File/File.h"
00032 #include "PLCore/Network/Socket.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    This class represents a tiny HTTP (Hypertext Transfer Protocol) client to download files via HTTP
00047 *
00048 *  @remarks
00049 *    You don't need to use it directly, as you can also use the HTTP protocol through the
00050 *    File/Directory classes, e.g.: File("http://www.pixellight.org/welcome.html")
00051 *
00052 *  @note
00053 *    - Port: 80/TCP
00054 */
00055 class HttpHandle {
00056 
00057 
00058     //[-------------------------------------------------------]
00059     //[ Public functions                                      ]
00060     //[-------------------------------------------------------]
00061     public:
00062         /**
00063         *  @brief
00064         *    Constructor
00065         */
00066         PLCORE_API HttpHandle();
00067 
00068         /**
00069         *  @brief
00070         *    Destructor
00071         */
00072         PLCORE_API ~HttpHandle();
00073 
00074         /**
00075         *  @brief
00076         *    Check if the connection is currently open
00077         *
00078         *  @return
00079         *    'true' if the connection is currently open, else 'false'
00080         */
00081         PLCORE_API bool IsOpen() const;
00082 
00083         /**
00084         *  @brief
00085         *    Open the connection
00086         *
00087         *  @param[in] sUrl
00088         *    URL
00089         *  @param[in] sUsername
00090         *    Username
00091         *  @param[in] sPassword
00092         *    Password
00093         *
00094         *  @return
00095         *    'true', if the file could be opened, 'false' on error
00096         */
00097         PLCORE_API bool Open(const String &sUrl, const String &sUsername, const String &sPassword);
00098 
00099         /**
00100         *  @brief
00101         *    Close the connection
00102         *
00103         *  @return
00104         *    'true', if the file could be closed, 'false' on error
00105         */
00106         PLCORE_API bool Close();
00107 
00108         /**
00109         *  @brief
00110         *    Get HTTP response string
00111         *
00112         *  @return
00113         *    HTTP response
00114         */
00115         PLCORE_API String GetResponse() const;
00116 
00117         /**
00118         *  @brief
00119         *    Get HTTP authenticate string
00120         *
00121         *  @return
00122         *    HTTP authenticate-field
00123         */
00124         PLCORE_API String GetAuthenticate() const;
00125 
00126         /**
00127         *  @brief
00128         *    Get HTTP server string
00129         *
00130         *  @return
00131         *    HTTP server-field
00132         */
00133         PLCORE_API String GetServer() const;
00134 
00135         /**
00136         *  @brief
00137         *    Get HTTP date string
00138         *
00139         *  @return
00140         *    HTTP date-field
00141         */
00142         PLCORE_API String GetDate() const;
00143 
00144         /**
00145         *  @brief
00146         *    Get HTTP ContentType string
00147         *
00148         *  @return
00149         *    HTTP ContentType-field
00150         */
00151         PLCORE_API String GetContentType() const;
00152 
00153         /**
00154         *  @brief
00155         *    Get HTTP content-length
00156         *
00157         *  @return
00158         *    HTTP ContentLength-field
00159         */
00160         PLCORE_API int GetContentLength() const;
00161 
00162         /**
00163         *  @brief
00164         *    Reads data from the connection
00165         *
00166         *  @param[out] pBuffer
00167         *    Buffer to store the data (MUST be valid and large enough!)
00168         *  @param[in]  nSize
00169         *    Item size in bytes
00170         *  @param[in]  nCount
00171         *    Number of items to read
00172         *
00173         *  @return
00174         *    Number of full read items, if != 'nCount' an error occurred
00175         */
00176         PLCORE_API uint32 Read(void *pBuffer, uint32 nSize, uint32 nCount);
00177 
00178         /**
00179         *  @brief
00180         *    Sets the starting position
00181         *
00182         *  @param[in] nOffset
00183         *    File offset in bytes relative to the given location
00184         *  @param[in] nLocation
00185         *    Location
00186         *
00187         *  @return
00188         *    'true' if all went fine, else 'false'
00189         */
00190         PLCORE_API bool Seek(int32 nOffset, File::ESeek nLocation);
00191 
00192         /**
00193         *  @brief
00194         *    Returns the file position
00195         *
00196         *  @return
00197         *    Current position within the file, or < 0 on error
00198         */
00199         PLCORE_API int32 Tell() const;
00200 
00201         /**
00202         *  @brief
00203         *    Returns whether end of file has been reached
00204         *
00205         *  @return
00206         *    'true', if the end of the file has been reached, else 'false'
00207         */
00208         PLCORE_API bool IsEof() const;
00209 
00210 
00211     //[-------------------------------------------------------]
00212     //[ Private functions                                     ]
00213     //[-------------------------------------------------------]
00214     private:
00215         /**
00216         *  @brief
00217         *    Connects to the web server
00218         *
00219         *  @return
00220         *    'true', if all went fine, else 'false'
00221         */
00222         bool Connect();
00223 
00224         /**
00225         *  @brief
00226         *    Reads a single line from the HTTP header
00227         *
00228         *  @return
00229         *    Next line from the header, "" at the end
00230         */
00231         String ReadLine();
00232 
00233 
00234     //[-------------------------------------------------------]
00235     //[ Private data                                          ]
00236     //[-------------------------------------------------------]
00237     private:
00238         Socket  m_cSocket;          /**< Socket */
00239         Url     m_cUrl;             /**< Current URL */
00240         String  m_sDomain;          /**< Domain part of the URL */
00241         String  m_sUsername;        /**< Username */
00242         String  m_sPassword;        /**< Password */
00243         String  m_sResponse;        /**< HTTP Response */
00244         String  m_sAuthenticate;    /**< HTTP WWW-Authenticate-field */
00245         String  m_sServer;          /**< HTTP Server-field */
00246         String  m_sDate;            /**< HTTP Date-field */
00247         String  m_sContentType;     /**< HTTP ContentType-field */
00248         int     m_nContentLength;   /**< HTTP ContentLength-field */
00249         int     m_nPosition;        /**< Current stream position */
00250 
00251 
00252 };
00253 
00254 
00255 //[-------------------------------------------------------]
00256 //[ Namespace                                             ]
00257 //[-------------------------------------------------------]
00258 } // PLCore
00259 
00260 
00261 #endif // __PLCORE_FILE_HTTPHANDLE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:56
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported