Main Page | Class List | File List | Class Members | Related Pages

httprequest.h

00001 /***************************************************************************
00002                            httprequest.h
00003                            -------------------
00004     class                : GetRequest
00005     begin                : 2004-05-15 - 2004-01-11
00006     copyright            : (C) 2004-2005 by Dominik Haumann
00007     email                : dhdev (at) gmx (dot) de
00008 
00009     dependency           : POSIX socket implementation and C++ (STL)
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Library General Public
00015  * License version 2 as published by the Free Software Foundation.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Library General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Library General Public License
00023  * along with this library; see the file COPYING.LIB.  If not, write to
00024  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00025  * Boston, MA 02111-1307, USA.
00026  ***************************************************************************/
00027 
00028 //BEGIN includes and defines
00029 #ifndef _HTTPREQUEST_H_
00030 #define _HTTPREQUEST_H_
00031 
00032 #include <string>
00033 #include <map>
00034 
00035 #ifdef WIN32
00036 #include <winsock.h>
00037 #else
00038 #include <netinet/in.h> // sin_*
00039 #endif
00040 //END includes and defines
00041 
00042 namespace HTTP {
00043 
00079 class GetRequest {
00080 
00081 public:
00085     GetRequest();
00086 
00090     virtual ~GetRequest();
00091 
00095     void setUserAgent(const std::string& ua);
00096 
00100     std::string getUserAgent() const;
00101 
00108     void addHeader(const std::string& key, const std::string& value);
00109 
00115     void addHeader(const std::string& key, int value);
00116 
00120     void clearHeaders();
00121 
00125     void reset();
00126 
00133     bool connect(const std::string& host, int port);
00134 
00140     bool request(const std::string& page);
00141 
00146     bool process();
00147 
00154     std::string getHeader() const;
00155 
00161     std::string getHeaderAsString(const std::string& key) const;
00162 
00168     int getHeaderAsInt(const std::string& key) const;
00169 
00173     unsigned int getHeaderSize() const;
00174 
00179     std::string getData() const;
00180 
00184     unsigned int getDataSize() const;
00185 
00190     std::string getFooter() const;
00191 
00195     unsigned int getFooterSize() const;
00196 
00201     std::string getRaw() const;
00202 
00207     unsigned int getRawSize() const;
00208 
00213     std::string getError() const;
00214 
00219     bool success() const;
00220 
00221 protected:
00226     void setError(std::string message);
00227 
00232     bool splitData();
00233 
00238     bool postProcessData();
00239 
00246     unsigned int findSize(unsigned int n, const std::string& source) const;
00247 
00252     bool isChunkedTransfer() const;
00253 
00262     bool isTransferFinished() const;
00263 
00268     unsigned int getContentLength() const;
00269 
00270 private:
00271     std::string m_data;            
00272     std::string m_header;          
00273     std::string m_footer;          
00274     std::string m_rawdata;         
00275     std::string m_errorMessage;    
00276     bool        m_success;         
00277     std::string m_host;            
00278 
00279     std::map <std::string, std::string> m_additionalHeader; 
00280 
00281     std::string m_useragent;       
00282 
00283     sockaddr_in server;            
00284     int sock;                      
00285 };
00286 
00287 }
00288 
00289 #endif // _HTTPREQUEST_H_
00290 
00291 // kate: space-indent on; indent-width 4; replace-tabs off;

Generated on Sun Jan 16 18:20:26 2005 for WDSMap by  doxygen 1.3.9.1