[Goodies-commits] r7696 - in xfce4-weather-plugin/trunk: . panel-plugin po

Colin Leroy colin at xfce.org
Wed Jul 8 19:20:18 CEST 2009


Author: colin
Date: 2009-07-08 17:20:18 +0000 (Wed, 08 Jul 2009)
New Revision: 7696

Modified:
   xfce4-weather-plugin/trunk/ChangeLog
   xfce4-weather-plugin/trunk/panel-plugin/weather-http.c
   xfce4-weather-plugin/trunk/panel-plugin/weather.c
   xfce4-weather-plugin/trunk/po/xfce4-weather-plugin.pot
Log:
Finish fixing bug 5055; use getaddrinfo() instead of gethostbyname()


Modified: xfce4-weather-plugin/trunk/ChangeLog
===================================================================
--- xfce4-weather-plugin/trunk/ChangeLog	2009-07-08 14:23:15 UTC (rev 7695)
+++ xfce4-weather-plugin/trunk/ChangeLog	2009-07-08 17:20:18 UTC (rev 7696)
@@ -1,3 +1,15 @@
+2009-07-07	Colin Leroy <colin at colino.net>
+
+	* panel-plugin/weather.c: Finish fixing bug 5505, 'some strings are not 
+	localized'
+	* panel-plugin/weather-http.c: use the non-deprecated getaddrinfo() 
+	instead of gethostbyname()
+
+2009-07-07	Colin Leroy <colin at colino.net>
+
+	* panel-plugin/weather-translate.c: Fix bug 5505, 'some strings are not 
+	localized'
+
 2009-06-24	Colin Leroy <colin at colino.net>
 
 	* Release 0.7.0

Modified: xfce4-weather-plugin/trunk/panel-plugin/weather-http.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/weather-http.c	2009-07-08 14:23:15 UTC (rev 7695)
+++ xfce4-weather-plugin/trunk/panel-plugin/weather-http.c	2009-07-08 17:20:18 UTC (rev 7696)
@@ -125,20 +125,7 @@
 static void refresh_resolvers(void)
 {
 #ifdef G_OS_UNIX
-	static time_t resolv_conf_changed = (time_t)NULL;
-	struct stat s;
-
-	/* This makes the glibc re-read resolv.conf, if it changed
-	 * since our startup. 
-	 * Why doesn't the glibc do it by itself?
-	 */
-	if (stat("/etc/resolv.conf", &s) == 0) {
-		if (s.st_mtime > resolv_conf_changed) {
-			resolv_conf_changed = s.st_mtime;
-			res_init();
-		}
-	} /* else
-		we'll have bigger problems. */
+	res_init();
 #endif /*G_OS_UNIX*/
 }
 
@@ -158,8 +145,11 @@
   gchar               buffer[1024];
   gint                bytes, n, m;
   gchar              *request;
-  struct hostent     *host;
-  struct sockaddr_in  sockaddr;
+  
+  struct addrinfo     h, *r, *a;
+  const gchar         *port = NULL;
+  gint                err;
+
   const gchar        *p;
   GTimeVal            timeout;
 #ifdef G_OS_UNIX
@@ -184,16 +174,30 @@
 #ifdef G_OS_UNIX
   alarm(WEATHER_MAX_CONN_TIMEOUT);
 #endif
-  host = gethostbyname (connection->proxy_host ? connection->proxy_host : connection->hostname);
+
+  memset(&h, 0, sizeof(h));
+  h.ai_family = AF_INET;
+  h.ai_socktype = SOCK_STREAM;
+  h.ai_protocol = IPPROTO_TCP;
+  
+  if (connection->proxy_port)
+  	port = g_strdup_printf("%d", connection->proxy_port);
+  else
+  	port = g_strdup("80");
+  
+  err = getaddrinfo(connection->proxy_host ? connection->proxy_host : connection->hostname,
+  		port, &h, &r);
+
+  g_free(port);
 #ifdef G_OS_UNIX
   alarm(0);
   signal(SIGALRM, prev_handler);
 #endif
 
-  if (G_UNLIKELY (host == NULL))
+  if (G_UNLIKELY (err != 0))
     {
       /* display error */
-      g_message (_("Failed to get the hostname. Retry in %d seconds."),
+      g_message (_("Failed to get the hostname %s. Retry in %d seconds."), gai_strerror(err),
                  WEATHER_RESCHEDULE_TIMEOUT / 1000);
 
       /* try again later */
@@ -206,7 +210,31 @@
     return FALSE;
 
   /* open the socket */
-  connection->fd = socket (PF_INET, SOCK_STREAM, 0);
+  
+  for (a = r; a != NULL; a = a->ai_next) {
+    connection->fd = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
+    if (connection->fd < 0) {
+      err = errno;
+      continue;
+    }
+#ifdef G_OS_UNIX
+    signal(SIGALRM, timeout_handler);
+    alarm(WEATHER_MAX_CONN_TIMEOUT);
+#endif
+    m = connect (connection->fd, a->ai_addr, a->ai_addrlen);
+#ifdef G_OS_UNIX
+    alarm(0);
+    signal(SIGALRM, prev_handler);
+#endif
+    if (m == 0)
+      break;
+    else 
+      err = errno;
+
+    if (weather_http_receive_data_check (connection, timeout))
+      break;
+  }
+
   if (G_UNLIKELY (connection->fd < 0))
     {
       /* display warning */
@@ -218,25 +246,6 @@
       return FALSE;
     }
 
-  if (weather_http_receive_data_check (connection, timeout))
-    return FALSE;
-
-  /* complete the host information */
-  sockaddr.sin_family = PF_INET;
-  sockaddr.sin_port = htons (connection->proxy_port ? connection->proxy_port : 80);
-  sockaddr.sin_addr = *((struct in_addr *)host->h_addr);
-  memset(&(sockaddr.sin_zero), '\0', 8);
-
-  /* open a connection with the host */
-#ifdef G_OS_UNIX
-  signal(SIGALRM, timeout_handler);
-  alarm(WEATHER_MAX_CONN_TIMEOUT);
-#endif
-  m = connect (connection->fd, (struct sockaddr *)&sockaddr, sizeof(struct sockaddr));
-#ifdef G_OS_UNIX
-  alarm(0);
-  signal(SIGALRM, prev_handler);
-#endif
   if (G_UNLIKELY (m < 0))
     {
       /* display warning */

Modified: xfce4-weather-plugin/trunk/panel-plugin/weather.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/weather.c	2009-07-08 14:23:15 UTC (rev 7695)
+++ xfce4-weather-plugin/trunk/panel-plugin/weather.c	2009-07-08 17:20:18 UTC (rev 7696)
@@ -172,6 +172,9 @@
     case WIND_GUST:
       value = translate_wind_speed (rawvalue, unit);
       break;
+    case BAR_D:
+      value = translate_bard(rawvalue);
+      break;
     default:
       value = NULL;
       break;

Modified: xfce4-weather-plugin/trunk/po/xfce4-weather-plugin.pot
===================================================================
--- xfce4-weather-plugin/trunk/po/xfce4-weather-plugin.pot	2009-07-08 14:23:15 UTC (rev 7695)
+++ xfce4-weather-plugin/trunk/po/xfce4-weather-plugin.pot	2009-07-08 17:20:18 UTC (rev 7696)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-07-07 06:55+0200\n"
+"POT-Creation-Date: 2009-07-08 19:18+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -56,22 +56,22 @@
 msgid "WG"
 msgstr ""
 
-#: ../panel-plugin/weather.c:261 ../panel-plugin/weather.c:747
+#: ../panel-plugin/weather.c:264 ../panel-plugin/weather.c:750
 msgid "Cannot update weather data"
 msgstr ""
 
-#: ../panel-plugin/weather.c:680
+#: ../panel-plugin/weather.c:683
 #, c-format
 msgid "Unable to open the following url: %s"
 msgstr ""
 
-#: ../panel-plugin/weather.c:708 ../panel-plugin/weather-summary.c:556
+#: ../panel-plugin/weather.c:711 ../panel-plugin/weather-summary.c:556
 #: ../panel-plugin/weather.desktop.in.in.h:2
 msgid "Weather Update"
 msgstr ""
 
 #. add refresh button to right click menu, for people who missed the middle mouse click feature
-#: ../panel-plugin/weather.c:828
+#: ../panel-plugin/weather.c:831
 msgid "_Forecast"
 msgstr ""
 
@@ -197,41 +197,41 @@
 msgstr ""
 
 #. display error
-#: ../panel-plugin/weather-http.c:196
+#: ../panel-plugin/weather-http.c:200
 #, c-format
-msgid "Failed to get the hostname. Retry in %d seconds."
+msgid "Failed to get the hostname %s. Retry in %d seconds."
 msgstr ""
 
 #. display warning
-#: ../panel-plugin/weather-http.c:213
+#: ../panel-plugin/weather-http.c:241
 #, c-format
 msgid "Failed to open the socket (%s)."
 msgstr ""
 
 #. display warning
-#: ../panel-plugin/weather-http.c:243
+#: ../panel-plugin/weather-http.c:252
 #, c-format
 msgid "Failed to create a connection with the host (%s)."
 msgstr ""
 
 #. display warning
-#: ../panel-plugin/weather-http.c:280
+#: ../panel-plugin/weather-http.c:289
 #, c-format
 msgid "Failed to send the request (%s)."
 msgstr ""
 
 #. display warning
-#: ../panel-plugin/weather-http.c:317
+#: ../panel-plugin/weather-http.c:326
 #, c-format
 msgid "Failed to receive data (%s)"
 msgstr ""
 
 #. display warning
-#: ../panel-plugin/weather-http.c:358
+#: ../panel-plugin/weather-http.c:367
 msgid "Unable to detect the content length."
 msgstr ""
 
-#: ../panel-plugin/weather-http.c:366
+#: ../panel-plugin/weather-http.c:375
 msgid "No content received."
 msgstr ""
 




More information about the Goodies-commits mailing list