kopia lustrzana https://gitlab.com/sane-project/backends
- added support for dell1600n_net.conf
- removed tmpfile usage (including overly large buffer) - fixed the indentation horrors inflicted by auto-formatting toolsmerge-requests/1/head
rodzic
98339fa803
commit
b7109db2eb
|
@ -42,10 +42,6 @@
|
|||
|
||||
Dell 1600n network scan driver for SANE.
|
||||
|
||||
NOTE
|
||||
|
||||
- need to add support for multiple network interfaces
|
||||
|
||||
To debug:
|
||||
SANE_DEBUG_DELL1600N_NET=255 scanimage --verbose 2>scan.errs 1>scan.png
|
||||
*/
|
||||
|
@ -60,6 +56,7 @@
|
|||
|
||||
#define BACKEND_NAME dell1600n_net
|
||||
#include "../include/sane/sanei_backend.h"
|
||||
#include "../include/sane/sanei_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -292,6 +289,10 @@ sane_get_devices (const SANE_Device *** device_list,
|
|||
fd_set readFds;
|
||||
struct timeval selTimeVal;
|
||||
int nread, iNextDevice;
|
||||
FILE *fConfig;
|
||||
char configBuf[ 256 ];
|
||||
char *pVal;
|
||||
int valLen;
|
||||
|
||||
/* init variables */
|
||||
ret = SANE_STATUS_GOOD;
|
||||
|
@ -302,6 +303,51 @@ sane_get_devices (const SANE_Device *** device_list,
|
|||
|
||||
/* clear previous results */
|
||||
ClearKnownDevices ();
|
||||
iNextDevice = 0;
|
||||
|
||||
/* look for a config file */
|
||||
fConfig = sanei_config_open( "dell1600n_net.conf" );
|
||||
if ( fConfig )
|
||||
{
|
||||
while ( ! feof( fConfig ) )
|
||||
{
|
||||
if ( ! sanei_config_read ( configBuf, sizeof( configBuf ), fConfig ) ) break;
|
||||
|
||||
/* skip whitespace */
|
||||
pVal = sanei_config_skip_whitespace ( configBuf );
|
||||
|
||||
/* skip comments */
|
||||
if ( *pVal == '#' ) continue;
|
||||
|
||||
/* process named_scanner */
|
||||
valLen = strlen( "named_scanner:" );
|
||||
if ( ! strncmp( pVal, "extra_scanner:", valLen ) ){
|
||||
|
||||
pVal = sanei_config_skip_whitespace ( pVal + valLen );
|
||||
|
||||
pDevice = malloc (sizeof (SANE_Device));
|
||||
if (!pDevice)
|
||||
{
|
||||
DBG (1, "sane_get_devices: memory allocation failure\n");
|
||||
break;
|
||||
}
|
||||
|
||||
pDevice->name = strdup (pVal);
|
||||
pDevice->vendor = "Dell";
|
||||
pDevice->model = strdup( "1600n" );
|
||||
pDevice->type = "multi-function peripheral";
|
||||
|
||||
/* add to list */
|
||||
gKnownDevices[iNextDevice++] = pDevice;
|
||||
|
||||
continue;
|
||||
} /* if */
|
||||
|
||||
} /* while */
|
||||
|
||||
/* Close the file */
|
||||
fclose( fConfig );
|
||||
}
|
||||
|
||||
/* open UDP socket */
|
||||
sock = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
@ -346,7 +392,6 @@ sane_get_devices (const SANE_Device *** device_list,
|
|||
}
|
||||
|
||||
/* process replies */
|
||||
iNextDevice = 0;
|
||||
while (select (sock + 1, &readFds, NULL, NULL, &selTimeVal))
|
||||
{
|
||||
|
||||
|
@ -367,8 +412,7 @@ sane_get_devices (const SANE_Device *** device_list,
|
|||
HexDump (10, sockBuf, nread);
|
||||
|
||||
/* process response (skipping bad ones) */
|
||||
if (!(pDevice = ProcessFindResponse (sockBuf, nread)))
|
||||
continue;
|
||||
if (!(pDevice = ProcessFindResponse (sockBuf, nread))) continue;
|
||||
|
||||
/* add to list */
|
||||
gKnownDevices[iNextDevice++] = pDevice;
|
||||
|
@ -405,8 +449,7 @@ sane_open (SANE_String_Const devicename, SANE_Handle * handle)
|
|||
for (i = 0; i < MAX_SCANNERS; ++i)
|
||||
{
|
||||
|
||||
if (gOpenScanners[i])
|
||||
continue;
|
||||
if (gOpenScanners[i]) continue;
|
||||
|
||||
iHandle = i;
|
||||
break;
|
||||
|
@ -715,19 +758,13 @@ sane_start (SANE_Handle handle)
|
|||
|
||||
} /* while */
|
||||
|
||||
|
||||
/* check whether we were cancelled */
|
||||
if ( gOpenScanners[iHandle]->m_bCancelled ) status = SANE_STATUS_CANCELLED;
|
||||
|
||||
|
||||
cleanup:
|
||||
|
||||
FreeComBuf (&buf);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return status;
|
||||
|
||||
} /* sane_start */
|
||||
|
@ -857,10 +894,8 @@ ClearKnownDevices ()
|
|||
|
||||
if (gKnownDevices[i])
|
||||
{
|
||||
if (gKnownDevices[i]->name)
|
||||
free ((void*)(gKnownDevices[i]->name));
|
||||
if (gKnownDevices[i]->model)
|
||||
free ((void*)(gKnownDevices[i]->model));
|
||||
if (gKnownDevices[i]->name) free ((void*)(gKnownDevices[i]->name));
|
||||
if (gKnownDevices[i]->model) free ((void*)(gKnownDevices[i]->model));
|
||||
free (gKnownDevices[i]);
|
||||
}
|
||||
gKnownDevices[i] = NULL;
|
||||
|
@ -878,9 +913,7 @@ HexDump (int debugLevel, const unsigned char *buf, size_t bufSize)
|
|||
|
||||
unsigned int i, j;
|
||||
|
||||
char itemBuf[16] = { 0 }, lineBuf[256] =
|
||||
{
|
||||
0};
|
||||
char itemBuf[16] = { 0 }, lineBuf[256] = { 0 };
|
||||
|
||||
if (DBG_LEVEL < debugLevel)
|
||||
return;
|
||||
|
@ -938,11 +971,8 @@ HexDump (int debugLevel, const unsigned char *buf, size_t bufSize)
|
|||
}
|
||||
strncat (lineBuf, itemBuf, sizeof (lineBuf));
|
||||
}
|
||||
|
||||
DBG (debugLevel, "%s\n", lineBuf);
|
||||
|
||||
}
|
||||
|
||||
} /* HexDump */
|
||||
|
||||
/***********************************************************/
|
||||
|
@ -997,7 +1027,6 @@ AppendToComBuf (struct ComBuf *pBuf, const unsigned char *pData,
|
|||
/* check we have enough space */
|
||||
if (pBuf->m_used + datSize > pBuf->m_capacity)
|
||||
{
|
||||
|
||||
/* nope - allocate some more */
|
||||
newSize = pBuf->m_used + datSize + INITIAL_COM_BUF_SIZE;
|
||||
pBuf->m_pBuf = realloc (pBuf->m_pBuf, newSize);
|
||||
|
@ -1199,8 +1228,7 @@ ProcessFindResponse (unsigned char *pData, size_t size)
|
|||
} /* while pItem */
|
||||
|
||||
/* just in case nothing sensible was found */
|
||||
if (!strlen (printerName))
|
||||
return NULL;
|
||||
if ( ! strlen( printerName ) ) return NULL;
|
||||
|
||||
pDevice = malloc (sizeof (SANE_Device));
|
||||
if (!pDevice)
|
||||
|
@ -1211,10 +1239,10 @@ ProcessFindResponse (unsigned char *pData, size_t size)
|
|||
|
||||
/* knock off "Dell " from start of model name */
|
||||
pModel = printerModel;
|
||||
if (!strncmp (pModel, "Dell ", 5))
|
||||
if ( ! strncmp( pModel, "Dell ", 5 ) )
|
||||
pModel += 5;
|
||||
|
||||
pDevice->name = strdup (printerName);
|
||||
pDevice->name = strdup( printerName );
|
||||
pDevice->vendor = "Dell";
|
||||
pDevice->model = strdup (pModel);
|
||||
pDevice->type = "multi-function peripheral";
|
||||
|
@ -1543,7 +1571,6 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
}
|
||||
else if (!strncmp ("std-scan-document-start", pName, nameSize))
|
||||
{
|
||||
|
||||
errorCheck |= InitPacket (&buf, 0x02);
|
||||
uiVal = 0;
|
||||
errorCheck |=
|
||||
|
@ -1552,19 +1579,15 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
&uiVal, sizeof (uiVal));
|
||||
FinalisePacket (&buf);
|
||||
send (pState->m_tcpFd, buf.m_pBuf, buf.m_used, 0);
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-document-file-type", pName, nameSize))
|
||||
{
|
||||
|
||||
memcpy (&pState->m_fileType, pValue, sizeof (pState->m_fileType));
|
||||
DBG (5, "File type: %x\n", ntohl (pState->m_fileType));
|
||||
|
||||
}
|
||||
else
|
||||
if (!strncmp ("std-scan-document-image-compression", pName, nameSize))
|
||||
{
|
||||
|
||||
memcpy (&pState->m_compression, pValue,
|
||||
sizeof (pState->m_compression));
|
||||
DBG (5, "Compression: %x\n", ntohl (pState->m_compression));
|
||||
|
@ -1572,17 +1595,13 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
}
|
||||
else if (!strncmp ("std-scan-document-xresolution", pName, nameSize))
|
||||
{
|
||||
|
||||
memcpy (&pState->m_xres, pValue, sizeof (pState->m_xres));
|
||||
DBG (5, "X resolution: %d\n", ntohs (pState->m_xres));
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-document-yresolution", pName, nameSize))
|
||||
{
|
||||
|
||||
memcpy (&pState->m_yres, pValue, sizeof (pState->m_yres));
|
||||
DBG (5, "Y resolution: %d\n", ntohs (pState->m_yres));
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-page-widthpixel", pName, nameSize))
|
||||
{
|
||||
|
@ -1596,11 +1615,9 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
{
|
||||
DBG (5, "Ignoring width (already have a value)\n");
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-page-heightpixel", pName, nameSize))
|
||||
{
|
||||
|
||||
if (1 || !pState->m_pixelHeight)
|
||||
{
|
||||
memcpy (&pState->m_pixelHeight, pValue,
|
||||
|
@ -1614,7 +1631,6 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
}
|
||||
else if (!strncmp ("std-scan-page-start", pName, nameSize))
|
||||
{
|
||||
|
||||
errorCheck |= InitPacket (&buf, 0x02);
|
||||
uiVal = 0;
|
||||
errorCheck |=
|
||||
|
@ -1623,10 +1639,6 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
FinalisePacket (&buf);
|
||||
send (pState->m_tcpFd, buf.m_pBuf, buf.m_used, 0);
|
||||
|
||||
/* write out any pre-existing page data
|
||||
errorCheck |= ProcessPageData (pState);
|
||||
*/
|
||||
|
||||
/* reset the data buffer ready to store a new page */
|
||||
pState->m_buf.m_used = 0;
|
||||
|
||||
|
@ -1635,11 +1647,9 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
|
||||
pState->m_pixelWidth = 0;
|
||||
pState->m_pixelHeight = 0;
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-page-end", pName, nameSize))
|
||||
{
|
||||
|
||||
bProcessImage = 1;
|
||||
|
||||
errorCheck |= InitPacket (&buf, 0x02);
|
||||
|
@ -1649,11 +1659,9 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
0x05, &uiVal, sizeof (uiVal));
|
||||
FinalisePacket (&buf);
|
||||
send (pState->m_tcpFd, buf.m_pBuf, buf.m_used, 0);
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-document-end", pName, nameSize))
|
||||
{
|
||||
|
||||
errorCheck |= InitPacket (&buf, 0x02);
|
||||
uiVal = 0;
|
||||
errorCheck |=
|
||||
|
@ -1663,16 +1671,11 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
FinalisePacket (&buf);
|
||||
send (pState->m_tcpFd, buf.m_pBuf, buf.m_used, 0);
|
||||
|
||||
/* write out any pre-existing page data */
|
||||
/* errorCheck |= ProcessPageData (pState); */
|
||||
|
||||
/* reset the data buffer ready to store a new page */
|
||||
pState->m_buf.m_used = 0;
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-session-end", pName, nameSize))
|
||||
{
|
||||
|
||||
errorCheck |= InitPacket (&buf, 0x02);
|
||||
uiVal = 0;
|
||||
errorCheck |=
|
||||
|
@ -1684,11 +1687,9 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
|
||||
/* initialise a shutodwn of the socket */
|
||||
shutdown (pState->m_tcpFd, SHUT_RDWR);
|
||||
|
||||
}
|
||||
else if (!strncmp ("std-scan-scandata-error", pName, nameSize))
|
||||
{
|
||||
|
||||
/* determine the size of data in this chunk */
|
||||
dataChunkSize = (pItem[6] << 8) + pItem[7];
|
||||
|
||||
|
@ -1703,12 +1704,9 @@ ProcessTcpResponse (struct ScannerState *pState, struct ComBuf *pTcpBuf)
|
|||
|
||||
DBG (10, "Accumulated %d bytes of scan data so far\n",
|
||||
pState->m_buf.m_used);
|
||||
|
||||
} /* if */
|
||||
|
||||
} /* while */
|
||||
|
||||
|
||||
/* process page data if required */
|
||||
if ( bProcessImage ) errorCheck |= ProcessPageData (pState);
|
||||
|
||||
|
@ -1762,7 +1760,6 @@ int
|
|||
ProcessPageData (struct ScannerState *pState)
|
||||
{
|
||||
|
||||
char tempFilename[TMP_MAX] = "scan.dat";
|
||||
FILE *fTmp;
|
||||
int fdTmp;
|
||||
struct jpeg_source_mgr jpegSrcMgr;
|
||||
|
@ -1965,17 +1962,12 @@ ProcessPageData (struct ScannerState *pState)
|
|||
default:
|
||||
/* this is not expected or very useful */
|
||||
{
|
||||
tmpnam (tempFilename);
|
||||
DBG (1, "ProcessPageData: Writing scan data to %s\n", tempFilename);
|
||||
fTmp = fopen (tempFilename, "w");
|
||||
fwrite (pState->m_buf.m_pBuf, pState->m_buf.m_used, 1, fTmp);
|
||||
fclose (fTmp);
|
||||
DBG (1, "ProcessPageData: Unexpected compression flag %d\n", ntohl (pState->m_compression));
|
||||
ret = SANE_STATUS_IO_ERROR;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
return ret;
|
||||
|
||||
} /* ProcessPageData */
|
||||
|
||||
/***********************************************************/
|
||||
|
|
Ładowanie…
Reference in New Issue