aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-01-18 16:29:02 -0600
committerDan Williams <dcbw@redhat.com>2012-01-18 16:30:15 -0600
commite2306a0dd5958ee9fef7305c6e41a0595bbeb3cc (patch)
tree6b735629ea1f12ef5de2a4162530b4dc3122dcf1 /src
parentc437da20ffe1873b15c338f95be4bee26e26b401 (diff)
gsm: change SMS send validity from 5-minute units to minutes
Might as well keep it simple.
Diffstat (limited to 'src')
-rw-r--r--src/mm-modem-gsm-sms.c2
-rw-r--r--src/mm-sms-utils.c46
-rw-r--r--src/tests/test-sms.c33
3 files changed, 53 insertions, 28 deletions
diff --git a/src/mm-modem-gsm-sms.c b/src/mm-modem-gsm-sms.c
index ab20d3ed..e82cace3 100644
--- a/src/mm-modem-gsm-sms.c
+++ b/src/mm-modem-gsm-sms.c
@@ -607,7 +607,7 @@ sms_send_auth_cb (MMAuthRequest *req,
if (value)
smsc = g_value_get_string (value);
- value = (GValue *) g_hash_table_lookup (info->hash, "validity");
+ value = (GValue *) g_hash_table_lookup (info->hash, "relative-validity");
if (value)
validity = g_value_get_uint (value);
diff --git a/src/mm-sms-utils.c b/src/mm-sms-utils.c
index 025a19dc..ddb35994 100644
--- a/src/mm-sms-utils.c
+++ b/src/mm-sms-utils.c
@@ -551,38 +551,40 @@ validity_to_relative (guint validity)
if (validity == 0)
return 167; /* 24 hours */
- if (validity <= 144) {
+ if (validity <= 720) {
/* 5 minute units up to 12 hours */
- return validity - 1;
+ if (validity % 5)
+ validity += 5;
+ return (validity / 5) - 1;
}
- if (validity > 144 && validity <= 288) {
+ if (validity > 720 && validity <= 1440) {
/* 12 hours + 30 minute units up to 1 day */
- if (validity % 6)
- validity += 6; /* round up to next 30 minutes */
- validity = MIN (validity, 288);
- return 143 + ((validity - 144) / 6); /* 6 = 30 minutes / 5 minutes */
+ if (validity % 30)
+ validity += 30; /* round up to next 30 minutes */
+ validity = MIN (validity, 1440);
+ return 143 + ((validity - 720) / 30);
}
- if (validity > 288 && validity <= 8640) {
+ if (validity > 1440 && validity <= 43200) {
/* 2 days up to 1 month */
- if (validity % 288)
- validity += 288; /* round up to next day */
- validity = MIN (validity, 8640);
- return 167 + ((validity - 288) / 288); /* 288 = 1 day / 5 minutes */
+ if (validity % 1440)
+ validity += 1440; /* round up to next day */
+ validity = MIN (validity, 43200);
+ return 167 + ((validity - 1440) / 1440);
}
- /* 8640 = 30 days in 5-minute units
- * 2016 = 7 days in 5-minute units
- * 127008 = 63 weeks in 5-minute units
- * 8064 = 4 weeks in 5-minute units
+ /* 43200 = 30 days in minutes
+ * 10080 = 7 days in minutes
+ * 635040 = 63 weeks in minutes
+ * 40320 = 4 weeks in minutes
*/
- if (validity > 8640 && validity <= 127008) {
+ if (validity > 43200 && validity <= 635040) {
/* 5 weeks up to 63 weeks */
- if (validity % 2016)
- validity += 2016; /* round up to next week */
- validity = MIN (validity, 127008);
- return 196 + ((validity - 8064) / 2016);
+ if (validity % 10080)
+ validity += 10080; /* round up to next week */
+ validity = MIN (validity, 635040);
+ return 196 + ((validity - 40320) / 10080);
}
return 255; /* 63 weeks */
@@ -596,7 +598,7 @@ validity_to_relative (guint validity)
* @number: the subscriber number to send this message to
* @text: the body of this SMS
* @smsc: if given, the SMSC address
- * @validity: validity period of this SMS in 5-minute increments, or 0 for a
+ * @validity: minutes until the SMS should expire in the SMSC, or 0 for a
* suitable default
* @class: unused
* @out_pdulen: on success, the size of the returned PDU in bytes
diff --git a/src/tests/test-sms.c b/src/tests/test-sms.c
index 11118c06..1a3f9333 100644
--- a/src/tests/test-sms.c
+++ b/src/tests/test-sms.c
@@ -491,7 +491,7 @@ test_create_pdu_ucs2_with_smsc (void *f, gpointer d)
guint len = 0, msgstart = 0;
GError *error = NULL;
- pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &msgstart, &error);
+ pdu = sms_create_submit_pdu (number, text, smsc, 5, 0, &len, &msgstart, &error);
g_assert_no_error (error);
g_assert (pdu);
g_assert_cmpint (len, ==, sizeof (expected));
@@ -517,7 +517,7 @@ test_create_pdu_ucs2_no_smsc (void *f, gpointer d)
guint len = 0, msgstart = 0;
GError *error = NULL;
- pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
g_assert_no_error (error);
g_assert (pdu);
g_assert_cmpint (len, ==, sizeof (expected));
@@ -543,7 +543,7 @@ test_create_pdu_gsm_with_smsc (void *f, gpointer d)
guint len = 0, msgstart = 0;
GError *error = NULL;
- pdu = sms_create_submit_pdu (number, text, smsc, 1, 0, &len, &msgstart, &error);
+ pdu = sms_create_submit_pdu (number, text, smsc, 5, 0, &len, &msgstart, &error);
g_assert_no_error (error);
g_assert (pdu);
g_assert_cmpint (len, ==, sizeof (expected));
@@ -568,7 +568,7 @@ test_create_pdu_gsm_no_smsc (void *f, gpointer d)
guint len = 0, msgstart = 0;
GError *error = NULL;
- pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
g_assert_no_error (error);
g_assert (pdu);
g_assert_cmpint (len, ==, sizeof (expected));
@@ -597,7 +597,29 @@ test_create_pdu_gsm_3 (void *f, gpointer d)
* leave off the last octet.
*/
- pdu = sms_create_submit_pdu (number, text, NULL, 1, 0, &len, &msgstart, &error);
+ pdu = sms_create_submit_pdu (number, text, NULL, 5, 0, &len, &msgstart, &error);
+ g_assert_no_error (error);
+ g_assert (pdu);
+ g_assert_cmpint (len, ==, sizeof (expected));
+ g_assert_cmpint (memcmp (pdu, expected, len), ==, 0);
+ g_assert_cmpint (msgstart, ==, 1);
+}
+
+static void
+test_create_pdu_gsm_no_validity (void *f, gpointer d)
+{
+ static const char *number = "+15556661234";
+ static const char *text = "This is really cool ΔΔΔΔΔ";
+ static const guint8 expected[] = {
+ 0x00, 0x01, 0x00, 0x0B, 0x91, 0x51, 0x55, 0x66, 0x16, 0x32, 0xF4, 0x00,
+ 0x00, 0x19, 0x54, 0x74, 0x7A, 0x0E, 0x4A, 0xCF, 0x41, 0xF2, 0x72, 0x98,
+ 0xCD, 0xCE, 0x83, 0xC6, 0xEF, 0x37, 0x1B, 0x04, 0x81, 0x40, 0x20, 0x10
+ };
+ guint8 *pdu;
+ guint len = 0, msgstart = 0;
+ GError *error = NULL;
+
+ pdu = sms_create_submit_pdu (number, text, NULL, 0, 0, &len, &msgstart, &error);
g_assert_no_error (error);
g_assert (pdu);
g_assert_cmpint (len, ==, sizeof (expected));
@@ -660,6 +682,7 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_no_smsc, NULL));
g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_create_pdu_gsm_no_validity, NULL));
result = g_test_run ();