2 * Printer routines for the CUPS scheduler.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
17 #ifdef HAVE_APPLICATIONSERVICES_H
18 # include <ApplicationServices/ApplicationServices.h>
19 #endif /* HAVE_APPLICATIONSERVICES_H */
20 #ifdef HAVE_SYS_MOUNT_H
21 # include <sys/mount.h>
22 #endif /* HAVE_SYS_MOUNT_H */
23 #ifdef HAVE_SYS_STATVFS_H
24 # include <sys/statvfs.h>
25 #elif defined(HAVE_SYS_STATFS_H)
26 # include <sys/statfs.h>
27 #endif /* HAVE_SYS_STATVFS_H */
30 #endif /* HAVE_SYS_VFS_H */
33 #endif /* __APPLE__ */
40 static void add_printer_defaults(cupsd_printer_t
*p
);
41 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
43 static void add_printer_formats(cupsd_printer_t
*p
);
44 static int compare_printers(void *first
, void *second
, void *data
);
45 static void delete_printer_filters(cupsd_printer_t
*p
);
46 static void dirty_printer(cupsd_printer_t
*p
);
47 static void load_ppd(cupsd_printer_t
*p
);
48 static ipp_t
*new_media_col(pwg_size_t
*size
, const char *source
,
50 static void write_xml_string(cups_file_t
*fp
, const char *s
);
54 * 'cupsdAddPrinter()' - Add a printer to the system.
57 cupsd_printer_t
* /* O - New printer */
58 cupsdAddPrinter(const char *name
) /* I - Name of printer */
60 cupsd_printer_t
*p
; /* New printer */
61 char uri
[1024], /* Printer URI */
62 uuid
[64]; /* Printer UUID */
66 * Range check input...
69 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
72 * Create a new printer entity...
75 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
77 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
82 _cupsRWInit(&p
->lock
);
84 cupsdSetString(&p
->name
, name
);
85 cupsdSetString(&p
->info
, name
);
86 cupsdSetString(&p
->hostname
, ServerName
);
88 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
89 ServerName
, RemotePort
, "/printers/%s", name
);
90 cupsdSetString(&p
->uri
, uri
);
91 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
93 cupsdSetDeviceURI(p
, "file:///dev/null");
95 p
->config_time
= time(NULL
);
96 p
->state
= IPP_PRINTER_STOPPED
;
97 p
->state_time
= time(NULL
);
99 p
->shared
= DefaultShared
;
100 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
102 cupsdSetString(&p
->job_sheets
[0], "none");
103 cupsdSetString(&p
->job_sheets
[1], "none");
105 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
106 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
108 p
->op_policy_ptr
= DefaultPolicyPtr
;
111 * Insert the printer in the printer list alphabetically...
115 Printers
= cupsArrayNew(compare_printers
, NULL
);
117 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
118 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
119 cupsArrayAdd(Printers
, p
);
122 * Return the new printer...
130 * 'cupsdCreateCommonData()' - Create the common printer data.
134 cupsdCreateCommonData(void)
136 int i
; /* Looping var */
137 ipp_attribute_t
*attr
; /* Attribute data */
138 cups_dir_t
*dir
; /* Notifier directory */
139 cups_dentry_t
*dent
; /* Notifier directory entry */
140 cups_array_t
*notifiers
; /* Notifier array */
141 char filename
[1024], /* Filename */
142 *notifier
; /* Current notifier */
143 cupsd_policy_t
*p
; /* Current policy */
144 int k_supported
; /* Maximum file size supported */
146 struct statvfs spoolinfo
; /* FS info for spool directory */
147 double spoolsize
; /* FS size */
148 #elif defined(HAVE_STATFS)
149 struct statfs spoolinfo
; /* FS info for spool directory */
150 double spoolsize
; /* FS size */
151 #endif /* HAVE_STATVFS */
152 static const char * const page_delivery
[] =
153 { /* page-delivery-supported values */
157 static const char * const print_scaling
[] =
158 { /* print-scaling-supported values */
165 static const int number_up
[] = /* number-up-supported values */
166 { 1, 2, 4, 6, 9, 16 };
167 static const char * const number_up_layout
[] =
168 { /* number-up-layout-supported values */
178 static const int orients
[4] =/* orientation-requested-supported values */
182 IPP_REVERSE_LANDSCAPE
,
185 static const char * const holds
[] = /* job-hold-until-supported values */
196 static const char * const features
[] =/* ipp-features-supported values */
198 "subscription-object"
200 static const char * const versions
[] =/* ipp-versions-supported values */
207 static const int ops
[] = /* operations-supported values */
212 IPP_OP_SEND_DOCUMENT
,
214 IPP_OP_GET_JOB_ATTRIBUTES
,
216 IPP_OP_GET_PRINTER_ATTRIBUTES
,
219 IPP_OP_PAUSE_PRINTER
,
220 IPP_OP_RESUME_PRINTER
,
222 IPP_OP_SET_PRINTER_ATTRIBUTES
,
223 IPP_OP_SET_JOB_ATTRIBUTES
,
224 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
225 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
226 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
227 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
228 IPP_OP_GET_SUBSCRIPTIONS
,
229 IPP_OP_RENEW_SUBSCRIPTION
,
230 IPP_OP_CANCEL_SUBSCRIPTION
,
231 IPP_OP_GET_NOTIFICATIONS
,
232 IPP_OP_ENABLE_PRINTER
,
233 IPP_OP_DISABLE_PRINTER
,
234 IPP_OP_HOLD_NEW_JOBS
,
235 IPP_OP_RELEASE_HELD_NEW_JOBS
,
237 IPP_OP_CANCEL_MY_JOBS
,
239 IPP_OP_CUPS_GET_DEFAULT
,
240 IPP_OP_CUPS_GET_PRINTERS
,
241 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
242 IPP_OP_CUPS_DELETE_PRINTER
,
243 IPP_OP_CUPS_GET_CLASSES
,
244 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
245 IPP_OP_CUPS_DELETE_CLASS
,
246 IPP_OP_CUPS_ACCEPT_JOBS
,
247 IPP_OP_CUPS_REJECT_JOBS
,
248 IPP_OP_CUPS_SET_DEFAULT
,
249 IPP_OP_CUPS_GET_DEVICES
,
250 IPP_OP_CUPS_GET_PPDS
,
251 IPP_OP_CUPS_MOVE_JOB
,
252 IPP_OP_CUPS_AUTHENTICATE_JOB
,
254 IPP_OP_CUPS_GET_DOCUMENT
,
257 static const char * const charsets
[] =/* charset-supported values */
262 static const char * const compressions
[] =
263 { /* document-compression-supported values */
267 #endif /* HAVE_LIBZ */
269 static const char * const media_col_supported
[] =
270 { /* media-col-supported values */
271 "media-bottom-margin",
273 "media-right-margin",
279 static const char * const multiple_document_handling
[] =
280 { /* multiple-document-handling-supported values */
281 "separate-documents-uncollated-copies",
282 "separate-documents-collated-copies"
284 static const char * const notify_attrs
[] =
285 { /* notify-attributes-supported values */
286 "printer-state-change-time",
287 "notify-lease-expiration-time",
288 "notify-subscriber-user-name"
290 static const char * const notify_events
[] =
291 { /* notify-events-supported values */
293 "job-config-changed",
300 "printer-config-changed",
302 "printer-finishings-changed",
303 "printer-media-changed",
307 "printer-state-changed",
314 static const char * const job_creation
[] =
315 { /* job-creation-attributes-supported */
319 "ipp-attribute-fidelity",
326 "multiple-document-handling",
329 "orientation-requested",
336 "printer-resolution",
339 static const char * const job_settable
[] =
340 { /* job-settable-attributes-supported */
348 "multiple-document-handling",
351 "orientation-requested",
355 "printer-resolution",
358 static const char * const pdf_versions
[] =
359 { /* pdf-versions-supported */
370 static const char * const printer_settable
[] =
371 { /* printer-settable-attributes-supported */
372 "printer-geo-location",
375 "printer-organization",
376 "printer-organizational-unit"
378 static const char * const which_jobs
[] =
379 { /* which-jobs-supported values */
393 ippDelete(CommonData
);
395 CommonData
= ippNew();
398 * Get the maximum spool size based on the size of the filesystem used for
399 * the RequestRoot directory. If the host OS doesn't support the statfs call
400 * or the filesystem is larger than 2TiB, always report INT_MAX.
404 if (statvfs(RequestRoot
, &spoolinfo
))
405 k_supported
= INT_MAX
;
406 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
408 k_supported
= INT_MAX
;
410 k_supported
= (int)spoolsize
;
412 #elif defined(HAVE_STATFS)
413 if (statfs(RequestRoot
, &spoolinfo
))
414 k_supported
= INT_MAX
;
415 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
417 k_supported
= INT_MAX
;
419 k_supported
= (int)spoolsize
;
422 k_supported
= INT_MAX
;
423 #endif /* HAVE_STATVFS */
426 * This list of attributes is sorted to improve performance when the
427 * client provides a requested-attributes attribute...
430 /* charset-configured */
431 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
432 "charset-configured", NULL
, "utf-8");
434 /* charset-supported */
435 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
436 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
439 /* compression-supported */
440 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
441 "compression-supported",
442 sizeof(compressions
) / sizeof(compressions
[0]),
445 /* copies-supported */
446 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
449 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
450 "cups-version", NULL
, CUPS_SVERSION
+ 6);
452 /* generated-natural-language-supported (no IPP_TAG_COPY) */
453 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
454 "generated-natural-language-supported", NULL
, DefaultLanguage
);
456 /* ipp-features-supported */
457 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
459 /* ipp-versions-supported */
460 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
461 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
464 /* ippget-event-life */
465 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
466 "ippget-event-life", 15);
468 /* job-cancel-after-supported */
469 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
472 /* job-creation-attributes-supported */
473 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
474 "job-creation-attributes-supported",
475 sizeof(job_creation
) / sizeof(job_creation
[0]),
478 /* job-hold-until-supported */
479 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
480 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
483 /* job-ids-supported */
484 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
486 /* job-k-octets-supported */
487 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
490 /* job-priority-supported */
491 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
492 "job-priority-supported", 100);
494 /* job-settable-attributes-supported */
495 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
496 "job-settable-attributes-supported",
497 sizeof(job_settable
) / sizeof(job_settable
[0]),
500 /* job-sheets-supported */
501 if (cupsArrayCount(Banners
) > 0)
504 * Setup the job-sheets-supported attribute...
507 if (Classification
&& !ClassifyOverride
)
508 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
509 IPP_TAG_NAME
| IPP_TAG_COPY
,
510 "job-sheets-supported", NULL
, Classification
);
512 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
513 IPP_TAG_NAME
| IPP_TAG_COPY
,
514 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
518 cupsdLogMessage(CUPSD_LOG_EMERG
,
519 "Unable to allocate memory for "
520 "job-sheets-supported attribute: %s!", strerror(errno
));
521 else if (!Classification
|| ClassifyOverride
)
523 cupsd_banner_t
*banner
; /* Current banner */
526 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
528 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
530 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
531 attr
->values
[i
].string
.text
= banner
->name
;
535 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
536 "job-sheets-supported", NULL
, "none");
538 /* jpeg-k-octets-supported */
539 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
542 /* jpeg-x-dimension-supported */
543 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
546 /* jpeg-y-dimension-supported */
547 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
550 /* media-col-supported */
551 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
552 "media-col-supported",
553 sizeof(media_col_supported
) /
554 sizeof(media_col_supported
[0]), NULL
,
555 media_col_supported
);
557 /* multiple-document-handling-supported */
558 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
559 "multiple-document-handling-supported",
560 sizeof(multiple_document_handling
) /
561 sizeof(multiple_document_handling
[0]), NULL
,
562 multiple_document_handling
);
564 /* multiple-document-jobs-supported */
565 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
566 "multiple-document-jobs-supported", 1);
568 /* multiple-operation-time-out */
569 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
570 "multiple-operation-time-out", MultipleOperationTimeout
);
572 /* multiple-operation-time-out-action */
573 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
575 /* natural-language-configured (no IPP_TAG_COPY) */
576 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
577 "natural-language-configured", NULL
, DefaultLanguage
);
579 /* notify-attributes-supported */
580 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
581 "notify-attributes-supported",
582 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
585 /* notify-lease-duration-supported */
586 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
587 "notify-lease-duration-supported", 0,
588 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
590 /* notify-max-events-supported */
591 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
592 "notify-max-events-supported", MaxEvents
);
594 /* notify-events-supported */
595 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
596 "notify-events-supported",
597 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
598 NULL
, notify_events
);
600 /* notify-pull-method-supported */
601 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
602 "notify-pull-method-supported", NULL
, "ippget");
604 /* notify-schemes-supported */
605 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
606 if ((dir
= cupsDirOpen(filename
)) != NULL
)
608 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
610 while ((dent
= cupsDirRead(dir
)) != NULL
)
611 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
612 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
613 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
615 if (cupsArrayCount(notifiers
) > 0)
617 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
618 "notify-schemes-supported",
619 cupsArrayCount(notifiers
), NULL
, NULL
);
621 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
623 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
624 attr
->values
[i
].string
.text
= notifier
;
627 cupsArrayDelete(notifiers
);
631 /* number-up-supported */
632 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
633 "number-up-supported", sizeof(number_up
) / sizeof(number_up
[0]), number_up
);
635 /* number-up-layout-supported */
636 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "number-up-layout-supported", sizeof(number_up_layout
) / sizeof(number_up_layout
[0]), NULL
, number_up_layout
);
638 /* operations-supported */
639 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
640 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
642 /* orientation-requested-supported */
643 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
644 "orientation-requested-supported", 4, orients
);
646 /* page-delivery-supported */
647 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "page-delivery-supported", sizeof(page_delivery
) / sizeof(page_delivery
[0]), NULL
, page_delivery
);
649 /* page-ranges-supported */
650 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
652 /* pdf-k-octets-supported */
653 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
656 /* pdf-versions-supported */
657 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
658 "pdf-versions-supported",
659 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
662 /* pdl-override-supported */
663 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
664 "pdl-override-supported", NULL
, "attempted");
666 /* print-scaling-supported */
667 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "print-scaling-supported", sizeof(print_scaling
) / sizeof(print_scaling
[0]), NULL
, print_scaling
);
669 /* printer-get-attributes-supported */
670 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
672 /* printer-op-policy-supported */
673 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
674 "printer-op-policy-supported", cupsArrayCount(Policies
),
676 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
678 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
679 attr
->values
[i
].string
.text
= p
->name
;
681 /* printer-settable-attributes-supported */
682 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
683 "printer-settable-attributes-supported",
684 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
685 NULL
, printer_settable
);
687 /* server-is-sharing-printers */
688 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
689 BrowseLocalProtocols
!= 0 && Browsing
);
691 /* which-jobs-supported */
692 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
693 "which-jobs-supported",
694 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
699 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
703 cupsdDeleteAllPrinters(void)
705 cupsd_printer_t
*p
; /* Pointer to current printer/class */
708 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
710 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
712 p
->op_policy_ptr
= DefaultPolicyPtr
;
713 cupsdDeletePrinter(p
, 0);
719 * 'cupsdDeletePrinter()' - Delete a printer from the system.
722 int /* O - 1 if classes affected, 0 otherwise */
724 cupsd_printer_t
*p
, /* I - Printer to delete */
725 int update
) /* I - Update printers.conf? */
727 int i
, /* Looping var */
728 changed
= 0; /* Class changed? */
731 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
735 * Save the current position in the Printers array...
738 cupsArraySave(Printers
);
741 * Stop printing on this printer...
744 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
746 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
749 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
750 update
? "Job stopped due to printer being deleted." :
754 * Remove the printer from the list...
757 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
758 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
759 cupsArrayRemove(Printers
, p
);
762 * If p is the default printer, assign a different one...
765 if (p
== DefaultPrinter
)
766 DefaultPrinter
= NULL
;
769 * Remove this printer from any classes...
772 changed
= cupsdDeletePrinterFromClasses(p
);
775 * Deregister from any browse protocols...
778 cupsdDeregisterPrinter(p
, 1);
781 * Remove support files if this is a temporary queue and deregister color
787 char filename
[1024]; /* Script/PPD filename */
790 * Remove any old PPD or script files...
793 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
795 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
798 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
801 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
805 * Unregister color profiles...
808 cupsdUnregisterColor(p
);
812 * Free all memory used by the printer...
815 if (p
->printers
!= NULL
)
818 delete_printer_filters(p
);
820 for (i
= 0; i
< p
->num_reasons
; i
++)
821 _cupsStrFree(p
->reasons
[i
]);
824 ippDelete(p
->ppd_attrs
);
826 mimeDeleteType(MimeDatabase
, p
->filetype
);
827 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
829 cupsdFreeStrings(&(p
->users
));
832 cupsdClearString(&p
->uri
);
833 cupsdClearString(&p
->hostname
);
834 cupsdClearString(&p
->name
);
835 cupsdClearString(&p
->location
);
836 cupsdClearString(&p
->geo_location
);
837 cupsdClearString(&p
->make_model
);
838 cupsdClearString(&p
->info
);
839 cupsdClearString(&p
->job_sheets
[0]);
840 cupsdClearString(&p
->job_sheets
[1]);
841 cupsdClearString(&p
->device_uri
);
842 cupsdClearString(&p
->sanitized_device_uri
);
843 cupsdClearString(&p
->port_monitor
);
844 cupsdClearString(&p
->op_policy
);
845 cupsdClearString(&p
->error_policy
);
846 cupsdClearString(&p
->strings
);
848 cupsdClearString(&p
->alert
);
849 cupsdClearString(&p
->alert_description
);
851 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
852 cupsdClearString(&p
->pdl
);
853 cupsdClearString(&p
->reg_name
);
854 #endif /* HAVE_DNSSD || HAVE_AVAHI */
856 cupsArrayDelete(p
->filetypes
);
858 cupsFreeOptions(p
->num_options
, p
->options
);
863 * Restore the previous position in the Printers array...
866 cupsArrayRestore(Printers
);
873 * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
877 cupsdDeleteTemporaryPrinters(int force
) /* I - Force deletion instead of auto? */
879 cupsd_printer_t
*p
; /* Current printer */
880 time_t unused_time
; /* Last time for printer state change */
884 * Allow temporary printers to stick around for 60 seconds after the last job
888 unused_time
= time(NULL
) - 60;
890 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
); p
; p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
892 if (p
->temporary
&& (force
|| p
->state_time
< unused_time
))
893 cupsdDeletePrinter(p
, 0);
899 * 'cupsdFindDest()' - Find a destination in the list.
902 cupsd_printer_t
* /* O - Destination in list */
903 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
905 cupsd_printer_t key
; /* Search key */
908 key
.name
= (char *)name
;
909 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
914 * 'cupsdFindPrinter()' - Find a printer in the list.
917 cupsd_printer_t
* /* O - Printer in list */
918 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
920 cupsd_printer_t
*p
; /* Printer in list */
923 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
931 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
935 cupsdLoadAllPrinters(void)
937 int i
; /* Looping var */
938 cups_file_t
*fp
; /* printers.conf file */
939 int linenum
; /* Current line number */
940 char line
[4096], /* Line from file */
941 *value
, /* Pointer to value */
942 *valueptr
; /* Pointer into value */
943 cupsd_printer_t
*p
; /* Current printer */
947 * Open the printers.conf file...
950 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
951 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
955 * Read printer configurations until we hit EOF...
961 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
964 * Decode the directive...
967 if (!_cups_strcasecmp(line
, "NextPrinterId"))
969 if (value
&& (i
= atoi(value
)) > 0)
972 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
974 else if (!_cups_strcasecmp(line
, "<Printer") || !_cups_strcasecmp(line
, "<DefaultPrinter"))
977 * <Printer name> or <DefaultPrinter name>
980 if (p
== NULL
&& value
)
983 * Add the printer and a base file type...
986 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
988 p
= cupsdAddPrinter(value
);
990 p
->state
= IPP_PRINTER_IDLE
;
993 * Set the default printer as needed...
996 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
1000 cupsdLogMessage(CUPSD_LOG_ERROR
,
1001 "Syntax error on line %d of printers.conf.", linenum
);
1003 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
1008 * Close out the current printer...
1013 p
->printer_id
= NextPrinterId
++;
1014 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
1017 cupsdSetPrinterAttrs(p
);
1019 if (strncmp(p
->device_uri
, "file:", 5) && p
->state
!= IPP_PRINTER_STOPPED
)
1022 * See if the backend exists...
1025 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
, p
->device_uri
);
1027 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
1028 *valueptr
= '\0'; /* Chop everything but URI scheme */
1030 if (access(line
, 0))
1033 * Backend does not exist, stop printer...
1036 p
->state
= IPP_PRINTER_STOPPED
;
1037 snprintf(p
->state_message
, sizeof(p
->state_message
), "Backend %s does not exist!", line
);
1044 cupsdLogMessage(CUPSD_LOG_ERROR
,
1045 "Syntax error on line %d of printers.conf.", linenum
);
1049 cupsdLogMessage(CUPSD_LOG_ERROR
,
1050 "Syntax error on line %d of printers.conf.", linenum
);
1052 else if (!_cups_strcasecmp(line
, "PrinterId"))
1054 if (value
&& (i
= atoi(value
)) > 0)
1057 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad PrinterId on line %d of printers.conf.", linenum
);
1059 else if (!_cups_strcasecmp(line
, "UUID"))
1061 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1062 cupsdSetString(&(p
->uuid
), value
);
1064 cupsdLogMessage(CUPSD_LOG_ERROR
,
1065 "Bad UUID on line %d of printers.conf.", linenum
);
1067 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1069 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Bad AuthInfoRequired on line %d of printers.conf.",
1074 else if (!_cups_strcasecmp(line
, "Info"))
1077 cupsdSetString(&p
->info
, value
);
1079 else if (!_cups_strcasecmp(line
, "MakeModel"))
1082 cupsdSetString(&p
->make_model
, value
);
1084 else if (!_cups_strcasecmp(line
, "Location"))
1087 cupsdSetString(&p
->location
, value
);
1089 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1092 cupsdSetString(&p
->geo_location
, value
);
1094 else if (!_cups_strcasecmp(line
, "Organization"))
1097 cupsdSetString(&p
->organization
, value
);
1099 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1102 cupsdSetString(&p
->organizational_unit
, value
);
1104 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1107 cupsdSetDeviceURI(p
, value
);
1109 cupsdLogMessage(CUPSD_LOG_ERROR
,
1110 "Syntax error on line %d of printers.conf.", linenum
);
1112 else if (!_cups_strcasecmp(line
, "Option") && value
)
1118 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1121 cupsdLogMessage(CUPSD_LOG_ERROR
,
1122 "Syntax error on line %d of printers.conf.", linenum
);
1125 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1127 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1131 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1133 if (value
&& strcmp(value
, "none"))
1134 cupsdSetString(&p
->port_monitor
, value
);
1136 cupsdClearString(&p
->port_monitor
);
1138 cupsdLogMessage(CUPSD_LOG_ERROR
,
1139 "Syntax error on line %d of printers.conf.", linenum
);
1141 else if (!_cups_strcasecmp(line
, "Reason"))
1144 strcmp(value
, "connecting-to-device") &&
1145 strcmp(value
, "cups-insecure-filter-warning") &&
1146 strcmp(value
, "cups-missing-filter-warning"))
1148 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1149 if (!strcmp(value
, p
->reasons
[i
]))
1152 if (i
>= p
->num_reasons
&&
1153 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1155 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1160 cupsdLogMessage(CUPSD_LOG_ERROR
,
1161 "Syntax error on line %d of printers.conf.", linenum
);
1163 else if (!_cups_strcasecmp(line
, "State"))
1166 * Set the initial queue state...
1169 if (value
&& !_cups_strcasecmp(value
, "idle"))
1170 p
->state
= IPP_PRINTER_IDLE
;
1171 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1173 p
->state
= IPP_PRINTER_STOPPED
;
1175 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1176 if (!strcmp("paused", p
->reasons
[i
]))
1179 if (i
>= p
->num_reasons
&&
1180 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1182 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1187 cupsdLogMessage(CUPSD_LOG_ERROR
,
1188 "Syntax error on line %d of printers.conf.", linenum
);
1190 else if (!_cups_strcasecmp(line
, "StateMessage"))
1193 * Set the initial queue state message...
1197 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1199 else if (!_cups_strcasecmp(line
, "StateTime"))
1202 * Set the state time...
1206 p
->state_time
= atoi(value
);
1208 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1211 * Set the config time...
1215 p
->config_time
= atoi(value
);
1217 else if (!_cups_strcasecmp(line
, "Accepting"))
1220 * Set the initial accepting state...
1224 (!_cups_strcasecmp(value
, "yes") ||
1225 !_cups_strcasecmp(value
, "on") ||
1226 !_cups_strcasecmp(value
, "true")))
1229 (!_cups_strcasecmp(value
, "no") ||
1230 !_cups_strcasecmp(value
, "off") ||
1231 !_cups_strcasecmp(value
, "false")))
1234 cupsdLogMessage(CUPSD_LOG_ERROR
,
1235 "Syntax error on line %d of printers.conf.", linenum
);
1237 else if (!_cups_strcasecmp(line
, "Type"))
1240 p
->type
= (cups_ptype_t
)atoi(value
);
1242 cupsdLogMessage(CUPSD_LOG_ERROR
,
1243 "Syntax error on line %d of printers.conf.", linenum
);
1245 else if (!_cups_strcasecmp(line
, "Shared"))
1248 * Set the initial shared state...
1252 (!_cups_strcasecmp(value
, "yes") ||
1253 !_cups_strcasecmp(value
, "on") ||
1254 !_cups_strcasecmp(value
, "true")))
1257 (!_cups_strcasecmp(value
, "no") ||
1258 !_cups_strcasecmp(value
, "off") ||
1259 !_cups_strcasecmp(value
, "false")))
1262 cupsdLogMessage(CUPSD_LOG_ERROR
,
1263 "Syntax error on line %d of printers.conf.", linenum
);
1265 else if (!_cups_strcasecmp(line
, "JobSheets"))
1268 * Set the initial job sheets...
1273 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1278 cupsdSetString(&p
->job_sheets
[0], value
);
1280 while (isspace(*valueptr
& 255))
1285 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1290 cupsdSetString(&p
->job_sheets
[1], value
);
1294 cupsdLogMessage(CUPSD_LOG_ERROR
,
1295 "Syntax error on line %d of printers.conf.", linenum
);
1297 else if (!_cups_strcasecmp(line
, "AllowUser"))
1302 cupsdAddString(&(p
->users
), value
);
1305 cupsdLogMessage(CUPSD_LOG_ERROR
,
1306 "Syntax error on line %d of printers.conf.", linenum
);
1308 else if (!_cups_strcasecmp(line
, "DenyUser"))
1313 cupsdAddString(&(p
->users
), value
);
1316 cupsdLogMessage(CUPSD_LOG_ERROR
,
1317 "Syntax error on line %d of printers.conf.", linenum
);
1319 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1322 p
->quota_period
= atoi(value
);
1324 cupsdLogMessage(CUPSD_LOG_ERROR
,
1325 "Syntax error on line %d of printers.conf.", linenum
);
1327 else if (!_cups_strcasecmp(line
, "PageLimit"))
1330 p
->page_limit
= atoi(value
);
1332 cupsdLogMessage(CUPSD_LOG_ERROR
,
1333 "Syntax error on line %d of printers.conf.", linenum
);
1335 else if (!_cups_strcasecmp(line
, "KLimit"))
1338 p
->k_limit
= atoi(value
);
1340 cupsdLogMessage(CUPSD_LOG_ERROR
,
1341 "Syntax error on line %d of printers.conf.", linenum
);
1343 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1347 cupsd_policy_t
*pol
; /* Policy */
1350 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1352 cupsdSetString(&p
->op_policy
, value
);
1353 p
->op_policy_ptr
= pol
;
1356 cupsdLogMessage(CUPSD_LOG_ERROR
,
1357 "Bad policy \"%s\" on line %d of printers.conf",
1361 cupsdLogMessage(CUPSD_LOG_ERROR
,
1362 "Syntax error on line %d of printers.conf.", linenum
);
1364 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1368 if (strcmp(value
, "retry-current-job") &&
1369 strcmp(value
, "abort-job") &&
1370 strcmp(value
, "retry-job") &&
1371 strcmp(value
, "stop-printer"))
1372 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1374 cupsdSetString(&p
->error_policy
, value
);
1377 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1379 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1381 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1384 cupsdLogMessage(CUPSD_LOG_ERROR
,
1385 "Syntax error on line %d of printers.conf.", linenum
);
1388 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1391 cupsdSetPrinterAttrs(p
);
1393 if (!strcmp(value
, "marker-change-time"))
1394 p
->marker_time
= atoi(valueptr
);
1396 cupsdSetPrinterAttr(p
, value
, valueptr
);
1399 else if (_cups_strcasecmp(line
, "Filter") &&
1400 _cups_strcasecmp(line
, "Prefilter") &&
1401 _cups_strcasecmp(line
, "Product"))
1404 * Something else we don't understand (and that wasn't used in a prior
1405 * release of CUPS...
1408 cupsdLogMessage(CUPSD_LOG_ERROR
,
1409 "Unknown configuration directive %s on line %d of "
1410 "printers.conf.", line
, linenum
);
1419 * 'cupsdRenamePrinter()' - Rename a printer.
1424 cupsd_printer_t
*p
, /* I - Printer */
1425 const char *name
) /* I - New name */
1428 * Remove the printer from the array(s) first...
1431 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1432 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1433 cupsArrayRemove(Printers
, p
);
1436 * Rename the printer type...
1439 mimeDeleteType(MimeDatabase
, p
->filetype
);
1440 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1442 if (p
->prefiltertype
)
1444 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1445 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1449 * Rename the printer...
1452 cupsdSetString(&p
->name
, name
);
1455 * Reset printer attributes...
1458 cupsdSetPrinterAttrs(p
);
1461 * Add the printer back to the printer array(s)...
1464 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1465 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1466 cupsArrayAdd(Printers
, p
);
1471 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1476 cupsdSaveAllPrinters(void)
1478 int i
; /* Looping var */
1479 cups_file_t
*fp
; /* printers.conf file */
1480 char filename
[1024], /* printers.conf filename */
1481 temp
[1024], /* Temporary string */
1482 value
[2048], /* Value string */
1483 *ptr
, /* Pointer into value */
1484 *name
; /* Current user/group name */
1485 cupsd_printer_t
*printer
; /* Current printer class */
1486 time_t curtime
; /* Current time */
1487 struct tm
*curdate
; /* Current date */
1488 cups_option_t
*option
; /* Current option */
1489 ipp_attribute_t
*marker
; /* Current marker attribute */
1493 * Create the printers.conf file...
1496 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1498 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1501 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1504 * Write a small header to the file...
1507 curtime
= time(NULL
);
1508 curdate
= localtime(&curtime
);
1509 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1511 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1512 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1513 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1515 cupsFilePrintf(fp
, "NextPrinterId %d\n", NextPrinterId
);
1518 * Write each local printer known to the system...
1521 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1523 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1526 * Skip printer classes and temporary queues...
1529 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1533 * Write printers as needed...
1536 if (printer
== DefaultPrinter
)
1537 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1539 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1541 if (printer
->printer_id
)
1542 cupsFilePrintf(fp
, "PrinterId %d\n", printer
->printer_id
);
1544 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1546 if (printer
->num_auth_info_required
> 0)
1548 switch (printer
->num_auth_info_required
)
1551 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1555 snprintf(value
, sizeof(value
), "%s,%s",
1556 printer
->auth_info_required
[0],
1557 printer
->auth_info_required
[1]);
1562 snprintf(value
, sizeof(value
), "%s,%s,%s",
1563 printer
->auth_info_required
[0],
1564 printer
->auth_info_required
[1],
1565 printer
->auth_info_required
[2]);
1569 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1573 cupsFilePutConf(fp
, "Info", printer
->info
);
1575 if (printer
->location
)
1576 cupsFilePutConf(fp
, "Location", printer
->location
);
1578 if (printer
->geo_location
)
1579 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1581 if (printer
->make_model
)
1582 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1584 if (printer
->organization
)
1585 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1587 if (printer
->organizational_unit
)
1588 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1590 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1592 if (printer
->port_monitor
)
1593 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1595 if (printer
->state
== IPP_PRINTER_STOPPED
)
1597 cupsFilePuts(fp
, "State Stopped\n");
1599 if (printer
->state_message
[0])
1600 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1603 cupsFilePuts(fp
, "State Idle\n");
1605 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1606 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1608 for (i
= 0; i
< printer
->num_reasons
; i
++)
1609 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1610 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1611 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1612 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1614 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1616 if (printer
->accepting
)
1617 cupsFilePuts(fp
, "Accepting Yes\n");
1619 cupsFilePuts(fp
, "Accepting No\n");
1621 if (printer
->shared
)
1622 cupsFilePuts(fp
, "Shared Yes\n");
1624 cupsFilePuts(fp
, "Shared No\n");
1626 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1627 printer
->job_sheets
[1]);
1628 cupsFilePutConf(fp
, "JobSheets", value
);
1630 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1631 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1632 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1634 for (name
= (char *)cupsArrayFirst(printer
->users
);
1636 name
= (char *)cupsArrayNext(printer
->users
))
1637 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1639 if (printer
->op_policy
)
1640 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1641 if (printer
->error_policy
)
1642 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1644 for (i
= printer
->num_options
, option
= printer
->options
;
1648 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1649 cupsFilePutConf(fp
, "Option", value
);
1652 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1653 IPP_TAG_NAME
)) != NULL
)
1655 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1657 for (i
= 0, ptr
= value
+ strlen(value
);
1658 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1664 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1669 cupsFilePutConf(fp
, "Attribute", value
);
1672 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1673 IPP_TAG_INTEGER
)) != NULL
)
1675 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1676 marker
->values
[0].integer
);
1677 for (i
= 1; i
< marker
->num_values
; i
++)
1678 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1679 cupsFilePuts(fp
, "\n");
1682 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1683 IPP_TAG_INTEGER
)) != NULL
)
1685 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1686 marker
->values
[0].integer
);
1687 for (i
= 1; i
< marker
->num_values
; i
++)
1688 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1689 cupsFilePuts(fp
, "\n");
1692 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1693 IPP_TAG_INTEGER
)) != NULL
)
1695 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1696 marker
->values
[0].integer
);
1697 for (i
= 1; i
< marker
->num_values
; i
++)
1698 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1699 cupsFilePuts(fp
, "\n");
1702 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1703 IPP_TAG_TEXT
)) != NULL
)
1705 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1706 marker
->values
[0].string
.text
);
1708 cupsFilePutConf(fp
, "Attribute", value
);
1711 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1712 IPP_TAG_NAME
)) != NULL
)
1714 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1716 for (i
= 0, ptr
= value
+ strlen(value
);
1717 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1723 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1728 cupsFilePutConf(fp
, "Attribute", value
);
1731 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1732 IPP_TAG_KEYWORD
)) != NULL
)
1734 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1736 for (i
= 0, ptr
= value
+ strlen(value
);
1737 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1743 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1748 cupsFilePutConf(fp
, "Attribute", value
);
1751 if (printer
->marker_time
)
1752 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1753 (long)printer
->marker_time
);
1755 if (printer
== DefaultPrinter
)
1756 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1758 cupsFilePuts(fp
, "</Printer>\n");
1761 cupsdCloseCreatedConfFile(fp
, filename
);
1766 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1769 int /* O - 1 if value OK, 0 otherwise */
1770 cupsdSetAuthInfoRequired(
1771 cupsd_printer_t
*p
, /* I - Printer */
1772 const char *values
, /* I - Plain text value (or NULL) */
1773 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1775 int i
; /* Looping var */
1778 p
->num_auth_info_required
= 0;
1781 * Do we have a plain text value?
1787 * Yes, grab the keywords...
1790 const char *end
; /* End of current value */
1793 while (*values
&& p
->num_auth_info_required
< 4)
1795 if ((end
= strchr(values
, ',')) == NULL
)
1796 end
= values
+ strlen(values
);
1798 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1800 if (p
->num_auth_info_required
!= 0 || *end
)
1803 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1804 p
->num_auth_info_required
++;
1808 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1810 if (p
->num_auth_info_required
!= 0 || *end
)
1813 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1814 p
->num_auth_info_required
++;
1817 * Don't allow sharing of queues that require Kerberos authentication.
1822 cupsdDeregisterPrinter(p
, 1);
1826 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1828 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1829 p
->num_auth_info_required
++;
1831 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1833 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1834 p
->num_auth_info_required
++;
1836 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1838 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1839 p
->num_auth_info_required
++;
1844 values
= (*end
) ? end
+ 1 : end
;
1847 if (p
->num_auth_info_required
== 0)
1849 p
->auth_info_required
[0] = "none";
1850 p
->num_auth_info_required
= 1;
1854 * Update the printer-type value as needed...
1857 if (p
->num_auth_info_required
> 1 ||
1858 strcmp(p
->auth_info_required
[0], "none"))
1859 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1861 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1867 * Grab values from an attribute instead...
1870 if (!attr
|| attr
->num_values
> 4)
1873 for (i
= 0; i
< attr
->num_values
; i
++)
1875 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1877 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1880 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1881 p
->num_auth_info_required
++;
1885 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1887 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1890 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1891 p
->num_auth_info_required
++;
1894 * Don't allow sharing of queues that require Kerberos authentication.
1899 cupsdDeregisterPrinter(p
, 1);
1905 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1907 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1908 p
->num_auth_info_required
++;
1910 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1912 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1913 p
->num_auth_info_required
++;
1915 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1917 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1918 p
->num_auth_info_required
++;
1929 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1933 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1934 const char *uri
) /* I - Device URI */
1936 char buffer
[1024], /* URI buffer */
1937 *start
, /* Start of data after scheme */
1938 *slash
, /* First slash after scheme:// */
1939 *ptr
; /* Pointer into user@host:port part */
1943 * Set the full device URI..
1946 cupsdSetString(&(p
->device_uri
), uri
);
1949 * Copy the device URI to a temporary buffer so we can sanitize any auth
1953 strlcpy(buffer
, uri
, sizeof(buffer
));
1956 * Find the end of the scheme:// part...
1959 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1961 for (start
= ptr
+ 1; *start
; start
++)
1966 * Find the next slash (/) in the URI...
1969 if ((slash
= strchr(start
, '/')) == NULL
)
1970 slash
= start
+ strlen(start
); /* No slash, point to the end */
1973 * Check for an @ sign before the slash...
1976 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1979 * Found an @ sign and it is before the resource part, so we have
1980 * an authentication string. Copy the remaining URI over the
1981 * authentication string...
1984 _cups_strcpy(start
, ptr
+ 1);
1989 * Save the sanitized URI...
1992 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1997 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
2001 cupsdSetPrinterAttr(
2002 cupsd_printer_t
*p
, /* I - Printer */
2003 const char *name
, /* I - Attribute name */
2004 const char *value
) /* I - Attribute value string */
2006 ipp_attribute_t
*attr
; /* Attribute */
2007 int i
, /* Looping var */
2008 count
; /* Number of values */
2009 char *temp
, /* Temporary copy of value string */
2010 *ptr
, /* Pointer into value */
2011 *start
, /* Start of value */
2012 quote
; /* Quote character */
2013 ipp_tag_t value_tag
; /* Value tag for this attribute */
2017 * Don't allow empty values...
2020 if (!*value
&& strcmp(name
, "marker-message"))
2022 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
2027 * Copy the value string so we can do what we want with it...
2030 if ((temp
= strdup(value
)) == NULL
)
2032 cupsdLogMessage(CUPSD_LOG_ERROR
,
2033 "Unable to duplicate value for \"%s\" attribute.", name
);
2038 * Count the number of values...
2041 for (count
= 1, quote
= '\0', ptr
= temp
;
2049 else if (*ptr
== '\\' && ptr
[1])
2051 else if (*ptr
== '\'' || *ptr
== '\"')
2053 else if (*ptr
== ',')
2058 * Then add or update the attribute as needed...
2061 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2062 !strcmp(name
, "marker-high-levels"))
2068 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2069 attr
->num_values
< count
)
2071 ippDeleteAttribute(p
->attrs
, attr
);
2076 attr
->num_values
= count
;
2078 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2084 cupsdLogMessage(CUPSD_LOG_ERROR
,
2085 "Unable to allocate memory for printer attribute "
2086 "(%d values)", count
);
2090 for (i
= 0, start
= temp
; i
< count
; i
++)
2092 if ((ptr
= strchr(start
, ',')) != NULL
)
2095 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2104 * Name or keyword values...
2107 if (!strcmp(name
, "marker-types"))
2108 value_tag
= IPP_TAG_KEYWORD
;
2109 else if (!strcmp(name
, "marker-message"))
2110 value_tag
= IPP_TAG_TEXT
;
2112 value_tag
= IPP_TAG_NAME
;
2114 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2115 attr
->num_values
< count
)
2117 ippDeleteAttribute(p
->attrs
, attr
);
2123 for (i
= 0; i
< attr
->num_values
; i
++)
2124 _cupsStrFree(attr
->values
[i
].string
.text
);
2126 attr
->num_values
= count
;
2129 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2135 cupsdLogMessage(CUPSD_LOG_ERROR
,
2136 "Unable to allocate memory for printer attribute "
2137 "(%d values)", count
);
2141 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2143 for (start
= ptr
; *ptr
; ptr
++)
2146 *ptr
= quote
= '\0';
2149 else if (*ptr
== '\\' && ptr
[1])
2150 _cups_strcpy(ptr
, ptr
+ 1);
2151 else if (*ptr
== '\'' || *ptr
== '\"')
2158 _cups_strcpy(ptr
, ptr
+ 1);
2160 else if (*ptr
== ',')
2167 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2174 * Update the printer-supply and printer-supply-description, as needed...
2177 if (!strcmp(name
, "marker-names"))
2179 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2180 /* printer-supply-description attribute */
2182 if (supply_desc
!= NULL
)
2183 ippDeleteAttribute(p
->attrs
, supply_desc
);
2185 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2186 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2187 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2189 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2191 char buffer
[256], /* printer-supply values */
2192 pstype
[64], /* printer-supply type value */
2193 *psptr
; /* Pointer into type */
2194 const char *color
, /* marker-colors value */
2195 *type
; /* marker-types value */
2196 int level
; /* marker-levels value */
2197 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2198 /* marker-colors attribute */
2199 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2200 /* marker-levels attribute */
2201 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2202 /* marker-types attribute */
2203 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2204 /* printer-supply attribute */
2208 ippDeleteAttribute(p
->attrs
, supply
);
2212 if (!colors
|| !levels
|| !types
)
2215 count
= ippGetCount(colors
);
2216 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2219 for (i
= 0; i
< count
; i
++)
2221 color
= ippGetString(colors
, i
, NULL
);
2222 level
= ippGetInteger(levels
, i
);
2223 type
= ippGetString(types
, i
, NULL
);
2225 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2229 *psptr
++ = (char)toupper(*type
& 255);
2235 snprintf(buffer
, sizeof(buffer
), "index=%d;class=%s;type=%s;unit=percent;maxcapacity=100;level=%d;colorantname=%s;", i
+ 1, strncmp(pstype
, "waste", 5) ? "supplyThatIsConsumed" : "receptacleThatIsFilled", pstype
, level
, color
);
2238 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2240 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2247 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2251 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2253 int i
; /* Looping var */
2254 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2255 cupsd_location_t
*auth
; /* Pointer to authentication element */
2256 const char *auth_supported
; /* Authentication supported */
2257 ipp_t
*oldattrs
; /* Old printer attributes */
2258 ipp_attribute_t
*attr
; /* Attribute data */
2259 char *name
, /* Current user/group name */
2260 *filter
; /* Current filter */
2263 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2267 * Make sure that we have the common attributes defined...
2271 cupsdCreateCommonData();
2273 _cupsRWLockWrite(&p
->lock
);
2276 * Clear out old filters, if any...
2279 delete_printer_filters(p
);
2282 * Figure out the authentication that is required for the printer.
2285 auth_supported
= "requesting-user-name";
2287 if (p
->type
& CUPS_PRINTER_CLASS
)
2288 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2290 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2292 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2293 auth
->type
== CUPSD_AUTH_NONE
)
2294 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2298 int auth_type
; /* Authentication type */
2301 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2302 auth_type
= cupsdDefaultAuthType();
2304 if (auth_type
== CUPSD_AUTH_BASIC
)
2305 auth_supported
= "basic";
2307 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2308 auth_supported
= "negotiate";
2309 #endif /* HAVE_GSSAPI */
2311 if (auth_type
!= CUPSD_AUTH_NONE
)
2312 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2314 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2317 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2320 * Create the required IPP attributes for a printer...
2323 oldattrs
= p
->attrs
;
2324 p
->attrs
= ippNew();
2326 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2327 "uri-authentication-supported", NULL
, auth_supported
);
2328 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2329 "uri-security-supported", NULL
, "none");
2331 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-id", p
->printer_id
);
2332 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2334 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2335 NULL
, p
->location
? p
->location
: "");
2336 if (p
->geo_location
)
2337 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2339 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2340 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2341 NULL
, p
->info
? p
->info
: "");
2342 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2343 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2344 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2346 if (cupsArrayCount(p
->users
) > 0)
2349 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2350 "requesting-user-name-denied",
2351 cupsArrayCount(p
->users
), NULL
, NULL
);
2353 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2354 "requesting-user-name-allowed",
2355 cupsArrayCount(p
->users
), NULL
, NULL
);
2357 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2359 i
++, name
= (char *)cupsArrayNext(p
->users
))
2360 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2363 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2364 "job-quota-period", p
->quota_period
);
2365 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2366 "job-k-limit", p
->k_limit
);
2367 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2368 "job-page-limit", p
->page_limit
);
2369 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2370 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2371 "auth-info-required", p
->num_auth_info_required
, NULL
,
2372 p
->auth_info_required
);
2374 if (cupsArrayCount(Banners
) > 0)
2377 * Setup the job-sheets-default attribute...
2380 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2381 "job-sheets-default", 2, NULL
, NULL
);
2385 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2386 Classification
: p
->job_sheets
[0]);
2387 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2388 Classification
: p
->job_sheets
[1]);
2396 * Assign additional attributes depending on whether this is a printer
2400 if (p
->type
& CUPS_PRINTER_CLASS
)
2403 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2406 * Add class-specific attributes...
2409 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2410 "printer-make-and-model", NULL
, "Local Printer Class");
2411 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2412 "file:///dev/null");
2414 if (p
->num_printers
> 0)
2417 * Add a list of member names; URIs are added in copy_printer_attrs...
2420 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2421 "member-names", p
->num_printers
, NULL
, NULL
);
2422 p
->type
|= CUPS_PRINTER_OPTIONS
;
2424 for (i
= 0; i
< p
->num_printers
; i
++)
2427 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2429 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2436 * Add printer-specific attributes...
2439 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2440 p
->sanitized_device_uri
);
2443 * Assign additional attributes from the PPD file (if any)...
2449 * Add filters for printer...
2452 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2453 "cups-insecure-filter-warning");
2455 if (p
->pc
&& p
->pc
->filters
)
2457 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2459 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2460 add_printer_filter(p
, p
->filetype
, filter
);
2462 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2465 * Add a filter from application/vnd.cups-raw to printer/name to
2466 * handle "raw" printing by users.
2469 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2472 * Add a PostScript filter, since this is still possibly PS printer.
2475 add_printer_filter(p
, p
->filetype
,
2476 "application/vnd.cups-postscript 0 -");
2479 if (p
->pc
&& p
->pc
->prefilters
)
2481 if (!p
->prefiltertype
)
2482 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2484 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2486 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2487 add_printer_filter(p
, p
->prefiltertype
, filter
);
2492 * Copy marker attributes as needed...
2497 ipp_attribute_t
*oldattr
; /* Old attribute */
2500 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2501 IPP_TAG_NAME
)) != NULL
)
2503 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2504 "marker-colors", oldattr
->num_values
, NULL
,
2507 for (i
= 0; i
< oldattr
->num_values
; i
++)
2508 attr
->values
[i
].string
.text
=
2509 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2513 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2514 IPP_TAG_INTEGER
)) != NULL
)
2516 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2517 "marker-levels", oldattr
->num_values
,
2520 for (i
= 0; i
< oldattr
->num_values
; i
++)
2521 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2525 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2526 IPP_TAG_TEXT
)) != NULL
)
2527 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2528 NULL
, oldattr
->values
[0].string
.text
);
2530 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2531 IPP_TAG_INTEGER
)) != NULL
)
2533 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2534 "marker-low-levels", oldattr
->num_values
,
2537 for (i
= 0; i
< oldattr
->num_values
; i
++)
2538 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2542 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2543 IPP_TAG_INTEGER
)) != NULL
)
2545 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2546 "marker-high-levels", oldattr
->num_values
,
2549 for (i
= 0; i
< oldattr
->num_values
; i
++)
2550 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2554 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2555 IPP_TAG_NAME
)) != NULL
)
2557 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2558 "marker-names", oldattr
->num_values
, NULL
,
2561 for (i
= 0; i
< oldattr
->num_values
; i
++)
2562 attr
->values
[i
].string
.text
=
2563 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2567 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2568 IPP_TAG_KEYWORD
)) != NULL
)
2570 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2571 "marker-types", oldattr
->num_values
, NULL
,
2574 for (i
= 0; i
< oldattr
->num_values
; i
++)
2575 attr
->values
[i
].string
.text
=
2576 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2580 ippDelete(oldattrs
);
2584 * Force sharing off for remote queues...
2587 if (p
->type
& CUPS_PRINTER_REMOTE
)
2591 * Populate the document-format-supported attribute...
2594 add_printer_formats(p
);
2596 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2600 * Add name-default attributes...
2603 add_printer_defaults(p
);
2605 _cupsRWUnlock(&p
->lock
);
2608 * Let the browse protocols reflect the change
2611 cupsdRegisterPrinter(p
);
2616 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2619 int /* O - 1 if something changed, 0 otherwise */
2620 cupsdSetPrinterReasons(
2621 cupsd_printer_t
*p
, /* I - Printer */
2622 const char *s
) /* I - Reasons strings */
2624 int i
, /* Looping var */
2625 changed
= 0; /* Did something change? */
2626 const char *sptr
; /* Pointer into reasons */
2627 char reason
[255], /* Reason string */
2628 *rptr
; /* Pointer into reason */
2631 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2632 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2634 if (s
[0] == '-' || s
[0] == '+')
2637 * Add/remove reasons...
2645 * Replace reasons...
2650 for (i
= 0; i
< p
->num_reasons
; i
++)
2651 _cupsStrFree(p
->reasons
[i
]);
2659 if (!strcmp(s
, "none"))
2663 * Loop through all of the reasons...
2669 * Skip leading whitespace and commas...
2672 while (isspace(*sptr
& 255) || *sptr
== ',')
2675 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2676 if (rptr
< (reason
+ sizeof(reason
) - 1))
2690 for (i
= 0; i
< p
->num_reasons
; i
++)
2691 if (!strcmp(reason
, p
->reasons
[i
]))
2694 * Found a match, so remove it...
2699 _cupsStrFree(p
->reasons
[i
]);
2701 if (i
< p
->num_reasons
)
2702 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2704 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2705 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2707 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2708 p
->job
->completed
= 0;
2710 if (strcmp(reason
, "connecting-to-device"))
2716 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2722 for (i
= 0; i
< p
->num_reasons
; i
++)
2723 if (!strcmp(reason
, p
->reasons
[i
]))
2726 if (i
>= p
->num_reasons
)
2728 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2730 cupsdLogMessage(CUPSD_LOG_ALERT
,
2731 "Too many printer-state-reasons values for %s (%d)",
2736 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2740 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2741 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2743 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2744 p
->job
->completed
= 1;
2746 if (strcmp(reason
, "connecting-to-device"))
2757 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2761 cupsdSetPrinterState(
2762 cupsd_printer_t
*p
, /* I - Printer to change */
2763 ipp_pstate_t s
, /* I - New state */
2764 int update
) /* I - Update printers.conf? */
2766 cupsd_job_t
*job
; /* Current job */
2767 ipp_pstate_t old_state
; /* Old printer state */
2768 static const char * const printer_states
[] =
2769 { /* State strings */
2777 * Set the new state...
2780 old_state
= p
->state
;
2785 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2786 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2787 "%s \"%s\" state changed to %s.",
2788 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2789 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2792 * Let the browse code know this needs to be updated...
2795 p
->state_time
= time(NULL
);
2799 * Set/clear the paused reason as needed...
2802 if (s
== IPP_PRINTER_STOPPED
)
2803 cupsdSetPrinterReasons(p
, "+paused");
2805 cupsdSetPrinterReasons(p
, "-paused");
2809 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2811 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2812 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2813 !_cups_strcasecmp(job
->dest
, p
->name
))
2814 ippSetString(job
->attrs
, &job
->reasons
, 0,
2815 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2819 * Clear the message for the queue when going to processing...
2822 if (s
== IPP_PRINTER_PROCESSING
)
2823 p
->state_message
[0] = '\0';
2826 * Let the browse protocols reflect the change...
2830 cupsdRegisterPrinter(p
);
2833 * Save the printer configuration if a printer goes from idle or processing
2834 * to stopped (or visa-versa)...
2838 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2844 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2848 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2849 int update
)/* I - Update printers.conf? */
2852 * Set the printer state...
2855 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2858 * See if we have a job printing on this printer...
2861 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2862 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2863 "Job stopped due to printer being paused.");
2868 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2871 int /* O - 1 if successful, 0 otherwise */
2872 cupsdUpdatePrinterPPD(
2873 cupsd_printer_t
*p
, /* I - Printer */
2874 int num_keywords
, /* I - Number of keywords */
2875 cups_option_t
*keywords
) /* I - Keywords */
2877 int i
; /* Looping var */
2878 cups_file_t
*src
, /* Original file */
2879 *dst
; /* New file */
2880 char srcfile
[1024], /* Original filename */
2881 dstfile
[1024], /* New filename */
2882 line
[1024], /* Line from file */
2883 keystring
[41]; /* Keyword from line */
2884 cups_option_t
*keyword
; /* Current keyword */
2887 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2891 * Get the old and new PPD filenames...
2894 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2895 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2898 * Rename the old file and open the old and new...
2901 if (rename(dstfile
, srcfile
))
2903 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2904 p
->name
, strerror(errno
));
2908 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2910 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2911 srcfile
, strerror(errno
));
2912 rename(srcfile
, dstfile
);
2916 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2918 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2919 dstfile
, strerror(errno
));
2921 rename(srcfile
, dstfile
);
2926 * Copy the first line and then write out all of the keywords...
2929 if (!cupsFileGets(src
, line
, sizeof(line
)))
2931 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2932 srcfile
, strerror(errno
));
2935 rename(srcfile
, dstfile
);
2939 cupsFilePrintf(dst
, "%s\n", line
);
2941 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2943 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2944 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2948 * Then copy the rest of the PPD file, dropping any keywords we changed.
2951 while (cupsFileGets(src
, line
, sizeof(line
)))
2954 * Skip keywords we've already set...
2957 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2958 cupsGetOption(keystring
, num_keywords
, keywords
))
2962 * Otherwise write the line...
2965 cupsFilePrintf(dst
, "%s\n", line
);
2969 * Close files and return...
2980 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2984 cupsdUpdatePrinters(void)
2986 cupsd_printer_t
*p
; /* Current printer */
2990 * Loop through the printers and recreate the printer attributes
2991 * for any local printers since the policy and/or access control
2992 * stuff may have changed. Also, if browsing is disabled, remove
2993 * any remote printers...
2996 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2998 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3001 * Update the operation policy pointer...
3004 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
3005 p
->op_policy_ptr
= DefaultPolicyPtr
;
3008 * Update printer attributes...
3011 cupsdSetPrinterAttrs(p
);
3017 * 'cupsdValidateDest()' - Validate a printer/class destination.
3020 const char * /* O - Printer or class name */
3022 const char *uri
, /* I - Printer URI */
3023 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3024 cupsd_printer_t
**printer
) /* O - Printer pointer */
3026 cupsd_printer_t
*p
; /* Current printer */
3027 char localname
[1024],/* Localized hostname */
3028 *lptr
, /* Pointer into localized hostname */
3029 *sptr
, /* Pointer into server name */
3030 *rptr
, /* Pointer into resource */
3031 scheme
[32], /* Scheme portion of URI */
3032 username
[64], /* Username portion of URI */
3033 hostname
[HTTP_MAX_HOST
],
3034 /* Host portion of URI */
3035 resource
[HTTP_MAX_URI
];
3036 /* Resource portion of URI */
3037 int port
; /* Port portion of URI */
3040 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3044 * Initialize return values...
3051 *dtype
= (cups_ptype_t
)0;
3054 * Pull the hostname and resource from the URI...
3057 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3058 username
, sizeof(username
), hostname
, sizeof(hostname
),
3059 &port
, resource
, sizeof(resource
));
3062 * See if the resource is a class or printer...
3065 if (!strncmp(resource
, "/classes/", 9))
3071 rptr
= resource
+ 9;
3073 else if (!strncmp(resource
, "/printers/", 10))
3079 rptr
= resource
+ 10;
3084 * Bad resource name...
3091 * See if the printer or class name exists...
3094 p
= cupsdFindDest(rptr
);
3096 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3104 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3110 * Change localhost to the server name...
3113 if (!_cups_strcasecmp(hostname
, "localhost"))
3114 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3116 strlcpy(localname
, hostname
, sizeof(localname
));
3118 if (!_cups_strcasecmp(hostname
, ServerName
))
3121 * Localize the hostname...
3124 lptr
= strchr(localname
, '.');
3125 sptr
= strchr(ServerName
, '.');
3127 if (sptr
!= NULL
&& lptr
!= NULL
)
3130 * Strip the common domain name components...
3133 while (lptr
!= NULL
)
3135 if (!_cups_strcasecmp(lptr
, sptr
))
3141 lptr
= strchr(lptr
+ 1, '.');
3146 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3149 * Find a matching printer or class...
3152 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3154 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3155 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3156 !_cups_strcasecmp(p
->name
, rptr
))
3162 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3172 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3177 cupsdWritePrintcap(void)
3179 int i
; /* Looping var */
3180 cups_file_t
*fp
; /* Printcap file */
3181 cupsd_printer_t
*p
; /* Current printer */
3185 * See if we have a printcap file; if not, don't bother writing it.
3188 if (!Printcap
|| !*Printcap
)
3191 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3194 * Open the printcap file...
3197 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3201 * Put a comment header at the top so that users will know where the
3202 * data has come from...
3205 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3206 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3208 "# %s/printers.conf file. All changes to this file\n"
3209 "# will be lost.\n", ServerRoot
);
3212 * Write a new printcap with the current list of printers.
3215 switch (PrintcapFormat
)
3219 * Each printer is put in the file as:
3229 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3230 DefaultPrinter
->info
, ServerName
,
3231 DefaultPrinter
->name
);
3233 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3235 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3236 if (p
!= DefaultPrinter
)
3237 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3238 ServerName
, p
->name
);
3241 case PRINTCAP_PLIST
:
3243 * Each printer is written as a dictionary in a plist file.
3244 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3245 * printer-location, printer-make-and-model, printer-state,
3246 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3249 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3250 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3251 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3252 "PropertyList-1.0.dtd\">\n"
3253 "<plist version=\"1.0\">\n"
3256 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3258 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3260 cupsFilePuts(fp
, "\t<dict>\n"
3261 "\t\t<key>printer-name</key>\n"
3263 write_xml_string(fp
, p
->name
);
3264 cupsFilePuts(fp
, "</string>\n"
3265 "\t\t<key>printer-info</key>\n"
3267 write_xml_string(fp
, p
->info
);
3268 cupsFilePrintf(fp
, "</string>\n"
3269 "\t\t<key>printer-is-accepting-jobs</key>\n"
3271 "\t\t<key>printer-location</key>\n"
3272 "\t\t<string>", p
->accepting
? "true" : "false");
3273 write_xml_string(fp
, p
->location
);
3274 cupsFilePuts(fp
, "</string>\n"
3275 "\t\t<key>printer-make-and-model</key>\n"
3277 write_xml_string(fp
, p
->make_model
);
3278 cupsFilePrintf(fp
, "</string>\n"
3279 "\t\t<key>printer-state</key>\n"
3280 "\t\t<integer>%d</integer>\n"
3281 "\t\t<key>printer-state-reasons</key>\n"
3282 "\t\t<array>\n", p
->state
);
3283 for (i
= 0; i
< p
->num_reasons
; i
++)
3285 cupsFilePuts(fp
, "\t\t\t<string>");
3286 write_xml_string(fp
, p
->reasons
[i
]);
3287 cupsFilePuts(fp
, "</string>\n");
3289 cupsFilePrintf(fp
, "\t\t</array>\n"
3290 "\t\t<key>printer-type</key>\n"
3291 "\t\t<integer>%d</integer>\n"
3292 "\t\t<key>device-uri</key>\n"
3293 "\t\t<string>", p
->type
);
3294 write_xml_string(fp
, p
->sanitized_device_uri
);
3295 cupsFilePuts(fp
, "</string>\n"
3298 cupsFilePuts(fp
, "</array>\n"
3302 case PRINTCAP_SOLARIS
:
3304 * Each printer is put in the file as:
3306 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3307 * _default:use=DefaultPrinter
3309 * :bsdaddr=ServerName,Printer1:\
3310 * :description=Description:
3312 * :bsdaddr=ServerName,Printer2:\
3313 * :description=Description:
3315 * :bsdaddr=ServerName,Printer3:\
3316 * :description=Description:
3319 * :bsdaddr=ServerName,PrinterN:\
3320 * :description=Description:
3323 cupsFilePuts(fp
, "_all:all=");
3324 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3326 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3327 cupsFilePrintf(fp
, "%s%c", p
->name
,
3328 cupsArrayNext(Printers
) ? ',' : '\n');
3331 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3333 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3335 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3336 cupsFilePrintf(fp
, "%s:\\\n"
3337 "\t:bsdaddr=%s,%s:\\\n"
3338 "\t:description=%s:\n",
3339 p
->name
, ServerName
, p
->name
,
3340 p
->info
? p
->info
: "");
3353 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3357 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3359 int i
; /* Looping var */
3360 int num_options
; /* Number of default options */
3361 cups_option_t
*options
, /* Default options */
3362 *option
; /* Current option */
3363 char name
[256]; /* name-default */
3367 * Maintain a common array of default attribute names...
3370 if (!CommonDefaults
)
3372 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3374 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3375 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3376 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3377 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3378 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-accounting-user-id-default"));
3379 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3380 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3381 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3382 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3383 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3384 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-lease-duration-default"));
3385 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-events-default"));
3386 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3387 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("orientation-requested-default"));
3388 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("print-quality-default"));
3392 * Add all of the default options from the .conf files...
3395 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3399 if (strcmp(option
->name
, "ipp-options") &&
3400 strcmp(option
->name
, "job-sheets") &&
3401 strcmp(option
->name
, "lease-duration"))
3403 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3404 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3406 if (!cupsArrayFind(CommonDefaults
, name
))
3407 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3412 * Convert options to IPP attributes...
3415 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3416 cupsFreeOptions(num_options
, options
);
3419 * Add standard -default attributes as needed...
3422 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3423 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3426 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3427 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3428 "document-format-default", NULL
, "application/octet-stream");
3430 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3431 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3432 "job-cancel-after-default", MaxJobTime
);
3434 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3435 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3436 "job-hold-until-default", NULL
, "no-hold");
3438 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3439 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3440 "job-priority-default", 50);
3442 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3443 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3444 "number-up-default", 1);
3446 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3447 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3448 "notify-lease-duration-default", DefaultLeaseDuration
);
3450 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3451 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3452 "notify-events-default", NULL
, "job-completed");
3454 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3455 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3456 "orientation-requested-default", NULL
, NULL
);
3458 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3459 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3460 "print-quality-default", IPP_QUALITY_NORMAL
);
3465 * 'add_printer_filter()' - Add a MIME filter for a printer.
3470 cupsd_printer_t
*p
, /* I - Printer to add to */
3471 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3472 const char *filter
) /* I - Filter to add */
3474 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3475 type
[MIME_MAX_TYPE
], /* Type for filter */
3476 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3477 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3478 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3479 /* Destination super/type */
3480 program
[1024]; /* Program/filter name */
3481 int cost
; /* Cost of filter */
3482 size_t maxsize
= 0; /* Maximum supported file size */
3483 mime_type_t
*temptype
, /* MIME type looping var */
3484 *desttype
; /* Destination MIME type */
3485 mime_filter_t
*filterptr
; /* MIME filter */
3486 char filename
[1024]; /* Full filter filename */
3489 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3490 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3491 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3492 filtertype
->type
, filter
);
3495 * Parse the filter string; it should be in one of the following formats:
3497 * source/type cost program
3498 * source/type cost maxsize(nnnn) program
3499 * source/type dest/type cost program
3500 * source/type dest/type cost maxsize(nnnn) program
3503 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3504 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3506 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3508 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3510 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3512 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3514 cupsArrayAdd(p
->dest_types
, desttype
);
3520 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3523 desttype
= filtertype
;
3527 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3533 if (!strncmp(program
, "maxsize(", 8))
3535 char *ptr
; /* Pointer into maxsize(nnnn) program */
3537 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3541 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3547 while (_cups_isspace(*ptr
))
3550 _cups_strcpy(program
, ptr
);
3554 * Check permissions on the filter and its containing directory...
3557 if (strcmp(program
, "-"))
3559 if (program
[0] == '/')
3560 strlcpy(filename
, program
, sizeof(filename
));
3562 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3564 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3565 cupsdLogFCMessage
, p
);
3569 * Add the filter to the MIME database, supporting wildcards as needed...
3572 for (temptype
= mimeFirstType(MimeDatabase
);
3574 temptype
= mimeNextType(MimeDatabase
))
3575 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3576 !_cups_strcasecmp(temptype
->super
, super
)) &&
3577 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3579 if (desttype
!= filtertype
)
3581 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3582 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3583 "%s", p
->name
, temptype
->super
, temptype
->type
,
3584 desttype
->super
, desttype
->type
,
3586 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3589 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3591 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3592 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3593 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3594 filtertype
->super
, filtertype
->type
);
3595 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3600 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3601 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3602 "%s", p
->name
, temptype
->super
, temptype
->type
,
3603 filtertype
->super
, filtertype
->type
,
3605 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3610 filterptr
->maxsize
= maxsize
;
3616 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3620 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3622 int i
; /* Looping var */
3623 mime_type_t
*type
; /* Current MIME type */
3624 cups_array_t
*filters
; /* Filters */
3625 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3626 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3627 /* MIME type name */
3631 * Raw (and remote) queues advertise all of the supported MIME
3635 cupsArrayDelete(p
->filetypes
);
3636 p
->filetypes
= NULL
;
3640 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3641 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3642 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3647 * Otherwise, loop through the supported MIME types and see if there
3648 * are filters for them...
3651 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3652 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3654 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3656 for (type
= mimeFirstType(MimeDatabase
);
3658 type
= mimeNextType(MimeDatabase
))
3660 if (!_cups_strcasecmp(type
->super
, "printer"))
3663 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3665 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3667 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3668 "add_printer_formats: %s: %s needs %d filters",
3669 p
->name
, mimetype
, cupsArrayCount(filters
));
3671 cupsArrayDelete(filters
);
3672 cupsArrayAdd(p
->filetypes
, type
);
3675 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3676 "add_printer_formats: %s: %s not supported",
3681 * Add the file formats that can be filtered...
3684 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3685 !cupsArrayFind(p
->filetypes
, type
))
3690 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3691 "add_printer_formats: %s: %d supported types",
3692 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3694 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3695 "document-format-supported",
3696 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3699 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3701 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3703 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3705 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3707 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3710 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3712 char pdl
[1024]; /* Buffer to build pdl list */
3713 mime_filter_t
*filter
; /* MIME filter looping var */
3717 * We only support raw printing if this is not a Tioga PrintJobMgr based
3718 * queue and if application/octet-stream is a known type...
3721 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3723 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3725 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3731 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3732 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3735 * Then list a bunch of formats that are supported by the printer...
3738 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3740 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3742 if (!_cups_strcasecmp(type
->super
, "application"))
3744 if (!_cups_strcasecmp(type
->type
, "pdf"))
3745 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3746 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3747 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3749 else if (!_cups_strcasecmp(type
->super
, "image"))
3751 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3752 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3753 else if (!_cups_strcasecmp(type
->type
, "png"))
3754 strlcat(pdl
, "image/png,", sizeof(pdl
));
3755 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3756 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3761 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3763 cupsdSetString(&p
->pdl
, pdl
);
3765 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3770 * 'compare_printers()' - Compare two printers.
3773 static int /* O - Result of comparison */
3774 compare_printers(void *first
, /* I - First printer */
3775 void *second
, /* I - Second printer */
3776 void *data
) /* I - App data (not used) */
3780 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3781 ((cupsd_printer_t
*)second
)->name
));
3786 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3790 delete_printer_filters(
3791 cupsd_printer_t
*p
) /* I - Printer to remove from */
3793 mime_filter_t
*filter
; /* MIME filter looping var */
3794 mime_type_t
*type
; /* Destination types for filters */
3798 * Range check input...
3805 * Remove all filters from the MIME database that have a destination
3806 * type == printer...
3809 for (filter
= mimeFirstFilter(MimeDatabase
);
3811 filter
= mimeNextFilter(MimeDatabase
))
3812 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3813 cupsArrayFind(p
->dest_types
, filter
->dst
))
3816 * Delete the current filter...
3819 mimeDeleteFilter(MimeDatabase
, filter
);
3822 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3824 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3825 mimeDeleteType(MimeDatabase
, type
);
3827 cupsArrayDelete(p
->dest_types
);
3828 p
->dest_types
= NULL
;
3830 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3831 ",cups-missing-filter-warning");
3836 * 'dirty_printer()' - Mark config and state files dirty for the specified
3841 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3843 if (p
->type
& CUPS_PRINTER_CLASS
)
3844 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3846 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3848 if (PrintcapFormat
== PRINTCAP_PLIST
)
3849 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3854 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3858 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3860 int i
, j
, k
; /* Looping vars */
3861 char cache_name
[1024]; /* Cache filename */
3862 struct stat cache_info
; /* Cache file info */
3863 ppd_file_t
*ppd
; /* PPD file */
3864 char ppd_name
[1024]; /* PPD filename */
3865 struct stat ppd_info
; /* PPD file info */
3866 char strings_name
[1024]; /* Strings filename */
3867 int num_media
; /* Number of media options */
3868 ppd_size_t
*size
; /* Current PPD size */
3869 ppd_option_t
*duplex
, /* Duplex option */
3870 *output_bin
, /* OutputBin option */
3871 *output_mode
, /* OutputMode option */
3872 *resolution
; /* (Set|JCL|)Resolution option */
3873 ppd_choice_t
*choice
, /* Current PPD choice */
3874 *input_slot
, /* Current input slot */
3875 *media_type
; /* Current media type */
3876 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3877 int xdpi
, /* Horizontal resolution */
3878 ydpi
; /* Vertical resolution */
3879 const char *resptr
; /* Pointer into resolution keyword */
3880 pwg_size_t
*pwgsize
; /* Current PWG size */
3881 pwg_map_t
*pwgsource
, /* Current PWG source */
3882 *pwgtype
; /* Current PWG type */
3883 ipp_attribute_t
*attr
; /* Attribute data */
3884 _ipp_value_t
*val
; /* Attribute value */
3885 int num_finishings
, /* Number of finishings */
3886 finishings
[100]; /* finishings-supported values */
3887 int num_qualities
, /* Number of print-quality values */
3888 qualities
[3]; /* print-quality values */
3889 int num_margins
, /* Number of media-*-margin-supported values */
3890 margins
[16]; /* media-*-margin-supported values */
3891 const char *filter
, /* Current filter */
3892 *mandatory
; /* Current mandatory attribute */
3893 static const char * const pwg_raster_document_types
[] =
3899 static const char * const sides
[3] = /* sides-supported values */
3902 "two-sided-long-edge",
3903 "two-sided-short-edge"
3905 static const char * const standard_commands
[] =
3906 { /* Standard CUPS commands */
3914 * Check to see if the cache is up-to-date...
3917 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3918 if (stat(cache_name
, &cache_info
))
3919 cache_info
.st_mtime
= 0;
3921 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3922 if (stat(ppd_name
, &ppd_info
))
3923 ppd_info
.st_mtime
= 1;
3925 snprintf(strings_name
, sizeof(strings_name
), "%s/%s.strings", CacheDir
, p
->name
);
3927 ippDelete(p
->ppd_attrs
);
3928 p
->ppd_attrs
= NULL
;
3930 _ppdCacheDestroy(p
->pc
);
3933 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3935 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3937 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3941 * Loaded successfully!
3949 * Reload PPD attributes from disk...
3952 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3954 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3956 cupsdClearString(&(p
->make_model
));
3958 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3959 p
->type
|= CUPS_PRINTER_BW
;
3961 finishings
[0] = IPP_FINISHINGS_NONE
;
3964 p
->ppd_attrs
= ippNew();
3966 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3969 * Add make/model and other various attributes...
3972 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3975 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3976 ppd_name
, cupsLastErrorString());
3978 ppdMarkDefaults(ppd
);
3980 if (ppd
->color_device
)
3981 p
->type
|= CUPS_PRINTER_COLOR
;
3982 if (ppd
->variable_sizes
)
3983 p
->type
|= CUPS_PRINTER_VARIABLE
;
3984 if (!ppd
->manual_copies
)
3985 p
->type
|= CUPS_PRINTER_COPIES
;
3986 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3987 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3988 p
->type
|= CUPS_PRINTER_FAX
;
3990 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3992 if (p
->pc
&& p
->pc
->charge_info_uri
)
3993 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3994 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3996 if (p
->pc
&& p
->pc
->account_id
)
3997 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
4000 if (p
->pc
&& p
->pc
->accounting_user_id
)
4001 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4002 "job-accounting-user-id-supported", 1);
4004 if (p
->pc
&& p
->pc
->password
)
4006 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4007 "job-password-encryption-supported", NULL
, "none");
4008 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4009 "job-password-supported", (int)strlen(p
->pc
->password
));
4012 if (ppd
->throughput
)
4014 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4015 "pages-per-minute", ppd
->throughput
);
4016 if (ppd
->color_device
)
4017 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4018 "pages-per-minute-color", ppd
->throughput
);
4023 * When there is no speed information, just say "1 page per minute".
4026 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4027 "pages-per-minute", 1);
4028 if (ppd
->color_device
)
4029 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4030 "pages-per-minute-color", 1);
4033 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
4034 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
4038 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4040 if (ppdFindChoice(output_mode
, "draft") ||
4041 ppdFindChoice(output_mode
, "fast"))
4042 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4044 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4046 if (ppdFindChoice(output_mode
, "best") ||
4047 ppdFindChoice(output_mode
, "high"))
4048 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4050 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4054 if (strstr(ppd_attr
->spec
, "draft") ||
4055 strstr(ppd_attr
->spec
, "Draft"))
4057 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4061 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4064 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4065 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4068 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4070 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4071 "print-quality-supported", num_qualities
, qualities
);
4076 * The NickName can be localized in the character set specified
4077 * by the LanugageEncoding attribute. However, ppdOpen2() has
4078 * already converted the ppd->nickname member to UTF-8 for us
4079 * (the original attribute value is available separately)
4082 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4084 else if (ppd
->modelname
)
4087 * Model name can only contain specific characters...
4090 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4093 cupsdSetString(&p
->make_model
, "Bad PPD File");
4095 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4096 "printer-make-and-model", NULL
, p
->make_model
);
4098 if (p
->pc
&& p
->pc
->strings
)
4099 _cupsMessageSave(strings_name
, _CUPS_MESSAGE_STRINGS
, p
->pc
->strings
);
4101 if (!access(strings_name
, R_OK
))
4102 cupsdSetString(&p
->strings
, strings_name
);
4104 cupsdClearString(&p
->strings
);
4107 * Add media options from the PPD file...
4110 if (ppd
->num_sizes
== 0 || !p
->pc
)
4112 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4113 cupsdLogMessage(CUPSD_LOG_CRIT
,
4114 "The PPD file for printer %s contains no media "
4115 "options and is therefore invalid.", p
->name
);
4117 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4118 "media-default", NULL
, "unknown");
4119 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4120 "media-supported", NULL
, "unknown");
4128 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4129 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4133 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4134 "media-default", NULL
,
4135 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4143 ipp_t
*col
; /* Collection value */
4145 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4146 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4147 col
= new_media_col(pwgsize
,
4148 input_slot
? _ppdCacheGetSource(p
->pc
, input_slot
->choice
) : NULL
,
4149 media_type
? _ppdCacheGetType(p
->pc
, media_type
->choice
) : NULL
);
4151 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default", col
);
4159 num_media
= p
->pc
->num_sizes
;
4160 if (p
->pc
->custom_min_keyword
)
4163 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4164 "media-supported", num_media
, NULL
,
4169 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4171 i
--, pwgsize
++, val
++)
4172 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4174 if (p
->pc
->custom_min_keyword
)
4176 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4178 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4183 * media-size-supported
4186 num_media
= p
->pc
->num_sizes
;
4187 if (p
->pc
->custom_min_keyword
)
4190 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4191 "media-size-supported", num_media
,
4196 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4198 i
--, pwgsize
++, val
++)
4200 val
->collection
= ippNew();
4201 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4202 "x-dimension", pwgsize
->width
);
4203 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4204 "y-dimension", pwgsize
->length
);
4207 if (p
->pc
->custom_min_keyword
)
4209 val
->collection
= ippNew();
4210 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4211 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4212 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4213 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4218 * media-source-supported
4221 if (p
->pc
->num_sources
> 0 &&
4222 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4223 "media-source-supported", p
->pc
->num_sources
,
4224 NULL
, NULL
)) != NULL
)
4226 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4229 i
--, pwgsource
++, val
++)
4230 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4234 * media-type-supported
4237 if (p
->pc
->num_types
> 0 &&
4238 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4239 "media-type-supported", p
->pc
->num_types
,
4240 NULL
, NULL
)) != NULL
)
4242 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4245 i
--, pwgtype
++, val
++)
4246 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4250 * media-*-margin-supported
4253 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4254 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4257 for (j
= 0; j
< num_margins
; j
++)
4258 if (pwgsize
->bottom
== margins
[j
])
4261 if (j
>= num_margins
)
4263 margins
[num_margins
] = pwgsize
->bottom
;
4268 if (num_margins
> 0)
4269 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4270 "media-bottom-margin-supported", num_margins
, margins
);
4272 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4273 "media-bottom-margin-supported", 0);
4275 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4276 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4279 for (j
= 0; j
< num_margins
; j
++)
4280 if (pwgsize
->left
== margins
[j
])
4283 if (j
>= num_margins
)
4285 margins
[num_margins
] = pwgsize
->left
;
4290 if (num_margins
> 0)
4291 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4292 "media-left-margin-supported", num_margins
, margins
);
4294 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4295 "media-left-margin-supported", 0);
4297 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4298 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4301 for (j
= 0; j
< num_margins
; j
++)
4302 if (pwgsize
->right
== margins
[j
])
4305 if (j
>= num_margins
)
4307 margins
[num_margins
] = pwgsize
->right
;
4312 if (num_margins
> 0)
4313 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4314 "media-right-margin-supported", num_margins
, margins
);
4316 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4317 "media-right-margin-supported", 0);
4319 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4320 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4323 for (j
= 0; j
< num_margins
; j
++)
4324 if (pwgsize
->top
== margins
[j
])
4327 if (j
>= num_margins
)
4329 margins
[num_margins
] = pwgsize
->top
;
4334 if (num_margins
> 0)
4335 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4336 "media-top-margin-supported", num_margins
, margins
);
4338 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4339 "media-top-margin-supported", 0);
4342 * media-col-database
4345 num_media
= p
->pc
->num_sizes
;
4346 if (p
->pc
->num_sources
)
4348 if (p
->pc
->num_types
> 0)
4349 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4352 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4354 else if (p
->pc
->num_types
)
4355 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4357 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4358 "media-col-database", num_media
,
4361 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4366 * Start by adding the page size without source or type...
4369 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4371 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4375 * Then add the specific, supported combinations of size, source, and
4379 if (p
->pc
->num_sources
> 0)
4381 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4385 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4387 if (p
->pc
->num_types
> 0)
4389 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4393 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4395 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4401 else if (!ppdConflicts(ppd
))
4403 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4408 else if (p
->pc
->num_types
> 0)
4410 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4414 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4416 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4424 * Update the number of media-col-database values...
4427 attr
->num_values
= val
- attr
->values
;
4435 if (p
->pc
&& p
->pc
->num_bins
> 0)
4437 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4438 "output-bin-supported", p
->pc
->num_bins
,
4443 for (i
= 0, val
= attr
->values
;
4444 i
< p
->pc
->num_bins
;
4446 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4449 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4451 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4452 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4455 if (i
>= p
->pc
->num_bins
)
4458 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4459 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4462 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4463 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4465 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4467 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4468 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4469 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4470 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4473 * Report that this printer has a single output bin that leaves pages face
4477 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4478 "output-bin-supported", NULL
, "face-up");
4479 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4480 "output-bin-default", NULL
, "face-up");
4484 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4485 "output-bin-supported", NULL
, "face-down");
4486 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4487 "output-bin-default", NULL
, "face-down");
4491 * print-color-mode...
4494 if (ppd
->color_device
)
4496 static const char * const color_modes
[] =
4502 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4503 "print-color-mode-supported", 2, NULL
, color_modes
);
4504 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4505 "print-color-mode-default", NULL
, "color");
4506 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4510 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4511 "print-color-mode-supported", NULL
, "monochrome");
4512 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4513 "print-color-mode-default", NULL
, "monochrome");
4514 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4518 * Mandatory job attributes, if any...
4521 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4523 int count
= cupsArrayCount(p
->pc
->mandatory
);
4524 /* Number of mandatory attributes */
4526 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4527 "printer-mandatory-job-attributes", count
, NULL
,
4530 for (val
= attr
->values
,
4531 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4533 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4534 val
->string
.text
= _cupsStrAlloc(mandatory
);
4538 * Printer resolutions...
4541 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4542 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4543 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4544 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4549 * Report all supported resolutions...
4552 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4554 for (i
= 0, choice
= resolution
->choices
;
4555 i
< resolution
->num_choices
;
4558 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4559 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4560 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4562 if (xdpi
<= 0 || ydpi
<= 0)
4564 cupsdLogMessage(CUPSD_LOG_WARN
,
4565 "Bad resolution \"%s\" for printer %s.",
4566 choice
->choice
, p
->name
);
4570 attr
->values
[i
].resolution
.xres
= xdpi
;
4571 attr
->values
[i
].resolution
.yres
= ydpi
;
4572 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4575 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4578 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4581 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4585 * Just the DefaultResolution to report...
4588 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4589 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4592 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4597 if (xdpi
<= 0 || ydpi
<= 0)
4599 cupsdLogMessage(CUPSD_LOG_WARN
,
4600 "Bad default resolution \"%s\" for printer %s.",
4601 ppd_attr
->value
, p
->name
);
4605 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4606 "printer-resolution-default", IPP_RES_PER_INCH
,
4608 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4609 "printer-resolution-supported", IPP_RES_PER_INCH
,
4611 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4616 * No resolutions in PPD - make one up...
4619 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4620 "printer-resolution-default", IPP_RES_PER_INCH
,
4622 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4623 "printer-resolution-supported", IPP_RES_PER_INCH
,
4625 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4632 ppdMarkDefaults(ppd
);
4634 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4635 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4636 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4637 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4638 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4640 if (duplex
&& duplex
->num_choices
> 1 &&
4641 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4643 p
->type
|= CUPS_PRINTER_DUPLEX
;
4645 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4647 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4648 "sides-supported", 3, NULL
, sides
);
4650 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4651 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4652 "sides-default", NULL
, "two-sided-short-edge");
4653 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4654 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4655 "sides-default", NULL
, "two-sided-long-edge");
4657 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4658 "sides-default", NULL
, "one-sided");
4662 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4663 "sides-supported", NULL
, "one-sided");
4664 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4665 "sides-default", NULL
, "one-sided");
4668 if (ppdFindOption(ppd
, "Collate") != NULL
)
4669 p
->type
|= CUPS_PRINTER_COLLATE
;
4671 if (p
->pc
&& p
->pc
->finishings
)
4673 _pwg_finishings_t
*fin
; /* Current finishing value */
4675 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4677 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4678 finishings
[num_finishings
++] = fin
->value
;
4682 case IPP_FINISHINGS_BIND
:
4683 case IPP_FINISHINGS_BIND_LEFT
:
4684 case IPP_FINISHINGS_BIND_TOP
:
4685 case IPP_FINISHINGS_BIND_RIGHT
:
4686 case IPP_FINISHINGS_BIND_BOTTOM
:
4687 case IPP_FINISHINGS_EDGE_STITCH
:
4688 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4689 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4690 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4691 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4692 p
->type
|= CUPS_PRINTER_BIND
;
4695 case IPP_FINISHINGS_COVER
:
4696 p
->type
|= CUPS_PRINTER_COVER
;
4699 case IPP_FINISHINGS_PUNCH
:
4700 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4701 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4702 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4703 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4704 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4705 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4706 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4707 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4708 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4709 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4710 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4711 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4712 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4713 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4714 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4715 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4716 p
->type
|= CUPS_PRINTER_PUNCH
;
4719 case IPP_FINISHINGS_STAPLE
:
4720 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4721 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4722 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4723 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4724 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4725 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4726 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4727 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4728 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4729 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4730 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4731 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4732 p
->type
|= CUPS_PRINTER_STAPLE
;
4741 if (p
->pc
&& p
->pc
->templates
)
4743 const char *template; /* Finishing template */
4744 ipp_attribute_t
*fin_col_db
; /* finishings-col-database attribute */
4745 ipp_t
*fin_col
; /* finishings-col value */
4747 fin_col_db
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
, "finishings-col-database", cupsArrayCount(p
->pc
->templates
), NULL
);
4748 for (i
= 0, template = (const char *)cupsArrayFirst(p
->pc
->templates
); template; i
++, template = (const char *)cupsArrayNext(p
->pc
->templates
))
4751 ippAddString(fin_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, template);
4752 ippSetCollection(p
->ppd_attrs
, &fin_col_db
, i
, fin_col
);
4757 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4758 if (ppd
->sizes
[i
].length
> 1728)
4759 p
->type
|= CUPS_PRINTER_LARGE
;
4760 else if (ppd
->sizes
[i
].length
> 1008)
4761 p
->type
|= CUPS_PRINTER_MEDIUM
;
4763 p
->type
|= CUPS_PRINTER_SMALL
;
4765 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4766 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4768 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4769 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4770 p
->type
|= CUPS_PRINTER_SCANNER
;
4772 p
->type
|= CUPS_PRINTER_MFP
;
4776 * Scan the filters in the PPD file...
4781 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4783 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4785 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4786 _cups_isspace(filter
[28]))
4788 p
->type
|= CUPS_PRINTER_COMMANDS
;
4794 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4796 char *commands
, /* Copy of commands */
4797 *start
, /* Start of name */
4798 *end
; /* End of name */
4799 int count
; /* Number of commands */
4801 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4803 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4805 while (_cups_isspace(*start
))
4811 while (*start
&& !isspace(*start
& 255))
4821 * Make a copy of the commands string and count how many commands there
4825 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4826 "printer-commands", count
, NULL
, NULL
);
4828 commands
= strdup(ppd_attr
->value
);
4830 for (count
= 0, start
= commands
; *start
; count
++)
4832 while (isspace(*start
& 255))
4839 while (*end
&& !isspace(*end
& 255))
4845 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4855 * Add the standard list of commands...
4858 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4860 (int)(sizeof(standard_commands
) /
4861 sizeof(standard_commands
[0])), NULL
,
4868 * No commands supported...
4871 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4872 "printer-commands", NULL
, "none");
4876 * Show current and available port monitors for this printer...
4879 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4880 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4882 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4884 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4888 if (strstr(ppd
->protocols
, "TBCP"))
4890 else if (strstr(ppd
->protocols
, "BCP"))
4894 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4895 "port-monitor-supported", i
, NULL
, NULL
);
4897 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4899 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4901 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4902 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4906 if (strstr(ppd
->protocols
, "TBCP"))
4907 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4908 else if (strstr(ppd
->protocols
, "BCP"))
4909 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4912 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4913 p
->type
|= CUPS_PRINTER_REMOTE
;
4915 #ifdef HAVE_APPLICATIONSERVICES_H
4917 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4918 * and save it as cacheDir/printername.png
4921 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4923 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4924 cupsdLogFCMessage
, p
))
4926 CGImageRef imageRef
= NULL
;/* Current icon image */
4927 CGImageRef biggestIconRef
= NULL
;
4928 /* Biggest icon image */
4929 CGImageRef closestTo128IconRef
= NULL
;
4930 /* Icon image closest to and >= 128 */
4931 CGImageSourceRef sourceRef
; /* The file's image source */
4932 char outPath
[HTTP_MAX_URI
];
4933 /* The path to the PNG file */
4934 CFURLRef outUrl
; /* The URL made from the outPath */
4935 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4936 CGImageDestinationRef destRef
; /* The image destination to write */
4937 size_t bytesPerRow
; /* The bytes per row used for resizing */
4938 CGContextRef context
; /* The CG context used for resizing */
4940 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4941 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4942 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4943 if (outUrl
&& icnsFileUrl
)
4945 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4948 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4950 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4954 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4957 * Loop through remembering the icon closest to 128 but >= 128
4958 * and then remember the largest icon.
4961 if (CGImageGetWidth(imageRef
) >= 128 &&
4962 (!closestTo128IconRef
||
4963 CGImageGetWidth(imageRef
) <
4964 CGImageGetWidth(closestTo128IconRef
)))
4966 CGImageRelease(closestTo128IconRef
);
4967 CGImageRetain(imageRef
);
4968 closestTo128IconRef
= imageRef
;
4971 if (!biggestIconRef
||
4972 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4974 CGImageRelease(biggestIconRef
);
4975 CGImageRetain(imageRef
);
4976 biggestIconRef
= imageRef
;
4980 CGImageRelease(imageRef
);
4986 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4987 * want the closest to 128, but if none are larger than 128, we want
4988 * the largest icon available.
4991 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4993 CGImageRetain(imageRef
);
4994 CGImageRelease(biggestIconRef
);
4995 if (closestTo128IconRef
)
4996 CGImageRelease(closestTo128IconRef
);
4997 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
5001 if (CGImageGetWidth(imageRef
) != 128)
5003 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
5004 CGImageGetWidth(imageRef
) * 128;
5005 context
= CGBitmapContextCreate(NULL
, 128, 128,
5006 CGImageGetBitsPerComponent(imageRef
),
5008 CGImageGetColorSpace(imageRef
),
5009 kCGImageAlphaPremultipliedFirst
);
5012 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
5014 CGImageRelease(imageRef
);
5015 imageRef
= CGBitmapContextCreateImage(context
);
5016 CGContextRelease(context
);
5020 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
5021 CGImageDestinationFinalize(destRef
);
5025 CGImageRelease(imageRef
);
5028 CFRelease(sourceRef
);
5036 CFRelease(icnsFileUrl
);
5038 #endif /* HAVE_APPLICATIONSERVICES_H */
5041 * Close the PPD and set the type...
5046 else if (!access(ppd_name
, 0))
5048 int pline
; /* PPD line number */
5049 ppd_status_t pstatus
; /* PPD load status */
5052 pstatus
= ppdLastError(&pline
);
5054 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
5056 if (pstatus
<= PPD_ALLOC_ERROR
)
5057 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
5059 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
5061 cupsdLogMessage(CUPSD_LOG_INFO
,
5062 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5067 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
5068 !strncmp(p
->device_uri
, "ipps://", 7)) &&
5069 (strstr(p
->device_uri
, "/printers/") != NULL
||
5070 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
5071 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
5072 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
5073 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
5076 * Tell the client this is really a hard-wired remote printer.
5079 p
->type
|= CUPS_PRINTER_REMOTE
;
5082 * Then set the make-and-model accordingly...
5085 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5086 "printer-make-and-model", NULL
, "Remote Printer");
5089 * Print all files directly...
5098 * Otherwise we have neither - treat this as a "dumb" printer
5099 * with no PPD file...
5102 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5103 "printer-make-and-model", NULL
, "Local Raw Printer");
5109 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5110 "finishings-supported", num_finishings
, finishings
);
5111 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5112 "finishings-default", IPP_FINISHINGS_NONE
);
5117 * Save cached PPD attributes to disk...
5120 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5122 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5127 * Remove cache files...
5130 if (cache_info
.st_mtime
)
5137 * 'new_media_col()' - Create a media-col collection value.
5140 static ipp_t
* /* O - Collection value */
5141 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5142 const char *source
, /* I - media-source value */
5143 const char *type
) /* I - media-type value */
5145 ipp_t
*media_col
, /* Collection value */
5146 *media_size
; /* media-size value */
5149 media_col
= ippNew();
5151 media_size
= ippNew();
5152 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5153 "x-dimension", size
->width
);
5154 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5155 "y-dimension", size
->length
);
5156 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5157 ippDelete(media_size
);
5159 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5160 "media-bottom-margin", size
->bottom
);
5161 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5162 "media-left-margin", size
->left
);
5163 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5164 "media-right-margin", size
->right
);
5165 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5166 "media-top-margin", size
->top
);
5169 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5173 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5181 * 'write_xml_string()' - Write a string with XML escaping.
5185 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5186 const char *s
) /* I - String to write */
5188 const char *start
; /* Start of current sequence */
5194 for (start
= s
; *s
; s
++)
5199 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5201 cupsFilePuts(fp
, "&");
5207 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5209 cupsFilePuts(fp
, "<");
5215 cupsFilePuts(fp
, start
);