Hi,

I am the current openobex maintainer for Debian and have collected some 
patches, mainly for the apps in the package:

* docbuild.patch makes creation of the documentation possible again

* ircp.patch fixes some security related problems (although low risk, it is 
still valid) that would overwrite files in receive mode. Instead, it adds a 
random string to the file (using mkstemp).

* obex_test.patch adds some error checking to the code and adds some missing 
ifs for the default case

* rodrigues_irobex_palm3.patch adds the possibility to specify the creation-ID 
of the object to send

I also have manpages for all apps in the package. If you are interested (they 
are written in docbook), please tell me (I have to rip out some sentences 
about Debian, first).


There are other bug reports in line waiting for a fix:
http://bugs.debian.org/cgi-bin/pkgreport.cgi?src=libopenobex

One issue with the IrDA-Server-Code (see debian bugs #236371 and #256245) is 
the missing possibility to wait for "OBEX" _and_ "OBEX:IrXfer" packages. So 
please make it possible to call IrOBEX_ServerRegister() more than once on the 
same handle. Or is there another proposed solution that a single call to 
OBEX_HandleInput() could handle?


Have fun...

Hendrik Sattler

PS: please CC me, I am not subscibed, yet (will do that later)
Index: libopenobex-1.2/doc/Makefile.am
===================================================================
--- libopenobex-1.2.orig/doc/Makefile.am	2006-03-24 10:20:00.000000000 +0100
+++ libopenobex-1.2/doc/Makefile.am	2006-03-24 10:20:13.000000000 +0100
@@ -5,7 +5,7 @@
 ps:	openobex.ps
 html:	openobex
 
-openobex.sgml: openobex.tmpl docproc ../src/obex.c
+openobex.sgml: openobex.tmpl docproc ../lib/obex.c
 	$(top_srcdir)/doc/docproc <$< >$@
 
 clean:
Index: libopenobex-1.2/doc/Makefile.in
===================================================================
--- libopenobex-1.2.orig/doc/Makefile.in	2006-03-24 10:20:00.000000000 +0100
+++ libopenobex-1.2/doc/Makefile.in	2006-03-24 10:20:13.000000000 +0100
@@ -421,7 +421,7 @@
 ps:	openobex.ps
 html:	openobex
 
-openobex.sgml: openobex.tmpl docproc ../src/obex.c
+openobex.sgml: openobex.tmpl docproc ../lib/obex.c
 	$(top_srcdir)/doc/docproc <$< >$@
 
 clean:
Index: libopenobex-1.2/doc/openobex.tmpl
===================================================================
--- libopenobex-1.2.orig/doc/openobex.tmpl	2006-03-24 10:20:31.000000000 +0100
+++ libopenobex-1.2/doc/openobex.tmpl	2006-03-24 10:20:50.000000000 +0100
@@ -304,7 +304,7 @@
 
   <chapter id="apiref">
      <title>API Reference</title>
-!Esrc/obex.c
+!Elib/obex.c
   </chapter>
 
 </book>
Index: libopenobex-1.2/ircp/ircp_io.c
===================================================================
--- libopenobex-1.2.orig/ircp/ircp_io.c	2006-05-10 00:31:25.000000000 +0200
+++ libopenobex-1.2/ircp/ircp_io.c	2006-05-10 00:48:06.000000000 +0200
@@ -126,13 +126,20 @@
 	if(ircp_nameok(name) == FALSE)
 		return -1;
 
-	//TODO! Rename file if already exist.
+	if (path == NULL || strnlen(path,sizeof(diskname)) == 0)
+	        path = ".";
+	if (snprintf(diskname, sizeof(diskname), "%s/%s", path, name) >= sizeof(diskname))
+	        return -1;
+
+	/* never overwrite an existing file */
+	fd = open(diskname, O_RDWR | O_CREAT | O_EXCL, DEFFILEMODE);
+	if (fd < 0 &&
+	    snprintf(diskname, sizeof(diskname), "%s/%s_XXXXXX", path, name) < sizeof(diskname))
+	        fd = mkstemp(diskname);
 
-	snprintf(diskname, MAXPATHLEN, "%s/%s", path, name);
+	if (fd >= 0)
+	        DEBUG(4, "Creating file %s\n", diskname);
 
-	DEBUG(4, "Creating file %s\n", diskname);
-
-	fd = open(diskname, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE);
 	return fd;
 }
 
@@ -150,7 +157,10 @@
 			return -1;
 	}
 
-	snprintf(newpath, MAXPATHLEN, "%s/%s", path, dir);
+	if (strnlen(path,sizeof(newpath)) != 0)
+		snprintf(newpath, sizeof(newpath), "%s/%s", path, dir);
+	else
+		strncpy(newpath, dir, sizeof(newpath));
 
 	DEBUG(4, "path = %s dir = %s, flags = %d\n", path, dir, flags);
 	if(stat(newpath, &statbuf) == 0) {
Index: libopenobex-1.2/apps/obex_tcp.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_tcp.c	2006-05-10 01:42:36.000000000 +0200
+++ libopenobex-1.2/apps/obex_tcp.c	2006-05-10 01:42:36.000000000 +0200
@@ -112,14 +112,19 @@
 	if (argc == 1)	{
 		printf("Waiting for files\n");
 		ret = InOBEX_ServerRegister(handle);
-		if(ret < 0)
+		if(ret < 0) {
+                        printf("Cannot listen to socket\n");
 			exit(ret);
+		}
 
 		while (!finished) {
 			ret = OBEX_HandleInput(handle, 10);
-			if (ret < 1) {
+			if (ret == 0) {
 				printf("Timeout waiting for connection\n");
 				break;
+			} else if (ret < 0) {
+			        printf("Error waiting for connection\n");
+				break;
 			}
 		}
 	}
Index: libopenobex-1.2/apps/obex_test.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_test.c	2006-05-10 01:42:32.000000000 +0200
+++ libopenobex-1.2/apps/obex_test.c	2006-05-10 01:42:36.000000000 +0200
@@ -340,7 +340,7 @@
 			case 'c':
 				/* First connect transport */
 				if(tcpobex) {
-					if(inet_connect(handle)) {
+					if(inet_connect(handle) < 0) {
 						printf("Transport connect error! (TCP)\n");
 						break;
 					}
@@ -371,7 +371,7 @@
 						break;
 					}
 				}	
-				else {
+				if (!tcpobex && !cobex && !btobex && !usbobex) {
 					if(IrOBEX_TransportConnect(handle, IR_SERVICE) < 0) {
 						printf("Transport connect error! (IrDA)\n");
 						break;
@@ -386,7 +386,7 @@
 			case 's':
 				/* First register server */
 				if(tcpobex) {
-					if(InOBEX_ServerRegister(handle)) {
+					if(InOBEX_ServerRegister(handle) < 0) {
 						printf("Server register error! (TCP)\n");
 						break;
 					}
@@ -407,7 +407,10 @@
 					printf("Transport not found! (Bluetooth)\n");
 #endif
 				}
-				else {
+				if (usbobex) {
+					printf("Transport not found! (USB)\n");
+				}
+				if (!tcpobex && !cobex && !btobex && !usbobex) {
 					if(IrOBEX_ServerRegister(handle, IR_SERVICE) < 0)	{
 						printf("Server register error! (IrDA)\n");
 						break;
Index: libopenobex-1.2/apps/obex_test_server.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_test_server.c	2006-05-10 01:42:32.000000000 +0200
+++ libopenobex-1.2/apps/obex_test_server.c	2006-05-10 01:42:36.000000000 +0200
@@ -239,14 +239,21 @@
 //
 void server_do(obex_t *handle)
 {
+        int ret;
 	struct context *gt;
 	gt = OBEX_GetUserData(handle);
 
 	gt->serverdone = FALSE;
 	while(!gt->serverdone) {
-		if(OBEX_HandleInput(handle, 1) < 0) {
+	        ret = OBEX_HandleInput(handle, 10);
+		if(ret < 0) {
 			printf("Error while doing OBEX_HandleInput()\n");
 			break;
+		} else if (ret == 0) {
+			printf("Timeout while doing OBEX_HandleInput()\n");
+			break;
+		} else {
+			printf("OBEX_HandleInput() returned %d\n",ret);
 		}
 	}
 }
Index: libopenobex-1.2/apps/obex_test_client.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_test_client.c	2006-05-10 01:42:32.000000000 +0200
+++ libopenobex-1.2/apps/obex_test_client.c	2006-05-10 01:42:36.000000000 +0200
@@ -231,8 +231,10 @@
 	bfname = strdup(basename(fname));
 
 	buf = easy_readfile(fname, &file_size);
-	if(buf == NULL)
+	if(buf == NULL) {
+	        printf("file not found: %s\n", fname);
 		return;
+	}
 	fileDesc = open(fname, O_RDONLY, 0);
 
 	if (fileDesc < 0) {
@@ -286,8 +288,10 @@
 	scanf("%s %s", lname, rname);
 
 	buf = easy_readfile(lname, &file_size);
-	if(buf == NULL)
+	if(buf == NULL) {
+	        printf("file not found: %s\n", lname);
 		return;
+	}
 
 	printf("Going to send %d bytes\n", file_size);
 
Index: libopenobex-1.2/apps/irobex_palm3.c
===================================================================
--- libopenobex-1.2.orig/apps/irobex_palm3.c	2006-05-10 00:28:39.000000000 +0200
+++ libopenobex-1.2/apps/irobex_palm3.c	2006-05-10 00:44:11.000000000 +0200
@@ -58,6 +58,15 @@
 extern int last_rsp;
 
 /*
+ * Function usage (void)
+ */
+int usage(char *argv[]) {
+	printf ("Usage: %s [-h xxxx] [name]\n", argv[0]);
+	printf ("       where xxxx is the header_creator_id (default: memo)\n");
+	return -1;
+}
+
+/*
  * Function main (argc, )
  *
  *    Starts all the fun!
@@ -67,11 +76,11 @@
 {
 	obex_object_t *object;
 	int ret, exitval = EXIT_SUCCESS;
+	uint32_t creator_id = 0;
 
 	printf("Send and receive files to Palm3\n");
-	if ((argc < 1) || (argc > 2))	{
-		printf ("Usage: %s [name]\n", argv[0]); 
-		return -1;
+	if ((argc < 1) || (argc > 4))	{
+		return usage(argv);
 	}
 	handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0);
 
@@ -87,6 +96,14 @@
 	else {
 		/* We are a client */
 
+		/* Check for parameters */
+		if(argc > 2) {
+			if(strcmp("-h", argv[1]) || strlen(argv[2]) != 4)
+				return usage(argv);
+			creator_id = argv[2][0] << 24 | argv[2][1] << 16 | argv[2][2] << 8 | argv[2][3];
+			printf("debug: %s %d;", argv[2], creator_id);
+		}
+
 		/* Try to connect to peer */
 		ret = IrOBEX_TransportConnect(handle, "OBEX");
 		if (ret < 0) {
@@ -100,7 +117,7 @@
 			printf("Sorry, unable to connect!\n");
 			return EXIT_FAILURE;
 		}
-		if ((object = build_object_from_file(handle, argv[1])))	{
+		if ((object = build_object_from_file(handle, argv[(creator_id ? 3 : 1)], creator_id))) {
 			ret = do_sync_request(handle, object, FALSE);
 			if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0))
 				exitval = EXIT_FAILURE;
Index: libopenobex-1.2/apps/irxfer.c
===================================================================
--- libopenobex-1.2.orig/apps/irxfer.c	2006-05-10 00:28:39.000000000 +0200
+++ libopenobex-1.2/apps/irxfer.c	2006-05-10 00:29:00.000000000 +0200
@@ -91,7 +91,7 @@
 		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
 		ret = do_sync_request(handle, object, 0);
 
-		if( (object = build_object_from_file(handle, argv[1])) )	{
+		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
 			ret = do_sync_request(handle, object, 0);
 		}
 		else	{
Index: libopenobex-1.2/apps/obex_io.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_io.c	2006-05-10 00:28:39.000000000 +0200
+++ libopenobex-1.2/apps/obex_io.c	2006-05-10 00:42:29.000000000 +0200
@@ -125,13 +125,13 @@
 //
 //
 //
-obex_object_t *build_object_from_file(obex_t *handle, const char *filename)
+obex_object_t *build_object_from_file(obex_t *handle, const char *filename, uint32_t creator_id)
 {
 	obex_headerdata_t hdd;
 	uint8_t unicode_buf[200];
 	int namebuf_len;
  	obex_object_t *object;
-	uint32_t creator_id;
+	//uint32_t creator_id;
 	int file_size;
 	char *name = NULL;
 	uint8_t *buf;
@@ -142,7 +142,8 @@
 		return NULL;
 
 	/* Set Memopad as the default creator ID */
-	creator_id = MEMO_PAD;	
+	if(creator_id == 0)
+		creator_id = MEMO_PAD;
 
 	/* Find the . in the filename */
 	name = strchr(filename, '.');
Index: libopenobex-1.2/apps/obex_io.h
===================================================================
--- libopenobex-1.2.orig/apps/obex_io.h	2006-05-10 00:28:39.000000000 +0200
+++ libopenobex-1.2/apps/obex_io.h	2006-05-10 00:29:00.000000000 +0200
@@ -11,7 +11,7 @@
 #define PILOT_RESOURCE 0x6c6e6368 /* "Inch" *.prc */
 
 int get_filesize(const char *filename);
-obex_object_t *build_object_from_file(obex_t *handle, const char *filename);
+obex_object_t *build_object_from_file(obex_t *handle, const char *filename, uint32_t creator_id);
 int safe_save_file(char *name, const uint8_t *buf, int len);
 uint8_t* easy_readfile(const char *filename, int *file_size);
 
Index: libopenobex-1.2/apps/obex_tcp.c
===================================================================
--- libopenobex-1.2.orig/apps/obex_tcp.c	2006-05-10 00:28:39.000000000 +0200
+++ libopenobex-1.2/apps/obex_tcp.c	2006-05-10 00:29:00.000000000 +0200
@@ -138,7 +138,7 @@
 		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
 		ret = do_sync_request(handle, object, 0);
 
-		if( (object = build_object_from_file(handle, argv[1])) )	{
+		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
 			ret = do_sync_request(handle, object, 0);
 		}
 		else	{

Attachment: pgpvTOajcTBMZ.pgp
Description: PGP signature

Reply via email to