[Xfce4-commits] <xfce4-weather-plugin:master> Update geolocation callback function for libsoup.
Harald Judt
noreply at xfce.org
Tue Nov 20 20:18:06 CET 2012
Updating branch refs/heads/master
to 6d1554fa46eab3744105eb2478e60734d9584fce (commit)
from c68cfd20d2f0de5ef50b4d9f99de4bb43e57b75c (commit)
commit 6d1554fa46eab3744105eb2478e60734d9584fce
Author: Harald Judt <h.judt at gmx.at>
Date: Tue Nov 20 20:02:50 2012 +0100
Update geolocation callback function for libsoup.
panel-plugin/weather-search.c | 49 ++++++-----------------------------------
1 files changed, 7 insertions(+), 42 deletions(-)
diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c
index 33c4375..ecfcf9c 100644
--- a/panel-plugin/weather-search.c
+++ b/panel-plugin/weather-search.c
@@ -36,8 +36,6 @@
typedef struct {
- const gchar *proxy_host;
- gint proxy_port;
void (*cb) (const gchar *loc_name,
const gchar *lat,
const gchar *lon,
@@ -353,49 +351,18 @@ get_preferred_unit_system(const gchar *country_code)
static void
-cb_geolocation(const gboolean succeed,
- gchar *received,
- const size_t len,
+cb_geolocation(SoupSession *session,
+ SoupMessage *msg,
gpointer user_data)
{
geolocation_data *data = (geolocation_data *) user_data;
- xmlDoc *doc;
xml_geolocation *geo;
gchar *full_loc, *p;
unit_systems unit_system;
gsize length;
- if (!succeed || received == NULL) {
- data->cb(NULL, NULL, NULL, METRIC, data->user_data);
- g_free(data);
- return;
- }
-
- /* hack for geoip.xfce.org, which return no content-length */
- p = strstr(received, "</Response>");
- if (p != NULL)
- length = p - received + strlen("</Response>");
- else
- length = strlen(received);
-
- if (g_utf8_validate(received, -1, NULL)) {
- /* force parsing as UTF-8, the XML encoding header may lie */
- doc = xmlReadMemory(received, length, NULL, "UTF-8", 0);
- } else
- doc = xmlParseMemory(received, length);
- g_free(received);
-
- if (!doc) {
- data->cb(NULL, NULL, NULL, METRIC, data->user_data);
- g_free(data);
- return;
- }
-
- geo = parse_geolocation(xmlDocGetRootElement(doc));
- xmlFreeDoc(doc);
- weather_dump(weather_dump_geolocation, geo);
-
- if (geo == NULL) {
+ if (!(geo = (xml_geolocation *)
+ parse_xml_document(msg, (XmlParseFunc) parse_geolocation))) {
data->cb(NULL, NULL, NULL, METRIC, data->user_data);
g_free(data);
return;
@@ -421,7 +388,8 @@ cb_geolocation(const gboolean succeed,
unit_system = get_preferred_unit_system(geo->country_code);
- data->cb(full_loc, geo->latitude, geo->longitude, unit_system, data->user_data);
+ data->cb(full_loc, geo->latitude, geo->longitude,
+ unit_system, data->user_data);
xml_geolocation_free(geo);
g_free(full_loc);
g_free(data);
@@ -445,10 +413,7 @@ void weather_search_by_ip(const gchar *proxy_host,
data = g_new0(geolocation_data, 1);
data->cb = gui_cb;
data->user_data = user_data;
- data->proxy_host = proxy_host;
- data->proxy_port = proxy_port;
g_message("getting http://geoip.xfce.org/");
- weather_http_receive_data("geoip.xfce.org", "/", proxy_host, proxy_port,
- cb_geolocation, data);
+ weather_http_queue_request("http://geoip.xfce.org/", cb_geolocation, data);
}
More information about the Xfce4-commits
mailing list