summaryrefslogtreecommitdiff
path: root/src/mm-sms-part.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-09-12 12:34:43 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-09-14 07:05:26 +0200
commitfbe01c8d6a22cb95ff74ddefc907e663cdeee710 (patch)
treeb63a0c99673a3f8e47c92b82c3f0d31889979a95 /src/mm-sms-part.c
parent15be01d4fac9c761411f23903df5c0d6c2360424 (diff)
downloadModemManager-fbe01c8d6a22cb95ff74ddefc907e663cdeee710.tar.gz
sms: 'Text' and 'Data' will never be given at the same time
When receiving an SMS, if the encoding is either GSM7 or UCS2, we will treat the contents of the SMS as text; and if the encoding is either 8BIT or unknown, we will just dump the contents of the SMS as data. When creating an SMS, the user is not allowed to give both text and data, only one can be given. We will use by default 8BIT when data is given, and guess the best encoding if text is given. Note that it's still possible to have SMS with neither text nor data, as in delivery status reports. This commit also handles the split of the input data in order to make it fit into singlepart or multipart messages.
Diffstat (limited to 'src/mm-sms-part.c')
-rw-r--r--src/mm-sms-part.c73
1 files changed, 58 insertions, 15 deletions
diff --git a/src/mm-sms-part.c b/src/mm-sms-part.c
index b78e9056b..cb1ee5fa7 100644
--- a/src/mm-sms-part.c
+++ b/src/mm-sms-part.c
@@ -499,7 +499,6 @@ mm_sms_part_new_from_binary_pdu (guint index,
GError **error)
{
MMSmsPart *sms_part;
- GByteArray *raw;
guint8 pdu_type;
guint offset;
guint smsc_addr_size_bytes;
@@ -835,28 +834,34 @@ mm_sms_part_new_from_binary_pdu (guint index,
tp_user_data_size_elements -= udhl;
}
- if ( user_data_encoding == MM_SMS_ENCODING_8BIT
- || user_data_encoding == MM_SMS_ENCODING_UNKNOWN) {
- /* 8-bit encoding is usually binary data, and we have no idea what
- * actual encoding the data is in so we can't convert it.
- */
- mm_dbg ("Skipping SMS part text: 8-bit or Unknown encoding");
- mm_sms_part_set_text (sms_part, "");
- } else {
+ switch (user_data_encoding) {
+ case MM_SMS_ENCODING_GSM7:
+ case MM_SMS_ENCODING_UCS2:
/* Otherwise if it's 7-bit or UCS2 we can decode it */
- mm_dbg ("Decoding text with '%u' elements", tp_user_data_size_elements);
+ mm_dbg ("Decoding SMS text with '%u' elements", tp_user_data_size_elements);
mm_sms_part_take_text (sms_part,
sms_decode_text (&pdu[tp_user_data_offset],
tp_user_data_size_elements,
user_data_encoding,
bit_offset));
g_warn_if_fail (sms_part->text != NULL);
- }
+ break;
+
+ default:
+ {
+ GByteArray *raw;
+
+ mm_dbg ("Skipping SMS text: Unknown encoding");
- /* Add the raw PDU data */
- raw = g_byte_array_sized_new (tp_user_data_size_bytes);
- g_byte_array_append (raw, &pdu[tp_user_data_offset], tp_user_data_size_bytes);
- mm_sms_part_take_data (sms_part, raw);
+ /* 8-bit encoding is usually binary data, and we have no idea what
+ * actual encoding the data is in so we can't convert it.
+ */
+ raw = g_byte_array_sized_new (tp_user_data_size_bytes);
+ g_byte_array_append (raw, &pdu[tp_user_data_offset], tp_user_data_size_bytes);
+ mm_sms_part_take_data (sms_part, raw);
+ break;
+ }
+ }
}
return sms_part;
@@ -1238,3 +1243,41 @@ mm_sms_part_util_split_text (const gchar *text,
return out;
}
+
+GByteArray **
+mm_sms_part_util_split_data (const GByteArray *data)
+{
+ GByteArray **out;
+
+ /* Some info about the rules for splitting.
+ *
+ * The User Data can be up to 140 bytes in the SMS part:
+ * 0) If we only need one chunk, it can be of up to 140 bytes.
+ * If we need more than one chunk, these have to be of 140 - 6 = 134
+ * bytes each, as we need place for the UDH header.
+ */
+
+ if (data->len <= 140) {
+ out = g_new0 (GByteArray *, 2);
+ out[0] = g_byte_array_append (g_byte_array_sized_new (data->len),
+ data->data,
+ data->len);
+ } else {
+ guint n_chunks;
+ guint i;
+ guint j;
+
+ n_chunks = data->len / 134;
+ if (data->len % 134 != 0)
+ n_chunks ++;
+
+ out = g_new0 (GByteArray *, n_chunks + 1);
+ for (i = 0, j = 0; i < n_chunks; i++, j+= 134) {
+ out[i] = g_byte_array_append (g_byte_array_sized_new (134),
+ &data->data[j],
+ MIN (data->len - j, 134));
+ }
+ }
+
+ return out;
+}