charsets: make charset_gsm_unpacked_to_utf8() private
Use the generic mm_modem_charset_bytearray_to_utf8() instead.
This commit is contained in:
@@ -2329,10 +2329,11 @@ decode (MMIfaceModem3gppUssd *self,
|
||||
const gchar *reply,
|
||||
GError **error)
|
||||
{
|
||||
g_autofree guint8 *bin = NULL;
|
||||
g_autofree guint8 *unpacked = NULL;
|
||||
gsize bin_len = 0;
|
||||
guint32 unpacked_len;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
gsize bin_len = 0;
|
||||
g_autofree guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
g_autoptr(GByteArray) unpacked_array = NULL;
|
||||
|
||||
bin = mm_utils_hexstr2bin (reply, -1, &bin_len, error);
|
||||
if (!bin)
|
||||
@@ -2342,7 +2343,11 @@ decode (MMIfaceModem3gppUssd *self,
|
||||
/* if the last character in a 7-byte block is padding, then drop it */
|
||||
if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d))
|
||||
unpacked_len--;
|
||||
return (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
|
||||
|
||||
unpacked_array = g_byte_array_sized_new (unpacked_len);
|
||||
g_byte_array_append (unpacked_array, unpacked, unpacked_len);
|
||||
|
||||
return mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
+16
-7
@@ -1412,22 +1412,31 @@ parse_spn (const gchar *response,
|
||||
(sw1 == 0x91) ||
|
||||
(sw1 == 0x92) ||
|
||||
(sw1 == 0x9f)) {
|
||||
gsize buflen = 0;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
g_autoptr(GByteArray) bin_array = NULL;
|
||||
g_autofree guint8 *bin = NULL;
|
||||
gsize binlen = 0;
|
||||
|
||||
/* Convert hex string to binary */
|
||||
bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
|
||||
bin = mm_utils_hexstr2bin (hex, -1, &binlen, error);
|
||||
if (!bin) {
|
||||
g_prefix_error (error, "SIM returned malformed response '%s': ", hex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Remove the FF filler at the end */
|
||||
while (buflen > 1 && bin[buflen - 1] == 0xff)
|
||||
buflen--;
|
||||
while (binlen > 1 && bin[binlen - 1] == 0xff)
|
||||
binlen--;
|
||||
if (binlen <= 1) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"SIM returned empty response '%s'", hex);
|
||||
return NULL;
|
||||
}
|
||||
/* Setup as bytearray.
|
||||
* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */
|
||||
bin_array = g_byte_array_sized_new (binlen - 1);
|
||||
g_byte_array_append (bin_array, bin + 1, binlen - 1);
|
||||
|
||||
/* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */
|
||||
return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1, FALSE, error);
|
||||
return mm_modem_charset_bytearray_to_utf8 (bin_array, MM_MODEM_CHARSET_GSM, FALSE, error);
|
||||
}
|
||||
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
|
||||
@@ -4809,11 +4809,14 @@ ussd_decode (guint32 scheme,
|
||||
gchar *decoded = NULL;
|
||||
|
||||
if (scheme == MM_MODEM_GSM_USSD_SCHEME_7BIT) {
|
||||
g_autofree guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
g_autoptr(GByteArray) unpacked_array = NULL;
|
||||
guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
|
||||
unpacked = mm_charset_gsm_unpack ((const guint8 *)data->data, (data->len * 8) / 7, 0, &unpacked_len);
|
||||
decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
|
||||
unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
|
||||
|
||||
decoded = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
|
||||
if (!decoded)
|
||||
g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme);
|
||||
} else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) {
|
||||
|
||||
+11
-10
@@ -343,11 +343,11 @@ utf8_to_gsm_ext_char (const gchar *utf8,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
|
||||
guint32 len,
|
||||
gboolean translit,
|
||||
GError **error)
|
||||
static guint8 *
|
||||
charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
|
||||
guint32 len,
|
||||
gboolean translit,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GByteArray) utf8 = NULL;
|
||||
guint i;
|
||||
@@ -744,7 +744,8 @@ mm_charset_take_and_convert_to_utf8 (gchar *str,
|
||||
break;
|
||||
|
||||
case MM_MODEM_CHARSET_GSM:
|
||||
utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL);
|
||||
/* This is WRONG! GSM may have embedded NULs (character @)! */
|
||||
utf8 = (gchar *) charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL);
|
||||
g_free (str);
|
||||
break;
|
||||
|
||||
@@ -1111,10 +1112,10 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray,
|
||||
|
||||
switch (charset) {
|
||||
case MM_MODEM_CHARSET_GSM:
|
||||
utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (bytearray->data,
|
||||
bytearray->len,
|
||||
translit,
|
||||
error);
|
||||
utf8 = (gchar *) charset_gsm_unpacked_to_utf8 (bytearray->data,
|
||||
bytearray->len,
|
||||
translit,
|
||||
error);
|
||||
break;
|
||||
case MM_MODEM_CHARSET_IRA:
|
||||
case MM_MODEM_CHARSET_UTF8:
|
||||
|
||||
@@ -48,11 +48,6 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array,
|
||||
gchar *mm_modem_charset_hex_to_utf8 (const gchar *src,
|
||||
MMModemCharset charset);
|
||||
|
||||
guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
|
||||
guint32 len,
|
||||
gboolean translit,
|
||||
GError **error);
|
||||
|
||||
/* Checks whether conversion to the given charset may be done without errors */
|
||||
gboolean mm_charset_can_convert_to (const gchar *utf8,
|
||||
MMModemCharset charset);
|
||||
|
||||
+11
-7
@@ -133,11 +133,13 @@ sms_decode_address (const guint8 *address,
|
||||
address++;
|
||||
|
||||
if (addrtype == SMS_NUMBER_TYPE_ALPHA) {
|
||||
g_autofree guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
g_autoptr(GByteArray) unpacked_array = NULL;
|
||||
guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
|
||||
unpacked = mm_charset_gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len);
|
||||
utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
|
||||
unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
|
||||
utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
|
||||
} else if (addrtype == SMS_NUMBER_TYPE_INTL &&
|
||||
addrplan == SMS_NUMBER_PLAN_TELEPHONE) {
|
||||
/* International telphone number, format as "+1234567890" */
|
||||
@@ -249,12 +251,14 @@ sms_decode_text (const guint8 *text,
|
||||
GError **error)
|
||||
{
|
||||
if (encoding == MM_SMS_ENCODING_GSM7) {
|
||||
g_autofree guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
gchar *utf8;
|
||||
g_autoptr(GByteArray) unpacked_array = NULL;
|
||||
guint8 *unpacked = NULL;
|
||||
guint32 unpacked_len;
|
||||
gchar *utf8;
|
||||
|
||||
unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len);
|
||||
utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
|
||||
unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
|
||||
utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
|
||||
if (utf8)
|
||||
mm_obj_dbg (log_object, "converted SMS part text from GSM-7 to UTF-8: %s", utf8);
|
||||
return utf8;
|
||||
|
||||
@@ -27,7 +27,8 @@ common_test_gsm7 (const gchar *in_utf8)
|
||||
guint32 unpacked_gsm_len_2 = 0;
|
||||
g_autoptr(GByteArray) unpacked_gsm = NULL;
|
||||
g_autofree guint8 *packed_gsm = NULL;
|
||||
g_autofree guint8 *unpacked_gsm_2 = NULL;
|
||||
guint8 *unpacked_gsm_2 = NULL;
|
||||
g_autoptr(GByteArray) unpacked_gsm_2_array = NULL;
|
||||
g_autofree gchar *built_utf8 = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
|
||||
@@ -56,9 +57,10 @@ common_test_gsm7 (const gchar *in_utf8)
|
||||
/* Unpack */
|
||||
unpacked_gsm_2 = mm_charset_gsm_unpack (packed_gsm, packed_gsm_len * 8 / 7, 0, &unpacked_gsm_len_2);
|
||||
g_assert_nonnull (unpacked_gsm_2);
|
||||
unpacked_gsm_2_array = g_byte_array_new_take (unpacked_gsm_2, unpacked_gsm_len_2);
|
||||
|
||||
/* And back to UTF-8 */
|
||||
built_utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked_gsm_2, unpacked_gsm_len_2, FALSE, &error);
|
||||
built_utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_gsm_2_array, MM_MODEM_CHARSET_GSM, FALSE, &error);
|
||||
g_assert_nonnull (built_utf8);
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpstr (built_utf8, ==, in_utf8);
|
||||
|
||||
Reference in New Issue
Block a user