00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef NET_HTTP_UTILITY_H
00028 #define NET_HTTP_UTILITY_H
00029
00030 #include <PVLE/Config.h>
00031
00032 #ifdef PVLE_URL
00033
00034 #include <string>
00035 #include <curl/curl.h>
00036 #include <PVLE/Util/Singleton.h>
00037 #include <PVLE/Util/Util.h>
00038 #include <PVLE/Export.h>
00039
00040
00041 typedef void CURL;
00042
00043 namespace Net {
00044
00046 class PVLE_EXPORT CURLHolder : public Util::Singleton<CURLHolder> {
00047 public:
00048 CURLHolder();
00049 virtual ~CURLHolder();
00050
00051 const CURL * getHandle() const { return handle; }
00052 CURL * getHandle() { return handle; }
00053 operator CURL *() const { return handle; }
00054 operator CURL *() { return handle; }
00055
00056 protected:
00057 CURL * handle;
00058 };
00059
00060
00062 class URLOptions {
00063 public:
00064 enum EProxyType {
00065 PROXY_HTTP = CURLPROXY_HTTP,
00066 PROXY_SOCKS4 = CURLPROXY_SOCKS4,
00067 PROXY_SOCKS5 = CURLPROXY_SOCKS5,
00068 PROXY_SOCKS4A = CURLPROXY_SOCKS4A,
00069 PROXY_SOCKS5_HOSTNAME = CURLPROXY_SOCKS5_HOSTNAME
00070 };
00071
00076 URLOptions(std::string proxyAddress = "", UINT proxyPort = 8080, EProxyType proxyType = PROXY_HTTP)
00077 : proxyAddress(proxyAddress), proxyPort(proxyPort), proxyType(), timeout(15)
00078 {}
00079
00082
00083 bool usesProxy() const { return !proxyAddress.empty() && proxyPort!=0; }
00084 const std::string & getProxyAddress() const { return proxyAddress; }
00085 void setProxyAddress(const std::string & address) { proxyAddress = address; }
00086 UINT getProxyPort() const { return proxyPort; }
00087 void setProxyPort(UINT port) { proxyPort = port; }
00088 EProxyType getProxyType() const { return proxyType; }
00089 void setProxyType(EProxyType type) { proxyType = type; }
00090 PVLE_EXPORT void setProxyType(std::string strType);
00092
00094 UINT getTimeout() const { return timeout; }
00096 void setTimeout(UINT time) { timeout = time; }
00097
00098 protected:
00099 std::string proxyAddress;
00100 UINT proxyPort;
00101 EProxyType proxyType;
00102 UINT timeout;
00103 };
00104
00105
00109 PVLE_EXPORT void applyOptions(const URLOptions & options);
00110
00111
00115 PVLE_EXPORT std::string readURLAsString(const std::string & url, const URLOptions & options = URLOptions());
00116
00117
00118 }
00119
00120 #endif // PVLE_URL
00121
00122 #endif // NET_CONVERTERS_H