Am Sonntag 17 Dezember 2006 20:00 schrieb Marcel Holtmann:
> The second is that the Bluetooth part is too hackish for me at the
> moment, I would need more time to look at it.
You were right, quite some bits of it were wrong.
I had to rearrange some of the bluetooth multi-platform (linux, *bsd) part to
integrate it cleanly.
I attached two additional patches:
debug-output.patch:
- flatten the macro structure
- adapt for win32
ws2bth.patch:
- win32 bt support
- fixes for other platforms
- removal of code duplication
Should be less "hackish" now :)
Don't get confused by the code-movements in the diff, look at the result
instead ;)
HS
Index: openobex-cvs/lib/btobex.c
===================================================================
--- openobex-cvs.orig/lib/btobex.c 2006-12-18 02:56:43.282152256 +0100
+++ openobex-cvs/lib/btobex.c 2006-12-18 02:57:19.240399506 +0100
@@ -30,46 +30,45 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include "obex_main.h"
+#include "btobex.h"
#ifdef HAVE_BLUETOOTH
+/* define everything needed for bluez compatibility */
#ifdef _WIN32
-#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <string.h>
+#define bacpy(dst,src) memcpy((dst),(src),sizeof(typeof((dst))))
+#define PF_BLUETOOTH PF_BTH
+#define AF_BLUETOOTH PF_BLUETOOTH
+#define BTPROTO_RFCOMM BTHPROTO_RFCOMM
+#define rc_family addressFamily
+#define rc_bdaddr btAddr
+#define rc_channel port
#else /* _WIN32 */
/* Linux/FreeBSD/NetBSD case */
-
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h> /* perror */
-#include <errno.h> /* errno and EADDRNOTAVAIL */
#include <netinet/in.h>
#include <sys/socket.h>
-#ifdef HAVE_BLUETOOTH_LINUX
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/rfcomm.h>
-#endif
-#ifdef HAVE_BLUETOOTH_FREEBSD
-#include <bluetooth.h>
-#define sockaddr_rc sockaddr_rfcomm
+#if defined(HAVE_BLUETOOTH_FREEBSD)
#define rc_family rfcomm_family
#define rc_bdaddr rfcomm_bdaddr
#define rc_channel rfcomm_channel
-#endif
-#ifdef HAVE_BLUETOOTH_NETBSD
+
+#elif defined(HAVE_BLUETOOTH_NETBSD)
#define rc_family bt_family
#define rc_bdaddr bt_bdaddr
#define rc_channel bt_channel
-#define sockaddr_rc sockaddr_bt
-#include <bluetooth.h>
-#include <netbt/rfcomm.h>
#endif
#endif /* _WIN32 */
-#include "obex_main.h"
-#include "btobex.h"
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h> /* perror */
+#include <errno.h> /* errno and EADDRNOTAVAIL */
/*
* Function btobex_prepare_connect (self, service)
@@ -79,7 +78,6 @@
*/
void btobex_prepare_connect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel)
{
-#ifndef _WIN32
self->trans.self.rfcomm.rc_family = AF_BLUETOOTH;
bacpy(&self->trans.self.rfcomm.rc_bdaddr, src);
self->trans.self.rfcomm.rc_channel = 0;
@@ -87,7 +85,6 @@
self->trans.peer.rfcomm.rc_family = AF_BLUETOOTH;
bacpy(&self->trans.peer.rfcomm.rc_bdaddr, dst);
self->trans.peer.rfcomm.rc_channel = channel;
-#endif /* _WIN32 */
}
/*
@@ -98,12 +95,10 @@
*/
void btobex_prepare_listen(obex_t *self, bdaddr_t *src, uint8_t channel)
{
-#ifndef _WIN32
/* Bind local service */
self->trans.self.rfcomm.rc_family = AF_BLUETOOTH;
bacpy(&self->trans.self.rfcomm.rc_bdaddr, src);
self->trans.self.rfcomm.rc_channel = channel;
-#endif /* _WIN32 */
}
/*
@@ -114,17 +109,16 @@
*/
int btobex_listen(obex_t *self)
{
-#ifndef _WIN32
DEBUG(3, "\n");
self->serverfd = obex_create_socket(self, AF_BLUETOOTH);
- if(self->serverfd < 0) {
+ if (invalid_socket(self->serverfd)) {
DEBUG(0, "Error creating socket\n");
return -1;
}
if (bind(self->serverfd, (struct sockaddr*) &self->trans.self.rfcomm,
- sizeof(struct sockaddr_rc)))
+ sizeof(self->trans.self.rfcomm)))
{
DEBUG(0, "Error doing bind\n");
goto out_freesock;
@@ -142,7 +136,6 @@
out_freesock:
obex_delete_socket(self, self->serverfd);
self->serverfd = -1;
-#endif /* _WIN32 */
return -1;
}
@@ -156,8 +149,7 @@
*/
int btobex_accept(obex_t *self)
{
-#ifndef _WIN32
- socklen_t addrlen = sizeof(struct sockaddr_rc);
+ socklen_t addrlen = sizeof(self->trans.self.rfcomm);
//int mtu;
//int len = sizeof(int);
@@ -170,7 +162,6 @@
}
self->trans.mtu = OBEX_DEFAULT_MTU;
-#endif /* _WIN32 */
return 0;
}
@@ -183,7 +174,6 @@
int btobex_connect_request(obex_t *self)
{
int ret;
-#ifndef _WIN32
int mtu = 0;
//int len = sizeof(int);
@@ -191,12 +181,12 @@
if(self->fd < 0) {
self->fd = obex_create_socket(self, AF_BLUETOOTH);
- if(self->fd < 0)
+ if(invalid_socket(self->fd))
return -1;
}
ret = bind(self->fd, (struct sockaddr*) &self->trans.self.rfcomm,
- sizeof(struct sockaddr_rc));
+ sizeof(self->trans.self.rfcomm));
if (ret < 0) {
DEBUG(4, "ret=%d\n", ret);
@@ -204,7 +194,7 @@
}
ret = connect(self->fd, (struct sockaddr*) &self->trans.peer.rfcomm,
- sizeof(struct sockaddr_rc));
+ sizeof(self->trans.self.rfcomm));
if (ret < 0) {
DEBUG(4, "ret=%d\n", ret);
goto out_freesock;
@@ -220,7 +210,6 @@
out_freesock:
obex_delete_socket(self, self->fd);
self->fd = -1;
-#endif /* _WIN32 */
return ret;
}
@@ -233,13 +222,11 @@
int btobex_disconnect_request(obex_t *self)
{
int ret;
-#ifndef _WIN32
DEBUG(4, "\n");
ret = obex_delete_socket(self, self->fd);
if(ret < 0)
return ret;
self->fd = -1;
-#endif /* _WIN32 */
return ret;
}
@@ -254,11 +241,9 @@
int btobex_disconnect_server(obex_t *self)
{
int ret;
-#ifndef _WIN32
DEBUG(4, "\n");
ret = obex_delete_socket(self, self->serverfd);
self->serverfd = -1;
-#endif /* _WIN32 */
return ret;
}
Index: openobex-cvs/lib/inobex.c
===================================================================
--- openobex-cvs.orig/lib/inobex.c 2006-12-18 02:56:43.326155006 +0100
+++ openobex-cvs/lib/inobex.c 2006-12-18 02:57:19.664426006 +0100
@@ -88,7 +88,7 @@
DEBUG(4, "\n");
self->serverfd = obex_create_socket(self, AF_INET);
- if(self->serverfd < 0) {
+ if(invalid_socket(self->serverfd)) {
DEBUG(0, "Cannot create server-socket\n");
return -1;
}
@@ -147,7 +147,7 @@
int ret;
self->fd = obex_create_socket(self, AF_INET);
- if(self->fd < 0)
+ if(invalid_socket(self->fd))
return -1;
/* Set these just in case */
Index: openobex-cvs/lib/irobex.c
===================================================================
--- openobex-cvs.orig/lib/irobex.c 2006-12-18 02:56:43.370157756 +0100
+++ openobex-cvs/lib/irobex.c 2006-12-18 02:57:19.716429256 +0100
@@ -131,7 +131,7 @@
DEBUG(3, "\n");
self->serverfd = obex_create_socket(self, AF_IRDA);
- if(self->serverfd < 0) {
+ if(invalid_socket(self->serverfd)) {
DEBUG(0, "Error creating socket\n");
return -1;
}
@@ -351,7 +351,7 @@
if(self->fd < 0) {
self->fd = obex_create_socket(self, AF_IRDA);
- if(self->fd < 0)
+ if(invalid_socket(self->fd))
return -1;
}
Index: openobex-cvs/lib/obex_main.c
===================================================================
--- openobex-cvs.orig/lib/obex_main.c 2006-12-18 02:56:43.418160756 +0100
+++ openobex-cvs/lib/obex_main.c 2006-12-18 02:57:19.760432006 +0100
@@ -34,8 +34,43 @@
#ifdef _WIN32
#include <winsock2.h>
-#else /* _WIN32 */
+#ifdef HAVE_BLUETOOTH
+#include <ws2bth.h>
+
+#define PF_BLUETOOTH PF_BTH
+#define AF_BLUETOOTH PF_BLUETOOTH
+#define BTPROTO_RFCOMM BTHPROTO_RFCOMM
+
+static inline
+void winbt_cleanup (void)
+{
+ WSACleanup();
+}
+
+#define VER_MAJOR 2
+#define VER_MINOR 2
+static inline
+int winbt_init ()
+{
+ WORD ver = MAKEWORD(VER_MAJOR,VER_MINOR);
+ WSADATA data;
+ int err;
+
+ err = WSAStartup(ver,&data);
+ if (err != 0 )
+ return -WSAGetLastError();
+
+ if (LOBYTE(data.wVersion) != VER_MAJOR ||
+ HIBYTE(data.wVersion) != VER_MINOR) {
+ winbt_cleanup();
+ return 0;
+ }
+ return 1;
+}
+
+#endif
+#else /* _WIN32 */
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
@@ -53,7 +88,7 @@
#include <bluetooth.h>
#define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM
#endif
-#ifdef HAVE_BLUETOOTH_NETBSB
+#ifdef HAVE_BLUETOOTH_NETBSD
#include <bluetooth.h>
#endif
#endif /*HAVE_BLUETOOTH*/
@@ -80,16 +115,22 @@
* Create socket if needed.
*
*/
-int obex_create_socket(obex_t *self, int domain)
+socket_t obex_create_socket(obex_t *self, int domain)
{
- int fd, proto;
+ socket_t fd;
+ int proto;
DEBUG(4, "\n");
proto = 0;
#ifdef HAVE_BLUETOOTH
- if (domain == AF_BLUETOOTH)
+ if (domain == AF_BLUETOOTH) {
proto = BTPROTO_RFCOMM;
+#ifdef _WIN32
+ if (winbt_init() <= 0)
+ return -1;
+#endif
+ }
#endif /*HAVE_BLUETOOTH*/
fd = socket(domain, SOCK_STREAM, proto);
@@ -102,7 +143,7 @@
* Close socket if opened.
*
*/
-int obex_delete_socket(obex_t *self, int fd)
+int obex_delete_socket(obex_t *self, socket_t fd)
{
int ret;
@@ -113,6 +154,10 @@
#ifdef _WIN32
ret = closesocket(fd);
+#ifdef HAVE_BLUETOOTH
+ if (self->trans.type == OBEX_TRANS_BLUETOOTH)
+ winbt_cleanup();
+#endif
#else /* _WIN32 */
ret = close(fd);
#endif /* _WIN32 */
Index: openobex-cvs/lib/obex_main.h
===================================================================
--- openobex-cvs.orig/lib/obex_main.h 2006-12-18 02:57:09.019760756 +0100
+++ openobex-cvs/lib/obex_main.h 2006-12-18 02:57:19.860438256 +0100
@@ -33,11 +33,19 @@
#include <time.h>
-#ifndef _WIN32
+#ifdef _WIN32
+#include <winsock2.h>
+#define socket_t SOCKET
+#define invalid_socket(s) ((s) == INVALID_SOCKET)
+
+#else /* _WIN32 */
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
-#endif
+#define socket_t int
+#define invalid_socket(s) ((s) == -1)
+
+#endif /* _WIN32 */
/* Forward decl */
typedef struct obex obex_t;
@@ -120,9 +128,9 @@
uint16_t mtu_rx; /* Maximum OBEX RX packet size */
uint16_t mtu_tx_max; /* Maximum TX we can accept */
- int fd; /* Socket descriptor */
- int serverfd;
- int writefd; /* write descriptor - only OBEX_TRANS_FD */
+ socket_t fd; /* Socket descriptor */
+ socket_t serverfd;
+ socket_t writefd; /* write descriptor - only OBEX_TRANS_FD */
unsigned int state;
int keepserver; /* Keep server alive */
@@ -145,8 +153,8 @@
};
-int obex_create_socket(obex_t *self, int domain);
-int obex_delete_socket(obex_t *self, int fd);
+socket_t obex_create_socket(obex_t *self, int domain);
+int obex_delete_socket(obex_t *self, socket_t fd);
void obex_deliver_event(obex_t *self, int event, int cmd, int rsp, int del);
int obex_data_indication(obex_t *self, uint8_t *buf, int buflen);
Index: openobex-cvs/include/obex.h
===================================================================
--- openobex-cvs.orig/include/obex.h 2006-12-18 02:56:43.650175256 +0100
+++ openobex-cvs/include/obex.h 2006-12-18 02:57:19.952444006 +0100
@@ -51,10 +51,6 @@
typedef void* obex_t;
typedef void* obex_object_t;
typedef void (*obex_event_t)(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp);
-// This is to workaround compilation without Bluetooth support. - Jean II
-#ifndef SOL_RFCOMM
-typedef char* bdaddr_t;
-#endif
#include <openobex/obex_const.h>
@@ -130,8 +126,13 @@
/*
* Bluetooth OBEX API
*/
+#ifdef SOL_RFCOMM
+#ifdef _WIN32
+#define bdaddr_t BTH_ADDR
+#endif
int BtOBEX_ServerRegister(obex_t *self, bdaddr_t *src, uint8_t channel);
int BtOBEX_TransportConnect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel);
+#endif
/*
* OBEX File API
Index: openobex-cvs/apps/Makefile.am
===================================================================
--- openobex-cvs.orig/apps/Makefile.am 2006-12-18 02:56:43.702178506 +0100
+++ openobex-cvs/apps/Makefile.am 2006-12-18 02:57:19.976445506 +0100
@@ -14,11 +14,11 @@
obex_test_server.c obex_test_server.h \
obex_test_cable.c obex_test_cable.h
-obex_test_LDADD = $(top_builddir)/lib/libopenobex.la @BLUEZ_LIBS@ libmisc.a
+obex_test_LDADD = $(top_builddir)/lib/libopenobex.la @BLUETOOTH_LIBS@ libmisc.a
LDADD = $(top_builddir)/lib/libopenobex.la libmisc.a
-INCLUDES = @BLUEZ_CFLAGS@ -I$(top_builddir)/include
+INCLUDES = @BLUETOOTH_CFLAGS@ -I$(top_builddir)/include
endif
MAINTAINERCLEANFILES = Makefile.in
Index: openobex-cvs/acinclude.m4
===================================================================
--- openobex-cvs.orig/acinclude.m4 2006-12-18 02:56:43.750181506 +0100
+++ openobex-cvs/acinclude.m4 2006-12-18 02:57:20.000447006 +0100
@@ -76,9 +76,16 @@
])
AC_DEFUN([AC_PATH_BLUEZ], [
- PKG_CHECK_MODULES(BLUEZ, bluez, bluez_found=yes, AC_MSG_RESULT(no))
- AC_SUBST(BLUEZ_CFLAGS)
- AC_SUBST(BLUEZ_LIBS)
+ PKG_CHECK_MODULES(BLUETOOTH, bluez, bluez_found=yes, AC_MSG_RESULT(no))
+])
+
+AC_DEFUN([AC_PATH_WINBT], [
+ AC_CACHE_CHECK([for Windows Bluetooth support],winbt_found,[
+ AC_CHECK_HEADERS(ws2bth.h, winbt_found=yes, winbt_found=no,
+ [
+ #include <winsock2.h>
+ ])
+ ])
])
AC_DEFUN([AC_PATH_BLUETOOTH], [
@@ -92,7 +99,12 @@
*-*-netbsd*)
AC_PATH_NETBSDBT
;;
+ *-*-mingw32*)
+ AC_PATH_WINBT
+ ;;
esac
+ AC_SUBST(BLUETOOTH_CFLAGS)
+ AC_SUBST(BLUETOOTH_LIBS)
])
AC_DEFUN([AC_PATH_USB], [
@@ -191,6 +203,10 @@
AC_DEFINE(HAVE_BLUETOOTH_LINUX, 1, [Define if system supports Bluetooth stack for Linux])
fi
+ if (test "${bluetooth_enable}" = "yes" && test "${winbt_found}" = "yes"); then
+ AC_DEFINE(HAVE_BLUETOOTH, 1, [Define if system supports Bluetooth and it's enabled])
+ fi
+
if (test "${usb_enable}" = "yes" && test "${usb_found}" = "yes"); then
AC_DEFINE(HAVE_USB, 1, [Define if system supports USB and it's enabled])
AC_CHECK_FILE(${prefix}/lib/pkgconfig/libusb.pc, REQUIRES="libusb")
Index: openobex-cvs/lib/btobex.h
===================================================================
--- openobex-cvs.orig/lib/btobex.h 2006-12-18 02:56:43.506166256 +0100
+++ openobex-cvs/lib/btobex.h 2006-12-18 02:57:20.024448506 +0100
@@ -30,6 +30,33 @@
#ifndef BTOBEX_H
#define BTOBEX_H
+#ifdef HAVE_BLUETOOTH
+#ifdef _WIN32
+#include <winsock2.h>
+#include <ws2bth.h>
+#define bdaddr_t BTH_ADDR
+
+#else /* _WIN32 */
+#if defined(HAVE_BLUETOOTH_LINUX)
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/rfcomm.h>
+
+#elif defined(HAVE_BLUETOOTH_FREEBSD)
+#include <bluetooth.h>
+
+#elif defined(HAVE_BLUETOOTH_NETBSD)
+#include <bluetooth.h>
+#include <netbt/rfcomm.h>
+#endif
+#endif /* _WIN32 */
+
+#else /* HAVE_BLUETOOTH */
+#define bdaddr_t char
+
+#endif /* HAVE_BLUETOOTH */
+
+#include <inttypes.h>
+
void btobex_prepare_connect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel);
void btobex_prepare_listen(obex_t *self, bdaddr_t *src, uint8_t channel);
int btobex_listen(obex_t *self);
Index: openobex-cvs/lib/obex.c
===================================================================
--- openobex-cvs.orig/lib/obex.c 2006-12-18 02:56:43.550169006 +0100
+++ openobex-cvs/lib/obex.c 2006-12-18 02:57:20.040449506 +0100
@@ -39,13 +39,14 @@
#ifdef _WIN32
#include <winsock2.h>
-#define ESOCKTNOSUPPORT 1
-#else /* _WIN32 */
+#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
+#else /* _WIN32 */
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
-#endif
+
+#endif /* _WIN32 */
#include "obex_main.h"
#include "obex_object.h"
@@ -53,17 +54,22 @@
#include "obex_client.h"
#include "inobex.h"
+
#ifdef HAVE_IRDA
#include "irobex.h"
#endif
+
#ifdef HAVE_USB
#include "usbobex.h"
#endif
+
#ifdef HAVE_BLUETOOTH
#include "btobex.h"
-#ifdef HAVE_BLUETOOTH_FREEBSD
-#define BDADDR_ANY NG_HCI_BDADDR_ANY
-#endif
+# if _WIN32
+# define BDADDR_ANY BTH_ADDR_NULL
+# elif defined(HAVE_BLUETOOTH_FREEBSD)
+# define BDADDR_ANY NG_HCI_BDADDR_ANY
+# endif
#else
// This is to workaround compilation without Bluetooth support. - Jean II
typedef char *bdaddr_t;
Index: openobex-cvs/lib/obex_transport.h
===================================================================
--- openobex-cvs.orig/lib/obex_transport.h 2006-12-18 02:56:43.598172006 +0100
+++ openobex-cvs/lib/obex_transport.h 2006-12-18 02:57:20.064451006 +0100
@@ -30,29 +30,32 @@
#ifndef OBEX_TRANSPORT_H
#define OBEX_TRANSPORT_H
-#ifdef _WIN32
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
#endif
#ifdef HAVE_IRDA
#include "irda_wrap.h"
#endif /*HAVE_IRDA*/
-#ifdef HAVE_BLUETOOTH
-#ifdef HAVE_BLUETOOTH_LINUX
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/rfcomm.h>
+
+#ifndef _WIN32
+#include <netinet/in.h>
#endif
-#ifdef HAVE_BLUETOOTH_FREEBSD
-#include <bluetooth.h>
+
+#ifdef HAVE_BLUETOOTH
+#include <btobex.h>
+#if defined(_WIN32)
+#define sockaddr_rc _SOCKADDR_BTH
+
+#elif defined(HAVE_BLUETOOTH_FREEBSD)
#define sockaddr_rc sockaddr_rfcomm
-#endif
-#ifdef HAVE_BLUETOOTH_NETBSD
-#include <bluetooth.h>
-#include <netbt/rfcomm.h>
+
+#elif defined(HAVE_BLUETOOTH_NETBSD)
+#define sockaddr_rc sockaddr_bt
#endif
#endif /*HAVE_BLUETOOTH*/
+
+
#ifdef HAVE_USB
#include "usbobex.h"
#endif /*HAVE_USB*/
@@ -65,12 +68,7 @@
#endif /*HAVE_IRDA*/
struct sockaddr_in inet;
#ifdef HAVE_BLUETOOTH
-#ifdef HAVE_BLUETOOTH_LINUX
struct sockaddr_rc rfcomm;
-#endif
-#ifdef HAVE_BLUETOOTH_NETBSD
- struct sockaddr_bt rfcomm;
-#endif
#endif /*HAVE_BLUETOOTH*/
#ifdef HAVE_USB
struct obex_usb_intf_transport_t usb;
Index: openobex-cvs/lib/databuffer.c
===================================================================
--- openobex-cvs.orig/lib/databuffer.c 2006-12-18 02:55:40.990259256 +0100
+++ openobex-cvs/lib/databuffer.c 2006-12-18 02:57:09.015760506 +0100
@@ -33,6 +33,8 @@
#include <stdio.h>
#include <string.h>
+#include "obex_main.h"
+
slist_t *slist_append(slist_t *list, void *element)
{
slist_t *node, *p;
@@ -286,22 +288,14 @@
n = 0;
for (i = 0; i < p->data_size; ++i) {
-#ifndef OBEX_SYSLOG
- if (n == 0)
- fprintf(stderr, "%s: ", label);
- fprintf(stderr, "%02X ", p->data[i]);
- if (n >= 25 || i == p->data_size - 1) {
- fprintf(stderr, "\n");
-#else
if (n == 0)
- syslog(LOG_DEBUG, "OpenObex: %s: ", label);
- syslog(LOG_DEBUG, "%02X ", p->data[i]);
+ log_debug("%s%s:", log_debug_prefix, label);
+ log_debug(" %02X", p->data[i]);
if (n >= 25 || i == p->data_size - 1) {
- syslog(LOG_DEBUG, "\n");
-#endif
- n = -1;
- }
- n++;
+ log_debug("\n");
+ n = 0;
+ } else
+ n++;
}
}
Index: openobex-cvs/lib/obex_main.h
===================================================================
--- openobex-cvs.orig/lib/obex_main.h 2006-12-18 02:56:43.462163506 +0100
+++ openobex-cvs/lib/obex_main.h 2006-12-18 02:57:09.019760756 +0100
@@ -61,45 +61,43 @@
#include "obex_transport.h"
#include "databuffer.h"
-#ifdef OBEX_SYSLOG
+
+#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
+#include <stdio.h>
+#define log_debug(format, args...) fprintf(stderr, format, ##args)
+#define log_debug_prefix ""
#endif
-/* use 0 for none, 1 for sendbuff, 2 for receivebuff and 3 for both */
-#ifndef OBEX_DUMP
-#define OBEX_DUMP 0
-#endif
-/* use 0 for production, 1 for verification, >2 for debug */
-#ifndef OBEX_DEBUG
-#define OBEX_DEBUG 0
+/* use integer: 0 for production
+ * 1 for verification
+ * >2 for debug
+ */
+#if OBEX_DEBUG
+extern int obex_debug;
+#define DEBUG(n, format, args...) \
+ if (obex_debug >= (n)) \
+ log_debug("%s%s(): " format, log_debug_prefix, __FUNCTION__, ##args)
+#else
+#define DEBUG(n, format, args...)
#endif
-#ifndef _WIN32
-# if OBEX_DEBUG
-extern int obex_debug;
-# ifdef OBEX_SYSLOG
-# define DEBUG(n, format, args...) if (obex_debug >= (n)) syslog(LOG_DEBUG, "OpenOBEX: %s(): " format, __FUNCTION__ , ##args)
-# else
-# define DEBUG(n, format, args...) if (obex_debug >= (n)) fprintf(stderr, "%s(): " format, __FUNCTION__ , ##args)
-# endif /* OBEX_SYSLOG */
-# else
-# define DEBUG(n, format, args...)
-# endif /* OBEX_DEBUG != 0 */
-
-# if OBEX_DUMP
+/* use bitmask: 0x1 for sendbuff
+ * 0x2 for receivebuff
+ */
+#if OBEX_DUMP
extern int obex_dump;
-# define DUMPBUFFER(n, label, msg) if (obex_dump & (n)) buf_dump(msg, label);
-# else
-# define DUMPBUFFER(n, label, msg)
-# endif /* OBEX_DUMP != 0 */
-
-#else /* _WIN32 */
-#define DEBUG(n, format, args...)
+#define DUMPBUFFER(n, label, msg) \
+ if ((obex_dump & 0x3) & (n)) buf_dump(msg, label);
+#else
#define DUMPBUFFER(n, label, msg)
+#endif
-#endif /* _WIN32 */
#define OBEX_VERSION 0x10 /* OBEX Protocol Version 1.1 */
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users