Diff between 9b883a0264dc7f1219a812afc18f05a2c9a4874c and fcd02ad59b6acc63743298ba6e27f14c50c2a690

Changed Files

File Additions Deletions Status
obexd/client/ftp.c +3 -5 modified
obexd/client/manager.c +3 -4 modified
obexd/client/map.c +2 -4 modified
obexd/client/pbap.c +22 -19 modified
obexd/client/sync.c +3 -3 modified
obexd/client/transfer.c +25 -24 modified
obexd/client/transfer.h +6 -9 modified

Full Patch

diff --git a/obexd/client/ftp.c b/obexd/client/ftp.c
index 6fa4e85..bb180ba 100644
--- a/obexd/client/ftp.c
+++ b/obexd/client/ftp.c
@@ -262,8 +262,7 @@ static DBusMessage *list_folder(DBusConnection *connection,
 	GError *err = NULL;
 	DBusMessage *reply;
 
-	transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL,
-				NULL, 0,  &err);
+	transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL, &err);
 	if (transfer == NULL)
 		goto fail;
 
@@ -297,8 +296,7 @@ static DBusMessage *get_file(DBusConnection *connection,
 		return g_dbus_create_error(message,
 				"org.openobex.Error.InvalidArguments", NULL);
 
-	transfer = obc_transfer_get(NULL, source_file, target_file, NULL, 0,
-									&err);
+	transfer = obc_transfer_get(NULL, source_file, target_file, &err);
 	if (transfer == NULL)
 		goto fail;
 
@@ -334,7 +332,7 @@ static DBusMessage *put_file(DBusConnection *connection,
 				"Invalid arguments in method call");
 
 	transfer = obc_transfer_put(NULL, targetfile, sourcefile, NULL, 0,
-								NULL, 0, &err);
+									&err);
 	if (transfer == NULL)
 		goto fail;
 
diff --git a/obexd/client/manager.c b/obexd/client/manager.c
index 1f70f60..4099e6f 100644
--- a/obexd/client/manager.c
+++ b/obexd/client/manager.c
@@ -116,7 +116,7 @@ static void create_callback(struct obc_session *session,
 		struct obc_transfer *transfer;
 
 		transfer = obc_transfer_put(NULL, basename, filename, NULL, 0,
-								NULL, 0, NULL);
+									NULL);
 
 		g_free(basename);
 		if (transfer == NULL)
@@ -293,8 +293,7 @@ static void pull_obc_session_callback(struct obc_session *session,
 		goto fail;
 	}
 
-	pull = obc_transfer_get("text/x-vcard", NULL, data->filename, NULL, 0,
-									&gerr);
+	pull = obc_transfer_get("text/x-vcard", NULL, data->filename, &gerr);
 
 	if (!obc_session_queue(session, pull, pull_complete_callback, data,
 								&gerr)) {
@@ -516,7 +515,7 @@ static void capability_obc_session_callback(struct obc_session *session,
 	}
 
 	pull = obc_transfer_get("x-obex/capability", NULL, data->filename,
-								NULL, 0, &gerr);
+									&gerr);
 
 	if (!obc_session_queue(session, pull, capabilities_complete_callback,
 								data, &gerr)) {
diff --git a/obexd/client/map.c b/obexd/client/map.c
index 3e6f237..fe6b460 100644
--- a/obexd/client/map.c
+++ b/obexd/client/map.c
@@ -139,8 +139,7 @@ static DBusMessage *map_get_folder_listing(DBusConnection *connection,
 	GError *err = NULL;
 	DBusMessage *reply;
 
-	transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL,
-								NULL, 0, &err);
+	transfer = obc_transfer_get("x-obex/folder-listing", NULL, NULL, &err);
 	if (transfer == NULL)
 		goto fail;
 
@@ -174,8 +173,7 @@ static DBusMessage *map_get_message_listing(DBusConnection *connection,
 
 	dbus_message_iter_get_basic(&msg_iter, &folder);
 
-	transfer = obc_transfer_get("x-bt/MAP-msg-listing", folder, NULL,
-								NULL, 0, &err);
+	transfer = obc_transfer_get("x-bt/MAP-msg-listing", folder, NULL, &err);
 	if (transfer == NULL)
 		goto fail;
 
diff --git a/obexd/client/pbap.c b/obexd/client/pbap.c
index 92292c9..7970c8e 100644
--- a/obexd/client/pbap.c
+++ b/obexd/client/pbap.c
@@ -467,6 +467,10 @@ static DBusMessage *pull_phonebook(struct pbap_data *pbap,
 	GError *err = NULL;
 	DBusMessage *reply;
 
+	transfer = obc_transfer_get("x-bt/phonebook", name, NULL, &err);
+	if (transfer == NULL)
+		goto fail;
+
 	apparam.filter_tag = FILTER_TAG;
 	apparam.filter_len = FILTER_LEN;
 	apparam.filter = GUINT64_TO_BE(filter);
@@ -494,19 +498,17 @@ static DBusMessage *pull_phonebook(struct pbap_data *pbap,
 
 	request = pending_request_new(pbap, message);
 
-	transfer = obc_transfer_get("x-bt/phonebook", name, NULL, &apparam,
-							sizeof(apparam), &err);
-	if (transfer == NULL)
-		goto fail;
+	obc_transfer_set_params(transfer, &apparam, sizeof(apparam));
 
 	if (obc_session_queue(pbap->session, transfer, func, request, &err))
 		return NULL;
 
+	pending_request_free(request);
+
 fail:
 	reply = g_dbus_create_error(message, "org.openobex.Error.Failed", "%s",
 								err->message);
 	g_error_free(err);
-	pending_request_free(request);
 	return reply;
 }
 
@@ -534,6 +536,10 @@ static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
 	GError *err = NULL;
 	DBusMessage *reply;
 
+	transfer = obc_transfer_get("x-bt/vcard-listing", name, NULL, &err);
+	if (transfer == NULL)
+		goto fail;
+
 	/* trunc the searchval string if it's length exceed the max value of guint8 */
 	if (strlen(searchval) > 254)
 		searchval[255] = '\0';
@@ -543,10 +549,7 @@ static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
 			(APPARAM_HDR_SIZE + SEARCHATTRIB_LEN) +
 			(APPARAM_HDR_SIZE + MAXLISTCOUNT_LEN) +
 			(APPARAM_HDR_SIZE + LISTSTARTOFFSET_LEN);
-	apparam = g_try_malloc0(apparam_size);
-	if (!apparam)
-		return g_dbus_create_error(message,
-				ERROR_INF ".Failed", "No Memory");
+	apparam = g_malloc0(apparam_size);
 
 	p = apparam;
 
@@ -562,21 +565,19 @@ static DBusMessage *pull_vcard_listing(struct pbap_data *pbap,
 
 	request = pending_request_new(pbap, message);
 
-	transfer = obc_transfer_get("x-bt/vcard-listing", name, NULL,
-						apparam, apparam_size, &err);
+	obc_transfer_set_params(transfer, apparam, apparam_size);
 	g_free(apparam);
-	if (transfer == NULL)
-		goto fail;
 
 	if (obc_session_queue(pbap->session, transfer,
 				pull_vcard_listing_callback, request, &err))
 		return NULL;
 
+	pending_request_free(request);
+
 fail:
 	reply = g_dbus_create_error(message, "org.openobex.Error.Failed", "%s",
 								err->message);
 	g_error_free(err);
-	pending_request_free(request);
 	return reply;
 }
 
@@ -781,6 +782,10 @@ static DBusMessage *pbap_pull_vcard(DBusConnection *connection,
 		return g_dbus_create_error(message,
 				ERROR_INF ".InvalidArguments", NULL);
 
+	transfer = obc_transfer_get("x-bt/vcard", name, NULL, &err);
+	if (transfer == NULL)
+		goto fail;
+
 	apparam.filter_tag = FILTER_TAG;
 	apparam.filter_len = FILTER_LEN;
 	apparam.filter = GUINT64_TO_BE(pbap->filter);
@@ -790,20 +795,18 @@ static DBusMessage *pbap_pull_vcard(DBusConnection *connection,
 
 	request = pending_request_new(pbap, message);
 
-	transfer = obc_transfer_get("x-bt/vcard", name, NULL,
-					&apparam, sizeof(apparam), &err);
-	if (transfer == NULL)
-		goto fail;
+	obc_transfer_set_params(transfer, &apparam, sizeof(apparam));
 
 	if (obc_session_queue(pbap->session, transfer, pull_phonebook_callback,
 								request, &err))
 		return NULL;
 
+	pending_request_free(request);
+
 fail:
 	reply = g_dbus_create_error(message, "org.openobex.Error.Failed", "%s",
 								err->message);
 	g_error_free(err);
-	pending_request_free(request);
 	return reply;
 }
 
diff --git a/obexd/client/sync.c b/obexd/client/sync.c
index 3c376cc..843e17a 100644
--- a/obexd/client/sync.c
+++ b/obexd/client/sync.c
@@ -139,8 +139,8 @@ static DBusMessage *sync_getphonebook(DBusConnection *connection,
 	if (!sync->phonebook_path)
 		sync->phonebook_path = g_strdup("telecom/pb.vcf");
 
-	transfer = obc_transfer_get("phonebook", sync->phonebook_path,
-							NULL, NULL, 0, &err);
+	transfer = obc_transfer_get("phonebook", sync->phonebook_path, NULL,
+									&err);
 	if (transfer == NULL)
 		goto fail;
 
@@ -178,7 +178,7 @@ static DBusMessage *sync_putphonebook(DBusConnection *connection,
 		sync->phonebook_path = g_strdup("telecom/pb.vcf");
 
 	transfer = obc_transfer_put(NULL, sync->phonebook_path, NULL, buf,
-						strlen(buf), NULL, 0, &err);
+							strlen(buf), &err);
 	if (transfer == NULL)
 		goto fail;
 
diff --git a/obexd/client/transfer.c b/obexd/client/transfer.c
index 37963c8..541fd2d 100644
--- a/obexd/client/transfer.c
+++ b/obexd/client/transfer.c
@@ -251,9 +251,7 @@ static void obc_transfer_free(struct obc_transfer *transfer)
 static struct obc_transfer *obc_transfer_create(guint8 op,
 						const char *filename,
 						const char *name,
-						const char *type,
-						const void *params,
-						size_t psize)
+						const char *type)
 {
 	struct obc_transfer *transfer;
 
@@ -263,12 +261,6 @@ static struct obc_transfer *obc_transfer_create(guint8 op,
 	transfer->name = g_strdup(name);
 	transfer->type = g_strdup(type);
 
-	if (params != NULL) {
-		transfer->params = g_new0(struct obc_transfer_params, 1);
-		transfer->params->data = g_memdup(params, psize);
-		transfer->params->size = psize;
-	}
-
 	return transfer;
 }
 
@@ -339,17 +331,13 @@ done:
 	return TRUE;
 }
 
-struct obc_transfer *obc_transfer_get(const char *type,
-					const char *name,
-					const char *filename,
-					const void *params, size_t psize,
-					GError **err)
+struct obc_transfer *obc_transfer_get(const char *type, const char *name,
+					const char *filename, GError **err)
 {
 	struct obc_transfer *transfer;
 	int perr;
 
-	transfer = obc_transfer_create(G_OBEX_OP_GET, filename, name, type,
-								params, psize);
+	transfer = obc_transfer_create(G_OBEX_OP_GET, filename, name, type);
 
 	perr = transfer_open(transfer, O_WRONLY | O_CREAT | O_TRUNC, 0600, err);
 	if (perr < 0) {
@@ -360,19 +348,16 @@ struct obc_transfer *obc_transfer_get(const char *type,
 	return transfer;
 }
 
-struct obc_transfer *obc_transfer_put(const char *type,
-					const char *name,
+struct obc_transfer *obc_transfer_put(const char *type, const char *name,
 					const char *filename,
-					const void *contents, size_t csize,
-					const void *params, size_t psize,
+					const void *contents, size_t size,
 					GError **err)
 {
 	struct obc_transfer *transfer;
 	struct stat st;
 	int perr;
 
-	transfer = obc_transfer_create(G_OBEX_OP_PUT, filename, name, type,
-								params, psize);
+	transfer = obc_transfer_create(G_OBEX_OP_PUT, filename, name, type);
 
 	if (contents != NULL) {
 		ssize_t w;
@@ -380,12 +365,12 @@ struct obc_transfer *obc_transfer_put(const char *type,
 		if (!transfer_open(transfer, O_RDWR, 0, err))
 			goto fail;
 
-		w = write(transfer->fd, contents, csize);
+		w = write(transfer->fd, contents, size);
 		if (w < 0) {
 			error("write(): %s(%d)", strerror(errno), errno);
 			perr = -errno;
 			goto fail;
-		} else if ((size_t) w != csize) {
+		} else if ((size_t) w != size) {
 			error("Unable to write all contents to file");
 			perr = -EFAULT;
 			goto fail;
@@ -654,6 +639,22 @@ guint8 obc_transfer_get_operation(struct obc_transfer *transfer)
 	return transfer->op;
 }
 
+void obc_transfer_set_params(struct obc_transfer *transfer,
+						const void *data, size_t size)
+{
+	if (transfer->params != NULL) {
+		g_free(transfer->params->data);
+		g_free(transfer->params);
+	}
+
+	if (data == NULL)
+		return;
+
+	transfer->params = g_new0(struct obc_transfer_params, 1);
+	transfer->params->data = g_memdup(data, size);
+	transfer->params->size = size;
+}
+
 const void *obc_transfer_get_params(struct obc_transfer *transfer, size_t *size)
 {
 	if (transfer->params == NULL)
diff --git a/obexd/client/transfer.h b/obexd/client/transfer.h
index 94bb800..bf40a4c 100644
--- a/obexd/client/transfer.h
+++ b/obexd/client/transfer.h
@@ -27,16 +27,11 @@ typedef void (*transfer_callback_t) (struct obc_transfer *transfer,
 					gint64 transferred, GError *err,
 					void *user_data);
 
-struct obc_transfer *obc_transfer_get(const char *type,
-					const char *name,
+struct obc_transfer *obc_transfer_get(const char *type, const char *name,
+					const char *filename, GError **err);
+struct obc_transfer *obc_transfer_put(const char *type, const char *name,
 					const char *filename,
-					const void *params, size_t psize,
-					GError **err);
-struct obc_transfer *obc_transfer_put(const char *type,
-					const char *name,
-					const char *filename,
-					const void *contents, size_t csize,
-					const void *params, size_t psize,
+					const void *contents, size_t size,
 					GError **err);
 
 gboolean obc_transfer_register(struct obc_transfer *transfer,
@@ -54,6 +49,8 @@ gboolean obc_transfer_start(struct obc_transfer *transfer, void *obex,
 								GError **err);
 guint8 obc_transfer_get_operation(struct obc_transfer *transfer);
 
+void obc_transfer_set_params(struct obc_transfer *transfer,
+						const void *data, size_t size);
 const void *obc_transfer_get_params(struct obc_transfer *transfer,
 								size_t *size);
 int obc_transfer_get_contents(struct obc_transfer *transfer, char **contents,