2 * Printer routines for the CUPS scheduler.
4 * Copyright 2007-2017 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 information.
11 * Include necessary headers...
16 #ifdef HAVE_APPLICATIONSERVICES_H
17 # include <ApplicationServices/ApplicationServices.h>
18 #endif /* HAVE_APPLICATIONSERVICES_H */
19 #ifdef HAVE_SYS_MOUNT_H
20 # include <sys/mount.h>
21 #endif /* HAVE_SYS_MOUNT_H */
22 #ifdef HAVE_SYS_STATVFS_H
23 # include <sys/statvfs.h>
24 #elif defined(HAVE_SYS_STATFS_H)
25 # include <sys/statfs.h>
26 #endif /* HAVE_SYS_STATVFS_H */
29 #endif /* HAVE_SYS_VFS_H */
32 #endif /* __APPLE__ */
39 static void add_printer_defaults(cupsd_printer_t
*p
);
40 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
42 static void add_printer_formats(cupsd_printer_t
*p
);
43 static int compare_printers(void *first
, void *second
, void *data
);
44 static void delete_printer_filters(cupsd_printer_t
*p
);
45 static void dirty_printer(cupsd_printer_t
*p
);
46 static void load_ppd(cupsd_printer_t
*p
);
47 static ipp_t
*new_media_col(pwg_size_t
*size
, const char *source
,
49 static void write_xml_string(cups_file_t
*fp
, const char *s
);
53 * 'cupsdAddPrinter()' - Add a printer to the system.
56 cupsd_printer_t
* /* O - New printer */
57 cupsdAddPrinter(const char *name
) /* I - Name of printer */
59 cupsd_printer_t
*p
; /* New printer */
60 char uri
[1024], /* Printer URI */
61 uuid
[64]; /* Printer UUID */
65 * Range check input...
68 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
71 * Create a new printer entity...
74 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
76 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
81 _cupsRWInit(&p
->lock
);
83 cupsdSetString(&p
->name
, name
);
84 cupsdSetString(&p
->info
, name
);
85 cupsdSetString(&p
->hostname
, ServerName
);
87 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
88 ServerName
, RemotePort
, "/printers/%s", name
);
89 cupsdSetString(&p
->uri
, uri
);
90 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
92 cupsdSetDeviceURI(p
, "file:///dev/null");
94 p
->config_time
= time(NULL
);
95 p
->state
= IPP_PRINTER_STOPPED
;
96 p
->state_time
= time(NULL
);
98 p
->shared
= DefaultShared
;
99 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
101 cupsdSetString(&p
->job_sheets
[0], "none");
102 cupsdSetString(&p
->job_sheets
[1], "none");
104 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
105 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
107 p
->op_policy_ptr
= DefaultPolicyPtr
;
110 * Insert the printer in the printer list alphabetically...
114 Printers
= cupsArrayNew(compare_printers
, NULL
);
116 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
117 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
118 cupsArrayAdd(Printers
, p
);
121 * Return the new printer...
129 * 'cupsdCreateCommonData()' - Create the common printer data.
133 cupsdCreateCommonData(void)
135 int i
; /* Looping var */
136 ipp_attribute_t
*attr
; /* Attribute data */
137 cups_dir_t
*dir
; /* Notifier directory */
138 cups_dentry_t
*dent
; /* Notifier directory entry */
139 cups_array_t
*notifiers
; /* Notifier array */
140 char filename
[1024], /* Filename */
141 *notifier
; /* Current notifier */
142 cupsd_policy_t
*p
; /* Current policy */
143 int k_supported
; /* Maximum file size supported */
145 struct statvfs spoolinfo
; /* FS info for spool directory */
146 double spoolsize
; /* FS size */
147 #elif defined(HAVE_STATFS)
148 struct statfs spoolinfo
; /* FS info for spool directory */
149 double spoolsize
; /* FS size */
150 #endif /* HAVE_STATVFS */
151 static const int nups
[] = /* number-up-supported values */
152 { 1, 2, 4, 6, 9, 16 };
153 static const int orients
[4] =/* orientation-requested-supported values */
157 IPP_REVERSE_LANDSCAPE
,
160 static const char * const holds
[] = /* job-hold-until-supported values */
171 static const char * const features
[] =/* ipp-features-supported values */
173 "subscription-object"
175 static const char * const versions
[] =/* ipp-versions-supported values */
182 static const int ops
[] = /* operations-supported values */
187 IPP_OP_SEND_DOCUMENT
,
189 IPP_OP_GET_JOB_ATTRIBUTES
,
191 IPP_OP_GET_PRINTER_ATTRIBUTES
,
194 IPP_OP_PAUSE_PRINTER
,
195 IPP_OP_RESUME_PRINTER
,
197 IPP_OP_SET_PRINTER_ATTRIBUTES
,
198 IPP_OP_SET_JOB_ATTRIBUTES
,
199 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
200 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
201 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
202 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
203 IPP_OP_GET_SUBSCRIPTIONS
,
204 IPP_OP_RENEW_SUBSCRIPTION
,
205 IPP_OP_CANCEL_SUBSCRIPTION
,
206 IPP_OP_GET_NOTIFICATIONS
,
207 IPP_OP_ENABLE_PRINTER
,
208 IPP_OP_DISABLE_PRINTER
,
209 IPP_OP_HOLD_NEW_JOBS
,
210 IPP_OP_RELEASE_HELD_NEW_JOBS
,
212 IPP_OP_CANCEL_MY_JOBS
,
214 IPP_OP_CUPS_GET_DEFAULT
,
215 IPP_OP_CUPS_GET_PRINTERS
,
216 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
217 IPP_OP_CUPS_DELETE_PRINTER
,
218 IPP_OP_CUPS_GET_CLASSES
,
219 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
220 IPP_OP_CUPS_DELETE_CLASS
,
221 IPP_OP_CUPS_ACCEPT_JOBS
,
222 IPP_OP_CUPS_REJECT_JOBS
,
223 IPP_OP_CUPS_SET_DEFAULT
,
224 IPP_OP_CUPS_GET_DEVICES
,
225 IPP_OP_CUPS_GET_PPDS
,
226 IPP_OP_CUPS_MOVE_JOB
,
227 IPP_OP_CUPS_AUTHENTICATE_JOB
,
229 IPP_OP_CUPS_GET_DOCUMENT
,
232 static const char * const charsets
[] =/* charset-supported values */
237 static const char * const compressions
[] =
238 { /* document-compression-supported values */
242 #endif /* HAVE_LIBZ */
244 static const char * const media_col_supported
[] =
245 { /* media-col-supported values */
246 "media-bottom-margin",
248 "media-right-margin",
254 static const char * const multiple_document_handling
[] =
255 { /* multiple-document-handling-supported values */
256 "separate-documents-uncollated-copies",
257 "separate-documents-collated-copies"
259 static const char * const notify_attrs
[] =
260 { /* notify-attributes-supported values */
261 "printer-state-change-time",
262 "notify-lease-expiration-time",
263 "notify-subscriber-user-name"
265 static const char * const notify_events
[] =
266 { /* notify-events-supported values */
268 "job-config-changed",
275 "printer-config-changed",
277 "printer-finishings-changed",
278 "printer-media-changed",
282 "printer-state-changed",
289 static const char * const job_creation
[] =
290 { /* job-creation-attributes-supported */
293 "ipp-attribute-fidelity",
300 "multiple-document-handling",
303 "orientation-requested",
307 "printer-resolution",
310 static const char * const job_settable
[] =
311 { /* job-settable-attributes-supported */
319 "multiple-document-handling",
322 "orientation-requested",
326 "printer-resolution",
329 static const char * const pdf_versions
[] =
330 { /* pdf-versions-supported */
341 static const char * const printer_settable
[] =
342 { /* printer-settable-attributes-supported */
343 "printer-geo-location",
346 "printer-organization",
347 "printer-organizational-unit"
349 static const char * const which_jobs
[] =
350 { /* which-jobs-supported values */
364 ippDelete(CommonData
);
366 CommonData
= ippNew();
369 * Get the maximum spool size based on the size of the filesystem used for
370 * the RequestRoot directory. If the host OS doesn't support the statfs call
371 * or the filesystem is larger than 2TiB, always report INT_MAX.
375 if (statvfs(RequestRoot
, &spoolinfo
))
376 k_supported
= INT_MAX
;
377 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
379 k_supported
= INT_MAX
;
381 k_supported
= (int)spoolsize
;
383 #elif defined(HAVE_STATFS)
384 if (statfs(RequestRoot
, &spoolinfo
))
385 k_supported
= INT_MAX
;
386 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
388 k_supported
= INT_MAX
;
390 k_supported
= (int)spoolsize
;
393 k_supported
= INT_MAX
;
394 #endif /* HAVE_STATVFS */
397 * This list of attributes is sorted to improve performance when the
398 * client provides a requested-attributes attribute...
401 /* charset-configured */
402 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
403 "charset-configured", NULL
, "utf-8");
405 /* charset-supported */
406 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
407 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
410 /* compression-supported */
411 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
412 "compression-supported",
413 sizeof(compressions
) / sizeof(compressions
[0]),
416 /* copies-supported */
417 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
420 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
421 "cups-version", NULL
, CUPS_SVERSION
+ 6);
423 /* generated-natural-language-supported (no IPP_TAG_COPY) */
424 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
425 "generated-natural-language-supported", NULL
, DefaultLanguage
);
427 /* ipp-features-supported */
428 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
430 /* ipp-versions-supported */
431 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
432 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
435 /* ippget-event-life */
436 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
437 "ippget-event-life", 15);
439 /* job-cancel-after-supported */
440 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
443 /* job-creation-attributes-supported */
444 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
445 "job-creation-attributes-supported",
446 sizeof(job_creation
) / sizeof(job_creation
[0]),
449 /* job-hold-until-supported */
450 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
451 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
454 /* job-ids-supported */
455 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
457 /* job-k-octets-supported */
458 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
461 /* job-priority-supported */
462 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
463 "job-priority-supported", 100);
465 /* job-settable-attributes-supported */
466 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
467 "job-settable-attributes-supported",
468 sizeof(job_settable
) / sizeof(job_settable
[0]),
471 /* job-sheets-supported */
472 if (cupsArrayCount(Banners
) > 0)
475 * Setup the job-sheets-supported attribute...
478 if (Classification
&& !ClassifyOverride
)
479 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
480 IPP_TAG_NAME
| IPP_TAG_COPY
,
481 "job-sheets-supported", NULL
, Classification
);
483 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
484 IPP_TAG_NAME
| IPP_TAG_COPY
,
485 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
489 cupsdLogMessage(CUPSD_LOG_EMERG
,
490 "Unable to allocate memory for "
491 "job-sheets-supported attribute: %s!", strerror(errno
));
492 else if (!Classification
|| ClassifyOverride
)
494 cupsd_banner_t
*banner
; /* Current banner */
497 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
499 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
501 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
502 attr
->values
[i
].string
.text
= banner
->name
;
506 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
507 "job-sheets-supported", NULL
, "none");
509 /* jpeg-k-octets-supported */
510 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
513 /* jpeg-x-dimension-supported */
514 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
517 /* jpeg-y-dimension-supported */
518 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
521 /* media-col-supported */
522 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
523 "media-col-supported",
524 sizeof(media_col_supported
) /
525 sizeof(media_col_supported
[0]), NULL
,
526 media_col_supported
);
528 /* multiple-document-handling-supported */
529 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
530 "multiple-document-handling-supported",
531 sizeof(multiple_document_handling
) /
532 sizeof(multiple_document_handling
[0]), NULL
,
533 multiple_document_handling
);
535 /* multiple-document-jobs-supported */
536 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
537 "multiple-document-jobs-supported", 1);
539 /* multiple-operation-time-out */
540 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
541 "multiple-operation-time-out", MultipleOperationTimeout
);
543 /* multiple-operation-time-out-action */
544 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
546 /* natural-language-configured (no IPP_TAG_COPY) */
547 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
548 "natural-language-configured", NULL
, DefaultLanguage
);
550 /* notify-attributes-supported */
551 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
552 "notify-attributes-supported",
553 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
556 /* notify-lease-duration-supported */
557 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
558 "notify-lease-duration-supported", 0,
559 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
561 /* notify-max-events-supported */
562 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
563 "notify-max-events-supported", MaxEvents
);
565 /* notify-events-supported */
566 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
567 "notify-events-supported",
568 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
569 NULL
, notify_events
);
571 /* notify-pull-method-supported */
572 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
573 "notify-pull-method-supported", NULL
, "ippget");
575 /* notify-schemes-supported */
576 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
577 if ((dir
= cupsDirOpen(filename
)) != NULL
)
579 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
581 while ((dent
= cupsDirRead(dir
)) != NULL
)
582 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
583 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
584 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
586 if (cupsArrayCount(notifiers
) > 0)
588 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
589 "notify-schemes-supported",
590 cupsArrayCount(notifiers
), NULL
, NULL
);
592 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
594 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
595 attr
->values
[i
].string
.text
= notifier
;
598 cupsArrayDelete(notifiers
);
602 /* number-up-supported */
603 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
604 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
606 /* operations-supported */
607 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
608 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
610 /* orientation-requested-supported */
611 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
612 "orientation-requested-supported", 4, orients
);
614 /* page-ranges-supported */
615 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
617 /* pdf-k-octets-supported */
618 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
621 /* pdf-versions-supported */
622 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
623 "pdf-versions-supported",
624 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
627 /* pdl-override-supported */
628 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
629 "pdl-override-supported", NULL
, "attempted");
631 /* printer-get-attributes-supported */
632 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
634 /* printer-op-policy-supported */
635 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
636 "printer-op-policy-supported", cupsArrayCount(Policies
),
638 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
640 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
641 attr
->values
[i
].string
.text
= p
->name
;
643 /* printer-settable-attributes-supported */
644 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
645 "printer-settable-attributes-supported",
646 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
647 NULL
, printer_settable
);
649 /* server-is-sharing-printers */
650 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
651 BrowseLocalProtocols
!= 0 && Browsing
);
653 /* which-jobs-supported */
654 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
655 "which-jobs-supported",
656 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
661 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
665 cupsdDeleteAllPrinters(void)
667 cupsd_printer_t
*p
; /* Pointer to current printer/class */
670 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
672 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
674 p
->op_policy_ptr
= DefaultPolicyPtr
;
675 cupsdDeletePrinter(p
, 0);
681 * 'cupsdDeletePrinter()' - Delete a printer from the system.
684 int /* O - 1 if classes affected, 0 otherwise */
686 cupsd_printer_t
*p
, /* I - Printer to delete */
687 int update
) /* I - Update printers.conf? */
689 int i
, /* Looping var */
690 changed
= 0; /* Class changed? */
693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
697 * Save the current position in the Printers array...
700 cupsArraySave(Printers
);
703 * Stop printing on this printer...
706 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
708 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
711 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
712 update
? "Job stopped due to printer being deleted." :
716 * Remove the printer from the list...
719 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
720 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
721 cupsArrayRemove(Printers
, p
);
724 * If p is the default printer, assign a different one...
727 if (p
== DefaultPrinter
)
728 DefaultPrinter
= NULL
;
731 * Remove this printer from any classes...
734 changed
= cupsdDeletePrinterFromClasses(p
);
737 * Deregister from any browse protocols...
740 cupsdDeregisterPrinter(p
, 1);
743 * Remove support files if this is a temporary queue and deregister color
749 char filename
[1024]; /* Script/PPD filename */
752 * Remove any old PPD or script files...
755 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
757 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
760 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
763 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
767 * Unregister color profiles...
770 cupsdUnregisterColor(p
);
774 * Free all memory used by the printer...
777 if (p
->printers
!= NULL
)
780 delete_printer_filters(p
);
782 for (i
= 0; i
< p
->num_reasons
; i
++)
783 _cupsStrFree(p
->reasons
[i
]);
786 ippDelete(p
->ppd_attrs
);
788 mimeDeleteType(MimeDatabase
, p
->filetype
);
789 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
791 cupsdFreeStrings(&(p
->users
));
794 cupsdClearString(&p
->uri
);
795 cupsdClearString(&p
->hostname
);
796 cupsdClearString(&p
->name
);
797 cupsdClearString(&p
->location
);
798 cupsdClearString(&p
->geo_location
);
799 cupsdClearString(&p
->make_model
);
800 cupsdClearString(&p
->info
);
801 cupsdClearString(&p
->job_sheets
[0]);
802 cupsdClearString(&p
->job_sheets
[1]);
803 cupsdClearString(&p
->device_uri
);
804 cupsdClearString(&p
->sanitized_device_uri
);
805 cupsdClearString(&p
->port_monitor
);
806 cupsdClearString(&p
->op_policy
);
807 cupsdClearString(&p
->error_policy
);
809 cupsdClearString(&p
->alert
);
810 cupsdClearString(&p
->alert_description
);
812 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
813 cupsdClearString(&p
->pdl
);
814 cupsdClearString(&p
->reg_name
);
815 #endif /* HAVE_DNSSD || HAVE_AVAHI */
817 cupsArrayDelete(p
->filetypes
);
819 cupsFreeOptions(p
->num_options
, p
->options
);
824 * Restore the previous position in the Printers array...
827 cupsArrayRestore(Printers
);
834 * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
838 cupsdDeleteTemporaryPrinters(int force
) /* I - Force deletion instead of auto? */
840 cupsd_printer_t
*p
; /* Current printer */
841 time_t unused_time
; /* Last time for printer state change */
845 * Allow temporary printers to stick around for 60 seconds after the last job
849 unused_time
= time(NULL
) - 60;
851 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
); p
; p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
853 if (p
->temporary
&& (force
|| p
->state_time
< unused_time
))
854 cupsdDeletePrinter(p
, 0);
860 * 'cupsdFindDest()' - Find a destination in the list.
863 cupsd_printer_t
* /* O - Destination in list */
864 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
866 cupsd_printer_t key
; /* Search key */
869 key
.name
= (char *)name
;
870 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
875 * 'cupsdFindPrinter()' - Find a printer in the list.
878 cupsd_printer_t
* /* O - Printer in list */
879 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
881 cupsd_printer_t
*p
; /* Printer in list */
884 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
892 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
896 cupsdLoadAllPrinters(void)
898 int i
; /* Looping var */
899 cups_file_t
*fp
; /* printers.conf file */
900 int linenum
; /* Current line number */
901 char line
[4096], /* Line from file */
902 *value
, /* Pointer to value */
903 *valueptr
; /* Pointer into value */
904 cupsd_printer_t
*p
; /* Current printer */
908 * Open the printers.conf file...
911 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
912 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
916 * Read printer configurations until we hit EOF...
922 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
925 * Decode the directive...
928 if (!_cups_strcasecmp(line
, "NextPrinterId"))
930 if (value
&& (i
= atoi(value
)) > 0)
933 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
935 else if (!_cups_strcasecmp(line
, "<Printer") || !_cups_strcasecmp(line
, "<DefaultPrinter"))
938 * <Printer name> or <DefaultPrinter name>
941 if (p
== NULL
&& value
)
944 * Add the printer and a base file type...
947 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
949 p
= cupsdAddPrinter(value
);
951 p
->state
= IPP_PRINTER_IDLE
;
954 * Set the default printer as needed...
957 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
961 cupsdLogMessage(CUPSD_LOG_ERROR
,
962 "Syntax error on line %d of printers.conf.", linenum
);
964 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
969 * Close out the current printer...
974 p
->printer_id
= NextPrinterId
++;
975 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
978 cupsdSetPrinterAttrs(p
);
980 if (strncmp(p
->device_uri
, "file:", 5) && p
->state
!= IPP_PRINTER_STOPPED
)
983 * See if the backend exists...
986 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
, p
->device_uri
);
988 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
989 *valueptr
= '\0'; /* Chop everything but URI scheme */
994 * Backend does not exist, stop printer...
997 p
->state
= IPP_PRINTER_STOPPED
;
998 snprintf(p
->state_message
, sizeof(p
->state_message
), "Backend %s does not exist!", line
);
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "Syntax error on line %d of printers.conf.", linenum
);
1010 cupsdLogMessage(CUPSD_LOG_ERROR
,
1011 "Syntax error on line %d of printers.conf.", linenum
);
1013 else if (!_cups_strcasecmp(line
, "PrinterId"))
1015 if (value
&& (i
= atoi(value
)) > 0)
1018 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad PrinterId on line %d of printers.conf.", linenum
);
1020 else if (!_cups_strcasecmp(line
, "UUID"))
1022 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1023 cupsdSetString(&(p
->uuid
), value
);
1025 cupsdLogMessage(CUPSD_LOG_ERROR
,
1026 "Bad UUID on line %d of printers.conf.", linenum
);
1028 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1030 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1031 cupsdLogMessage(CUPSD_LOG_ERROR
,
1032 "Bad AuthInfoRequired on line %d of printers.conf.",
1035 else if (!_cups_strcasecmp(line
, "Info"))
1038 cupsdSetString(&p
->info
, value
);
1040 else if (!_cups_strcasecmp(line
, "MakeModel"))
1043 cupsdSetString(&p
->make_model
, value
);
1045 else if (!_cups_strcasecmp(line
, "Location"))
1048 cupsdSetString(&p
->location
, value
);
1050 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1053 cupsdSetString(&p
->geo_location
, value
);
1055 else if (!_cups_strcasecmp(line
, "Organization"))
1058 cupsdSetString(&p
->organization
, value
);
1060 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1063 cupsdSetString(&p
->organizational_unit
, value
);
1065 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1068 cupsdSetDeviceURI(p
, value
);
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1073 else if (!_cups_strcasecmp(line
, "Option") && value
)
1079 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1082 cupsdLogMessage(CUPSD_LOG_ERROR
,
1083 "Syntax error on line %d of printers.conf.", linenum
);
1086 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1088 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1092 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1094 if (value
&& strcmp(value
, "none"))
1095 cupsdSetString(&p
->port_monitor
, value
);
1097 cupsdClearString(&p
->port_monitor
);
1099 cupsdLogMessage(CUPSD_LOG_ERROR
,
1100 "Syntax error on line %d of printers.conf.", linenum
);
1102 else if (!_cups_strcasecmp(line
, "Reason"))
1105 strcmp(value
, "connecting-to-device") &&
1106 strcmp(value
, "cups-insecure-filter-warning") &&
1107 strcmp(value
, "cups-missing-filter-warning"))
1109 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1110 if (!strcmp(value
, p
->reasons
[i
]))
1113 if (i
>= p
->num_reasons
&&
1114 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1116 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1121 cupsdLogMessage(CUPSD_LOG_ERROR
,
1122 "Syntax error on line %d of printers.conf.", linenum
);
1124 else if (!_cups_strcasecmp(line
, "State"))
1127 * Set the initial queue state...
1130 if (value
&& !_cups_strcasecmp(value
, "idle"))
1131 p
->state
= IPP_PRINTER_IDLE
;
1132 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1134 p
->state
= IPP_PRINTER_STOPPED
;
1136 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1137 if (!strcmp("paused", p
->reasons
[i
]))
1140 if (i
>= p
->num_reasons
&&
1141 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1143 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1148 cupsdLogMessage(CUPSD_LOG_ERROR
,
1149 "Syntax error on line %d of printers.conf.", linenum
);
1151 else if (!_cups_strcasecmp(line
, "StateMessage"))
1154 * Set the initial queue state message...
1158 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1160 else if (!_cups_strcasecmp(line
, "StateTime"))
1163 * Set the state time...
1167 p
->state_time
= atoi(value
);
1169 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1172 * Set the config time...
1176 p
->config_time
= atoi(value
);
1178 else if (!_cups_strcasecmp(line
, "Accepting"))
1181 * Set the initial accepting state...
1185 (!_cups_strcasecmp(value
, "yes") ||
1186 !_cups_strcasecmp(value
, "on") ||
1187 !_cups_strcasecmp(value
, "true")))
1190 (!_cups_strcasecmp(value
, "no") ||
1191 !_cups_strcasecmp(value
, "off") ||
1192 !_cups_strcasecmp(value
, "false")))
1195 cupsdLogMessage(CUPSD_LOG_ERROR
,
1196 "Syntax error on line %d of printers.conf.", linenum
);
1198 else if (!_cups_strcasecmp(line
, "Type"))
1201 p
->type
= (cups_ptype_t
)atoi(value
);
1203 cupsdLogMessage(CUPSD_LOG_ERROR
,
1204 "Syntax error on line %d of printers.conf.", linenum
);
1206 else if (!_cups_strcasecmp(line
, "Shared"))
1209 * Set the initial shared state...
1213 (!_cups_strcasecmp(value
, "yes") ||
1214 !_cups_strcasecmp(value
, "on") ||
1215 !_cups_strcasecmp(value
, "true")))
1218 (!_cups_strcasecmp(value
, "no") ||
1219 !_cups_strcasecmp(value
, "off") ||
1220 !_cups_strcasecmp(value
, "false")))
1223 cupsdLogMessage(CUPSD_LOG_ERROR
,
1224 "Syntax error on line %d of printers.conf.", linenum
);
1226 else if (!_cups_strcasecmp(line
, "JobSheets"))
1229 * Set the initial job sheets...
1234 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1239 cupsdSetString(&p
->job_sheets
[0], value
);
1241 while (isspace(*valueptr
& 255))
1246 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1251 cupsdSetString(&p
->job_sheets
[1], value
);
1255 cupsdLogMessage(CUPSD_LOG_ERROR
,
1256 "Syntax error on line %d of printers.conf.", linenum
);
1258 else if (!_cups_strcasecmp(line
, "AllowUser"))
1263 cupsdAddString(&(p
->users
), value
);
1266 cupsdLogMessage(CUPSD_LOG_ERROR
,
1267 "Syntax error on line %d of printers.conf.", linenum
);
1269 else if (!_cups_strcasecmp(line
, "DenyUser"))
1274 cupsdAddString(&(p
->users
), value
);
1277 cupsdLogMessage(CUPSD_LOG_ERROR
,
1278 "Syntax error on line %d of printers.conf.", linenum
);
1280 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1283 p
->quota_period
= atoi(value
);
1285 cupsdLogMessage(CUPSD_LOG_ERROR
,
1286 "Syntax error on line %d of printers.conf.", linenum
);
1288 else if (!_cups_strcasecmp(line
, "PageLimit"))
1291 p
->page_limit
= atoi(value
);
1293 cupsdLogMessage(CUPSD_LOG_ERROR
,
1294 "Syntax error on line %d of printers.conf.", linenum
);
1296 else if (!_cups_strcasecmp(line
, "KLimit"))
1299 p
->k_limit
= atoi(value
);
1301 cupsdLogMessage(CUPSD_LOG_ERROR
,
1302 "Syntax error on line %d of printers.conf.", linenum
);
1304 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1308 cupsd_policy_t
*pol
; /* Policy */
1311 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1313 cupsdSetString(&p
->op_policy
, value
);
1314 p
->op_policy_ptr
= pol
;
1317 cupsdLogMessage(CUPSD_LOG_ERROR
,
1318 "Bad policy \"%s\" on line %d of printers.conf",
1322 cupsdLogMessage(CUPSD_LOG_ERROR
,
1323 "Syntax error on line %d of printers.conf.", linenum
);
1325 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1329 if (strcmp(value
, "retry-current-job") &&
1330 strcmp(value
, "abort-job") &&
1331 strcmp(value
, "retry-job") &&
1332 strcmp(value
, "stop-printer"))
1333 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1335 cupsdSetString(&p
->error_policy
, value
);
1338 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1340 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1342 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1345 cupsdLogMessage(CUPSD_LOG_ERROR
,
1346 "Syntax error on line %d of printers.conf.", linenum
);
1349 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1352 cupsdSetPrinterAttrs(p
);
1354 if (!strcmp(value
, "marker-change-time"))
1355 p
->marker_time
= atoi(valueptr
);
1357 cupsdSetPrinterAttr(p
, value
, valueptr
);
1360 else if (_cups_strcasecmp(line
, "Filter") &&
1361 _cups_strcasecmp(line
, "Prefilter") &&
1362 _cups_strcasecmp(line
, "Product"))
1365 * Something else we don't understand (and that wasn't used in a prior
1366 * release of CUPS...
1369 cupsdLogMessage(CUPSD_LOG_ERROR
,
1370 "Unknown configuration directive %s on line %d of "
1371 "printers.conf.", line
, linenum
);
1380 * 'cupsdRenamePrinter()' - Rename a printer.
1385 cupsd_printer_t
*p
, /* I - Printer */
1386 const char *name
) /* I - New name */
1389 * Remove the printer from the array(s) first...
1392 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1393 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1394 cupsArrayRemove(Printers
, p
);
1397 * Rename the printer type...
1400 mimeDeleteType(MimeDatabase
, p
->filetype
);
1401 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1403 if (p
->prefiltertype
)
1405 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1406 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1410 * Rename the printer...
1413 cupsdSetString(&p
->name
, name
);
1416 * Reset printer attributes...
1419 cupsdSetPrinterAttrs(p
);
1422 * Add the printer back to the printer array(s)...
1425 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1426 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1427 cupsArrayAdd(Printers
, p
);
1432 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1437 cupsdSaveAllPrinters(void)
1439 int i
; /* Looping var */
1440 cups_file_t
*fp
; /* printers.conf file */
1441 char filename
[1024], /* printers.conf filename */
1442 temp
[1024], /* Temporary string */
1443 value
[2048], /* Value string */
1444 *ptr
, /* Pointer into value */
1445 *name
; /* Current user/group name */
1446 cupsd_printer_t
*printer
; /* Current printer class */
1447 time_t curtime
; /* Current time */
1448 struct tm
*curdate
; /* Current date */
1449 cups_option_t
*option
; /* Current option */
1450 ipp_attribute_t
*marker
; /* Current marker attribute */
1454 * Create the printers.conf file...
1457 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1459 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1462 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1465 * Write a small header to the file...
1468 curtime
= time(NULL
);
1469 curdate
= localtime(&curtime
);
1470 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1472 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1473 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1474 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1476 cupsFilePrintf(fp
, "NextPrinterId %d\n", NextPrinterId
);
1479 * Write each local printer known to the system...
1482 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1484 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1487 * Skip printer classes and temporary queues...
1490 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1494 * Write printers as needed...
1497 if (printer
== DefaultPrinter
)
1498 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1500 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1502 if (printer
->printer_id
)
1503 cupsFilePrintf(fp
, "PrinterId %d\n", printer
->printer_id
);
1505 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1507 if (printer
->num_auth_info_required
> 0)
1509 switch (printer
->num_auth_info_required
)
1512 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1516 snprintf(value
, sizeof(value
), "%s,%s",
1517 printer
->auth_info_required
[0],
1518 printer
->auth_info_required
[1]);
1523 snprintf(value
, sizeof(value
), "%s,%s,%s",
1524 printer
->auth_info_required
[0],
1525 printer
->auth_info_required
[1],
1526 printer
->auth_info_required
[2]);
1530 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1534 cupsFilePutConf(fp
, "Info", printer
->info
);
1536 if (printer
->location
)
1537 cupsFilePutConf(fp
, "Location", printer
->location
);
1539 if (printer
->geo_location
)
1540 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1542 if (printer
->make_model
)
1543 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1545 if (printer
->organization
)
1546 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1548 if (printer
->organizational_unit
)
1549 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1551 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1553 if (printer
->port_monitor
)
1554 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1556 if (printer
->state
== IPP_PRINTER_STOPPED
)
1558 cupsFilePuts(fp
, "State Stopped\n");
1560 if (printer
->state_message
[0])
1561 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1564 cupsFilePuts(fp
, "State Idle\n");
1566 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1567 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1569 for (i
= 0; i
< printer
->num_reasons
; i
++)
1570 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1571 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1572 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1573 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1575 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1577 if (printer
->accepting
)
1578 cupsFilePuts(fp
, "Accepting Yes\n");
1580 cupsFilePuts(fp
, "Accepting No\n");
1582 if (printer
->shared
)
1583 cupsFilePuts(fp
, "Shared Yes\n");
1585 cupsFilePuts(fp
, "Shared No\n");
1587 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1588 printer
->job_sheets
[1]);
1589 cupsFilePutConf(fp
, "JobSheets", value
);
1591 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1592 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1593 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1595 for (name
= (char *)cupsArrayFirst(printer
->users
);
1597 name
= (char *)cupsArrayNext(printer
->users
))
1598 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1600 if (printer
->op_policy
)
1601 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1602 if (printer
->error_policy
)
1603 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1605 for (i
= printer
->num_options
, option
= printer
->options
;
1609 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1610 cupsFilePutConf(fp
, "Option", value
);
1613 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1614 IPP_TAG_NAME
)) != NULL
)
1616 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1618 for (i
= 0, ptr
= value
+ strlen(value
);
1619 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1625 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1630 cupsFilePutConf(fp
, "Attribute", value
);
1633 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1634 IPP_TAG_INTEGER
)) != NULL
)
1636 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1637 marker
->values
[0].integer
);
1638 for (i
= 1; i
< marker
->num_values
; i
++)
1639 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1640 cupsFilePuts(fp
, "\n");
1643 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1644 IPP_TAG_INTEGER
)) != NULL
)
1646 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1647 marker
->values
[0].integer
);
1648 for (i
= 1; i
< marker
->num_values
; i
++)
1649 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1650 cupsFilePuts(fp
, "\n");
1653 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1654 IPP_TAG_INTEGER
)) != NULL
)
1656 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1657 marker
->values
[0].integer
);
1658 for (i
= 1; i
< marker
->num_values
; i
++)
1659 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1660 cupsFilePuts(fp
, "\n");
1663 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1664 IPP_TAG_TEXT
)) != NULL
)
1666 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1667 marker
->values
[0].string
.text
);
1669 cupsFilePutConf(fp
, "Attribute", value
);
1672 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1673 IPP_TAG_NAME
)) != NULL
)
1675 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1677 for (i
= 0, ptr
= value
+ strlen(value
);
1678 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1684 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1689 cupsFilePutConf(fp
, "Attribute", value
);
1692 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1693 IPP_TAG_KEYWORD
)) != NULL
)
1695 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1697 for (i
= 0, ptr
= value
+ strlen(value
);
1698 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1704 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1709 cupsFilePutConf(fp
, "Attribute", value
);
1712 if (printer
->marker_time
)
1713 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1714 (long)printer
->marker_time
);
1716 if (printer
== DefaultPrinter
)
1717 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1719 cupsFilePuts(fp
, "</Printer>\n");
1722 cupsdCloseCreatedConfFile(fp
, filename
);
1727 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1730 int /* O - 1 if value OK, 0 otherwise */
1731 cupsdSetAuthInfoRequired(
1732 cupsd_printer_t
*p
, /* I - Printer */
1733 const char *values
, /* I - Plain text value (or NULL) */
1734 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1736 int i
; /* Looping var */
1739 p
->num_auth_info_required
= 0;
1742 * Do we have a plain text value?
1748 * Yes, grab the keywords...
1751 const char *end
; /* End of current value */
1754 while (*values
&& p
->num_auth_info_required
< 4)
1756 if ((end
= strchr(values
, ',')) == NULL
)
1757 end
= values
+ strlen(values
);
1759 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1761 if (p
->num_auth_info_required
!= 0 || *end
)
1764 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1765 p
->num_auth_info_required
++;
1769 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1771 if (p
->num_auth_info_required
!= 0 || *end
)
1774 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1775 p
->num_auth_info_required
++;
1778 * Don't allow sharing of queues that require Kerberos authentication.
1783 cupsdDeregisterPrinter(p
, 1);
1787 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1789 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1790 p
->num_auth_info_required
++;
1792 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1794 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1795 p
->num_auth_info_required
++;
1797 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1800 p
->num_auth_info_required
++;
1805 values
= (*end
) ? end
+ 1 : end
;
1808 if (p
->num_auth_info_required
== 0)
1810 p
->auth_info_required
[0] = "none";
1811 p
->num_auth_info_required
= 1;
1815 * Update the printer-type value as needed...
1818 if (p
->num_auth_info_required
> 1 ||
1819 strcmp(p
->auth_info_required
[0], "none"))
1820 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1822 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1828 * Grab values from an attribute instead...
1831 if (!attr
|| attr
->num_values
> 4)
1834 for (i
= 0; i
< attr
->num_values
; i
++)
1836 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1838 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1841 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1842 p
->num_auth_info_required
++;
1846 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1848 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1851 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1852 p
->num_auth_info_required
++;
1855 * Don't allow sharing of queues that require Kerberos authentication.
1860 cupsdDeregisterPrinter(p
, 1);
1866 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1868 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1869 p
->num_auth_info_required
++;
1871 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1873 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1874 p
->num_auth_info_required
++;
1876 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1878 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1879 p
->num_auth_info_required
++;
1890 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1894 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1895 const char *uri
) /* I - Device URI */
1897 char buffer
[1024], /* URI buffer */
1898 *start
, /* Start of data after scheme */
1899 *slash
, /* First slash after scheme:// */
1900 *ptr
; /* Pointer into user@host:port part */
1904 * Set the full device URI..
1907 cupsdSetString(&(p
->device_uri
), uri
);
1910 * Copy the device URI to a temporary buffer so we can sanitize any auth
1914 strlcpy(buffer
, uri
, sizeof(buffer
));
1917 * Find the end of the scheme:// part...
1920 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1922 for (start
= ptr
+ 1; *start
; start
++)
1927 * Find the next slash (/) in the URI...
1930 if ((slash
= strchr(start
, '/')) == NULL
)
1931 slash
= start
+ strlen(start
); /* No slash, point to the end */
1934 * Check for an @ sign before the slash...
1937 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1940 * Found an @ sign and it is before the resource part, so we have
1941 * an authentication string. Copy the remaining URI over the
1942 * authentication string...
1945 _cups_strcpy(start
, ptr
+ 1);
1950 * Save the sanitized URI...
1953 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1958 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1962 cupsdSetPrinterAttr(
1963 cupsd_printer_t
*p
, /* I - Printer */
1964 const char *name
, /* I - Attribute name */
1965 const char *value
) /* I - Attribute value string */
1967 ipp_attribute_t
*attr
; /* Attribute */
1968 int i
, /* Looping var */
1969 count
; /* Number of values */
1970 char *temp
, /* Temporary copy of value string */
1971 *ptr
, /* Pointer into value */
1972 *start
, /* Start of value */
1973 quote
; /* Quote character */
1974 ipp_tag_t value_tag
; /* Value tag for this attribute */
1978 * Don't allow empty values...
1981 if (!*value
&& strcmp(name
, "marker-message"))
1983 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1988 * Copy the value string so we can do what we want with it...
1991 if ((temp
= strdup(value
)) == NULL
)
1993 cupsdLogMessage(CUPSD_LOG_ERROR
,
1994 "Unable to duplicate value for \"%s\" attribute.", name
);
1999 * Count the number of values...
2002 for (count
= 1, quote
= '\0', ptr
= temp
;
2010 else if (*ptr
== '\\' && ptr
[1])
2012 else if (*ptr
== '\'' || *ptr
== '\"')
2014 else if (*ptr
== ',')
2019 * Then add or update the attribute as needed...
2022 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2023 !strcmp(name
, "marker-high-levels"))
2029 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2030 attr
->num_values
< count
)
2032 ippDeleteAttribute(p
->attrs
, attr
);
2037 attr
->num_values
= count
;
2039 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2045 cupsdLogMessage(CUPSD_LOG_ERROR
,
2046 "Unable to allocate memory for printer attribute "
2047 "(%d values)", count
);
2051 for (i
= 0, start
= temp
; i
< count
; i
++)
2053 if ((ptr
= strchr(start
, ',')) != NULL
)
2056 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2065 * Name or keyword values...
2068 if (!strcmp(name
, "marker-types"))
2069 value_tag
= IPP_TAG_KEYWORD
;
2070 else if (!strcmp(name
, "marker-message"))
2071 value_tag
= IPP_TAG_TEXT
;
2073 value_tag
= IPP_TAG_NAME
;
2075 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2076 attr
->num_values
< count
)
2078 ippDeleteAttribute(p
->attrs
, attr
);
2084 for (i
= 0; i
< attr
->num_values
; i
++)
2085 _cupsStrFree(attr
->values
[i
].string
.text
);
2087 attr
->num_values
= count
;
2090 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2096 cupsdLogMessage(CUPSD_LOG_ERROR
,
2097 "Unable to allocate memory for printer attribute "
2098 "(%d values)", count
);
2102 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2104 for (start
= ptr
; *ptr
; ptr
++)
2107 *ptr
= quote
= '\0';
2110 else if (*ptr
== '\\' && ptr
[1])
2111 _cups_strcpy(ptr
, ptr
+ 1);
2112 else if (*ptr
== '\'' || *ptr
== '\"')
2119 _cups_strcpy(ptr
, ptr
+ 1);
2121 else if (*ptr
== ',')
2128 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2135 * Update the printer-supply and printer-supply-description, as needed...
2138 if (!strcmp(name
, "marker-names"))
2140 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2141 /* printer-supply-description attribute */
2143 if (supply_desc
!= NULL
)
2144 ippDeleteAttribute(p
->attrs
, supply_desc
);
2146 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2147 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2148 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2150 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2152 char buffer
[256], /* printer-supply values */
2153 pstype
[64], /* printer-supply type value */
2154 *psptr
; /* Pointer into type */
2155 const char *color
, /* marker-colors value */
2156 *type
; /* marker-types value */
2157 int level
; /* marker-levels value */
2158 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2159 /* marker-colors attribute */
2160 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2161 /* marker-levels attribute */
2162 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2163 /* marker-types attribute */
2164 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2165 /* printer-supply attribute */
2169 ippDeleteAttribute(p
->attrs
, supply
);
2173 if (!colors
|| !levels
|| !types
)
2176 count
= ippGetCount(colors
);
2177 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2180 for (i
= 0; i
< count
; i
++)
2182 color
= ippGetString(colors
, i
, NULL
);
2183 level
= ippGetInteger(levels
, i
);
2184 type
= ippGetString(types
, i
, NULL
);
2186 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2190 *psptr
++ = (char)toupper(*type
& 255);
2196 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
);
2199 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2201 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2208 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2212 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2214 int i
; /* Looping var */
2215 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2216 cupsd_location_t
*auth
; /* Pointer to authentication element */
2217 const char *auth_supported
; /* Authentication supported */
2218 ipp_t
*oldattrs
; /* Old printer attributes */
2219 ipp_attribute_t
*attr
; /* Attribute data */
2220 char *name
, /* Current user/group name */
2221 *filter
; /* Current filter */
2224 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2228 * Make sure that we have the common attributes defined...
2232 cupsdCreateCommonData();
2234 _cupsRWLockWrite(&p
->lock
);
2237 * Clear out old filters, if any...
2240 delete_printer_filters(p
);
2243 * Figure out the authentication that is required for the printer.
2246 auth_supported
= "requesting-user-name";
2248 if (p
->type
& CUPS_PRINTER_CLASS
)
2249 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2251 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2253 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2254 auth
->type
== CUPSD_AUTH_NONE
)
2255 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2259 int auth_type
; /* Authentication type */
2262 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2263 auth_type
= cupsdDefaultAuthType();
2265 if (auth_type
== CUPSD_AUTH_BASIC
)
2266 auth_supported
= "basic";
2268 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2269 auth_supported
= "negotiate";
2270 #endif /* HAVE_GSSAPI */
2272 if (auth_type
!= CUPSD_AUTH_NONE
)
2273 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2275 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2278 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2281 * Create the required IPP attributes for a printer...
2284 oldattrs
= p
->attrs
;
2285 p
->attrs
= ippNew();
2287 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2288 "uri-authentication-supported", NULL
, auth_supported
);
2289 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2290 "uri-security-supported", NULL
, "none");
2292 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-id", p
->printer_id
);
2293 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2295 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2296 NULL
, p
->location
? p
->location
: "");
2297 if (p
->geo_location
)
2298 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2300 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2301 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2302 NULL
, p
->info
? p
->info
: "");
2303 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2305 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2307 if (cupsArrayCount(p
->users
) > 0)
2310 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2311 "requesting-user-name-denied",
2312 cupsArrayCount(p
->users
), NULL
, NULL
);
2314 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2315 "requesting-user-name-allowed",
2316 cupsArrayCount(p
->users
), NULL
, NULL
);
2318 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2320 i
++, name
= (char *)cupsArrayNext(p
->users
))
2321 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2324 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2325 "job-quota-period", p
->quota_period
);
2326 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2327 "job-k-limit", p
->k_limit
);
2328 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2329 "job-page-limit", p
->page_limit
);
2330 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2331 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2332 "auth-info-required", p
->num_auth_info_required
, NULL
,
2333 p
->auth_info_required
);
2335 if (cupsArrayCount(Banners
) > 0)
2338 * Setup the job-sheets-default attribute...
2341 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2342 "job-sheets-default", 2, NULL
, NULL
);
2346 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2347 Classification
: p
->job_sheets
[0]);
2348 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2349 Classification
: p
->job_sheets
[1]);
2357 * Assign additional attributes depending on whether this is a printer
2361 if (p
->type
& CUPS_PRINTER_CLASS
)
2364 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2367 * Add class-specific attributes...
2370 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2371 "printer-make-and-model", NULL
, "Local Printer Class");
2372 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2373 "file:///dev/null");
2375 if (p
->num_printers
> 0)
2378 * Add a list of member names; URIs are added in copy_printer_attrs...
2381 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2382 "member-names", p
->num_printers
, NULL
, NULL
);
2383 p
->type
|= CUPS_PRINTER_OPTIONS
;
2385 for (i
= 0; i
< p
->num_printers
; i
++)
2388 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2390 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2397 * Add printer-specific attributes...
2400 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2401 p
->sanitized_device_uri
);
2404 * Assign additional attributes from the PPD file (if any)...
2410 * Add filters for printer...
2413 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2414 "cups-insecure-filter-warning");
2416 if (p
->pc
&& p
->pc
->filters
)
2418 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2420 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2421 add_printer_filter(p
, p
->filetype
, filter
);
2423 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2426 * Add a filter from application/vnd.cups-raw to printer/name to
2427 * handle "raw" printing by users.
2430 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2433 * Add a PostScript filter, since this is still possibly PS printer.
2436 add_printer_filter(p
, p
->filetype
,
2437 "application/vnd.cups-postscript 0 -");
2440 if (p
->pc
&& p
->pc
->prefilters
)
2442 if (!p
->prefiltertype
)
2443 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2445 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2447 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2448 add_printer_filter(p
, p
->prefiltertype
, filter
);
2453 * Copy marker attributes as needed...
2458 ipp_attribute_t
*oldattr
; /* Old attribute */
2461 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2462 IPP_TAG_NAME
)) != NULL
)
2464 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2465 "marker-colors", oldattr
->num_values
, NULL
,
2468 for (i
= 0; i
< oldattr
->num_values
; i
++)
2469 attr
->values
[i
].string
.text
=
2470 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2474 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2475 IPP_TAG_INTEGER
)) != NULL
)
2477 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2478 "marker-levels", oldattr
->num_values
,
2481 for (i
= 0; i
< oldattr
->num_values
; i
++)
2482 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2486 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2487 IPP_TAG_TEXT
)) != NULL
)
2488 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2489 NULL
, oldattr
->values
[0].string
.text
);
2491 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2492 IPP_TAG_INTEGER
)) != NULL
)
2494 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2495 "marker-low-levels", oldattr
->num_values
,
2498 for (i
= 0; i
< oldattr
->num_values
; i
++)
2499 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2503 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2504 IPP_TAG_INTEGER
)) != NULL
)
2506 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2507 "marker-high-levels", oldattr
->num_values
,
2510 for (i
= 0; i
< oldattr
->num_values
; i
++)
2511 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2515 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2516 IPP_TAG_NAME
)) != NULL
)
2518 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2519 "marker-names", oldattr
->num_values
, NULL
,
2522 for (i
= 0; i
< oldattr
->num_values
; i
++)
2523 attr
->values
[i
].string
.text
=
2524 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2528 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2529 IPP_TAG_KEYWORD
)) != NULL
)
2531 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2532 "marker-types", oldattr
->num_values
, NULL
,
2535 for (i
= 0; i
< oldattr
->num_values
; i
++)
2536 attr
->values
[i
].string
.text
=
2537 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2541 ippDelete(oldattrs
);
2545 * Force sharing off for remote queues...
2548 if (p
->type
& CUPS_PRINTER_REMOTE
)
2552 * Populate the document-format-supported attribute...
2555 add_printer_formats(p
);
2557 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2561 * Add name-default attributes...
2564 add_printer_defaults(p
);
2566 _cupsRWUnlock(&p
->lock
);
2569 * Let the browse protocols reflect the change
2572 cupsdRegisterPrinter(p
);
2577 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2580 int /* O - 1 if something changed, 0 otherwise */
2581 cupsdSetPrinterReasons(
2582 cupsd_printer_t
*p
, /* I - Printer */
2583 const char *s
) /* I - Reasons strings */
2585 int i
, /* Looping var */
2586 changed
= 0; /* Did something change? */
2587 const char *sptr
; /* Pointer into reasons */
2588 char reason
[255], /* Reason string */
2589 *rptr
; /* Pointer into reason */
2592 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2593 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2595 if (s
[0] == '-' || s
[0] == '+')
2598 * Add/remove reasons...
2606 * Replace reasons...
2611 for (i
= 0; i
< p
->num_reasons
; i
++)
2612 _cupsStrFree(p
->reasons
[i
]);
2620 if (!strcmp(s
, "none"))
2624 * Loop through all of the reasons...
2630 * Skip leading whitespace and commas...
2633 while (isspace(*sptr
& 255) || *sptr
== ',')
2636 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2637 if (rptr
< (reason
+ sizeof(reason
) - 1))
2651 for (i
= 0; i
< p
->num_reasons
; i
++)
2652 if (!strcmp(reason
, p
->reasons
[i
]))
2655 * Found a match, so remove it...
2660 _cupsStrFree(p
->reasons
[i
]);
2662 if (i
< p
->num_reasons
)
2663 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2665 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2666 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2668 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2669 p
->job
->completed
= 0;
2671 if (strcmp(reason
, "connecting-to-device"))
2677 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2683 for (i
= 0; i
< p
->num_reasons
; i
++)
2684 if (!strcmp(reason
, p
->reasons
[i
]))
2687 if (i
>= p
->num_reasons
)
2689 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2691 cupsdLogMessage(CUPSD_LOG_ALERT
,
2692 "Too many printer-state-reasons values for %s (%d)",
2697 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2701 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2702 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2704 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2705 p
->job
->completed
= 1;
2707 if (strcmp(reason
, "connecting-to-device"))
2718 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2722 cupsdSetPrinterState(
2723 cupsd_printer_t
*p
, /* I - Printer to change */
2724 ipp_pstate_t s
, /* I - New state */
2725 int update
) /* I - Update printers.conf? */
2727 cupsd_job_t
*job
; /* Current job */
2728 ipp_pstate_t old_state
; /* Old printer state */
2729 static const char * const printer_states
[] =
2730 { /* State strings */
2738 * Set the new state...
2741 old_state
= p
->state
;
2746 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2747 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2748 "%s \"%s\" state changed to %s.",
2749 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2750 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2753 * Let the browse code know this needs to be updated...
2756 p
->state_time
= time(NULL
);
2760 * Set/clear the paused reason as needed...
2763 if (s
== IPP_PRINTER_STOPPED
)
2764 cupsdSetPrinterReasons(p
, "+paused");
2766 cupsdSetPrinterReasons(p
, "-paused");
2770 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2772 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2773 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2774 !_cups_strcasecmp(job
->dest
, p
->name
))
2775 ippSetString(job
->attrs
, &job
->reasons
, 0,
2776 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2780 * Clear the message for the queue when going to processing...
2783 if (s
== IPP_PRINTER_PROCESSING
)
2784 p
->state_message
[0] = '\0';
2787 * Let the browse protocols reflect the change...
2791 cupsdRegisterPrinter(p
);
2794 * Save the printer configuration if a printer goes from idle or processing
2795 * to stopped (or visa-versa)...
2799 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2805 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2809 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2810 int update
)/* I - Update printers.conf? */
2813 * Set the printer state...
2816 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2819 * See if we have a job printing on this printer...
2822 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2823 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2824 "Job stopped due to printer being paused.");
2829 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2832 int /* O - 1 if successful, 0 otherwise */
2833 cupsdUpdatePrinterPPD(
2834 cupsd_printer_t
*p
, /* I - Printer */
2835 int num_keywords
, /* I - Number of keywords */
2836 cups_option_t
*keywords
) /* I - Keywords */
2838 int i
; /* Looping var */
2839 cups_file_t
*src
, /* Original file */
2840 *dst
; /* New file */
2841 char srcfile
[1024], /* Original filename */
2842 dstfile
[1024], /* New filename */
2843 line
[1024], /* Line from file */
2844 keystring
[41]; /* Keyword from line */
2845 cups_option_t
*keyword
; /* Current keyword */
2848 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2852 * Get the old and new PPD filenames...
2855 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2856 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2859 * Rename the old file and open the old and new...
2862 if (rename(dstfile
, srcfile
))
2864 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2865 p
->name
, strerror(errno
));
2869 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2871 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2872 srcfile
, strerror(errno
));
2873 rename(srcfile
, dstfile
);
2877 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2879 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2880 dstfile
, strerror(errno
));
2882 rename(srcfile
, dstfile
);
2887 * Copy the first line and then write out all of the keywords...
2890 if (!cupsFileGets(src
, line
, sizeof(line
)))
2892 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2893 srcfile
, strerror(errno
));
2896 rename(srcfile
, dstfile
);
2900 cupsFilePrintf(dst
, "%s\n", line
);
2902 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2904 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2905 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2909 * Then copy the rest of the PPD file, dropping any keywords we changed.
2912 while (cupsFileGets(src
, line
, sizeof(line
)))
2915 * Skip keywords we've already set...
2918 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2919 cupsGetOption(keystring
, num_keywords
, keywords
))
2923 * Otherwise write the line...
2926 cupsFilePrintf(dst
, "%s\n", line
);
2930 * Close files and return...
2941 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2945 cupsdUpdatePrinters(void)
2947 cupsd_printer_t
*p
; /* Current printer */
2951 * Loop through the printers and recreate the printer attributes
2952 * for any local printers since the policy and/or access control
2953 * stuff may have changed. Also, if browsing is disabled, remove
2954 * any remote printers...
2957 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2959 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2962 * Update the operation policy pointer...
2965 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2966 p
->op_policy_ptr
= DefaultPolicyPtr
;
2969 * Update printer attributes...
2972 cupsdSetPrinterAttrs(p
);
2978 * 'cupsdValidateDest()' - Validate a printer/class destination.
2981 const char * /* O - Printer or class name */
2983 const char *uri
, /* I - Printer URI */
2984 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2985 cupsd_printer_t
**printer
) /* O - Printer pointer */
2987 cupsd_printer_t
*p
; /* Current printer */
2988 char localname
[1024],/* Localized hostname */
2989 *lptr
, /* Pointer into localized hostname */
2990 *sptr
, /* Pointer into server name */
2991 *rptr
, /* Pointer into resource */
2992 scheme
[32], /* Scheme portion of URI */
2993 username
[64], /* Username portion of URI */
2994 hostname
[HTTP_MAX_HOST
],
2995 /* Host portion of URI */
2996 resource
[HTTP_MAX_URI
];
2997 /* Resource portion of URI */
2998 int port
; /* Port portion of URI */
3001 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3005 * Initialize return values...
3012 *dtype
= (cups_ptype_t
)0;
3015 * Pull the hostname and resource from the URI...
3018 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3019 username
, sizeof(username
), hostname
, sizeof(hostname
),
3020 &port
, resource
, sizeof(resource
));
3023 * See if the resource is a class or printer...
3026 if (!strncmp(resource
, "/classes/", 9))
3032 rptr
= resource
+ 9;
3034 else if (!strncmp(resource
, "/printers/", 10))
3040 rptr
= resource
+ 10;
3045 * Bad resource name...
3052 * See if the printer or class name exists...
3055 p
= cupsdFindDest(rptr
);
3057 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3065 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3071 * Change localhost to the server name...
3074 if (!_cups_strcasecmp(hostname
, "localhost"))
3075 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3077 strlcpy(localname
, hostname
, sizeof(localname
));
3079 if (!_cups_strcasecmp(hostname
, ServerName
))
3082 * Localize the hostname...
3085 lptr
= strchr(localname
, '.');
3086 sptr
= strchr(ServerName
, '.');
3088 if (sptr
!= NULL
&& lptr
!= NULL
)
3091 * Strip the common domain name components...
3094 while (lptr
!= NULL
)
3096 if (!_cups_strcasecmp(lptr
, sptr
))
3102 lptr
= strchr(lptr
+ 1, '.');
3107 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3110 * Find a matching printer or class...
3113 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3115 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3116 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3117 !_cups_strcasecmp(p
->name
, rptr
))
3123 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3133 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3138 cupsdWritePrintcap(void)
3140 int i
; /* Looping var */
3141 cups_file_t
*fp
; /* Printcap file */
3142 cupsd_printer_t
*p
; /* Current printer */
3146 * See if we have a printcap file; if not, don't bother writing it.
3149 if (!Printcap
|| !*Printcap
)
3152 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3155 * Open the printcap file...
3158 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3162 * Put a comment header at the top so that users will know where the
3163 * data has come from...
3166 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3167 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3169 "# %s/printers.conf file. All changes to this file\n"
3170 "# will be lost.\n", ServerRoot
);
3173 * Write a new printcap with the current list of printers.
3176 switch (PrintcapFormat
)
3180 * Each printer is put in the file as:
3190 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3191 DefaultPrinter
->info
, ServerName
,
3192 DefaultPrinter
->name
);
3194 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3196 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3197 if (p
!= DefaultPrinter
)
3198 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3199 ServerName
, p
->name
);
3202 case PRINTCAP_PLIST
:
3204 * Each printer is written as a dictionary in a plist file.
3205 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3206 * printer-location, printer-make-and-model, printer-state,
3207 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3210 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3211 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3212 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3213 "PropertyList-1.0.dtd\">\n"
3214 "<plist version=\"1.0\">\n"
3217 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3219 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3221 cupsFilePuts(fp
, "\t<dict>\n"
3222 "\t\t<key>printer-name</key>\n"
3224 write_xml_string(fp
, p
->name
);
3225 cupsFilePuts(fp
, "</string>\n"
3226 "\t\t<key>printer-info</key>\n"
3228 write_xml_string(fp
, p
->info
);
3229 cupsFilePrintf(fp
, "</string>\n"
3230 "\t\t<key>printer-is-accepting-jobs</key>\n"
3232 "\t\t<key>printer-location</key>\n"
3233 "\t\t<string>", p
->accepting
? "true" : "false");
3234 write_xml_string(fp
, p
->location
);
3235 cupsFilePuts(fp
, "</string>\n"
3236 "\t\t<key>printer-make-and-model</key>\n"
3238 write_xml_string(fp
, p
->make_model
);
3239 cupsFilePrintf(fp
, "</string>\n"
3240 "\t\t<key>printer-state</key>\n"
3241 "\t\t<integer>%d</integer>\n"
3242 "\t\t<key>printer-state-reasons</key>\n"
3243 "\t\t<array>\n", p
->state
);
3244 for (i
= 0; i
< p
->num_reasons
; i
++)
3246 cupsFilePuts(fp
, "\t\t\t<string>");
3247 write_xml_string(fp
, p
->reasons
[i
]);
3248 cupsFilePuts(fp
, "</string>\n");
3250 cupsFilePrintf(fp
, "\t\t</array>\n"
3251 "\t\t<key>printer-type</key>\n"
3252 "\t\t<integer>%d</integer>\n"
3253 "\t\t<key>device-uri</key>\n"
3254 "\t\t<string>", p
->type
);
3255 write_xml_string(fp
, p
->sanitized_device_uri
);
3256 cupsFilePuts(fp
, "</string>\n"
3259 cupsFilePuts(fp
, "</array>\n"
3263 case PRINTCAP_SOLARIS
:
3265 * Each printer is put in the file as:
3267 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3268 * _default:use=DefaultPrinter
3270 * :bsdaddr=ServerName,Printer1:\
3271 * :description=Description:
3273 * :bsdaddr=ServerName,Printer2:\
3274 * :description=Description:
3276 * :bsdaddr=ServerName,Printer3:\
3277 * :description=Description:
3280 * :bsdaddr=ServerName,PrinterN:\
3281 * :description=Description:
3284 cupsFilePuts(fp
, "_all:all=");
3285 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3287 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3288 cupsFilePrintf(fp
, "%s%c", p
->name
,
3289 cupsArrayNext(Printers
) ? ',' : '\n');
3292 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3294 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3296 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3297 cupsFilePrintf(fp
, "%s:\\\n"
3298 "\t:bsdaddr=%s,%s:\\\n"
3299 "\t:description=%s:\n",
3300 p
->name
, ServerName
, p
->name
,
3301 p
->info
? p
->info
: "");
3314 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3318 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3320 int i
; /* Looping var */
3321 int num_options
; /* Number of default options */
3322 cups_option_t
*options
, /* Default options */
3323 *option
; /* Current option */
3324 char name
[256]; /* name-default */
3328 * Maintain a common array of default attribute names...
3331 if (!CommonDefaults
)
3333 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3335 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3336 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3337 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3338 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3339 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-accounting-user-id-default"));
3340 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3341 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3342 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3343 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3344 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3345 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-lease-duration-default"));
3346 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-events-default"));
3347 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3348 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("orientation-requested-default"));
3349 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("print-quality-default"));
3353 * Add all of the default options from the .conf files...
3356 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3360 if (strcmp(option
->name
, "ipp-options") &&
3361 strcmp(option
->name
, "job-sheets") &&
3362 strcmp(option
->name
, "lease-duration"))
3364 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3365 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3367 if (!cupsArrayFind(CommonDefaults
, name
))
3368 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3373 * Convert options to IPP attributes...
3376 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3377 cupsFreeOptions(num_options
, options
);
3380 * Add standard -default attributes as needed...
3383 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3384 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3387 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3388 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3389 "document-format-default", NULL
, "application/octet-stream");
3391 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3392 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3393 "job-cancel-after-default", MaxJobTime
);
3395 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3396 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3397 "job-hold-until-default", NULL
, "no-hold");
3399 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3400 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3401 "job-priority-default", 50);
3403 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3404 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3405 "number-up-default", 1);
3407 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3408 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3409 "notify-lease-duration-default", DefaultLeaseDuration
);
3411 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3412 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3413 "notify-events-default", NULL
, "job-completed");
3415 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3416 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3417 "orientation-requested-default", NULL
, NULL
);
3419 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3420 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3421 "print-quality-default", IPP_QUALITY_NORMAL
);
3426 * 'add_printer_filter()' - Add a MIME filter for a printer.
3431 cupsd_printer_t
*p
, /* I - Printer to add to */
3432 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3433 const char *filter
) /* I - Filter to add */
3435 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3436 type
[MIME_MAX_TYPE
], /* Type for filter */
3437 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3438 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3439 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3440 /* Destination super/type */
3441 program
[1024]; /* Program/filter name */
3442 int cost
; /* Cost of filter */
3443 size_t maxsize
= 0; /* Maximum supported file size */
3444 mime_type_t
*temptype
, /* MIME type looping var */
3445 *desttype
; /* Destination MIME type */
3446 mime_filter_t
*filterptr
; /* MIME filter */
3447 char filename
[1024]; /* Full filter filename */
3450 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3451 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3452 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3453 filtertype
->type
, filter
);
3456 * Parse the filter string; it should be in one of the following formats:
3458 * source/type cost program
3459 * source/type cost maxsize(nnnn) program
3460 * source/type dest/type cost program
3461 * source/type dest/type cost maxsize(nnnn) program
3464 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3465 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3467 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3469 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3471 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3473 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3475 cupsArrayAdd(p
->dest_types
, desttype
);
3481 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3484 desttype
= filtertype
;
3488 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3494 if (!strncmp(program
, "maxsize(", 8))
3496 char *ptr
; /* Pointer into maxsize(nnnn) program */
3498 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3502 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3508 while (_cups_isspace(*ptr
))
3511 _cups_strcpy(program
, ptr
);
3515 * Check permissions on the filter and its containing directory...
3518 if (strcmp(program
, "-"))
3520 if (program
[0] == '/')
3521 strlcpy(filename
, program
, sizeof(filename
));
3523 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3525 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3526 cupsdLogFCMessage
, p
);
3530 * Add the filter to the MIME database, supporting wildcards as needed...
3533 for (temptype
= mimeFirstType(MimeDatabase
);
3535 temptype
= mimeNextType(MimeDatabase
))
3536 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3537 !_cups_strcasecmp(temptype
->super
, super
)) &&
3538 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3540 if (desttype
!= filtertype
)
3542 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3543 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3544 "%s", p
->name
, temptype
->super
, temptype
->type
,
3545 desttype
->super
, desttype
->type
,
3547 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3550 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3552 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3553 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3554 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3555 filtertype
->super
, filtertype
->type
);
3556 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3561 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3562 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3563 "%s", p
->name
, temptype
->super
, temptype
->type
,
3564 filtertype
->super
, filtertype
->type
,
3566 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3571 filterptr
->maxsize
= maxsize
;
3577 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3581 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3583 int i
; /* Looping var */
3584 mime_type_t
*type
; /* Current MIME type */
3585 cups_array_t
*filters
; /* Filters */
3586 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3587 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3588 /* MIME type name */
3592 * Raw (and remote) queues advertise all of the supported MIME
3596 cupsArrayDelete(p
->filetypes
);
3597 p
->filetypes
= NULL
;
3601 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3602 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3603 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3608 * Otherwise, loop through the supported MIME types and see if there
3609 * are filters for them...
3612 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3613 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3615 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3617 for (type
= mimeFirstType(MimeDatabase
);
3619 type
= mimeNextType(MimeDatabase
))
3621 if (!_cups_strcasecmp(type
->super
, "printer"))
3624 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3626 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3628 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3629 "add_printer_formats: %s: %s needs %d filters",
3630 p
->name
, mimetype
, cupsArrayCount(filters
));
3632 cupsArrayDelete(filters
);
3633 cupsArrayAdd(p
->filetypes
, type
);
3636 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3637 "add_printer_formats: %s: %s not supported",
3642 * Add the file formats that can be filtered...
3645 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3646 !cupsArrayFind(p
->filetypes
, type
))
3651 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3652 "add_printer_formats: %s: %d supported types",
3653 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3655 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3656 "document-format-supported",
3657 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3660 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3662 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3664 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3666 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3668 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3671 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3673 char pdl
[1024]; /* Buffer to build pdl list */
3674 mime_filter_t
*filter
; /* MIME filter looping var */
3678 * We only support raw printing if this is not a Tioga PrintJobMgr based
3679 * queue and if application/octet-stream is a known type...
3682 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3684 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3686 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3692 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3693 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3696 * Then list a bunch of formats that are supported by the printer...
3699 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3701 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3703 if (!_cups_strcasecmp(type
->super
, "application"))
3705 if (!_cups_strcasecmp(type
->type
, "pdf"))
3706 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3707 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3708 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3710 else if (!_cups_strcasecmp(type
->super
, "image"))
3712 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3713 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3714 else if (!_cups_strcasecmp(type
->type
, "png"))
3715 strlcat(pdl
, "image/png,", sizeof(pdl
));
3716 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3717 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3722 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3724 cupsdSetString(&p
->pdl
, pdl
);
3726 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3731 * 'compare_printers()' - Compare two printers.
3734 static int /* O - Result of comparison */
3735 compare_printers(void *first
, /* I - First printer */
3736 void *second
, /* I - Second printer */
3737 void *data
) /* I - App data (not used) */
3741 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3742 ((cupsd_printer_t
*)second
)->name
));
3747 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3751 delete_printer_filters(
3752 cupsd_printer_t
*p
) /* I - Printer to remove from */
3754 mime_filter_t
*filter
; /* MIME filter looping var */
3755 mime_type_t
*type
; /* Destination types for filters */
3759 * Range check input...
3766 * Remove all filters from the MIME database that have a destination
3767 * type == printer...
3770 for (filter
= mimeFirstFilter(MimeDatabase
);
3772 filter
= mimeNextFilter(MimeDatabase
))
3773 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3774 cupsArrayFind(p
->dest_types
, filter
->dst
))
3777 * Delete the current filter...
3780 mimeDeleteFilter(MimeDatabase
, filter
);
3783 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3785 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3786 mimeDeleteType(MimeDatabase
, type
);
3788 cupsArrayDelete(p
->dest_types
);
3789 p
->dest_types
= NULL
;
3791 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3792 ",cups-missing-filter-warning");
3797 * 'dirty_printer()' - Mark config and state files dirty for the specified
3802 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3804 if (p
->type
& CUPS_PRINTER_CLASS
)
3805 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3807 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3809 if (PrintcapFormat
== PRINTCAP_PLIST
)
3810 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3815 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3819 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3821 int i
, j
, k
; /* Looping vars */
3822 char cache_name
[1024]; /* Cache filename */
3823 struct stat cache_info
; /* Cache file info */
3824 ppd_file_t
*ppd
; /* PPD file */
3825 char ppd_name
[1024]; /* PPD filename */
3826 struct stat ppd_info
; /* PPD file info */
3827 int num_media
; /* Number of media options */
3828 ppd_size_t
*size
; /* Current PPD size */
3829 ppd_option_t
*duplex
, /* Duplex option */
3830 *output_bin
, /* OutputBin option */
3831 *output_mode
, /* OutputMode option */
3832 *resolution
; /* (Set|JCL|)Resolution option */
3833 ppd_choice_t
*choice
, /* Current PPD choice */
3834 *input_slot
, /* Current input slot */
3835 *media_type
; /* Current media type */
3836 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3837 int xdpi
, /* Horizontal resolution */
3838 ydpi
; /* Vertical resolution */
3839 const char *resptr
; /* Pointer into resolution keyword */
3840 pwg_size_t
*pwgsize
; /* Current PWG size */
3841 pwg_map_t
*pwgsource
, /* Current PWG source */
3842 *pwgtype
; /* Current PWG type */
3843 ipp_attribute_t
*attr
; /* Attribute data */
3844 _ipp_value_t
*val
; /* Attribute value */
3845 int num_finishings
, /* Number of finishings */
3846 finishings
[100]; /* finishings-supported values */
3847 int num_qualities
, /* Number of print-quality values */
3848 qualities
[3]; /* print-quality values */
3849 int num_margins
, /* Number of media-*-margin-supported values */
3850 margins
[16]; /* media-*-margin-supported values */
3851 const char *filter
, /* Current filter */
3852 *mandatory
; /* Current mandatory attribute */
3853 static const char * const pwg_raster_document_types
[] =
3859 static const char * const sides
[3] = /* sides-supported values */
3862 "two-sided-long-edge",
3863 "two-sided-short-edge"
3865 static const char * const standard_commands
[] =
3866 { /* Standard CUPS commands */
3874 * Check to see if the cache is up-to-date...
3877 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3878 if (stat(cache_name
, &cache_info
))
3879 cache_info
.st_mtime
= 0;
3881 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3882 if (stat(ppd_name
, &ppd_info
))
3883 ppd_info
.st_mtime
= 1;
3885 ippDelete(p
->ppd_attrs
);
3886 p
->ppd_attrs
= NULL
;
3888 _ppdCacheDestroy(p
->pc
);
3891 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3893 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3895 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3899 * Loaded successfully!
3907 * Reload PPD attributes from disk...
3910 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3912 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3914 cupsdClearString(&(p
->make_model
));
3916 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3917 p
->type
|= CUPS_PRINTER_BW
;
3919 finishings
[0] = IPP_FINISHINGS_NONE
;
3922 p
->ppd_attrs
= ippNew();
3924 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3927 * Add make/model and other various attributes...
3930 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3933 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3934 ppd_name
, cupsLastErrorString());
3936 ppdMarkDefaults(ppd
);
3938 if (ppd
->color_device
)
3939 p
->type
|= CUPS_PRINTER_COLOR
;
3940 if (ppd
->variable_sizes
)
3941 p
->type
|= CUPS_PRINTER_VARIABLE
;
3942 if (!ppd
->manual_copies
)
3943 p
->type
|= CUPS_PRINTER_COPIES
;
3944 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3945 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3946 p
->type
|= CUPS_PRINTER_FAX
;
3948 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3950 if (p
->pc
&& p
->pc
->charge_info_uri
)
3951 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3952 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3954 if (p
->pc
&& p
->pc
->account_id
)
3955 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3958 if (p
->pc
&& p
->pc
->accounting_user_id
)
3959 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3960 "job-accounting-user-id-supported", 1);
3962 if (p
->pc
&& p
->pc
->password
)
3964 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3965 "job-password-encryption-supported", NULL
, "none");
3966 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3967 "job-password-supported", (int)strlen(p
->pc
->password
));
3970 if (ppd
->throughput
)
3972 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3973 "pages-per-minute", ppd
->throughput
);
3974 if (ppd
->color_device
)
3975 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3976 "pages-per-minute-color", ppd
->throughput
);
3981 * When there is no speed information, just say "1 page per minute".
3984 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3985 "pages-per-minute", 1);
3986 if (ppd
->color_device
)
3987 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3988 "pages-per-minute-color", 1);
3991 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3992 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3996 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3998 if (ppdFindChoice(output_mode
, "draft") ||
3999 ppdFindChoice(output_mode
, "fast"))
4000 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4002 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4004 if (ppdFindChoice(output_mode
, "best") ||
4005 ppdFindChoice(output_mode
, "high"))
4006 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4008 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4012 if (strstr(ppd_attr
->spec
, "draft") ||
4013 strstr(ppd_attr
->spec
, "Draft"))
4015 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4019 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4022 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4023 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4026 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4028 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4029 "print-quality-supported", num_qualities
, qualities
);
4034 * The NickName can be localized in the character set specified
4035 * by the LanugageEncoding attribute. However, ppdOpen2() has
4036 * already converted the ppd->nickname member to UTF-8 for us
4037 * (the original attribute value is available separately)
4040 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4042 else if (ppd
->modelname
)
4045 * Model name can only contain specific characters...
4048 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4051 cupsdSetString(&p
->make_model
, "Bad PPD File");
4053 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4054 "printer-make-and-model", NULL
, p
->make_model
);
4056 if (p
->pc
->strings_uri
)
4057 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-strings-uri", NULL
, p
->pc
->strings_uri
);
4060 * Add media options from the PPD file...
4063 if (ppd
->num_sizes
== 0 || !p
->pc
)
4065 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4066 cupsdLogMessage(CUPSD_LOG_CRIT
,
4067 "The PPD file for printer %s contains no media "
4068 "options and is therefore invalid.", p
->name
);
4070 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4071 "media-default", NULL
, "unknown");
4072 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4073 "media-supported", NULL
, "unknown");
4081 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4082 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4086 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4087 "media-default", NULL
,
4088 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4096 ipp_t
*col
; /* Collection value */
4098 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4099 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4100 col
= new_media_col(pwgsize
,
4102 _ppdCacheGetSource(p
->pc
,
4103 input_slot
->choice
) :
4106 _ppdCacheGetType(p
->pc
,
4107 media_type
->choice
) :
4110 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4119 num_media
= p
->pc
->num_sizes
;
4120 if (p
->pc
->custom_min_keyword
)
4123 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4124 "media-supported", num_media
, NULL
,
4129 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4131 i
--, pwgsize
++, val
++)
4132 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4134 if (p
->pc
->custom_min_keyword
)
4136 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4138 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4143 * media-size-supported
4146 num_media
= p
->pc
->num_sizes
;
4147 if (p
->pc
->custom_min_keyword
)
4150 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4151 "media-size-supported", num_media
,
4156 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4158 i
--, pwgsize
++, val
++)
4160 val
->collection
= ippNew();
4161 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4162 "x-dimension", pwgsize
->width
);
4163 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4164 "y-dimension", pwgsize
->length
);
4167 if (p
->pc
->custom_min_keyword
)
4169 val
->collection
= ippNew();
4170 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4171 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4172 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4173 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4178 * media-source-supported
4181 if (p
->pc
->num_sources
> 0 &&
4182 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4183 "media-source-supported", p
->pc
->num_sources
,
4184 NULL
, NULL
)) != NULL
)
4186 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4189 i
--, pwgsource
++, val
++)
4190 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4194 * media-type-supported
4197 if (p
->pc
->num_types
> 0 &&
4198 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4199 "media-type-supported", p
->pc
->num_types
,
4200 NULL
, NULL
)) != NULL
)
4202 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4205 i
--, pwgtype
++, val
++)
4206 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4210 * media-*-margin-supported
4213 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4214 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4217 for (j
= 0; j
< num_margins
; j
++)
4218 if (pwgsize
->bottom
== margins
[j
])
4221 if (j
>= num_margins
)
4223 margins
[num_margins
] = pwgsize
->bottom
;
4228 if (num_margins
> 0)
4229 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4230 "media-bottom-margin-supported", num_margins
, margins
);
4232 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4233 "media-bottom-margin-supported", 0);
4235 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4236 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4239 for (j
= 0; j
< num_margins
; j
++)
4240 if (pwgsize
->left
== margins
[j
])
4243 if (j
>= num_margins
)
4245 margins
[num_margins
] = pwgsize
->left
;
4250 if (num_margins
> 0)
4251 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4252 "media-left-margin-supported", num_margins
, margins
);
4254 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4255 "media-left-margin-supported", 0);
4257 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4258 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4261 for (j
= 0; j
< num_margins
; j
++)
4262 if (pwgsize
->right
== margins
[j
])
4265 if (j
>= num_margins
)
4267 margins
[num_margins
] = pwgsize
->right
;
4272 if (num_margins
> 0)
4273 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4274 "media-right-margin-supported", num_margins
, margins
);
4276 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4277 "media-right-margin-supported", 0);
4279 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4280 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4283 for (j
= 0; j
< num_margins
; j
++)
4284 if (pwgsize
->top
== margins
[j
])
4287 if (j
>= num_margins
)
4289 margins
[num_margins
] = pwgsize
->top
;
4294 if (num_margins
> 0)
4295 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4296 "media-top-margin-supported", num_margins
, margins
);
4298 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4299 "media-top-margin-supported", 0);
4302 * media-col-database
4305 num_media
= p
->pc
->num_sizes
;
4306 if (p
->pc
->num_sources
)
4308 if (p
->pc
->num_types
> 0)
4309 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4312 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4314 else if (p
->pc
->num_types
)
4315 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4317 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4318 "media-col-database", num_media
,
4321 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4326 * Start by adding the page size without source or type...
4329 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4331 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4335 * Then add the specific, supported combinations of size, source, and
4339 if (p
->pc
->num_sources
> 0)
4341 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4345 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4347 if (p
->pc
->num_types
> 0)
4349 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4353 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4355 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4361 else if (!ppdConflicts(ppd
))
4363 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4368 else if (p
->pc
->num_types
> 0)
4370 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4374 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4376 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4384 * Update the number of media-col-database values...
4387 attr
->num_values
= val
- attr
->values
;
4395 if (p
->pc
&& p
->pc
->num_bins
> 0)
4397 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4398 "output-bin-supported", p
->pc
->num_bins
,
4403 for (i
= 0, val
= attr
->values
;
4404 i
< p
->pc
->num_bins
;
4406 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4409 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4411 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4412 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4415 if (i
>= p
->pc
->num_bins
)
4418 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4419 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4422 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4423 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4425 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4427 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4428 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4429 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4430 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4433 * Report that this printer has a single output bin that leaves pages face
4437 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4438 "output-bin-supported", NULL
, "face-up");
4439 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4440 "output-bin-default", NULL
, "face-up");
4444 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4445 "output-bin-supported", NULL
, "face-down");
4446 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4447 "output-bin-default", NULL
, "face-down");
4451 * print-color-mode...
4454 if (ppd
->color_device
)
4456 static const char * const color_modes
[] =
4462 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4463 "print-color-mode-supported", 2, NULL
, color_modes
);
4464 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4465 "print-color-mode-default", NULL
, "color");
4466 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4470 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4471 "print-color-mode-supported", NULL
, "monochrome");
4472 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4473 "print-color-mode-default", NULL
, "monochrome");
4474 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4478 * Mandatory job attributes, if any...
4481 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4483 int count
= cupsArrayCount(p
->pc
->mandatory
);
4484 /* Number of mandatory attributes */
4486 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4487 "printer-mandatory-job-attributes", count
, NULL
,
4490 for (val
= attr
->values
,
4491 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4493 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4494 val
->string
.text
= _cupsStrAlloc(mandatory
);
4498 * Printer resolutions...
4501 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4502 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4503 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4504 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4509 * Report all supported resolutions...
4512 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4514 for (i
= 0, choice
= resolution
->choices
;
4515 i
< resolution
->num_choices
;
4518 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4519 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4520 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4522 if (xdpi
<= 0 || ydpi
<= 0)
4524 cupsdLogMessage(CUPSD_LOG_WARN
,
4525 "Bad resolution \"%s\" for printer %s.",
4526 choice
->choice
, p
->name
);
4530 attr
->values
[i
].resolution
.xres
= xdpi
;
4531 attr
->values
[i
].resolution
.yres
= ydpi
;
4532 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4535 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4538 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4541 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4545 * Just the DefaultResolution to report...
4548 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4549 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4552 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4557 if (xdpi
<= 0 || ydpi
<= 0)
4559 cupsdLogMessage(CUPSD_LOG_WARN
,
4560 "Bad default resolution \"%s\" for printer %s.",
4561 ppd_attr
->value
, p
->name
);
4565 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4566 "printer-resolution-default", IPP_RES_PER_INCH
,
4568 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4569 "printer-resolution-supported", IPP_RES_PER_INCH
,
4571 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4576 * No resolutions in PPD - make one up...
4579 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4580 "printer-resolution-default", IPP_RES_PER_INCH
,
4582 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4583 "printer-resolution-supported", IPP_RES_PER_INCH
,
4585 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4592 ppdMarkDefaults(ppd
);
4594 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4595 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4596 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4597 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4598 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4600 if (duplex
&& duplex
->num_choices
> 1 &&
4601 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4603 p
->type
|= CUPS_PRINTER_DUPLEX
;
4605 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4607 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4608 "sides-supported", 3, NULL
, sides
);
4610 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4611 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4612 "sides-default", NULL
, "two-sided-short-edge");
4613 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4614 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4615 "sides-default", NULL
, "two-sided-long-edge");
4617 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4618 "sides-default", NULL
, "one-sided");
4622 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4623 "sides-supported", NULL
, "one-sided");
4624 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4625 "sides-default", NULL
, "one-sided");
4628 if (ppdFindOption(ppd
, "Collate") != NULL
)
4629 p
->type
|= CUPS_PRINTER_COLLATE
;
4631 if (p
->pc
&& p
->pc
->finishings
)
4633 _pwg_finishings_t
*fin
; /* Current finishing value */
4635 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4637 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4638 finishings
[num_finishings
++] = fin
->value
;
4642 case IPP_FINISHINGS_BIND
:
4643 case IPP_FINISHINGS_BIND_LEFT
:
4644 case IPP_FINISHINGS_BIND_TOP
:
4645 case IPP_FINISHINGS_BIND_RIGHT
:
4646 case IPP_FINISHINGS_BIND_BOTTOM
:
4647 case IPP_FINISHINGS_EDGE_STITCH
:
4648 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4649 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4650 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4651 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4652 p
->type
|= CUPS_PRINTER_BIND
;
4655 case IPP_FINISHINGS_COVER
:
4656 p
->type
|= CUPS_PRINTER_COVER
;
4659 case IPP_FINISHINGS_PUNCH
:
4660 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4661 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4662 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4663 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4664 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4665 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4666 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4667 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4668 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4669 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4670 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4671 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4672 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4673 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4674 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4675 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4676 p
->type
|= CUPS_PRINTER_PUNCH
;
4679 case IPP_FINISHINGS_STAPLE
:
4680 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4681 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4682 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4683 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4684 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4685 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4686 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4687 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4688 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4689 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4690 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4691 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4692 p
->type
|= CUPS_PRINTER_STAPLE
;
4701 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4702 if (ppd
->sizes
[i
].length
> 1728)
4703 p
->type
|= CUPS_PRINTER_LARGE
;
4704 else if (ppd
->sizes
[i
].length
> 1008)
4705 p
->type
|= CUPS_PRINTER_MEDIUM
;
4707 p
->type
|= CUPS_PRINTER_SMALL
;
4709 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4710 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4712 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4713 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4714 p
->type
|= CUPS_PRINTER_SCANNER
;
4716 p
->type
|= CUPS_PRINTER_MFP
;
4720 * Scan the filters in the PPD file...
4725 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4727 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4729 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4730 _cups_isspace(filter
[28]))
4732 p
->type
|= CUPS_PRINTER_COMMANDS
;
4738 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4740 char *commands
, /* Copy of commands */
4741 *start
, /* Start of name */
4742 *end
; /* End of name */
4743 int count
; /* Number of commands */
4745 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4747 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4749 while (_cups_isspace(*start
))
4755 while (*start
&& !isspace(*start
& 255))
4765 * Make a copy of the commands string and count how many commands there
4769 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4770 "printer-commands", count
, NULL
, NULL
);
4772 commands
= strdup(ppd_attr
->value
);
4774 for (count
= 0, start
= commands
; *start
; count
++)
4776 while (isspace(*start
& 255))
4783 while (*end
&& !isspace(*end
& 255))
4789 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4799 * Add the standard list of commands...
4802 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4804 (int)(sizeof(standard_commands
) /
4805 sizeof(standard_commands
[0])), NULL
,
4812 * No commands supported...
4815 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4816 "printer-commands", NULL
, "none");
4820 * Show current and available port monitors for this printer...
4823 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4824 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4826 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4828 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4832 if (strstr(ppd
->protocols
, "TBCP"))
4834 else if (strstr(ppd
->protocols
, "BCP"))
4838 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4839 "port-monitor-supported", i
, NULL
, NULL
);
4841 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4843 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4845 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4846 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4850 if (strstr(ppd
->protocols
, "TBCP"))
4851 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4852 else if (strstr(ppd
->protocols
, "BCP"))
4853 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4856 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4857 p
->type
|= CUPS_PRINTER_REMOTE
;
4859 #ifdef HAVE_APPLICATIONSERVICES_H
4861 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4862 * and save it as cacheDir/printername.png
4865 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4867 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4868 cupsdLogFCMessage
, p
))
4870 CGImageRef imageRef
= NULL
;/* Current icon image */
4871 CGImageRef biggestIconRef
= NULL
;
4872 /* Biggest icon image */
4873 CGImageRef closestTo128IconRef
= NULL
;
4874 /* Icon image closest to and >= 128 */
4875 CGImageSourceRef sourceRef
; /* The file's image source */
4876 char outPath
[HTTP_MAX_URI
];
4877 /* The path to the PNG file */
4878 CFURLRef outUrl
; /* The URL made from the outPath */
4879 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4880 CGImageDestinationRef destRef
; /* The image destination to write */
4881 size_t bytesPerRow
; /* The bytes per row used for resizing */
4882 CGContextRef context
; /* The CG context used for resizing */
4884 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4885 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4886 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4887 if (outUrl
&& icnsFileUrl
)
4889 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4892 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4894 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4898 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4901 * Loop through remembering the icon closest to 128 but >= 128
4902 * and then remember the largest icon.
4905 if (CGImageGetWidth(imageRef
) >= 128 &&
4906 (!closestTo128IconRef
||
4907 CGImageGetWidth(imageRef
) <
4908 CGImageGetWidth(closestTo128IconRef
)))
4910 CGImageRelease(closestTo128IconRef
);
4911 CGImageRetain(imageRef
);
4912 closestTo128IconRef
= imageRef
;
4915 if (!biggestIconRef
||
4916 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4918 CGImageRelease(biggestIconRef
);
4919 CGImageRetain(imageRef
);
4920 biggestIconRef
= imageRef
;
4924 CGImageRelease(imageRef
);
4930 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4931 * want the closest to 128, but if none are larger than 128, we want
4932 * the largest icon available.
4935 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4937 CGImageRetain(imageRef
);
4938 CGImageRelease(biggestIconRef
);
4939 if (closestTo128IconRef
)
4940 CGImageRelease(closestTo128IconRef
);
4941 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4945 if (CGImageGetWidth(imageRef
) != 128)
4947 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4948 CGImageGetWidth(imageRef
) * 128;
4949 context
= CGBitmapContextCreate(NULL
, 128, 128,
4950 CGImageGetBitsPerComponent(imageRef
),
4952 CGImageGetColorSpace(imageRef
),
4953 kCGImageAlphaPremultipliedFirst
);
4956 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4958 CGImageRelease(imageRef
);
4959 imageRef
= CGBitmapContextCreateImage(context
);
4960 CGContextRelease(context
);
4964 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4965 CGImageDestinationFinalize(destRef
);
4969 CGImageRelease(imageRef
);
4972 CFRelease(sourceRef
);
4980 CFRelease(icnsFileUrl
);
4982 #endif /* HAVE_APPLICATIONSERVICES_H */
4985 * Close the PPD and set the type...
4990 else if (!access(ppd_name
, 0))
4992 int pline
; /* PPD line number */
4993 ppd_status_t pstatus
; /* PPD load status */
4996 pstatus
= ppdLastError(&pline
);
4998 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
5000 if (pstatus
<= PPD_ALLOC_ERROR
)
5001 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
5003 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
5005 cupsdLogMessage(CUPSD_LOG_INFO
,
5006 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5011 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
5012 !strncmp(p
->device_uri
, "ipps://", 7)) &&
5013 (strstr(p
->device_uri
, "/printers/") != NULL
||
5014 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
5015 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
5016 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
5017 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
5020 * Tell the client this is really a hard-wired remote printer.
5023 p
->type
|= CUPS_PRINTER_REMOTE
;
5026 * Then set the make-and-model accordingly...
5029 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5030 "printer-make-and-model", NULL
, "Remote Printer");
5033 * Print all files directly...
5042 * Otherwise we have neither - treat this as a "dumb" printer
5043 * with no PPD file...
5046 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5047 "printer-make-and-model", NULL
, "Local Raw Printer");
5053 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5054 "finishings-supported", num_finishings
, finishings
);
5055 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5056 "finishings-default", IPP_FINISHINGS_NONE
);
5061 * Save cached PPD attributes to disk...
5064 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5066 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5071 * Remove cache files...
5074 if (cache_info
.st_mtime
)
5081 * 'new_media_col()' - Create a media-col collection value.
5084 static ipp_t
* /* O - Collection value */
5085 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5086 const char *source
, /* I - media-source value */
5087 const char *type
) /* I - media-type value */
5089 ipp_t
*media_col
, /* Collection value */
5090 *media_size
; /* media-size value */
5093 media_col
= ippNew();
5095 media_size
= ippNew();
5096 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5097 "x-dimension", size
->width
);
5098 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5099 "y-dimension", size
->length
);
5100 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5101 ippDelete(media_size
);
5103 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5104 "media-bottom-margin", size
->bottom
);
5105 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5106 "media-left-margin", size
->left
);
5107 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5108 "media-right-margin", size
->right
);
5109 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5110 "media-top-margin", size
->top
);
5113 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5117 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5125 * 'write_xml_string()' - Write a string with XML escaping.
5129 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5130 const char *s
) /* I - String to write */
5132 const char *start
; /* Start of current sequence */
5138 for (start
= s
; *s
; s
++)
5143 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5145 cupsFilePuts(fp
, "&");
5151 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5153 cupsFilePuts(fp
, "<");
5159 cupsFilePuts(fp
, start
);