2 * Printer routines for the CUPS scheduler.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
16 #ifdef HAVE_APPLICATIONSERVICES_H
17 # include <ApplicationServices/ApplicationServices.h>
18 #endif /* HAVE_APPLICATIONSERVICES_H */
19 #ifdef HAVE_SYS_MOUNT_H
20 # include <sys/mount.h>
21 #endif /* HAVE_SYS_MOUNT_H */
22 #ifdef HAVE_SYS_STATVFS_H
23 # include <sys/statvfs.h>
24 #elif defined(HAVE_SYS_STATFS_H)
25 # include <sys/statfs.h>
26 #endif /* HAVE_SYS_STATVFS_H */
29 #endif /* HAVE_SYS_VFS_H */
32 #endif /* __APPLE__ */
39 static void add_printer_defaults(cupsd_printer_t
*p
);
40 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
42 static void add_printer_formats(cupsd_printer_t
*p
);
43 static int compare_printers(void *first
, void *second
, void *data
);
44 static void delete_printer_filters(cupsd_printer_t
*p
);
45 static void dirty_printer(cupsd_printer_t
*p
);
46 static void load_ppd(cupsd_printer_t
*p
);
47 static ipp_t
*new_media_col(pwg_size_t
*size
, const char *source
,
49 static void write_xml_string(cups_file_t
*fp
, const char *s
);
53 * 'cupsdAddPrinter()' - Add a printer to the system.
56 cupsd_printer_t
* /* O - New printer */
57 cupsdAddPrinter(const char *name
) /* I - Name of printer */
59 cupsd_printer_t
*p
; /* New printer */
60 char uri
[1024], /* Printer URI */
61 uuid
[64]; /* Printer UUID */
65 * Range check input...
68 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
71 * Create a new printer entity...
74 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
76 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
81 _cupsRWInit(&p
->lock
);
83 cupsdSetString(&p
->name
, name
);
84 cupsdSetString(&p
->info
, name
);
85 cupsdSetString(&p
->hostname
, ServerName
);
87 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
88 ServerName
, RemotePort
, "/printers/%s", name
);
89 cupsdSetString(&p
->uri
, uri
);
90 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
92 cupsdSetDeviceURI(p
, "file:///dev/null");
94 p
->config_time
= time(NULL
);
95 p
->state
= IPP_PRINTER_STOPPED
;
96 p
->state_time
= time(NULL
);
98 p
->shared
= DefaultShared
;
99 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
101 cupsdSetString(&p
->job_sheets
[0], "none");
102 cupsdSetString(&p
->job_sheets
[1], "none");
104 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
105 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
107 p
->op_policy_ptr
= DefaultPolicyPtr
;
110 * Insert the printer in the printer list alphabetically...
114 Printers
= cupsArrayNew(compare_printers
, NULL
);
116 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
117 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
118 cupsArrayAdd(Printers
, p
);
121 * Return the new printer...
129 * 'cupsdCreateCommonData()' - Create the common printer data.
133 cupsdCreateCommonData(void)
135 int i
; /* Looping var */
136 ipp_attribute_t
*attr
; /* Attribute data */
137 cups_dir_t
*dir
; /* Notifier directory */
138 cups_dentry_t
*dent
; /* Notifier directory entry */
139 cups_array_t
*notifiers
; /* Notifier array */
140 char filename
[1024], /* Filename */
141 *notifier
; /* Current notifier */
142 cupsd_policy_t
*p
; /* Current policy */
143 int k_supported
; /* Maximum file size supported */
145 struct statvfs spoolinfo
; /* FS info for spool directory */
146 double spoolsize
; /* FS size */
147 #elif defined(HAVE_STATFS)
148 struct statfs spoolinfo
; /* FS info for spool directory */
149 double spoolsize
; /* FS size */
150 #endif /* HAVE_STATVFS */
151 static const int nups
[] = /* number-up-supported values */
152 { 1, 2, 4, 6, 9, 16 };
153 static const int orients
[4] =/* orientation-requested-supported values */
157 IPP_REVERSE_LANDSCAPE
,
160 static const char * const holds
[] = /* job-hold-until-supported values */
171 static const char * const features
[] =/* ipp-features-supported values */
173 "subscription-object"
175 static const char * const versions
[] =/* ipp-versions-supported values */
182 static const int ops
[] = /* operations-supported values */
187 IPP_OP_SEND_DOCUMENT
,
189 IPP_OP_GET_JOB_ATTRIBUTES
,
191 IPP_OP_GET_PRINTER_ATTRIBUTES
,
194 IPP_OP_PAUSE_PRINTER
,
195 IPP_OP_RESUME_PRINTER
,
197 IPP_OP_SET_PRINTER_ATTRIBUTES
,
198 IPP_OP_SET_JOB_ATTRIBUTES
,
199 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
200 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
201 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
202 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
203 IPP_OP_GET_SUBSCRIPTIONS
,
204 IPP_OP_RENEW_SUBSCRIPTION
,
205 IPP_OP_CANCEL_SUBSCRIPTION
,
206 IPP_OP_GET_NOTIFICATIONS
,
207 IPP_OP_ENABLE_PRINTER
,
208 IPP_OP_DISABLE_PRINTER
,
209 IPP_OP_HOLD_NEW_JOBS
,
210 IPP_OP_RELEASE_HELD_NEW_JOBS
,
212 IPP_OP_CANCEL_MY_JOBS
,
214 IPP_OP_CUPS_GET_DEFAULT
,
215 IPP_OP_CUPS_GET_PRINTERS
,
216 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
217 IPP_OP_CUPS_DELETE_PRINTER
,
218 IPP_OP_CUPS_GET_CLASSES
,
219 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
220 IPP_OP_CUPS_DELETE_CLASS
,
221 IPP_OP_CUPS_ACCEPT_JOBS
,
222 IPP_OP_CUPS_REJECT_JOBS
,
223 IPP_OP_CUPS_SET_DEFAULT
,
224 IPP_OP_CUPS_GET_DEVICES
,
225 IPP_OP_CUPS_GET_PPDS
,
226 IPP_OP_CUPS_MOVE_JOB
,
227 IPP_OP_CUPS_AUTHENTICATE_JOB
,
229 IPP_OP_CUPS_GET_DOCUMENT
,
232 static const char * const charsets
[] =/* charset-supported values */
237 static const char * const compressions
[] =
238 { /* document-compression-supported values */
242 #endif /* HAVE_LIBZ */
244 static const char * const media_col_supported
[] =
245 { /* media-col-supported values */
246 "media-bottom-margin",
248 "media-right-margin",
254 static const char * const multiple_document_handling
[] =
255 { /* multiple-document-handling-supported values */
256 "separate-documents-uncollated-copies",
257 "separate-documents-collated-copies"
259 static const char * const notify_attrs
[] =
260 { /* notify-attributes-supported values */
261 "printer-state-change-time",
262 "notify-lease-expiration-time",
263 "notify-subscriber-user-name"
265 static const char * const notify_events
[] =
266 { /* notify-events-supported values */
268 "job-config-changed",
275 "printer-config-changed",
277 "printer-finishings-changed",
278 "printer-media-changed",
282 "printer-state-changed",
289 static const char * const job_creation
[] =
290 { /* job-creation-attributes-supported */
293 "ipp-attribute-fidelity",
300 "multiple-document-handling",
303 "orientation-requested",
307 "printer-resolution",
310 static const char * const job_settable
[] =
311 { /* job-settable-attributes-supported */
319 "multiple-document-handling",
322 "orientation-requested",
326 "printer-resolution",
329 static const char * const pdf_versions
[] =
330 { /* pdf-versions-supported */
341 static const char * const printer_settable
[] =
342 { /* printer-settable-attributes-supported */
343 "printer-geo-location",
346 "printer-organization",
347 "printer-organizational-unit"
349 static const char * const which_jobs
[] =
350 { /* which-jobs-supported values */
364 ippDelete(CommonData
);
366 CommonData
= ippNew();
369 * Get the maximum spool size based on the size of the filesystem used for
370 * the RequestRoot directory. If the host OS doesn't support the statfs call
371 * or the filesystem is larger than 2TiB, always report INT_MAX.
375 if (statvfs(RequestRoot
, &spoolinfo
))
376 k_supported
= INT_MAX
;
377 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
379 k_supported
= INT_MAX
;
381 k_supported
= (int)spoolsize
;
383 #elif defined(HAVE_STATFS)
384 if (statfs(RequestRoot
, &spoolinfo
))
385 k_supported
= INT_MAX
;
386 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
388 k_supported
= INT_MAX
;
390 k_supported
= (int)spoolsize
;
393 k_supported
= INT_MAX
;
394 #endif /* HAVE_STATVFS */
397 * This list of attributes is sorted to improve performance when the
398 * client provides a requested-attributes attribute...
401 /* charset-configured */
402 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
403 "charset-configured", NULL
, "utf-8");
405 /* charset-supported */
406 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
407 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
410 /* compression-supported */
411 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
412 "compression-supported",
413 sizeof(compressions
) / sizeof(compressions
[0]),
416 /* copies-supported */
417 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
420 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
421 "cups-version", NULL
, CUPS_SVERSION
+ 6);
423 /* generated-natural-language-supported (no IPP_TAG_COPY) */
424 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
425 "generated-natural-language-supported", NULL
, DefaultLanguage
);
427 /* ipp-features-supported */
428 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
430 /* ipp-versions-supported */
431 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
432 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
435 /* ippget-event-life */
436 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
437 "ippget-event-life", 15);
439 /* job-cancel-after-supported */
440 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
443 /* job-creation-attributes-supported */
444 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
445 "job-creation-attributes-supported",
446 sizeof(job_creation
) / sizeof(job_creation
[0]),
449 /* job-hold-until-supported */
450 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
451 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
454 /* job-ids-supported */
455 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
457 /* job-k-octets-supported */
458 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
461 /* job-priority-supported */
462 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
463 "job-priority-supported", 100);
465 /* job-settable-attributes-supported */
466 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
467 "job-settable-attributes-supported",
468 sizeof(job_settable
) / sizeof(job_settable
[0]),
471 /* job-sheets-supported */
472 if (cupsArrayCount(Banners
) > 0)
475 * Setup the job-sheets-supported attribute...
478 if (Classification
&& !ClassifyOverride
)
479 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
480 IPP_TAG_NAME
| IPP_TAG_COPY
,
481 "job-sheets-supported", NULL
, Classification
);
483 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
484 IPP_TAG_NAME
| IPP_TAG_COPY
,
485 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
489 cupsdLogMessage(CUPSD_LOG_EMERG
,
490 "Unable to allocate memory for "
491 "job-sheets-supported attribute: %s!", strerror(errno
));
492 else if (!Classification
|| ClassifyOverride
)
494 cupsd_banner_t
*banner
; /* Current banner */
497 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
499 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
501 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
502 attr
->values
[i
].string
.text
= banner
->name
;
506 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
507 "job-sheets-supported", NULL
, "none");
509 /* jpeg-k-octets-supported */
510 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
513 /* jpeg-x-dimension-supported */
514 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
517 /* jpeg-y-dimension-supported */
518 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
521 /* media-col-supported */
522 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
523 "media-col-supported",
524 sizeof(media_col_supported
) /
525 sizeof(media_col_supported
[0]), NULL
,
526 media_col_supported
);
528 /* multiple-document-handling-supported */
529 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
530 "multiple-document-handling-supported",
531 sizeof(multiple_document_handling
) /
532 sizeof(multiple_document_handling
[0]), NULL
,
533 multiple_document_handling
);
535 /* multiple-document-jobs-supported */
536 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
537 "multiple-document-jobs-supported", 1);
539 /* multiple-operation-time-out */
540 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
541 "multiple-operation-time-out", MultipleOperationTimeout
);
543 /* multiple-operation-time-out-action */
544 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
546 /* natural-language-configured (no IPP_TAG_COPY) */
547 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
548 "natural-language-configured", NULL
, DefaultLanguage
);
550 /* notify-attributes-supported */
551 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
552 "notify-attributes-supported",
553 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
556 /* notify-lease-duration-supported */
557 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
558 "notify-lease-duration-supported", 0,
559 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
561 /* notify-max-events-supported */
562 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
563 "notify-max-events-supported", MaxEvents
);
565 /* notify-events-supported */
566 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
567 "notify-events-supported",
568 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
569 NULL
, notify_events
);
571 /* notify-pull-method-supported */
572 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
573 "notify-pull-method-supported", NULL
, "ippget");
575 /* notify-schemes-supported */
576 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
577 if ((dir
= cupsDirOpen(filename
)) != NULL
)
579 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
581 while ((dent
= cupsDirRead(dir
)) != NULL
)
582 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
583 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
584 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
586 if (cupsArrayCount(notifiers
) > 0)
588 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
589 "notify-schemes-supported",
590 cupsArrayCount(notifiers
), NULL
, NULL
);
592 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
594 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
595 attr
->values
[i
].string
.text
= notifier
;
598 cupsArrayDelete(notifiers
);
602 /* number-up-supported */
603 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
604 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
606 /* operations-supported */
607 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
608 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
610 /* orientation-requested-supported */
611 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
612 "orientation-requested-supported", 4, orients
);
614 /* page-ranges-supported */
615 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
617 /* pdf-k-octets-supported */
618 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
621 /* pdf-versions-supported */
622 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
623 "pdf-versions-supported",
624 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
627 /* pdl-override-supported */
628 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
629 "pdl-override-supported", NULL
, "attempted");
631 /* printer-get-attributes-supported */
632 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
634 /* printer-op-policy-supported */
635 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
636 "printer-op-policy-supported", cupsArrayCount(Policies
),
638 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
640 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
641 attr
->values
[i
].string
.text
= p
->name
;
643 /* printer-settable-attributes-supported */
644 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
645 "printer-settable-attributes-supported",
646 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
647 NULL
, printer_settable
);
649 /* server-is-sharing-printers */
650 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
651 BrowseLocalProtocols
!= 0 && Browsing
);
653 /* which-jobs-supported */
654 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
655 "which-jobs-supported",
656 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
661 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
665 cupsdDeleteAllPrinters(void)
667 cupsd_printer_t
*p
; /* Pointer to current printer/class */
670 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
672 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
674 p
->op_policy_ptr
= DefaultPolicyPtr
;
675 cupsdDeletePrinter(p
, 0);
681 * 'cupsdDeletePrinter()' - Delete a printer from the system.
684 int /* O - 1 if classes affected, 0 otherwise */
686 cupsd_printer_t
*p
, /* I - Printer to delete */
687 int update
) /* I - Update printers.conf? */
689 int i
, /* Looping var */
690 changed
= 0; /* Class changed? */
693 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
697 * Save the current position in the Printers array...
700 cupsArraySave(Printers
);
703 * Stop printing on this printer...
706 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
708 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
711 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
712 update
? "Job stopped due to printer being deleted." :
716 * Remove the printer from the list...
719 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
720 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
721 cupsArrayRemove(Printers
, p
);
724 * If p is the default printer, assign a different one...
727 if (p
== DefaultPrinter
)
728 DefaultPrinter
= NULL
;
731 * Remove this printer from any classes...
734 changed
= cupsdDeletePrinterFromClasses(p
);
737 * Deregister from any browse protocols...
740 cupsdDeregisterPrinter(p
, 1);
743 * Remove support files if this is a temporary queue and deregister color
749 char filename
[1024]; /* Script/PPD filename */
752 * Remove any old PPD or script files...
755 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
757 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
760 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
763 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
767 * Unregister color profiles...
770 cupsdUnregisterColor(p
);
774 * Free all memory used by the printer...
777 if (p
->printers
!= NULL
)
780 delete_printer_filters(p
);
782 for (i
= 0; i
< p
->num_reasons
; i
++)
783 _cupsStrFree(p
->reasons
[i
]);
786 ippDelete(p
->ppd_attrs
);
788 mimeDeleteType(MimeDatabase
, p
->filetype
);
789 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
791 cupsdFreeStrings(&(p
->users
));
794 cupsdClearString(&p
->uri
);
795 cupsdClearString(&p
->hostname
);
796 cupsdClearString(&p
->name
);
797 cupsdClearString(&p
->location
);
798 cupsdClearString(&p
->geo_location
);
799 cupsdClearString(&p
->make_model
);
800 cupsdClearString(&p
->info
);
801 cupsdClearString(&p
->job_sheets
[0]);
802 cupsdClearString(&p
->job_sheets
[1]);
803 cupsdClearString(&p
->device_uri
);
804 cupsdClearString(&p
->sanitized_device_uri
);
805 cupsdClearString(&p
->port_monitor
);
806 cupsdClearString(&p
->op_policy
);
807 cupsdClearString(&p
->error_policy
);
808 cupsdClearString(&p
->strings
);
810 cupsdClearString(&p
->alert
);
811 cupsdClearString(&p
->alert_description
);
813 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
814 cupsdClearString(&p
->pdl
);
815 cupsdClearString(&p
->reg_name
);
816 #endif /* HAVE_DNSSD || HAVE_AVAHI */
818 cupsArrayDelete(p
->filetypes
);
820 cupsFreeOptions(p
->num_options
, p
->options
);
825 * Restore the previous position in the Printers array...
828 cupsArrayRestore(Printers
);
835 * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
839 cupsdDeleteTemporaryPrinters(int force
) /* I - Force deletion instead of auto? */
841 cupsd_printer_t
*p
; /* Current printer */
842 time_t unused_time
; /* Last time for printer state change */
846 * Allow temporary printers to stick around for 60 seconds after the last job
850 unused_time
= time(NULL
) - 60;
852 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
); p
; p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
854 if (p
->temporary
&& (force
|| p
->state_time
< unused_time
))
855 cupsdDeletePrinter(p
, 0);
861 * 'cupsdFindDest()' - Find a destination in the list.
864 cupsd_printer_t
* /* O - Destination in list */
865 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
867 cupsd_printer_t key
; /* Search key */
870 key
.name
= (char *)name
;
871 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
876 * 'cupsdFindPrinter()' - Find a printer in the list.
879 cupsd_printer_t
* /* O - Printer in list */
880 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
882 cupsd_printer_t
*p
; /* Printer in list */
885 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
893 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
897 cupsdLoadAllPrinters(void)
899 int i
; /* Looping var */
900 cups_file_t
*fp
; /* printers.conf file */
901 int linenum
; /* Current line number */
902 char line
[4096], /* Line from file */
903 *value
, /* Pointer to value */
904 *valueptr
; /* Pointer into value */
905 cupsd_printer_t
*p
; /* Current printer */
909 * Open the printers.conf file...
912 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
913 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
917 * Read printer configurations until we hit EOF...
923 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
926 * Decode the directive...
929 if (!_cups_strcasecmp(line
, "NextPrinterId"))
931 if (value
&& (i
= atoi(value
)) > 0)
934 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
936 else if (!_cups_strcasecmp(line
, "<Printer") || !_cups_strcasecmp(line
, "<DefaultPrinter"))
939 * <Printer name> or <DefaultPrinter name>
942 if (p
== NULL
&& value
)
945 * Add the printer and a base file type...
948 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
950 p
= cupsdAddPrinter(value
);
952 p
->state
= IPP_PRINTER_IDLE
;
955 * Set the default printer as needed...
958 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
962 cupsdLogMessage(CUPSD_LOG_ERROR
,
963 "Syntax error on line %d of printers.conf.", linenum
);
965 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
970 * Close out the current printer...
975 p
->printer_id
= NextPrinterId
++;
976 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
979 cupsdSetPrinterAttrs(p
);
981 if (strncmp(p
->device_uri
, "file:", 5) && p
->state
!= IPP_PRINTER_STOPPED
)
984 * See if the backend exists...
987 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
, p
->device_uri
);
989 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
990 *valueptr
= '\0'; /* Chop everything but URI scheme */
995 * Backend does not exist, stop printer...
998 p
->state
= IPP_PRINTER_STOPPED
;
999 snprintf(p
->state_message
, sizeof(p
->state_message
), "Backend %s does not exist!", line
);
1006 cupsdLogMessage(CUPSD_LOG_ERROR
,
1007 "Syntax error on line %d of printers.conf.", linenum
);
1011 cupsdLogMessage(CUPSD_LOG_ERROR
,
1012 "Syntax error on line %d of printers.conf.", linenum
);
1014 else if (!_cups_strcasecmp(line
, "PrinterId"))
1016 if (value
&& (i
= atoi(value
)) > 0)
1019 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad PrinterId on line %d of printers.conf.", linenum
);
1021 else if (!_cups_strcasecmp(line
, "UUID"))
1023 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1024 cupsdSetString(&(p
->uuid
), value
);
1026 cupsdLogMessage(CUPSD_LOG_ERROR
,
1027 "Bad UUID on line %d of printers.conf.", linenum
);
1029 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1031 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1032 cupsdLogMessage(CUPSD_LOG_ERROR
,
1033 "Bad AuthInfoRequired on line %d of printers.conf.",
1036 else if (!_cups_strcasecmp(line
, "Info"))
1039 cupsdSetString(&p
->info
, value
);
1041 else if (!_cups_strcasecmp(line
, "MakeModel"))
1044 cupsdSetString(&p
->make_model
, value
);
1046 else if (!_cups_strcasecmp(line
, "Location"))
1049 cupsdSetString(&p
->location
, value
);
1051 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1054 cupsdSetString(&p
->geo_location
, value
);
1056 else if (!_cups_strcasecmp(line
, "Organization"))
1059 cupsdSetString(&p
->organization
, value
);
1061 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1064 cupsdSetString(&p
->organizational_unit
, value
);
1066 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1069 cupsdSetDeviceURI(p
, value
);
1071 cupsdLogMessage(CUPSD_LOG_ERROR
,
1072 "Syntax error on line %d of printers.conf.", linenum
);
1074 else if (!_cups_strcasecmp(line
, "Option") && value
)
1080 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1083 cupsdLogMessage(CUPSD_LOG_ERROR
,
1084 "Syntax error on line %d of printers.conf.", linenum
);
1087 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1089 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1093 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1095 if (value
&& strcmp(value
, "none"))
1096 cupsdSetString(&p
->port_monitor
, value
);
1098 cupsdClearString(&p
->port_monitor
);
1100 cupsdLogMessage(CUPSD_LOG_ERROR
,
1101 "Syntax error on line %d of printers.conf.", linenum
);
1103 else if (!_cups_strcasecmp(line
, "Reason"))
1106 strcmp(value
, "connecting-to-device") &&
1107 strcmp(value
, "cups-insecure-filter-warning") &&
1108 strcmp(value
, "cups-missing-filter-warning"))
1110 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1111 if (!strcmp(value
, p
->reasons
[i
]))
1114 if (i
>= p
->num_reasons
&&
1115 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1117 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1122 cupsdLogMessage(CUPSD_LOG_ERROR
,
1123 "Syntax error on line %d of printers.conf.", linenum
);
1125 else if (!_cups_strcasecmp(line
, "State"))
1128 * Set the initial queue state...
1131 if (value
&& !_cups_strcasecmp(value
, "idle"))
1132 p
->state
= IPP_PRINTER_IDLE
;
1133 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1135 p
->state
= IPP_PRINTER_STOPPED
;
1137 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1138 if (!strcmp("paused", p
->reasons
[i
]))
1141 if (i
>= p
->num_reasons
&&
1142 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1144 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1149 cupsdLogMessage(CUPSD_LOG_ERROR
,
1150 "Syntax error on line %d of printers.conf.", linenum
);
1152 else if (!_cups_strcasecmp(line
, "StateMessage"))
1155 * Set the initial queue state message...
1159 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1161 else if (!_cups_strcasecmp(line
, "StateTime"))
1164 * Set the state time...
1168 p
->state_time
= atoi(value
);
1170 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1173 * Set the config time...
1177 p
->config_time
= atoi(value
);
1179 else if (!_cups_strcasecmp(line
, "Accepting"))
1182 * Set the initial accepting state...
1186 (!_cups_strcasecmp(value
, "yes") ||
1187 !_cups_strcasecmp(value
, "on") ||
1188 !_cups_strcasecmp(value
, "true")))
1191 (!_cups_strcasecmp(value
, "no") ||
1192 !_cups_strcasecmp(value
, "off") ||
1193 !_cups_strcasecmp(value
, "false")))
1196 cupsdLogMessage(CUPSD_LOG_ERROR
,
1197 "Syntax error on line %d of printers.conf.", linenum
);
1199 else if (!_cups_strcasecmp(line
, "Type"))
1202 p
->type
= (cups_ptype_t
)atoi(value
);
1204 cupsdLogMessage(CUPSD_LOG_ERROR
,
1205 "Syntax error on line %d of printers.conf.", linenum
);
1207 else if (!_cups_strcasecmp(line
, "Shared"))
1210 * Set the initial shared state...
1214 (!_cups_strcasecmp(value
, "yes") ||
1215 !_cups_strcasecmp(value
, "on") ||
1216 !_cups_strcasecmp(value
, "true")))
1219 (!_cups_strcasecmp(value
, "no") ||
1220 !_cups_strcasecmp(value
, "off") ||
1221 !_cups_strcasecmp(value
, "false")))
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Syntax error on line %d of printers.conf.", linenum
);
1227 else if (!_cups_strcasecmp(line
, "JobSheets"))
1230 * Set the initial job sheets...
1235 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1240 cupsdSetString(&p
->job_sheets
[0], value
);
1242 while (isspace(*valueptr
& 255))
1247 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1252 cupsdSetString(&p
->job_sheets
[1], value
);
1256 cupsdLogMessage(CUPSD_LOG_ERROR
,
1257 "Syntax error on line %d of printers.conf.", linenum
);
1259 else if (!_cups_strcasecmp(line
, "AllowUser"))
1264 cupsdAddString(&(p
->users
), value
);
1267 cupsdLogMessage(CUPSD_LOG_ERROR
,
1268 "Syntax error on line %d of printers.conf.", linenum
);
1270 else if (!_cups_strcasecmp(line
, "DenyUser"))
1275 cupsdAddString(&(p
->users
), value
);
1278 cupsdLogMessage(CUPSD_LOG_ERROR
,
1279 "Syntax error on line %d of printers.conf.", linenum
);
1281 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1284 p
->quota_period
= atoi(value
);
1286 cupsdLogMessage(CUPSD_LOG_ERROR
,
1287 "Syntax error on line %d of printers.conf.", linenum
);
1289 else if (!_cups_strcasecmp(line
, "PageLimit"))
1292 p
->page_limit
= atoi(value
);
1294 cupsdLogMessage(CUPSD_LOG_ERROR
,
1295 "Syntax error on line %d of printers.conf.", linenum
);
1297 else if (!_cups_strcasecmp(line
, "KLimit"))
1300 p
->k_limit
= atoi(value
);
1302 cupsdLogMessage(CUPSD_LOG_ERROR
,
1303 "Syntax error on line %d of printers.conf.", linenum
);
1305 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1309 cupsd_policy_t
*pol
; /* Policy */
1312 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1314 cupsdSetString(&p
->op_policy
, value
);
1315 p
->op_policy_ptr
= pol
;
1318 cupsdLogMessage(CUPSD_LOG_ERROR
,
1319 "Bad policy \"%s\" on line %d of printers.conf",
1323 cupsdLogMessage(CUPSD_LOG_ERROR
,
1324 "Syntax error on line %d of printers.conf.", linenum
);
1326 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1330 if (strcmp(value
, "retry-current-job") &&
1331 strcmp(value
, "abort-job") &&
1332 strcmp(value
, "retry-job") &&
1333 strcmp(value
, "stop-printer"))
1334 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1336 cupsdSetString(&p
->error_policy
, value
);
1339 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1341 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1343 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1346 cupsdLogMessage(CUPSD_LOG_ERROR
,
1347 "Syntax error on line %d of printers.conf.", linenum
);
1350 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1353 cupsdSetPrinterAttrs(p
);
1355 if (!strcmp(value
, "marker-change-time"))
1356 p
->marker_time
= atoi(valueptr
);
1358 cupsdSetPrinterAttr(p
, value
, valueptr
);
1361 else if (_cups_strcasecmp(line
, "Filter") &&
1362 _cups_strcasecmp(line
, "Prefilter") &&
1363 _cups_strcasecmp(line
, "Product"))
1366 * Something else we don't understand (and that wasn't used in a prior
1367 * release of CUPS...
1370 cupsdLogMessage(CUPSD_LOG_ERROR
,
1371 "Unknown configuration directive %s on line %d of "
1372 "printers.conf.", line
, linenum
);
1381 * 'cupsdRenamePrinter()' - Rename a printer.
1386 cupsd_printer_t
*p
, /* I - Printer */
1387 const char *name
) /* I - New name */
1390 * Remove the printer from the array(s) first...
1393 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1394 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1395 cupsArrayRemove(Printers
, p
);
1398 * Rename the printer type...
1401 mimeDeleteType(MimeDatabase
, p
->filetype
);
1402 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1404 if (p
->prefiltertype
)
1406 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1407 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1411 * Rename the printer...
1414 cupsdSetString(&p
->name
, name
);
1417 * Reset printer attributes...
1420 cupsdSetPrinterAttrs(p
);
1423 * Add the printer back to the printer array(s)...
1426 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1427 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1428 cupsArrayAdd(Printers
, p
);
1433 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1438 cupsdSaveAllPrinters(void)
1440 int i
; /* Looping var */
1441 cups_file_t
*fp
; /* printers.conf file */
1442 char filename
[1024], /* printers.conf filename */
1443 temp
[1024], /* Temporary string */
1444 value
[2048], /* Value string */
1445 *ptr
, /* Pointer into value */
1446 *name
; /* Current user/group name */
1447 cupsd_printer_t
*printer
; /* Current printer class */
1448 time_t curtime
; /* Current time */
1449 struct tm
*curdate
; /* Current date */
1450 cups_option_t
*option
; /* Current option */
1451 ipp_attribute_t
*marker
; /* Current marker attribute */
1455 * Create the printers.conf file...
1458 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1460 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1463 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1466 * Write a small header to the file...
1469 curtime
= time(NULL
);
1470 curdate
= localtime(&curtime
);
1471 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1473 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1474 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1475 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1477 cupsFilePrintf(fp
, "NextPrinterId %d\n", NextPrinterId
);
1480 * Write each local printer known to the system...
1483 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1485 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1488 * Skip printer classes and temporary queues...
1491 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1495 * Write printers as needed...
1498 if (printer
== DefaultPrinter
)
1499 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1501 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1503 if (printer
->printer_id
)
1504 cupsFilePrintf(fp
, "PrinterId %d\n", printer
->printer_id
);
1506 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1508 if (printer
->num_auth_info_required
> 0)
1510 switch (printer
->num_auth_info_required
)
1513 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1517 snprintf(value
, sizeof(value
), "%s,%s",
1518 printer
->auth_info_required
[0],
1519 printer
->auth_info_required
[1]);
1524 snprintf(value
, sizeof(value
), "%s,%s,%s",
1525 printer
->auth_info_required
[0],
1526 printer
->auth_info_required
[1],
1527 printer
->auth_info_required
[2]);
1531 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1535 cupsFilePutConf(fp
, "Info", printer
->info
);
1537 if (printer
->location
)
1538 cupsFilePutConf(fp
, "Location", printer
->location
);
1540 if (printer
->geo_location
)
1541 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1543 if (printer
->make_model
)
1544 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1546 if (printer
->organization
)
1547 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1549 if (printer
->organizational_unit
)
1550 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1552 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1554 if (printer
->port_monitor
)
1555 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1557 if (printer
->state
== IPP_PRINTER_STOPPED
)
1559 cupsFilePuts(fp
, "State Stopped\n");
1561 if (printer
->state_message
[0])
1562 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1565 cupsFilePuts(fp
, "State Idle\n");
1567 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1568 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1570 for (i
= 0; i
< printer
->num_reasons
; i
++)
1571 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1572 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1573 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1574 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1576 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1578 if (printer
->accepting
)
1579 cupsFilePuts(fp
, "Accepting Yes\n");
1581 cupsFilePuts(fp
, "Accepting No\n");
1583 if (printer
->shared
)
1584 cupsFilePuts(fp
, "Shared Yes\n");
1586 cupsFilePuts(fp
, "Shared No\n");
1588 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1589 printer
->job_sheets
[1]);
1590 cupsFilePutConf(fp
, "JobSheets", value
);
1592 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1593 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1594 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1596 for (name
= (char *)cupsArrayFirst(printer
->users
);
1598 name
= (char *)cupsArrayNext(printer
->users
))
1599 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1601 if (printer
->op_policy
)
1602 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1603 if (printer
->error_policy
)
1604 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1606 for (i
= printer
->num_options
, option
= printer
->options
;
1610 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1611 cupsFilePutConf(fp
, "Option", value
);
1614 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1615 IPP_TAG_NAME
)) != NULL
)
1617 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1619 for (i
= 0, ptr
= value
+ strlen(value
);
1620 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1626 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1631 cupsFilePutConf(fp
, "Attribute", value
);
1634 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1635 IPP_TAG_INTEGER
)) != NULL
)
1637 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1638 marker
->values
[0].integer
);
1639 for (i
= 1; i
< marker
->num_values
; i
++)
1640 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1641 cupsFilePuts(fp
, "\n");
1644 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1645 IPP_TAG_INTEGER
)) != NULL
)
1647 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1648 marker
->values
[0].integer
);
1649 for (i
= 1; i
< marker
->num_values
; i
++)
1650 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1651 cupsFilePuts(fp
, "\n");
1654 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1655 IPP_TAG_INTEGER
)) != NULL
)
1657 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1658 marker
->values
[0].integer
);
1659 for (i
= 1; i
< marker
->num_values
; i
++)
1660 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1661 cupsFilePuts(fp
, "\n");
1664 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1665 IPP_TAG_TEXT
)) != NULL
)
1667 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1668 marker
->values
[0].string
.text
);
1670 cupsFilePutConf(fp
, "Attribute", value
);
1673 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1674 IPP_TAG_NAME
)) != NULL
)
1676 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1678 for (i
= 0, ptr
= value
+ strlen(value
);
1679 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1685 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1690 cupsFilePutConf(fp
, "Attribute", value
);
1693 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1694 IPP_TAG_KEYWORD
)) != NULL
)
1696 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1698 for (i
= 0, ptr
= value
+ strlen(value
);
1699 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1705 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1710 cupsFilePutConf(fp
, "Attribute", value
);
1713 if (printer
->marker_time
)
1714 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1715 (long)printer
->marker_time
);
1717 if (printer
== DefaultPrinter
)
1718 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1720 cupsFilePuts(fp
, "</Printer>\n");
1723 cupsdCloseCreatedConfFile(fp
, filename
);
1728 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1731 int /* O - 1 if value OK, 0 otherwise */
1732 cupsdSetAuthInfoRequired(
1733 cupsd_printer_t
*p
, /* I - Printer */
1734 const char *values
, /* I - Plain text value (or NULL) */
1735 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1737 int i
; /* Looping var */
1740 p
->num_auth_info_required
= 0;
1743 * Do we have a plain text value?
1749 * Yes, grab the keywords...
1752 const char *end
; /* End of current value */
1755 while (*values
&& p
->num_auth_info_required
< 4)
1757 if ((end
= strchr(values
, ',')) == NULL
)
1758 end
= values
+ strlen(values
);
1760 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1762 if (p
->num_auth_info_required
!= 0 || *end
)
1765 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1766 p
->num_auth_info_required
++;
1770 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1772 if (p
->num_auth_info_required
!= 0 || *end
)
1775 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1776 p
->num_auth_info_required
++;
1779 * Don't allow sharing of queues that require Kerberos authentication.
1784 cupsdDeregisterPrinter(p
, 1);
1788 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1790 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1791 p
->num_auth_info_required
++;
1793 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1795 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1796 p
->num_auth_info_required
++;
1798 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1800 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1801 p
->num_auth_info_required
++;
1806 values
= (*end
) ? end
+ 1 : end
;
1809 if (p
->num_auth_info_required
== 0)
1811 p
->auth_info_required
[0] = "none";
1812 p
->num_auth_info_required
= 1;
1816 * Update the printer-type value as needed...
1819 if (p
->num_auth_info_required
> 1 ||
1820 strcmp(p
->auth_info_required
[0], "none"))
1821 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1823 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1829 * Grab values from an attribute instead...
1832 if (!attr
|| attr
->num_values
> 4)
1835 for (i
= 0; i
< attr
->num_values
; i
++)
1837 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1839 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1842 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1843 p
->num_auth_info_required
++;
1847 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1849 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1852 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1853 p
->num_auth_info_required
++;
1856 * Don't allow sharing of queues that require Kerberos authentication.
1861 cupsdDeregisterPrinter(p
, 1);
1867 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1869 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1870 p
->num_auth_info_required
++;
1872 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1874 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1875 p
->num_auth_info_required
++;
1877 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1879 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1880 p
->num_auth_info_required
++;
1891 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1895 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1896 const char *uri
) /* I - Device URI */
1898 char buffer
[1024], /* URI buffer */
1899 *start
, /* Start of data after scheme */
1900 *slash
, /* First slash after scheme:// */
1901 *ptr
; /* Pointer into user@host:port part */
1905 * Set the full device URI..
1908 cupsdSetString(&(p
->device_uri
), uri
);
1911 * Copy the device URI to a temporary buffer so we can sanitize any auth
1915 strlcpy(buffer
, uri
, sizeof(buffer
));
1918 * Find the end of the scheme:// part...
1921 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1923 for (start
= ptr
+ 1; *start
; start
++)
1928 * Find the next slash (/) in the URI...
1931 if ((slash
= strchr(start
, '/')) == NULL
)
1932 slash
= start
+ strlen(start
); /* No slash, point to the end */
1935 * Check for an @ sign before the slash...
1938 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1941 * Found an @ sign and it is before the resource part, so we have
1942 * an authentication string. Copy the remaining URI over the
1943 * authentication string...
1946 _cups_strcpy(start
, ptr
+ 1);
1951 * Save the sanitized URI...
1954 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1959 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1963 cupsdSetPrinterAttr(
1964 cupsd_printer_t
*p
, /* I - Printer */
1965 const char *name
, /* I - Attribute name */
1966 const char *value
) /* I - Attribute value string */
1968 ipp_attribute_t
*attr
; /* Attribute */
1969 int i
, /* Looping var */
1970 count
; /* Number of values */
1971 char *temp
, /* Temporary copy of value string */
1972 *ptr
, /* Pointer into value */
1973 *start
, /* Start of value */
1974 quote
; /* Quote character */
1975 ipp_tag_t value_tag
; /* Value tag for this attribute */
1979 * Don't allow empty values...
1982 if (!*value
&& strcmp(name
, "marker-message"))
1984 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1989 * Copy the value string so we can do what we want with it...
1992 if ((temp
= strdup(value
)) == NULL
)
1994 cupsdLogMessage(CUPSD_LOG_ERROR
,
1995 "Unable to duplicate value for \"%s\" attribute.", name
);
2000 * Count the number of values...
2003 for (count
= 1, quote
= '\0', ptr
= temp
;
2011 else if (*ptr
== '\\' && ptr
[1])
2013 else if (*ptr
== '\'' || *ptr
== '\"')
2015 else if (*ptr
== ',')
2020 * Then add or update the attribute as needed...
2023 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2024 !strcmp(name
, "marker-high-levels"))
2030 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2031 attr
->num_values
< count
)
2033 ippDeleteAttribute(p
->attrs
, attr
);
2038 attr
->num_values
= count
;
2040 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2046 cupsdLogMessage(CUPSD_LOG_ERROR
,
2047 "Unable to allocate memory for printer attribute "
2048 "(%d values)", count
);
2052 for (i
= 0, start
= temp
; i
< count
; i
++)
2054 if ((ptr
= strchr(start
, ',')) != NULL
)
2057 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2066 * Name or keyword values...
2069 if (!strcmp(name
, "marker-types"))
2070 value_tag
= IPP_TAG_KEYWORD
;
2071 else if (!strcmp(name
, "marker-message"))
2072 value_tag
= IPP_TAG_TEXT
;
2074 value_tag
= IPP_TAG_NAME
;
2076 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2077 attr
->num_values
< count
)
2079 ippDeleteAttribute(p
->attrs
, attr
);
2085 for (i
= 0; i
< attr
->num_values
; i
++)
2086 _cupsStrFree(attr
->values
[i
].string
.text
);
2088 attr
->num_values
= count
;
2091 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2097 cupsdLogMessage(CUPSD_LOG_ERROR
,
2098 "Unable to allocate memory for printer attribute "
2099 "(%d values)", count
);
2103 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2105 for (start
= ptr
; *ptr
; ptr
++)
2108 *ptr
= quote
= '\0';
2111 else if (*ptr
== '\\' && ptr
[1])
2112 _cups_strcpy(ptr
, ptr
+ 1);
2113 else if (*ptr
== '\'' || *ptr
== '\"')
2120 _cups_strcpy(ptr
, ptr
+ 1);
2122 else if (*ptr
== ',')
2129 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2136 * Update the printer-supply and printer-supply-description, as needed...
2139 if (!strcmp(name
, "marker-names"))
2141 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2142 /* printer-supply-description attribute */
2144 if (supply_desc
!= NULL
)
2145 ippDeleteAttribute(p
->attrs
, supply_desc
);
2147 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2148 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2149 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2151 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2153 char buffer
[256], /* printer-supply values */
2154 pstype
[64], /* printer-supply type value */
2155 *psptr
; /* Pointer into type */
2156 const char *color
, /* marker-colors value */
2157 *type
; /* marker-types value */
2158 int level
; /* marker-levels value */
2159 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2160 /* marker-colors attribute */
2161 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2162 /* marker-levels attribute */
2163 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2164 /* marker-types attribute */
2165 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2166 /* printer-supply attribute */
2170 ippDeleteAttribute(p
->attrs
, supply
);
2174 if (!colors
|| !levels
|| !types
)
2177 count
= ippGetCount(colors
);
2178 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2181 for (i
= 0; i
< count
; i
++)
2183 color
= ippGetString(colors
, i
, NULL
);
2184 level
= ippGetInteger(levels
, i
);
2185 type
= ippGetString(types
, i
, NULL
);
2187 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2191 *psptr
++ = (char)toupper(*type
& 255);
2197 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
);
2200 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2202 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2209 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2213 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2215 int i
; /* Looping var */
2216 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2217 cupsd_location_t
*auth
; /* Pointer to authentication element */
2218 const char *auth_supported
; /* Authentication supported */
2219 ipp_t
*oldattrs
; /* Old printer attributes */
2220 ipp_attribute_t
*attr
; /* Attribute data */
2221 char *name
, /* Current user/group name */
2222 *filter
; /* Current filter */
2225 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2229 * Make sure that we have the common attributes defined...
2233 cupsdCreateCommonData();
2235 _cupsRWLockWrite(&p
->lock
);
2238 * Clear out old filters, if any...
2241 delete_printer_filters(p
);
2244 * Figure out the authentication that is required for the printer.
2247 auth_supported
= "requesting-user-name";
2249 if (p
->type
& CUPS_PRINTER_CLASS
)
2250 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2252 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2254 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2255 auth
->type
== CUPSD_AUTH_NONE
)
2256 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2260 int auth_type
; /* Authentication type */
2263 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2264 auth_type
= cupsdDefaultAuthType();
2266 if (auth_type
== CUPSD_AUTH_BASIC
)
2267 auth_supported
= "basic";
2269 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2270 auth_supported
= "negotiate";
2271 #endif /* HAVE_GSSAPI */
2273 if (auth_type
!= CUPSD_AUTH_NONE
)
2274 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2276 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2279 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2282 * Create the required IPP attributes for a printer...
2285 oldattrs
= p
->attrs
;
2286 p
->attrs
= ippNew();
2288 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2289 "uri-authentication-supported", NULL
, auth_supported
);
2290 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2291 "uri-security-supported", NULL
, "none");
2293 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "printer-id", p
->printer_id
);
2294 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2296 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2297 NULL
, p
->location
? p
->location
: "");
2298 if (p
->geo_location
)
2299 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2301 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2302 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2303 NULL
, p
->info
? p
->info
: "");
2304 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2305 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2306 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2308 if (cupsArrayCount(p
->users
) > 0)
2311 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2312 "requesting-user-name-denied",
2313 cupsArrayCount(p
->users
), NULL
, NULL
);
2315 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2316 "requesting-user-name-allowed",
2317 cupsArrayCount(p
->users
), NULL
, NULL
);
2319 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2321 i
++, name
= (char *)cupsArrayNext(p
->users
))
2322 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2325 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2326 "job-quota-period", p
->quota_period
);
2327 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2328 "job-k-limit", p
->k_limit
);
2329 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2330 "job-page-limit", p
->page_limit
);
2331 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2332 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2333 "auth-info-required", p
->num_auth_info_required
, NULL
,
2334 p
->auth_info_required
);
2336 if (cupsArrayCount(Banners
) > 0)
2339 * Setup the job-sheets-default attribute...
2342 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2343 "job-sheets-default", 2, NULL
, NULL
);
2347 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2348 Classification
: p
->job_sheets
[0]);
2349 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2350 Classification
: p
->job_sheets
[1]);
2358 * Assign additional attributes depending on whether this is a printer
2362 if (p
->type
& CUPS_PRINTER_CLASS
)
2365 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2368 * Add class-specific attributes...
2371 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2372 "printer-make-and-model", NULL
, "Local Printer Class");
2373 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2374 "file:///dev/null");
2376 if (p
->num_printers
> 0)
2379 * Add a list of member names; URIs are added in copy_printer_attrs...
2382 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2383 "member-names", p
->num_printers
, NULL
, NULL
);
2384 p
->type
|= CUPS_PRINTER_OPTIONS
;
2386 for (i
= 0; i
< p
->num_printers
; i
++)
2389 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2391 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2398 * Add printer-specific attributes...
2401 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2402 p
->sanitized_device_uri
);
2405 * Assign additional attributes from the PPD file (if any)...
2411 * Add filters for printer...
2414 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2415 "cups-insecure-filter-warning");
2417 if (p
->pc
&& p
->pc
->filters
)
2419 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2421 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2422 add_printer_filter(p
, p
->filetype
, filter
);
2424 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2427 * Add a filter from application/vnd.cups-raw to printer/name to
2428 * handle "raw" printing by users.
2431 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2434 * Add a PostScript filter, since this is still possibly PS printer.
2437 add_printer_filter(p
, p
->filetype
,
2438 "application/vnd.cups-postscript 0 -");
2441 if (p
->pc
&& p
->pc
->prefilters
)
2443 if (!p
->prefiltertype
)
2444 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2446 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2448 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2449 add_printer_filter(p
, p
->prefiltertype
, filter
);
2454 * Copy marker attributes as needed...
2459 ipp_attribute_t
*oldattr
; /* Old attribute */
2462 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2463 IPP_TAG_NAME
)) != NULL
)
2465 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2466 "marker-colors", oldattr
->num_values
, NULL
,
2469 for (i
= 0; i
< oldattr
->num_values
; i
++)
2470 attr
->values
[i
].string
.text
=
2471 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2475 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2476 IPP_TAG_INTEGER
)) != NULL
)
2478 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2479 "marker-levels", oldattr
->num_values
,
2482 for (i
= 0; i
< oldattr
->num_values
; i
++)
2483 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2487 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2488 IPP_TAG_TEXT
)) != NULL
)
2489 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2490 NULL
, oldattr
->values
[0].string
.text
);
2492 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2493 IPP_TAG_INTEGER
)) != NULL
)
2495 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2496 "marker-low-levels", oldattr
->num_values
,
2499 for (i
= 0; i
< oldattr
->num_values
; i
++)
2500 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2504 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2505 IPP_TAG_INTEGER
)) != NULL
)
2507 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2508 "marker-high-levels", oldattr
->num_values
,
2511 for (i
= 0; i
< oldattr
->num_values
; i
++)
2512 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2516 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2517 IPP_TAG_NAME
)) != NULL
)
2519 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2520 "marker-names", oldattr
->num_values
, NULL
,
2523 for (i
= 0; i
< oldattr
->num_values
; i
++)
2524 attr
->values
[i
].string
.text
=
2525 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2529 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2530 IPP_TAG_KEYWORD
)) != NULL
)
2532 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2533 "marker-types", oldattr
->num_values
, NULL
,
2536 for (i
= 0; i
< oldattr
->num_values
; i
++)
2537 attr
->values
[i
].string
.text
=
2538 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2542 ippDelete(oldattrs
);
2546 * Force sharing off for remote queues...
2549 if (p
->type
& CUPS_PRINTER_REMOTE
)
2553 * Populate the document-format-supported attribute...
2556 add_printer_formats(p
);
2558 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2562 * Add name-default attributes...
2565 add_printer_defaults(p
);
2567 _cupsRWUnlock(&p
->lock
);
2570 * Let the browse protocols reflect the change
2573 cupsdRegisterPrinter(p
);
2578 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2581 int /* O - 1 if something changed, 0 otherwise */
2582 cupsdSetPrinterReasons(
2583 cupsd_printer_t
*p
, /* I - Printer */
2584 const char *s
) /* I - Reasons strings */
2586 int i
, /* Looping var */
2587 changed
= 0; /* Did something change? */
2588 const char *sptr
; /* Pointer into reasons */
2589 char reason
[255], /* Reason string */
2590 *rptr
; /* Pointer into reason */
2593 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2594 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2596 if (s
[0] == '-' || s
[0] == '+')
2599 * Add/remove reasons...
2607 * Replace reasons...
2612 for (i
= 0; i
< p
->num_reasons
; i
++)
2613 _cupsStrFree(p
->reasons
[i
]);
2621 if (!strcmp(s
, "none"))
2625 * Loop through all of the reasons...
2631 * Skip leading whitespace and commas...
2634 while (isspace(*sptr
& 255) || *sptr
== ',')
2637 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2638 if (rptr
< (reason
+ sizeof(reason
) - 1))
2652 for (i
= 0; i
< p
->num_reasons
; i
++)
2653 if (!strcmp(reason
, p
->reasons
[i
]))
2656 * Found a match, so remove it...
2661 _cupsStrFree(p
->reasons
[i
]);
2663 if (i
< p
->num_reasons
)
2664 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2666 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2667 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2669 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2670 p
->job
->completed
= 0;
2672 if (strcmp(reason
, "connecting-to-device"))
2678 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2684 for (i
= 0; i
< p
->num_reasons
; i
++)
2685 if (!strcmp(reason
, p
->reasons
[i
]))
2688 if (i
>= p
->num_reasons
)
2690 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2692 cupsdLogMessage(CUPSD_LOG_ALERT
,
2693 "Too many printer-state-reasons values for %s (%d)",
2698 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2702 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2703 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2705 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2706 p
->job
->completed
= 1;
2708 if (strcmp(reason
, "connecting-to-device"))
2719 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2723 cupsdSetPrinterState(
2724 cupsd_printer_t
*p
, /* I - Printer to change */
2725 ipp_pstate_t s
, /* I - New state */
2726 int update
) /* I - Update printers.conf? */
2728 cupsd_job_t
*job
; /* Current job */
2729 ipp_pstate_t old_state
; /* Old printer state */
2730 static const char * const printer_states
[] =
2731 { /* State strings */
2739 * Set the new state...
2742 old_state
= p
->state
;
2747 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2748 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2749 "%s \"%s\" state changed to %s.",
2750 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2751 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2754 * Let the browse code know this needs to be updated...
2757 p
->state_time
= time(NULL
);
2761 * Set/clear the paused reason as needed...
2764 if (s
== IPP_PRINTER_STOPPED
)
2765 cupsdSetPrinterReasons(p
, "+paused");
2767 cupsdSetPrinterReasons(p
, "-paused");
2771 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2773 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2774 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2775 !_cups_strcasecmp(job
->dest
, p
->name
))
2776 ippSetString(job
->attrs
, &job
->reasons
, 0,
2777 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2781 * Clear the message for the queue when going to processing...
2784 if (s
== IPP_PRINTER_PROCESSING
)
2785 p
->state_message
[0] = '\0';
2788 * Let the browse protocols reflect the change...
2792 cupsdRegisterPrinter(p
);
2795 * Save the printer configuration if a printer goes from idle or processing
2796 * to stopped (or visa-versa)...
2800 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2806 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2810 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2811 int update
)/* I - Update printers.conf? */
2814 * Set the printer state...
2817 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2820 * See if we have a job printing on this printer...
2823 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2824 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2825 "Job stopped due to printer being paused.");
2830 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2833 int /* O - 1 if successful, 0 otherwise */
2834 cupsdUpdatePrinterPPD(
2835 cupsd_printer_t
*p
, /* I - Printer */
2836 int num_keywords
, /* I - Number of keywords */
2837 cups_option_t
*keywords
) /* I - Keywords */
2839 int i
; /* Looping var */
2840 cups_file_t
*src
, /* Original file */
2841 *dst
; /* New file */
2842 char srcfile
[1024], /* Original filename */
2843 dstfile
[1024], /* New filename */
2844 line
[1024], /* Line from file */
2845 keystring
[41]; /* Keyword from line */
2846 cups_option_t
*keyword
; /* Current keyword */
2849 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2853 * Get the old and new PPD filenames...
2856 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2857 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2860 * Rename the old file and open the old and new...
2863 if (rename(dstfile
, srcfile
))
2865 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2866 p
->name
, strerror(errno
));
2870 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2872 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2873 srcfile
, strerror(errno
));
2874 rename(srcfile
, dstfile
);
2878 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2880 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2881 dstfile
, strerror(errno
));
2883 rename(srcfile
, dstfile
);
2888 * Copy the first line and then write out all of the keywords...
2891 if (!cupsFileGets(src
, line
, sizeof(line
)))
2893 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2894 srcfile
, strerror(errno
));
2897 rename(srcfile
, dstfile
);
2901 cupsFilePrintf(dst
, "%s\n", line
);
2903 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2905 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2906 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2910 * Then copy the rest of the PPD file, dropping any keywords we changed.
2913 while (cupsFileGets(src
, line
, sizeof(line
)))
2916 * Skip keywords we've already set...
2919 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2920 cupsGetOption(keystring
, num_keywords
, keywords
))
2924 * Otherwise write the line...
2927 cupsFilePrintf(dst
, "%s\n", line
);
2931 * Close files and return...
2942 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2946 cupsdUpdatePrinters(void)
2948 cupsd_printer_t
*p
; /* Current printer */
2952 * Loop through the printers and recreate the printer attributes
2953 * for any local printers since the policy and/or access control
2954 * stuff may have changed. Also, if browsing is disabled, remove
2955 * any remote printers...
2958 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2960 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2963 * Update the operation policy pointer...
2966 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2967 p
->op_policy_ptr
= DefaultPolicyPtr
;
2970 * Update printer attributes...
2973 cupsdSetPrinterAttrs(p
);
2979 * 'cupsdValidateDest()' - Validate a printer/class destination.
2982 const char * /* O - Printer or class name */
2984 const char *uri
, /* I - Printer URI */
2985 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2986 cupsd_printer_t
**printer
) /* O - Printer pointer */
2988 cupsd_printer_t
*p
; /* Current printer */
2989 char localname
[1024],/* Localized hostname */
2990 *lptr
, /* Pointer into localized hostname */
2991 *sptr
, /* Pointer into server name */
2992 *rptr
, /* Pointer into resource */
2993 scheme
[32], /* Scheme portion of URI */
2994 username
[64], /* Username portion of URI */
2995 hostname
[HTTP_MAX_HOST
],
2996 /* Host portion of URI */
2997 resource
[HTTP_MAX_URI
];
2998 /* Resource portion of URI */
2999 int port
; /* Port portion of URI */
3002 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
3006 * Initialize return values...
3013 *dtype
= (cups_ptype_t
)0;
3016 * Pull the hostname and resource from the URI...
3019 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3020 username
, sizeof(username
), hostname
, sizeof(hostname
),
3021 &port
, resource
, sizeof(resource
));
3024 * See if the resource is a class or printer...
3027 if (!strncmp(resource
, "/classes/", 9))
3033 rptr
= resource
+ 9;
3035 else if (!strncmp(resource
, "/printers/", 10))
3041 rptr
= resource
+ 10;
3046 * Bad resource name...
3053 * See if the printer or class name exists...
3056 p
= cupsdFindDest(rptr
);
3058 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3066 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3072 * Change localhost to the server name...
3075 if (!_cups_strcasecmp(hostname
, "localhost"))
3076 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3078 strlcpy(localname
, hostname
, sizeof(localname
));
3080 if (!_cups_strcasecmp(hostname
, ServerName
))
3083 * Localize the hostname...
3086 lptr
= strchr(localname
, '.');
3087 sptr
= strchr(ServerName
, '.');
3089 if (sptr
!= NULL
&& lptr
!= NULL
)
3092 * Strip the common domain name components...
3095 while (lptr
!= NULL
)
3097 if (!_cups_strcasecmp(lptr
, sptr
))
3103 lptr
= strchr(lptr
+ 1, '.');
3108 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3111 * Find a matching printer or class...
3114 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3116 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3117 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3118 !_cups_strcasecmp(p
->name
, rptr
))
3124 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3134 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3139 cupsdWritePrintcap(void)
3141 int i
; /* Looping var */
3142 cups_file_t
*fp
; /* Printcap file */
3143 cupsd_printer_t
*p
; /* Current printer */
3147 * See if we have a printcap file; if not, don't bother writing it.
3150 if (!Printcap
|| !*Printcap
)
3153 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3156 * Open the printcap file...
3159 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3163 * Put a comment header at the top so that users will know where the
3164 * data has come from...
3167 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3168 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3170 "# %s/printers.conf file. All changes to this file\n"
3171 "# will be lost.\n", ServerRoot
);
3174 * Write a new printcap with the current list of printers.
3177 switch (PrintcapFormat
)
3181 * Each printer is put in the file as:
3191 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3192 DefaultPrinter
->info
, ServerName
,
3193 DefaultPrinter
->name
);
3195 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3197 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3198 if (p
!= DefaultPrinter
)
3199 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3200 ServerName
, p
->name
);
3203 case PRINTCAP_PLIST
:
3205 * Each printer is written as a dictionary in a plist file.
3206 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3207 * printer-location, printer-make-and-model, printer-state,
3208 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3211 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3212 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3213 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3214 "PropertyList-1.0.dtd\">\n"
3215 "<plist version=\"1.0\">\n"
3218 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3220 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3222 cupsFilePuts(fp
, "\t<dict>\n"
3223 "\t\t<key>printer-name</key>\n"
3225 write_xml_string(fp
, p
->name
);
3226 cupsFilePuts(fp
, "</string>\n"
3227 "\t\t<key>printer-info</key>\n"
3229 write_xml_string(fp
, p
->info
);
3230 cupsFilePrintf(fp
, "</string>\n"
3231 "\t\t<key>printer-is-accepting-jobs</key>\n"
3233 "\t\t<key>printer-location</key>\n"
3234 "\t\t<string>", p
->accepting
? "true" : "false");
3235 write_xml_string(fp
, p
->location
);
3236 cupsFilePuts(fp
, "</string>\n"
3237 "\t\t<key>printer-make-and-model</key>\n"
3239 write_xml_string(fp
, p
->make_model
);
3240 cupsFilePrintf(fp
, "</string>\n"
3241 "\t\t<key>printer-state</key>\n"
3242 "\t\t<integer>%d</integer>\n"
3243 "\t\t<key>printer-state-reasons</key>\n"
3244 "\t\t<array>\n", p
->state
);
3245 for (i
= 0; i
< p
->num_reasons
; i
++)
3247 cupsFilePuts(fp
, "\t\t\t<string>");
3248 write_xml_string(fp
, p
->reasons
[i
]);
3249 cupsFilePuts(fp
, "</string>\n");
3251 cupsFilePrintf(fp
, "\t\t</array>\n"
3252 "\t\t<key>printer-type</key>\n"
3253 "\t\t<integer>%d</integer>\n"
3254 "\t\t<key>device-uri</key>\n"
3255 "\t\t<string>", p
->type
);
3256 write_xml_string(fp
, p
->sanitized_device_uri
);
3257 cupsFilePuts(fp
, "</string>\n"
3260 cupsFilePuts(fp
, "</array>\n"
3264 case PRINTCAP_SOLARIS
:
3266 * Each printer is put in the file as:
3268 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3269 * _default:use=DefaultPrinter
3271 * :bsdaddr=ServerName,Printer1:\
3272 * :description=Description:
3274 * :bsdaddr=ServerName,Printer2:\
3275 * :description=Description:
3277 * :bsdaddr=ServerName,Printer3:\
3278 * :description=Description:
3281 * :bsdaddr=ServerName,PrinterN:\
3282 * :description=Description:
3285 cupsFilePuts(fp
, "_all:all=");
3286 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3288 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3289 cupsFilePrintf(fp
, "%s%c", p
->name
,
3290 cupsArrayNext(Printers
) ? ',' : '\n');
3293 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3295 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3297 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3298 cupsFilePrintf(fp
, "%s:\\\n"
3299 "\t:bsdaddr=%s,%s:\\\n"
3300 "\t:description=%s:\n",
3301 p
->name
, ServerName
, p
->name
,
3302 p
->info
? p
->info
: "");
3315 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3319 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3321 int i
; /* Looping var */
3322 int num_options
; /* Number of default options */
3323 cups_option_t
*options
, /* Default options */
3324 *option
; /* Current option */
3325 char name
[256]; /* name-default */
3329 * Maintain a common array of default attribute names...
3332 if (!CommonDefaults
)
3334 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3336 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3337 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3338 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3339 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3340 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-accounting-user-id-default"));
3341 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3342 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3343 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3344 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3345 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3346 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-lease-duration-default"));
3347 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("notify-events-default"));
3348 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3349 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("orientation-requested-default"));
3350 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("print-quality-default"));
3354 * Add all of the default options from the .conf files...
3357 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3361 if (strcmp(option
->name
, "ipp-options") &&
3362 strcmp(option
->name
, "job-sheets") &&
3363 strcmp(option
->name
, "lease-duration"))
3365 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3366 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3368 if (!cupsArrayFind(CommonDefaults
, name
))
3369 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3374 * Convert options to IPP attributes...
3377 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3378 cupsFreeOptions(num_options
, options
);
3381 * Add standard -default attributes as needed...
3384 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3385 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3388 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3389 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3390 "document-format-default", NULL
, "application/octet-stream");
3392 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3393 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3394 "job-cancel-after-default", MaxJobTime
);
3396 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3397 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3398 "job-hold-until-default", NULL
, "no-hold");
3400 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3401 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3402 "job-priority-default", 50);
3404 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3405 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3406 "number-up-default", 1);
3408 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3409 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3410 "notify-lease-duration-default", DefaultLeaseDuration
);
3412 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3413 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3414 "notify-events-default", NULL
, "job-completed");
3416 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3417 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3418 "orientation-requested-default", NULL
, NULL
);
3420 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3421 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3422 "print-quality-default", IPP_QUALITY_NORMAL
);
3427 * 'add_printer_filter()' - Add a MIME filter for a printer.
3432 cupsd_printer_t
*p
, /* I - Printer to add to */
3433 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3434 const char *filter
) /* I - Filter to add */
3436 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3437 type
[MIME_MAX_TYPE
], /* Type for filter */
3438 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3439 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3440 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3441 /* Destination super/type */
3442 program
[1024]; /* Program/filter name */
3443 int cost
; /* Cost of filter */
3444 size_t maxsize
= 0; /* Maximum supported file size */
3445 mime_type_t
*temptype
, /* MIME type looping var */
3446 *desttype
; /* Destination MIME type */
3447 mime_filter_t
*filterptr
; /* MIME filter */
3448 char filename
[1024]; /* Full filter filename */
3451 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3452 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3453 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3454 filtertype
->type
, filter
);
3457 * Parse the filter string; it should be in one of the following formats:
3459 * source/type cost program
3460 * source/type cost maxsize(nnnn) program
3461 * source/type dest/type cost program
3462 * source/type dest/type cost maxsize(nnnn) program
3465 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3466 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3468 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3470 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3472 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3474 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3476 cupsArrayAdd(p
->dest_types
, desttype
);
3482 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3485 desttype
= filtertype
;
3489 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3495 if (!strncmp(program
, "maxsize(", 8))
3497 char *ptr
; /* Pointer into maxsize(nnnn) program */
3499 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3503 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3509 while (_cups_isspace(*ptr
))
3512 _cups_strcpy(program
, ptr
);
3516 * Check permissions on the filter and its containing directory...
3519 if (strcmp(program
, "-"))
3521 if (program
[0] == '/')
3522 strlcpy(filename
, program
, sizeof(filename
));
3524 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3526 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3527 cupsdLogFCMessage
, p
);
3531 * Add the filter to the MIME database, supporting wildcards as needed...
3534 for (temptype
= mimeFirstType(MimeDatabase
);
3536 temptype
= mimeNextType(MimeDatabase
))
3537 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3538 !_cups_strcasecmp(temptype
->super
, super
)) &&
3539 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3541 if (desttype
!= filtertype
)
3543 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3544 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3545 "%s", p
->name
, temptype
->super
, temptype
->type
,
3546 desttype
->super
, desttype
->type
,
3548 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3551 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3553 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3554 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3555 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3556 filtertype
->super
, filtertype
->type
);
3557 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3562 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3563 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3564 "%s", p
->name
, temptype
->super
, temptype
->type
,
3565 filtertype
->super
, filtertype
->type
,
3567 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3572 filterptr
->maxsize
= maxsize
;
3578 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3582 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3584 int i
; /* Looping var */
3585 mime_type_t
*type
; /* Current MIME type */
3586 cups_array_t
*filters
; /* Filters */
3587 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3588 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3589 /* MIME type name */
3593 * Raw (and remote) queues advertise all of the supported MIME
3597 cupsArrayDelete(p
->filetypes
);
3598 p
->filetypes
= NULL
;
3602 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3603 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3604 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3609 * Otherwise, loop through the supported MIME types and see if there
3610 * are filters for them...
3613 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3614 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3616 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3618 for (type
= mimeFirstType(MimeDatabase
);
3620 type
= mimeNextType(MimeDatabase
))
3622 if (!_cups_strcasecmp(type
->super
, "printer"))
3625 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3627 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3629 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3630 "add_printer_formats: %s: %s needs %d filters",
3631 p
->name
, mimetype
, cupsArrayCount(filters
));
3633 cupsArrayDelete(filters
);
3634 cupsArrayAdd(p
->filetypes
, type
);
3637 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3638 "add_printer_formats: %s: %s not supported",
3643 * Add the file formats that can be filtered...
3646 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3647 !cupsArrayFind(p
->filetypes
, type
))
3652 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3653 "add_printer_formats: %s: %d supported types",
3654 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3656 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3657 "document-format-supported",
3658 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3661 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3663 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3665 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3667 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3669 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3672 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3674 char pdl
[1024]; /* Buffer to build pdl list */
3675 mime_filter_t
*filter
; /* MIME filter looping var */
3679 * We only support raw printing if this is not a Tioga PrintJobMgr based
3680 * queue and if application/octet-stream is a known type...
3683 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3685 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3687 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3693 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3694 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3697 * Then list a bunch of formats that are supported by the printer...
3700 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3702 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3704 if (!_cups_strcasecmp(type
->super
, "application"))
3706 if (!_cups_strcasecmp(type
->type
, "pdf"))
3707 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3708 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3709 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3711 else if (!_cups_strcasecmp(type
->super
, "image"))
3713 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3714 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3715 else if (!_cups_strcasecmp(type
->type
, "png"))
3716 strlcat(pdl
, "image/png,", sizeof(pdl
));
3717 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3718 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3723 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3725 cupsdSetString(&p
->pdl
, pdl
);
3727 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3732 * 'compare_printers()' - Compare two printers.
3735 static int /* O - Result of comparison */
3736 compare_printers(void *first
, /* I - First printer */
3737 void *second
, /* I - Second printer */
3738 void *data
) /* I - App data (not used) */
3742 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3743 ((cupsd_printer_t
*)second
)->name
));
3748 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3752 delete_printer_filters(
3753 cupsd_printer_t
*p
) /* I - Printer to remove from */
3755 mime_filter_t
*filter
; /* MIME filter looping var */
3756 mime_type_t
*type
; /* Destination types for filters */
3760 * Range check input...
3767 * Remove all filters from the MIME database that have a destination
3768 * type == printer...
3771 for (filter
= mimeFirstFilter(MimeDatabase
);
3773 filter
= mimeNextFilter(MimeDatabase
))
3774 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3775 cupsArrayFind(p
->dest_types
, filter
->dst
))
3778 * Delete the current filter...
3781 mimeDeleteFilter(MimeDatabase
, filter
);
3784 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3786 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3787 mimeDeleteType(MimeDatabase
, type
);
3789 cupsArrayDelete(p
->dest_types
);
3790 p
->dest_types
= NULL
;
3792 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3793 ",cups-missing-filter-warning");
3798 * 'dirty_printer()' - Mark config and state files dirty for the specified
3803 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3805 if (p
->type
& CUPS_PRINTER_CLASS
)
3806 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3808 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3810 if (PrintcapFormat
== PRINTCAP_PLIST
)
3811 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3816 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3820 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3822 int i
, j
, k
; /* Looping vars */
3823 char cache_name
[1024]; /* Cache filename */
3824 struct stat cache_info
; /* Cache file info */
3825 ppd_file_t
*ppd
; /* PPD file */
3826 char ppd_name
[1024]; /* PPD filename */
3827 struct stat ppd_info
; /* PPD file info */
3828 char strings_name
[1024]; /* Strings filename */
3829 int num_media
; /* Number of media options */
3830 ppd_size_t
*size
; /* Current PPD size */
3831 ppd_option_t
*duplex
, /* Duplex option */
3832 *output_bin
, /* OutputBin option */
3833 *output_mode
, /* OutputMode option */
3834 *resolution
; /* (Set|JCL|)Resolution option */
3835 ppd_choice_t
*choice
, /* Current PPD choice */
3836 *input_slot
, /* Current input slot */
3837 *media_type
; /* Current media type */
3838 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3839 int xdpi
, /* Horizontal resolution */
3840 ydpi
; /* Vertical resolution */
3841 const char *resptr
; /* Pointer into resolution keyword */
3842 pwg_size_t
*pwgsize
; /* Current PWG size */
3843 pwg_map_t
*pwgsource
, /* Current PWG source */
3844 *pwgtype
; /* Current PWG type */
3845 ipp_attribute_t
*attr
; /* Attribute data */
3846 _ipp_value_t
*val
; /* Attribute value */
3847 int num_finishings
, /* Number of finishings */
3848 finishings
[100]; /* finishings-supported values */
3849 int num_qualities
, /* Number of print-quality values */
3850 qualities
[3]; /* print-quality values */
3851 int num_margins
, /* Number of media-*-margin-supported values */
3852 margins
[16]; /* media-*-margin-supported values */
3853 const char *filter
, /* Current filter */
3854 *mandatory
; /* Current mandatory attribute */
3855 static const char * const pwg_raster_document_types
[] =
3861 static const char * const sides
[3] = /* sides-supported values */
3864 "two-sided-long-edge",
3865 "two-sided-short-edge"
3867 static const char * const standard_commands
[] =
3868 { /* Standard CUPS commands */
3876 * Check to see if the cache is up-to-date...
3879 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3880 if (stat(cache_name
, &cache_info
))
3881 cache_info
.st_mtime
= 0;
3883 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3884 if (stat(ppd_name
, &ppd_info
))
3885 ppd_info
.st_mtime
= 1;
3887 snprintf(strings_name
, sizeof(strings_name
), "%s/%s.strings", CacheDir
, p
->name
);
3889 ippDelete(p
->ppd_attrs
);
3890 p
->ppd_attrs
= NULL
;
3892 _ppdCacheDestroy(p
->pc
);
3895 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3897 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3899 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3903 * Loaded successfully!
3911 * Reload PPD attributes from disk...
3914 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3916 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3918 cupsdClearString(&(p
->make_model
));
3920 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3921 p
->type
|= CUPS_PRINTER_BW
;
3923 finishings
[0] = IPP_FINISHINGS_NONE
;
3926 p
->ppd_attrs
= ippNew();
3928 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3931 * Add make/model and other various attributes...
3934 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3937 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3938 ppd_name
, cupsLastErrorString());
3940 ppdMarkDefaults(ppd
);
3942 if (ppd
->color_device
)
3943 p
->type
|= CUPS_PRINTER_COLOR
;
3944 if (ppd
->variable_sizes
)
3945 p
->type
|= CUPS_PRINTER_VARIABLE
;
3946 if (!ppd
->manual_copies
)
3947 p
->type
|= CUPS_PRINTER_COPIES
;
3948 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3949 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3950 p
->type
|= CUPS_PRINTER_FAX
;
3952 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3954 if (p
->pc
&& p
->pc
->charge_info_uri
)
3955 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3956 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3958 if (p
->pc
&& p
->pc
->account_id
)
3959 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3962 if (p
->pc
&& p
->pc
->accounting_user_id
)
3963 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3964 "job-accounting-user-id-supported", 1);
3966 if (p
->pc
&& p
->pc
->password
)
3968 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3969 "job-password-encryption-supported", NULL
, "none");
3970 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3971 "job-password-supported", (int)strlen(p
->pc
->password
));
3974 if (ppd
->throughput
)
3976 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3977 "pages-per-minute", ppd
->throughput
);
3978 if (ppd
->color_device
)
3979 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3980 "pages-per-minute-color", ppd
->throughput
);
3985 * When there is no speed information, just say "1 page per minute".
3988 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3989 "pages-per-minute", 1);
3990 if (ppd
->color_device
)
3991 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3992 "pages-per-minute-color", 1);
3995 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3996 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
4000 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
4002 if (ppdFindChoice(output_mode
, "draft") ||
4003 ppdFindChoice(output_mode
, "fast"))
4004 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4006 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4008 if (ppdFindChoice(output_mode
, "best") ||
4009 ppdFindChoice(output_mode
, "high"))
4010 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4012 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
4016 if (strstr(ppd_attr
->spec
, "draft") ||
4017 strstr(ppd_attr
->spec
, "Draft"))
4019 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
4023 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4026 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4027 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4030 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4032 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4033 "print-quality-supported", num_qualities
, qualities
);
4038 * The NickName can be localized in the character set specified
4039 * by the LanugageEncoding attribute. However, ppdOpen2() has
4040 * already converted the ppd->nickname member to UTF-8 for us
4041 * (the original attribute value is available separately)
4044 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4046 else if (ppd
->modelname
)
4049 * Model name can only contain specific characters...
4052 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4055 cupsdSetString(&p
->make_model
, "Bad PPD File");
4057 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4058 "printer-make-and-model", NULL
, p
->make_model
);
4060 if (p
->pc
&& p
->pc
->strings
)
4061 _cupsMessageSave(strings_name
, _CUPS_MESSAGE_STRINGS
, p
->pc
->strings
);
4063 if (!access(strings_name
, R_OK
))
4064 cupsdSetString(&p
->strings
, strings_name
);
4066 cupsdClearString(&p
->strings
);
4069 * Add media options from the PPD file...
4072 if (ppd
->num_sizes
== 0 || !p
->pc
)
4074 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4075 cupsdLogMessage(CUPSD_LOG_CRIT
,
4076 "The PPD file for printer %s contains no media "
4077 "options and is therefore invalid.", p
->name
);
4079 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4080 "media-default", NULL
, "unknown");
4081 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4082 "media-supported", NULL
, "unknown");
4090 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4091 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4095 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4096 "media-default", NULL
,
4097 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4105 ipp_t
*col
; /* Collection value */
4107 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4108 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4109 col
= new_media_col(pwgsize
,
4110 input_slot
? _ppdCacheGetSource(p
->pc
, input_slot
->choice
) : NULL
,
4111 media_type
? _ppdCacheGetType(p
->pc
, media_type
->choice
) : NULL
);
4113 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default", col
);
4121 num_media
= p
->pc
->num_sizes
;
4122 if (p
->pc
->custom_min_keyword
)
4125 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4126 "media-supported", num_media
, NULL
,
4131 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4133 i
--, pwgsize
++, val
++)
4134 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4136 if (p
->pc
->custom_min_keyword
)
4138 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4140 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4145 * media-size-supported
4148 num_media
= p
->pc
->num_sizes
;
4149 if (p
->pc
->custom_min_keyword
)
4152 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4153 "media-size-supported", num_media
,
4158 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4160 i
--, pwgsize
++, val
++)
4162 val
->collection
= ippNew();
4163 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4164 "x-dimension", pwgsize
->width
);
4165 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4166 "y-dimension", pwgsize
->length
);
4169 if (p
->pc
->custom_min_keyword
)
4171 val
->collection
= ippNew();
4172 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4173 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4174 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4175 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4180 * media-source-supported
4183 if (p
->pc
->num_sources
> 0 &&
4184 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4185 "media-source-supported", p
->pc
->num_sources
,
4186 NULL
, NULL
)) != NULL
)
4188 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4191 i
--, pwgsource
++, val
++)
4192 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4196 * media-type-supported
4199 if (p
->pc
->num_types
> 0 &&
4200 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4201 "media-type-supported", p
->pc
->num_types
,
4202 NULL
, NULL
)) != NULL
)
4204 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4207 i
--, pwgtype
++, val
++)
4208 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4212 * media-*-margin-supported
4215 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4216 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4219 for (j
= 0; j
< num_margins
; j
++)
4220 if (pwgsize
->bottom
== margins
[j
])
4223 if (j
>= num_margins
)
4225 margins
[num_margins
] = pwgsize
->bottom
;
4230 if (num_margins
> 0)
4231 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4232 "media-bottom-margin-supported", num_margins
, margins
);
4234 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4235 "media-bottom-margin-supported", 0);
4237 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4238 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4241 for (j
= 0; j
< num_margins
; j
++)
4242 if (pwgsize
->left
== margins
[j
])
4245 if (j
>= num_margins
)
4247 margins
[num_margins
] = pwgsize
->left
;
4252 if (num_margins
> 0)
4253 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4254 "media-left-margin-supported", num_margins
, margins
);
4256 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4257 "media-left-margin-supported", 0);
4259 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4260 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4263 for (j
= 0; j
< num_margins
; j
++)
4264 if (pwgsize
->right
== margins
[j
])
4267 if (j
>= num_margins
)
4269 margins
[num_margins
] = pwgsize
->right
;
4274 if (num_margins
> 0)
4275 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4276 "media-right-margin-supported", num_margins
, margins
);
4278 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4279 "media-right-margin-supported", 0);
4281 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4282 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4285 for (j
= 0; j
< num_margins
; j
++)
4286 if (pwgsize
->top
== margins
[j
])
4289 if (j
>= num_margins
)
4291 margins
[num_margins
] = pwgsize
->top
;
4296 if (num_margins
> 0)
4297 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4298 "media-top-margin-supported", num_margins
, margins
);
4300 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4301 "media-top-margin-supported", 0);
4304 * media-col-database
4307 num_media
= p
->pc
->num_sizes
;
4308 if (p
->pc
->num_sources
)
4310 if (p
->pc
->num_types
> 0)
4311 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4314 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4316 else if (p
->pc
->num_types
)
4317 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4319 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4320 "media-col-database", num_media
,
4323 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4328 * Start by adding the page size without source or type...
4331 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4333 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4337 * Then add the specific, supported combinations of size, source, and
4341 if (p
->pc
->num_sources
> 0)
4343 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4347 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4349 if (p
->pc
->num_types
> 0)
4351 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4355 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4357 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4363 else if (!ppdConflicts(ppd
))
4365 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4370 else if (p
->pc
->num_types
> 0)
4372 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4376 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4378 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4386 * Update the number of media-col-database values...
4389 attr
->num_values
= val
- attr
->values
;
4397 if (p
->pc
&& p
->pc
->num_bins
> 0)
4399 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4400 "output-bin-supported", p
->pc
->num_bins
,
4405 for (i
= 0, val
= attr
->values
;
4406 i
< p
->pc
->num_bins
;
4408 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4411 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4413 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4414 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4417 if (i
>= p
->pc
->num_bins
)
4420 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4421 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4424 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4425 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4427 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4429 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4430 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4431 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4432 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4435 * Report that this printer has a single output bin that leaves pages face
4439 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4440 "output-bin-supported", NULL
, "face-up");
4441 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4442 "output-bin-default", NULL
, "face-up");
4446 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4447 "output-bin-supported", NULL
, "face-down");
4448 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4449 "output-bin-default", NULL
, "face-down");
4453 * print-color-mode...
4456 if (ppd
->color_device
)
4458 static const char * const color_modes
[] =
4464 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4465 "print-color-mode-supported", 2, NULL
, color_modes
);
4466 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4467 "print-color-mode-default", NULL
, "color");
4468 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4472 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4473 "print-color-mode-supported", NULL
, "monochrome");
4474 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4475 "print-color-mode-default", NULL
, "monochrome");
4476 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4480 * Mandatory job attributes, if any...
4483 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4485 int count
= cupsArrayCount(p
->pc
->mandatory
);
4486 /* Number of mandatory attributes */
4488 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4489 "printer-mandatory-job-attributes", count
, NULL
,
4492 for (val
= attr
->values
,
4493 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4495 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4496 val
->string
.text
= _cupsStrAlloc(mandatory
);
4500 * Printer resolutions...
4503 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4504 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4505 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4506 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4511 * Report all supported resolutions...
4514 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4516 for (i
= 0, choice
= resolution
->choices
;
4517 i
< resolution
->num_choices
;
4520 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4521 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4522 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4524 if (xdpi
<= 0 || ydpi
<= 0)
4526 cupsdLogMessage(CUPSD_LOG_WARN
,
4527 "Bad resolution \"%s\" for printer %s.",
4528 choice
->choice
, p
->name
);
4532 attr
->values
[i
].resolution
.xres
= xdpi
;
4533 attr
->values
[i
].resolution
.yres
= ydpi
;
4534 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4537 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4540 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4543 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4547 * Just the DefaultResolution to report...
4550 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4551 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4554 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4559 if (xdpi
<= 0 || ydpi
<= 0)
4561 cupsdLogMessage(CUPSD_LOG_WARN
,
4562 "Bad default resolution \"%s\" for printer %s.",
4563 ppd_attr
->value
, p
->name
);
4567 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4568 "printer-resolution-default", IPP_RES_PER_INCH
,
4570 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4571 "printer-resolution-supported", IPP_RES_PER_INCH
,
4573 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4578 * No resolutions in PPD - make one up...
4581 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4582 "printer-resolution-default", IPP_RES_PER_INCH
,
4584 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4585 "printer-resolution-supported", IPP_RES_PER_INCH
,
4587 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4594 ppdMarkDefaults(ppd
);
4596 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4597 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4598 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4599 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4600 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4602 if (duplex
&& duplex
->num_choices
> 1 &&
4603 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4605 p
->type
|= CUPS_PRINTER_DUPLEX
;
4607 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4609 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4610 "sides-supported", 3, NULL
, sides
);
4612 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4613 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4614 "sides-default", NULL
, "two-sided-short-edge");
4615 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4616 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4617 "sides-default", NULL
, "two-sided-long-edge");
4619 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4620 "sides-default", NULL
, "one-sided");
4624 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4625 "sides-supported", NULL
, "one-sided");
4626 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4627 "sides-default", NULL
, "one-sided");
4630 if (ppdFindOption(ppd
, "Collate") != NULL
)
4631 p
->type
|= CUPS_PRINTER_COLLATE
;
4633 if (p
->pc
&& p
->pc
->finishings
)
4635 _pwg_finishings_t
*fin
; /* Current finishing value */
4637 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4639 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4640 finishings
[num_finishings
++] = fin
->value
;
4644 case IPP_FINISHINGS_BIND
:
4645 case IPP_FINISHINGS_BIND_LEFT
:
4646 case IPP_FINISHINGS_BIND_TOP
:
4647 case IPP_FINISHINGS_BIND_RIGHT
:
4648 case IPP_FINISHINGS_BIND_BOTTOM
:
4649 case IPP_FINISHINGS_EDGE_STITCH
:
4650 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4651 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4652 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4653 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4654 p
->type
|= CUPS_PRINTER_BIND
;
4657 case IPP_FINISHINGS_COVER
:
4658 p
->type
|= CUPS_PRINTER_COVER
;
4661 case IPP_FINISHINGS_PUNCH
:
4662 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4663 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4664 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4665 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4666 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4667 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4668 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4669 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4670 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4671 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4672 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4673 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4674 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4675 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4676 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4677 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4678 p
->type
|= CUPS_PRINTER_PUNCH
;
4681 case IPP_FINISHINGS_STAPLE
:
4682 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4683 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4684 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4685 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4686 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4687 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4688 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4689 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4690 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4691 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4692 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4693 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4694 p
->type
|= CUPS_PRINTER_STAPLE
;
4703 if (p
->pc
&& p
->pc
->templates
)
4705 const char *template; /* Finishing template */
4706 ipp_attribute_t
*fin_col_db
; /* finishings-col-database attribute */
4707 ipp_t
*fin_col
; /* finishings-col value */
4709 fin_col_db
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
, "finishings-col-database", cupsArrayCount(p
->pc
->templates
), NULL
);
4710 for (i
= 0, template = (const char *)cupsArrayFirst(p
->pc
->templates
); template; i
++, template = (const char *)cupsArrayNext(p
->pc
->templates
))
4713 ippAddString(fin_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "finishing-template", NULL
, template);
4714 ippSetCollection(p
->ppd_attrs
, &fin_col_db
, i
, fin_col
);
4719 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4720 if (ppd
->sizes
[i
].length
> 1728)
4721 p
->type
|= CUPS_PRINTER_LARGE
;
4722 else if (ppd
->sizes
[i
].length
> 1008)
4723 p
->type
|= CUPS_PRINTER_MEDIUM
;
4725 p
->type
|= CUPS_PRINTER_SMALL
;
4727 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4728 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4730 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4731 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4732 p
->type
|= CUPS_PRINTER_SCANNER
;
4734 p
->type
|= CUPS_PRINTER_MFP
;
4738 * Scan the filters in the PPD file...
4743 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4745 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4747 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4748 _cups_isspace(filter
[28]))
4750 p
->type
|= CUPS_PRINTER_COMMANDS
;
4756 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4758 char *commands
, /* Copy of commands */
4759 *start
, /* Start of name */
4760 *end
; /* End of name */
4761 int count
; /* Number of commands */
4763 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4765 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4767 while (_cups_isspace(*start
))
4773 while (*start
&& !isspace(*start
& 255))
4783 * Make a copy of the commands string and count how many commands there
4787 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4788 "printer-commands", count
, NULL
, NULL
);
4790 commands
= strdup(ppd_attr
->value
);
4792 for (count
= 0, start
= commands
; *start
; count
++)
4794 while (isspace(*start
& 255))
4801 while (*end
&& !isspace(*end
& 255))
4807 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4817 * Add the standard list of commands...
4820 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4822 (int)(sizeof(standard_commands
) /
4823 sizeof(standard_commands
[0])), NULL
,
4830 * No commands supported...
4833 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4834 "printer-commands", NULL
, "none");
4838 * Show current and available port monitors for this printer...
4841 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4842 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4844 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4846 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4850 if (strstr(ppd
->protocols
, "TBCP"))
4852 else if (strstr(ppd
->protocols
, "BCP"))
4856 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4857 "port-monitor-supported", i
, NULL
, NULL
);
4859 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4861 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4863 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4864 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4868 if (strstr(ppd
->protocols
, "TBCP"))
4869 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4870 else if (strstr(ppd
->protocols
, "BCP"))
4871 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4874 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4875 p
->type
|= CUPS_PRINTER_REMOTE
;
4877 #ifdef HAVE_APPLICATIONSERVICES_H
4879 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4880 * and save it as cacheDir/printername.png
4883 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4885 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4886 cupsdLogFCMessage
, p
))
4888 CGImageRef imageRef
= NULL
;/* Current icon image */
4889 CGImageRef biggestIconRef
= NULL
;
4890 /* Biggest icon image */
4891 CGImageRef closestTo128IconRef
= NULL
;
4892 /* Icon image closest to and >= 128 */
4893 CGImageSourceRef sourceRef
; /* The file's image source */
4894 char outPath
[HTTP_MAX_URI
];
4895 /* The path to the PNG file */
4896 CFURLRef outUrl
; /* The URL made from the outPath */
4897 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4898 CGImageDestinationRef destRef
; /* The image destination to write */
4899 size_t bytesPerRow
; /* The bytes per row used for resizing */
4900 CGContextRef context
; /* The CG context used for resizing */
4902 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4903 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4904 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4905 if (outUrl
&& icnsFileUrl
)
4907 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4910 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4912 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4916 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4919 * Loop through remembering the icon closest to 128 but >= 128
4920 * and then remember the largest icon.
4923 if (CGImageGetWidth(imageRef
) >= 128 &&
4924 (!closestTo128IconRef
||
4925 CGImageGetWidth(imageRef
) <
4926 CGImageGetWidth(closestTo128IconRef
)))
4928 CGImageRelease(closestTo128IconRef
);
4929 CGImageRetain(imageRef
);
4930 closestTo128IconRef
= imageRef
;
4933 if (!biggestIconRef
||
4934 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4936 CGImageRelease(biggestIconRef
);
4937 CGImageRetain(imageRef
);
4938 biggestIconRef
= imageRef
;
4942 CGImageRelease(imageRef
);
4948 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4949 * want the closest to 128, but if none are larger than 128, we want
4950 * the largest icon available.
4953 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4955 CGImageRetain(imageRef
);
4956 CGImageRelease(biggestIconRef
);
4957 if (closestTo128IconRef
)
4958 CGImageRelease(closestTo128IconRef
);
4959 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4963 if (CGImageGetWidth(imageRef
) != 128)
4965 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4966 CGImageGetWidth(imageRef
) * 128;
4967 context
= CGBitmapContextCreate(NULL
, 128, 128,
4968 CGImageGetBitsPerComponent(imageRef
),
4970 CGImageGetColorSpace(imageRef
),
4971 kCGImageAlphaPremultipliedFirst
);
4974 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4976 CGImageRelease(imageRef
);
4977 imageRef
= CGBitmapContextCreateImage(context
);
4978 CGContextRelease(context
);
4982 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4983 CGImageDestinationFinalize(destRef
);
4987 CGImageRelease(imageRef
);
4990 CFRelease(sourceRef
);
4998 CFRelease(icnsFileUrl
);
5000 #endif /* HAVE_APPLICATIONSERVICES_H */
5003 * Close the PPD and set the type...
5008 else if (!access(ppd_name
, 0))
5010 int pline
; /* PPD line number */
5011 ppd_status_t pstatus
; /* PPD load status */
5014 pstatus
= ppdLastError(&pline
);
5016 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
5018 if (pstatus
<= PPD_ALLOC_ERROR
)
5019 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
5021 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
5023 cupsdLogMessage(CUPSD_LOG_INFO
,
5024 "Hint: Run \"cupstestppd %s\" and fix any errors.",
5029 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
5030 !strncmp(p
->device_uri
, "ipps://", 7)) &&
5031 (strstr(p
->device_uri
, "/printers/") != NULL
||
5032 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
5033 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
5034 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
5035 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
5038 * Tell the client this is really a hard-wired remote printer.
5041 p
->type
|= CUPS_PRINTER_REMOTE
;
5044 * Then set the make-and-model accordingly...
5047 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5048 "printer-make-and-model", NULL
, "Remote Printer");
5051 * Print all files directly...
5060 * Otherwise we have neither - treat this as a "dumb" printer
5061 * with no PPD file...
5064 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5065 "printer-make-and-model", NULL
, "Local Raw Printer");
5071 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5072 "finishings-supported", num_finishings
, finishings
);
5073 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5074 "finishings-default", IPP_FINISHINGS_NONE
);
5079 * Save cached PPD attributes to disk...
5082 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5084 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5089 * Remove cache files...
5092 if (cache_info
.st_mtime
)
5099 * 'new_media_col()' - Create a media-col collection value.
5102 static ipp_t
* /* O - Collection value */
5103 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5104 const char *source
, /* I - media-source value */
5105 const char *type
) /* I - media-type value */
5107 ipp_t
*media_col
, /* Collection value */
5108 *media_size
; /* media-size value */
5111 media_col
= ippNew();
5113 media_size
= ippNew();
5114 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5115 "x-dimension", size
->width
);
5116 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5117 "y-dimension", size
->length
);
5118 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5119 ippDelete(media_size
);
5121 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5122 "media-bottom-margin", size
->bottom
);
5123 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5124 "media-left-margin", size
->left
);
5125 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5126 "media-right-margin", size
->right
);
5127 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5128 "media-top-margin", size
->top
);
5131 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5135 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5143 * 'write_xml_string()' - Write a string with XML escaping.
5147 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5148 const char *s
) /* I - String to write */
5150 const char *start
; /* Start of current sequence */
5156 for (start
= s
; *s
; s
++)
5161 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5163 cupsFilePuts(fp
, "&");
5169 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5171 cupsFilePuts(fp
, "<");
5177 cupsFilePuts(fp
, start
);