aboutsummaryrefslogtreecommitdiff
path: root/src/mm-charsets.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-02-14 22:56:22 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-23 11:35:11 +0000
commit4a06a02765df1db1e641ef41d642ca27b8158005 (patch)
tree66f72778a6491381b744de4408373afa84c79072 /src/mm-charsets.c
parent8a8e00168b02c5064f01d5da20a97c7268ba1e2b (diff)
charsets: detect iconv() support in runtime
The only purpose of this is to log what we found, nothing else, as a quick way to detect platform support for the charsets we need.
Diffstat (limited to 'src/mm-charsets.c')
-rw-r--r--src/mm-charsets.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/mm-charsets.c b/src/mm-charsets.c
index 5430e253..a48da368 100644
--- a/src/mm-charsets.c
+++ b/src/mm-charsets.c
@@ -924,3 +924,46 @@ mm_modem_charset_str_to_utf8 (const gchar *str,
return mm_modem_charset_bytearray_to_utf8 (bytearray, charset, translit, error);
}
+
+/******************************************************************************/
+/* Runtime charset support via iconv() */
+
+void
+mm_modem_charsets_init (void)
+{
+ /* As test string, something we can convert to/from all the encodings */
+ static const gchar *default_test_str = "ModemManager";
+ guint i;
+
+ mm_obj_dbg (NULL, "[charsets] detecting platform iconv() support...");
+ for (i = 0; i < G_N_ELEMENTS (charset_settings); i++) {
+ g_autofree guint8 *enc = NULL;
+ guint enc_size;
+ g_autofree gchar *dec = NULL;
+
+ if (!charset_settings[i].iconv_name)
+ continue;
+
+ enc = charset_iconv_from_utf8 (default_test_str,
+ &charset_settings[i],
+ FALSE,
+ &enc_size,
+ NULL);
+ if (!enc) {
+ mm_obj_dbg (NULL, "[charsets] %s: iconv conversion to charset not supported", charset_settings[i].iconv_name);
+ continue;
+ }
+
+ dec = charset_iconv_to_utf8 (enc,
+ enc_size,
+ &charset_settings[i],
+ FALSE,
+ NULL);
+ if (!enc) {
+ mm_obj_dbg (NULL, "[charsets] %s: iconv conversion from charset not supported", charset_settings[i].iconv_name);
+ continue;
+ }
+
+ mm_obj_dbg (NULL, "[charsets] %s: iconv conversion to/from charset is supported", charset_settings[i].iconv_name);
+ }
+}