From 47a9356259e53ead3492a5e93921a08ac9f131f4 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 6 Jun 2022 16:04:06 +0200 Subject: [PATCH] [idn] convert_string instead of iconv --- src/protocol/uri.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/protocol/uri.c b/src/protocol/uri.c index 9c81c28c0..573c63ffb 100644 --- a/src/protocol/uri.c +++ b/src/protocol/uri.c @@ -544,33 +544,11 @@ add_uri_to_string(struct string *string, const struct uri *uri, char *host = NULL; #if defined(CONFIG_NLS) || defined(CONFIG_GETTEXT) if (current_charset != -1 && !is_cp_utf8(current_charset)) { - size_t iconv_res; - size_t ileft = uri->hostlen; - size_t oleft = ileft * 8; - char *inbuf, *outbuf; - char *utf8_data = (char *)mem_calloc(1, oleft); - iconv_t cd; - - if (!utf8_data) { - goto error; - } - cd = iconv_open("utf-8", get_cp_mime_name(current_charset)); - if (cd == (iconv_t)-1) { - mem_free(utf8_data); - goto error; - } - inbuf = uri->host; - outbuf = utf8_data; - iconv_res = iconv(cd, &inbuf, &ileft, &outbuf, &oleft); - - if (iconv_res == -1) { - mem_free(utf8_data); - goto error; - } - iconv_close(cd); - host = utf8_data; + int utf8_cp = get_cp_index("utf-8"); + struct conv_table *ctable = get_translation_table(current_charset, utf8_cp); + host = convert_string(ctable, uri->host, uri->hostlen, utf8_cp, CSM_NONE, + NULL, NULL, NULL); } -error: #endif if (!host) { host = memacpy(uri->host, uri->hostlen);