1db2c04
diff --git a/Makefile.am b/Makefile.am
1db2c04
index 62a25d3..2c4d6f8 100644
1db2c04
--- a/Makefile.am
1db2c04
+++ b/Makefile.am
1db2c04
@@ -3,7 +3,7 @@
1db2c04
 #
1db2c04
 #  (c) 2004-2015 Copyright HP Development Company, LP
1db2c04
 #  Author: David Suffield, Naga Samrat Chowdary Narla, Sarbeswar Meher
1db2c04
-INCLUDES = -Iip -Iio/hpmud -Iscan/sane -Iprnt/hpijs -Icommon/
1db2c04
+INCLUDES = -Iip -Iio/hpmud -Iscan/sane -Iprnt/hpijs -Icommon/ -Iprotocol
1db2c04
 CFLAGS+= -DCONFDIR=\"$(hplip_confdir)\"
1db2c04
 CXXFLAGS+= -DCONFDIR=\"$(hplip_confdir)\"
1db2c04
 
1db2c04
@@ -304,7 +304,7 @@ dist_pcard_DATA = pcard/__init__.py pcard/photocard.py
1db2c04
 pcardextdir = $(pyexecdir)
1db2c04
 pcardext_LTLIBRARIES = pcardext.la
1db2c04
 pcardext_la_LDFLAGS = -module -avoid-version
1db2c04
-pcardext_la_SOURCES = pcard/pcardext/pcardext.c pcard/fat.c
1db2c04
+pcardext_la_SOURCES = pcard/pcardext/pcardext.c pcard/fat.c pcard/pcardext/pcardext.h
1db2c04
 pcardext_la_CFLAGS = -I$(PYTHONINCLUDEDIR)
1db2c04
 
1db2c04
 # prnt
1db2c04
@@ -316,7 +316,7 @@ lib_LTLIBRARIES += libhpipp.la
1db2c04
 #hpipp_LTLIBRARIES = hpipp.la
1db2c04
 #hpipp_la_LDFLAGS = -module -avoid-version
1db2c04
 libhpipp_la_SOURCES = protocol/hp_ipp.c protocol/hp_ipp.h protocol/hp_ipp_i.h
1db2c04
-libhpipp_la_CFLAGS = -DCONFDIR=\"$(hplip_confdir)\"
1db2c04
+libhpipp_la_CFLAGS = -DCONFDIR=\"$(hplip_confdir)\" -D_GNU_SOURCE
1db2c04
 libhpipp_la_LDFLAGS = -version-info 0:1:0
1db2c04
 libhpipp_la_LIBADD = libhpmud.la
1db2c04
 
1db2c04
diff --git a/common/utils.c b/common/utils.c
1db2c04
index d8ecee9..def4e47 100644
1db2c04
--- a/common/utils.c
1db2c04
+++ b/common/utils.c
1db2c04
@@ -1,5 +1,9 @@
1db2c04
+#ifndef _GNU_SOURCE
1db2c04
+#define _GNU_SOURCE
1db2c04
+#endif
1db2c04
+
1db2c04
 #include "utils.h"
1db2c04
-#include "string.h"
1db2c04
+#include <string.h>
1db2c04
 #include <dlfcn.h>
1db2c04
 #include <sys/stat.h>
1db2c04
 #include <errno.h>
1db2c04
diff --git a/io/hpmud/hpmud.c b/io/hpmud/hpmud.c
1db2c04
index 0eb6fff..358f279 100644
1db2c04
--- a/io/hpmud/hpmud.c
1db2c04
+++ b/io/hpmud/hpmud.c
1db2c04
@@ -759,6 +759,7 @@ enum HPMUD_RESULT hpmud_get_dstat(HPMUD_DEVICE dd, struct hpmud_dstat *ds)
1db2c04
    }
1db2c04
 
1db2c04
    strncpy(ds->uri, msp->device[dd].uri, sizeof(ds->uri));
1db2c04
+   ds->uri[sizeof(ds->uri)-1] = '\0';
1db2c04
    ds->io_mode = msp->device[dd].io_mode;
1db2c04
    ds->channel_cnt = msp->device[dd].channel_cnt;
1db2c04
    ds->mlc_up = msp->device[dd].mlc_up;
1db2c04
diff --git a/io/hpmud/jd.c b/io/hpmud/jd.c
1db2c04
index 06f5072..20df27a 100644
1db2c04
--- a/io/hpmud/jd.c
1db2c04
+++ b/io/hpmud/jd.c
1db2c04
@@ -31,6 +31,7 @@
1db2c04
 #endif
1db2c04
 
1db2c04
 #include <signal.h>
1db2c04
+#include <stdlib.h>
1db2c04
 #include "hpmud.h"
1db2c04
 #include "hpmudi.h"
1db2c04
 
1db2c04
diff --git a/io/hpmud/model.c b/io/hpmud/model.c
1db2c04
index 4ea8990..a917d69 100644
1db2c04
--- a/io/hpmud/model.c
1db2c04
+++ b/io/hpmud/model.c
1db2c04
@@ -117,6 +117,7 @@ static int ReadConfig()
1db2c04
       if (rcbuf[0] == '[')
1db2c04
       {
1db2c04
          strncpy(section, rcbuf, sizeof(section)); /* found new section */
1db2c04
+         section[sizeof(section)-1] = '\0';
1db2c04
          continue;
1db2c04
       }
1db2c04
 
1db2c04
@@ -125,6 +126,7 @@ static int ReadConfig()
1db2c04
       if ((strncasecmp(section, "[dirs]", 6) == 0) && (strcasecmp(key, "home") == 0))
1db2c04
       {
1db2c04
          strncpy(homedir, value, sizeof(homedir));
1db2c04
+         homedir[sizeof(homedir)-1] = '\0';
1db2c04
          break;  /* done */
1db2c04
       }
1db2c04
    }
1db2c04
diff --git a/io/hpmud/musb.c b/io/hpmud/musb.c
1db2c04
index 6e99c15..755493e 100644
1db2c04
--- a/io/hpmud/musb.c
1db2c04
+++ b/io/hpmud/musb.c
1db2c04
@@ -775,7 +775,7 @@ static int device_id(int fd, unsigned char *buffer, int size)
1db2c04
         len = size-1;   /* leave byte for zero termination */
1db2c04
     if (len > 2)
1db2c04
         len -= 2;
1db2c04
-    memcpy(buffer, buffer+2, len);    /* remove length */
1db2c04
+    memmove(buffer, buffer+2, len);    /* remove length */
1db2c04
     buffer[len]=0;
1db2c04
     DBG("read actual device_id successfully fd=%d len=%d\n", fd, len);
1db2c04
 
1db2c04
diff --git a/io/hpmud/pp.c b/io/hpmud/pp.c
1db2c04
index 74c5fdc..021d627 100644
1db2c04
--- a/io/hpmud/pp.c
1db2c04
+++ b/io/hpmud/pp.c
1db2c04
@@ -632,7 +632,7 @@ static int device_id(int fd, char *buffer, int size)
1db2c04
       len = size-1;   /* leave byte for zero termination */
1db2c04
    if (len > 2)
1db2c04
       len -= 2;
1db2c04
-   memcpy(buffer, buffer+2, len);    /* remove length */
1db2c04
+   memmove(buffer, buffer+2, len);    /* remove length */
1db2c04
    buffer[len]=0;
1db2c04
 
1db2c04
    DBG("read actual device_id successfully fd=%d len=%d\n", fd, len);
1db2c04
diff --git a/pcard/fat.c b/pcard/fat.c
1db2c04
index caa383f..e1425c0 100644
1db2c04
--- a/pcard/fat.c
1db2c04
+++ b/pcard/fat.c
1db2c04
@@ -519,14 +519,17 @@ int FatFreeSpace(void)
1db2c04
 
1db2c04
 int FatDiskAttributes( PHOTO_CARD_ATTRIBUTES * pa )
1db2c04
 {
1db2c04
-    strncpy( pa->OEMID, bpb.OEMID, 8 );
1db2c04
+    strncpy(pa->OEMID, bpb.OEMID, sizeof(pa->OEMID));
1db2c04
+    pa->OEMID[sizeof(pa->OEMID)-1] = '\0';
1db2c04
     pa->BytesPerSector = bpb.BytesPerSector;
1db2c04
     pa->SectorsPerCluster = bpb.SectorsPerCluster;
1db2c04
     pa->ReservedSectors = bpb.ReservedSectors;
1db2c04
     pa->SectorsPerFat = bpb.SectorsPerFat;
1db2c04
     pa->RootEntries = bpb.RootEntries;
1db2c04
-    strncpy( pa->SystemID, (char *)bpb.SystemID, 8 );
1db2c04
-    strncpy( pa->VolumeLabel, (char *)bpb.VolumeLabel, 11 );
1db2c04
+    strncpy(pa->SystemID, (char *)bpb.SystemID, sizeof(pa->SystemID));
1db2c04
+    pa->SystemID[sizeof(pa->SystemID)-1] = '\0';
1db2c04
+    strncpy(pa->VolumeLabel, (char *)bpb.VolumeLabel, sizeof(pa->VolumeLabel));
1db2c04
+    pa->VolumeLabel[sizeof(pa->VolumeLabel)-1] = '\0';
1db2c04
     pa->WriteProtect = da.WriteProtect;
1db2c04
     
1db2c04
     return 0;
1db2c04
@@ -741,6 +744,7 @@ int FatSetCWD(char *dir)
1db2c04
       return 1;
1db2c04
 
1db2c04
    strncpy(cwd.Name, fa.Name, sizeof(cwd.Name));
1db2c04
+   cwd.Name[sizeof(cwd.Name)-1] = '\0';
1db2c04
    cwd.StartSector = ConvertClusterToSector(fa.StartCluster);
1db2c04
    cwd.CurrSector = cwd.StartSector;
1db2c04
    cwd.StartCluster = fa.StartCluster;
1db2c04
diff --git a/prnt/hpcups/genPCLm.cpp b/prnt/hpcups/genPCLm.cpp
1db2c04
index c0cdc73..4db4bde 100644
1db2c04
--- a/prnt/hpcups/genPCLm.cpp
1db2c04
+++ b/prnt/hpcups/genPCLm.cpp
1db2c04
@@ -1237,11 +1237,16 @@ void PCLmGenerator::writeJobTicket()
1db2c04
 	char orientation[256];
1db2c04
 	char duplex[256];
1db2c04
 	char colorthemes[256];
1db2c04
-	strncpy(colorthemes,getColorThemesString(m_pPCLmSSettings->colorTheme),256);
1db2c04
-	strncpy(inputBin,getInputBinString(m_pPCLmSSettings->userInputBin),256);
1db2c04
-	strncpy(outputBin,getOutputBin(m_pPCLmSSettings->userOutputBin),256);
1db2c04
-	strncpy(orientation,getOrientationString(m_pPCLmSSettings->userOrientation),256);
1db2c04
-	strncpy(duplex,getDuplexString(currDuplexDisposition),256);
1db2c04
+	strncpy(colorthemes,getColorThemesString(m_pPCLmSSettings->colorTheme), sizeof(colorthemes));
1db2c04
+	colorthemes[sizeof(colorthemes)-1] = '\0';
1db2c04
+	strncpy(inputBin,getInputBinString(m_pPCLmSSettings->userInputBin), sizeof(inputBin));
1db2c04
+	inputBin[sizeof(inputBin)-1] = '\0';
1db2c04
+	strncpy(outputBin,getOutputBin(m_pPCLmSSettings->userOutputBin), sizeof(outputBin));
1db2c04
+	outputBin[sizeof(outputBin)-1] = '\0';
1db2c04
+	strncpy(orientation,getOrientationString(m_pPCLmSSettings->userOrientation), sizeof(orientation));
1db2c04
+	orientation[sizeof(orientation)-1] = '\0';
1db2c04
+	strncpy(duplex,getDuplexString(currDuplexDisposition), sizeof(duplex));
1db2c04
+	duplex[sizeof(duplex)-1] = '\0';
1db2c04
 
1db2c04
 	snprintf(pOutStr,OUT_STR_SIZE,"%%  genPCLm (Ver: %f)\n",PCLM_Ver); writeStr2OutBuff(pOutStr);
1db2c04
 	snprintf(pOutStr,OUT_STR_SIZE,"%%============= Job Ticket =============\n"); writeStr2OutBuff(pOutStr);
1db2c04
@@ -1635,7 +1640,10 @@ int  PCLmGenerator::StartPage(PCLmPageSetup *PCLmPageContent, void **pOutBuffer,
1db2c04
 	}
1db2c04
 
1db2c04
 	if(strlen(PCLmPageContent->mediaSizeName))
1db2c04
-		strncpy(currMediaName,PCLmPageContent->mediaSizeName,256);
1db2c04
+	{
1db2c04
+		strncpy(currMediaName,PCLmPageContent->mediaSizeName, sizeof(currMediaName));
1db2c04
+		currMediaName[sizeof(currMediaName)-1] = '\0';
1db2c04
+	}
1db2c04
 
1db2c04
 	currStripHeight=PCLmPageContent->stripHeight;
1db2c04
 	if(!currStripHeight)
1db2c04
diff --git a/prnt/hpijs/context2.cpp b/prnt/hpijs/context2.cpp
1db2c04
index c3df482..19490b1 100644
1db2c04
--- a/prnt/hpijs/context2.cpp
1db2c04
+++ b/prnt/hpijs/context2.cpp
1db2c04
@@ -1302,6 +1302,7 @@ DRIVER_ERROR PrintContext::SelectDevice
1db2c04
 	if(0 == strnlen((const char *)pSS->strDevID, DevIDBuffSize))
1db2c04
 	{
1db2c04
 		strncpy((char *)pSS->strDevID,szDeviceId,DevIDBuffSize);
1db2c04
+		pSS->strDevID[sizeof(pSS->strDevID)-1] = '\0';
1db2c04
 	}
1db2c04
     thePrinter = pPFI->CreatePrinter (pSS, familyHandle);
1db2c04
     if (thePrinter->constructor_error != NO_ERROR)
1db2c04
diff --git a/prnt/hpijs/systemservices.cpp b/prnt/hpijs/systemservices.cpp
1db2c04
index 95f5a64..f5b4bb5 100644
1db2c04
--- a/prnt/hpijs/systemservices.cpp
1db2c04
+++ b/prnt/hpijs/systemservices.cpp
1db2c04
@@ -396,7 +396,10 @@ void SystemServices::AdjustIO(IO_MODE IM, const char* model)
1db2c04
     IOMode.bDevID =IM.bDevID  && IOMode.bDevID;
1db2c04
 
1db2c04
     if (model)
1db2c04
+    {
1db2c04
         strncpy(strModel,model, sizeof(strModel));
1db2c04
+        strModel[sizeof(strModel)-1] = '\0';
1db2c04
+    }
1db2c04
 }
1db2c04
 
1db2c04
 APDK_END_NAMESPACE
1db2c04
diff --git a/prnt/hpps/hppsfilter.c b/prnt/hpps/hppsfilter.c
1db2c04
index 5879a70..d246041 100644
1db2c04
--- a/prnt/hpps/hppsfilter.c
1db2c04
+++ b/prnt/hpps/hppsfilter.c
1db2c04
@@ -230,13 +230,13 @@ static void WriteHeader(char **argument)
1db2c04
     /*		Writing Header Information
1db2c04
     argument[1] = JOB ID , argument[2]= USERNAME,  argument[3] = TITLE		*/
1db2c04
     hpwrite("\x1b%-12345X@PJL JOBNAME=", strlen("\x1b%-12345X@PJL JOBNAME="));
1db2c04
-    sprintf(buffer, "hplip_%s_%s\x0a", argument[2], argument[1]);
1db2c04
+    snprintf(buffer, MAX_BUFFER-1, "hplip_%s_%s\x0a", argument[2], argument[1]);
1db2c04
     hpwrite(buffer, strlen(buffer));
1db2c04
     memset(buffer, 0, sizeof(buffer));
1db2c04
-    sprintf(buffer, "@PJL SET USERNAME=\"%s\"\x0a", argument[2]);
1db2c04
+    snprintf(buffer, MAX_BUFFER-1, "@PJL SET USERNAME=\"%s\"\x0a", argument[2]);
1db2c04
     hpwrite(buffer, strlen(buffer));
1db2c04
     memset(buffer, 0, sizeof(buffer));
1db2c04
-    sprintf(buffer, "@PJL SET JOBNAME=\"%s\"\x0a", argument[3]);
1db2c04
+    snprintf(buffer, MAX_BUFFER-1, "@PJL SET JOBNAME=\"%s\"\x0a", argument[3]);
1db2c04
     hpwrite(buffer, strlen(buffer));
1db2c04
     fprintf(stderr, "HP PS filter func = WriteHeader           : WRITING PJL HEADER INFO\n");
1db2c04
     return;
1db2c04
diff --git a/protocol/discovery/mdns.c b/protocol/discovery/mdns.c
1db2c04
index abca295..8dd6fa5 100644
1db2c04
--- a/protocol/discovery/mdns.c
1db2c04
+++ b/protocol/discovery/mdns.c
1db2c04
@@ -31,6 +31,10 @@
1db2c04
 #include <netinet/in.h>
1db2c04
 #include <netdb.h>
1db2c04
 #include <arpa/inet.h>
1db2c04
+#include <unistd.h>
1db2c04
+#include <ctype.h>
1db2c04
+#include <stdio.h>
1db2c04
+#include <stdlib.h>
1db2c04
 #include "mdns.h"
1db2c04
 
1db2c04
 /* Convert "www.google.com" to "3www6google3com". */
1db2c04
diff --git a/protocol/hp_ipp.h b/protocol/hp_ipp.h
1db2c04
index 3853f84..de76202 100644
1db2c04
--- a/protocol/hp_ipp.h
1db2c04
+++ b/protocol/hp_ipp.h
1db2c04
@@ -166,5 +166,10 @@ int     getCupsPrinters(printer_t **printer_list);
1db2c04
 HPIPP_RESULT parseResponseHeader(char* header, int *content_length, int *chunked, int* header_size);
1db2c04
 HPIPP_RESULT prepend_http_header(raw_ipp *raw_request);
1db2c04
 enum HPMUD_RESULT sendUSBRequest(char *buf, int size, raw_ipp *responseptr, char * device_uri);
1db2c04
+void _releaseCupsInstance();
1db2c04
+int addCupsPrinter(char *name, char *device_uri, char *location, char *ppd_file, char *model, char *info);
1db2c04
+int delCupsPrinter(char *pr_name);
1db2c04
+int setDefaultCupsPrinter(char *pr_name);
1db2c04
+int controlCupsPrinter(char *pr_name, int op);
1db2c04
 
1db2c04
 # endif //_IPP_H
1db2c04
diff --git a/scan/sane/bb_ledm.c b/scan/sane/bb_ledm.c
1db2c04
index b233d1e..7ba0edf 100644
1db2c04
--- a/scan/sane/bb_ledm.c
1db2c04
+++ b/scan/sane/bb_ledm.c
1db2c04
@@ -26,6 +26,7 @@
1db2c04
 # include "http.h"
1db2c04
 # include "xml.h"
1db2c04
 # include <stdlib.h>
1db2c04
+# include <unistd.h>
1db2c04
 
1db2c04
 # include <stdint.h>
1db2c04
 
1db2c04
diff --git a/scan/sane/common.h b/scan/sane/common.h
1db2c04
index 0f67542..e496a74 100644
1db2c04
--- a/scan/sane/common.h
1db2c04
+++ b/scan/sane/common.h
1db2c04
@@ -36,7 +36,7 @@
1db2c04
 #define _STRINGIZE(x) #x
1db2c04
 #define STRINGIZE(x) _STRINGIZE(x)
1db2c04
 
1db2c04
-#define BUG(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); DBG(2, __FILE__ " " STRINGIZE(__LINE__) ": " args);}
1db2c04
+#define BUG_SCAN(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); DBG(2, __FILE__ " " STRINGIZE(__LINE__) ": " args);}
1db2c04
 #define BUG_DUMP(data, size) bugdump((data), (size))
1db2c04
 #define BUG_SZ(args...) {syslog(LOG_ERR, args); DBG(2, args);}
1db2c04
 
1db2c04
diff --git a/scan/sane/escl.c b/scan/sane/escl.c
1db2c04
index af45bff..4f59b21 100644
1db2c04
--- a/scan/sane/escl.c
1db2c04
+++ b/scan/sane/escl.c
1db2c04
@@ -795,7 +795,7 @@ SANE_Status escl_control_option(SANE_Handle handle, SANE_Int option, SANE_Action
1db2c04
   //DBG8("escl_control_option (option=%s) action=%d\n", ps->option[option].name, action);
1db2c04
   if (stat != SANE_STATUS_GOOD)
1db2c04
   {
1db2c04
-     BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
+     BUG_SCAN("control_option failed: option=%s action=%s\n", ps->option[option].name, action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
   }
1db2c04
 
1db2c04
    return stat;
1db2c04
@@ -1102,7 +1102,7 @@ void escl_close(SANE_Handle handle)
1db2c04
 
1db2c04
   if (ps == NULL || ps != session)
1db2c04
   {
1db2c04
-    BUG("invalid sane_close\n");
1db2c04
+    BUG_SCAN("invalid sane_close\n");
1db2c04
     return;
1db2c04
   }
1db2c04
 
1db2c04
diff --git a/scan/sane/hpaio.c b/scan/sane/hpaio.c
1db2c04
index ae34cfb..ffde2ad 100644
1db2c04
--- a/scan/sane/hpaio.c
1db2c04
+++ b/scan/sane/hpaio.c
1db2c04
@@ -41,6 +41,7 @@
1db2c04
 #include "soap.h"
1db2c04
 #include "soapht.h"
1db2c04
 #include "marvell.h"
1db2c04
+#include "mdns.h"
1db2c04
 #include "hpaio.h"
1db2c04
 #include "ledm.h"
1db2c04
 #include "sclpml.h"
1db2c04
diff --git a/scan/sane/http.c b/scan/sane/http.c
1db2c04
index 800df91..45668cd 100644
1db2c04
--- a/scan/sane/http.c
1db2c04
+++ b/scan/sane/http.c
1db2c04
@@ -36,6 +36,7 @@
1db2c04
 #include <string.h>
1db2c04
 #include <syslog.h>
1db2c04
 #include <ctype.h>
1db2c04
+#include <unistd.h>
1db2c04
 #include "hpmud.h"
1db2c04
 #include "http.h"
1db2c04
 
1db2c04
diff --git a/scan/sane/io.c b/scan/sane/io.c
1db2c04
index 4508458..7bbddea 100755
1db2c04
--- a/scan/sane/io.c
1db2c04
+++ b/scan/sane/io.c
1db2c04
@@ -50,7 +50,7 @@ int __attribute__ ((visibility ("hidden"))) InitDbus(void)
1db2c04
     
1db2c04
    if (dbus_error_is_set(&dbus_err))
1db2c04
    { 
1db2c04
-      BUG("dBus Connection Error (%s)!\n", dbus_err.message); 
1db2c04
+      BUG_SCAN("dBus Connection Error (%s)!\n", dbus_err.message); 
1db2c04
       dbus_error_free(&dbus_err); 
1db2c04
    }
1db2c04
 
1db2c04
@@ -79,7 +79,7 @@ int __attribute__ ((visibility ("hidden"))) SendScanEvent(char *device_uri, int
1db2c04
 
1db2c04
     if (NULL == msg)
1db2c04
     {
1db2c04
-        BUG("dbus message is NULL!\n");
1db2c04
+        BUG_SCAN("dbus message is NULL!\n");
1db2c04
         return 0;
1db2c04
     }
1db2c04
 
1db2c04
@@ -94,7 +94,7 @@ int __attribute__ ((visibility ("hidden"))) SendScanEvent(char *device_uri, int
1db2c04
 
1db2c04
     if (!dbus_connection_send(dbus_conn, msg, NULL))
1db2c04
     {
1db2c04
-        BUG("dbus message send failed!\n");
1db2c04
+        BUG_SCAN("dbus message send failed!\n");
1db2c04
         return 0;
1db2c04
     }
1db2c04
 
1db2c04
diff --git a/scan/sane/ledm.c b/scan/sane/ledm.c
1db2c04
index 9a1ff02..07ab5b0 100644
1db2c04
--- a/scan/sane/ledm.c
1db2c04
+++ b/scan/sane/ledm.c
1db2c04
@@ -802,7 +802,7 @@ SANE_Status ledm_control_option(SANE_Handle handle, SANE_Int option, SANE_Action
1db2c04
 
1db2c04
   if (stat != SANE_STATUS_GOOD)
1db2c04
   {
1db2c04
-     BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
+     BUG_SCAN("control_option failed: option=%s action=%s\n", ps->option[option].name, action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
   }
1db2c04
 
1db2c04
    return stat;
1db2c04
@@ -1067,7 +1067,7 @@ void ledm_close(SANE_Handle handle)
1db2c04
 
1db2c04
   if (ps == NULL || ps != session)
1db2c04
   {
1db2c04
-    BUG("invalid sane_close\n");
1db2c04
+    BUG_SCAN("invalid sane_close\n");
1db2c04
     return;
1db2c04
   }
1db2c04
 
1db2c04
diff --git a/scan/sane/marvell.c b/scan/sane/marvell.c
1db2c04
index ad267a3..236f7c9 100644
1db2c04
--- a/scan/sane/marvell.c
1db2c04
+++ b/scan/sane/marvell.c
1db2c04
@@ -134,7 +134,7 @@ static int get_ip_data(struct marvell_session *ps, SANE_Byte *data, SANE_Int max
1db2c04
 
1db2c04
    if (!ps->ip_handle)
1db2c04
    {
1db2c04
-      BUG("invalid ipconvert state\n");
1db2c04
+      BUG_SCAN("invalid ipconvert state\n");
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
    
1db2c04
@@ -335,7 +335,7 @@ static struct marvell_session *create_session()
1db2c04
 
1db2c04
    if ((ps = malloc(sizeof(struct marvell_session))) == NULL)
1db2c04
    {
1db2c04
-      BUG("malloc failed: %m\n");
1db2c04
+      BUG_SCAN("malloc failed: %m\n");
1db2c04
       return NULL;
1db2c04
    }
1db2c04
    memset(ps, 0, sizeof(struct marvell_session));
1db2c04
@@ -402,7 +402,7 @@ SANE_Status marvell_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (session)
1db2c04
    {
1db2c04
-      BUG("session in use\n");
1db2c04
+      BUG_SCAN("session in use\n");
1db2c04
       return SANE_STATUS_DEVICE_BUSY;
1db2c04
    }
1db2c04
       
1db2c04
@@ -431,7 +431,7 @@ SANE_Status marvell_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (hpmud_open_device(session->uri, ma.mfp_mode, &session->dd) != HPMUD_R_OK)
1db2c04
    {
1db2c04
-      BUG("unable to open device %s\n", session->uri);
1db2c04
+      BUG_SCAN("unable to open device %s\n", session->uri);
1db2c04
       goto bugout;
1db2c04
 
1db2c04
       free(session);
1db2c04
@@ -441,7 +441,7 @@ SANE_Status marvell_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (hpmud_open_channel(session->dd, HPMUD_S_MARVELL_SCAN_CHANNEL, &session->cd) != HPMUD_R_OK)
1db2c04
    {
1db2c04
-      BUG("unable to open %s channel %s\n", HPMUD_S_MARVELL_SCAN_CHANNEL, session->uri);
1db2c04
+      BUG_SCAN("unable to open %s channel %s\n", HPMUD_S_MARVELL_SCAN_CHANNEL, session->uri);
1db2c04
       stat = SANE_STATUS_DEVICE_BUSY;
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
@@ -554,7 +554,7 @@ void marvell_close(SANE_Handle handle)
1db2c04
 
1db2c04
    if (ps == NULL || ps != session)
1db2c04
    {
1db2c04
-      BUG("invalid sane_close\n");
1db2c04
+      BUG_SCAN("invalid sane_close\n");
1db2c04
       return;
1db2c04
    }
1db2c04
 
1db2c04
@@ -849,7 +849,7 @@ SANE_Status marvell_control_option(SANE_Handle handle, SANE_Int option, SANE_Act
1db2c04
                stat = SANE_STATUS_GOOD;
1db2c04
                break;
1db2c04
             }
1db2c04
-            BUG("value=%d brymin=%d brymax=%d\n", *int_value, ps->bryRange.min, ps->bryRange.max);
1db2c04
+            BUG_SCAN("value=%d brymin=%d brymax=%d\n", *int_value, ps->bryRange.min, ps->bryRange.max);
1db2c04
          }
1db2c04
          else
1db2c04
          {  /* Set default. */
1db2c04
@@ -866,7 +866,7 @@ SANE_Status marvell_control_option(SANE_Handle handle, SANE_Int option, SANE_Act
1db2c04
 
1db2c04
    if (stat != SANE_STATUS_GOOD)
1db2c04
    {
1db2c04
-      BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
+      BUG_SCAN("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
                   action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
    }
1db2c04
 
1db2c04
@@ -905,7 +905,7 @@ SANE_Status marvell_start(SANE_Handle handle)
1db2c04
    
1db2c04
    if (set_extents(ps))
1db2c04
    {
1db2c04
-      BUG("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
+      BUG_SCAN("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
          ps->currentTlx, ps->currentTly, ps->currentBrx, ps->currentBry, ps->min_width, ps->min_height, ps->tlxRange.max, ps->tlyRange.max);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
@@ -963,7 +963,7 @@ SANE_Status marvell_start(SANE_Handle handle)
1db2c04
    /* Open image processor. */
1db2c04
    if ((ret = ipOpen(pXform-xforms, xforms, 0, &ps->ip_handle)) != IP_DONE)
1db2c04
    {
1db2c04
-      BUG("unable open image processor: err=%d\n", ret);
1db2c04
+      BUG_SCAN("unable open image processor: err=%d\n", ret);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
@@ -1023,7 +1023,7 @@ SANE_Status marvell_read(SANE_Handle handle, SANE_Byte *data, SANE_Int maxLength
1db2c04
 
1db2c04
    if(ret & (IP_INPUT_ERROR | IP_FATAL_ERROR))
1db2c04
    {
1db2c04
-      BUG("ipConvert error=%x\n", ret);
1db2c04
+      BUG_SCAN("ipConvert error=%x\n", ret);
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
 
1db2c04
diff --git a/scan/sane/sclpml.c b/scan/sane/sclpml.c
1db2c04
index 9a5975f..dc8b32c 100644
1db2c04
--- a/scan/sane/sclpml.c
1db2c04
+++ b/scan/sane/sclpml.c
1db2c04
@@ -30,6 +30,7 @@
1db2c04
 #include <unistd.h>
1db2c04
 #include <fcntl.h>
1db2c04
 #include <string.h>
1db2c04
+#include <sys/time.h>
1db2c04
 #include "sane.h"
1db2c04
 #include "saneopts.h"
1db2c04
 #include "common.h"
1db2c04
@@ -2090,7 +2091,7 @@ void sclpml_close(SANE_Handle handle)
1db2c04
     DBG(8, "sane_hpaio_close(): %s %d\n", __FILE__, __LINE__); 
1db2c04
     if (hpaio == NULL || hpaio != session)
1db2c04
     {
1db2c04
-      BUG("invalid sane_close\n");
1db2c04
+      BUG_SCAN("invalid sane_close\n");
1db2c04
       return;
1db2c04
      }
1db2c04
 
1db2c04
diff --git a/scan/sane/soap.c b/scan/sane/soap.c
1db2c04
index 07106fe..0d22e52 100644
1db2c04
--- a/scan/sane/soap.c
1db2c04
+++ b/scan/sane/soap.c
1db2c04
@@ -142,7 +142,7 @@ static int get_ip_data(struct soap_session *ps, SANE_Byte *data, SANE_Int maxLen
1db2c04
 
1db2c04
    if (!ps->ip_handle)
1db2c04
    {
1db2c04
-      BUG("invalid ipconvert state\n");
1db2c04
+      BUG_SCAN("invalid ipconvert state\n");
1db2c04
       goto bugout;
1db2c04
    }      
1db2c04
 
1db2c04
@@ -219,7 +219,7 @@ static struct soap_session *create_session()
1db2c04
 
1db2c04
    if ((ps = malloc(sizeof(struct soap_session))) == NULL)
1db2c04
    {
1db2c04
-      BUG("malloc failed: %m\n");
1db2c04
+      BUG_SCAN("malloc failed: %m\n");
1db2c04
       return NULL;
1db2c04
    }
1db2c04
    memset(ps, 0, sizeof(struct soap_session));
1db2c04
@@ -418,7 +418,7 @@ SANE_Status soap_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (session)
1db2c04
    {
1db2c04
-      BUG("session in use\n");
1db2c04
+      BUG_SCAN("session in use\n");
1db2c04
       return SANE_STATUS_DEVICE_BUSY;
1db2c04
    }
1db2c04
 
1db2c04
@@ -434,7 +434,7 @@ SANE_Status soap_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (hpmud_open_device(session->uri, ma.mfp_mode, &session->dd) != HPMUD_R_OK)
1db2c04
    {
1db2c04
-      BUG("unable to open device %s\n", session->uri);
1db2c04
+      BUG_SCAN("unable to open device %s\n", session->uri);
1db2c04
       goto bugout;
1db2c04
 
1db2c04
       free(session);
1db2c04
@@ -519,7 +519,7 @@ void soap_close(SANE_Handle handle)
1db2c04
 
1db2c04
    if (ps == NULL || ps != session)
1db2c04
    {
1db2c04
-      BUG("invalid sane_close\n");
1db2c04
+      BUG_SCAN("invalid sane_close\n");
1db2c04
       return;
1db2c04
    }
1db2c04
 
1db2c04
@@ -824,7 +824,7 @@ SANE_Status soap_control_option(SANE_Handle handle, SANE_Int option, SANE_Action
1db2c04
 
1db2c04
    if (stat != SANE_STATUS_GOOD)
1db2c04
    {
1db2c04
-      BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
+      BUG_SCAN("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
                   action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
    }
1db2c04
 
1db2c04
@@ -862,7 +862,7 @@ SANE_Status soap_start(SANE_Handle handle)
1db2c04
    ps->user_cancel = 0;
1db2c04
    if (set_extents(ps))
1db2c04
    {
1db2c04
-      BUG("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
+      BUG_SCAN("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
          ps->currentTlx, ps->currentTly, ps->currentBrx, ps->currentBry, ps->min_width, ps->min_height, ps->tlxRange.max, ps->tlyRange.max);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
@@ -913,7 +913,7 @@ SANE_Status soap_start(SANE_Handle handle)
1db2c04
    /* Open image processor. */
1db2c04
    if ((ret = ipOpen(pXform-xforms, xforms, 0, &ps->ip_handle)) != IP_DONE)
1db2c04
    {
1db2c04
-      BUG("unable open image processor: err=%d\n", ret);
1db2c04
+      BUG_SCAN("unable open image processor: err=%d\n", ret);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
@@ -955,7 +955,7 @@ SANE_Status soap_start(SANE_Handle handle)
1db2c04
 
1db2c04
          if (ret & (IP_INPUT_ERROR | IP_FATAL_ERROR | IP_DONE))
1db2c04
          {
1db2c04
-            BUG("ipConvert error=%x\n", ret);
1db2c04
+            BUG_SCAN("ipConvert error=%x\n", ret);
1db2c04
             stat = SANE_STATUS_IO_ERROR;
1db2c04
             goto bugout;
1db2c04
          }
1db2c04
@@ -1007,7 +1007,7 @@ SANE_Status soap_read(SANE_Handle handle, SANE_Byte *data, SANE_Int maxLength, S
1db2c04
 
1db2c04
    if(ret & (IP_INPUT_ERROR | IP_FATAL_ERROR))
1db2c04
    {
1db2c04
-      BUG("ipConvert error=%x\n", ret);
1db2c04
+      BUG_SCAN("ipConvert error=%x\n", ret);
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
 
1db2c04
diff --git a/scan/sane/soapht.c b/scan/sane/soapht.c
1db2c04
index 269ab21..139100d 100644
1db2c04
--- a/scan/sane/soapht.c
1db2c04
+++ b/scan/sane/soapht.c
1db2c04
@@ -136,7 +136,7 @@ static int get_ip_data(struct soap_session *ps, SANE_Byte *data, SANE_Int maxLen
1db2c04
 
1db2c04
    if (!ps->ip_handle)
1db2c04
    {
1db2c04
-      BUG("invalid ipconvert state\n");
1db2c04
+      BUG_SCAN("invalid ipconvert state\n");
1db2c04
       goto bugout;
1db2c04
    }      
1db2c04
 
1db2c04
@@ -435,7 +435,7 @@ static struct soap_session *create_session()
1db2c04
 
1db2c04
    if ((ps = malloc(sizeof(struct soap_session))) == NULL)
1db2c04
    {
1db2c04
-      BUG("malloc failed: %m\n");
1db2c04
+      BUG_SCAN("malloc failed: %m\n");
1db2c04
       return NULL;
1db2c04
    }
1db2c04
    memset(ps, 0, sizeof(struct soap_session));
1db2c04
@@ -459,7 +459,7 @@ SANE_Status soapht_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (session)
1db2c04
    {
1db2c04
-      BUG("session in use\n");
1db2c04
+      BUG_SCAN("session in use\n");
1db2c04
       return SANE_STATUS_DEVICE_BUSY;
1db2c04
    }
1db2c04
 
1db2c04
@@ -475,7 +475,7 @@ SANE_Status soapht_open(SANE_String_Const device, SANE_Handle *handle)
1db2c04
 
1db2c04
    if (hpmud_open_device(session->uri, ma.mfp_mode, &session->dd) != HPMUD_R_OK)
1db2c04
    {
1db2c04
-      BUG("unable to open device %s\n", session->uri);
1db2c04
+      BUG_SCAN("unable to open device %s\n", session->uri);
1db2c04
       goto bugout;
1db2c04
 
1db2c04
       free(session);
1db2c04
@@ -554,7 +554,7 @@ void soapht_close(SANE_Handle handle)
1db2c04
 
1db2c04
    if (ps == NULL || ps != session)
1db2c04
    {
1db2c04
-      BUG("invalid sane_close\n");
1db2c04
+      BUG_SCAN("invalid sane_close\n");
1db2c04
       return;
1db2c04
    }
1db2c04
 
1db2c04
@@ -904,7 +904,7 @@ SANE_Status soapht_control_option(SANE_Handle handle, SANE_Int option, SANE_Acti
1db2c04
 
1db2c04
    if (stat != SANE_STATUS_GOOD)
1db2c04
    {
1db2c04
-      BUG("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
+      BUG_SCAN("control_option failed: option=%s action=%s\n", ps->option[option].name, 
1db2c04
                   action==SANE_ACTION_GET_VALUE ? "get" : action==SANE_ACTION_SET_VALUE ? "set" : "auto");
1db2c04
    }
1db2c04
 
1db2c04
@@ -946,7 +946,7 @@ SANE_Status soapht_start(SANE_Handle handle)
1db2c04
   
1db2c04
    if (set_extents(ps))
1db2c04
    {
1db2c04
-      BUG("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
+      BUG_SCAN("invalid extents: tlx=%d brx=%d tly=%d bry=%d minwidth=%d minheight%d maxwidth=%d maxheight=%d\n",
1db2c04
          ps->currentTlx, ps->currentTly, ps->currentBrx, ps->currentBry, ps->min_width, ps->min_height, ps->tlxRange.max, ps->tlyRange.max);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
@@ -1032,7 +1032,7 @@ SANE_Status soapht_start(SANE_Handle handle)
1db2c04
    /* Open image processor. */
1db2c04
    if ((ret = ipOpen(pXform-xforms, xforms, 0, &ps->ip_handle)) != IP_DONE)
1db2c04
    {
1db2c04
-      BUG("unable open image processor: err=%d\n", ret);
1db2c04
+      BUG_SCAN("unable open image processor: err=%d\n", ret);
1db2c04
       stat = SANE_STATUS_INVAL;
1db2c04
       goto bugout;
1db2c04
    }
1db2c04
@@ -1075,7 +1075,7 @@ SANE_Status soapht_start(SANE_Handle handle)
1db2c04
 
1db2c04
          if (ret & (IP_INPUT_ERROR | IP_FATAL_ERROR | IP_DONE))
1db2c04
          {
1db2c04
-            BUG("ipConvert error=%x\n", ret);
1db2c04
+            BUG_SCAN("ipConvert error=%x\n", ret);
1db2c04
             stat = SANE_STATUS_IO_ERROR;
1db2c04
             goto bugout;
1db2c04
          }
1db2c04
@@ -1124,7 +1124,7 @@ SANE_Status soapht_read(SANE_Handle handle, SANE_Byte *data, SANE_Int maxLength,
1db2c04
 
1db2c04
    if(ret & (IP_INPUT_ERROR | IP_FATAL_ERROR))
1db2c04
    {
1db2c04
-      BUG("ipConvert error=%x\n", ret);
1db2c04
+      BUG_SCAN("ipConvert error=%x\n", ret);
1db2c04
       goto bugout;
1db2c04
    }
1db2c04