PixelLightAPI  .
HttpServerConnection.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: HttpServerConnection.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_HTTPSERVERCONNECTION_H__
00024 #define __PLCORE_HTTPSERVERCONNECTION_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/Network/Buffer.h"
00032 #include "PLCore/Network/Connection.h"
00033 #include "PLCore/Network/Http/HttpHeader.h"
00034 
00035 
00036 //[-------------------------------------------------------]
00037 //[ Namespace                                             ]
00038 //[-------------------------------------------------------]
00039 namespace PLCore {
00040 
00041 
00042 //[-------------------------------------------------------]
00043 //[ Forward declarations                                  ]
00044 //[-------------------------------------------------------]
00045 class HttpServer;
00046 
00047 
00048 //[-------------------------------------------------------]
00049 //[ Classes                                               ]
00050 //[-------------------------------------------------------]
00051 /**
00052 *  @brief
00053 *    Http server connection
00054 */
00055 class HttpServerConnection : public Connection {
00056 
00057 
00058     //[-------------------------------------------------------]
00059     //[ Public functions                                      ]
00060     //[-------------------------------------------------------]
00061     public:
00062         /**
00063         *  @brief
00064         *    Constructor
00065         *
00066         *  @param[in] cServer
00067         *    HTTP server
00068         */
00069         PLCORE_API HttpServerConnection(HttpServer &cServer);
00070 
00071         /**
00072         *  @brief
00073         *    Destructor
00074         */
00075         PLCORE_API virtual ~HttpServerConnection();
00076 
00077         /**
00078         *  @brief
00079         *    Send a file to the client
00080         *
00081         *  @param[in] nStatus
00082         *    HTTP status code
00083         *  @param[in] sFilename
00084         *    Filename
00085         */
00086         PLCORE_API void SendFile(EHttpStatus nStatus, const String &sFilename);
00087 
00088         /**
00089         *  @brief
00090         *    Send data to the client
00091         *
00092         *  @param[in] nStatus
00093         *    HTTP status code
00094         *  @param[in] sMimeType
00095         *    MIME type
00096         *  @param[in] sContent
00097         *    Data to send
00098         */
00099         PLCORE_API void SendData(EHttpStatus nStatus, const String &sMimeType, const String &sContent);
00100 
00101         /**
00102         *  @brief
00103         *    Send a redirect
00104         *
00105         *  @param[in] sLocation
00106         *    New location
00107         */
00108         PLCORE_API void SendRedirect(const String &sLocation);
00109 
00110         /**
00111         *  @brief
00112         *    Send an error
00113         *
00114         *  @param[in] nStatus
00115         *    HTTP status code
00116         */
00117         PLCORE_API void SendError(EHttpStatus nStatus);
00118 
00119         /**
00120         *  @brief
00121         *    Send HTTP header
00122         *
00123         *  @param[in] nStatus
00124         *    HTTP status code
00125         *  @param[in] sMimeType
00126         *    MIME type
00127         *  @param[in] nLength
00128         *    Content length (0 for not sending the content-length at all)
00129         */
00130         PLCORE_API void SendHeader(EHttpStatus nStatus, const String &sMimeType, uint32 nLength);
00131 
00132 
00133     //[-------------------------------------------------------]
00134     //[ Protected virtual HttpServerConnection functions      ]
00135     //[-------------------------------------------------------]
00136     protected:
00137         /**
00138         *  @brief
00139         *    A HTTP request has been received
00140         *
00141         *  @param[in] cHttpHeader
00142         *    HTTP header
00143         */
00144         PLCORE_API virtual void OnHttpRequest(const HttpHeader &cHttpHeader);
00145 
00146 
00147     //[-------------------------------------------------------]
00148     //[ Protected virtual Connection functions                ]
00149     //[-------------------------------------------------------]
00150     protected:
00151         PLCORE_API virtual void OnConnect() override;
00152         PLCORE_API virtual void OnDisconnect() override;
00153         PLCORE_API virtual void OnReceive(const char *pBuffer, uint32 nSize) override;
00154 
00155 
00156     //[-------------------------------------------------------]
00157     //[ Protected data                                        ]
00158     //[-------------------------------------------------------]
00159     protected:
00160         HttpServer  *m_pServer;     /**< HTTP server */
00161         Buffer       m_cBuffer;     /**< Receive buffer */
00162         HttpHeader   m_cHttpHeader; /**< Received HTTP header */
00163 
00164 
00165 };
00166 
00167 
00168 //[-------------------------------------------------------]
00169 //[ Namespace                                             ]
00170 //[-------------------------------------------------------]
00171 } // PLCore
00172 
00173 
00174 #endif // __PLCORE_HTTPSERVERCONNECTION_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