From 436b5f388536157fb0befd933aaa59a56d2c6a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Mon, 9 Mar 2009 14:01:51 +0000 Subject: [PATCH] first release --- autoproxy.hxx | 78 +++++++++++++++++++++++++++++++++++ bootstrap.sh | 19 +++++++++ configure.in | 3 ++ makefile.am | 1 + proxyface/unix.hxx | 62 ++++++++++++++++++++++++++++ proxyface/windoze.hxx | 92 ++++++++++++++++++++++++++++++++++++++++++ test.cxx | 53 ++++++++++++++++++++++++ winhttp.a | Bin 0 -> 9038 bytes 8 files changed, 308 insertions(+) create mode 100644 autoproxy.hxx create mode 100755 bootstrap.sh create mode 100644 configure.in create mode 100644 makefile.am create mode 100644 proxyface/unix.hxx create mode 100644 proxyface/windoze.hxx create mode 100644 test.cxx create mode 100644 winhttp.a diff --git a/autoproxy.hxx b/autoproxy.hxx new file mode 100644 index 0000000..ac572a1 --- /dev/null +++ b/autoproxy.hxx @@ -0,0 +1,78 @@ +/*! @file + + @id $Id$ + */ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#ifndef PROXYFACE_HXX +#define PROXYFACE_HXX + +#include +#include + +//! auto proxy configuration +namespace proxy { + + //! exceptions + namespace exc { + + //! unspecific error + class error: std::exception { + public: + virtual const char* what() const throw() { + return "Auto Proxy Detection Error"; + } + }; + + } + + //! Proxy types + enum Type { + DIRECT, //< direct connection, no proxy + DEFAULT, //< default proxy + HTTP, //< HTTP proxy host + SOCKS // url and port + typedef std::list< std::pair > > + List; + + //! Unified Interface for accessing proxy::Face + /*! Abstract interface, impementation for Unix and Windoze differs. + + Instanciate proxy::Face, which is a typedef to your + platform's implementation. + + @code + proxy::Auto pf; // keep for program life time (because of caching) + proxy::List pf.proxies("http://swisssign.com"); + [...] // set proxy, read from http://swisssign.com + @endcode */ + class Interface { + public: + //! Keep your instance as long as possible, because of caching. + Interface() {} + virtual ~Interface() {} + //! Get list of proxies for a given URL. + /*! @throw a child of std::exception if anything fails */ + virtual List proxies(const std::string& url) = 0; + }; +} + +#ifdef WIN32 +// use windoze proprietary winhttp +#include +namespace proxy { + typedef Windoze Face; +} +#else +// normal operating systems: use http://code.google.com/p/libproxy +#include +namespace proxy { + typedef Unix Face; +} +#endif + +#endif diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..f39ba8a --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,19 @@ +#! /bin/sh + +## @file +## +## $Id$ +## +## $Date: 2004/08/31 15:57:19 $ +## $Author: marc $ +## +## @copy © Marc Wäckerlin +## @license LGPL, see file COPYING +## +## $Log: bootstrap.sh,v $ +## Revision 1.3 2004/08/31 15:57:19 marc +## added file header +## + +test -f makefile && make distclean +aclocal && libtoolize --force && automake -a && autoconf diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..d224edc --- /dev/null +++ b/configure.in @@ -0,0 +1,3 @@ +AC_INIT +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/makefile.am b/makefile.am new file mode 100644 index 0000000..f3efef4 --- /dev/null +++ b/makefile.am @@ -0,0 +1 @@ +include_HEADERS = proxyface.hxx proxyface/unix.hxx proxyface/windoze.hxx diff --git a/proxyface/unix.hxx b/proxyface/unix.hxx new file mode 100644 index 0000000..d2bdb03 --- /dev/null +++ b/proxyface/unix.hxx @@ -0,0 +1,62 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#ifndef PROXY_LINUX +#define PROXY_LINUX + +extern "C" { + #include +} + +#include // debug + +namespace proxy { + + class Unix: Interface { + + public: + + Unix(): _factory(px_proxy_factory_new()) {} + + virtual ~Unix() { + px_proxy_factory_free(_factory); + } + + //! Implemented using http://code.google.com/p/libproxy/ + virtual List proxies(const std::string& url) { + List res; + char** proxies(px_proxy_factory_get_proxies + (_factory, const_cast(url.data()))); + for (int i(0); proxies[i]; ++i) { + std::string proxy(proxies[i]); + Type type(proxy.find("http://")==0?HTTP: + (proxy.find("socks://")==0?SOCKS:DIRECT)); + if (proxy.find("://")!=std::string::npos) + proxy=proxy.substr(proxy.find("://")+3); + std::string::size_type oldpos(0); + std::string port((oldpos=proxy.rfind(":"))!=std::string::npos + ?proxy.substr(oldpos+1):std::string()); + std::string host(proxy.substr(0, proxy.rfind(":"))); + std::cout<<"Proxy found: "< +#include + +#include // debug + +namespace proxy { + + class Windoze: Interface { + + public: + + Windoze() {} + + virtual ~Windoze() {} + + //! Implemented using M$ WinHTTP + virtual List proxies(const std::string& url) { + + List res; + WINHTTP_PROXY_INFO proxyInfo; + ZeroMemory(&proxyInfo, sizeof(proxyInfo)); + HINTERNET hHttpSession(WinHttpOpen(L"WinHTTP AutoProxy/1.0", + WINHTTP_ACCESS_TYPE_NO_PROXY, + WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, + 0)); + try { + if (!hHttpSession) throw exc::error(); + + WINHTTP_AUTOPROXY_OPTIONS AutoProxyOptions; + ZeroMemory(&AutoProxyOptions, sizeof(AutoProxyOptions)); + AutoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT; + AutoProxyOptions.dwAutoDetectFlags = + WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; + AutoProxyOptions.fAutoLogonIfChallenged = FALSE; + + if (!WinHttpGetProxyForUrl(hHttpSession, + std::wstring(url.begin(), url.end()).data(), + &AutoProxyOptions, &proxyInfo)) + throw exc::error(); + + std::wstring list(proxyInfo.lpszProxy); + std::wcout<<"LIST=\""< +#include + +int main(int argc, char** argv) try { + proxy::Face detect; + while (++argv, --argc) { + std::cout<<"detecting proxies for url: "<<*argv< found " + <<(p.begin()->first==proxy::DIRECT?"DIRECT" + :(p.begin()->first==proxy::DEFAULT?"DEFAULT" + :(p.begin()->first==proxy::HTTP?"HTTP" + :(p.begin()->first==proxy::SOCKS?"SOCKS":"**ER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