/*
* Printer routines for the CUPS scheduler.
*
- * Copyright 2007-2016 by Apple Inc.
+ * Copyright 2007-2017 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
* Remove any old PPD or script files...
*/
- snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot, p->name);
- unlink(filename);
- snprintf(filename, sizeof(filename), "%s/interfaces/%s.O", ServerRoot, p->name);
- unlink(filename);
-
snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot, p->name);
unlink(filename);
snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd.O", ServerRoot, p->name);
}
+/*
+ * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
+ */
+
+void
+cupsdDeleteTemporaryPrinters(int force) /* I - Force deletion instead of auto? */
+{
+ cupsd_printer_t *p; /* Current printer */
+ time_t unused_time; /* Last time for printer state change */
+
+
+ /*
+ * Allow temporary printers to stick around for 60 seconds after the last job
+ * completes.
+ */
+
+ unused_time = time(NULL) - 60;
+
+ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers))
+ {
+ if (p->temporary && (force || p->state_time < unused_time))
+ cupsdDeletePrinter(p, 0);
+ }
+}
+
+
/*
* 'cupsdFindDest()' - Find a destination in the list.
*/
* Decode the directive...
*/
- if (!_cups_strcasecmp(line, "<Printer") ||
- !_cups_strcasecmp(line, "<DefaultPrinter"))
+ if (!_cups_strcasecmp(line, "NextPrinterId"))
+ {
+ if (value && (i = atoi(value)) > 0)
+ NextPrinterId = i;
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Syntax error on line %d of printers.conf.", linenum);
+ }
+ else if (!_cups_strcasecmp(line, "<Printer") || !_cups_strcasecmp(line, "<DefaultPrinter"))
{
/*
* <Printer name> or <DefaultPrinter name>
* Close out the current printer...
*/
+ if (!p->printer_id)
+ {
+ p->printer_id = NextPrinterId ++;
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+ }
+
cupsdSetPrinterAttrs(p);
- if (strncmp(p->device_uri, "file:", 5) &&
- p->state != IPP_PRINTER_STOPPED)
+ if (strncmp(p->device_uri, "file:", 5) && p->state != IPP_PRINTER_STOPPED)
{
/*
* See if the backend exists...
*/
- snprintf(line, sizeof(line), "%s/backend/%s", ServerBin,
- p->device_uri);
+ snprintf(line, sizeof(line), "%s/backend/%s", ServerBin, p->device_uri);
if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL)
*valueptr = '\0'; /* Chop everything but URI scheme */
*/
p->state = IPP_PRINTER_STOPPED;
- snprintf(p->state_message, sizeof(p->state_message),
- "Backend %s does not exist!", line);
+ snprintf(p->state_message, sizeof(p->state_message), "Backend %s does not exist!", line);
}
}
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
}
+ else if (!_cups_strcasecmp(line, "PrinterId"))
+ {
+ if (value && (i = atoi(value)) > 0)
+ p->printer_id = i;
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Bad PrinterId on line %d of printers.conf.", linenum);
+ }
else if (!_cups_strcasecmp(line, "UUID"))
{
if (value && !strncmp(value, "urn:uuid:", 9))
cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
cupsFilePuts(fp, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
+ cupsFilePrintf(fp, "NextPrinterId %d\n", NextPrinterId);
+
/*
* Write each local printer known to the system...
*/
else
cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
+ if (printer->printer_id)
+ cupsFilePrintf(fp, "PrinterId %d\n", printer->printer_id);
+
cupsFilePrintf(fp, "UUID %s\n", printer->uuid);
if (printer->num_auth_info_required > 0)
"uri-authentication-supported", NULL, auth_supported);
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
"uri-security-supported", NULL, "none");
+ if (p->printer_id)
+ ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, "printer-id", p->printer_id);
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
p->name);
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("finishings-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-account-id-default"));
- cupsArrayAdd(CommonDefaults,
- _cupsStrAlloc("job-accounting-user-id-default"));
+ cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-accounting-user-id-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-cancel-after-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-hold-until-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-priority-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("job-sheets-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("media-col-default"));
+ cupsArrayAdd(CommonDefaults, _cupsStrAlloc("notify-lease-duration-default"));
+ cupsArrayAdd(CommonDefaults, _cupsStrAlloc("notify-events-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("number-up-default"));
- cupsArrayAdd(CommonDefaults,
- _cupsStrAlloc("orientation-requested-default"));
+ cupsArrayAdd(CommonDefaults, _cupsStrAlloc("orientation-requested-default"));
+ cupsArrayAdd(CommonDefaults, _cupsStrAlloc("print-quality-default"));
}
/*
ipp_attribute_t *attr; /* Attribute data */
_ipp_value_t *val; /* Attribute value */
int num_finishings, /* Number of finishings */
- finishings[5]; /* finishings-supported values */
+ finishings[100]; /* finishings-supported values */
int num_qualities, /* Number of print-quality values */
qualities[3]; /* print-quality values */
int num_margins, /* Number of media-*-margin-supported values */
if (ppdFindOption(ppd, "Collate") != NULL)
p->type |= CUPS_PRINTER_COLLATE;
- if (ppdFindOption(ppd, "StapleLocation") != NULL)
+ if (p->pc && p->pc->finishings)
{
- p->type |= CUPS_PRINTER_STAPLE;
- finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
- }
+ _pwg_finishings_t *fin; /* Current finishing value */
- if (ppdFindOption(ppd, "BindEdge") != NULL)
- {
- p->type |= CUPS_PRINTER_BIND;
- finishings[num_finishings++] = IPP_FINISHINGS_BIND;
+ for (fin = (_pwg_finishings_t *)cupsArrayFirst(p->pc->finishings); fin; fin = (_pwg_finishings_t *)cupsArrayNext(p->pc->finishings))
+ {
+ if (num_finishings < (int)(sizeof(finishings) / sizeof(finishings[0])))
+ finishings[num_finishings++] = fin->value;
+
+ switch (fin->value)
+ {
+ case IPP_FINISHINGS_BIND :
+ case IPP_FINISHINGS_BIND_LEFT :
+ case IPP_FINISHINGS_BIND_TOP :
+ case IPP_FINISHINGS_BIND_RIGHT :
+ case IPP_FINISHINGS_BIND_BOTTOM :
+ case IPP_FINISHINGS_EDGE_STITCH :
+ case IPP_FINISHINGS_EDGE_STITCH_LEFT :
+ case IPP_FINISHINGS_EDGE_STITCH_TOP :
+ case IPP_FINISHINGS_EDGE_STITCH_RIGHT :
+ case IPP_FINISHINGS_EDGE_STITCH_BOTTOM :
+ p->type |= CUPS_PRINTER_BIND;
+ break;
+
+ case IPP_FINISHINGS_COVER :
+ p->type |= CUPS_PRINTER_COVER;
+ break;
+
+ case IPP_FINISHINGS_PUNCH :
+ case IPP_FINISHINGS_PUNCH_TOP_LEFT :
+ case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT :
+ case IPP_FINISHINGS_PUNCH_TOP_RIGHT :
+ case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT :
+ case IPP_FINISHINGS_PUNCH_DUAL_LEFT :
+ case IPP_FINISHINGS_PUNCH_DUAL_TOP :
+ case IPP_FINISHINGS_PUNCH_DUAL_RIGHT :
+ case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM :
+ case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT :
+ case IPP_FINISHINGS_PUNCH_TRIPLE_TOP :
+ case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT :
+ case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM :
+ case IPP_FINISHINGS_PUNCH_QUAD_LEFT :
+ case IPP_FINISHINGS_PUNCH_QUAD_TOP :
+ case IPP_FINISHINGS_PUNCH_QUAD_RIGHT :
+ case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM :
+ p->type |= CUPS_PRINTER_PUNCH;
+ break;
+
+ case IPP_FINISHINGS_STAPLE :
+ case IPP_FINISHINGS_STAPLE_TOP_LEFT :
+ case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT :
+ case IPP_FINISHINGS_STAPLE_TOP_RIGHT :
+ case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT :
+ case IPP_FINISHINGS_STAPLE_DUAL_LEFT :
+ case IPP_FINISHINGS_STAPLE_DUAL_TOP :
+ case IPP_FINISHINGS_STAPLE_DUAL_RIGHT :
+ case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM :
+ case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT :
+ case IPP_FINISHINGS_STAPLE_TRIPLE_TOP :
+ case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT :
+ case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM :
+ p->type |= CUPS_PRINTER_STAPLE;
+ break;
+
+ default :
+ break;
+ }
+ }
}
for (i = 0; i < ppd->num_sizes; i ++)
"printer-commands", NULL, "none");
}
- /*
- * 3D printer support...
- */
-
- if (ppdFindAttr(ppd, "cups3D", NULL))
- p->type |= CUPS_PRINTER_3D;
-
/*
* Show current and available port monitors for this printer...
*/
p->type |= CUPS_PRINTER_REMOTE;
- /*
- * Point the printer-uri-supported attribute to the
- * remote printer...
- */
-
- if (strchr(p->device_uri, '?'))
- {
- /*
- * Strip trailing "?options" from URI...
- */
-
- char resource[HTTP_MAX_URI], /* New URI */
- *ptr; /* Pointer into URI */
-
- strlcpy(resource, p->device_uri, sizeof(resource));
- if ((ptr = strchr(resource, '?')) != NULL)
- *ptr = '\0';
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-uri-supported", NULL, resource);
- }
- else
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-uri-supported", NULL, p->device_uri);
-
/*
* Then set the make-and-model accordingly...
*/