linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Szatkowski <bulislaw@linux.com>
To: linux-bluetooth@vger.kernel.org
Cc: Bartosz Szatkowski <bulislaw@linux.com>
Subject: [PATCHv2 obexd 3/4] Add response handling for MAP client
Date: Fri,  2 Dec 2011 13:32:21 +0100	[thread overview]
Message-ID: <1322829142-7855-3-git-send-email-bulislaw@linux.com> (raw)
In-Reply-To: <1322829142-7855-1-git-send-email-bulislaw@linux.com>

---
 client/map.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/client/map.c b/client/map.c
index e5ebecb..8bc1583 100644
--- a/client/map.c
+++ b/client/map.c
@@ -50,17 +50,50 @@ struct map_data {
 	DBusMessage *msg;
 };
 
+static struct error_code {
+	const char *name;
+	guint8 code;
+} map_errors[] = {
+	{"Success", G_OBEX_RSP_SUCCESS},
+	{"Bad Request", G_OBEX_RSP_BAD_REQUEST},
+	{"Not Implemented", G_OBEX_RSP_NOT_IMPLEMENTED},
+	{"Service Unavailable", G_OBEX_RSP_SERVICE_UNAVAILABLE},
+	{"Forbidden", G_OBEX_RSP_FORBIDDEN},
+	{"Unauthorized", G_OBEX_RSP_UNAUTHORIZED},
+	{"Precondition Failed", G_OBEX_RSP_PRECONDITION_FAILED},
+	{"Not Acceptable", G_OBEX_RSP_NOT_ACCEPTABLE},
+	{"Not Found", G_OBEX_RSP_NOT_FOUND},
+	{ }
+};
+
 static DBusConnection *conn = NULL;
 
+static const char *get_error_string(guint8 err_code)
+{
+	struct error_code *error;
+
+	for (error = map_errors; error != NULL; error++)
+		if (error->code == err_code)
+			return error->name;
+
+	return NULL;
+}
+
 static void simple_cb(GObex *obex, GError *err, GObexPacket *rsp,
 							gpointer user_data)
 {
 	DBusMessage *reply;
 	struct map_data *map = user_data;
+	guint8 err_code = g_obex_packet_get_operation(rsp, NULL);
 
 	if (err != NULL)
 		reply = g_dbus_create_error(map->msg, ERROR_FAILED_PATH,
 							"%s", err->message);
+	else if (err_code != G_OBEX_RSP_SUCCESS)
+		reply = g_dbus_create_error(map->msg,
+					"org.openobex.Error.Response",
+					"%s(0x%X)", get_error_string(err_code),
+					err_code);
 	else
 		reply = dbus_message_new_method_return(map->msg);
 
-- 
1.7.4.1


  parent reply	other threads:[~2011-12-02 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-02 12:32 [PATCHv2 obexd 1/4] Add basic support for MAP client in obex-client Bartosz Szatkowski
2011-12-02 12:32 ` [PATCHv2 obexd 2/4] Add support for SetFolder in MAP client Bartosz Szatkowski
2011-12-02 12:32 ` Bartosz Szatkowski [this message]
2011-12-02 14:37   ` [PATCHv2 obexd 3/4] Add response handling for " Johan Hedberg
2011-12-02 14:43     ` Bartosz Szatkowski
2011-12-02 12:32 ` [PATCHv2 obexd 4/4] Add simple helper " Bartosz Szatkowski
2011-12-02 14:38   ` Johan Hedberg

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=1322829142-7855-3-git-send-email-bulislaw@linux.com \
    --to=bulislaw@linux.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).