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
))
2347 char interface
[1024]; /* Interface script */
2350 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
2352 if (!access(interface
, X_OK
))
2355 * Yes, we have a System V style interface script; use it!
2358 snprintf(interface
, sizeof(interface
), "*/* 0 %s/interfaces/%s",
2359 ServerRoot
, p
->name
);
2360 add_printer_filter(p
, p
->filetype
, interface
);
2365 * Add a filter from application/vnd.cups-raw to printer/name to
2366 * handle "raw" printing by users.
2369 add_printer_filter(p
, p
->filetype
, "application/vnd.cups-raw 0 -");
2372 * Add a PostScript filter, since this is still possibly PS printer.
2375 add_printer_filter(p
, p
->filetype
,
2376 "application/vnd.cups-postscript 0 -");
2380 if (p
->pc
&& p
->pc
->prefilters
)
2382 if (!p
->prefiltertype
)
2383 p
->prefiltertype
= mimeAddType(MimeDatabase
, "prefilter", p
->name
);
2385 for (filter
= (char *)cupsArrayFirst(p
->pc
->prefilters
);
2387 filter
= (char *)cupsArrayNext(p
->pc
->prefilters
))
2388 add_printer_filter(p
, p
->prefiltertype
, filter
);
2393 * Copy marker attributes as needed...
2398 ipp_attribute_t
*oldattr
; /* Old attribute */
2401 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-colors",
2402 IPP_TAG_NAME
)) != NULL
)
2404 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2405 "marker-colors", oldattr
->num_values
, NULL
,
2408 for (i
= 0; i
< oldattr
->num_values
; i
++)
2409 attr
->values
[i
].string
.text
=
2410 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2414 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-levels",
2415 IPP_TAG_INTEGER
)) != NULL
)
2417 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2418 "marker-levels", oldattr
->num_values
,
2421 for (i
= 0; i
< oldattr
->num_values
; i
++)
2422 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2426 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-message",
2427 IPP_TAG_TEXT
)) != NULL
)
2428 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "marker-message",
2429 NULL
, oldattr
->values
[0].string
.text
);
2431 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-low-levels",
2432 IPP_TAG_INTEGER
)) != NULL
)
2434 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2435 "marker-low-levels", oldattr
->num_values
,
2438 for (i
= 0; i
< oldattr
->num_values
; i
++)
2439 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2443 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-high-levels",
2444 IPP_TAG_INTEGER
)) != NULL
)
2446 if ((attr
= ippAddIntegers(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
2447 "marker-high-levels", oldattr
->num_values
,
2450 for (i
= 0; i
< oldattr
->num_values
; i
++)
2451 attr
->values
[i
].integer
= oldattr
->values
[i
].integer
;
2455 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-names",
2456 IPP_TAG_NAME
)) != NULL
)
2458 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2459 "marker-names", oldattr
->num_values
, NULL
,
2462 for (i
= 0; i
< oldattr
->num_values
; i
++)
2463 attr
->values
[i
].string
.text
=
2464 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2468 if ((oldattr
= ippFindAttribute(oldattrs
, "marker-types",
2469 IPP_TAG_KEYWORD
)) != NULL
)
2471 if ((attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
2472 "marker-types", oldattr
->num_values
, NULL
,
2475 for (i
= 0; i
< oldattr
->num_values
; i
++)
2476 attr
->values
[i
].string
.text
=
2477 _cupsStrAlloc(oldattr
->values
[i
].string
.text
);
2481 ippDelete(oldattrs
);
2485 * Force sharing off for remote queues...
2488 if (p
->type
& CUPS_PRINTER_REMOTE
)
2492 * Populate the document-format-supported attribute...
2495 add_printer_formats(p
);
2497 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p
->name
,
2501 * Add name-default attributes...
2504 add_printer_defaults(p
);
2507 * Let the browse protocols reflect the change
2510 cupsdRegisterPrinter(p
);
2515 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2518 int /* O - 1 if something changed, 0 otherwise */
2519 cupsdSetPrinterReasons(
2520 cupsd_printer_t
*p
, /* I - Printer */
2521 const char *s
) /* I - Reasons strings */
2523 int i
, /* Looping var */
2524 changed
= 0; /* Did something change? */
2525 const char *sptr
; /* Pointer into reasons */
2526 char reason
[255], /* Reason string */
2527 *rptr
; /* Pointer into reason */
2530 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2531 "cupsdSetPrinterReasons(p=%p(%s),s=\"%s\"", p
, p
->name
, s
);
2533 if (s
[0] == '-' || s
[0] == '+')
2536 * Add/remove reasons...
2544 * Replace reasons...
2549 for (i
= 0; i
< p
->num_reasons
; i
++)
2550 _cupsStrFree(p
->reasons
[i
]);
2558 if (!strcmp(s
, "none"))
2562 * Loop through all of the reasons...
2568 * Skip leading whitespace and commas...
2571 while (isspace(*sptr
& 255) || *sptr
== ',')
2574 for (rptr
= reason
; *sptr
&& !isspace(*sptr
& 255) && *sptr
!= ','; sptr
++)
2575 if (rptr
< (reason
+ sizeof(reason
) - 1))
2589 for (i
= 0; i
< p
->num_reasons
; i
++)
2590 if (!strcmp(reason
, p
->reasons
[i
]))
2593 * Found a match, so remove it...
2598 _cupsStrFree(p
->reasons
[i
]);
2600 if (i
< p
->num_reasons
)
2601 memmove(p
->reasons
+ i
, p
->reasons
+ i
+ 1, (size_t)(p
->num_reasons
- i
) * sizeof(char *));
2603 if (!strcmp(reason
, "paused") && p
->state
== IPP_PRINTER_STOPPED
)
2604 cupsdSetPrinterState(p
, IPP_PRINTER_IDLE
, 1);
2606 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2607 p
->job
->completed
= 0;
2609 if (strcmp(reason
, "connecting-to-device"))
2615 else if (p
->num_reasons
< (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2621 for (i
= 0; i
< p
->num_reasons
; i
++)
2622 if (!strcmp(reason
, p
->reasons
[i
]))
2625 if (i
>= p
->num_reasons
)
2627 if (i
>= (int)(sizeof(p
->reasons
) / sizeof(p
->reasons
[0])))
2629 cupsdLogMessage(CUPSD_LOG_ALERT
,
2630 "Too many printer-state-reasons values for %s (%d)",
2635 p
->reasons
[i
] = _cupsStrAlloc(reason
);
2639 if (!strcmp(reason
, "paused") && p
->state
!= IPP_PRINTER_STOPPED
)
2640 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, 1);
2642 if (!strcmp(reason
, "cups-waiting-for-job-completed") && p
->job
)
2643 p
->job
->completed
= 1;
2645 if (strcmp(reason
, "connecting-to-device"))
2656 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2660 cupsdSetPrinterState(
2661 cupsd_printer_t
*p
, /* I - Printer to change */
2662 ipp_pstate_t s
, /* I - New state */
2663 int update
) /* I - Update printers.conf? */
2665 cupsd_job_t
*job
; /* Current job */
2666 ipp_pstate_t old_state
; /* Old printer state */
2667 static const char * const printer_states
[] =
2668 { /* State strings */
2676 * Set the new state...
2679 old_state
= p
->state
;
2684 cupsdAddEvent(s
== IPP_PRINTER_STOPPED
? CUPSD_EVENT_PRINTER_STOPPED
:
2685 CUPSD_EVENT_PRINTER_STATE
, p
, NULL
,
2686 "%s \"%s\" state changed to %s.",
2687 (p
->type
& CUPS_PRINTER_CLASS
) ? "Class" : "Printer",
2688 p
->name
, printer_states
[p
->state
- IPP_PRINTER_IDLE
]);
2691 * Let the browse code know this needs to be updated...
2694 p
->state_time
= time(NULL
);
2698 * Set/clear the paused reason as needed...
2701 if (s
== IPP_PRINTER_STOPPED
)
2702 cupsdSetPrinterReasons(p
, "+paused");
2704 cupsdSetPrinterReasons(p
, "-paused");
2708 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
2710 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
2711 if (job
->reasons
&& job
->state_value
== IPP_JOB_PENDING
&&
2712 !_cups_strcasecmp(job
->dest
, p
->name
))
2713 ippSetString(job
->attrs
, &job
->reasons
, 0,
2714 s
== IPP_PRINTER_STOPPED
? "printer-stopped" : "none");
2718 * Clear the message for the queue when going to processing...
2721 if (s
== IPP_PRINTER_PROCESSING
)
2722 p
->state_message
[0] = '\0';
2725 * Let the browse protocols reflect the change...
2729 cupsdRegisterPrinter(p
);
2732 * Save the printer configuration if a printer goes from idle or processing
2733 * to stopped (or visa-versa)...
2737 (old_state
== IPP_PRINTER_STOPPED
) != (s
== IPP_PRINTER_STOPPED
))
2743 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2747 cupsdStopPrinter(cupsd_printer_t
*p
, /* I - Printer to stop */
2748 int update
)/* I - Update printers.conf? */
2751 * Set the printer state...
2754 cupsdSetPrinterState(p
, IPP_PRINTER_STOPPED
, update
);
2757 * See if we have a job printing on this printer...
2760 if (p
->job
&& p
->job
->state_value
== IPP_JOB_PROCESSING
)
2761 cupsdSetJobState(p
->job
, IPP_JOB_PENDING
, CUPSD_JOB_DEFAULT
,
2762 "Job stopped due to printer being paused.");
2767 * 'cupsdUpdatePrinterPPD()' - Update keywords in a printer's PPD file.
2770 int /* O - 1 if successful, 0 otherwise */
2771 cupsdUpdatePrinterPPD(
2772 cupsd_printer_t
*p
, /* I - Printer */
2773 int num_keywords
, /* I - Number of keywords */
2774 cups_option_t
*keywords
) /* I - Keywords */
2776 int i
; /* Looping var */
2777 cups_file_t
*src
, /* Original file */
2778 *dst
; /* New file */
2779 char srcfile
[1024], /* Original filename */
2780 dstfile
[1024], /* New filename */
2781 line
[1024], /* Line from file */
2782 keystring
[41]; /* Keyword from line */
2783 cups_option_t
*keyword
; /* Current keyword */
2786 cupsdLogMessage(CUPSD_LOG_INFO
, "Updating keywords in PPD file for %s...",
2790 * Get the old and new PPD filenames...
2793 snprintf(srcfile
, sizeof(srcfile
), "%s/ppd/%s.ppd.O", ServerRoot
, p
->name
);
2794 snprintf(dstfile
, sizeof(srcfile
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
2797 * Rename the old file and open the old and new...
2800 if (rename(dstfile
, srcfile
))
2802 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to backup PPD file for %s: %s",
2803 p
->name
, strerror(errno
));
2807 if ((src
= cupsFileOpen(srcfile
, "r")) == NULL
)
2809 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open PPD file \"%s\": %s",
2810 srcfile
, strerror(errno
));
2811 rename(srcfile
, dstfile
);
2815 if ((dst
= cupsFileOpen(dstfile
, "w")) == NULL
)
2817 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create PPD file \"%s\": %s",
2818 dstfile
, strerror(errno
));
2820 rename(srcfile
, dstfile
);
2825 * Copy the first line and then write out all of the keywords...
2828 if (!cupsFileGets(src
, line
, sizeof(line
)))
2830 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to read PPD file \"%s\": %s",
2831 srcfile
, strerror(errno
));
2834 rename(srcfile
, dstfile
);
2838 cupsFilePrintf(dst
, "%s\n", line
);
2840 for (i
= num_keywords
, keyword
= keywords
; i
> 0; i
--, keyword
++)
2842 cupsdLogMessage(CUPSD_LOG_DEBUG
, "*%s: %s", keyword
->name
, keyword
->value
);
2843 cupsFilePrintf(dst
, "*%s: %s\n", keyword
->name
, keyword
->value
);
2847 * Then copy the rest of the PPD file, dropping any keywords we changed.
2850 while (cupsFileGets(src
, line
, sizeof(line
)))
2853 * Skip keywords we've already set...
2856 if (sscanf(line
, "*%40[^:]:", keystring
) == 1 &&
2857 cupsGetOption(keystring
, num_keywords
, keywords
))
2861 * Otherwise write the line...
2864 cupsFilePrintf(dst
, "%s\n", line
);
2868 * Close files and return...
2879 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2883 cupsdUpdatePrinters(void)
2885 cupsd_printer_t
*p
; /* Current printer */
2889 * Loop through the printers and recreate the printer attributes
2890 * for any local printers since the policy and/or access control
2891 * stuff may have changed. Also, if browsing is disabled, remove
2892 * any remote printers...
2895 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
2897 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
2900 * Update the operation policy pointer...
2903 if ((p
->op_policy_ptr
= cupsdFindPolicy(p
->op_policy
)) == NULL
)
2904 p
->op_policy_ptr
= DefaultPolicyPtr
;
2907 * Update printer attributes...
2910 cupsdSetPrinterAttrs(p
);
2916 * 'cupsdValidateDest()' - Validate a printer/class destination.
2919 const char * /* O - Printer or class name */
2921 const char *uri
, /* I - Printer URI */
2922 cups_ptype_t
*dtype
, /* O - Type (printer or class) */
2923 cupsd_printer_t
**printer
) /* O - Printer pointer */
2925 cupsd_printer_t
*p
; /* Current printer */
2926 char localname
[1024],/* Localized hostname */
2927 *lptr
, /* Pointer into localized hostname */
2928 *sptr
, /* Pointer into server name */
2929 *rptr
, /* Pointer into resource */
2930 scheme
[32], /* Scheme portion of URI */
2931 username
[64], /* Username portion of URI */
2932 hostname
[HTTP_MAX_HOST
],
2933 /* Host portion of URI */
2934 resource
[HTTP_MAX_URI
];
2935 /* Resource portion of URI */
2936 int port
; /* Port portion of URI */
2939 DEBUG_printf(("cupsdValidateDest(uri=\"%s\", dtype=%p, printer=%p)\n", uri
,
2943 * Initialize return values...
2950 *dtype
= (cups_ptype_t
)0;
2953 * Pull the hostname and resource from the URI...
2956 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
2957 username
, sizeof(username
), hostname
, sizeof(hostname
),
2958 &port
, resource
, sizeof(resource
));
2961 * See if the resource is a class or printer...
2964 if (!strncmp(resource
, "/classes/", 9))
2970 rptr
= resource
+ 9;
2972 else if (!strncmp(resource
, "/printers/", 10))
2978 rptr
= resource
+ 10;
2983 * Bad resource name...
2990 * See if the printer or class name exists...
2993 p
= cupsdFindDest(rptr
);
2995 if (p
== NULL
&& strchr(rptr
, '@') == NULL
)
3003 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3009 * Change localhost to the server name...
3012 if (!_cups_strcasecmp(hostname
, "localhost"))
3013 strlcpy(hostname
, ServerName
, sizeof(hostname
));
3015 strlcpy(localname
, hostname
, sizeof(localname
));
3017 if (!_cups_strcasecmp(hostname
, ServerName
))
3020 * Localize the hostname...
3023 lptr
= strchr(localname
, '.');
3024 sptr
= strchr(ServerName
, '.');
3026 if (sptr
!= NULL
&& lptr
!= NULL
)
3029 * Strip the common domain name components...
3032 while (lptr
!= NULL
)
3034 if (!_cups_strcasecmp(lptr
, sptr
))
3040 lptr
= strchr(lptr
+ 1, '.');
3045 DEBUG_printf(("localized hostname is \"%s\"...\n", localname
));
3048 * Find a matching printer or class...
3051 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3053 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3054 if (!_cups_strcasecmp(p
->hostname
, localname
) &&
3055 !_cups_strcasecmp(p
->name
, rptr
))
3061 *dtype
= p
->type
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
3071 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
3076 cupsdWritePrintcap(void)
3078 int i
; /* Looping var */
3079 cups_file_t
*fp
; /* Printcap file */
3080 cupsd_printer_t
*p
; /* Current printer */
3084 * See if we have a printcap file; if not, don't bother writing it.
3087 if (!Printcap
|| !*Printcap
)
3090 cupsdLogMessage(CUPSD_LOG_INFO
, "Generating printcap %s...", Printcap
);
3093 * Open the printcap file...
3096 if ((fp
= cupsFileOpen(Printcap
, "w")) == NULL
)
3100 * Put a comment header at the top so that users will know where the
3101 * data has come from...
3104 if (PrintcapFormat
!= PRINTCAP_PLIST
)
3105 cupsFilePrintf(fp
, "# This file was automatically generated by cupsd(8) "
3107 "# %s/printers.conf file. All changes to this file\n"
3108 "# will be lost.\n", ServerRoot
);
3111 * Write a new printcap with the current list of printers.
3114 switch (PrintcapFormat
)
3118 * Each printer is put in the file as:
3128 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter
->name
,
3129 DefaultPrinter
->info
, ServerName
,
3130 DefaultPrinter
->name
);
3132 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3134 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3135 if (p
!= DefaultPrinter
)
3136 cupsFilePrintf(fp
, "%s|%s:rm=%s:rp=%s:\n", p
->name
, p
->info
,
3137 ServerName
, p
->name
);
3140 case PRINTCAP_PLIST
:
3142 * Each printer is written as a dictionary in a plist file.
3143 * Currently the printer-name, printer-info, printer-is-accepting-jobs,
3144 * printer-location, printer-make-and-model, printer-state,
3145 * printer-state-reasons, printer-type, and (sanitized) device-uri.
3148 cupsFilePuts(fp
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
3149 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD "
3150 "PLIST 1.0//EN\" \"http://www.apple.com/DTDs/"
3151 "PropertyList-1.0.dtd\">\n"
3152 "<plist version=\"1.0\">\n"
3155 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3157 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3159 cupsFilePuts(fp
, "\t<dict>\n"
3160 "\t\t<key>printer-name</key>\n"
3162 write_xml_string(fp
, p
->name
);
3163 cupsFilePuts(fp
, "</string>\n"
3164 "\t\t<key>printer-info</key>\n"
3166 write_xml_string(fp
, p
->info
);
3167 cupsFilePrintf(fp
, "</string>\n"
3168 "\t\t<key>printer-is-accepting-jobs</key>\n"
3170 "\t\t<key>printer-location</key>\n"
3171 "\t\t<string>", p
->accepting
? "true" : "false");
3172 write_xml_string(fp
, p
->location
);
3173 cupsFilePuts(fp
, "</string>\n"
3174 "\t\t<key>printer-make-and-model</key>\n"
3176 write_xml_string(fp
, p
->make_model
);
3177 cupsFilePrintf(fp
, "</string>\n"
3178 "\t\t<key>printer-state</key>\n"
3179 "\t\t<integer>%d</integer>\n"
3180 "\t\t<key>printer-state-reasons</key>\n"
3181 "\t\t<array>\n", p
->state
);
3182 for (i
= 0; i
< p
->num_reasons
; i
++)
3184 cupsFilePuts(fp
, "\t\t\t<string>");
3185 write_xml_string(fp
, p
->reasons
[i
]);
3186 cupsFilePuts(fp
, "</string>\n");
3188 cupsFilePrintf(fp
, "\t\t</array>\n"
3189 "\t\t<key>printer-type</key>\n"
3190 "\t\t<integer>%d</integer>\n"
3191 "\t\t<key>device-uri</key>\n"
3192 "\t\t<string>", p
->type
);
3193 write_xml_string(fp
, p
->sanitized_device_uri
);
3194 cupsFilePuts(fp
, "</string>\n"
3197 cupsFilePuts(fp
, "</array>\n"
3201 case PRINTCAP_SOLARIS
:
3203 * Each printer is put in the file as:
3205 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
3206 * _default:use=DefaultPrinter
3208 * :bsdaddr=ServerName,Printer1:\
3209 * :description=Description:
3211 * :bsdaddr=ServerName,Printer2:\
3212 * :description=Description:
3214 * :bsdaddr=ServerName,Printer3:\
3215 * :description=Description:
3218 * :bsdaddr=ServerName,PrinterN:\
3219 * :description=Description:
3222 cupsFilePuts(fp
, "_all:all=");
3223 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3225 p
= (cupsd_printer_t
*)cupsArrayCurrent(Printers
))
3226 cupsFilePrintf(fp
, "%s%c", p
->name
,
3227 cupsArrayNext(Printers
) ? ',' : '\n');
3230 cupsFilePrintf(fp
, "_default:use=%s\n", DefaultPrinter
->name
);
3232 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
3234 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
3235 cupsFilePrintf(fp
, "%s:\\\n"
3236 "\t:bsdaddr=%s,%s:\\\n"
3237 "\t:description=%s:\n",
3238 p
->name
, ServerName
, p
->name
,
3239 p
->info
? p
->info
: "");
3252 * 'add_printer_defaults()' - Add name-default attributes to the printer attributes.
3256 add_printer_defaults(cupsd_printer_t
*p
)/* I - Printer */
3258 int i
; /* Looping var */
3259 int num_options
; /* Number of default options */
3260 cups_option_t
*options
, /* Default options */
3261 *option
; /* Current option */
3262 char name
[256]; /* name-default */
3266 * Maintain a common array of default attribute names...
3269 if (!CommonDefaults
)
3271 CommonDefaults
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
3273 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("copies-default"));
3274 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("document-format-default"));
3275 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("finishings-default"));
3276 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-account-id-default"));
3277 cupsArrayAdd(CommonDefaults
,
3278 _cupsStrAlloc("job-accounting-user-id-default"));
3279 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-cancel-after-default"));
3280 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-hold-until-default"));
3281 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-priority-default"));
3282 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("job-sheets-default"));
3283 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("media-col-default"));
3284 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc("number-up-default"));
3285 cupsArrayAdd(CommonDefaults
,
3286 _cupsStrAlloc("orientation-requested-default"));
3290 * Add all of the default options from the .conf files...
3293 for (num_options
= 0, options
= NULL
, i
= p
->num_options
, option
= p
->options
;
3297 if (strcmp(option
->name
, "ipp-options") &&
3298 strcmp(option
->name
, "job-sheets") &&
3299 strcmp(option
->name
, "lease-duration"))
3301 snprintf(name
, sizeof(name
), "%s-default", option
->name
);
3302 num_options
= cupsAddOption(name
, option
->value
, num_options
, &options
);
3304 if (!cupsArrayFind(CommonDefaults
, name
))
3305 cupsArrayAdd(CommonDefaults
, _cupsStrAlloc(name
));
3310 * Convert options to IPP attributes...
3313 cupsEncodeOptions2(p
->attrs
, num_options
, options
, IPP_TAG_PRINTER
);
3314 cupsFreeOptions(num_options
, options
);
3317 * Add standard -default attributes as needed...
3320 if (!cupsGetOption("copies", p
->num_options
, p
->options
))
3321 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
, "copies-default",
3324 if (!cupsGetOption("document-format", p
->num_options
, p
->options
))
3325 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3326 "document-format-default", NULL
, "application/octet-stream");
3328 if (!cupsGetOption("job-cancel-after", p
->num_options
, p
->options
))
3329 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3330 "job-cancel-after-default", MaxJobTime
);
3332 if (!cupsGetOption("job-hold-until", p
->num_options
, p
->options
))
3333 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3334 "job-hold-until-default", NULL
, "no-hold");
3336 if (!cupsGetOption("job-priority", p
->num_options
, p
->options
))
3337 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3338 "job-priority-default", 50);
3340 if (!cupsGetOption("number-up", p
->num_options
, p
->options
))
3341 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3342 "number-up-default", 1);
3344 if (!cupsGetOption("notify-lease-duration", p
->num_options
, p
->options
))
3345 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3346 "notify-lease-duration-default", DefaultLeaseDuration
);
3348 if (!cupsGetOption("notify-events", p
->num_options
, p
->options
))
3349 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3350 "notify-events-default", NULL
, "job-completed");
3352 if (!cupsGetOption("orientation-requested", p
->num_options
, p
->options
))
3353 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_NOVALUE
,
3354 "orientation-requested-default", NULL
, NULL
);
3356 if (!cupsGetOption("print-quality", p
->num_options
, p
->options
))
3357 ippAddInteger(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3358 "print-quality-default", IPP_QUALITY_NORMAL
);
3363 * 'add_printer_filter()' - Add a MIME filter for a printer.
3368 cupsd_printer_t
*p
, /* I - Printer to add to */
3369 mime_type_t
*filtertype
, /* I - Filter or prefilter MIME type */
3370 const char *filter
) /* I - Filter to add */
3372 char super
[MIME_MAX_SUPER
], /* Super-type for filter */
3373 type
[MIME_MAX_TYPE
], /* Type for filter */
3374 dsuper
[MIME_MAX_SUPER
], /* Destination super-type for filter */
3375 dtype
[MIME_MAX_TYPE
], /* Destination type for filter */
3376 dest
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2],
3377 /* Destination super/type */
3378 program
[1024]; /* Program/filter name */
3379 int cost
; /* Cost of filter */
3380 size_t maxsize
= 0; /* Maximum supported file size */
3381 mime_type_t
*temptype
, /* MIME type looping var */
3382 *desttype
; /* Destination MIME type */
3383 mime_filter_t
*filterptr
; /* MIME filter */
3384 char filename
[1024]; /* Full filter filename */
3387 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3388 "add_printer_filter(p=%p(%s), filtertype=%p(%s/%s), "
3389 "filter=\"%s\")", p
, p
->name
, filtertype
, filtertype
->super
,
3390 filtertype
->type
, filter
);
3393 * Parse the filter string; it should be in one of the following formats:
3395 * source/type cost program
3396 * source/type cost maxsize(nnnn) program
3397 * source/type dest/type cost program
3398 * source/type dest/type cost maxsize(nnnn) program
3401 if (sscanf(filter
, "%15[^/]/%255s%*[ \t]%15[^/]/%255s%d%*[ \t]%1023[^\n]",
3402 super
, type
, dsuper
, dtype
, &cost
, program
) == 6)
3404 snprintf(dest
, sizeof(dest
), "%s/%s/%s", p
->name
, dsuper
, dtype
);
3406 if ((desttype
= mimeType(MimeDatabase
, "printer", dest
)) == NULL
)
3408 desttype
= mimeAddType(MimeDatabase
, "printer", dest
);
3410 p
->dest_types
= cupsArrayNew(NULL
, NULL
);
3412 cupsArrayAdd(p
->dest_types
, desttype
);
3418 if (sscanf(filter
, "%15[^/]/%255s%d%*[ \t]%1023[^\n]", super
, type
, &cost
,
3421 desttype
= filtertype
;
3425 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3431 if (!strncmp(program
, "maxsize(", 8))
3433 char *ptr
; /* Pointer into maxsize(nnnn) program */
3435 maxsize
= (size_t)strtoll(program
+ 8, &ptr
, 10);
3439 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: invalid filter string \"%s\"!",
3445 while (_cups_isspace(*ptr
))
3448 _cups_strcpy(program
, ptr
);
3452 * Check permissions on the filter and its containing directory...
3455 if (strcmp(program
, "-"))
3457 if (program
[0] == '/')
3458 strlcpy(filename
, program
, sizeof(filename
));
3460 snprintf(filename
, sizeof(filename
), "%s/filter/%s", ServerBin
, program
);
3462 _cupsFileCheck(filename
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
3463 cupsdLogFCMessage
, p
);
3467 * Add the filter to the MIME database, supporting wildcards as needed...
3470 for (temptype
= mimeFirstType(MimeDatabase
);
3472 temptype
= mimeNextType(MimeDatabase
))
3473 if (((super
[0] == '*' && _cups_strcasecmp(temptype
->super
, "printer")) ||
3474 !_cups_strcasecmp(temptype
->super
, super
)) &&
3475 (type
[0] == '*' || !_cups_strcasecmp(temptype
->type
, type
)))
3477 if (desttype
!= filtertype
)
3479 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3480 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3481 "%s", p
->name
, temptype
->super
, temptype
->type
,
3482 desttype
->super
, desttype
->type
,
3484 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, desttype
, cost
,
3487 if (!mimeFilterLookup(MimeDatabase
, desttype
, filtertype
))
3489 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3490 "add_printer_filter: %s: adding filter %s/%s %s/%s "
3491 "0 -", p
->name
, desttype
->super
, desttype
->type
,
3492 filtertype
->super
, filtertype
->type
);
3493 mimeAddFilter(MimeDatabase
, desttype
, filtertype
, 0, "-");
3498 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3499 "add_printer_filter: %s: adding filter %s/%s %s/%s %d "
3500 "%s", p
->name
, temptype
->super
, temptype
->type
,
3501 filtertype
->super
, filtertype
->type
,
3503 filterptr
= mimeAddFilter(MimeDatabase
, temptype
, filtertype
, cost
,
3508 filterptr
->maxsize
= maxsize
;
3514 * 'add_printer_formats()' - Add document-format-supported values for a printer.
3518 add_printer_formats(cupsd_printer_t
*p
) /* I - Printer */
3520 int i
; /* Looping var */
3521 mime_type_t
*type
; /* Current MIME type */
3522 cups_array_t
*filters
; /* Filters */
3523 ipp_attribute_t
*attr
; /* document-format-supported attribute */
3524 char mimetype
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
+ 2];
3525 /* MIME type name */
3529 * Raw (and remote) queues advertise all of the supported MIME
3533 cupsArrayDelete(p
->filetypes
);
3534 p
->filetypes
= NULL
;
3538 ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
,
3539 (ipp_tag_t
)(IPP_TAG_MIMETYPE
| IPP_TAG_COPY
),
3540 "document-format-supported", NumMimeTypes
, NULL
, MimeTypes
);
3545 * Otherwise, loop through the supported MIME types and see if there
3546 * are filters for them...
3549 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "add_printer_formats: %d types, %d filters",
3550 mimeNumTypes(MimeDatabase
), mimeNumFilters(MimeDatabase
));
3552 p
->filetypes
= cupsArrayNew(NULL
, NULL
);
3554 for (type
= mimeFirstType(MimeDatabase
);
3556 type
= mimeNextType(MimeDatabase
))
3558 if (!_cups_strcasecmp(type
->super
, "printer"))
3561 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3563 if ((filters
= mimeFilter(MimeDatabase
, type
, p
->filetype
, NULL
)) != NULL
)
3565 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3566 "add_printer_formats: %s: %s needs %d filters",
3567 p
->name
, mimetype
, cupsArrayCount(filters
));
3569 cupsArrayDelete(filters
);
3570 cupsArrayAdd(p
->filetypes
, type
);
3573 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3574 "add_printer_formats: %s: %s not supported",
3579 * Add the file formats that can be filtered...
3582 if ((type
= mimeType(MimeDatabase
, "application", "octet-stream")) == NULL
||
3583 !cupsArrayFind(p
->filetypes
, type
))
3588 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
3589 "add_printer_formats: %s: %d supported types",
3590 p
->name
, cupsArrayCount(p
->filetypes
) + i
);
3592 attr
= ippAddStrings(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_MIMETYPE
,
3593 "document-format-supported",
3594 cupsArrayCount(p
->filetypes
) + i
, NULL
, NULL
);
3597 attr
->values
[0].string
.text
= _cupsStrAlloc("application/octet-stream");
3599 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3601 i
++, type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3603 snprintf(mimetype
, sizeof(mimetype
), "%s/%s", type
->super
, type
->type
);
3605 attr
->values
[i
].string
.text
= _cupsStrAlloc(mimetype
);
3608 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
3610 char pdl
[1024]; /* Buffer to build pdl list */
3611 mime_filter_t
*filter
; /* MIME filter looping var */
3615 * We only support raw printing if this is not a Tioga PrintJobMgr based
3616 * queue and if application/octet-stream is a known type...
3619 for (filter
= (mime_filter_t
*)cupsArrayFirst(MimeDatabase
->filters
);
3621 filter
= (mime_filter_t
*)cupsArrayNext(MimeDatabase
->filters
))
3623 if (filter
->dst
== p
->filetype
&& strstr(filter
->filter
, "PrintJobMgr"))
3629 if (!filter
&& mimeType(MimeDatabase
, "application", "octet-stream"))
3630 strlcat(pdl
, "application/octet-stream,", sizeof(pdl
));
3633 * Then list a bunch of formats that are supported by the printer...
3636 for (type
= (mime_type_t
*)cupsArrayFirst(p
->filetypes
);
3638 type
= (mime_type_t
*)cupsArrayNext(p
->filetypes
))
3640 if (!_cups_strcasecmp(type
->super
, "application"))
3642 if (!_cups_strcasecmp(type
->type
, "pdf"))
3643 strlcat(pdl
, "application/pdf,", sizeof(pdl
));
3644 else if (!_cups_strcasecmp(type
->type
, "postscript"))
3645 strlcat(pdl
, "application/postscript,", sizeof(pdl
));
3647 else if (!_cups_strcasecmp(type
->super
, "image"))
3649 if (!_cups_strcasecmp(type
->type
, "jpeg"))
3650 strlcat(pdl
, "image/jpeg,", sizeof(pdl
));
3651 else if (!_cups_strcasecmp(type
->type
, "png"))
3652 strlcat(pdl
, "image/png,", sizeof(pdl
));
3653 else if (!_cups_strcasecmp(type
->type
, "pwg-raster"))
3654 strlcat(pdl
, "image/pwg-raster,", sizeof(pdl
));
3659 pdl
[strlen(pdl
) - 1] = '\0'; /* Remove trailing comma */
3661 cupsdSetString(&p
->pdl
, pdl
);
3663 #endif /* HAVE_DNSSD || HAVE_AVAHI */
3668 * 'compare_printers()' - Compare two printers.
3671 static int /* O - Result of comparison */
3672 compare_printers(void *first
, /* I - First printer */
3673 void *second
, /* I - Second printer */
3674 void *data
) /* I - App data (not used) */
3678 return (_cups_strcasecmp(((cupsd_printer_t
*)first
)->name
,
3679 ((cupsd_printer_t
*)second
)->name
));
3684 * 'delete_printer_filters()' - Delete all MIME filters for a printer.
3688 delete_printer_filters(
3689 cupsd_printer_t
*p
) /* I - Printer to remove from */
3691 mime_filter_t
*filter
; /* MIME filter looping var */
3692 mime_type_t
*type
; /* Destination types for filters */
3696 * Range check input...
3703 * Remove all filters from the MIME database that have a destination
3704 * type == printer...
3707 for (filter
= mimeFirstFilter(MimeDatabase
);
3709 filter
= mimeNextFilter(MimeDatabase
))
3710 if (filter
->dst
== p
->filetype
|| filter
->dst
== p
->prefiltertype
||
3711 cupsArrayFind(p
->dest_types
, filter
->dst
))
3714 * Delete the current filter...
3717 mimeDeleteFilter(MimeDatabase
, filter
);
3720 for (type
= (mime_type_t
*)cupsArrayFirst(p
->dest_types
);
3722 type
= (mime_type_t
*)cupsArrayNext(p
->dest_types
))
3723 mimeDeleteType(MimeDatabase
, type
);
3725 cupsArrayDelete(p
->dest_types
);
3726 p
->dest_types
= NULL
;
3728 cupsdSetPrinterReasons(p
, "-cups-insecure-filter-warning"
3729 ",cups-missing-filter-warning");
3734 * 'dirty_printer()' - Mark config and state files dirty for the specified
3739 dirty_printer(cupsd_printer_t
*p
) /* I - Printer */
3741 if (p
->type
& CUPS_PRINTER_CLASS
)
3742 cupsdMarkDirty(CUPSD_DIRTY_CLASSES
);
3744 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3746 if (PrintcapFormat
== PRINTCAP_PLIST
)
3747 cupsdMarkDirty(CUPSD_DIRTY_PRINTCAP
);
3752 * 'load_ppd()' - Load a cached PPD file, updating the cache as needed.
3756 load_ppd(cupsd_printer_t
*p
) /* I - Printer */
3758 int i
, j
, k
; /* Looping vars */
3759 char cache_name
[1024]; /* Cache filename */
3760 struct stat cache_info
; /* Cache file info */
3761 ppd_file_t
*ppd
; /* PPD file */
3762 char ppd_name
[1024]; /* PPD filename */
3763 struct stat ppd_info
; /* PPD file info */
3764 int num_media
; /* Number of media options */
3765 ppd_size_t
*size
; /* Current PPD size */
3766 ppd_option_t
*duplex
, /* Duplex option */
3767 *output_bin
, /* OutputBin option */
3768 *output_mode
, /* OutputMode option */
3769 *resolution
; /* (Set|JCL|)Resolution option */
3770 ppd_choice_t
*choice
, /* Current PPD choice */
3771 *input_slot
, /* Current input slot */
3772 *media_type
; /* Current media type */
3773 ppd_attr_t
*ppd_attr
; /* PPD attribute */
3774 int xdpi
, /* Horizontal resolution */
3775 ydpi
; /* Vertical resolution */
3776 const char *resptr
; /* Pointer into resolution keyword */
3777 _pwg_size_t
*pwgsize
; /* Current PWG size */
3778 _pwg_map_t
*pwgsource
, /* Current PWG source */
3779 *pwgtype
; /* Current PWG type */
3780 ipp_attribute_t
*attr
; /* Attribute data */
3781 _ipp_value_t
*val
; /* Attribute value */
3782 int num_finishings
, /* Number of finishings */
3783 finishings
[5]; /* finishings-supported values */
3784 int num_qualities
, /* Number of print-quality values */
3785 qualities
[3]; /* print-quality values */
3786 int num_margins
, /* Number of media-*-margin-supported values */
3787 margins
[16]; /* media-*-margin-supported values */
3788 const char *filter
, /* Current filter */
3789 *mandatory
; /* Current mandatory attribute */
3790 static const char * const sides
[3] = /* sides-supported values */
3793 "two-sided-long-edge",
3794 "two-sided-short-edge"
3796 static const char * const standard_commands
[] =
3797 { /* Standard CUPS commands */
3805 * Check to see if the cache is up-to-date...
3808 snprintf(cache_name
, sizeof(cache_name
), "%s/%s.data", CacheDir
, p
->name
);
3809 if (stat(cache_name
, &cache_info
))
3810 cache_info
.st_mtime
= 0;
3812 snprintf(ppd_name
, sizeof(ppd_name
), "%s/ppd/%s.ppd", ServerRoot
, p
->name
);
3813 if (stat(ppd_name
, &ppd_info
))
3814 ppd_info
.st_mtime
= 1;
3816 ippDelete(p
->ppd_attrs
);
3817 p
->ppd_attrs
= NULL
;
3819 _ppdCacheDestroy(p
->pc
);
3822 if (cache_info
.st_mtime
>= ppd_info
.st_mtime
)
3824 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", cache_name
);
3826 if ((p
->pc
= _ppdCacheCreateWithFile(cache_name
, &p
->ppd_attrs
)) != NULL
&&
3830 * Loaded successfully!
3838 * Reload PPD attributes from disk...
3841 cupsdMarkDirty(CUPSD_DIRTY_PRINTERS
);
3843 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Loading %s...", ppd_name
);
3845 cupsdClearString(&(p
->make_model
));
3847 p
->type
&= (cups_ptype_t
)~CUPS_PRINTER_OPTIONS
;
3848 p
->type
|= CUPS_PRINTER_BW
;
3850 finishings
[0] = IPP_FINISHINGS_NONE
;
3853 p
->ppd_attrs
= ippNew();
3855 if ((ppd
= _ppdOpenFile(ppd_name
, _PPD_LOCALIZATION_NONE
)) != NULL
)
3858 * Add make/model and other various attributes...
3861 p
->pc
= _ppdCacheCreateWithPPD(ppd
);
3864 cupsdLogMessage(CUPSD_LOG_WARN
, "Unable to create cache of \"%s\": %s",
3865 ppd_name
, cupsLastErrorString());
3867 ppdMarkDefaults(ppd
);
3869 if (ppd
->color_device
)
3870 p
->type
|= CUPS_PRINTER_COLOR
;
3871 if (ppd
->variable_sizes
)
3872 p
->type
|= CUPS_PRINTER_VARIABLE
;
3873 if (!ppd
->manual_copies
)
3874 p
->type
|= CUPS_PRINTER_COPIES
;
3875 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsFax", NULL
)) != NULL
)
3876 if (ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
3877 p
->type
|= CUPS_PRINTER_FAX
;
3879 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "color-supported", (char)ppd
->color_device
);
3881 if (p
->pc
&& p
->pc
->charge_info_uri
)
3882 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
3883 "printer-charge-info-uri", NULL
, p
->pc
->charge_info_uri
);
3885 if (p
->pc
&& p
->pc
->account_id
)
3886 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
, "job-account-id-supported",
3889 if (p
->pc
&& p
->pc
->accounting_user_id
)
3890 ippAddBoolean(p
->ppd_attrs
, IPP_TAG_PRINTER
,
3891 "job-accounting-user-id-supported", 1);
3893 if (p
->pc
&& p
->pc
->password
)
3895 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3896 "job-password-encryption-supported", NULL
, "none");
3897 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3898 "job-password-supported", (int)strlen(p
->pc
->password
));
3901 if (ppd
->throughput
)
3903 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3904 "pages-per-minute", ppd
->throughput
);
3905 if (ppd
->color_device
)
3906 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3907 "pages-per-minute-color", ppd
->throughput
);
3912 * When there is no speed information, just say "1 page per minute".
3915 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3916 "pages-per-minute", 1);
3917 if (ppd
->color_device
)
3918 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
3919 "pages-per-minute-color", 1);
3922 if ((ppd_attr
= ppdFindAttr(ppd
, "1284DeviceId", NULL
)) != NULL
)
3923 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-device-id", NULL
, ppd_attr
->value
);
3927 if ((output_mode
= ppdFindOption(ppd
, "OutputMode")) != NULL
)
3929 if (ppdFindChoice(output_mode
, "draft") ||
3930 ppdFindChoice(output_mode
, "fast"))
3931 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3933 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3935 if (ppdFindChoice(output_mode
, "best") ||
3936 ppdFindChoice(output_mode
, "high"))
3937 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3939 else if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterPreset", NULL
)) != NULL
)
3943 if (strstr(ppd_attr
->spec
, "draft") ||
3944 strstr(ppd_attr
->spec
, "Draft"))
3946 qualities
[num_qualities
++] = IPP_QUALITY_DRAFT
;
3950 while ((ppd_attr
= ppdFindNextAttr(ppd
, "APPrinterPreset",
3953 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3954 qualities
[num_qualities
++] = IPP_QUALITY_HIGH
;
3957 qualities
[num_qualities
++] = IPP_QUALITY_NORMAL
;
3959 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
3960 "print-quality-supported", num_qualities
, qualities
);
3965 * The NickName can be localized in the character set specified
3966 * by the LanugageEncoding attribute. However, ppdOpen2() has
3967 * already converted the ppd->nickname member to UTF-8 for us
3968 * (the original attribute value is available separately)
3971 cupsdSetString(&p
->make_model
, ppd
->nickname
);
3973 else if (ppd
->modelname
)
3976 * Model name can only contain specific characters...
3979 cupsdSetString(&p
->make_model
, ppd
->modelname
);
3982 cupsdSetString(&p
->make_model
, "Bad PPD File");
3984 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
3985 "printer-make-and-model", NULL
, p
->make_model
);
3988 * Add media options from the PPD file...
3991 if (ppd
->num_sizes
== 0 || !p
->pc
)
3993 if (!ppdFindAttr(ppd
, "APScannerOnly", NULL
))
3994 cupsdLogMessage(CUPSD_LOG_CRIT
,
3995 "The PPD file for printer %s contains no media "
3996 "options and is therefore invalid!", p
->name
);
3998 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
3999 "media-default", NULL
, "unknown");
4000 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4001 "media-supported", NULL
, "unknown");
4009 if ((size
= ppdPageSize(ppd
, NULL
)) != NULL
)
4010 pwgsize
= _ppdCacheGetSize(p
->pc
, size
->name
);
4014 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4015 "media-default", NULL
,
4016 pwgsize
? pwgsize
->map
.pwg
: "unknown");
4024 ipp_t
*col
; /* Collection value */
4026 input_slot
= ppdFindMarkedChoice(ppd
, "InputSlot");
4027 media_type
= ppdFindMarkedChoice(ppd
, "MediaType");
4028 col
= new_media_col(pwgsize
,
4030 _ppdCacheGetSource(p
->pc
,
4031 input_slot
->choice
) :
4034 _ppdCacheGetType(p
->pc
,
4035 media_type
->choice
) :
4038 ippAddCollection(p
->ppd_attrs
, IPP_TAG_PRINTER
, "media-col-default",
4047 num_media
= p
->pc
->num_sizes
;
4048 if (p
->pc
->custom_min_keyword
)
4051 if ((attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4052 "media-supported", num_media
, NULL
,
4057 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4059 i
--, pwgsize
++, val
++)
4060 val
->string
.text
= _cupsStrAlloc(pwgsize
->map
.pwg
);
4062 if (p
->pc
->custom_min_keyword
)
4064 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_min_keyword
);
4066 val
->string
.text
= _cupsStrAlloc(p
->pc
->custom_max_keyword
);
4071 * media-size-supported
4074 num_media
= p
->pc
->num_sizes
;
4075 if (p
->pc
->custom_min_keyword
)
4078 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4079 "media-size-supported", num_media
,
4084 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
;
4086 i
--, pwgsize
++, val
++)
4088 val
->collection
= ippNew();
4089 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4090 "x-dimension", pwgsize
->width
);
4091 ippAddInteger(val
->collection
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4092 "y-dimension", pwgsize
->length
);
4095 if (p
->pc
->custom_min_keyword
)
4097 val
->collection
= ippNew();
4098 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "x-dimension",
4099 p
->pc
->custom_min_width
, p
->pc
->custom_max_width
);
4100 ippAddRange(val
->collection
, IPP_TAG_PRINTER
, "y-dimension",
4101 p
->pc
->custom_min_length
, p
->pc
->custom_max_length
);
4106 * media-source-supported
4109 if (p
->pc
->num_sources
> 0 &&
4110 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4111 "media-source-supported", p
->pc
->num_sources
,
4112 NULL
, NULL
)) != NULL
)
4114 for (i
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
,
4117 i
--, pwgsource
++, val
++)
4118 val
->string
.text
= _cupsStrAlloc(pwgsource
->pwg
);
4122 * media-type-supported
4125 if (p
->pc
->num_types
> 0 &&
4126 (attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4127 "media-type-supported", p
->pc
->num_types
,
4128 NULL
, NULL
)) != NULL
)
4130 for (i
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
,
4133 i
--, pwgtype
++, val
++)
4134 val
->string
.text
= _cupsStrAlloc(pwgtype
->pwg
);
4138 * media-*-margin-supported
4141 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4142 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4145 for (j
= 0; j
< num_margins
; j
++)
4146 if (pwgsize
->bottom
== margins
[j
])
4149 if (j
>= num_margins
)
4151 margins
[num_margins
] = pwgsize
->bottom
;
4156 if (num_margins
> 0)
4157 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4158 "media-bottom-margin-supported", num_margins
, margins
);
4160 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4161 "media-bottom-margin-supported", 0);
4163 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4164 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4167 for (j
= 0; j
< num_margins
; j
++)
4168 if (pwgsize
->left
== margins
[j
])
4171 if (j
>= num_margins
)
4173 margins
[num_margins
] = pwgsize
->left
;
4178 if (num_margins
> 0)
4179 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4180 "media-left-margin-supported", num_margins
, margins
);
4182 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4183 "media-left-margin-supported", 0);
4185 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4186 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4189 for (j
= 0; j
< num_margins
; j
++)
4190 if (pwgsize
->right
== margins
[j
])
4193 if (j
>= num_margins
)
4195 margins
[num_margins
] = pwgsize
->right
;
4200 if (num_margins
> 0)
4201 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4202 "media-right-margin-supported", num_margins
, margins
);
4204 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4205 "media-right-margin-supported", 0);
4207 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, num_margins
= 0;
4208 i
> 0 && num_margins
< (int)(sizeof(margins
) / sizeof(margins
[0]));
4211 for (j
= 0; j
< num_margins
; j
++)
4212 if (pwgsize
->top
== margins
[j
])
4215 if (j
>= num_margins
)
4217 margins
[num_margins
] = pwgsize
->top
;
4222 if (num_margins
> 0)
4223 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4224 "media-top-margin-supported", num_margins
, margins
);
4226 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
4227 "media-top-margin-supported", 0);
4230 * media-col-database
4233 num_media
= p
->pc
->num_sizes
;
4234 if (p
->pc
->num_sources
)
4236 if (p
->pc
->num_types
> 0)
4237 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
*
4240 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_sources
;
4242 else if (p
->pc
->num_types
)
4243 num_media
+= p
->pc
->num_sizes
* p
->pc
->num_types
;
4245 if ((attr
= ippAddCollections(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4246 "media-col-database", num_media
,
4249 for (i
= p
->pc
->num_sizes
, pwgsize
= p
->pc
->sizes
, val
= attr
->values
;
4254 * Start by adding the page size without source or type...
4257 ppdMarkOption(ppd
, "PageSize", pwgsize
->map
.ppd
);
4259 val
->collection
= new_media_col(pwgsize
, NULL
, NULL
);
4263 * Then add the specific, supported combinations of size, source, and
4267 if (p
->pc
->num_sources
> 0)
4269 for (j
= p
->pc
->num_sources
, pwgsource
= p
->pc
->sources
;
4273 ppdMarkOption(ppd
, "InputSlot", pwgsource
->ppd
);
4275 if (p
->pc
->num_types
> 0)
4277 for (k
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4281 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4283 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
,
4289 else if (!ppdConflicts(ppd
))
4291 val
->collection
= new_media_col(pwgsize
, pwgsource
->pwg
, NULL
);
4296 else if (p
->pc
->num_types
> 0)
4298 for (j
= p
->pc
->num_types
, pwgtype
= p
->pc
->types
;
4302 if (!ppdMarkOption(ppd
, "MediaType", pwgtype
->ppd
))
4304 val
->collection
= new_media_col(pwgsize
, NULL
, pwgtype
->pwg
);
4312 * Update the number of media-col-database values...
4315 attr
->num_values
= val
- attr
->values
;
4323 if (p
->pc
&& p
->pc
->num_bins
> 0)
4325 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4326 "output-bin-supported", p
->pc
->num_bins
,
4331 for (i
= 0, val
= attr
->values
;
4332 i
< p
->pc
->num_bins
;
4334 val
->string
.text
= _cupsStrAlloc(p
->pc
->bins
[i
].pwg
);
4337 if ((output_bin
= ppdFindOption(ppd
, "OutputBin")) != NULL
)
4339 for (i
= 0; i
< p
->pc
->num_bins
; i
++)
4340 if (!strcmp(p
->pc
->bins
[i
].ppd
, output_bin
->defchoice
))
4343 if (i
>= p
->pc
->num_bins
)
4346 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4347 "output-bin-default", NULL
, p
->pc
->bins
[i
].pwg
);
4350 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4351 "output-bin-default", NULL
, p
->pc
->bins
[0].pwg
);
4353 else if (((ppd_attr
= ppdFindAttr(ppd
, "DefaultOutputOrder",
4355 !_cups_strcasecmp(ppd_attr
->value
, "Reverse")) ||
4356 (!ppd_attr
&& ppd
->manufacturer
&& /* "Compatibility heuristic" */
4357 (!_cups_strcasecmp(ppd
->manufacturer
, "epson") ||
4358 !_cups_strcasecmp(ppd
->manufacturer
, "lexmark"))))
4361 * Report that this printer has a single output bin that leaves pages face
4365 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4366 "output-bin-supported", NULL
, "face-up");
4367 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4368 "output-bin-default", NULL
, "face-up");
4372 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4373 "output-bin-supported", NULL
, "face-down");
4374 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4375 "output-bin-default", NULL
, "face-down");
4379 * print-color-mode...
4382 if (ppd
->color_device
)
4384 static const char * const color_modes
[] =
4390 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4391 "print-color-mode-supported", 2, NULL
, color_modes
);
4392 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4393 "print-color-mode-default", NULL
, "color");
4397 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4398 "print-color-mode-supported", NULL
, "monochrome");
4399 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4400 "print-color-mode-default", NULL
, "monochrome");
4404 * Mandatory job attributes, if any...
4407 if (p
->pc
&& cupsArrayCount(p
->pc
->mandatory
) > 0)
4409 int count
= cupsArrayCount(p
->pc
->mandatory
);
4410 /* Number of mandatory attributes */
4412 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4413 "printer-mandatory-job-attributes", count
, NULL
,
4416 for (val
= attr
->values
,
4417 mandatory
= (char *)cupsArrayFirst(p
->pc
->mandatory
);
4419 val
++, mandatory
= (char *)cupsArrayNext(p
->pc
->mandatory
))
4420 val
->string
.text
= _cupsStrAlloc(mandatory
);
4424 * Printer resolutions...
4427 if ((resolution
= ppdFindOption(ppd
, "Resolution")) == NULL
)
4428 if ((resolution
= ppdFindOption(ppd
, "JCLResolution")) == NULL
)
4429 if ((resolution
= ppdFindOption(ppd
, "SetResolution")) == NULL
)
4430 resolution
= ppdFindOption(ppd
, "CNRes_PGP");
4435 * Report all supported resolutions...
4438 attr
= ippAddResolutions(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4439 "printer-resolution-supported",
4440 resolution
->num_choices
, IPP_RES_PER_INCH
,
4443 for (i
= 0, choice
= resolution
->choices
;
4444 i
< resolution
->num_choices
;
4447 xdpi
= ydpi
= (int)strtol(choice
->choice
, (char **)&resptr
, 10);
4448 if (resptr
> choice
->choice
&& xdpi
> 0 && *resptr
== 'x')
4449 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4451 if (xdpi
<= 0 || ydpi
<= 0)
4453 cupsdLogMessage(CUPSD_LOG_WARN
,
4454 "Bad resolution \"%s\" for printer %s.",
4455 choice
->choice
, p
->name
);
4459 attr
->values
[i
].resolution
.xres
= xdpi
;
4460 attr
->values
[i
].resolution
.yres
= ydpi
;
4461 attr
->values
[i
].resolution
.units
= IPP_RES_PER_INCH
;
4464 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4465 "printer-resolution-default", IPP_RES_PER_INCH
,
4469 else if ((ppd_attr
= ppdFindAttr(ppd
, "DefaultResolution", NULL
)) != NULL
&&
4473 * Just the DefaultResolution to report...
4476 xdpi
= ydpi
= (int)strtol(ppd_attr
->value
, (char **)&resptr
, 10);
4477 if (resptr
> ppd_attr
->value
&& xdpi
> 0)
4480 ydpi
= (int)strtol(resptr
+ 1, (char **)&resptr
, 10);
4485 if (xdpi
<= 0 || ydpi
<= 0)
4487 cupsdLogMessage(CUPSD_LOG_WARN
,
4488 "Bad default resolution \"%s\" for printer %s.",
4489 ppd_attr
->value
, p
->name
);
4493 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4494 "printer-resolution-default", IPP_RES_PER_INCH
,
4496 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4497 "printer-resolution-supported", IPP_RES_PER_INCH
,
4503 * No resolutions in PPD - make one up...
4506 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4507 "printer-resolution-default", IPP_RES_PER_INCH
,
4509 ippAddResolution(p
->ppd_attrs
, IPP_TAG_PRINTER
,
4510 "printer-resolution-supported", IPP_RES_PER_INCH
,
4518 ppdMarkDefaults(ppd
);
4520 if ((duplex
= ppdFindOption(ppd
, "Duplex")) == NULL
)
4521 if ((duplex
= ppdFindOption(ppd
, "EFDuplex")) == NULL
)
4522 if ((duplex
= ppdFindOption(ppd
, "EFDuplexing")) == NULL
)
4523 if ((duplex
= ppdFindOption(ppd
, "KD03Duplex")) == NULL
)
4524 duplex
= ppdFindOption(ppd
, "JCLDuplex");
4526 if (duplex
&& duplex
->num_choices
> 1 &&
4527 !ppdInstallableConflict(ppd
, duplex
->keyword
, "DuplexTumble"))
4529 p
->type
|= CUPS_PRINTER_DUPLEX
;
4531 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4532 "sides-supported", 3, NULL
, sides
);
4534 if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexTumble"))
4535 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4536 "sides-default", NULL
, "two-sided-short-edge");
4537 else if (!_cups_strcasecmp(duplex
->defchoice
, "DuplexNoTumble"))
4538 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4539 "sides-default", NULL
, "two-sided-long-edge");
4541 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4542 "sides-default", NULL
, "one-sided");
4546 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4547 "sides-supported", NULL
, "one-sided");
4548 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4549 "sides-default", NULL
, "one-sided");
4552 if (ppdFindOption(ppd
, "Collate") != NULL
)
4553 p
->type
|= CUPS_PRINTER_COLLATE
;
4555 if (ppdFindOption(ppd
, "StapleLocation") != NULL
)
4557 p
->type
|= CUPS_PRINTER_STAPLE
;
4558 finishings
[num_finishings
++] = IPP_FINISHINGS_STAPLE
;
4561 if (ppdFindOption(ppd
, "BindEdge") != NULL
)
4563 p
->type
|= CUPS_PRINTER_BIND
;
4564 finishings
[num_finishings
++] = IPP_FINISHINGS_BIND
;
4567 for (i
= 0; i
< ppd
->num_sizes
; i
++)
4568 if (ppd
->sizes
[i
].length
> 1728)
4569 p
->type
|= CUPS_PRINTER_LARGE
;
4570 else if (ppd
->sizes
[i
].length
> 1008)
4571 p
->type
|= CUPS_PRINTER_MEDIUM
;
4573 p
->type
|= CUPS_PRINTER_SMALL
;
4575 if ((ppd_attr
= ppdFindAttr(ppd
, "APICADriver", NULL
)) != NULL
&&
4576 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4578 if ((ppd_attr
= ppdFindAttr(ppd
, "APScannerOnly", NULL
)) != NULL
&&
4579 ppd_attr
->value
&& !_cups_strcasecmp(ppd_attr
->value
, "true"))
4580 p
->type
|= CUPS_PRINTER_SCANNER
;
4582 p
->type
|= CUPS_PRINTER_MFP
;
4586 * Scan the filters in the PPD file...
4591 for (filter
= (const char *)cupsArrayFirst(p
->pc
->filters
);
4593 filter
= (const char *)cupsArrayNext(p
->pc
->filters
))
4595 if (!_cups_strncasecmp(filter
, "application/vnd.cups-command", 28) &&
4596 _cups_isspace(filter
[28]))
4598 p
->type
|= CUPS_PRINTER_COMMANDS
;
4604 if (p
->type
& CUPS_PRINTER_COMMANDS
)
4606 char *commands
, /* Copy of commands */
4607 *start
, /* Start of name */
4608 *end
; /* End of name */
4609 int count
; /* Number of commands */
4611 if ((ppd_attr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
)
4613 for (count
= 0, start
= ppd_attr
->value
; *start
; count
++)
4615 while (_cups_isspace(*start
))
4621 while (*start
&& !isspace(*start
& 255))
4631 * Make a copy of the commands string and count how many commands there
4635 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4636 "printer-commands", count
, NULL
, NULL
);
4638 commands
= strdup(ppd_attr
->value
);
4640 for (count
= 0, start
= commands
; *start
; count
++)
4642 while (isspace(*start
& 255))
4649 while (*end
&& !isspace(*end
& 255))
4655 attr
->values
[count
].string
.text
= _cupsStrAlloc(start
);
4665 * Add the standard list of commands...
4668 ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4670 (int)(sizeof(standard_commands
) /
4671 sizeof(standard_commands
[0])), NULL
,
4678 * No commands supported...
4681 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
,
4682 "printer-commands", NULL
, "none");
4686 * Show current and available port monitors for this printer...
4689 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
, "port-monitor",
4690 NULL
, p
->port_monitor
? p
->port_monitor
: "none");
4692 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4694 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
));
4698 if (strstr(ppd
->protocols
, "TBCP"))
4700 else if (strstr(ppd
->protocols
, "BCP"))
4704 attr
= ippAddStrings(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
4705 "port-monitor-supported", i
, NULL
, NULL
);
4707 attr
->values
[0].string
.text
= _cupsStrAlloc("none");
4709 for (i
= 1, ppd_attr
= ppdFindAttr(ppd
, "cupsPortMonitor", NULL
);
4711 i
++, ppd_attr
= ppdFindNextAttr(ppd
, "cupsPortMonitor", NULL
))
4712 attr
->values
[i
].string
.text
= _cupsStrAlloc(ppd_attr
->value
);
4716 if (strstr(ppd
->protocols
, "TBCP"))
4717 attr
->values
[i
].string
.text
= _cupsStrAlloc("tbcp");
4718 else if (strstr(ppd
->protocols
, "BCP"))
4719 attr
->values
[i
].string
.text
= _cupsStrAlloc("bcp");
4722 if (ppdFindAttr(ppd
, "APRemoteQueueID", NULL
))
4723 p
->type
|= CUPS_PRINTER_REMOTE
;
4725 #ifdef HAVE_APPLICATIONSERVICES_H
4727 * Convert the file referenced in APPrinterIconPath to a 128x128 PNG
4728 * and save it as cacheDir/printername.png
4731 if ((ppd_attr
= ppdFindAttr(ppd
, "APPrinterIconPath", NULL
)) != NULL
&&
4733 !_cupsFileCheck(ppd_attr
->value
, _CUPS_FILE_CHECK_FILE
, !RunUser
,
4734 cupsdLogFCMessage
, p
))
4736 CGImageRef imageRef
= NULL
;/* Current icon image */
4737 CGImageRef biggestIconRef
= NULL
;
4738 /* Biggest icon image */
4739 CGImageRef closestTo128IconRef
= NULL
;
4740 /* Icon image closest to and >= 128 */
4741 CGImageSourceRef sourceRef
; /* The file's image source */
4742 char outPath
[HTTP_MAX_URI
];
4743 /* The path to the PNG file */
4744 CFURLRef outUrl
; /* The URL made from the outPath */
4745 CFURLRef icnsFileUrl
; /* The URL of the original ICNS icon file */
4746 CGImageDestinationRef destRef
; /* The image destination to write */
4747 size_t bytesPerRow
; /* The bytes per row used for resizing */
4748 CGContextRef context
; /* The CG context used for resizing */
4750 snprintf(outPath
, sizeof(outPath
), "%s/%s.png", CacheDir
, p
->name
);
4751 outUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)outPath
, (CFIndex
)strlen(outPath
), FALSE
);
4752 icnsFileUrl
= CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault
, (UInt8
*)ppd_attr
->value
, (CFIndex
)strlen(ppd_attr
->value
), FALSE
);
4753 if (outUrl
&& icnsFileUrl
)
4755 sourceRef
= CGImageSourceCreateWithURL(icnsFileUrl
, NULL
);
4758 for (i
= 0; i
< (int)CGImageSourceGetCount(sourceRef
); i
++)
4760 imageRef
= CGImageSourceCreateImageAtIndex(sourceRef
, (size_t)i
, NULL
);
4764 if (CGImageGetWidth(imageRef
) == CGImageGetHeight(imageRef
))
4767 * Loop through remembering the icon closest to 128 but >= 128
4768 * and then remember the largest icon.
4771 if (CGImageGetWidth(imageRef
) >= 128 &&
4772 (!closestTo128IconRef
||
4773 CGImageGetWidth(imageRef
) <
4774 CGImageGetWidth(closestTo128IconRef
)))
4776 CGImageRelease(closestTo128IconRef
);
4777 CGImageRetain(imageRef
);
4778 closestTo128IconRef
= imageRef
;
4781 if (!biggestIconRef
||
4782 CGImageGetWidth(imageRef
) > CGImageGetWidth(biggestIconRef
))
4784 CGImageRelease(biggestIconRef
);
4785 CGImageRetain(imageRef
);
4786 biggestIconRef
= imageRef
;
4790 CGImageRelease(imageRef
);
4796 * If biggestIconRef is NULL, we found no icons. Otherwise we first
4797 * want the closest to 128, but if none are larger than 128, we want
4798 * the largest icon available.
4801 imageRef
= closestTo128IconRef
? closestTo128IconRef
:
4803 CGImageRetain(imageRef
);
4804 CGImageRelease(biggestIconRef
);
4805 if (closestTo128IconRef
)
4806 CGImageRelease(closestTo128IconRef
);
4807 destRef
= CGImageDestinationCreateWithURL(outUrl
, kUTTypePNG
, 1,
4811 if (CGImageGetWidth(imageRef
) != 128)
4813 bytesPerRow
= CGImageGetBytesPerRow(imageRef
) /
4814 CGImageGetWidth(imageRef
) * 128;
4815 context
= CGBitmapContextCreate(NULL
, 128, 128,
4816 CGImageGetBitsPerComponent(imageRef
),
4818 CGImageGetColorSpace(imageRef
),
4819 kCGImageAlphaPremultipliedFirst
);
4822 CGContextDrawImage(context
, CGRectMake(0, 0, 128, 128),
4824 CGImageRelease(imageRef
);
4825 imageRef
= CGBitmapContextCreateImage(context
);
4826 CGContextRelease(context
);
4830 CGImageDestinationAddImage(destRef
, imageRef
, NULL
);
4831 CGImageDestinationFinalize(destRef
);
4835 CGImageRelease(imageRef
);
4838 CFRelease(sourceRef
);
4846 CFRelease(icnsFileUrl
);
4848 #endif /* HAVE_APPLICATIONSERVICES_H */
4851 * Close the PPD and set the type...
4856 else if (!access(ppd_name
, 0))
4858 int pline
; /* PPD line number */
4859 ppd_status_t pstatus
; /* PPD load status */
4862 pstatus
= ppdLastError(&pline
);
4864 cupsdLogMessage(CUPSD_LOG_ERROR
, "PPD file for %s cannot be loaded.", p
->name
);
4866 if (pstatus
<= PPD_ALLOC_ERROR
)
4867 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s: %s", ppd_name
, strerror(errno
));
4869 cupsdLogMessage(CUPSD_LOG_ERROR
, "%s on line %d of %s.", ppdErrorString(pstatus
), pline
, ppd_name
);
4871 cupsdLogMessage(CUPSD_LOG_INFO
,
4872 "Hint: Run \"cupstestppd %s\" and fix any errors.",
4878 * If we have an interface script, add a filter entry for it...
4881 char interface
[1024]; /* Interface script */
4884 snprintf(interface
, sizeof(interface
), "%s/interfaces/%s", ServerRoot
,
4886 if (!access(interface
, X_OK
))
4889 * Yes, we have a System V style interface script; use it!
4892 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4893 "printer-make-and-model", NULL
,
4894 "Local System V Printer");
4896 else if (((!strncmp(p
->device_uri
, "ipp://", 6) ||
4897 !strncmp(p
->device_uri
, "ipps://", 7)) &&
4898 (strstr(p
->device_uri
, "/printers/") != NULL
||
4899 strstr(p
->device_uri
, "/classes/") != NULL
)) ||
4900 ((strstr(p
->device_uri
, "._ipp.") != NULL
||
4901 strstr(p
->device_uri
, "._ipps.") != NULL
) &&
4902 !strcmp(p
->device_uri
+ strlen(p
->device_uri
) - 5, "/cups")))
4905 * Tell the client this is really a hard-wired remote printer.
4908 p
->type
|= CUPS_PRINTER_REMOTE
;
4911 * Point the printer-uri-supported attribute to the
4915 if (strchr(p
->device_uri
, '?'))
4918 * Strip trailing "?options" from URI...
4921 char resource
[HTTP_MAX_URI
], /* New URI */
4922 *ptr
; /* Pointer into URI */
4924 strlcpy(resource
, p
->device_uri
, sizeof(resource
));
4925 if ((ptr
= strchr(resource
, '?')) != NULL
)
4928 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4929 "printer-uri-supported", NULL
, resource
);
4932 ippAddString(p
->attrs
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
4933 "printer-uri-supported", NULL
, p
->device_uri
);
4936 * Then set the make-and-model accordingly...
4939 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4940 "printer-make-and-model", NULL
, "Remote Printer");
4943 * Print all files directly...
4952 * Otherwise we have neither - treat this as a "dumb" printer
4953 * with no PPD file...
4956 ippAddString(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
,
4957 "printer-make-and-model", NULL
, "Local Raw Printer");
4963 ippAddIntegers(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4964 "finishings-supported", num_finishings
, finishings
);
4965 ippAddInteger(p
->ppd_attrs
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
,
4966 "finishings-default", IPP_FINISHINGS_NONE
);
4971 * Save cached PPD attributes to disk...
4974 cupsdLogMessage(CUPSD_LOG_DEBUG
, "load_ppd: Saving %s...", cache_name
);
4976 _ppdCacheWriteFile(p
->pc
, cache_name
, p
->ppd_attrs
);
4981 * Remove cache files...
4984 if (cache_info
.st_mtime
)
4991 * 'new_media_col()' - Create a media-col collection value.
4994 static ipp_t
* /* O - Collection value */
4995 new_media_col(_pwg_size_t
*size
, /* I - media-size/margin values */
4996 const char *source
, /* I - media-source value */
4997 const char *type
) /* I - media-type value */
4999 ipp_t
*media_col
, /* Collection value */
5000 *media_size
; /* media-size value */
5003 media_col
= ippNew();
5005 media_size
= ippNew();
5006 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5007 "x-dimension", size
->width
);
5008 ippAddInteger(media_size
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5009 "y-dimension", size
->length
);
5010 ippAddCollection(media_col
, IPP_TAG_PRINTER
, "media-size", media_size
);
5011 ippDelete(media_size
);
5013 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5014 "media-bottom-margin", size
->bottom
);
5015 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5016 "media-left-margin", size
->left
);
5017 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5018 "media-right-margin", size
->right
);
5019 ippAddInteger(media_col
, IPP_TAG_PRINTER
, IPP_TAG_INTEGER
,
5020 "media-top-margin", size
->top
);
5023 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-source",
5027 ippAddString(media_col
, IPP_TAG_PRINTER
, IPP_TAG_KEYWORD
, "media-type",
5035 * 'write_xml_string()' - Write a string with XML escaping.
5039 write_xml_string(cups_file_t
*fp
, /* I - File to write to */
5040 const char *s
) /* I - String to write */
5042 const char *start
; /* Start of current sequence */
5048 for (start
= s
; *s
; s
++)
5053 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5055 cupsFilePuts(fp
, "&");
5061 cupsFileWrite(fp
, start
, (size_t)(s
- start
));
5063 cupsFilePuts(fp
, "<");
5069 cupsFilePuts(fp
, start
);