Mercurial > pidgin
diff libpurple/network.c @ 27635:7fbf964c6c6c
Move the IDN support into the DNS routines.
This turned out to be cleaner than I first thought, so here we go.
All libpurple DNS routines support IDN when built against GNU libidn.
| author | Paul Aurich <paul@darkrain42.org> |
|---|---|
| date | Sun, 19 Jul 2009 23:45:13 +0000 |
| parents | 627d23bfdb05 |
| children | 02f6f49da454 |
line wrap: on
line diff
--- a/libpurple/network.c Sun Jul 19 22:40:10 2009 +0000 +++ b/libpurple/network.c Sun Jul 19 23:45:13 2009 +0000 @@ -50,6 +50,10 @@ #include "upnp.h" #include "dnsquery.h" +#ifdef USE_IDN +#include <idna.h> +#endif + /* * Calling sizeof(struct ifreq) isn't always correct on * Mac OS X (and maybe others). @@ -966,7 +970,33 @@ } } } - + +int purple_network_convert_idn_to_ascii(const gchar *in, gchar **out) +{ +#ifdef USE_IDN + char *tmp; + int ret; + + g_return_val_if_fail(out != NULL, -1); + + ret = idna_to_ascii_8z(in, &tmp, IDNA_USE_STD3_ASCII_RULES); + if (ret != IDNA_SUCCESS) { + *out = NULL; + return ret; + } + + *out = g_strdup(tmp); + /* This *MUST* be freed with free, not g_free */ + free(tmp); + return 0; +#else + g_return_val_if_fail(out != NULL, -1); + + *out = g_strdup(in); + return 0; +#endif +} + void purple_network_init(void) {
