00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00025 #ifndef SFML_HTTP_HPP 00026 #define SFML_HTTP_HPP 00027 00029 // Headers 00031 #include <SFML/System/NonCopyable.hpp> 00032 #include <SFML/Network/IPAddress.hpp> 00033 #include <SFML/Network/SocketTCP.hpp> 00034 #include <map> 00035 #include <string> 00036 00037 00038 namespace sf 00039 { 00045 class SFML_API Http : NonCopyable 00046 { 00047 public : 00048 00054 class SFML_API Request 00055 { 00056 public : 00057 00061 enum Method 00062 { 00063 Get, 00064 Post, 00065 Head 00066 }; 00067 00076 Request(Method method = Get, const std::string& URI = "/", const std::string& body = ""); 00077 00085 void SetField(const std::string& field, const std::string& value); 00086 00094 void SetMethod(Method method); 00095 00103 void SetURI(const std::string& URI); 00104 00113 void SetHttpVersion(unsigned int major, unsigned int minor); 00114 00123 void SetBody(const std::string& body); 00124 00125 private : 00126 00127 friend class Http; 00128 00135 std::string ToString() const; 00136 00145 bool HasField(const std::string& field) const; 00146 00148 // Types 00150 typedef std::map<std::string, std::string> FieldTable; 00151 00153 // Member data 00155 FieldTable myFields; 00156 Method myMethod; 00157 std::string myURI; 00158 unsigned int myMajorVersion; 00159 unsigned int myMinorVersion; 00160 std::string myBody; 00161 }; 00162 00168 class SFML_API Response 00169 { 00170 public : 00171 00176 enum Status 00177 { 00178 // 2xx: success 00179 Ok = 200, 00180 Created = 201, 00181 Accepted = 202, 00182 NoContent = 204, 00183 ResetContent = 205, 00184 PartialContent = 206, 00185 00186 // 3xx: redirection 00187 MultipleChoices = 300, 00188 MovedPermanently = 301, 00189 MovedTemporarily = 302, 00190 NotModified = 304, 00191 00192 // 4xx: client error 00193 BadRequest = 400, 00194 Unauthorized = 401, 00195 Forbidden = 403, 00196 NotFound = 404, 00197 RangeNotSatisfiable = 407, 00198 00199 // 5xx: server error 00200 InternalServerError = 500, 00201 NotImplemented = 501, 00202 BadGateway = 502, 00203 ServiceNotAvailable = 503, 00204 GatewayTimeout = 504, 00205 VersionNotSupported = 505, 00206 00207 // 10xx: SFML custom codes 00208 InvalidResponse = 1000, 00209 ConnectionFailed = 1001 00210 }; 00211 00216 Response(); 00217 00226 const std::string& GetField(const std::string& field) const; 00227 00234 Status GetStatus() const; 00235 00242 unsigned int GetMajorHttpVersion() const; 00243 00250 unsigned int GetMinorHttpVersion() const; 00251 00262 const std::string& GetBody() const; 00263 00264 private : 00265 00266 friend class Http; 00267 00274 void FromString(const std::string& data); 00275 00277 // Types 00279 typedef std::map<std::string, std::string> FieldTable; 00280 00282 // Member data 00284 FieldTable myFields; 00285 Status myStatus; 00286 unsigned int myMajorVersion; 00287 unsigned int myMinorVersion; 00288 std::string myBody; 00289 }; 00290 00295 Http(); 00296 00304 Http(const std::string& host, unsigned short port = 0); 00305 00313 void SetHost(const std::string& host, unsigned short port = 0); 00314 00329 Response SendRequest(const Request& request, float timeout = 0.f); 00330 00331 private : 00332 00334 // Member data 00336 SocketTCP myConnection; 00337 IPAddress myHost; 00338 std::string myHostName; 00339 unsigned short myPort; 00340 }; 00341 00342 } // namespace sf 00343 00344 00345 #endif // SFML_HTTP_HPP
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::