api: new `PduType' property in the SMS interface
It will help deciding the type of message.
This commit is contained in:
@@ -19,6 +19,7 @@ MMModemLock
|
||||
MMModemMode
|
||||
MMModemState
|
||||
MMModemStateChangeReason
|
||||
MMSmsPduType
|
||||
MMSmsState
|
||||
MMSmsStorage
|
||||
</SECTION>
|
||||
|
@@ -354,6 +354,22 @@ typedef enum { /*< underscore_name=mm_modem_band >*/
|
||||
MM_MODEM_BAND_ANY = 256
|
||||
} MMModemBand;
|
||||
|
||||
/**
|
||||
* MMSmsPduType:
|
||||
* @MM_SMS_PDU_TYPE_UNKNOWN: Unknown type.
|
||||
* @MM_SMS_PDU_TYPE_DELIVER: SMS has been received from the SMSC.
|
||||
* @MM_SMS_PDU_TYPE_SUBMIT: SMS is sent, or to be sent to the SMSC.
|
||||
* @MM_SMS_PDU_TYPE_STATUS_REPORT: SMS is a status report received from the SMSC.
|
||||
*
|
||||
* Type of PDUs used in the SMS.
|
||||
*/
|
||||
typedef enum { /*< underscore_name=mm_sms_pdu_type >*/
|
||||
MM_SMS_PDU_TYPE_UNKNOWN = 0,
|
||||
MM_SMS_PDU_TYPE_DELIVER = 1,
|
||||
MM_SMS_PDU_TYPE_SUBMIT = 2,
|
||||
MM_SMS_PDU_TYPE_STATUS_REPORT = 3
|
||||
} MMSmsPduType;
|
||||
|
||||
/**
|
||||
* MMSmsState:
|
||||
* @MM_SMS_STATE_UNKNOWN: State unknown or not reportable.
|
||||
|
@@ -48,6 +48,14 @@
|
||||
-->
|
||||
<property name="State" type="u" access="read" />
|
||||
|
||||
<!--
|
||||
PduType:
|
||||
|
||||
A <link linkend="MMSmsPduType">MMSmsPduType</link> value,
|
||||
describing the type of PDUs used in the SMS message.
|
||||
-->
|
||||
<property name="PduType" type="u" access="read" />
|
||||
|
||||
<!--
|
||||
Number:
|
||||
|
||||
|
@@ -4816,6 +4816,19 @@ sms_state_from_str (const gchar *str)
|
||||
return MM_SMS_STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
static MMSmsPduType
|
||||
sms_pdu_type_from_str (const gchar *str)
|
||||
{
|
||||
/* We merge unread and read messages in the same state */
|
||||
if (strstr (str, "REC"))
|
||||
return MM_SMS_PDU_TYPE_DELIVER;
|
||||
|
||||
if (strstr (str, "STO"))
|
||||
return MM_SMS_PDU_TYPE_SUBMIT;
|
||||
|
||||
return MM_SMS_PDU_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
static void
|
||||
sms_text_part_list_ready (MMBroadbandModem *self,
|
||||
GAsyncResult *res,
|
||||
@@ -4866,24 +4879,24 @@ sms_text_part_list_ready (MMBroadbandModem *self,
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Get part state */
|
||||
stat = mm_get_string_unquoted_from_match_info (match_info, 2);
|
||||
if (!stat) {
|
||||
mm_dbg ("Failed to get part status");
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Get and parse number */
|
||||
number = mm_get_string_unquoted_from_match_info (match_info, 3);
|
||||
if (!number) {
|
||||
mm_dbg ("Failed to get message sender number");
|
||||
g_free (stat);
|
||||
goto next;
|
||||
}
|
||||
|
||||
number = mm_broadband_modem_take_and_convert_to_utf8 (MM_BROADBAND_MODEM (self),
|
||||
number);
|
||||
|
||||
/* Get part state */
|
||||
stat = mm_get_string_unquoted_from_match_info (match_info, 2);
|
||||
if (!stat) {
|
||||
mm_dbg ("Failed to get part status");
|
||||
g_free (number);
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Get and parse timestamp (always expected in ASCII) */
|
||||
timestamp = mm_get_string_unquoted_from_match_info (match_info, 5);
|
||||
|
||||
@@ -4901,7 +4914,8 @@ sms_text_part_list_ready (MMBroadbandModem *self,
|
||||
g_free (ucs2_text);
|
||||
|
||||
/* all take() methods pass ownership of the value as well */
|
||||
part = mm_sms_part_new (idx);
|
||||
part = mm_sms_part_new (idx,
|
||||
sms_pdu_type_from_str (stat));
|
||||
mm_sms_part_take_number (part, number);
|
||||
mm_sms_part_take_timestamp (part, timestamp);
|
||||
mm_sms_part_take_text (part, text);
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <ModemManager.h>
|
||||
#include <mm-errors-types.h>
|
||||
#include <libmm-common.h>
|
||||
|
||||
#include "mm-sms-part.h"
|
||||
#include "mm-charsets.h"
|
||||
@@ -260,6 +261,7 @@ sms_decode_text (const guint8 *text, int len, MMSmsEncoding encoding, int bit_of
|
||||
|
||||
struct _MMSmsPart {
|
||||
guint index;
|
||||
MMSmsPduType pdu_type;
|
||||
gchar *smsc;
|
||||
gchar *timestamp;
|
||||
gchar *number;
|
||||
@@ -323,6 +325,8 @@ mm_sms_part_free (MMSmsPart *self)
|
||||
|
||||
PART_GET_FUNC (guint, index)
|
||||
PART_SET_FUNC (guint, index)
|
||||
PART_GET_FUNC (MMSmsPduType, pdu_type)
|
||||
PART_SET_FUNC (MMSmsPduType, pdu_type)
|
||||
PART_GET_FUNC (const gchar *, smsc)
|
||||
PART_SET_TAKE_STR_FUNC (smsc)
|
||||
PART_GET_FUNC (const gchar *, number)
|
||||
@@ -383,12 +387,14 @@ mm_sms_part_should_concat (MMSmsPart *self)
|
||||
}
|
||||
|
||||
MMSmsPart *
|
||||
mm_sms_part_new (guint index)
|
||||
mm_sms_part_new (guint index,
|
||||
MMSmsPduType pdu_type)
|
||||
{
|
||||
MMSmsPart *sms_part;
|
||||
|
||||
sms_part = g_slice_new0 (MMSmsPart);
|
||||
sms_part->index = index;
|
||||
sms_part->pdu_type = pdu_type;
|
||||
|
||||
return sms_part;
|
||||
}
|
||||
@@ -500,7 +506,7 @@ mm_sms_part_new_from_binary_pdu (guint index,
|
||||
}
|
||||
|
||||
/* Create the new MMSmsPart */
|
||||
sms_part = mm_sms_part_new (index);
|
||||
sms_part = mm_sms_part_new (index, MM_SMS_PDU_TYPE_SUBMIT);
|
||||
mm_sms_part_take_smsc (sms_part,
|
||||
sms_decode_address (&pdu[1], 2 * (pdu[0] - 1)));
|
||||
mm_sms_part_take_number (sms_part,
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#define MM_SMS_PART_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <ModemManager-enums.h>
|
||||
|
||||
typedef enum {
|
||||
MM_SMS_ENCODING_UNKNOWN = 0x0,
|
||||
@@ -31,7 +32,8 @@ typedef struct _MMSmsPart MMSmsPart;
|
||||
#define SMS_MAX_PDU_LEN 344
|
||||
#define SMS_PART_INVALID_INDEX G_MAXUINT
|
||||
|
||||
MMSmsPart *mm_sms_part_new (guint index);
|
||||
MMSmsPart *mm_sms_part_new (guint index,
|
||||
MMSmsPduType type);
|
||||
MMSmsPart *mm_sms_part_new_from_pdu (guint index,
|
||||
const gchar *hexpdu,
|
||||
GError **error);
|
||||
@@ -50,6 +52,10 @@ guint mm_sms_part_get_index (MMSmsPart *part);
|
||||
void mm_sms_part_set_index (MMSmsPart *part,
|
||||
guint index);
|
||||
|
||||
MMSmsPduType mm_sms_part_get_pdu_type (MMSmsPart *part);
|
||||
void mm_sms_part_set_pdu_type (MMSmsPart *part,
|
||||
MMSmsPduType type);
|
||||
|
||||
const gchar *mm_sms_part_get_smsc (MMSmsPart *part);
|
||||
void mm_sms_part_set_smsc (MMSmsPart *part,
|
||||
const gchar *smsc);
|
||||
|
@@ -1171,6 +1171,7 @@ assemble_sms (MMSms *self,
|
||||
|
||||
/* If we got everything, assemble the text! */
|
||||
g_object_set (self,
|
||||
"pdu-type", mm_sms_part_get_pdu_type (sorted_parts[0]),
|
||||
"text", fulltext->str,
|
||||
"data", g_variant_new_from_data (G_VARIANT_TYPE ("ay"),
|
||||
fulldata->data,
|
||||
@@ -1392,7 +1393,8 @@ mm_sms_new_from_properties (MMBaseModem *modem,
|
||||
i, (guint)strlen (split_text[i]));
|
||||
|
||||
/* Create new part */
|
||||
part = mm_sms_part_new (SMS_PART_INVALID_INDEX);
|
||||
part = mm_sms_part_new (SMS_PART_INVALID_INDEX,
|
||||
MM_SMS_PDU_TYPE_SUBMIT);
|
||||
mm_sms_part_set_text (part, split_text[i]);
|
||||
mm_sms_part_set_encoding (part, encoding);
|
||||
mm_sms_part_set_number (part, mm_sms_properties_get_number (properties));
|
||||
@@ -1429,7 +1431,8 @@ mm_sms_new_from_properties (MMBaseModem *modem,
|
||||
}
|
||||
|
||||
/* Single part it will be */
|
||||
part = mm_sms_part_new (SMS_PART_INVALID_INDEX);
|
||||
part = mm_sms_part_new (SMS_PART_INVALID_INDEX,
|
||||
MM_SMS_PDU_TYPE_SUBMIT);
|
||||
if (n_parts == 1) {
|
||||
mm_sms_part_set_text (part, mm_sms_properties_get_text (properties));
|
||||
mm_sms_part_set_encoding (part, encoding);
|
||||
|
@@ -527,7 +527,7 @@ common_test_create_pdu (const gchar *smsc,
|
||||
guint len = 0, msgstart = 0;
|
||||
GError *error = NULL;
|
||||
|
||||
part = mm_sms_part_new (0);
|
||||
part = mm_sms_part_new (0, MM_SMS_PDU_TYPE_SUBMIT);
|
||||
if (smsc)
|
||||
mm_sms_part_set_smsc (part, smsc);
|
||||
if (number)
|
||||
|
Reference in New Issue
Block a user