diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-10-24 09:50:09 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-10-25 19:49:56 +0200 |
commit | 3174b7b73fe2cfb08e39fd95c34195d1e25d1d08 (patch) | |
tree | cfc0d11e68aec16406cbb7a62c1508dc76a0d4ef | |
parent | 57882f6dad82e605fbe39fe292145939811fe64d (diff) | |
download | ModemManager-3174b7b73fe2cfb08e39fd95c34195d1e25d1d08.tar.gz |
sms-part-cdma: support receiving SMS with Latin encoding
-rw-r--r-- | src/mm-sms-part-cdma.c | 26 | ||||
-rw-r--r-- | src/tests/test-sms-part-cdma.c | 46 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/mm-sms-part-cdma.c b/src/mm-sms-part-cdma.c index 5a913427a..46970c998 100644 --- a/src/mm-sms-part-cdma.c +++ b/src/mm-sms-part-cdma.c @@ -862,6 +862,32 @@ read_bearer_data_user_data (MMSmsPart *sms_part, break; } + case ENCODING_LATIN: { + gchar *latin; + gchar *text; + guint i; + + SUBPARAMETER_SIZE_CHECK (byte_offset + 1 + ((bit_offset + (num_fields * 8)) / 8)); + + latin = g_malloc (num_fields + 1); + for (i = 0; i < num_fields; i++) { + latin[i] = read_bits (&subparameter->parameter_value[byte_offset], bit_offset, 8); + OFFSETS_UPDATE (8); + } + latin[i] = '\0'; + + text = g_convert (latin, -1, "UTF-8", "ISO−8859−1", NULL, NULL, NULL); + if (!text) { + mm_dbg (" text/data: ignored (latin to UTF-8 conversion error)"); + } else { + mm_dbg (" text: '%s'", text); + mm_sms_part_take_text (sms_part, text); + } + + g_free (latin); + break; + } + default: mm_dbg (" text/data: ignored (unsupported encoding)"); } diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index f95b7ac81..ddaf573aa 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -238,6 +238,50 @@ test_created_by_us (void) "AAAA"); } +static void +test_latin_encoding (void) +{ + static const guint8 pdu[] = { + /* message type */ + 0x00, + /* teleservice id */ + 0x00, 0x02, + 0x10, 0x02, + /* originating address */ + 0x02, 0x07, + 0x02, 0x8C, 0xE9, 0x5D, 0xCC, 0x65, 0x80, + /* bearer reply option */ + 0x06, 0x01, + 0xFC, + /* bearer data */ + 0x08, 0x39, + /* message id */ + 0x00, 0x03, + 0x13, 0x8D, 0x20, + /* user data */ + 0x01, 0x27, + 0x41, 0x29, 0x19, 0x22, 0xE1, 0x19, 0x1A, 0xE1, + 0x1A, 0x01, 0x19, 0xA1, 0x19, 0xA1, 0xA9, 0xB1, + 0xB9, 0xE9, 0x53, 0x4B, 0x23, 0xAB, 0x53, 0x23, + 0xAB, 0x23, 0x2B, 0xAB, 0xAB, 0x2B, 0x23, 0xAB, + 0x53, 0x23, 0x2B, 0xAB, 0x53, 0xAB, 0x20, + /* message center timestamp */ + 0x03, 0x06, + 0x13, 0x10, 0x23, 0x20, 0x06, 0x37, + /* priority indicator */ + 0x08, 0x01, + 0x00 + }; + + common_test_part_from_pdu ( + pdu, sizeof (pdu), + MM_SMS_CDMA_TELESERVICE_ID_WMT, + MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN, + "3305773196", + 63, + "#$\\##\\#@#4#4567=*idujdudeuuedujdeujud"); +} + /********************* PDU CREATOR TESTS *********************/ static void @@ -341,6 +385,8 @@ int main (int argc, char **argv) g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/invalid-parameter-length", test_invalid_parameter_length); g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/invalid-address-length", test_invalid_address_length); g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/created-by-us", test_created_by_us); + g_test_add_func ("/MM/SMS/CDMA/PDU-Parser/latin-encoding", test_latin_encoding); + g_test_add_func ("/MM/SMS/CDMA/PDU-Creator/Text", test_create_pdu_text); return g_test_run (); |