[PATCH obexd 6/7] client: Move common code to pull_phonebook

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

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

---
 client/pbap.c | 79 +++++++++++++++++++++++------------------------------------
 1 file changed, 30 insertions(+), 49 deletions(-)

diff --git a/client/pbap.c b/client/pbap.c
index 3e9301a..b460987 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -522,22 +522,29 @@ static GObexApparam *parse_filters(GObexApparam *apparam,
 	return apparam;
 }
 
-static struct obc_transfer *pull_phonebook(struct pbap_data *pbap,
+static DBusMessage *pull_phonebook(struct pbap_data *pbap,
 						DBusMessage *message,
-						guint8 type, const char *name,
+						guint8 type,
 						const char *targetfile,
-						GObexApparam *apparam,
-						GError **err)
+						GObexApparam *apparam)
 {
 	struct pending_request *request;
 	struct obc_transfer *transfer;
+	char *name;
 	guint8 buf[32];
 	gsize len;
 	session_callback_t func;
+	DBusMessage *reply;
+	GError *err = NULL;
+
+	name = g_strconcat(pbap->path, ".vcf", NULL);
+
+	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
+	g_obex_apparam_free(apparam);
 
-	transfer = obc_transfer_get("x-bt/phonebook", name, targetfile, err);
+	transfer = obc_transfer_get("x-bt/phonebook", name, targetfile, &err);
 	if (transfer == NULL)
-		return NULL;
+		goto fail;
 
 	switch (type) {
 	case PULLPHONEBOOK:
@@ -553,19 +560,28 @@ static struct obc_transfer *pull_phonebook(struct pbap_data *pbap,
 		return NULL;
 	}
 
-	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
-
 	obc_transfer_set_params(transfer, buf, len);
 
-	if (!obc_session_queue(pbap->session, transfer, func, request, err)) {
+	if (!obc_session_queue(pbap->session, transfer, func, request, &err)) {
 		if (request != NULL)
 			pending_request_free(request);
 
-		return NULL;
+		goto fail;
 	}
 
+	g_free(name);
+
+	if (targetfile == NULL)
+		return NULL;
 
-	return transfer;
+	return obc_transfer_create_dbus_reply(transfer, message);
+
+fail:
+	g_free(name);
+	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+								err->message);
+	g_error_free(err);
+	return reply;
 }
 
 static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
@@ -654,11 +670,8 @@ static DBusMessage *pbap_pull_all(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	struct pbap_data *pbap = user_data;
-	struct obc_transfer *transfer;
 	const char *targetfile;
-	char *name;
 	GObexApparam *apparam;
-	GError *err = NULL;
 	DBusMessageIter args;
 
 	if (!pbap->path)
@@ -686,22 +699,8 @@ static DBusMessage *pbap_pull_all(DBusConnection *connection,
 				ERROR_INTERFACE ".InvalidArguments", NULL);
 	}
 
-	name = g_strconcat(pbap->path, ".vcf", NULL);
-
-	transfer = pull_phonebook(pbap, message, PULLPHONEBOOK, name,
-						targetfile, apparam, &err);
-	g_free(name);
-	g_obex_apparam_free(apparam);
-
-	if (transfer == NULL) {
-		DBusMessage *reply = g_dbus_create_error(message,
-					ERROR_INTERFACE ".Failed", "%s",
-					err->message);
-		g_error_free(err);
-		return reply;
-	}
-
-	return obc_transfer_create_dbus_reply(transfer, message);
+	return pull_phonebook(pbap, message, PULLPHONEBOOK, targetfile,
+								apparam);
 }
 
 static DBusMessage *pull_vcard(struct pbap_data *pbap, DBusMessage *message,
@@ -877,11 +876,7 @@ static DBusMessage *pbap_get_size(DBusConnection *connection,
 					DBusMessage *message, void *user_data)
 {
 	struct pbap_data *pbap = user_data;
-	DBusMessage *reply;
-	struct obc_transfer *transfer;
-	char *name;
 	GObexApparam *apparam;
-	GError *err = NULL;
 	DBusMessageIter args;
 
 	if (!pbap->path)
@@ -891,25 +886,11 @@ static DBusMessage *pbap_get_size(DBusConnection *connection,
 
 	dbus_message_iter_init(message, &args);
 
-	name = g_strconcat(pbap->path, ".vcf", NULL);
-
 	apparam = g_obex_apparam_set_uint16(NULL, MAXLISTCOUNT_TAG, 0);
 	apparam = g_obex_apparam_set_uint16(apparam, LISTSTARTOFFSET_TAG,
 							DEFAULT_OFFSET);
 
-	transfer = pull_phonebook(pbap, message, GETPHONEBOOKSIZE, name, NULL,
-								apparam, &err);
-
-	g_free(name);
-	g_obex_apparam_free(apparam);
-
-	if (transfer != NULL)
-		return NULL;
-
-	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
-								err->message);
-	g_error_free(err);
-	return reply;
+	return pull_phonebook(pbap, message, GETPHONEBOOKSIZE, NULL, apparam);
 }
 
 static const GDBusMethodTable pbap_methods[] = {
-- 
1.7.11.4

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