Q: Using a proxy or not given an url
Koos Vriezen
koos.vriezen at xs4all.nl
Sat Feb 15 14:09:41 GMT 2003
On Sat, 15 Feb 2003, David Faure wrote:
> On Friday 14 February 2003 17:43, Koos Vriezen wrote:
> > Hi,
> >
> > What is the most easy way to determine if a given URL should use a proxy
> > or not? KProtocolManager::proxyForURL doesn't look at the noProxyFor urls.
> > Seems somewhat primitive to check that string myself.
> >
> > Before using gdb to see why it works with konqueror, maybe someone just knows.
>
> KProtocolManager::slaveProtocol() has some code that looks like a good
> candidate for being moved to a separate method, indeed.
Seems to me that proxyForURL doesn't fully cover what it name implies.
Anyway below what I added in kmplayer (bad to copy code like that)
....uhm this doesn't work for mms:// urls aaarch :-(
Checking 'Use same proxy server for all protocols' adds this to kioslaverc
ftpProxy=http://localhost:3128
httpProxy=http://localhost:3128
httpsProxy=http://localhost:3128
(doesn't look very extendable this way...I need another workaround :-( )
Koos
ps. private code for proxyForURL that accounts for exceptions
//merge KProtocolManager::proxyForURL and KProtocolManager::slaveProtocol
static bool revmatch(const char *host, const char *nplist) {
if (host == 0) return false;
const char *hptr = host + strlen( host ) - 1;
const char *nptr = nplist + strlen( nplist ) - 1;
const char *shptr = hptr;
while (nptr >= nplist) {
if (*hptr != *nptr) {
hptr = shptr;
// Try to find another domain or host in the list
while (--nptr >= nplist && *nptr != ',' && *nptr != ' ');
// Strip out multiple spaces and commas
while (--nptr >= nplist && (*nptr == ',' || *nptr == ' '));
} else {
if (nptr == nplist || nptr[-1] == ',' || nptr[-1] == ' ')
return true;
hptr--;
nptr--;
}
}
return false;
}
static bool proxyForURL (const KURL & url, QString & proxy) {
proxy = KProtocolManager::proxyForURL (url);
if (!proxy.isEmpty() && proxy != QString::fromLatin1 ("DIRECT")) {
QString noProxy = KProtocolManager::noProxyFor ();
KProtocolManager::ProxyType type = KProtocolManager::proxyType();
bool useRevProxy = ((type == KProtocolManager::ManualProxy ||
type == KProtocolManager::EnvVarProxy) &&
KProtocolManager::useReverseProxy ());
bool isRevMatch = false;
if (!noProxy.isEmpty()) {
QString qhost = url.host().lower();
const char *host = qhost.latin1();
QString qno_proxy = noProxy.stripWhiteSpace().lower();
const char *no_proxy = qno_proxy.latin1();
isRevMatch = revmatch(host, no_proxy);
// If the hostname does not contain a dot, check if
// <local> is part of noProxy.
if (!isRevMatch && host && (strchr(host, '.') == NULL))
isRevMatch = revmatch("<local>", no_proxy);
}
if ((!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch))
return true;
}
return false;
}
More information about the kfm-devel
mailing list