sms-part-3gpp: SMS timestamp in ISO8601 format

This commit is contained in:
amol.lad
2019-09-19 16:49:15 +05:30
committed by Aleksander Morgado
parent 59e82b3f32
commit 16145c29de
2 changed files with 28 additions and 27 deletions

View File

@@ -156,25 +156,26 @@ sms_decode_address (const guint8 *address, int len)
return utf8; return utf8;
} }
static char * static gchar *
sms_decode_timestamp (const guint8 *timestamp) sms_decode_timestamp (const guint8 *timestamp)
{ {
/* YYMMDDHHMMSS+ZZ */ /* ISO8601 format: YYYY-MM-DDTHH:MM:SS+HHMM */
char *timestr; guint year, month, day, hour, minute, second;
int quarters, hours; gint quarters, offset_minutes;
timestr = g_malloc0 (16); year = 2000 + ((timestamp[0] & 0xf) * 10) + ((timestamp[0] >> 4) & 0xf);
sms_semi_octets_to_bcd_string (timestr, timestamp, 6); month = ((timestamp[1] & 0xf) * 10) + ((timestamp[1] >> 4) & 0xf);
day = ((timestamp[2] & 0xf) * 10) + ((timestamp[2] >> 4) & 0xf);
hour = ((timestamp[3] & 0xf) * 10) + ((timestamp[3] >> 4) & 0xf);
minute = ((timestamp[4] & 0xf) * 10) + ((timestamp[4] >> 4) & 0xf);
second = ((timestamp[5] & 0xf) * 10) + ((timestamp[5] >> 4) & 0xf);
quarters = ((timestamp[6] & 0x7) * 10) + ((timestamp[6] >> 4) & 0xf); quarters = ((timestamp[6] & 0x7) * 10) + ((timestamp[6] >> 4) & 0xf);
hours = quarters / 4; offset_minutes = quarters * 15;
if (timestamp[6] & 0x08) if (timestamp[6] & 0x08)
timestr[12] = '-'; offset_minutes = -1 * offset_minutes;
else
timestr[12] = '+'; return mm_new_iso8601_time (year, month, day, hour,
timestr[13] = (hours / 10) + '0'; minute, second, TRUE, offset_minutes);
timestr[14] = (hours % 10) + '0';
/* TODO(njw): Change timestamp rep to something that includes quarter-hours */
return timestr;
} }
static MMSmsEncoding static MMSmsEncoding

View File

@@ -136,7 +136,7 @@ test_pdu1 (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12404492164", /* smsc */ "+12404492164", /* smsc */
"+16175927198", /* number */ "+16175927198", /* number */
"110228115050-05", /* timestamp */ "2011-02-28T11:50:50-05:00", /* timestamp */
FALSE, FALSE,
"Here's a longer message [{with some extended characters}] " "Here's a longer message [{with some extended characters}] "
"thrown in, such as £ and ΩΠΨ and §¿ as well.", /* text */ "thrown in, such as £ and ΩΠΨ and §¿ as well.", /* text */
@@ -157,7 +157,7 @@ test_pdu2 (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+79037011111", /* smsc */ "+79037011111", /* smsc */
"InternetSMS", /* number */ "InternetSMS", /* number */
"110329192004+04", /* timestamp */ "2011-03-29T19:20:04+04:00", /* timestamp */
FALSE, FALSE,
"тест", /* text */ "тест", /* text */
NULL, 0); NULL, 0);
@@ -177,7 +177,7 @@ test_pdu3 (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"+18005551212", /* number */ "+18005551212", /* number */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
"hellohello", /* text */ "hellohello", /* text */
NULL, 0); NULL, 0);
@@ -198,7 +198,7 @@ test_pdu3_nzpid (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"+18005551212", /* number */ "+18005551212", /* number */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
"hellohello", /* text */ "hellohello", /* text */
NULL, 0); NULL, 0);
@@ -219,7 +219,7 @@ test_pdu3_mms (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"+18005551212", /* number */ "+18005551212", /* number */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
"hellohello", /* text */ "hellohello", /* text */
NULL, 0); NULL, 0);
@@ -240,7 +240,7 @@ test_pdu3_natl (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"18005551212", /* number, no plus */ "18005551212", /* number, no plus */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
"hellohello", /* text */ "hellohello", /* text */
NULL, 0); NULL, 0);
@@ -262,7 +262,7 @@ test_pdu3_8bit (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"+18005551212", /* number */ "+18005551212", /* number */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
NULL, /* text */ NULL, /* text */
expected_data, /* data */ expected_data, /* data */
@@ -310,7 +310,7 @@ test_pdu_dcsf1 (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+33609001390", /* smsc */ "+33609001390", /* smsc */
"1800", /* number */ "1800", /* number */
"110624130815+02", /* timestamp */ "2011-06-24T13:08:15+02:00", /* timestamp */
FALSE, FALSE,
"Info SFR - Confidentiel, à ne jamais transmettre -\r\n" "Info SFR - Confidentiel, à ne jamais transmettre -\r\n"
"Voici votre nouveau mot de passe : sw2ced pour gérer " "Voici votre nouveau mot de passe : sw2ced pour gérer "
@@ -334,7 +334,7 @@ test_pdu_dcsf_8bit (void)
pdu, sizeof (pdu), pdu, sizeof (pdu),
"+12345678901", /* smsc */ "+12345678901", /* smsc */
"+18005551212", /* number */ "+18005551212", /* number */
"110101123456+00", /* timestamp */ "2011-01-01T12:34:56+00:00", /* timestamp */
FALSE, FALSE,
NULL, /* text */ NULL, /* text */
expected_data, /* data */ expected_data, /* data */
@@ -380,7 +380,7 @@ test_pdu_udhi (void)
hexpdu, hexpdu,
"+31653131316", /* smsc */ "+31653131316", /* smsc */
"1002", /* number */ "1002", /* number */
"110629233219+02", /* timestamp */ "2011-06-29T23:32:19+02:00", /* timestamp */
TRUE, TRUE,
"Welkom, bel om uw Voicemail te beluisteren naar +31612001233" "Welkom, bel om uw Voicemail te beluisteren naar +31612001233"
" (PrePay: *100*1233#). Voicemail ontvangen is altijd gratis." " (PrePay: *100*1233#). Voicemail ontvangen is altijd gratis."
@@ -405,7 +405,7 @@ test_pdu_multipart (void)
hexpdu1, hexpdu1,
"+12063130025", /* smsc */ "+12063130025", /* smsc */
"+16175046925", /* number */ "+16175046925", /* number */
"120425195650-04", /* timestamp */ "2012-04-25T19:56:50-04:00", /* timestamp */
TRUE, /* multipart! */ TRUE, /* multipart! */
"This is a very long test designed to exercise multi part capability. It should " "This is a very long test designed to exercise multi part capability. It should "
"show up as one message, not as two, as the underlying encoding represents ", /* text */ "show up as one message, not as two, as the underlying encoding represents ", /* text */
@@ -415,7 +415,7 @@ test_pdu_multipart (void)
hexpdu2, hexpdu2,
"+12063130026", /* smsc */ "+12063130026", /* smsc */
"+16175046925", /* number */ "+16175046925", /* number */
"120425195651-04", /* timestamp */ "2012-04-25T19:56:51-04:00", /* timestamp */
TRUE, /* multipart! */ TRUE, /* multipart! */
"that the parts are related to one another. ", /* text */ "that the parts are related to one another. ", /* text */
NULL, 0); NULL, 0);
@@ -448,7 +448,7 @@ test_pdu_not_stored (void)
hexpdu1, hexpdu1,
"+34656000311", /* smsc */ "+34656000311", /* smsc */
"639337937", /* number */ "639337937", /* number */
"120911074036+02", /* timestamp */ "2012-09-11T07:40:36+02:00", /* timestamp */
FALSE, /* multipart! */ FALSE, /* multipart! */
NULL, /* text */ NULL, /* text */
NULL, 0); NULL, 0);