All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Szatkowski <bulislaw@linux.com>
To: linux-bluetooth@vger.kernel.org
Cc: Bartosz Szatkowski <bulislaw@linux.com>
Subject: [PATCH obexd 3/4] Add response handling for MAP client
Date: Tue, 22 Nov 2011 15:46:37 +0100	[thread overview]
Message-ID: <1321973198-23091-3-git-send-email-bulislaw@linux.com> (raw)
In-Reply-To: <1321973198-23091-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 54ab9c0..4f3eb89 100644
--- a/client/map.c
+++ b/client/map.c
@@ -50,13 +50,41 @@ 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,
@@ -64,6 +92,11 @@ static void simple_cb(GObex *obex, GError *err, GObexPacket *rsp,
 						"%s", err->message);
 
 		g_error_free(err);
+	} 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-11-22 14:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-22 14:46 [PATCH obexd 1/4] Add basic support for MAP client in obex-client Bartosz Szatkowski
2011-11-22 14:46 ` [PATCH obexd 2/4] Add support for SetFolder in MAP client Bartosz Szatkowski
2011-11-22 14:46 ` Bartosz Szatkowski [this message]
2011-11-22 14:46 ` [PATCH obexd 4/4] Add simple helper for " Bartosz Szatkowski
2011-11-25 11:08 ` [PATCH obexd 1/4] Add basic support for MAP client in obex-client Johan Hedberg
2011-11-25 12:40   ` Bartosz Szatkowski
2011-11-25 15:58     ` Marcel Holtmann
2011-11-25 16:54       ` Bartosz Szatkowski
2011-12-02 11:23 ` 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=1321973198-23091-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 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.