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 */
2264 * Make sure that we have the common attributes defined...
2268 cupsdCreateCommonData();
2270 _cupsRWLockWrite(&p
->lock
);
2273 * Clear out old filters, if any...
2276 delete_printer_filters(p
);
2279 * Figure out the authentication that is required for the printer.
2282 auth_supported
= "requesting-user-name";
2284 if (p
->type
& CUPS_PRINTER_CLASS
)
2285 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2287 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2289 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2290 auth
->type
== CUPSD_AUTH_NONE
)
2291 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2295 int auth_type
; /* Authentication type */
2298 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2299 auth_type
= cupsdDefaultAuthType();
2301 if (auth_type
== CUPSD_AUTH_BASIC
)
2302 auth_supported
= "basic";
2304 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2305 auth_supported
= "negotiate";
2306 #endif /* HAVE_GSSAPI */
2308 if (auth_type
!= CUPSD_AUTH_NONE
)
2309 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2311 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2314 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2317 * Create the required IPP attributes for a printer...
2320 oldattrs
= p
->attrs
;
2321 p
->attrs
= ippNew();
2323 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2324 "uri-authentication-supported", NULL
, auth_supported
);
2325 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2326 "uri-security-supported", NULL
, "none");
2328 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-id", p
->printer_id
);
2329 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2331 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2332 NULL
, p
->location
? p
->location
: "");
2333 if (p
->geo_location
)
2334 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2336 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2337 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2338 NULL
, p
->info
? p
->info
: "");
2339 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2340 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2341 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2343 if (cupsArrayCount(p
->users
) > 0)
2346 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2347 "requesting-user-name-denied",
2348 cupsArrayCount(p
->users
), NULL
, NULL
);
2350 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2351 "requesting-user-name-allowed",
2352 cupsArrayCount(p
->users
), NULL
, NULL
);
2354 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2356 i
++, name
= (char *)cupsArrayNext(p
->users
))
2357 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2360 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2361 "job-quota-period", p
->quota_period
);
2362 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2363 "job-k-limit", p
->k_limit
);
2364 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2365 "job-page-limit", p
->page_limit
);
2366 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2367 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2368 "auth-info-required", p
->num_auth_info_required
, NULL
,
2369 p
->auth_info_required
);
2371 if (cupsArrayCount(Banners
) > 0)
2374 * Setup the job-sheets-default attribute...
2377 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2378 "job-sheets-default", 2, NULL
, NULL
);
2382 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2383 Classification
: p
->job_sheets
[0]);
2384 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2385 Classification
: p
->job_sheets
[1]);
2393 * Assign additional attributes depending on whether this is a printer
2397 if (p
->type
& CUPS_PRINTER_CLASS
)
2400 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2403 * Add class-specific attributes...
2406 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2407 "printer-make-and-model", NULL
, "Local Printer Class");
2408 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2409 "file:///dev/null");
2411 if (p
->num_printers
> 0)
2414 * Add a list of member names; URIs are added in copy_printer_attrs...
2417 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2418 "member-names", p
->num_printers
, NULL
, NULL
);
2419 p
->type
|= CUPS_PRINTER_OPTIONS
;
2421 for (i
= 0; i
< p
->num_printers
; i
++)
2424 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2426 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2433 * Add printer-specific attributes...
2436 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2437 p
->sanitized_device_uri
);
2440 * Assign additional attributes from the PPD file (if any)...
2446 * Add filters for printer...
2449 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2450 "cups-insecure-filter-warning");
2452 if (p
->pc
&& p
->pc
->filters
)
2454 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2456 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2457 add_printer_filter(p
, p
->filetype
, filter
);
2459 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2462 * Add a filter from application/vnd.cups-raw to printer/name to
2463 * handle "raw" printing by users.
2466 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2469 * Add a PostScript filter, since this is still possibly PS printer.
2472 add_printer_filter(p
, p
->filetype
,
2473 "application/vnd.cups-postscript 0 -");
2476 if (p
->pc
&& p
->pc
->prefilters
)
2478 if (!p
->prefiltertype
)
2479 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2481 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2483 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2484 add_printer_filter(p
, p
->prefiltertype
, filter
);
2489 * Copy marker attributes as needed...
2494 ipp_attribute_t
*oldattr
; /* Old attribute */
2497 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2498 IPP_TAG_NAME
)) != NULL
)
2500 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2501 "marker-colors", oldattr
->num_values
, NULL
,
2504 for (i
= 0; i
< oldattr
->num_values
; i
++)
2505 attr
->values
[i
].string
.text
=
2506 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2510 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2511 IPP_TAG_INTEGER
)) != NULL
)
2513 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2514 "marker-levels", oldattr
->num_values
,
2517 for (i
= 0; i
< oldattr
->num_values
; i
++)
2518 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2522 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2523 IPP_TAG_TEXT
)) != NULL
)
2524 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2525 NULL
, oldattr
->values
[0].string
.text
);
2527 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2528 IPP_TAG_INTEGER
)) != NULL
)
2530 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2531 "marker-low-levels", oldattr
->num_values
,
2534 for (i
= 0; i
< oldattr
->num_values
; i
++)
2535 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2539 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2540 IPP_TAG_INTEGER
)) != NULL
)
2542 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2543 "marker-high-levels", oldattr
->num_values
,
2546 for (i
= 0; i
< oldattr
->num_values
; i
++)
2547 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2551 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2552 IPP_TAG_NAME
)) != NULL
)
2554 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2555 "marker-names", oldattr
->num_values
, NULL
,
2558 for (i
= 0; i
< oldattr
->num_values
; i
++)
2559 attr
->values
[i
].string
.text
=
2560 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2564 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2565 IPP_TAG_KEYWORD
)) != NULL
)
2567 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2568 "marker-types", oldattr
->num_values
, NULL
,
2571 for (i
= 0; i
< oldattr
->num_values
; i
++)
2572 attr
->values
[i
].string
.text
=
2573 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2577 ippDelete(oldattrs
);
2581 * Force sharing off for remote queues...
2584 if (p
->type
& CUPS_PRINTER_REMOTE
)
2588 * Populate the document-format-supported attribute...
2591 add_printer_formats(p
);
2594 * Add name-default attributes...
2597 add_printer_defaults(p
);
2599 _cupsRWUnlock(&p
->lock
);
2602 * Let the browse protocols reflect the change
2605 cupsdRegisterPrinter(p
);
2610 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2613 int /* O - 1 if something changed, 0 otherwise */
2614 cupsdSetPrinterReasons(
2615 cupsd_printer_t
*p
, /* I - Printer */
2616 const char *s
) /* I - Reasons strings */
2618 int i
, /* Looping var */
2619 changed
= 0; /* Did something change? */
2620 const char *sptr
; /* Pointer into reasons */
2621 char reason
[255], /* Reason string */
2622 *rptr
; /* Pointer into reason */
2625 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2626 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2628 if (s
[0] == '-' || s
[0] == '+')
2631 * Add/remove reasons...
2639 * Replace reasons...
2644 for (i
= 0; i
< p
->num_reasons
; i
++)
2645 _cupsStrFree(p
->reasons
[i
]);
2653 if (!strcmp(s
, "none"))
2657 * Loop through all of the reasons...
2663 * Skip leading whitespace and commas...
2666 while (isspace(*sptr
& 255) || *sptr
== ',')
2669 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2670 if (rptr
< (reason
+ sizeof(reason
) - 1))
2684 for (i
= 0; i
< p
->num_reasons
; i
++)
2685 if (!strcmp(reason
, p
->reasons
[i
]))
2688 * Found a match, so remove it...
2693 _cupsStrFree(p
->reasons
[i
]);
2695 if (i
< p
->num_reasons
)
2696 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2698 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2699 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2701 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2702 p
->job
->completed
= 0;
2704 if (strcmp(reason
, "connecting-to-device"))
2710 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2716 for (i
= 0; i
< p
->num_reasons
; i
++)
2717 if (!strcmp(reason
, p
->reasons
[i
]))
2720 if (i
>= p
->num_reasons
)
2722 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2724 cupsdLogMessage(CUPSD_LOG_ALERT
,
2725 "Too many printer-state-reasons values for %s (%d)",
2730 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2734 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2735 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2737 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2738 p
->job
->completed
= 1;
2740 if (strcmp(reason
, "connecting-to-device"))
2751 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2755 cupsdSetPrinterState(
2756 cupsd_printer_t
*p
, /* I - Printer to change */
2757 ipp_pstate_t s
, /* I - New state */
2758 int update
) /* I - Update printers.conf? */
2760 cupsd_job_t
*job
; /* Current job */
2761 ipp_pstate_t old_state
; /* Old printer state */
2762 static const char * const printer_states
[] =
2763 { /* State strings */
2771 * Set the new state...
2774 old_state
= p
->state
;
2779 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2780 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2781 "%s \"%s\" state changed to %s.",
2782 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2783 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2786 * Let the browse code know this needs to be updated...
2789 p
->state_time
= time(NULL
);
2793 * Set/clear the paused reason as needed...
2796 if (s
== IPP_PRINTER_STOPPED
)
2797 cupsdSetPrinterReasons(p
, "+paused");
2799 cupsdSetPrinterReasons(p
, "-paused");
2803 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2805 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2806 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2807 !_cups_strcasecmp(job
->dest
, p
->name
))
2808 ippSetString(job
->attrs
, &job
->reasons
, 0,
2809 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2813 * Clear the message for the queue when going to processing...
2816 if (s
== IPP_PRINTER_PROCESSING
)
2817 p
->state_message
[0] = '\0';
2820 * Let the browse protocols reflect the change...
2824 cupsdRegisterPrinter(p
);
2827 * Save the printer configuration if a printer goes from idle or processing
2828 * to stopped (or visa-versa)...
2832 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2838 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2842 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2843 int update
)/* I - Update printers.conf? */
2846 * Set the printer state...
2849 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2852 * See if we have a job printing on this printer...
2855 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2856 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2857 "Job stopped due to printer being paused.");
2862 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2865 int /* O - 1 if successful, 0 otherwise */
2866 cupsdUpdatePrinterPPD(
2867 cupsd_printer_t
*p
, /* I - Printer */
2868 int num_keywords
, /* I - Number of keywords */
2869 cups_option_t
*keywords
) /* I - Keywords */
2871 int i
; /* Looping var */
2872 cups_file_t
*src
, /* Original file */
2873 *dst
; /* New file */
2874 char srcfile
[1024], /* Original filename */
2875 dstfile
[1024], /* New filename */
2876 line
[1024], /* Line from file */
2877 keystring
[41]; /* Keyword from line */
2878 cups_option_t
*keyword
; /* Current keyword */
2881 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2885 * Get the old and new PPD filenames...
2888 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2889 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2892 * Rename the old file and open the old and new...
2895 if (rename(dstfile
, srcfile
))
2897 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2898 p
->name
, strerror(errno
));
2902 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2904 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2905 srcfile
, strerror(errno
));
2906 rename(srcfile
, dstfile
);
2910 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2912 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2913 dstfile
, strerror(errno
));
2915 rename(srcfile
, dstfile
);
2920 * Copy the first line and then write out all of the keywords...
2923 if (!cupsFileGets(src
, line
, sizeof(line
)))
2925 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2926 srcfile
, strerror(errno
));
2929 rename(srcfile
, dstfile
);
2933 cupsFilePrintf(dst
, "%s\n", line
);
2935 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2937 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2938 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2942 * Then copy the rest of the PPD file, dropping any keywords we changed.
2945 while (cupsFileGets(src
, line
, sizeof(line
)))
2948 * Skip keywords we've already set...
2951 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2952 cupsGetOption(keystring
, num_keywords
, keywords
))
2956 * Otherwise write the line...
2959 cupsFilePrintf(dst
, "%s\n", line
);
2963 * Close files and return...
2974 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2978 cupsdUpdatePrinters(void)
2980 cupsd_printer_t
*p
; /* Current printer */
2984 * Loop through the printers and recreate the printer attributes
2985 * for any local printers since the policy and/or access control
2986 * stuff may have changed. Also, if browsing is disabled, remove
2987 * any remote printers...
2990 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2992 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2995 * Update the operation policy pointer...
2998 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2999 p
->op_policy_ptr
= DefaultPolicyPtr
;
3002 * Update printer attributes...
3005 cupsdSetPrinterAttrs(p
);
3011 * 'cupsdValidateDest()' - Validate a printer/class destination.
3014 const char * /* O - Printer or class name */
3016 const char *uri
, /* I - Printer URI */
3017 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
3018 cupsd_printer_t
**printer
) /* O - Printer pointer */
3020 cupsd_printer_t
*p
; /* Current printer */
3021 char localname
[1024],/* Localized hostname */
3022 *lptr
, /* Pointer into localized hostname */
3023 *sptr
, /* Pointer into server name */
3024 *rptr
, /* Pointer into resource */
3025 scheme
[32], /* Scheme portion of URI */
3026 username
[64], /* Username portion of URI */
3027 hostname
[HTTP_MAX_HOST
],
3028 /* Host portion of URI */
3029 resource
[HTTP_MAX_URI
];
3030 /* Resource portion of URI */
3031 int port
; /* Port portion of URI */
3035 * Initialize return values...
3042 *dtype
= (cups_ptype_t
)0;
3045 * Pull the hostname and resource from the URI...
3048 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3049 username
, sizeof(username
), hostname
, sizeof(hostname
),
3050 &port
, resource
, sizeof(resource
));
3053 * See if the resource is a class or printer...
3056 if (!strncmp(resource
, "/classes/", 9))
3062 rptr
= resource
+ 9;
3064 else if (!strncmp(resource
, "/printers/", 10))
3070 rptr
= resource
+ 10;
3075 * Bad resource name...
3082 * See if the printer or class name exists...
3085 p
= cupsdFindDest(rptr
);
3087 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3095 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3101 * Change localhost to the server name...
3104 if (!_cups_strcasecmp(hostname
, "localhost"))
3105 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3107 strlcpy(localname
, hostname
, sizeof(localname
));
3109 if (!_cups_strcasecmp(hostname
, ServerName
))
3112 * Localize the hostname...
3115 lptr
= strchr(localname
, '.');
3116 sptr
= strchr(ServerName
, '.');
3118 if (sptr
!= NULL
&& lptr
!= NULL
)
3121 * Strip the common domain name components...
3124 while (lptr
!= NULL
)
3126 if (!_cups_strcasecmp(lptr
, sptr
))
3132 lptr
= strchr(lptr
+ 1, '.');
3138 * Find a matching printer or class...
3141 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3143 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3144 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3145 !_cups_strcasecmp(p
->name
, rptr
))
3151 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3161 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3166 cupsdWritePrintcap(void)
3168 int i
; /* Looping var */
3169 cups_file_t
*fp
; /* Printcap file */
3170 cupsd_printer_t
*p
; /* Current printer */
3174 * See if we have a printcap file; if not, don't bother writing it.
3177 if (!Printcap
|| !*Printcap
)
3180 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3183 * Open the printcap file...
3186 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3190 * Put a comment header at the top so that users will know where the
3191 * data has come from...
3194 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3195 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3197 "# %s/printers.conf file. All changes to this file\n"
3198 "# will be lost.\n", ServerRoot
);
3201 * Write a new printcap with the current list of printers.
3204 switch (PrintcapFormat
)
3208 * Each printer is put in the file as:
3218 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3219 DefaultPrinter
->info
, ServerName
,
3220 DefaultPrinter
->name
);
3222 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3224 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3225 if (p
!= DefaultPrinter
)
3226 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3227 ServerName
, p
->name
);
3230 case PRINTCAP_PLIST
:
3232 * Each printer is written as a dictionary in a plist file.
3233 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3234 * printer-location, printer-make-and-model, printer-state,
3235 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3238 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3239 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3240 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3241 "PropertyList-1.0.dtd\">\n"
3242 "<plist version=\"1.0\">\n"
3245 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3247 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3249 cupsFilePuts(fp
, "\t<dict>\n"
3250 "\t\t<key>printer-name</key>\n"
3252 write_xml_string(fp
, p
->name
);
3253 cupsFilePuts(fp
, "</string>\n"
3254 "\t\t<key>printer-info</key>\n"
3256 write_xml_string(fp
, p
->info
);
3257 cupsFilePrintf(fp
, "</string>\n"
3258 "\t\t<key>printer-is-accepting-jobs</key>\n"
3260 "\t\t<key>printer-location</key>\n"
3261 "\t\t<string>", p
->accepting
? "true" : "false");
3262 write_xml_string(fp
, p
->location
);
3263 cupsFilePuts(fp
, "</string>\n"
3264 "\t\t<key>printer-make-and-model</key>\n"
3266 write_xml_string(fp
, p
->make_model
);
3267 cupsFilePrintf(fp
, "</string>\n"
3268 "\t\t<key>printer-state</key>\n"
3269 "\t\t<integer>%d</integer>\n"
3270 "\t\t<key>printer-state-reasons</key>\n"
3271 "\t\t<array>\n", p
->state
);
3272 for (i
= 0; i
< p
->num_reasons
; i
++)
3274 cupsFilePuts(fp
, "\t\t\t<string>");
3275 write_xml_string(fp
, p
->reasons
[i
]);
3276 cupsFilePuts(fp
, "</string>\n");
3278 cupsFilePrintf(fp
, "\t\t</array>\n"
3279 "\t\t<key>printer-type</key>\n"
3280 "\t\t<integer>%d</integer>\n"
3281 "\t\t<key>device-uri</key>\n"
3282 "\t\t<string>", p
->type
);
3283 write_xml_string(fp
, p
->sanitized_device_uri
);
3284 cupsFilePuts(fp
, "</string>\n"
3287 cupsFilePuts(fp
, "</array>\n"
3291 case PRINTCAP_SOLARIS
:
3293 * Each printer is put in the file as:
3295 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3296 * _default:use=DefaultPrinter
3298 * :bsdaddr=ServerName,Printer1:\
3299 * :description=Description:
3301 * :bsdaddr=ServerName,Printer2:\
3302 * :description=Description:
3304 * :bsdaddr=ServerName,Printer3:\
3305 * :description=Description:
3308 * :bsdaddr=ServerName,PrinterN:\
3309 * :description=Description:
3312 cupsFilePuts(fp
, "_all:all=");
3313 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3315 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3316 cupsFilePrintf(fp
, "%s%c", p
->name
,
3317 cupsArrayNext(Printers
) ? ',' : '\n');
3320 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3322 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3324 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3325 cupsFilePrintf(fp
, "%s:\\\n"
3326 "\t:bsdaddr=%s,%s:\\\n"
3327 "\t:description=%s:\n",
3328 p
->name
, ServerName
, p
->name
,
3329 p
->info
? p
->info
: "");
3342 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3346 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3348 int i
; /* Looping var */
3349 int num_options
; /* Number of default options */
3350 cups_option_t
*options
, /* Default options */
3351 *option
; /* Current option */
3352 char name
[256]; /* name-default */
3356 * Maintain a common array of default attribute names...
3359 if (!CommonDefaults
)
3361 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3363 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3364 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3365 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3366 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3367 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-accounting-user-id-default"));
3368 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3369 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3370 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3371 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3372 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3373 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-lease-duration-default"));
3374 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-events-default"));
3375 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3376 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("orientation-requested-default"));
3377 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("print-quality-default"));
3381 * Add all of the default options from the .conf files...
3384 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3388 if (strcmp(option
->name
, "ipp-options") &&
3389 strcmp(option
->name
, "job-sheets") &&
3390 strcmp(option
->name
, "lease-duration"))
3392 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3393 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3395 if (!cupsArrayFind(CommonDefaults
, name
))
3396 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3401 * Convert options to IPP attributes...
3404 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3405 cupsFreeOptions(num_options
, options
);
3408 * Add standard -default attributes as needed...
3411 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3412 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3415 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3416 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3417 "document-format-default", NULL
, "application/octet-stream");
3419 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3420 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3421 "job-cancel-after-default", MaxJobTime
);
3423 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3424 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3425 "job-hold-until-default", NULL
, "no-hold");
3427 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3428 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3429 "job-priority-default", 50);
3431 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3432 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3433 "number-up-default", 1);
3435 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3436 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3437 "notify-lease-duration-default", DefaultLeaseDuration
);
3439 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3440 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3441 "notify-events-default", NULL
, "job-completed");
3443 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3444 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3445 "orientation-requested-default", NULL
, NULL
);
3447 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3448 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3449 "print-quality-default", IPP_QUALITY_NORMAL
);
3454 * 'add_printer_filter()' - Add a MIME filter for a printer.
3459 cupsd_printer_t
*p
, /* I - Printer to add to */
3460 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3461 const char *filter
) /* I - Filter to add */
3463 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3464 type
[MIME_MAX_TYPE
], /* Type for filter */
3465 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3466 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3467 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3468 /* Destination super/type */
3469 program
[1024]; /* Program/filter name */
3470 int cost
; /* Cost of filter */
3471 size_t maxsize
= 0; /* Maximum supported file size */
3472 mime_type_t
*temptype
, /* MIME type looping var */
3473 *desttype
; /* Destination MIME type */
3474 mime_filter_t
*filterptr
; /* MIME filter */
3475 char filename
[1024]; /* Full filter filename */
3478 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3479 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3480 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3481 filtertype
->type
, filter
);
3484 * Parse the filter string; it should be in one of the following formats:
3486 * source/type cost program
3487 * source/type cost maxsize(nnnn) program
3488 * source/type dest/type cost program
3489 * source/type dest/type cost maxsize(nnnn) program
3492 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3493 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3495 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3497 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3499 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3501 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3503 cupsArrayAdd(p
->dest_types
, desttype
);
3509 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3512 desttype
= filtertype
;
3516 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3522 if (!strncmp(program
, "maxsize(", 8))
3524 char *ptr
; /* Pointer into maxsize(nnnn) program */
3526 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3530 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3536 while (_cups_isspace(*ptr
))
3539 _cups_strcpy(program
, ptr
);
3543 * Check permissions on the filter and its containing directory...
3546 if (strcmp(program
, "-"))
3548 if (program
[0] == '/')
3549 strlcpy(filename
, program
, sizeof(filename
));
3551 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3553 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3554 cupsdLogFCMessage
, p
);
3558 * Add the filter to the MIME database, supporting wildcards as needed...
3561 for (temptype
= mimeFirstType(MimeDatabase
);
3563 temptype
= mimeNextType(MimeDatabase
))
3564 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3565 !_cups_strcasecmp(temptype
->super
, super
)) &&
3566 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3568 if (desttype
!= filtertype
)
3570 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3571 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3572 "%s", p
->name
, temptype
->super
, temptype
->type
,
3573 desttype
->super
, desttype
->type
,
3575 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3578 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3580 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3581 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3582 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3583 filtertype
->super
, filtertype
->type
);
3584 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3589 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3590 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3591 "%s", p
->name
, temptype
->super
, temptype
->type
,
3592 filtertype
->super
, filtertype
->type
,
3594 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3599 filterptr
->maxsize
= maxsize
;
3605 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3609 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3611 int i
; /* Looping var */
3612 mime_type_t
*type
; /* Current MIME type */
3613 cups_array_t
*filters
; /* Filters */
3614 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3615 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3616 /* MIME type name */
3620 * Raw (and remote) queues advertise all of the supported MIME
3624 cupsArrayDelete(p
->filetypes
);
3625 p
->filetypes
= NULL
;
3629 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3630 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3631 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3636 * Otherwise, loop through the supported MIME types and see if there
3637 * are filters for them...
3640 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3641 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3643 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3645 for (type
= mimeFirstType(MimeDatabase
);
3647 type
= mimeNextType(MimeDatabase
))
3649 if (!_cups_strcasecmp(type
->super
, "printer"))
3652 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3654 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3656 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3657 "add_printer_formats: %s: %s needs %d filters",
3658 p
->name
, mimetype
, cupsArrayCount(filters
));
3660 cupsArrayDelete(filters
);
3661 cupsArrayAdd(p
->filetypes
, type
);
3664 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3665 "add_printer_formats: %s: %s not supported",
3670 * Add the file formats that can be filtered...
3673 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3674 !cupsArrayFind(p
->filetypes
, type
))
3679 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3680 "add_printer_formats: %s: %d supported types",
3681 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3683 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3684 "document-format-supported",
3685 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3688 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3690 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3692 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3694 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3696 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3699 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3701 char pdl
[1024]; /* Buffer to build pdl list */
3702 mime_filter_t
*filter
; /* MIME filter looping var */
3706 * We only support raw printing if this is not a Tioga PrintJobMgr based
3707 * queue and if application/octet-stream is a known type...
3710 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3712 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3714 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3720 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3721 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3724 * Then list a bunch of formats that are supported by the printer...
3727 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3729 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3731 if (!_cups_strcasecmp(type
->super
, "application"))
3733 if (!_cups_strcasecmp(type
->type
, "pdf"))
3734 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3735 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3736 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3738 else if (!_cups_strcasecmp(type
->super
, "image"))
3740 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3741 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3742 else if (!_cups_strcasecmp(type
->type
, "png"))
3743 strlcat(pdl
, "image/png,", sizeof(pdl
));
3744 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3745 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3750 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3752 cupsdSetString(&p
->pdl
, pdl
);
3754 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3759 * 'compare_printers()' - Compare two printers.
3762 static int /* O - Result of comparison */
3763 compare_printers(void *first
, /* I - First printer */
3764 void *second
, /* I - Second printer */
3765 void *data
) /* I - App data (not used) */
3769 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3770 ((cupsd_printer_t
*)second
)->name
));
3775 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3779 delete_printer_filters(
3780 cupsd_printer_t
*p
) /* I - Printer to remove from */
3782 mime_filter_t
*filter
; /* MIME filter looping var */
3783 mime_type_t
*type
; /* Destination types for filters */
3787 * Range check input...
3794 * Remove all filters from the MIME database that have a destination
3795 * type == printer...
3798 for (filter
= mimeFirstFilter(MimeDatabase
);
3800 filter
= mimeNextFilter(MimeDatabase
))
3801 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3802 cupsArrayFind(p
->dest_types
, filter
->dst
))
3805 * Delete the current filter...
3808 mimeDeleteFilter(MimeDatabase
, filter
);
3811 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3813 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3814 mimeDeleteType(MimeDatabase
, type
);
3816 cupsArrayDelete(p
->dest_types
);
3817 p
->dest_types
= NULL
;
3819 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3820 ",cups-missing-filter-warning");
3825 * 'dirty_printer()' - Mark config and state files dirty for the specified
3830 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3832 if (p
->type
& CUPS_PRINTER_CLASS
)
3833 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3835 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3837 if (PrintcapFormat
== PRINTCAP_PLIST
)
3838 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3843 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3847 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3849 int i
, j
, k
; /* Looping vars */
3850 char cache_name
[1024]; /* Cache filename */
3851 struct stat cache_info
; /* Cache file info */
3852 ppd_file_t
*ppd
; /* PPD file */
3853 char ppd_name
[1024]; /* PPD filename */
3854 struct stat ppd_info
; /* PPD file info */
3855 char strings_name
[1024]; /* Strings filename */
3856 int num_media
; /* Number of media options */
3857 ppd_size_t
*size
; /* Current PPD size */
3858 ppd_option_t
*duplex
, /* Duplex option */
3859 *output_bin
, /* OutputBin option */
3860 *output_mode
, /* OutputMode option */
3861 *resolution
; /* (Set|JCL|)Resolution option */
3862 ppd_choice_t
*choice
, /* Current PPD choice */
3863 *input_slot
, /* Current input slot */
3864 *media_type
; /* Current media type */
3865 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3866 int xdpi
, /* Horizontal resolution */
3867 ydpi
; /* Vertical resolution */
3868 const char *resptr
; /* Pointer into resolution keyword */
3869 pwg_size_t
*pwgsize
; /* Current PWG size */
3870 pwg_map_t
*pwgsource
, /* Current PWG source */
3871 *pwgtype
; /* Current PWG type */
3872 ipp_attribute_t
*attr
; /* Attribute data */
3873 _ipp_value_t
*val
; /* Attribute value */
3874 int num_finishings
, /* Number of finishings */
3875 finishings
[100]; /* finishings-supported values */
3876 int num_qualities
, /* Number of print-quality values */
3877 qualities
[3]; /* print-quality values */
3878 int num_margins
, /* Number of media-*-margin-supported values */
3879 margins
[16]; /* media-*-margin-supported values */
3880 const char *filter
, /* Current filter */
3881 *mandatory
; /* Current mandatory attribute */
3882 static const char * const pwg_raster_document_types
[] =
3888 static const char * const sides
[3] = /* sides-supported values */
3891 "two-sided-long-edge",
3892 "two-sided-short-edge"
3894 static const char * const standard_commands
[] =
3895 { /* Standard CUPS commands */
3903 * Check to see if the cache is up-to-date...
3906 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3907 if (stat(cache_name
, &cache_info
))
3908 cache_info
.st_mtime
= 0;
3910 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3911 if (stat(ppd_name
, &ppd_info
))
3912 ppd_info
.st_mtime
= 1;
3914 snprintf(strings_name
, sizeof(strings_name
), "%s/%s.strings", CacheDir
, p
->name
);
3916 ippDelete(p
->ppd_attrs
);
3917 p
->ppd_attrs
= NULL
;
3919 _ppdCacheDestroy(p
->pc
);
3922 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3924 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3926 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3930 * Loaded successfully!
3938 * Reload PPD attributes from disk...
3941 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3943 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3945 cupsdClearString(&(p
->make_model
));
3947 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3948 p
->type
|= CUPS_PRINTER_BW
;
3950 finishings
[0] = IPP_FINISHINGS_NONE
;
3953 p
->ppd_attrs
= ippNew();
3955 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3958 * Add make/model and other various attributes...
3961 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3964 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3965 ppd_name
, cupsLastErrorString());
3967 ppdMarkDefaults(ppd
);
3969 if (ppd
->color_device
)
3970 p
->type
|= CUPS_PRINTER_COLOR
;
3971 if (ppd
->variable_sizes
)
3972 p
->type
|= CUPS_PRINTER_VARIABLE
;
3973 if (!ppd
->manual_copies
)
3974 p
->type
|= CUPS_PRINTER_COPIES
;
3975 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3976 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3977 p
->type
|= CUPS_PRINTER_FAX
;
3979 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3981 if (p
->pc
&& p
->pc
->charge_info_uri
)
3982 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3983 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3985 if (p
->pc
&& p
->pc
->account_id
)
3986 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3989 if (p
->pc
&& p
->pc
->accounting_user_id
)
3990 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3991 "job-accounting-user-id-supported", 1);
3993 if (p
->pc
&& p
->pc
->password
)
3995 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3996 "job-password-encryption-supported", NULL
, "none");
3997 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3998 "job-password-supported", (int)strlen(p
->pc
->password
));
4001 if (ppd
->throughput
)
4003 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4004 "pages-per-minute", ppd
->throughput
);
4005 if (ppd
->color_device
)
4006 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4007 "pages-per-minute-color", ppd
->throughput
);
4012 * When there is no speed information, just say "1 page per minute".
4015 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4016 "pages-per-minute", 1);
4017 if (ppd
->color_device
)
4018 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4019 "pages-per-minute-color", 1);
4022 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
4023 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
4027 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4029 if (ppdFindChoice(output_mode
, "draft") ||
4030 ppdFindChoice(output_mode
, "fast"))
4031 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4033 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4035 if (ppdFindChoice(output_mode
, "best") ||
4036 ppdFindChoice(output_mode
, "high"))
4037 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4039 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4043 if (strstr(ppd_attr
->spec
, "draft") ||
4044 strstr(ppd_attr
->spec
, "Draft"))
4046 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4050 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4053 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4054 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4057 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4059 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4060 "print-quality-supported", num_qualities
, qualities
);
4065 * The NickName can be localized in the character set specified
4066 * by the LanugageEncoding attribute. However, ppdOpen2() has
4067 * already converted the ppd->nickname member to UTF-8 for us
4068 * (the original attribute value is available separately)
4071 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4073 else if (ppd
->modelname
)
4076 * Model name can only contain specific characters...
4079 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4082 cupsdSetString(&p
->make_model
, "Bad PPD File");
4084 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4085 "printer-make-and-model", NULL
, p
->make_model
);
4087 if (p
->pc
&& p
->pc
->strings
)
4088 _cupsMessageSave(strings_name
, _CUPS_MESSAGE_STRINGS
, p
->pc
->strings
);
4090 if (!access(strings_name
, R_OK
))
4091 cupsdSetString(&p
->strings
, strings_name
);
4093 cupsdClearString(&p
->strings
);
4096 * Add media options from the PPD file...
4099 if (ppd
->num_sizes
== 0 || !p
->pc
)
4101 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4102 cupsdLogMessage(CUPSD_LOG_CRIT
,
4103 "The PPD file for printer %s contains no media "
4104 "options and is therefore invalid.", p
->name
);
4106 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4107 "media-default", NULL
, "unknown");
4108 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4109 "media-supported", NULL
, "unknown");
4117 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4118 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4122 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4123 "media-default", NULL
,
4124 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4132 ipp_t
*col
; /* Collection value */
4134 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4135 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4136 col
= new_media_col(pwgsize
,
4137 input_slot
? _ppdCacheGetSource(p
->pc
, input_slot
->choice
) : NULL
,
4138 media_type
? _ppdCacheGetType(p
->pc
, media_type
->choice
) : NULL
);
4140 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default", col
);
4148 num_media
= p
->pc
->num_sizes
;
4149 if (p
->pc
->custom_min_keyword
)
4152 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4153 "media-supported", num_media
, NULL
,
4158 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4160 i
--, pwgsize
++, val
++)
4161 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4163 if (p
->pc
->custom_min_keyword
)
4165 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4167 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4172 * media-size-supported
4175 num_media
= p
->pc
->num_sizes
;
4176 if (p
->pc
->custom_min_keyword
)
4179 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4180 "media-size-supported", num_media
,
4185 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4187 i
--, pwgsize
++, val
++)
4189 val
->collection
= ippNew();
4190 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4191 "x-dimension", pwgsize
->width
);
4192 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4193 "y-dimension", pwgsize
->length
);
4196 if (p
->pc
->custom_min_keyword
)
4198 val
->collection
= ippNew();
4199 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4200 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4201 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4202 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4207 * media-source-supported
4210 if (p
->pc
->num_sources
> 0 &&
4211 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4212 "media-source-supported", p
->pc
->num_sources
,
4213 NULL
, NULL
)) != NULL
)
4215 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4218 i
--, pwgsource
++, val
++)
4219 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4223 * media-type-supported
4226 if (p
->pc
->num_types
> 0 &&
4227 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4228 "media-type-supported", p
->pc
->num_types
,
4229 NULL
, NULL
)) != NULL
)
4231 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4234 i
--, pwgtype
++, val
++)
4235 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4239 * media-*-margin-supported
4242 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4243 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4246 for (j
= 0; j
< num_margins
; j
++)
4247 if (pwgsize
->bottom
== margins
[j
])
4250 if (j
>= num_margins
)
4252 margins
[num_margins
] = pwgsize
->bottom
;
4257 if (num_margins
> 0)
4258 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4259 "media-bottom-margin-supported", num_margins
, margins
);
4261 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4262 "media-bottom-margin-supported", 0);
4264 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4265 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4268 for (j
= 0; j
< num_margins
; j
++)
4269 if (pwgsize
->left
== margins
[j
])
4272 if (j
>= num_margins
)
4274 margins
[num_margins
] = pwgsize
->left
;
4279 if (num_margins
> 0)
4280 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4281 "media-left-margin-supported", num_margins
, margins
);
4283 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4284 "media-left-margin-supported", 0);
4286 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4287 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4290 for (j
= 0; j
< num_margins
; j
++)
4291 if (pwgsize
->right
== margins
[j
])
4294 if (j
>= num_margins
)
4296 margins
[num_margins
] = pwgsize
->right
;
4301 if (num_margins
> 0)
4302 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4303 "media-right-margin-supported", num_margins
, margins
);
4305 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4306 "media-right-margin-supported", 0);
4308 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4309 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4312 for (j
= 0; j
< num_margins
; j
++)
4313 if (pwgsize
->top
== margins
[j
])
4316 if (j
>= num_margins
)
4318 margins
[num_margins
] = pwgsize
->top
;
4323 if (num_margins
> 0)
4324 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4325 "media-top-margin-supported", num_margins
, margins
);
4327 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4328 "media-top-margin-supported", 0);
4331 * media-col-database
4334 num_media
= p
->pc
->num_sizes
;
4335 if (p
->pc
->num_sources
)
4337 if (p
->pc
->num_types
> 0)
4338 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4341 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4343 else if (p
->pc
->num_types
)
4344 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4346 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4347 "media-col-database", num_media
,
4350 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4355 * Start by adding the page size without source or type...
4358 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4360 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4364 * Then add the specific, supported combinations of size, source, and
4368 if (p
->pc
->num_sources
> 0)
4370 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4374 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4376 if (p
->pc
->num_types
> 0)
4378 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4382 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4384 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4390 else if (!ppdConflicts(ppd
))
4392 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4397 else if (p
->pc
->num_types
> 0)
4399 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4403 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4405 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4413 * Update the number of media-col-database values...
4416 attr
->num_values
= val
- attr
->values
;
4424 if (p
->pc
&& p
->pc
->num_bins
> 0)
4426 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4427 "output-bin-supported", p
->pc
->num_bins
,
4432 for (i
= 0, val
= attr
->values
;
4433 i
< p
->pc
->num_bins
;
4435 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4438 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4440 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4441 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4444 if (i
>= p
->pc
->num_bins
)
4447 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4448 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4451 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4452 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4454 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4456 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4457 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4458 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4459 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4462 * Report that this printer has a single output bin that leaves pages face
4466 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4467 "output-bin-supported", NULL
, "face-up");
4468 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4469 "output-bin-default", NULL
, "face-up");
4473 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4474 "output-bin-supported", NULL
, "face-down");
4475 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4476 "output-bin-default", NULL
, "face-down");
4480 * print-color-mode...
4483 if (ppd
->color_device
)
4485 static const char * const color_modes
[] =
4491 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4492 "print-color-mode-supported", 2, NULL
, color_modes
);
4493 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4494 "print-color-mode-default", NULL
, "color");
4495 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4499 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4500 "print-color-mode-supported", NULL
, "monochrome");
4501 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4502 "print-color-mode-default", NULL
, "monochrome");
4503 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4507 * Mandatory job attributes, if any...
4510 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4512 int count
= cupsArrayCount(p
->pc
->mandatory
);
4513 /* Number of mandatory attributes */
4515 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4516 "printer-mandatory-job-attributes", count
, NULL
,
4519 for (val
= attr
->values
,
4520 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4522 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4523 val
->string
.text
= _cupsStrAlloc(mandatory
);
4527 * Printer resolutions...
4530 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4531 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4532 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4533 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4538 * Report all supported resolutions...
4541 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4543 for (i
= 0, choice
= resolution
->choices
;
4544 i
< resolution
->num_choices
;
4547 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4548 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4549 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4551 if (xdpi
<= 0 || ydpi
<= 0)
4553 cupsdLogMessage(CUPSD_LOG_WARN
,
4554 "Bad resolution \"%s\" for printer %s.",
4555 choice
->choice
, p
->name
);
4559 attr
->values
[i
].resolution
.xres
= xdpi
;
4560 attr
->values
[i
].resolution
.yres
= ydpi
;
4561 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4564 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4567 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4570 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4574 * Just the DefaultResolution to report...
4577 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4578 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4581 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4586 if (xdpi
<= 0 || ydpi
<= 0)
4588 cupsdLogMessage(CUPSD_LOG_WARN
,
4589 "Bad default resolution \"%s\" for printer %s.",
4590 ppd_attr
->value
, p
->name
);
4594 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4595 "printer-resolution-default", IPP_RES_PER_INCH
,
4597 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4598 "printer-resolution-supported", IPP_RES_PER_INCH
,
4600 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4605 * No resolutions in PPD - make one up...
4608 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4609 "printer-resolution-default", IPP_RES_PER_INCH
,
4611 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4612 "printer-resolution-supported", IPP_RES_PER_INCH
,
4614 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4621 ppdMarkDefaults(ppd
);
4623 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4624 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4625 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4626 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4627 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4629 if (duplex
&& duplex
->num_choices
> 1 &&
4630 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4632 p
->type
|= CUPS_PRINTER_DUPLEX
;
4634 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4636 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4637 "sides-supported", 3, NULL
, sides
);
4639 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4640 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4641 "sides-default", NULL
, "two-sided-short-edge");
4642 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4643 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4644 "sides-default", NULL
, "two-sided-long-edge");
4646 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4647 "sides-default", NULL
, "one-sided");
4651 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4652 "sides-supported", NULL
, "one-sided");
4653 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4654 "sides-default", NULL
, "one-sided");
4657 if (ppdFindOption(ppd
, "Collate") != NULL
)
4658 p
->type
|= CUPS_PRINTER_COLLATE
;
4660 if (p
->pc
&& p
->pc
->finishings
)
4662 _pwg_finishings_t
*fin
; /* Current finishing value */
4664 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4666 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4667 finishings
[num_finishings
++] = fin
->value
;
4671 case IPP_FINISHINGS_BIND
:
4672 case IPP_FINISHINGS_BIND_LEFT
:
4673 case IPP_FINISHINGS_BIND_TOP
:
4674 case IPP_FINISHINGS_BIND_RIGHT
:
4675 case IPP_FINISHINGS_BIND_BOTTOM
:
4676 case IPP_FINISHINGS_EDGE_STITCH
:
4677 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4678 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4679 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4680 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4681 p
->type
|= CUPS_PRINTER_BIND
;
4684 case IPP_FINISHINGS_COVER
:
4685 p
->type
|= CUPS_PRINTER_COVER
;
4688 case IPP_FINISHINGS_PUNCH
:
4689 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4690 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4691 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4692 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4693 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4694 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4695 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4696 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4697 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4698 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4699 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4700 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4701 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4702 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4703 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4704 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4705 p
->type
|= CUPS_PRINTER_PUNCH
;
4708 case IPP_FINISHINGS_STAPLE
:
4709 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4710 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4711 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4712 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4713 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4714 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4715 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4716 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4717 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4718 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4719 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4720 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4721 p
->type
|= CUPS_PRINTER_STAPLE
;
4730 if (p
->pc
&& p
->pc
->templates
)
4732 const char *template; /* Finishing template */
4733 ipp_attribute_t
*fin_col_db
; /* finishings-col-database attribute */
4734 ipp_t
*fin_col
; /* finishings-col value */
4736 fin_col_db
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
, "finishings-col-database", cupsArrayCount(p
->pc
->templates
), NULL
);
4737 for (i
= 0, template = (const char *)cupsArrayFirst(p
->pc
->templates
); template; i
++, template = (const char *)cupsArrayNext(p
->pc
->templates
))
4740 ippAddString(fin_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, template);
4741 ippSetCollection(p
->ppd_attrs
, &fin_col_db
, i
, fin_col
);
4746 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4747 if (ppd
->sizes
[i
].length
> 1728)
4748 p
->type
|= CUPS_PRINTER_LARGE
;
4749 else if (ppd
->sizes
[i
].length
> 1008)
4750 p
->type
|= CUPS_PRINTER_MEDIUM
;
4752 p
->type
|= CUPS_PRINTER_SMALL
;
4754 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4755 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4757 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4758 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4759 p
->type
|= CUPS_PRINTER_SCANNER
;
4761 p
->type
|= CUPS_PRINTER_MFP
;
4765 * Scan the filters in the PPD file...
4770 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4772 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4774 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4775 _cups_isspace(filter
[28]))
4777 p
->type
|= CUPS_PRINTER_COMMANDS
;
4783 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4785 char *commands
, /* Copy of commands */
4786 *start
, /* Start of name */
4787 *end
; /* End of name */
4788 int count
; /* Number of commands */
4790 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4792 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4794 while (_cups_isspace(*start
))
4800 while (*start
&& !isspace(*start
& 255))
4810 * Make a copy of the commands string and count how many commands there
4814 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4815 "printer-commands", count
, NULL
, NULL
);
4817 commands
= strdup(ppd_attr
->value
);
4819 for (count
= 0, start
= commands
; *start
; count
++)
4821 while (isspace(*start
& 255))
4828 while (*end
&& !isspace(*end
& 255))
4834 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4844 * Add the standard list of commands...
4847 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4849 (int)(sizeof(standard_commands
) /
4850 sizeof(standard_commands
[0])), NULL
,
4857 * No commands supported...
4860 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4861 "printer-commands", NULL
, "none");
4865 * Show current and available port monitors for this printer...
4868 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4869 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4871 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4873 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4877 if (strstr(ppd
->protocols
, "TBCP"))
4879 else if (strstr(ppd
->protocols
, "BCP"))
4883 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4884 "port-monitor-supported", i
, NULL
, NULL
);
4886 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4888 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4890 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4891 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4895 if (strstr(ppd
->protocols
, "TBCP"))
4896 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4897 else if (strstr(ppd
->protocols
, "BCP"))
4898 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4901 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4902 p
->type
|= CUPS_PRINTER_REMOTE
;
4904 #ifdef HAVE_APPLICATIONSERVICES_H
4906 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4907 * and save it as cacheDir/printername.png
4910 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4912 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4913 cupsdLogFCMessage
, p
))
4915 CGImageRef imageRef
= NULL
;/* Current icon image */
4916 CGImageRef biggestIconRef
= NULL
;
4917 /* Biggest icon image */
4918 CGImageRef closestTo128IconRef
= NULL
;
4919 /* Icon image closest to and >= 128 */
4920 CGImageSourceRef sourceRef
; /* The file's image source */
4921 char outPath
[HTTP_MAX_URI
];
4922 /* The path to the PNG file */
4923 CFURLRef outUrl
; /* The URL made from the outPath */
4924 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4925 CGImageDestinationRef destRef
; /* The image destination to write */
4926 size_t bytesPerRow
; /* The bytes per row used for resizing */
4927 CGContextRef context
; /* The CG context used for resizing */
4929 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4930 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4931 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4932 if (outUrl
&& icnsFileUrl
)
4934 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4937 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4939 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4943 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4946 * Loop through remembering the icon closest to 128 but >= 128
4947 * and then remember the largest icon.
4950 if (CGImageGetWidth(imageRef
) >= 128 &&
4951 (!closestTo128IconRef
||
4952 CGImageGetWidth(imageRef
) <
4953 CGImageGetWidth(closestTo128IconRef
)))
4955 CGImageRelease(closestTo128IconRef
);
4956 CGImageRetain(imageRef
);
4957 closestTo128IconRef
= imageRef
;
4960 if (!biggestIconRef
||
4961 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4963 CGImageRelease(biggestIconRef
);
4964 CGImageRetain(imageRef
);
4965 biggestIconRef
= imageRef
;
4969 CGImageRelease(imageRef
);
4975 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4976 * want the closest to 128, but if none are larger than 128, we want
4977 * the largest icon available.
4980 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4982 CGImageRetain(imageRef
);
4983 CGImageRelease(biggestIconRef
);
4984 if (closestTo128IconRef
)
4985 CGImageRelease(closestTo128IconRef
);
4986 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4990 if (CGImageGetWidth(imageRef
) != 128)
4992 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4993 CGImageGetWidth(imageRef
) * 128;
4994 context
= CGBitmapContextCreate(NULL
, 128, 128,
4995 CGImageGetBitsPerComponent(imageRef
),
4997 CGImageGetColorSpace(imageRef
),
4998 kCGImageAlphaPremultipliedFirst
);
5001 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
5003 CGImageRelease(imageRef
);
5004 imageRef
= CGBitmapContextCreateImage(context
);
5005 CGContextRelease(context
);
5009 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
5010 CGImageDestinationFinalize(destRef
);
5014 CGImageRelease(imageRef
);
5017 CFRelease(sourceRef
);
5025 CFRelease(icnsFileUrl
);
5027 #endif /* HAVE_APPLICATIONSERVICES_H */
5030 * Close the PPD and set the type...
5035 else if (!access(ppd_name
, 0))
5037 int pline
; /* PPD line number */
5038 ppd_status_t pstatus
; /* PPD load status */
5041 pstatus
= ppdLastError(&pline
);
5043 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
5045 if (pstatus
<= PPD_ALLOC_ERROR
)
5046 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
5048 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
5050 cupsdLogMessage(CUPSD_LOG_INFO
,
5051 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5056 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
5057 !strncmp(p
->device_uri
, "ipps://", 7)) &&
5058 (strstr(p
->device_uri
, "/printers/") != NULL
||
5059 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
5060 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
5061 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
5062 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
5065 * Tell the client this is really a hard-wired remote printer.
5068 p
->type
|= CUPS_PRINTER_REMOTE
;
5071 * Then set the make-and-model accordingly...
5074 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5075 "printer-make-and-model", NULL
, "Remote Printer");
5078 * Print all files directly...
5087 * Otherwise we have neither - treat this as a "dumb" printer
5088 * with no PPD file...
5091 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5092 "printer-make-and-model", NULL
, "Local Raw Printer");
5098 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5099 "finishings-supported", num_finishings
, finishings
);
5100 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5101 "finishings-default", IPP_FINISHINGS_NONE
);
5106 * Save cached PPD attributes to disk...
5109 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5111 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5116 * Remove cache files...
5119 if (cache_info
.st_mtime
)
5126 * 'new_media_col()' - Create a media-col collection value.
5129 static ipp_t
* /* O - Collection value */
5130 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5131 const char *source
, /* I - media-source value */
5132 const char *type
) /* I - media-type value */
5134 ipp_t
*media_col
, /* Collection value */
5135 *media_size
; /* media-size value */
5138 media_col
= ippNew();
5140 media_size
= ippNew();
5141 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5142 "x-dimension", size
->width
);
5143 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5144 "y-dimension", size
->length
);
5145 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5146 ippDelete(media_size
);
5148 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5149 "media-bottom-margin", size
->bottom
);
5150 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5151 "media-left-margin", size
->left
);
5152 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5153 "media-right-margin", size
->right
);
5154 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5155 "media-top-margin", size
->top
);
5158 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5162 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5170 * 'write_xml_string()' - Write a string with XML escaping.
5174 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5175 const char *s
) /* I - String to write */
5177 const char *start
; /* Start of current sequence */
5183 for (start
= s
; *s
; s
++)
5188 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5190 cupsFilePuts(fp
, "&");
5196 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5198 cupsFilePuts(fp
, "<");
5204 cupsFilePuts(fp
, start
);