Linux bluetooth development
 help / color / mirror / Atom feed
From: Slawomir Bochenski <lkslawek@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Slawomir Bochenski <lkslawek@gmail.com>
Subject: [PATCH v2 4/4] Add detection of MAP function in OBEX requests
Date: Fri, 11 Mar 2011 08:46:52 +0100	[thread overview]
Message-ID: <1299829612-3704-4-git-send-email-lkslawek@gmail.com> (raw)
In-Reply-To: <1299829612-3704-1-git-send-email-lkslawek@gmail.com>

There is also first part of mas.c <-> backend API. The mas_request
structure will be used when calling backend functions.
---
 plugins/mas.c      |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/messages.h |   15 +++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index a84b8fd..106544d 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -25,6 +25,7 @@
 #include <config.h>
 #endif
 
+#include <string.h>
 #include <errno.h>
 #include <glib.h>
 #include <openobex/obex.h>
@@ -38,6 +39,14 @@
 
 #include "messages.h"
 
+#define EVENT_TYPE		"x-bt/MAP-event-report"
+#define MESSAGE_TYPE		"x-bt/message"
+#define FOLDER_LISTING_TYPE	"x-obex/folder-listing"
+#define MESSAGES_LISTING_TYPE	"x-bt/MAP-msg-listing"
+#define NOTIFICATION_TYPE	"x-bt/MAP-NotificationRegistration"
+#define STATUS_TYPE		"x-bt/messageStatus"
+#define UPDATE_TYPE		"x-bt/MAP-messageUpdate"
+
 /* Channel number according to bluez doc/assigned-numbers.txt */
 #define MAS_CHANNEL	16
 
@@ -99,6 +108,14 @@ static void mas_clean(struct mas_session *mas)
 	g_free(mas);
 }
 
+static void reset_request(struct mas_session *mas)
+{
+	if (mas->request) {
+		g_free(mas->request);
+		mas->request = NULL;
+	}
+}
+
 static void *mas_connect(struct obex_session *os, int *err)
 {
 	struct mas_session *mas;
@@ -139,6 +156,21 @@ static int mas_get(struct obex_session *os, obex_object_t *obj,
 	if (type == NULL)
 		return -EBADR;
 
+	mas->request = g_new0(struct mas_request, 1);
+
+	/* NOTE: type is case-insensitive! */
+	if (g_ascii_strcasecmp(type, FOLDER_LISTING_TYPE) == 0)
+		mas->request->fid = MFID_GET_FOLDER_LISTING;
+	else if (g_ascii_strcasecmp(type, MESSAGES_LISTING_TYPE) == 0)
+		mas->request->fid = MFID_GET_MESSAGES_LISTING;
+	else if (g_ascii_strcasecmp(type, MESSAGE_TYPE) == 0)
+		mas->request->fid = MFID_GET_MESSAGE;
+	else {
+		DBG("Incorrect type: %s", type);
+		ret = -EBADR;
+		goto failed;
+	}
+
 	*stream = FALSE;
 
 	ret = obex_get_stream_start(os, name);
@@ -148,6 +180,8 @@ static int mas_get(struct obex_session *os, obex_object_t *obj,
 	return 0;
 
 failed:
+	reset_request(mas);
+
 	return ret;
 }
 
@@ -163,6 +197,23 @@ static int mas_put(struct obex_session *os, obex_object_t *obj, void *user_data)
 	if (type == NULL)
 		return -EBADR;
 
+	mas->request = g_new0(struct mas_request, 1);
+
+	/* NOTE: type is case-insensitive! */
+	if (g_ascii_strcasecmp(type, NOTIFICATION_TYPE) == 0)
+		mas->request->fid = MFID_SET_NOTIFICATION_REGISTRATION;
+	else if (g_ascii_strcasecmp(type, STATUS_TYPE) == 0)
+		mas->request->fid = MFID_SET_MESSAGE_STATUS;
+	else if (g_ascii_strcasecmp(type, MESSAGE_TYPE) == 0)
+		mas->request->fid = MFID_PUSH_MESSAGE;
+	else if (g_ascii_strcasecmp(type, UPDATE_TYPE) == 0)
+		mas->request->fid = MFID_UPDATE_INBOX;
+	else {
+		DBG("Incorrect type: %s", type);
+		ret = -EBADR;
+		goto failed;
+	}
+
 	ret = obex_put_stream_start(os, name);
 	if (ret < 0)
 		goto failed;
@@ -170,6 +221,8 @@ static int mas_put(struct obex_session *os, obex_object_t *obj, void *user_data)
 	return 0;
 
 failed:
+	reset_request(mas);
+
 	return ret;
 }
 
@@ -228,8 +281,12 @@ static ssize_t any_read(void *obj, void *buf, size_t count,
 
 static int any_close(void *obj)
 {
+	struct mas_session *mas = obj;
+
 	DBG("");
 
+	reset_request(mas);
+
 	return 0;
 }
 
diff --git a/plugins/messages.h b/plugins/messages.h
index c510244..91e7b3b 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -20,3 +20,18 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+
+enum messages_function_id {
+	MFID_INVALID = 0,
+	MFID_SET_NOTIFICATION_REGISTRATION,
+	MFID_GET_FOLDER_LISTING,
+	MFID_GET_MESSAGES_LISTING,
+	MFID_GET_MESSAGE,
+	MFID_SET_MESSAGE_STATUS,
+	MFID_PUSH_MESSAGE,
+	MFID_UPDATE_INBOX,
+};
+
+struct mas_request {
+	enum messages_function_id fid;
+};
-- 
1.7.1


  parent reply	other threads:[~2011-03-11  7:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-11  7:46 [PATCH v2 0/4] Message Access Profile plugin Slawomir Bochenski
2011-03-11  7:46 ` [PATCH v2 2/4] Add actual service for Message Access Profile Slawomir Bochenski
2011-03-11  7:46 ` [PATCH v2 3/4] Add MIME driver to MAP plugin Slawomir Bochenski
2011-03-11  7:46 ` Slawomir Bochenski [this message]
2011-03-11 11:13   ` [PATCH v2 4/4] Add detection of MAP function in OBEX requests Johan Hedberg
2011-03-11 11:40     ` Slawomir Bochenski
2011-03-11 14:48       ` Johan Hedberg
2011-03-11 21:27         ` Johan Hedberg
2011-03-14 14:27           ` Slawomir Bochenski

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=1299829612-3704-4-git-send-email-lkslawek@gmail.com \
    --to=lkslawek@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