diff options
author | Dan Williams <dcbw@redhat.com> | 2013-04-30 12:07:16 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2013-05-06 10:45:55 -0500 |
commit | 9bbcd9d6a5d0b01e16bdd4f94f707f0341f73e24 (patch) | |
tree | 0bf82eb0494145860c0434583fc27ac791819415 | |
parent | ab4198f576cb4308fecef3897675fe49cbcbe48a (diff) | |
download | ModemManager-9bbcd9d6a5d0b01e16bdd4f94f707f0341f73e24.tar.gz |
sms: add support for message class
We need to redefine the message class property to int since class
0 is a valid message class. Thus -1 now means "unspecified class".
-rw-r--r-- | introspection/org.freedesktop.ModemManager1.Sms.xml | 7 | ||||
-rw-r--r-- | libmm-glib/mm-sms-properties.c | 35 | ||||
-rw-r--r-- | libmm-glib/mm-sms-properties.h | 4 | ||||
-rw-r--r-- | libmm-glib/mm-sms.c | 6 | ||||
-rw-r--r-- | libmm-glib/mm-sms.h | 2 | ||||
-rw-r--r-- | src/mm-broadband-modem.c | 2 | ||||
-rw-r--r-- | src/mm-sms-part.c | 20 | ||||
-rw-r--r-- | src/mm-sms-part.h | 4 | ||||
-rw-r--r-- | src/tests/test-sms-part.c | 16 |
9 files changed, 50 insertions, 46 deletions
diff --git a/introspection/org.freedesktop.ModemManager1.Sms.xml b/introspection/org.freedesktop.ModemManager1.Sms.xml index 16e29d2f9..586c2fd66 100644 --- a/introspection/org.freedesktop.ModemManager1.Sms.xml +++ b/introspection/org.freedesktop.ModemManager1.Sms.xml @@ -122,11 +122,12 @@ <!-- Class: - 3GPP message class (0..3). + 3GPP message class (-1..3). -1 means class is not available or + is not used for this message, otherwise the 3GPP SMS message class. - Always 0 for 3GPP2/CDMA. + Always -1 for 3GPP2/CDMA. --> - <property name="Class" type="u" access="read" /> + <property name="Class" type="i" access="read" /> <!-- DeliveryReportRequest: diff --git a/libmm-glib/mm-sms-properties.c b/libmm-glib/mm-sms-properties.c index 05d5fd16b..a6947269c 100644 --- a/libmm-glib/mm-sms-properties.c +++ b/libmm-glib/mm-sms-properties.c @@ -51,8 +51,7 @@ struct _MMSmsPropertiesPrivate { gchar *smsc; MMSmsValidityType validity_type; guint validity_relative; - gboolean class_set; - guint class; + gint class; gboolean delivery_report_request_set; gboolean delivery_report_request; }; @@ -319,17 +318,16 @@ mm_sms_properties_get_validity_relative (MMSmsProperties *self) /** * mm_sms_properties_set_class: * @self: A #MMSmsProperties. - * @class: The message class. + * @class: The message class, or -1 for invalid/unset class. * * Sets the 3GPP message class of the SMS. */ void mm_sms_properties_set_class (MMSmsProperties *self, - guint class) + gint class) { g_return_if_fail (MM_IS_SMS_PROPERTIES (self)); - self->priv->class_set = TRUE; self->priv->class = class; } @@ -339,12 +337,12 @@ mm_sms_properties_set_class (MMSmsProperties *self, * * Gets the 3GPP message class of the SMS. * - * Returns: the message class. + * Returns: the message class, or -1 for invalid/unset class. */ -guint +gint mm_sms_properties_get_class (MMSmsProperties *self) { - g_return_val_if_fail (MM_IS_SMS_PROPERTIES (self), 0); + g_return_val_if_fail (MM_IS_SMS_PROPERTIES (self), -1); return self->priv->class; } @@ -435,11 +433,11 @@ mm_sms_properties_get_dictionary (MMSmsProperties *self) PROPERTY_VALIDITY, g_variant_new ("(uv)", MM_SMS_VALIDITY_TYPE_RELATIVE, g_variant_new_uint32 (self->priv->validity_relative))); - if (self->priv->class_set) + if (self->priv->class >= 0) g_variant_builder_add (&builder, "{sv}", PROPERTY_CLASS, - g_variant_new_uint32 (self->priv->class)); + g_variant_new_int32 (self->priv->class)); if (self->priv->delivery_report_request_set) g_variant_builder_add (&builder, @@ -517,12 +515,14 @@ consume_string (MMSmsProperties *self, mm_sms_properties_set_validity_relative (self, n); } else if (g_str_equal (key, PROPERTY_CLASS)) { - GError *inner_error = NULL; - guint n; - - n = parse_uint (value, &inner_error); - if (inner_error) { - g_propagate_error (error, inner_error); + gint n = 0; + + if (!mm_get_int_from_str (value, &n)) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_INVALID_ARGS, + "Invalid properties string, cannot parse '%s' as int", + value); return FALSE; } @@ -642,7 +642,7 @@ consume_variant (MMSmsProperties *properties, } else if (g_str_equal (key, PROPERTY_CLASS)) mm_sms_properties_set_class ( properties, - g_variant_get_uint32 (value)); + g_variant_get_int32 (value)); else if (g_str_equal (key, PROPERTY_DELIVERY_REPORT_REQUEST)) mm_sms_properties_set_delivery_report_request ( properties, @@ -746,6 +746,7 @@ mm_sms_properties_init (MMSmsProperties *self) MM_TYPE_SMS_PROPERTIES, MMSmsPropertiesPrivate); self->priv->validity_type = MM_SMS_VALIDITY_TYPE_UNKNOWN; + self->priv->class = -1; } static void diff --git a/libmm-glib/mm-sms-properties.h b/libmm-glib/mm-sms-properties.h index 82c65595a..b0c290a09 100644 --- a/libmm-glib/mm-sms-properties.h +++ b/libmm-glib/mm-sms-properties.h @@ -71,7 +71,7 @@ void mm_sms_properties_set_smsc (MMSmsProperties *self, void mm_sms_properties_set_validity_relative (MMSmsProperties *self, guint validity); void mm_sms_properties_set_class (MMSmsProperties *self, - guint class); + gint class); void mm_sms_properties_set_delivery_report_request (MMSmsProperties *self, gboolean request); @@ -84,7 +84,7 @@ const gchar *mm_sms_properties_get_number (MMSmsProperties *se const gchar *mm_sms_properties_get_smsc (MMSmsProperties *self); MMSmsValidityType mm_sms_properties_get_validity_type (MMSmsProperties *self); guint mm_sms_properties_get_validity_relative (MMSmsProperties *self); -guint mm_sms_properties_get_class (MMSmsProperties *self); +gint mm_sms_properties_get_class (MMSmsProperties *self); gboolean mm_sms_properties_get_delivery_report_request (MMSmsProperties *self); /*****************************************************************************/ diff --git a/libmm-glib/mm-sms.c b/libmm-glib/mm-sms.c index a69b5dc73..822902185 100644 --- a/libmm-glib/mm-sms.c +++ b/libmm-glib/mm-sms.c @@ -445,12 +445,12 @@ mm_sms_get_validity_relative (MMSms *self) * * Gets the 3GPP message class of the SMS. * - * Returns: the message class. + * Returns: the message class, or -1 for invalid/unset class. */ -guint +gint mm_sms_get_class (MMSms *self) { - g_return_val_if_fail (MM_IS_SMS (self), 0); + g_return_val_if_fail (MM_IS_SMS (self), -1); return mm_gdbus_sms_get_class (MM_GDBUS_SMS (self)); } diff --git a/libmm-glib/mm-sms.h b/libmm-glib/mm-sms.h index cb5b2b9d3..def70c10b 100644 --- a/libmm-glib/mm-sms.h +++ b/libmm-glib/mm-sms.h @@ -89,7 +89,7 @@ gchar *mm_sms_dup_discharge_timestamp (MMSms *self); MMSmsValidityType mm_sms_get_validity_type (MMSms *self); guint mm_sms_get_validity_relative (MMSms *self); -guint mm_sms_get_class (MMSms *self); +gint mm_sms_get_class (MMSms *self); guint mm_sms_get_message_reference (MMSms *self); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 45d9027ad..33e3246f5 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -5828,7 +5828,7 @@ sms_text_part_list_ready (MMBroadbandModem *self, mm_sms_part_take_timestamp (part, timestamp); mm_sms_part_take_text (part, text); mm_sms_part_take_data (part, raw); - mm_sms_part_set_class (part, 0); + mm_sms_part_set_class (part, -1); mm_dbg ("Correctly parsed SMS list entry (%d)", idx); mm_iface_modem_messaging_take_part (MM_IFACE_MODEM_MESSAGING (self), diff --git a/src/mm-sms-part.c b/src/mm-sms-part.c index a5e8b33c7..77fa3b82d 100644 --- a/src/mm-sms-part.c +++ b/src/mm-sms-part.c @@ -325,7 +325,7 @@ struct _MMSmsPart { gchar *text; MMSmsEncoding encoding; GByteArray *data; - guint class; + gint class; guint validity_relative; gboolean delivery_report_request; guint message_reference; @@ -403,8 +403,8 @@ PART_GET_FUNC (const gchar *, text) PART_SET_TAKE_STR_FUNC (text) PART_GET_FUNC (MMSmsEncoding, encoding) PART_SET_FUNC (MMSmsEncoding, encoding) -PART_GET_FUNC (guint, class) -PART_SET_FUNC (guint, class) +PART_GET_FUNC (gint, class) +PART_SET_FUNC (gint, class) PART_GET_FUNC (guint, validity_relative) PART_SET_FUNC (guint, validity_relative) PART_GET_FUNC (gboolean, delivery_report_request) @@ -461,6 +461,7 @@ mm_sms_part_new (guint index, sms_part->pdu_type = pdu_type; sms_part->encoding = MM_SMS_ENCODING_UNKNOWN; sms_part->delivery_state = MM_SMS_DELIVERY_STATE_UNKNOWN; + sms_part->class = -1; return sms_part; } @@ -917,12 +918,7 @@ mm_sms_part_encode_address (const gchar *address, /** * mm_sms_part_get_submit_pdu: * - * @number: the subscriber number to send this message to - * @text: the body of this SMS - * @smsc: if given, the SMSC address - * @validity: minutes until the SMS should expire in the SMSC, or 0 for a - * suitable default - * @class: unused + * @part: the SMS message part * @out_pdulen: on success, the size of the returned PDU in bytes * @out_msgstart: on success, the byte index in the returned PDU where the * message starts (ie, skipping the SMSC length byte and address, if present) @@ -1023,6 +1019,12 @@ mm_sms_part_get_submit_pdu (MMSmsPart *part, /* ----------- TP-DCS (1 byte) ----------- */ pdu[offset] = 0x00; + if (part->class >= 0 && part->class <= 3) { + mm_dbg (" using class %d...", part->class); + pdu[offset] |= SMS_DCS_CLASS_VALID; + pdu[offset] |= part->class; + } + if (part->encoding == MM_SMS_ENCODING_UCS2) { mm_dbg (" using UCS2 encoding..."); pdu[offset] |= SMS_DCS_CODING_UCS2; diff --git a/src/mm-sms-part.h b/src/mm-sms-part.h index 8e7cdd92b..d44ed5bcd 100644 --- a/src/mm-sms-part.h +++ b/src/mm-sms-part.h @@ -96,9 +96,9 @@ MMSmsEncoding mm_sms_part_get_encoding (MMSmsPart *part); void mm_sms_part_set_encoding (MMSmsPart *part, MMSmsEncoding encoding); -guint mm_sms_part_get_class (MMSmsPart *part); +gint mm_sms_part_get_class (MMSmsPart *part); void mm_sms_part_set_class (MMSmsPart *part, - guint class); + gint class); guint mm_sms_part_get_validity_relative (MMSmsPart *part); void mm_sms_part_set_validity_relative (MMSmsPart *part, diff --git a/src/tests/test-sms-part.c b/src/tests/test-sms-part.c index 6a3f7183c..d1f75886f 100644 --- a/src/tests/test-sms-part.c +++ b/src/tests/test-sms-part.c @@ -512,7 +512,7 @@ common_test_create_pdu (const gchar *smsc, const gchar *number, const gchar *text, guint validity, - guint class, + gint class, const guint8 *expected, gsize expected_size, guint expected_msgstart) @@ -537,7 +537,7 @@ common_test_create_pdu (const gchar *smsc, } if (validity > 0) mm_sms_part_set_validity_relative (part, validity); - if (class > 0) + if (class >= 0) mm_sms_part_set_class (part, class); pdu = mm_sms_part_get_submit_pdu (part, @@ -576,7 +576,7 @@ test_create_pdu_ucs2_with_smsc (void) number, text, 5, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 8); /* expected_msgstart */ @@ -601,7 +601,7 @@ test_create_pdu_ucs2_no_smsc (void) number, text, 5, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 1); /* expected_msgstart */ @@ -626,7 +626,7 @@ test_create_pdu_gsm_with_smsc (void) number, text, 5, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 8); /* expected_msgstart */ @@ -650,7 +650,7 @@ test_create_pdu_gsm_no_smsc (void) number, text, 5, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 1); /* expected_msgstart */ @@ -678,7 +678,7 @@ test_create_pdu_gsm_3 (void) number, text, 5, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 1); /* expected_msgstart */ @@ -699,7 +699,7 @@ test_create_pdu_gsm_no_validity (void) number, text, 0, /* validity */ - 0, /* class */ + -1, /* class */ expected, sizeof (expected), 1); /* expected_msgstart */ |