2006-06-16 Mikael Hallendal <micke@imendio.com>
* configure.ac:
* loudmouth-1.0.pc.in:
* loudmouth/Makefile.am:
- Add checks for libidn.
* loudmouth/lm-connection.c: (lm_connection_new),
(lm_connection_set_server):
* loudmouth/lm-proxy.c: (lm_proxy_set_server):
- Use the new function _lm_utils_hostname_to_punycode.
* loudmouth/lm-internals.h:
* loudmouth/lm-utils.c: (_lm_utils_hostname_to_punycode):
- Added function to support internationalised host names.
- Patch from Frederic Peters.
- Fixes LM-42.
--- a/ChangeLog Fri Jun 16 08:51:48 2006 +0000
+++ b/ChangeLog Fri Jun 16 09:21:33 2006 +0000
@@ -1,3 +1,19 @@
+2006-06-16 Mikael Hallendal <micke@imendio.com>
+
+ * configure.ac:
+ * loudmouth-1.0.pc.in:
+ * loudmouth/Makefile.am:
+ - Add checks for libidn.
+ * loudmouth/lm-connection.c: (lm_connection_new),
+ (lm_connection_set_server):
+ * loudmouth/lm-proxy.c: (lm_proxy_set_server):
+ - Use the new function _lm_utils_hostname_to_punycode.
+ * loudmouth/lm-internals.h:
+ * loudmouth/lm-utils.c: (_lm_utils_hostname_to_punycode):
+ - Added function to support internationalised host names.
+ - Patch from Frederic Peters.
+ - Fixes LM-42.
+
2006-06-06 Mikael Hallendal <micke@imendio.com>
* loudmouth/lm-connection.c: (connection_free):
--- a/configure.ac Fri Jun 16 08:51:48 2006 +0000
+++ b/configure.ac Fri Jun 16 09:21:33 2006 +0000
@@ -76,6 +76,11 @@
PKG_CHECK_MODULES(LOUDMOUTH, glib-2.0 >= $GLIB2_REQUIRED)
+PKG_CHECK_MODULES(LIBIDN, libidn, have_idn=yes, have_idn=no)
+if test "x$have_idn" = "xyes"; then
+ AC_DEFINE(HAVE_IDN, 1, [Define if IDN support is included])
+fi
+
# Check Unit test framework (defined in acinclude.m4)
IDT_PATH_CHECK(0.9.2, have_check=yes, have_check=no)
@@ -257,6 +262,7 @@
prefix: ${prefix}
compiler: ${CC}
+ Have IDN support: ${have_idn}
Enable SSL ${enable_ssl}
Enable Debug: ${enable_debug}
Enable Unit Tests: ${have_check}
--- a/loudmouth-1.0.pc.in Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth-1.0.pc.in Fri Jun 16 09:21:33 2006 +0000
@@ -7,5 +7,5 @@
Description: libloudmouth
Requires: glib-2.0
Version: @VERSION@
-Libs: -L${libdir} -lloudmouth-1
+Libs: -L${libdir} -lloudmouth-1 @LIBIDN_LIBS@
Cflags: -I${includedir}/loudmouth-1.0
--- a/loudmouth/Makefile.am Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth/Makefile.am Fri Jun 16 09:21:33 2006 +0000
@@ -4,6 +4,7 @@
-I. \
-I$(top_srcdir) \
$(LOUDMOUTH_CFLAGS) \
+ $(LIBIDN_CFLAGS) \
-DLM_COMPILATION \
-DRUNTIME_ENDIAN \
$(NULL)
@@ -57,7 +58,8 @@
$(NULL)
libloudmouth_1_la_LIBADD = \
- $(LOUDMOUTH_LIBS)
+ $(LOUDMOUTH_LIBS) \
+ $(LIBIDN_LIBS)
libloudmouthincludedir = $(includedir)/loudmouth-1.0/loudmouth
--- a/loudmouth/lm-connection.c Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth/lm-connection.c Fri Jun 16 09:21:33 2006 +0000
@@ -36,6 +36,7 @@
#include "lm-parser.h"
#include "lm-sha.h"
#include "lm-connection.h"
+#include "lm-utils.h"
#define IN_BUFFER_SIZE 1024
@@ -1459,7 +1460,7 @@
connection = g_new0 (LmConnection, 1);
if (server) {
- connection->server = g_strdup (server);
+ connection->server = _lm_utils_hostname_to_punycode (server);
} else {
connection->server = NULL;
}
@@ -1895,7 +1896,7 @@
}
g_free (connection->server);
- connection->server = g_strdup (server);
+ connection->server = _lm_utils_hostname_to_punycode (server);
}
/**
--- a/loudmouth/lm-internals.h Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth/lm-internals.h Fri Jun 16 09:21:33 2006 +0000
@@ -65,6 +65,7 @@
gchar * _lm_utils_generate_id (void);
gchar * _lm_utils_base64_encode (const gchar *str);
+gchar * _lm_utils_hostname_to_punycode (const gchar *hostname);
const gchar * _lm_message_type_to_string (LmMessageType type);
const gchar * _lm_message_sub_type_to_string (LmMessageSubType type);
LmMessage * _lm_message_new_from_node (LmMessageNode *node);
--- a/loudmouth/lm-proxy.c Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth/lm-proxy.c Fri Jun 16 09:21:33 2006 +0000
@@ -37,6 +37,7 @@
#include "lm-internals.h"
#include "lm-proxy.h"
+#include "lm-utils.h"
struct _LmProxy {
LmProxyType type;
@@ -337,7 +338,7 @@
g_return_if_fail (server != NULL);
g_free (proxy->server);
- proxy->server = g_strdup (server);
+ proxy->server = _lm_utils_hostname_to_punycode (server);
}
/**
--- a/loudmouth/lm-utils.c Fri Jun 16 08:51:48 2006 +0000
+++ b/loudmouth/lm-utils.c Fri Jun 16 09:21:33 2006 +0000
@@ -21,6 +21,7 @@
#include <config.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <time.h>
#include <glib.h>
@@ -29,6 +30,12 @@
#include <unistd.h>
#endif
+#ifdef HAVE_IDN
+#include <stringprep.h>
+#include <punycode.h>
+#include <idna.h>
+#endif
+
#include "lm-internals.h"
#include "lm-utils.h"
@@ -131,7 +138,35 @@
return str;
}
-struct tm *
+gchar*
+_lm_utils_hostname_to_punycode (const gchar *hostname)
+{
+#ifdef HAVE_IDN
+ char *s;
+ uint32_t *q;
+ int rc;
+ gchar *result;
+
+ q = stringprep_utf8_to_ucs4 (hostname, -1, NULL);
+ if (q == NULL) {
+ return g_strdup (hostname);
+ }
+
+ rc = idna_to_ascii_4z (q, &s, IDNA_ALLOW_UNASSIGNED);
+ free(q);
+ if (rc != IDNA_SUCCESS) {
+ return g_strdup (hostname);
+ }
+
+ /* insures result is allocated through glib */
+ result = g_strdup(s);
+ free(s);
+
+ return result;
+#else
+ return g_strdup(hostname);
+#endif
+}struct tm *
lm_utils_get_localtime (const gchar *stamp)
{
struct tm tm;
@@ -162,3 +197,4 @@
return localtime (&t);
}
+