/*
- * "$Id: ieee1284.c 7687 2008-06-24 01:28:36Z mike $"
+ * "$Id: ieee1284.c 10996 2013-05-29 11:51:34Z msweet $"
*
- * IEEE-1284 support functions for the Common UNIX Printing System (CUPS).
+ * IEEE-1284 support functions for CUPS.
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2011 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
*/
#include "backend-private.h"
-
-#ifdef __linux
-# include <sys/ioctl.h>
-# include <linux/lp.h>
-# define IOCNR_GET_DEVICE_ID 1
-# define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
-# include <linux/parport.h>
-# include <linux/ppdev.h>
-# include <unistd.h>
-# include <fcntl.h>
-#endif /* __linux */
-
-#ifdef __sun
-# ifdef __sparc
-# include <sys/ecppio.h>
-# else
-# include <sys/ioccom.h>
-# include <sys/ecppsys.h>
-# endif /* __sparc */
-#endif /* __sun */
+#include <cups/cups-private.h>
/*
int uri_size) /* I - Size of buffer */
{
#ifdef __APPLE__ /* This function is a no-op */
+ (void)fd;
+ (void)device_id;
+ (void)device_id_size;
+ (void)make_model;
+ (void)make_model_size;
+ (void)scheme;
+ (void)uri;
+ (void)uri_size;
+
return (-1);
#else /* Get the device ID from the specified file descriptor... */
# if defined(__sun) && defined(ECPPIOC_GETDEVID)
struct ecpp_device_id did; /* Device ID buffer */
# endif /* __sun && ECPPIOC_GETDEVID */
+ char *ptr; /* Pointer into device ID */
DEBUG_printf(("backendGetDeviceID(fd=%d, device_id=%p, device_id_size=%d, "
* and then limit the length to the size of our buffer...
*/
- if (length > (device_id_size - 2))
+ if (length > device_id_size || length < 14)
length = (((unsigned)device_id[1] & 255) << 8) +
((unsigned)device_id[0] & 255);
- if (length > (device_id_size - 2))
- length = device_id_size - 2;
+ if (length > device_id_size)
+ length = device_id_size;
/*
- * Copy the device ID text to the beginning of the buffer and
- * nul-terminate.
+ * The length field counts the number of bytes in the string
+ * including the length field itself (2 bytes). The minimum
+ * length for a valid/usable device ID is 14 bytes:
+ *
+ * <LENGTH> MFG: <MFG> ;MDL: <MDL> ;
+ * 2 + 4 + 1 + 5 + 1 + 1
*/
- memmove(device_id, device_id + 2, length);
- device_id[length] = '\0';
+ if (length < 14)
+ {
+ /*
+ * Can't use this device ID, so don't try to copy it...
+ */
+
+ device_id[0] = '\0';
+ got_id = 0;
+ }
+ else
+ {
+ /*
+ * Copy the device ID text to the beginning of the buffer and
+ * nul-terminate.
+ */
+
+ length -= 2;
+
+ memmove(device_id, device_id + 2, length);
+ device_id[length] = '\0';
+ }
}
-# ifdef DEBUG
else
+ {
DEBUG_printf(("backendGetDeviceID: ioctl failed - %s\n",
strerror(errno)));
-# endif /* DEBUG */
+ *device_id = '\0';
+ }
# endif /* __linux */
# if defined(__sun) && defined(ECPPIOC_GETDEVID)
# endif /* __sun && ECPPIOC_GETDEVID */
}
+ /*
+ * Check whether device ID is valid. Turn line breaks and tabs to spaces and
+ * reject device IDs with non-printable characters.
+ */
+
+ for (ptr = device_id; *ptr; ptr ++)
+ if (_cups_isspace(*ptr))
+ *ptr = ' ';
+ else if ((*ptr & 255) < ' ' || *ptr == 127)
+ {
+ DEBUG_printf(("backendGetDeviceID: Bad device_id character %d.",
+ *ptr & 255));
+ *device_id = '\0';
+ break;
+ }
+
DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id));
if (scheme && uri)
* Get the make, model, and serial numbers...
*/
- num_values = _ppdGet1284Values(device_id, &values);
+ num_values = _cupsGet1284Values(device_id, &values);
if ((sern = cupsGetOption("SERIALNUMBER", num_values, values)) == NULL)
if ((sern = cupsGetOption("SERN", num_values, values)) == NULL)
if (mfg)
{
- if (!strcasecmp(mfg, "Hewlett-Packard"))
+ if (!_cups_strcasecmp(mfg, "Hewlett-Packard"))
mfg = "HP";
- else if (!strcasecmp(mfg, "Lexmark International"))
+ else if (!_cups_strcasecmp(mfg, "Lexmark International"))
mfg = "Lexmark";
}
else
mfg = temp;
}
- if (!strncasecmp(mdl, mfg, strlen(mfg)))
+ if (!mdl)
+ mdl = "";
+
+ if (!_cups_strncasecmp(mdl, mfg, strlen(mfg)))
{
mdl += strlen(mfg);
* Look for the description field...
*/
- num_values = _ppdGet1284Values(device_id, &values);
+ num_values = _cupsGet1284Values(device_id, &values);
if ((mdl = cupsGetOption("MODEL", num_values, values)) == NULL)
mdl = cupsGetOption("MDL", num_values, values);
if ((mfg = cupsGetOption("MANUFACTURER", num_values, values)) == NULL)
mfg = cupsGetOption("MFG", num_values, values);
- if (!mfg || !strncasecmp(mdl, mfg, strlen(mfg)))
+ if (!mfg || !_cups_strncasecmp(mdl, mfg, strlen(mfg)))
{
/*
* Just copy the model string, since it has the manufacturer...
char temp[1024]; /* Temporary make and model */
snprintf(temp, sizeof(temp), "%s %s", mfg, mdl);
+
_ppdNormalizeMakeAndModel(temp, make_model, make_model_size);
}
}
/*
- * End of "$Id: ieee1284.c 7687 2008-06-24 01:28:36Z mike $".
+ * End of "$Id: ieee1284.c 10996 2013-05-29 11:51:34Z msweet $".
*/