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.
This commit is contained in:
Aleksander Morgado
2021-02-14 22:56:22 +01:00
parent 8a8e00168b
commit 4a06a02765
3 changed files with 50 additions and 0 deletions

View File

@@ -182,6 +182,9 @@ main (int argc, char *argv[])
mm_info ("ModemManager (version " MM_DIST_VERSION ") starting in %s bus...",
mm_context_get_test_session () ? "session" : "system");
/* Detect runtime charset conversion support */
mm_modem_charsets_init ();
/* Acquire name, don't allow replacement */
name_id = g_bus_own_name (mm_context_get_test_session () ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM,
MM_DBUS_SERVICE,

View File

@@ -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);
}
}

View File

@@ -108,4 +108,8 @@ gchar *mm_modem_charset_str_to_utf8 (const gchar *str,
gboolean translit,
GError **error);
/*****************************************************************************************/
void mm_modem_charsets_init (void);
#endif /* MM_CHARSETS_H */