Diff between 680e9abc4b78c755f8c0347f9ff26921c1c42da1 and 57478308afc225278aef2a18e9123fcf44bd01ca

Changed Files

File Additions Deletions Status
gobex/gobex.c +23 -2 modified
gobex/gobex.h +2 -1 modified
unit/test-gobex.c +2 -2 modified

Full Patch

diff --git a/gobex/gobex.c b/gobex/gobex.c
index f5e8179..555d720 100644
--- a/gobex/gobex.c
+++ b/gobex/gobex.c
@@ -50,6 +50,9 @@ struct _GObex {
 
 	guint write_source;
 
+	gssize io_rx_mtu;
+	gssize io_tx_mtu;
+
 	guint16 rx_mtu;
 	guint16 tx_mtu;
 
@@ -428,6 +431,8 @@ static void parse_connect_data(GObex *obex, GObexPacket *pkt)
 	memcpy(&u16, &data->mtu, sizeof(u16));
 
 	obex->tx_mtu = g_ntohs(u16);
+	if (obex->io_tx_mtu > 0 && obex->tx_mtu > obex->io_tx_mtu)
+		obex->tx_mtu = obex->io_tx_mtu;
 	obex->tx_buf = g_realloc(obex->tx_buf, obex->tx_mtu);
 }
 
@@ -632,7 +637,8 @@ failed:
 	return FALSE;
 }
 
-GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type)
+GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
+					gssize io_rx_mtu, gssize io_tx_mtu)
 {
 	GObex *obex;
 	GIOCondition cond;
@@ -640,12 +646,27 @@ GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type)
 	if (io == NULL)
 		return NULL;
 
+	if (io_rx_mtu >= 0 && io_rx_mtu < G_OBEX_MINIMUM_MTU)
+		return NULL;
+
+	if (io_tx_mtu >= 0 && io_tx_mtu < G_OBEX_MINIMUM_MTU)
+		return NULL;
+
 	obex = g_new0(GObex, 1);
 
 	obex->io = io;
 	obex->ref_count = 1;
-	obex->rx_mtu = G_OBEX_DEFAULT_MTU;
+
+	obex->io_rx_mtu = io_rx_mtu;
+	obex->io_tx_mtu = io_tx_mtu;
+
+	if (io_rx_mtu > G_OBEX_MAXIMUM_MTU)
+		obex->rx_mtu = G_OBEX_MAXIMUM_MTU;
+	else
+		obex->rx_mtu = io_rx_mtu;
+
 	obex->tx_mtu = G_OBEX_MINIMUM_MTU;
+
 	obex->tx_queue = g_queue_new();
 	obex->rx_buf = g_malloc(obex->rx_mtu);
 	obex->tx_buf = g_malloc(obex->tx_mtu);
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 19a0fb7..2111588 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -53,7 +53,8 @@ void g_obex_set_request_function(GObex *obex, GObexRequestFunc func,
 void g_obex_set_disconnect_function(GObex *obex, GObexDisconnectFunc func,
 							gpointer user_data);
 
-GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type);
+GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
+						gssize rx_mtu, gssize tx_mtu);
 
 GObex *g_obex_ref(GObex *obex);
 void g_obex_unref(GObex *obex);
diff --git a/unit/test-gobex.c b/unit/test-gobex.c
index 1492ab9..6aae16f 100644
--- a/unit/test-gobex.c
+++ b/unit/test-gobex.c
@@ -71,7 +71,7 @@ static GObex *create_gobex(int fd, GObexTransportType transport_type,
 
 	g_io_channel_set_close_on_unref(io, close_on_unref);
 
-	return g_obex_new(io, transport_type);
+	return g_obex_new(io, transport_type, -1, -1);
 }
 
 static void create_endpoints(GObex **obex, GIOChannel **io, int sock_type)
@@ -771,7 +771,7 @@ static void test_null_io(void)
 {
 	GObex *obex;
 
-	obex = g_obex_new(NULL, 0);
+	obex = g_obex_new(NULL, 0, -1, -1);
 
 	g_assert(obex == NULL);
 }