Bug 131377

Summary: MusicBrainz lookup in Amarok is missing support for proxy exceptions
Product: [Applications] amarok Reporter: N.Cat <trisk-bug>
Component: generalAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.4.1   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Patch for proxy exception support

Description N.Cat 2006-07-26 04:44:11 UTC
Version:           1.4.1 (using KDE KDE 3.5.4)
Installed from:    Compiled From Sources

MusicBrainz lookup in Amarok uses the HTTP proxy server defined in kcontrol. It will try to use the proxy server even if "Use proxy only for entries in this list" is enabled in kcontrol, which is not correct behaviour and causes it to fail here.

I've converted the fix (with a slight improvement) by Michael Pyne for the same bug in JuK (#107517). This allows Amarok to check the exception list and only use the proxy if it is actually enabled for the MusicBrainz site.

It's possible the proxy support is broken in tunepimp altogether, see #118288.
Comment 1 N.Cat 2006-07-26 04:45:39 UTC
Created attachment 17129 [details]
Patch for proxy exception support

This is the patch that correctly fixes the problem, also available at
http://trisk.acm.jhu.edu/ktrm-proxy-exception.diff
Comment 2 Martin Aumueller 2006-07-30 00:03:43 UTC
SVN commit 567716 by aumuell:

proxy exceptions for musicbrainz lookups
BUG: 131377


 M  +2 -0      ChangeLog  
 M  +35 -2     src/ktrm.cpp  


--- trunk/extragear/multimedia/amarok/ChangeLog #567715:567716
@@ -68,6 +68,8 @@
       since the last time it was enabled.
 
   BUGFIXES:
+    * Honour proxy exceptions for MusicBrainz lookups. Patch by N. Cat
+      <trisk-bug@quasarnet.org>. (BR 131377)
     * Correctly pass links containing parentheses to external browsers. Patch
       by Thomas Lindroth <tholi945@student.liu.se>. (BR 131307)
     * iPods would not show podcast descriptions. (BR 129824)
--- trunk/extragear/multimedia/amarok/src/ktrm.cpp #567715:567716
@@ -28,6 +28,7 @@
 #include <kapplication.h>
 #include <kprotocolmanager.h>
 #include <kurl.h>
+#include <kresolver.h>
 
 #include <qmutex.h>
 #include <qevent.h>
@@ -142,9 +143,41 @@
 #endif
         tp_SetNotifyCallback(m_pimp, TRMNotifyCallback, 0);
 
+        KProtocolManager::reparseConfiguration();
+
         if(KProtocolManager::useProxy()) {
-            KURL proxy = KProtocolManager::proxyFor("http");
-            tp_SetProxy(m_pimp, proxy.host().latin1(), short(proxy.port()));
+            QString noProxiesFor = KProtocolManager::noProxyFor();
+            QStringList noProxies = QStringList::split(QRegExp("[',''\t'' ']"), noProxiesFor);
+            bool useProxy = true;
+
+            char server[255];
+            short port;
+            tp_GetServer(m_pimp, server, 255, &port);
+            QString tunepimpHost = QString(server);
+            QString tunepimpHostWithPort = (tunepimpHost + ":%1").arg(port);
+
+            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;
+                }
+
+                if(normalizedHost == tunepimpHostWithPort ||
+                    tunepimpHostWithPort.endsWith("." + normalizedHost)) {
+                    useProxy = false;
+                    break;
+                }
+            }
+
+            if(KProtocolManager::useReverseProxy())
+                useProxy = !useProxy;
+
+            if(useProxy) {
+                KURL proxy = KProtocolManager::proxyFor("http");
+                tp_SetProxy(m_pimp, proxy.host().latin1(), short(proxy.port()));
+            }
         }
     }