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 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
20 #ifdef HAVE_APPLICATIONSERVICES_H
21 # include <ApplicationServices/ApplicationServices.h>
22 #endif /* HAVE_APPLICATIONSERVICES_H */
23 #ifdef HAVE_SYS_MOUNT_H
24 # include <sys/mount.h>
25 #endif /* HAVE_SYS_MOUNT_H */
26 #ifdef HAVE_SYS_STATVFS_H
27 # include <sys/statvfs.h>
28 #elif defined(HAVE_SYS_STATFS_H)
29 # include <sys/statfs.h>
30 #endif /* HAVE_SYS_STATVFS_H */
33 #endif /* HAVE_SYS_VFS_H */
36 #endif /* __APPLE__ */
43 static void add_printer_defaults(cupsd_printer_t
*p
);
44 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
46 static void add_printer_formats(cupsd_printer_t
*p
);
47 static int compare_printers(void *first
, void *second
, void *data
);
48 static void delete_printer_filters(cupsd_printer_t
*p
);
49 static void dirty_printer(cupsd_printer_t
*p
);
50 static void load_ppd(cupsd_printer_t
*p
);
51 static ipp_t
*new_media_col(pwg_size_t
*size
, const char *source
,
53 static void write_xml_string(cups_file_t
*fp
, const char *s
);
57 * 'cupsdAddPrinter()' - Add a printer to the system.
60 cupsd_printer_t
* /* O - New printer */
61 cupsdAddPrinter(const char *name
) /* I - Name of printer */
63 cupsd_printer_t
*p
; /* New printer */
64 char uri
[1024], /* Printer URI */
65 uuid
[64]; /* Printer UUID */
69 * Range check input...
72 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
75 * Create a new printer entity...
78 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
80 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
85 _cupsRWInit(&p
->lock
);
87 cupsdSetString(&p
->name
, name
);
88 cupsdSetString(&p
->info
, name
);
89 cupsdSetString(&p
->hostname
, ServerName
);
91 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
92 ServerName
, RemotePort
, "/printers/%s", name
);
93 cupsdSetString(&p
->uri
, uri
);
94 cupsdSetString(&p
->uuid
, httpAssembleUUID(ServerName
, RemotePort
, name
, 0,
96 cupsdSetDeviceURI(p
, "file:///dev/null");
98 p
->config_time
= time(NULL
);
99 p
->state
= IPP_PRINTER_STOPPED
;
100 p
->state_time
= time(NULL
);
102 p
->shared
= DefaultShared
;
103 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
105 cupsdSetString(&p
->job_sheets
[0], "none");
106 cupsdSetString(&p
->job_sheets
[1], "none");
108 cupsdSetString(&p
->error_policy
, ErrorPolicy
);
109 cupsdSetString(&p
->op_policy
, DefaultPolicy
);
111 p
->op_policy_ptr
= DefaultPolicyPtr
;
114 * Insert the printer in the printer list alphabetically...
118 Printers
= cupsArrayNew(compare_printers
, NULL
);
120 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
121 "cupsdAddPrinter: Adding %s to Printers", p
->name
);
122 cupsArrayAdd(Printers
, p
);
125 * Return the new printer...
133 * 'cupsdCreateCommonData()' - Create the common printer data.
137 cupsdCreateCommonData(void)
139 int i
; /* Looping var */
140 ipp_attribute_t
*attr
; /* Attribute data */
141 cups_dir_t
*dir
; /* Notifier directory */
142 cups_dentry_t
*dent
; /* Notifier directory entry */
143 cups_array_t
*notifiers
; /* Notifier array */
144 char filename
[1024], /* Filename */
145 *notifier
; /* Current notifier */
146 cupsd_policy_t
*p
; /* Current policy */
147 int k_supported
; /* Maximum file size supported */
149 struct statvfs spoolinfo
; /* FS info for spool directory */
150 double spoolsize
; /* FS size */
151 #elif defined(HAVE_STATFS)
152 struct statfs spoolinfo
; /* FS info for spool directory */
153 double spoolsize
; /* FS size */
154 #endif /* HAVE_STATVFS */
155 static const int nups
[] = /* number-up-supported values */
156 { 1, 2, 4, 6, 9, 16 };
157 static const int orients
[4] =/* orientation-requested-supported values */
161 IPP_REVERSE_LANDSCAPE
,
164 static const char * const holds
[] = /* job-hold-until-supported values */
175 static const char * const features
[] =/* ipp-features-supported values */
177 "subscription-object"
179 static const char * const versions
[] =/* ipp-versions-supported values */
186 static const int ops
[] = /* operations-supported values */
191 IPP_OP_SEND_DOCUMENT
,
193 IPP_OP_GET_JOB_ATTRIBUTES
,
195 IPP_OP_GET_PRINTER_ATTRIBUTES
,
198 IPP_OP_PAUSE_PRINTER
,
199 IPP_OP_RESUME_PRINTER
,
201 IPP_OP_SET_PRINTER_ATTRIBUTES
,
202 IPP_OP_SET_JOB_ATTRIBUTES
,
203 IPP_OP_GET_PRINTER_SUPPORTED_VALUES
,
204 IPP_OP_CREATE_PRINTER_SUBSCRIPTIONS
,
205 IPP_OP_CREATE_JOB_SUBSCRIPTIONS
,
206 IPP_OP_GET_SUBSCRIPTION_ATTRIBUTES
,
207 IPP_OP_GET_SUBSCRIPTIONS
,
208 IPP_OP_RENEW_SUBSCRIPTION
,
209 IPP_OP_CANCEL_SUBSCRIPTION
,
210 IPP_OP_GET_NOTIFICATIONS
,
211 IPP_OP_ENABLE_PRINTER
,
212 IPP_OP_DISABLE_PRINTER
,
213 IPP_OP_HOLD_NEW_JOBS
,
214 IPP_OP_RELEASE_HELD_NEW_JOBS
,
216 IPP_OP_CANCEL_MY_JOBS
,
218 IPP_OP_CUPS_GET_DEFAULT
,
219 IPP_OP_CUPS_GET_PRINTERS
,
220 IPP_OP_CUPS_ADD_MODIFY_PRINTER
,
221 IPP_OP_CUPS_DELETE_PRINTER
,
222 IPP_OP_CUPS_GET_CLASSES
,
223 IPP_OP_CUPS_ADD_MODIFY_CLASS
,
224 IPP_OP_CUPS_DELETE_CLASS
,
225 IPP_OP_CUPS_ACCEPT_JOBS
,
226 IPP_OP_CUPS_REJECT_JOBS
,
227 IPP_OP_CUPS_SET_DEFAULT
,
228 IPP_OP_CUPS_GET_DEVICES
,
229 IPP_OP_CUPS_GET_PPDS
,
230 IPP_OP_CUPS_MOVE_JOB
,
231 IPP_OP_CUPS_AUTHENTICATE_JOB
,
233 IPP_OP_CUPS_GET_DOCUMENT
,
236 static const char * const charsets
[] =/* charset-supported values */
241 static const char * const compressions
[] =
242 { /* document-compression-supported values */
246 #endif /* HAVE_LIBZ */
248 static const char * const media_col_supported
[] =
249 { /* media-col-supported values */
250 "media-bottom-margin",
252 "media-right-margin",
258 static const char * const multiple_document_handling
[] =
259 { /* multiple-document-handling-supported values */
260 "separate-documents-uncollated-copies",
261 "separate-documents-collated-copies"
263 static const char * const notify_attrs
[] =
264 { /* notify-attributes-supported values */
265 "printer-state-change-time",
266 "notify-lease-expiration-time",
267 "notify-subscriber-user-name"
269 static const char * const notify_events
[] =
270 { /* notify-events-supported values */
272 "job-config-changed",
279 "printer-config-changed",
281 "printer-finishings-changed",
282 "printer-media-changed",
286 "printer-state-changed",
293 static const char * const job_creation
[] =
294 { /* job-creation-attributes-supported */
297 "ipp-attribute-fidelity",
304 "multiple-document-handling",
307 "orientation-requested",
311 "printer-resolution",
314 static const char * const job_settable
[] =
315 { /* job-settable-attributes-supported */
323 "multiple-document-handling",
326 "orientation-requested",
330 "printer-resolution",
333 static const char * const pdf_versions
[] =
334 { /* pdf-versions-supported */
345 static const char * const printer_settable
[] =
346 { /* printer-settable-attributes-supported */
347 "printer-geo-location",
350 "printer-organization",
351 "printer-organizational-unit"
353 static const char * const which_jobs
[] =
354 { /* which-jobs-supported values */
368 ippDelete(CommonData
);
370 CommonData
= ippNew();
373 * Get the maximum spool size based on the size of the filesystem used for
374 * the RequestRoot directory. If the host OS doesn't support the statfs call
375 * or the filesystem is larger than 2TiB, always report INT_MAX.
379 if (statvfs(RequestRoot
, &spoolinfo
))
380 k_supported
= INT_MAX
;
381 else if ((spoolsize
= (double)spoolinfo
.f_frsize
* spoolinfo
.f_blocks
/ 1024) >
383 k_supported
= INT_MAX
;
385 k_supported
= (int)spoolsize
;
387 #elif defined(HAVE_STATFS)
388 if (statfs(RequestRoot
, &spoolinfo
))
389 k_supported
= INT_MAX
;
390 else if ((spoolsize
= (double)spoolinfo
.f_bsize
* spoolinfo
.f_blocks
/ 1024) >
392 k_supported
= INT_MAX
;
394 k_supported
= (int)spoolsize
;
397 k_supported
= INT_MAX
;
398 #endif /* HAVE_STATVFS */
401 * This list of attributes is sorted to improve performance when the
402 * client provides a requested-attributes attribute...
405 /* charset-configured */
406 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
407 "charset-configured", NULL
, "utf-8");
409 /* charset-supported */
410 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_CHARSET
| IPP_TAG_COPY
,
411 "charset-supported", sizeof(charsets
) / sizeof(charsets
[0]),
414 /* compression-supported */
415 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
416 "compression-supported",
417 sizeof(compressions
) / sizeof(compressions
[0]),
420 /* copies-supported */
421 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "copies-supported", 1, MaxCopies
);
424 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
| IPP_TAG_COPY
,
425 "cups-version", NULL
, CUPS_SVERSION
+ 6);
427 /* generated-natural-language-supported (no IPP_TAG_COPY) */
428 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
429 "generated-natural-language-supported", NULL
, DefaultLanguage
);
431 /* ipp-features-supported */
432 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "ipp-features-supported", sizeof(features
) / sizeof(features
[0]), NULL
, features
);
434 /* ipp-versions-supported */
435 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
436 "ipp-versions-supported", sizeof(versions
) / sizeof(versions
[0]),
439 /* ippget-event-life */
440 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
441 "ippget-event-life", 15);
443 /* job-cancel-after-supported */
444 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-cancel-after-supported",
447 /* job-creation-attributes-supported */
448 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
449 "job-creation-attributes-supported",
450 sizeof(job_creation
) / sizeof(job_creation
[0]),
453 /* job-hold-until-supported */
454 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
455 "job-hold-until-supported", sizeof(holds
) / sizeof(holds
[0]),
458 /* job-ids-supported */
459 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "job-ids-supported", 1);
461 /* job-k-octets-supported */
462 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "job-k-octets-supported", 0,
465 /* job-priority-supported */
466 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
467 "job-priority-supported", 100);
469 /* job-settable-attributes-supported */
470 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
471 "job-settable-attributes-supported",
472 sizeof(job_settable
) / sizeof(job_settable
[0]),
475 /* job-sheets-supported */
476 if (cupsArrayCount(Banners
) > 0)
479 * Setup the job-sheets-supported attribute...
482 if (Classification
&& !ClassifyOverride
)
483 attr
= ippAddString(CommonData
, IPP_TAG_PRINTER
,
484 IPP_TAG_NAME
| IPP_TAG_COPY
,
485 "job-sheets-supported", NULL
, Classification
);
487 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
,
488 IPP_TAG_NAME
| IPP_TAG_COPY
,
489 "job-sheets-supported", cupsArrayCount(Banners
) + 1,
493 cupsdLogMessage(CUPSD_LOG_EMERG
,
494 "Unable to allocate memory for "
495 "job-sheets-supported attribute: %s!", strerror(errno
));
496 else if (!Classification
|| ClassifyOverride
)
498 cupsd_banner_t
*banner
; /* Current banner */
501 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
503 for (i
= 1, banner
= (cupsd_banner_t
*)cupsArrayFirst(Banners
);
505 i
++, banner
= (cupsd_banner_t
*)cupsArrayNext(Banners
))
506 attr
->values
[i
].string
.text
= banner
->name
;
510 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
511 "job-sheets-supported", NULL
, "none");
513 /* jpeg-k-octets-supported */
514 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-k-octets-supported", 0,
517 /* jpeg-x-dimension-supported */
518 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-x-dimension-supported", 0,
521 /* jpeg-y-dimension-supported */
522 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "jpeg-y-dimension-supported", 1,
525 /* media-col-supported */
526 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
527 "media-col-supported",
528 sizeof(media_col_supported
) /
529 sizeof(media_col_supported
[0]), NULL
,
530 media_col_supported
);
532 /* multiple-document-handling-supported */
533 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
534 "multiple-document-handling-supported",
535 sizeof(multiple_document_handling
) /
536 sizeof(multiple_document_handling
[0]), NULL
,
537 multiple_document_handling
);
539 /* multiple-document-jobs-supported */
540 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
,
541 "multiple-document-jobs-supported", 1);
543 /* multiple-operation-time-out */
544 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
545 "multiple-operation-time-out", MultipleOperationTimeout
);
547 /* multiple-operation-time-out-action */
548 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "multiple-operation-time-out-action", NULL
, "process-job");
550 /* natural-language-configured (no IPP_TAG_COPY) */
551 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_LANGUAGE
,
552 "natural-language-configured", NULL
, DefaultLanguage
);
554 /* notify-attributes-supported */
555 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
556 "notify-attributes-supported",
557 (int)(sizeof(notify_attrs
) / sizeof(notify_attrs
[0])),
560 /* notify-lease-duration-supported */
561 ippAddRange(CommonData
, IPP_TAG_PRINTER
,
562 "notify-lease-duration-supported", 0,
563 MaxLeaseDuration
? MaxLeaseDuration
: 2147483647);
565 /* notify-max-events-supported */
566 ippAddInteger(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
567 "notify-max-events-supported", MaxEvents
);
569 /* notify-events-supported */
570 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
571 "notify-events-supported",
572 (int)(sizeof(notify_events
) / sizeof(notify_events
[0])),
573 NULL
, notify_events
);
575 /* notify-pull-method-supported */
576 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
577 "notify-pull-method-supported", NULL
, "ippget");
579 /* notify-schemes-supported */
580 snprintf(filename
, sizeof(filename
), "%s/notifier", ServerBin
);
581 if ((dir
= cupsDirOpen(filename
)) != NULL
)
583 notifiers
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
585 while ((dent
= cupsDirRead(dir
)) != NULL
)
586 if (S_ISREG(dent
->fileinfo
.st_mode
) &&
587 (dent
->fileinfo
.st_mode
& S_IXOTH
) != 0)
588 cupsArrayAdd(notifiers
, _cupsStrAlloc(dent
->filename
));
590 if (cupsArrayCount(notifiers
) > 0)
592 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
593 "notify-schemes-supported",
594 cupsArrayCount(notifiers
), NULL
, NULL
);
596 for (i
= 0, notifier
= (char *)cupsArrayFirst(notifiers
);
598 i
++, notifier
= (char *)cupsArrayNext(notifiers
))
599 attr
->values
[i
].string
.text
= notifier
;
602 cupsArrayDelete(notifiers
);
606 /* number-up-supported */
607 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
608 "number-up-supported", sizeof(nups
) / sizeof(nups
[0]), nups
);
610 /* operations-supported */
611 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
612 "operations-supported", sizeof(ops
) / sizeof(ops
[0]), ops
);
614 /* orientation-requested-supported */
615 ippAddIntegers(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
616 "orientation-requested-supported", 4, orients
);
618 /* page-ranges-supported */
619 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "page-ranges-supported", 1);
621 /* pdf-k-octets-supported */
622 ippAddRange(CommonData
, IPP_TAG_PRINTER
, "pdf-k-octets-supported", 0,
625 /* pdf-versions-supported */
626 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
627 "pdf-versions-supported",
628 sizeof(pdf_versions
) / sizeof(pdf_versions
[0]), NULL
,
631 /* pdl-override-supported */
632 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
633 "pdl-override-supported", NULL
, "attempted");
635 /* printer-get-attributes-supported */
636 ippAddString(CommonData
, IPP_TAG_PRINTER
, IPP_CONST_TAG(IPP_TAG_KEYWORD
), "printer-get-attributes-supported", NULL
, "document-format");
638 /* printer-op-policy-supported */
639 attr
= ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_NAME
| IPP_TAG_COPY
,
640 "printer-op-policy-supported", cupsArrayCount(Policies
),
642 for (i
= 0, p
= (cupsd_policy_t
*)cupsArrayFirst(Policies
);
644 i
++, p
= (cupsd_policy_t
*)cupsArrayNext(Policies
))
645 attr
->values
[i
].string
.text
= p
->name
;
647 /* printer-settable-attributes-supported */
648 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
649 "printer-settable-attributes-supported",
650 sizeof(printer_settable
) / sizeof(printer_settable
[0]),
651 NULL
, printer_settable
);
653 /* server-is-sharing-printers */
654 ippAddBoolean(CommonData
, IPP_TAG_PRINTER
, "server-is-sharing-printers",
655 BrowseLocalProtocols
!= 0 && Browsing
);
657 /* which-jobs-supported */
658 ippAddStrings(CommonData
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
| IPP_TAG_COPY
,
659 "which-jobs-supported",
660 sizeof(which_jobs
) / sizeof(which_jobs
[0]), NULL
, which_jobs
);
665 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
669 cupsdDeleteAllPrinters(void)
671 cupsd_printer_t
*p
; /* Pointer to current printer/class */
674 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
676 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
678 p
->op_policy_ptr
= DefaultPolicyPtr
;
679 cupsdDeletePrinter(p
, 0);
685 * 'cupsdDeletePrinter()' - Delete a printer from the system.
688 int /* O - 1 if classes affected, 0 otherwise */
690 cupsd_printer_t
*p
, /* I - Printer to delete */
691 int update
) /* I - Update printers.conf? */
693 int i
, /* Looping var */
694 changed
= 0; /* Class changed? */
697 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeletePrinter(p=%p(%s), update=%d)",
701 * Save the current position in the Printers array...
704 cupsArraySave(Printers
);
707 * Stop printing on this printer...
710 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
712 p
->state
= IPP_PRINTER_STOPPED
; /* Force for browsed printers */
715 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_FORCE
,
716 update
? "Job stopped due to printer being deleted." :
720 * Remove the printer from the list...
723 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
724 "cupsdDeletePrinter: Removing %s from Printers", p
->name
);
725 cupsArrayRemove(Printers
, p
);
728 * If p is the default printer, assign a different one...
731 if (p
== DefaultPrinter
)
732 DefaultPrinter
= NULL
;
735 * Remove this printer from any classes...
738 changed
= cupsdDeletePrinterFromClasses(p
);
741 * Deregister from any browse protocols...
744 cupsdDeregisterPrinter(p
, 1);
747 * Remove support files if this is a temporary queue and deregister color
753 char filename
[1024]; /* Script/PPD filename */
756 * Remove any old PPD or script files...
759 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
761 snprintf(filename
, sizeof(filename
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
764 snprintf(filename
, sizeof(filename
), "%s/%s.png", CacheDir
, p
->name
);
767 snprintf(filename
, sizeof(filename
), "%s/%s.data", CacheDir
, p
->name
);
771 * Unregister color profiles...
774 cupsdUnregisterColor(p
);
778 * Free all memory used by the printer...
781 if (p
->printers
!= NULL
)
784 delete_printer_filters(p
);
786 for (i
= 0; i
< p
->num_reasons
; i
++)
787 _cupsStrFree(p
->reasons
[i
]);
790 ippDelete(p
->ppd_attrs
);
792 mimeDeleteType(MimeDatabase
, p
->filetype
);
793 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
795 cupsdFreeStrings(&(p
->users
));
798 cupsdClearString(&p
->uri
);
799 cupsdClearString(&p
->hostname
);
800 cupsdClearString(&p
->name
);
801 cupsdClearString(&p
->location
);
802 cupsdClearString(&p
->geo_location
);
803 cupsdClearString(&p
->make_model
);
804 cupsdClearString(&p
->info
);
805 cupsdClearString(&p
->job_sheets
[0]);
806 cupsdClearString(&p
->job_sheets
[1]);
807 cupsdClearString(&p
->device_uri
);
808 cupsdClearString(&p
->sanitized_device_uri
);
809 cupsdClearString(&p
->port_monitor
);
810 cupsdClearString(&p
->op_policy
);
811 cupsdClearString(&p
->error_policy
);
813 cupsdClearString(&p
->alert
);
814 cupsdClearString(&p
->alert_description
);
816 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
817 cupsdClearString(&p
->pdl
);
818 cupsdClearString(&p
->reg_name
);
819 #endif /* HAVE_DNSSD || HAVE_AVAHI */
821 cupsArrayDelete(p
->filetypes
);
823 cupsFreeOptions(p
->num_options
, p
->options
);
828 * Restore the previous position in the Printers array...
831 cupsArrayRestore(Printers
);
838 * 'cupsdDeleteTemporaryPrinters()' - Delete unneeded temporary printers.
842 cupsdDeleteTemporaryPrinters(int force
) /* I - Force deletion instead of auto? */
844 cupsd_printer_t
*p
; /* Current printer */
845 time_t unused_time
; /* Last time for printer state change */
849 * Allow temporary printers to stick around for 60 seconds after the last job
853 unused_time
= time(NULL
) - 60;
855 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
); p
; p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
857 if (p
->temporary
&& (force
|| p
->state_time
< unused_time
))
858 cupsdDeletePrinter(p
, 0);
864 * 'cupsdFindDest()' - Find a destination in the list.
867 cupsd_printer_t
* /* O - Destination in list */
868 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
870 cupsd_printer_t key
; /* Search key */
873 key
.name
= (char *)name
;
874 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
879 * 'cupsdFindPrinter()' - Find a printer in the list.
882 cupsd_printer_t
* /* O - Printer in list */
883 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
885 cupsd_printer_t
*p
; /* Printer in list */
888 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
896 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
900 cupsdLoadAllPrinters(void)
902 int i
; /* Looping var */
903 cups_file_t
*fp
; /* printers.conf file */
904 int linenum
; /* Current line number */
905 char line
[4096], /* Line from file */
906 *value
, /* Pointer to value */
907 *valueptr
; /* Pointer into value */
908 cupsd_printer_t
*p
; /* Current printer */
912 * Open the printers.conf file...
915 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
916 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
920 * Read printer configurations until we hit EOF...
926 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
929 * Decode the directive...
932 if (!_cups_strcasecmp(line
, "<Printer") ||
933 !_cups_strcasecmp(line
, "<DefaultPrinter"))
936 * <Printer name> or <DefaultPrinter name>
939 if (p
== NULL
&& value
)
942 * Add the printer and a base file type...
945 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
947 p
= cupsdAddPrinter(value
);
949 p
->state
= IPP_PRINTER_IDLE
;
952 * Set the default printer as needed...
955 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
959 cupsdLogMessage(CUPSD_LOG_ERROR
,
960 "Syntax error on line %d of printers.conf.", linenum
);
962 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
967 * Close out the current printer...
970 cupsdSetPrinterAttrs(p
);
972 if (strncmp(p
->device_uri
, "file:", 5) &&
973 p
->state
!= IPP_PRINTER_STOPPED
)
976 * See if the backend exists...
979 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
982 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
983 *valueptr
= '\0'; /* Chop everything but URI scheme */
988 * Backend does not exist, stop printer...
991 p
->state
= IPP_PRINTER_STOPPED
;
992 snprintf(p
->state_message
, sizeof(p
->state_message
),
993 "Backend %s does not exist!", line
);
1000 cupsdLogMessage(CUPSD_LOG_ERROR
,
1001 "Syntax error on line %d of printers.conf.", linenum
);
1005 cupsdLogMessage(CUPSD_LOG_ERROR
,
1006 "Syntax error on line %d of printers.conf.", linenum
);
1008 else if (!_cups_strcasecmp(line
, "UUID"))
1010 if (value
&& !strncmp(value
, "urn:uuid:", 9))
1011 cupsdSetString(&(p
->uuid
), value
);
1013 cupsdLogMessage(CUPSD_LOG_ERROR
,
1014 "Bad UUID on line %d of printers.conf.", linenum
);
1016 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
1018 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
1019 cupsdLogMessage(CUPSD_LOG_ERROR
,
1020 "Bad AuthInfoRequired on line %d of printers.conf.",
1023 else if (!_cups_strcasecmp(line
, "Info"))
1026 cupsdSetString(&p
->info
, value
);
1028 else if (!_cups_strcasecmp(line
, "MakeModel"))
1031 cupsdSetString(&p
->make_model
, value
);
1033 else if (!_cups_strcasecmp(line
, "Location"))
1036 cupsdSetString(&p
->location
, value
);
1038 else if (!_cups_strcasecmp(line
, "GeoLocation"))
1041 cupsdSetString(&p
->geo_location
, value
);
1043 else if (!_cups_strcasecmp(line
, "Organization"))
1046 cupsdSetString(&p
->organization
, value
);
1048 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
1051 cupsdSetString(&p
->organizational_unit
, value
);
1053 else if (!_cups_strcasecmp(line
, "DeviceURI"))
1056 cupsdSetDeviceURI(p
, value
);
1058 cupsdLogMessage(CUPSD_LOG_ERROR
,
1059 "Syntax error on line %d of printers.conf.", linenum
);
1061 else if (!_cups_strcasecmp(line
, "Option") && value
)
1067 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1070 cupsdLogMessage(CUPSD_LOG_ERROR
,
1071 "Syntax error on line %d of printers.conf.", linenum
);
1074 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1076 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1080 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1082 if (value
&& strcmp(value
, "none"))
1083 cupsdSetString(&p
->port_monitor
, value
);
1085 cupsdClearString(&p
->port_monitor
);
1087 cupsdLogMessage(CUPSD_LOG_ERROR
,
1088 "Syntax error on line %d of printers.conf.", linenum
);
1090 else if (!_cups_strcasecmp(line
, "Reason"))
1093 strcmp(value
, "connecting-to-device") &&
1094 strcmp(value
, "cups-insecure-filter-warning") &&
1095 strcmp(value
, "cups-missing-filter-warning"))
1097 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1098 if (!strcmp(value
, p
->reasons
[i
]))
1101 if (i
>= p
->num_reasons
&&
1102 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1104 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1109 cupsdLogMessage(CUPSD_LOG_ERROR
,
1110 "Syntax error on line %d of printers.conf.", linenum
);
1112 else if (!_cups_strcasecmp(line
, "State"))
1115 * Set the initial queue state...
1118 if (value
&& !_cups_strcasecmp(value
, "idle"))
1119 p
->state
= IPP_PRINTER_IDLE
;
1120 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1122 p
->state
= IPP_PRINTER_STOPPED
;
1124 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1125 if (!strcmp("paused", p
->reasons
[i
]))
1128 if (i
>= p
->num_reasons
&&
1129 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1131 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1136 cupsdLogMessage(CUPSD_LOG_ERROR
,
1137 "Syntax error on line %d of printers.conf.", linenum
);
1139 else if (!_cups_strcasecmp(line
, "StateMessage"))
1142 * Set the initial queue state message...
1146 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1148 else if (!_cups_strcasecmp(line
, "StateTime"))
1151 * Set the state time...
1155 p
->state_time
= atoi(value
);
1157 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1160 * Set the config time...
1164 p
->config_time
= atoi(value
);
1166 else if (!_cups_strcasecmp(line
, "Accepting"))
1169 * Set the initial accepting state...
1173 (!_cups_strcasecmp(value
, "yes") ||
1174 !_cups_strcasecmp(value
, "on") ||
1175 !_cups_strcasecmp(value
, "true")))
1178 (!_cups_strcasecmp(value
, "no") ||
1179 !_cups_strcasecmp(value
, "off") ||
1180 !_cups_strcasecmp(value
, "false")))
1183 cupsdLogMessage(CUPSD_LOG_ERROR
,
1184 "Syntax error on line %d of printers.conf.", linenum
);
1186 else if (!_cups_strcasecmp(line
, "Type"))
1189 p
->type
= (cups_ptype_t
)atoi(value
);
1191 cupsdLogMessage(CUPSD_LOG_ERROR
,
1192 "Syntax error on line %d of printers.conf.", linenum
);
1194 else if (!_cups_strcasecmp(line
, "Shared"))
1197 * Set the initial shared state...
1201 (!_cups_strcasecmp(value
, "yes") ||
1202 !_cups_strcasecmp(value
, "on") ||
1203 !_cups_strcasecmp(value
, "true")))
1206 (!_cups_strcasecmp(value
, "no") ||
1207 !_cups_strcasecmp(value
, "off") ||
1208 !_cups_strcasecmp(value
, "false")))
1211 cupsdLogMessage(CUPSD_LOG_ERROR
,
1212 "Syntax error on line %d of printers.conf.", linenum
);
1214 else if (!_cups_strcasecmp(line
, "JobSheets"))
1217 * Set the initial job sheets...
1222 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1227 cupsdSetString(&p
->job_sheets
[0], value
);
1229 while (isspace(*valueptr
& 255))
1234 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1239 cupsdSetString(&p
->job_sheets
[1], value
);
1243 cupsdLogMessage(CUPSD_LOG_ERROR
,
1244 "Syntax error on line %d of printers.conf.", linenum
);
1246 else if (!_cups_strcasecmp(line
, "AllowUser"))
1251 cupsdAddString(&(p
->users
), value
);
1254 cupsdLogMessage(CUPSD_LOG_ERROR
,
1255 "Syntax error on line %d of printers.conf.", linenum
);
1257 else if (!_cups_strcasecmp(line
, "DenyUser"))
1262 cupsdAddString(&(p
->users
), value
);
1265 cupsdLogMessage(CUPSD_LOG_ERROR
,
1266 "Syntax error on line %d of printers.conf.", linenum
);
1268 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1271 p
->quota_period
= atoi(value
);
1273 cupsdLogMessage(CUPSD_LOG_ERROR
,
1274 "Syntax error on line %d of printers.conf.", linenum
);
1276 else if (!_cups_strcasecmp(line
, "PageLimit"))
1279 p
->page_limit
= atoi(value
);
1281 cupsdLogMessage(CUPSD_LOG_ERROR
,
1282 "Syntax error on line %d of printers.conf.", linenum
);
1284 else if (!_cups_strcasecmp(line
, "KLimit"))
1287 p
->k_limit
= atoi(value
);
1289 cupsdLogMessage(CUPSD_LOG_ERROR
,
1290 "Syntax error on line %d of printers.conf.", linenum
);
1292 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1296 cupsd_policy_t
*pol
; /* Policy */
1299 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1301 cupsdSetString(&p
->op_policy
, value
);
1302 p
->op_policy_ptr
= pol
;
1305 cupsdLogMessage(CUPSD_LOG_ERROR
,
1306 "Bad policy \"%s\" on line %d of printers.conf",
1310 cupsdLogMessage(CUPSD_LOG_ERROR
,
1311 "Syntax error on line %d of printers.conf.", linenum
);
1313 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1317 if (strcmp(value
, "retry-current-job") &&
1318 strcmp(value
, "abort-job") &&
1319 strcmp(value
, "retry-job") &&
1320 strcmp(value
, "stop-printer"))
1321 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1323 cupsdSetString(&p
->error_policy
, value
);
1326 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1328 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1330 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1333 cupsdLogMessage(CUPSD_LOG_ERROR
,
1334 "Syntax error on line %d of printers.conf.", linenum
);
1337 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1340 cupsdSetPrinterAttrs(p
);
1342 if (!strcmp(value
, "marker-change-time"))
1343 p
->marker_time
= atoi(valueptr
);
1345 cupsdSetPrinterAttr(p
, value
, valueptr
);
1348 else if (_cups_strcasecmp(line
, "Filter") &&
1349 _cups_strcasecmp(line
, "Prefilter") &&
1350 _cups_strcasecmp(line
, "Product"))
1353 * Something else we don't understand (and that wasn't used in a prior
1354 * release of CUPS...
1357 cupsdLogMessage(CUPSD_LOG_ERROR
,
1358 "Unknown configuration directive %s on line %d of "
1359 "printers.conf.", line
, linenum
);
1368 * 'cupsdRenamePrinter()' - Rename a printer.
1373 cupsd_printer_t
*p
, /* I - Printer */
1374 const char *name
) /* I - New name */
1377 * Remove the printer from the array(s) first...
1380 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1381 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1382 cupsArrayRemove(Printers
, p
);
1385 * Rename the printer type...
1388 mimeDeleteType(MimeDatabase
, p
->filetype
);
1389 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1391 if (p
->prefiltertype
)
1393 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1394 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1398 * Rename the printer...
1401 cupsdSetString(&p
->name
, name
);
1404 * Reset printer attributes...
1407 cupsdSetPrinterAttrs(p
);
1410 * Add the printer back to the printer array(s)...
1413 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1414 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1415 cupsArrayAdd(Printers
, p
);
1420 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1425 cupsdSaveAllPrinters(void)
1427 int i
; /* Looping var */
1428 cups_file_t
*fp
; /* printers.conf file */
1429 char filename
[1024], /* printers.conf filename */
1430 temp
[1024], /* Temporary string */
1431 value
[2048], /* Value string */
1432 *ptr
, /* Pointer into value */
1433 *name
; /* Current user/group name */
1434 cupsd_printer_t
*printer
; /* Current printer class */
1435 time_t curtime
; /* Current time */
1436 struct tm
*curdate
; /* Current date */
1437 cups_option_t
*option
; /* Current option */
1438 ipp_attribute_t
*marker
; /* Current marker attribute */
1442 * Create the printers.conf file...
1445 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1447 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1450 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1453 * Write a small header to the file...
1456 curtime
= time(NULL
);
1457 curdate
= localtime(&curtime
);
1458 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1460 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1461 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1462 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1465 * Write each local printer known to the system...
1468 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1470 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1473 * Skip printer classes and temporary queues...
1476 if ((printer
->type
& CUPS_PRINTER_CLASS
) || printer
->temporary
)
1480 * Write printers as needed...
1483 if (printer
== DefaultPrinter
)
1484 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1486 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1488 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1490 if (printer
->num_auth_info_required
> 0)
1492 switch (printer
->num_auth_info_required
)
1495 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1499 snprintf(value
, sizeof(value
), "%s,%s",
1500 printer
->auth_info_required
[0],
1501 printer
->auth_info_required
[1]);
1506 snprintf(value
, sizeof(value
), "%s,%s,%s",
1507 printer
->auth_info_required
[0],
1508 printer
->auth_info_required
[1],
1509 printer
->auth_info_required
[2]);
1513 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1517 cupsFilePutConf(fp
, "Info", printer
->info
);
1519 if (printer
->location
)
1520 cupsFilePutConf(fp
, "Location", printer
->location
);
1522 if (printer
->geo_location
)
1523 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1525 if (printer
->make_model
)
1526 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1528 if (printer
->organization
)
1529 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1531 if (printer
->organizational_unit
)
1532 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1534 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1536 if (printer
->port_monitor
)
1537 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1539 if (printer
->state
== IPP_PRINTER_STOPPED
)
1541 cupsFilePuts(fp
, "State Stopped\n");
1543 if (printer
->state_message
[0])
1544 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1547 cupsFilePuts(fp
, "State Idle\n");
1549 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1550 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1552 for (i
= 0; i
< printer
->num_reasons
; i
++)
1553 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1554 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1555 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1556 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1558 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1560 if (printer
->accepting
)
1561 cupsFilePuts(fp
, "Accepting Yes\n");
1563 cupsFilePuts(fp
, "Accepting No\n");
1565 if (printer
->shared
)
1566 cupsFilePuts(fp
, "Shared Yes\n");
1568 cupsFilePuts(fp
, "Shared No\n");
1570 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1571 printer
->job_sheets
[1]);
1572 cupsFilePutConf(fp
, "JobSheets", value
);
1574 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1575 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1576 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1578 for (name
= (char *)cupsArrayFirst(printer
->users
);
1580 name
= (char *)cupsArrayNext(printer
->users
))
1581 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1583 if (printer
->op_policy
)
1584 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1585 if (printer
->error_policy
)
1586 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1588 for (i
= printer
->num_options
, option
= printer
->options
;
1592 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1593 cupsFilePutConf(fp
, "Option", value
);
1596 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1597 IPP_TAG_NAME
)) != NULL
)
1599 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1601 for (i
= 0, ptr
= value
+ strlen(value
);
1602 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1608 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1613 cupsFilePutConf(fp
, "Attribute", value
);
1616 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1617 IPP_TAG_INTEGER
)) != NULL
)
1619 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1620 marker
->values
[0].integer
);
1621 for (i
= 1; i
< marker
->num_values
; i
++)
1622 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1623 cupsFilePuts(fp
, "\n");
1626 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1627 IPP_TAG_INTEGER
)) != NULL
)
1629 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1630 marker
->values
[0].integer
);
1631 for (i
= 1; i
< marker
->num_values
; i
++)
1632 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1633 cupsFilePuts(fp
, "\n");
1636 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1637 IPP_TAG_INTEGER
)) != NULL
)
1639 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1640 marker
->values
[0].integer
);
1641 for (i
= 1; i
< marker
->num_values
; i
++)
1642 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1643 cupsFilePuts(fp
, "\n");
1646 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1647 IPP_TAG_TEXT
)) != NULL
)
1649 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1650 marker
->values
[0].string
.text
);
1652 cupsFilePutConf(fp
, "Attribute", value
);
1655 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1656 IPP_TAG_NAME
)) != NULL
)
1658 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1660 for (i
= 0, ptr
= value
+ strlen(value
);
1661 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1667 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1672 cupsFilePutConf(fp
, "Attribute", value
);
1675 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1676 IPP_TAG_KEYWORD
)) != NULL
)
1678 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1680 for (i
= 0, ptr
= value
+ strlen(value
);
1681 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1687 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1692 cupsFilePutConf(fp
, "Attribute", value
);
1695 if (printer
->marker_time
)
1696 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1697 (long)printer
->marker_time
);
1699 if (printer
== DefaultPrinter
)
1700 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1702 cupsFilePuts(fp
, "</Printer>\n");
1705 cupsdCloseCreatedConfFile(fp
, filename
);
1710 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1713 int /* O - 1 if value OK, 0 otherwise */
1714 cupsdSetAuthInfoRequired(
1715 cupsd_printer_t
*p
, /* I - Printer */
1716 const char *values
, /* I - Plain text value (or NULL) */
1717 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1719 int i
; /* Looping var */
1722 p
->num_auth_info_required
= 0;
1725 * Do we have a plain text value?
1731 * Yes, grab the keywords...
1734 const char *end
; /* End of current value */
1737 while (*values
&& p
->num_auth_info_required
< 4)
1739 if ((end
= strchr(values
, ',')) == NULL
)
1740 end
= values
+ strlen(values
);
1742 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1744 if (p
->num_auth_info_required
!= 0 || *end
)
1747 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1748 p
->num_auth_info_required
++;
1752 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1754 if (p
->num_auth_info_required
!= 0 || *end
)
1757 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1758 p
->num_auth_info_required
++;
1761 * Don't allow sharing of queues that require Kerberos authentication.
1766 cupsdDeregisterPrinter(p
, 1);
1770 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1772 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1773 p
->num_auth_info_required
++;
1775 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1777 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1778 p
->num_auth_info_required
++;
1780 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1782 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1783 p
->num_auth_info_required
++;
1788 values
= (*end
) ? end
+ 1 : end
;
1791 if (p
->num_auth_info_required
== 0)
1793 p
->auth_info_required
[0] = "none";
1794 p
->num_auth_info_required
= 1;
1798 * Update the printer-type value as needed...
1801 if (p
->num_auth_info_required
> 1 ||
1802 strcmp(p
->auth_info_required
[0], "none"))
1803 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1805 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1811 * Grab values from an attribute instead...
1814 if (!attr
|| attr
->num_values
> 4)
1817 for (i
= 0; i
< attr
->num_values
; i
++)
1819 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1821 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1824 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1825 p
->num_auth_info_required
++;
1829 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1831 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1834 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1835 p
->num_auth_info_required
++;
1838 * Don't allow sharing of queues that require Kerberos authentication.
1843 cupsdDeregisterPrinter(p
, 1);
1849 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1851 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1852 p
->num_auth_info_required
++;
1854 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1856 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1857 p
->num_auth_info_required
++;
1859 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1861 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1862 p
->num_auth_info_required
++;
1873 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1877 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1878 const char *uri
) /* I - Device URI */
1880 char buffer
[1024], /* URI buffer */
1881 *start
, /* Start of data after scheme */
1882 *slash
, /* First slash after scheme:// */
1883 *ptr
; /* Pointer into user@host:port part */
1887 * Set the full device URI..
1890 cupsdSetString(&(p
->device_uri
), uri
);
1893 * Copy the device URI to a temporary buffer so we can sanitize any auth
1897 strlcpy(buffer
, uri
, sizeof(buffer
));
1900 * Find the end of the scheme:// part...
1903 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1905 for (start
= ptr
+ 1; *start
; start
++)
1910 * Find the next slash (/) in the URI...
1913 if ((slash
= strchr(start
, '/')) == NULL
)
1914 slash
= start
+ strlen(start
); /* No slash, point to the end */
1917 * Check for an @ sign before the slash...
1920 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1923 * Found an @ sign and it is before the resource part, so we have
1924 * an authentication string. Copy the remaining URI over the
1925 * authentication string...
1928 _cups_strcpy(start
, ptr
+ 1);
1933 * Save the sanitized URI...
1936 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1941 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1945 cupsdSetPrinterAttr(
1946 cupsd_printer_t
*p
, /* I - Printer */
1947 const char *name
, /* I - Attribute name */
1948 const char *value
) /* I - Attribute value string */
1950 ipp_attribute_t
*attr
; /* Attribute */
1951 int i
, /* Looping var */
1952 count
; /* Number of values */
1953 char *temp
, /* Temporary copy of value string */
1954 *ptr
, /* Pointer into value */
1955 *start
, /* Start of value */
1956 quote
; /* Quote character */
1957 ipp_tag_t value_tag
; /* Value tag for this attribute */
1961 * Don't allow empty values...
1964 if (!*value
&& strcmp(name
, "marker-message"))
1966 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1971 * Copy the value string so we can do what we want with it...
1974 if ((temp
= strdup(value
)) == NULL
)
1976 cupsdLogMessage(CUPSD_LOG_ERROR
,
1977 "Unable to duplicate value for \"%s\" attribute.", name
);
1982 * Count the number of values...
1985 for (count
= 1, quote
= '\0', ptr
= temp
;
1993 else if (*ptr
== '\\' && ptr
[1])
1995 else if (*ptr
== '\'' || *ptr
== '\"')
1997 else if (*ptr
== ',')
2002 * Then add or update the attribute as needed...
2005 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
2006 !strcmp(name
, "marker-high-levels"))
2012 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
2013 attr
->num_values
< count
)
2015 ippDeleteAttribute(p
->attrs
, attr
);
2020 attr
->num_values
= count
;
2022 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
2028 cupsdLogMessage(CUPSD_LOG_ERROR
,
2029 "Unable to allocate memory for printer attribute "
2030 "(%d values)", count
);
2034 for (i
= 0, start
= temp
; i
< count
; i
++)
2036 if ((ptr
= strchr(start
, ',')) != NULL
)
2039 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
2048 * Name or keyword values...
2051 if (!strcmp(name
, "marker-types"))
2052 value_tag
= IPP_TAG_KEYWORD
;
2053 else if (!strcmp(name
, "marker-message"))
2054 value_tag
= IPP_TAG_TEXT
;
2056 value_tag
= IPP_TAG_NAME
;
2058 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2059 attr
->num_values
< count
)
2061 ippDeleteAttribute(p
->attrs
, attr
);
2067 for (i
= 0; i
< attr
->num_values
; i
++)
2068 _cupsStrFree(attr
->values
[i
].string
.text
);
2070 attr
->num_values
= count
;
2073 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2079 cupsdLogMessage(CUPSD_LOG_ERROR
,
2080 "Unable to allocate memory for printer attribute "
2081 "(%d values)", count
);
2085 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2087 for (start
= ptr
; *ptr
; ptr
++)
2090 *ptr
= quote
= '\0';
2093 else if (*ptr
== '\\' && ptr
[1])
2094 _cups_strcpy(ptr
, ptr
+ 1);
2095 else if (*ptr
== '\'' || *ptr
== '\"')
2102 _cups_strcpy(ptr
, ptr
+ 1);
2104 else if (*ptr
== ',')
2111 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2118 * Update the printer-supply and printer-supply-description, as needed...
2121 if (!strcmp(name
, "marker-names"))
2123 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2124 /* printer-supply-description attribute */
2126 if (supply_desc
!= NULL
)
2127 ippDeleteAttribute(p
->attrs
, supply_desc
);
2129 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2130 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2131 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2133 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2135 char buffer
[256], /* printer-supply values */
2136 pstype
[64], /* printer-supply type value */
2137 *psptr
; /* Pointer into type */
2138 const char *color
, /* marker-colors value */
2139 *type
; /* marker-types value */
2140 int level
; /* marker-levels value */
2141 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2142 /* marker-colors attribute */
2143 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2144 /* marker-levels attribute */
2145 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2146 /* marker-types attribute */
2147 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2148 /* printer-supply attribute */
2152 ippDeleteAttribute(p
->attrs
, supply
);
2156 if (!colors
|| !levels
|| !types
)
2159 count
= ippGetCount(colors
);
2160 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2163 for (i
= 0; i
< count
; i
++)
2165 color
= ippGetString(colors
, i
, NULL
);
2166 level
= ippGetInteger(levels
, i
);
2167 type
= ippGetString(types
, i
, NULL
);
2169 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2173 *psptr
++ = (char)toupper(*type
& 255);
2179 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
);
2182 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2184 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2191 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2195 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2197 int i
; /* Looping var */
2198 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2199 cupsd_location_t
*auth
; /* Pointer to authentication element */
2200 const char *auth_supported
; /* Authentication supported */
2201 ipp_t
*oldattrs
; /* Old printer attributes */
2202 ipp_attribute_t
*attr
; /* Attribute data */
2203 char *name
, /* Current user/group name */
2204 *filter
; /* Current filter */
2207 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2211 * Make sure that we have the common attributes defined...
2215 cupsdCreateCommonData();
2217 _cupsRWLockWrite(&p
->lock
);
2220 * Clear out old filters, if any...
2223 delete_printer_filters(p
);
2226 * Figure out the authentication that is required for the printer.
2229 auth_supported
= "requesting-user-name";
2231 if (p
->type
& CUPS_PRINTER_CLASS
)
2232 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2234 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2236 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2237 auth
->type
== CUPSD_AUTH_NONE
)
2238 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2242 int auth_type
; /* Authentication type */
2245 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2246 auth_type
= cupsdDefaultAuthType();
2248 if (auth_type
== CUPSD_AUTH_BASIC
)
2249 auth_supported
= "basic";
2251 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2252 auth_supported
= "negotiate";
2253 #endif /* HAVE_GSSAPI */
2255 if (auth_type
!= CUPSD_AUTH_NONE
)
2256 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2258 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2261 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2264 * Create the required IPP attributes for a printer...
2267 oldattrs
= p
->attrs
;
2268 p
->attrs
= ippNew();
2270 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2271 "uri-authentication-supported", NULL
, auth_supported
);
2272 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2273 "uri-security-supported", NULL
, "none");
2274 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2276 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2277 NULL
, p
->location
? p
->location
: "");
2278 if (p
->geo_location
)
2279 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2281 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2282 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2283 NULL
, p
->info
? p
->info
: "");
2284 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2285 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2286 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2288 if (cupsArrayCount(p
->users
) > 0)
2291 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2292 "requesting-user-name-denied",
2293 cupsArrayCount(p
->users
), NULL
, NULL
);
2295 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2296 "requesting-user-name-allowed",
2297 cupsArrayCount(p
->users
), NULL
, NULL
);
2299 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2301 i
++, name
= (char *)cupsArrayNext(p
->users
))
2302 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2305 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2306 "job-quota-period", p
->quota_period
);
2307 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2308 "job-k-limit", p
->k_limit
);
2309 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2310 "job-page-limit", p
->page_limit
);
2311 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2312 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2313 "auth-info-required", p
->num_auth_info_required
, NULL
,
2314 p
->auth_info_required
);
2316 if (cupsArrayCount(Banners
) > 0)
2319 * Setup the job-sheets-default attribute...
2322 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2323 "job-sheets-default", 2, NULL
, NULL
);
2327 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2328 Classification
: p
->job_sheets
[0]);
2329 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2330 Classification
: p
->job_sheets
[1]);
2338 * Assign additional attributes depending on whether this is a printer
2342 if (p
->type
& CUPS_PRINTER_CLASS
)
2345 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2348 * Add class-specific attributes...
2351 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2352 "printer-make-and-model", NULL
, "Local Printer Class");
2353 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2354 "file:///dev/null");
2356 if (p
->num_printers
> 0)
2359 * Add a list of member names; URIs are added in copy_printer_attrs...
2362 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2363 "member-names", p
->num_printers
, NULL
, NULL
);
2364 p
->type
|= CUPS_PRINTER_OPTIONS
;
2366 for (i
= 0; i
< p
->num_printers
; i
++)
2369 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2371 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2378 * Add printer-specific attributes...
2381 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2382 p
->sanitized_device_uri
);
2385 * Assign additional attributes from the PPD file (if any)...
2391 * Add filters for printer...
2394 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2395 "cups-insecure-filter-warning");
2397 if (p
->pc
&& p
->pc
->filters
)
2399 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2401 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2402 add_printer_filter(p
, p
->filetype
, filter
);
2404 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2407 * Add a filter from application/vnd.cups-raw to printer/name to
2408 * handle "raw" printing by users.
2411 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2414 * Add a PostScript filter, since this is still possibly PS printer.
2417 add_printer_filter(p
, p
->filetype
,
2418 "application/vnd.cups-postscript 0 -");
2421 if (p
->pc
&& p
->pc
->prefilters
)
2423 if (!p
->prefiltertype
)
2424 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2426 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2428 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2429 add_printer_filter(p
, p
->prefiltertype
, filter
);
2434 * Copy marker attributes as needed...
2439 ipp_attribute_t
*oldattr
; /* Old attribute */
2442 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2443 IPP_TAG_NAME
)) != NULL
)
2445 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2446 "marker-colors", oldattr
->num_values
, NULL
,
2449 for (i
= 0; i
< oldattr
->num_values
; i
++)
2450 attr
->values
[i
].string
.text
=
2451 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2455 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2456 IPP_TAG_INTEGER
)) != NULL
)
2458 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2459 "marker-levels", oldattr
->num_values
,
2462 for (i
= 0; i
< oldattr
->num_values
; i
++)
2463 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2467 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2468 IPP_TAG_TEXT
)) != NULL
)
2469 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2470 NULL
, oldattr
->values
[0].string
.text
);
2472 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2473 IPP_TAG_INTEGER
)) != NULL
)
2475 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2476 "marker-low-levels", oldattr
->num_values
,
2479 for (i
= 0; i
< oldattr
->num_values
; i
++)
2480 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2484 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2485 IPP_TAG_INTEGER
)) != NULL
)
2487 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2488 "marker-high-levels", oldattr
->num_values
,
2491 for (i
= 0; i
< oldattr
->num_values
; i
++)
2492 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2496 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2497 IPP_TAG_NAME
)) != NULL
)
2499 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2500 "marker-names", oldattr
->num_values
, NULL
,
2503 for (i
= 0; i
< oldattr
->num_values
; i
++)
2504 attr
->values
[i
].string
.text
=
2505 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2509 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2510 IPP_TAG_KEYWORD
)) != NULL
)
2512 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2513 "marker-types", oldattr
->num_values
, NULL
,
2516 for (i
= 0; i
< oldattr
->num_values
; i
++)
2517 attr
->values
[i
].string
.text
=
2518 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2522 ippDelete(oldattrs
);
2526 * Force sharing off for remote queues...
2529 if (p
->type
& CUPS_PRINTER_REMOTE
)
2533 * Populate the document-format-supported attribute...
2536 add_printer_formats(p
);
2538 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2542 * Add name-default attributes...
2545 add_printer_defaults(p
);
2547 _cupsRWUnlock(&p
->lock
);
2550 * Let the browse protocols reflect the change
2553 cupsdRegisterPrinter(p
);
2558 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2561 int /* O - 1 if something changed, 0 otherwise */
2562 cupsdSetPrinterReasons(
2563 cupsd_printer_t
*p
, /* I - Printer */
2564 const char *s
) /* I - Reasons strings */
2566 int i
, /* Looping var */
2567 changed
= 0; /* Did something change? */
2568 const char *sptr
; /* Pointer into reasons */
2569 char reason
[255], /* Reason string */
2570 *rptr
; /* Pointer into reason */
2573 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2574 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2576 if (s
[0] == '-' || s
[0] == '+')
2579 * Add/remove reasons...
2587 * Replace reasons...
2592 for (i
= 0; i
< p
->num_reasons
; i
++)
2593 _cupsStrFree(p
->reasons
[i
]);
2601 if (!strcmp(s
, "none"))
2605 * Loop through all of the reasons...
2611 * Skip leading whitespace and commas...
2614 while (isspace(*sptr
& 255) || *sptr
== ',')
2617 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2618 if (rptr
< (reason
+ sizeof(reason
) - 1))
2632 for (i
= 0; i
< p
->num_reasons
; i
++)
2633 if (!strcmp(reason
, p
->reasons
[i
]))
2636 * Found a match, so remove it...
2641 _cupsStrFree(p
->reasons
[i
]);
2643 if (i
< p
->num_reasons
)
2644 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2646 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2647 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2649 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2650 p
->job
->completed
= 0;
2652 if (strcmp(reason
, "connecting-to-device"))
2658 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2664 for (i
= 0; i
< p
->num_reasons
; i
++)
2665 if (!strcmp(reason
, p
->reasons
[i
]))
2668 if (i
>= p
->num_reasons
)
2670 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2672 cupsdLogMessage(CUPSD_LOG_ALERT
,
2673 "Too many printer-state-reasons values for %s (%d)",
2678 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2682 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2683 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2685 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2686 p
->job
->completed
= 1;
2688 if (strcmp(reason
, "connecting-to-device"))
2699 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2703 cupsdSetPrinterState(
2704 cupsd_printer_t
*p
, /* I - Printer to change */
2705 ipp_pstate_t s
, /* I - New state */
2706 int update
) /* I - Update printers.conf? */
2708 cupsd_job_t
*job
; /* Current job */
2709 ipp_pstate_t old_state
; /* Old printer state */
2710 static const char * const printer_states
[] =
2711 { /* State strings */
2719 * Set the new state...
2722 old_state
= p
->state
;
2727 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2728 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2729 "%s \"%s\" state changed to %s.",
2730 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2731 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2734 * Let the browse code know this needs to be updated...
2737 p
->state_time
= time(NULL
);
2741 * Set/clear the paused reason as needed...
2744 if (s
== IPP_PRINTER_STOPPED
)
2745 cupsdSetPrinterReasons(p
, "+paused");
2747 cupsdSetPrinterReasons(p
, "-paused");
2751 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2753 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2754 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2755 !_cups_strcasecmp(job
->dest
, p
->name
))
2756 ippSetString(job
->attrs
, &job
->reasons
, 0,
2757 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2761 * Clear the message for the queue when going to processing...
2764 if (s
== IPP_PRINTER_PROCESSING
)
2765 p
->state_message
[0] = '\0';
2768 * Let the browse protocols reflect the change...
2772 cupsdRegisterPrinter(p
);
2775 * Save the printer configuration if a printer goes from idle or processing
2776 * to stopped (or visa-versa)...
2780 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2786 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2790 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2791 int update
)/* I - Update printers.conf? */
2794 * Set the printer state...
2797 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2800 * See if we have a job printing on this printer...
2803 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2804 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2805 "Job stopped due to printer being paused.");
2810 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2813 int /* O - 1 if successful, 0 otherwise */
2814 cupsdUpdatePrinterPPD(
2815 cupsd_printer_t
*p
, /* I - Printer */
2816 int num_keywords
, /* I - Number of keywords */
2817 cups_option_t
*keywords
) /* I - Keywords */
2819 int i
; /* Looping var */
2820 cups_file_t
*src
, /* Original file */
2821 *dst
; /* New file */
2822 char srcfile
[1024], /* Original filename */
2823 dstfile
[1024], /* New filename */
2824 line
[1024], /* Line from file */
2825 keystring
[41]; /* Keyword from line */
2826 cups_option_t
*keyword
; /* Current keyword */
2829 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2833 * Get the old and new PPD filenames...
2836 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2837 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2840 * Rename the old file and open the old and new...
2843 if (rename(dstfile
, srcfile
))
2845 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2846 p
->name
, strerror(errno
));
2850 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2852 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2853 srcfile
, strerror(errno
));
2854 rename(srcfile
, dstfile
);
2858 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2860 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2861 dstfile
, strerror(errno
));
2863 rename(srcfile
, dstfile
);
2868 * Copy the first line and then write out all of the keywords...
2871 if (!cupsFileGets(src
, line
, sizeof(line
)))
2873 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2874 srcfile
, strerror(errno
));
2877 rename(srcfile
, dstfile
);
2881 cupsFilePrintf(dst
, "%s\n", line
);
2883 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2885 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2886 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2890 * Then copy the rest of the PPD file, dropping any keywords we changed.
2893 while (cupsFileGets(src
, line
, sizeof(line
)))
2896 * Skip keywords we've already set...
2899 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2900 cupsGetOption(keystring
, num_keywords
, keywords
))
2904 * Otherwise write the line...
2907 cupsFilePrintf(dst
, "%s\n", line
);
2911 * Close files and return...
2922 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2926 cupsdUpdatePrinters(void)
2928 cupsd_printer_t
*p
; /* Current printer */
2932 * Loop through the printers and recreate the printer attributes
2933 * for any local printers since the policy and/or access control
2934 * stuff may have changed. Also, if browsing is disabled, remove
2935 * any remote printers...
2938 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2940 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2943 * Update the operation policy pointer...
2946 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2947 p
->op_policy_ptr
= DefaultPolicyPtr
;
2950 * Update printer attributes...
2953 cupsdSetPrinterAttrs(p
);
2959 * 'cupsdValidateDest()' - Validate a printer/class destination.
2962 const char * /* O - Printer or class name */
2964 const char *uri
, /* I - Printer URI */
2965 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2966 cupsd_printer_t
**printer
) /* O - Printer pointer */
2968 cupsd_printer_t
*p
; /* Current printer */
2969 char localname
[1024],/* Localized hostname */
2970 *lptr
, /* Pointer into localized hostname */
2971 *sptr
, /* Pointer into server name */
2972 *rptr
, /* Pointer into resource */
2973 scheme
[32], /* Scheme portion of URI */
2974 username
[64], /* Username portion of URI */
2975 hostname
[HTTP_MAX_HOST
],
2976 /* Host portion of URI */
2977 resource
[HTTP_MAX_URI
];
2978 /* Resource portion of URI */
2979 int port
; /* Port portion of URI */
2982 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2986 * Initialize return values...
2993 *dtype
= (cups_ptype_t
)0;
2996 * Pull the hostname and resource from the URI...
2999 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
3000 username
, sizeof(username
), hostname
, sizeof(hostname
),
3001 &port
, resource
, sizeof(resource
));
3004 * See if the resource is a class or printer...
3007 if (!strncmp(resource
, "/classes/", 9))
3013 rptr
= resource
+ 9;
3015 else if (!strncmp(resource
, "/printers/", 10))
3021 rptr
= resource
+ 10;
3026 * Bad resource name...
3033 * See if the printer or class name exists...
3036 p
= cupsdFindDest(rptr
);
3038 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3046 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3052 * Change localhost to the server name...
3055 if (!_cups_strcasecmp(hostname
, "localhost"))
3056 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3058 strlcpy(localname
, hostname
, sizeof(localname
));
3060 if (!_cups_strcasecmp(hostname
, ServerName
))
3063 * Localize the hostname...
3066 lptr
= strchr(localname
, '.');
3067 sptr
= strchr(ServerName
, '.');
3069 if (sptr
!= NULL
&& lptr
!= NULL
)
3072 * Strip the common domain name components...
3075 while (lptr
!= NULL
)
3077 if (!_cups_strcasecmp(lptr
, sptr
))
3083 lptr
= strchr(lptr
+ 1, '.');
3088 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3091 * Find a matching printer or class...
3094 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3096 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3097 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3098 !_cups_strcasecmp(p
->name
, rptr
))
3104 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3114 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3119 cupsdWritePrintcap(void)
3121 int i
; /* Looping var */
3122 cups_file_t
*fp
; /* Printcap file */
3123 cupsd_printer_t
*p
; /* Current printer */
3127 * See if we have a printcap file; if not, don't bother writing it.
3130 if (!Printcap
|| !*Printcap
)
3133 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3136 * Open the printcap file...
3139 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3143 * Put a comment header at the top so that users will know where the
3144 * data has come from...
3147 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3148 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3150 "# %s/printers.conf file. All changes to this file\n"
3151 "# will be lost.\n", ServerRoot
);
3154 * Write a new printcap with the current list of printers.
3157 switch (PrintcapFormat
)
3161 * Each printer is put in the file as:
3171 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3172 DefaultPrinter
->info
, ServerName
,
3173 DefaultPrinter
->name
);
3175 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3177 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3178 if (p
!= DefaultPrinter
)
3179 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3180 ServerName
, p
->name
);
3183 case PRINTCAP_PLIST
:
3185 * Each printer is written as a dictionary in a plist file.
3186 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3187 * printer-location, printer-make-and-model, printer-state,
3188 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3191 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3192 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3193 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3194 "PropertyList-1.0.dtd\">\n"
3195 "<plist version=\"1.0\">\n"
3198 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3200 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3202 cupsFilePuts(fp
, "\t<dict>\n"
3203 "\t\t<key>printer-name</key>\n"
3205 write_xml_string(fp
, p
->name
);
3206 cupsFilePuts(fp
, "</string>\n"
3207 "\t\t<key>printer-info</key>\n"
3209 write_xml_string(fp
, p
->info
);
3210 cupsFilePrintf(fp
, "</string>\n"
3211 "\t\t<key>printer-is-accepting-jobs</key>\n"
3213 "\t\t<key>printer-location</key>\n"
3214 "\t\t<string>", p
->accepting
? "true" : "false");
3215 write_xml_string(fp
, p
->location
);
3216 cupsFilePuts(fp
, "</string>\n"
3217 "\t\t<key>printer-make-and-model</key>\n"
3219 write_xml_string(fp
, p
->make_model
);
3220 cupsFilePrintf(fp
, "</string>\n"
3221 "\t\t<key>printer-state</key>\n"
3222 "\t\t<integer>%d</integer>\n"
3223 "\t\t<key>printer-state-reasons</key>\n"
3224 "\t\t<array>\n", p
->state
);
3225 for (i
= 0; i
< p
->num_reasons
; i
++)
3227 cupsFilePuts(fp
, "\t\t\t<string>");
3228 write_xml_string(fp
, p
->reasons
[i
]);
3229 cupsFilePuts(fp
, "</string>\n");
3231 cupsFilePrintf(fp
, "\t\t</array>\n"
3232 "\t\t<key>printer-type</key>\n"
3233 "\t\t<integer>%d</integer>\n"
3234 "\t\t<key>device-uri</key>\n"
3235 "\t\t<string>", p
->type
);
3236 write_xml_string(fp
, p
->sanitized_device_uri
);
3237 cupsFilePuts(fp
, "</string>\n"
3240 cupsFilePuts(fp
, "</array>\n"
3244 case PRINTCAP_SOLARIS
:
3246 * Each printer is put in the file as:
3248 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3249 * _default:use=DefaultPrinter
3251 * :bsdaddr=ServerName,Printer1:\
3252 * :description=Description:
3254 * :bsdaddr=ServerName,Printer2:\
3255 * :description=Description:
3257 * :bsdaddr=ServerName,Printer3:\
3258 * :description=Description:
3261 * :bsdaddr=ServerName,PrinterN:\
3262 * :description=Description:
3265 cupsFilePuts(fp
, "_all:all=");
3266 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3268 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3269 cupsFilePrintf(fp
, "%s%c", p
->name
,
3270 cupsArrayNext(Printers
) ? ',' : '\n');
3273 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3275 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3277 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3278 cupsFilePrintf(fp
, "%s:\\\n"
3279 "\t:bsdaddr=%s,%s:\\\n"
3280 "\t:description=%s:\n",
3281 p
->name
, ServerName
, p
->name
,
3282 p
->info
? p
->info
: "");
3295 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3299 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3301 int i
; /* Looping var */
3302 int num_options
; /* Number of default options */
3303 cups_option_t
*options
, /* Default options */
3304 *option
; /* Current option */
3305 char name
[256]; /* name-default */
3309 * Maintain a common array of default attribute names...
3312 if (!CommonDefaults
)
3314 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3316 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3317 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3318 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3319 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3320 cupsArrayAdd(CommonDefaults
,
3321 _cupsStrAlloc("job-accounting-user-id-default"));
3322 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3323 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3324 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3325 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3326 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3327 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3328 cupsArrayAdd(CommonDefaults
,
3329 _cupsStrAlloc("orientation-requested-default"));
3333 * Add all of the default options from the .conf files...
3336 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3340 if (strcmp(option
->name
, "ipp-options") &&
3341 strcmp(option
->name
, "job-sheets") &&
3342 strcmp(option
->name
, "lease-duration"))
3344 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3345 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3347 if (!cupsArrayFind(CommonDefaults
, name
))
3348 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3353 * Convert options to IPP attributes...
3356 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3357 cupsFreeOptions(num_options
, options
);
3360 * Add standard -default attributes as needed...
3363 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3364 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3367 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3368 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3369 "document-format-default", NULL
, "application/octet-stream");
3371 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3372 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3373 "job-cancel-after-default", MaxJobTime
);
3375 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3376 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3377 "job-hold-until-default", NULL
, "no-hold");
3379 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3380 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3381 "job-priority-default", 50);
3383 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3384 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3385 "number-up-default", 1);
3387 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3388 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3389 "notify-lease-duration-default", DefaultLeaseDuration
);
3391 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3392 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3393 "notify-events-default", NULL
, "job-completed");
3395 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3396 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3397 "orientation-requested-default", NULL
, NULL
);
3399 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3400 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3401 "print-quality-default", IPP_QUALITY_NORMAL
);
3406 * 'add_printer_filter()' - Add a MIME filter for a printer.
3411 cupsd_printer_t
*p
, /* I - Printer to add to */
3412 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3413 const char *filter
) /* I - Filter to add */
3415 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3416 type
[MIME_MAX_TYPE
], /* Type for filter */
3417 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3418 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3419 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3420 /* Destination super/type */
3421 program
[1024]; /* Program/filter name */
3422 int cost
; /* Cost of filter */
3423 size_t maxsize
= 0; /* Maximum supported file size */
3424 mime_type_t
*temptype
, /* MIME type looping var */
3425 *desttype
; /* Destination MIME type */
3426 mime_filter_t
*filterptr
; /* MIME filter */
3427 char filename
[1024]; /* Full filter filename */
3430 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3431 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3432 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3433 filtertype
->type
, filter
);
3436 * Parse the filter string; it should be in one of the following formats:
3438 * source/type cost program
3439 * source/type cost maxsize(nnnn) program
3440 * source/type dest/type cost program
3441 * source/type dest/type cost maxsize(nnnn) program
3444 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3445 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3447 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3449 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3451 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3453 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3455 cupsArrayAdd(p
->dest_types
, desttype
);
3461 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3464 desttype
= filtertype
;
3468 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3474 if (!strncmp(program
, "maxsize(", 8))
3476 char *ptr
; /* Pointer into maxsize(nnnn) program */
3478 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3482 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3488 while (_cups_isspace(*ptr
))
3491 _cups_strcpy(program
, ptr
);
3495 * Check permissions on the filter and its containing directory...
3498 if (strcmp(program
, "-"))
3500 if (program
[0] == '/')
3501 strlcpy(filename
, program
, sizeof(filename
));
3503 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3505 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3506 cupsdLogFCMessage
, p
);
3510 * Add the filter to the MIME database, supporting wildcards as needed...
3513 for (temptype
= mimeFirstType(MimeDatabase
);
3515 temptype
= mimeNextType(MimeDatabase
))
3516 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3517 !_cups_strcasecmp(temptype
->super
, super
)) &&
3518 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3520 if (desttype
!= filtertype
)
3522 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3523 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3524 "%s", p
->name
, temptype
->super
, temptype
->type
,
3525 desttype
->super
, desttype
->type
,
3527 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3530 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3532 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3533 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3534 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3535 filtertype
->super
, filtertype
->type
);
3536 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3541 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3542 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3543 "%s", p
->name
, temptype
->super
, temptype
->type
,
3544 filtertype
->super
, filtertype
->type
,
3546 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3551 filterptr
->maxsize
= maxsize
;
3557 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3561 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3563 int i
; /* Looping var */
3564 mime_type_t
*type
; /* Current MIME type */
3565 cups_array_t
*filters
; /* Filters */
3566 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3567 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3568 /* MIME type name */
3572 * Raw (and remote) queues advertise all of the supported MIME
3576 cupsArrayDelete(p
->filetypes
);
3577 p
->filetypes
= NULL
;
3581 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3582 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3583 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3588 * Otherwise, loop through the supported MIME types and see if there
3589 * are filters for them...
3592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3593 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3595 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3597 for (type
= mimeFirstType(MimeDatabase
);
3599 type
= mimeNextType(MimeDatabase
))
3601 if (!_cups_strcasecmp(type
->super
, "printer"))
3604 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3606 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3608 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3609 "add_printer_formats: %s: %s needs %d filters",
3610 p
->name
, mimetype
, cupsArrayCount(filters
));
3612 cupsArrayDelete(filters
);
3613 cupsArrayAdd(p
->filetypes
, type
);
3616 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3617 "add_printer_formats: %s: %s not supported",
3622 * Add the file formats that can be filtered...
3625 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3626 !cupsArrayFind(p
->filetypes
, type
))
3631 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3632 "add_printer_formats: %s: %d supported types",
3633 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3635 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3636 "document-format-supported",
3637 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3640 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3642 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3644 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3646 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3648 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3651 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3653 char pdl
[1024]; /* Buffer to build pdl list */
3654 mime_filter_t
*filter
; /* MIME filter looping var */
3658 * We only support raw printing if this is not a Tioga PrintJobMgr based
3659 * queue and if application/octet-stream is a known type...
3662 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3664 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3666 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3672 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3673 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3676 * Then list a bunch of formats that are supported by the printer...
3679 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3681 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3683 if (!_cups_strcasecmp(type
->super
, "application"))
3685 if (!_cups_strcasecmp(type
->type
, "pdf"))
3686 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3687 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3688 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3690 else if (!_cups_strcasecmp(type
->super
, "image"))
3692 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3693 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3694 else if (!_cups_strcasecmp(type
->type
, "png"))
3695 strlcat(pdl
, "image/png,", sizeof(pdl
));
3696 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3697 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3702 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3704 cupsdSetString(&p
->pdl
, pdl
);
3706 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3711 * 'compare_printers()' - Compare two printers.
3714 static int /* O - Result of comparison */
3715 compare_printers(void *first
, /* I - First printer */
3716 void *second
, /* I - Second printer */
3717 void *data
) /* I - App data (not used) */
3721 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3722 ((cupsd_printer_t
*)second
)->name
));
3727 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3731 delete_printer_filters(
3732 cupsd_printer_t
*p
) /* I - Printer to remove from */
3734 mime_filter_t
*filter
; /* MIME filter looping var */
3735 mime_type_t
*type
; /* Destination types for filters */
3739 * Range check input...
3746 * Remove all filters from the MIME database that have a destination
3747 * type == printer...
3750 for (filter
= mimeFirstFilter(MimeDatabase
);
3752 filter
= mimeNextFilter(MimeDatabase
))
3753 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3754 cupsArrayFind(p
->dest_types
, filter
->dst
))
3757 * Delete the current filter...
3760 mimeDeleteFilter(MimeDatabase
, filter
);
3763 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3765 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3766 mimeDeleteType(MimeDatabase
, type
);
3768 cupsArrayDelete(p
->dest_types
);
3769 p
->dest_types
= NULL
;
3771 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3772 ",cups-missing-filter-warning");
3777 * 'dirty_printer()' - Mark config and state files dirty for the specified
3782 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3784 if (p
->type
& CUPS_PRINTER_CLASS
)
3785 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3787 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3789 if (PrintcapFormat
== PRINTCAP_PLIST
)
3790 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3795 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3799 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3801 int i
, j
, k
; /* Looping vars */
3802 char cache_name
[1024]; /* Cache filename */
3803 struct stat cache_info
; /* Cache file info */
3804 ppd_file_t
*ppd
; /* PPD file */
3805 char ppd_name
[1024]; /* PPD filename */
3806 struct stat ppd_info
; /* PPD file info */
3807 int num_media
; /* Number of media options */
3808 ppd_size_t
*size
; /* Current PPD size */
3809 ppd_option_t
*duplex
, /* Duplex option */
3810 *output_bin
, /* OutputBin option */
3811 *output_mode
, /* OutputMode option */
3812 *resolution
; /* (Set|JCL|)Resolution option */
3813 ppd_choice_t
*choice
, /* Current PPD choice */
3814 *input_slot
, /* Current input slot */
3815 *media_type
; /* Current media type */
3816 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3817 int xdpi
, /* Horizontal resolution */
3818 ydpi
; /* Vertical resolution */
3819 const char *resptr
; /* Pointer into resolution keyword */
3820 pwg_size_t
*pwgsize
; /* Current PWG size */
3821 pwg_map_t
*pwgsource
, /* Current PWG source */
3822 *pwgtype
; /* Current PWG type */
3823 ipp_attribute_t
*attr
; /* Attribute data */
3824 _ipp_value_t
*val
; /* Attribute value */
3825 int num_finishings
, /* Number of finishings */
3826 finishings
[100]; /* finishings-supported values */
3827 int num_qualities
, /* Number of print-quality values */
3828 qualities
[3]; /* print-quality values */
3829 int num_margins
, /* Number of media-*-margin-supported values */
3830 margins
[16]; /* media-*-margin-supported values */
3831 const char *filter
, /* Current filter */
3832 *mandatory
; /* Current mandatory attribute */
3833 static const char * const pwg_raster_document_types
[] =
3839 static const char * const sides
[3] = /* sides-supported values */
3842 "two-sided-long-edge",
3843 "two-sided-short-edge"
3845 static const char * const standard_commands
[] =
3846 { /* Standard CUPS commands */
3854 * Check to see if the cache is up-to-date...
3857 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3858 if (stat(cache_name
, &cache_info
))
3859 cache_info
.st_mtime
= 0;
3861 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3862 if (stat(ppd_name
, &ppd_info
))
3863 ppd_info
.st_mtime
= 1;
3865 ippDelete(p
->ppd_attrs
);
3866 p
->ppd_attrs
= NULL
;
3868 _ppdCacheDestroy(p
->pc
);
3871 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3873 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3875 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3879 * Loaded successfully!
3887 * Reload PPD attributes from disk...
3890 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3892 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3894 cupsdClearString(&(p
->make_model
));
3896 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3897 p
->type
|= CUPS_PRINTER_BW
;
3899 finishings
[0] = IPP_FINISHINGS_NONE
;
3902 p
->ppd_attrs
= ippNew();
3904 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3907 * Add make/model and other various attributes...
3910 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3913 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3914 ppd_name
, cupsLastErrorString());
3916 ppdMarkDefaults(ppd
);
3918 if (ppd
->color_device
)
3919 p
->type
|= CUPS_PRINTER_COLOR
;
3920 if (ppd
->variable_sizes
)
3921 p
->type
|= CUPS_PRINTER_VARIABLE
;
3922 if (!ppd
->manual_copies
)
3923 p
->type
|= CUPS_PRINTER_COPIES
;
3924 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3925 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3926 p
->type
|= CUPS_PRINTER_FAX
;
3928 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3930 if (p
->pc
&& p
->pc
->charge_info_uri
)
3931 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3932 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3934 if (p
->pc
&& p
->pc
->account_id
)
3935 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3938 if (p
->pc
&& p
->pc
->accounting_user_id
)
3939 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3940 "job-accounting-user-id-supported", 1);
3942 if (p
->pc
&& p
->pc
->password
)
3944 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3945 "job-password-encryption-supported", NULL
, "none");
3946 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3947 "job-password-supported", (int)strlen(p
->pc
->password
));
3950 if (ppd
->throughput
)
3952 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3953 "pages-per-minute", ppd
->throughput
);
3954 if (ppd
->color_device
)
3955 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3956 "pages-per-minute-color", ppd
->throughput
);
3961 * When there is no speed information, just say "1 page per minute".
3964 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3965 "pages-per-minute", 1);
3966 if (ppd
->color_device
)
3967 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3968 "pages-per-minute-color", 1);
3971 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3972 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3976 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3978 if (ppdFindChoice(output_mode
, "draft") ||
3979 ppdFindChoice(output_mode
, "fast"))
3980 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3982 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3984 if (ppdFindChoice(output_mode
, "best") ||
3985 ppdFindChoice(output_mode
, "high"))
3986 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3988 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3992 if (strstr(ppd_attr
->spec
, "draft") ||
3993 strstr(ppd_attr
->spec
, "Draft"))
3995 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3999 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
4002 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4003 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
4006 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
4008 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4009 "print-quality-supported", num_qualities
, qualities
);
4014 * The NickName can be localized in the character set specified
4015 * by the LanugageEncoding attribute. However, ppdOpen2() has
4016 * already converted the ppd->nickname member to UTF-8 for us
4017 * (the original attribute value is available separately)
4020 cupsdSetString(&p
->make_model
, ppd
->nickname
);
4022 else if (ppd
->modelname
)
4025 * Model name can only contain specific characters...
4028 cupsdSetString(&p
->make_model
, ppd
->modelname
);
4031 cupsdSetString(&p
->make_model
, "Bad PPD File");
4033 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4034 "printer-make-and-model", NULL
, p
->make_model
);
4037 * Add media options from the PPD file...
4040 if (ppd
->num_sizes
== 0 || !p
->pc
)
4042 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
4043 cupsdLogMessage(CUPSD_LOG_CRIT
,
4044 "The PPD file for printer %s contains no media "
4045 "options and is therefore invalid.", p
->name
);
4047 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4048 "media-default", NULL
, "unknown");
4049 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4050 "media-supported", NULL
, "unknown");
4058 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4059 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4063 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4064 "media-default", NULL
,
4065 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4073 ipp_t
*col
; /* Collection value */
4075 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4076 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4077 col
= new_media_col(pwgsize
,
4079 _ppdCacheGetSource(p
->pc
,
4080 input_slot
->choice
) :
4083 _ppdCacheGetType(p
->pc
,
4084 media_type
->choice
) :
4087 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4096 num_media
= p
->pc
->num_sizes
;
4097 if (p
->pc
->custom_min_keyword
)
4100 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4101 "media-supported", num_media
, NULL
,
4106 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4108 i
--, pwgsize
++, val
++)
4109 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4111 if (p
->pc
->custom_min_keyword
)
4113 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4115 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4120 * media-size-supported
4123 num_media
= p
->pc
->num_sizes
;
4124 if (p
->pc
->custom_min_keyword
)
4127 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4128 "media-size-supported", num_media
,
4133 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4135 i
--, pwgsize
++, val
++)
4137 val
->collection
= ippNew();
4138 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4139 "x-dimension", pwgsize
->width
);
4140 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4141 "y-dimension", pwgsize
->length
);
4144 if (p
->pc
->custom_min_keyword
)
4146 val
->collection
= ippNew();
4147 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4148 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4149 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4150 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4155 * media-source-supported
4158 if (p
->pc
->num_sources
> 0 &&
4159 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4160 "media-source-supported", p
->pc
->num_sources
,
4161 NULL
, NULL
)) != NULL
)
4163 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4166 i
--, pwgsource
++, val
++)
4167 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4171 * media-type-supported
4174 if (p
->pc
->num_types
> 0 &&
4175 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4176 "media-type-supported", p
->pc
->num_types
,
4177 NULL
, NULL
)) != NULL
)
4179 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4182 i
--, pwgtype
++, val
++)
4183 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4187 * media-*-margin-supported
4190 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4191 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4194 for (j
= 0; j
< num_margins
; j
++)
4195 if (pwgsize
->bottom
== margins
[j
])
4198 if (j
>= num_margins
)
4200 margins
[num_margins
] = pwgsize
->bottom
;
4205 if (num_margins
> 0)
4206 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4207 "media-bottom-margin-supported", num_margins
, margins
);
4209 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4210 "media-bottom-margin-supported", 0);
4212 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4213 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4216 for (j
= 0; j
< num_margins
; j
++)
4217 if (pwgsize
->left
== margins
[j
])
4220 if (j
>= num_margins
)
4222 margins
[num_margins
] = pwgsize
->left
;
4227 if (num_margins
> 0)
4228 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4229 "media-left-margin-supported", num_margins
, margins
);
4231 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4232 "media-left-margin-supported", 0);
4234 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4235 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4238 for (j
= 0; j
< num_margins
; j
++)
4239 if (pwgsize
->right
== margins
[j
])
4242 if (j
>= num_margins
)
4244 margins
[num_margins
] = pwgsize
->right
;
4249 if (num_margins
> 0)
4250 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4251 "media-right-margin-supported", num_margins
, margins
);
4253 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4254 "media-right-margin-supported", 0);
4256 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4257 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4260 for (j
= 0; j
< num_margins
; j
++)
4261 if (pwgsize
->top
== margins
[j
])
4264 if (j
>= num_margins
)
4266 margins
[num_margins
] = pwgsize
->top
;
4271 if (num_margins
> 0)
4272 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4273 "media-top-margin-supported", num_margins
, margins
);
4275 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4276 "media-top-margin-supported", 0);
4279 * media-col-database
4282 num_media
= p
->pc
->num_sizes
;
4283 if (p
->pc
->num_sources
)
4285 if (p
->pc
->num_types
> 0)
4286 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4289 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4291 else if (p
->pc
->num_types
)
4292 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4294 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4295 "media-col-database", num_media
,
4298 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4303 * Start by adding the page size without source or type...
4306 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4308 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4312 * Then add the specific, supported combinations of size, source, and
4316 if (p
->pc
->num_sources
> 0)
4318 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4322 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4324 if (p
->pc
->num_types
> 0)
4326 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4330 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4332 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4338 else if (!ppdConflicts(ppd
))
4340 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4345 else if (p
->pc
->num_types
> 0)
4347 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4351 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4353 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4361 * Update the number of media-col-database values...
4364 attr
->num_values
= val
- attr
->values
;
4372 if (p
->pc
&& p
->pc
->num_bins
> 0)
4374 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4375 "output-bin-supported", p
->pc
->num_bins
,
4380 for (i
= 0, val
= attr
->values
;
4381 i
< p
->pc
->num_bins
;
4383 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4386 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4388 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4389 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4392 if (i
>= p
->pc
->num_bins
)
4395 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4396 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4399 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4400 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4402 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4404 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4405 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4406 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4407 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4410 * Report that this printer has a single output bin that leaves pages face
4414 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4415 "output-bin-supported", NULL
, "face-up");
4416 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4417 "output-bin-default", NULL
, "face-up");
4421 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4422 "output-bin-supported", NULL
, "face-down");
4423 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4424 "output-bin-default", NULL
, "face-down");
4428 * print-color-mode...
4431 if (ppd
->color_device
)
4433 static const char * const color_modes
[] =
4439 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4440 "print-color-mode-supported", 2, NULL
, color_modes
);
4441 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4442 "print-color-mode-default", NULL
, "color");
4443 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 3, NULL
, pwg_raster_document_types
);
4447 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4448 "print-color-mode-supported", NULL
, "monochrome");
4449 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4450 "print-color-mode-default", NULL
, "monochrome");
4451 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-type-supported", 2, NULL
, pwg_raster_document_types
);
4455 * Mandatory job attributes, if any...
4458 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4460 int count
= cupsArrayCount(p
->pc
->mandatory
);
4461 /* Number of mandatory attributes */
4463 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4464 "printer-mandatory-job-attributes", count
, NULL
,
4467 for (val
= attr
->values
,
4468 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4470 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4471 val
->string
.text
= _cupsStrAlloc(mandatory
);
4475 * Printer resolutions...
4478 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4479 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4480 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4481 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4486 * Report all supported resolutions...
4489 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-supported", resolution
->num_choices
, IPP_RES_PER_INCH
, NULL
, NULL
);
4491 for (i
= 0, choice
= resolution
->choices
;
4492 i
< resolution
->num_choices
;
4495 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4496 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4497 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4499 if (xdpi
<= 0 || ydpi
<= 0)
4501 cupsdLogMessage(CUPSD_LOG_WARN
,
4502 "Bad resolution \"%s\" for printer %s.",
4503 choice
->choice
, p
->name
);
4507 attr
->values
[i
].resolution
.xres
= xdpi
;
4508 attr
->values
[i
].resolution
.yres
= ydpi
;
4509 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4512 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "printer-resolution-default", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4515 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4518 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4522 * Just the DefaultResolution to report...
4525 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4526 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4529 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4534 if (xdpi
<= 0 || ydpi
<= 0)
4536 cupsdLogMessage(CUPSD_LOG_WARN
,
4537 "Bad default resolution \"%s\" for printer %s.",
4538 ppd_attr
->value
, p
->name
);
4542 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4543 "printer-resolution-default", IPP_RES_PER_INCH
,
4545 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4546 "printer-resolution-supported", IPP_RES_PER_INCH
,
4548 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, xdpi
, ydpi
);
4553 * No resolutions in PPD - make one up...
4556 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4557 "printer-resolution-default", IPP_RES_PER_INCH
,
4559 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4560 "printer-resolution-supported", IPP_RES_PER_INCH
,
4562 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
, "pwg-raster-document-resolution-supported", IPP_RES_PER_INCH
, 300, 300);
4569 ppdMarkDefaults(ppd
);
4571 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4572 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4573 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4574 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4575 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4577 if (duplex
&& duplex
->num_choices
> 1 &&
4578 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4580 p
->type
|= CUPS_PRINTER_DUPLEX
;
4582 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "pwg-raster-document-sheet-back", NULL
, "normal");
4584 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4585 "sides-supported", 3, NULL
, sides
);
4587 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4588 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4589 "sides-default", NULL
, "two-sided-short-edge");
4590 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4591 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4592 "sides-default", NULL
, "two-sided-long-edge");
4594 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4595 "sides-default", NULL
, "one-sided");
4599 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4600 "sides-supported", NULL
, "one-sided");
4601 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4602 "sides-default", NULL
, "one-sided");
4605 if (ppdFindOption(ppd
, "Collate") != NULL
)
4606 p
->type
|= CUPS_PRINTER_COLLATE
;
4608 if (p
->pc
&& p
->pc
->finishings
)
4610 _pwg_finishings_t
*fin
; /* Current finishing value */
4612 for (fin
= (_pwg_finishings_t
*)cupsArrayFirst(p
->pc
->finishings
); fin
; fin
= (_pwg_finishings_t
*)cupsArrayNext(p
->pc
->finishings
))
4614 if (num_finishings
< (int)(sizeof(finishings
) / sizeof(finishings
[0])))
4615 finishings
[num_finishings
++] = fin
->value
;
4619 case IPP_FINISHINGS_BIND
:
4620 case IPP_FINISHINGS_BIND_LEFT
:
4621 case IPP_FINISHINGS_BIND_TOP
:
4622 case IPP_FINISHINGS_BIND_RIGHT
:
4623 case IPP_FINISHINGS_BIND_BOTTOM
:
4624 case IPP_FINISHINGS_EDGE_STITCH
:
4625 case IPP_FINISHINGS_EDGE_STITCH_LEFT
:
4626 case IPP_FINISHINGS_EDGE_STITCH_TOP
:
4627 case IPP_FINISHINGS_EDGE_STITCH_RIGHT
:
4628 case IPP_FINISHINGS_EDGE_STITCH_BOTTOM
:
4629 p
->type
|= CUPS_PRINTER_BIND
;
4632 case IPP_FINISHINGS_COVER
:
4633 p
->type
|= CUPS_PRINTER_COVER
;
4636 case IPP_FINISHINGS_PUNCH
:
4637 case IPP_FINISHINGS_PUNCH_TOP_LEFT
:
4638 case IPP_FINISHINGS_PUNCH_BOTTOM_LEFT
:
4639 case IPP_FINISHINGS_PUNCH_TOP_RIGHT
:
4640 case IPP_FINISHINGS_PUNCH_BOTTOM_RIGHT
:
4641 case IPP_FINISHINGS_PUNCH_DUAL_LEFT
:
4642 case IPP_FINISHINGS_PUNCH_DUAL_TOP
:
4643 case IPP_FINISHINGS_PUNCH_DUAL_RIGHT
:
4644 case IPP_FINISHINGS_PUNCH_DUAL_BOTTOM
:
4645 case IPP_FINISHINGS_PUNCH_TRIPLE_LEFT
:
4646 case IPP_FINISHINGS_PUNCH_TRIPLE_TOP
:
4647 case IPP_FINISHINGS_PUNCH_TRIPLE_RIGHT
:
4648 case IPP_FINISHINGS_PUNCH_TRIPLE_BOTTOM
:
4649 case IPP_FINISHINGS_PUNCH_QUAD_LEFT
:
4650 case IPP_FINISHINGS_PUNCH_QUAD_TOP
:
4651 case IPP_FINISHINGS_PUNCH_QUAD_RIGHT
:
4652 case IPP_FINISHINGS_PUNCH_QUAD_BOTTOM
:
4653 p
->type
|= CUPS_PRINTER_PUNCH
;
4656 case IPP_FINISHINGS_STAPLE
:
4657 case IPP_FINISHINGS_STAPLE_TOP_LEFT
:
4658 case IPP_FINISHINGS_STAPLE_BOTTOM_LEFT
:
4659 case IPP_FINISHINGS_STAPLE_TOP_RIGHT
:
4660 case IPP_FINISHINGS_STAPLE_BOTTOM_RIGHT
:
4661 case IPP_FINISHINGS_STAPLE_DUAL_LEFT
:
4662 case IPP_FINISHINGS_STAPLE_DUAL_TOP
:
4663 case IPP_FINISHINGS_STAPLE_DUAL_RIGHT
:
4664 case IPP_FINISHINGS_STAPLE_DUAL_BOTTOM
:
4665 case IPP_FINISHINGS_STAPLE_TRIPLE_LEFT
:
4666 case IPP_FINISHINGS_STAPLE_TRIPLE_TOP
:
4667 case IPP_FINISHINGS_STAPLE_TRIPLE_RIGHT
:
4668 case IPP_FINISHINGS_STAPLE_TRIPLE_BOTTOM
:
4669 p
->type
|= CUPS_PRINTER_STAPLE
;
4678 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4679 if (ppd
->sizes
[i
].length
> 1728)
4680 p
->type
|= CUPS_PRINTER_LARGE
;
4681 else if (ppd
->sizes
[i
].length
> 1008)
4682 p
->type
|= CUPS_PRINTER_MEDIUM
;
4684 p
->type
|= CUPS_PRINTER_SMALL
;
4686 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4687 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4689 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4690 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4691 p
->type
|= CUPS_PRINTER_SCANNER
;
4693 p
->type
|= CUPS_PRINTER_MFP
;
4697 * Scan the filters in the PPD file...
4702 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4704 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4706 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4707 _cups_isspace(filter
[28]))
4709 p
->type
|= CUPS_PRINTER_COMMANDS
;
4715 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4717 char *commands
, /* Copy of commands */
4718 *start
, /* Start of name */
4719 *end
; /* End of name */
4720 int count
; /* Number of commands */
4722 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4724 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4726 while (_cups_isspace(*start
))
4732 while (*start
&& !isspace(*start
& 255))
4742 * Make a copy of the commands string and count how many commands there
4746 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4747 "printer-commands", count
, NULL
, NULL
);
4749 commands
= strdup(ppd_attr
->value
);
4751 for (count
= 0, start
= commands
; *start
; count
++)
4753 while (isspace(*start
& 255))
4760 while (*end
&& !isspace(*end
& 255))
4766 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4776 * Add the standard list of commands...
4779 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4781 (int)(sizeof(standard_commands
) /
4782 sizeof(standard_commands
[0])), NULL
,
4789 * No commands supported...
4792 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4793 "printer-commands", NULL
, "none");
4797 * Show current and available port monitors for this printer...
4800 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4801 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4803 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4805 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4809 if (strstr(ppd
->protocols
, "TBCP"))
4811 else if (strstr(ppd
->protocols
, "BCP"))
4815 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4816 "port-monitor-supported", i
, NULL
, NULL
);
4818 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4820 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4822 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4823 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4827 if (strstr(ppd
->protocols
, "TBCP"))
4828 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4829 else if (strstr(ppd
->protocols
, "BCP"))
4830 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4833 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4834 p
->type
|= CUPS_PRINTER_REMOTE
;
4836 #ifdef HAVE_APPLICATIONSERVICES_H
4838 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4839 * and save it as cacheDir/printername.png
4842 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4844 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4845 cupsdLogFCMessage
, p
))
4847 CGImageRef imageRef
= NULL
;/* Current icon image */
4848 CGImageRef biggestIconRef
= NULL
;
4849 /* Biggest icon image */
4850 CGImageRef closestTo128IconRef
= NULL
;
4851 /* Icon image closest to and >= 128 */
4852 CGImageSourceRef sourceRef
; /* The file's image source */
4853 char outPath
[HTTP_MAX_URI
];
4854 /* The path to the PNG file */
4855 CFURLRef outUrl
; /* The URL made from the outPath */
4856 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4857 CGImageDestinationRef destRef
; /* The image destination to write */
4858 size_t bytesPerRow
; /* The bytes per row used for resizing */
4859 CGContextRef context
; /* The CG context used for resizing */
4861 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4862 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4863 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4864 if (outUrl
&& icnsFileUrl
)
4866 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4869 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4871 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4875 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4878 * Loop through remembering the icon closest to 128 but >= 128
4879 * and then remember the largest icon.
4882 if (CGImageGetWidth(imageRef
) >= 128 &&
4883 (!closestTo128IconRef
||
4884 CGImageGetWidth(imageRef
) <
4885 CGImageGetWidth(closestTo128IconRef
)))
4887 CGImageRelease(closestTo128IconRef
);
4888 CGImageRetain(imageRef
);
4889 closestTo128IconRef
= imageRef
;
4892 if (!biggestIconRef
||
4893 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4895 CGImageRelease(biggestIconRef
);
4896 CGImageRetain(imageRef
);
4897 biggestIconRef
= imageRef
;
4901 CGImageRelease(imageRef
);
4907 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4908 * want the closest to 128, but if none are larger than 128, we want
4909 * the largest icon available.
4912 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4914 CGImageRetain(imageRef
);
4915 CGImageRelease(biggestIconRef
);
4916 if (closestTo128IconRef
)
4917 CGImageRelease(closestTo128IconRef
);
4918 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4922 if (CGImageGetWidth(imageRef
) != 128)
4924 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4925 CGImageGetWidth(imageRef
) * 128;
4926 context
= CGBitmapContextCreate(NULL
, 128, 128,
4927 CGImageGetBitsPerComponent(imageRef
),
4929 CGImageGetColorSpace(imageRef
),
4930 kCGImageAlphaPremultipliedFirst
);
4933 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4935 CGImageRelease(imageRef
);
4936 imageRef
= CGBitmapContextCreateImage(context
);
4937 CGContextRelease(context
);
4941 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4942 CGImageDestinationFinalize(destRef
);
4946 CGImageRelease(imageRef
);
4949 CFRelease(sourceRef
);
4957 CFRelease(icnsFileUrl
);
4959 #endif /* HAVE_APPLICATIONSERVICES_H */
4962 * Close the PPD and set the type...
4967 else if (!access(ppd_name
, 0))
4969 int pline
; /* PPD line number */
4970 ppd_status_t pstatus
; /* PPD load status */
4973 pstatus
= ppdLastError(&pline
);
4975 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4977 if (pstatus
<= PPD_ALLOC_ERROR
)
4978 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4980 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4982 cupsdLogMessage(CUPSD_LOG_INFO
,
4983 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4988 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4989 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4990 (strstr(p
->device_uri
, "/printers/") != NULL
||
4991 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4992 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4993 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4994 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4997 * Tell the client this is really a hard-wired remote printer.
5000 p
->type
|= CUPS_PRINTER_REMOTE
;
5003 * Point the printer-uri-supported attribute to the
5007 if (strchr(p
->device_uri
, '?'))
5010 * Strip trailing "?options" from URI...
5013 char resource
[HTTP_MAX_URI
], /* New URI */
5014 *ptr
; /* Pointer into URI */
5016 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
5017 if ((ptr
= strchr(resource
, '?')) != NULL
)
5020 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5021 "printer-uri-supported", NULL
, resource
);
5024 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
5025 "printer-uri-supported", NULL
, p
->device_uri
);
5028 * Then set the make-and-model accordingly...
5031 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5032 "printer-make-and-model", NULL
, "Remote Printer");
5035 * Print all files directly...
5044 * Otherwise we have neither - treat this as a "dumb" printer
5045 * with no PPD file...
5048 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
5049 "printer-make-and-model", NULL
, "Local Raw Printer");
5055 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5056 "finishings-supported", num_finishings
, finishings
);
5057 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
5058 "finishings-default", IPP_FINISHINGS_NONE
);
5063 * Save cached PPD attributes to disk...
5066 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
5068 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
5073 * Remove cache files...
5076 if (cache_info
.st_mtime
)
5083 * 'new_media_col()' - Create a media-col collection value.
5086 static ipp_t
* /* O - Collection value */
5087 new_media_col(pwg_size_t
*size
, /* I - media-size/margin values */
5088 const char *source
, /* I - media-source value */
5089 const char *type
) /* I - media-type value */
5091 ipp_t
*media_col
, /* Collection value */
5092 *media_size
; /* media-size value */
5095 media_col
= ippNew();
5097 media_size
= ippNew();
5098 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5099 "x-dimension", size
->width
);
5100 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5101 "y-dimension", size
->length
);
5102 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5103 ippDelete(media_size
);
5105 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5106 "media-bottom-margin", size
->bottom
);
5107 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5108 "media-left-margin", size
->left
);
5109 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5110 "media-right-margin", size
->right
);
5111 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5112 "media-top-margin", size
->top
);
5115 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5119 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5127 * 'write_xml_string()' - Write a string with XML escaping.
5131 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5132 const char *s
) /* I - String to write */
5134 const char *start
; /* Start of current sequence */
5140 for (start
= s
; *s
; s
++)
5145 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5147 cupsFilePuts(fp
, "&");
5153 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5155 cupsFilePuts(fp
, "<");
5161 cupsFilePuts(fp
, start
);