Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH 1/2] stk: Constraint the appearance of empty item
Date: Mon, 31 May 2010 19:13:21 +0800	[thread overview]
Message-ID: <1275304402-23708-1-git-send-email-yang.gu@intel.com> (raw)

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

If empty item turns out, it must be the only item in the list.
So the following situations are deemed as invalid:
1. Two empty items
2. Valid item + empty item
3. empty + valid item
---
 src/stkutil.c |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 2ca5c6a..a31ae20 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -2014,6 +2014,12 @@ static dataobj_handler handler_for_type(enum stk_data_object_type type)
 	}
 }
 
+static void destroy_stk_item(struct stk_item *item)
+{
+	g_free(item->text);
+	g_free(item);
+}
+
 static gboolean parse_item_list(struct comprehension_tlv_iter *iter,
 				void *data)
 {
@@ -2022,21 +2028,40 @@ static gboolean parse_item_list(struct comprehension_tlv_iter *iter,
 	struct comprehension_tlv_iter iter_old;
 	struct stk_item item;
 	GSList *list = NULL;
+	unsigned int count = 0;
+	gboolean has_empty = FALSE;
 
 	do {
 		comprehension_tlv_iter_copy(iter, &iter_old);
 		memset(&item, 0, sizeof(item));
+		count++;
+
+		if (parse_dataobj_item(iter, &item) == TRUE) {
+			if (item.id == 0) {
+				has_empty = TRUE;
+				continue;
+			}
 
-		if (parse_dataobj_item(iter, &item) == TRUE)
 			list = g_slist_prepend(list,
 						g_memdup(&item, sizeof(item)));
+		}
 	} while (comprehension_tlv_iter_next(iter) == TRUE &&
 			comprehension_tlv_iter_get_tag(iter) == tag);
 
 	comprehension_tlv_iter_copy(&iter_old, iter);
-	*out = g_slist_reverse(list);
 
-	return TRUE;
+	if (!has_empty) {
+		*out = g_slist_reverse(list);
+		return TRUE;
+	}
+
+	if (count == 1)
+		return TRUE;
+
+	g_slist_foreach(list, (GFunc)destroy_stk_item, NULL);
+	g_slist_free(list);
+	return FALSE;
+
 }
 
 static gboolean parse_provisioning_list(struct comprehension_tlv_iter *iter,
@@ -2342,12 +2367,6 @@ static gboolean parse_poll_interval(struct stk_command *command,
 	return TRUE;
 }
 
-static void destroy_stk_item(struct stk_item *item)
-{
-	g_free(item->text);
-	g_free(item);
-}
-
 static void destroy_setup_menu(struct stk_command *command)
 {
 	g_free(command->setup_menu.alpha_id);
@@ -2392,9 +2411,6 @@ static gboolean parse_setup_menu(struct stk_command *command,
 	if (ret == FALSE)
 		return FALSE;
 
-	if (obj->items == NULL)
-		return FALSE;
-
 	return TRUE;
 }
 
-- 
1.7.0.4


             reply	other threads:[~2010-05-31 11:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-31 11:13 Yang Gu [this message]
2010-05-31 11:13 ` [PATCH 2/2] stktest: Add negative cases for setup menu Yang Gu
2010-06-01 19:12 ` [PATCH 1/2] stk: Constraint the appearance of empty item 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=1275304402-23708-1-git-send-email-yang.gu@intel.com \
    --to=yang.gu@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox