Commit Graph
32 Commits
Author SHA1 Message Date
Andrey Skvortsov 2ece78c80f charsets: move mm_sms_part_3gpp_util_split_text to mm_charset_util_split_text 2022-09-13 20:49:01 +00:00
Dmitry Skorykh a87a1f8ced mm-sms-part-3gpp: sms_decode_text: avoid decoding an empty text message
Fix segfault that can occur during message text decoding if there are no
elements in SMS text
2022-06-27 12:09:15 +03:00
Carlo Lobrano ac243f9467 sms: prevent crash if date is out of range
g_date_time_new, and g_date_time_new_utc return NULL if inputs are out
of range, and currently mm_new_iso8601_time passes the GDateTime created
by those two functions to date_time_format_iso8601 without checking for
NULL values, causing a g_date_time_format_iso8601 crash if PDU data is
corrupted with wrong date.

To prevent this, mm_new_iso8601_time now can return NULL and set a new
GError if GDateTime created by g_date_time_new is NULL.

Fixes #546
2022-04-08 15:41:49 +02:00
Frederic Martinsons 9d82d30978 cli, plugins: factorize usage of iso8601 datetime format
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>

Includes updates by Aleksander Morgado to fix coding style issues.
2021-10-22 13:48:20 +02:00
Clayton Craft 43c39d5226 sms-part-3gpp: add flag for indicating PDU is transfer-route message
When the message is a transfer-route MT, there is no SMSC address to
parse out. This flag allows indicating when the PDU is one such message.
2021-04-20 15:16:50 -07:00
Aleksander Morgado 5ea4a591a4 charsets: use new bytearray_to_utf8() instead of byte_array_to_utf8() 2021-02-23 11:35:11 +00:00
Aleksander Morgado 033e174e44 charsets: make charset_gsm_unpacked_to_utf8() private
Use the generic mm_modem_charset_bytearray_to_utf8() instead.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 8bfdfb187b charsets: use new bytearray_from_utf8() instead of byte_array_append() 2021-02-23 11:35:11 +00:00
Aleksander Morgado 75b37e16b1 charsets: make charset_utf8_to_unpacked_gsm() private
Use the generic mm_modem_charset_bytearray_from_utf8() instead.
2021-02-23 11:35:11 +00:00
Aleksander Morgado bc449cbe87 charsets: make translit optional in utf8_to_unpacked_gsm()
If the conversion is not fully compatible, the user of the method
needs to request transliteration enabled explicitly in order to avoid
returning errors in this method.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 5ce97abd73 charsets: make translit optional in gsm_unpacked_to_utf8()
Until now, this method would automatically apply transliteration;
i.e. replacing characters with '?' when no direct translation was
available.

We can attempt to do that transliteration on strings that are not
critical, e.g. the operator name reported by the network. But we
should not do that on other types of strings, e.g. on SMS contents
that may really have additional purposes than just being
human-readable.

This commit makes the transliteration option to be explicitly
requested by the caller.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 34de613dea libmm-glib,common-helpers: make hexstr2bin() return a guint8 array
It makes much more sense than returning a gchar array, as gchar is
signed.
2021-02-23 11:35:11 +00:00
Aleksander Morgado a211981d4a libmm-glib,common-helpers: make hexstr2bin() accept input string length
Optionally given explicitly, and -1 can be used to assume it's
NUL-terminated.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 657cabcfce libmm-glib,common-helpers: make hexstr2bin() return a GError
This util method checks whether the input string is a valid hex
string, so make sure we return a GError on failure.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 8b590721df charsets: don't allow quoting in byte_array_append()
There's no point in adding a quoting option to this method; if the
caller needs the appended string quoted, it should quote it before
passing it to this method.

It was nowhere used anyway.
2021-02-23 11:35:11 +00:00
Aleksander Morgado 599f545c0d sms-part-3gpp: allow sending UTF-16 as if it were UCS-2
Despite 3GPP TS 23.038 specifies that Unicode SMS messages are
encoded in UCS-2, UTF-16 encoding is commonly used instead on many
modern platforms to allow encoding code points that fall outside the
Basic Multilingual Plane (BMP), such as Emoji.

Update the logic to always use UTF-16 instead of UCS-2 when creating
or parsing PDUs (even if we always report as sending or receiving
UCS-2). For all purposes, UCS-2 is considered a subset of UTF-16
(assuming that code points out of the [U+0000,U+D7FF] and
[U+E000,U+FFFF] ranges are not applicable in UCS-2).

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/250
2020-08-20 18:15:37 +02:00
Aleksander Morgado 93686510d7 sms-part-3gpp: minor refactor in text split logic 2020-08-20 10:57:01 +02:00
Maxim Anisimov 1e0b38d98a sms-part-3gpp: fix unicode names in sms decode iconv() operations
So that the limited iconv() in OpenWRT supports the conversion properly.

Signed-off-by: Maxim Anisimov <maxim.anisimov.ua@gmail.com>
2020-06-05 08:43:05 +03:00
Aleksander Morgado 2376859f36 charsets: report GError in byte_array_append() failures 2020-04-08 16:35:09 +02:00
Aleksander Morgado 3186a498c1 sms-part-3gpp: port to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado a5c0a7849a sms-part-3gpp: fix warnings with -Wswitch-enum
mm-sms-part-3gpp.c: In function ‘mm_sms_part_3gpp_new_from_binary_pdu’:
  mm-sms-part-3gpp.c:721:9: error: enumeration value ‘MM_SMS_ENCODING_8BIT’ not handled in switch [-Werror=switch-enum]
    721 |         switch (user_data_encoding) {
        |         ^~~~~~
  mm-sms-part-3gpp.c: In function ‘mm_sms_part_3gpp_get_submit_pdu’:
  mm-sms-part-3gpp.c:917:5: error: enumeration value ‘MM_SMS_ENCODING_UNKNOWN’ not handled in switch [-Werror=switch-enum]
    917 |     switch (mm_sms_part_get_encoding (part)) {
        |     ^~~~~~
  mm-sms-part-3gpp.c:917:5: error: enumeration value ‘MM_SMS_ENCODING_8BIT’ not handled in switch [-Werror=switch-enum]
2020-01-31 14:52:49 +01:00
Aleksander Morgado 6a7b1e7b8c sms-part-3gpp: fix warnings with -Wswitch-enum
mm-sms-part-3gpp.c: In function ‘mm_sms_part_3gpp_new_from_binary_pdu’:
  mm-sms-part-3gpp.c:607:9: error: enumeration value ‘MM_SMS_ENCODING_UNKNOWN’ not handled in switch [-Werror=switch-enum]
    607 |         switch (user_data_encoding) {
        |         ^~~~~~
  mm-sms-part-3gpp.c:714:9: error: enumeration value ‘MM_SMS_ENCODING_UNKNOWN’ not handled in switch [-Werror=switch-enum]
    714 |         switch (user_data_encoding) {
        |         ^~~~~~
2020-01-31 14:52:49 +01:00
Aleksander Morgado 5eedad988e sms-part-3gpp: fix warnings with -Wswitch-default
mm-sms-part-3gpp.c: In function ‘sms_encoding_type’:
  mm-sms-part-3gpp.c:190:13: error: switch missing default case [-Werror=switch-default]
    190 |             switch (dcs & 0x0c) {
        |             ^~~~~~
  mm-sms-part-3gpp.c:219:13: error: switch missing default case [-Werror=switch-default]
    219 |             switch (dcs & 0x04) {
        |             ^~~~~~
2020-01-31 14:52:49 +01:00
amol.lad 16145c29de sms-part-3gpp: SMS timestamp in ISO8601 format 2019-09-22 09:15:51 +02:00
Ville Skyttä 90b89bb9f4 *: Spelling fixes 2018-01-25 09:52:12 +01:00
Aleksander Morgado 8f6e5bfefa sms-part-3gpp: improve warnings when decoding fails 2017-12-18 11:47:44 +01:00
Ben Chan e8bac6cb92 sms-part-3gpp: decode Unicode SMS with non-BMP code points
Depsite 3GPP TS 23.038 specifies that Unicode SMS messages are encoded in
UCS-2, UTF-16 encoding is commonly used instead on many modern platforms to
allow encoding code points that fall outside the Basic Multilingual Plane
(BMP), such as Emoji. Most of the UCS-2 code points are identical to their
equivalent UTF-16 code points.  In UTF-16, non-BMP code points are encoded in a
pair of surrogate code points (i.e. a high surrogate in 0xD800..0xDBFF,
followed by a low surrogate in 0xDC00..0xDFFF). An isolated surrogate code
point has no general interpretation in UTF-16, but could be a valid (though
unmapped) code point in UCS-2.

This patch modifies the 3GPP SMS decoding to first try UTF-16BE and then fall
back to UCS-2BE on failure. If both fail, an empty string is returned
instead of a NULL pointer.
2017-12-18 10:21:29 +01:00
Aleksander Morgado 5a01e54066 charsets: simplify check to see if conversion to charset possible
Instead of having a method that returns the expected length after the
conversion and the amount of input UTF-8 characters that couldn't be
converted to the given charset, simplify the logic and just define a
method that returns a boolean specifying whether the conversion is
possible or not.

Also, include unit tests.
2017-08-16 16:27:42 +02:00
Aleksander Morgado 1f2bb64028 charsets: ensure all methods are prefixed with 'mm_' 2017-08-16 16:08:15 +02:00
Ben Chan 45682aa7ee sms-part-3gpp: minor coding style fixes 2017-07-14 10:59:46 +02:00
Aleksander Morgado cadbc0412d sms-part-3gpp: ensure PDU type in part is the correct one when building SUBMIT 2013-10-25 19:47:19 +02:00
Aleksander Morgado df986c076d sms: split SMS part handling into common and 3GPP-specific 2013-10-25 19:47:18 +02:00