2 * Printer routines for the CUPS scheduler.
4 * Copyright 2007-2019 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
20 #ifdef HAVE_APPLICATIONSERVICES_H
21 # include <ApplicationServices/ApplicationServices.h>
22 #endif /* HAVE_APPLICATIONSERVICES_H */
23 #ifdef HAVE_SYS_MOUNT_H
24 # include <sys/mount.h>
25 #endif /* HAVE_SYS_MOUNT_H */
26 #ifdef HAVE_SYS_STATVFS_H
27 # include <sys/statvfs.h>
28 #elif defined(HAVE_SYS_STATFS_H)
29 # include <sys/statfs.h>
30 #endif /* HAVE_SYS_STATVFS_H */
33 #endif /* HAVE_SYS_VFS_H */
36 #endif /* __APPLE__ */
43 static void add_printer_defaults(cupsd_printer_t
*p
);
44 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
46 static void add_printer_formats(cupsd_printer_t
*p
);
47 static int compare_printers(void *first
, void *second
, void *data
);
48 static void delete_printer_filters(cupsd_printer_t
*p
);
49 static void dirty_printer(cupsd_printer_t
*p
);
50 static void load_ppd(cupsd_printer_t
*p
);
51 static ipp_t
*new_media_col(pwg_size_t
*size
);
52 static void write_xml_string(cups_file_t
*fp
, const char *s
);
56 * 'cupsdAddPrinter()' - Add a printer to the system.
59 cupsd_printer_t
* /* O - New printer */
60 cupsdAddPrinter(const char *name
) /* I - Name of printer */
62 cupsd_printer_t
*p
; /* New printer */
63 char uri
[1024], /* Printer URI */
64 uuid
[64]; /* Printer UUID */
68 * Range check input...
71 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
74 * Create a new printer entity...
77 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
79 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
84 _cupsRWInit(&p
->lock
);
86 cupsdSetString(&p
->name
, name
);
87 cupsdSetString(&p
->info
, name
);
88 cupsdSetString(&p
->hostname
, ServerName
);
90 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
91 ServerName
, RemotePort
, "/printers/%s", name
);
92 cupsdSetString(&p
->uri
, uri
);
93 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
95 cupsdSetDeviceURI(p
, "file:///dev/null");
97 p
->config_time
= time(NULL
);
98 p
->state
= IPP_PRINTER_STOPPED
;
99 p
->state_time
= time(NULL
);
101 p
->shared
= DefaultShared
;
102 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
104 cupsdSetString(&p
->job_sheets
[0], "none");
105 cupsdSetString(&p
->job_sheets
[1], "none");
107 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
108 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
110 p
->op_policy_ptr
= DefaultPolicyPtr
;
113 * Insert the printer in the printer list alphabetically...
117 Printers
= cupsArrayNew(compare_printers
, NULL
);
119 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
120 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
121 cupsArrayAdd(Printers
, p
);
124 * Return the new printer...
132 * 'cupsdCreateCommonData()' - Create the common printer data.
136 cupsdCreateCommonData(void)
138 int i
; /* Looping var */
139 ipp_attribute_t
*attr
; /* Attribute data */
140 cups_dir_t
*dir
; /* Notifier directory */
141 cups_dentry_t
*dent
; /* Notifier directory entry */
142 cups_array_t
*notifiers
; /* Notifier array */
143 char filename
[1024], /* Filename */
144 *notifier
; /* Current notifier */
145 cupsd_policy_t
*p
; /* Current policy */
146 int k_supported
; /* Maximum file size supported */
148 struct statvfs spoolinfo
; /* FS info for spool directory */
149 double spoolsize
; /* FS size */
150 #elif defined(HAVE_STATFS)
151 struct statfs spoolinfo
; /* FS info for spool directory */
152 double spoolsize
; /* FS size */
153 #endif /* HAVE_STATVFS */
154 static const int nups
[] = /* number-up-supported values */
155 { 1, 2, 4, 6, 9, 16 };
156 static const int orients
[4] =/* orientation-requested-supported values */
160 IPP_REVERSE_LANDSCAPE
,
163 static const char * const holds
[] = /* job-hold-until-supported values */
174 static const char * const features
[] =/* ipp-features-supported values */
176 "subscription-object"
178 static const char * const versions
[] =/* ipp-versions-supported values */
185 static const int ops
[] = /* operations-supported values */
190 IPP_OP_SEND_DOCUMENT
,
192 IPP_OP_GET_JOB_ATTRIBUTES
,
194 IPP_OP_GET_PRINTER_ATTRIBUTES
,
197 IPP_OP_PAUSE_PRINTER
,
198 IPP_OP_RESUME_PRINTER
,
200 IPP_OP_SET_PRINTER_ATTRIBUTES
,
201 IPP_OP_SET_JOB_ATTRIBUTES
,
202 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
203 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
204 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
205 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
206 IPP_OP_GET_SUBSCRIPTIONS
,
207 IPP_OP_RENEW_SUBSCRIPTION
,
208 IPP_OP_CANCEL_SUBSCRIPTION
,
209 IPP_OP_GET_NOTIFICATIONS
,
210 IPP_OP_ENABLE_PRINTER
,
211 IPP_OP_DISABLE_PRINTER
,
212 IPP_OP_HOLD_NEW_JOBS
,
213 IPP_OP_RELEASE_HELD_NEW_JOBS
,
215 IPP_OP_CANCEL_MY_JOBS
,
217 IPP_OP_CUPS_GET_DEFAULT
,
218 IPP_OP_CUPS_GET_PRINTERS
,
219 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
220 IPP_OP_CUPS_DELETE_PRINTER
,
221 IPP_OP_CUPS_GET_CLASSES
,
222 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
223 IPP_OP_CUPS_DELETE_CLASS
,
224 IPP_OP_CUPS_ACCEPT_JOBS
,
225 IPP_OP_CUPS_REJECT_JOBS
,
226 IPP_OP_CUPS_SET_DEFAULT
,
227 IPP_OP_CUPS_GET_DEVICES
,
228 IPP_OP_CUPS_GET_PPDS
,
229 IPP_OP_CUPS_MOVE_JOB
,
230 IPP_OP_CUPS_AUTHENTICATE_JOB
,
232 IPP_OP_CUPS_GET_DOCUMENT
,
235 static const char * const charsets
[] =/* charset-supported values */
240 static const char * const compressions
[] =
241 { /* document-compression-supported values */
245 #endif /* HAVE_LIBZ */
247 static const char * const media_col_supported
[] =
248 { /* media-col-supported values */
249 "media-bottom-margin",
251 "media-right-margin",
257 static const char * const multiple_document_handling
[] =
258 { /* multiple-document-handling-supported values */
259 "separate-documents-uncollated-copies",
260 "separate-documents-collated-copies"
262 static const char * const notify_attrs
[] =
263 { /* notify-attributes-supported values */
264 "printer-state-change-time",
265 "notify-lease-expiration-time",
266 "notify-subscriber-user-name"
268 static const char * const notify_events
[] =
269 { /* notify-events-supported values */
271 "job-config-changed",
278 "printer-config-changed",
280 "printer-finishings-changed",
281 "printer-media-changed",
285 "printer-state-changed",
292 static const char * const job_creation
[] =
293 { /* job-creation-attributes-supported */
296 "ipp-attribute-fidelity",
303 "multiple-document-handling",
306 "orientation-requested",
310 "printer-resolution",
313 static const char * const job_settable
[] =
314 { /* job-settable-attributes-supported */
322 "multiple-document-handling",
325 "orientation-requested",
329 "printer-resolution",
332 static const char * const pdf_versions
[] =
333 { /* pdf-versions-supported */
344 static const char * const printer_settable
[] =
345 { /* printer-settable-attributes-supported */
346 "printer-geo-location",
349 "printer-organization",
350 "printer-organizational-unit"
352 static const char * const which_jobs
[] =
353 { /* which-jobs-supported values */
367 ippDelete(CommonData
);
369 CommonData
= ippNew();
372 * Get the maximum spool size based on the size of the filesystem used for
373 * the RequestRoot directory. If the host OS doesn't support the statfs call
374 * or the filesystem is larger than 2TiB, always report INT_MAX.
378 if (statvfs(RequestRoot
, &spoolinfo
))
379 k_supported
= INT_MAX
;
380 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
382 k_supported
= INT_MAX
;
384 k_supported
= (int)spoolsize
;
386 #elif defined(HAVE_STATFS)
387 if (statfs(RequestRoot
, &spoolinfo
))
388 k_supported
= INT_MAX
;
389 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
391 k_supported
= INT_MAX
;
393 k_supported
= (int)spoolsize
;
396 k_supported
= INT_MAX
;
397 #endif /* HAVE_STATVFS */
400 * This list of attributes is sorted to improve performance when the
401 * client provides a requested-attributes attribute...
404 /* charset-configured */
405 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
406 "charset-configured", NULL
, "utf-8");
408 /* charset-supported */
409 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
410 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
413 /* compression-supported */
414 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
415 "compression-supported",
416 sizeof(compressions
) / sizeof(compressions
[0]),
419 /* copies-supported */
420 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
423 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
424 "cups-version", NULL
, CUPS_SVERSION
+ 6);
426 /* generated-natural-language-supported (no IPP_TAG_COPY) */
427 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
428 "generated-natural-language-supported", NULL
, DefaultLanguage
);
430 /* ipp-features-supported */
431 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
433 /* ipp-versions-supported */
434 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
435 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
438 /* ippget-event-life */
439 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
440 "ippget-event-life", 15);
442 /* job-cancel-after-supported */
443 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
446 /* job-creation-attributes-supported */
447 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
448 "job-creation-attributes-supported",
449 sizeof(job_creation
) / sizeof(job_creation
[0]),
452 /* job-hold-until-supported */
453 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
454 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
457 /* job-ids-supported */
458 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
460 /* job-k-octets-supported */
461 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
464 /* job-priority-supported */
465 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
466 "job-priority-supported", 100);
468 /* job-settable-attributes-supported */
469 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
470 "job-settable-attributes-supported",
471 sizeof(job_settable
) / sizeof(job_settable
[0]),
474 /* job-sheets-supported */
475 if (cupsArrayCount(Banners
) > 0)
478 * Setup the job-sheets-supported attribute...
481 if (Classification
&& !ClassifyOverride
)
482 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
483 IPP_TAG_NAME
| IPP_TAG_COPY
,
484 "job-sheets-supported", NULL
, Classification
);
486 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
487 IPP_TAG_NAME
| IPP_TAG_COPY
,
488 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
492 cupsdLogMessage(CUPSD_LOG_EMERG
,
493 "Unable to allocate memory for "
494 "job-sheets-supported attribute: %s!", strerror(errno
));
495 else if (!Classification
|| ClassifyOverride
)
497 cupsd_banner_t
*banner
; /* Current banner */
500 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
502 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
504 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
505 attr
->values
[i
].string
.text
= banner
->name
;
509 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
510 "job-sheets-supported", NULL
, "none");
512 /* jpeg-k-octets-supported */
513 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
516 /* jpeg-x-dimension-supported */
517 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
520 /* jpeg-y-dimension-supported */
521 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
524 /* media-col-supported */
525 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
526 "media-col-supported",
527 sizeof(media_col_supported
) /
528 sizeof(media_col_supported
[0]), NULL
,
529 media_col_supported
);
531 /* multiple-document-handling-supported */
532 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
533 "multiple-document-handling-supported",
534 sizeof(multiple_document_handling
) /
535 sizeof(multiple_document_handling
[0]), NULL
,
536 multiple_document_handling
);
538 /* multiple-document-jobs-supported */
539 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
540 "multiple-document-jobs-supported", 1);
542 /* multiple-operation-time-out */
543 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
544 "multiple-operation-time-out", MultipleOperationTimeout
);
546 /* multiple-operation-time-out-action */
547 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
549 /* natural-language-configured (no IPP_TAG_COPY) */
550 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
551 "natural-language-configured", NULL
, DefaultLanguage
);
553 /* notify-attributes-supported */
554 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
555 "notify-attributes-supported",
556 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
559 /* notify-lease-duration-supported */
560 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
561 "notify-lease-duration-supported", 0,
562 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
564 /* notify-max-events-supported */
565 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
566 "notify-max-events-supported", MaxEvents
);
568 /* notify-events-supported */
569 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
570 "notify-events-supported",
571 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
572 NULL
, notify_events
);
574 /* notify-pull-method-supported */
575 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
576 "notify-pull-method-supported", NULL
, "ippget");
578 /* notify-schemes-supported */
579 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
580 if ((dir
= cupsDirOpen(filename
)) != NULL
)
582 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
584 while ((dent
= cupsDirRead(dir
)) != NULL
)
585 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
586 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
587 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
589 if (cupsArrayCount(notifiers
) > 0)
591 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
592 "notify-schemes-supported",
593 cupsArrayCount(notifiers
), NULL
, NULL
);
595 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
597 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
598 attr
->values
[i
].string
.text
= notifier
;
601 cupsArrayDelete(notifiers
);
605 /* number-up-supported */
606 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
607 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
609 /* operations-supported */
610 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
611 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
613 /* orientation-requested-supported */
614 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
615 "orientation-requested-supported", 4, orients
);
617 /* page-ranges-supported */
618 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
620 /* pdf-k-octets-supported */
621 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
624 /* pdf-versions-supported */
625 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
626 "pdf-versions-supported",
627 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
630 /* pdl-override-supported */
631 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
632 "pdl-override-supported", NULL
, "attempted");
634 /* printer-get-attributes-supported */
635 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
637 /* printer-op-policy-supported */
638 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
639 "printer-op-policy-supported", cupsArrayCount(Policies
),
641 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
643 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
644 attr
->values
[i
].string
.text
= p
->name
;
646 /* printer-settable-attributes-supported */
647 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
648 "printer-settable-attributes-supported",
649 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
650 NULL
, printer_settable
);
652 /* server-is-sharing-printers */
653 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
654 BrowseLocalProtocols
!= 0 && Browsing
);
656 /* which-jobs-supported */
657 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
658 "which-jobs-supported",
659 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
664 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
668 cupsdDeleteAllPrinters(void)
670 cupsd_printer_t
*p
; /* Pointer to current printer/class */
673 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
675 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
677 p
->op_policy_ptr
= DefaultPolicyPtr
;
678 cupsdDeletePrinter(p
, 0);
684 * 'cupsdDeletePrinter()' - Delete a printer from the system.
687 int /* O - 1 if classes affected, 0 otherwise */
689 cupsd_printer_t
*p
, /* I - Printer to delete */
690 int update
) /* I - Update printers.conf? */
692 int i
, /* Looping var */
693 changed
= 0; /* Class changed? */
696 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
700 * Save the current position in the Printers array...
703 cupsArraySave(Printers
);
706 * Stop printing on this printer...
709 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
711 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
714 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
715 update
? "Job stopped due to printer being deleted." :
719 * Remove the printer from the list...
722 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
723 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
724 cupsArrayRemove(Printers
, p
);
727 * If p is the default printer, assign a different one...
730 if (p
== DefaultPrinter
)
731 DefaultPrinter
= NULL
;
734 * Remove this printer from any classes...
737 changed
= cupsdDeletePrinterFromClasses(p
);
740 * Deregister from any browse protocols...
743 cupsdDeregisterPrinter(p
, 1);
746 * Remove support files if this is a temporary queue and deregister color
752 char filename
[1024]; /* Script/PPD filename */
755 * Remove any old PPD or script files...
758 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
760 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
763 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
766 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
770 * Unregister color profiles...
773 cupsdUnregisterColor(p
);
777 * Free all memory used by the printer...
780 if (p
->printers
!= NULL
)
783 delete_printer_filters(p
);
785 for (i
= 0; i
< p
->num_reasons
; i
++)
786 _cupsStrFree(p
->reasons
[i
]);
789 ippDelete(p
->ppd_attrs
);
791 mimeDeleteType(MimeDatabase
, p
->filetype
);
792 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
794 cupsdFreeStrings(&(p
->users
));
797 cupsdClearString(&p
->uri
);
798 cupsdClearString(&p
->hostname
);
799 cupsdClearString(&p
->name
);
800 cupsdClearString(&p
->location
);
801 cupsdClearString(&p
->geo_location
);
802 cupsdClearString(&p
->make_model
);
803 cupsdClearString(&p
->info
);
804 cupsdClearString(&p
->job_sheets
[0]);
805 cupsdClearString(&p
->job_sheets
[1]);
806 cupsdClearString(&p
->device_uri
);
807 cupsdClearString(&p
->sanitized_device_uri
);
808 cupsdClearString(&p
->port_monitor
);
809 cupsdClearString(&p
->op_policy
);
810 cupsdClearString(&p
->error_policy
);
812 cupsdClearString(&p
->alert
);
813 cupsdClearString(&p
->alert_description
);
815 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
816 cupsdClearString(&p
->pdl
);
817 cupsdClearString(&p
->reg_name
);
818 #endif /* HAVE_DNSSD || HAVE_AVAHI */
820 cupsArrayDelete(p
->filetypes
);
822 cupsFreeOptions(p
->num_options
, p
->options
);
827 * Restore the previous position in the Printers array...
830 cupsArrayRestore(Printers
);
837 * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
841 cupsdDeleteTemporaryPrinters(int force
) /* I - Force deletion instead of auto? */
843 cupsd_printer_t
*p
; /* Current printer */
844 time_t unused_time
; /* Last time for printer state change */
848 * Allow temporary printers to stick around for 60 seconds after the last job
852 unused_time
= time(NULL
) - 60;
854 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
); p
; p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
856 if (p
->temporary
&& (force
|| p
->state_time
< unused_time
))
857 cupsdDeletePrinter(p
, 0);
863 * 'cupsdFindDest()' - Find a destination in the list.
866 cupsd_printer_t
* /* O - Destination in list */
867 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
869 cupsd_printer_t key
; /* Search key */
872 key
.name
= (char *)name
;
873 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
878 * 'cupsdFindPrinter()' - Find a printer in the list.
881 cupsd_printer_t
* /* O - Printer in list */
882 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
884 cupsd_printer_t
*p
; /* Printer in list */
887 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
895 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
899 cupsdLoadAllPrinters(void)
901 int i
; /* Looping var */
902 cups_file_t
*fp
; /* printers.conf file */
903 int linenum
; /* Current line number */
904 char line
[4096], /* Line from file */
905 *value
, /* Pointer to value */
906 *valueptr
; /* Pointer into value */
907 cupsd_printer_t
*p
; /* Current printer */
911 * Open the printers.conf file...
914 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
915 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
919 * Read printer configurations until we hit EOF...
925 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
928 * Decode the directive...
931 if (!_cups_strcasecmp(line
, "<Printer") ||
932 !_cups_strcasecmp(line
, "<DefaultPrinter"))
935 * <Printer name> or <DefaultPrinter name>
938 if (p
== NULL
&& value
)
941 * Add the printer and a base file type...
944 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
946 p
= cupsdAddPrinter(value
);
948 p
->state
= IPP_PRINTER_IDLE
;
951 * Set the default printer as needed...
954 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
958 cupsdLogMessage(CUPSD_LOG_ERROR
,
959 "Syntax error on line %d of printers.conf.", linenum
);
961 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
966 * Close out the current printer...
969 cupsdSetPrinterAttrs(p
);
971 if (strncmp(p
->device_uri
, "file:", 5) &&
972 p
->state
!= IPP_PRINTER_STOPPED
)
975 * See if the backend exists...
978 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
981 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
982 *valueptr
= '\0'; /* Chop everything but URI scheme */
987 * Backend does not exist, stop printer...
990 p
->state
= IPP_PRINTER_STOPPED
;
991 snprintf(p
->state_message
, sizeof(p
->state_message
),
992 "Backend %s does not exist!", line
);
999 cupsdLogMessage(CUPSD_LOG_ERROR
,
1000 "Syntax error on line %d of printers.conf.", linenum
);
1004 cupsdLogMessage(CUPSD_LOG_ERROR
,
1005 "Syntax error on line %d of printers.conf.", linenum
);
1007 else if (!_cups_strcasecmp(line
, "UUID"))
1009 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1010 cupsdSetString(&(p
->uuid
), value
);
1012 cupsdLogMessage(CUPSD_LOG_ERROR
,
1013 "Bad UUID on line %d of printers.conf.", linenum
);
1015 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1017 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1018 cupsdLogMessage(CUPSD_LOG_ERROR
,
1019 "Bad AuthInfoRequired on line %d of printers.conf.",
1022 else if (!_cups_strcasecmp(line
, "Info"))
1025 cupsdSetString(&p
->info
, value
);
1027 else if (!_cups_strcasecmp(line
, "MakeModel"))
1030 cupsdSetString(&p
->make_model
, value
);
1032 else if (!_cups_strcasecmp(line
, "Location"))
1035 cupsdSetString(&p
->location
, value
);
1037 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1040 cupsdSetString(&p
->geo_location
, value
);
1042 else if (!_cups_strcasecmp(line
, "Organization"))
1045 cupsdSetString(&p
->organization
, value
);
1047 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1050 cupsdSetString(&p
->organizational_unit
, value
);
1052 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1055 cupsdSetDeviceURI(p
, value
);
1057 cupsdLogMessage(CUPSD_LOG_ERROR
,
1058 "Syntax error on line %d of printers.conf.", linenum
);
1060 else if (!_cups_strcasecmp(line
, "Option") && value
)
1066 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1069 cupsdLogMessage(CUPSD_LOG_ERROR
,
1070 "Syntax error on line %d of printers.conf.", linenum
);
1073 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1075 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1079 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1081 if (value
&& strcmp(value
, "none"))
1082 cupsdSetString(&p
->port_monitor
, value
);
1084 cupsdClearString(&p
->port_monitor
);
1086 cupsdLogMessage(CUPSD_LOG_ERROR
,
1087 "Syntax error on line %d of printers.conf.", linenum
);
1089 else if (!_cups_strcasecmp(line
, "Reason"))
1092 strcmp(value
, "connecting-to-device") &&
1093 strcmp(value
, "cups-insecure-filter-warning") &&
1094 strcmp(value
, "cups-missing-filter-warning"))
1096 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1097 if (!strcmp(value
, p
->reasons
[i
]))
1100 if (i
>= p
->num_reasons
&&
1101 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1103 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1108 cupsdLogMessage(CUPSD_LOG_ERROR
,
1109 "Syntax error on line %d of printers.conf.", linenum
);
1111 else if (!_cups_strcasecmp(line
, "State"))
1114 * Set the initial queue state...
1117 if (value
&& !_cups_strcasecmp(value
, "idle"))
1118 p
->state
= IPP_PRINTER_IDLE
;
1119 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1121 p
->state
= IPP_PRINTER_STOPPED
;
1123 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1124 if (!strcmp("paused", p
->reasons
[i
]))
1127 if (i
>= p
->num_reasons
&&
1128 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1130 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1135 cupsdLogMessage(CUPSD_LOG_ERROR
,
1136 "Syntax error on line %d of printers.conf.", linenum
);
1138 else if (!_cups_strcasecmp(line
, "StateMessage"))
1141 * Set the initial queue state message...
1145 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1147 else if (!_cups_strcasecmp(line
, "StateTime"))
1150 * Set the state time...
1154 p
->state_time
= atoi(value
);
1156 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1159 * Set the config time...
1163 p
->config_time
= atoi(value
);
1165 else if (!_cups_strcasecmp(line
, "Accepting"))
1168 * Set the initial accepting state...
1172 (!_cups_strcasecmp(value
, "yes") ||
1173 !_cups_strcasecmp(value
, "on") ||
1174 !_cups_strcasecmp(value
, "true")))
1177 (!_cups_strcasecmp(value
, "no") ||
1178 !_cups_strcasecmp(value
, "off") ||
1179 !_cups_strcasecmp(value
, "false")))
1182 cupsdLogMessage(CUPSD_LOG_ERROR
,
1183 "Syntax error on line %d of printers.conf.", linenum
);
1185 else if (!_cups_strcasecmp(line
, "Type"))
1188 p
->type
= (cups_ptype_t
)atoi(value
);
1190 cupsdLogMessage(CUPSD_LOG_ERROR
,
1191 "Syntax error on line %d of printers.conf.", linenum
);
1193 else if (!_cups_strcasecmp(line
, "Shared"))
1196 * Set the initial shared state...
1200 (!_cups_strcasecmp(value
, "yes") ||
1201 !_cups_strcasecmp(value
, "on") ||
1202 !_cups_strcasecmp(value
, "true")))
1205 (!_cups_strcasecmp(value
, "no") ||
1206 !_cups_strcasecmp(value
, "off") ||
1207 !_cups_strcasecmp(value
, "false")))
1210 cupsdLogMessage(CUPSD_LOG_ERROR
,
1211 "Syntax error on line %d of printers.conf.", linenum
);
1213 else if (!_cups_strcasecmp(line
, "JobSheets"))
1216 * Set the initial job sheets...
1221 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1226 cupsdSetString(&p
->job_sheets
[0], value
);
1228 while (isspace(*valueptr
& 255))
1233 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1238 cupsdSetString(&p
->job_sheets
[1], value
);
1242 cupsdLogMessage(CUPSD_LOG_ERROR
,
1243 "Syntax error on line %d of printers.conf.", linenum
);
1245 else if (!_cups_strcasecmp(line
, "AllowUser"))
1250 cupsdAddString(&(p
->users
), value
);
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Syntax error on line %d of printers.conf.", linenum
);
1256 else if (!_cups_strcasecmp(line
, "DenyUser"))
1261 cupsdAddString(&(p
->users
), value
);
1264 cupsdLogMessage(CUPSD_LOG_ERROR
,
1265 "Syntax error on line %d of printers.conf.", linenum
);
1267 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1270 p
->quota_period
= atoi(value
);
1272 cupsdLogMessage(CUPSD_LOG_ERROR
,
1273 "Syntax error on line %d of printers.conf.", linenum
);
1275 else if (!_cups_strcasecmp(line
, "PageLimit"))
1278 p
->page_limit
= atoi(value
);
1280 cupsdLogMessage(CUPSD_LOG_ERROR
,
1281 "Syntax error on line %d of printers.conf.", linenum
);
1283 else if (!_cups_strcasecmp(line
, "KLimit"))
1286 p
->k_limit
= atoi(value
);
1288 cupsdLogMessage(CUPSD_LOG_ERROR
,
1289 "Syntax error on line %d of printers.conf.", linenum
);
1291 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1295 cupsd_policy_t
*pol
; /* Policy */
1298 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1300 cupsdSetString(&p
->op_policy
, value
);
1301 p
->op_policy_ptr
= pol
;
1304 cupsdLogMessage(CUPSD_LOG_ERROR
,
1305 "Bad policy \"%s\" on line %d of printers.conf",
1309 cupsdLogMessage(CUPSD_LOG_ERROR
,
1310 "Syntax error on line %d of printers.conf.", linenum
);
1312 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1316 if (strcmp(value
, "retry-current-job") &&
1317 strcmp(value
, "abort-job") &&
1318 strcmp(value
, "retry-job") &&
1319 strcmp(value
, "stop-printer"))
1320 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1322 cupsdSetString(&p
->error_policy
, value
);
1325 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1327 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1329 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1332 cupsdLogMessage(CUPSD_LOG_ERROR
,
1333 "Syntax error on line %d of printers.conf.", linenum
);
1336 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1339 cupsdSetPrinterAttrs(p
);
1341 if (!strcmp(value
, "marker-change-time"))
1342 p
->marker_time
= atoi(valueptr
);
1344 cupsdSetPrinterAttr(p
, value
, valueptr
);
1347 else if (_cups_strcasecmp(line
, "Filter") &&
1348 _cups_strcasecmp(line
, "Prefilter") &&
1349 _cups_strcasecmp(line
, "Product"))
1352 * Something else we don't understand (and that wasn't used in a prior
1353 * release of CUPS...
1356 cupsdLogMessage(CUPSD_LOG_ERROR
,
1357 "Unknown configuration directive %s on line %d of "
1358 "printers.conf.", line
, linenum
);
1367 * 'cupsdRenamePrinter()' - Rename a printer.
1372 cupsd_printer_t
*p
, /* I - Printer */
1373 const char *name
) /* I - New name */
1376 * Remove the printer from the array(s) first...
1379 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1380 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1381 cupsArrayRemove(Printers
, p
);
1384 * Rename the printer type...
1387 mimeDeleteType(MimeDatabase
, p
->filetype
);
1388 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1390 if (p
->prefiltertype
)
1392 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1393 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1397 * Rename the printer...
1400 cupsdSetString(&p
->name
, name
);
1403 * Reset printer attributes...
1406 cupsdSetPrinterAttrs(p
);
1409 * Add the printer back to the printer array(s)...
1412 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1413 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1414 cupsArrayAdd(Printers
, p
);
1419 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1424 cupsdSaveAllPrinters(void)
1426 int i
; /* Looping var */
1427 cups_file_t
*fp
; /* printers.conf file */
1428 char filename
[1024], /* printers.conf filename */
1429 temp
[1024], /* Temporary string */
1430 value
[2048], /* Value string */
1431 *ptr
, /* Pointer into value */
1432 *name
; /* Current user/group name */
1433 cupsd_printer_t
*printer
; /* Current printer class */
1434 time_t curtime
; /* Current time */
1435 struct tm
*curdate
; /* Current date */
1436 cups_option_t
*option
; /* Current option */
1437 ipp_attribute_t
*marker
; /* Current marker attribute */
1441 * Create the printers.conf file...
1444 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1446 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1449 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1452 * Write a small header to the file...
1455 curtime
= time(NULL
);
1456 curdate
= localtime(&curtime
);
1457 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1459 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1460 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1461 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1464 * Write each local printer known to the system...
1467 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1469 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1472 * Skip printer classes and temporary queues...
1475 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1479 * Write printers as needed...
1482 if (printer
== DefaultPrinter
)
1483 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1485 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1487 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1489 if (printer
->num_auth_info_required
> 0)
1491 switch (printer
->num_auth_info_required
)
1494 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1498 snprintf(value
, sizeof(value
), "%s,%s",
1499 printer
->auth_info_required
[0],
1500 printer
->auth_info_required
[1]);
1505 snprintf(value
, sizeof(value
), "%s,%s,%s",
1506 printer
->auth_info_required
[0],
1507 printer
->auth_info_required
[1],
1508 printer
->auth_info_required
[2]);
1512 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1516 cupsFilePutConf(fp
, "Info", printer
->info
);
1518 if (printer
->location
)
1519 cupsFilePutConf(fp
, "Location", printer
->location
);
1521 if (printer
->geo_location
)
1522 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1524 if (printer
->make_model
)
1525 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1527 if (printer
->organization
)
1528 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1530 if (printer
->organizational_unit
)
1531 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1533 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1535 if (printer
->port_monitor
)
1536 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1538 if (printer
->state
== IPP_PRINTER_STOPPED
)
1540 cupsFilePuts(fp
, "State Stopped\n");
1542 if (printer
->state_message
[0])
1543 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1546 cupsFilePuts(fp
, "State Idle\n");
1548 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1549 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1551 for (i
= 0; i
< printer
->num_reasons
; i
++)
1552 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1553 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1554 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1555 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1557 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1559 if (printer
->accepting
)
1560 cupsFilePuts(fp
, "Accepting Yes\n");
1562 cupsFilePuts(fp
, "Accepting No\n");
1564 if (printer
->shared
)
1565 cupsFilePuts(fp
, "Shared Yes\n");
1567 cupsFilePuts(fp
, "Shared No\n");
1569 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1570 printer
->job_sheets
[1]);
1571 cupsFilePutConf(fp
, "JobSheets", value
);
1573 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1574 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1575 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1577 for (name
= (char *)cupsArrayFirst(printer
->users
);
1579 name
= (char *)cupsArrayNext(printer
->users
))
1580 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1582 if (printer
->op_policy
)
1583 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1584 if (printer
->error_policy
)
1585 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1587 for (i
= printer
->num_options
, option
= printer
->options
;
1591 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1592 cupsFilePutConf(fp
, "Option", value
);
1595 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1596 IPP_TAG_NAME
)) != NULL
)
1598 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1600 for (i
= 0, ptr
= value
+ strlen(value
);
1601 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1607 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1612 cupsFilePutConf(fp
, "Attribute", value
);
1615 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1616 IPP_TAG_INTEGER
)) != NULL
)
1618 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1619 marker
->values
[0].integer
);
1620 for (i
= 1; i
< marker
->num_values
; i
++)
1621 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1622 cupsFilePuts(fp
, "\n");
1625 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1626 IPP_TAG_INTEGER
)) != NULL
)
1628 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1629 marker
->values
[0].integer
);
1630 for (i
= 1; i
< marker
->num_values
; i
++)
1631 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1632 cupsFilePuts(fp
, "\n");
1635 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1636 IPP_TAG_INTEGER
)) != NULL
)
1638 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1639 marker
->values
[0].integer
);
1640 for (i
= 1; i
< marker
->num_values
; i
++)
1641 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1642 cupsFilePuts(fp
, "\n");
1645 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1646 IPP_TAG_TEXT
)) != NULL
)
1648 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1649 marker
->values
[0].string
.text
);
1651 cupsFilePutConf(fp
, "Attribute", value
);
1654 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1655 IPP_TAG_NAME
)) != NULL
)
1657 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1659 for (i
= 0, ptr
= value
+ strlen(value
);
1660 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1666 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1671 cupsFilePutConf(fp
, "Attribute", value
);
1674 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1675 IPP_TAG_KEYWORD
)) != NULL
)
1677 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1679 for (i
= 0, ptr
= value
+ strlen(value
);
1680 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1686 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1691 cupsFilePutConf(fp
, "Attribute", value
);
1694 if (printer
->marker_time
)
1695 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1696 (long)printer
->marker_time
);
1698 if (printer
== DefaultPrinter
)
1699 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1701 cupsFilePuts(fp
, "</Printer>\n");
1704 cupsdCloseCreatedConfFile(fp
, filename
);
1709 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1712 int /* O - 1 if value OK, 0 otherwise */
1713 cupsdSetAuthInfoRequired(
1714 cupsd_printer_t
*p
, /* I - Printer */
1715 const char *values
, /* I - Plain text value (or NULL) */
1716 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1718 int i
; /* Looping var */
1721 p
->num_auth_info_required
= 0;
1724 * Do we have a plain text value?
1730 * Yes, grab the keywords...
1733 const char *end
; /* End of current value */
1736 while (*values
&& p
->num_auth_info_required
< 4)
1738 if ((end
= strchr(values
, ',')) == NULL
)
1739 end
= values
+ strlen(values
);
1741 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1743 if (p
->num_auth_info_required
!= 0 || *end
)
1746 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1747 p
->num_auth_info_required
++;
1751 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1753 if (p
->num_auth_info_required
!= 0 || *end
)
1756 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1757 p
->num_auth_info_required
++;
1760 * Don't allow sharing of queues that require Kerberos authentication.
1765 cupsdDeregisterPrinter(p
, 1);
1769 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1771 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1772 p
->num_auth_info_required
++;
1774 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1776 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1777 p
->num_auth_info_required
++;
1779 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1781 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1782 p
->num_auth_info_required
++;
1787 values
= (*end
) ? end
+ 1 : end
;
1790 if (p
->num_auth_info_required
== 0)
1792 p
->auth_info_required
[0] = "none";
1793 p
->num_auth_info_required
= 1;
1797 * Update the printer-type value as needed...
1800 if (p
->num_auth_info_required
> 1 ||
1801 strcmp(p
->auth_info_required
[0], "none"))
1802 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1804 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1810 * Grab values from an attribute instead...
1813 if (!attr
|| attr
->num_values
> 4)
1816 for (i
= 0; i
< attr
->num_values
; i
++)
1818 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1820 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1823 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1824 p
->num_auth_info_required
++;
1828 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1830 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1833 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1834 p
->num_auth_info_required
++;
1837 * Don't allow sharing of queues that require Kerberos authentication.
1842 cupsdDeregisterPrinter(p
, 1);
1848 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1850 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1851 p
->num_auth_info_required
++;
1853 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1855 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1856 p
->num_auth_info_required
++;
1858 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1860 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1861 p
->num_auth_info_required
++;
1872 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1876 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1877 const char *uri
) /* I - Device URI */
1879 char buffer
[1024], /* URI buffer */
1880 *start
, /* Start of data after scheme */
1881 *slash
, /* First slash after scheme:// */
1882 *ptr
; /* Pointer into user@host:port part */
1886 * Set the full device URI..
1889 cupsdSetString(&(p
->device_uri
), uri
);
1892 * Copy the device URI to a temporary buffer so we can sanitize any auth
1896 strlcpy(buffer
, uri
, sizeof(buffer
));
1899 * Find the end of the scheme:// part...
1902 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1904 for (start
= ptr
+ 1; *start
; start
++)
1909 * Find the next slash (/) in the URI...
1912 if ((slash
= strchr(start
, '/')) == NULL
)
1913 slash
= start
+ strlen(start
); /* No slash, point to the end */
1916 * Check for an @ sign before the slash...
1919 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1922 * Found an @ sign and it is before the resource part, so we have
1923 * an authentication string. Copy the remaining URI over the
1924 * authentication string...
1927 _cups_strcpy(start
, ptr
+ 1);
1932 * Save the sanitized URI...
1935 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1940 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1944 cupsdSetPrinterAttr(
1945 cupsd_printer_t
*p
, /* I - Printer */
1946 const char *name
, /* I - Attribute name */
1947 const char *value
) /* I - Attribute value string */
1949 ipp_attribute_t
*attr
; /* Attribute */
1950 int i
, /* Looping var */
1951 count
; /* Number of values */
1952 char *temp
, /* Temporary copy of value string */
1953 *ptr
, /* Pointer into value */
1954 *start
, /* Start of value */
1955 quote
; /* Quote character */
1956 ipp_tag_t value_tag
; /* Value tag for this attribute */
1960 * Don't allow empty values...
1963 if (!*value
&& strcmp(name
, "marker-message"))
1965 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1970 * Copy the value string so we can do what we want with it...
1973 if ((temp
= strdup(value
)) == NULL
)
1975 cupsdLogMessage(CUPSD_LOG_ERROR
,
1976 "Unable to duplicate value for \"%s\" attribute.", name
);
1981 * Count the number of values...
1984 for (count
= 1, quote
= '\0', ptr
= temp
;
1992 else if (*ptr
== '\\' && ptr
[1])
1994 else if (*ptr
== '\'' || *ptr
== '\"')
1996 else if (*ptr
== ',')
2001 * Then add or update the attribute as needed...
2004 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2005 !strcmp(name
, "marker-high-levels"))
2011 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2012 attr
->num_values
< count
)
2014 ippDeleteAttribute(p
->attrs
, attr
);
2019 attr
->num_values
= count
;
2021 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2027 cupsdLogMessage(CUPSD_LOG_ERROR
,
2028 "Unable to allocate memory for printer attribute "
2029 "(%d values)", count
);
2033 for (i
= 0, start
= temp
; i
< count
; i
++)
2035 if ((ptr
= strchr(start
, ',')) != NULL
)
2038 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2047 * Name or keyword values...
2050 if (!strcmp(name
, "marker-types"))
2051 value_tag
= IPP_TAG_KEYWORD
;
2052 else if (!strcmp(name
, "marker-message"))
2053 value_tag
= IPP_TAG_TEXT
;
2055 value_tag
= IPP_TAG_NAME
;
2057 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2058 attr
->num_values
< count
)
2060 ippDeleteAttribute(p
->attrs
, attr
);
2066 for (i
= 0; i
< attr
->num_values
; i
++)
2067 _cupsStrFree(attr
->values
[i
].string
.text
);
2069 attr
->num_values
= count
;
2072 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2078 cupsdLogMessage(CUPSD_LOG_ERROR
,
2079 "Unable to allocate memory for printer attribute "
2080 "(%d values)", count
);
2084 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2086 for (start
= ptr
; *ptr
; ptr
++)
2089 *ptr
= quote
= '\0';
2092 else if (*ptr
== '\\' && ptr
[1])
2093 _cups_strcpy(ptr
, ptr
+ 1);
2094 else if (*ptr
== '\'' || *ptr
== '\"')
2101 _cups_strcpy(ptr
, ptr
+ 1);
2103 else if (*ptr
== ',')
2110 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2117 * Update the printer-supply and printer-supply-description, as needed...
2120 if (!strcmp(name
, "marker-names"))
2122 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2123 /* printer-supply-description attribute */
2125 if (supply_desc
!= NULL
)
2126 ippDeleteAttribute(p
->attrs
, supply_desc
);
2128 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2129 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2130 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2132 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2134 char buffer
[256], /* printer-supply values */
2135 pstype
[64], /* printer-supply type value */
2136 *psptr
; /* Pointer into type */
2137 const char *color
, /* marker-colors value */
2138 *type
; /* marker-types value */
2139 int level
; /* marker-levels value */
2140 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2141 /* marker-colors attribute */
2142 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2143 /* marker-levels attribute */
2144 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2145 /* marker-types attribute */
2146 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2147 /* printer-supply attribute */
2151 ippDeleteAttribute(p
->attrs
, supply
);
2155 if (!colors
|| !levels
|| !types
)
2158 count
= ippGetCount(colors
);
2159 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2162 for (i
= 0; i
< count
; i
++)
2164 color
= ippGetString(colors
, i
, NULL
);
2165 level
= ippGetInteger(levels
, i
);
2166 type
= ippGetString(types
, i
, NULL
);
2168 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2172 *psptr
++ = (char)toupper(*type
& 255);
2178 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
);
2181 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2183 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2190 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2194 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2196 int i
; /* Looping var */
2197 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2198 cupsd_location_t
*auth
; /* Pointer to authentication element */
2199 const char *auth_supported
; /* Authentication supported */
2200 ipp_t
*oldattrs
; /* Old printer attributes */
2201 ipp_attribute_t
*attr
; /* Attribute data */
2202 char *name
, /* Current user/group name */
2203 *filter
; /* Current filter */
2206 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2210 * Make sure that we have the common attributes defined...
2214 cupsdCreateCommonData();
2216 _cupsRWLockWrite(&p
->lock
);
2219 * Clear out old filters, if any...
2222 delete_printer_filters(p
);
2225 * Figure out the authentication that is required for the printer.
2228 auth_supported
= "requesting-user-name";
2230 if (p
->type
& CUPS_PRINTER_CLASS
)
2231 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2233 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2235 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2236 auth
->type
== CUPSD_AUTH_NONE
)
2237 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2241 int auth_type
; /* Authentication type */
2244 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2245 auth_type
= cupsdDefaultAuthType();
2247 if (auth_type
== CUPSD_AUTH_BASIC
)
2248 auth_supported
= "basic";
2250 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2251 auth_supported
= "negotiate";
2252 #endif /* HAVE_GSSAPI */
2254 if (auth_type
!= CUPSD_AUTH_NONE
)
2255 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2257 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2260 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2263 * Create the required IPP attributes for a printer...
2266 oldattrs
= p
->attrs
;
2267 p
->attrs
= ippNew();
2269 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2270 "uri-authentication-supported", NULL
, auth_supported
);
2271 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2272 "uri-security-supported", NULL
, "none");
2273 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2275 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2276 NULL
, p
->location
? p
->location
: "");
2277 if (p
->geo_location
)
2278 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2280 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2281 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2282 NULL
, p
->info
? p
->info
: "");
2283 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2284 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2285 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2287 if (cupsArrayCount(p
->users
) > 0)
2290 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2291 "requesting-user-name-denied",
2292 cupsArrayCount(p
->users
), NULL
, NULL
);
2294 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2295 "requesting-user-name-allowed",
2296 cupsArrayCount(p
->users
), NULL
, NULL
);
2298 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2300 i
++, name
= (char *)cupsArrayNext(p
->users
))
2301 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2304 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2305 "job-quota-period", p
->quota_period
);
2306 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2307 "job-k-limit", p
->k_limit
);
2308 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2309 "job-page-limit", p
->page_limit
);
2310 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2311 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2312 "auth-info-required", p
->num_auth_info_required
, NULL
,
2313 p
->auth_info_required
);
2315 if (cupsArrayCount(Banners
) > 0)
2318 * Setup the job-sheets-default attribute...
2321 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2322 "job-sheets-default", 2, NULL
, NULL
);
2326 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2327 Classification
: p
->job_sheets
[0]);
2328 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2329 Classification
: p
->job_sheets
[1]);
2337 * Assign additional attributes depending on whether this is a printer
2341 if (p
->type
& CUPS_PRINTER_CLASS
)
2344 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2347 * Add class-specific attributes...
2350 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2351 "printer-make-and-model", NULL
, "Local Printer Class");
2352 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2353 "file:///dev/null");
2355 if (p
->num_printers
> 0)
2358 * Add a list of member names; URIs are added in copy_printer_attrs...
2361 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2362 "member-names", p
->num_printers
, NULL
, NULL
);
2363 p
->type
|= CUPS_PRINTER_OPTIONS
;
2365 for (i
= 0; i
< p
->num_printers
; i
++)
2368 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2370 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2377 * Add printer-specific attributes...
2380 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2381 p
->sanitized_device_uri
);
2384 * Assign additional attributes from the PPD file (if any)...
2390 * Add filters for printer...
2393 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2394 "cups-insecure-filter-warning");
2396 if (p
->pc
&& p
->pc
->filters
)
2398 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2400 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2401 add_printer_filter(p
, p
->filetype
, filter
);
2403 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2406 * Add a filter from application/vnd.cups-raw to printer/name to
2407 * handle "raw" printing by users.
2410 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2413 * Add a PostScript filter, since this is still possibly PS printer.
2416 add_printer_filter(p
, p
->filetype
,
2417 "application/vnd.cups-postscript 0 -");
2420 if (p
->pc
&& p
->pc
->prefilters
)
2422 if (!p
->prefiltertype
)
2423 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2425 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2427 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2428 add_printer_filter(p
, p
->prefiltertype
, filter
);
2433 * Copy marker attributes as needed...
2438 ipp_attribute_t
*oldattr
; /* Old attribute */
2441 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2442 IPP_TAG_NAME
)) != NULL
)
2444 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2445 "marker-colors", oldattr
->num_values
, NULL
,
2448 for (i
= 0; i
< oldattr
->num_values
; i
++)
2449 attr
->values
[i
].string
.text
=
2450 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2454 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2455 IPP_TAG_INTEGER
)) != NULL
)
2457 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2458 "marker-levels", oldattr
->num_values
,
2461 for (i
= 0; i
< oldattr
->num_values
; i
++)
2462 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2466 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2467 IPP_TAG_TEXT
)) != NULL
)
2468 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2469 NULL
, oldattr
->values
[0].string
.text
);
2471 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2472 IPP_TAG_INTEGER
)) != NULL
)
2474 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2475 "marker-low-levels", oldattr
->num_values
,
2478 for (i
= 0; i
< oldattr
->num_values
; i
++)
2479 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2483 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2484 IPP_TAG_INTEGER
)) != NULL
)
2486 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2487 "marker-high-levels", oldattr
->num_values
,
2490 for (i
= 0; i
< oldattr
->num_values
; i
++)
2491 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2495 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2496 IPP_TAG_NAME
)) != NULL
)
2498 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2499 "marker-names", oldattr
->num_values
, NULL
,
2502 for (i
= 0; i
< oldattr
->num_values
; i
++)
2503 attr
->values
[i
].string
.text
=
2504 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2508 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2509 IPP_TAG_KEYWORD
)) != NULL
)
2511 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2512 "marker-types", oldattr
->num_values
, NULL
,
2515 for (i
= 0; i
< oldattr
->num_values
; i
++)
2516 attr
->values
[i
].string
.text
=
2517 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2521 ippDelete(oldattrs
);
2525 * Force sharing off for remote queues...
2528 if (p
->type
& CUPS_PRINTER_REMOTE
)
2532 * Populate the document-format-supported attribute...
2535 add_printer_formats(p
);
2537 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2541 * Add name-default attributes...
2544 add_printer_defaults(p
);
2546 _cupsRWUnlock(&p
->lock
);
2549 * Let the browse protocols reflect the change
2552 cupsdRegisterPrinter(p
);
2557 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2560 int /* O - 1 if something changed, 0 otherwise */
2561 cupsdSetPrinterReasons(
2562 cupsd_printer_t
*p
, /* I - Printer */
2563 const char *s
) /* I - Reasons strings */
2565 int i
, /* Looping var */
2566 changed
= 0; /* Did something change? */
2567 const char *sptr
; /* Pointer into reasons */
2568 char reason
[255], /* Reason string */
2569 *rptr
; /* Pointer into reason */
2572 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2573 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2575 if (s
[0] == '-' || s
[0] == '+')
2578 * Add/remove reasons...
2586 * Replace reasons...
2591 for (i
= 0; i
< p
->num_reasons
; i
++)
2592 _cupsStrFree(p
->reasons
[i
]);
2600 if (!strcmp(s
, "none"))
2604 * Loop through all of the reasons...
2610 * Skip leading whitespace and commas...
2613 while (isspace(*sptr
& 255) || *sptr
== ',')
2616 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2617 if (rptr
< (reason
+ sizeof(reason
) - 1))
2631 for (i
= 0; i
< p
->num_reasons
; i
++)
2632 if (!strcmp(reason
, p
->reasons
[i
]))
2635 * Found a match, so remove it...
2640 _cupsStrFree(p
->reasons
[i
]);
2642 if (i
< p
->num_reasons
)
2643 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2645 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2646 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2648 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2649 p
->job
->completed
= 0;
2651 if (strcmp(reason
, "connecting-to-device"))
2657 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2663 for (i
= 0; i
< p
->num_reasons
; i
++)
2664 if (!strcmp(reason
, p
->reasons
[i
]))
2667 if (i
>= p
->num_reasons
)
2669 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2671 cupsdLogMessage(CUPSD_LOG_ALERT
,
2672 "Too many printer-state-reasons values for %s (%d)",
2677 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2681 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2682 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2684 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2685 p
->job
->completed
= 1;
2687 if (strcmp(reason
, "connecting-to-device"))
2698 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2702 cupsdSetPrinterState(
2703 cupsd_printer_t
*p
, /* I - Printer to change */
2704 ipp_pstate_t s
, /* I - New state */
2705 int update
) /* I - Update printers.conf? */
2707 cupsd_job_t
*job
; /* Current job */
2708 ipp_pstate_t old_state
; /* Old printer state */
2709 static const char * const printer_states
[] =
2710 { /* State strings */
2718 * Set the new state...
2721 old_state
= p
->state
;
2726 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2727 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2728 "%s \"%s\" state changed to %s.",
2729 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2730 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2733 * Let the browse code know this needs to be updated...
2736 p
->state_time
= time(NULL
);
2740 * Set/clear the paused reason as needed...
2743 if (s
== IPP_PRINTER_STOPPED
)
2744 cupsdSetPrinterReasons(p
, "+paused");
2746 cupsdSetPrinterReasons(p
, "-paused");
2750 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2752 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2753 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2754 !_cups_strcasecmp(job
->dest
, p
->name
))
2755 ippSetString(job
->attrs
, &job
->reasons
, 0,
2756 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2760 * Clear the message for the queue when going to processing...
2763 if (s
== IPP_PRINTER_PROCESSING
)
2764 p
->state_message
[0] = '\0';
2767 * Let the browse protocols reflect the change...
2771 cupsdRegisterPrinter(p
);
2774 * Save the printer configuration if a printer goes from idle or processing
2775 * to stopped (or visa-versa)...
2779 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2785 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2789 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2790 int update
)/* I - Update printers.conf? */
2793 * Set the printer state...
2796 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2799 * See if we have a job printing on this printer...
2802 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2803 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2804 "Job stopped due to printer being paused.");
2809 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2812 int /* O - 1 if successful, 0 otherwise */
2813 cupsdUpdatePrinterPPD(
2814 cupsd_printer_t
*p
, /* I - Printer */
2815 int num_keywords
, /* I - Number of keywords */
2816 cups_option_t
*keywords
) /* I - Keywords */
2818 int i
; /* Looping var */
2819 cups_file_t
*src
, /* Original file */
2820 *dst
; /* New file */
2821 char srcfile
[1024], /* Original filename */
2822 dstfile
[1024], /* New filename */
2823 line
[1024], /* Line from file */
2824 keystring
[41]; /* Keyword from line */
2825 cups_option_t
*keyword
; /* Current keyword */
2828 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2832 * Get the old and new PPD filenames...
2835 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2836 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2839 * Rename the old file and open the old and new...
2842 if (rename(dstfile
, srcfile
))
2844 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2845 p
->name
, strerror(errno
));
2849 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2851 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2852 srcfile
, strerror(errno
));
2853 rename(srcfile
, dstfile
);
2857 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2859 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2860 dstfile
, strerror(errno
));
2862 rename(srcfile
, dstfile
);
2867 * Copy the first line and then write out all of the keywords...
2870 if (!cupsFileGets(src
, line
, sizeof(line
)))
2872 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2873 srcfile
, strerror(errno
));
2876 rename(srcfile
, dstfile
);
2880 cupsFilePrintf(dst
, "%s\n", line
);
2882 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2884 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2885 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2889 * Then copy the rest of the PPD file, dropping any keywords we changed.
2892 while (cupsFileGets(src
, line
, sizeof(line
)))
2895 * Skip keywords we've already set...
2898 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2899 cupsGetOption(keystring
, num_keywords
, keywords
))
2903 * Otherwise write the line...
2906 cupsFilePrintf(dst
, "%s\n", line
);
2910 * Close files and return...
2921 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2925 cupsdUpdatePrinters(void)
2927 cupsd_printer_t
*p
; /* Current printer */
2931 * Loop through the printers and recreate the printer attributes
2932 * for any local printers since the policy and/or access control
2933 * stuff may have changed. Also, if browsing is disabled, remove
2934 * any remote printers...
2937 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2939 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2942 * Update the operation policy pointer...
2945 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2946 p
->op_policy_ptr
= DefaultPolicyPtr
;
2949 * Update printer attributes...
2952 cupsdSetPrinterAttrs(p
);
2958 * 'cupsdValidateDest()' - Validate a printer/class destination.
2961 const char * /* O - Printer or class name */
2963 const char *uri
, /* I - Printer URI */
2964 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2965 cupsd_printer_t
**printer
) /* O - Printer pointer */
2967 cupsd_printer_t
*p
; /* Current printer */
2968 char localname
[1024],/* Localized hostname */
2969 *lptr
, /* Pointer into localized hostname */
2970 *sptr
, /* Pointer into server name */
2971 *rptr
, /* Pointer into resource */
2972 scheme
[32], /* Scheme portion of URI */
2973 username
[64], /* Username portion of URI */
2974 hostname
[HTTP_MAX_HOST
],
2975 /* Host portion of URI */
2976 resource
[HTTP_MAX_URI
];
2977 /* Resource portion of URI */
2978 int port
; /* Port portion of URI */
2981 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2985 * Initialize return values...
2992 *dtype
= (cups_ptype_t
)0;
2995 * Pull the hostname and resource from the URI...
2998 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2999 username
, sizeof(username
), hostname
, sizeof(hostname
),
3000 &port
, resource
, sizeof(resource
));
3003 * See if the resource is a class or printer...
3006 if (!strncmp(resource
, "/classes/", 9))
3012 rptr
= resource
+ 9;
3014 else if (!strncmp(resource
, "/printers/", 10))
3020 rptr
= resource
+ 10;
3025 * Bad resource name...
3032 * See if the printer or class name exists...
3035 p
= cupsdFindDest(rptr
);
3037 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3045 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3051 * Change localhost to the server name...
3054 if (!_cups_strcasecmp(hostname
, "localhost"))
3055 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3057 strlcpy(localname
, hostname
, sizeof(localname
));
3059 if (!_cups_strcasecmp(hostname
, ServerName
))
3062 * Localize the hostname...
3065 lptr
= strchr(localname
, '.');
3066 sptr
= strchr(ServerName
, '.');
3068 if (sptr
!= NULL
&& lptr
!= NULL
)
3071 * Strip the common domain name components...
3074 while (lptr
!= NULL
)
3076 if (!_cups_strcasecmp(lptr
, sptr
))
3082 lptr
= strchr(lptr
+ 1, '.');
3087 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3090 * Find a matching printer or class...
3093 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3095 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3096 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3097 !_cups_strcasecmp(p
->name
, rptr
))
3103 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3113 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3118 cupsdWritePrintcap(void)
3120 int i
; /* Looping var */
3121 cups_file_t
*fp
; /* Printcap file */
3122 cupsd_printer_t
*p
; /* Current printer */
3126 * See if we have a printcap file; if not, don't bother writing it.
3129 if (!Printcap
|| !*Printcap
)
3132 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3135 * Open the printcap file...
3138 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3142 * Put a comment header at the top so that users will know where the
3143 * data has come from...
3146 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3147 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3149 "# %s/printers.conf file. All changes to this file\n"
3150 "# will be lost.\n", ServerRoot
);
3153 * Write a new printcap with the current list of printers.
3156 switch (PrintcapFormat
)
3160 * Each printer is put in the file as:
3170 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3171 DefaultPrinter
->info
, ServerName
,
3172 DefaultPrinter
->name
);
3174 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3176 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3177 if (p
!= DefaultPrinter
)
3178 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3179 ServerName
, p
->name
);
3182 case PRINTCAP_PLIST
:
3184 * Each printer is written as a dictionary in a plist file.
3185 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3186 * printer-location, printer-make-and-model, printer-state,
3187 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3190 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3191 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3192 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3193 "PropertyList-1.0.dtd\">\n"
3194 "<plist version=\"1.0\">\n"
3197 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3199 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3201 cupsFilePuts(fp
, "\t<dict>\n"
3202 "\t\t<key>printer-name</key>\n"
3204 write_xml_string(fp
, p
->name
);
3205 cupsFilePuts(fp
, "</string>\n"
3206 "\t\t<key>printer-info</key>\n"
3208 write_xml_string(fp
, p
->info
);
3209 cupsFilePrintf(fp
, "</string>\n"
3210 "\t\t<key>printer-is-accepting-jobs</key>\n"
3212 "\t\t<key>printer-location</key>\n"
3213 "\t\t<string>", p
->accepting
? "true" : "false");
3214 write_xml_string(fp
, p
->location
);
3215 cupsFilePuts(fp
, "</string>\n"
3216 "\t\t<key>printer-make-and-model</key>\n"
3218 write_xml_string(fp
, p
->make_model
);
3219 cupsFilePrintf(fp
, "</string>\n"
3220 "\t\t<key>printer-state</key>\n"
3221 "\t\t<integer>%d</integer>\n"
3222 "\t\t<key>printer-state-reasons</key>\n"
3223 "\t\t<array>\n", p
->state
);
3224 for (i
= 0; i
< p
->num_reasons
; i
++)
3226 cupsFilePuts(fp
, "\t\t\t<string>");
3227 write_xml_string(fp
, p
->reasons
[i
]);
3228 cupsFilePuts(fp
, "</string>\n");
3230 cupsFilePrintf(fp
, "\t\t</array>\n"
3231 "\t\t<key>printer-type</key>\n"
3232 "\t\t<integer>%d</integer>\n"
3233 "\t\t<key>device-uri</key>\n"
3234 "\t\t<string>", p
->type
);
3235 write_xml_string(fp
, p
->sanitized_device_uri
);
3236 cupsFilePuts(fp
, "</string>\n"
3239 cupsFilePuts(fp
, "</array>\n"
3243 case PRINTCAP_SOLARIS
:
3245 * Each printer is put in the file as:
3247 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3248 * _default:use=DefaultPrinter
3250 * :bsdaddr=ServerName,Printer1:\
3251 * :description=Description:
3253 * :bsdaddr=ServerName,Printer2:\
3254 * :description=Description:
3256 * :bsdaddr=ServerName,Printer3:\
3257 * :description=Description:
3260 * :bsdaddr=ServerName,PrinterN:\
3261 * :description=Description:
3264 cupsFilePuts(fp
, "_all:all=");
3265 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3267 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3268 cupsFilePrintf(fp
, "%s%c", p
->name
,
3269 cupsArrayNext(Printers
) ? ',' : '\n');
3272 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3274 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3276 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3277 cupsFilePrintf(fp
, "%s:\\\n"
3278 "\t:bsdaddr=%s,%s:\\\n"
3279 "\t:description=%s:\n",
3280 p
->name
, ServerName
, p
->name
,
3281 p
->info
? p
->info
: "");
3294 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3298 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3300 int i
; /* Looping var */
3301 int num_options
; /* Number of default options */
3302 cups_option_t
*options
, /* Default options */
3303 *option
; /* Current option */
3304 char name
[256]; /* name-default */
3308 * Maintain a common array of default attribute names...
3311 if (!CommonDefaults
)
3313 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3315 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3316 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3317 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3318 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3319 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-accounting-user-id-default"));
3320 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3321 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3322 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3323 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3324 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3325 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-lease-duration-default"));
3326 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-events-default"));
3327 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3328 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("orientation-requested-default"));
3329 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("print-quality-default"));
3333 * Add all of the default options from the .conf files...
3336 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3340 if (strcmp(option
->name
, "ipp-options") &&
3341 strcmp(option
->name
, "job-sheets") &&
3342 strcmp(option
->name
, "lease-duration"))
3344 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3345 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3347 if (!cupsArrayFind(CommonDefaults
, name
))
3348 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3353 * Convert options to IPP attributes...
3356 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3357 cupsFreeOptions(num_options
, options
);
3360 * Add standard -default attributes as needed...
3363 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3364 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3367 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3368 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3369 "document-format-default", NULL
, "application/octet-stream");
3371 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3372 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, MaxJobTime
> 0 ? IPP_TAG_INTEGER
: IPP_TAG_NOVALUE
,
3373 "job-cancel-after-default", MaxJobTime
);
3375 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3376 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3377 "job-hold-until-default", NULL
, "no-hold");
3379 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3380 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3381 "job-priority-default", 50);
3383 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3384 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3385 "number-up-default", 1);
3387 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3388 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3389 "notify-lease-duration-default", DefaultLeaseDuration
);
3391 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3392 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3393 "notify-events-default", NULL
, "job-completed");
3395 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3396 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3397 "orientation-requested-default", NULL
, NULL
);
3399 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3400 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3401 "print-quality-default", IPP_QUALITY_NORMAL
);
3406 * 'add_printer_filter()' - Add a MIME filter for a printer.
3411 cupsd_printer_t
*p
, /* I - Printer to add to */
3412 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3413 const char *filter
) /* I - Filter to add */
3415 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3416 type
[MIME_MAX_TYPE
], /* Type for filter */
3417 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3418 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3419 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3420 /* Destination super/type */
3421 program
[1024]; /* Program/filter name */
3422 int cost
; /* Cost of filter */
3423 size_t maxsize
= 0; /* Maximum supported file size */
3424 mime_type_t
*temptype
, /* MIME type looping var */
3425 *desttype
; /* Destination MIME type */
3426 mime_filter_t
*filterptr
; /* MIME filter */
3427 char filename
[1024]; /* Full filter filename */
3430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3431 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3432 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3433 filtertype
->type
, filter
);
3436 * Parse the filter string; it should be in one of the following formats:
3438 * source/type cost program
3439 * source/type cost maxsize(nnnn) program
3440 * source/type dest/type cost program
3441 * source/type dest/type cost maxsize(nnnn) program
3444 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3445 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3447 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3449 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3451 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3453 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3455 cupsArrayAdd(p
->dest_types
, desttype
);
3461 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3464 desttype
= filtertype
;
3468 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3474 if (!strncmp(program
, "maxsize(", 8))
3476 char *ptr
; /* Pointer into maxsize(nnnn) program */
3478 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3482 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3488 while (_cups_isspace(*ptr
))
3491 _cups_strcpy(program
, ptr
);
3495 * Check permissions on the filter and its containing directory...
3498 if (strcmp(program
, "-"))
3500 if (program
[0] == '/')
3501 strlcpy(filename
, program
, sizeof(filename
));
3503 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3505 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3506 cupsdLogFCMessage
, p
);
3510 * Add the filter to the MIME database, supporting wildcards as needed...
3513 for (temptype
= mimeFirstType(MimeDatabase
);
3515 temptype
= mimeNextType(MimeDatabase
))
3516 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3517 !_cups_strcasecmp(temptype
->super
, super
)) &&
3518 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3520 if (desttype
!= filtertype
)
3522 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3523 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3524 "%s", p
->name
, temptype
->super
, temptype
->type
,
3525 desttype
->super
, desttype
->type
,
3527 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3530 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3532 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3533 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3534 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3535 filtertype
->super
, filtertype
->type
);
3536 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3541 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3542 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3543 "%s", p
->name
, temptype
->super
, temptype
->type
,
3544 filtertype
->super
, filtertype
->type
,
3546 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3551 filterptr
->maxsize
= maxsize
;
3557 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3561 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3563 int i
; /* Looping var */
3564 mime_type_t
*type
; /* Current MIME type */
3565 cups_array_t
*filters
; /* Filters */
3566 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3567 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3568 /* MIME type name */
3572 * Raw (and remote) queues advertise all of the supported MIME
3576 cupsArrayDelete(p
->filetypes
);
3577 p
->filetypes
= NULL
;
3581 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3582 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3583 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3588 * Otherwise, loop through the supported MIME types and see if there
3589 * are filters for them...
3592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3593 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3595 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3597 for (type
= mimeFirstType(MimeDatabase
);
3599 type
= mimeNextType(MimeDatabase
))
3601 if (!_cups_strcasecmp(type
->super
, "printer"))
3604 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3606 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3608 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3609 "add_printer_formats: %s: %s needs %d filters",
3610 p
->name
, mimetype
, cupsArrayCount(filters
));
3612 cupsArrayDelete(filters
);
3613 cupsArrayAdd(p
->filetypes
, type
);
3616 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3617 "add_printer_formats: %s: %s not supported",
3622 * Add the file formats that can be filtered...
3625 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3626 !cupsArrayFind(p
->filetypes
, type
))
3631 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3632 "add_printer_formats: %s: %d supported types",
3633 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3635 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3636 "document-format-supported",
3637 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3640 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3642 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3644 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3646 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3648 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3651 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3653 char pdl
[1024]; /* Buffer to build pdl list */
3654 mime_filter_t
*filter
; /* MIME filter looping var */
3658 * We only support raw printing if this is not a Tioga PrintJobMgr based
3659 * queue and if application/octet-stream is a known type...
3662 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3664 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3666 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3672 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3673 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3676 * Then list a bunch of formats that are supported by the printer...
3679 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3681 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3683 if (!_cups_strcasecmp(type
->super
, "application"))
3685 if (!_cups_strcasecmp(type
->type
, "pdf"))
3686 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3687 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3688 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3690 else if (!_cups_strcasecmp(type
->super
, "image"))
3692 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3693 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3694 else if (!_cups_strcasecmp(type
->type
, "png"))
3695 strlcat(pdl
, "image/png,", sizeof(pdl
));
3696 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3697 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3702 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3704 cupsdSetString(&p
->pdl
, pdl
);
3706 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3711 * 'compare_printers()' - Compare two printers.
3714 static int /* O - Result of comparison */
3715 compare_printers(void *first
, /* I - First printer */
3716 void *second
, /* I - Second printer */
3717 void *data
) /* I - App data (not used) */
3721 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3722 ((cupsd_printer_t
*)second
)->name
));
3727 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3731 delete_printer_filters(
3732 cupsd_printer_t
*p
) /* I - Printer to remove from */
3734 mime_filter_t
*filter
; /* MIME filter looping var */
3735 mime_type_t
*type
; /* Destination types for filters */
3739 * Range check input...
3746 * Remove all filters from the MIME database that have a destination
3747 * type == printer...
3750 for (filter
= mimeFirstFilter(MimeDatabase
);
3752 filter
= mimeNextFilter(MimeDatabase
))
3753 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3754 cupsArrayFind(p
->dest_types
, filter
->dst
))
3757 * Delete the current filter...
3760 mimeDeleteFilter(MimeDatabase
, filter
);
3763 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3765 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3766 mimeDeleteType(MimeDatabase
, type
);
3768 cupsArrayDelete(p
->dest_types
);
3769 p
->dest_types
= NULL
;
3771 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3772 ",cups-missing-filter-warning");
3777 * 'dirty_printer()' - Mark config and state files dirty for the specified
3782 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3784 if (p
->type
& CUPS_PRINTER_CLASS
)
3785 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3787 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3789 if (PrintcapFormat
== PRINTCAP_PLIST
)
3790 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3795 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3799 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3801 int i
, j
; /* Looping vars */
3802 char cache_name
[1024]; /* Cache filename */
3803 struct stat cache_info
; /* Cache file info */
3804 ppd_file_t
*ppd
; /* PPD file */
3805 char ppd_name
[1024]; /* PPD filename */
3806 struct stat ppd_info
; /* PPD file info */
3807 int num_media
; /* Number of media options */
3808 ppd_size_t
*size
; /* Current PPD size */
3809 ppd_option_t
*duplex
, /* Duplex option */
3810 *output_bin
, /* OutputBin option */
3811 *output_mode
, /* OutputMode option */
3812 *resolution
; /* (Set|JCL|)Resolution option */
3813 ppd_choice_t
*choice
; /* Current PPD choice */
3814 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3815 int xdpi
, /* Horizontal resolution */
3816 ydpi
; /* Vertical resolution */
3817 const char *resptr
; /* Pointer into resolution keyword */
3818 pwg_size_t
*pwgsize
; /* Current PWG size */
3819 pwg_map_t
*pwgsource
, /* Current PWG source */
3820 *pwgtype
; /* Current PWG type */
3821 ipp_attribute_t
*attr
; /* Attribute data */
3822 _ipp_value_t
*val
; /* Attribute value */
3823 int num_finishings
, /* Number of finishings */
3824 finishings
[100]; /* finishings-supported values */
3825 int num_qualities
, /* Number of print-quality values */
3826 qualities
[3]; /* print-quality values */
3827 int num_margins
, /* Number of media-*-margin-supported values */
3828 margins
[16]; /* media-*-margin-supported values */
3829 const char *filter
, /* Current filter */
3830 *mandatory
; /* Current mandatory attribute */
3831 static const char * const pwg_raster_document_types
[] =
3837 static const char * const sides
[3] = /* sides-supported values */
3840 "two-sided-long-edge",
3841 "two-sided-short-edge"
3843 static const char * const standard_commands
[] =
3844 { /* Standard CUPS commands */
3852 * Check to see if the cache is up-to-date...
3855 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3856 if (stat(cache_name
, &cache_info
))
3857 cache_info
.st_mtime
= 0;
3859 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3860 if (stat(ppd_name
, &ppd_info
))
3861 ppd_info
.st_mtime
= 1;
3863 ippDelete(p
->ppd_attrs
);
3864 p
->ppd_attrs
= NULL
;
3866 _ppdCacheDestroy(p
->pc
);
3869 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3871 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3873 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3877 * Loaded successfully!
3885 * Reload PPD attributes from disk...
3888 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3890 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3892 cupsdClearString(&(p
->make_model
));
3894 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3895 p
->type
|= CUPS_PRINTER_BW
;
3897 finishings
[0] = IPP_FINISHINGS_NONE
;
3900 p
->ppd_attrs
= ippNew();
3902 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3905 * Add make/model and other various attributes...
3908 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3911 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3912 ppd_name
, cupsLastErrorString());
3914 ppdMarkDefaults(ppd
);
3916 if (ppd
->color_device
)
3917 p
->type
|= CUPS_PRINTER_COLOR
;
3918 if (ppd
->variable_sizes
)
3919 p
->type
|= CUPS_PRINTER_VARIABLE
;
3920 if (!ppd
->manual_copies
)
3921 p
->type
|= CUPS_PRINTER_COPIES
;
3922 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3923 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3924 p
->type
|= CUPS_PRINTER_FAX
;
3926 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3928 if (p
->pc
&& p
->pc
->charge_info_uri
)
3929 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3930 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3932 if (p
->pc
&& p
->pc
->account_id
)
3933 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3936 if (p
->pc
&& p
->pc
->accounting_user_id
)
3937 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3938 "job-accounting-user-id-supported", 1);
3940 if (p
->pc
&& p
->pc
->password
)
3942 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3943 "job-password-encryption-supported", NULL
, "none");
3944 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3945 "job-password-supported", (int)strlen(p
->pc
->password
));
3948 if (ppd
->throughput
)
3950 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3951 "pages-per-minute", ppd
->throughput
);
3952 if (ppd
->color_device
)
3953 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3954 "pages-per-minute-color", ppd
->throughput
);
3959 * When there is no speed information, just say "1 page per minute".
3962 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3963 "pages-per-minute", 1);
3964 if (ppd
->color_device
)
3965 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3966 "pages-per-minute-color", 1);
3969 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3970 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3974 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3976 if (ppdFindChoice(output_mode
, "draft") ||
3977 ppdFindChoice(output_mode
, "fast"))
3978 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3980 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3982 if (ppdFindChoice(output_mode
, "best") ||
3983 ppdFindChoice(output_mode
, "high"))
3984 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3986 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3990 if (strstr(ppd_attr
->spec
, "draft") ||
3991 strstr(ppd_attr
->spec
, "Draft"))
3993 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3997 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4000 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4001 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4004 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4006 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4007 "print-quality-supported", num_qualities
, qualities
);
4012 * The NickName can be localized in the character set specified
4013 * by the LanugageEncoding attribute. However, ppdOpen2() has
4014 * already converted the ppd->nickname member to UTF-8 for us
4015 * (the original attribute value is available separately)
4018 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4020 else if (ppd
->modelname
)
4023 * Model name can only contain specific characters...
4026 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4029 cupsdSetString(&p
->make_model
, "Bad PPD File");
4031 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4032 "printer-make-and-model", NULL
, p
->make_model
);
4035 * Add media options from the PPD file...
4038 if (ppd
->num_sizes
== 0 || !p
->pc
)
4040 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4041 cupsdLogMessage(CUPSD_LOG_CRIT
,
4042 "The PPD file for printer %s contains no media "
4043 "options and is therefore invalid.", p
->name
);
4045 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4046 "media-default", NULL
, "unknown");
4047 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4048 "media-supported", NULL
, "unknown");
4056 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4057 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4061 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4062 "media-default", NULL
,
4063 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4071 ipp_t
*col
; /* Collection value */
4073 col
= new_media_col(pwgsize
);
4074 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default", col
);
4082 num_media
= p
->pc
->num_sizes
;
4083 if (p
->pc
->custom_min_keyword
)
4086 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4087 "media-supported", num_media
, NULL
,
4092 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4094 i
--, pwgsize
++, val
++)
4095 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4097 if (p
->pc
->custom_min_keyword
)
4099 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4101 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4106 * media-size-supported
4109 num_media
= p
->pc
->num_sizes
;
4110 if (p
->pc
->custom_min_keyword
)
4113 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4114 "media-size-supported", num_media
,
4119 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4121 i
--, pwgsize
++, val
++)
4123 val
->collection
= ippNew();
4124 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4125 "x-dimension", pwgsize
->width
);
4126 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4127 "y-dimension", pwgsize
->length
);
4130 if (p
->pc
->custom_min_keyword
)
4132 val
->collection
= ippNew();
4133 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4134 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4135 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4136 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4141 * media-source-supported
4144 if (p
->pc
->num_sources
> 0 &&
4145 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4146 "media-source-supported", p
->pc
->num_sources
,
4147 NULL
, NULL
)) != NULL
)
4149 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4152 i
--, pwgsource
++, val
++)
4153 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4157 * media-type-supported
4160 if (p
->pc
->num_types
> 0 &&
4161 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4162 "media-type-supported", p
->pc
->num_types
,
4163 NULL
, NULL
)) != NULL
)
4165 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4168 i
--, pwgtype
++, val
++)
4169 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4173 * media-*-margin-supported
4176 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4177 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4180 for (j
= 0; j
< num_margins
; j
++)
4181 if (pwgsize
->bottom
== margins
[j
])
4184 if (j
>= num_margins
)
4186 margins
[num_margins
] = pwgsize
->bottom
;
4191 if (num_margins
> 0)
4192 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4193 "media-bottom-margin-supported", num_margins
, margins
);
4195 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4196 "media-bottom-margin-supported", 0);
4198 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4199 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4202 for (j
= 0; j
< num_margins
; j
++)
4203 if (pwgsize
->left
== margins
[j
])
4206 if (j
>= num_margins
)
4208 margins
[num_margins
] = pwgsize
->left
;
4213 if (num_margins
> 0)
4214 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4215 "media-left-margin-supported", num_margins
, margins
);
4217 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4218 "media-left-margin-supported", 0);
4220 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4221 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4224 for (j
= 0; j
< num_margins
; j
++)
4225 if (pwgsize
->right
== margins
[j
])
4228 if (j
>= num_margins
)
4230 margins
[num_margins
] = pwgsize
->right
;
4235 if (num_margins
> 0)
4236 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4237 "media-right-margin-supported", num_margins
, margins
);
4239 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4240 "media-right-margin-supported", 0);
4242 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4243 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4246 for (j
= 0; j
< num_margins
; j
++)
4247 if (pwgsize
->top
== margins
[j
])
4250 if (j
>= num_margins
)
4252 margins
[num_margins
] = pwgsize
->top
;
4257 if (num_margins
> 0)
4258 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4259 "media-top-margin-supported", num_margins
, margins
);
4261 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4262 "media-top-margin-supported", 0);
4265 * media-col-database
4268 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-database", p
->pc
->num_sizes
, NULL
)) != NULL
)
4271 * Adding each page size without source or type...
4274 for (i
= 0, pwgsize
= p
->pc
->sizes
; i
< p
->pc
->num_sizes
; i
++, pwgsize
++)
4276 ipp_t
*col
= new_media_col(pwgsize
);
4278 ippSetCollection(p
->ppd_attrs
, &attr
, i
, col
);
4288 if (p
->pc
&& p
->pc
->num_bins
> 0)
4290 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4291 "output-bin-supported", p
->pc
->num_bins
,
4296 for (i
= 0, val
= attr
->values
;
4297 i
< p
->pc
->num_bins
;
4299 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4302 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4304 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4305 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4308 if (i
>= p
->pc
->num_bins
)
4311 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4312 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4315 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4316 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4318 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4320 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4321 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4322 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4323 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4326 * Report that this printer has a single output bin that leaves pages face
4330 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4331 "output-bin-supported", NULL
, "face-up");
4332 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4333 "output-bin-default", NULL
, "face-up");
4337 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4338 "output-bin-supported", NULL
, "face-down");
4339 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4340 "output-bin-default", NULL
, "face-down");
4344 * print-color-mode...
4347 if (ppd
->color_device
)
4349 static const char * const color_modes
[] =
4355 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4356 "print-color-mode-supported", 2, NULL
, color_modes
);
4357 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4358 "print-color-mode-default", NULL
, "color");
4359 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4363 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4364 "print-color-mode-supported", NULL
, "monochrome");
4365 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4366 "print-color-mode-default", NULL
, "monochrome");
4367 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4371 * Mandatory job attributes, if any...
4374 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4376 int count
= cupsArrayCount(p
->pc
->mandatory
);
4377 /* Number of mandatory attributes */
4379 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4380 "printer-mandatory-job-attributes", count
, NULL
,
4383 for (val
= attr
->values
,
4384 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4386 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4387 val
->string
.text
= _cupsStrAlloc(mandatory
);
4391 * Printer resolutions...
4394 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4395 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4396 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4397 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4402 * Report all supported resolutions...
4405 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4407 for (i
= 0, choice
= resolution
->choices
;
4408 i
< resolution
->num_choices
;
4411 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4412 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4413 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4415 if (xdpi
<= 0 || ydpi
<= 0)
4417 cupsdLogMessage(CUPSD_LOG_WARN
,
4418 "Bad resolution \"%s\" for printer %s.",
4419 choice
->choice
, p
->name
);
4423 attr
->values
[i
].resolution
.xres
= xdpi
;
4424 attr
->values
[i
].resolution
.yres
= ydpi
;
4425 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4428 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4431 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4434 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4438 * Just the DefaultResolution to report...
4441 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4442 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4445 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4450 if (xdpi
<= 0 || ydpi
<= 0)
4452 cupsdLogMessage(CUPSD_LOG_WARN
,
4453 "Bad default resolution \"%s\" for printer %s.",
4454 ppd_attr
->value
, p
->name
);
4458 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4459 "printer-resolution-default", IPP_RES_PER_INCH
,
4461 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4462 "printer-resolution-supported", IPP_RES_PER_INCH
,
4464 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4469 * No resolutions in PPD - make one up...
4472 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4473 "printer-resolution-default", IPP_RES_PER_INCH
,
4475 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4476 "printer-resolution-supported", IPP_RES_PER_INCH
,
4478 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4485 ppdMarkDefaults(ppd
);
4487 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4488 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4489 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4490 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4491 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4493 if (duplex
&& duplex
->num_choices
> 1 &&
4494 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4496 p
->type
|= CUPS_PRINTER_DUPLEX
;
4498 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4500 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4501 "sides-supported", 3, NULL
, sides
);
4503 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4504 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4505 "sides-default", NULL
, "two-sided-short-edge");
4506 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4507 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4508 "sides-default", NULL
, "two-sided-long-edge");
4510 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4511 "sides-default", NULL
, "one-sided");
4515 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4516 "sides-supported", NULL
, "one-sided");
4517 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4518 "sides-default", NULL
, "one-sided");
4521 if (ppdFindOption(ppd
, "Collate") != NULL
)
4522 p
->type
|= CUPS_PRINTER_COLLATE
;
4524 if (p
->pc
&& p
->pc
->finishings
)
4526 _pwg_finishings_t
*fin
; /* Current finishing value */
4528 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4530 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4531 finishings
[num_finishings
++] = fin
->value
;
4535 case IPP_FINISHINGS_BIND
:
4536 case IPP_FINISHINGS_BIND_LEFT
:
4537 case IPP_FINISHINGS_BIND_TOP
:
4538 case IPP_FINISHINGS_BIND_RIGHT
:
4539 case IPP_FINISHINGS_BIND_BOTTOM
:
4540 case IPP_FINISHINGS_EDGE_STITCH
:
4541 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4542 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4543 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4544 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4545 p
->type
|= CUPS_PRINTER_BIND
;
4548 case IPP_FINISHINGS_COVER
:
4549 p
->type
|= CUPS_PRINTER_COVER
;
4552 case IPP_FINISHINGS_PUNCH
:
4553 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4554 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4555 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4556 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4557 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4558 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4559 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4560 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4561 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4562 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4563 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4564 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4565 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4566 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4567 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4568 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4569 p
->type
|= CUPS_PRINTER_PUNCH
;
4572 case IPP_FINISHINGS_STAPLE
:
4573 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4574 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4575 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4576 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4577 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4578 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4579 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4580 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4581 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4582 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4583 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4584 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4585 p
->type
|= CUPS_PRINTER_STAPLE
;
4594 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4595 if (ppd
->sizes
[i
].length
> 1728)
4596 p
->type
|= CUPS_PRINTER_LARGE
;
4597 else if (ppd
->sizes
[i
].length
> 1008)
4598 p
->type
|= CUPS_PRINTER_MEDIUM
;
4600 p
->type
|= CUPS_PRINTER_SMALL
;
4602 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4603 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4605 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4606 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4607 p
->type
|= CUPS_PRINTER_SCANNER
;
4609 p
->type
|= CUPS_PRINTER_MFP
;
4613 * Scan the filters in the PPD file...
4618 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4620 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4622 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4623 _cups_isspace(filter
[28]))
4625 p
->type
|= CUPS_PRINTER_COMMANDS
;
4631 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4633 char *commands
, /* Copy of commands */
4634 *start
, /* Start of name */
4635 *end
; /* End of name */
4636 int count
; /* Number of commands */
4638 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4640 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4642 while (_cups_isspace(*start
))
4648 while (*start
&& !isspace(*start
& 255))
4658 * Make a copy of the commands string and count how many commands there
4662 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4663 "printer-commands", count
, NULL
, NULL
);
4665 commands
= strdup(ppd_attr
->value
);
4667 for (count
= 0, start
= commands
; *start
; count
++)
4669 while (isspace(*start
& 255))
4676 while (*end
&& !isspace(*end
& 255))
4682 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4692 * Add the standard list of commands...
4695 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4697 (int)(sizeof(standard_commands
) /
4698 sizeof(standard_commands
[0])), NULL
,
4705 * No commands supported...
4708 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4709 "printer-commands", NULL
, "none");
4713 * Show current and available port monitors for this printer...
4716 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4717 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4719 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4721 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4725 if (strstr(ppd
->protocols
, "TBCP"))
4727 else if (strstr(ppd
->protocols
, "BCP"))
4731 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4732 "port-monitor-supported", i
, NULL
, NULL
);
4734 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4736 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4738 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4739 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4743 if (strstr(ppd
->protocols
, "TBCP"))
4744 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4745 else if (strstr(ppd
->protocols
, "BCP"))
4746 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4749 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4750 p
->type
|= CUPS_PRINTER_REMOTE
;
4752 #ifdef HAVE_APPLICATIONSERVICES_H
4754 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4755 * and save it as cacheDir/printername.png
4758 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4760 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4761 cupsdLogFCMessage
, p
))
4763 CGImageRef imageRef
= NULL
;/* Current icon image */
4764 CGImageRef biggestIconRef
= NULL
;
4765 /* Biggest icon image */
4766 CGImageRef closestTo128IconRef
= NULL
;
4767 /* Icon image closest to and >= 128 */
4768 CGImageSourceRef sourceRef
; /* The file's image source */
4769 char outPath
[HTTP_MAX_URI
];
4770 /* The path to the PNG file */
4771 CFURLRef outUrl
; /* The URL made from the outPath */
4772 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4773 CGImageDestinationRef destRef
; /* The image destination to write */
4774 size_t bytesPerRow
; /* The bytes per row used for resizing */
4775 CGContextRef context
; /* The CG context used for resizing */
4777 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4778 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4779 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4780 if (outUrl
&& icnsFileUrl
)
4782 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4785 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4787 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4791 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4794 * Loop through remembering the icon closest to 128 but >= 128
4795 * and then remember the largest icon.
4798 if (CGImageGetWidth(imageRef
) >= 128 &&
4799 (!closestTo128IconRef
||
4800 CGImageGetWidth(imageRef
) <
4801 CGImageGetWidth(closestTo128IconRef
)))
4803 CGImageRelease(closestTo128IconRef
);
4804 CGImageRetain(imageRef
);
4805 closestTo128IconRef
= imageRef
;
4808 if (!biggestIconRef
||
4809 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4811 CGImageRelease(biggestIconRef
);
4812 CGImageRetain(imageRef
);
4813 biggestIconRef
= imageRef
;
4817 CGImageRelease(imageRef
);
4823 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4824 * want the closest to 128, but if none are larger than 128, we want
4825 * the largest icon available.
4828 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4830 CGImageRetain(imageRef
);
4831 CGImageRelease(biggestIconRef
);
4832 if (closestTo128IconRef
)
4833 CGImageRelease(closestTo128IconRef
);
4834 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4838 if (CGImageGetWidth(imageRef
) != 128)
4840 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4841 CGImageGetWidth(imageRef
) * 128;
4842 context
= CGBitmapContextCreate(NULL
, 128, 128,
4843 CGImageGetBitsPerComponent(imageRef
),
4845 CGImageGetColorSpace(imageRef
),
4846 kCGImageAlphaPremultipliedFirst
);
4849 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4851 CGImageRelease(imageRef
);
4852 imageRef
= CGBitmapContextCreateImage(context
);
4853 CGContextRelease(context
);
4857 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4858 CGImageDestinationFinalize(destRef
);
4862 CGImageRelease(imageRef
);
4865 CFRelease(sourceRef
);
4873 CFRelease(icnsFileUrl
);
4875 #endif /* HAVE_APPLICATIONSERVICES_H */
4878 * Close the PPD and set the type...
4883 else if (!access(ppd_name
, 0))
4885 int pline
; /* PPD line number */
4886 ppd_status_t pstatus
; /* PPD load status */
4889 pstatus
= ppdLastError(&pline
);
4891 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4893 if (pstatus
<= PPD_ALLOC_ERROR
)
4894 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4896 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4898 cupsdLogMessage(CUPSD_LOG_INFO
,
4899 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4904 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4905 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4906 (strstr(p
->device_uri
, "/printers/") != NULL
||
4907 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4908 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4909 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4910 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4913 * Tell the client this is really a hard-wired remote printer.
4916 p
->type
|= CUPS_PRINTER_REMOTE
;
4919 * Then set the make-and-model accordingly...
4922 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4923 "printer-make-and-model", NULL
, "Remote Printer");
4926 * Print all files directly...
4935 * Otherwise we have neither - treat this as a "dumb" printer
4936 * with no PPD file...
4939 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4940 "printer-make-and-model", NULL
, "Local Raw Printer");
4946 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4947 "finishings-supported", num_finishings
, finishings
);
4948 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4949 "finishings-default", IPP_FINISHINGS_NONE
);
4954 * Save cached PPD attributes to disk...
4957 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4959 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4964 * Remove cache files...
4967 if (cache_info
.st_mtime
)
4974 * 'new_media_col()' - Create a media-col collection value.
4977 static ipp_t
* /* O - Collection value */
4978 new_media_col(pwg_size_t
*size
) /* I - media-size/margin values */
4980 ipp_t
*media_col
, /* Collection value */
4981 *media_size
; /* media-size value */
4984 media_col
= ippNew();
4986 media_size
= ippNew();
4987 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "x-dimension", size
->width
);
4988 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "y-dimension", size
->length
);
4989 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4990 ippDelete(media_size
);
4992 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "media-bottom-margin", size
->bottom
);
4993 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "media-left-margin", size
->left
);
4994 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "media-right-margin", size
->right
);
4995 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "media-top-margin", size
->top
);
5002 * 'write_xml_string()' - Write a string with XML escaping.
5006 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5007 const char *s
) /* I - String to write */
5009 const char *start
; /* Start of current sequence */
5015 for (start
= s
; *s
; s
++)
5020 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5022 cupsFilePuts(fp
, "&");
5028 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5030 cupsFilePuts(fp
, "<");
5036 cupsFilePuts(fp
, start
);