This formats addresses in SMS messages (sender address and SMSC) in accordance with ITU E.164/E.123 by including a "+" before the number when it's an international phone number (according to the other address-type fields).
- Nathan
From 6b18bc94a9347972d0d180386ff92cac03a6bcbb Mon Sep 17 00:00:00 2001 From: Nathan Williams <n...@google.com> Date: Tue, 31 May 2011 13:50:17 -0400 Subject: [PATCH] sms_decode_address(): Add a leading "+" on international numbers. BUG=chromium-os-partner:4278 TEST=Send SMS from phone (to get +... format) and from AIM-SMS gateway (to get raw-digit format). Change-Id: I36eb9f1432a432435578180dfdb315b0e7ee5744 --- src/mm-generic-gsm.c | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 9bc16c9..f7db4f2 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -3967,6 +3967,14 @@ mm_generic_gsm_get_charset (MMGenericGsm *self) #define SMS_TP_MTI_SMS_SUBMIT_REPORT 0x01 #define SMS_TP_MTI_SMS_STATUS_REPORT 0x02 +#define SMS_NUMBER_TYPE_MASK 0x70 +#define SMS_NUMBER_TYPE_UNKNOWN 0x00 +#define SMS_NUMBER_TYPE_INTL 0x10 +#define SMS_NUMBER_TYPE_ALPHA 0x50 + +#define SMS_NUMBER_PLAN_MASK 0x0f +#define SMS_NUMBER_PLAN_TELEPHONE 0x01 + #define SMS_TP_MMS 0x04 #define SMS_TP_SRI 0x20 #define SMS_TP_UDHI 0x40 @@ -4046,21 +4054,33 @@ sms_semi_octets_to_bcd_string (char *dest, const guint8 *octets, int num_octets) static char * sms_decode_address (const guint8 *address, int len) { - guint8 addrtype; + guint8 addrtype, addrplan; char *utf8; - addrtype = address[0]; + addrtype = address[0] & SMS_NUMBER_TYPE_MASK; + addrplan = address[0] & SMS_NUMBER_PLAN_MASK; address++; - if (addrtype == 0xd0) { + if (addrtype == SMS_NUMBER_TYPE_ALPHA) { guint8 *unpacked; guint32 unpacked_len; unpacked = gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len); utf8 = (char *)mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len); g_free(unpacked); + } else if (addrtype == SMS_NUMBER_TYPE_INTL && + addrplan == SMS_NUMBER_PLAN_TELEPHONE) { + /* International telphone number, format as "+1234567890" */ + utf8 = g_malloc (len + 3); /* '+' + digits + possible trailing 0xf + NUL */ + utf8[0] = '+'; + sms_semi_octets_to_bcd_string (utf8 + 1, address, (len + 1) / 2); } else { - utf8 = g_malloc (len + 2); /* may need one extra for trailing 0xf */ + /* + * All non-alphanumeric types and plans are just digits, but + * don't apply any special formatting if we don't know the + * format. + */ + utf8 = g_malloc (len + 2); /* digits + possible trailing 0xf + NUL */ sms_semi_octets_to_bcd_string (utf8, address, (len + 1) / 2); } -- 1.7.3.1
_______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list