linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slawomir Bochenski <lkslawek@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: johan.hedberg@gmail.com, Slawomir Bochenski <lkslawek@gmail.com>
Subject: [PATCH obexd v2 3/3] MAP/dummy: Add sorting of folder listing
Date: Fri,  9 Mar 2012 07:53:25 +0100	[thread overview]
Message-ID: <1331276005-4434-3-git-send-email-lkslawek@gmail.com> (raw)
In-Reply-To: <1331276005-4434-1-git-send-email-lkslawek@gmail.com>

---
 plugins/messages-dummy.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index b54e9b5..be080c4 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -52,6 +52,36 @@ struct folder_listing_data {
 	void *user_data;
 };
 
+/* NOTE: Neither IrOBEX nor MAP specs says that folder listing needs to
+ * be sorted (in IrOBEX examples it is not). However existing implementations
+ * seem to follow the fig. 3-2 from MAP specification v1.0, and I've seen a
+ * test suite requiring folder listing to be in that order.
+ */
+static gint folder_names_cmp(gconstpointer a, gconstpointer b,
+						gpointer user_data)
+{
+	static const char *order[] = {
+		"inbox", "outbox", "sent", "deleted", "draft", NULL
+	};
+	struct session *session = user_data;
+	int ia, ib;
+
+	if (g_strcmp0(session->cwd, "telecom/msg") == 0) {
+		for (ia = 0; order[ia]; ++ia) {
+			if (g_strcmp0(a, order[ia]) == 0)
+				break;
+		}
+		for (ib = 0; order[ib]; ++ib) {
+			if (g_strcmp0(b, order[ib]) == 0)
+				break;
+		}
+		if (ia != ib)
+			return ia - ib;
+	}
+
+	return g_strcmp0(a, b);
+}
+
 static char *get_next_subdir(DIR *dp, char *path)
 {
 	struct dirent *ep;
@@ -113,6 +143,8 @@ static ssize_t get_subdirs(struct folder_listing_data *fld, GSList **list)
 	closedir(dp);
 	g_free(path);
 
+	*list = g_slist_sort_with_data(*list, folder_names_cmp, fld->session);
+
 	return n;
 }
 
-- 
1.7.4.1


      parent reply	other threads:[~2012-03-09  6:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-09  6:53 [PATCH obexd v2 1/3] MAP/dummy: Actual code for folder listing retrieval Slawomir Bochenski
2012-03-09  6:53 ` [PATCH obexd v2 2/3] MAP/dummy: Code for returning folder listing Slawomir Bochenski
2012-03-09  6:53 ` Slawomir Bochenski [this message]

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=1331276005-4434-3-git-send-email-lkslawek@gmail.com \
    --to=lkslawek@gmail.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).