! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
HTTP Proxy prevents plugin from downloading weather data
Status:
RESOLVED: FIXED
Severity:
blocker
Product:
Xfce4-weather-plugin
Component:
General

Comments

Description Issa 2014-04-15 13:10:27 CEST
Created attachment 5433 
debug session

I have to use a proxy with authentication to access Internet.

The plugin does not show any results when searching for location.

Please note that the proxy settings are set perfectly. I can update packages without problem form YaST. The proxy settings are set via YaST.

Is this a problem in libsoup ? or libproxy ?
Comment 1 Harald Judt 2014-04-15 13:29:47 CEST
Is the HTTP_PROXY (or http_proxy) environment variable set to a value like "http://username:password@host:port"? The plugin reads that environment variable and hands it on to libsoup.
Comment 2 Issa 2014-04-15 17:09:48 CEST
With http_proxy set with or without credentials - the result is the same error - proxy returns 407.
Comment 3 Issa 2014-04-15 17:23:15 CEST
https://developer.gnome.org/libsoup/stable/libsoup-client-howto.html

It seems the code is not handling http authentication...
Comment 4 Harald Judt 2014-04-15 17:50:05 CEST
Honestly, I have never needed nor tested proxy authentication, so this is very likely true. To fix it, I will have to find out how to read username and password and if it is really stored in that http_proxy env var. Maybe you could look that up? Did you have to set http_proxy manually? If that is all that's needed, it shouldn't be hard to extract those two values from the env variable.
Comment 5 Issa 2014-04-18 11:54:20 CEST
Hi,

Please find a patch which seems to work at my side. I would request to review the code because I'm a regular JAVA programmer and memory management in C is not something I do.

diff -u -r xfce4-weather-plugin-0.8.3/panel-plugin/weather.c xfce4-weather-plugin-0.8.3.proxy/panel-plugin/weather.c
--- xfce4-weather-plugin-0.8.3/panel-plugin/weather.c	2013-02-18 11:21:00.000000000 +0100
+++ xfce4-weather-plugin-0.8.3.proxy/panel-plugin/weather.c	2014-04-18 11:51:50.845916058 +0200
@@ -1481,6 +1481,33 @@
     update_weatherdata_with_reset(data);
 }
 
+static void
+proxy_auth(SoupSession *session,
+           SoupMessage *msg,
+           SoupAuth *auth,
+           gboolean retrying,
+           gpointer user_data)
+{
+    SoupURI *soup_proxy_uri;
+    const gchar *proxy_uri;
+
+
+    if (!retrying) {
+        if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
+            proxy_uri = g_getenv("HTTP_PROXY");
+            if (!proxy_uri)
+                proxy_uri = g_getenv("http_proxy");
+            if (proxy_uri) {
+                soup_proxy_uri = soup_uri_new(proxy_uri);
+                soup_auth_authenticate(auth,
+                                       soup_uri_get_user(soup_proxy_uri),
+                                       soup_uri_get_password(soup_proxy_uri));
+                soup_uri_free(soup_proxy_uri);
+            }
+        }
+    }
+}
+
 
 #ifdef HAVE_UPOWER_GLIB
 static void
@@ -1783,6 +1810,13 @@
         soup_proxy_uri = soup_uri_new (proxy_uri);
         g_object_set(data->session, SOUP_SESSION_PROXY_URI,
                      soup_proxy_uri, NULL);
+
+		/* check if uri contains authentication info */
+		if (strlen(soup_uri_get_user(soup_proxy_uri)) > 0) {
+			g_signal_connect(G_OBJECT(data->session), "authenticate",
+			                 G_CALLBACK(proxy_auth), NULL);
+		}
+		
         soup_uri_free(soup_proxy_uri);
     }
Comment 6 Issa 2014-04-22 13:20:31 CEST
Please remove comment 5 - when there is no creds into http_proxy - the plugin will not start...

Fixed patch

--- xfce4-weather-plugin-0.8.3/panel-plugin/weather.c	2013-02-18 11:21:00.000000000 +0100
+++ xfce4-weather-plugin-0.8.3.proxy/panel-plugin/weather.c	2014-04-22 13:14:15.225100772 +0200
@@ -1481,6 +1481,33 @@
     update_weatherdata_with_reset(data);
 }
 
+static void
+proxy_auth(SoupSession *session,
+           SoupMessage *msg,
+           SoupAuth *auth,
+           gboolean retrying,
+           gpointer user_data)
+{
+    SoupURI *soup_proxy_uri;
+    const gchar *proxy_uri;
+
+
+    if (!retrying) {
+        if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
+            proxy_uri = g_getenv("HTTP_PROXY");
+            if (!proxy_uri)
+                proxy_uri = g_getenv("http_proxy");
+            if (proxy_uri) {
+                soup_proxy_uri = soup_uri_new(proxy_uri);
+                soup_auth_authenticate(auth,
+                                       soup_uri_get_user(soup_proxy_uri),
+                                       soup_uri_get_password(soup_proxy_uri));
+                soup_uri_free(soup_proxy_uri);
+            }
+        }
+    }
+}
+
 
 #ifdef HAVE_UPOWER_GLIB
 static void
@@ -1742,6 +1769,7 @@
     plugin_data *data = g_slice_new0(plugin_data);
     SoupURI *soup_proxy_uri;
     const gchar *proxy_uri;
+    const char *proxy_user;
     GtkWidget *refresh;
     data_types lbl;
     GdkPixbuf *icon = NULL;
@@ -1783,6 +1811,14 @@
         soup_proxy_uri = soup_uri_new (proxy_uri);
         g_object_set(data->session, SOUP_SESSION_PROXY_URI,
                      soup_proxy_uri, NULL);
+
+		/* check if uri contains authentication info */
+               proxy_user = soup_uri_get_user(soup_proxy_uri);
+		if (proxy_user && strlen(proxy_user) > 0) {
+			g_signal_connect(G_OBJECT(data->session), "authenticate",
+			                 G_CALLBACK(proxy_auth), NULL);
+		}
+		
         soup_uri_free(soup_proxy_uri);
     }
Comment 7 Harald Judt 2014-04-26 09:04:03 CEST
I have applied your patch to current git:
http://git.xfce.org/panel-plugins/xfce4-weather-plugin/commit/?id=19458ea08d85aa6c48f3866f3ee2069517d4640d

I could not test proxy authentication due to the lack of a proper test environment for this, but the patch seems sane to me and the plugin also functions normally without any HTTP_PROXY authentication set. Using soup_uri_get_user bumps libsoup requirements to 2.32 (previously 2.26).

Thanks for the patch, the fix will be included in the next version. Note that git head - while stable - has a few bugs with the update routine and is in state of rewrite.

Bug #10820

Reported by:
Issa
Reported on: 2014-04-15
Last modified on: 2014-04-26

People

Assignee:
Harald Judt
CC List:
1 user

Version

Attachments

debug session (71.06 KB, text/plain)
2014-04-15 13:10 CEST , Issa
no flags

Additional information