Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH obexd 6/7 v3] client: Move common code to pull_phonebook
Date: Thu,  6 Sep 2012 12:26:01 +0300	[thread overview]
Message-ID: <1346923562-2654-6-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1346923562-2654-1-git-send-email-luiz.dentz@gmail.com>

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

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

diff --git a/client/pbap.c b/client/pbap.c
index a90d515..16778f8 100644
--- a/client/pbap.c
+++ b/client/pbap.c
@@ -523,22 +523,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:
@@ -554,19 +561,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 gchar **get_filter_strs(uint64_t filter, gint *size)
-- 
1.7.11.4


  parent reply	other threads:[~2012-09-06  9:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-06  9:25 [PATCH obexd 1/7 v3] client: Add filters to Phonebook.PullAll Luiz Augusto von Dentz
2012-09-06  9:25 ` [PATCH obexd 2/7 v2] client: Add filters to PhonebookAccess.Pull Luiz Augusto von Dentz
2012-09-06  9:25 ` [PATCH obexd 3/7 v3] client: Add filters to PhonebookAccess.List and PhonebookAccess.Search Luiz Augusto von Dentz
2012-09-06  9:25 ` [PATCH obexd 4/7 v3] client: Remove deprecated methods from PhonebookAccess Luiz Augusto von Dentz
2012-09-06  9:26 ` [PATCH obexd 5/7 v3] test: Update pbap-client to work with changes in PhonebookAcess Luiz Augusto von Dentz
2012-09-06  9:26 ` Luiz Augusto von Dentz [this message]
2012-09-06  9:26 ` [PATCH obexd 7/7 v3] client-doc: Update documentation of PhonebookAccess interface Luiz Augusto von Dentz

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=1346923562-2654-6-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@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