Diff between c5cab062fc6ef2ccdbaf39f8583242a6a398a282 and 36803c249d65fe2d93d0833176cc178b467a56cd

Changed Files

File Additions Deletions Status
tools/obex-client-tool.c +39 -42 modified
tools/obex-server-tool.c +22 -22 modified

Full Patch

diff --git a/tools/obex-client-tool.c b/tools/obex-client-tool.c
index 81a2be0..8488a20 100644
--- a/tools/obex-client-tool.c
+++ b/tools/obex-client-tool.c
@@ -344,69 +344,66 @@ static void conn_callback(GIOChannel *io, GError *err, gpointer user_data)
 	transport_connect(io, transport);
 }
 
-static GIOChannel *bluetooth_connect(GObexTransportType transport)
+static GIOChannel *l2cap_connect(GObexTransportType transport, GError **err)
 {
-	GIOChannel *io;
-	GError *err = NULL;
-	BtIOType type;
-	BtIOOption option;
-
-	if (option_dest == NULL || option_channel < 0)
-		return NULL;
-
-	if (option_channel > 31) {
-		type = option_packet ? BT_IO_L2CAP : BT_IO_L2ERTM;
-		option = BT_IO_OPT_PSM;
-	} else {
-		type = BT_IO_RFCOMM;
-		option = BT_IO_OPT_CHANNEL;
-	}
-
-	if (option_source) {
-		if (type == BT_IO_L2CAP) {
-			io = bt_io_connect(type, conn_callback,
+	if (option_source)
+		return bt_io_connect(conn_callback,
 					GUINT_TO_POINTER(transport),
-					NULL, &err,
+					NULL, err,
 					BT_IO_OPT_SOURCE, option_source,
 					BT_IO_OPT_DEST, option_dest,
-					option, option_channel,
+					BT_IO_OPT_PSM, option_channel,
 					BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
 					BT_IO_OPT_OMTU, option_omtu,
 					BT_IO_OPT_IMTU, option_imtu,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-		} else {
-			io = bt_io_connect(type, conn_callback,
+
+	return bt_io_connect(conn_callback,
 					GUINT_TO_POINTER(transport),
-					NULL, &err,
-					BT_IO_OPT_SOURCE, option_source,
+					NULL, err,
 					BT_IO_OPT_DEST, option_dest,
-					option, option_channel,
+					BT_IO_OPT_PSM, option_channel,
+					BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
+					BT_IO_OPT_OMTU, option_omtu,
+					BT_IO_OPT_IMTU, option_imtu,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-		}
-	} else {
-		if (type == BT_IO_L2CAP) {
-			io = bt_io_connect(type, conn_callback,
+}
+
+static GIOChannel *rfcomm_connect(GObexTransportType transport, GError **err)
+{
+	if (option_source)
+		return bt_io_connect(conn_callback,
 					GUINT_TO_POINTER(transport),
-					NULL, &err,
+					NULL, err,
+					BT_IO_OPT_SOURCE, option_source,
 					BT_IO_OPT_DEST, option_dest,
-					option, option_channel,
-					BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
-					BT_IO_OPT_OMTU, option_omtu,
-					BT_IO_OPT_IMTU, option_imtu,
+					BT_IO_OPT_CHANNEL, option_channel,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-		} else {
-			io = bt_io_connect(type, conn_callback,
+
+	return bt_io_connect(conn_callback,
 					GUINT_TO_POINTER(transport),
-					NULL, &err,
+					NULL, err,
 					BT_IO_OPT_DEST, option_dest,
-					option, option_channel,
+					BT_IO_OPT_CHANNEL, option_channel,
 					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
 					BT_IO_OPT_INVALID);
-		}
-	}
+}
+
+static GIOChannel *bluetooth_connect(GObexTransportType transport)
+{
+	GIOChannel *io;
+	GError *err = NULL;
+
+	if (option_dest == NULL || option_channel < 0)
+		return NULL;
+
+	if (option_channel > 31)
+		io = l2cap_connect(transport, &err);
+	else
+		io = rfcomm_connect(transport, &err);
 
 	if (io != NULL)
 		return io;
diff --git a/tools/obex-server-tool.c b/tools/obex-server-tool.c
index 3a660f4..e37c56f 100644
--- a/tools/obex-server-tool.c
+++ b/tools/obex-server-tool.c
@@ -308,40 +308,40 @@ static gboolean bluetooth_watch(GIOChannel *chan, GIOCondition cond, gpointer da
 	return FALSE;
 }
 
+static GIOChannel *l2cap_listen(GError **err)
+{
+	return bt_io_listen(bluetooth_accept, NULL, NULL,
+					NULL, err,
+					BT_IO_OPT_PSM, option_channel,
+					BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
+					BT_IO_OPT_OMTU, option_omtu,
+					BT_IO_OPT_IMTU, option_imtu,
+					BT_IO_OPT_INVALID);
+}
+
+static GIOChannel *rfcomm_listen(GError **err)
+{
+	return bt_io_listen(bluetooth_accept, NULL, NULL,
+					NULL, err,
+					BT_IO_OPT_CHANNEL, option_channel,
+					BT_IO_OPT_INVALID);
+}
+
 static guint bluetooth_listen(void)
 {
 	GIOChannel *io;
 	guint id;
 	GError *err = NULL;
-	BtIOType type;
-	BtIOOption option;
 
 	if (option_channel == -1) {
 		g_printerr("Bluetooth channel not set\n");
 		return 0;
 	}
 
-	if (option_packet || option_channel > 31) {
-		type = option_packet ? BT_IO_L2CAP : BT_IO_L2ERTM;
-		option = BT_IO_OPT_PSM;
-	} else {
-		type = BT_IO_RFCOMM;
-		option = BT_IO_OPT_CHANNEL;
-	}
-
-	if (type == BT_IO_L2CAP)
-		io = bt_io_listen(type, bluetooth_accept, NULL, NULL,
-					NULL, &err,
-					option, option_channel,
-					BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
-					BT_IO_OPT_OMTU, option_omtu,
-					BT_IO_OPT_IMTU, option_imtu,
-					BT_IO_OPT_INVALID);
+	if (option_packet || option_channel > 31)
+		io = l2cap_listen(&err);
 	else
-		io = bt_io_listen(type, bluetooth_accept, NULL, NULL,
-					NULL, &err,
-					option, option_channel,
-					BT_IO_OPT_INVALID);
+		io = rfcomm_listen(&err);
 
 	if (io == NULL) {
 		g_printerr("%s\n", err->message);