Logo
~Sockets~
~Examples~
~Contact~


HTTPSocket.h

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00029 */
00030 #ifndef _SOCKETS_HTTPSocket_H
00031 #define _SOCKETS_HTTPSocket_H
00032 
00033 #include "sockets-config.h"
00034 #include <map>
00035 #include "TcpSocket.h"
00036 
00037 #ifdef SOCKETS_NAMESPACE
00038 namespace SOCKETS_NAMESPACE {
00039 #endif
00040 
00044 class HTTPSocket : public TcpSocket
00045 {
00047         typedef std::map<std::string,std::string> string_m;
00048 public:
00049         HTTPSocket(ISocketHandler& );
00050         ~HTTPSocket();
00051 
00052 //      void OnRead();
00054 //      void ReadLine();
00055         void OnRawData(const char *buf,size_t len);
00056         void OnLine(const std::string& line);
00057 
00060         virtual void OnFirst() = 0;
00064         virtual void OnHeader(const std::string& key,const std::string& value) = 0;
00066         virtual void OnHeaderComplete() = 0;
00068         virtual void OnData(const char *,size_t) = 0;
00069 
00071         const std::string& GetMethod();
00073         void SetMethod(const std::string& x);
00075         const std::string& GetUrl();
00077         void SetUrl(const std::string& x);
00079         const std::string& GetUri();
00081         void SetUri(const std::string& x);
00083         const std::string& GetQueryString();
00085         const std::string& GetHttpVersion();
00087         const std::string& GetStatus();
00089         const std::string& GetStatusText();
00091         bool IsRequest();
00093         bool IsResponse();
00095         void SetHttpVersion(const std::string& x);
00097         void SetStatus(const std::string& x);
00099         void SetStatusText(const std::string& x);
00101         void AddResponseHeader(const std::string& x,const std::string& y);
00103         void AddResponseHeader(const std::string& x,const char *format, ...);
00106         void SendResponse();
00109         void SendRequest();
00110 
00112         virtual std::string MyUseragent();
00113 
00115         void url_this(const std::string& url_in,std::string& protocol,std::string& host,port_t& port,std::string& url,std::string& file);
00116 
00117 protected:
00118         HTTPSocket(const HTTPSocket& s) : TcpSocket(s) {}
00120         virtual void Reset();
00121 
00122 private:
00123         HTTPSocket& operator=(const HTTPSocket& ) { return *this; }
00124         bool m_first;
00125         bool m_header;
00126         std::string m_line;
00127         std::string m_method;
00128         std::string m_url;
00129         std::string m_uri;
00130         std::string m_query_string;
00131         std::string m_http_version;
00132         std::string m_status;
00133         std::string m_status_text;
00134         bool m_request;
00135         bool m_response;
00136         string_m m_response_header;
00137 };
00138 
00139 
00140 
00141 
00142 #ifdef SOCKETS_NAMESPACE
00143 }
00144 #endif
00145 
00146 #endif // _SOCKETS_HTTPSocket_H
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4