Index: include/obex_const.h
===================================================================
RCS file: /cvsroot/openobex/openobex/include/obex_const.h,v
retrieving revision 1.32
diff -u -5 -r1.32 obex_const.h
--- include/obex_const.h	31 Dec 2006 14:58:55 -0000	1.32
+++ include/obex_const.h	24 Jun 2007 04:22:38 -0000
@@ -29,11 +29,15 @@
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <inttypes.h>
+#ifdef _MSC_VER
+#define inline __inline
+#endif
+
+#include "obex_stdint.h"
 
 typedef union {
 	uint32_t bq4;
 	uint8_t bq1;
 	const uint8_t *bs;
Index: lib/databuffer.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/databuffer.c,v
retrieving revision 1.2
diff -u -5 -r1.2 databuffer.c
--- lib/databuffer.c	24 Jan 2007 18:45:50 -0000	1.2
+++ lib/databuffer.c	24 Jun 2007 04:22:38 -0000
@@ -25,11 +25,11 @@
  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *     MA  02111-1307  USA
  *
  *************************************************************************/
 
-#include <databuffer.h>
+#include "databuffer.h"
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -52,13 +52,14 @@
 	return list;
 }
 
 slist_t *slist_remove(slist_t *list, void *element) 
 {
+	slist_t *prev, *next;
+
 	if (!list)
 		return NULL;
-	slist_t *prev, *next;
 	prev = list;
 	next = list;
 	while (next != NULL) {
 		if (next->data == element) {
 			/* if first element, update list pointer */
@@ -208,13 +209,14 @@
 	}
 }
 
 void *buf_reserve_end(buf_t *p, size_t data_size) 
 {
+	void *t;
+
 	if (!p)
 		return NULL;
-	void *t;
 
 	if (p->tail_avail >= data_size)
 		p->tail_avail -= data_size;
 	else {
 		if (data_size > p->tail_avail + p->data_avail) {
@@ -280,13 +282,14 @@
 	}
 }
 
 void buf_dump(buf_t *p, const char *label) 
 {
+	int i, n;
+
 	if (!p || !label)
 		return;
-	int i, n;
 
 	n = 0;
 	for (i = 0; i < p->data_size; ++i) {
 		if (n == 0)
 			log_debug("%s%s:", log_debug_prefix, label);
Index: lib/databuffer.h
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/databuffer.h,v
retrieving revision 1.1
diff -u -5 -r1.1 databuffer.h
--- lib/databuffer.h	4 May 2006 11:24:21 -0000	1.1
+++ lib/databuffer.h	24 Jun 2007 04:22:39 -0000
@@ -30,11 +30,11 @@
 #ifndef DATABUFFER_H
 #define DATABUFFER_H
 
 #define __need_size_t
 #include <stddef.h>
-#include <stdint.h>
+#include "obex_stdint.h"
 
 /*
  * Implements a single linked list
  */
 typedef struct _slist_t {
Index: lib/inobex.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/inobex.c,v
retrieving revision 1.19
diff -u -5 -r1.19 inobex.c
--- lib/inobex.c	22 May 2007 07:24:29 -0000	1.19
+++ lib/inobex.c	24 Jun 2007 04:22:39 -0000
@@ -31,16 +31,18 @@
 #include <config.h>
 #endif
 
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #ifdef _WIN32
 #include <winsock2.h>
 #include <ws2tcpip.h>
+/* This is necessary for Windows 2000, 95/98/Me & NT support of getnameinfo */
+#include <wspiapi.h>
 #else
-
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
@@ -48,10 +50,59 @@
 
 #include "obex_main.h"
 
 #define OBEX_PORT 650
 
+/* Visual C++ based compilers don't define inet_ntop. */
+/* Some older cygwin based compilers only support */
+/* AF_INET, not AF_INET6.  Fake the inet_ntop here */
+/* Should be supported on Windows XP and above */
+#ifdef _WIN32
+#define EAFNOSUPPORT    WSAEAFNOSUPPORT
+char *inet_ntop(int af, const void *src, char *dst, size_t cnt)
+{
+	int r;
+
+	if (af == AF_INET) {
+		struct sockaddr_in in;
+
+		memset(&in, 0, sizeof(in));
+		in.sin_family = AF_INET;
+		memcpy(&in.sin_addr, src, sizeof(struct in_addr));
+		r = getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in),
+			dst, cnt, NULL, 0, NI_NUMERICHOST);
+
+		if (r == 0)
+			return dst;
+
+		if (r == WSAEFAULT)
+			errno = ENOSPC;
+
+		return NULL;
+	} else if (af == AF_INET6) {
+		struct sockaddr_in6 in;
+
+		memset(&in, 0, sizeof(in));
+		in.sin6_family = AF_INET6;
+		memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
+		r = getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), 
+			dst, cnt, NULL, 0, NI_NUMERICHOST);
+
+		if (r == 0)
+			return dst;
+
+		if (r == WSAEFAULT)
+			errno = ENOSPC;
+
+		return NULL;
+	}
+
+	errno = EAFNOSUPPORT;
+	return NULL;
+}
+#endif
+
 static void map_ip4to6(struct sockaddr_in *in, struct sockaddr_in6 *out)
 {
 	out->sin6_family = AF_INET6;
 	if (in->sin_port == 0)
 		out->sin6_port = htons(OBEX_PORT);
@@ -69,11 +120,12 @@
 		break;
 	default:
 		/* map the IPv4 address to [::FFFF:<ipv4>]
 		 * see RFC2373 and RFC2553 for details
 		 */
-		out->sin6_addr.s6_addr16[10/2] = 0xFFFF;
+		out->sin6_addr.s6_addr[10] = 0xFF;
+		out->sin6_addr.s6_addr[11] = 0xFF;
 		out->sin6_addr.s6_addr[12] = (in->sin_addr.s_addr >>  0) & 0xFF;
 		out->sin6_addr.s6_addr[13] = (in->sin_addr.s_addr >>  8) & 0xFF;
 		out->sin6_addr.s6_addr[14] = (in->sin_addr.s_addr >> 16) & 0xFF;
 		out->sin6_addr.s6_addr[15] = (in->sin_addr.s_addr >> 24) & 0xFF;
 		break;
@@ -86,20 +138,17 @@
  *    Prepare for INET-connect
  *
  */
 void inobex_prepare_connect(obex_t *self, struct sockaddr *saddr, int addrlen)
 {
-	struct sockaddr_in6 addr = {
-		.sin6_family       = AF_INET6,
-		.sin6_port         = htons(OBEX_PORT),
-#ifdef _WIN32
-		.sin6_addr.s6_addr = IN6ADDR_LOOPBACK_INIT,
-#else
-		.sin6_addr         = IN6ADDR_LOOPBACK_INIT,
-#endif
-		.sin6_flowinfo     = 0
-	};
+	struct sockaddr_in6 addr;
+	memset(&addr, 0, sizeof(struct sockaddr_in6));
+	addr.sin6_family = AF_INET6;
+	addr.sin6_port = htons(OBEX_PORT);
+	addr.sin6_addr = in6addr_loopback;
+	addr.sin6_flowinfo = 0;
+
 	if (saddr == NULL)
 		saddr = (struct sockaddr*)(&addr);
 	else
 		switch (saddr->sa_family){
 		case AF_INET6:
@@ -120,20 +169,17 @@
  *    Prepare for INET-listen
  *
  */
 void inobex_prepare_listen(obex_t *self, struct sockaddr *saddr, int addrlen)
 {
-	struct sockaddr_in6 addr = {
-		.sin6_family       = AF_INET6,
-		.sin6_port         = htons(OBEX_PORT),
-#ifdef _WIN32
-		.sin6_addr.s6_addr = IN6ADDR_ANY_INIT,
-#else
-		.sin6_addr         = IN6ADDR_ANY_INIT,
-#endif
-		.sin6_flowinfo     = 0
-	};
+	struct sockaddr_in6 addr;
+	memset(&addr, 0, sizeof(struct sockaddr_in6));
+	addr.sin6_family = AF_INET6;
+	addr.sin6_port = htons(OBEX_PORT);
+	addr.sin6_addr = in6addr_loopback;
+	addr.sin6_flowinfo = 0;
+
 	/* Bind local service */
 	if (saddr == NULL)
 		saddr = (struct sockaddr *) &addr;
 	else
 		switch (saddr->sa_family) {
@@ -224,20 +270,18 @@
 
 	/* Set these just in case */
 	if (self->trans.peer.inet6.sin6_port == 0)
 		self->trans.peer.inet6.sin6_port = htons(OBEX_PORT);
 
-#ifndef _WIN32
 	if (!inet_ntop(AF_INET6,&self->trans.peer.inet6.sin6_addr,
 		       addr,sizeof(addr))) {
 		DEBUG(4, "Adress problem\n");
 		obex_delete_socket(self, self->fd);
 		self->fd = -1;
 		return -1;
 	}
 	DEBUG(2, "peer addr = [%s]:%u\n",addr,ntohs(self->trans.peer.inet6.sin6_port));
-#endif
 
 	ret = connect(self->fd, (struct sockaddr *) &self->trans.peer.inet6,
 		      sizeof(struct sockaddr_in6));
 	if (ret < 0) {
 		DEBUG(4, "Connect failed\n");
Index: lib/obex_client.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/obex_client.c,v
retrieving revision 1.21
diff -u -5 -r1.21 obex_client.c
--- lib/obex_client.c	8 Sep 2006 19:39:39 -0000	1.21
+++ lib/obex_client.c	24 Jun 2007 04:22:40 -0000
@@ -183,19 +183,20 @@
 
 			self->object->continue_received = 0;
 		} else {
 			/* Notify app that client-operation is done! */
 			DEBUG(3, "Done! Rsp=%02x!\n", rsp);
-			self->state = MODE_SRV | STATE_IDLE;
 			if (self->object->abort) {
 				if (rsp == OBEX_RSP_SUCCESS)
 					obex_deliver_event(self, OBEX_EV_ABORT, self->object->opcode, rsp, TRUE);
 				else
 					obex_deliver_event(self, OBEX_EV_LINKERR, self->object->opcode, rsp, TRUE);
 			}
 			else
 				obex_deliver_event(self, OBEX_EV_REQDONE, self->object->opcode, rsp, TRUE);
+
+			self->state = MODE_SRV | STATE_IDLE;
 		}
 		break;
        	
        	default:
 		DEBUG(0, "Unknown state\n");		
Index: lib/obex_main.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/obex_main.c,v
retrieving revision 1.32
diff -u -5 -r1.32 obex_main.c
--- lib/obex_main.c	31 Dec 2006 15:09:27 -0000	1.32
+++ lib/obex_main.c	24 Jun 2007 04:22:40 -0000
@@ -63,16 +63,16 @@
 #include "obex_main.h"
 #include "obex_header.h"
 #include "obex_server.h"
 #include "obex_client.h"
 
-#include <openobex/obex_const.h>
+#include "obex_const.h"
 
-#ifdef OBEX_DEBUG
+#if OBEX_DEBUG
 int obex_debug;
 #endif
-#ifdef OBEX_DUMP
+#if OBEX_DUMP
 int obex_dump;
 #endif
 
 /*
  * Function obex_create_socket()
Index: lib/obex_main.h
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/obex_main.h,v
retrieving revision 1.26
diff -u -5 -r1.26 obex_main.h
--- lib/obex_main.h	24 Jan 2007 18:45:50 -0000	1.26
+++ lib/obex_main.h	24 Jun 2007 04:22:41 -0000
@@ -53,39 +53,46 @@
 #define FALSE		0
 
 #define obex_return_if_fail(test)	do { if (!(test)) return; } while(0);
 #define obex_return_val_if_fail(test, val)	do { if (!(test)) return val; } while(0);
 
-#include <openobex/obex_const.h>
+#include "obex_const.h"
 
 #include "obex_object.h"
 #include "obex_transport.h"
 #include "databuffer.h"
 
 
 #if defined(OBEX_SYSLOG) && !defined(_WIN32)
 #include <syslog.h>
 #define log_debug(format, args...) syslog(LOG_DEBUG, format, ##args)
 #define log_debug_prefix "OpenOBEX: "
-#else
+#elif !defined(_WIN32)
 #include <stdio.h>
 #define log_debug(format, args...) fprintf(stderr, format, ##args)
 #define log_debug_prefix ""
+#else
+#define log_debug_prefix ""
+void log_debug(const char *format, ...);
 #endif
 
 
 /* use integer:  0 for production
  *               1 for verification
  *              >2 for debug
  */
-#if OBEX_DEBUG
+#if OBEX_DEBUG && !defined(_WIN32)
 extern int obex_debug;
 #define DEBUG(n, format, args...) \
         if (obex_debug >= (n)) \
           log_debug("%s%s(): " format, log_debug_prefix, __FUNCTION__, ##args)
-#else
+#elif !defined(_WIN32)
+extern int obex_debug;
 #define DEBUG(n, format, args...)
+#else
+extern int obex_debug;
+void DEBUG(unsigned int n, const char *format, ...);
 #endif
 
 
 /* use bitmask: 0x1 for sendbuff
  *              0x2 for receivebuff
Index: lib/obex_transport.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/obex_transport.c,v
retrieving revision 1.33
diff -u -5 -r1.33 obex_transport.c
--- lib/obex_transport.c	22 May 2007 07:24:29 -0000	1.33
+++ lib/obex_transport.c	24 Jun 2007 04:22:42 -0000
@@ -31,11 +31,13 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include <string.h>
+#ifndef _WIN32
 #include <unistd.h>
+#endif
 #include <stdio.h>
 
 #include "obex_main.h"
 #ifdef HAVE_IRDA
 #include "irobex.h"
@@ -365,10 +367,36 @@
 }
 
 /*
  * does fragmented write
  */
+static int do_send(int fd, buf_t *msg, int mtu)
+{
+	int actual = -1;
+	int size;
+
+	/* Send and fragment if necessary  */
+	while (msg->data_size) {
+		if (msg->data_size > mtu)
+			size = mtu;
+		else
+			size = msg->data_size;
+		DEBUG(1, "sending %d bytes\n", size);
+
+		actual = send(fd, msg->data, size, 0);
+		if (actual <= 0)
+			return actual;
+			
+		/* Hide sent data */
+		buf_remove_begin(msg, actual);
+	}
+	return actual;
+}
+
+/*
+ * does fragmented write
+ */
 static int do_write(int fd, buf_t *msg, int mtu)
 {
 	int actual = -1;
 	int size;
 
@@ -408,11 +436,11 @@
 #endif /*HAVE_IRDA*/
 #ifdef HAVE_BLUETOOTH
 	case OBEX_TRANS_BLUETOOTH:
 #endif /*HAVE_BLUETOOTH*/
 	case OBEX_TRANS_INET:
-		actual = do_write(self->fd, msg, self->trans.mtu);
+		actual = do_send(self->fd, msg, self->trans.mtu);
 		break;
 	case OBEX_TRANS_FD:
 		actual = do_write(self->writefd, msg, self->trans.mtu);
 		break;
 #ifdef HAVE_USB 
@@ -458,10 +486,14 @@
 #endif /*HAVE_IRDA*/
 #ifdef HAVE_BLUETOOTH
 	case OBEX_TRANS_BLUETOOTH:
 #endif /*HAVE_BLUETOOTH*/
 	case OBEX_TRANS_INET:
+		actual = recv(self->fd, buf_reserve_end(msg, max), max, 0);
+		if (actual > 0)
+			buf_remove_end(msg, max - actual);
+		break;
 	case OBEX_TRANS_FD:
 		actual = read(self->fd, buf_reserve_end(msg, max), max);
 		if (actual > 0)
 			buf_remove_end(msg, max - actual);
 		break;
Index: lib/win32compat.c
===================================================================
RCS file: /cvsroot/openobex/openobex/lib/win32compat.c,v
retrieving revision 1.7
diff -u -5 -r1.7 win32compat.c
--- lib/win32compat.c	6 Mar 2004 11:32:56 -0000	1.7
+++ lib/win32compat.c	24 Jun 2007 04:22:42 -0000
@@ -25,28 +25,45 @@
  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  *     MA  02111-1307  USA
  *
  ********************************************************************/
 
-#include "config.h"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <inttypes.h>
-
-#include "obex_main.h"
-
 // The VC proprocessor can't handle variable argument macros,
 // so we are forced to do an ugly thing like this.
 
 #ifdef OBEX_DEBUG
 extern obex_debug;
 
-void DEBUG(unsigned int n, const char *format, void *a1, void *a2, void *a3, void *a4, 
-		void *a5, void *a6, void *a7, void *a8, void *a9, void *a10)
+#include <stdio.h>
+#include <stdarg.h>
+#include <varargs.h>
+
+void log_debug(const char *format, ...)
+{
+	va_list ptr;
+
+	va_start(ptr, format);
+	vfprintf(stderr, format, ptr);
+	va_end(ptr);
+}
+
+void DEBUG(unsigned int n, const char *format, ...)
 {
-	if(n <= obex_debug)
-		fprintf(stderr, format, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);
+	va_list ptr;
+
+	if(n > obex_debug)
+		return;
+
+	va_start(ptr, format);
+	vfprintf(stderr, format, ptr);
+	va_end(ptr);
 }
 #else
-void DEBUG(int n, const char *format, ...){};
+void DEBUG(unsigned int n, const char *format, ...)
+{
+}
+
+void log_debug(const char *format, ...)
+{
+
+}
 #endif
