Esempio n. 1
0
		SharedPtr<Proxy> GetProxyForURLImpl(URI& uri)
		{
			InitializeWin32ProxyConfig();
			std::string url(uri.toString());

			// The auto proxy configuration might tell us to simply use
			// a direct connection, which should cause us to just return
			// null. Otherwise we should try to use the IE proxy list (next block)
			if (useProxyAutoConfig || !autoConfigURL.empty())
			{
				std::vector<SharedProxy> autoProxies;
				bool shouldUseIEProxy = GetAutoProxiesForURL(url, autoProxies);

				for (int i = 0; i < autoProxies.size(); i++)
				{
					SharedProxy proxy = autoProxies.at(i);
					if (proxy->ShouldBypass(uri))
					{
						return 0;
					}
					else if (proxy->info->getScheme().empty() ||
						proxy->info->getScheme() == uri.getScheme())
					{
						return proxy;
					}
				}

				if (!shouldUseIEProxy)
					return 0;
			}

			// Try the IE proxy list
			for (int i = 0; i < ieProxies.size(); i++)
			{
				SharedProxy proxy = ieProxies.at(i);
				std::string proxyScheme = proxy->info->getScheme();
				if (proxy->ShouldBypass(uri))
				{
					return 0;
				}
				else if (proxyScheme.empty() || proxyScheme == uri.getScheme())
				{
					return proxy;
				}
			}

			return 0;
		}
Esempio n. 2
0
Connection::Connection(cb::Event::Base &base, DNSBase &dns, const URI &uri,
                       const SmartPointer<SSLContext> &sslCtx) :
  con(0), deallocate(true) {
  bool https = uri.getScheme() == "https";

#ifdef HAVE_OPENSSL
  if (https && sslCtx.isNull()) THROW("Need SSL context for https connection");

  BufferEvent bev(base, https ? sslCtx : 0, uri.getHost());
#else

  if (https) THROW("C! not built with OpenSSL support");

  BufferEvent bev(base, 0, uri.getHost());
#endif

  // TODO OpenSSL connections do not work with async DNS
  con = evhttp_connection_base_bufferevent_new
    (base.getBase(), sslCtx.isNull() ? dns.getDNSBase() : 0, bev.adopt(),
     uri.getHost().c_str(), uri.getPort());

  LOG_DEBUG(5, "Connecting to " << uri.getHost() << ':' << uri.getPort());

  if (!con) THROWS("Failed to create connection to " << uri);
}
Esempio n. 3
0
	bool Proxy::ShouldBypass(URI& uri)
	{
		const std::string& uriHost = uri.getHost();
		const std::string& uriScheme = uri.getScheme();
		unsigned short uriPort = uri.getPort();
		for (size_t i = 0; i < bypassList.size(); i++)
		{
			SharedURI entry = bypassList.at(i);

			// An empty bypass entry equals an unconditional bypass.
			if (entry.isNull())
			{
				return true;
			}
			else
			{
				const std::string& entryHost = entry->getHost();
				const std::string& entryScheme = entry->getScheme();
				unsigned short entryPort = entry->getPort();

				if (entryHost == "<local>" && uriHost.find(".") == string::npos)
				{
					return true;
				}
				else if (EndsWith(uriHost, entryHost) &&
					(entryScheme.empty() || entryScheme == uriScheme) &&
					(entryPort == 0 || entryPort == uriPort))
				{
					return true;
				}
			}
		}

		return false;
	}
Esempio n. 4
0
static bool ShouldBypassWithEntry(URI& uri, SharedPtr<BypassEntry> entry)
{
    const std::string& uriHost = uri.getHost();
    const std::string& uriScheme = uri.getScheme();
    unsigned short uriPort = uri.getPort();
    const std::string& entryHost = entry->host;
    const std::string& entryScheme = entry->scheme;
    unsigned short entryPort = entry->port;

    GetLogger()->Debug("bypass entry: scheme='%s' host='%s' port='%i'",
                       entry->scheme.c_str(), entry->host.c_str(), entry->port);

    // An empty bypass entry equals an unconditional bypass.
    if (entry.isNull())
    {
        return true;
    }
    else
    {
        if (entryHost == "<local>" && uriHost.find(".") == string::npos)
        {
            return true;
        }
        else if (EndsWith(uriHost, entryHost) &&
                 (entryScheme.empty() || entryScheme == uriScheme) &&
                 (entryPort == 0 || entryPort == uriPort))
        {
            return true;
        }
    }

    return false;
}
Esempio n. 5
0
Request::Request(RequestMethod method, const URI &uri, float version) :
  Message(version), method(method), uri(uri) {
  if (version != 1.0) {
    set("Host", uri.getHost());
    if ((uri.getScheme() == "http" && uri.getPort() != 80) ||
        (uri.getScheme() == "https" && uri.getPort() != 443))
      append("Host", String(uri.getPort()));
  }
}
Esempio n. 6
0
URI Transaction::resolve(const URI &_uri) {
  URI uri = _uri;

  if (uri.getHost().empty()) {
    uri.setHost(address.getHost());
    if (uri.getScheme().empty()) uri.setScheme("http");
    if (!uri.getPort()) uri.setPort(address.getPort());
  }

  return uri;
}
Esempio n. 7
0
bool PersistentMap::handles( const URI& uri )
{
#ifdef LUNCHBOX_USE_LEVELDB
    if( lunchbox::leveldb::PersistentMap::handles( uri ))
        return true;
#endif
#ifdef LUNCHBOX_USE_SKV
    if( lunchbox::skv::PersistentMap::handles( uri ))
        return true;
#endif

    if( !uri.getScheme().empty( ))
        return false;

#ifdef LUNCHBOX_USE_LEVELDB
    return true;
#endif
    return false;
}
Esempio n. 8
0
void URITest::testConstruction()
{
	URI uri;
	assert (uri.getScheme().empty());
	assert (uri.getAuthority().empty());
	assert (uri.getUserInfo().empty());
	assert (uri.getHost().empty());
	assert (uri.getPort() == 0);
	assert (uri.getPath().empty());
	assert (uri.getQuery().empty());
	assert (uri.getFragment().empty());
	
	uri.setScheme("ftp");
	assert (uri.getScheme() == "ftp");
	assert (uri.getPort() == 21);
	
	uri.setScheme("HTTP");
	assert (uri.getScheme() == "http");
	
	uri.setAuthority("www.appinf.com");
	assert (uri.getAuthority() == "www.appinf.com");
	assert (uri.getPort() == 80);
	
	uri.setAuthority("[email protected]:8000");
	assert (uri.getUserInfo() == "user");
	assert (uri.getHost() == "services.appinf.com");
	assert (uri.getPort() == 8000);
	
	uri.setPath("/index.html");
	assert (uri.getPath() == "/index.html");
	
	uri.setPath("/file%20with%20spaces.html");
	assert (uri.getPath() == "/file with spaces.html");
	
	uri.setPathEtc("/query.cgi?query=foo");
	assert (uri.getPath() == "/query.cgi");
	assert (uri.getQuery() == "query=foo");
	assert (uri.getFragment().empty());
	assert (uri.getPathEtc() == "/query.cgi?query=foo");
	assert (uri.getPathAndQuery() == "/query.cgi?query=foo");
	
	uri.setPathEtc("/query.cgi?query=bar#frag");
	assert (uri.getPath() == "/query.cgi");
	assert (uri.getQuery() == "query=bar");
	assert (uri.getFragment() == "frag");
	assert (uri.getPathEtc() == "/query.cgi?query=bar#frag");
	assert (uri.getPathAndQuery() == "/query.cgi?query=bar");
	
	uri.setQuery("query=test");
	assert (uri.getQuery() == "query=test");
	
	uri.setFragment("result");
	assert (uri.getFragment() == "result");
	
	URI uri2("file", "/home/guenter/foo.bar");
	assert (uri2.getScheme() == "file");
	assert (uri2.getPath() == "/home/guenter/foo.bar");
	
	URI uri3("http", "www.appinf.com", "/index.html");
	assert (uri3.getScheme() == "http");
	assert (uri3.getAuthority() == "www.appinf.com");
	assert (uri3.getPath() == "/index.html");
	
	URI uri4("http", "www.appinf.com:8000", "/index.html");
	assert (uri4.getScheme() == "http");
	assert (uri4.getAuthority() == "www.appinf.com:8000");
	assert (uri4.getPath() == "/index.html");

	URI uri5("http", "[email protected]:8000", "/index.html");
	assert (uri5.getScheme() == "http");
	assert (uri5.getUserInfo() == "user");
	assert (uri5.getHost() == "www.appinf.com");
	assert (uri5.getPort() == 8000);
	assert (uri5.getAuthority() == "[email protected]:8000");
	assert (uri5.getPath() == "/index.html");

	URI uri6("http", "[email protected]:80", "/index.html");
	assert (uri6.getScheme() == "http");
	assert (uri6.getUserInfo() == "user");
	assert (uri6.getHost() == "www.appinf.com");
	assert (uri6.getPort() == 80);
	assert (uri6.getAuthority() == "*****@*****.**");
	assert (uri6.getPath() == "/index.html");

	URI uri7("http", "[email protected]:", "/index.html");
	assert (uri7.getScheme() == "http");
	assert (uri7.getUserInfo() == "user");
	assert (uri7.getHost() == "www.appinf.com");
	assert (uri7.getPort() == 80);
	assert (uri7.getAuthority() == "*****@*****.**");
	assert (uri7.getPath() == "/index.html");
	
	URI uri8("http", "www.appinf.com", "/index.html", "query=test");
	assert (uri8.getScheme() == "http");
	assert (uri8.getAuthority() == "www.appinf.com");
	assert (uri8.getPath() == "/index.html");
	assert (uri8.getQuery() == "query=test");

	URI uri9("http", "www.appinf.com", "/index.html", "query=test", "fragment");
	assert (uri9.getScheme() == "http");
	assert (uri9.getAuthority() == "www.appinf.com");
	assert (uri9.getPath() == "/index.html");
	assert (uri9.getPathEtc() == "/index.html?query=test#fragment");
	assert (uri9.getQuery() == "query=test");
	assert (uri9.getFragment() == "fragment");

	uri9.clear();
	assert (uri9.getScheme().empty());
	assert (uri9.getAuthority().empty());
	assert (uri9.getUserInfo().empty());
	assert (uri9.getHost().empty());
	assert (uri9.getPort() == 0);
	assert (uri9.getPath().empty());
	assert (uri9.getQuery().empty());
	assert (uri9.getFragment().empty());

	URI uri10("ldap", "[2001:db8::7]", "/c=GB?objectClass?one");
	assert (uri10.getScheme() == "ldap");
	assert (uri10.getUserInfo().empty());
	assert (uri10.getHost() == "2001:db8::7");
	assert (uri10.getPort() == 389);
	assert (uri10.getAuthority() == "[2001:db8::7]");
	assert (uri10.getPathEtc() == "/c=GB?objectClass?one");
	
	URI uri11("http", "www.appinf.com", "/index.html?query=test#fragment");
	assert (uri11.getScheme() == "http");
	assert (uri11.getAuthority() == "www.appinf.com");
	assert (uri11.getPath() == "/index.html");
	assert (uri11.getPathEtc() == "/index.html?query=test#fragment");
	assert (uri11.getQuery() == "query=test");
	assert (uri11.getFragment() == "fragment");
}
Esempio n. 9
0
int main( int argc, char*argv[] ) {
   LOG_NOTICE( "Test Started" );

   URI u;

   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );

   string ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );

   for (uint32_t i = 0; i < ARRAY_SIZE( test_urls ); i++) {
      bool res = u.setString( test_urls[i] );

#ifdef DEBUG_PRINTS
      cout << "scheme: " << u.getScheme() << endl;
      cout << "authority: " << u.getAuthority() << endl;
      cout << "host: " << u.getHost() << endl;
      cout << "port: " << u.getPort() << endl;
      cout << "query: " << u.getQuery() << endl;
      cout << "path: " << u.getPath() << endl;
      cout << "fragment: " << u.getFragment() << endl;
      cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
      cout << "query param \"e\": " << u.getQueryParam( "e" ) << endl;
      cout << "is relative: " << u.isRelative() << endl;
#endif

      if ( not res ) {
         LOG_WARN( "parse uri %s: FAILED", test_urls[i] );
         exit( 1 );
      } else {
         LOG_NOTICE( "parse uri %s: PASSED", test_urls[ i ] );
      }
   }

   u.clear();
   u.setScheme( "http" );
   u.setAuthority( "www.jetheaddev.com" );
   u.setPath( "pages/index.html" );
   u.appendQueryParam( "a", "b" );
   u.appendQueryParam( "c", "d" );
   u.setFragment( "m" );

   URI copy = u;

   ustr = u.getString();
   LOG_NOTICE( "URI is: %s", ustr.c_str() );
   ustr = copy.getString();
   LOG_NOTICE( "Copy is: %s", ustr.c_str() );

#ifdef DEBUG_PRINTS
   cout << "scheme: " << u.getScheme() << endl;
   cout << "scheme: " << copy.getScheme() << endl;
   cout << "authority: " << u.getAuthority() << endl;
   cout << "authority: " << copy.getAuthority() << endl;
   cout << "host: " << u.getHost() << endl;
   cout << "host: " << copy.getHost() << endl;
   cout << "port: " << u.getPort() << endl;
   cout << "port: " << copy.getPort() << endl;
   cout << "query: " << u.getQuery() << endl;
   cout << "query: " << copy.getQuery() << endl;
   cout << "path: " << u.getPath() << endl;
   cout << "path: " << copy.getPath() << endl;
   cout << "fragment: " << u.getFragment() << endl;
   cout << "fragment: " << copy.getFragment() << endl;
   cout << "query param \"a\": " << u.getQueryParam( "a" ) << endl;
   cout << "query param \"a\": " << copy.getQueryParam( "a" ) << endl;
   cout << "query param \"c\": " << u.getQueryParam( "c" ) << endl;
   cout << "query param \"c\": " << copy.getQueryParam( "c" ) << endl;
   cout << "is relative: " << u.isRelative() << endl;
   cout << "is relative: " << copy.isRelative() << endl;
#endif

   if ( u.getScheme() != copy.getScheme()
         or u.getAuthority() != copy.getAuthority()
         or u.getQuery() != copy.getQuery() or u.getPath() != copy.getPath()
         or u.getFragment() != copy.getFragment()
         or u.getQueryParam( "a" ) != copy.getQueryParam( "a" )
         or u.getQueryParam( "c" ) != copy.getQueryParam( "c" )
         or u.isRelative() != copy.isRelative() ) {
      LOG_WARN( "copy of uri: FAILED" );
   } else {
      LOG_NOTICE( "copy of uri: PASSED" );
   }

   return 0;
}