/*
- * "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $"
+ * "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $"
*
* Printer routines for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2009 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
*
* Contents:
*
- * cupsdAddPrinter() - Add a printer to the system.
- * cupsdAddPrinterHistory() - Add the current printer state to the history.
- * cupsdAddPrinterUser() - Add a user to the ACL.
- * cupsdCreateCommonData() - Create the common printer data.
- * cupsdDeleteAllPrinters() - Delete all printers from the system.
- * cupsdDeletePrinter() - Delete a printer from the system.
- * cupsdFindPrinter() - Find a printer in the list.
- * cupsdFreePrinterUsers() - Free allow/deny users.
- * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
- * cupsdRenamePrinter() - Rename a printer.
- * cupsdSaveAllPrinters() - Save all printer definitions to the
- * printers.conf file.
- * cupsdSetAuthInfoRequired() - Set the required authentication info.
- * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
- * file.
- * cupsdSetPrinterReasons() - Set/update the reasons strings.
- * cupsdSetPrinterState() - Update the current state of a printer.
- * cupsdStopPrinter() - Stop a printer from printing any jobs...
- * cupsdUpdatePrinters() - Update printers after a partial reload.
- * cupsdValidateDest() - Validate a printer/class destination.
- * cupsdWritePrintcap() - Write a pseudo-printcap file for older
- * applications that need it...
- * cupsdSanitizeURI() - Sanitize a device URI...
- * add_printer_defaults() - Add name-default attributes to the printer
- * attributes.
- * add_printer_filter() - Add a MIME filter for a printer.
- * add_printer_formats() - Add document-format-supported values for
- * a printer.
- * compare_printers() - Compare two printers.
- * delete_printer_filters() - Delete all MIME filters for a printer.
- * write_irix_config() - Update the config files used by the IRIX
- * desktop tools.
- * write_irix_state() - Update the status files used by IRIX
- * printing desktop tools.
+ * cupsdAddPrinter() - Add a printer to the system.
+ * cupsdAddPrinterHistory() - Add the current printer state to the history.
+ * cupsdAddPrinterUser() - Add a user to the ACL.
+ * cupsdCreateCommonData() - Create the common printer data.
+ * cupsdDeleteAllPrinters() - Delete all printers from the system.
+ * cupsdDeletePrinter() - Delete a printer from the system.
+ * cupsdFindDest() - Find a destination in the list.
+ * cupsdFindPrinter() - Find a printer in the list.
+ * cupsdFreePrinterUsers() - Free allow/deny users.
+ * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
+ * cupsdRenamePrinter() - Rename a printer.
+ * cupsdSaveAllPrinters() - Save all printer definitions to the
+ * printers.conf file.
+ * cupsdSetAuthInfoRequired() - Set the required authentication info.
+ * cupsdSetDeviceURI() - Set the device URI for a printer.
+ * cupsdSetPrinterAttr() - Set a printer attribute.
+ * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
+ * file.
+ * cupsdSetPrinterReasons() - Set/update the reasons strings.
+ * cupsdSetPrinterState() - Update the current state of a printer.
+ * cupsdStopPrinter() - Stop a printer from printing any jobs...
+ * cupsdUpdatePrinterPPD() - Update keywords in a printer's PPD file.
+ * cupsdUpdatePrinters() - Update printers after a partial reload.
+ * cupsdValidateDest() - Validate a printer/class destination.
+ * cupsdWritePrintcap() - Write a pseudo-printcap file for older
+ * applications that need it...
+ * add_printer_defaults() - Add name-default attributes to the printer
+ * attributes.
+ * add_printer_filter() - Add a MIME filter for a printer.
+ * add_printer_formats() - Add document-format-supported values for a
+ * printer.
+ * add_string_array() - Add a string to an array of CUPS strings.
+ * compare_printers() - Compare two printers.
+ * delete_printer_filters() - Delete all MIME filters for a printer.
+ * delete_string_array() - Delete an array of CUPS strings.
+ * load_ppd() - Load a cached PPD file, updating the cache as
+ * needed.
+ * write_irix_config() - Update the config files used by the IRIX
+ * desktop tools.
+ * write_irix_state() - Update the status files used by IRIX printing
+ * desktop tools.
+ * write_xml_string() - Write a string with XML escaping.
*/
/*
#include "cupsd.h"
#include <cups/dir.h>
+#include <cups/pwgmedia.h>
/*
static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type,
const char *filter);
static void add_printer_formats(cupsd_printer_t *p);
+static void add_string_array(cups_array_t **a, const char *s);
static int compare_printers(void *first, void *second, void *data);
static void delete_printer_filters(cupsd_printer_t *p);
+static void delete_string_array(cups_array_t **a);
+static void load_ppd(cupsd_printer_t *p);
#ifdef __sgi
static void write_irix_config(cupsd_printer_t *p);
static void write_irix_state(cupsd_printer_t *p);
#endif /* __sgi */
+static void write_xml_string(cups_file_t *fp, const char *s);
/*
cupsdSetString(&p->hostname, ServerName);
cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name);
- cupsdSetStringf(&p->device_uri, "file:/dev/null");
+ cupsdSetDeviceURI(p, "file:///dev/null");
p->state = IPP_PRINTER_STOPPED;
p->state_time = time(NULL);
if (!Printers)
Printers = cupsArrayNew(compare_printers, NULL);
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdAddPrinter: Adding %s to Printers", p->name);
cupsArrayAdd(Printers, p);
if (!ImplicitPrinters)
#endif /* __APPLE__ */
if (p->num_reasons == 0)
ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "printer-state-reasons", NULL,
- p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
+ "printer-state-reasons", NULL, "none");
else
ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
"printer-state-reasons", p->num_reasons, NULL,
static const char * const versions[] =/* ipp-versions-supported values */
{
"1.0",
- "1.1"
+ "1.1",
+ "2.0",
+ "2.1"
};
static const int ops[] = /* operations-supported values */
{
IPP_PAUSE_PRINTER,
IPP_RESUME_PRINTER,
IPP_PURGE_JOBS,
+ IPP_SET_PRINTER_ATTRIBUTES,
IPP_SET_JOB_ATTRIBUTES,
+ IPP_GET_PRINTER_SUPPORTED_VALUES,
IPP_CREATE_PRINTER_SUBSCRIPTION,
IPP_CREATE_JOB_SUBSCRIPTION,
IPP_GET_SUBSCRIPTION_ATTRIBUTES,
IPP_GET_NOTIFICATIONS,
IPP_ENABLE_PRINTER,
IPP_DISABLE_PRINTER,
+ IPP_HOLD_NEW_JOBS,
+ IPP_RELEASE_HELD_NEW_JOBS,
CUPS_GET_DEFAULT,
CUPS_GET_PRINTERS,
CUPS_ADD_PRINTER,
,"gzip"
#endif /* HAVE_LIBZ */
};
+ static const char * const media_col_supported[] =
+ { /* media-col-supported values */
+ "media-color",
+ "media-key",
+ "media-size",
+ "media-type"
+ };
static const char * const multiple_document_handling[] =
{ /* multiple-document-handling-supported values */
"separate-documents-uncollated-copies",
static const char * const errors[] = /* printer-error-policy-supported values */
{
"abort-job",
+ "retry-current-job",
"retry-job",
"stop-printer"
};
"server-started",
"server-stopped"
};
+ static const char * const job_settable[] =
+ { /* job-settable-attributes-supported */
+ "copies",
+ "finishings",
+ "job-hold-until",
+ "job-priority",
+ "media",
+ "multiple-document-handling",
+ "number-up",
+ "orientation-requested",
+ "page-ranges",
+ "print-quality",
+ "printer-resolution",
+ "sides"
+ };
+ static const char * const printer_settable[] =
+ { /* printer-settable-attributes-supported */
+ "printer-info",
+ "printer-location"
+ };
if (CommonData)
*/
/* charset-configured */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY,
"charset-configured", NULL, DefaultCharset);
/* charset-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET | IPP_TAG_COPY,
"charset-supported", sizeof(charsets) / sizeof(charsets[0]),
NULL, charsets);
/* compression-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"compression-supported",
sizeof(compressions) / sizeof(compressions[0]),
NULL, compressions);
ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
/* cups-version */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT, "cups-version",
- NULL, CUPS_SVERSION + 6);
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_TEXT | IPP_TAG_COPY,
+ "cups-version", NULL, CUPS_SVERSION + 6);
/* generated-natural-language-supported */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE | IPP_TAG_COPY,
"generated-natural-language-supported", NULL, DefaultLanguage);
/* ipp-versions-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
NULL, versions);
/* job-hold-until-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
NULL, holds);
ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
"job-priority-supported", 100);
+ /* job-settable-attributes-supported */
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
+ "job-settable-attributes-supported",
+ sizeof(job_settable) / sizeof(job_settable[0]),
+ NULL, job_settable);
+
/* job-sheets-supported */
if (cupsArrayCount(Banners) > 0)
{
*/
if (Classification && !ClassifyOverride)
- attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ attr = ippAddString(CommonData, IPP_TAG_PRINTER,
+ IPP_TAG_NAME | IPP_TAG_COPY,
"job-sheets-supported", NULL, Classification);
else
- attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ attr = ippAddStrings(CommonData, IPP_TAG_PRINTER,
+ IPP_TAG_NAME | IPP_TAG_COPY,
"job-sheets-supported", cupsArrayCount(Banners) + 1,
NULL, NULL);
for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
banner;
i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
- attr->values[i].string.text = _cupsStrAlloc(banner->name);
+ attr->values[i].string.text = banner->name;
}
}
else
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
"job-sheets-supported", NULL, "none");
+ /* media-col-supported */
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
+ "media-col-supported",
+ sizeof(media_col_supported) /
+ sizeof(media_col_supported[0]), NULL,
+ media_col_supported);
+
/* multiple-document-handling-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"multiple-document-handling-supported",
sizeof(multiple_document_handling) /
sizeof(multiple_document_handling[0]), NULL,
/* multiple-operation-time-out */
ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "multiple-operation-time-out", 60);
+ "multiple-operation-time-out", MultipleOperationTimeout);
/* natural-language-configured */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE | IPP_TAG_COPY,
"natural-language-configured", NULL, DefaultLanguage);
/* notify-attributes-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"notify-attributes-supported",
(int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
NULL, notify_attrs);
"notify-max-events-supported", MaxEvents);
/* notify-events-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"notify-events-supported",
(int)(sizeof(notify_events) / sizeof(notify_events[0])),
NULL, notify_events);
/* notify-pull-method-supported */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"notify-pull-method-supported", NULL, "ippget");
/* notify-schemes-supported */
ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);
/* pdf-override-supported */
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
"pdl-override-supported", NULL, "not-attempted");
/* printer-error-policy-supported */
- ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
"printer-error-policy-supported",
sizeof(errors) / sizeof(errors[0]), NULL, errors);
/* printer-op-policy-supported */
- attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY,
"printer-op-policy-supported", cupsArrayCount(Policies),
NULL, NULL);
for (i = 0, p = (cupsd_policy_t *)cupsArrayFirst(Policies);
p;
i ++, p = (cupsd_policy_t *)cupsArrayNext(Policies))
- attr->values[i].string.text = _cupsStrAlloc(p->name);
+ attr->values[i].string.text = p->name;
+
+ /* printer-settable-attributes-supported */
+ ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD | IPP_TAG_COPY,
+ "printer-settable-attributes-supported",
+ sizeof(printer_settable) / sizeof(printer_settable[0]),
+ NULL, printer_settable);
+ /* server-is-sharing-printers */
ippAddBoolean(CommonData, IPP_TAG_PRINTER, "server-is-sharing-printers",
BrowseLocalProtocols != 0 && Browsing);
}
for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
p;
p = (cupsd_printer_t *)cupsArrayNext(Printers))
- if (!(p->type & CUPS_PRINTER_CLASS))
- cupsdDeletePrinter(p, 0);
+ cupsdDeletePrinter(p, 0);
}
cupsd_printer_t *p, /* I - Printer to delete */
int update) /* I - Update printers.conf? */
{
- int i; /* Looping var */
+ int i; /* Looping var */
#ifdef __sgi
- char filename[1024]; /* Interface script filename */
+ char filename[1024]; /* Interface script filename */
#endif /* __sgi */
* Remove the printer from the list...
*/
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdDeletePrinter: Removing %s from Printers", p->name);
cupsArrayRemove(Printers, p);
if (p->type & CUPS_PRINTER_IMPLICIT)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdDeletePrinter: Removing %s from ImplicitPrinters",
+ p->name);
cupsArrayRemove(ImplicitPrinters, p);
+ }
/*
* Remove the dummy interface/icon/option files under IRIX...
free(p->history);
}
+ delete_printer_filters(p);
+
for (i = 0; i < p->num_reasons; i ++)
- free(p->reasons[i]);
+ _cupsStrFree(p->reasons[i]);
ippDelete(p->attrs);
-
- delete_printer_filters(p);
+ ippDelete(p->ppd_attrs);
mimeDeleteType(MimeDatabase, p->filetype);
mimeDeleteType(MimeDatabase, p->prefiltertype);
+ delete_string_array(&(p->filters));
+ delete_string_array(&(p->pre_filters));
+
cupsdFreePrinterUsers(p);
cupsdFreeQuotas(p);
cupsdClearString(&p->job_sheets[0]);
cupsdClearString(&p->job_sheets[1]);
cupsdClearString(&p->device_uri);
+ cupsdClearString(&p->sanitized_device_uri);
cupsdClearString(&p->port_monitor);
cupsdClearString(&p->op_policy);
cupsdClearString(&p->error_policy);
void
cupsdLoadAllPrinters(void)
{
+ int i; /* Looping var */
cups_file_t *fp; /* printers.conf file */
int linenum; /* Current line number */
- char line[1024], /* Line from file */
+ char line[4096], /* Line from file */
*value, /* Pointer to value */
*valueptr; /* Pointer into value */
cupsd_printer_t *p; /* Current printer */
DefaultPrinter = p;
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "</Printer>"))
{
cupsdSetPrinterAttrs(p);
cupsdAddPrinterHistory(p);
- if (p->device_uri && strncmp(p->device_uri, "file:", 5) &&
+ if (strncmp(p->device_uri, "file:", 5) &&
p->state != IPP_PRINTER_STOPPED)
{
/*
p = NULL;
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!p)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
}
else if (!strcasecmp(line, "AuthInfoRequired"))
{
if (value)
cupsdSetString(&p->info, value);
}
+ else if (!strcasecmp(line, "MakeModel"))
+ {
+ if (value)
+ cupsdSetString(&p->make_model, value);
+ }
else if (!strcasecmp(line, "Location"))
{
if (value)
else if (!strcasecmp(line, "DeviceURI"))
{
if (value)
- cupsdSetString(&p->device_uri, value);
+ cupsdSetDeviceURI(p, value);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "Option") && value)
{
else if (value)
cupsdClearString(&p->port_monitor);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
+ }
+ else if (!strcasecmp(line, "Reason"))
+ {
+ if (value &&
+ strcmp(value, "com.apple.print.recoverable-warning") &&
+ strcmp(value, "connecting-to-device") &&
+ strcmp(value, "cups-insecure-filter-error") &&
+ strcmp(value, "cups-missing-filter-error"))
+ {
+ for (i = 0 ; i < p->num_reasons; i ++)
+ if (!strcmp(value, p->reasons[i]))
+ break;
+
+ if (i >= p->num_reasons &&
+ p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
+ {
+ p->reasons[p->num_reasons] = _cupsStrAlloc(value);
+ p->num_reasons ++;
+ }
}
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
}
else if (!strcasecmp(line, "State"))
{
if (value && !strcasecmp(value, "idle"))
p->state = IPP_PRINTER_IDLE;
else if (value && !strcasecmp(value, "stopped"))
+ {
p->state = IPP_PRINTER_STOPPED;
+ cupsdSetPrinterReasons(p, "+paused");
+ }
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "StateMessage"))
{
!strcasecmp(value, "false")))
p->accepting = 0;
else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
+ }
+ else if (!strcasecmp(line, "Type"))
+ {
+ if (value)
+ p->type = atoi(value);
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
+ }
+ else if (!strcasecmp(line, "Product"))
+ {
+ if (value)
+ {
+#ifdef HAVE_DNSSD
+ p->product = _cupsStrAlloc(value);
+#endif /* HAVE_DNSSD */
+ }
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
+ }
+ else if (!strcasecmp(line, "Filter"))
+ {
+ if (value)
{
+ if (!p->filters)
+ p->filters = cupsArrayNew(NULL, NULL);
+
+ cupsArrayAdd(p->filters, _cupsStrAlloc(value));
+ }
+ else
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
+ }
+ else if (!strcasecmp(line, "PreFilter"))
+ {
+ if (value)
+ {
+ if (!p->pre_filters)
+ p->pre_filters = cupsArrayNew(NULL, NULL);
+
+ cupsArrayAdd(p->pre_filters, _cupsStrAlloc(value));
}
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
}
else if (!strcasecmp(line, "Shared"))
{
!strcasecmp(value, "false")))
p->shared = 0;
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "JobSheets"))
{
for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
if (*valueptr)
- *valueptr++ = '\0';
+ *valueptr = '\0';
cupsdSetString(&p->job_sheets[1], value);
}
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "AllowUser"))
{
cupsdAddPrinterUser(p, value);
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "DenyUser"))
{
cupsdAddPrinterUser(p, value);
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "QuotaPeriod"))
{
if (value)
p->quota_period = atoi(value);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "PageLimit"))
{
if (value)
p->page_limit = atoi(value);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "KLimit"))
{
if (value)
p->k_limit = atoi(value);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "OpPolicy"))
{
value, linenum);
}
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
- }
}
else if (!strcasecmp(line, "ErrorPolicy"))
{
if (value)
cupsdSetString(&p->error_policy, value);
else
- {
cupsdLogMessage(CUPSD_LOG_ERROR,
"Syntax error on line %d of printers.conf.", linenum);
- break;
+ }
+ else if (!strcasecmp(line, "Attribute") && value)
+ {
+ for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
+
+ if (!*valueptr)
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Syntax error on line %d of printers.conf.", linenum);
+ else
+ {
+ for (; *valueptr && isspace(*valueptr & 255); *valueptr++ = '\0');
+
+ if (!p->attrs)
+ cupsdSetPrinterAttrs(p);
+
+ if (!strcmp(value, "marker-change-time"))
+ p->marker_time = atoi(valueptr);
+ else
+ cupsdSetPrinterAttr(p, value, valueptr);
}
}
else
* Remove the printer from the array(s) first...
*/
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdRenamePrinter: Removing %s from Printers", p->name);
cupsArrayRemove(Printers, p);
if (p->type & CUPS_PRINTER_IMPLICIT)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdRenamePrinter: Removing %s from ImplicitPrinters",
+ p->name);
cupsArrayRemove(ImplicitPrinters, p);
+ }
/*
* Rename the printer type...
* Add the printer back to the printer array(s)...
*/
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdRenamePrinter: Adding %s to Printers", p->name);
cupsArrayAdd(Printers, p);
if (p->type & CUPS_PRINTER_IMPLICIT)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdRenamePrinter: Adding %s to ImplicitPrinters",
+ p->name);
cupsArrayAdd(ImplicitPrinters, p);
+ }
}
{
int i; /* Looping var */
cups_file_t *fp; /* printers.conf file */
- char temp[1024]; /* Temporary string */
- char backup[1024]; /* printers.conf.O file */
+ char temp[1024], /* Temporary string */
+ backup[1024], /* printers.conf.O file */
+ value[2048], /* Value string */
+ *ptr; /* Pointer into value */
cupsd_printer_t *printer; /* Current printer class */
time_t curtime; /* Current time */
struct tm *curdate; /* Current date */
cups_option_t *option; /* Current option */
- const char *ptr; /* Pointer into info/location */
+ ipp_attribute_t *marker; /* Current marker attribute */
/*
if (printer->num_auth_info_required > 0)
{
- cupsFilePrintf(fp, "AuthInfoRequired %s", printer->auth_info_required[0]);
- for (i = 1; i < printer->num_auth_info_required; i ++)
- cupsFilePrintf(fp, ",%s", printer->auth_info_required[i]);
- cupsFilePutChar(fp, '\n');
- }
-
- if (printer->info)
- {
- if ((ptr = strchr(printer->info, '#')) != NULL)
+ switch (printer->num_auth_info_required)
{
- /*
- * Need to quote the first # in the info string...
- */
-
- cupsFilePuts(fp, "Info ");
- cupsFileWrite(fp, printer->info, ptr - printer->info);
- cupsFilePutChar(fp, '\\');
- cupsFilePuts(fp, ptr);
- cupsFilePutChar(fp, '\n');
+ case 1 :
+ strlcpy(value, printer->auth_info_required[0], sizeof(value));
+ break;
+
+ case 2 :
+ snprintf(value, sizeof(value), "%s,%s",
+ printer->auth_info_required[0],
+ printer->auth_info_required[1]);
+ break;
+
+ case 3 :
+ default :
+ snprintf(value, sizeof(value), "%s,%s,%s",
+ printer->auth_info_required[0],
+ printer->auth_info_required[1],
+ printer->auth_info_required[2]);
+ break;
}
- else
- cupsFilePrintf(fp, "Info %s\n", printer->info);
+
+ cupsFilePutConf(fp, "AuthInfoRequired", value);
}
+ if (printer->info)
+ cupsFilePutConf(fp, "Info", printer->info);
+
if (printer->location)
- {
- if ((ptr = strchr(printer->info, '#')) != NULL)
- {
- /*
- * Need to quote the first # in the location string...
- */
+ cupsFilePutConf(fp, "Location", printer->location);
- cupsFilePuts(fp, "Location ");
- cupsFileWrite(fp, printer->location, ptr - printer->location);
- cupsFilePutChar(fp, '\\');
- cupsFilePuts(fp, ptr);
- cupsFilePutChar(fp, '\n');
- }
- else
- cupsFilePrintf(fp, "Location %s\n", printer->location);
- }
- if (printer->device_uri)
- cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
+ if (printer->make_model)
+ cupsFilePutConf(fp, "MakeModel", printer->make_model);
+
+ cupsFilePutConf(fp, "DeviceURI", printer->device_uri);
if (printer->port_monitor)
- cupsFilePrintf(fp, "PortMonitor %s\n", printer->port_monitor);
+ cupsFilePutConf(fp, "PortMonitor", printer->port_monitor);
if (printer->state == IPP_PRINTER_STOPPED)
{
cupsFilePuts(fp, "State Stopped\n");
- cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
+
+ if (printer->state_message)
+ cupsFilePutConf(fp, "StateMessage", printer->state_message);
}
else
cupsFilePuts(fp, "State Idle\n");
cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
+ for (i = 0; i < printer->num_reasons; i ++)
+ if (strcmp(printer->reasons[i], "com.apple.print.recoverable-warning") &&
+ strcmp(printer->reasons[i], "connecting-to-device") &&
+ strcmp(printer->reasons[i], "cups-insecure-filter-error") &&
+ strcmp(printer->reasons[i], "cups-missing-filter-error"))
+ cupsFilePutConf(fp, "Reason", printer->reasons[i]);
+
+ cupsFilePrintf(fp, "Type %d\n", printer->type);
+
+#ifdef HAVE_DNSSD
+ if (printer->product)
+ cupsFilePutConf(fp, "Product", printer->product);
+#endif /* HAVE_DNSSD */
+
+ for (ptr = (char *)cupsArrayFirst(printer->filters);
+ ptr;
+ ptr = (char *)cupsArrayNext(printer->filters))
+ cupsFilePutConf(fp, "Filter", ptr);
+
+ for (ptr = (char *)cupsArrayFirst(printer->pre_filters);
+ ptr;
+ ptr = (char *)cupsArrayNext(printer->pre_filters))
+ cupsFilePutConf(fp, "PreFilter", ptr);
+
if (printer->accepting)
cupsFilePuts(fp, "Accepting Yes\n");
else
else
cupsFilePuts(fp, "Shared No\n");
- cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
- printer->job_sheets[1]);
+ snprintf(value, sizeof(value), "%s %s", printer->job_sheets[0],
+ printer->job_sheets[1]);
+ cupsFilePutConf(fp, "JobSheets", value);
cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
for (i = 0; i < printer->num_users; i ++)
- cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
- printer->users[i]);
+ cupsFilePutConf(fp, printer->deny_users ? "DenyUser" : "AllowUser",
+ printer->users[i]);
if (printer->op_policy)
- cupsFilePrintf(fp, "OpPolicy %s\n", printer->op_policy);
+ cupsFilePutConf(fp, "OpPolicy", printer->op_policy);
if (printer->error_policy)
- cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy);
+ cupsFilePutConf(fp, "ErrorPolicy", printer->error_policy);
for (i = printer->num_options, option = printer->options;
i > 0;
i --, option ++)
- cupsFilePrintf(fp, "Option %s %s\n", option->name, option->value);
+ {
+ snprintf(value, sizeof(value), "%s %s", option->name, option->value);
+ cupsFilePutConf(fp, "Option", value);
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-colors",
+ IPP_TAG_NAME)) != NULL)
+ {
+ snprintf(value, sizeof(value), "%s ", marker->name);
+
+ for (i = 0, ptr = value + strlen(value);
+ i < marker->num_values && ptr < (value + sizeof(value) - 1);
+ i ++)
+ {
+ if (i)
+ *ptr++ = ',';
+
+ strlcpy(ptr, marker->values[i].string.text,
+ value + sizeof(value) - ptr);
+ ptr += strlen(ptr);
+ }
+
+ *ptr = '\0';
+ cupsFilePutConf(fp, "Attribute", value);
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ cupsFilePrintf(fp, "Attribute %s %d", marker->name,
+ marker->values[0].integer);
+ for (i = 1; i < marker->num_values; i ++)
+ cupsFilePrintf(fp, ",%d", marker->values[i].integer);
+ cupsFilePuts(fp, "\n");
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-low-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ cupsFilePrintf(fp, "Attribute %s %d", marker->name,
+ marker->values[0].integer);
+ for (i = 1; i < marker->num_values; i ++)
+ cupsFilePrintf(fp, ",%d", marker->values[i].integer);
+ cupsFilePuts(fp, "\n");
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-high-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ cupsFilePrintf(fp, "Attribute %s %d", marker->name,
+ marker->values[0].integer);
+ for (i = 1; i < marker->num_values; i ++)
+ cupsFilePrintf(fp, ",%d", marker->values[i].integer);
+ cupsFilePuts(fp, "\n");
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-message",
+ IPP_TAG_TEXT)) != NULL)
+ {
+ snprintf(value, sizeof(value), "%s %s", marker->name,
+ marker->values[0].string.text);
+
+ cupsFilePutConf(fp, "Attribute", value);
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-names",
+ IPP_TAG_NAME)) != NULL)
+ {
+ snprintf(value, sizeof(value), "%s ", marker->name);
+
+ for (i = 0, ptr = value + strlen(value);
+ i < marker->num_values && ptr < (value + sizeof(value) - 1);
+ i ++)
+ {
+ if (i)
+ *ptr++ = ',';
+
+ strlcpy(ptr, marker->values[i].string.text,
+ value + sizeof(value) - ptr);
+ ptr += strlen(ptr);
+ }
+
+ *ptr = '\0';
+ cupsFilePutConf(fp, "Attribute", value);
+ }
+
+ if ((marker = ippFindAttribute(printer->attrs, "marker-types",
+ IPP_TAG_KEYWORD)) != NULL)
+ {
+ snprintf(value, sizeof(value), "%s ", marker->name);
+
+ for (i = 0, ptr = value + strlen(value);
+ i < marker->num_values && ptr < (value + sizeof(value) - 1);
+ i ++)
+ {
+ if (i)
+ *ptr++ = ',';
+
+ strlcpy(ptr, marker->values[i].string.text,
+ value + sizeof(value) - ptr);
+ ptr += strlen(ptr);
+ }
+
+ *ptr = '\0';
+ cupsFilePutConf(fp, "Attribute", value);
+ }
+
+ if (printer->marker_time)
+ cupsFilePrintf(fp, "Attribute marker-change-time %ld\n",
+ (long)printer->marker_time);
cupsFilePuts(fp, "</Printer>\n");
/*
- * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
+ * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
*/
void
-cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
+cupsdSetDeviceURI(cupsd_printer_t *p, /* I - Printer */
+ const char *uri) /* I - Device URI */
{
- int i, /* Looping var */
- length; /* Length of browse attributes */
- char uri[HTTP_MAX_URI]; /* URI for printer */
- char resource[HTTP_MAX_URI]; /* Resource portion of URI */
- char filename[1024]; /* Name of PPD file */
- int num_air; /* Number of auth-info-required values */
- const char * const *air; /* auth-info-required values */
- int num_media; /* Number of media options */
- cupsd_location_t *auth; /* Pointer to authentication element */
- const char *auth_supported; /* Authentication supported */
- ppd_file_t *ppd; /* PPD file data */
- ppd_option_t *input_slot, /* InputSlot options */
- *media_type, /* MediaType options */
- *page_size, /* PageSize options */
- *output_bin, /* OutputBin options */
- *media_quality, /* EFMediaQualityMode options */
- *duplex; /* Duplex options */
- ppd_attr_t *ppdattr; /* PPD attribute */
- ipp_attribute_t *attr; /* Attribute data */
- ipp_value_t *val; /* Attribute value */
- int num_finishings; /* Number of finishings */
- int finishings[5]; /* finishings-supported values */
- cups_option_t *option; /* Current printer option */
- static const char * const sides[3] = /* sides-supported values */
- {
- "one-sided",
- "two-sided-long-edge",
- "two-sided-short-edge"
- };
- static const char * const air_userpass[] =
- { /* Basic/Digest authentication */
- "username",
- "password"
- };
-#ifdef HAVE_GSSAPI
- static const char * const air_negotiate[] =
- { /* Kerberos authentication */
- "negotiate"
- };
-#endif /* HAVE_GSSAPI */
- static const char * const air_none[] =
- { /* No authentication */
- "none"
- };
-
+ char buffer[1024], /* URI buffer */
+ *start, /* Start of data after scheme */
+ *slash, /* First slash after scheme:// */
+ *ptr; /* Pointer into user@host:port part */
- DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
- p->type));
/*
- * Make sure that we have the common attributes defined...
+ * Set the full device URI..
*/
- if (!CommonData)
- cupsdCreateCommonData();
+ cupsdSetString(&(p->device_uri), uri);
/*
- * Clear out old filters, if any...
+ * Copy the device URI to a temporary buffer so we can sanitize any auth
+ * info in it...
*/
- delete_printer_filters(p);
+ strlcpy(buffer, uri, sizeof(buffer));
/*
- * Figure out the authentication that is required for the printer.
+ * Find the end of the scheme:// part...
*/
- auth_supported = "requesting-user-name";
- num_air = 1;
- air = air_none;
-
- if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
+ if ((ptr = strchr(buffer, ':')) != NULL)
{
- num_air = p->num_auth_info_required;
- air = p->auth_info_required;
+ for (start = ptr + 1; *start; start ++)
+ if (*start != '/')
+ break;
- if (!strcmp(air[0], "username"))
- auth_supported = "basic";
- else
- auth_supported = "negotiate";
- }
- else if (!(p->type & CUPS_PRINTER_DISCOVERED))
+ /*
+ * Find the next slash (/) in the URI...
+ */
+
+ if ((slash = strchr(start, '/')) == NULL)
+ slash = start + strlen(start); /* No slash, point to the end */
+
+ /*
+ * Check for an @ sign before the slash...
+ */
+
+ if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
+ {
+ /*
+ * Found an @ sign and it is before the resource part, so we have
+ * an authentication string. Copy the remaining URI over the
+ * authentication string...
+ */
+
+ _cups_strcpy(start, ptr + 1);
+ }
+ }
+
+ /*
+ * Save the sanitized URI...
+ */
+
+ cupsdSetString(&(p->sanitized_device_uri), buffer);
+}
+
+
+/*
+ * 'cupsdSetPrinterAttr()' - Set a printer attribute.
+ */
+
+void
+cupsdSetPrinterAttr(
+ cupsd_printer_t *p, /* I - Printer */
+ const char *name, /* I - Attribute name */
+ char *value) /* I - Attribute value string */
+{
+ ipp_attribute_t *attr; /* Attribute */
+ int i, /* Looping var */
+ count; /* Number of values */
+ char *ptr; /* Pointer into value */
+ ipp_tag_t value_tag; /* Value tag for this attribute */
+
+
+ /*
+ * Don't allow empty values...
+ */
+
+ if (!*value && strcmp(name, "marker-message"))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Ignoring empty \"%s\" attribute", name);
+ return;
+ }
+
+ /*
+ * Count the number of values...
+ */
+
+ for (count = 1, ptr = value;
+ (ptr = strchr(ptr, ',')) != NULL;
+ ptr ++, count ++);
+
+ /*
+ * Then add or update the attribute as needed...
+ */
+
+ if (!strcmp(name, "marker-levels") || !strcmp(name, "marker-low-levels") ||
+ !strcmp(name, "marker-high-levels"))
+ {
+ /*
+ * Integer values...
+ */
+
+ if ((attr = ippFindAttribute(p->attrs, name, IPP_TAG_INTEGER)) != NULL &&
+ attr->num_values < count)
+ {
+ ippDeleteAttribute(p->attrs, attr);
+ attr = NULL;
+ }
+
+ if (attr)
+ attr->num_values = count;
+ else
+ attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER, name,
+ count, NULL);
+
+ if (!attr)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to allocate memory for printer attribute "
+ "(%d values)", count);
+ return;
+ }
+
+ for (i = 0; i < count; i ++)
+ {
+ if ((ptr = strchr(value, ',')) != NULL)
+ *ptr++ = '\0';
+
+ attr->values[i].integer = strtol(value, NULL, 10);
+
+ if (ptr)
+ value = ptr;
+ }
+ }
+ else
+ {
+ /*
+ * Name or keyword values...
+ */
+
+ if (!strcmp(name, "marker-types"))
+ value_tag = IPP_TAG_KEYWORD;
+ else if (!strcmp(name, "marker-message"))
+ value_tag = IPP_TAG_TEXT;
+ else
+ value_tag = IPP_TAG_NAME;
+
+ if ((attr = ippFindAttribute(p->attrs, name, value_tag)) != NULL &&
+ attr->num_values < count)
+ {
+ ippDeleteAttribute(p->attrs, attr);
+ attr = NULL;
+ }
+
+ if (attr)
+ {
+ for (i = 0; i < attr->num_values; i ++)
+ _cupsStrFree(attr->values[i].string.text);
+
+ attr->num_values = count;
+ }
+ else
+ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, value_tag, name,
+ count, NULL, NULL);
+
+ if (!attr)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to allocate memory for printer attribute "
+ "(%d values)", count);
+ return;
+ }
+
+ for (i = 0; i < count; i ++)
+ {
+ if ((ptr = strchr(value, ',')) != NULL)
+ *ptr++ = '\0';
+
+ attr->values[i].string.text = _cupsStrAlloc(value);
+
+ if (ptr)
+ value = ptr;
+ }
+ }
+}
+
+
+/*
+ * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
+ */
+
+void
+cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
+{
+ int i, /* Looping var */
+ length; /* Length of browse attributes */
+ char resource[HTTP_MAX_URI]; /* Resource portion of URI */
+ int num_air; /* Number of auth-info-required values */
+ const char * const *air; /* auth-info-required values */
+ cupsd_location_t *auth; /* Pointer to authentication element */
+ const char *auth_supported; /* Authentication supported */
+ ipp_t *oldattrs; /* Old printer attributes */
+ ipp_attribute_t *attr; /* Attribute data */
+ cups_option_t *option; /* Current printer option */
+ char *filter; /* Current filter */
+ static const char * const air_userpass[] =
+ { /* Basic/Digest authentication */
+ "username",
+ "password"
+ };
+#ifdef HAVE_GSSAPI
+ static const char * const air_negotiate[] =
+ { /* Kerberos authentication */
+ "negotiate"
+ };
+#endif /* HAVE_GSSAPI */
+ static const char * const air_none[] =
+ { /* No authentication */
+ "none"
+ };
+
+
+ DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
+ p->type));
+
+ /*
+ * Make sure that we have the common attributes defined...
+ */
+
+ if (!CommonData)
+ cupsdCreateCommonData();
+
+ /*
+ * Clear out old filters, if any...
+ */
+
+ delete_printer_filters(p);
+
+ /*
+ * Figure out the authentication that is required for the printer.
+ */
+
+ auth_supported = "requesting-user-name";
+ num_air = 1;
+ air = air_none;
+
+ if (p->num_auth_info_required > 0 && strcmp(p->auth_info_required[0], "none"))
+ {
+ num_air = p->num_auth_info_required;
+ air = p->auth_info_required;
+
+ if (!strcmp(air[0], "username"))
+ auth_supported = "basic";
+ else
+ auth_supported = "negotiate";
+ }
+ else if (!(p->type & CUPS_PRINTER_DISCOVERED))
{
if (p->type & CUPS_PRINTER_CLASS)
snprintf(resource, sizeof(resource), "/classes/%s", p->name);
if (auth)
{
- if (auth->type == CUPSD_AUTH_BASIC || auth->type == CUPSD_AUTH_BASICDIGEST)
+ int auth_type; /* Authentication type */
+
+
+ if ((auth_type = auth->type) == CUPSD_AUTH_DEFAULT)
+ auth_type = DefaultAuthType;
+
+ if (auth_type == CUPSD_AUTH_BASIC || auth_type == CUPSD_AUTH_BASICDIGEST)
{
auth_supported = "basic";
num_air = 2;
air = air_userpass;
}
- else if (auth->type == CUPSD_AUTH_DIGEST)
+ else if (auth_type == CUPSD_AUTH_DIGEST)
{
auth_supported = "digest";
num_air = 2;
air = air_userpass;
}
#ifdef HAVE_GSSAPI
- else if (auth->type == CUPSD_AUTH_NEGOTIATE)
+ else if (auth_type == CUPSD_AUTH_NEGOTIATE)
{
auth_supported = "negotiate";
num_air = 1;
}
#endif /* HAVE_GSSAPI */
- if (auth->type != CUPSD_AUTH_NONE)
+ if (auth_type != CUPSD_AUTH_NONE)
p->type |= CUPS_PRINTER_AUTHENTICATED;
else
p->type &= ~CUPS_PRINTER_AUTHENTICATED;
* Create the required IPP attributes for a printer...
*/
- if (p->attrs)
- ippDelete(p->attrs);
-
+ oldattrs = p->attrs;
p->attrs = ippNew();
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
NULL, p->location ? p->location : "");
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
NULL, p->info ? p->info : "");
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
- NULL, p->uri);
if (p->num_users)
{
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
"printer-uri-supported", NULL, p->uri);
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
+ NULL, p->uri);
+
if (p->make_model)
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
"printer-make-and-model", NULL, p->make_model);
* or class...
*/
- p->type &= ~CUPS_PRINTER_OPTIONS;
-
if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
{
p->raw = 1;
+ p->type &= ~CUPS_PRINTER_OPTIONS;
/*
* Add class-specific attributes...
if (p->num_printers > 0)
{
/*
- * Add a list of member URIs and names...
+ * Add a list of member names; URIs are added in copy_printer_attrs...
*/
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
- "member-uris", p->num_printers, NULL, NULL);
+ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "member-names", p->num_printers, NULL, NULL);
p->type |= CUPS_PRINTER_OPTIONS;
for (i = 0; i < p->num_printers; i ++)
{
if (attr != NULL)
- attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->uri);
+ attr->values[i].string.text = _cupsStrRetain(p->printers[i]->name);
p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
}
-
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "member-names", p->num_printers, NULL, NULL);
-
- if (attr != NULL)
- {
- for (i = 0; i < p->num_printers; i ++)
- attr->values[i].string.text = _cupsStrAlloc(p->printers[i]->name);
- }
}
}
else
{
/*
- * Add printer-specific attributes... Start by sanitizing the device
- * URI so it doesn't have a username or password in it...
+ * Add printer-specific attributes...
*/
- if (!p->device_uri)
- strcpy(uri, "file:/dev/null");
- else if (strstr(p->device_uri, "://") != NULL)
- {
- /*
- * http://..., ipp://..., etc.
- */
-
- cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));
- }
- else
- {
- /*
- * file:..., serial:..., etc.
- */
-
- strlcpy(uri, p->device_uri, sizeof(uri));
- }
-
ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
- uri);
+ p->sanitized_device_uri);
/*
* Assign additional attributes from the PPD file (if any)...
*/
- p->type |= CUPS_PRINTER_BW;
- finishings[0] = IPP_FINISHINGS_NONE;
- num_finishings = 1;
+ load_ppd(p);
- snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
- p->name);
+ /*
+ * Add filters for printer...
+ */
- if ((ppd = ppdOpenFile(filename)) != NULL)
- {
- /*
- * Add make/model and other various attributes...
- */
+ cupsdSetPrinterReasons(p, "-cups-missing-filter-error");
- if (ppd->color_device)
- p->type |= CUPS_PRINTER_COLOR;
- if (ppd->variable_sizes)
- p->type |= CUPS_PRINTER_VARIABLE;
- if (!ppd->manual_copies)
- p->type |= CUPS_PRINTER_COPIES;
- if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
- if (ppdattr->value && !strcasecmp(ppdattr->value, "true"))
- p->type |= CUPS_PRINTER_FAX;
-
- ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",
- ppd->color_device);
- if (ppd->throughput)
- ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
- "pages-per-minute", ppd->throughput);
-
- if (ppd->nickname)
- {
- /*
- * The NickName can be localized in the character set specified
- * by the LanugageEncoding attribute. However, ppdOpen2() has
- * already converted the ppd->nickname member to UTF-8 for us
- * (the original attribute value is available separately)
- */
+ for (filter = (char *)cupsArrayFirst(p->filters);
+ filter;
+ filter = (char *)cupsArrayNext(p->filters))
+ add_printer_filter(p, p->filetype, filter);
- cupsdSetString(&p->make_model, ppd->nickname);
- }
- else if (ppd->modelname)
- {
- /*
- * Model name can only contain specific characters...
- */
+ if (p->pre_filters)
+ {
+ p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
- cupsdSetString(&p->make_model, ppd->modelname);
- }
- else
- cupsdSetString(&p->make_model, "Bad PPD File");
+ for (filter = (char *)cupsArrayFirst(p->pre_filters);
+ filter;
+ filter = (char *)cupsArrayNext(p->pre_filters))
+ add_printer_filter(p, p->prefiltertype, filter);
+ }
+ }
+ }
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-make-and-model", NULL, p->make_model);
+ /*
+ * Copy marker attributes as needed...
+ */
- /*
- * Add media options from the PPD file...
- */
+ if (oldattrs)
+ {
+ ipp_attribute_t *oldattr; /* Old attribute */
- if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)
- num_media = input_slot->num_choices;
- else
- num_media = 0;
- if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
- num_media += media_type->num_choices;
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-colors",
+ IPP_TAG_NAME)) != NULL)
+ {
+ if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "marker-colors", oldattr->num_values, NULL,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].string.text =
+ _cupsStrRetain(oldattr->values[i].string.text);
+ }
+ }
- if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)
- num_media += page_size->num_choices;
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "marker-levels", oldattr->num_values,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].integer = oldattr->values[i].integer;
+ }
+ }
- if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)
- num_media += media_quality->num_choices;
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-low-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "marker-low-levels", oldattr->num_values,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].integer = oldattr->values[i].integer;
+ }
+ }
- if (num_media == 0)
- {
- cupsdLogMessage(CUPSD_LOG_CRIT,
- "The PPD file for printer %s contains no media "
- "options and is therefore invalid!", p->name);
- }
- else
- {
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-supported", num_media, NULL, NULL);
- if (attr != NULL)
- {
- val = attr->values;
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-high-levels",
+ IPP_TAG_INTEGER)) != NULL)
+ {
+ if ((attr = ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "marker-high-levels", oldattr->num_values,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].integer = oldattr->values[i].integer;
+ }
+ }
- if (input_slot != NULL)
- for (i = 0; i < input_slot->num_choices; i ++, val ++)
- val->string.text = _cupsStrAlloc(input_slot->choices[i].choice);
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-names",
+ IPP_TAG_NAME)) != NULL)
+ {
+ if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "marker-names", oldattr->num_values, NULL,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].string.text =
+ _cupsStrRetain(oldattr->values[i].string.text);
+ }
+ }
- if (media_type != NULL)
- for (i = 0; i < media_type->num_choices; i ++, val ++)
- val->string.text = _cupsStrAlloc(media_type->choices[i].choice);
+ if ((oldattr = ippFindAttribute(oldattrs, "marker-types",
+ IPP_TAG_KEYWORD)) != NULL)
+ {
+ if ((attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "marker-types", oldattr->num_values, NULL,
+ NULL)) != NULL)
+ {
+ for (i = 0; i < oldattr->num_values; i ++)
+ attr->values[i].string.text =
+ _cupsStrRetain(oldattr->values[i].string.text);
+ }
+ }
- if (media_quality != NULL)
- for (i = 0; i < media_quality->num_choices; i ++, val ++)
- val->string.text = _cupsStrAlloc(media_quality->choices[i].choice);
+ ippDelete(oldattrs);
+ }
- if (page_size != NULL)
- {
- for (i = 0; i < page_size->num_choices; i ++, val ++)
- val->string.text = _cupsStrAlloc(page_size->choices[i].choice);
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-default", NULL, page_size->defchoice);
- }
- else if (input_slot != NULL)
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-default", NULL, input_slot->defchoice);
- else if (media_type != NULL)
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-default", NULL, media_type->defchoice);
- else if (media_quality != NULL)
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-default", NULL, media_quality->defchoice);
- else
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "media-default", NULL, "none");
- }
- }
+ /*
+ * Force sharing off for remote queues...
+ */
- /*
- * Output bin...
- */
+ if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
+ p->shared = 0;
+ else
+ {
+ /*
+ * Copy the printer options into a browse attributes string we can re-use.
+ */
- if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
- {
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "output-bin-supported", output_bin->num_choices,
- NULL, NULL);
-
- if (attr != NULL)
- {
- for (i = 0, val = attr->values;
- i < output_bin->num_choices;
- i ++, val ++)
- val->string.text = _cupsStrAlloc(output_bin->choices[i].choice);
- }
- }
-
- /*
- * Duplexing, etc...
- */
-
- if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
- if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
- if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
- if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
- duplex = ppdFindOption(ppd, "JCLDuplex");
-
- if (duplex && duplex->num_choices > 1)
- {
- p->type |= CUPS_PRINTER_DUPLEX;
-
- ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "sides-supported", 3, NULL, sides);
-
- if (!strcasecmp(duplex->defchoice, "DuplexTumble"))
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "sides-default", NULL, "two-sided-short-edge");
- else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble"))
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "sides-default", NULL, "two-sided-long-edge");
- else
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
- "sides-default", NULL, "one-sided");
- }
-
- if (ppdFindOption(ppd, "Collate") != NULL)
- p->type |= CUPS_PRINTER_COLLATE;
-
- if (ppdFindOption(ppd, "StapleLocation") != NULL)
- {
- p->type |= CUPS_PRINTER_STAPLE;
- finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
- }
-
- if (ppdFindOption(ppd, "BindEdge") != NULL)
- {
- p->type |= CUPS_PRINTER_BIND;
- finishings[num_finishings++] = IPP_FINISHINGS_BIND;
- }
-
- for (i = 0; i < ppd->num_sizes; i ++)
- if (ppd->sizes[i].length > 1728)
- p->type |= CUPS_PRINTER_LARGE;
- else if (ppd->sizes[i].length > 1008)
- p->type |= CUPS_PRINTER_MEDIUM;
- else
- p->type |= CUPS_PRINTER_SMALL;
-
- /*
- * Add a filter from application/vnd.cups-raw to printer/name to
- * handle "raw" printing by users.
- */
-
- add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
-
- /*
- * Add any pre-filters in the PPD file...
- */
-
- if ((ppdattr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL)
- {
- p->prefiltertype = mimeAddType(MimeDatabase, "prefilter", p->name);
-
- for (; ppdattr; ppdattr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
- if (ppdattr->value)
- add_printer_filter(p, p->prefiltertype, ppdattr->value);
- }
-
- /*
- * Add any filters in the PPD file...
- */
-
- DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
- for (i = 0; i < ppd->num_filters; i ++)
- {
- DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
- add_printer_filter(p, p->filetype, ppd->filters[i]);
- }
-
- if (ppd->num_filters == 0)
- {
- /*
- * If there are no filters, add a PostScript printing filter.
- */
-
- add_printer_filter(p, p->filetype,
- "application/vnd.cups-postscript 0 -");
- }
-
- /*
- * Show current and available port monitors for this printer...
- */
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
- NULL, p->port_monitor ? p->port_monitor : "none");
-
- for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
- ppdattr;
- i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
-
- if (ppd->protocols)
- {
- if (strstr(ppd->protocols, "TBCP"))
- i ++;
- else if (strstr(ppd->protocols, "BCP"))
- i ++;
- }
-
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "port-monitor-supported", i, NULL, NULL);
-
- attr->values[0].string.text = _cupsStrAlloc("none");
-
- for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
- ppdattr;
- i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
- attr->values[i].string.text = _cupsStrAlloc(ppdattr->value);
-
- if (ppd->protocols)
- {
- if (strstr(ppd->protocols, "TBCP"))
- attr->values[i].string.text = _cupsStrAlloc("tbcp");
- else if (strstr(ppd->protocols, "BCP"))
- attr->values[i].string.text = _cupsStrAlloc("bcp");
- }
-
-#ifdef HAVE_DNSSD
- cupsdSetString(&p->product, ppd->product);
-#endif /* HAVE_DNSSD */
-
- if (ppdFindAttr(ppd, "APRemoteQueueID", NULL))
- p->type |= CUPS_PRINTER_REMOTE;
-
- /*
- * Close the PPD and set the type...
- */
-
- ppdClose(ppd);
- }
- else if (!access(filename, 0))
- {
- int pline; /* PPD line number */
- ppd_status_t pstatus; /* PPD load status */
-
-
- pstatus = ppdLastError(&pline);
-
- cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
- p->name);
-
- if (pstatus <= PPD_ALLOC_ERROR)
- cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
- else
- cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
- ppdErrorString(pstatus), pline);
-
- cupsdLogMessage(CUPSD_LOG_INFO,
- "Hint: Run \"cupstestppd %s\" and fix any errors.",
- filename);
-
- /*
- * Add a filter from application/vnd.cups-raw to printer/name to
- * handle "raw" printing by users.
- */
-
- add_printer_filter(p, p->filetype, "application/vnd.cups-raw 0 -");
-
- /*
- * Add a PostScript filter, since this is still possibly PS printer.
- */
-
- add_printer_filter(p, p->filetype,
- "application/vnd.cups-postscript 0 -");
- }
- else
- {
- /*
- * If we have an interface script, add a filter entry for it...
- */
-
- snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
- p->name);
- if (!access(filename, X_OK))
- {
- /*
- * Yes, we have a System V style interface script; use it!
- */
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-make-and-model", NULL,
- "Local System V Printer");
-
- snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
- ServerRoot, p->name);
- add_printer_filter(p, p->filetype, filename);
- }
- else if (p->device_uri &&
- !strncmp(p->device_uri, "ipp://", 6) &&
- (strstr(p->device_uri, "/printers/") != NULL ||
- strstr(p->device_uri, "/classes/") != NULL))
- {
- /*
- * Tell the client this is really a hard-wired remote printer.
- */
-
- p->type |= CUPS_PRINTER_REMOTE;
-
- /*
- * Point the printer-uri-supported attribute to the
- * remote printer...
- */
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
- "printer-uri-supported", NULL, p->device_uri);
-
- /*
- * Then set the make-and-model accordingly...
- */
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-make-and-model", NULL, "Remote Printer");
-
- /*
- * Print all files directly...
- */
-
- p->raw = 1;
- p->remote = 1;
- }
- else
- {
- /*
- * Otherwise we have neither - treat this as a "dumb" printer
- * with no PPD file...
- */
-
- ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
- "printer-make-and-model", NULL, "Local Raw Printer");
-
- p->raw = 1;
- }
- }
-
- ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
- "finishings-supported", num_finishings, finishings);
- ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
- "finishings-default", IPP_FINISHINGS_NONE);
- }
- }
-
- /*
- * Force sharing off for remote queues...
- */
-
- if (p->type & (CUPS_PRINTER_REMOTE | CUPS_PRINTER_IMPLICIT))
- p->shared = 0;
- else
- {
- /*
- * Copy the printer options into a browse attributes string we can re-use.
- */
-
- const char *valptr; /* Pointer into value */
- char *attrptr; /* Pointer into attribute string */
+ const char *valptr; /* Pointer into value */
+ char *attrptr; /* Pointer into attribute string */
/*
*rptr; /* Pointer into reason */
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p, p->name, s);
+
if (s[0] == '-' || s[0] == '+')
{
/*
sptr = s;
for (i = 0; i < p->num_reasons; i ++)
- free(p->reasons[i]);
+ _cupsStrFree(p->reasons[i]);
p->num_reasons = 0;
+
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+
+ if (PrintcapFormat == PRINTCAP_PLIST)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
}
if (!strcmp(s, "none"))
*/
for (i = 0; i < p->num_reasons; i ++)
- if (!strcasecmp(reason, p->reasons[i]))
+ if (!strcmp(reason, p->reasons[i]))
{
/*
* Found a match, so remove it...
*/
p->num_reasons --;
- free(p->reasons[i]);
+ _cupsStrFree(p->reasons[i]);
if (i < p->num_reasons)
memmove(p->reasons + i, p->reasons + i + 1,
(p->num_reasons - i) * sizeof(char *));
- i --;
-
if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED)
cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1);
+
+ if (strcmp(reason, "connecting-to-device"))
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+
+ if (PrintcapFormat == PRINTCAP_PLIST)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+
+ break;
}
}
else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
*/
for (i = 0; i < p->num_reasons; i ++)
- if (!strcasecmp(reason, p->reasons[i]))
+ if (!strcmp(reason, p->reasons[i]))
break;
if (i >= p->num_reasons)
{
- p->reasons[i] = strdup(reason);
+ if (i >= (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
+ {
+ cupsdLogMessage(CUPSD_LOG_ALERT,
+ "Too many printer-state-reasons values for %s (%d)",
+ p->name, i + 1);
+ return;
+ }
+
+ p->reasons[i] = _cupsStrAlloc(reason);
p->num_reasons ++;
if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED)
cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1);
+
+ if (strcmp(reason, "connecting-to-device"))
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+
+ if (PrintcapFormat == PRINTCAP_PLIST)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
}
}
}
* Set the new state...
*/
+ if (PrintcapFormat == PRINTCAP_PLIST)
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP);
+
old_state = p->state;
p->state = s;
if (old_state != s)
{
cupsdAddEvent(s == IPP_PRINTER_STOPPED ? CUPSD_EVENT_PRINTER_STOPPED :
- CUPSD_EVENT_PRINTER_STATE_CHANGED, p, NULL,
+ CUPSD_EVENT_PRINTER_STATE, p, NULL,
"%s \"%s\" state changed.",
(p->type & CUPS_PRINTER_CLASS) ? "Class" : "Printer",
p->name);
#endif /* __sgi */
}
+ /*
+ * Set/clear the paused reason as needed...
+ */
+
+ if (s == IPP_PRINTER_STOPPED)
+ cupsdSetPrinterReasons(p, "+paused");
+ else
+ cupsdSetPrinterReasons(p, "-paused");
+
+ /*
+ * Clear the message for the queue when going to processing...
+ */
+
+ if (s == IPP_PRINTER_PROCESSING)
+ p->state_message[0] = '\0';
+
+ /*
+ * Update the printer history...
+ */
+
cupsdAddPrinterHistory(p);
/*
* Let the browse protocols reflect the change...
*/
- cupsdRegisterPrinter(p);
+ if (update)
+ cupsdRegisterPrinter(p);
/*
* Save the printer configuration if a printer goes from idle or processing
* to stopped (or visa-versa)...
*/
- if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&
- update)
+ if (update &&
+ (old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED))
{
if (p->type & CUPS_PRINTER_CLASS)
- cupsdSaveAllClasses();
+ cupsdMarkDirty(CUPSD_DIRTY_CLASSES);
else
- cupsdSaveAllPrinters();
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
}
}
cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */
int update)/* I - Update printers.conf? */
{
- cupsd_job_t *job; /* Active print job */
-
-
/*
* Set the printer state...
*/
*/
if (p->job)
+ cupsdSetJobState(p->job, IPP_JOB_PENDING, CUPSD_JOB_DEFAULT,
+ "Job stopped due to printer being paused.");
+}
+
+
+/*
+ * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
+ */
+
+int /* O - 1 if successful, 0 otherwise */
+cupsdUpdatePrinterPPD(
+ cupsd_printer_t *p, /* I - Printer */
+ int num_keywords, /* I - Number of keywords */
+ cups_option_t *keywords) /* I - Keywords */
+{
+ int i; /* Looping var */
+ cups_file_t *src, /* Original file */
+ *dst; /* New file */
+ char srcfile[1024], /* Original filename */
+ dstfile[1024], /* New filename */
+ line[1024], /* Line from file */
+ keystring[41]; /* Keyword from line */
+ cups_option_t *keyword; /* Current keyword */
+
+
+ cupsdLogMessage(CUPSD_LOG_INFO, "Updating keywords in PPD file for %s...",
+ p->name);
+
+ /*
+ * Get the old and new PPD filenames...
+ */
+
+ snprintf(srcfile, sizeof(srcfile), "%s/ppd/%s.ppd.O", ServerRoot, p->name);
+ snprintf(dstfile, sizeof(srcfile), "%s/ppd/%s.ppd", ServerRoot, p->name);
+
+ /*
+ * Rename the old file and open the old and new...
+ */
+
+ if (rename(dstfile, srcfile))
{
- /*
- * Get pointer to job...
- */
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to backup PPD file for %s: %s",
+ p->name, strerror(errno));
+ return (0);
+ }
+
+ if ((src = cupsFileOpen(srcfile, "r")) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open PPD file \"%s\": %s",
+ srcfile, strerror(errno));
+ rename(srcfile, dstfile);
+ return (0);
+ }
+
+ if ((dst = cupsFileOpen(dstfile, "w")) == NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create PPD file \"%s\": %s",
+ dstfile, strerror(errno));
+ cupsFileClose(src);
+ rename(srcfile, dstfile);
+ return (0);
+ }
+
+ /*
+ * Copy the first line and then write out all of the keywords...
+ */
+
+ if (!cupsFileGets(src, line, sizeof(line)))
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to read PPD file \"%s\": %s",
+ srcfile, strerror(errno));
+ cupsFileClose(src);
+ cupsFileClose(dst);
+ rename(srcfile, dstfile);
+ return (0);
+ }
+
+ cupsFilePrintf(dst, "%s\n", line);
+
+ for (i = num_keywords, keyword = keywords; i > 0; i --, keyword ++)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "*%s: %s", keyword->name, keyword->value);
+ cupsFilePrintf(dst, "*%s: %s\n", keyword->name, keyword->value);
+ }
- job = (cupsd_job_t *)p->job;
+ /*
+ * Then copy the rest of the PPD file, dropping any keywords we changed.
+ */
+ while (cupsFileGets(src, line, sizeof(line)))
+ {
/*
- * Stop it...
+ * Skip keywords we've already set...
*/
- cupsdStopJob(job, 0);
+ if (sscanf(line, "*%40[^:]:", keystring) == 1 &&
+ cupsGetOption(keystring, num_keywords, keywords))
+ continue;
/*
- * Reset the state to pending...
+ * Otherwise write the line...
*/
- job->state->values[0].integer = IPP_JOB_PENDING;
- job->state_value = IPP_JOB_PENDING;
+ cupsFilePrintf(dst, "%s\n", line);
+ }
+
+ /*
+ * Close files and return...
+ */
- cupsdSaveJob(job);
+ cupsFileClose(src);
+ cupsFileClose(dst);
- cupsdAddEvent(CUPSD_EVENT_JOB_STOPPED, p, job,
- "Job stopped due to printer being paused");
- }
+ return (1);
}
void
cupsdWritePrintcap(void)
{
- cups_file_t *fp; /* printcap file */
+ int i; /* Looping var */
+ cups_file_t *fp; /* Printcap file */
cupsd_printer_t *p; /* Current printer */
* data has come from...
*/
- cupsFilePuts(fp,
- "# This file was automatically generated by cupsd(8) from the\n");
- cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
- ServerRoot);
- cupsFilePuts(fp, "# will be lost.\n");
+ if (PrintcapFormat != PRINTCAP_PLIST)
+ cupsFilePrintf(fp, "# This file was automatically generated by cupsd(8) "
+ "from the\n"
+ "# %s/printers.conf file. All changes to this file\n"
+ "# will be lost.\n", ServerRoot);
- if (Printers)
- {
- /*
- * Write a new printcap with the current list of printers.
- */
+ /*
+ * Write a new printcap with the current list of printers.
+ */
- switch (PrintcapFormat)
- {
- case PRINTCAP_BSD:
- /*
- * Each printer is put in the file as:
- *
- * Printer1:
- * Printer2:
- * Printer3:
- * ...
- * PrinterN:
- */
+ switch (PrintcapFormat)
+ {
+ case PRINTCAP_BSD :
+ /*
+ * Each printer is put in the file as:
+ *
+ * Printer1:
+ * Printer2:
+ * Printer3:
+ * ...
+ * PrinterN:
+ */
- if (DefaultPrinter)
- cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
- DefaultPrinter->info, ServerName,
- DefaultPrinter->name);
+ if (DefaultPrinter)
+ cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
+ DefaultPrinter->info, ServerName,
+ DefaultPrinter->name);
+
+ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+ p;
+ p = (cupsd_printer_t *)cupsArrayNext(Printers))
+ if (p != DefaultPrinter)
+ cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
+ ServerName, p->name);
+ break;
- for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
- p;
- p = (cupsd_printer_t *)cupsArrayNext(Printers))
- if (p != DefaultPrinter)
- cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
- ServerName, p->name);
- break;
+ case PRINTCAP_PLIST :
+ /*
+ * Each printer is written as a dictionary in a plist file.
+ * Currently the printer-name, printer-info, printer-is-accepting-jobs,
+ * printer-location, printer-make-and-model, printer-state,
+ * printer-state-reasons, printer-type, and (sanitized) device-uri.
+ */
- case PRINTCAP_SOLARIS:
- /*
- * Each printer is put in the file as:
- *
- * _all:all=Printer1,Printer2,Printer3,...,PrinterN
- * _default:use=DefaultPrinter
- * Printer1:\
- * :bsdaddr=ServerName,Printer1:\
- * :description=Description:
- * Printer2:
- * :bsdaddr=ServerName,Printer2:\
- * :description=Description:
- * Printer3:
- * :bsdaddr=ServerName,Printer3:\
- * :description=Description:
- * ...
- * PrinterN:
- * :bsdaddr=ServerName,PrinterN:\
- * :description=Description:
- */
+ cupsFilePuts(fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
+ "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
+ "PropertyList-1.0.dtd\">\n"
+ "<plist version=\"1.0\">\n"
+ "<array>\n");
- cupsFilePuts(fp, "_all:all=");
- for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
- p;
- p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
- cupsFilePrintf(fp, "%s%c", p->name,
- cupsArrayNext(Printers) ? ',' : '\n');
+ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+ p;
+ p = (cupsd_printer_t *)cupsArrayNext(Printers))
+ {
+ cupsFilePuts(fp, "\t<dict>\n"
+ "\t\t<key>printer-name</key>\n"
+ "\t\t<string>");
+ write_xml_string(fp, p->name);
+ cupsFilePuts(fp, "</string>\n"
+ "\t\t<key>printer-info</key>\n"
+ "\t\t<string>");
+ write_xml_string(fp, p->info);
+ cupsFilePrintf(fp, "</string>\n"
+ "\t\t<key>printer-is-accepting-jobs</key>\n"
+ "\t\t<%s/>\n"
+ "\t\t<key>printer-location</key>\n"
+ "\t\t<string>", p->accepting ? "true" : "false");
+ write_xml_string(fp, p->location);
+ cupsFilePuts(fp, "</string>\n"
+ "\t\t<key>printer-make-and-model</key>\n"
+ "\t\t<string>");
+ write_xml_string(fp, p->make_model);
+ cupsFilePrintf(fp, "</string>\n"
+ "\t\t<key>printer-state</key>\n"
+ "\t\t<integer>%d</integer>\n"
+ "\t\t<key>printer-state-reasons</key>\n"
+ "\t\t<array>\n", p->state);
+ for (i = 0; i < p->num_reasons; i ++)
+ {
+ cupsFilePuts(fp, "\t\t\t<string>");
+ write_xml_string(fp, p->reasons[i]);
+ cupsFilePuts(fp, "</string>\n");
+ }
+ cupsFilePrintf(fp, "\t\t</array>\n"
+ "\t\t<key>printer-type</key>\n"
+ "\t\t<integer>%d</integer>\n"
+ "\t\t<key>device-uri</key>\n"
+ "\t\t<string>", p->type);
+ write_xml_string(fp, p->sanitized_device_uri);
+ cupsFilePuts(fp, "</string>\n"
+ "\t</dict>\n");
+ }
+ cupsFilePuts(fp, "</array>\n"
+ "</plist>\n");
+ break;
- if (DefaultPrinter)
- cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
+ case PRINTCAP_SOLARIS :
+ /*
+ * Each printer is put in the file as:
+ *
+ * _all:all=Printer1,Printer2,Printer3,...,PrinterN
+ * _default:use=DefaultPrinter
+ * Printer1:\
+ * :bsdaddr=ServerName,Printer1:\
+ * :description=Description:
+ * Printer2:
+ * :bsdaddr=ServerName,Printer2:\
+ * :description=Description:
+ * Printer3:
+ * :bsdaddr=ServerName,Printer3:\
+ * :description=Description:
+ * ...
+ * PrinterN:
+ * :bsdaddr=ServerName,PrinterN:\
+ * :description=Description:
+ */
- for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
- p;
- p = (cupsd_printer_t *)cupsArrayNext(Printers))
- cupsFilePrintf(fp, "%s:\\\n"
- "\t:bsdaddr=%s,%s:\\\n"
- "\t:description=%s:\n",
- p->name, ServerName, p->name,
- p->info ? p->info : "");
- break;
- }
+ cupsFilePuts(fp, "_all:all=");
+ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+ p;
+ p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
+ cupsFilePrintf(fp, "%s%c", p->name,
+ cupsArrayNext(Printers) ? ',' : '\n');
+
+ if (DefaultPrinter)
+ cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
+
+ for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
+ p;
+ p = (cupsd_printer_t *)cupsArrayNext(Printers))
+ cupsFilePrintf(fp, "%s:\\\n"
+ "\t:bsdaddr=%s,%s:\\\n"
+ "\t:description=%s:\n",
+ p->name, ServerName, p->name,
+ p->info ? p->info : "");
+ break;
}
/*
/*
- * 'cupsdSanitizeURI()' - Sanitize a device URI...
+ * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
*/
-char * /* O - New device URI */
-cupsdSanitizeURI(const char *uri, /* I - Original device URI */
- char *buffer, /* O - New device URI */
- int buflen) /* I - Size of new device URI buffer */
+static void
+add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
{
- char *start, /* Start of data after scheme */
- *slash, /* First slash after scheme:// */
- *ptr; /* Pointer into user@host:port part */
+ int i; /* Looping var */
+ int num_options; /* Number of default options */
+ cups_option_t *options, /* Default options */
+ *option; /* Current option */
+ char name[256]; /* name-default */
/*
- * Range check input...
+ * Maintain a common array of default attribute names...
*/
- if (!uri || !buffer || buflen < 2)
- return (NULL);
-
- /*
- * Copy the device URI to the new buffer...
- */
-
- strlcpy(buffer, uri, buflen);
-
- /*
- * Find the end of the scheme:// part...
- */
-
- if ((ptr = strchr(buffer, ':')) == NULL)
- return (buffer); /* No scheme: part... */
-
- for (start = ptr + 1; *start; start ++)
- if (*start != '/')
- break;
-
- /*
- * Find the next slash (/) in the URI...
- */
-
- if ((slash = strchr(start, '/')) == NULL)
- slash = start + strlen(start); /* No slash, point to the end */
-
- /*
- * Check for an @ sign before the slash...
- */
-
- if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
- {
- /*
- * Found an @ sign and it is before the resource part, so we have
- * an authentication string. Copy the remaining URI over the
- * authentication string...
- */
-
- _cups_strcpy(start, ptr + 1);
- }
-
- /*
- * Return the new device URI...
- */
-
- return (buffer);
-}
-
-
-/*
- * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
- */
-
-static void
-add_printer_defaults(cupsd_printer_t *p)/* I - Printer */
-{
- int i; /* Looping var */
- int num_options; /* Number of default options */
- cups_option_t *options, /* Default options */
- *option; /* Current option */
- char name[256]; /* name-default */
-
-
- /*
- * Maintain a common array of default attribute names...
- */
-
- if (!CommonDefaults)
- {
- CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+ if (!CommonDefaults)
+ {
+ CommonDefaults = cupsArrayNew((cups_array_func_t)strcmp, NULL);
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("copies-default"));
cupsArrayAdd(CommonDefaults, _cupsStrAlloc("document-format-default"));
* Add all of the default options from the .conf files...
*/
- for (num_options = 0, i = p->num_options, option = p->options;
+ for (num_options = 0, options = NULL, i = p->num_options, option = p->options;
i > 0;
i --, option ++)
{
1);
if (!cupsGetOption("document-format", p->num_options, p->options))
- ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
"document-format-default", NULL, "application/octet-stream");
if (!cupsGetOption("job-hold-until", p->num_options, p->options))
program[1024]; /* Program/filter name */
int cost; /* Cost of filter */
mime_type_t *temptype; /* MIME type looping var */
- char filename[1024]; /* Full filter filename */
+ char filename[1024], /* Full filter filename */
+ *dirsep; /* Pointer to directory separator */
+ struct stat fileinfo; /* File information */
/*
* super/type cost program
*/
- if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
+ if (sscanf(filter, "%15[^/]/%31s%d%*[ \t]%1023[^\n]", super, type, &cost,
+ program) != 4)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
p->name, filter);
else
snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
- if (access(filename, X_OK))
+ if (stat(filename, &fileinfo))
{
snprintf(p->state_message, sizeof(p->state_message),
"Filter \"%s\" for printer \"%s\" not available: %s",
- program, p->name, strerror(errno));
+ filename, p->name, strerror(errno));
cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
- cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0);
cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
+ return;
+ }
+
+ /*
+ * When running as root, do additional security checks...
+ */
+
+ if (!RunUser)
+ {
+ /*
+ * Only use filters that are owned by root and do not have world write
+ * permissions.
+ */
+
+ if (fileinfo.st_uid || (fileinfo.st_mode & S_IWOTH) != 0)
+ {
+ if (fileinfo.st_uid)
+ snprintf(p->state_message, sizeof(p->state_message),
+ "Filter \"%s\" for printer \"%s\" not owned by root",
+ filename, p->name);
+ else
+ snprintf(p->state_message, sizeof(p->state_message),
+ "Filter \"%s\" for printer \"%s\" has insecure permissions "
+ "(0%o)", filename, p->name, fileinfo.st_mode);
+
+ cupsdSetPrinterReasons(p, "+cups-insecure-filter-error");
+
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
+ return;
+ }
+
+ /*
+ * Similarly, check that the parent directory is also owned by root and
+ * does not have world write permissions.
+ */
+
+ if ((dirsep = strrchr(filename, '/')) != NULL)
+ *dirsep = '\0';
+
+ if (stat(filename, &fileinfo))
+ {
+ snprintf(p->state_message, sizeof(p->state_message),
+ "Filter directory \"%s\" for printer \"%s\" not accessible: %s",
+ filename, p->name, strerror(errno));
+ cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
+
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
+ return;
+ }
+ else if (fileinfo.st_uid || (fileinfo.st_mode & S_IWOTH) != 0)
+ {
+ if (fileinfo.st_uid)
+ snprintf(p->state_message, sizeof(p->state_message),
+ "Filter directory \"%s\" for printer \"%s\" not owned by "
+ "root", filename, p->name);
+ else
+ snprintf(p->state_message, sizeof(p->state_message),
+ "Filter directory \"%s\" for printer \"%s\" has insecure "
+ "permissions (0%o)", filename, p->name, fileinfo.st_mode);
+
+ cupsdSetPrinterReasons(p, "+cups-insecure-filter-error");
+
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
+ return;
+ }
+ }
+ }
+
+ /*
+ * Add the filter to the MIME database, supporting wildcards as needed...
+ */
+
+ for (temptype = mimeFirstType(MimeDatabase);
+ temptype;
+ temptype = mimeNextType(MimeDatabase))
+ if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
+ !strcasecmp(temptype->super, super)) &&
+ (type[0] == '*' || !strcasecmp(temptype->type, type)))
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
+ p->name, temptype->super, temptype->type,
+ filtertype->super, filtertype->type,
+ cost, program);
+ mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program);
+ }
+}
+
+
+/*
+ * 'add_printer_formats()' - Add document-format-supported values for a printer.
+ */
+
+static void
+add_printer_formats(cupsd_printer_t *p) /* I - Printer */
+{
+ int i; /* Looping var */
+ mime_type_t *type; /* Current MIME type */
+ cups_array_t *filters; /* Filters */
+ ipp_attribute_t *attr; /* document-format-supported attribute */
+ char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
+ /* MIME type name */
+
+
+ /*
+ * Raw (and remote) queues advertise all of the supported MIME
+ * types...
+ */
+
+ cupsArrayDelete(p->filetypes);
+ p->filetypes = NULL;
+
+ if (p->raw)
+ {
+ ippAddStrings(p->attrs, IPP_TAG_PRINTER,
+ (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
+ "document-format-supported", NumMimeTypes, NULL, MimeTypes);
+ return;
+ }
+
+ /*
+ * Otherwise, loop through the supported MIME types and see if there
+ * are filters for them...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
+ mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
+
+ p->filetypes = cupsArrayNew(NULL, NULL);
+
+ for (type = mimeFirstType(MimeDatabase);
+ type;
+ type = mimeNextType(MimeDatabase))
+ {
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+
+ if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
+ {
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "add_printer_formats: %s: %s needs %d filters",
+ p->name, mimetype, cupsArrayCount(filters));
+
+ cupsArrayDelete(filters);
+ cupsArrayAdd(p->filetypes, type);
}
+ else
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "add_printer_formats: %s: %s not supported",
+ p->name, mimetype);
+ }
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG2,
+ "add_printer_formats: %s: %d supported types",
+ p->name, cupsArrayCount(p->filetypes) + 1);
+
+ /*
+ * Add the file formats that can be filtered...
+ */
+
+ if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
+ !cupsArrayFind(p->filetypes, type))
+ i = 1;
+ else
+ i = 0;
+
+ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
+ "document-format-supported",
+ cupsArrayCount(p->filetypes) + 1, NULL, NULL);
+
+ if (i)
+ attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
+
+ for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
+ type;
+ i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
+ {
+ snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+
+ attr->values[i].string.text = _cupsStrAlloc(mimetype);
}
- /*
- * Mark the CUPS_PRINTER_COMMANDS bit if we have a filter for
- * application/vnd.cups-command...
- */
+#ifdef HAVE_DNSSD
+ {
+ char pdl[1024]; /* Buffer to build pdl list */
+ mime_filter_t *filter; /* MIME filter looping var */
+
+
+ pdl[0] = '\0';
+
+ if (mimeType(MimeDatabase, "application", "pdf"))
+ strlcat(pdl, "application/pdf,", sizeof(pdl));
+
+ if (mimeType(MimeDatabase, "application", "postscript"))
+ strlcat(pdl, "application/postscript,", sizeof(pdl));
+
+ if (mimeType(MimeDatabase, "application", "vnd.cups-raster"))
+ strlcat(pdl, "application/vnd.cups-raster,", sizeof(pdl));
+
+ /*
+ * Determine if this is a Tioga PrintJobMgr based queue...
+ */
+
+ for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters);
+ filter;
+ filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters))
+ {
+ if (filter->dst == p->filetype && filter->filter &&
+ strstr(filter->filter, "PrintJobMgr"))
+ break;
+ }
+
+ /*
+ * We only support raw printing if this is not a Tioga PrintJobMgr based
+ * queue and if application/octet-stream is a known conversion...
+ */
+
+ if (!filter && mimeType(MimeDatabase, "application", "octet-stream"))
+ strlcat(pdl, "application/octet-stream,", sizeof(pdl));
+
+ if (mimeType(MimeDatabase, "image", "png"))
+ strlcat(pdl, "image/png,", sizeof(pdl));
+
+ if (pdl[0])
+ pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */
+
+ cupsdSetString(&p->pdl, pdl);
+ }
+#endif /* HAVE_DNSSD */
+}
+
+
+/*
+ * 'add_string_array()' - Add a string to an array of CUPS strings.
+ */
+
+static void
+add_string_array(cups_array_t **a, /* I - Array */
+ const char *s) /* I - String */
+{
+ if (!*a)
+ *a = cupsArrayNew(NULL, NULL);
+
+ cupsArrayAdd(*a, _cupsStrAlloc(s));
+}
+
+
+/*
+ * 'compare_printers()' - Compare two printers.
+ */
+
+static int /* O - Result of comparison */
+compare_printers(void *first, /* I - First printer */
+ void *second, /* I - Second printer */
+ void *data) /* I - App data (not used) */
+{
+ return (strcasecmp(((cupsd_printer_t *)first)->name,
+ ((cupsd_printer_t *)second)->name));
+}
+
+
+/*
+ * 'delete_printer_filters()' - Delete all MIME filters for a printer.
+ */
+
+static void
+delete_printer_filters(
+ cupsd_printer_t *p) /* I - Printer to remove from */
+{
+ mime_filter_t *filter; /* MIME filter looping var */
+
+
+ /*
+ * Range check input...
+ */
+
+ if (p == NULL)
+ return;
+
+ /*
+ * Remove all filters from the MIME database that have a destination
+ * type == printer...
+ */
+
+ for (filter = mimeFirstFilter(MimeDatabase);
+ filter;
+ filter = mimeNextFilter(MimeDatabase))
+ if (filter->dst == p->filetype)
+ {
+ /*
+ * Delete the current filter...
+ */
+
+ mimeDeleteFilter(MimeDatabase, filter);
+ }
+
+ cupsdSetPrinterReasons(p, "-cups-insecure-filter-error"
+ ",cups-missing-filter-error");
+}
+
+
+/*
+ * 'delete_string_array()' - Delete an array of CUPS strings.
+ */
+
+static void
+delete_string_array(cups_array_t **a) /* I - Array */
+{
+ char *ptr; /* Current string */
+
+
+ for (ptr = (char *)cupsArrayFirst(*a);
+ ptr;
+ ptr = (char *)cupsArrayNext(*a))
+ _cupsStrFree(ptr);
+
+ cupsArrayDelete(*a);
+ *a = NULL;
+}
+
+
+/*
+ * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
+ */
+
+static void
+load_ppd(cupsd_printer_t *p) /* I - Printer */
+{
+ int i; /* Looping var */
+ cups_file_t *cache; /* Cache file */
+ char cache_name[1024]; /* Cache filename */
+ struct stat cache_info; /* Cache file info */
+ ppd_file_t *ppd; /* PPD file */
+ char ppd_name[1024]; /* PPD filename */
+ struct stat ppd_info; /* PPD file info */
+ int num_media; /* Number of media options */
+ char custom_in[256], /* Custom size name in inches */
+ custom_mm[256]; /* Custom size name in millimeters */
+ ppd_size_t *size; /* Current size */
+ ppd_option_t *output_bin, /* OutputBin options */
+ *duplex; /* Duplex options */
+ ppd_attr_t *ppd_attr; /* PPD attribute */
+ _cups_pwg_media_t *pwgmedia; /* Matching PWG size name */
+ ipp_attribute_t *attr; /* Attribute data */
+ ipp_t *media_col_default, /* media-col-default collection value */
+ *media_size; /* media-size collection value */
+ ipp_value_t *val; /* Attribute value */
+ int num_finishings; /* Number of finishings */
+ int finishings[5]; /* finishings-supported values */
+ static const char * const sides[3] = /* sides-supported values */
+ {
+ "one-sided",
+ "two-sided-long-edge",
+ "two-sided-short-edge"
+ };
+ static const char * const standard_commands[] =
+ { /* Standard CUPS commands */
+ "AutoConfigure",
+ "Clean",
+ "PrintSelfTestPage"
+ };
+
+
+ /*
+ * Check to see if the cache is up-to-date...
+ */
+
+ snprintf(cache_name, sizeof(cache_name), "%s/%s.ipp", CacheDir, p->name);
+ if (stat(cache_name, &cache_info))
+ cache_info.st_mtime = 0;
+
+ snprintf(ppd_name, sizeof(ppd_name), "%s/ppd/%s.ppd", ServerRoot, p->name);
+ if (stat(ppd_name, &ppd_info))
+ ppd_info.st_mtime = 1;
+
+ ippDelete(p->ppd_attrs);
+ p->ppd_attrs = ippNew();
+
+ if (cache_info.st_mtime >= ppd_info.st_mtime &&
+ (cache = cupsFileOpen(cache_name, "r")) != NULL)
+ {
+ /*
+ * Load cached information and return...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", cache_name);
+
+ if (ippReadIO(cache, (ipp_iocb_t)cupsFileRead, 1, NULL,
+ p->ppd_attrs) == IPP_DATA)
+ {
+ cupsFileClose(cache);
+ return;
+ }
+
+ cupsFileClose(cache);
+ }
+
+ /*
+ * Reload PPD attributes from disk...
+ */
+
+ cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Loading %s...", ppd_name);
+
+ delete_string_array(&(p->filters));
+ delete_string_array(&(p->pre_filters));
+
+ p->type &= ~CUPS_PRINTER_OPTIONS;
+ p->type |= CUPS_PRINTER_BW;
+
+ finishings[0] = IPP_FINISHINGS_NONE;
+ num_finishings = 1;
+
+ if ((ppd = ppdOpenFile(ppd_name)) != NULL)
+ {
+ /*
+ * Add make/model and other various attributes...
+ */
+
+ ppdMarkDefaults(ppd);
+
+ if (ppd->color_device)
+ p->type |= CUPS_PRINTER_COLOR;
+ if (ppd->variable_sizes)
+ p->type |= CUPS_PRINTER_VARIABLE;
+ if (!ppd->manual_copies)
+ p->type |= CUPS_PRINTER_COPIES;
+ if ((ppd_attr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
+ if (ppd_attr->value && !strcasecmp(ppd_attr->value, "true"))
+ p->type |= CUPS_PRINTER_FAX;
+
+ ippAddBoolean(p->ppd_attrs, IPP_TAG_PRINTER, "color-supported",
+ ppd->color_device);
+ if (ppd->throughput)
+ ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "pages-per-minute", ppd->throughput);
+
+ if (ppd->nickname)
+ {
+ /*
+ * The NickName can be localized in the character set specified
+ * by the LanugageEncoding attribute. However, ppdOpen2() has
+ * already converted the ppd->nickname member to UTF-8 for us
+ * (the original attribute value is available separately)
+ */
+
+ cupsdSetString(&p->make_model, ppd->nickname);
+ }
+ else if (ppd->modelname)
+ {
+ /*
+ * Model name can only contain specific characters...
+ */
+
+ cupsdSetString(&p->make_model, ppd->modelname);
+ }
+ else
+ cupsdSetString(&p->make_model, "Bad PPD File");
+
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "printer-make-and-model", NULL, p->make_model);
+
+ /*
+ * Add media options from the PPD file...
+ */
+
+ if (ppd->num_sizes == 0)
+ {
+ if (!ppdFindAttr(ppd, "APScannerOnly", NULL))
+ cupsdLogMessage(CUPSD_LOG_CRIT,
+ "The PPD file for printer %s contains no media "
+ "options and is therefore invalid!", p->name);
+
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "media-supported", NULL, "unknown");
+ }
+ else
+ {
+ num_media = ppd->num_sizes;
+ if (ppd->variable_sizes)
+ num_media ++;
+
+ attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "media-supported", num_media, NULL, NULL);
+ if (attr != NULL)
+ {
+ val = attr->values;
+
+ for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
+ {
+ if (strcasecmp(size->name, "Custom"))
+ {
+ if ((pwgmedia = _cupsPWGMediaBySize(size->width,
+ size->length)) != NULL)
+ {
+ val->string.text = _cupsStrAlloc(pwgmedia->pwg);
+ }
+ else
+ {
+ snprintf(custom_in, sizeof(custom_in), "adobe_%s_%gx%gin",
+ size->name, size->width / 72.0, size->length / 72.0);
+ snprintf(custom_mm, sizeof(custom_mm), "adobe_%s_%gx%gmm",
+ size->name, size->width * 25.4 / 72.0,
+ size->length * 25.4 / 72.0);
+ if (strlen(custom_in) < strlen(custom_mm))
+ val->string.text = _cupsStrAlloc(custom_in);
+ else
+ val->string.text = _cupsStrAlloc(custom_mm);
+ }
+
+ if (size->marked)
+ {
+ /*
+ * Add media-default...
+ */
+
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "media-default", NULL, val->string.text);
+
+ /*
+ * Add media-col-default...
+ */
+
+ media_size = ippNew();
+ ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "x-dimension", (int)(size->width * 2540.0 / 72.0));
+ ippAddInteger(media_size, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
+ "y-dimension", (int)(size->length * 2540.0 / 72.0));
+
+ media_col_default = ippNew();
+ ippAddString(media_col_default, IPP_TAG_PRINTER,
+ IPP_TAG_KEYWORD | IPP_TAG_COPY, "media-color", NULL,
+ "white");
+ ippAddString(media_col_default, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "media-key", NULL,val->string.text);
+ ippAddCollection(media_col_default, IPP_TAG_PRINTER, "media-size",
+ media_size);
+ ippAddString(media_col_default, IPP_TAG_PRINTER,
+ IPP_TAG_KEYWORD | IPP_TAG_COPY, "media-type", NULL,
+ "stationary");
+
+ ippAddCollection(p->ppd_attrs, IPP_TAG_PRINTER,
+ "media-col-default", media_col_default);
+ }
+
+ val ++;
+ }
+ }
+
+ if (ppd->variable_sizes)
+ {
+ snprintf(custom_in, sizeof(custom_in), "custom_min_%gx%gin",
+ ppd->custom_min[0] / 72.0, ppd->custom_min[1] / 72.0);
+ snprintf(custom_mm, sizeof(custom_mm), "custom_min_%gx%gmm",
+ ppd->custom_min[0] * 25.4 / 72.0,
+ ppd->custom_min[1] * 25.4 / 72.0);
+ if (strlen(custom_in) < strlen(custom_mm))
+ val->string.text = _cupsStrAlloc(custom_in);
+ else
+ val->string.text = _cupsStrAlloc(custom_mm);
+ val ++;
+
+ snprintf(custom_in, sizeof(custom_in), "custom_max_%gx%gin",
+ ppd->custom_max[0] / 72.0, ppd->custom_max[1] / 72.0);
+ snprintf(custom_mm, sizeof(custom_mm), "custom_max_%gx%gmm",
+ ppd->custom_max[0] * 25.4 / 72.0,
+ ppd->custom_max[1] * 25.4 / 72.0);
+ if (strlen(custom_in) < strlen(custom_mm))
+ val->string.text = _cupsStrAlloc(custom_in);
+ else
+ val->string.text = _cupsStrAlloc(custom_mm);
+ }
+ }
+ }
+
+ /*
+ * Output bin...
+ */
+
+ if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
+ {
+ attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "output-bin-supported", output_bin->num_choices,
+ NULL, NULL);
+
+ if (attr != NULL)
+ {
+ for (i = 0, val = attr->values;
+ i < output_bin->num_choices;
+ i ++, val ++)
+ val->string.text = _cupsStrAlloc(output_bin->choices[i].choice);
+ }
+
+ attr = ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "output-bin-default", NULL, output_bin->defchoice);
+ }
+
+ /*
+ * Duplexing, etc...
+ */
+
+ if ((duplex = ppdFindOption(ppd, "Duplex")) == NULL)
+ if ((duplex = ppdFindOption(ppd, "EFDuplex")) == NULL)
+ if ((duplex = ppdFindOption(ppd, "EFDuplexing")) == NULL)
+ if ((duplex = ppdFindOption(ppd, "KD03Duplex")) == NULL)
+ duplex = ppdFindOption(ppd, "JCLDuplex");
+
+ if (duplex && duplex->num_choices > 1 &&
+ !ppdInstallableConflict(ppd, duplex->keyword, "DuplexTumble"))
+ {
+ p->type |= CUPS_PRINTER_DUPLEX;
+
+ ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "sides-supported", 3, NULL, sides);
+
+ if (!strcasecmp(duplex->defchoice, "DuplexTumble"))
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "sides-default", NULL, "two-sided-short-edge");
+ else if (!strcasecmp(duplex->defchoice, "DuplexNoTumble"))
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "sides-default", NULL, "two-sided-long-edge");
+ else
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "sides-default", NULL, "one-sided");
+ }
+
+ if (ppdFindOption(ppd, "Collate") != NULL)
+ p->type |= CUPS_PRINTER_COLLATE;
+
+ if (ppdFindOption(ppd, "StapleLocation") != NULL)
+ {
+ p->type |= CUPS_PRINTER_STAPLE;
+ finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
+ }
+
+ if (ppdFindOption(ppd, "BindEdge") != NULL)
+ {
+ p->type |= CUPS_PRINTER_BIND;
+ finishings[num_finishings++] = IPP_FINISHINGS_BIND;
+ }
+
+ for (i = 0; i < ppd->num_sizes; i ++)
+ if (ppd->sizes[i].length > 1728)
+ p->type |= CUPS_PRINTER_LARGE;
+ else if (ppd->sizes[i].length > 1008)
+ p->type |= CUPS_PRINTER_MEDIUM;
+ else
+ p->type |= CUPS_PRINTER_SMALL;
+
+ if ((ppd_attr = ppdFindAttr(ppd, "APICADriver", NULL)) != NULL &&
+ ppd_attr->value && !strcasecmp(ppd_attr->value, "true"))
+ {
+ if ((ppd_attr = ppdFindAttr(ppd, "APScannerOnly", NULL)) != NULL &&
+ ppd_attr->value && !strcasecmp(ppd_attr->value, "true"))
+ p->type |= CUPS_PRINTER_SCANNER;
+ else
+ p->type |= CUPS_PRINTER_MFP;
+ }
+
+ /*
+ * Add a filter from application/vnd.cups-raw to printer/name to
+ * handle "raw" printing by users.
+ */
+
+ add_string_array(&(p->filters), "application/vnd.cups-raw 0 -");
+
+ /*
+ * Add any pre-filters in the PPD file...
+ */
+
+ if ((ppd_attr = ppdFindAttr(ppd, "cupsPreFilter", NULL)) != NULL)
+ {
+ for (; ppd_attr; ppd_attr = ppdFindNextAttr(ppd, "cupsPreFilter", NULL))
+ if (ppd_attr->value)
+ add_string_array(&(p->pre_filters), ppd_attr->value);
+ }
+
+ /*
+ * Add any filters in the PPD file...
+ */
+
+ DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
+ for (i = 0; i < ppd->num_filters; i ++)
+ {
+ DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
+ add_string_array(&(p->filters), ppd->filters[i]);
+
+ if (!strncasecmp(ppd->filters[i], "application/vnd.cups-command", 28) &&
+ isspace(ppd->filters[i][28] & 255))
+ p->type |= CUPS_PRINTER_COMMANDS;
+ }
+
+ if (ppd->num_filters == 0)
+ {
+ /*
+ * If there are no filters, add PostScript printing filters.
+ */
+
+ add_string_array(&(p->filters),
+ "application/vnd.cups-command 0 commandtops");
+ add_string_array(&(p->filters),
+ "application/vnd.cups-postscript 0 -");
+
+ p->type |= CUPS_PRINTER_COMMANDS;
+ }
+ else if (!(p->type & CUPS_PRINTER_COMMANDS))
+ {
+ /*
+ * See if this is a PostScript device without a command filter...
+ */
+
+ for (i = 0; i < ppd->num_filters; i ++)
+ if (!strncasecmp(ppd->filters[i],
+ "application/vnd.cups-postscript", 31) &&
+ isspace(ppd->filters[i][31] & 255))
+ break;
+
+ if (i < ppd->num_filters)
+ {
+ /*
+ * Add the generic PostScript command filter...
+ */
+
+ add_string_array(&(p->filters),
+ "application/vnd.cups-command 0 commandtops");
+ p->type |= CUPS_PRINTER_COMMANDS;
+ }
+ }
+
+ if (p->type & CUPS_PRINTER_COMMANDS)
+ {
+ char *commands, /* Copy of commands */
+ *start, /* Start of name */
+ *end; /* End of name */
+ int count; /* Number of commands */
- if (!strcasecmp(super, "application") &&
- !strcasecmp(type, "vnd.cups-command"))
- p->type |= CUPS_PRINTER_COMMANDS;
- /*
- * Add the filter to the MIME database, supporting wildcards as needed...
- */
+ if ((ppd_attr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL &&
+ ppd_attr->value && ppd_attr->value[0])
+ {
+ for (count = 0, start = ppd_attr->value; *start; count ++)
+ {
+ while (isspace(*start & 255))
+ start ++;
- for (temptype = mimeFirstType(MimeDatabase);
- temptype;
- temptype = mimeNextType(MimeDatabase))
- if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
- !strcasecmp(temptype->super, super)) &&
- (type[0] == '*' || !strcasecmp(temptype->type, type)))
- {
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
- p->name, temptype->super, temptype->type,
- filtertype->super, filtertype->type,
- cost, program);
- mimeAddFilter(MimeDatabase, temptype, filtertype, cost, program);
- }
-}
+ if (!*start)
+ break;
+ while (*start && !isspace(*start & 255))
+ start ++;
+ }
+ }
+ else
+ count = 0;
-/*
- * 'add_printer_formats()' - Add document-format-supported values for a printer.
- */
+ if (count > 0)
+ {
+ /*
+ * Make a copy of the commands string and count how many ...
+ */
-static void
-add_printer_formats(cupsd_printer_t *p) /* I - Printer */
-{
- int i; /* Looping var */
- mime_type_t *type; /* Current MIME type */
- cups_array_t *filters; /* Filters */
- ipp_attribute_t *attr; /* document-format-supported attribute */
- char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
- /* MIME type name */
+ attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "printer-commands", count, NULL, NULL);
+ commands = strdup(ppd_attr->value);
- /*
- * Raw (and remote) queues advertise all of the supported MIME
- * types...
- */
+ for (count = 0, start = commands; *start; count ++)
+ {
+ while (isspace(*start & 255))
+ start ++;
- cupsArrayDelete(p->filetypes);
- p->filetypes = NULL;
+ if (!*start)
+ break;
- if (p->raw)
- {
- ippAddStrings(p->attrs, IPP_TAG_PRINTER,
- (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
- "document-format-supported", NumMimeTypes, NULL, MimeTypes);
- return;
- }
+ end = start;
+ while (*end && !isspace(*end & 255))
+ end ++;
- /*
- * Otherwise, loop through the supported MIME types and see if there
- * are filters for them...
- */
+ if (*end)
+ *end++ = '\0';
- cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
- mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
+ attr->values[count].string.text = _cupsStrAlloc(start);
- p->filetypes = cupsArrayNew(NULL, NULL);
+ start = end;
+ }
- for (type = mimeFirstType(MimeDatabase);
- type;
- type = mimeNextType(MimeDatabase))
- {
- snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+ free(commands);
+ }
+ else
+ {
+ /*
+ * Add the standard list of commands...
+ */
- if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
+ ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "printer-commands",
+ (int)(sizeof(standard_commands) /
+ sizeof(standard_commands[0])), NULL,
+ standard_commands);
+ }
+ }
+ else
{
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "add_printer_formats: %s: %s needs %d filters",
- p->name, mimetype, cupsArrayCount(filters));
+ /*
+ * No commands supported...
+ */
- cupsArrayDelete(filters);
- cupsArrayAdd(p->filetypes, type);
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
+ "printer-commands", NULL, "none");
}
- else
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "add_printer_formats: %s: %s not supported",
- p->name, mimetype);
- }
- cupsdLogMessage(CUPSD_LOG_DEBUG2,
- "add_printer_formats: %s: %d supported types",
- p->name, cupsArrayCount(p->filetypes) + 1);
+ /*
+ * Show current and available port monitors for this printer...
+ */
- /*
- * Add the file formats that can be filtered...
- */
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "port-monitor",
+ NULL, p->port_monitor ? p->port_monitor : "none");
- if ((type = mimeType(MimeDatabase, "application", "octet-stream")) == NULL ||
- !cupsArrayFind(p->filetypes, type))
- i = 1;
- else
- i = 0;
+ for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
+ ppd_attr;
+ i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
- attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
- "document-format-supported",
- cupsArrayCount(p->filetypes) + 1, NULL, NULL);
+ if (ppd->protocols)
+ {
+ if (strstr(ppd->protocols, "TBCP"))
+ i ++;
+ else if (strstr(ppd->protocols, "BCP"))
+ i ++;
+ }
- if (i)
- attr->values[0].string.text = _cupsStrAlloc("application/octet-stream");
+ attr = ippAddStrings(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "port-monitor-supported", i, NULL, NULL);
- for (type = (mime_type_t *)cupsArrayFirst(p->filetypes);
- type;
- i ++, type = (mime_type_t *)cupsArrayNext(p->filetypes))
- {
- snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
+ attr->values[0].string.text = _cupsStrAlloc("none");
- attr->values[i].string.text = _cupsStrAlloc(mimetype);
- }
+ for (i = 1, ppd_attr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
+ ppd_attr;
+ i ++, ppd_attr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
+ attr->values[i].string.text = _cupsStrAlloc(ppd_attr->value);
+
+ if (ppd->protocols)
+ {
+ if (strstr(ppd->protocols, "TBCP"))
+ attr->values[i].string.text = _cupsStrAlloc("tbcp");
+ else if (strstr(ppd->protocols, "BCP"))
+ attr->values[i].string.text = _cupsStrAlloc("bcp");
+ }
#ifdef HAVE_DNSSD
+ cupsdSetString(&p->product, ppd->product);
+#endif /* HAVE_DNSSD */
+
+ if (ppdFindAttr(ppd, "APRemoteQueueID", NULL))
+ p->type |= CUPS_PRINTER_REMOTE;
+
+ /*
+ * Close the PPD and set the type...
+ */
+
+ ppdClose(ppd);
+ }
+ else if (!access(ppd_name, 0))
{
- char pdl[1024]; /* Buffer to build pdl list */
- mime_filter_t *filter; /* MIME filter looping var */
+ int pline; /* PPD line number */
+ ppd_status_t pstatus; /* PPD load status */
- pdl[0] = '\0';
+ pstatus = ppdLastError(&pline);
- if (mimeType(MimeDatabase, "application", "pdf"))
- strlcat(pdl, "application/pdf,", sizeof(pdl));
+ cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!",
+ p->name);
- if (mimeType(MimeDatabase, "application", "postscript"))
- strlcat(pdl, "application/postscript,", sizeof(pdl));
+ if (pstatus <= PPD_ALLOC_ERROR)
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
+ else
+ cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.",
+ ppdErrorString(pstatus), pline);
- if (mimeType(MimeDatabase, "application", "vnd.cups-raster"))
- strlcat(pdl, "application/vnd.cups-raster,", sizeof(pdl));
+ cupsdLogMessage(CUPSD_LOG_INFO,
+ "Hint: Run \"cupstestppd %s\" and fix any errors.",
+ ppd_name);
/*
- * Determine if this is a Tioga PrintJobMgr based queue...
+ * Add a filter from application/vnd.cups-raw to printer/name to
+ * handle "raw" printing by users.
*/
- for (filter = (mime_filter_t *)cupsArrayFirst(MimeDatabase->filters);
- filter;
- filter = (mime_filter_t *)cupsArrayNext(MimeDatabase->filters))
- {
- if (filter->dst == p->filetype && filter->filter &&
- strstr(filter->filter, "PrintJobMgr"))
- break;
- }
+ add_string_array(&(p->filters), "application/vnd.cups-raw 0 -");
/*
- * We only support raw printing if this is not a Tioga PrintJobMgr based
- * queue and if application/octet-stream is a known conversion...
+ * Add a PostScript filter, since this is still possibly PS printer.
*/
- if (!filter && mimeType(MimeDatabase, "application", "octet-stream"))
- strlcat(pdl, "application/octet-stream,", sizeof(pdl));
-
- if (mimeType(MimeDatabase, "image", "png"))
- strlcat(pdl, "image/png,", sizeof(pdl));
-
- if (pdl[0])
- pdl[strlen(pdl) - 1] = '\0'; /* Remove trailing comma */
-
- cupsdSetString(&p->pdl, pdl);
+ add_string_array(&(p->filters), "application/vnd.cups-postscript 0 -");
}
-#endif /* HAVE_DNSSD */
-}
+ else
+ {
+ /*
+ * If we have an interface script, add a filter entry for it...
+ */
+ char interface[1024]; /* Interface script */
-/*
- * 'compare_printers()' - Compare two printers.
- */
-static int /* O - Result of comparison */
-compare_printers(void *first, /* I - First printer */
- void *second, /* I - Second printer */
- void *data) /* I - App data (not used) */
-{
- return (strcasecmp(((cupsd_printer_t *)first)->name,
- ((cupsd_printer_t *)second)->name));
-}
+ snprintf(interface, sizeof(interface), "%s/interfaces/%s", ServerRoot,
+ p->name);
+ if (!access(interface, X_OK))
+ {
+ /*
+ * Yes, we have a System V style interface script; use it!
+ */
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "printer-make-and-model", NULL,
+ "Local System V Printer");
-/*
- * 'delete_printer_filters()' - Delete all MIME filters for a printer.
- */
+ snprintf(interface, sizeof(interface), "*/* 0 %s/interfaces/%s",
+ ServerRoot, p->name);
+ add_string_array(&(p->filters), interface);
+ }
+ else if (!strncmp(p->device_uri, "ipp://", 6) &&
+ (strstr(p->device_uri, "/printers/") != NULL ||
+ strstr(p->device_uri, "/classes/") != NULL ||
+ (strstr(p->device_uri, "._ipp.") != NULL &&
+ !strcmp(p->device_uri + strlen(p->device_uri) - 5,
+ "/cups"))))
+ {
+ /*
+ * Tell the client this is really a hard-wired remote printer.
+ */
-static void
-delete_printer_filters(
- cupsd_printer_t *p) /* I - Printer to remove from */
-{
- mime_filter_t *filter; /* MIME filter looping var */
+ p->type |= CUPS_PRINTER_REMOTE;
+ /*
+ * Point the printer-uri-supported attribute to the
+ * remote printer...
+ */
- /*
- * Range check input...
- */
+ ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
+ "printer-uri-supported", NULL, p->device_uri);
- if (p == NULL)
- return;
+ /*
+ * Then set the make-and-model accordingly...
+ */
- /*
- * Remove all filters from the MIME database that have a destination
- * type == printer...
- */
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "printer-make-and-model", NULL, "Remote Printer");
- for (filter = mimeFirstFilter(MimeDatabase);
- filter;
- filter = mimeNextFilter(MimeDatabase))
- if (filter->dst == p->filetype)
+ /*
+ * Print all files directly...
+ */
+
+ p->raw = 1;
+ p->remote = 1;
+ }
+ else
{
/*
- * Delete the current filter...
+ * Otherwise we have neither - treat this as a "dumb" printer
+ * with no PPD file...
*/
- mimeDeleteFilter(MimeDatabase, filter);
+ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
+ "printer-make-and-model", NULL, "Local Raw Printer");
+
+ p->raw = 1;
+ }
+ }
+
+ ippAddIntegers(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
+ "finishings-supported", num_finishings, finishings);
+ ippAddInteger(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
+ "finishings-default", IPP_FINISHINGS_NONE);
+
+ if (ppd && (cache = cupsFileOpen(cache_name, "w")) != NULL)
+ {
+ /*
+ * Save cached PPD attributes to disk...
+ */
+
+ cupsdLogMessage(CUPSD_LOG_DEBUG, "load_ppd: Saving %s...", cache_name);
+
+ p->ppd_attrs->state = IPP_IDLE;
+
+ if (ippWriteIO(cache, (ipp_iocb_t)cupsFileWrite, 1, NULL,
+ p->ppd_attrs) != IPP_DATA)
+ {
+ cupsdLogMessage(CUPSD_LOG_ERROR,
+ "Unable to save PPD cache file \"%s\" - %s", cache_name,
+ strerror(errno));
+ unlink(cache_name);
}
+
+ cupsFileClose(cache);
+ }
+ else if (cache_info.st_mtime)
+ {
+ /*
+ * Remove cache file...
+ */
+
+ unlink(cache_name);
+ }
}
cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
- cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
+ cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri);
cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
"Faulted");
cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
- p->device_uri ? p->device_uri : "");
+ p->device_uri);
cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
p->accepting ? "Accepting" : "Not accepting");
cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
/*
- * End of "$Id: printers.c 6970 2007-09-17 23:58:28Z mike $".
+ * 'write_xml_string()' - Write a string with XML escaping.
+ */
+
+static void
+write_xml_string(cups_file_t *fp, /* I - File to write to */
+ const char *s) /* I - String to write */
+{
+ const char *start; /* Start of current sequence */
+
+
+ if (!s)
+ return;
+
+ for (start = s; *s; s ++)
+ {
+ if (*s == '&')
+ {
+ if (s > start)
+ cupsFileWrite(fp, start, s - start);
+
+ cupsFilePuts(fp, "&");
+ start = s + 1;
+ }
+ else if (*s == '<')
+ {
+ if (s > start)
+ cupsFileWrite(fp, start, s - start);
+
+ cupsFilePuts(fp, "<");
+ start = s + 1;
+ }
+ }
+
+ if (s > start)
+ cupsFilePuts(fp, start);
+}
+
+
+/*
+ * End of "$Id: printers.c 7968 2008-09-19 23:03:01Z mike $".
*/