4 * Printer routines for the CUPS scheduler.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
22 #ifdef HAVE_APPLICATIONSERVICES_H
23 # include <ApplicationServices/ApplicationServices.h>
24 #endif /* HAVE_APPLICATIONSERVICES_H */
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
27 #endif /* HAVE_SYS_MOUNT_H */
28 #ifdef HAVE_SYS_STATVFS_H
29 # include <sys/statvfs.h>
30 #elif defined(HAVE_SYS_STATFS_H)
31 # include <sys/statfs.h>
32 #endif /* HAVE_SYS_STATVFS_H */
35 #endif /* HAVE_SYS_VFS_H */
38 #endif /* __APPLE__ */
45 static void add_printer_defaults(cupsd_printer_t
*p
);
46 static void add_printer_filter(cupsd_printer_t
*p
, mime_type_t
*type
,
48 static void add_printer_formats(cupsd_printer_t
*p
);
49 static int compare_printers(void *first
, void *second
, void *data
);
50 static void delete_printer_filters(cupsd_printer_t
*p
);
51 static void dirty_printer(cupsd_printer_t
*p
);
52 static void load_ppd(cupsd_printer_t
*p
);
53 static ipp_t
*new_media_col(_pwg_size_t
*size
, const char *source
,
55 static void write_xml_string(cups_file_t
*fp
, const char *s
);
59 * 'cupsdAddPrinter()' - Add a printer to the system.
62 cupsd_printer_t
* /* O - New printer */
63 cupsdAddPrinter(const char *name
) /* I - Name of printer */
65 cupsd_printer_t
*p
; /* New printer */
66 char uri
[1024], /* Printer URI */
67 uuid
[64]; /* Printer UUID */
71 * Range check input...
74 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPrinter(\"%s\")", name
);
77 * Create a new printer entity...
80 if ((p
= calloc(1, sizeof(cupsd_printer_t
))) == NULL
)
82 cupsdLogMessage(CUPSD_LOG_CRIT
, "Unable to allocate memory for printer - %s",
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 * Free all memory used by the printer...
750 if (p
->printers
!= NULL
)
753 delete_printer_filters(p
);
755 for (i
= 0; i
< p
->num_reasons
; i
++)
756 _cupsStrFree(p
->reasons
[i
]);
759 ippDelete(p
->ppd_attrs
);
761 mimeDeleteType(MimeDatabase
, p
->filetype
);
762 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
764 cupsdFreeStrings(&(p
->users
));
767 cupsdClearString(&p
->uri
);
768 cupsdClearString(&p
->hostname
);
769 cupsdClearString(&p
->name
);
770 cupsdClearString(&p
->location
);
771 cupsdClearString(&p
->geo_location
);
772 cupsdClearString(&p
->make_model
);
773 cupsdClearString(&p
->info
);
774 cupsdClearString(&p
->job_sheets
[0]);
775 cupsdClearString(&p
->job_sheets
[1]);
776 cupsdClearString(&p
->device_uri
);
777 cupsdClearString(&p
->sanitized_device_uri
);
778 cupsdClearString(&p
->port_monitor
);
779 cupsdClearString(&p
->op_policy
);
780 cupsdClearString(&p
->error_policy
);
782 cupsdClearString(&p
->alert
);
783 cupsdClearString(&p
->alert_description
);
785 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
786 cupsdClearString(&p
->pdl
);
787 cupsdClearString(&p
->reg_name
);
788 #endif /* HAVE_DNSSD || HAVE_AVAHI */
790 cupsArrayDelete(p
->filetypes
);
792 cupsFreeOptions(p
->num_options
, p
->options
);
797 * Restore the previous position in the Printers array...
800 cupsArrayRestore(Printers
);
807 * 'cupsdFindDest()' - Find a destination in the list.
810 cupsd_printer_t
* /* O - Destination in list */
811 cupsdFindDest(const char *name
) /* I - Name of printer or class to find */
813 cupsd_printer_t key
; /* Search key */
816 key
.name
= (char *)name
;
817 return ((cupsd_printer_t
*)cupsArrayFind(Printers
, &key
));
822 * 'cupsdFindPrinter()' - Find a printer in the list.
825 cupsd_printer_t
* /* O - Printer in list */
826 cupsdFindPrinter(const char *name
) /* I - Name of printer to find */
828 cupsd_printer_t
*p
; /* Printer in list */
831 if ((p
= cupsdFindDest(name
)) != NULL
&& (p
->type
& CUPS_PRINTER_CLASS
))
839 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
843 cupsdLoadAllPrinters(void)
845 int i
; /* Looping var */
846 cups_file_t
*fp
; /* printers.conf file */
847 int linenum
; /* Current line number */
848 char line
[4096], /* Line from file */
849 *value
, /* Pointer to value */
850 *valueptr
; /* Pointer into value */
851 cupsd_printer_t
*p
; /* Current printer */
855 * Open the printers.conf file...
858 snprintf(line
, sizeof(line
), "%s/printers.conf", ServerRoot
);
859 if ((fp
= cupsdOpenConfFile(line
)) == NULL
)
863 * Read printer configurations until we hit EOF...
869 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
872 * Decode the directive...
875 if (!_cups_strcasecmp(line
, "<Printer") ||
876 !_cups_strcasecmp(line
, "<DefaultPrinter"))
879 * <Printer name> or <DefaultPrinter name>
882 if (p
== NULL
&& value
)
885 * Add the printer and a base file type...
888 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Loading printer %s...", value
);
890 p
= cupsdAddPrinter(value
);
892 p
->state
= IPP_PRINTER_IDLE
;
895 * Set the default printer as needed...
898 if (!_cups_strcasecmp(line
, "<DefaultPrinter"))
902 cupsdLogMessage(CUPSD_LOG_ERROR
,
903 "Syntax error on line %d of printers.conf.", linenum
);
905 else if (!_cups_strcasecmp(line
, "</Printer>") || !_cups_strcasecmp(line
, "</DefaultPrinter>"))
910 * Close out the current printer...
913 cupsdSetPrinterAttrs(p
);
915 if (strncmp(p
->device_uri
, "file:", 5) &&
916 p
->state
!= IPP_PRINTER_STOPPED
)
919 * See if the backend exists...
922 snprintf(line
, sizeof(line
), "%s/backend/%s", ServerBin
,
925 if ((valueptr
= strchr(line
+ strlen(ServerBin
), ':')) != NULL
)
926 *valueptr
= '\0'; /* Chop everything but URI scheme */
931 * Backend does not exist, stop printer...
934 p
->state
= IPP_PRINTER_STOPPED
;
935 snprintf(p
->state_message
, sizeof(p
->state_message
),
936 "Backend %s does not exist!", line
);
943 cupsdLogMessage(CUPSD_LOG_ERROR
,
944 "Syntax error on line %d of printers.conf.", linenum
);
948 cupsdLogMessage(CUPSD_LOG_ERROR
,
949 "Syntax error on line %d of printers.conf.", linenum
);
951 else if (!_cups_strcasecmp(line
, "UUID"))
953 if (value
&& !strncmp(value
, "urn:uuid:", 9))
954 cupsdSetString(&(p
->uuid
), value
);
956 cupsdLogMessage(CUPSD_LOG_ERROR
,
957 "Bad UUID on line %d of printers.conf.", linenum
);
959 else if (!_cups_strcasecmp(line
, "AuthInfoRequired"))
961 if (!cupsdSetAuthInfoRequired(p
, value
, NULL
))
962 cupsdLogMessage(CUPSD_LOG_ERROR
,
963 "Bad AuthInfoRequired on line %d of printers.conf.",
966 else if (!_cups_strcasecmp(line
, "Info"))
969 cupsdSetString(&p
->info
, value
);
971 else if (!_cups_strcasecmp(line
, "MakeModel"))
974 cupsdSetString(&p
->make_model
, value
);
976 else if (!_cups_strcasecmp(line
, "Location"))
979 cupsdSetString(&p
->location
, value
);
981 else if (!_cups_strcasecmp(line
, "GeoLocation"))
984 cupsdSetString(&p
->geo_location
, value
);
986 else if (!_cups_strcasecmp(line
, "Organization"))
989 cupsdSetString(&p
->organization
, value
);
991 else if (!_cups_strcasecmp(line
, "OrganizationalUnit"))
994 cupsdSetString(&p
->organizational_unit
, value
);
996 else if (!_cups_strcasecmp(line
, "DeviceURI"))
999 cupsdSetDeviceURI(p
, value
);
1001 cupsdLogMessage(CUPSD_LOG_ERROR
,
1002 "Syntax error on line %d of printers.conf.", linenum
);
1004 else if (!_cups_strcasecmp(line
, "Option") && value
)
1010 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1013 cupsdLogMessage(CUPSD_LOG_ERROR
,
1014 "Syntax error on line %d of printers.conf.", linenum
);
1017 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1019 p
->num_options
= cupsAddOption(value
, valueptr
, p
->num_options
,
1023 else if (!_cups_strcasecmp(line
, "PortMonitor"))
1025 if (value
&& strcmp(value
, "none"))
1026 cupsdSetString(&p
->port_monitor
, value
);
1028 cupsdClearString(&p
->port_monitor
);
1030 cupsdLogMessage(CUPSD_LOG_ERROR
,
1031 "Syntax error on line %d of printers.conf.", linenum
);
1033 else if (!_cups_strcasecmp(line
, "Reason"))
1036 strcmp(value
, "connecting-to-device") &&
1037 strcmp(value
, "cups-insecure-filter-warning") &&
1038 strcmp(value
, "cups-missing-filter-warning"))
1040 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1041 if (!strcmp(value
, p
->reasons
[i
]))
1044 if (i
>= p
->num_reasons
&&
1045 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1047 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc(value
);
1052 cupsdLogMessage(CUPSD_LOG_ERROR
,
1053 "Syntax error on line %d of printers.conf.", linenum
);
1055 else if (!_cups_strcasecmp(line
, "State"))
1058 * Set the initial queue state...
1061 if (value
&& !_cups_strcasecmp(value
, "idle"))
1062 p
->state
= IPP_PRINTER_IDLE
;
1063 else if (value
&& !_cups_strcasecmp(value
, "stopped"))
1065 p
->state
= IPP_PRINTER_STOPPED
;
1067 for (i
= 0 ; i
< p
->num_reasons
; i
++)
1068 if (!strcmp("paused", p
->reasons
[i
]))
1071 if (i
>= p
->num_reasons
&&
1072 p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
1074 p
->reasons
[p
->num_reasons
] = _cupsStrAlloc("paused");
1079 cupsdLogMessage(CUPSD_LOG_ERROR
,
1080 "Syntax error on line %d of printers.conf.", linenum
);
1082 else if (!_cups_strcasecmp(line
, "StateMessage"))
1085 * Set the initial queue state message...
1089 strlcpy(p
->state_message
, value
, sizeof(p
->state_message
));
1091 else if (!_cups_strcasecmp(line
, "StateTime"))
1094 * Set the state time...
1098 p
->state_time
= atoi(value
);
1100 else if (!_cups_strcasecmp(line
, "ConfigTime"))
1103 * Set the config time...
1107 p
->config_time
= atoi(value
);
1109 else if (!_cups_strcasecmp(line
, "Accepting"))
1112 * Set the initial accepting state...
1116 (!_cups_strcasecmp(value
, "yes") ||
1117 !_cups_strcasecmp(value
, "on") ||
1118 !_cups_strcasecmp(value
, "true")))
1121 (!_cups_strcasecmp(value
, "no") ||
1122 !_cups_strcasecmp(value
, "off") ||
1123 !_cups_strcasecmp(value
, "false")))
1126 cupsdLogMessage(CUPSD_LOG_ERROR
,
1127 "Syntax error on line %d of printers.conf.", linenum
);
1129 else if (!_cups_strcasecmp(line
, "Type"))
1132 p
->type
= (cups_ptype_t
)atoi(value
);
1134 cupsdLogMessage(CUPSD_LOG_ERROR
,
1135 "Syntax error on line %d of printers.conf.", linenum
);
1137 else if (!_cups_strcasecmp(line
, "Shared"))
1140 * Set the initial shared state...
1144 (!_cups_strcasecmp(value
, "yes") ||
1145 !_cups_strcasecmp(value
, "on") ||
1146 !_cups_strcasecmp(value
, "true")))
1149 (!_cups_strcasecmp(value
, "no") ||
1150 !_cups_strcasecmp(value
, "off") ||
1151 !_cups_strcasecmp(value
, "false")))
1154 cupsdLogMessage(CUPSD_LOG_ERROR
,
1155 "Syntax error on line %d of printers.conf.", linenum
);
1157 else if (!_cups_strcasecmp(line
, "JobSheets"))
1160 * Set the initial job sheets...
1165 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1170 cupsdSetString(&p
->job_sheets
[0], value
);
1172 while (isspace(*valueptr
& 255))
1177 for (value
= valueptr
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1182 cupsdSetString(&p
->job_sheets
[1], value
);
1186 cupsdLogMessage(CUPSD_LOG_ERROR
,
1187 "Syntax error on line %d of printers.conf.", linenum
);
1189 else if (!_cups_strcasecmp(line
, "AllowUser"))
1194 cupsdAddString(&(p
->users
), value
);
1197 cupsdLogMessage(CUPSD_LOG_ERROR
,
1198 "Syntax error on line %d of printers.conf.", linenum
);
1200 else if (!_cups_strcasecmp(line
, "DenyUser"))
1205 cupsdAddString(&(p
->users
), value
);
1208 cupsdLogMessage(CUPSD_LOG_ERROR
,
1209 "Syntax error on line %d of printers.conf.", linenum
);
1211 else if (!_cups_strcasecmp(line
, "QuotaPeriod"))
1214 p
->quota_period
= atoi(value
);
1216 cupsdLogMessage(CUPSD_LOG_ERROR
,
1217 "Syntax error on line %d of printers.conf.", linenum
);
1219 else if (!_cups_strcasecmp(line
, "PageLimit"))
1222 p
->page_limit
= atoi(value
);
1224 cupsdLogMessage(CUPSD_LOG_ERROR
,
1225 "Syntax error on line %d of printers.conf.", linenum
);
1227 else if (!_cups_strcasecmp(line
, "KLimit"))
1230 p
->k_limit
= atoi(value
);
1232 cupsdLogMessage(CUPSD_LOG_ERROR
,
1233 "Syntax error on line %d of printers.conf.", linenum
);
1235 else if (!_cups_strcasecmp(line
, "OpPolicy"))
1239 cupsd_policy_t
*pol
; /* Policy */
1242 if ((pol
= cupsdFindPolicy(value
)) != NULL
)
1244 cupsdSetString(&p
->op_policy
, value
);
1245 p
->op_policy_ptr
= pol
;
1248 cupsdLogMessage(CUPSD_LOG_ERROR
,
1249 "Bad policy \"%s\" on line %d of printers.conf",
1253 cupsdLogMessage(CUPSD_LOG_ERROR
,
1254 "Syntax error on line %d of printers.conf.", linenum
);
1256 else if (!_cups_strcasecmp(line
, "ErrorPolicy"))
1260 if (strcmp(value
, "retry-current-job") &&
1261 strcmp(value
, "abort-job") &&
1262 strcmp(value
, "retry-job") &&
1263 strcmp(value
, "stop-printer"))
1264 cupsdLogMessage(CUPSD_LOG_ALERT
, "Invalid ErrorPolicy \"%s\" on line %d or printers.conf.", ErrorPolicy
, linenum
);
1266 cupsdSetString(&p
->error_policy
, value
);
1269 cupsdLogMessage(CUPSD_LOG_ERROR
, "Syntax error on line %d of printers.conf.", linenum
);
1271 else if (!_cups_strcasecmp(line
, "Attribute") && value
)
1273 for (valueptr
= value
; *valueptr
&& !isspace(*valueptr
& 255); valueptr
++);
1276 cupsdLogMessage(CUPSD_LOG_ERROR
,
1277 "Syntax error on line %d of printers.conf.", linenum
);
1280 for (; *valueptr
&& isspace(*valueptr
& 255); *valueptr
++ = '\0');
1283 cupsdSetPrinterAttrs(p
);
1285 if (!strcmp(value
, "marker-change-time"))
1286 p
->marker_time
= atoi(valueptr
);
1288 cupsdSetPrinterAttr(p
, value
, valueptr
);
1291 else if (_cups_strcasecmp(line
, "Filter") &&
1292 _cups_strcasecmp(line
, "Prefilter") &&
1293 _cups_strcasecmp(line
, "Product"))
1296 * Something else we don't understand (and that wasn't used in a prior
1297 * release of CUPS...
1300 cupsdLogMessage(CUPSD_LOG_ERROR
,
1301 "Unknown configuration directive %s on line %d of "
1302 "printers.conf.", line
, linenum
);
1311 * 'cupsdRenamePrinter()' - Rename a printer.
1316 cupsd_printer_t
*p
, /* I - Printer */
1317 const char *name
) /* I - New name */
1320 * Remove the printer from the array(s) first...
1323 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1324 "cupsdRenamePrinter: Removing %s from Printers", p
->name
);
1325 cupsArrayRemove(Printers
, p
);
1328 * Rename the printer type...
1331 mimeDeleteType(MimeDatabase
, p
->filetype
);
1332 p
->filetype
= mimeAddType(MimeDatabase
, "printer", name
);
1334 if (p
->prefiltertype
)
1336 mimeDeleteType(MimeDatabase
, p
->prefiltertype
);
1337 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", name
);
1341 * Rename the printer...
1344 cupsdSetString(&p
->name
, name
);
1347 * Reset printer attributes...
1350 cupsdSetPrinterAttrs(p
);
1353 * Add the printer back to the printer array(s)...
1356 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1357 "cupsdRenamePrinter: Adding %s to Printers", p
->name
);
1358 cupsArrayAdd(Printers
, p
);
1363 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1368 cupsdSaveAllPrinters(void)
1370 int i
; /* Looping var */
1371 cups_file_t
*fp
; /* printers.conf file */
1372 char filename
[1024], /* printers.conf filename */
1373 temp
[1024], /* Temporary string */
1374 value
[2048], /* Value string */
1375 *ptr
, /* Pointer into value */
1376 *name
; /* Current user/group name */
1377 cupsd_printer_t
*printer
; /* Current printer class */
1378 time_t curtime
; /* Current time */
1379 struct tm
*curdate
; /* Current date */
1380 cups_option_t
*option
; /* Current option */
1381 ipp_attribute_t
*marker
; /* Current marker attribute */
1385 * Create the printers.conf file...
1388 snprintf(filename
, sizeof(filename
), "%s/printers.conf", ServerRoot
);
1390 if ((fp
= cupsdCreateConfFile(filename
, ConfigFilePerm
& 0600)) == NULL
)
1393 cupsdLogMessage(CUPSD_LOG_INFO
, "Saving printers.conf...");
1396 * Write a small header to the file...
1399 curtime
= time(NULL
);
1400 curdate
= localtime(&curtime
);
1401 strftime(temp
, sizeof(temp
) - 1, "%Y-%m-%d %H:%M", curdate
);
1403 cupsFilePuts(fp
, "# Printer configuration file for " CUPS_SVERSION
"\n");
1404 cupsFilePrintf(fp
, "# Written by cupsd on %s\n", temp
);
1405 cupsFilePuts(fp
, "# DO NOT EDIT THIS FILE WHEN CUPSD IS RUNNING\n");
1408 * Write each local printer known to the system...
1411 for (printer
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1413 printer
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1416 * Skip printer classes...
1419 if (printer
->type
& CUPS_PRINTER_CLASS
)
1423 * Write printers as needed...
1426 if (printer
== DefaultPrinter
)
1427 cupsFilePrintf(fp
, "<DefaultPrinter %s>\n", printer
->name
);
1429 cupsFilePrintf(fp
, "<Printer %s>\n", printer
->name
);
1431 cupsFilePrintf(fp
, "UUID %s\n", printer
->uuid
);
1433 if (printer
->num_auth_info_required
> 0)
1435 switch (printer
->num_auth_info_required
)
1438 strlcpy(value
, printer
->auth_info_required
[0], sizeof(value
));
1442 snprintf(value
, sizeof(value
), "%s,%s",
1443 printer
->auth_info_required
[0],
1444 printer
->auth_info_required
[1]);
1449 snprintf(value
, sizeof(value
), "%s,%s,%s",
1450 printer
->auth_info_required
[0],
1451 printer
->auth_info_required
[1],
1452 printer
->auth_info_required
[2]);
1456 cupsFilePutConf(fp
, "AuthInfoRequired", value
);
1460 cupsFilePutConf(fp
, "Info", printer
->info
);
1462 if (printer
->location
)
1463 cupsFilePutConf(fp
, "Location", printer
->location
);
1465 if (printer
->geo_location
)
1466 cupsFilePutConf(fp
, "GeoLocation", printer
->geo_location
);
1468 if (printer
->make_model
)
1469 cupsFilePutConf(fp
, "MakeModel", printer
->make_model
);
1471 if (printer
->organization
)
1472 cupsFilePutConf(fp
, "Organization", printer
->organization
);
1474 if (printer
->organizational_unit
)
1475 cupsFilePutConf(fp
, "OrganizationalUnit", printer
->organizational_unit
);
1477 cupsFilePutConf(fp
, "DeviceURI", printer
->device_uri
);
1479 if (printer
->port_monitor
)
1480 cupsFilePutConf(fp
, "PortMonitor", printer
->port_monitor
);
1482 if (printer
->state
== IPP_PRINTER_STOPPED
)
1484 cupsFilePuts(fp
, "State Stopped\n");
1486 if (printer
->state_message
[0])
1487 cupsFilePutConf(fp
, "StateMessage", printer
->state_message
);
1490 cupsFilePuts(fp
, "State Idle\n");
1492 cupsFilePrintf(fp
, "StateTime %d\n", (int)printer
->state_time
);
1493 cupsFilePrintf(fp
, "ConfigTime %d\n", (int)printer
->config_time
);
1495 for (i
= 0; i
< printer
->num_reasons
; i
++)
1496 if (strcmp(printer
->reasons
[i
], "connecting-to-device") &&
1497 strcmp(printer
->reasons
[i
], "cups-insecure-filter-warning") &&
1498 strcmp(printer
->reasons
[i
], "cups-missing-filter-warning"))
1499 cupsFilePutConf(fp
, "Reason", printer
->reasons
[i
]);
1501 cupsFilePrintf(fp
, "Type %d\n", printer
->type
);
1503 if (printer
->accepting
)
1504 cupsFilePuts(fp
, "Accepting Yes\n");
1506 cupsFilePuts(fp
, "Accepting No\n");
1508 if (printer
->shared
)
1509 cupsFilePuts(fp
, "Shared Yes\n");
1511 cupsFilePuts(fp
, "Shared No\n");
1513 snprintf(value
, sizeof(value
), "%s %s", printer
->job_sheets
[0],
1514 printer
->job_sheets
[1]);
1515 cupsFilePutConf(fp
, "JobSheets", value
);
1517 cupsFilePrintf(fp
, "QuotaPeriod %d\n", printer
->quota_period
);
1518 cupsFilePrintf(fp
, "PageLimit %d\n", printer
->page_limit
);
1519 cupsFilePrintf(fp
, "KLimit %d\n", printer
->k_limit
);
1521 for (name
= (char *)cupsArrayFirst(printer
->users
);
1523 name
= (char *)cupsArrayNext(printer
->users
))
1524 cupsFilePutConf(fp
, printer
->deny_users
? "DenyUser" : "AllowUser", name
);
1526 if (printer
->op_policy
)
1527 cupsFilePutConf(fp
, "OpPolicy", printer
->op_policy
);
1528 if (printer
->error_policy
)
1529 cupsFilePutConf(fp
, "ErrorPolicy", printer
->error_policy
);
1531 for (i
= printer
->num_options
, option
= printer
->options
;
1535 snprintf(value
, sizeof(value
), "%s %s", option
->name
, option
->value
);
1536 cupsFilePutConf(fp
, "Option", value
);
1539 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-colors",
1540 IPP_TAG_NAME
)) != NULL
)
1542 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1544 for (i
= 0, ptr
= value
+ strlen(value
);
1545 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1551 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1556 cupsFilePutConf(fp
, "Attribute", value
);
1559 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-levels",
1560 IPP_TAG_INTEGER
)) != NULL
)
1562 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1563 marker
->values
[0].integer
);
1564 for (i
= 1; i
< marker
->num_values
; i
++)
1565 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1566 cupsFilePuts(fp
, "\n");
1569 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-low-levels",
1570 IPP_TAG_INTEGER
)) != NULL
)
1572 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1573 marker
->values
[0].integer
);
1574 for (i
= 1; i
< marker
->num_values
; i
++)
1575 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1576 cupsFilePuts(fp
, "\n");
1579 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-high-levels",
1580 IPP_TAG_INTEGER
)) != NULL
)
1582 cupsFilePrintf(fp
, "Attribute %s %d", marker
->name
,
1583 marker
->values
[0].integer
);
1584 for (i
= 1; i
< marker
->num_values
; i
++)
1585 cupsFilePrintf(fp
, ",%d", marker
->values
[i
].integer
);
1586 cupsFilePuts(fp
, "\n");
1589 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-message",
1590 IPP_TAG_TEXT
)) != NULL
)
1592 snprintf(value
, sizeof(value
), "%s %s", marker
->name
,
1593 marker
->values
[0].string
.text
);
1595 cupsFilePutConf(fp
, "Attribute", value
);
1598 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-names",
1599 IPP_TAG_NAME
)) != NULL
)
1601 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1603 for (i
= 0, ptr
= value
+ strlen(value
);
1604 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1610 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1615 cupsFilePutConf(fp
, "Attribute", value
);
1618 if ((marker
= ippFindAttribute(printer
->attrs
, "marker-types",
1619 IPP_TAG_KEYWORD
)) != NULL
)
1621 snprintf(value
, sizeof(value
), "%s ", marker
->name
);
1623 for (i
= 0, ptr
= value
+ strlen(value
);
1624 i
< marker
->num_values
&& ptr
< (value
+ sizeof(value
) - 1);
1630 strlcpy(ptr
, marker
->values
[i
].string
.text
, (size_t)(value
+ sizeof(value
) - ptr
));
1635 cupsFilePutConf(fp
, "Attribute", value
);
1638 if (printer
->marker_time
)
1639 cupsFilePrintf(fp
, "Attribute marker-change-time %ld\n",
1640 (long)printer
->marker_time
);
1642 if (printer
== DefaultPrinter
)
1643 cupsFilePuts(fp
, "</DefaultPrinter>\n");
1645 cupsFilePuts(fp
, "</Printer>\n");
1648 cupsdCloseCreatedConfFile(fp
, filename
);
1653 * 'cupsdSetAuthInfoRequired()' - Set the required authentication info.
1656 int /* O - 1 if value OK, 0 otherwise */
1657 cupsdSetAuthInfoRequired(
1658 cupsd_printer_t
*p
, /* I - Printer */
1659 const char *values
, /* I - Plain text value (or NULL) */
1660 ipp_attribute_t
*attr
) /* I - IPP attribute value (or NULL) */
1662 int i
; /* Looping var */
1665 p
->num_auth_info_required
= 0;
1668 * Do we have a plain text value?
1674 * Yes, grab the keywords...
1677 const char *end
; /* End of current value */
1680 while (*values
&& p
->num_auth_info_required
< 4)
1682 if ((end
= strchr(values
, ',')) == NULL
)
1683 end
= values
+ strlen(values
);
1685 if ((end
- values
) == 4 && !strncmp(values
, "none", 4))
1687 if (p
->num_auth_info_required
!= 0 || *end
)
1690 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1691 p
->num_auth_info_required
++;
1695 else if ((end
- values
) == 9 && !strncmp(values
, "negotiate", 9))
1697 if (p
->num_auth_info_required
!= 0 || *end
)
1700 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1701 p
->num_auth_info_required
++;
1704 * Don't allow sharing of queues that require Kerberos authentication.
1709 cupsdDeregisterPrinter(p
, 1);
1713 else if ((end
- values
) == 6 && !strncmp(values
, "domain", 6))
1715 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1716 p
->num_auth_info_required
++;
1718 else if ((end
- values
) == 8 && !strncmp(values
, "password", 8))
1720 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1721 p
->num_auth_info_required
++;
1723 else if ((end
- values
) == 8 && !strncmp(values
, "username", 8))
1725 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1726 p
->num_auth_info_required
++;
1731 values
= (*end
) ? end
+ 1 : end
;
1734 if (p
->num_auth_info_required
== 0)
1736 p
->auth_info_required
[0] = "none";
1737 p
->num_auth_info_required
= 1;
1741 * Update the printer-type value as needed...
1744 if (p
->num_auth_info_required
> 1 ||
1745 strcmp(p
->auth_info_required
[0], "none"))
1746 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
1748 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
1754 * Grab values from an attribute instead...
1757 if (!attr
|| attr
->num_values
> 4)
1760 for (i
= 0; i
< attr
->num_values
; i
++)
1762 if (!strcmp(attr
->values
[i
].string
.text
, "none"))
1764 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1767 p
->auth_info_required
[p
->num_auth_info_required
] = "none";
1768 p
->num_auth_info_required
++;
1772 else if (!strcmp(attr
->values
[i
].string
.text
, "negotiate"))
1774 if (p
->num_auth_info_required
!= 0 || attr
->num_values
!= 1)
1777 p
->auth_info_required
[p
->num_auth_info_required
] = "negotiate";
1778 p
->num_auth_info_required
++;
1781 * Don't allow sharing of queues that require Kerberos authentication.
1786 cupsdDeregisterPrinter(p
, 1);
1792 else if (!strcmp(attr
->values
[i
].string
.text
, "domain"))
1794 p
->auth_info_required
[p
->num_auth_info_required
] = "domain";
1795 p
->num_auth_info_required
++;
1797 else if (!strcmp(attr
->values
[i
].string
.text
, "password"))
1799 p
->auth_info_required
[p
->num_auth_info_required
] = "password";
1800 p
->num_auth_info_required
++;
1802 else if (!strcmp(attr
->values
[i
].string
.text
, "username"))
1804 p
->auth_info_required
[p
->num_auth_info_required
] = "username";
1805 p
->num_auth_info_required
++;
1816 * 'cupsdSetDeviceURI()' - Set the device URI for a printer.
1820 cupsdSetDeviceURI(cupsd_printer_t
*p
, /* I - Printer */
1821 const char *uri
) /* I - Device URI */
1823 char buffer
[1024], /* URI buffer */
1824 *start
, /* Start of data after scheme */
1825 *slash
, /* First slash after scheme:// */
1826 *ptr
; /* Pointer into user@host:port part */
1830 * Set the full device URI..
1833 cupsdSetString(&(p
->device_uri
), uri
);
1836 * Copy the device URI to a temporary buffer so we can sanitize any auth
1840 strlcpy(buffer
, uri
, sizeof(buffer
));
1843 * Find the end of the scheme:// part...
1846 if ((ptr
= strchr(buffer
, ':')) != NULL
)
1848 for (start
= ptr
+ 1; *start
; start
++)
1853 * Find the next slash (/) in the URI...
1856 if ((slash
= strchr(start
, '/')) == NULL
)
1857 slash
= start
+ strlen(start
); /* No slash, point to the end */
1860 * Check for an @ sign before the slash...
1863 if ((ptr
= strchr(start
, '@')) != NULL
&& ptr
< slash
)
1866 * Found an @ sign and it is before the resource part, so we have
1867 * an authentication string. Copy the remaining URI over the
1868 * authentication string...
1871 _cups_strcpy(start
, ptr
+ 1);
1876 * Save the sanitized URI...
1879 cupsdSetString(&(p
->sanitized_device_uri
), buffer
);
1884 * 'cupsdSetPrinterAttr()' - Set a printer attribute.
1888 cupsdSetPrinterAttr(
1889 cupsd_printer_t
*p
, /* I - Printer */
1890 const char *name
, /* I - Attribute name */
1891 const char *value
) /* I - Attribute value string */
1893 ipp_attribute_t
*attr
; /* Attribute */
1894 int i
, /* Looping var */
1895 count
; /* Number of values */
1896 char *temp
, /* Temporary copy of value string */
1897 *ptr
, /* Pointer into value */
1898 *start
, /* Start of value */
1899 quote
; /* Quote character */
1900 ipp_tag_t value_tag
; /* Value tag for this attribute */
1904 * Don't allow empty values...
1907 if (!*value
&& strcmp(name
, "marker-message"))
1909 cupsdLogMessage(CUPSD_LOG_ERROR
, "Ignoring empty \"%s\" attribute", name
);
1914 * Copy the value string so we can do what we want with it...
1917 if ((temp
= strdup(value
)) == NULL
)
1919 cupsdLogMessage(CUPSD_LOG_ERROR
,
1920 "Unable to duplicate value for \"%s\" attribute.", name
);
1925 * Count the number of values...
1928 for (count
= 1, quote
= '\0', ptr
= temp
;
1936 else if (*ptr
== '\\' && ptr
[1])
1938 else if (*ptr
== '\'' || *ptr
== '\"')
1940 else if (*ptr
== ',')
1945 * Then add or update the attribute as needed...
1948 if (!strcmp(name
, "marker-levels") || !strcmp(name
, "marker-low-levels") ||
1949 !strcmp(name
, "marker-high-levels"))
1955 if ((attr
= ippFindAttribute(p
->attrs
, name
, IPP_TAG_INTEGER
)) != NULL
&&
1956 attr
->num_values
< count
)
1958 ippDeleteAttribute(p
->attrs
, attr
);
1963 attr
->num_values
= count
;
1965 attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, name
,
1971 cupsdLogMessage(CUPSD_LOG_ERROR
,
1972 "Unable to allocate memory for printer attribute "
1973 "(%d values)", count
);
1977 for (i
= 0, start
= temp
; i
< count
; i
++)
1979 if ((ptr
= strchr(start
, ',')) != NULL
)
1982 attr
->values
[i
].integer
= strtol(start
, NULL
, 10);
1991 * Name or keyword values...
1994 if (!strcmp(name
, "marker-types"))
1995 value_tag
= IPP_TAG_KEYWORD
;
1996 else if (!strcmp(name
, "marker-message"))
1997 value_tag
= IPP_TAG_TEXT
;
1999 value_tag
= IPP_TAG_NAME
;
2001 if ((attr
= ippFindAttribute(p
->attrs
, name
, value_tag
)) != NULL
&&
2002 attr
->num_values
< count
)
2004 ippDeleteAttribute(p
->attrs
, attr
);
2010 for (i
= 0; i
< attr
->num_values
; i
++)
2011 _cupsStrFree(attr
->values
[i
].string
.text
);
2013 attr
->num_values
= count
;
2016 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, value_tag
, name
,
2022 cupsdLogMessage(CUPSD_LOG_ERROR
,
2023 "Unable to allocate memory for printer attribute "
2024 "(%d values)", count
);
2028 for (i
= 0, quote
= '\0', ptr
= temp
; i
< count
; i
++)
2030 for (start
= ptr
; *ptr
; ptr
++)
2033 *ptr
= quote
= '\0';
2036 else if (*ptr
== '\\' && ptr
[1])
2037 _cups_strcpy(ptr
, ptr
+ 1);
2038 else if (*ptr
== '\'' || *ptr
== '\"')
2045 _cups_strcpy(ptr
, ptr
+ 1);
2047 else if (*ptr
== ',')
2054 attr
->values
[i
].string
.text
= _cupsStrAlloc(start
);
2061 * Update the printer-supply and printer-supply-description, as needed...
2064 if (!strcmp(name
, "marker-names"))
2066 ipp_attribute_t
*supply_desc
= ippFindAttribute(p
->attrs
, "printer-supply-description", IPP_TAG_TEXT
);
2067 /* printer-supply-description attribute */
2069 if (supply_desc
!= NULL
)
2070 ippDeleteAttribute(p
->attrs
, supply_desc
);
2072 supply_desc
= ippCopyAttribute(p
->attrs
, attr
, 0);
2073 ippSetName(p
->attrs
, &supply_desc
, "printer-supply-description");
2074 ippSetValueTag(p
->attrs
, &supply_desc
, IPP_TAG_TEXT
);
2076 else if (!strcmp(name
, "marker-colors") || !strcmp(name
, "marker-levels") || !strcmp(name
, "marker-types"))
2078 char buffer
[256], /* printer-supply values */
2079 pstype
[64], /* printer-supply type value */
2080 *psptr
; /* Pointer into type */
2081 const char *color
, /* marker-colors value */
2082 *type
; /* marker-types value */
2083 int level
; /* marker-levels value */
2084 ipp_attribute_t
*colors
= ippFindAttribute(p
->attrs
, "marker-colors", IPP_TAG_NAME
);
2085 /* marker-colors attribute */
2086 ipp_attribute_t
*levels
= ippFindAttribute(p
->attrs
, "marker-levels", IPP_TAG_INTEGER
);
2087 /* marker-levels attribute */
2088 ipp_attribute_t
*types
= ippFindAttribute(p
->attrs
, "marker-types", IPP_TAG_KEYWORD
);
2089 /* marker-types attribute */
2090 ipp_attribute_t
*supply
= ippFindAttribute(p
->attrs
, "printer-supply", IPP_TAG_STRING
);
2091 /* printer-supply attribute */
2095 ippDeleteAttribute(p
->attrs
, supply
);
2099 if (!colors
|| !levels
|| !types
)
2102 count
= ippGetCount(colors
);
2103 if (count
!= ippGetCount(levels
) || count
!= ippGetCount(types
))
2106 for (i
= 0; i
< count
; i
++)
2108 color
= ippGetString(colors
, i
, NULL
);
2109 level
= ippGetInteger(levels
, i
);
2110 type
= ippGetString(types
, i
, NULL
);
2112 for (psptr
= pstype
; *type
&& psptr
< (pstype
+ sizeof(pstype
) - 1); type
++)
2116 *psptr
++ = (char)toupper(*type
& 255);
2122 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
);
2125 supply
= ippAddOctetString(p
->attrs
, IPP_TAG_PRINTER
, "printer-supply", buffer
, (int)strlen(buffer
));
2127 ippSetOctetString(p
->attrs
, &supply
, i
, buffer
, (int)strlen(buffer
));
2134 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
2138 cupsdSetPrinterAttrs(cupsd_printer_t
*p
)/* I - Printer to setup */
2140 int i
; /* Looping var */
2141 char resource
[HTTP_MAX_URI
]; /* Resource portion of URI */
2142 cupsd_location_t
*auth
; /* Pointer to authentication element */
2143 const char *auth_supported
; /* Authentication supported */
2144 ipp_t
*oldattrs
; /* Old printer attributes */
2145 ipp_attribute_t
*attr
; /* Attribute data */
2146 char *name
, /* Current user/group name */
2147 *filter
; /* Current filter */
2150 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p
->name
,
2154 * Make sure that we have the common attributes defined...
2158 cupsdCreateCommonData();
2161 * Clear out old filters, if any...
2164 delete_printer_filters(p
);
2167 * Figure out the authentication that is required for the printer.
2170 auth_supported
= "requesting-user-name";
2172 if (p
->type
& CUPS_PRINTER_CLASS
)
2173 snprintf(resource
, sizeof(resource
), "/classes/%s", p
->name
);
2175 snprintf(resource
, sizeof(resource
), "/printers/%s", p
->name
);
2177 if ((auth
= cupsdFindBest(resource
, HTTP_POST
)) == NULL
||
2178 auth
->type
== CUPSD_AUTH_NONE
)
2179 auth
= cupsdFindPolicyOp(p
->op_policy_ptr
, IPP_PRINT_JOB
);
2183 int auth_type
; /* Authentication type */
2186 if ((auth_type
= auth
->type
) == CUPSD_AUTH_DEFAULT
)
2187 auth_type
= cupsdDefaultAuthType();
2189 if (auth_type
== CUPSD_AUTH_BASIC
)
2190 auth_supported
= "basic";
2192 else if (auth_type
== CUPSD_AUTH_NEGOTIATE
)
2193 auth_supported
= "negotiate";
2194 #endif /* HAVE_GSSAPI */
2196 if (auth_type
!= CUPSD_AUTH_NONE
)
2197 p
->type
|= CUPS_PRINTER_AUTHENTICATED
;
2199 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2202 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_AUTHENTICATED
;
2205 * Create the required IPP attributes for a printer...
2208 oldattrs
= p
->attrs
;
2209 p
->attrs
= ippNew();
2211 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2212 "uri-authentication-supported", NULL
, auth_supported
);
2213 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2214 "uri-security-supported", NULL
, "none");
2215 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "printer-name", NULL
,
2217 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
2218 NULL
, p
->location
? p
->location
: "");
2219 if (p
->geo_location
)
2220 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-geo-location", NULL
, p
->geo_location
);
2222 ippAddOutOfBand(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_UNKNOWN
, "printer-geo-location");
2223 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
2224 NULL
, p
->info
? p
->info
: "");
2225 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organization", NULL
, p
->organization
? p
->organization
: "");
2226 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-organizational-unit", NULL
, p
->organizational_unit
? p
->organizational_unit
: "");
2227 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "printer-uuid", NULL
, p
->uuid
);
2229 if (cupsArrayCount(p
->users
) > 0)
2232 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2233 "requesting-user-name-denied",
2234 cupsArrayCount(p
->users
), NULL
, NULL
);
2236 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2237 "requesting-user-name-allowed",
2238 cupsArrayCount(p
->users
), NULL
, NULL
);
2240 for (i
= 0, name
= (char *)cupsArrayFirst(p
->users
);
2242 i
++, name
= (char *)cupsArrayNext(p
->users
))
2243 attr
->values
[i
].string
.text
= _cupsStrAlloc(name
);
2246 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2247 "job-quota-period", p
->quota_period
);
2248 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2249 "job-k-limit", p
->k_limit
);
2250 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2251 "job-page-limit", p
->page_limit
);
2252 if (p
->num_auth_info_required
> 0 && strcmp(p
->auth_info_required
[0], "none"))
2253 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2254 "auth-info-required", p
->num_auth_info_required
, NULL
,
2255 p
->auth_info_required
);
2257 if (cupsArrayCount(Banners
) > 0)
2260 * Setup the job-sheets-default attribute...
2263 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2264 "job-sheets-default", 2, NULL
, NULL
);
2268 attr
->values
[0].string
.text
= _cupsStrAlloc(Classification
?
2269 Classification
: p
->job_sheets
[0]);
2270 attr
->values
[1].string
.text
= _cupsStrAlloc(Classification
?
2271 Classification
: p
->job_sheets
[1]);
2279 * Assign additional attributes depending on whether this is a printer
2283 if (p
->type
& CUPS_PRINTER_CLASS
)
2286 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
2289 * Add class-specific attributes...
2292 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
2293 "printer-make-and-model", NULL
, "Local Printer Class");
2294 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2295 "file:///dev/null");
2297 if (p
->num_printers
> 0)
2300 * Add a list of member names; URIs are added in copy_printer_attrs...
2303 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2304 "member-names", p
->num_printers
, NULL
, NULL
);
2305 p
->type
|= CUPS_PRINTER_OPTIONS
;
2307 for (i
= 0; i
< p
->num_printers
; i
++)
2310 attr
->values
[i
].string
.text
= _cupsStrAlloc(p
->printers
[i
]->name
);
2312 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
| p
->printers
[i
]->type
;
2319 * Add printer-specific attributes...
2322 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
2323 p
->sanitized_device_uri
);
2326 * Assign additional attributes from the PPD file (if any)...
2332 * Add filters for printer...
2335 cupsdSetPrinterReasons(p
, "-cups-missing-filter-warning,"
2336 "cups-insecure-filter-warning");
2338 if (p
->pc
&& p
->pc
->filters
)
2340 for (filter
= (char *)cupsArrayFirst(p
->pc
->filters
);
2342 filter
= (char *)cupsArrayNext(p
->pc
->filters
))
2343 add_printer_filter(p
, p
->filetype
, filter
);
2345 else if (!(p
->type
& CUPS_PRINTER_REMOTE
))
2348 * Add a filter from application/vnd.cups-raw to printer/name to
2349 * handle "raw" printing by users.
2352 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2355 * Add a PostScript filter, since this is still possibly PS printer.
2358 add_printer_filter(p
, p
->filetype
,
2359 "application/vnd.cups-postscript 0 -");
2362 if (p
->pc
&& p
->pc
->prefilters
)
2364 if (!p
->prefiltertype
)
2365 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2367 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2369 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2370 add_printer_filter(p
, p
->prefiltertype
, filter
);
2375 * Copy marker attributes as needed...
2380 ipp_attribute_t
*oldattr
; /* Old attribute */
2383 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2384 IPP_TAG_NAME
)) != NULL
)
2386 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2387 "marker-colors", oldattr
->num_values
, NULL
,
2390 for (i
= 0; i
< oldattr
->num_values
; i
++)
2391 attr
->values
[i
].string
.text
=
2392 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2396 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2397 IPP_TAG_INTEGER
)) != NULL
)
2399 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2400 "marker-levels", oldattr
->num_values
,
2403 for (i
= 0; i
< oldattr
->num_values
; i
++)
2404 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2408 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2409 IPP_TAG_TEXT
)) != NULL
)
2410 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2411 NULL
, oldattr
->values
[0].string
.text
);
2413 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2414 IPP_TAG_INTEGER
)) != NULL
)
2416 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2417 "marker-low-levels", oldattr
->num_values
,
2420 for (i
= 0; i
< oldattr
->num_values
; i
++)
2421 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2425 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2426 IPP_TAG_INTEGER
)) != NULL
)
2428 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2429 "marker-high-levels", oldattr
->num_values
,
2432 for (i
= 0; i
< oldattr
->num_values
; i
++)
2433 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2437 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2438 IPP_TAG_NAME
)) != NULL
)
2440 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2441 "marker-names", oldattr
->num_values
, NULL
,
2444 for (i
= 0; i
< oldattr
->num_values
; i
++)
2445 attr
->values
[i
].string
.text
=
2446 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2450 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2451 IPP_TAG_KEYWORD
)) != NULL
)
2453 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2454 "marker-types", oldattr
->num_values
, NULL
,
2457 for (i
= 0; i
< oldattr
->num_values
; i
++)
2458 attr
->values
[i
].string
.text
=
2459 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2463 ippDelete(oldattrs
);
2467 * Force sharing off for remote queues...
2470 if (p
->type
& CUPS_PRINTER_REMOTE
)
2474 * Populate the document-format-supported attribute...
2477 add_printer_formats(p
);
2479 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2483 * Add name-default attributes...
2486 add_printer_defaults(p
);
2489 * Let the browse protocols reflect the change
2492 cupsdRegisterPrinter(p
);
2497 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2500 int /* O - 1 if something changed, 0 otherwise */
2501 cupsdSetPrinterReasons(
2502 cupsd_printer_t
*p
, /* I - Printer */
2503 const char *s
) /* I - Reasons strings */
2505 int i
, /* Looping var */
2506 changed
= 0; /* Did something change? */
2507 const char *sptr
; /* Pointer into reasons */
2508 char reason
[255], /* Reason string */
2509 *rptr
; /* Pointer into reason */
2512 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2513 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2515 if (s
[0] == '-' || s
[0] == '+')
2518 * Add/remove reasons...
2526 * Replace reasons...
2531 for (i
= 0; i
< p
->num_reasons
; i
++)
2532 _cupsStrFree(p
->reasons
[i
]);
2540 if (!strcmp(s
, "none"))
2544 * Loop through all of the reasons...
2550 * Skip leading whitespace and commas...
2553 while (isspace(*sptr
& 255) || *sptr
== ',')
2556 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2557 if (rptr
< (reason
+ sizeof(reason
) - 1))
2571 for (i
= 0; i
< p
->num_reasons
; i
++)
2572 if (!strcmp(reason
, p
->reasons
[i
]))
2575 * Found a match, so remove it...
2580 _cupsStrFree(p
->reasons
[i
]);
2582 if (i
< p
->num_reasons
)
2583 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2585 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2586 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2588 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2589 p
->job
->completed
= 0;
2591 if (strcmp(reason
, "connecting-to-device"))
2597 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2603 for (i
= 0; i
< p
->num_reasons
; i
++)
2604 if (!strcmp(reason
, p
->reasons
[i
]))
2607 if (i
>= p
->num_reasons
)
2609 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2611 cupsdLogMessage(CUPSD_LOG_ALERT
,
2612 "Too many printer-state-reasons values for %s (%d)",
2617 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2621 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2622 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2624 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2625 p
->job
->completed
= 1;
2627 if (strcmp(reason
, "connecting-to-device"))
2638 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2642 cupsdSetPrinterState(
2643 cupsd_printer_t
*p
, /* I - Printer to change */
2644 ipp_pstate_t s
, /* I - New state */
2645 int update
) /* I - Update printers.conf? */
2647 cupsd_job_t
*job
; /* Current job */
2648 ipp_pstate_t old_state
; /* Old printer state */
2649 static const char * const printer_states
[] =
2650 { /* State strings */
2658 * Set the new state...
2661 old_state
= p
->state
;
2666 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2667 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2668 "%s \"%s\" state changed to %s.",
2669 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2670 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2673 * Let the browse code know this needs to be updated...
2676 p
->state_time
= time(NULL
);
2680 * Set/clear the paused reason as needed...
2683 if (s
== IPP_PRINTER_STOPPED
)
2684 cupsdSetPrinterReasons(p
, "+paused");
2686 cupsdSetPrinterReasons(p
, "-paused");
2690 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2692 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2693 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2694 !_cups_strcasecmp(job
->dest
, p
->name
))
2695 ippSetString(job
->attrs
, &job
->reasons
, 0,
2696 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2700 * Clear the message for the queue when going to processing...
2703 if (s
== IPP_PRINTER_PROCESSING
)
2704 p
->state_message
[0] = '\0';
2707 * Let the browse protocols reflect the change...
2711 cupsdRegisterPrinter(p
);
2714 * Save the printer configuration if a printer goes from idle or processing
2715 * to stopped (or visa-versa)...
2719 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2725 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2729 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2730 int update
)/* I - Update printers.conf? */
2733 * Set the printer state...
2736 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2739 * See if we have a job printing on this printer...
2742 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2743 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2744 "Job stopped due to printer being paused.");
2749 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2752 int /* O - 1 if successful, 0 otherwise */
2753 cupsdUpdatePrinterPPD(
2754 cupsd_printer_t
*p
, /* I - Printer */
2755 int num_keywords
, /* I - Number of keywords */
2756 cups_option_t
*keywords
) /* I - Keywords */
2758 int i
; /* Looping var */
2759 cups_file_t
*src
, /* Original file */
2760 *dst
; /* New file */
2761 char srcfile
[1024], /* Original filename */
2762 dstfile
[1024], /* New filename */
2763 line
[1024], /* Line from file */
2764 keystring
[41]; /* Keyword from line */
2765 cups_option_t
*keyword
; /* Current keyword */
2768 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2772 * Get the old and new PPD filenames...
2775 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2776 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2779 * Rename the old file and open the old and new...
2782 if (rename(dstfile
, srcfile
))
2784 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2785 p
->name
, strerror(errno
));
2789 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2791 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2792 srcfile
, strerror(errno
));
2793 rename(srcfile
, dstfile
);
2797 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2799 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2800 dstfile
, strerror(errno
));
2802 rename(srcfile
, dstfile
);
2807 * Copy the first line and then write out all of the keywords...
2810 if (!cupsFileGets(src
, line
, sizeof(line
)))
2812 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2813 srcfile
, strerror(errno
));
2816 rename(srcfile
, dstfile
);
2820 cupsFilePrintf(dst
, "%s\n", line
);
2822 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2824 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2825 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2829 * Then copy the rest of the PPD file, dropping any keywords we changed.
2832 while (cupsFileGets(src
, line
, sizeof(line
)))
2835 * Skip keywords we've already set...
2838 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2839 cupsGetOption(keystring
, num_keywords
, keywords
))
2843 * Otherwise write the line...
2846 cupsFilePrintf(dst
, "%s\n", line
);
2850 * Close files and return...
2861 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2865 cupsdUpdatePrinters(void)
2867 cupsd_printer_t
*p
; /* Current printer */
2871 * Loop through the printers and recreate the printer attributes
2872 * for any local printers since the policy and/or access control
2873 * stuff may have changed. Also, if browsing is disabled, remove
2874 * any remote printers...
2877 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2879 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2882 * Update the operation policy pointer...
2885 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2886 p
->op_policy_ptr
= DefaultPolicyPtr
;
2889 * Update printer attributes...
2892 cupsdSetPrinterAttrs(p
);
2898 * 'cupsdValidateDest()' - Validate a printer/class destination.
2901 const char * /* O - Printer or class name */
2903 const char *uri
, /* I - Printer URI */
2904 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2905 cupsd_printer_t
**printer
) /* O - Printer pointer */
2907 cupsd_printer_t
*p
; /* Current printer */
2908 char localname
[1024],/* Localized hostname */
2909 *lptr
, /* Pointer into localized hostname */
2910 *sptr
, /* Pointer into server name */
2911 *rptr
, /* Pointer into resource */
2912 scheme
[32], /* Scheme portion of URI */
2913 username
[64], /* Username portion of URI */
2914 hostname
[HTTP_MAX_HOST
],
2915 /* Host portion of URI */
2916 resource
[HTTP_MAX_URI
];
2917 /* Resource portion of URI */
2918 int port
; /* Port portion of URI */
2921 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2925 * Initialize return values...
2932 *dtype
= (cups_ptype_t
)0;
2935 * Pull the hostname and resource from the URI...
2938 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2939 username
, sizeof(username
), hostname
, sizeof(hostname
),
2940 &port
, resource
, sizeof(resource
));
2943 * See if the resource is a class or printer...
2946 if (!strncmp(resource
, "/classes/", 9))
2952 rptr
= resource
+ 9;
2954 else if (!strncmp(resource
, "/printers/", 10))
2960 rptr
= resource
+ 10;
2965 * Bad resource name...
2972 * See if the printer or class name exists...
2975 p
= cupsdFindDest(rptr
);
2977 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
2985 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2991 * Change localhost to the server name...
2994 if (!_cups_strcasecmp(hostname
, "localhost"))
2995 strlcpy(hostname
, ServerName
, sizeof(hostname
));
2997 strlcpy(localname
, hostname
, sizeof(localname
));
2999 if (!_cups_strcasecmp(hostname
, ServerName
))
3002 * Localize the hostname...
3005 lptr
= strchr(localname
, '.');
3006 sptr
= strchr(ServerName
, '.');
3008 if (sptr
!= NULL
&& lptr
!= NULL
)
3011 * Strip the common domain name components...
3014 while (lptr
!= NULL
)
3016 if (!_cups_strcasecmp(lptr
, sptr
))
3022 lptr
= strchr(lptr
+ 1, '.');
3027 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3030 * Find a matching printer or class...
3033 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3035 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3036 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3037 !_cups_strcasecmp(p
->name
, rptr
))
3043 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3053 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3058 cupsdWritePrintcap(void)
3060 int i
; /* Looping var */
3061 cups_file_t
*fp
; /* Printcap file */
3062 cupsd_printer_t
*p
; /* Current printer */
3066 * See if we have a printcap file; if not, don't bother writing it.
3069 if (!Printcap
|| !*Printcap
)
3072 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3075 * Open the printcap file...
3078 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3082 * Put a comment header at the top so that users will know where the
3083 * data has come from...
3086 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3087 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3089 "# %s/printers.conf file. All changes to this file\n"
3090 "# will be lost.\n", ServerRoot
);
3093 * Write a new printcap with the current list of printers.
3096 switch (PrintcapFormat
)
3100 * Each printer is put in the file as:
3110 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3111 DefaultPrinter
->info
, ServerName
,
3112 DefaultPrinter
->name
);
3114 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3116 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3117 if (p
!= DefaultPrinter
)
3118 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3119 ServerName
, p
->name
);
3122 case PRINTCAP_PLIST
:
3124 * Each printer is written as a dictionary in a plist file.
3125 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3126 * printer-location, printer-make-and-model, printer-state,
3127 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3130 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3131 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3132 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3133 "PropertyList-1.0.dtd\">\n"
3134 "<plist version=\"1.0\">\n"
3137 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3139 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3141 cupsFilePuts(fp
, "\t<dict>\n"
3142 "\t\t<key>printer-name</key>\n"
3144 write_xml_string(fp
, p
->name
);
3145 cupsFilePuts(fp
, "</string>\n"
3146 "\t\t<key>printer-info</key>\n"
3148 write_xml_string(fp
, p
->info
);
3149 cupsFilePrintf(fp
, "</string>\n"
3150 "\t\t<key>printer-is-accepting-jobs</key>\n"
3152 "\t\t<key>printer-location</key>\n"
3153 "\t\t<string>", p
->accepting
? "true" : "false");
3154 write_xml_string(fp
, p
->location
);
3155 cupsFilePuts(fp
, "</string>\n"
3156 "\t\t<key>printer-make-and-model</key>\n"
3158 write_xml_string(fp
, p
->make_model
);
3159 cupsFilePrintf(fp
, "</string>\n"
3160 "\t\t<key>printer-state</key>\n"
3161 "\t\t<integer>%d</integer>\n"
3162 "\t\t<key>printer-state-reasons</key>\n"
3163 "\t\t<array>\n", p
->state
);
3164 for (i
= 0; i
< p
->num_reasons
; i
++)
3166 cupsFilePuts(fp
, "\t\t\t<string>");
3167 write_xml_string(fp
, p
->reasons
[i
]);
3168 cupsFilePuts(fp
, "</string>\n");
3170 cupsFilePrintf(fp
, "\t\t</array>\n"
3171 "\t\t<key>printer-type</key>\n"
3172 "\t\t<integer>%d</integer>\n"
3173 "\t\t<key>device-uri</key>\n"
3174 "\t\t<string>", p
->type
);
3175 write_xml_string(fp
, p
->sanitized_device_uri
);
3176 cupsFilePuts(fp
, "</string>\n"
3179 cupsFilePuts(fp
, "</array>\n"
3183 case PRINTCAP_SOLARIS
:
3185 * Each printer is put in the file as:
3187 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3188 * _default:use=DefaultPrinter
3190 * :bsdaddr=ServerName,Printer1:\
3191 * :description=Description:
3193 * :bsdaddr=ServerName,Printer2:\
3194 * :description=Description:
3196 * :bsdaddr=ServerName,Printer3:\
3197 * :description=Description:
3200 * :bsdaddr=ServerName,PrinterN:\
3201 * :description=Description:
3204 cupsFilePuts(fp
, "_all:all=");
3205 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3207 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3208 cupsFilePrintf(fp
, "%s%c", p
->name
,
3209 cupsArrayNext(Printers
) ? ',' : '\n');
3212 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3214 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3216 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3217 cupsFilePrintf(fp
, "%s:\\\n"
3218 "\t:bsdaddr=%s,%s:\\\n"
3219 "\t:description=%s:\n",
3220 p
->name
, ServerName
, p
->name
,
3221 p
->info
? p
->info
: "");
3234 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3238 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3240 int i
; /* Looping var */
3241 int num_options
; /* Number of default options */
3242 cups_option_t
*options
, /* Default options */
3243 *option
; /* Current option */
3244 char name
[256]; /* name-default */
3248 * Maintain a common array of default attribute names...
3251 if (!CommonDefaults
)
3253 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3255 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3256 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3257 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3258 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3259 cupsArrayAdd(CommonDefaults
,
3260 _cupsStrAlloc("job-accounting-user-id-default"));
3261 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3262 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3263 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3264 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3265 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3266 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3267 cupsArrayAdd(CommonDefaults
,
3268 _cupsStrAlloc("orientation-requested-default"));
3272 * Add all of the default options from the .conf files...
3275 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3279 if (strcmp(option
->name
, "ipp-options") &&
3280 strcmp(option
->name
, "job-sheets") &&
3281 strcmp(option
->name
, "lease-duration"))
3283 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3284 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3286 if (!cupsArrayFind(CommonDefaults
, name
))
3287 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3292 * Convert options to IPP attributes...
3295 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3296 cupsFreeOptions(num_options
, options
);
3299 * Add standard -default attributes as needed...
3302 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3303 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3306 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3307 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3308 "document-format-default", NULL
, "application/octet-stream");
3310 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3311 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3312 "job-cancel-after-default", MaxJobTime
);
3314 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3315 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3316 "job-hold-until-default", NULL
, "no-hold");
3318 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3319 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3320 "job-priority-default", 50);
3322 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3323 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3324 "number-up-default", 1);
3326 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3327 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3328 "notify-lease-duration-default", DefaultLeaseDuration
);
3330 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3331 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3332 "notify-events-default", NULL
, "job-completed");
3334 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3335 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3336 "orientation-requested-default", NULL
, NULL
);
3338 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3339 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3340 "print-quality-default", IPP_QUALITY_NORMAL
);
3345 * 'add_printer_filter()' - Add a MIME filter for a printer.
3350 cupsd_printer_t
*p
, /* I - Printer to add to */
3351 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3352 const char *filter
) /* I - Filter to add */
3354 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3355 type
[MIME_MAX_TYPE
], /* Type for filter */
3356 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3357 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3358 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3359 /* Destination super/type */
3360 program
[1024]; /* Program/filter name */
3361 int cost
; /* Cost of filter */
3362 size_t maxsize
= 0; /* Maximum supported file size */
3363 mime_type_t
*temptype
, /* MIME type looping var */
3364 *desttype
; /* Destination MIME type */
3365 mime_filter_t
*filterptr
; /* MIME filter */
3366 char filename
[1024]; /* Full filter filename */
3369 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3370 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3371 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3372 filtertype
->type
, filter
);
3375 * Parse the filter string; it should be in one of the following formats:
3377 * source/type cost program
3378 * source/type cost maxsize(nnnn) program
3379 * source/type dest/type cost program
3380 * source/type dest/type cost maxsize(nnnn) program
3383 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3384 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3386 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3388 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3390 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3392 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3394 cupsArrayAdd(p
->dest_types
, desttype
);
3400 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3403 desttype
= filtertype
;
3407 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3413 if (!strncmp(program
, "maxsize(", 8))
3415 char *ptr
; /* Pointer into maxsize(nnnn) program */
3417 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3421 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3427 while (_cups_isspace(*ptr
))
3430 _cups_strcpy(program
, ptr
);
3434 * Check permissions on the filter and its containing directory...
3437 if (strcmp(program
, "-"))
3439 if (program
[0] == '/')
3440 strlcpy(filename
, program
, sizeof(filename
));
3442 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3444 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3445 cupsdLogFCMessage
, p
);
3449 * Add the filter to the MIME database, supporting wildcards as needed...
3452 for (temptype
= mimeFirstType(MimeDatabase
);
3454 temptype
= mimeNextType(MimeDatabase
))
3455 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3456 !_cups_strcasecmp(temptype
->super
, super
)) &&
3457 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3459 if (desttype
!= filtertype
)
3461 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3462 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3463 "%s", p
->name
, temptype
->super
, temptype
->type
,
3464 desttype
->super
, desttype
->type
,
3466 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3469 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3471 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3472 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3473 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3474 filtertype
->super
, filtertype
->type
);
3475 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3480 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3481 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3482 "%s", p
->name
, temptype
->super
, temptype
->type
,
3483 filtertype
->super
, filtertype
->type
,
3485 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3490 filterptr
->maxsize
= maxsize
;
3496 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3500 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3502 int i
; /* Looping var */
3503 mime_type_t
*type
; /* Current MIME type */
3504 cups_array_t
*filters
; /* Filters */
3505 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3506 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3507 /* MIME type name */
3511 * Raw (and remote) queues advertise all of the supported MIME
3515 cupsArrayDelete(p
->filetypes
);
3516 p
->filetypes
= NULL
;
3520 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3521 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3522 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3527 * Otherwise, loop through the supported MIME types and see if there
3528 * are filters for them...
3531 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3532 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3534 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3536 for (type
= mimeFirstType(MimeDatabase
);
3538 type
= mimeNextType(MimeDatabase
))
3540 if (!_cups_strcasecmp(type
->super
, "printer"))
3543 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3545 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3547 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3548 "add_printer_formats: %s: %s needs %d filters",
3549 p
->name
, mimetype
, cupsArrayCount(filters
));
3551 cupsArrayDelete(filters
);
3552 cupsArrayAdd(p
->filetypes
, type
);
3555 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3556 "add_printer_formats: %s: %s not supported",
3561 * Add the file formats that can be filtered...
3564 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3565 !cupsArrayFind(p
->filetypes
, type
))
3570 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3571 "add_printer_formats: %s: %d supported types",
3572 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3574 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3575 "document-format-supported",
3576 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3579 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3581 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3583 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3585 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3587 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3590 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3592 char pdl
[1024]; /* Buffer to build pdl list */
3593 mime_filter_t
*filter
; /* MIME filter looping var */
3597 * We only support raw printing if this is not a Tioga PrintJobMgr based
3598 * queue and if application/octet-stream is a known type...
3601 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3603 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3605 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3611 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3612 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3615 * Then list a bunch of formats that are supported by the printer...
3618 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3620 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3622 if (!_cups_strcasecmp(type
->super
, "application"))
3624 if (!_cups_strcasecmp(type
->type
, "pdf"))
3625 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3626 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3627 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3629 else if (!_cups_strcasecmp(type
->super
, "image"))
3631 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3632 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3633 else if (!_cups_strcasecmp(type
->type
, "png"))
3634 strlcat(pdl
, "image/png,", sizeof(pdl
));
3635 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3636 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3641 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3643 cupsdSetString(&p
->pdl
, pdl
);
3645 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3650 * 'compare_printers()' - Compare two printers.
3653 static int /* O - Result of comparison */
3654 compare_printers(void *first
, /* I - First printer */
3655 void *second
, /* I - Second printer */
3656 void *data
) /* I - App data (not used) */
3660 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3661 ((cupsd_printer_t
*)second
)->name
));
3666 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3670 delete_printer_filters(
3671 cupsd_printer_t
*p
) /* I - Printer to remove from */
3673 mime_filter_t
*filter
; /* MIME filter looping var */
3674 mime_type_t
*type
; /* Destination types for filters */
3678 * Range check input...
3685 * Remove all filters from the MIME database that have a destination
3686 * type == printer...
3689 for (filter
= mimeFirstFilter(MimeDatabase
);
3691 filter
= mimeNextFilter(MimeDatabase
))
3692 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3693 cupsArrayFind(p
->dest_types
, filter
->dst
))
3696 * Delete the current filter...
3699 mimeDeleteFilter(MimeDatabase
, filter
);
3702 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3704 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3705 mimeDeleteType(MimeDatabase
, type
);
3707 cupsArrayDelete(p
->dest_types
);
3708 p
->dest_types
= NULL
;
3710 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3711 ",cups-missing-filter-warning");
3716 * 'dirty_printer()' - Mark config and state files dirty for the specified
3721 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3723 if (p
->type
& CUPS_PRINTER_CLASS
)
3724 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3726 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3728 if (PrintcapFormat
== PRINTCAP_PLIST
)
3729 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3734 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3738 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3740 int i
, j
, k
; /* Looping vars */
3741 char cache_name
[1024]; /* Cache filename */
3742 struct stat cache_info
; /* Cache file info */
3743 ppd_file_t
*ppd
; /* PPD file */
3744 char ppd_name
[1024]; /* PPD filename */
3745 struct stat ppd_info
; /* PPD file info */
3746 int num_media
; /* Number of media options */
3747 ppd_size_t
*size
; /* Current PPD size */
3748 ppd_option_t
*duplex
, /* Duplex option */
3749 *output_bin
, /* OutputBin option */
3750 *output_mode
, /* OutputMode option */
3751 *resolution
; /* (Set|JCL|)Resolution option */
3752 ppd_choice_t
*choice
, /* Current PPD choice */
3753 *input_slot
, /* Current input slot */
3754 *media_type
; /* Current media type */
3755 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3756 int xdpi
, /* Horizontal resolution */
3757 ydpi
; /* Vertical resolution */
3758 const char *resptr
; /* Pointer into resolution keyword */
3759 _pwg_size_t
*pwgsize
; /* Current PWG size */
3760 _pwg_map_t
*pwgsource
, /* Current PWG source */
3761 *pwgtype
; /* Current PWG type */
3762 ipp_attribute_t
*attr
; /* Attribute data */
3763 _ipp_value_t
*val
; /* Attribute value */
3764 int num_finishings
, /* Number of finishings */
3765 finishings
[5]; /* finishings-supported values */
3766 int num_qualities
, /* Number of print-quality values */
3767 qualities
[3]; /* print-quality values */
3768 int num_margins
, /* Number of media-*-margin-supported values */
3769 margins
[16]; /* media-*-margin-supported values */
3770 const char *filter
, /* Current filter */
3771 *mandatory
; /* Current mandatory attribute */
3772 static const char * const sides
[3] = /* sides-supported values */
3775 "two-sided-long-edge",
3776 "two-sided-short-edge"
3778 static const char * const standard_commands
[] =
3779 { /* Standard CUPS commands */
3787 * Check to see if the cache is up-to-date...
3790 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3791 if (stat(cache_name
, &cache_info
))
3792 cache_info
.st_mtime
= 0;
3794 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3795 if (stat(ppd_name
, &ppd_info
))
3796 ppd_info
.st_mtime
= 1;
3798 ippDelete(p
->ppd_attrs
);
3799 p
->ppd_attrs
= NULL
;
3801 _ppdCacheDestroy(p
->pc
);
3804 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3806 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3808 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3812 * Loaded successfully!
3820 * Reload PPD attributes from disk...
3823 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3825 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3827 cupsdClearString(&(p
->make_model
));
3829 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3830 p
->type
|= CUPS_PRINTER_BW
;
3832 finishings
[0] = IPP_FINISHINGS_NONE
;
3835 p
->ppd_attrs
= ippNew();
3837 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3840 * Add make/model and other various attributes...
3843 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3846 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3847 ppd_name
, cupsLastErrorString());
3849 ppdMarkDefaults(ppd
);
3851 if (ppd
->color_device
)
3852 p
->type
|= CUPS_PRINTER_COLOR
;
3853 if (ppd
->variable_sizes
)
3854 p
->type
|= CUPS_PRINTER_VARIABLE
;
3855 if (!ppd
->manual_copies
)
3856 p
->type
|= CUPS_PRINTER_COPIES
;
3857 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3858 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3859 p
->type
|= CUPS_PRINTER_FAX
;
3861 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3863 if (p
->pc
&& p
->pc
->charge_info_uri
)
3864 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3865 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3867 if (p
->pc
&& p
->pc
->account_id
)
3868 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3871 if (p
->pc
&& p
->pc
->accounting_user_id
)
3872 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3873 "job-accounting-user-id-supported", 1);
3875 if (p
->pc
&& p
->pc
->password
)
3877 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3878 "job-password-encryption-supported", NULL
, "none");
3879 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3880 "job-password-supported", (int)strlen(p
->pc
->password
));
3883 if (ppd
->throughput
)
3885 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3886 "pages-per-minute", ppd
->throughput
);
3887 if (ppd
->color_device
)
3888 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3889 "pages-per-minute-color", ppd
->throughput
);
3894 * When there is no speed information, just say "1 page per minute".
3897 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3898 "pages-per-minute", 1);
3899 if (ppd
->color_device
)
3900 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3901 "pages-per-minute-color", 1);
3904 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3905 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3909 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3911 if (ppdFindChoice(output_mode
, "draft") ||
3912 ppdFindChoice(output_mode
, "fast"))
3913 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3915 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3917 if (ppdFindChoice(output_mode
, "best") ||
3918 ppdFindChoice(output_mode
, "high"))
3919 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3921 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3925 if (strstr(ppd_attr
->spec
, "draft") ||
3926 strstr(ppd_attr
->spec
, "Draft"))
3928 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3932 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3935 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3936 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3939 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3941 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3942 "print-quality-supported", num_qualities
, qualities
);
3947 * The NickName can be localized in the character set specified
3948 * by the LanugageEncoding attribute. However, ppdOpen2() has
3949 * already converted the ppd->nickname member to UTF-8 for us
3950 * (the original attribute value is available separately)
3953 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3955 else if (ppd
->modelname
)
3958 * Model name can only contain specific characters...
3961 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3964 cupsdSetString(&p
->make_model
, "Bad PPD File");
3966 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3967 "printer-make-and-model", NULL
, p
->make_model
);
3970 * Add media options from the PPD file...
3973 if (ppd
->num_sizes
== 0 || !p
->pc
)
3975 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
) && !ppdFindAttr(ppd
, "cups3D", NULL
))
3976 cupsdLogMessage(CUPSD_LOG_CRIT
,
3977 "The PPD file for printer %s contains no media "
3978 "options and is therefore invalid.", p
->name
);
3980 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3981 "media-default", NULL
, "unknown");
3982 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3983 "media-supported", NULL
, "unknown");
3991 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
3992 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
3996 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3997 "media-default", NULL
,
3998 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4006 ipp_t
*col
; /* Collection value */
4008 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4009 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4010 col
= new_media_col(pwgsize
,
4012 _ppdCacheGetSource(p
->pc
,
4013 input_slot
->choice
) :
4016 _ppdCacheGetType(p
->pc
,
4017 media_type
->choice
) :
4020 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4029 num_media
= p
->pc
->num_sizes
;
4030 if (p
->pc
->custom_min_keyword
)
4033 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4034 "media-supported", num_media
, NULL
,
4039 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4041 i
--, pwgsize
++, val
++)
4042 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4044 if (p
->pc
->custom_min_keyword
)
4046 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4048 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4053 * media-size-supported
4056 num_media
= p
->pc
->num_sizes
;
4057 if (p
->pc
->custom_min_keyword
)
4060 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4061 "media-size-supported", num_media
,
4066 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4068 i
--, pwgsize
++, val
++)
4070 val
->collection
= ippNew();
4071 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4072 "x-dimension", pwgsize
->width
);
4073 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4074 "y-dimension", pwgsize
->length
);
4077 if (p
->pc
->custom_min_keyword
)
4079 val
->collection
= ippNew();
4080 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4081 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4082 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4083 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4088 * media-source-supported
4091 if (p
->pc
->num_sources
> 0 &&
4092 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4093 "media-source-supported", p
->pc
->num_sources
,
4094 NULL
, NULL
)) != NULL
)
4096 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4099 i
--, pwgsource
++, val
++)
4100 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4104 * media-type-supported
4107 if (p
->pc
->num_types
> 0 &&
4108 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4109 "media-type-supported", p
->pc
->num_types
,
4110 NULL
, NULL
)) != NULL
)
4112 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4115 i
--, pwgtype
++, val
++)
4116 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4120 * media-*-margin-supported
4123 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4124 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4127 for (j
= 0; j
< num_margins
; j
++)
4128 if (pwgsize
->bottom
== margins
[j
])
4131 if (j
>= num_margins
)
4133 margins
[num_margins
] = pwgsize
->bottom
;
4138 if (num_margins
> 0)
4139 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4140 "media-bottom-margin-supported", num_margins
, margins
);
4142 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4143 "media-bottom-margin-supported", 0);
4145 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4146 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4149 for (j
= 0; j
< num_margins
; j
++)
4150 if (pwgsize
->left
== margins
[j
])
4153 if (j
>= num_margins
)
4155 margins
[num_margins
] = pwgsize
->left
;
4160 if (num_margins
> 0)
4161 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4162 "media-left-margin-supported", num_margins
, margins
);
4164 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4165 "media-left-margin-supported", 0);
4167 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4168 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4171 for (j
= 0; j
< num_margins
; j
++)
4172 if (pwgsize
->right
== margins
[j
])
4175 if (j
>= num_margins
)
4177 margins
[num_margins
] = pwgsize
->right
;
4182 if (num_margins
> 0)
4183 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4184 "media-right-margin-supported", num_margins
, margins
);
4186 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4187 "media-right-margin-supported", 0);
4189 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4190 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4193 for (j
= 0; j
< num_margins
; j
++)
4194 if (pwgsize
->top
== margins
[j
])
4197 if (j
>= num_margins
)
4199 margins
[num_margins
] = pwgsize
->top
;
4204 if (num_margins
> 0)
4205 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4206 "media-top-margin-supported", num_margins
, margins
);
4208 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4209 "media-top-margin-supported", 0);
4212 * media-col-database
4215 num_media
= p
->pc
->num_sizes
;
4216 if (p
->pc
->num_sources
)
4218 if (p
->pc
->num_types
> 0)
4219 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4222 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4224 else if (p
->pc
->num_types
)
4225 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4227 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4228 "media-col-database", num_media
,
4231 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4236 * Start by adding the page size without source or type...
4239 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4241 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4245 * Then add the specific, supported combinations of size, source, and
4249 if (p
->pc
->num_sources
> 0)
4251 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4255 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4257 if (p
->pc
->num_types
> 0)
4259 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4263 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4265 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4271 else if (!ppdConflicts(ppd
))
4273 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4278 else if (p
->pc
->num_types
> 0)
4280 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4284 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4286 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4294 * Update the number of media-col-database values...
4297 attr
->num_values
= val
- attr
->values
;
4305 if (p
->pc
&& p
->pc
->num_bins
> 0)
4307 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4308 "output-bin-supported", p
->pc
->num_bins
,
4313 for (i
= 0, val
= attr
->values
;
4314 i
< p
->pc
->num_bins
;
4316 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4319 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4321 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4322 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4325 if (i
>= p
->pc
->num_bins
)
4328 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4329 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4332 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4333 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4335 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4337 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4338 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4339 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4340 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4343 * Report that this printer has a single output bin that leaves pages face
4347 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4348 "output-bin-supported", NULL
, "face-up");
4349 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4350 "output-bin-default", NULL
, "face-up");
4354 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4355 "output-bin-supported", NULL
, "face-down");
4356 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4357 "output-bin-default", NULL
, "face-down");
4361 * print-color-mode...
4364 if (ppd
->color_device
)
4366 static const char * const color_modes
[] =
4372 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4373 "print-color-mode-supported", 2, NULL
, color_modes
);
4374 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4375 "print-color-mode-default", NULL
, "color");
4379 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4380 "print-color-mode-supported", NULL
, "monochrome");
4381 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4382 "print-color-mode-default", NULL
, "monochrome");
4386 * Mandatory job attributes, if any...
4389 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4391 int count
= cupsArrayCount(p
->pc
->mandatory
);
4392 /* Number of mandatory attributes */
4394 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4395 "printer-mandatory-job-attributes", count
, NULL
,
4398 for (val
= attr
->values
,
4399 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4401 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4402 val
->string
.text
= _cupsStrAlloc(mandatory
);
4406 * Printer resolutions...
4409 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4410 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4411 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4412 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4417 * Report all supported resolutions...
4420 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4421 "printer-resolution-supported",
4422 resolution
->num_choices
, IPP_RES_PER_INCH
,
4425 for (i
= 0, choice
= resolution
->choices
;
4426 i
< resolution
->num_choices
;
4429 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4430 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4431 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4433 if (xdpi
<= 0 || ydpi
<= 0)
4435 cupsdLogMessage(CUPSD_LOG_WARN
,
4436 "Bad resolution \"%s\" for printer %s.",
4437 choice
->choice
, p
->name
);
4441 attr
->values
[i
].resolution
.xres
= xdpi
;
4442 attr
->values
[i
].resolution
.yres
= ydpi
;
4443 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4446 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4447 "printer-resolution-default", IPP_RES_PER_INCH
,
4451 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4455 * Just the DefaultResolution to report...
4458 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4459 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4462 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4467 if (xdpi
<= 0 || ydpi
<= 0)
4469 cupsdLogMessage(CUPSD_LOG_WARN
,
4470 "Bad default resolution \"%s\" for printer %s.",
4471 ppd_attr
->value
, p
->name
);
4475 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4476 "printer-resolution-default", IPP_RES_PER_INCH
,
4478 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4479 "printer-resolution-supported", IPP_RES_PER_INCH
,
4485 * No resolutions in PPD - make one up...
4488 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4489 "printer-resolution-default", IPP_RES_PER_INCH
,
4491 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4492 "printer-resolution-supported", IPP_RES_PER_INCH
,
4500 ppdMarkDefaults(ppd
);
4502 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4503 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4504 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4505 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4506 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4508 if (duplex
&& duplex
->num_choices
> 1 &&
4509 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4511 p
->type
|= CUPS_PRINTER_DUPLEX
;
4513 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4514 "sides-supported", 3, NULL
, sides
);
4516 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4517 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4518 "sides-default", NULL
, "two-sided-short-edge");
4519 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4520 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4521 "sides-default", NULL
, "two-sided-long-edge");
4523 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4524 "sides-default", NULL
, "one-sided");
4528 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4529 "sides-supported", NULL
, "one-sided");
4530 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4531 "sides-default", NULL
, "one-sided");
4534 if (ppdFindOption(ppd
, "Collate") != NULL
)
4535 p
->type
|= CUPS_PRINTER_COLLATE
;
4537 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4539 p
->type
|= CUPS_PRINTER_STAPLE
;
4540 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4543 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4545 p
->type
|= CUPS_PRINTER_BIND
;
4546 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4549 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4550 if (ppd
->sizes
[i
].length
> 1728)
4551 p
->type
|= CUPS_PRINTER_LARGE
;
4552 else if (ppd
->sizes
[i
].length
> 1008)
4553 p
->type
|= CUPS_PRINTER_MEDIUM
;
4555 p
->type
|= CUPS_PRINTER_SMALL
;
4557 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4558 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4560 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4561 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4562 p
->type
|= CUPS_PRINTER_SCANNER
;
4564 p
->type
|= CUPS_PRINTER_MFP
;
4568 * Scan the filters in the PPD file...
4573 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4575 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4577 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4578 _cups_isspace(filter
[28]))
4580 p
->type
|= CUPS_PRINTER_COMMANDS
;
4586 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4588 char *commands
, /* Copy of commands */
4589 *start
, /* Start of name */
4590 *end
; /* End of name */
4591 int count
; /* Number of commands */
4593 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4595 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4597 while (_cups_isspace(*start
))
4603 while (*start
&& !isspace(*start
& 255))
4613 * Make a copy of the commands string and count how many commands there
4617 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4618 "printer-commands", count
, NULL
, NULL
);
4620 commands
= strdup(ppd_attr
->value
);
4622 for (count
= 0, start
= commands
; *start
; count
++)
4624 while (isspace(*start
& 255))
4631 while (*end
&& !isspace(*end
& 255))
4637 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4647 * Add the standard list of commands...
4650 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4652 (int)(sizeof(standard_commands
) /
4653 sizeof(standard_commands
[0])), NULL
,
4660 * No commands supported...
4663 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4664 "printer-commands", NULL
, "none");
4668 * 3D printer support...
4671 if (ppdFindAttr(ppd
, "cups3D", NULL
))
4672 p
->type
|= CUPS_PRINTER_3D
;
4675 * Show current and available port monitors for this printer...
4678 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4679 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4681 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4683 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4687 if (strstr(ppd
->protocols
, "TBCP"))
4689 else if (strstr(ppd
->protocols
, "BCP"))
4693 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4694 "port-monitor-supported", i
, NULL
, NULL
);
4696 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4698 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4700 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4701 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4705 if (strstr(ppd
->protocols
, "TBCP"))
4706 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4707 else if (strstr(ppd
->protocols
, "BCP"))
4708 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4711 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4712 p
->type
|= CUPS_PRINTER_REMOTE
;
4714 #ifdef HAVE_APPLICATIONSERVICES_H
4716 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4717 * and save it as cacheDir/printername.png
4720 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4722 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4723 cupsdLogFCMessage
, p
))
4725 CGImageRef imageRef
= NULL
;/* Current icon image */
4726 CGImageRef biggestIconRef
= NULL
;
4727 /* Biggest icon image */
4728 CGImageRef closestTo128IconRef
= NULL
;
4729 /* Icon image closest to and >= 128 */
4730 CGImageSourceRef sourceRef
; /* The file's image source */
4731 char outPath
[HTTP_MAX_URI
];
4732 /* The path to the PNG file */
4733 CFURLRef outUrl
; /* The URL made from the outPath */
4734 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4735 CGImageDestinationRef destRef
; /* The image destination to write */
4736 size_t bytesPerRow
; /* The bytes per row used for resizing */
4737 CGContextRef context
; /* The CG context used for resizing */
4739 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4740 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4741 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4742 if (outUrl
&& icnsFileUrl
)
4744 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4747 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4749 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4753 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4756 * Loop through remembering the icon closest to 128 but >= 128
4757 * and then remember the largest icon.
4760 if (CGImageGetWidth(imageRef
) >= 128 &&
4761 (!closestTo128IconRef
||
4762 CGImageGetWidth(imageRef
) <
4763 CGImageGetWidth(closestTo128IconRef
)))
4765 CGImageRelease(closestTo128IconRef
);
4766 CGImageRetain(imageRef
);
4767 closestTo128IconRef
= imageRef
;
4770 if (!biggestIconRef
||
4771 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4773 CGImageRelease(biggestIconRef
);
4774 CGImageRetain(imageRef
);
4775 biggestIconRef
= imageRef
;
4779 CGImageRelease(imageRef
);
4785 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4786 * want the closest to 128, but if none are larger than 128, we want
4787 * the largest icon available.
4790 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4792 CGImageRetain(imageRef
);
4793 CGImageRelease(biggestIconRef
);
4794 if (closestTo128IconRef
)
4795 CGImageRelease(closestTo128IconRef
);
4796 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4800 if (CGImageGetWidth(imageRef
) != 128)
4802 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4803 CGImageGetWidth(imageRef
) * 128;
4804 context
= CGBitmapContextCreate(NULL
, 128, 128,
4805 CGImageGetBitsPerComponent(imageRef
),
4807 CGImageGetColorSpace(imageRef
),
4808 kCGImageAlphaPremultipliedFirst
);
4811 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4813 CGImageRelease(imageRef
);
4814 imageRef
= CGBitmapContextCreateImage(context
);
4815 CGContextRelease(context
);
4819 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4820 CGImageDestinationFinalize(destRef
);
4824 CGImageRelease(imageRef
);
4827 CFRelease(sourceRef
);
4835 CFRelease(icnsFileUrl
);
4837 #endif /* HAVE_APPLICATIONSERVICES_H */
4840 * Close the PPD and set the type...
4845 else if (!access(ppd_name
, 0))
4847 int pline
; /* PPD line number */
4848 ppd_status_t pstatus
; /* PPD load status */
4851 pstatus
= ppdLastError(&pline
);
4853 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4855 if (pstatus
<= PPD_ALLOC_ERROR
)
4856 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4858 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4860 cupsdLogMessage(CUPSD_LOG_INFO
,
4861 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4866 if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4867 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4868 (strstr(p
->device_uri
, "/printers/") != NULL
||
4869 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4870 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4871 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4872 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4875 * Tell the client this is really a hard-wired remote printer.
4878 p
->type
|= CUPS_PRINTER_REMOTE
;
4881 * Point the printer-uri-supported attribute to the
4885 if (strchr(p
->device_uri
, '?'))
4888 * Strip trailing "?options" from URI...
4891 char resource
[HTTP_MAX_URI
], /* New URI */
4892 *ptr
; /* Pointer into URI */
4894 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4895 if ((ptr
= strchr(resource
, '?')) != NULL
)
4898 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4899 "printer-uri-supported", NULL
, resource
);
4902 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4903 "printer-uri-supported", NULL
, p
->device_uri
);
4906 * Then set the make-and-model accordingly...
4909 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4910 "printer-make-and-model", NULL
, "Remote Printer");
4913 * Print all files directly...
4922 * Otherwise we have neither - treat this as a "dumb" printer
4923 * with no PPD file...
4926 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4927 "printer-make-and-model", NULL
, "Local Raw Printer");
4933 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4934 "finishings-supported", num_finishings
, finishings
);
4935 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4936 "finishings-default", IPP_FINISHINGS_NONE
);
4941 * Save cached PPD attributes to disk...
4944 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4946 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4951 * Remove cache files...
4954 if (cache_info
.st_mtime
)
4961 * 'new_media_col()' - Create a media-col collection value.
4964 static ipp_t
* /* O - Collection value */
4965 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4966 const char *source
, /* I - media-source value */
4967 const char *type
) /* I - media-type value */
4969 ipp_t
*media_col
, /* Collection value */
4970 *media_size
; /* media-size value */
4973 media_col
= ippNew();
4975 media_size
= ippNew();
4976 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4977 "x-dimension", size
->width
);
4978 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4979 "y-dimension", size
->length
);
4980 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
4981 ippDelete(media_size
);
4983 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4984 "media-bottom-margin", size
->bottom
);
4985 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4986 "media-left-margin", size
->left
);
4987 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4988 "media-right-margin", size
->right
);
4989 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4990 "media-top-margin", size
->top
);
4993 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
4997 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5005 * 'write_xml_string()' - Write a string with XML escaping.
5009 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5010 const char *s
) /* I - String to write */
5012 const char *start
; /* Start of current sequence */
5018 for (start
= s
; *s
; s
++)
5023 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5025 cupsFilePuts(fp
, "&");
5031 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5033 cupsFilePuts(fp
, "<");
5039 cupsFilePuts(fp
, start
);