im.pidgin.pidgin: b4fd63bb4dd01f0dff314a75235be5fbbe7b98d0

markdoliner at pidgin.im markdoliner at pidgin.im
Tue Dec 18 03:45:39 EST 2007


-----------------------------------------------------------------
Revision: b4fd63bb4dd01f0dff314a75235be5fbbe7b98d0
Ancestor: fa5978af2779532e133e750eb81967e1f9f6c04d
Author: markdoliner at pidgin.im
Date: 2007-12-18T08:42:41
Branch: im.pidgin.pidgin

Modified files:
        libpurple/dnsquery.c libpurple/network.c libpurple/util.c
        libpurple/util.h

ChangeLog: 

Create a purple_gai_strerror() function similar to g_str_error() which
calls gai_strerror() then tries to convert the result into UTF-8.  I
believe this fixes #3003

-------------- next part --------------
============================================================
--- libpurple/dnsquery.c	e2c239b19422fcaef6ba5ad5d7ee70cf06fe8521
+++ libpurple/dnsquery.c	c4f6cf98cc75dcea5f18c4fe2f14d46025dedd9a
@@ -547,7 +547,7 @@ host_resolved(gpointer data, gint source
 	{
 #ifdef HAVE_GETADDRINFO
 		g_snprintf(message, sizeof(message), _("Error resolving %s:\n%s"),
-				query_data->hostname, gai_strerror(err));
+				query_data->hostname, purple_gai_strerror(err));
 #else
 		g_snprintf(message, sizeof(message), _("Error resolving %s: %d"),
 				query_data->hostname, err);
@@ -695,7 +695,7 @@ dns_thread(gpointer data)
 		}
 		freeaddrinfo(tmp);
 	} else {
-		query_data->error_message = g_strdup_printf(_("Error resolving %s:\n%s"), query_data->hostname, gai_strerror(rc));
+		query_data->error_message = g_strdup_printf(_("Error resolving %s:\n%s"), query_data->hostname, purple_gai_strerror(rc));
 	}
 #else
 	if ((hp = gethostbyname(query_data->hostname))) {
============================================================
--- libpurple/network.c	7962f181d8d09cd1b4471e469d9f2d44730e5b30
+++ libpurple/network.c	86079b9237ff9b29de277648ee46bb9f1b3483d1
@@ -289,7 +289,7 @@ purple_network_do_listen(unsigned short 
 	errnum = getaddrinfo(NULL /* any IP */, serv, &hints, &res);
 	if (errnum != 0) {
 #ifndef _WIN32
-		purple_debug_warning("network", "getaddrinfo: %s\n", gai_strerror(errnum));
+		purple_debug_warning("network", "getaddrinfo: %s\n", purple_gai_strerror(errnum));
 		if (errnum == EAI_SYSTEM)
 			purple_debug_warning("network", "getaddrinfo: system error: %s\n", g_strerror(errno));
 #else
============================================================
--- libpurple/util.c	a03c8c18a2d8a6d40b8b65a7f9b709930def59d5
+++ libpurple/util.c	75d6e80f91cf317963117e2a93d6b1deea89e65b
@@ -4257,7 +4257,50 @@ purple_utf8_salvage(const char *str)
 	return g_string_free(workstr, FALSE);
 }
 
+G_CONST_RETURN gchar *
+purple_gai_strerror(gint errnum)
+{
+	static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
+	char *msg;
+	int saved_errno = errno;
 
+	const char *msg_locale;
+
+	msg_locale = gai_strerror(errnum);
+	if (g_get_charset(NULL))
+	{
+		/* This string is already UTF-8--great! */
+		errno = saved_errno;
+		return msg_locale;
+	}
+	else
+	{
+		gchar *msg_utf8 = g_locale_to_utf8(msg_locale, -1, NULL, NULL, NULL);
+		if (msg_utf8)
+		{
+			/* Stick in the quark table so that we can return a static result */
+			GQuark msg_quark = g_quark_from_string(msg_utf8);
+			g_free(msg_utf8);
+
+			msg_utf8 = (gchar *)g_quark_to_string(msg_quark);
+			errno = saved_errno;
+			return msg_utf8;
+		}
+	}
+
+	msg = g_static_private_get(&msg_private);
+	if (!msg)
+	{
+		msg = g_new(gchar, 64);
+		g_static_private_set(&msg_private, msg, g_free);
+	}
+
+	sprintf(msg, "unknown error (%d)", errnum);
+
+	errno = saved_errno;
+	return msg;
+}
+
 char *
 purple_utf8_ncr_encode(const char *str)
 {
============================================================
--- libpurple/util.h	ffcb6eba7a5d6611d36c251612d564a1a7051c87
+++ libpurple/util.h	28ebc0ed940a2a3cf772da2d21f76541a99cef87
@@ -1110,6 +1110,17 @@ gchar *purple_utf8_salvage(const char *s
 gchar *purple_utf8_salvage(const char *str);
 
 /**
+ * Return the UTF-8 version of gai_strerror().  It calls gai_strerror()
+ * then converts the result to UTF-8.  This function is analogous to
+ * g_strerror().
+ *
+ * @param errnum The error code.
+ *
+ * @return The UTF-8 error message.
+ */
+G_CONST_RETURN gchar *purple_gai_strerror(gint errnum);
+
+/**
  * Compares two UTF-8 strings case-insensitively.  This string is
  * more expensive than a simple g_utf8_collate() comparison because
  * it calls g_utf8_casefold() on each string, which allocates new


More information about the Commits mailing list