diff -ruN sobexsrv-1.0.1/src/fs.c sobexsrv-1.0.1-new/src/fs.c
--- sobexsrv-1.0.1/src/fs.c	2007-10-06 17:54:03.000000000 +0200
+++ sobexsrv-1.0.1-new/src/fs.c	2007-10-26 14:15:00.000000000 +0200
@@ -59,7 +59,7 @@
 	struct tm ttime;
 	char item[LINE_LENGTH];
 	unsigned int line_leng;
-	unsigned out_leng;
+	unsigned int out_leng = 0;
 	int s_gu = 1;
 	int s_gunum = 0;
 	int s_perms = 1;
@@ -85,11 +85,11 @@
 	}
 	
 	if (params != NULL) {
-		s_gu = (int) strchr(params, 'O');
-		s_gunum = (int) strchr(params, 'N');
-		s_perms = (int) strchr(params, 'P');
-		s_times = (int) strchr(params, 'T');
-		s_dotdot = (int) strchr(params, 'D');
+		s_gu = strchr(params, 'O') ? 1 : 0;
+		s_gunum = strchr(params, 'N') ? 1 : 0;
+		s_perms = strchr(params, 'P') ? 1 : 0;
+		s_times = strchr(params, 'T') ? 1 : 0;
+		s_dotdot = strchr(params, 'D') ? 1 : 0;
 	}
 	
 	e = readdir(d);
diff -ruN sobexsrv-1.0.1/src/obexsrv.c sobexsrv-1.0.1-new/src/obexsrv.c
--- sobexsrv-1.0.1/src/obexsrv.c	2007-10-06 18:36:51.000000000 +0200
+++ sobexsrv-1.0.1-new/src/obexsrv.c	2007-10-26 14:11:40.000000000 +0200
@@ -44,26 +44,6 @@
 server_context context;
 static handler_func handler;
 
-void debug4(char *m1, char *m2, char *m3, char *m4)
-{
-	if (!context.daemon) fprintf(stderr, m1, m2, m3, m4);
-}
-
-void debug(char *m1)
-{
-	debug4(m1, NULL, NULL, NULL);
-}
-
-void debug2(char *m1, char *m2)
-{
-	debug4(m1, m2, NULL, NULL);
-}
-
-void debug3(char *m1, char *m2, char *m3)
-{
-	debug4(m1, m2, m3, NULL);
-}
-
 void UnicodeToChar(uint8_t *c, const uint8_t *uc, int size)
 {
 	iconv_t dsc = iconv_open(nl_langinfo(CODESET),"UTF16BE");
@@ -73,7 +53,7 @@
 	isiz = osiz=size;
 
 	if (iconv(dsc,&ip,&isiz,&op,&osiz) == -1) {
-		debug2("iconv: error %s\n", strerror(errno));
+		debug_printf("iconv: error %s\n", strerror(errno));
 		OBEX_UnicodeToChar(c,uc,size);
 	}
 	iconv_close(dsc);
@@ -102,7 +82,7 @@
 	int res = 0;
 	int opt;
 		
-	debug3("%s: mode = %d\n", (char*)__func__, (char*)mode);
+	debug_printf("%s: mode = %d\n", (char*)__func__, mode);
 	
 	switch (mode) {
 	case 0:
@@ -135,7 +115,7 @@
 		}
 		break;
 	case 4:
-		debug2("%s: wait until connect before security mode is decided\n", (char*)__func__);
+		debug_printf("%s: wait until connect before security mode is decided\n", (char*)__func__);
 		return(1);
 		break;
 	}
@@ -183,7 +163,7 @@
 		free(fullpath);
 		fullpath = tmp;
 		if (strncmp(fullpath, context.rootdir, strlen(context.rootdir)) != 0) {
-			debug3("%s: path check failed for: %s\n", (char*)__func__, fullpath);
+			debug_printf("%s: path check failed for: %s\n", (char*)__func__, fullpath);
 			free(fullpath);
 			fullpath = NULL;
 		}
@@ -247,7 +227,7 @@
 					}
 				}
 				
-				debug3("%s: lsdir for: \"%s\"\n", (char*)__func__, path);
+				debug_printf("%s: lsdir for: \"%s\"\n", (char*)__func__, path);
 				
 				lsdir(path, context.lsdir_params, &data);
 				if (data != NULL) {
@@ -258,11 +238,11 @@
 					context.data_length = sprintf((char*)context.data, "%s%s%s", OBEX_FTP_FOLDER_LISTING_START_PARENT, data, OBEX_FTP_FOLDER_LISTING_END);
 					free(data);
 					
-					debug2("%s", (char*)context.data);
+					debug_printf("%s", (char*)context.data);
 					ret = 1;
 				}
 				else {
-					debug2("%s: lsdir didn't return data!\n", (char*)__func__);
+					debug_printf("%s: lsdir didn't return data!\n", (char*)__func__);
 					goto out_err_folder_listing;
 				}
 				
@@ -272,17 +252,17 @@
 				return(ret);
 			}
 			else {
-				debug2("%s: target check failed\n", (char*)__func__);
+				debug_printf("%s: target check failed\n", (char*)__func__);
 deny_folder_listing:
 				return(0);
 			}
 		}
 		// handle generic mime type get
 		else if (context.type && !context.filename) {
-			debug3("%s: generic mime request for: %s\n", (char*)__func__, context.type);
+			debug_printf("%s: generic mime request for: %s\n", (char*)__func__, context.type);
 			
 			if (strstr(context.type, "..")) {
-				debug2("%s: mime type contains unsafe \"..\"\n", (char*)__func__);
+				debug_printf("%s: mime type contains unsafe \"..\"\n", (char*)__func__);
 				return(0);
 			}
 			if (context.mime_type_dir) {			
@@ -297,14 +277,14 @@
 				goto generic_mime_type_get;
 			}
 			else {
-				debug2("%s: no mime_type_dir specified\n", (char*)__func__);
+				debug_printf("%s: no mime_type_dir specified\n", (char*)__func__);
 				return(0);
 			}
 		}
 		// normal get
 		else if (context.filename) {			
 			if ((fullpath = getfullpath()) == NULL) {
-				debug2("%s: invalid pathname\n", (char*)__func__);
+				debug_printf("%s: invalid pathname\n", (char*)__func__);
 				dosyslog("pull failed (invalid pathname)\n", 0, 0);
 				return(0);
 			}
@@ -315,10 +295,10 @@
 			 */
 			if (1 == 2) {
 generic_mime_type_get:
-				debug2("%s: get from generic mime type\n", (char*)__func__);
+				debug_printf("%s: get from generic mime type\n", (char*)__func__);
 			}
 			
-			debug3("%s: get for \"%s\"\n", (char*)__func__, fullpath);
+			debug_printf("%s: get for \"%s\"\n", (char*)__func__, fullpath);
 		
 			if ((fp = open(fullpath, O_RDONLY)) < 0) {
 				goto get_out;
@@ -343,18 +323,18 @@
 			return(ret);
 		}
 		else {
-			debug2("%s: get without filename!\n", (char*)__func__);
+			debug_printf("%s: get without filename!\n", (char*)__func__);
 			return(0);
 		}
 	}
 	else if (strcmp(friendlyname, "put") == 0) {
 		if ((fullpath = getfullpath()) == NULL) {
-			debug2("%s: invalid pathname\n", (char*)__func__);
+			debug_printf("%s: invalid pathname\n", (char*)__func__);
 			dosyslog("push failed (invalid pathname)\n", 0, 0);
 			return(0);
 		}
 		
-		debug4("%s: put for \"%s\" length=%d\n", (char*)__func__, fullpath, (char*)context.data_length);
+		debug_printf("%s: put for \"%s\" length=%d\n", (char*)__func__, fullpath, context.data_length);
 		
 		if ((fp = open(fullpath, O_WRONLY|O_CREAT, 0666)) < 0) {
 			goto put_out;
@@ -383,12 +363,12 @@
 		}
 		*/
 		if ((fullpath = getfullpath()) == NULL) {
-			debug2("%s: delete: invalid path\n", (char*)__func__);
+			debug_printf("%s: delete: invalid path\n", (char*)__func__);
 			dosyslog("delete failed (invalid path)\n", 0, 0);
 			return(0);
 		}
 		
-		debug3("%s: delete for \"%s\"\n", (char*)__func__, fullpath);
+		debug_printf("%s: delete for \"%s\"\n", (char*)__func__, fullpath);
 	
 		if (stat(fullpath, &di) == 0) {
 			if (S_ISDIR(di.st_mode)) {
@@ -396,7 +376,7 @@
 					ret = 1;
 				}
 				else {
-					debug3("%s: deleting directory \"%s\" failed\n", (char*)__func__, fullpath);
+					debug_printf("%s: deleting directory \"%s\" failed\n", (char*)__func__, fullpath);
 				}
 			}
 			else {
@@ -404,7 +384,7 @@
 					ret = 1;
 				}
 				else {
-					debug3("%s: deleting file \"%s\" failed\n", (char*)__func__, fullpath);
+					debug_printf("%s: deleting file \"%s\" failed\n", (char*)__func__, fullpath);
 				}
 			}
 		}
@@ -450,7 +430,7 @@
 		}
 		*/
 		
-		debug3("%s: setpath for \"%s\"\n", (char*)__func__, fullpath);
+		debug_printf("%s: setpath for \"%s\"\n", (char*)__func__, fullpath);
 		
 		if (stat(fullpath, &di) == 0) {
 			if (S_ISDIR(di.st_mode)) {
@@ -463,7 +443,7 @@
 				dosyslog("created directory \"%s\"\n", fullpath, 0);
 			}
 			else {
-				debug3("%s: mkdir \"%s\" failed\n", (char*)__func__, fullpath);
+				debug_printf("%s: mkdir \"%s\" failed\n", (char*)__func__, fullpath);
 				ret = 0;
 				dosyslog("failed to create directory \"%s\"\n", fullpath, 0);
 			}
@@ -504,7 +484,7 @@
 	
 
 	if ((buf = malloc(BUFSIZE)) == NULL) {
-		debug2("%s: can't alloc memory\n", (char*)__func__);
+		debug_printf("%s: can't alloc memory\n", (char*)__func__);
 		exit(-1);
 	}
 	
@@ -575,9 +555,9 @@
 	close(rd[1]);
 	close(wr[0]);
 	
-	debug2("handler: header buf size %d\n", (char*)strlen(buf));
+	debug_printf("handler: header buf size %lu\n", (long unsigned)strlen(buf));
 	if (nwrite(wr[1], buf, strlen(buf)) <= 0) {
-		debug("handler: write failed\n");
+		debug_printf("handler: write failed\n");
 		exit(-1);
 	}
 	free(buf);
@@ -586,7 +566,7 @@
 	if (strcmp(command, "put") == 0) {
 		if (context.data_type == 1) {
 			if (context.data == NULL) {
-				debug("handler: put with no body data\n");
+				debug_printf("handler: put with no body data\n");
 				exit(-1);
 			}
 			if (strcmp(friendlyname, "puthint") == 0) {
@@ -594,7 +574,7 @@
 			}
 			else {
 				if (nwrite(wr[1], context.data, context.data_length) <= 0) {
-					debug("handler: put body write failed\n");
+					debug_printf("handler: put body write failed\n");
 					exit(-1);
 				}
 			}
@@ -609,7 +589,7 @@
 		
 		do {
 			if (cread(rd[0], &buf[i], 1) <= 0) {
-				debug("handler: get read failed\n");
+				debug_printf("handler: get read failed\n");
 				break;
 			}
 			if (i > 2) {
@@ -621,24 +601,24 @@
 		if ((p = strstr(buf, "length:")) != NULL) {
 			context.data_length = strtol(p+7, NULL, 10);
 			if (context.data_length < 0) {
-				debug2("handler: get length error (%d)\n", (char*)context.data_length);
+				debug_printf("handler: get length error (%d)\n", context.data_length);
 				exit(-1);
 			}
-			debug2("handler: get length %d\n", (char*)context.data_length);
+			debug_printf("handler: get length %d\n", context.data_length);
 			
 			if (context.data_length > 0) {
 				if ((context.data = malloc(context.data_length)) == NULL) {
-					debug("handler: get data malloc failed\n");
+					debug_printf("handler: get data malloc failed\n");
 					exit(-1);
 				}
 				if ((cread(rd[0], context.data, context.data_length)) < context.data_length) {
-					debug("handler: get data read failed\n");
+					debug_printf("handler: get data read failed\n");
 					exit(-1);
 				}
 			}
 		}
 		else {
-			debug("handler: get result parse error\n");
+			debug_printf("handler: get result parse error\n");
 			exit(-1);
 		}
 	}
@@ -650,7 +630,7 @@
 		waitpid(pid, &handler_res, 0); // , WNOHANG);
 	} while (!WIFEXITED(handler_res));
 	
-	debug2("handler: returned with exit code %d\n", (char*)WEXITSTATUS(handler_res));
+	debug_printf("handler: returned with exit code %d\n", WEXITSTATUS(handler_res));
 	return(WEXITSTATUS(handler_res));
 }
 
@@ -701,14 +681,14 @@
 	int ret = 0;
 	
 
-	debug("CONNECT start\n");
+	debug_printf("CONNECT start\n");
 
 	while (OBEX_ObjectGetNextHeader(handle, oo, &hi, &hv, &hlen))	{
 		switch (hi) {
 		case OBEX_HDR_CONNECTION:
 			context.connection_id = hv.bq4;
 			
-			debug2("CONNECT connection id: %d\n", (char*)hv.bq4);
+			debug_printf("CONNECT connection id: %d\n", hv.bq4);
 			break;
 		case OBEX_HDR_TARGET:
 			if ((context.target = malloc(hlen+1))) {
@@ -716,23 +696,23 @@
 				memcpy(context.target, hv.bs, hlen);
 				context.target_length = hlen;
 				
-				debug("CONNECT target ");
+				debug_printf("CONNECT target ");
 				if ((unsigned char)context.target[0] > 'z') {
 					for (i = 0; i < hlen; i++) {
-						debug2("%0.2X", (char*)((int)hv.bs[i]));
+						debug_printf("%02X", (int)hv.bs[i]);
 					}
-					debug("\n");
+					debug_printf("\n");
 				}
 				else {
-					debug2("%s\n", context.target);
+					debug_printf("%s\n", context.target);
 				}
 			}
 			else {
-				debug("CONNECT target malloc error\n");
+				debug_printf("CONNECT target malloc error\n");
 			}
 			break;
 		default:
-			debug2("CONNECT skipped header %02x\n", (char*)((int)hi));
+			debug_printf("CONNECT skipped header %02x\n", (int)hi);
 			break;
 		}
 	}
@@ -741,13 +721,13 @@
 	
 	switch (handler_res) {
 	case -1:
-		debug("CONNECT handler error\n");
+		debug_printf("CONNECT handler error\n");
 		exit(-1);
 		break;
 	case 1:
 	case 2:
 	case 3:
-		debug2("CONNECT ok, result = %d\n", (char*)handler_res);
+		debug_printf("CONNECT ok, result = %d\n", handler_res);
 		if (context.security == 4 || context.security == 0) {
 			if (security(handler_res)) {
 				OBEX_ObjectSetRsp(oo, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
@@ -765,27 +745,27 @@
 		}
 		break;
 	default:
-		debug("CONNECT deny (fix me!)\n");
+		debug_printf("CONNECT deny (fix me!)\n");
 		// FIX ME
 err:
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
 		break;
 	}
 
-	debug("CONNECT end\n");
+	debug_printf("CONNECT end\n");
 
 	return(ret);
 }
 
 int cmd_disconnect(obex_t *handle, obex_object_t *oo)
 {
-	debug("DISCONNECT start\n");
+	debug_printf("DISCONNECT start\n");
 
 	OBEX_ObjectSetRsp(oo, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
 	
 	if (context.mode) dosyslog("disconnecting...\n", 0,0);
 	
-	debug("DISCONNECT end\n");
+	debug_printf("DISCONNECT end\n");
 	
 	return(1);
 }
@@ -799,7 +779,7 @@
 	int ret;
 
 	
-	debug("SETPATH start\n");
+	debug_printf("SETPATH start\n");
 
 	while (OBEX_ObjectGetNextHeader(handle, oo, &hi, &hv, &hlen))	{
 		switch (hi) {
@@ -865,12 +845,12 @@
 			else {
 				if (context.path) free(context.path);
 				context.path = NULL;
-				debug("SETPATH with empty name\n");
+				debug_printf("SETPATH with empty name\n");
 			}
-			debug2("SETPATH path %s\n", context.path);
+			debug_printf("SETPATH path %s\n", context.path);
 			break;
 		default:
-			debug2("SETPATH skipped header %02x\n", (char*)((int)hi));
+			debug_printf("SETPATH skipped header %02x\n", (int)hi);
 			break;
 		}
 	}
@@ -879,7 +859,7 @@
 	 *  treat no name_hdr as empty name_hdr
 	 */
 	if (!ispath) {
-		debug("SETPATH no name header\n");
+		debug_printf("SETPATH no name header\n");
 nonamehdr:
 		if (context.path) free(context.path);
 		context.path = NULL;
@@ -889,23 +869,23 @@
 	
 	switch (ret) {
 	case -1:
-		debug("SETPATH handler error\n");
+		debug_printf("SETPATH handler error\n");
 		exit(-1);
 		break;
 	case 1:
-		debug("SETPATH ok\n");
+		debug_printf("SETPATH ok\n");
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
 		//hv.bq4 = context.connection_id;
 		//OBEX_ObjectAddHeader(handle, oo, OBEX_HDR_CONNECTION, hv, sizeof(uint32_t), 0);
 		break;
 	default:
-		debug("SETPATH deny (fix me!)\n");
+		debug_printf("SETPATH deny (fix me!)\n");
 		// FIX ME
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
 		break;
 	}
 
-	debug("SETPATH end\n");
+	debug_printf("SETPATH end\n");
 	context_clear(0);
 	return(1);
 }
@@ -917,7 +897,7 @@
 	unsigned int hlen;
 
 	
-	debug("GET start\n");
+	debug_printf("GET start\n");
 
 	while (OBEX_ObjectGetNextHeader(handle, oo, &hi, &hv, &hlen))	{
 		switch (hi) {
@@ -925,7 +905,7 @@
 			if ((context.filename = (char*) malloc(hlen + 1))) {
 				bzero(context.filename, hlen + 1);
 				UnicodeToChar((unsigned char*)context.filename, hv.bs, hlen);
-				debug2("GET filename: %s\n", context.filename);
+				debug_printf("GET filename: %s\n", context.filename);
 			}
 			else {
 				perror("cmd_get malloc:");
@@ -936,7 +916,7 @@
 		if ((context.type = (char*) malloc(hlen + 1))) {
 				bzero(context.type, hlen + 1);
 				memcpy(context.type, hv.bs, hlen);	
-				debug2("GET type: %s\n", context.type);
+				debug_printf("GET type: %s\n", context.type);
 			}
 			else {
 				perror("cmd_get malloc:");
@@ -944,21 +924,21 @@
 			}
 			break;
 		case OBEX_HDR_CONNECTION:
-			debug2("GET connection %d\n", (char*)((int)hv.bq4));
+			debug_printf("GET connection %d\n", (int)hv.bq4);
 			break;
 		default:
-			debug2("GET skipped header %02x\n", (char*)((int)hi));
+			debug_printf("GET skipped header %02x\n", (int)hi);
 			break;
 		}
 	}
 
 	switch (handler("get", "get")) {
 	case -1:
-		debug("GET handler error\n");
+		debug_printf("GET handler error\n");
 		exit(-1);
 		break;
 	case 1:
-		debug("GET ok\n");
+		debug_printf("GET ok\n");
 		if (context.data_length > 0) {
 			// FIX ME (more header fields?)
 			OBEX_ObjectSetRsp(oo, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
@@ -968,7 +948,7 @@
 			OBEX_ObjectAddHeader(handle, oo, OBEX_HDR_LENGTH, hv, sizeof(uint32_t), 0);
 		}
 		else {
-			debug("GET ok (body length <= 0)\n");
+			debug_printf("GET ok (body length <= 0)\n");
 			OBEX_ObjectSetRsp(oo, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
 			hv.bq4 = context.data_length;
 			OBEX_ObjectAddHeader(handle, oo, OBEX_HDR_LENGTH, hv, sizeof(uint32_t), 0);
@@ -976,7 +956,7 @@
 		}
 		break;
 	default:
-		debug("GET deny (fix me!)\n");
+		debug_printf("GET deny (fix me!)\n");
 		// FIX ME
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
 		break;
@@ -993,7 +973,7 @@
 	unsigned int hlen;
 
 
-	debug("PUT start\n");
+	debug_printf("PUT start\n");
 
 	while (OBEX_ObjectGetNextHeader(handle, oo, &hi, &hv, &hlen))	{
 		switch (hi) {
@@ -1003,14 +983,14 @@
 			if (hlen > 0) context.data_type = 1;
 			else context.data_type = 2;
 			
-			debug2("PUT body length: %d\n", (char*)hlen);
+			debug_printf("PUT body length: %d\n", hlen);
 			break;
 		case OBEX_HDR_NAME:
 			if ((context.filename = (char*) malloc(hlen + 1)))	{
 				bzero(context.filename, hlen + 1);
 				UnicodeToChar((unsigned char*)context.filename, hv.bs, hlen);
 
-				debug2("PUT name: %s\n", context.filename);
+				debug_printf("PUT name: %s\n", context.filename);
 			}
 			else {
 				perror("cmd_put malloc:");
@@ -1022,7 +1002,7 @@
 				bzero(context.type, hlen + 1);
 				memcpy(context.type, hv.bs, hlen);
 								
-				debug2("PUT type: %s\n", context.type);
+				debug_printf("PUT type: %s\n", context.type);
 			}
 			else {
 				perror("cmd_put malloc:");
@@ -1034,19 +1014,19 @@
 				context.data_length = hv.bq4;
 			}
 			else {
-				debug3("PUT: length_header=%d body_length=%d WTF?\n", (char*)hv.bq4, (char*)context.data_length);
+				debug_printf("PUT: length_header=%d body_length=%d WTF?\n", hv.bq4, context.data_length);
 			}
 			
-			debug2("PUT length: %d\n", (char*)context.data_length);
+			debug_printf("PUT length: %d\n", context.data_length);
 			break;
 		case OBEX_HDR_TIME:
-			debug2("PUT time: %u (fix me!)\n", (char*)((int)hv.bq4));
+			debug_printf("PUT time: %u (fix me!)\n", (uint)hv.bq4);
 			break;
 		case OBEX_HDR_DESCRIPTION:
 			if ((context.description = (char*) malloc(hlen + 1)))	{
 				bzero(context.description, hlen + 1);
 				UnicodeToChar((unsigned char*)context.description, hv.bs, hlen);
-				debug2("PUT description: %s\n", context.description);
+				debug_printf("PUT description: %s\n", context.description);
 			}
 			else {
 				perror("cmd_put malloc:");
@@ -1055,37 +1035,37 @@
 			break;
 		case OBEX_HDR_COUNT:
 			context.count = hv.bq4;
-			debug2("PUT count: %d\n", (char*)context.count);
+			debug_printf("PUT count: %d\n", context.count);
 			break;
 		default:
-			debug2("skipped header %02x\n", (char*)((int)hi));
+			debug_printf("skipped header %02x\n", (int)hi);
 			break;
 		}
 	}
 
 	if (context.filename == NULL)	{
-		debug("PUT warning - no name!\n");
+		debug_printf("PUT warning - no name!\n");
 	}
 
-	debug2("PUT data_type %d\n", (char*)context.data_type);
+	debug_printf("PUT data_type %d\n", context.data_type);
 
 	switch(handler("put", (context.data_length == 0) ? "delete" : "put")) {
 	case -1:
-		debug("PUT handler error\n");
+		debug_printf("PUT handler error\n");
 		exit(-1);
 		break;
 	case 1:
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
-		debug("PUT ok\n");
+		debug_printf("PUT ok\n");
 		break;
 	default:
 		// FIX ME
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
-		debug("PUT deny - fix me!\n");
+		debug_printf("PUT deny - fix me!\n");
 		break;
 	}
 
-	debug("PUT end\n");
+	debug_printf("PUT end\n");
 	/* 
 	 *  set to null so clear context doesn't touch it
 	 *  obexlib will free this memory!
@@ -1099,7 +1079,7 @@
 {
 	switch (event) {
 	case OBEX_EV_PROGRESS:
-		debug("PROGRESS\n");
+		debug_printf("PROGRESS\n");
 		break;
 
 	case OBEX_EV_REQDONE:
@@ -1108,13 +1088,13 @@
 			OBEX_TransportDisconnect(handle);
 			break;
 		default:
-			debug("REQDONE\n");
+			debug_printf("REQDONE\n");
 			break;
 		}
 		break;
 		
 	case OBEX_EV_REQHINT:
-		debug("REQHINT - add handler for this!\n");
+		debug_printf("REQHINT - add handler for this!\n");
 		OBEX_ObjectSetRsp(oo, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
 		break;
 
@@ -1125,7 +1105,7 @@
 			break;
 		case OBEX_CMD_CONNECT:
 			if (!cmd_connect(handle, oo)) {
-				debug2("%s: connect failed\b", (char*)__func__);
+				debug_printf("%s: connect failed\b", (char*)__func__);
 				goto disconnect;
 			}
 			break;
@@ -1155,13 +1135,13 @@
 				if (!security(1))
 					goto disconnect;
 			}
-			debug("REQ unknown\n");
+			debug_printf("REQ unknown\n");
 			break;
 		}
 		break;
 		
 	case OBEX_EV_LINKERR:
-		debug("LINKERR\n");
+		debug_printf("LINKERR\n");
 		break;
 	
 	case OBEX_EV_UNEXPECTED:
@@ -1169,7 +1149,7 @@
 		break;
 	
 	case OBEX_EV_ABORT:
-		debug("CLIENT ABORT\n");
+		debug_printf("CLIENT ABORT\n");
 		cmd_disconnect(handle, oo);
 		break;
 	
@@ -1355,13 +1335,13 @@
 			exit(-1);
 		}
 		else {
-			if (context.chroot) debug2("doing chroot(%s)\n", context.rootdir);
+			if (context.chroot) debug_printf("doing chroot(%s)\n", context.rootdir);
 			if (setuid(getuid()) < 0) {
 				perror("setuid(getuid()) failed: ");
 				exit(-1);
 			}
 			else {
-				debug2("dropping privileges setuid(%d)\n", (char*)getuid());
+				debug_printf("dropping privileges setuid(%d)\n", getuid());
 			}
 		}
 	}
@@ -1461,26 +1441,26 @@
 			// invoke accept handler	
 			handler_res = handler("accept", "accept");
 			if (handler_res == -1) {
-				debug2("%s: accept handler failed\n", (char*)__func__);
+				debug_printf("%s: accept handler failed\n", (char*)__func__);
 				goto disconnect;
 			}
 			
 			// trigger security mode-2
 			if (!security(handler_res)) {
-				debug2("%s: security mode-2 failed or rejected\n", (char*)__func__);
+				debug_printf("%s: security mode-2 failed or rejected\n", (char*)__func__);
 				goto disconnect;
 			}
 			
 			// setup obex session
 			context.libObex = OBEX_Init(OBEX_TRANS_FD, eventhandler, 0);
 			if (context.libObex == NULL) {
-				debug("OBEX can't initialize\n");
+				debug_printf("OBEX can't initialize\n");
 				goto disconnect;
 			}
 			OBEX_SetCustomData(context.libObex, (void*)&context);
 
 			if (FdOBEX_TransportSetup(context.libObex, context.client, context.client, OBEX_DEFAULT_MTU) < 0) {
-				debug("OBEX can't setup transport\n");
+				debug_printf("OBEX can't setup transport\n");
 				goto disconnect;
 			}
 
diff -ruN sobexsrv-1.0.1/src/obexsrv.h sobexsrv-1.0.1-new/src/obexsrv.h
--- sobexsrv-1.0.1/src/obexsrv.h	2007-10-06 18:47:25.000000000 +0200
+++ sobexsrv-1.0.1-new/src/obexsrv.h	2007-10-26 11:48:25.000000000 +0200
@@ -19,6 +19,8 @@
 #ifndef __OBEXSRV_H__
 #define __OBEXSRV_H__
 
+#define debug_printf(...) do { if(!context.daemon) printf(__VA_ARGS__); } while (0);
+
 typedef int (*handler_func)(char*, char*);
 
 #define OBEX_FTP_TARGET 0xF9,0xEC,0x7B,0xC4,0x95,0x3C,0x11,0xD2,0x98,0x4E,0x52,0x54,0x00,0xDC,0x9E,0x09
diff -ruN sobexsrv-1.0.1/src/sdp.c sobexsrv-1.0.1-new/src/sdp.c
--- sobexsrv-1.0.1/src/sdp.c	2007-10-06 18:47:03.000000000 +0200
+++ sobexsrv-1.0.1-new/src/sdp.c	2007-10-26 11:47:48.000000000 +0200
@@ -40,9 +40,6 @@
 
 extern server_context context;
 
-extern void debug(char*);
-extern void debug2(char*, void*);
-
 /*
  * mostly  taken from sdptool of bluez-utils (www.bluez.org)
  */
@@ -63,7 +60,7 @@
 
 
 	if (!context.sdp_session) {
-		debug2("%s: sdp_session invalid\n", (char*)__func__);
+		debug_printf("%s: sdp_session invalid\n", (char*)__func__);
 		exit(-1);
 	}
 	session = context.sdp_session;
@@ -116,7 +113,7 @@
 	sdp_set_info_attr(context.sdp_record[0], "OBEX Object Push", 0, 0);
 
 	if (sdp_record_register(session, context.sdp_record[0], 0) < 0) {
-		debug2("%s: OBEX Object Push Service Record registration failed\n", (char*)__func__);
+		debug_printf("%s: OBEX Object Push Service Record registration failed\n", (char*)__func__);
 		exit(-1);
 	}
 	
@@ -138,7 +135,7 @@
 
 
 	if (!context.sdp_session) {
-		debug2("%s: sdp_session invalid\n", (char*)__func__);
+		debug_printf("%s: sdp_session invalid\n", (char*)__func__);
 		exit(-1);
 	}
 	session = context.sdp_session;
@@ -184,7 +181,7 @@
 	sdp_set_info_attr(context.sdp_record[1], "OBEX File Transfer", 0, 0);
 
 	if (sdp_record_register(session, context.sdp_record[1], 0) < 0) {
-		debug2("%s: OBEX File Transfer Service Record registration failed\n", (char*)__func__);
+		debug_printf("%s: OBEX File Transfer Service Record registration failed\n", (char*)__func__);
 		exit(-1);
 	}
 	
@@ -194,10 +191,10 @@
 void remove_sdp()
 {
 	if (context.sdp_ftp && sdp_record_unregister(context.sdp_session, context.sdp_record[1])) {
-		debug2("%s: OBEX File Transfer Service record unregistration failed.\n", (char*)__func__);
+		debug_printf("%s: OBEX File Transfer Service record unregistration failed.\n", (char*)__func__);
 	}
 	if (context.sdp_opush && sdp_record_unregister(context.sdp_session, context.sdp_record[0])) {
-		debug2("%s: OBEX Object Push Service record unregistration failed.\n", (char*)__func__);
+		debug_printf("%s: OBEX Object Push Service record unregistration failed.\n", (char*)__func__);
 	}
 	
 	sdp_close(context.sdp_session);
@@ -209,7 +206,7 @@
 		context.sdp_session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
 	}
 	if (!context.sdp_session) {
-		debug2("%s: sdp_session invalid\n", (char*)__func__);
+		debug_printf("%s: sdp_session invalid\n", (char*)__func__);
 		exit(-1);
 	}
 }
