gsm: change SMS send validity from 5-minute units to minutes

Might as well keep it simple.
This commit is contained in:
Dan Williams
2012-01-18 16:29:02 -06:00
parent c437da20ff
commit e2306a0dd5
5 changed files with 56 additions and 32 deletions

View File

@@ -35,7 +35,6 @@
data : byte array - SMS user data (TP-UD) (mandatory)
data-coding-scheme: uint (0..255) - SMS user data coding scheme (TP-DCS) (mandatory)
smsc : string - SMS service center number (optional)
validity : uint (0..255) - Specifies when the SMS expires in SMSC (optional)
class : uint (0..3) - Message importance and location (optional)
completed: boolean - Whether all message parts have been received or not (optional)
index : uint - Index of message (for Get and Delete) (optional)
@@ -83,7 +82,7 @@
number : string - Phone number (mandatory)
text : string - SMS text (mandatory)
smsc : string - SMS service center number (optional)
validity : uint (0..255) - Specifies when the SMS expires in SMSC (optional)
relative-validity : uint - Minutes until the SMS expires in SMSC (optional)
class : uint (0..3) - Message importance and location (optional)
</tp:docstring>
</arg>
@@ -100,7 +99,7 @@
number : string - Phone number (mandatory)
text : string - SMS text (mandatory)
smsc : string - SMS service center number (optional)
validity : uint (0..127008) - Specifies when the SMS expires in SMSC (units of 5 minutes) (optional)
relative-validity : uint - Minutes until the SMS expires in SMSC (optional)
class : uint (0..3) - Message importance and location (optional)
</tp:docstring>
</arg>

View File

@@ -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);

View File

@@ -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

View File

@@ -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 ();

View File

@@ -21,7 +21,7 @@ import os
arglen = len(sys.argv)
if arglen != 4 and arglen != 6 and arglen != 8:
print "Usage: %s --number <number> [--smsc <smsc>] [--validity <5 minute units>] <message>" % sys.argv[0]
print "Usage: %s --number <number> [--smsc <smsc>] [--validity <minutes>] <message>" % sys.argv[0]
sys.exit(1)
number = None