<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From a57817c7e52ede1589ffbd7e2abb444734e2df92 Mon Sep 17 00:00:00 2001
From: Tomas Hozza &lt;thozza@redhat.com&gt;
Date: Mon, 9 Sep 2013 18:12:00 +0200
Subject: [PATCH 1/2] Add sample application obex_push

obex_push is a sample application capable of pushing
and receiving files over the Bluetooth OBEX Push Channel.

Signed-off-by: Tomas Hozza &lt;thozza@redhat.com&gt;
---
 apps/CMakeLists.txt      |   9 +++
 apps/obex_push.c         | 177 +++++++++++++++++++++++++++++++++++++++++++++++
 doc/obex_push.xml        |  78 +++++++++++++++++++++
 doc/openobex-apps.xml    |   1 +
 doc/referenceinfo.xml.in |   6 ++
 5 files changed, 271 insertions(+)
 create mode 100644 apps/obex_push.c
 create mode 100644 doc/obex_push.xml

diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 55268ca..6aefb23 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -4,6 +4,10 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/lib )
 add_subdirectory ( obex_test )
 add_subdirectory ( ircp )
 
+set ( OPENOBEX_BLUETOOTH_APPS
+  obex_push
+)
+
 set ( OPENOBEX_COMMON_APPS
   irxfer
   irobex_palm3
@@ -18,6 +22,11 @@ if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" )
   list ( APPEND OPENOBEX_COMMON_APPS obex_tcp )
 endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" )
 
+foreach ( prog ${OPENOBEX_BLUETOOTH_APPS} )
+  list ( APPEND ${prog}_LIBS bluetooth )
+  list ( APPEND OPENOBEX_COMMON_APPS ${prog} )
+endforeach ( prog )
+
 foreach ( prog ${OPENOBEX_COMMON_APPS} )
   list ( APPEND ${prog}_LIBS openobex-apps-common )
   list ( APPEND OPENOBEX_APPS ${prog} )
diff --git a/apps/obex_push.c b/apps/obex_push.c
new file mode 100644
index 0000000..c5b7d2e
--- /dev/null
+++ b/apps/obex_push.c
@@ -0,0 +1,177 @@
+/*********************************************************************
+ *                
+ * Filename:      obex_push.c
+ * Version:       0.1
+ * Description:   Demonstrates use of PUSH command
+ * Status:        Experimental.
+ * Author:        Harald Hoyer &lt;harald@redhat.com
+ *
+ *     modified irobex_palm3.c
+ * 
+ *     Copyright (C) 2003-2007 Harald Hoyer, All Rights Reserved.
+ *     Copyright (C) 2003-2007 Red Hat, Inc.
+ *     
+ *     This program is free software; you can redistribute it and/or 
+ *     modify it under the terms of the GNU General Public License as 
+ *     published by the Free Software Foundation; either version 2 of 
+ *     the License, or (at your option) any later version.
+ * 
+ *     This program is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *     GNU General Public License for more details.
+ * 
+ *     You should have received a copy of the GNU General Public License 
+ *     along with this program; if not, write to the Free Software 
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
+ *     MA 02111-1307 USA
+ *
+ *
+ *     Start without arguments to receive a file.
+ *     Start with address and filename as argument to send a file. 
+ *     
+ ********************************************************************/
+
+#include &lt;stdio.h&gt;
+#include &lt;stdlib.h&gt;
+
+#ifndef _WIN32
+#include &lt;unistd.h&gt;
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include &lt;config.h&gt;
+#endif
+
+#if _WIN32
+#include &lt;winsock.h&gt;
+#else
+#include &lt;sys/socket.h&gt;
+#include &lt;arpa/inet.h&gt;
+#include &lt;netdb.h&gt;
+#include &lt;netinet/in.h&gt;
+#endif /* _WIN32 */
+
+#include &lt;libgen.h&gt;
+
+#include &lt;bluetooth/bluetooth.h&gt;
+#include &lt;bluetooth/rfcomm.h&gt;
+
+#include &lt;openobex/obex.h&gt;
+
+#include "obex_put_common.h"
+#include "ircp/ircp_io.h"
+
+#define OBEX_PUSH_HANDLE	10
+
+#define TRUE  1
+#define FALSE 0
+
+obex_t *handle = NULL;
+volatile int finished = FALSE;
+extern int last_rsp;
+
+/*
+ * Function main (argc, )
+ *
+ *    Starts all the fun!
+ *
+ */
+int main(int argc, char *argv[])
+{
+	obex_object_t *object;
+	int ret, exitval = EXIT_SUCCESS;
+	bdaddr_t bdaddr;
+	uint8_t channel;
+	char *filename;
+	if ((argc &lt; 1) || (argc &gt; 4))	{
+		printf ("Usage: %s [&lt;channel&gt;] [&lt;bdaddr&gt; &lt;filename&gt;]\n", argv[0]); 
+		return -1;
+	}
+	handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0);
+
+	switch (argc) {
+#ifdef HAVE_BLUETOOTH
+	case 4:
+		channel = atoi(argv[1]);
+		str2ba(argv[2], &amp;bdaddr);
+		filename = argv[3];
+		break;
+	case 3:
+		str2ba(argv[1], &amp;bdaddr);
+		filename = argv[2];
+		channel = OBEX_PUSH_HANDLE;
+		break;
+	case 2:
+		channel = atoi(argv[1]);
+		break;
+	case 1:
+		channel = OBEX_PUSH_HANDLE;
+		break;
+#endif
+	default:
+		printf("Wrong number of arguments\n");
+		exit(0);
+	}
+
+	printf("Send and receive files through bluetooth OBEX PUSH channel %d\n", channel);
+	if (argc &lt;= 2)	{
+		char cmd[1024];
+		int ret;
+		/* We are server*/
+		snprintf(cmd, sizeof(cmd), "sdptool add --channel=%d OPUSH", channel);
+		ret = system(cmd);
+		if (ret != 0) {
+			fprintf(stderr, "Command failed: %s\n", cmd);
+		}
+		
+		printf("Waiting for files\n");
+		BtOBEX_ServerRegister(handle, NULL, channel);
+		
+		while (!finished)
+			OBEX_HandleInput(handle, 1);
+	}
+	else {
+		char *basefilename = basename(strdup(filename));
+		/* We are a client */
+		if (bacmp(&amp;bdaddr, BDADDR_ANY) == 0) {
+			printf("Device address error! (Bluetooth)\n");
+			return -1;
+		}
+
+		/* Try to connect to peer */
+		ret = BtOBEX_TransportConnect(handle, BDADDR_ANY, &amp;bdaddr,
+					      channel);
+		if (ret &lt; 0) {
+			printf("Sorry, unable to connect!\n");
+			return EXIT_FAILURE;
+		}
+
+		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
+		ret = do_sync_request(handle, object, FALSE);
+		if ((last_rsp != OBEX_RSP_SUCCESS) || (ret &lt; 0)) {
+			printf("Sorry, unable to connect!\n");
+			return EXIT_FAILURE;
+		}
+		if ((object = build_object_from_file(handle, filename,
+					basefilename)))
+		{
+			ret = do_sync_request(handle, object, FALSE);
+			if ((last_rsp != OBEX_RSP_SUCCESS) || (ret &lt; 0))
+				exitval = EXIT_FAILURE;
+		} else
+			exitval = EXIT_FAILURE;
+
+		object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
+		ret = do_sync_request(handle, object, FALSE);
+		if ((last_rsp != OBEX_RSP_SUCCESS) || (ret &lt; 0))
+			exitval = EXIT_FAILURE;
+
+		if (exitval == EXIT_SUCCESS)
+			printf("PUT successful\n");
+		else
+			printf("PUT failed\n");
+	}
+//	sleep(1);
+	return exitval;
+}
diff --git a/doc/obex_push.xml b/doc/obex_push.xml
new file mode 100644
index 0000000..0d3b105
--- /dev/null
+++ b/doc/obex_push.xml
@@ -0,0 +1,78 @@
+&lt;?xml version="1.0" ?&gt;
+&lt;!DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"&gt;
+&lt;reference id="openobex-apps"&gt;
+  &lt;xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="referenceinfo.xml" /&gt;
+
+  &lt;title&gt;openobex&lt;/title&gt;
+
+  &lt;refentry id="obex_push"&gt;
+    &lt;refmeta&gt;
+      &lt;refentrytitle&gt;obex_push&lt;/refentrytitle&gt;
+      &lt;manvolnum&gt;1&lt;/manvolnum&gt;
+      &lt;refmiscinfo class="manual"&gt;User commands&lt;/refmiscinfo&gt;
+    &lt;/refmeta&gt;
+    &lt;refnamediv&gt;
+      &lt;refname&gt;obex_push&lt;/refname&gt;
+      &lt;refpurpose&gt;Push and Receive Files over the Bluetooth OBEX Push Channel&lt;/refpurpose&gt;
+    &lt;/refnamediv&gt;
+    &lt;refsynopsisdiv&gt;
+      &lt;cmdsynopsis&gt;
+        &lt;command&gt;obex_push&lt;/command&gt;
+        &lt;arg&gt;&lt;replaceable&gt;channel&lt;/replaceable&gt;&lt;/arg&gt;
+        &lt;arg&gt;&lt;replaceable&gt;bdaddr&lt;/replaceable&gt;&lt;/arg&gt;
+        &lt;arg&gt;&lt;replaceable&gt;filename&lt;/replaceable&gt;&lt;/arg&gt;
+      &lt;/cmdsynopsis&gt;
+    &lt;/refsynopsisdiv&gt;
+    &lt;refsect1&gt;
+      &lt;title&gt;Description&lt;/title&gt;
+      &lt;para&gt;
+        obex_push can send and receive files over the Bluetooth OBEX Push Channel.
+      &lt;/para&gt;
+      &lt;para&gt;
+        This program is designed to be an example application for the openobex library.
+      &lt;/para&gt;
+      &lt;para&gt;
+        Link your bluetooth device with your computer.
+      &lt;/para&gt;
+      &lt;para&gt;
+        You can see the SDP services with: "sdptool browse &lt;replaceable&gt;bdaddr&lt;/replaceable&gt;"
+      &lt;/para&gt;
+    &lt;/refsect1&gt;
+    &lt;refsect1&gt;
+      &lt;title&gt;Options&lt;/title&gt;
+      &lt;para&gt;
+        If no options are given, any files sent over bluetooth will be received over channel 10 and stored in /tmp.
+        If &lt;replaceable&gt;bdaddr&lt;/replaceable&gt; and &lt;replaceable&gt;filename&lt;/replaceable&gt; are given, the file will be
+        send to the device specified with &lt;replaceable&gt;bdaddr&lt;/replaceable&gt;.
+      &lt;/para&gt;
+      &lt;para&gt;
+        &lt;variablelist&gt;
+          &lt;varlistentry&gt;
+            &lt;term&gt;&lt;replaceable&gt;channel&lt;/replaceable&gt;&lt;/term&gt;
+            &lt;listitem&gt;
+              &lt;para&gt;
+                The bluetooth channel to use. Lookup the OBEX Push channel with sdptool browse &lt;replaceable&gt;bdaddr&lt;/replaceable&gt;.
+              &lt;/para&gt;
+            &lt;/listitem&gt;
+          &lt;/varlistentry&gt;
+          &lt;varlistentry&gt;
+            &lt;term&gt;&lt;replaceable&gt;bdaddr&lt;/replaceable&gt;&lt;/term&gt;
+            &lt;listitem&gt;
+              &lt;para&gt;
+                The bluetooth address &lt;replaceable&gt;bdaddr&lt;/replaceable&gt; of the device to send to.
+              &lt;/para&gt;
+            &lt;/listitem&gt;
+          &lt;/varlistentry&gt;
+          &lt;varlistentry&gt;
+            &lt;term&gt;&lt;replaceable&gt;filename&lt;/replaceable&gt;&lt;/term&gt;
+            &lt;listitem&gt;
+              &lt;para&gt;
+                The file to send.
+              &lt;/para&gt;
+            &lt;/listitem&gt;
+          &lt;/varlistentry&gt;
+        &lt;/variablelist&gt;
+      &lt;/para&gt;
+    &lt;/refsect1&gt;
+  &lt;/refentry&gt;
+&lt;/reference&gt;
diff --git a/doc/openobex-apps.xml b/doc/openobex-apps.xml
index e874f6c..202c842 100644
--- a/doc/openobex-apps.xml
+++ b/doc/openobex-apps.xml
@@ -11,4 +11,5 @@
   &lt;xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="obex_find.xml" xpointer="obex_find" /&gt;
   &lt;xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="obex_tcp.xml" xpointer="obex_tcp" /&gt;
   &lt;xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="obex_test.xml" xpointer="obex_test" /&gt;
+  &lt;xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="obex_push.xml" xpointer="obex_push" /&gt;
 &lt;/reference&gt;
diff --git a/doc/referenceinfo.xml.in b/doc/referenceinfo.xml.in
index 77f56c3..1dde6bd 100644
--- a/doc/referenceinfo.xml.in
+++ b/doc/referenceinfo.xml.in
@@ -11,5 +11,11 @@
       &lt;contrib&gt;initial version of manpage&lt;/contrib&gt;
       &lt;email&gt;post@hendrik-sattler.de&lt;/email&gt;
     &lt;/author&gt;
+    &lt;author&gt;
+      &lt;firstname&gt;Harald&lt;/firstname&gt;
+      &lt;surname&gt;Hoyer&lt;/surname&gt;
+      &lt;contrib&gt;Initial version of obex_push manpage&lt;/contrib&gt;
+      &lt;email&gt;harald@redhat.com&lt;/email&gt;
+    &lt;/author&gt;
   &lt;/authorgroup&gt;
 &lt;/referenceinfo&gt;
-- 
1.8.3.1

</pre></body></html>