4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
22 #ifdef HAVE_APPLICATIONSERVICES_H
23 # include <ApplicationServices/ApplicationServices.h>
24 #endif /* HAVE_APPLICATIONSERVICES_H */
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
27 #endif /* HAVE_SYS_MOUNT_H */
28 #ifdef HAVE_SYS_STATVFS_H
29 # include <sys/statvfs.h>
30 #elif defined(HAVE_SYS_STATFS_H)
31 # include <sys/statfs.h>
32 #endif /* HAVE_SYS_STATVFS_H */
35 #endif /* HAVE_SYS_VFS_H */
38 #endif /* __APPLE__ */
45 static void add_printer_defaults(cupsd_printer_t
*p
);
46 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
48 static void add_printer_formats(cupsd_printer_t
*p
);
49 static int compare_printers(void *first
, void *second
, void *data
);
50 static void delete_printer_filters(cupsd_printer_t
*p
);
51 static void dirty_printer(cupsd_printer_t
*p
);
52 static void load_ppd(cupsd_printer_t
*p
);
53 static void log_ipp_conformance(cupsd_printer_t
*p
, const char *reason
);
54 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
56 static void write_xml_string(cups_file_t
*fp
, const char *s
);
60 * 'cupsdAddPrinter()' - Add a printer to the system.
63 cupsd_printer_t
* /* O - New printer */
64 cupsdAddPrinter(const char *name
) /* I - Name of printer */
66 cupsd_printer_t
*p
; /* New printer */
67 char uri
[1024], /* Printer URI */
68 uuid
[64]; /* Printer UUID */
72 * Range check input...
75 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
78 * Create a new printer entity...
81 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
83 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
88 cupsdSetString(&p
->name
, name
);
89 cupsdSetString(&p
->info
, name
);
90 cupsdSetString(&p
->hostname
, ServerName
);
92 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
93 ServerName
, RemotePort
, "/printers/%s", name
);
94 cupsdSetString(&p
->uri
, uri
);
95 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
97 cupsdSetDeviceURI(p
, "file:///dev/null");
99 p
->state
= IPP_PRINTER_STOPPED
;
100 p
->state_time
= time(NULL
);
102 p
->shared
= DefaultShared
;
103 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
105 cupsdSetString(&p
->job_sheets
[0], "none");
106 cupsdSetString(&p
->job_sheets
[1], "none");
108 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
109 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
111 p
->op_policy_ptr
= DefaultPolicyPtr
;
114 * Insert the printer in the printer list alphabetically...
118 Printers
= cupsArrayNew(compare_printers
, NULL
);
120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
121 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
122 cupsArrayAdd(Printers
, p
);
125 * Return the new printer...
133 * 'cupsdCreateCommonData()' - Create the common printer data.
137 cupsdCreateCommonData(void)
139 int i
; /* Looping var */
140 ipp_attribute_t
*attr
; /* Attribute data */
141 cups_dir_t
*dir
; /* Notifier directory */
142 cups_dentry_t
*dent
; /* Notifier directory entry */
143 cups_array_t
*notifiers
; /* Notifier array */
144 char filename
[1024], /* Filename */
145 *notifier
; /* Current notifier */
146 cupsd_policy_t
*p
; /* Current policy */
147 int k_supported
; /* Maximum file size supported */
149 struct statvfs spoolinfo
; /* FS info for spool directory */
150 double spoolsize
; /* FS size */
151 #elif defined(HAVE_STATFS)
152 struct statfs spoolinfo
; /* FS info for spool directory */
153 double spoolsize
; /* FS size */
154 #endif /* HAVE_STATVFS */
155 static const int nups
[] = /* number-up-supported values */
156 { 1, 2, 4, 6, 9, 16 };
157 static const int orients
[4] =/* orientation-requested-supported values */
161 IPP_REVERSE_LANDSCAPE
,
164 static const char * const holds
[] = /* job-hold-until-supported values */
175 static const char * const versions
[] =/* ipp-versions-supported values */
182 static const int ops
[] = /* operations-supported values */
189 IPP_GET_JOB_ATTRIBUTES
,
191 IPP_GET_PRINTER_ATTRIBUTES
,
198 IPP_SET_PRINTER_ATTRIBUTES
,
199 IPP_SET_JOB_ATTRIBUTES
,
200 IPP_GET_PRINTER_SUPPORTED_VALUES
,
201 IPP_CREATE_PRINTER_SUBSCRIPTION
,
202 IPP_CREATE_JOB_SUBSCRIPTION
,
203 IPP_GET_SUBSCRIPTION_ATTRIBUTES
,
204 IPP_GET_SUBSCRIPTIONS
,
205 IPP_RENEW_SUBSCRIPTION
,
206 IPP_CANCEL_SUBSCRIPTION
,
207 IPP_GET_NOTIFICATIONS
,
211 IPP_RELEASE_HELD_NEW_JOBS
,
228 CUPS_AUTHENTICATE_JOB
,
233 static const char * const charsets
[] =/* charset-supported values */
238 static const char * const compressions
[] =
239 { /* document-compression-supported values */
243 #endif /* HAVE_LIBZ */
245 static const char * const media_col_supported
[] =
246 { /* media-col-supported values */
247 "media-bottom-margin",
249 "media-right-margin",
255 static const char * const multiple_document_handling
[] =
256 { /* multiple-document-handling-supported values */
257 "separate-documents-uncollated-copies",
258 "separate-documents-collated-copies"
260 static const char * const notify_attrs
[] =
261 { /* notify-attributes-supported values */
262 "printer-state-change-time",
263 "notify-lease-expiration-time",
264 "notify-subscriber-user-name"
266 static const char * const notify_events
[] =
267 { /* notify-events-supported values */
269 "job-config-changed",
276 "printer-config-changed",
278 "printer-finishings-changed",
279 "printer-media-changed",
283 "printer-state-changed",
290 static const char * const job_creation
[] =
291 { /* job-creation-attributes-supported */
294 "ipp-attribute-fidelity",
301 "multiple-document-handling",
304 "orientation-requested",
308 "printer-resolution",
311 static const char * const job_settable
[] =
312 { /* job-settable-attributes-supported */
320 "multiple-document-handling",
323 "orientation-requested",
327 "printer-resolution",
330 static const char * const pdf_versions
[] =
331 { /* pdf-versions-supported */
342 static const char * const printer_settable
[] =
343 { /* printer-settable-attributes-supported */
347 static const char * const which_jobs
[] =
348 { /* which-jobs-supported values */
362 ippDelete(CommonData
);
364 CommonData
= ippNew();
367 * Get the maximum spool size based on the size of the filesystem used for
368 * the RequestRoot directory. If the host OS doesn't support the statfs call
369 * or the filesystem is larger than 2TiB, always report INT_MAX.
373 if (statvfs(RequestRoot
, &spoolinfo
))
374 k_supported
= INT_MAX
;
375 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
377 k_supported
= INT_MAX
;
379 k_supported
= (int)spoolsize
;
381 #elif defined(HAVE_STATFS)
382 if (statfs(RequestRoot
, &spoolinfo
))
383 k_supported
= INT_MAX
;
384 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
386 k_supported
= INT_MAX
;
388 k_supported
= (int)spoolsize
;
391 k_supported
= INT_MAX
;
392 #endif /* HAVE_STATVFS */
395 * This list of attributes is sorted to improve performance when the
396 * client provides a requested-attributes attribute...
399 /* charset-configured */
400 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
401 "charset-configured", NULL
, "utf-8");
403 /* charset-supported */
404 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
405 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
408 /* compression-supported */
409 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
410 "compression-supported",
411 sizeof(compressions
) / sizeof(compressions
[0]),
414 /* copies-supported */
415 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
418 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
419 "cups-version", NULL
, CUPS_SVERSION
+ 6);
421 /* generated-natural-language-supported (no IPP_TAG_COPY) */
422 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
423 "generated-natural-language-supported", NULL
, DefaultLanguage
);
425 /* ipp-versions-supported */
426 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
427 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
430 /* ippget-event-life */
431 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
432 "ippget-event-life", 15);
434 /* job-cancel-after-supported */
435 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
438 /* job-creation-attributes-supported */
439 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
440 "job-creation-attributes-supported",
441 sizeof(job_creation
) / sizeof(job_creation
[0]),
444 /* job-hold-until-supported */
445 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
446 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
449 /* job-ids-supported */
450 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
452 /* job-k-octets-supported */
453 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
456 /* job-priority-supported */
457 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
458 "job-priority-supported", 100);
460 /* job-settable-attributes-supported */
461 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
462 "job-settable-attributes-supported",
463 sizeof(job_settable
) / sizeof(job_settable
[0]),
466 /* job-sheets-supported */
467 if (cupsArrayCount(Banners
) > 0)
470 * Setup the job-sheets-supported attribute...
473 if (Classification
&& !ClassifyOverride
)
474 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
475 IPP_TAG_NAME
| IPP_TAG_COPY
,
476 "job-sheets-supported", NULL
, Classification
);
478 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
479 IPP_TAG_NAME
| IPP_TAG_COPY
,
480 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
484 cupsdLogMessage(CUPSD_LOG_EMERG
,
485 "Unable to allocate memory for "
486 "job-sheets-supported attribute: %s!", strerror(errno
));
487 else if (!Classification
|| ClassifyOverride
)
489 cupsd_banner_t
*banner
; /* Current banner */
492 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
494 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
496 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
497 attr
->values
[i
].string
.text
= banner
->name
;
501 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
502 "job-sheets-supported", NULL
, "none");
504 /* jpeg-k-octets-supported */
505 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
508 /* jpeg-x-dimension-supported */
509 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
512 /* jpeg-y-dimension-supported */
513 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
516 /* media-col-supported */
517 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
518 "media-col-supported",
519 sizeof(media_col_supported
) /
520 sizeof(media_col_supported
[0]), NULL
,
521 media_col_supported
);
523 /* multiple-document-handling-supported */
524 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
525 "multiple-document-handling-supported",
526 sizeof(multiple_document_handling
) /
527 sizeof(multiple_document_handling
[0]), NULL
,
528 multiple_document_handling
);
530 /* multiple-document-jobs-supported */
531 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
532 "multiple-document-jobs-supported", 1);
534 /* multiple-operation-time-out */
535 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
536 "multiple-operation-time-out", MultipleOperationTimeout
);
538 /* natural-language-configured (no IPP_TAG_COPY) */
539 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
540 "natural-language-configured", NULL
, DefaultLanguage
);
542 /* notify-attributes-supported */
543 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
544 "notify-attributes-supported",
545 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
548 /* notify-lease-duration-supported */
549 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
550 "notify-lease-duration-supported", 0,
551 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
553 /* notify-max-events-supported */
554 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
555 "notify-max-events-supported", MaxEvents
);
557 /* notify-events-supported */
558 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
559 "notify-events-supported",
560 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
561 NULL
, notify_events
);
563 /* notify-pull-method-supported */
564 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
565 "notify-pull-method-supported", NULL
, "ippget");
567 /* notify-schemes-supported */
568 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
569 if ((dir
= cupsDirOpen(filename
)) != NULL
)
571 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
573 while ((dent
= cupsDirRead(dir
)) != NULL
)
574 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
575 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
576 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
578 if (cupsArrayCount(notifiers
) > 0)
580 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
581 "notify-schemes-supported",
582 cupsArrayCount(notifiers
), NULL
, NULL
);
584 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
586 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
587 attr
->values
[i
].string
.text
= notifier
;
590 cupsArrayDelete(notifiers
);
594 /* number-up-supported */
595 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
596 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
598 /* operations-supported */
599 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
600 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
602 /* orientation-requested-supported */
603 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
604 "orientation-requested-supported", 4, orients
);
606 /* page-ranges-supported */
607 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
609 /* pdf-k-octets-supported */
610 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
613 /* pdf-versions-supported */
614 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
615 "pdf-versions-supported",
616 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
619 /* pdl-override-supported */
620 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
621 "pdl-override-supported", NULL
, "attempted");
623 /* printer-op-policy-supported */
624 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
625 "printer-op-policy-supported", cupsArrayCount(Policies
),
627 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
629 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
630 attr
->values
[i
].string
.text
= p
->name
;
632 /* printer-settable-attributes-supported */
633 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
634 "printer-settable-attributes-supported",
635 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
636 NULL
, printer_settable
);
638 /* server-is-sharing-printers */
639 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
640 BrowseLocalProtocols
!= 0 && Browsing
);
642 /* which-jobs-supported */
643 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
644 "which-jobs-supported",
645 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
650 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
654 cupsdDeleteAllPrinters(void)
656 cupsd_printer_t
*p
; /* Pointer to current printer/class */
659 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
661 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
663 p
->op_policy_ptr
= DefaultPolicyPtr
;
664 cupsdDeletePrinter(p
, 0);
670 * 'cupsdDeletePrinter()' - Delete a printer from the system.
673 int /* O - 1 if classes affected, 0 otherwise */
675 cupsd_printer_t
*p
, /* I - Printer to delete */
676 int update
) /* I - Update printers.conf? */
678 int i
, /* Looping var */
679 changed
= 0; /* Class changed? */
682 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
686 * Save the current position in the Printers array...
689 cupsArraySave(Printers
);
692 * Stop printing on this printer...
695 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
697 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
700 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
701 update
? "Job stopped due to printer being deleted." :
705 * Remove the printer from the list...
708 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
709 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
710 cupsArrayRemove(Printers
, p
);
713 * If p is the default printer, assign a different one...
716 if (p
== DefaultPrinter
)
717 DefaultPrinter
= NULL
;
720 * Remove this printer from any classes...
723 changed
= cupsdDeletePrinterFromClasses(p
);
726 * Deregister from any browse protocols...
729 cupsdDeregisterPrinter(p
, 1);
732 * Free all memory used by the printer...
735 if (p
->printers
!= NULL
)
738 delete_printer_filters(p
);
740 for (i
= 0; i
< p
->num_reasons
; i
++)
741 _cupsStrFree(p
->reasons
[i
]);
744 ippDelete(p
->ppd_attrs
);
746 mimeDeleteType(MimeDatabase
, p
->filetype
);
747 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
749 cupsdFreeStrings(&(p
->users
));
752 cupsdClearString(&p
->uri
);
753 cupsdClearString(&p
->hostname
);
754 cupsdClearString(&p
->name
);
755 cupsdClearString(&p
->location
);
756 cupsdClearString(&p
->make_model
);
757 cupsdClearString(&p
->info
);
758 cupsdClearString(&p
->job_sheets
[0]);
759 cupsdClearString(&p
->job_sheets
[1]);
760 cupsdClearString(&p
->device_uri
);
761 cupsdClearString(&p
->sanitized_device_uri
);
762 cupsdClearString(&p
->port_monitor
);
763 cupsdClearString(&p
->op_policy
);
764 cupsdClearString(&p
->error_policy
);
766 cupsdClearString(&p
->alert
);
767 cupsdClearString(&p
->alert_description
);
769 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
770 cupsdClearString(&p
->pdl
);
771 cupsdClearString(&p
->reg_name
);
772 #endif /* HAVE_DNSSD || HAVE_AVAHI */
774 cupsArrayDelete(p
->filetypes
);
776 cupsFreeOptions(p
->num_options
, p
->options
);
781 * Restore the previous position in the Printers array...
784 cupsArrayRestore(Printers
);
791 * 'cupsdFindDest()' - Find a destination in the list.
794 cupsd_printer_t
* /* O - Destination in list */
795 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
797 cupsd_printer_t key
; /* Search key */
800 key
.name
= (char *)name
;
801 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
806 * 'cupsdFindPrinter()' - Find a printer in the list.
809 cupsd_printer_t
* /* O - Printer in list */
810 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
812 cupsd_printer_t
*p
; /* Printer in list */
815 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
823 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
827 cupsdLoadAllPrinters(void)
829 int i
; /* Looping var */
830 cups_file_t
*fp
; /* printers.conf file */
831 int linenum
; /* Current line number */
832 char line
[4096], /* Line from file */
833 *value
, /* Pointer to value */
834 *valueptr
; /* Pointer into value */
835 cupsd_printer_t
*p
; /* Current printer */
839 * Open the printers.conf file...
842 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
843 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
847 * Read printer configurations until we hit EOF...
853 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
856 * Decode the directive...
859 if (!_cups_strcasecmp(line
, "<Printer") ||
860 !_cups_strcasecmp(line
, "<DefaultPrinter"))
863 * <Printer name> or <DefaultPrinter name>
866 if (p
== NULL
&& value
)
869 * Add the printer and a base file type...
872 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
874 p
= cupsdAddPrinter(value
);
876 p
->state
= IPP_PRINTER_IDLE
;
879 * Set the default printer as needed...
882 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
886 cupsdLogMessage(CUPSD_LOG_ERROR
,
887 "Syntax error on line %d of printers.conf.", linenum
);
889 else if (!_cups_strcasecmp(line
, "</Printer>"))
894 * Close out the current printer...
897 cupsdSetPrinterAttrs(p
);
899 if (strncmp(p
->device_uri
, "file:", 5) &&
900 p
->state
!= IPP_PRINTER_STOPPED
)
903 * See if the backend exists...
906 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
909 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
910 *valueptr
= '\0'; /* Chop everything but URI scheme */
915 * Backend does not exist, stop printer...
918 p
->state
= IPP_PRINTER_STOPPED
;
919 snprintf(p
->state_message
, sizeof(p
->state_message
),
920 "Backend %s does not exist!", line
);
927 cupsdLogMessage(CUPSD_LOG_ERROR
,
928 "Syntax error on line %d of printers.conf.", linenum
);
932 cupsdLogMessage(CUPSD_LOG_ERROR
,
933 "Syntax error on line %d of printers.conf.", linenum
);
935 else if (!_cups_strcasecmp(line
, "UUID"))
937 if (value
&& !strncmp(value
, "urn:uuid:", 9))
938 cupsdSetString(&(p
->uuid
), value
);
940 cupsdLogMessage(CUPSD_LOG_ERROR
,
941 "Bad UUID on line %d of printers.conf.", linenum
);
943 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
945 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
946 cupsdLogMessage(CUPSD_LOG_ERROR
,
947 "Bad AuthInfoRequired on line %d of printers.conf.",
950 else if (!_cups_strcasecmp(line
, "Info"))
953 cupsdSetString(&p
->info
, value
);
955 else if (!_cups_strcasecmp(line
, "MakeModel"))
958 cupsdSetString(&p
->make_model
, value
);
960 else if (!_cups_strcasecmp(line
, "Location"))
963 cupsdSetString(&p
->location
, value
);
965 else if (!_cups_strcasecmp(line
, "DeviceURI"))
968 cupsdSetDeviceURI(p
, value
);
970 cupsdLogMessage(CUPSD_LOG_ERROR
,
971 "Syntax error on line %d of printers.conf.", linenum
);
973 else if (!_cups_strcasecmp(line
, "Option") && value
)
979 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
982 cupsdLogMessage(CUPSD_LOG_ERROR
,
983 "Syntax error on line %d of printers.conf.", linenum
);
986 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
988 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
992 else if (!_cups_strcasecmp(line
, "PortMonitor"))
994 if (value
&& strcmp(value
, "none"))
995 cupsdSetString(&p
->port_monitor
, value
);
997 cupsdClearString(&p
->port_monitor
);
999 cupsdLogMessage(CUPSD_LOG_ERROR
,
1000 "Syntax error on line %d of printers.conf.", linenum
);
1002 else if (!_cups_strcasecmp(line
, "Reason"))
1005 strcmp(value
, "connecting-to-device") &&
1006 strcmp(value
, "cups-insecure-filter-warning") &&
1007 strcmp(value
, "cups-missing-filter-warning"))
1009 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1010 if (!strcmp(value
, p
->reasons
[i
]))
1013 if (i
>= p
->num_reasons
&&
1014 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1016 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1021 cupsdLogMessage(CUPSD_LOG_ERROR
,
1022 "Syntax error on line %d of printers.conf.", linenum
);
1024 else if (!_cups_strcasecmp(line
, "State"))
1027 * Set the initial queue state...
1030 if (value
&& !_cups_strcasecmp(value
, "idle"))
1031 p
->state
= IPP_PRINTER_IDLE
;
1032 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1034 p
->state
= IPP_PRINTER_STOPPED
;
1036 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1037 if (!strcmp("paused", p
->reasons
[i
]))
1040 if (i
>= p
->num_reasons
&&
1041 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1043 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1048 cupsdLogMessage(CUPSD_LOG_ERROR
,
1049 "Syntax error on line %d of printers.conf.", linenum
);
1051 else if (!_cups_strcasecmp(line
, "StateMessage"))
1054 * Set the initial queue state message...
1058 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1060 else if (!_cups_strcasecmp(line
, "StateTime"))
1063 * Set the state time...
1067 p
->state_time
= atoi(value
);
1069 else if (!_cups_strcasecmp(line
, "Accepting"))
1072 * Set the initial accepting state...
1076 (!_cups_strcasecmp(value
, "yes") ||
1077 !_cups_strcasecmp(value
, "on") ||
1078 !_cups_strcasecmp(value
, "true")))
1081 (!_cups_strcasecmp(value
, "no") ||
1082 !_cups_strcasecmp(value
, "off") ||
1083 !_cups_strcasecmp(value
, "false")))
1086 cupsdLogMessage(CUPSD_LOG_ERROR
,
1087 "Syntax error on line %d of printers.conf.", linenum
);
1089 else if (!_cups_strcasecmp(line
, "Type"))
1092 p
->type
= atoi(value
);
1094 cupsdLogMessage(CUPSD_LOG_ERROR
,
1095 "Syntax error on line %d of printers.conf.", linenum
);
1097 else if (!_cups_strcasecmp(line
, "Shared"))
1100 * Set the initial shared state...
1104 (!_cups_strcasecmp(value
, "yes") ||
1105 !_cups_strcasecmp(value
, "on") ||
1106 !_cups_strcasecmp(value
, "true")))
1109 (!_cups_strcasecmp(value
, "no") ||
1110 !_cups_strcasecmp(value
, "off") ||
1111 !_cups_strcasecmp(value
, "false")))
1114 cupsdLogMessage(CUPSD_LOG_ERROR
,
1115 "Syntax error on line %d of printers.conf.", linenum
);
1117 else if (!_cups_strcasecmp(line
, "JobSheets"))
1120 * Set the initial job sheets...
1125 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1130 cupsdSetString(&p
->job_sheets
[0], value
);
1132 while (isspace(*valueptr
& 255))
1137 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1142 cupsdSetString(&p
->job_sheets
[1], value
);
1146 cupsdLogMessage(CUPSD_LOG_ERROR
,
1147 "Syntax error on line %d of printers.conf.", linenum
);
1149 else if (!_cups_strcasecmp(line
, "AllowUser"))
1154 cupsdAddString(&(p
->users
), value
);
1157 cupsdLogMessage(CUPSD_LOG_ERROR
,
1158 "Syntax error on line %d of printers.conf.", linenum
);
1160 else if (!_cups_strcasecmp(line
, "DenyUser"))
1165 cupsdAddString(&(p
->users
), value
);
1168 cupsdLogMessage(CUPSD_LOG_ERROR
,
1169 "Syntax error on line %d of printers.conf.", linenum
);
1171 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1174 p
->quota_period
= atoi(value
);
1176 cupsdLogMessage(CUPSD_LOG_ERROR
,
1177 "Syntax error on line %d of printers.conf.", linenum
);
1179 else if (!_cups_strcasecmp(line
, "PageLimit"))
1182 p
->page_limit
= atoi(value
);
1184 cupsdLogMessage(CUPSD_LOG_ERROR
,
1185 "Syntax error on line %d of printers.conf.", linenum
);
1187 else if (!_cups_strcasecmp(line
, "KLimit"))
1190 p
->k_limit
= atoi(value
);
1192 cupsdLogMessage(CUPSD_LOG_ERROR
,
1193 "Syntax error on line %d of printers.conf.", linenum
);
1195 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1199 cupsd_policy_t
*pol
; /* Policy */
1202 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1204 cupsdSetString(&p
->op_policy
, value
);
1205 p
->op_policy_ptr
= pol
;
1208 cupsdLogMessage(CUPSD_LOG_ERROR
,
1209 "Bad policy \"%s\" on line %d of printers.conf",
1213 cupsdLogMessage(CUPSD_LOG_ERROR
,
1214 "Syntax error on line %d of printers.conf.", linenum
);
1216 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1219 cupsdSetString(&p
->error_policy
, value
);
1221 cupsdLogMessage(CUPSD_LOG_ERROR
,
1222 "Syntax error on line %d of printers.conf.", linenum
);
1224 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1226 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1229 cupsdLogMessage(CUPSD_LOG_ERROR
,
1230 "Syntax error on line %d of printers.conf.", linenum
);
1233 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1236 cupsdSetPrinterAttrs(p
);
1238 if (!strcmp(value
, "marker-change-time"))
1239 p
->marker_time
= atoi(valueptr
);
1241 cupsdSetPrinterAttr(p
, value
, valueptr
);
1244 else if (_cups_strcasecmp(line
, "Filter") &&
1245 _cups_strcasecmp(line
, "Prefilter") &&
1246 _cups_strcasecmp(line
, "Product"))
1249 * Something else we don't understand (and that wasn't used in a prior
1250 * release of CUPS...
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Unknown configuration directive %s on line %d of "
1255 "printers.conf.", line
, linenum
);
1264 * 'cupsdRenamePrinter()' - Rename a printer.
1269 cupsd_printer_t
*p
, /* I - Printer */
1270 const char *name
) /* I - New name */
1273 * Remove the printer from the array(s) first...
1276 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1277 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1278 cupsArrayRemove(Printers
, p
);
1281 * Rename the printer type...
1284 mimeDeleteType(MimeDatabase
, p
->filetype
);
1285 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1287 if (p
->prefiltertype
)
1289 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1290 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1294 * Rename the printer...
1297 cupsdSetString(&p
->name
, name
);
1300 * Reset printer attributes...
1303 cupsdSetPrinterAttrs(p
);
1306 * Add the printer back to the printer array(s)...
1309 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1310 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1311 cupsArrayAdd(Printers
, p
);
1316 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1321 cupsdSaveAllPrinters(void)
1323 int i
; /* Looping var */
1324 cups_file_t
*fp
; /* printers.conf file */
1325 char filename
[1024], /* printers.conf filename */
1326 temp
[1024], /* Temporary string */
1327 value
[2048], /* Value string */
1328 *ptr
, /* Pointer into value */
1329 *name
; /* Current user/group name */
1330 cupsd_printer_t
*printer
; /* Current printer class */
1331 time_t curtime
; /* Current time */
1332 struct tm
*curdate
; /* Current date */
1333 cups_option_t
*option
; /* Current option */
1334 ipp_attribute_t
*marker
; /* Current marker attribute */
1338 * Create the printers.conf file...
1341 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1343 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1346 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1349 * Write a small header to the file...
1352 curtime
= time(NULL
);
1353 curdate
= localtime(&curtime
);
1354 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1356 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1357 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1358 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1361 * Write each local printer known to the system...
1364 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1366 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1369 * Skip printer classes...
1372 if (printer
->type
& CUPS_PRINTER_CLASS
)
1376 * Write printers as needed...
1379 if (printer
== DefaultPrinter
)
1380 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1382 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1384 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1386 if (printer
->num_auth_info_required
> 0)
1388 switch (printer
->num_auth_info_required
)
1391 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1395 snprintf(value
, sizeof(value
), "%s,%s",
1396 printer
->auth_info_required
[0],
1397 printer
->auth_info_required
[1]);
1402 snprintf(value
, sizeof(value
), "%s,%s,%s",
1403 printer
->auth_info_required
[0],
1404 printer
->auth_info_required
[1],
1405 printer
->auth_info_required
[2]);
1409 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1413 cupsFilePutConf(fp
, "Info", printer
->info
);
1415 if (printer
->location
)
1416 cupsFilePutConf(fp
, "Location", printer
->location
);
1418 if (printer
->make_model
)
1419 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1421 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1423 if (printer
->port_monitor
)
1424 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1426 if (printer
->state
== IPP_PRINTER_STOPPED
)
1428 cupsFilePuts(fp
, "State Stopped\n");
1430 if (printer
->state_message
)
1431 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1434 cupsFilePuts(fp
, "State Idle\n");
1436 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1438 for (i
= 0; i
< printer
->num_reasons
; i
++)
1439 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1440 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1441 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1442 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1444 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1446 if (printer
->accepting
)
1447 cupsFilePuts(fp
, "Accepting Yes\n");
1449 cupsFilePuts(fp
, "Accepting No\n");
1451 if (printer
->shared
)
1452 cupsFilePuts(fp
, "Shared Yes\n");
1454 cupsFilePuts(fp
, "Shared No\n");
1456 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1457 printer
->job_sheets
[1]);
1458 cupsFilePutConf(fp
, "JobSheets", value
);
1460 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1461 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1462 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1464 for (name
= (char *)cupsArrayFirst(printer
->users
);
1466 name
= (char *)cupsArrayNext(printer
->users
))
1467 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1469 if (printer
->op_policy
)
1470 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1471 if (printer
->error_policy
)
1472 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1474 for (i
= printer
->num_options
, option
= printer
->options
;
1478 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1479 cupsFilePutConf(fp
, "Option", value
);
1482 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1483 IPP_TAG_NAME
)) != NULL
)
1485 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1487 for (i
= 0, ptr
= value
+ strlen(value
);
1488 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1494 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1495 value
+ sizeof(value
) - ptr
);
1500 cupsFilePutConf(fp
, "Attribute", value
);
1503 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1504 IPP_TAG_INTEGER
)) != NULL
)
1506 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1507 marker
->values
[0].integer
);
1508 for (i
= 1; i
< marker
->num_values
; i
++)
1509 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1510 cupsFilePuts(fp
, "\n");
1513 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1514 IPP_TAG_INTEGER
)) != NULL
)
1516 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1517 marker
->values
[0].integer
);
1518 for (i
= 1; i
< marker
->num_values
; i
++)
1519 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1520 cupsFilePuts(fp
, "\n");
1523 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1524 IPP_TAG_INTEGER
)) != NULL
)
1526 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1527 marker
->values
[0].integer
);
1528 for (i
= 1; i
< marker
->num_values
; i
++)
1529 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1530 cupsFilePuts(fp
, "\n");
1533 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1534 IPP_TAG_TEXT
)) != NULL
)
1536 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1537 marker
->values
[0].string
.text
);
1539 cupsFilePutConf(fp
, "Attribute", value
);
1542 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1543 IPP_TAG_NAME
)) != NULL
)
1545 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1547 for (i
= 0, ptr
= value
+ strlen(value
);
1548 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1554 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1555 value
+ sizeof(value
) - ptr
);
1560 cupsFilePutConf(fp
, "Attribute", value
);
1563 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1564 IPP_TAG_KEYWORD
)) != NULL
)
1566 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1568 for (i
= 0, ptr
= value
+ strlen(value
);
1569 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1575 strlcpy(ptr
, marker
->values
[i
].string
.text
,
1576 value
+ sizeof(value
) - ptr
);
1581 cupsFilePutConf(fp
, "Attribute", value
);
1584 if (printer
->marker_time
)
1585 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1586 (long)printer
->marker_time
);
1588 cupsFilePuts(fp
, "</Printer>\n");
1591 cupsdCloseCreatedConfFile(fp
, filename
);
1596 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1599 int /* O - 1 if value OK, 0 otherwise */
1600 cupsdSetAuthInfoRequired(
1601 cupsd_printer_t
*p
, /* I - Printer */
1602 const char *values
, /* I - Plain text value (or NULL) */
1603 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1605 int i
; /* Looping var */
1608 p
->num_auth_info_required
= 0;
1611 * Do we have a plain text value?
1617 * Yes, grab the keywords...
1620 const char *end
; /* End of current value */
1623 while (*values
&& p
->num_auth_info_required
< 4)
1625 if ((end
= strchr(values
, ',')) == NULL
)
1626 end
= values
+ strlen(values
);
1628 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1630 if (p
->num_auth_info_required
!= 0 || *end
)
1633 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1634 p
->num_auth_info_required
++;
1638 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1640 if (p
->num_auth_info_required
!= 0 || *end
)
1643 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1644 p
->num_auth_info_required
++;
1647 * Don't allow sharing of queues that require Kerberos authentication.
1652 cupsdDeregisterPrinter(p
, 1);
1656 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1658 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1659 p
->num_auth_info_required
++;
1661 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1663 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1664 p
->num_auth_info_required
++;
1666 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1668 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1669 p
->num_auth_info_required
++;
1674 values
= (*end
) ? end
+ 1 : end
;
1677 if (p
->num_auth_info_required
== 0)
1679 p
->auth_info_required
[0] = "none";
1680 p
->num_auth_info_required
= 1;
1684 * Update the printer-type value as needed...
1687 if (p
->num_auth_info_required
> 1 ||
1688 strcmp(p
->auth_info_required
[0], "none"))
1689 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1691 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
1697 * Grab values from an attribute instead...
1700 if (!attr
|| attr
->num_values
> 4)
1703 for (i
= 0; i
< attr
->num_values
; i
++)
1705 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1707 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1710 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1711 p
->num_auth_info_required
++;
1715 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1717 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1720 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1721 p
->num_auth_info_required
++;
1724 * Don't allow sharing of queues that require Kerberos authentication.
1729 cupsdDeregisterPrinter(p
, 1);
1735 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1737 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1738 p
->num_auth_info_required
++;
1740 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1742 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1743 p
->num_auth_info_required
++;
1745 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1748 p
->num_auth_info_required
++;
1759 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1763 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1764 const char *uri
) /* I - Device URI */
1766 char buffer
[1024], /* URI buffer */
1767 *start
, /* Start of data after scheme */
1768 *slash
, /* First slash after scheme:// */
1769 *ptr
; /* Pointer into user@host:port part */
1773 * Set the full device URI..
1776 cupsdSetString(&(p
->device_uri
), uri
);
1779 * Copy the device URI to a temporary buffer so we can sanitize any auth
1783 strlcpy(buffer
, uri
, sizeof(buffer
));
1786 * Find the end of the scheme:// part...
1789 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1791 for (start
= ptr
+ 1; *start
; start
++)
1796 * Find the next slash (/) in the URI...
1799 if ((slash
= strchr(start
, '/')) == NULL
)
1800 slash
= start
+ strlen(start
); /* No slash, point to the end */
1803 * Check for an @ sign before the slash...
1806 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1809 * Found an @ sign and it is before the resource part, so we have
1810 * an authentication string. Copy the remaining URI over the
1811 * authentication string...
1814 _cups_strcpy(start
, ptr
+ 1);
1819 * Save the sanitized URI...
1822 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1827 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1831 cupsdSetPrinterAttr(
1832 cupsd_printer_t
*p
, /* I - Printer */
1833 const char *name
, /* I - Attribute name */
1834 const char *value
) /* I - Attribute value string */
1836 ipp_attribute_t
*attr
; /* Attribute */
1837 int i
, /* Looping var */
1838 count
; /* Number of values */
1839 char *temp
, /* Temporary copy of value string */
1840 *ptr
, /* Pointer into value */
1841 *start
, /* Start of value */
1842 quote
; /* Quote character */
1843 ipp_tag_t value_tag
; /* Value tag for this attribute */
1847 * Don't allow empty values...
1850 if (!*value
&& strcmp(name
, "marker-message"))
1852 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1857 * Copy the value string so we can do what we want with it...
1860 if ((temp
= strdup(value
)) == NULL
)
1862 cupsdLogMessage(CUPSD_LOG_ERROR
,
1863 "Unable to duplicate value for \"%s\" attribute.", name
);
1868 * Count the number of values...
1871 for (count
= 1, quote
= '\0', ptr
= temp
;
1879 else if (*ptr
== '\\' && ptr
[1])
1881 else if (*ptr
== '\'' || *ptr
== '\"')
1883 else if (*ptr
== ',')
1888 * Then add or update the attribute as needed...
1891 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1892 !strcmp(name
, "marker-high-levels"))
1898 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1899 attr
->num_values
< count
)
1901 ippDeleteAttribute(p
->attrs
, attr
);
1906 attr
->num_values
= count
;
1908 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1913 cupsdLogMessage(CUPSD_LOG_ERROR
,
1914 "Unable to allocate memory for printer attribute "
1915 "(%d values)", count
);
1919 for (i
= 0, start
= temp
; i
< count
; i
++)
1921 if ((ptr
= strchr(start
, ',')) != NULL
)
1924 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
1933 * Name or keyword values...
1936 if (!strcmp(name
, "marker-types"))
1937 value_tag
= IPP_TAG_KEYWORD
;
1938 else if (!strcmp(name
, "marker-message"))
1939 value_tag
= IPP_TAG_TEXT
;
1941 value_tag
= IPP_TAG_NAME
;
1943 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
1944 attr
->num_values
< count
)
1946 ippDeleteAttribute(p
->attrs
, attr
);
1952 for (i
= 0; i
< attr
->num_values
; i
++)
1953 _cupsStrFree(attr
->values
[i
].string
.text
);
1955 attr
->num_values
= count
;
1958 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
1963 cupsdLogMessage(CUPSD_LOG_ERROR
,
1964 "Unable to allocate memory for printer attribute "
1965 "(%d values)", count
);
1969 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
1971 for (start
= ptr
; *ptr
; ptr
++)
1974 *ptr
= quote
= '\0';
1977 else if (*ptr
== '\\' && ptr
[1])
1978 _cups_strcpy(ptr
, ptr
+ 1);
1979 else if (*ptr
== '\'' || *ptr
== '\"')
1986 _cups_strcpy(ptr
, ptr
+ 1);
1988 else if (*ptr
== ',')
1995 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2004 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2008 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2010 int i
; /* Looping var */
2011 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2012 cupsd_location_t
*auth
; /* Pointer to authentication element */
2013 const char *auth_supported
; /* Authentication supported */
2014 ipp_t
*oldattrs
; /* Old printer attributes */
2015 ipp_attribute_t
*attr
; /* Attribute data */
2016 char *name
, /* Current user/group name */
2017 *filter
; /* Current filter */
2020 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2024 * Make sure that we have the common attributes defined...
2028 cupsdCreateCommonData();
2031 * Clear out old filters, if any...
2034 delete_printer_filters(p
);
2037 * Figure out the authentication that is required for the printer.
2040 auth_supported
= "requesting-user-name";
2042 if (p
->type
& CUPS_PRINTER_CLASS
)
2043 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2045 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2047 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2048 auth
->type
== CUPSD_AUTH_NONE
)
2049 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2053 int auth_type
; /* Authentication type */
2056 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2057 auth_type
= cupsdDefaultAuthType();
2059 if (auth_type
== CUPSD_AUTH_BASIC
|| auth_type
== CUPSD_AUTH_BASICDIGEST
)
2060 auth_supported
= "basic";
2061 else if (auth_type
== CUPSD_AUTH_DIGEST
)
2062 auth_supported
= "digest";
2064 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2065 auth_supported
= "negotiate";
2066 #endif /* HAVE_GSSAPI */
2068 if (auth_type
!= CUPSD_AUTH_NONE
)
2069 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2071 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2074 p
->type
&= ~CUPS_PRINTER_AUTHENTICATED
;
2077 * Create the required IPP attributes for a printer...
2080 oldattrs
= p
->attrs
;
2081 p
->attrs
= ippNew();
2083 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2084 "uri-authentication-supported", NULL
, auth_supported
);
2085 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2086 "uri-security-supported", NULL
, "none");
2087 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2089 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2090 NULL
, p
->location
? p
->location
: "");
2091 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2092 NULL
, p
->info
? p
->info
: "");
2093 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
,
2096 if (cupsArrayCount(p
->users
) > 0)
2099 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2100 "requesting-user-name-denied",
2101 cupsArrayCount(p
->users
), NULL
, NULL
);
2103 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2104 "requesting-user-name-allowed",
2105 cupsArrayCount(p
->users
), NULL
, NULL
);
2107 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2109 i
++, name
= (char *)cupsArrayNext(p
->users
))
2110 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2113 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2114 "job-quota-period", p
->quota_period
);
2115 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2116 "job-k-limit", p
->k_limit
);
2117 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2118 "job-page-limit", p
->page_limit
);
2119 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2120 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2121 "auth-info-required", p
->num_auth_info_required
, NULL
,
2122 p
->auth_info_required
);
2124 if (cupsArrayCount(Banners
) > 0)
2127 * Setup the job-sheets-default attribute...
2130 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2131 "job-sheets-default", 2, NULL
, NULL
);
2135 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2136 Classification
: p
->job_sheets
[0]);
2137 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2138 Classification
: p
->job_sheets
[1]);
2146 * Assign additional attributes depending on whether this is a printer
2150 if (p
->type
& CUPS_PRINTER_CLASS
)
2153 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
2156 * Add class-specific attributes...
2159 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2160 "printer-make-and-model", NULL
, "Local Printer Class");
2161 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2162 "file:///dev/null");
2164 if (p
->num_printers
> 0)
2167 * Add a list of member names; URIs are added in copy_printer_attrs...
2170 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2171 "member-names", p
->num_printers
, NULL
, NULL
);
2172 p
->type
|= CUPS_PRINTER_OPTIONS
;
2174 for (i
= 0; i
< p
->num_printers
; i
++)
2177 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2179 p
->type
&= ~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2186 * Add printer-specific attributes...
2189 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2190 p
->sanitized_device_uri
);
2193 * Assign additional attributes from the PPD file (if any)...
2199 * Add filters for printer...
2202 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2203 "cups-insecure-filter-warning");
2205 if (p
->pc
&& p
->pc
->filters
)
2207 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2209 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2210 add_printer_filter(p
, p
->filetype
, filter
);
2212 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2214 char interface
[1024]; /* Interface script */
2217 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2219 if (!access(interface
, X_OK
))
2222 * Yes, we have a System V style interface script; use it!
2225 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2226 ServerRoot
, p
->name
);
2227 add_printer_filter(p
, p
->filetype
, interface
);
2232 * Add a filter from application/vnd.cups-raw to printer/name to
2233 * handle "raw" printing by users.
2236 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2239 * Add a PostScript filter, since this is still possibly PS printer.
2242 add_printer_filter(p
, p
->filetype
,
2243 "application/vnd.cups-postscript 0 -");
2247 if (p
->pc
&& p
->pc
->prefilters
)
2249 if (!p
->prefiltertype
)
2250 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2252 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2254 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2255 add_printer_filter(p
, p
->prefiltertype
, filter
);
2260 * Copy marker attributes as needed...
2265 ipp_attribute_t
*oldattr
; /* Old attribute */
2268 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2269 IPP_TAG_NAME
)) != NULL
)
2271 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2272 "marker-colors", oldattr
->num_values
, NULL
,
2275 for (i
= 0; i
< oldattr
->num_values
; i
++)
2276 attr
->values
[i
].string
.text
=
2277 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2281 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2282 IPP_TAG_INTEGER
)) != NULL
)
2284 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2285 "marker-levels", oldattr
->num_values
,
2288 for (i
= 0; i
< oldattr
->num_values
; i
++)
2289 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2293 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2294 IPP_TAG_TEXT
)) != NULL
)
2295 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2296 NULL
, oldattr
->values
[0].string
.text
);
2298 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2299 IPP_TAG_INTEGER
)) != NULL
)
2301 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2302 "marker-low-levels", oldattr
->num_values
,
2305 for (i
= 0; i
< oldattr
->num_values
; i
++)
2306 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2310 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2311 IPP_TAG_INTEGER
)) != NULL
)
2313 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2314 "marker-high-levels", oldattr
->num_values
,
2317 for (i
= 0; i
< oldattr
->num_values
; i
++)
2318 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2322 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2323 IPP_TAG_NAME
)) != NULL
)
2325 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2326 "marker-names", oldattr
->num_values
, NULL
,
2329 for (i
= 0; i
< oldattr
->num_values
; i
++)
2330 attr
->values
[i
].string
.text
=
2331 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2335 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2336 IPP_TAG_KEYWORD
)) != NULL
)
2338 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2339 "marker-types", oldattr
->num_values
, NULL
,
2342 for (i
= 0; i
< oldattr
->num_values
; i
++)
2343 attr
->values
[i
].string
.text
=
2344 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2348 ippDelete(oldattrs
);
2352 * Force sharing off for remote queues...
2355 if (p
->type
& CUPS_PRINTER_REMOTE
)
2359 * Populate the document-format-supported attribute...
2362 add_printer_formats(p
);
2364 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2368 * Add name-default attributes...
2371 add_printer_defaults(p
);
2374 * Let the browse protocols reflect the change
2377 cupsdRegisterPrinter(p
);
2382 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2385 int /* O - 1 if something changed, 0 otherwise */
2386 cupsdSetPrinterReasons(
2387 cupsd_printer_t
*p
, /* I - Printer */
2388 const char *s
) /* I - Reasons strings */
2390 int i
, /* Looping var */
2391 changed
= 0; /* Did something change? */
2392 const char *sptr
; /* Pointer into reasons */
2393 char reason
[255], /* Reason string */
2394 *rptr
; /* Pointer into reason */
2397 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2398 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2400 if (s
[0] == '-' || s
[0] == '+')
2403 * Add/remove reasons...
2411 * Replace reasons...
2416 for (i
= 0; i
< p
->num_reasons
; i
++)
2417 _cupsStrFree(p
->reasons
[i
]);
2425 if (!strcmp(s
, "none"))
2429 * Loop through all of the reasons...
2435 * Skip leading whitespace and commas...
2438 while (isspace(*sptr
& 255) || *sptr
== ',')
2441 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2442 if (rptr
< (reason
+ sizeof(reason
) - 1))
2456 for (i
= 0; i
< p
->num_reasons
; i
++)
2457 if (!strcmp(reason
, p
->reasons
[i
]))
2460 * Found a match, so remove it...
2465 _cupsStrFree(p
->reasons
[i
]);
2467 if (i
< p
->num_reasons
)
2468 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1,
2469 (p
->num_reasons
- i
) * sizeof(char *));
2471 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2472 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2474 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2475 p
->job
->completed
= 0;
2477 if (strcmp(reason
, "connecting-to-device"))
2483 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2489 for (i
= 0; i
< p
->num_reasons
; i
++)
2490 if (!strcmp(reason
, p
->reasons
[i
]))
2493 if (i
>= p
->num_reasons
)
2495 if (!strncmp(reason
, "cups-ipp-missing-", 17) ||
2496 !strncmp(reason
, "cups-ipp-wrong-", 15))
2497 log_ipp_conformance(p
, reason
);
2499 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2501 cupsdLogMessage(CUPSD_LOG_ALERT
,
2502 "Too many printer-state-reasons values for %s (%d)",
2507 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2511 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2512 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2514 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2515 p
->job
->completed
= 1;
2517 if (strcmp(reason
, "connecting-to-device"))
2528 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2532 cupsdSetPrinterState(
2533 cupsd_printer_t
*p
, /* I - Printer to change */
2534 ipp_pstate_t s
, /* I - New state */
2535 int update
) /* I - Update printers.conf? */
2537 cupsd_job_t
*job
; /* Current job */
2538 ipp_pstate_t old_state
; /* Old printer state */
2539 static const char * const printer_states
[] =
2540 { /* State strings */
2548 * Set the new state...
2551 old_state
= p
->state
;
2556 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2557 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2558 "%s \"%s\" state changed to %s.",
2559 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2560 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2563 * Let the browse code know this needs to be updated...
2566 p
->state_time
= time(NULL
);
2570 * Set/clear the paused reason as needed...
2573 if (s
== IPP_PRINTER_STOPPED
)
2574 cupsdSetPrinterReasons(p
, "+paused");
2576 cupsdSetPrinterReasons(p
, "-paused");
2580 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2582 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2583 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2584 !_cups_strcasecmp(job
->dest
, p
->name
))
2585 ippSetString(job
->attrs
, &job
->reasons
, 0,
2586 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2590 * Clear the message for the queue when going to processing...
2593 if (s
== IPP_PRINTER_PROCESSING
)
2594 p
->state_message
[0] = '\0';
2597 * Let the browse protocols reflect the change...
2601 cupsdRegisterPrinter(p
);
2604 * Save the printer configuration if a printer goes from idle or processing
2605 * to stopped (or visa-versa)...
2609 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2615 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2619 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2620 int update
)/* I - Update printers.conf? */
2623 * Set the printer state...
2626 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2629 * See if we have a job printing on this printer...
2632 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2633 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2634 "Job stopped due to printer being paused.");
2639 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2642 int /* O - 1 if successful, 0 otherwise */
2643 cupsdUpdatePrinterPPD(
2644 cupsd_printer_t
*p
, /* I - Printer */
2645 int num_keywords
, /* I - Number of keywords */
2646 cups_option_t
*keywords
) /* I - Keywords */
2648 int i
; /* Looping var */
2649 cups_file_t
*src
, /* Original file */
2650 *dst
; /* New file */
2651 char srcfile
[1024], /* Original filename */
2652 dstfile
[1024], /* New filename */
2653 line
[1024], /* Line from file */
2654 keystring
[41]; /* Keyword from line */
2655 cups_option_t
*keyword
; /* Current keyword */
2658 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2662 * Get the old and new PPD filenames...
2665 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2666 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2669 * Rename the old file and open the old and new...
2672 if (rename(dstfile
, srcfile
))
2674 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2675 p
->name
, strerror(errno
));
2679 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2681 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2682 srcfile
, strerror(errno
));
2683 rename(srcfile
, dstfile
);
2687 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2689 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2690 dstfile
, strerror(errno
));
2692 rename(srcfile
, dstfile
);
2697 * Copy the first line and then write out all of the keywords...
2700 if (!cupsFileGets(src
, line
, sizeof(line
)))
2702 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2703 srcfile
, strerror(errno
));
2706 rename(srcfile
, dstfile
);
2710 cupsFilePrintf(dst
, "%s\n", line
);
2712 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2714 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2715 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2719 * Then copy the rest of the PPD file, dropping any keywords we changed.
2722 while (cupsFileGets(src
, line
, sizeof(line
)))
2725 * Skip keywords we've already set...
2728 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2729 cupsGetOption(keystring
, num_keywords
, keywords
))
2733 * Otherwise write the line...
2736 cupsFilePrintf(dst
, "%s\n", line
);
2740 * Close files and return...
2751 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2755 cupsdUpdatePrinters(void)
2757 cupsd_printer_t
*p
; /* Current printer */
2761 * Loop through the printers and recreate the printer attributes
2762 * for any local printers since the policy and/or access control
2763 * stuff may have changed. Also, if browsing is disabled, remove
2764 * any remote printers...
2767 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2769 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2772 * Update the operation policy pointer...
2775 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2776 p
->op_policy_ptr
= DefaultPolicyPtr
;
2779 * Update printer attributes...
2782 cupsdSetPrinterAttrs(p
);
2788 * 'cupsdValidateDest()' - Validate a printer/class destination.
2791 const char * /* O - Printer or class name */
2793 const char *uri
, /* I - Printer URI */
2794 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2795 cupsd_printer_t
**printer
) /* O - Printer pointer */
2797 cupsd_printer_t
*p
; /* Current printer */
2798 char localname
[1024],/* Localized hostname */
2799 *lptr
, /* Pointer into localized hostname */
2800 *sptr
, /* Pointer into server name */
2801 *rptr
, /* Pointer into resource */
2802 scheme
[32], /* Scheme portion of URI */
2803 username
[64], /* Username portion of URI */
2804 hostname
[HTTP_MAX_HOST
],
2805 /* Host portion of URI */
2806 resource
[HTTP_MAX_URI
];
2807 /* Resource portion of URI */
2808 int port
; /* Port portion of URI */
2811 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2815 * Initialize return values...
2822 *dtype
= (cups_ptype_t
)0;
2825 * Pull the hostname and resource from the URI...
2828 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2829 username
, sizeof(username
), hostname
, sizeof(hostname
),
2830 &port
, resource
, sizeof(resource
));
2833 * See if the resource is a class or printer...
2836 if (!strncmp(resource
, "/classes/", 9))
2842 rptr
= resource
+ 9;
2844 else if (!strncmp(resource
, "/printers/", 10))
2850 rptr
= resource
+ 10;
2855 * Bad resource name...
2862 * See if the printer or class name exists...
2865 p
= cupsdFindDest(rptr
);
2867 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2875 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2881 * Change localhost to the server name...
2884 if (!_cups_strcasecmp(hostname
, "localhost"))
2885 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2887 strlcpy(localname
, hostname
, sizeof(localname
));
2889 if (!_cups_strcasecmp(hostname
, ServerName
))
2892 * Localize the hostname...
2895 lptr
= strchr(localname
, '.');
2896 sptr
= strchr(ServerName
, '.');
2898 if (sptr
!= NULL
&& lptr
!= NULL
)
2901 * Strip the common domain name components...
2904 while (lptr
!= NULL
)
2906 if (!_cups_strcasecmp(lptr
, sptr
))
2912 lptr
= strchr(lptr
+ 1, '.');
2917 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
2920 * Find a matching printer or class...
2923 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2925 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2926 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
2927 !_cups_strcasecmp(p
->name
, rptr
))
2933 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2943 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2948 cupsdWritePrintcap(void)
2950 int i
; /* Looping var */
2951 cups_file_t
*fp
; /* Printcap file */
2952 cupsd_printer_t
*p
; /* Current printer */
2956 * See if we have a printcap file; if not, don't bother writing it.
2959 if (!Printcap
|| !*Printcap
)
2962 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
2965 * Open the printcap file...
2968 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
2972 * Put a comment header at the top so that users will know where the
2973 * data has come from...
2976 if (PrintcapFormat
!= PRINTCAP_PLIST
)
2977 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
2979 "# %s/printers.conf file. All changes to this file\n"
2980 "# will be lost.\n", ServerRoot
);
2983 * Write a new printcap with the current list of printers.
2986 switch (PrintcapFormat
)
2990 * Each printer is put in the file as:
3000 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3001 DefaultPrinter
->info
, ServerName
,
3002 DefaultPrinter
->name
);
3004 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3006 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3007 if (p
!= DefaultPrinter
)
3008 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3009 ServerName
, p
->name
);
3012 case PRINTCAP_PLIST
:
3014 * Each printer is written as a dictionary in a plist file.
3015 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3016 * printer-location, printer-make-and-model, printer-state,
3017 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3020 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3021 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3022 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3023 "PropertyList-1.0.dtd\">\n"
3024 "<plist version=\"1.0\">\n"
3027 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3029 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3031 cupsFilePuts(fp
, "\t<dict>\n"
3032 "\t\t<key>printer-name</key>\n"
3034 write_xml_string(fp
, p
->name
);
3035 cupsFilePuts(fp
, "</string>\n"
3036 "\t\t<key>printer-info</key>\n"
3038 write_xml_string(fp
, p
->info
);
3039 cupsFilePrintf(fp
, "</string>\n"
3040 "\t\t<key>printer-is-accepting-jobs</key>\n"
3042 "\t\t<key>printer-location</key>\n"
3043 "\t\t<string>", p
->accepting
? "true" : "false");
3044 write_xml_string(fp
, p
->location
);
3045 cupsFilePuts(fp
, "</string>\n"
3046 "\t\t<key>printer-make-and-model</key>\n"
3048 write_xml_string(fp
, p
->make_model
);
3049 cupsFilePrintf(fp
, "</string>\n"
3050 "\t\t<key>printer-state</key>\n"
3051 "\t\t<integer>%d</integer>\n"
3052 "\t\t<key>printer-state-reasons</key>\n"
3053 "\t\t<array>\n", p
->state
);
3054 for (i
= 0; i
< p
->num_reasons
; i
++)
3056 cupsFilePuts(fp
, "\t\t\t<string>");
3057 write_xml_string(fp
, p
->reasons
[i
]);
3058 cupsFilePuts(fp
, "</string>\n");
3060 cupsFilePrintf(fp
, "\t\t</array>\n"
3061 "\t\t<key>printer-type</key>\n"
3062 "\t\t<integer>%d</integer>\n"
3063 "\t\t<key>device-uri</key>\n"
3064 "\t\t<string>", p
->type
);
3065 write_xml_string(fp
, p
->sanitized_device_uri
);
3066 cupsFilePuts(fp
, "</string>\n"
3069 cupsFilePuts(fp
, "</array>\n"
3073 case PRINTCAP_SOLARIS
:
3075 * Each printer is put in the file as:
3077 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3078 * _default:use=DefaultPrinter
3080 * :bsdaddr=ServerName,Printer1:\
3081 * :description=Description:
3083 * :bsdaddr=ServerName,Printer2:\
3084 * :description=Description:
3086 * :bsdaddr=ServerName,Printer3:\
3087 * :description=Description:
3090 * :bsdaddr=ServerName,PrinterN:\
3091 * :description=Description:
3094 cupsFilePuts(fp
, "_all:all=");
3095 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3097 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3098 cupsFilePrintf(fp
, "%s%c", p
->name
,
3099 cupsArrayNext(Printers
) ? ',' : '\n');
3102 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3104 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3106 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3107 cupsFilePrintf(fp
, "%s:\\\n"
3108 "\t:bsdaddr=%s,%s:\\\n"
3109 "\t:description=%s:\n",
3110 p
->name
, ServerName
, p
->name
,
3111 p
->info
? p
->info
: "");
3124 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3128 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3130 int i
; /* Looping var */
3131 int num_options
; /* Number of default options */
3132 cups_option_t
*options
, /* Default options */
3133 *option
; /* Current option */
3134 char name
[256]; /* name-default */
3138 * Maintain a common array of default attribute names...
3141 if (!CommonDefaults
)
3143 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3145 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3146 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3147 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3148 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3149 cupsArrayAdd(CommonDefaults
,
3150 _cupsStrAlloc("job-accounting-user-id-default"));
3151 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3152 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3153 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3154 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3155 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3156 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3157 cupsArrayAdd(CommonDefaults
,
3158 _cupsStrAlloc("orientation-requested-default"));
3162 * Add all of the default options from the .conf files...
3165 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3169 if (strcmp(option
->name
, "ipp-options") &&
3170 strcmp(option
->name
, "job-sheets") &&
3171 strcmp(option
->name
, "lease-duration"))
3173 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3174 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3176 if (!cupsArrayFind(CommonDefaults
, name
))
3177 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3182 * Convert options to IPP attributes...
3185 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3186 cupsFreeOptions(num_options
, options
);
3189 * Add standard -default attributes as needed...
3192 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3193 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3196 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3197 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3198 "document-format-default", NULL
, "application/octet-stream");
3200 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3201 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3202 "job-cancel-after-default", MaxJobTime
);
3204 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3205 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3206 "job-hold-until-default", NULL
, "no-hold");
3208 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3209 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3210 "job-priority-default", 50);
3212 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3213 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3214 "number-up-default", 1);
3216 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3217 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3218 "notify-lease-duration-default", DefaultLeaseDuration
);
3220 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3221 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3222 "notify-events-default", NULL
, "job-completed");
3224 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3225 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3226 "orientation-requested-default", NULL
, NULL
);
3228 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3229 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3230 "print-quality-default", IPP_QUALITY_NORMAL
);
3235 * 'add_printer_filter()' - Add a MIME filter for a printer.
3240 cupsd_printer_t
*p
, /* I - Printer to add to */
3241 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3242 const char *filter
) /* I - Filter to add */
3244 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3245 type
[MIME_MAX_TYPE
], /* Type for filter */
3246 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3247 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3248 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3249 /* Destination super/type */
3250 program
[1024]; /* Program/filter name */
3251 int cost
; /* Cost of filter */
3252 size_t maxsize
= 0; /* Maximum supported file size */
3253 mime_type_t
*temptype
, /* MIME type looping var */
3254 *desttype
; /* Destination MIME type */
3255 mime_filter_t
*filterptr
; /* MIME filter */
3256 char filename
[1024]; /* Full filter filename */
3259 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3260 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3261 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3262 filtertype
->type
, filter
);
3265 * Parse the filter string; it should be in one of the following formats:
3267 * source/type cost program
3268 * source/type cost maxsize(nnnn) program
3269 * source/type dest/type cost program
3270 * source/type dest/type cost maxsize(nnnn) program
3273 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3274 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3276 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3278 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3280 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3282 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3284 cupsArrayAdd(p
->dest_types
, desttype
);
3290 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3293 desttype
= filtertype
;
3297 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3303 if (!strncmp(program
, "maxsize(", 8))
3305 char *ptr
; /* Pointer into maxsize(nnnn) program */
3307 maxsize
= strtoll(program
+ 8, &ptr
, 10);
3311 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3317 while (_cups_isspace(*ptr
))
3320 _cups_strcpy(program
, ptr
);
3324 * Check permissions on the filter and its containing directory...
3327 if (strcmp(program
, "-"))
3329 if (program
[0] == '/')
3330 strlcpy(filename
, program
, sizeof(filename
));
3332 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3334 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3335 cupsdLogFCMessage
, p
);
3339 * Add the filter to the MIME database, supporting wildcards as needed...
3342 for (temptype
= mimeFirstType(MimeDatabase
);
3344 temptype
= mimeNextType(MimeDatabase
))
3345 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3346 !_cups_strcasecmp(temptype
->super
, super
)) &&
3347 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3349 if (desttype
!= filtertype
)
3351 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3352 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3353 "%s", p
->name
, temptype
->super
, temptype
->type
,
3354 desttype
->super
, desttype
->type
,
3356 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3359 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3361 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3362 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3363 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3364 filtertype
->super
, filtertype
->type
);
3365 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3370 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3371 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3372 "%s", p
->name
, temptype
->super
, temptype
->type
,
3373 filtertype
->super
, filtertype
->type
,
3375 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3380 filterptr
->maxsize
= maxsize
;
3386 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3390 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3392 int i
; /* Looping var */
3393 mime_type_t
*type
; /* Current MIME type */
3394 cups_array_t
*filters
; /* Filters */
3395 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3396 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3397 /* MIME type name */
3401 * Raw (and remote) queues advertise all of the supported MIME
3405 cupsArrayDelete(p
->filetypes
);
3406 p
->filetypes
= NULL
;
3410 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3411 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3412 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3417 * Otherwise, loop through the supported MIME types and see if there
3418 * are filters for them...
3421 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3422 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3424 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3426 for (type
= mimeFirstType(MimeDatabase
);
3428 type
= mimeNextType(MimeDatabase
))
3430 if (!_cups_strcasecmp(type
->super
, "printer"))
3433 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3435 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3437 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3438 "add_printer_formats: %s: %s needs %d filters",
3439 p
->name
, mimetype
, cupsArrayCount(filters
));
3441 cupsArrayDelete(filters
);
3442 cupsArrayAdd(p
->filetypes
, type
);
3445 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3446 "add_printer_formats: %s: %s not supported",
3451 * Add the file formats that can be filtered...
3454 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3455 !cupsArrayFind(p
->filetypes
, type
))
3460 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3461 "add_printer_formats: %s: %d supported types",
3462 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3464 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3465 "document-format-supported",
3466 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3469 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3471 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3473 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3475 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3477 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3480 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3482 char pdl
[1024]; /* Buffer to build pdl list */
3483 mime_filter_t
*filter
; /* MIME filter looping var */
3487 * We only support raw printing if this is not a Tioga PrintJobMgr based
3488 * queue and if application/octet-stream is a known type...
3491 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3493 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3495 if (filter
->dst
== p
->filetype
&& filter
->filter
&&
3496 strstr(filter
->filter
, "PrintJobMgr"))
3502 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3503 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3506 * Then list a bunch of formats that are supported by the printer...
3509 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3511 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3513 if (!_cups_strcasecmp(type
->super
, "application"))
3515 if (!_cups_strcasecmp(type
->type
, "pdf"))
3516 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3517 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3518 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3520 else if (!_cups_strcasecmp(type
->super
, "image"))
3522 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3523 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3524 else if (!_cups_strcasecmp(type
->type
, "png"))
3525 strlcat(pdl
, "image/png,", sizeof(pdl
));
3526 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3527 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3532 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3534 cupsdSetString(&p
->pdl
, pdl
);
3536 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3541 * 'compare_printers()' - Compare two printers.
3544 static int /* O - Result of comparison */
3545 compare_printers(void *first
, /* I - First printer */
3546 void *second
, /* I - Second printer */
3547 void *data
) /* I - App data (not used) */
3551 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3552 ((cupsd_printer_t
*)second
)->name
));
3557 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3561 delete_printer_filters(
3562 cupsd_printer_t
*p
) /* I - Printer to remove from */
3564 mime_filter_t
*filter
; /* MIME filter looping var */
3565 mime_type_t
*type
; /* Destination types for filters */
3569 * Range check input...
3576 * Remove all filters from the MIME database that have a destination
3577 * type == printer...
3580 for (filter
= mimeFirstFilter(MimeDatabase
);
3582 filter
= mimeNextFilter(MimeDatabase
))
3583 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3584 cupsArrayFind(p
->dest_types
, filter
->dst
))
3587 * Delete the current filter...
3590 mimeDeleteFilter(MimeDatabase
, filter
);
3593 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3595 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3596 mimeDeleteType(MimeDatabase
, type
);
3598 cupsArrayDelete(p
->dest_types
);
3599 p
->dest_types
= NULL
;
3601 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3602 ",cups-missing-filter-warning");
3607 * 'dirty_printer()' - Mark config and state files dirty for the specified
3612 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3614 if (p
->type
& CUPS_PRINTER_CLASS
)
3615 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3617 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3619 if (PrintcapFormat
== PRINTCAP_PLIST
)
3620 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3625 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3629 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3631 int i
, j
, k
; /* Looping vars */
3632 char cache_name
[1024]; /* Cache filename */
3633 struct stat cache_info
; /* Cache file info */
3634 ppd_file_t
*ppd
; /* PPD file */
3635 char ppd_name
[1024]; /* PPD filename */
3636 struct stat ppd_info
; /* PPD file info */
3637 int num_media
; /* Number of media options */
3638 ppd_size_t
*size
; /* Current PPD size */
3639 ppd_option_t
*duplex
, /* Duplex option */
3640 *output_bin
, /* OutputBin option */
3641 *output_mode
, /* OutputMode option */
3642 *resolution
; /* (Set|JCL|)Resolution option */
3643 ppd_choice_t
*choice
, /* Current PPD choice */
3644 *input_slot
, /* Current input slot */
3645 *media_type
; /* Current media type */
3646 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3647 int xdpi
, /* Horizontal resolution */
3648 ydpi
; /* Vertical resolution */
3649 const char *resptr
; /* Pointer into resolution keyword */
3650 _pwg_size_t
*pwgsize
; /* Current PWG size */
3651 _pwg_map_t
*pwgsource
, /* Current PWG source */
3652 *pwgtype
; /* Current PWG type */
3653 ipp_attribute_t
*attr
; /* Attribute data */
3654 _ipp_value_t
*val
; /* Attribute value */
3655 int num_finishings
, /* Number of finishings */
3656 finishings
[5]; /* finishings-supported values */
3657 int num_qualities
, /* Number of print-quality values */
3658 qualities
[3]; /* print-quality values */
3659 int num_margins
, /* Number of media-*-margin-supported values */
3660 margins
[16]; /* media-*-margin-supported values */
3661 const char *filter
, /* Current filter */
3662 *mandatory
; /* Current mandatory attribute */
3663 static const char * const sides
[3] = /* sides-supported values */
3666 "two-sided-long-edge",
3667 "two-sided-short-edge"
3669 static const char * const standard_commands
[] =
3670 { /* Standard CUPS commands */
3678 * Check to see if the cache is up-to-date...
3681 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3682 if (stat(cache_name
, &cache_info
))
3683 cache_info
.st_mtime
= 0;
3685 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3686 if (stat(ppd_name
, &ppd_info
))
3687 ppd_info
.st_mtime
= 1;
3689 ippDelete(p
->ppd_attrs
);
3690 p
->ppd_attrs
= NULL
;
3692 _ppdCacheDestroy(p
->pc
);
3695 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3697 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3699 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3703 * Loaded successfully!
3711 * Reload PPD attributes from disk...
3714 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3716 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3718 p
->type
&= ~CUPS_PRINTER_OPTIONS
;
3719 p
->type
|= CUPS_PRINTER_BW
;
3721 finishings
[0] = IPP_FINISHINGS_NONE
;
3724 p
->ppd_attrs
= ippNew();
3726 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3729 * Add make/model and other various attributes...
3732 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3735 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3736 ppd_name
, cupsLastErrorString());
3738 ppdMarkDefaults(ppd
);
3740 if (ppd
->color_device
)
3741 p
->type
|= CUPS_PRINTER_COLOR
;
3742 if (ppd
->variable_sizes
)
3743 p
->type
|= CUPS_PRINTER_VARIABLE
;
3744 if (!ppd
->manual_copies
)
3745 p
->type
|= CUPS_PRINTER_COPIES
;
3746 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3747 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3748 p
->type
|= CUPS_PRINTER_FAX
;
3750 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported",
3753 if (p
->pc
&& p
->pc
->charge_info_uri
)
3754 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3755 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3757 if (p
->pc
&& p
->pc
->account_id
)
3758 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3761 if (p
->pc
&& p
->pc
->accounting_user_id
)
3762 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3763 "job-accounting-user-id-supported", 1);
3765 if (p
->pc
&& p
->pc
->password
)
3767 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3768 "job-password-encryption-supported", NULL
, "none");
3769 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3770 "job-password-supported", strlen(p
->pc
->password
));
3773 if (ppd
->throughput
)
3775 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3776 "pages-per-minute", ppd
->throughput
);
3777 if (ppd
->color_device
)
3778 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3779 "pages-per-minute-color", ppd
->throughput
);
3784 * When there is no speed information, just say "1 page per minute".
3787 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3788 "pages-per-minute", 1);
3789 if (ppd
->color_device
)
3790 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3791 "pages-per-minute-color", 1);
3796 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3798 if (ppdFindChoice(output_mode
, "draft") ||
3799 ppdFindChoice(output_mode
, "fast"))
3800 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3802 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3804 if (ppdFindChoice(output_mode
, "best") ||
3805 ppdFindChoice(output_mode
, "high"))
3806 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3808 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3812 if (strstr(ppd_attr
->spec
, "draft") ||
3813 strstr(ppd_attr
->spec
, "Draft"))
3815 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3819 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3822 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3823 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3826 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3828 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3829 "print-quality-supported", num_qualities
, qualities
);
3834 * The NickName can be localized in the character set specified
3835 * by the LanugageEncoding attribute. However, ppdOpen2() has
3836 * already converted the ppd->nickname member to UTF-8 for us
3837 * (the original attribute value is available separately)
3840 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3842 else if (ppd
->modelname
)
3845 * Model name can only contain specific characters...
3848 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3851 cupsdSetString(&p
->make_model
, "Bad PPD File");
3853 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3854 "printer-make-and-model", NULL
, p
->make_model
);
3857 * Add media options from the PPD file...
3860 if (ppd
->num_sizes
== 0 || !p
->pc
)
3862 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3863 cupsdLogMessage(CUPSD_LOG_CRIT
,
3864 "The PPD file for printer %s contains no media "
3865 "options and is therefore invalid!", p
->name
);
3867 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3868 "media-default", NULL
, "unknown");
3869 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3870 "media-supported", NULL
, "unknown");
3878 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3879 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3883 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3884 "media-default", NULL
,
3885 pwgsize
? pwgsize
->map
.pwg
: "unknown");
3893 ipp_t
*col
; /* Collection value */
3895 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
3896 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
3897 col
= new_media_col(pwgsize
,
3899 _ppdCacheGetSource(p
->pc
,
3900 input_slot
->choice
) :
3903 _ppdCacheGetType(p
->pc
,
3904 media_type
->choice
) :
3907 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
3916 num_media
= p
->pc
->num_sizes
;
3917 if (p
->pc
->custom_min_keyword
)
3920 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3921 "media-supported", num_media
, NULL
,
3926 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3928 i
--, pwgsize
++, val
++)
3929 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
3931 if (p
->pc
->custom_min_keyword
)
3933 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
3935 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
3940 * media-size-supported
3943 num_media
= p
->pc
->num_sizes
;
3944 if (p
->pc
->custom_min_keyword
)
3947 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3948 "media-size-supported", num_media
,
3953 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
3955 i
--, pwgsize
++, val
++)
3957 val
->collection
= ippNew();
3958 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3959 "x-dimension", pwgsize
->width
);
3960 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3961 "y-dimension", pwgsize
->length
);
3964 if (p
->pc
->custom_min_keyword
)
3966 val
->collection
= ippNew();
3967 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
3968 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
3969 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
3970 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
3975 * media-source-supported
3978 if (p
->pc
->num_sources
> 0 &&
3979 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3980 "media-source-supported", p
->pc
->num_sources
,
3981 NULL
, NULL
)) != NULL
)
3983 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
3986 i
--, pwgsource
++, val
++)
3987 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
3991 * media-type-supported
3994 if (p
->pc
->num_types
> 0 &&
3995 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3996 "media-type-supported", p
->pc
->num_types
,
3997 NULL
, NULL
)) != NULL
)
3999 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4002 i
--, pwgtype
++, val
++)
4003 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4007 * media-*-margin-supported
4010 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4011 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4014 for (j
= 0; j
< num_margins
; j
++)
4015 if (pwgsize
->bottom
== margins
[j
])
4018 if (j
>= num_margins
)
4020 margins
[num_margins
] = pwgsize
->bottom
;
4025 if (num_margins
> 0)
4026 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4027 "media-bottom-margin-supported", num_margins
, margins
);
4029 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4030 "media-bottom-margin-supported", 0);
4032 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4033 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4036 for (j
= 0; j
< num_margins
; j
++)
4037 if (pwgsize
->left
== margins
[j
])
4040 if (j
>= num_margins
)
4042 margins
[num_margins
] = pwgsize
->left
;
4047 if (num_margins
> 0)
4048 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4049 "media-left-margin-supported", num_margins
, margins
);
4051 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4052 "media-left-margin-supported", 0);
4054 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4055 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4058 for (j
= 0; j
< num_margins
; j
++)
4059 if (pwgsize
->right
== margins
[j
])
4062 if (j
>= num_margins
)
4064 margins
[num_margins
] = pwgsize
->right
;
4069 if (num_margins
> 0)
4070 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4071 "media-right-margin-supported", num_margins
, margins
);
4073 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4074 "media-right-margin-supported", 0);
4076 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4077 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4080 for (j
= 0; j
< num_margins
; j
++)
4081 if (pwgsize
->top
== margins
[j
])
4084 if (j
>= num_margins
)
4086 margins
[num_margins
] = pwgsize
->top
;
4091 if (num_margins
> 0)
4092 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4093 "media-top-margin-supported", num_margins
, margins
);
4095 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4096 "media-top-margin-supported", 0);
4099 * media-col-database
4102 num_media
= p
->pc
->num_sizes
;
4103 if (p
->pc
->num_sources
)
4105 if (p
->pc
->num_types
> 0)
4106 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4109 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4111 else if (p
->pc
->num_types
)
4112 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4114 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4115 "media-col-database", num_media
,
4118 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4123 * Start by adding the page size without source or type...
4126 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4128 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4132 * Then add the specific, supported combinations of size, source, and
4136 if (p
->pc
->num_sources
> 0)
4138 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4142 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4144 if (p
->pc
->num_types
> 0)
4146 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4150 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4152 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4158 else if (!ppdConflicts(ppd
))
4160 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4165 else if (p
->pc
->num_types
> 0)
4167 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4171 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4173 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4181 * Update the number of media-col-database values...
4184 attr
->num_values
= val
- attr
->values
;
4192 if (p
->pc
&& p
->pc
->num_bins
> 0)
4194 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4195 "output-bin-supported", p
->pc
->num_bins
,
4200 for (i
= 0, val
= attr
->values
;
4201 i
< p
->pc
->num_bins
;
4203 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4206 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4208 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4209 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4212 if (i
>= p
->pc
->num_bins
)
4215 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4216 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4219 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4220 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4222 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4224 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4225 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4226 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4227 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4230 * Report that this printer has a single output bin that leaves pages face
4234 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4235 "output-bin-supported", NULL
, "face-up");
4236 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4237 "output-bin-default", NULL
, "face-up");
4241 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4242 "output-bin-supported", NULL
, "face-down");
4243 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4244 "output-bin-default", NULL
, "face-down");
4248 * print-color-mode...
4251 if (ppd
->color_device
)
4253 static const char * const color_modes
[] =
4259 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4260 "print-color-mode-supported", 2, NULL
, color_modes
);
4261 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4262 "print-color-mode-default", NULL
, "color");
4266 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4267 "print-color-mode-supported", NULL
, "monochrome");
4268 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4269 "print-color-mode-default", NULL
, "monochrome");
4273 * Mandatory job attributes, if any...
4276 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4278 int count
= cupsArrayCount(p
->pc
->mandatory
);
4279 /* Number of mandatory attributes */
4281 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4282 "printer-mandatory-job-attributes", count
, NULL
,
4285 for (val
= attr
->values
,
4286 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4288 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4289 val
->string
.text
= _cupsStrAlloc(mandatory
);
4293 * Printer resolutions...
4296 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4297 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4298 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4299 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4304 * Report all supported resolutions...
4307 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4308 "printer-resolution-supported",
4309 resolution
->num_choices
, IPP_RES_PER_INCH
,
4312 for (i
= 0, choice
= resolution
->choices
;
4313 i
< resolution
->num_choices
;
4316 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4317 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4318 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4320 if (xdpi
<= 0 || ydpi
<= 0)
4322 cupsdLogMessage(CUPSD_LOG_WARN
,
4323 "Bad resolution \"%s\" for printer %s.",
4324 choice
->choice
, p
->name
);
4328 attr
->values
[i
].resolution
.xres
= xdpi
;
4329 attr
->values
[i
].resolution
.yres
= ydpi
;
4330 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4333 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4334 "printer-resolution-default", IPP_RES_PER_INCH
,
4338 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4342 * Just the DefaultResolution to report...
4345 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4346 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4349 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4354 if (xdpi
<= 0 || ydpi
<= 0)
4356 cupsdLogMessage(CUPSD_LOG_WARN
,
4357 "Bad default resolution \"%s\" for printer %s.",
4358 ppd_attr
->value
, p
->name
);
4362 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4363 "printer-resolution-default", IPP_RES_PER_INCH
,
4365 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4366 "printer-resolution-supported", IPP_RES_PER_INCH
,
4372 * No resolutions in PPD - make one up...
4375 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4376 "printer-resolution-default", IPP_RES_PER_INCH
,
4378 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4379 "printer-resolution-supported", IPP_RES_PER_INCH
,
4387 ppdMarkDefaults(ppd
);
4389 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4390 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4391 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4392 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4393 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4395 if (duplex
&& duplex
->num_choices
> 1 &&
4396 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4398 p
->type
|= CUPS_PRINTER_DUPLEX
;
4400 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4401 "sides-supported", 3, NULL
, sides
);
4403 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4404 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4405 "sides-default", NULL
, "two-sided-short-edge");
4406 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4407 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4408 "sides-default", NULL
, "two-sided-long-edge");
4410 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4411 "sides-default", NULL
, "one-sided");
4415 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4416 "sides-supported", NULL
, "one-sided");
4417 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4418 "sides-default", NULL
, "one-sided");
4421 if (ppdFindOption(ppd
, "Collate") != NULL
)
4422 p
->type
|= CUPS_PRINTER_COLLATE
;
4424 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4426 p
->type
|= CUPS_PRINTER_STAPLE
;
4427 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4430 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4432 p
->type
|= CUPS_PRINTER_BIND
;
4433 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4436 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4437 if (ppd
->sizes
[i
].length
> 1728)
4438 p
->type
|= CUPS_PRINTER_LARGE
;
4439 else if (ppd
->sizes
[i
].length
> 1008)
4440 p
->type
|= CUPS_PRINTER_MEDIUM
;
4442 p
->type
|= CUPS_PRINTER_SMALL
;
4444 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4445 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4447 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4448 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4449 p
->type
|= CUPS_PRINTER_SCANNER
;
4451 p
->type
|= CUPS_PRINTER_MFP
;
4455 * Scan the filters in the PPD file...
4460 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4462 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4464 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4465 _cups_isspace(filter
[28]))
4467 p
->type
|= CUPS_PRINTER_COMMANDS
;
4473 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4475 char *commands
, /* Copy of commands */
4476 *start
, /* Start of name */
4477 *end
; /* End of name */
4478 int count
; /* Number of commands */
4480 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4482 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4484 while (_cups_isspace(*start
))
4490 while (*start
&& !isspace(*start
& 255))
4500 * Make a copy of the commands string and count how many commands there
4504 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4505 "printer-commands", count
, NULL
, NULL
);
4507 commands
= strdup(ppd_attr
->value
);
4509 for (count
= 0, start
= commands
; *start
; count
++)
4511 while (isspace(*start
& 255))
4518 while (*end
&& !isspace(*end
& 255))
4524 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4534 * Add the standard list of commands...
4537 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4539 (int)(sizeof(standard_commands
) /
4540 sizeof(standard_commands
[0])), NULL
,
4547 * No commands supported...
4550 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4551 "printer-commands", NULL
, "none");
4555 * Show current and available port monitors for this printer...
4558 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4559 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4561 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4563 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4567 if (strstr(ppd
->protocols
, "TBCP"))
4569 else if (strstr(ppd
->protocols
, "BCP"))
4573 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4574 "port-monitor-supported", i
, NULL
, NULL
);
4576 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4578 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4580 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4581 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4585 if (strstr(ppd
->protocols
, "TBCP"))
4586 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4587 else if (strstr(ppd
->protocols
, "BCP"))
4588 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4591 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4592 p
->type
|= CUPS_PRINTER_REMOTE
;
4594 #ifdef HAVE_APPLICATIONSERVICES_H
4596 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4597 * and save it as cacheDir/printername.png
4600 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4602 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4603 cupsdLogFCMessage
, p
))
4605 CGImageRef imageRef
= NULL
;/* Current icon image */
4606 CGImageRef biggestIconRef
= NULL
;
4607 /* Biggest icon image */
4608 CGImageRef closestTo128IconRef
= NULL
;
4609 /* Icon image closest to and >= 128 */
4610 CGImageSourceRef sourceRef
; /* The file's image source */
4611 char outPath
[HTTP_MAX_URI
];
4612 /* The path to the PNG file */
4613 CFURLRef outUrl
; /* The URL made from the outPath */
4614 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4615 CGImageDestinationRef destRef
; /* The image destination to write */
4616 size_t bytesPerRow
; /* The bytes per row used for resizing */
4617 CGContextRef context
; /* The CG context used for resizing */
4619 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4620 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4624 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
,
4625 (UInt8
*)ppd_attr
->value
,
4626 strlen(ppd_attr
->value
),
4628 if (outUrl
&& icnsFileUrl
)
4630 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4633 for (i
= 0; i
< CGImageSourceGetCount(sourceRef
); i
++)
4635 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, i
, NULL
);
4639 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4642 * Loop through remembering the icon closest to 128 but >= 128
4643 * and then remember the largest icon.
4646 if (CGImageGetWidth(imageRef
) >= 128 &&
4647 (!closestTo128IconRef
||
4648 CGImageGetWidth(imageRef
) <
4649 CGImageGetWidth(closestTo128IconRef
)))
4651 CGImageRelease(closestTo128IconRef
);
4652 CGImageRetain(imageRef
);
4653 closestTo128IconRef
= imageRef
;
4656 if (!biggestIconRef
||
4657 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4659 CGImageRelease(biggestIconRef
);
4660 CGImageRetain(imageRef
);
4661 biggestIconRef
= imageRef
;
4665 CGImageRelease(imageRef
);
4671 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4672 * want the closest to 128, but if none are larger than 128, we want
4673 * the largest icon available.
4676 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4678 CGImageRetain(imageRef
);
4679 CGImageRelease(biggestIconRef
);
4680 if (closestTo128IconRef
)
4681 CGImageRelease(closestTo128IconRef
);
4682 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4686 if (CGImageGetWidth(imageRef
) != 128)
4688 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4689 CGImageGetWidth(imageRef
) * 128;
4690 context
= CGBitmapContextCreate(NULL
, 128, 128,
4691 CGImageGetBitsPerComponent(imageRef
),
4693 CGImageGetColorSpace(imageRef
),
4694 kCGImageAlphaPremultipliedFirst
);
4697 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4699 CGImageRelease(imageRef
);
4700 imageRef
= CGBitmapContextCreateImage(context
);
4701 CGContextRelease(context
);
4705 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4706 CGImageDestinationFinalize(destRef
);
4710 CGImageRelease(imageRef
);
4713 CFRelease(sourceRef
);
4721 CFRelease(icnsFileUrl
);
4723 #endif /* HAVE_APPLICATIONSERVICES_H */
4726 * Close the PPD and set the type...
4731 else if (!access(ppd_name
, 0))
4733 int pline
; /* PPD line number */
4734 ppd_status_t pstatus
; /* PPD load status */
4737 pstatus
= ppdLastError(&pline
);
4739 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded!",
4742 if (pstatus
<= PPD_ALLOC_ERROR
)
4743 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s", strerror(errno
));
4745 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d.",
4746 ppdErrorString(pstatus
), pline
);
4748 cupsdLogMessage(CUPSD_LOG_INFO
,
4749 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4755 * If we have an interface script, add a filter entry for it...
4758 char interface
[1024]; /* Interface script */
4761 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4763 if (!access(interface
, X_OK
))
4766 * Yes, we have a System V style interface script; use it!
4769 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4770 "printer-make-and-model", NULL
,
4771 "Local System V Printer");
4773 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4774 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4775 (strstr(p
->device_uri
, "/printers/") != NULL
||
4776 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4777 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4778 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4779 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4782 * Tell the client this is really a hard-wired remote printer.
4785 p
->type
|= CUPS_PRINTER_REMOTE
;
4788 * Point the printer-uri-supported attribute to the
4792 if (strchr(p
->device_uri
, '?'))
4795 * Strip trailing "?options" from URI...
4798 char resource
[HTTP_MAX_URI
], /* New URI */
4799 *ptr
; /* Pointer into URI */
4801 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4802 if ((ptr
= strchr(resource
, '?')) != NULL
)
4805 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4806 "printer-uri-supported", NULL
, resource
);
4809 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4810 "printer-uri-supported", NULL
, p
->device_uri
);
4813 * Then set the make-and-model accordingly...
4816 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4817 "printer-make-and-model", NULL
, "Remote Printer");
4820 * Print all files directly...
4829 * Otherwise we have neither - treat this as a "dumb" printer
4830 * with no PPD file...
4833 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4834 "printer-make-and-model", NULL
, "Local Raw Printer");
4840 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4841 "finishings-supported", num_finishings
, finishings
);
4842 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4843 "finishings-default", IPP_FINISHINGS_NONE
);
4848 * Save cached PPD attributes to disk...
4851 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4853 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4858 * Remove cache files...
4861 if (cache_info
.st_mtime
)
4868 * 'log_ipp_conformance()' - Log an IPP conformance issue with a printer.
4872 log_ipp_conformance(
4873 cupsd_printer_t
*p
, /* I - Printer */
4874 const char *reason
) /* I - Printer state reason */
4876 const char *message
; /* Message to log */
4878 aslmsg aslm
; /* Apple System Log message */
4879 #endif /* __APPLE__ */
4883 * Strip the leading "cups-ipp-" from the reason and create a log message for
4888 if (!strcmp(reason
, "missing-cancel-job"))
4889 message
= "Printer does not support REQUIRED Cancel-Job operation.";
4890 else if (!strcmp(reason
, "missing-get-job-attributes"))
4891 message
= "Printer does not support REQUIRED Get-Job-Attributes operation.";
4892 else if (!strcmp(reason
, "missing-print-job"))
4893 message
= "Printer does not support REQUIRED Print-Job operation.";
4894 else if (!strcmp(reason
, "missing-validate-job"))
4895 message
= "Printer does not support REQUIRED Validate-Job operation.";
4896 else if (!strcmp(reason
, "missing-get-printer-attributes"))
4897 message
= "Printer does not support REQUIRED Get-Printer-Attributes operation.";
4898 else if (!strcmp(reason
, "missing-send-document"))
4899 message
= "Printer supports Create-Job but not Send-Document operation.";
4900 else if (!strcmp(reason
, "missing-job-history"))
4901 message
= "Printer does not provide REQUIRED job history.";
4902 else if (!strcmp(reason
, "missing-job-id"))
4903 message
= "Printer does not provide REQUIRED job-id attribute.";
4904 else if (!strcmp(reason
, "missing-job-state"))
4905 message
= "Printer does not provide REQUIRED job-state attribute.";
4906 else if (!strcmp(reason
, "missing-operations-supported"))
4907 message
= "Printer does not provide REQUIRED operations-supported "
4909 else if (!strcmp(reason
, "missing-printer-is-accepting-jobs"))
4910 message
= "Printer does not provide REQUIRED printer-is-accepting-jobs "
4912 else if (!strcmp(reason
, "missing-printer-state-reasons"))
4913 message
= "Printer does not provide REQUIRED printer-state-reasons "
4915 else if (!strcmp(reason
, "wrong-http-version"))
4916 message
= "Printer does not use REQUIRED HTTP/1.1 transport.";
4918 message
= "Unknown IPP conformance failure.";
4920 cupsdLogMessage(CUPSD_LOG_WARN
, "%s: %s", p
->name
, message
);
4924 * Report the failure information to Apple if the user opts into providing
4925 * feedback to Apple...
4928 aslm
= asl_new(ASL_TYPE_MSG
);
4931 asl_set(aslm
, "com.apple.message.domain", "com.apple.printing.ipp.conformance");
4932 asl_set(aslm
, "com.apple.message.domain_scope", "com.apple.printing.ipp.conformance");
4933 asl_set(aslm
, "com.apple.message.signature", reason
);
4934 asl_set(aslm
, "com.apple.message.signature2",
4935 p
->make_model
? p
->make_model
: "Unknown");
4936 asl_log(NULL
, aslm
, ASL_LEVEL_NOTICE
, "%s: %s",
4937 p
->make_model
? p
->make_model
: "Unknown", message
);
4940 #endif /* __APPLE__ */
4945 * 'new_media_col()' - Create a media-col collection value.
4948 static ipp_t
* /* O - Collection value */
4949 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4950 const char *source
, /* I - media-source value */
4951 const char *type
) /* I - media-type value */
4953 ipp_t
*media_col
, /* Collection value */
4954 *media_size
; /* media-size value */
4957 media_col
= ippNew();
4959 media_size
= ippNew();
4960 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4961 "x-dimension", size
->width
);
4962 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4963 "y-dimension", size
->length
);
4964 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4965 ippDelete(media_size
);
4967 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4968 "media-bottom-margin", size
->bottom
);
4969 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4970 "media-left-margin", size
->left
);
4971 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4972 "media-right-margin", size
->right
);
4973 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4974 "media-top-margin", size
->top
);
4977 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4981 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
4989 * 'write_xml_string()' - Write a string with XML escaping.
4993 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
4994 const char *s
) /* I - String to write */
4996 const char *start
; /* Start of current sequence */
5002 for (start
= s
; *s
; s
++)
5007 cupsFileWrite(fp
, start
, s
- start
);
5009 cupsFilePuts(fp
, "&");
5015 cupsFileWrite(fp
, start
, s
- start
);
5017 cupsFilePuts(fp
, "<");
5023 cupsFilePuts(fp
, start
);