93 lines
2.2 KiB
C++
93 lines
2.2 KiB
C++
#ifndef _WININET_INTERNET_HPP_
|
|
#define _WININET_INTERNET_HPP_
|
|
#ifndef _COMMON_EXCEPTION_HPP_
|
|
#include <common/except.hpp>
|
|
#endif
|
|
#ifndef _COMMON_REGKEY_HPP_
|
|
#include <common/regkey.hpp>
|
|
#endif
|
|
#ifndef _COMMON_WININET_HPP_
|
|
#include <common/wininet.hpp>
|
|
#endif
|
|
|
|
class Internet
|
|
{
|
|
public:
|
|
typedef enum AccessType{OpenDirect=INTERNET_OPEN_TYPE_DIRECT,PreConfig=INTERNET_OPEN_TYPE_PRECONFIG,NoAutoProxy=
|
|
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,Proxy=INTERNET_OPEN_TYPE_PROXY};
|
|
typedef enum Flags{Async=INTERNET_FLAG_ASYNC,FromCache=INTERNET_FLAG_FROM_CACHE,
|
|
Offline=INTERNET_FLAG_OFFLINE,InvalidPort=INTERNET_INVALID_PORT_NUMBER,None=0};
|
|
Internet();
|
|
virtual ~Internet();
|
|
bool open(AccessType accessType=NoAutoProxy,const String &strProxyServer=String(),const String &proxyBypass=String(),Flags flags=None,const String &agent="Microsoft Internet Explorer");
|
|
bool open(const String &strProxyServer,const String &agent="Microsoft Internet Explorer");
|
|
bool connect();
|
|
void close();
|
|
bool isOkay(void)const;
|
|
HINTERNET getHANDLE(void)const;
|
|
static String getProxyServer(void);
|
|
private:
|
|
HINTERNET mhInternet;
|
|
};
|
|
|
|
inline
|
|
Internet::Internet()
|
|
: mhInternet(0)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Internet::~Internet()
|
|
{
|
|
close();
|
|
}
|
|
|
|
inline
|
|
bool Internet::open(AccessType accessType,const String &strProxyServer,const String &proxyByPass,Flags flags,const String &agent)
|
|
{
|
|
close();
|
|
mhInternet=::InternetOpen(agent.str(),accessType,strProxyServer.str(),proxyByPass.str(),flags);
|
|
return isOkay();
|
|
}
|
|
|
|
inline
|
|
bool Internet::open(const String &strProxyServer,const String &agent)
|
|
{
|
|
close();
|
|
mhInternet=::InternetOpen(agent.str(),Proxy,strProxyServer.str(),0,None);
|
|
return isOkay();
|
|
}
|
|
|
|
|
|
inline
|
|
void Internet::close()
|
|
{
|
|
if(!isOkay())return;
|
|
::InternetCloseHandle(mhInternet);
|
|
mhInternet=0;
|
|
}
|
|
|
|
inline
|
|
HINTERNET Internet::getHANDLE(void)const
|
|
{
|
|
return mhInternet;
|
|
}
|
|
|
|
inline
|
|
bool Internet::isOkay()const
|
|
{
|
|
return mhInternet?true:false;
|
|
}
|
|
|
|
inline
|
|
String Internet::getProxyServer(void)
|
|
{
|
|
String strProxyServer;
|
|
|
|
RegKey regKey(RegKey::CurrentUser);
|
|
if(!regKey.openKey("Comm\\Wininet"))return strProxyServer;
|
|
if(!regKey.queryValue("ProxyServer",strProxyServer))return strProxyServer;
|
|
return strProxyServer;
|
|
}
|
|
#endif
|