Bug 107517 - JuK ignores KDE proxy exception setting for MusicBrainz
Summary: JuK ignores KDE proxy exception setting for MusicBrainz
Status: RESOLVED FIXED
Alias: None
Product: juk
Classification: Applications
Component: general (show other bugs)
Version: 2.2.1
Platform: unspecified Linux
: NOR normal with 20 votes (vote)
Target Milestone: ---
Assignee: Scott Wheeler
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-16 08:11 UTC by N.Cat
Modified: 2005-10-05 23:46 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description N.Cat 2005-06-16 08:11:48 UTC
Version:           2.2.1 (using KDE 3.4.1, Debian Package 4:3.4.1-1 (3.1))
Compiler:          gcc version 3.3.6 (Debian 1:3.3.6-5)
OS:                Linux (i686) release 2.6.11-1-k7

When a proxy server for kio_http has been manually configured in kcontrol and "Use proxy only for entries in this list" is enabled for the exception list, JuK still attempts to use the proxy server for queries to the MusicBrainz server, resulting in a connection failure.

To reproduce:
1. Add a proxy server in kcontrol (any address is fine)
2. Add a site that the proxy should apply to
3. Check "Use proxy only for entries in this list"
4. Restart juk (needed to reload proxy settings, perhaps this should be filed as a bug too)
5. Try to get juk to query MusicBrainz

I've not had a chance to check whether this occurs with non-Debian builds of juk, or looked at the MusicBrainz query code at this time, but this consistently happens on the Debians builds with current musicbrainz libraries.
Comment 1 Scott Wheeler 2005-09-27 16:32:07 UTC
This is kind of a hard one because the URL is handled completely internally to MusicBrainz.  We basically pass some things we would like to look up and it has a place to specify the proxy, but its proxy handling is pretty simplistic...

So, basically we could either hard code it (a little ugly) or try to convince Robert to export the URL.  We might go with the former for the next release and see if we can convince him of the latter for something later.
Comment 2 Michael Pyne 2005-10-05 23:46:30 UTC
SVN commit 467659 by mpyne:

Backport fix for bug 107517 (JuK ignores MusicBrainz proxy exceptions) to KDE 3.4.  Should
be in KDE 3.4.3.

I've also fixed it for 3.5 but forgot to CC the bug.

Thanks to Thiago for advice on the implementation.

BUG:107517


 M  +49 -2     ktrm.cpp  


--- branches/KDE/3.4/kdemultimedia/juk/ktrm.cpp #467658:467659
@@ -24,11 +24,13 @@
 #if HAVE_MUSICBRAINZ
 
 #include <kapplication.h>
+#include <kresolver.h>
 #include <kprotocolmanager.h>
 #include <kurl.h>
 #include <kdebug.h>
 
 #include <qmutex.h>
+#include <qregexp.h>
 #include <qevent.h>
 #include <qobject.h>
 #include <qfile.h>
@@ -121,9 +123,52 @@
         tp_SetUseUTF8(m_pimp, true);
         tp_SetNotifyCallback(m_pimp, TRMNotifyCallback, 0);
 
+        // Re-read proxy config.
+        KProtocolManager::reparseConfiguration();
+
         if(KProtocolManager::useProxy()) {
-            KURL proxy = KProtocolManager::proxyFor("http");
-            tp_SetProxy(m_pimp, proxy.host().latin1(), short(proxy.port()));
+            // split code copied from kcm_kio.
+            QString noProxiesFor = KProtocolManager::noProxyFor();
+            QStringList noProxies = QStringList::split(QRegExp("[',''\t'' ']"), noProxiesFor);
+            bool useProxy = true;
+
+            // Host that libtunepimp will contact.
+            QString tunepimpHost = "www.musicbrainz.org";
+            QString tunepimpHostWithPort = "www.musicbrainz.org:80";
+
+            // Check what hosts are allowed to proceed without being proxied,
+            // or is using reversed proxy, what hosts must be proxied.
+            for(QStringList::ConstIterator it = noProxies.constBegin(); it != noProxies.constEnd(); ++it) {
+                QString normalizedHost = KNetwork::KResolver::normalizeDomain(*it);
+
+                if(normalizedHost == tunepimpHost ||
+                   tunepimpHost.endsWith("." + normalizedHost))
+                {
+                    useProxy = false;
+                    break;
+                }
+
+                // KDE's proxy mechanism also supports exempting a specific
+                // host/port combo, check that also.
+                if(normalizedHost == tunepimpHostWithPort ||
+                   tunepimpHostWithPort.endsWith("." + normalizedHost))
+                {
+                    useProxy = false;
+                    break;
+                }
+            }
+
+            // KDE supports a reverse proxy mechanism.  Uh, yay.
+            if(KProtocolManager::useReverseProxy())
+                useProxy = !useProxy;
+
+            if(useProxy) {
+                KURL proxy = KProtocolManager::proxyFor("http");
+                QString proxyHost = proxy.host();
+
+                kdDebug(65432) << "Using proxy server " << proxyHost << " for www.musicbrainz.org.\n";
+                tp_SetProxy(m_pimp, proxyHost.latin1(), short(proxy.port()));
+            }
         }
     }
 
@@ -505,3 +550,5 @@
 }
 
 #endif
+
+// vim: set et ts=8 sw=4: