libgweather r488 - in trunk: . libgweather



Author: danw
Date: Fri Oct 17 19:30:01 2008
New Revision: 488
URL: http://svn.gnome.org/viewvc/libgweather?rev=488&view=rev

Log:
	* libgweather/weather.c (weather_info_network_error): Add this so
	we can distinguish "the requested code was invalid" from "we
	couldn't access the METAR site". Needed for #556776

	* libgweather/weather-metar.c (metar_finish): set network_error if
	the soup request gets a "transport error" status code, or if it
	gets back an HTML page that looks like it didn't come from the
	METAR server.


Modified:
   trunk/ChangeLog
   trunk/libgweather/weather-metar.c
   trunk/libgweather/weather-priv.h
   trunk/libgweather/weather.c
   trunk/libgweather/weather.h

Modified: trunk/libgweather/weather-metar.c
==============================================================================
--- trunk/libgweather/weather-metar.c	(original)
+++ trunk/libgweather/weather-metar.c	Fri Oct 17 19:30:01 2008
@@ -494,9 +494,13 @@
     g_return_if_fail (info != NULL);
    
     if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-        /* Translators: %d is an error code, and %s the error string */
-        g_warning (_("Failed to get METAR data: %d %s.\n"),
-		   msg->status_code, msg->reason_phrase);
+	if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
+	    info->network_error = TRUE;
+	else {
+	    /* Translators: %d is an error code, and %s the error string */
+	    g_warning (_("Failed to get METAR data: %d %s.\n"),
+		       msg->status_code, msg->reason_phrase);
+	}
 	request_done (info, FALSE);
 	return;
     }
@@ -515,6 +519,12 @@
 	    metar = g_strdup (p);
 	success = metar_parse (metar, info);
 	g_free (metar);
+    } else if (!strstr (msg->response_body->data, "National Weather Service")) {
+	/* The response doesn't even seem to have come from NWS...
+	 * most likely it is a wifi hotspot login page. Call that a
+	 * network error.
+	 */
+	info->network_error = TRUE;
     }
 
     info->valid = success;
@@ -529,7 +539,7 @@
     SoupMessage *msg;
 
     g_return_if_fail (info != NULL);
-    info->valid = FALSE;
+    info->valid = info->network_error = FALSE;
     loc = info->location;
     if (loc == NULL) {
 	g_warning (_("WeatherInfo missing location"));

Modified: trunk/libgweather/weather-priv.h
==============================================================================
--- trunk/libgweather/weather-priv.h	(original)
+++ trunk/libgweather/weather-priv.h	Fri Oct 17 19:30:01 2008
@@ -137,6 +137,7 @@
     DistanceUnit distance_unit;
 
     gboolean valid;
+    gboolean network_error;
     gboolean sunValid;
     WeatherLocation *location;
     WeatherUpdate update;

Modified: trunk/libgweather/weather.c
==============================================================================
--- trunk/libgweather/weather.c	(original)
+++ trunk/libgweather/weather.c	Fri Oct 17 19:30:01 2008
@@ -614,6 +614,13 @@
     return info->valid;
 }
 
+gboolean
+weather_info_network_error (WeatherInfo *info)
+{
+    g_return_val_if_fail (info != NULL, FALSE);
+    return info->network_error;
+}
+
 const WeatherLocation *
 weather_info_get_location (WeatherInfo *info)
 {

Modified: trunk/libgweather/weather.h
==============================================================================
--- trunk/libgweather/weather.h	(original)
+++ trunk/libgweather/weather.h	Fri Oct 17 19:30:01 2008
@@ -142,6 +142,7 @@
 void			weather_info_free		(WeatherInfo *info);
 
 gboolean		weather_info_is_valid		(WeatherInfo *info);
+gboolean		weather_info_network_error	(WeatherInfo *info);
 
 void			weather_info_to_metric		(WeatherInfo *info);
 void			weather_info_to_imperial	(WeatherInfo *info);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]