[PATCH obexd 3/4] Add response handling for MAP client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux