[Xfce4-commits] <xfce4-weather-plugin:master> Add function for performing HTTP requests using libsoup.

Harald Judt noreply at xfce.org
Tue Nov 20 20:18:02 CET 2012


Updating branch refs/heads/master
         to e4d8aa09938564c25832128b7a1f34ffc9ad6074 (commit)
       from a1465cce448e3cc8d13e6aa515790e8be7ac5e96 (commit)

commit e4d8aa09938564c25832128b7a1f34ffc9ad6074
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Nov 20 19:58:22 2012 +0100

    Add function for performing HTTP requests using libsoup.
    
    It will get the proxy server from the environment variables if set.
    In the future, the proxy server settings will be removed from any
    data structures and the configuration dialog, as they are usually
    configured elsewhere.
    
    Also add a callback function type for handling our session callbacks.

 panel-plugin/weather-http.c |   27 +++++++++++++++++++++++++++
 panel-plugin/weather-http.h |   10 ++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/panel-plugin/weather-http.c b/panel-plugin/weather-http.c
index 8e1500b..491b0b4 100644
--- a/panel-plugin/weather-http.c
+++ b/panel-plugin/weather-http.c
@@ -512,3 +512,30 @@ weather_http_cleanup_queue(void)
         }
     }
 }
+
+
+void
+weather_http_queue_request(const gchar *uri,
+                           SoupSessionCallback callback_func,
+                           gpointer user_data)
+{
+    SoupSession *session;
+    SoupMessage *msg;
+    SoupURI *soup_proxy_uri;
+    const gchar *proxy_uri;
+
+    /* create a new soup session */
+    session = soup_session_async_new();
+
+    /* Set the proxy URI if any */
+    proxy_uri = g_getenv("http_proxy");
+
+    if (proxy_uri != NULL) {
+        soup_proxy_uri = soup_uri_new (proxy_uri);
+        g_object_set(session, "proxy-uri", soup_proxy_uri, NULL);
+        soup_uri_free(soup_proxy_uri);
+    }
+
+    msg = soup_message_new("GET", uri);
+    soup_session_queue_message(session, msg, callback_func, user_data);
+}
diff --git a/panel-plugin/weather-http.h b/panel-plugin/weather-http.h
index 9a7f99f..c423ed4 100644
--- a/panel-plugin/weather-http.h
+++ b/panel-plugin/weather-http.h
@@ -19,6 +19,8 @@
 #ifndef __WEATHER_HTTP_H__
 #define __WEATHER_HTTP_H__
 
+#include <libsoup/soup.h>
+
 G_BEGIN_DECLS
 
 typedef void (*WeatherFunc) (gboolean succeed,
@@ -26,6 +28,10 @@ typedef void (*WeatherFunc) (gboolean succeed,
                              size_t len,
                              gpointer user_data);
 
+typedef void (*SoupSessionCallback) (SoupSession *session,
+                                     SoupMessage *msg,
+                                     gpointer user_data);
+
 
 void weather_http_cleanup_queue(void);
 
@@ -36,6 +42,10 @@ void weather_http_receive_data(const gchar *hostname,
                                const WeatherFunc cb_func,
                                gpointer user_data);
 
+void weather_http_queue_request(const gchar *uri,
+                                SoupSessionCallback callback_func,
+                                gpointer user_data);
+
 G_END_DECLS
 
 #endif


More information about the Xfce4-commits mailing list