All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petteri Tikander <petteri.tikander@ixonos.com>
To: ofono@ofono.org
Subject: [RFC PATCH 1/2] smsutil: national to international conversion in status report
Date: Tue, 14 Sep 2010 20:38:45 +0300	[thread overview]
Message-ID: <1284485926-5255-1-git-send-email-petteri.tikander@ixonos.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 4154 bytes --]

---
 src/smsutil.c |   70 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index 26c7951..2d47289 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -2826,14 +2826,18 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly,
 	unsigned int offset = status_report->status_report.mr / 32;
 	unsigned int bit = 1 << (status_report->status_report.mr % 32);
 	struct id_table_node *node = NULL;
-	const char *straddr;
+	const char *straddr, *sent_addr;
+	struct sms_address addr;
 	GHashTable *id_table;
 	gpointer key, value;
 	gboolean delivered;
-	GHashTableIter iter;
+	GHashTableIter iter_addr, iter;
 	gboolean pending;
 	int i;
 	unsigned int msg_id;
+	unsigned int n_digits;
+	unsigned int len_sent_addr;
+	unsigned int len_rec_addr;
 
 	/* We ignore temporary or tempfinal status reports */
 	if (sr_st_to_delivered(status_report->status_report.st,
@@ -2841,20 +2845,54 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly,
 		return FALSE;
 
 	straddr = sms_address_to_string(&status_report->status_report.raddr);
-	id_table = g_hash_table_lookup(assembly->assembly_table, straddr);
 
-	/* key (receiver address) does not exist in assembly */
-	if (id_table == NULL)
-		return FALSE;
+	g_hash_table_iter_init(&iter_addr, assembly->assembly_table);
 
-	g_hash_table_iter_init(&iter, id_table);
-	while (g_hash_table_iter_next(&iter, &key, &value)) {
-		node = value;
+	/*
+	 * Go through all addresses. Each address can relate to
+	 * 1-n msg_ids.
+	 */
+	while (g_hash_table_iter_next(&iter_addr, (gpointer) &sent_addr,
+					(gpointer) &id_table)) {
+		/*
+		 * Some networks can change address to international format,
+		 * although address is sent in the national format.
+		 * So notify this special case by checking only
+		 * last six digits. If address contains less than six digits,
+		 * compare only existing digits.
+		 */
+		if ((straddr[0] == '+') && (sent_addr[0] != '+')) {
+			len_sent_addr = strlen(sent_addr);
+			len_rec_addr = strlen(straddr);
+			n_digits = (len_sent_addr > 6) ? 6 : len_sent_addr;
 
-		if (node->mrs[offset] & bit)
-			break;
+			if (strcmp(&straddr[len_rec_addr - n_digits],
+					&sent_addr[len_sent_addr - n_digits]))
+				continue;
+		}
+		/*
+		 * In other cases the whole number received in the status report
+		 * should match with the number originally sent.
+		 */
+		else if (strcmp(straddr, sent_addr))
+				continue;
+
+		g_hash_table_iter_init(&iter, id_table);
+		while (g_hash_table_iter_next(&iter, &key, &value)) {
+			node = value;
+
+			if (node->mrs[offset] & bit)
+				break;
 
-		node = NULL;
+			node = NULL;
+		}
+
+		/*
+		 * Received address with MR matched with one of the stored
+		 * addresses and MR, so no need to continue searching.
+		 */
+		if (node)
+			break;
 	}
 
 	/* Unable to find a message reference belonging to this address */
@@ -2881,6 +2919,8 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly,
 
 	msg_id = *(unsigned int *) key;
 
+	sms_address_from_string(&addr, sent_addr);
+
 	if (pending == TRUE && node->deliverable == TRUE) {
 		/*
 		 * More status reports expected, and already received
@@ -2888,7 +2928,7 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly,
 		 */
 		sr_assembly_add_fragment_backup(
 					assembly->imsi, node,
-					&status_report->status_report.raddr,
+					&addr,
 					msg_id);
 
 		return FALSE;
@@ -2901,14 +2941,14 @@ gboolean status_report_assembly_report(struct status_report_assembly *assembly,
 		*out_id = msg_id;
 
 	sr_assembly_remove_fragment_backup(assembly->imsi,
-					&status_report->status_report.raddr,
+					&addr,
 					msg_id);
 
 	g_hash_table_iter_remove(&iter);
 
 	if (g_hash_table_size(id_table) == 0)
 		g_hash_table_remove(assembly->assembly_table,
-				status_report->status_report.raddr.address);
+					sent_addr);
 
 	return TRUE;
 }
-- 
1.6.3.3



             reply	other threads:[~2010-09-14 17:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-14 17:38 Petteri Tikander [this message]
2010-09-14 17:38 ` [RFC PATCH 2/2] unit: national to international conversion Petteri Tikander
2010-09-15  7:25 [RFC PATCH 1/2] smsutil: national to international conversion in status report Petteri Tikander
2010-09-15 16:10 ` Denis Kenzior
2010-09-17 17:24   ` Petteri Tikander
2010-09-17 18:15     ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284485926-5255-1-git-send-email-petteri.tikander@ixonos.com \
    --to=petteri.tikander@ixonos.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.